-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KAFKA-18555: Avoid casting MetadataCache to KRaftMetadataCache #18632
base: trunk
Are you sure you want to change the base?
Conversation
Signed-off-by: PoAn Yang <[email protected]>
@ijuma The only remaining casting is in
|
It's ok to pull up that method to MetadataCache, but we should take the chance and make it more concise. Instead of |
Signed-off-by: PoAn Yang <[email protected]>
Signed-off-by: PoAn Yang <[email protected]>
Signed-off-by: PoAn Yang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, left a few comments.
Some(new DescribeTopicPartitionsRequestHandler(kRaftMetadataCache, authHelper, config)) | ||
case _ => None | ||
} | ||
val describeTopicPartitionsRequestHandler : DescribeTopicPartitionsRequestHandler = new DescribeTopicPartitionsRequestHandler( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an existing issue, but since you're touching this file, remove the : DescribeTopicPartitionsRequestHandler
(it's redundant).
@@ -272,7 +272,7 @@ class KRaftMetadataCache( | |||
* @param maximumNumberOfPartitions The max number of partitions to return. | |||
* @param ignoreTopicsWithExceptions Whether ignore the topics with exception. | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this scaladoc to the interface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FrankYang0529 Could you please remove those comments as you have moved them to the interface
KRaftMetadataCache metadataCache = new KRaftMetadataCache(0, () -> KRaftVersion.KRAFT_VERSION_1); | ||
updateKraftMetadataCache(metadataCache, records); | ||
MetadataCache metadataCache = new KRaftMetadataCache(0, () -> KRaftVersion.KRAFT_VERSION_1); | ||
updateKraftMetadataCache((KRaftMetadataCache) metadataCache, records); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these changes seem to make things worse.
KRaftMetadataCache metadataCache = new KRaftMetadataCache(0, () -> KRaftVersion.KRAFT_VERSION_1); | ||
updateKraftMetadataCache(metadataCache, records); | ||
MetadataCache metadataCache = new KRaftMetadataCache(0, () -> KRaftVersion.KRAFT_VERSION_1); | ||
updateKraftMetadataCache((KRaftMetadataCache) metadataCache, records); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as the comment above.
@@ -348,6 +348,7 @@ class PartitionLockTest extends Logging { | |||
val controllerEpoch = 0 | |||
val replicas = (0 to numReplicaFetchers).map(i => Integer.valueOf(brokerId + i)).toList.asJava | |||
val isr = replicas | |||
replicas.forEach(replicaId => when(metadataCache.getAliveBrokerEpoch(replicaId)).thenReturn(Some(1L))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this extra code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use mock(classOf[MetadataCache])
for metadataCache
, so it didn't really get into KRaftMetadataCache
block. In this PR, we remove match
block, so we have to add related mock.
val metadataCache: MetadataCache = mock(classOf[MetadataCache]) |
kafka/core/src/main/scala/kafka/cluster/Replica.scala
Lines 116 to 125 in 94a1bfb
metadataCache match { | |
case kRaftMetadataCache: KRaftMetadataCache => | |
val cachedBrokerEpoch = kRaftMetadataCache.getAliveBrokerEpoch(brokerId) | |
// Fence the update if it provides a stale broker epoch. | |
if (brokerEpoch != -1 && cachedBrokerEpoch.exists(_ > brokerEpoch)) { | |
throw new NotLeaderOrFollowerException(s"Received stale fetch state update. broker epoch=$brokerEpoch " + | |
s"vs expected=${cachedBrokerEpoch.get}") | |
} | |
case _ => | |
} |
@@ -186,6 +186,7 @@ class PartitionTest extends AbstractPartitionTest { | |||
val leaderEpoch = 10 | |||
val logStartOffset = 0L | |||
val partition = setupPartitionWithMocks(leaderEpoch = leaderEpoch, isLeader = true) | |||
addBrokerEpochToMockMetadataCache(metadataCache, List(remoteReplicaId)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, why are these changes needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. We use mock(classOf[MetadataCache])
in AbstractPartitionTest
.
val metadataCache: MetadataCache = mock(classOf[MetadataCache]) |
@@ -793,6 +793,7 @@ class ReplicaManagerTest { | |||
|
|||
try { | |||
val brokerList = Seq[Integer](0, 1).asJava | |||
when(replicaManager.metadataCache.getAliveBrokerEpoch(1)).thenReturn(Some(brokerEpoch)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above. In ReplicaManagerTest#setupReplicaManagerWithMockedPurgatories
, it uses mock(classOf[MetadataCache])
.
val metadataCache: MetadataCache = mock(classOf[MetadataCache]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please move the mock to line#3154? We should mock the method after creating the mocked metadataCache
Signed-off-by: PoAn Yang <[email protected]>
isBrokerEpochIsrEligible(storedBrokerEpoch, cachedBrokerEpoch) | ||
|
||
case _ => true | ||
// In KRaft mode, only a replica which meets all of the following requirements is allowed to join the ISR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can remove "In KRaft mode"?
Signed-off-by: PoAn Yang <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: PoAn Yang <[email protected]>
Updated it. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FrankYang0529 overall LGTM except for one trivial comment
@@ -272,7 +272,7 @@ class KRaftMetadataCache( | |||
* @param maximumNumberOfPartitions The max number of partitions to return. | |||
* @param ignoreTopicsWithExceptions Whether ignore the topics with exception. | |||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@FrankYang0529 Could you please remove those comments as you have moved them to the interface
Signed-off-by: PoAn Yang <[email protected]>
The ZkMetadataCache is removed in https://issues.apache.org/jira/browse/KAFKA-18373. We should pull up the relevant methods so that no casting from MetadataCache to KRaftMetadataCache is required.
Add following methods to MetadataCache:
Committer Checklist (excluded from commit message)