-
Notifications
You must be signed in to change notification settings - Fork 15.4k
KAFKA-10301: Do not clear Partition#remoteReplicasMap during partition assignment updates #9065
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 5 commits
5611fd8
664b7cd
f6d9340
12016f1
21fb575
c13e738
0f813d6
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 |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ import org.mockito.ArgumentMatchers | |
| import org.mockito.Mockito.{mock, when} | ||
|
|
||
| import scala.jdk.CollectionConverters._ | ||
| import scala.concurrent.duration._ | ||
|
|
||
| /** | ||
| * Verifies that slow appends to log don't block request threads processing replica fetch requests. | ||
|
|
@@ -116,6 +117,56 @@ class PartitionLockTest extends Logging { | |
| future.get(15, TimeUnit.SECONDS) | ||
| } | ||
|
|
||
| /** | ||
| * Concurrently calling updateAssignmentAndIsr should always ensure that non-lock access | ||
| * to the inner remoteReplicaMap (accessed by getReplica) cannot see an intermediate state | ||
| * where replicas present both in the old and new assignment are missing | ||
| */ | ||
| @Test | ||
| def testGetReplicaWithUpdateAssignmentAndIsr(): Unit = { | ||
|
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. This fails incredibly quickly 100/100 times without the Partition.scala changes. |
||
| val active = new AtomicBoolean(true) | ||
| val replicaToCheck = 3 | ||
| val firstReplicaSet = Seq[Integer](3, 4, 5).asJava | ||
| val secondReplicaSet = Seq[Integer](1, 2, 3).asJava | ||
| def partitionState(replicas: java.util.List[Integer]): LeaderAndIsrPartitionState = new LeaderAndIsrPartitionState() | ||
|
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. No need to repeat |
||
| .setControllerEpoch(1) | ||
| .setLeader(replicas.get(0)) | ||
| .setLeaderEpoch(1) | ||
| .setIsr(replicas) | ||
| .setZkVersion(1) | ||
| .setReplicas(replicas) | ||
| .setIsNew(true) | ||
| val offsetCheckpoints: OffsetCheckpoints = mock(classOf[OffsetCheckpoints]) | ||
| // Update replica set synchronously first to avoid race conditions | ||
| partition.makeLeader(partitionState(secondReplicaSet), offsetCheckpoints) | ||
| assertTrue(s"Expected replica $replicaToCheck to be defined", partition.getReplica(replicaToCheck).isDefined) | ||
|
|
||
| var i = 0 | ||
|
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. Shouldn't this be inside the thread state?
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. Yeah, nice catch |
||
| val future = executorService.submit((() => { | ||
| // Flip assignment between two replica sets | ||
| while (active.get) { | ||
| val replicas = if (i % 2 == 0) { | ||
| firstReplicaSet | ||
| } else { | ||
| secondReplicaSet | ||
| } | ||
|
|
||
| partition.makeLeader(partitionState(replicas), offsetCheckpoints) | ||
|
|
||
| i += 1 | ||
| Thread.sleep(1) // just to avoid tight loop | ||
| } | ||
| }): Runnable) | ||
|
|
||
| val deadline = 5.seconds.fromNow | ||
|
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. 5 seconds is quite a bit. Can it be lower?
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 think so. I opted for 5s as I saw the other tests had up to 15s of waits for futures. Let me see if 1s can go
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. Lowered to 1s |
||
| while(deadline.hasTimeLeft()) { | ||
|
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. Nit: space missing after |
||
| assertTrue(s"Expected replica $replicaToCheck to be defined", partition.getReplica(replicaToCheck).isDefined) | ||
| } | ||
| active.set(false) | ||
| future.get(5, TimeUnit.SECONDS) | ||
| assertTrue(s"Expected replica $replicaToCheck to be defined", partition.getReplica(replicaToCheck).isDefined) | ||
| } | ||
|
|
||
| /** | ||
| * Perform concurrent appends and replica fetch requests that don't require write lock to | ||
| * update follower state. Release sufficient append permits to complete all except one append. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package unit.kafka.utils | ||
|
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. Remove |
||
|
|
||
| import kafka.utils.Pool | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Test | ||
|
|
||
|
|
||
| class PoolTest { | ||
| @Test | ||
| def testRemoveAll(): Unit = { | ||
| val pool = new Pool[Int, String] | ||
| pool.put(1, "1") | ||
| pool.put(2, "2") | ||
| pool.put(3, "3") | ||
|
|
||
| assertEquals(3, pool.size) | ||
|
|
||
| pool.removeAll(Seq(1, 2)) | ||
| assertEquals(1, pool.size) | ||
| assertEquals("3", pool.get(3)) | ||
| pool.removeAll(Seq(3)) | ||
| assertEquals(0, pool.size) | ||
| } | ||
| } | ||
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.
Nit:
()is not needed.