use of org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition in project kafka by apache.
the class ReplicationControlManager method alterPartitionReassignment.
void alterPartitionReassignment(String topicName, ReassignablePartition target, List<ApiMessageAndVersion> records) {
Uuid topicId = topicsByName.get(topicName);
if (topicId == null) {
throw new UnknownTopicOrPartitionException("Unable to find a topic " + "named " + topicName + ".");
}
TopicControlInfo topicInfo = topics.get(topicId);
if (topicInfo == null) {
throw new UnknownTopicOrPartitionException("Unable to find a topic " + "with ID " + topicId + ".");
}
TopicIdPartition tp = new TopicIdPartition(topicId, target.partitionIndex());
PartitionRegistration part = topicInfo.parts.get(target.partitionIndex());
if (part == null) {
throw new UnknownTopicOrPartitionException("Unable to find partition " + topicName + ":" + target.partitionIndex() + ".");
}
Optional<ApiMessageAndVersion> record;
if (target.replicas() == null) {
record = cancelPartitionReassignment(topicName, tp, part);
} else {
record = changePartitionReassignment(tp, part, target);
}
record.ifPresent(records::add);
}
use of org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition in project kafka by apache.
the class BrokersToIsrsTest method testIterator.
@Test
public void testIterator() {
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
BrokersToIsrs brokersToIsrs = new BrokersToIsrs(snapshotRegistry);
assertEquals(toSet(), toSet(brokersToIsrs.iterator(1, false)));
brokersToIsrs.update(UUIDS[0], 0, null, new int[] { 1, 2, 3 }, -1, 1);
brokersToIsrs.update(UUIDS[1], 1, null, new int[] { 2, 3, 4 }, -1, 4);
assertEquals(toSet(new TopicIdPartition(UUIDS[0], 0)), toSet(brokersToIsrs.iterator(1, false)));
assertEquals(toSet(new TopicIdPartition(UUIDS[0], 0), new TopicIdPartition(UUIDS[1], 1)), toSet(brokersToIsrs.iterator(2, false)));
assertEquals(toSet(new TopicIdPartition(UUIDS[1], 1)), toSet(brokersToIsrs.iterator(4, false)));
assertEquals(toSet(), toSet(brokersToIsrs.iterator(5, false)));
brokersToIsrs.update(UUIDS[1], 2, null, new int[] { 3, 2, 1 }, -1, 3);
assertEquals(toSet(new TopicIdPartition(UUIDS[0], 0), new TopicIdPartition(UUIDS[1], 1), new TopicIdPartition(UUIDS[1], 2)), toSet(brokersToIsrs.iterator(2, false)));
}
use of org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition in project kafka by apache.
the class BrokersToIsrsTest method testNoLeader.
@Test
public void testNoLeader() {
SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
BrokersToIsrs brokersToIsrs = new BrokersToIsrs(snapshotRegistry);
brokersToIsrs.update(UUIDS[0], 2, null, new int[] { 1, 2, 3 }, -1, 3);
assertEquals(toSet(new TopicIdPartition(UUIDS[0], 2)), toSet(brokersToIsrs.iterator(3, true)));
assertEquals(toSet(), toSet(brokersToIsrs.iterator(2, true)));
assertEquals(toSet(), toSet(brokersToIsrs.partitionsWithNoLeader()));
brokersToIsrs.update(UUIDS[0], 2, new int[] { 1, 2, 3 }, new int[] { 1, 2, 3 }, 3, -1);
assertEquals(toSet(new TopicIdPartition(UUIDS[0], 2)), toSet(brokersToIsrs.partitionsWithNoLeader()));
}
use of org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition in project kafka by apache.
the class QuorumControllerTest method testUnregisterBroker.
@Test
public void testUnregisterBroker() throws Throwable {
try (LocalLogManagerTestEnv logEnv = new LocalLogManagerTestEnv(1, Optional.empty())) {
try (QuorumControllerTestEnv controlEnv = new QuorumControllerTestEnv(logEnv, b -> b.setConfigDefs(CONFIGS))) {
ListenerCollection listeners = new ListenerCollection();
listeners.add(new Listener().setName("PLAINTEXT").setHost("localhost").setPort(9092));
QuorumController active = controlEnv.activeController();
CompletableFuture<BrokerRegistrationReply> reply = active.registerBroker(new BrokerRegistrationRequestData().setBrokerId(0).setClusterId(active.clusterId()).setIncarnationId(Uuid.fromString("kxAT73dKQsitIedpiPtwBA")).setListeners(listeners));
assertEquals(0L, reply.get().epoch());
CreateTopicsRequestData createTopicsRequestData = new CreateTopicsRequestData().setTopics(new CreatableTopicCollection(Collections.singleton(new CreatableTopic().setName("foo").setNumPartitions(1).setReplicationFactor((short) 1)).iterator()));
assertEquals(Errors.INVALID_REPLICATION_FACTOR.code(), active.createTopics(createTopicsRequestData).get().topics().find("foo").errorCode());
assertEquals("Unable to replicate the partition 1 time(s): All brokers " + "are currently fenced.", active.createTopics(createTopicsRequestData).get().topics().find("foo").errorMessage());
assertEquals(new BrokerHeartbeatReply(true, false, false, false), active.processBrokerHeartbeat(new BrokerHeartbeatRequestData().setWantFence(false).setBrokerEpoch(0L).setBrokerId(0).setCurrentMetadataOffset(100000L)).get());
assertEquals(Errors.NONE.code(), active.createTopics(createTopicsRequestData).get().topics().find("foo").errorCode());
CompletableFuture<TopicIdPartition> topicPartitionFuture = active.appendReadEvent("debugGetPartition", () -> {
Iterator<TopicIdPartition> iterator = active.replicationControl().brokersToIsrs().iterator(0, true);
assertTrue(iterator.hasNext());
return iterator.next();
});
assertEquals(0, topicPartitionFuture.get().partitionId());
active.unregisterBroker(0).get();
topicPartitionFuture = active.appendReadEvent("debugGetPartition", () -> {
Iterator<TopicIdPartition> iterator = active.replicationControl().brokersToIsrs().partitionsWithNoLeader();
assertTrue(iterator.hasNext());
return iterator.next();
});
assertEquals(0, topicPartitionFuture.get().partitionId());
}
}
}
use of org.apache.kafka.controller.BrokersToIsrs.TopicIdPartition in project kafka by apache.
the class ReplicationControlManagerTest method testRemoveLeaderships.
@Test
public void testRemoveLeaderships() throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext();
ReplicationControlManager replicationControl = ctx.replicationControl;
ctx.registerBrokers(0, 1, 2, 3);
ctx.unfenceBrokers(0, 1, 2, 3);
CreatableTopicResult result = ctx.createTestTopic("foo", new int[][] { new int[] { 0, 1, 2 }, new int[] { 1, 2, 3 }, new int[] { 2, 3, 0 }, new int[] { 0, 2, 1 } });
Set<TopicIdPartition> expectedPartitions = new HashSet<>();
expectedPartitions.add(new TopicIdPartition(result.topicId(), 0));
expectedPartitions.add(new TopicIdPartition(result.topicId(), 3));
assertEquals(expectedPartitions, RecordTestUtils.iteratorToSet(replicationControl.brokersToIsrs().iterator(0, true)));
List<ApiMessageAndVersion> records = new ArrayList<>();
replicationControl.handleBrokerFenced(0, records);
ctx.replay(records);
assertEquals(Collections.emptySet(), RecordTestUtils.iteratorToSet(replicationControl.brokersToIsrs().iterator(0, true)));
}
Aggregations