Search in sources :

Example 6 with BrokerHeartbeatRequestData

use of org.apache.kafka.common.message.BrokerHeartbeatRequestData in project kafka by apache.

the class QuorumControllerTest method testSnapshotOnlyAfterConfiguredMinBytes.

@Test
public void testSnapshotOnlyAfterConfiguredMinBytes() throws Throwable {
    final int numBrokers = 4;
    final int maxNewRecordBytes = 1000;
    Map<Integer, Long> brokerEpochs = new HashMap<>();
    try (LocalLogManagerTestEnv logEnv = new LocalLogManagerTestEnv(3, Optional.empty())) {
        try (QuorumControllerTestEnv controlEnv = new QuorumControllerTestEnv(logEnv, builder -> builder.setConfigDefs(CONFIGS).setSnapshotMaxNewRecordBytes(maxNewRecordBytes))) {
            QuorumController active = controlEnv.activeController();
            for (int i = 0; i < numBrokers; i++) {
                BrokerRegistrationReply reply = active.registerBroker(new BrokerRegistrationRequestData().setBrokerId(i).setRack(null).setClusterId(active.clusterId()).setIncarnationId(Uuid.fromString("kxAT73dKQsitIedpiPtwB" + i)).setListeners(new ListenerCollection(Arrays.asList(new Listener().setName("PLAINTEXT").setHost("localhost").setPort(9092 + i)).iterator()))).get();
                brokerEpochs.put(i, reply.epoch());
                assertEquals(new BrokerHeartbeatReply(true, false, false, false), active.processBrokerHeartbeat(new BrokerHeartbeatRequestData().setWantFence(false).setBrokerEpoch(brokerEpochs.get(i)).setBrokerId(i).setCurrentMetadataOffset(100000L)).get());
            }
            assertTrue(logEnv.appendedBytes() < maxNewRecordBytes, String.format("%s appended bytes is not less than %s max new record bytes", logEnv.appendedBytes(), maxNewRecordBytes));
            // Keep creating topic until we reached the max bytes limit
            int counter = 0;
            while (logEnv.appendedBytes() < maxNewRecordBytes) {
                counter += 1;
                String topicName = String.format("foo-%s", counter);
                active.createTopics(new CreateTopicsRequestData().setTopics(new CreatableTopicCollection(Collections.singleton(new CreatableTopic().setName(topicName).setNumPartitions(-1).setReplicationFactor((short) -1).setAssignments(new CreatableReplicaAssignmentCollection(Arrays.asList(new CreatableReplicaAssignment().setPartitionIndex(0).setBrokerIds(Arrays.asList(0, 1, 2)), new CreatableReplicaAssignment().setPartitionIndex(1).setBrokerIds(Arrays.asList(1, 2, 0))).iterator()))).iterator()))).get();
            }
            logEnv.waitForLatestSnapshot();
        }
    }
}
Also used : BrokerHeartbeatReply(org.apache.kafka.metadata.BrokerHeartbeatReply) ListenerCollection(org.apache.kafka.common.message.BrokerRegistrationRequestData.ListenerCollection) LocalLogManagerTestEnv(org.apache.kafka.metalog.LocalLogManagerTestEnv) Listener(org.apache.kafka.common.message.BrokerRegistrationRequestData.Listener) HashMap(java.util.HashMap) BrokerRegistrationRequestData(org.apache.kafka.common.message.BrokerRegistrationRequestData) BrokerRegistrationReply(org.apache.kafka.metadata.BrokerRegistrationReply) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) CreatableTopicCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopicCollection) BrokerHeartbeatRequestData(org.apache.kafka.common.message.BrokerHeartbeatRequestData) CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) CreatableReplicaAssignment(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableReplicaAssignment) CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) CreatableReplicaAssignmentCollection(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableReplicaAssignmentCollection) Test(org.junit.jupiter.api.Test)

Example 7 with BrokerHeartbeatRequestData

use of org.apache.kafka.common.message.BrokerHeartbeatRequestData in project kafka by apache.

the class BrokerHeartbeatManagerTest method testCalculateNextBrokerState.

@Test
public void testCalculateNextBrokerState() {
    BrokerHeartbeatManager manager = newBrokerHeartbeatManager();
    manager.touch(0, true, 100);
    manager.touch(1, false, 98);
    manager.touch(2, false, 100);
    manager.touch(3, false, 100);
    manager.touch(4, true, 100);
    manager.touch(5, false, 99);
    manager.updateControlledShutdownOffset(5, 99);
    assertEquals(98L, manager.lowestActiveOffset());
    assertEquals(new BrokerControlStates(FENCED, SHUTDOWN_NOW), manager.calculateNextBrokerState(0, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> false));
    assertEquals(new BrokerControlStates(FENCED, UNFENCED), manager.calculateNextBrokerState(0, new BrokerHeartbeatRequestData().setWantFence(false).setCurrentMetadataOffset(100), 100, () -> false));
    assertEquals(new BrokerControlStates(FENCED, FENCED), manager.calculateNextBrokerState(0, new BrokerHeartbeatRequestData().setWantFence(false).setCurrentMetadataOffset(50), 100, () -> false));
    assertEquals(new BrokerControlStates(FENCED, FENCED), manager.calculateNextBrokerState(0, new BrokerHeartbeatRequestData().setWantFence(true), 100, () -> false));
    assertEquals(new BrokerControlStates(UNFENCED, CONTROLLED_SHUTDOWN), manager.calculateNextBrokerState(1, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> true));
    assertEquals(new BrokerControlStates(UNFENCED, SHUTDOWN_NOW), manager.calculateNextBrokerState(1, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> false));
    assertEquals(new BrokerControlStates(UNFENCED, UNFENCED), manager.calculateNextBrokerState(1, new BrokerHeartbeatRequestData().setWantFence(false), 100, () -> false));
    assertEquals(new BrokerControlStates(CONTROLLED_SHUTDOWN, CONTROLLED_SHUTDOWN), manager.calculateNextBrokerState(5, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> true));
    assertEquals(new BrokerControlStates(CONTROLLED_SHUTDOWN, CONTROLLED_SHUTDOWN), manager.calculateNextBrokerState(5, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> false));
    manager.fence(1);
    assertEquals(new BrokerControlStates(CONTROLLED_SHUTDOWN, SHUTDOWN_NOW), manager.calculateNextBrokerState(5, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> false));
    assertEquals(new BrokerControlStates(CONTROLLED_SHUTDOWN, CONTROLLED_SHUTDOWN), manager.calculateNextBrokerState(5, new BrokerHeartbeatRequestData().setWantShutDown(true), 100, () -> true));
}
Also used : BrokerHeartbeatRequestData(org.apache.kafka.common.message.BrokerHeartbeatRequestData) Test(org.junit.jupiter.api.Test)

Aggregations

BrokerHeartbeatRequestData (org.apache.kafka.common.message.BrokerHeartbeatRequestData)7 BrokerRegistrationRequestData (org.apache.kafka.common.message.BrokerRegistrationRequestData)5 Listener (org.apache.kafka.common.message.BrokerRegistrationRequestData.Listener)5 ListenerCollection (org.apache.kafka.common.message.BrokerRegistrationRequestData.ListenerCollection)5 BrokerHeartbeatReply (org.apache.kafka.metadata.BrokerHeartbeatReply)5 BrokerRegistrationReply (org.apache.kafka.metadata.BrokerRegistrationReply)5 Test (org.junit.jupiter.api.Test)5 HashMap (java.util.HashMap)4 CreateTopicsRequestData (org.apache.kafka.common.message.CreateTopicsRequestData)4 CreatableTopic (org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic)4 CreatableTopicCollection (org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopicCollection)4 BrokerEndpoint (org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)4 LocalLogManagerTestEnv (org.apache.kafka.metalog.LocalLogManagerTestEnv)4 CreatableReplicaAssignment (org.apache.kafka.common.message.CreateTopicsRequestData.CreatableReplicaAssignment)3 CreatableReplicaAssignmentCollection (org.apache.kafka.common.message.CreateTopicsRequestData.CreatableReplicaAssignmentCollection)3 Uuid (org.apache.kafka.common.Uuid)2 AllocateProducerIdsRequestData (org.apache.kafka.common.message.AllocateProducerIdsRequestData)2 CreateTopicsResponseData (org.apache.kafka.common.message.CreateTopicsResponseData)2 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)2 Iterator (java.util.Iterator)1