KAFKA-9750 Flaky test kafka.server.ReplicaManagerTest.testFencedError…#8344
KAFKA-9750 Flaky test kafka.server.ReplicaManagerTest.testFencedError…#8344chia7712 wants to merge 1 commit intoapache:trunkfrom
Conversation
|
@jsancio FYI |
bfa84b4 to
a4aaa30
Compare
|
cc @hachikuji @junrao to help with the review. |
There was a problem hiding this comment.
At a high level, I am concerned with the stability of this test as we make changes to the code in the future. It seems like we are exposing internal concurrency requirements to the tests.
There was a problem hiding this comment.
Got it. Let me revert this change.
|
the build error is traced by #8361 |
|
@chia7712 Will look more carefully later today. Just want to confirm that this is an issue with the test case only? |
@hachikuji Could you share the log to me? |
it seems the second run (created by #becomeLeaderOrFollower) start to run as the first run (created by #alterReplicaLogDirs) is completed. Hence, the future log is removed by first run and then second run crashes. Finally, the assert fails (since the second run crashes so the pending partition exists) and we see the terrible error message. #8223 introduced this issue since it tries to create an new alter thread (or add partition to existent thread) for the existent partition. Before #8223, it works only for the new partition. |
|
Apply the attachment and then the error can happen consistently :( |
|
There are three scenarios when ReplicaManager#becomeLeaderOrFollower is updating epoch and the alter thread is running.
In short, this PR adds new method (AbstractFetcherThread#updateEpochs) to alter thread to enable us to update epoch of pending thread and resume the thread from fenced error. |
There was a problem hiding this comment.
handle the fenced error only
There was a problem hiding this comment.
update the epoch in alter thread. the update make alter thread aware of new epoch so it is able to keep fetching data with new epoch
2166e0a to
eda568d
Compare
mumrah
left a comment
There was a problem hiding this comment.
Thanks for the patch! Only one real question:
Previously, online partitions and new partitions would get added to the updatedPartitions set and later pass their initial fetch state toAbstractFetcherManager#addFetcherForPartitions. Now it seems like only new partitions follow this code path and existing online partitions simply update the epoch in the existing fetcher threads.
I'm wondering if this code still gets run in AbstractFetcherManager#addFetcherForPartitions:
case Some(f) =>
f.shutdown()
addAndStartFetcherThread(brokerAndFetcherId, brokerIdAndFetcherId)
Will new threads still be created in cases where the source broker has moved?
There was a problem hiding this comment.
Does this need to be synchronized here? Shouldn't it only be called from becomeLeaderOrFollower which holds the replicaStateChangeLock?
There was a problem hiding this comment.
The other methods used to update inner threads are in synchronized lock so this new method is synchronized also.
There was a problem hiding this comment.
nit: Can this be handled with a nested match/case using types? (rather than using getClass)
There was a problem hiding this comment.
not sure how to match dynamical class type in scala. But I rewrite this match pattern by Errors.forException which converts the exception to Error.
failedPartitions.exception(tp) match {
case Some(e) =>
Errors.forException(e) match {
case Errors.FENCED_LEADER_EPOCH =>
addPartitions(Map(tp -> OffsetAndEpoch(state.initOffset, state.currentLeaderEpoch)))
failedPartitions.removeAll(Set(tp))
case _ =>
// the exception is NOT caused by inconsistent epoch so we can't resume the error
}
case None =>
Option(partitionStates.stateValue(tp)).map(_.copy(currentLeaderEpoch = state.currentLeaderEpoch))
.foreach(partitionStates.updateAndMoveToEnd(tp, _))
}
IIRC, the source folder and target folder must be on the same broker when altering a replica folder. The case you mentioned should not happen on |
…rCausedByBecomeLeader
|
@chia7712 @mumrah I wanted to suggest an alternative fix: hachikuji@20a9c6a. As I understand the problem, there is a race between adding the partition to the alter log dir fetcher on receiving the LeaderAndIsr request and the completion of the log dir reassignment which removes the partition directly from the fetcher thread. It seems like it might be a little simpler to check at the time the partition is added whether the future log dir still exists. Does this miss any cases? |
|
I turned this into a separate PR: #8412. I think this patch is simpler and less risky for 2.5, but let me know if I have missed anything. |
|
@hachikuji I have left some comment on you PR. I will close this PR later :) |
The root cause is race condition. The partition is add to the end instead of being removed if the epoch in ReplicaAlterLogDirsThread is increased. This PR includes following changes.
Committer Checklist (excluded from commit message)