Search in sources :

Example 1 with BrokerRegistration

use of org.apache.kafka.metadata.BrokerRegistration in project kafka by apache.

the class ReplicationControlManager method handleBrokerFenced.

/**
 * Generate the appropriate records to handle a broker being fenced.
 *
 * First, we remove this broker from any non-singleton ISR. Then we generate a
 * FenceBrokerRecord.
 *
 * @param brokerId      The broker id.
 * @param records       The record list to append to.
 */
void handleBrokerFenced(int brokerId, List<ApiMessageAndVersion> records) {
    BrokerRegistration brokerRegistration = clusterControl.brokerRegistrations().get(brokerId);
    if (brokerRegistration == null) {
        throw new RuntimeException("Can't find broker registration for broker " + brokerId);
    }
    generateLeaderAndIsrUpdates("handleBrokerFenced", brokerId, NO_LEADER, records, brokersToIsrs.partitionsWithBrokerInIsr(brokerId));
    records.add(new ApiMessageAndVersion(new FenceBrokerRecord().setId(brokerId).setEpoch(brokerRegistration.epoch()), FENCE_BROKER_RECORD.highestSupportedVersion()));
}
Also used : ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) FenceBrokerRecord(org.apache.kafka.common.metadata.FenceBrokerRecord) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration)

Example 2 with BrokerRegistration

use of org.apache.kafka.metadata.BrokerRegistration in project kafka by apache.

the class ClusterDelta method replay.

public void replay(FenceBrokerRecord record) {
    BrokerRegistration broker = getBrokerOrThrow(record.id(), record.epoch(), "fence");
    changedBrokers.put(record.id(), Optional.of(broker.cloneWithFencing(true)));
}
Also used : BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration)

Example 3 with BrokerRegistration

use of org.apache.kafka.metadata.BrokerRegistration in project kafka by apache.

the class ClusterDelta method replay.

public void replay(UnfenceBrokerRecord record) {
    BrokerRegistration broker = getBrokerOrThrow(record.id(), record.epoch(), "unfence");
    changedBrokers.put(record.id(), Optional.of(broker.cloneWithFencing(false)));
}
Also used : BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration)

Example 4 with BrokerRegistration

use of org.apache.kafka.metadata.BrokerRegistration 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 5 with BrokerRegistration

use of org.apache.kafka.metadata.BrokerRegistration in project kafka by apache.

the class ReplicationControlManager method unregisterBroker.

public ControllerResult<Void> unregisterBroker(int brokerId) {
    BrokerRegistration registration = clusterControl.brokerRegistrations().get(brokerId);
    if (registration == null) {
        throw new BrokerIdNotRegisteredException("Broker ID " + brokerId + " is not currently registered");
    }
    List<ApiMessageAndVersion> records = new ArrayList<>();
    handleBrokerUnregistered(brokerId, registration.epoch(), records);
    return ControllerResult.of(records, null);
}
Also used : BrokerIdNotRegisteredException(org.apache.kafka.common.errors.BrokerIdNotRegisteredException) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) ArrayList(java.util.ArrayList) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration)

Aggregations

BrokerRegistration (org.apache.kafka.metadata.BrokerRegistration)12 Endpoint (org.apache.kafka.common.Endpoint)6 BrokerEndpoint (org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)6 ArrayList (java.util.ArrayList)4 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)4 RegisterBrokerRecord (org.apache.kafka.common.metadata.RegisterBrokerRecord)2 BrokerFeature (org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerFeature)2 VersionRange (org.apache.kafka.metadata.VersionRange)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 BrokerIdNotRegisteredException (org.apache.kafka.common.errors.BrokerIdNotRegisteredException)1 DuplicateBrokerRegistrationException (org.apache.kafka.common.errors.DuplicateBrokerRegistrationException)1 InconsistentClusterIdException (org.apache.kafka.common.errors.InconsistentClusterIdException)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1 BrokerRegistrationRequestData (org.apache.kafka.common.message.BrokerRegistrationRequestData)1 FenceBrokerRecord (org.apache.kafka.common.metadata.FenceBrokerRecord)1 UnregisterBrokerRecord (org.apache.kafka.common.metadata.UnregisterBrokerRecord)1 LogContext (org.apache.kafka.common.utils.LogContext)1 MockTime (org.apache.kafka.common.utils.MockTime)1 BrokerRegistrationReply (org.apache.kafka.metadata.BrokerRegistrationReply)1