Search in sources :

Example 1 with UnregisterBrokerRecord

use of org.apache.kafka.common.metadata.UnregisterBrokerRecord in project kafka by apache.

the class MetadataNodeManagerTest method testRegisterBrokerRecordAndUnregisterBrokerRecord.

@Test
public void testRegisterBrokerRecordAndUnregisterBrokerRecord() {
    // Register broker
    RegisterBrokerRecord record = new RegisterBrokerRecord().setBrokerId(1).setBrokerEpoch(2);
    metadataNodeManager.handleMessage(record);
    assertEquals(record.toString(), metadataNodeManager.getData().root().directory("brokers", "1").file("registration").contents());
    assertEquals("true", metadataNodeManager.getData().root().directory("brokers", "1").file("isFenced").contents());
    // Unregister broker
    UnregisterBrokerRecord unregisterBrokerRecord = new UnregisterBrokerRecord().setBrokerId(1);
    metadataNodeManager.handleMessage(unregisterBrokerRecord);
    assertFalse(metadataNodeManager.getData().root().directory("brokers").children().containsKey("1"));
}
Also used : RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) UnregisterBrokerRecord(org.apache.kafka.common.metadata.UnregisterBrokerRecord) Test(org.junit.jupiter.api.Test)

Example 2 with UnregisterBrokerRecord

use of org.apache.kafka.common.metadata.UnregisterBrokerRecord in project kafka by apache.

the class ClusterControlManagerTest method testUnregister.

@Test
public void testUnregister() throws Exception {
    RegisterBrokerRecord brokerRecord = new RegisterBrokerRecord().setBrokerId(1).setBrokerEpoch(100).setIncarnationId(Uuid.fromString("fPZv1VBsRFmnlRvmGcOW9w")).setRack("arack");
    brokerRecord.endPoints().add(new BrokerEndpoint().setSecurityProtocol(SecurityProtocol.PLAINTEXT.id).setPort((short) 9092).setName("PLAINTEXT").setHost("example.com"));
    SnapshotRegistry snapshotRegistry = new SnapshotRegistry(new LogContext());
    ClusterControlManager clusterControl = new ClusterControlManager(new LogContext(), Uuid.randomUuid().toString(), new MockTime(0, 0, 0), snapshotRegistry, 1000, new StripedReplicaPlacer(new Random()), new MockControllerMetrics());
    clusterControl.activate();
    clusterControl.replay(brokerRecord);
    assertEquals(new BrokerRegistration(1, 100, Uuid.fromString("fPZv1VBsRFmnlRvmGcOW9w"), Collections.singletonMap("PLAINTEXT", new Endpoint("PLAINTEXT", SecurityProtocol.PLAINTEXT, "example.com", 9092)), Collections.emptyMap(), Optional.of("arack"), true), clusterControl.brokerRegistrations().get(1));
    UnregisterBrokerRecord unregisterRecord = new UnregisterBrokerRecord().setBrokerId(1).setBrokerEpoch(100);
    clusterControl.replay(unregisterRecord);
    assertFalse(clusterControl.brokerRegistrations().containsKey(1));
}
Also used : SnapshotRegistry(org.apache.kafka.timeline.SnapshotRegistry) Random(java.util.Random) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) UnregisterBrokerRecord(org.apache.kafka.common.metadata.UnregisterBrokerRecord) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) LogContext(org.apache.kafka.common.utils.LogContext) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) MockTime(org.apache.kafka.common.utils.MockTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with UnregisterBrokerRecord

use of org.apache.kafka.common.metadata.UnregisterBrokerRecord in project kafka by apache.

the class ReplicationControlManager method handleBrokerUnregistered.

/**
 * Generate the appropriate records to handle a broker being unregistered.
 *
 * First, we remove this broker from any non-singleton ISR. Then we generate an
 * UnregisterBrokerRecord.
 *
 * @param brokerId      The broker id.
 * @param brokerEpoch   The broker epoch.
 * @param records       The record list to append to.
 */
void handleBrokerUnregistered(int brokerId, long brokerEpoch, List<ApiMessageAndVersion> records) {
    generateLeaderAndIsrUpdates("handleBrokerUnregistered", brokerId, NO_LEADER, records, brokersToIsrs.partitionsWithBrokerInIsr(brokerId));
    records.add(new ApiMessageAndVersion(new UnregisterBrokerRecord().setBrokerId(brokerId).setBrokerEpoch(brokerEpoch), UNREGISTER_BROKER_RECORD.highestSupportedVersion()));
}
Also used : UnregisterBrokerRecord(org.apache.kafka.common.metadata.UnregisterBrokerRecord) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion)

Aggregations

UnregisterBrokerRecord (org.apache.kafka.common.metadata.UnregisterBrokerRecord)3 RegisterBrokerRecord (org.apache.kafka.common.metadata.RegisterBrokerRecord)2 Test (org.junit.jupiter.api.Test)2 Random (java.util.Random)1 Endpoint (org.apache.kafka.common.Endpoint)1 BrokerEndpoint (org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)1 LogContext (org.apache.kafka.common.utils.LogContext)1 MockTime (org.apache.kafka.common.utils.MockTime)1 BrokerRegistration (org.apache.kafka.metadata.BrokerRegistration)1 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)1 SnapshotRegistry (org.apache.kafka.timeline.SnapshotRegistry)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1