codelipenghui commented on a change in pull request #10383:
URL: https://github.com/apache/pulsar/pull/10383#discussion_r620798662
##########
File path:
pulsar-broker/src/main/java/org/apache/pulsar/broker/service/schema/BookkeeperSchemaStorage.java
##########
@@ -396,33 +391,42 @@ public void close() throws Exception {
} else {
// The version is only for the compatibility of the current
interface
final long version = -1;
- final List<Long> ledgerIds = schemaLedgers.get(schemaId);
- if (ledgerIds != null) {
- CompletableFuture<Long> future = new CompletableFuture<>();
- final AtomicInteger numOfLedgerIds = new
AtomicInteger(ledgerIds.size());
- for (long ledgerId : ledgerIds) {
- bookKeeper.asyncDeleteLedger(ledgerId, (int rc, Object
cnx) -> {
- if (rc != BKException.Code.OK) {
- // It's not a serious error, we didn't need
call future.completeExceptionally()
- log.warn("Failed to delete ledger {} of {}:
{}", ledgerId, schemaId, rc);
- }
- if (numOfLedgerIds.decrementAndGet() == 0) {
- try {
-
ZkUtils.deleteFullPathOptimistic(zooKeeper, getSchemaPath(schemaId), -1);
- } catch (InterruptedException |
KeeperException e) {
- future.completeExceptionally(e);
+ CompletableFuture<Long> future = new CompletableFuture<>();
+ getLocator(schemaId).whenComplete((locator, ex) -> {
+ if (ex != null) {
+ future.completeExceptionally(ex);
+ } else {
+ if (!locator.isPresent()) {
+ future.complete(null);
+ return;
+ }
+ List<SchemaStorageFormat.IndexEntry> indexEntryList =
locator.get().locator.getIndexList();
+ List<CompletableFuture<Void>> deleteFutures = new
ArrayList<>(indexEntryList.size());
+ indexEntryList.forEach(indexEntry -> {
+ final long ledgerId =
indexEntry.getPosition().getLedgerId();
+ CompletableFuture<Void> deleteFuture = new
CompletableFuture<>();
+ deleteFutures.add(deleteFuture);
+ bookKeeper.asyncDeleteLedger(ledgerId, (int rc,
Object cnx) -> {
+ if (rc != BKException.Code.OK) {
+ // It's not a serious error, we didn't
need call future.completeExceptionally()
+ log.warn("Failed to delete ledger {} of
{}: {}", ledgerId, schemaId, rc);
}
- clearLocatorCache(getSchemaPath(schemaId));
- future.complete(version);
+ deleteFuture.complete(null);
+ }, null);
+ });
+ FutureUtil.waitForAll(deleteFutures).whenComplete((v,
e) -> {
+ try {
+ ZkUtils.deleteFullPathOptimistic(zooKeeper,
getSchemaPath(schemaId), -1);
Review comment:
@merlimat Fixed, PTAL.
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]