-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-9750; Fix race condition with log dir reassign completion #8412
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
Changes from all commits
553ab81
2580441
d9df438
9dd4ec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,7 +62,7 @@ abstract class AbstractFetcherThread(name: String, | |
| type EpochData = OffsetsForLeaderEpochRequest.PartitionData | ||
|
|
||
| private val partitionStates = new PartitionStates[PartitionFetchState] | ||
| private val partitionMapLock = new ReentrantLock | ||
| protected val partitionMapLock = new ReentrantLock | ||
| private val partitionMapCond = partitionMapLock.newCondition() | ||
|
|
||
| private val metricId = ClientIdAndBroker(clientId, sourceBroker.host, sourceBroker.port) | ||
|
|
@@ -199,7 +199,7 @@ abstract class AbstractFetcherThread(name: String, | |
| * - Send OffsetsForLeaderEpochRequest, retrieving the latest offset for each partition's | ||
| * leader epoch. This is the offset the follower should truncate to ensure | ||
| * accurate log replication. | ||
| * - Finally truncate the logs for partitions in the truncating phase and mark them | ||
| * - Finally truncate the logs for partitions in the truncating phase and mark the | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was tempted to fix this with the plural |
||
| * truncation complete. Do this within a lock to ensure no leadership changes can | ||
| * occur during truncation. | ||
| */ | ||
|
|
@@ -419,10 +419,11 @@ abstract class AbstractFetcherThread(name: String, | |
| warn(s"Partition $topicPartition marked as failed") | ||
| } | ||
|
|
||
|
|
||
| def addPartitions(initialFetchStates: Map[TopicPartition, OffsetAndEpoch]): Unit = { | ||
| def addPartitions(initialFetchStates: Map[TopicPartition, OffsetAndEpoch]): Set[TopicPartition] = { | ||
| partitionMapLock.lockInterruptibly() | ||
| try { | ||
| failedPartitions.removeAll(initialFetchStates.keySet) | ||
|
|
||
| initialFetchStates.foreach { case (tp, initialFetchState) => | ||
| // We can skip the truncation step iff the leader epoch matches the existing epoch | ||
| val currentState = partitionStates.stateValue(tp) | ||
|
|
@@ -437,6 +438,7 @@ abstract class AbstractFetcherThread(name: String, | |
| } | ||
|
|
||
| partitionMapCond.signalAll() | ||
| initialFetchStates.keySet | ||
| } finally partitionMapLock.unlock() | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -91,7 +91,7 @@ class ReplicaAlterLogDirsThread(name: String, | |
| Request.FutureLocalReplicaId, | ||
| request.minBytes, | ||
| request.maxBytes, | ||
| request.version <= 2, | ||
| false, | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We always build with the latest fetch version, so this check was unneeded. |
||
| request.fetchData.asScala.toSeq, | ||
| UnboundedQuota, | ||
| processResponseCallback, | ||
|
|
@@ -116,7 +116,11 @@ class ReplicaAlterLogDirsThread(name: String, | |
| throw new IllegalStateException("Offset mismatch for the future replica %s: fetched offset = %d, log end offset = %d.".format( | ||
| topicPartition, fetchOffset, futureLog.logEndOffset)) | ||
|
|
||
| val logAppendInfo = partition.appendRecordsToFollowerOrFutureReplica(records, isFuture = true) | ||
| val logAppendInfo = if (records.sizeInBytes() > 0) | ||
| partition.appendRecordsToFollowerOrFutureReplica(records, isFuture = true) | ||
| else | ||
| None | ||
|
|
||
| futureLog.updateHighWatermark(partitionData.highWatermark) | ||
| futureLog.maybeIncrementLogStartOffset(partitionData.logStartOffset) | ||
|
|
||
|
|
@@ -127,6 +131,20 @@ class ReplicaAlterLogDirsThread(name: String, | |
| logAppendInfo | ||
| } | ||
|
|
||
| override def addPartitions(initialFetchStates: Map[TopicPartition, OffsetAndEpoch]): Set[TopicPartition] = { | ||
| partitionMapLock.lockInterruptibly() | ||
| try { | ||
| // It is possible that the log dir fetcher completed just before this call, so we | ||
| // filter only the partitions which still have a future log dir. | ||
| val filteredFetchStates = initialFetchStates.filter { case (tp, _) => | ||
| replicaMgr.futureLogExists(tp) | ||
| } | ||
| super.addPartitions(filteredFetchStates) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we skip to create thread if the collection of filtered states is empty?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this will be a no-op in |
||
| } finally { | ||
| partitionMapLock.unlock() | ||
| } | ||
| } | ||
|
|
||
| override protected def fetchEarliestOffsetFromLeader(topicPartition: TopicPartition, leaderEpoch: Int): Long = { | ||
| val partition = replicaMgr.getPartitionOrException(topicPartition, expectLeader = false) | ||
| partition.localLogOrException.logStartOffset | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.