Search in sources :

Example 1 with FenceBrokerRecord

use of org.apache.kafka.common.metadata.FenceBrokerRecord 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 FenceBrokerRecord

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

the class MetadataNodeManagerTest method testUnfenceBrokerRecordAndFenceBrokerRecord.

@Test
public void testUnfenceBrokerRecordAndFenceBrokerRecord() {
    RegisterBrokerRecord record = new RegisterBrokerRecord().setBrokerId(1).setBrokerEpoch(2);
    metadataNodeManager.handleMessage(record);
    assertEquals("true", metadataNodeManager.getData().root().directory("brokers", "1").file("isFenced").contents());
    UnfenceBrokerRecord unfenceBrokerRecord = new UnfenceBrokerRecord().setId(1).setEpoch(2);
    metadataNodeManager.handleMessage(unfenceBrokerRecord);
    assertEquals("false", metadataNodeManager.getData().root().directory("brokers", "1").file("isFenced").contents());
    FenceBrokerRecord fenceBrokerRecord = new FenceBrokerRecord().setId(1).setEpoch(2);
    metadataNodeManager.handleMessage(fenceBrokerRecord);
    assertEquals("true", metadataNodeManager.getData().root().directory("brokers", "1").file("isFenced").contents());
}
Also used : RegisterBrokerRecord(org.apache.kafka.common.metadata.RegisterBrokerRecord) FenceBrokerRecord(org.apache.kafka.common.metadata.FenceBrokerRecord) UnfenceBrokerRecord(org.apache.kafka.common.metadata.UnfenceBrokerRecord) Test(org.junit.jupiter.api.Test)

Aggregations

FenceBrokerRecord (org.apache.kafka.common.metadata.FenceBrokerRecord)2 RegisterBrokerRecord (org.apache.kafka.common.metadata.RegisterBrokerRecord)1 UnfenceBrokerRecord (org.apache.kafka.common.metadata.UnfenceBrokerRecord)1 BrokerRegistration (org.apache.kafka.metadata.BrokerRegistration)1 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)1 Test (org.junit.jupiter.api.Test)1