-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-8002: Replica reassignment to new log dir may not complete if f… #6346
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,7 +26,7 @@ import kafka.api.{ApiVersion, Request} | |
| import kafka.common.UnexpectedAppendOffsetException | ||
| import kafka.log.{Defaults => _, _} | ||
| import kafka.server._ | ||
| import kafka.utils.{CoreUtils, MockScheduler, MockTime, TestUtils} | ||
| import kafka.utils._ | ||
| import kafka.zk.KafkaZkClient | ||
| import org.apache.kafka.common.TopicPartition | ||
| import org.apache.kafka.common.errors.{ApiException, OffsetNotAvailableException, ReplicaNotAvailableException} | ||
|
|
@@ -199,6 +199,52 @@ class PartitionTest { | |
| assertEquals(None, partition.futureLocalReplica) | ||
| } | ||
|
|
||
| @Test | ||
| // Verify that replacement works when the replicas have the same log end offset but different base offsets in the | ||
|
Contributor
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. nit: Move this comment above annotation? |
||
| // active segment | ||
| def testMaybeReplaceCurrentWithFutureReplicaDifferentBaseOffsets(): Unit = { | ||
| // Write records with duplicate keys to current replica and roll at offset 6 | ||
| logManager.maybeUpdatePreferredLogDir(topicPartition, logDir1.getAbsolutePath) | ||
| val log1 = logManager.getOrCreateLog(topicPartition, logConfig) | ||
| log1.appendAsLeader(MemoryRecords.withRecords(0L, CompressionType.NONE, 0, | ||
| new SimpleRecord("k1".getBytes, "v1".getBytes), | ||
| new SimpleRecord("k1".getBytes, "v2".getBytes), | ||
| new SimpleRecord("k1".getBytes, "v3".getBytes), | ||
| new SimpleRecord("k2".getBytes, "v4".getBytes), | ||
| new SimpleRecord("k2".getBytes, "v5".getBytes), | ||
| new SimpleRecord("k2".getBytes, "v6".getBytes) | ||
| ), leaderEpoch = 0) | ||
| log1.roll() | ||
| log1.appendAsLeader(MemoryRecords.withRecords(0L, CompressionType.NONE, 0, | ||
| new SimpleRecord("k3".getBytes, "v7".getBytes), | ||
| new SimpleRecord("k4".getBytes, "v8".getBytes) | ||
| ), leaderEpoch = 0) | ||
|
|
||
| // Write to the future replica as if the log had been compacted, and do not roll the segment | ||
| logManager.maybeUpdatePreferredLogDir(topicPartition, logDir2.getAbsolutePath) | ||
| val log2 = logManager.getOrCreateLog(topicPartition, logConfig, isFuture = true) | ||
| val buffer = ByteBuffer.allocate(1024) | ||
| var builder = MemoryRecords.builder(buffer, RecordBatch.CURRENT_MAGIC_VALUE, CompressionType.NONE, | ||
| TimestampType.CREATE_TIME, 0L, RecordBatch.NO_TIMESTAMP, 0) | ||
| builder.appendWithOffset(2L, new SimpleRecord("k1".getBytes, "v3".getBytes)) | ||
| builder.appendWithOffset(5L, new SimpleRecord("k2".getBytes, "v6".getBytes)) | ||
| builder.appendWithOffset(6L, new SimpleRecord("k3".getBytes, "v7".getBytes)) | ||
| builder.appendWithOffset(7L, new SimpleRecord("k4".getBytes, "v8".getBytes)) | ||
|
|
||
| log2.appendAsFollower(builder.build()) | ||
|
|
||
| val currentReplica = new Replica(brokerId, topicPartition, time, log = Some(log1)) | ||
| val futureReplica = new Replica(Request.FutureLocalReplicaId, topicPartition, time, log = Some(log2)) | ||
| val partition = Partition(topicPartition, time, replicaManager) | ||
|
|
||
| partition.addReplicaIfNotExists(futureReplica) | ||
| partition.addReplicaIfNotExists(currentReplica) | ||
| assertEquals(Some(currentReplica), partition.localReplica) | ||
| assertEquals(Some(futureReplica), partition.futureLocalReplica) | ||
|
|
||
| assertTrue(partition.maybeReplaceCurrentWithFutureReplica()) | ||
| } | ||
|
|
||
| @Test | ||
| def testFetchOffsetSnapshotEpochValidationForLeader(): Unit = { | ||
| val leaderEpoch = 5 | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
One thing I was discussing with @apovzner is whether we should consider renaming
logEndOffset. The bug probably would never have occurred if we had a better name. Maybe we should have two methods: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.
I like the suggestion of having
logEndOffsetMetadatamethod. Although, need to be careful not to miss any calls that would need to be renamed tologEndOffsetMetadata (and get to the same type of bug we found here). I guess one way to make sure this does not happen is to first change the name of logEndOffset to
logEndOffsetMetadata, make sure to compile, and only after that add
logEndOffset that returns Long.