|
21 | 21 | import static com.google.common.base.Preconditions.checkNotNull; |
22 | 22 | import static org.apache.commons.lang3.StringUtils.isBlank; |
23 | 23 | import static org.apache.commons.lang3.StringUtils.isNotBlank; |
| 24 | +import static org.apache.pulsar.broker.admin.impl.BrokersBase.getHeartbeatTopicName; |
24 | 25 | import static org.apache.pulsar.broker.resourcegroup.ResourceUsageTransportManager.DISABLE_RESOURCE_USAGE_TRANSPORT_MANAGER; |
25 | 26 | import static org.apache.pulsar.common.naming.SystemTopicNames.isTransactionInternalName; |
26 | 27 | import com.google.common.annotations.VisibleForTesting; |
|
72 | 73 | import org.apache.bookkeeper.mledger.LedgerOffloader; |
73 | 74 | import org.apache.bookkeeper.mledger.LedgerOffloaderFactory; |
74 | 75 | import org.apache.bookkeeper.mledger.LedgerOffloaderStats; |
| 76 | +import org.apache.bookkeeper.mledger.ManagedLedgerException; |
75 | 77 | import org.apache.bookkeeper.mledger.ManagedLedgerFactory; |
76 | 78 | import org.apache.bookkeeper.mledger.impl.NullLedgerOffloader; |
77 | 79 | import org.apache.bookkeeper.mledger.offload.Offloaders; |
@@ -414,6 +416,41 @@ private void closeLeaderElectionService() throws Exception { |
414 | 416 | } |
415 | 417 | } |
416 | 418 |
|
| 419 | + private boolean isManagedLedgerNotFoundException(Throwable e) { |
| 420 | + Throwable realCause = e.getCause(); |
| 421 | + return realCause instanceof ManagedLedgerException.MetadataNotFoundException |
| 422 | + || realCause instanceof MetadataStoreException.NotFoundException; |
| 423 | + } |
| 424 | + |
| 425 | + private void deleteHeartbeatResource() { |
| 426 | + if (this.brokerService != null) { |
| 427 | + LOG.info("forcefully delete heartbeat topic when close broker"); |
| 428 | + |
| 429 | + String heartbeatTopicNameV1 = getHeartbeatTopicName(getBrokerId(), getConfiguration(), false); |
| 430 | + String heartbeatTopicNameV2 = getHeartbeatTopicName(getBrokerId(), getConfiguration(), true); |
| 431 | + |
| 432 | + try { |
| 433 | + this.brokerService.deleteTopic(heartbeatTopicNameV1, true).get(); |
| 434 | + } catch (Exception e) { |
| 435 | + if (!isManagedLedgerNotFoundException(e)) { |
| 436 | + LOG.error("Closed with errors in delete heartbeat topic [{}]", |
| 437 | + heartbeatTopicNameV1, e); |
| 438 | + } |
| 439 | + } |
| 440 | + |
| 441 | + try { |
| 442 | + this.brokerService.deleteTopic(heartbeatTopicNameV2, true).get(); |
| 443 | + } catch (Exception e) { |
| 444 | + if (!isManagedLedgerNotFoundException(e)) { |
| 445 | + LOG.error("Closed with errors in delete heartbeat topic [{}]", |
| 446 | + heartbeatTopicNameV2, e); |
| 447 | + } |
| 448 | + } |
| 449 | + |
| 450 | + LOG.info("finish forcefully delete heartbeat topic when close broker"); |
| 451 | + } |
| 452 | + } |
| 453 | + |
417 | 454 | @Override |
418 | 455 | public void close() throws PulsarServerException { |
419 | 456 | try { |
@@ -460,6 +497,11 @@ public CompletableFuture<Void> closeAsync() { |
460 | 497 | // It only tells the Pulsar clients that this service is not ready to serve for the lookup requests |
461 | 498 | state = State.Closing; |
462 | 499 |
|
| 500 | + if (brokerId != null) { |
| 501 | + // forcefully delete heartbeat topic when close broker |
| 502 | + deleteHeartbeatResource(); |
| 503 | + } |
| 504 | + |
463 | 505 | // close the service in reverse order v.s. in which they are started |
464 | 506 | if (this.resourceUsageTransportManager != null) { |
465 | 507 | try { |
|
0 commit comments