Table of Contents |
---|
This page is meant as a template for writing a KIP. To create a KIP choose Tools->Copy on this page and modify with your content and replace the heading with the next KIP number and a description of your issue. Replace anything in italics with your own description.
Status
Current state:"Under DiscussionApproved"
Discussion thread: here
JIRA: KAFKA-13888
Please keep the discussion on the mailing list rather than commenting on the wiki (wiki discussions get unwieldy fast).
Motivation
The DescribeQuorum
API as defined in KIP-595 is intended to allow the admin client to query the status of the Kraft quorum, including information about voter lag.
...
This KIP proposes making DescribeQuorum
API accessible via the admin client and augmenting the DescribeQuorum
API response with more information to be able to ascertain the liveness and lag of the voters in the quorum more accurately.
Public Interfaces
Additional Classes to expose the
...
DescribeMetadataQuorumResult API to the admin client:
Code Block |
---|
public class DescribeQuorumResultDescribeMetadataQuorumResult { private final KafkaFuture<DescribeQuorumResponseData>KafkaFuture<QuorumInfo> resultquorumInfo; public DescribeQuorumResultDescribeMetadataQuorumResult(KafkaFuture<DescribeQuorumResponseData>KafkaFuture<QuorumInfo> resultquorumInfo) { this.resultquorumInfo = resultquorumInfo; } /** * Returns a future containing the DescribeQuorumResponseQuorumInfo */ public KafkaFuture<DescribeQuorumResponseData>KafkaFuture<QuorumInfo> resultquorumInfo() { return resultquorumInfo; } } |
Code Block |
---|
public class DescribeQuorumOptionsQuorumInfo extends{ AbstractOptions<DescribeQuorumOptions> { } |
DescribeQuorum Handler in the Admin Client
Code Block |
---|
/** private final Integer leaderId; * Describe the state of the raft quorumprivate final List<ReplicaState> voters; private final List<ReplicaState> observers; QuorumInfo(Integer *leaderId, <p> List<ReplicaState> voters, List<ReplicaState> observers) { * The following exceptions can be anticipated whenthis.leaderId calling {@code get()} on the futures obtained from * the returned {@code DescribeQuorumResult}: * <ul>= leaderId; this.voters = voters; this.observers = observers; } * <li>{@link org.apache.kafka.common.errors.ClusterAuthorizationException} public Integer leaderId() { * return IfleaderId; the authenticated user didn't have {@code DESCRIBE} access to the cluster.</li> } public List<ReplicaState> voters() { * <li>{@link org.apache.kafka.common.errors.TimeoutException}return voters; } * Ifpublic theList<ReplicaState> request timed out before the controller could list the cluster links.</li>observers() { return observers; * </ul>} *@Override public * @param options The options to use when describing the quorum. * @return The DescribeQuorumResult. boolean equals(Object o) { if (this == o) return true; */ if (o == null DescribeQuorumResult|| describeQuorum(DescribeQuorumOptions options); |
Proposed change in the DescribeQuorum
Response:
Code Block |
---|
"apiKey": 55, "type": "response", "name": "DescribeQuorumResponse", "validVersions": "0-1", "flexibleVersions": "0+", "fields": [ { "name": "ErrorCode", "type": "int16", "versions": "0+", "about": "The top level error code."}, { "name": "Topics", "type": "[]TopicData", "versions": "0+", "fields": [ { "name": "TopicName", "type": "string", "versions": "0+", "entityType": "topicName", "about": "The topic name." },getClass() != o.getClass()) return false; QuorumInfo that = (QuorumInfo) o; return leaderId.equals(that.leaderId) && voters.equals(that.voters) && observers.equals(that.observers); } @Override public int hashCode() { return Objects.hash(leaderId, voters, observers); } @Override public String toString() { { "name": "Partitions", return "typeQuorumInfo(": "[]PartitionData", + "versionsleaderId=": "0+", "fields": [ leaderId + { "name": "PartitionIndex", "typevoters=": "int32", "versions": "0+",+ voters + "about":, observers="The partition+ index." },observers + { "name": "ErrorCode", "type": "int16", "versions": "0+"}, ')'; } public static class ReplicaState { "name": "LeaderId", "type": "int32", "versions": "0+", "entityType": "brokerId", private final int replicaId; private final "about": "The ID of the current leader or -1 if the leader is unknown."}, long logEndOffset; private final OptionalLong lastFetchTimestamp; private { "name": "LeaderEpoch", "type": "int32", "versions": "0+",final OptionalLong lastCaughtUpTimestamp; ReplicaState() { "about": "The latest known leader epoch"}, this(0, { "name": "HighWatermark", "type": "int64", "versions": "0+"}, 0, OptionalLong.empty(), OptionalLong.empty()); } ReplicaState( { "name": "CurrentVoters", "type": "[]ReplicaState", "versions": "0+" }, { "name": "Observers", "type": "[]ReplicaState", "versions": "0+" } ]} ]}], "commonStructs": [ { "name": "ReplicaState", "versions": "0+", "fields": [ { "name": "ReplicaId", "type": "int32", "versions": "0+", "entityType": "brokerId" }, { "name": "LogEndOffset", "type": "int64", "versions": "0+", "about": "The last known log end offset of the follower or -1 if it is unknown"}, { "name": "LastFetchTime", "type": "int64", "versions": "1+", "about": "The last known leader wall int replicaId, long logEndOffset, OptionalLong lastFetchTimestamp, OptionalLong lastCaughtUpTimestamp ) { this.replicaId = replicaId; this.logEndOffset = logEndOffset; this.lastFetchTimestamp = lastFetchTimestamp; this.lastCaughtUpTimestamp = lastCaughtUpTimestamp; } /** * Return the ID for this replica. * @return The ID for this replica */ public int replicaId() { return replicaId; } /** * Return the logEndOffset known by the leader for this replica. * @return The logEndOffset for this replica */ public long logEndOffset() { return logEndOffset; } /** * Return the lastFetchTime in milliseconds for this replica. * @return The value of the lastFetchTime if known, empty otherwise */ public OptionalLong lastFetchTimestamp() { return lastFetchTimestamp; } /** * Return the lastCaughtUpTime in milliseconds for this replica. * @return The value of the lastCaughtUpTime if known, empty otherwise */ public OptionalLong lastCaughtUpTimestamp() { return lastCaughtUpTimestamp; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ReplicaState that = (ReplicaState) o; return replicaId == that.replicaId && logEndOffset == that.logEndOffset && lastFetchTimestamp.equals(that.lastFetchTimestamp) && lastCaughtUpTimestamp.equals(that.lastCaughtUpTimestamp); } @Override public int hashCode() { return Objects.hash(replicaId, logEndOffset, lastFetchTimestamp, lastCaughtUpTimestamp); } @Override public String toString() { return "ReplicaState(" + "replicaId=" + replicaId + ", logEndOffset=" + logEndOffset + ", lastFetchTimestamp=" + lastFetchTimestamp + ", lastCaughtUpTimestamp=" + lastCaughtUpTimestamp + ')'; } } } |
Code Block |
---|
public class DescribeMetadataQuorumOptions extends AbstractOptions<DescribeMetadataQuorumOptions> {
} |
DescribeMetadataQuorum Handler in the Admin Client
Code Block |
---|
/**
* Describes the state of the metadata quorum.
* <p>
* This is a convenience method for {@link #describeMetadataQuorum(DescribeMetadataQuorumOptions)} with default options.
* See the overload for more details.
*
* @return the {@link DescribeMetadataQuorumResult} containing the result
*/
default DescribeMetadataQuorumResult describeMetadataQuorum() {
return describeMetadataQuorum(new DescribeMetadataQuorumOptions());
}
/**
* Describes the state of the metadata quorum.
* <p>
* The following exceptions can be anticipated when calling {@code get()} on the futures obtained from
* the returned {@code DescribeMetadataQuorumResult}:
* <ul>
* <li>{@link org.apache.kafka.common.errors.ClusterAuthorizationException}
* If the authenticated user didn't have {@code DESCRIBE} access to the cluster.</li>
* <li>{@link org.apache.kafka.common.errors.TimeoutException}
* If the request timed out before the controller could list the cluster links.</li>
* </ul>
*
* @param options The {@link DescribeMetadataQuorumOptions} to use when describing the quorum.
* @return the {@link DescribeMetadataQuorumResult} containing the result
*/
DescribeMetadataQuorumResult describeMetadataQuorum(DescribeMetadataQuorumOptions options); |
Proposed change in the DescribeQuorum
Response:
Code Block |
---|
"apiKey": 55,
"type": "response",
"name": "DescribeQuorumResponse",
"validVersions": "0-1",
"flexibleVersions": "0+",
"fields": [
{ "name": "ErrorCode", "type": "int16", "versions": "0+",
"about": "The top level error code."},
{ "name": "Topics", "type": "[]TopicData",
"versions": "0+", "fields": [
{ "name": "TopicName", "type": "string", "versions": "0+", "entityType": "topicName",
"about": "The topic name." },
{ "name": "Partitions", "type": "[]PartitionData",
"versions": "0+", "fields": [
{ "name": "PartitionIndex", "type": "int32", "versions": "0+",
"about": "The partition index." },
{ "name": "ErrorCode", "type": "int16", "versions": "0+"},
{ "name": "LeaderId", "type": "int32", "versions": "0+", "entityType": "brokerId",
"about": "The ID of the current leader or -1 if the leader is unknown."},
{ "name": "LeaderEpoch", "type": "int32", "versions": "0+",
"about": "The latest known leader epoch"},
{ "name": "HighWatermark", "type": "int64", "versions": "0+"},
{ "name": "CurrentVoters", "type": "[]ReplicaState", "versions": "0+" },
{ "name": "Observers", "type": "[]ReplicaState", "versions": "0+" }
]}
]}],
"commonStructs": [
{ "name": "ReplicaState", "versions": "0+", "fields": [
{ "name": "ReplicaId", "type": "int32", "versions": "0+", "entityType": "brokerId" },
{ "name": "LogEndOffset", "type": "int64", "versions": "0+",
"about": "The last known log end offset of the follower or -1 if it is unknown"},
{ "name": "LastFetchTimestamp", "type": "int64", "versions": "1+", "ignorable": true, "default": -1,
"about": "The last known leader wall clock time time when a follower fetched from the leader. This is reported as -1 both for the current leader or if it is unknown for a voter"},
{ "name": "LastCaughtUpTimestamp", "type": "int64", "versions": "1+", "ignorable": true, "default": -1,
"about": "The leader wall clock append time of the offset for which the follower made the most recent fetch request. This is reported as the current time for the leader and -1 if unknown for a voter"}
]}
] |
kafka-metadata-quorum.sh
The output from this API will also be captured in the kafka-metadata-quorum.sh
. The output of the --describe replication
command in the tool as defined in KIP-595 will change as follows:
Code Block |
---|
> bin/kafka-metadata-quorum.sh --describe replication ReplicaId LogEndOffset Lag LastFetchTimestamp LastCaughtUpTimestamp Status 0 234134 0 tnow tnow Leader 1 234130 4 t2 t6 Follower 2 234100 34 t3 t7 Follower 3 234124 10 t4 t8 Observer 4 234130 4 t5 t9 Observerclock time time when a follower fetched from the leader. This is reported as -1 both for the current leader or if it is unknown for a voter"}, { "name": "LastCaughtUpTime", "type": "int64", "versions": "1+", "about": "The leader wall clock append time of the offset for which the follower made the most recent fetch request. This is reported as the current time for the leader and -1 if unknown for a voter"} ]} ] |
Proposed Changes
This KIP proposes exposing the DescribeQuorum
API to the admin client and adding two new fields (per voterper replica (including voters and observers) to the DescribeQuorum
API response.
These fields are intended to approximate the "time-lag" between the leader and the followers in the quorum.
LastFetchTimestampLast Fetch Time
This metric will be reported for each voter. This is a good approximation of the “liveness” of the voters and can be used to detect a network partition in the quorum.
This information is already known to the leader for all voters and only needs to be added to the responseLastCaughtUpTimestampLast Caught Up Time
This metric will be reported for each voter. This is akin to the metric used to track lag for replicas in ISR and it measures the approximate lag between the leader and the replica based on the offsets requested in the fetch requests and when they were made. The metric gives a measure of when was the last time a replica caught up to the leader. .
To compute this metric, the Replica state maintains a few bits of information about fetch requests as they are received. Some of this information is not tracked by the Raft layer but it can be easily added in. The cost to track this information is minimal and it only requires some additional bookkeeping during pre-existing processing for a fetch.
NOTE: Given the leader is always caught up to itself, the Last Caught Up Time for the leader will be the leader's wall clock time when it responded to theDescribeQuorum
request.
Compatibility, Deprecation, and Migration Plan
The API response is versioned and the newly added fields will bump the message version on the response. This should handle any issues around compatibility.
Rejected Alternatives
Use Existing Fields
An alternative here was to not add in this information and use existing information available in the response to compute voter lag. As discussed in the motivation section, the only information available in the response at the moment is the offset, which does not allow for a very reliable mechanism to ascertain voter lag.
Track Some Other Information
Another possibility here is to add information which allows us to tell the voter lag more accurately. An argument can be made against the accuracy of the lag as measured by the additional fields proposed in this KIP. A more complete view of the voters would be to add in Replica Time/Offset Information
...