use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class ReplicationControlManagerTest method assertConsistentAlterIsrResponse.
private void assertConsistentAlterIsrResponse(ReplicationControlManager replicationControl, TopicIdPartition topicIdPartition, AlterIsrResponseData.PartitionData partitionData) {
PartitionRegistration partitionControl = replicationControl.getPartition(topicIdPartition.topicId(), topicIdPartition.partitionId());
assertEquals(partitionControl.leader, partitionData.leaderId());
assertEquals(partitionControl.leaderEpoch, partitionData.leaderEpoch());
assertEquals(partitionControl.partitionEpoch, partitionData.currentIsrVersion());
List<Integer> expectedIsr = IntStream.of(partitionControl.isr).boxed().collect(Collectors.toList());
assertEquals(expectedIsr, partitionData.isr());
}
use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class PartitionReassignmentRevertTest method testNoneAddedOrRemoved.
@Test
public void testNoneAddedOrRemoved() {
PartitionRegistration registration = new PartitionRegistration(new int[] { 3, 2, 1 }, new int[] { 3, 2 }, Replicas.NONE, Replicas.NONE, 3, 100, 200);
PartitionReassignmentRevert revert = new PartitionReassignmentRevert(registration);
assertEquals(Arrays.asList(3, 2, 1), revert.replicas());
assertEquals(Arrays.asList(3, 2), revert.isr());
assertFalse(revert.unclean());
}
use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class QuorumControllerTest method testMissingInMemorySnapshot.
@Test
public void testMissingInMemorySnapshot() throws Exception {
int numBrokers = 3;
int numPartitions = 3;
String topicName = "topic-name";
try (LocalLogManagerTestEnv logEnv = new LocalLogManagerTestEnv(1, Optional.empty());
QuorumControllerTestEnv controlEnv = new QuorumControllerTestEnv(logEnv, b -> b.setConfigDefs(CONFIGS))) {
QuorumController controller = controlEnv.activeController();
Map<Integer, Long> brokerEpochs = registerBrokers(controller, numBrokers);
// Create a lot of partitions
List<CreatableReplicaAssignment> partitions = IntStream.range(0, numPartitions).mapToObj(partitionIndex -> new CreatableReplicaAssignment().setPartitionIndex(partitionIndex).setBrokerIds(Arrays.asList(0, 1, 2))).collect(Collectors.toList());
Uuid topicId = controller.createTopics(new CreateTopicsRequestData().setTopics(new CreatableTopicCollection(Collections.singleton(new CreatableTopic().setName(topicName).setNumPartitions(-1).setReplicationFactor((short) -1).setAssignments(new CreatableReplicaAssignmentCollection(partitions.iterator()))).iterator()))).get().topics().find(topicName).topicId();
// Create a lot of alter isr
List<AlterIsrRequestData.PartitionData> alterIsrs = IntStream.range(0, numPartitions).mapToObj(partitionIndex -> {
PartitionRegistration partitionRegistration = controller.replicationControl().getPartition(topicId, partitionIndex);
return new AlterIsrRequestData.PartitionData().setPartitionIndex(partitionIndex).setLeaderEpoch(partitionRegistration.leaderEpoch).setCurrentIsrVersion(partitionRegistration.partitionEpoch).setNewIsr(Arrays.asList(0, 1));
}).collect(Collectors.toList());
AlterIsrRequestData.TopicData topicData = new AlterIsrRequestData.TopicData().setName(topicName);
topicData.partitions().addAll(alterIsrs);
int leaderId = 0;
AlterIsrRequestData alterIsrRequest = new AlterIsrRequestData().setBrokerId(leaderId).setBrokerEpoch(brokerEpochs.get(leaderId));
alterIsrRequest.topics().add(topicData);
logEnv.logManagers().get(0).resignAfterNonAtomicCommit();
int oldClaimEpoch = controller.curClaimEpoch();
assertThrows(ExecutionException.class, () -> controller.alterIsr(alterIsrRequest).get());
// Wait for the controller to become active again
assertSame(controller, controlEnv.activeController());
assertTrue(oldClaimEpoch < controller.curClaimEpoch(), String.format("oldClaimEpoch = %s, newClaimEpoch = %s", oldClaimEpoch, controller.curClaimEpoch()));
// Since the alterIsr partially failed we expect to see
// some partitions to still have 2 in the ISR.
int partitionsWithReplica2 = Utils.toList(controller.replicationControl().brokersToIsrs().partitionsWithBrokerInIsr(2)).size();
int partitionsWithReplica0 = Utils.toList(controller.replicationControl().brokersToIsrs().partitionsWithBrokerInIsr(0)).size();
assertEquals(numPartitions, partitionsWithReplica0);
assertNotEquals(0, partitionsWithReplica2);
assertTrue(partitionsWithReplica0 > partitionsWithReplica2, String.format("partitionsWithReplica0 = %s, partitionsWithReplica2 = %s", partitionsWithReplica0, partitionsWithReplica2));
}
}
use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class ReplicationControlManagerTest method testCreatePartitionsFailsWithManualAssignmentWithAllFenced.
@Test
public void testCreatePartitionsFailsWithManualAssignmentWithAllFenced() throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext();
ctx.registerBrokers(0, 1, 2, 3, 4, 5);
ctx.unfenceBrokers(0, 1, 2);
Uuid fooId = ctx.createTestTopic("foo", new int[][] { new int[] { 0, 1, 2 } }).topicId();
ctx.createPartitions(2, "foo", new int[][] { new int[] { 3, 4, 5 } }, INVALID_REPLICA_ASSIGNMENT.code());
ctx.createPartitions(2, "foo", new int[][] { new int[] { 2, 4, 5 } }, NONE.code());
assertEquals(new PartitionRegistration(new int[] { 2, 4, 5 }, new int[] { 2 }, Replicas.NONE, Replicas.NONE, 2, 0, 0), ctx.replicationControl.getPartition(fooId, 1));
}
use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class ReplicationControlManagerTest method testFenceMultipleBrokers.
@Test
public void testFenceMultipleBrokers() throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext();
ReplicationControlManager replication = ctx.replicationControl;
ctx.registerBrokers(0, 1, 2, 3, 4);
ctx.unfenceBrokers(0, 1, 2, 3, 4);
Uuid fooId = ctx.createTestTopic("foo", new int[][] { new int[] { 1, 2, 3 }, new int[] { 2, 3, 4 }, new int[] { 0, 2, 1 } }).topicId();
assertTrue(ctx.clusterControl.fencedBrokerIds().isEmpty());
ctx.fenceBrokers(Utils.mkSet(2, 3));
PartitionRegistration partition0 = replication.getPartition(fooId, 0);
PartitionRegistration partition1 = replication.getPartition(fooId, 1);
PartitionRegistration partition2 = replication.getPartition(fooId, 2);
assertArrayEquals(new int[] { 1, 2, 3 }, partition0.replicas);
assertArrayEquals(new int[] { 1 }, partition0.isr);
assertEquals(1, partition0.leader);
assertArrayEquals(new int[] { 2, 3, 4 }, partition1.replicas);
assertArrayEquals(new int[] { 4 }, partition1.isr);
assertEquals(4, partition1.leader);
assertArrayEquals(new int[] { 0, 2, 1 }, partition2.replicas);
assertArrayEquals(new int[] { 0, 1 }, partition2.isr);
assertNotEquals(2, partition2.leader);
}
Aggregations