@@ -90,7 +90,7 @@ static class Builder {
90
90
private long sessionTimeoutNs = DEFAULT_SESSION_TIMEOUT_NS ;
91
91
private ReplicaPlacer replicaPlacer = null ;
92
92
private FeatureControlManager featureControl = null ;
93
- private BrokerUncleanShutdownHandler brokerUncleanShutdownHandler = null ;
93
+ private BrokerShutdownHandler brokerShutdownHandler = null ;
94
94
private String interBrokerListenerName = "PLAINTEXT" ;
95
95
96
96
Builder setLogContext (LogContext logContext ) {
@@ -128,8 +128,8 @@ Builder setFeatureControlManager(FeatureControlManager featureControl) {
128
128
return this ;
129
129
}
130
130
131
- Builder setBrokerUncleanShutdownHandler ( BrokerUncleanShutdownHandler brokerUncleanShutdownHandler ) {
132
- this .brokerUncleanShutdownHandler = brokerUncleanShutdownHandler ;
131
+ Builder setBrokerShutdownHandler ( BrokerShutdownHandler brokerShutdownHandler ) {
132
+ this .brokerShutdownHandler = brokerShutdownHandler ;
133
133
return this ;
134
134
}
135
135
@@ -154,8 +154,8 @@ ClusterControlManager build() {
154
154
if (featureControl == null ) {
155
155
throw new RuntimeException ("You must specify FeatureControlManager" );
156
156
}
157
- if (brokerUncleanShutdownHandler == null ) {
158
- throw new RuntimeException ("You must specify BrokerUncleanShutdownHandler " );
157
+ if (brokerShutdownHandler == null ) {
158
+ throw new RuntimeException ("You must specify BrokerShutdownHandler " );
159
159
}
160
160
return new ClusterControlManager (logContext ,
161
161
clusterId ,
@@ -164,7 +164,7 @@ ClusterControlManager build() {
164
164
sessionTimeoutNs ,
165
165
replicaPlacer ,
166
166
featureControl ,
167
- brokerUncleanShutdownHandler ,
167
+ brokerShutdownHandler ,
168
168
interBrokerListenerName
169
169
);
170
170
}
@@ -252,7 +252,7 @@ boolean check() {
252
252
*/
253
253
private final FeatureControlManager featureControl ;
254
254
255
- private final BrokerUncleanShutdownHandler brokerUncleanShutdownHandler ;
255
+ private final BrokerShutdownHandler brokerShutdownHandler ;
256
256
257
257
/**
258
258
* The statically configured inter-broker listener name.
@@ -277,7 +277,7 @@ private ClusterControlManager(
277
277
long sessionTimeoutNs ,
278
278
ReplicaPlacer replicaPlacer ,
279
279
FeatureControlManager featureControl ,
280
- BrokerUncleanShutdownHandler brokerUncleanShutdownHandler ,
280
+ BrokerShutdownHandler brokerShutdownHandler ,
281
281
String interBrokerListenerName
282
282
) {
283
283
this .logContext = logContext ;
@@ -293,7 +293,7 @@ private ClusterControlManager(
293
293
this .featureControl = featureControl ;
294
294
this .controllerRegistrations = new TimelineHashMap <>(snapshotRegistry , 0 );
295
295
this .directoryToBroker = new TimelineHashMap <>(snapshotRegistry , 0 );
296
- this .brokerUncleanShutdownHandler = brokerUncleanShutdownHandler ;
296
+ this .brokerShutdownHandler = brokerShutdownHandler ;
297
297
this .interBrokerListenerName = interBrokerListenerName ;
298
298
}
299
299
@@ -335,7 +335,8 @@ Map<Integer, BrokerRegistration> brokerRegistrations() {
335
335
public ControllerResult <BrokerRegistrationReply > registerBroker (
336
336
BrokerRegistrationRequestData request ,
337
337
long newBrokerEpoch ,
338
- FinalizedControllerFeatures finalizedFeatures
338
+ FinalizedControllerFeatures finalizedFeatures ,
339
+ boolean cleanShutdownDetectionEnabled
339
340
) {
340
341
if (heartbeatManager == null ) {
341
342
throw new RuntimeException ("ClusterControlManager is not active." );
@@ -348,8 +349,10 @@ public ControllerResult<BrokerRegistrationReply> registerBroker(
348
349
List <ApiMessageAndVersion > records = new ArrayList <>();
349
350
BrokerRegistration existing = brokerRegistrations .get (brokerId );
350
351
Uuid prevIncarnationId = null ;
352
+ long storedBrokerEpoch = -2 ; // BrokerRegistration.previousBrokerEpoch default value is -1
351
353
if (existing != null ) {
352
354
prevIncarnationId = existing .incarnationId ();
355
+ storedBrokerEpoch = existing .epoch ();
353
356
if (heartbeatManager .hasValidSession (brokerId , existing .epoch ())) {
354
357
if (!request .incarnationId ().equals (prevIncarnationId )) {
355
358
throw new DuplicateBrokerRegistrationException ("Another broker is " +
@@ -424,7 +427,9 @@ public ControllerResult<BrokerRegistrationReply> registerBroker(
424
427
425
428
if (!request .incarnationId ().equals (prevIncarnationId )) {
426
429
int prevNumRecords = records .size ();
427
- brokerUncleanShutdownHandler .addRecordsForShutdown (request .brokerId (), records );
430
+ boolean isCleanShutdown = cleanShutdownDetectionEnabled ?
431
+ storedBrokerEpoch == request .previousBrokerEpoch () : false ;
432
+ brokerShutdownHandler .addRecordsForShutdown (request .brokerId (), isCleanShutdown , records );
428
433
int numRecordsAdded = records .size () - prevNumRecords ;
429
434
if (existing == null ) {
430
435
log .info ("No previous registration found for broker {}. New incarnation ID is " +
@@ -847,7 +852,7 @@ public Entry<Integer, Map<String, VersionRange>> next() {
847
852
}
848
853
849
854
@ FunctionalInterface
850
- interface BrokerUncleanShutdownHandler {
851
- void addRecordsForShutdown (int brokerId , List <ApiMessageAndVersion > records );
855
+ interface BrokerShutdownHandler {
856
+ void addRecordsForShutdown (int brokerId , boolean isCleanShutdown , List <ApiMessageAndVersion > records );
852
857
}
853
858
}
0 commit comments