Search in sources :

Example 6 with BrokerRegistration

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

the class ClusterControlManager method replay.

public void replay(FenceBrokerRecord record) {
    int brokerId = record.id();
    BrokerRegistration registration = brokerRegistrations.get(brokerId);
    if (registration == null) {
        throw new RuntimeException(String.format("Unable to replay %s: no broker " + "registration found for that id", record.toString()));
    } else if (registration.epoch() != record.epoch()) {
        throw new RuntimeException(String.format("Unable to replay %s: no broker " + "registration with that epoch found", record.toString()));
    } else {
        brokerRegistrations.put(brokerId, registration.cloneWithFencing(true));
        updateMetrics(registration, brokerRegistrations.get(brokerId));
        log.info("Fenced broker: {}", record);
    }
}
Also used : BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)

Example 7 with BrokerRegistration

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

the class ClusterControlManager method replay.

public void replay(UnfenceBrokerRecord record) {
    int brokerId = record.id();
    BrokerRegistration registration = brokerRegistrations.get(brokerId);
    if (registration == null) {
        throw new RuntimeException(String.format("Unable to replay %s: no broker " + "registration found for that id", record.toString()));
    } else if (registration.epoch() != record.epoch()) {
        throw new RuntimeException(String.format("Unable to replay %s: no broker " + "registration with that epoch found", record.toString()));
    } else {
        brokerRegistrations.put(brokerId, registration.cloneWithFencing(false));
        updateMetrics(registration, brokerRegistrations.get(brokerId));
        log.info("Unfenced broker: {}", record);
    }
    if (readyBrokersFuture.isPresent()) {
        if (readyBrokersFuture.get().check()) {
            readyBrokersFuture.get().future.complete(null);
            readyBrokersFuture = Optional.empty();
        }
    }
}
Also used : BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)

Example 8 with BrokerRegistration

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

the class ClusterControlManager method replay.

public void replay(RegisterBrokerRecord record) {
    int brokerId = record.brokerId();
    List<Endpoint> listeners = new ArrayList<>();
    for (BrokerEndpoint endpoint : record.endPoints()) {
        listeners.add(new Endpoint(endpoint.name(), SecurityProtocol.forId(endpoint.securityProtocol()), endpoint.host(), endpoint.port()));
    }
    Map<String, VersionRange> features = new HashMap<>();
    for (BrokerFeature feature : record.features()) {
        features.put(feature.name(), new VersionRange(feature.minSupportedVersion(), feature.maxSupportedVersion()));
    }
    // Update broker registrations.
    BrokerRegistration prevRegistration = brokerRegistrations.put(brokerId, new BrokerRegistration(brokerId, record.brokerEpoch(), record.incarnationId(), listeners, features, Optional.ofNullable(record.rack()), record.fenced()));
    updateMetrics(prevRegistration, brokerRegistrations.get(brokerId));
    if (prevRegistration == null) {
        log.info("Registered new broker: {}", record);
    } else if (prevRegistration.incarnationId().equals(record.incarnationId())) {
        log.info("Re-registered broker incarnation: {}", record);
    } else {
        log.info("Re-registered broker id {}: {}", brokerId, record);
    }
}
Also used : BrokerFeature(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerFeature) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) TimelineHashMap(org.apache.kafka.timeline.TimelineHashMap) HashMap(java.util.HashMap) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) ArrayList(java.util.ArrayList) VersionRange(org.apache.kafka.metadata.VersionRange) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)

Example 9 with BrokerRegistration

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

the class ClusterControlManager method registerBroker.

/**
 * Process an incoming broker registration request.
 */
public ControllerResult<BrokerRegistrationReply> registerBroker(BrokerRegistrationRequestData request, long brokerEpoch, FeatureMapAndEpoch finalizedFeatures) {
    if (heartbeatManager == null) {
        throw new RuntimeException("ClusterControlManager is not active.");
    }
    if (!clusterId.equals(request.clusterId())) {
        throw new InconsistentClusterIdException("Expected cluster ID " + clusterId + ", but got cluster ID " + request.clusterId());
    }
    int brokerId = request.brokerId();
    BrokerRegistration existing = brokerRegistrations.get(brokerId);
    if (existing != null) {
        if (heartbeatManager.hasValidSession(brokerId)) {
            if (!existing.incarnationId().equals(request.incarnationId())) {
                throw new DuplicateBrokerRegistrationException("Another broker is " + "registered with that broker id.");
            }
        } else {
            if (!existing.incarnationId().equals(request.incarnationId())) {
                // Remove any existing session for the old broker incarnation.
                heartbeatManager.remove(brokerId);
                existing = null;
            }
        }
    }
    RegisterBrokerRecord record = new RegisterBrokerRecord().setBrokerId(brokerId).setIncarnationId(request.incarnationId()).setBrokerEpoch(brokerEpoch).setRack(request.rack());
    for (BrokerRegistrationRequestData.Listener listener : request.listeners()) {
        record.endPoints().add(new BrokerEndpoint().setHost(listener.host()).setName(listener.name()).setPort(listener.port()).setSecurityProtocol(listener.securityProtocol()));
    }
    for (BrokerRegistrationRequestData.Feature feature : request.features()) {
        Optional<VersionRange> finalized = finalizedFeatures.map().get(feature.name());
        if (finalized.isPresent()) {
            if (!finalized.get().contains(new VersionRange(feature.minSupportedVersion(), feature.maxSupportedVersion()))) {
                throw new UnsupportedVersionException("Unable to register because " + "the broker has an unsupported version of " + feature.name());
            }
        }
        record.features().add(new BrokerFeature().setName(feature.name()).setMinSupportedVersion(feature.minSupportedVersion()).setMaxSupportedVersion(feature.maxSupportedVersion()));
    }
    if (existing == null) {
        heartbeatManager.touch(brokerId, true, -1);
    } else {
        heartbeatManager.touch(brokerId, existing.fenced(), -1);
    }
    List<ApiMessageAndVersion> records = new ArrayList<>();
    records.add(new ApiMessageAndVersion(record, REGISTER_BROKER_RECORD.highestSupportedVersion()));
    return ControllerResult.atomicOf(records, new BrokerRegistrationReply(brokerEpoch));
}
Also used : BrokerFeature(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerFeature) BrokerRegistrationRequestData(org.apache.kafka.common.message.BrokerRegistrationRequestData) ArrayList(java.util.ArrayList) BrokerRegistrationReply(org.apache.kafka.metadata.BrokerRegistrationReply) VersionRange(org.apache.kafka.metadata.VersionRange) BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) InconsistentClusterIdException(org.apache.kafka.common.errors.InconsistentClusterIdException) DuplicateBrokerRegistrationException(org.apache.kafka.common.errors.DuplicateBrokerRegistrationException) RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException)

Example 10 with BrokerRegistration

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

the class ClusterControlManager method replay.

public void replay(UnregisterBrokerRecord record) {
    int brokerId = record.brokerId();
    BrokerRegistration registration = brokerRegistrations.get(brokerId);
    if (registration == null) {
        throw new RuntimeException(String.format("Unable to replay %s: no broker " + "registration found for that id", record.toString()));
    } else if (registration.epoch() != record.brokerEpoch()) {
        throw new RuntimeException(String.format("Unable to replay %s: no broker " + "registration with that epoch found", record.toString()));
    } else {
        brokerRegistrations.remove(brokerId);
        updateMetrics(registration, brokerRegistrations.get(brokerId));
        log.info("Unregistered broker: {}", record);
    }
}
Also used : BrokerRegistration(org.apache.kafka.metadata.BrokerRegistration) Endpoint(org.apache.kafka.common.Endpoint) BrokerEndpoint(org.apache.kafka.common.metadata.RegisterBrokerRecord.BrokerEndpoint)

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