cmccabe commented on code in PR #12195:
URL: https://github.com/apache/kafka/pull/12195#discussion_r887114909
##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1095,9 +1118,15 @@ void handleBrokerFenced(int brokerId,
List<ApiMessageAndVersion> records) {
}
generateLeaderAndIsrUpdates("handleBrokerFenced", brokerId, NO_LEADER,
records,
brokersToIsrs.partitionsWithBrokerInIsr(brokerId));
- records.add(new ApiMessageAndVersion(new FenceBrokerRecord().
- setId(brokerId).setEpoch(brokerRegistration.epoch()),
- FENCE_BROKER_RECORD.highestSupportedVersion()));
+ if
(featureControl.metadataVersion().brokerRegistrationChangeRecordSupported()) {
+ records.add(new ApiMessageAndVersion(new
BrokerRegistrationChangeRecord().
+
setBrokerId(brokerId).setBrokerEpoch(brokerRegistration.epoch()).setFenced((byte)
1),
Review Comment:
ok
##########
metadata/src/main/java/org/apache/kafka/controller/ClusterControlManager.java:
##########
@@ -391,41 +393,60 @@ public void replay(UnregisterBrokerRecord record) {
}
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 {
- if (heartbeatManager != null) heartbeatManager.register(brokerId,
true);
- brokerRegistrations.put(brokerId,
registration.cloneWithFencing(true));
- updateMetrics(registration, brokerRegistrations.get(brokerId));
- log.info("Fenced broker: {}", record);
- }
+ replayRegistrationChange(record, record.id(), record.epoch(),
Optional.of(true));
}
public void replay(UnfenceBrokerRecord record) {
- int brokerId = record.id();
- BrokerRegistration registration = brokerRegistrations.get(brokerId);
- if (registration == null) {
+ replayRegistrationChange(record, record.id(), record.epoch(),
Optional.of(false));
+ }
+
+ public void replay(BrokerRegistrationChangeRecord record) {
+ replayRegistrationChange(record, record.brokerId(),
record.brokerEpoch(), getFencingChange(record.fenced()));
+ }
+
+ private Optional<Boolean> getFencingChange(byte value) {
+ switch (value) {
+ case -1:
+ return Optional.of(false);
+ case 0:
+ return Optional.empty();
+ case 1:
+ return Optional.of(true);
+ default:
+ throw new RuntimeException(String.format("Invalid value for
fenced: %d", value));
+ }
+ }
+
+ private void replayRegistrationChange(
+ ApiMessage record,
+ int brokerId,
+ long brokerEpoch,
+ Optional<Boolean> fenced
+ ) {
+ BrokerRegistration curRegistration = brokerRegistrations.get(brokerId);
+ if (curRegistration == 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()) {
+ } else if (curRegistration.epoch() != brokerEpoch) {
throw new RuntimeException(String.format("Unable to replay %s: no
broker " +
"registration with that epoch found", record.toString()));
} else {
- if (heartbeatManager != null) heartbeatManager.register(brokerId,
false);
- 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();
+ BrokerRegistration nextRegistration = curRegistration;
+ if (fenced.isPresent()) {
+ nextRegistration =
nextRegistration.cloneWithFencing(fenced.get());
+ }
+ if (!curRegistration.equals(nextRegistration)) {
+ brokerRegistrations.put(brokerId, nextRegistration);
+ updateMetrics(curRegistration, nextRegistration);
+ } else {
+ log.info("Ignoring no-op registration change for {}",
curRegistration);
+ }
+ if (heartbeatManager != null) heartbeatManager.register(brokerId,
nextRegistration.fenced());
Review Comment:
yes
##########
metadata/src/main/java/org/apache/kafka/controller/ReplicationControlManager.java:
##########
@@ -1114,9 +1143,15 @@ 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()));
+ if
(featureControl.metadataVersion().brokerRegistrationChangeRecordSupported()) {
+ records.add(new ApiMessageAndVersion(new
BrokerRegistrationChangeRecord().
+
setBrokerId(brokerId).setBrokerEpoch(brokerEpoch).setFenced((byte) -1),
Review Comment:
ok
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]