43
43
import java .util .concurrent .ConcurrentHashMap ;
44
44
import java .util .concurrent .TimeUnit ;
45
45
import lombok .Getter ;
46
- import lombok .NonNull ;
47
46
import lombok .extern .slf4j .Slf4j ;
48
47
import org .apache .bookkeeper .common .util .OrderedScheduler ;
49
48
import org .apache .commons .configuration .Configuration ;
52
51
import org .apache .kafka .common .record .CompressionType ;
53
52
import org .apache .kafka .common .utils .Time ;
54
53
import org .apache .pulsar .broker .PulsarServerException ;
55
- import org .apache .pulsar .broker .PulsarService ;
56
54
import org .apache .pulsar .broker .ServiceConfiguration ;
57
55
import org .apache .pulsar .broker .namespace .NamespaceService ;
58
56
import org .apache .pulsar .broker .protocol .ProtocolHandler ;
@@ -71,8 +69,6 @@ public class KafkaProtocolHandler implements ProtocolHandler, TenantContextManag
71
69
72
70
public static final String PROTOCOL_NAME = "kafka" ;
73
71
public static final String TLS_HANDLER = "tls" ;
74
- private static final Map <PulsarService , LookupClient > LOOKUP_CLIENT_MAP = new ConcurrentHashMap <>();
75
-
76
72
@ Getter
77
73
private RequestStats requestStats ;
78
74
private PrometheusMetricsProvider statsProvider ;
@@ -84,6 +80,7 @@ public class KafkaProtocolHandler implements ProtocolHandler, TenantContextManag
84
80
private SystemTopicClient txnTopicClient ;
85
81
private DelayedOperationPurgatory <DelayedOperation > producePurgatory ;
86
82
private DelayedOperationPurgatory <DelayedOperation > fetchPurgatory ;
83
+ private LookupClient lookupClient ;
87
84
@ VisibleForTesting
88
85
@ Getter
89
86
private Map <InetSocketAddress , ChannelInitializer <SocketChannel >> channelInitializerMap ;
@@ -202,12 +199,12 @@ public void start(BrokerService service) {
202
199
throw new IllegalStateException (e );
203
200
}
204
201
205
- LOOKUP_CLIENT_MAP . put ( brokerService . pulsar (), new LookupClient (brokerService .pulsar (), kafkaConfig ) );
202
+ lookupClient = new LookupClient (brokerService .pulsar (), kafkaConfig );
206
203
offsetTopicClient = new SystemTopicClient (brokerService .pulsar (), kafkaConfig );
207
204
txnTopicClient = new SystemTopicClient (brokerService .pulsar (), kafkaConfig );
208
205
209
206
try {
210
- kopBrokerLookupManager = new KopBrokerLookupManager (kafkaConfig , brokerService .getPulsar ());
207
+ kopBrokerLookupManager = new KopBrokerLookupManager (kafkaConfig , brokerService .getPulsar (), lookupClient );
211
208
} catch (Exception ex ) {
212
209
log .error ("Failed to get kopBrokerLookupManager" , ex );
213
210
throw new IllegalStateException (ex );
@@ -402,7 +399,8 @@ private KafkaChannelInitializer newKafkaChannelInitializer(final EndPoint endPoi
402
399
kafkaConfig .isSkipMessagesWithoutIndex (),
403
400
requestStats ,
404
401
sendResponseScheduler ,
405
- kafkaTopicManagerSharedState );
402
+ kafkaTopicManagerSharedState ,
403
+ lookupClient );
406
404
}
407
405
408
406
// this is called after initialize, and with kafkaConfig, brokerService all set.
@@ -456,16 +454,6 @@ public Map<InetSocketAddress, ChannelInitializer<SocketChannel>> newChannelIniti
456
454
457
455
@ Override
458
456
public void close () {
459
- Optional .ofNullable (LOOKUP_CLIENT_MAP .remove (brokerService .pulsar ())).ifPresent (LookupClient ::close );
460
- if (offsetTopicClient != null ) {
461
- offsetTopicClient .close ();
462
- }
463
- if (txnTopicClient != null ) {
464
- txnTopicClient .close ();
465
- }
466
- if (adminManager != null ) {
467
- adminManager .shutdown ();
468
- }
469
457
if (producePurgatory != null ) {
470
458
producePurgatory .shutdown ();
471
459
}
@@ -483,6 +471,19 @@ public void close() {
483
471
kopBrokerLookupManager .close ();
484
472
statsProvider .stop ();
485
473
sendResponseScheduler .shutdown ();
474
+
475
+ if (offsetTopicClient != null ) {
476
+ offsetTopicClient .close ();
477
+ }
478
+ if (txnTopicClient != null ) {
479
+ txnTopicClient .close ();
480
+ }
481
+ if (adminManager != null ) {
482
+ adminManager .shutdown ();
483
+ }
484
+ if (lookupClient != null ) {
485
+ lookupClient .close ();
486
+ }
486
487
}
487
488
488
489
@ VisibleForTesting
@@ -571,8 +572,4 @@ public TransactionCoordinator initTransactionCoordinator(String tenant, PulsarAd
571
572
572
573
return transactionCoordinator ;
573
574
}
574
-
575
- public static @ NonNull LookupClient getLookupClient (final PulsarService pulsarService ) {
576
- return LOOKUP_CLIENT_MAP .computeIfAbsent (pulsarService , ignored -> new LookupClient (pulsarService ));
577
- }
578
575
}
0 commit comments