You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "Divij Vaidya (Jira)" <ji...@apache.org> on 2022/06/15 11:01:00 UTC
[jira] [Created] (KAFKA-13994) Incorrect quota calculation due to a bug
Divij Vaidya created KAFKA-13994:
------------------------------------
Summary: Incorrect quota calculation due to a bug
Key: KAFKA-13994
URL: https://issues.apache.org/jira/browse/KAFKA-13994
Project: Kafka
Issue Type: Bug
Components: core
Reporter: Divij Vaidya
*Problem*
This was noted by [~tombentley] at [https://github.com/apache/kafka/pull/12045#discussion_r895592286]
The completion of a sample window in `SampledStat.java` is based on comparison of `
recordingTimeMs` with startTimeOfPreviousWindow [1]. `recordingTimeMs` is calculated as a System.currentTimeMillis which:
1. is not guaranteed to be monotonically increasing due to clock drifts.
2. is not necessarily the current time when it arrives at [1] because the thread may be blocked at `synchronized` at {{{}Sensor.recordInternal [2]{}}}, because synchronized provides no guarantee about fairness for blocked threads.
Hence, it is possible that when isComplete comparison is made at [1], recordingTimeMs < endTimeOfCurrentWindow whereas the wallClockTimeAtTheMoment > startTimeOfCurrentWindow + window length.
The implication of this would be:
1. The current sample window will not be considered completed even if it has completed as per wall clock time.
2. The value will be recorded in a sample window which has elapsed instead of a new window where it belongs.
Due to the above two implications, the metrics captured by the sensor may not be correct which could lead to incorrect quota calculations.
[1] [https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/metrics/stats/SampledStat.java#L138]
[2] https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/common/metrics/Sensor.java#L232
--
This message was sent by Atlassian Jira
(v8.20.7#820007)