From 5571779402c1cf2724bbd0422fed9e7b2decee81 Mon Sep 17 00:00:00 2001 From: Lishen Yao Date: Tue, 2 Apr 2024 07:44:34 +0800 Subject: [PATCH] Add Cookie to LocalBookie (#4052) ### Motivation I tried to use command `bin/bookkeeper shell listbookies -a` to get all bookies from localbookie, it raised error ``` ERROR Fail to process command 'list' org.apache.bookkeeper.client.BKException$ZKException: Error while using ZooKeeper at org.apache.bookkeeper.discover.ZKRegistrationClient.lambda$getChildren$4(ZKRegistrationClient.java:352) ~[bookkeeper-server-4.17.0-SNAPSHOT.jar:4.17.0-SNAPSHOT] at org.apache.bookkeeper.zookeeper.ZooKeeperClient$25$1.processResult(ZooKeeperClient.java:1177) ~[bookkeeper-server-4.17.0-SNAPSHOT.jar:4.17.0-SNAPSHOT] at org.apache.zookeeper.ClientCnxn$EventThread.processEvent(ClientCnxn.java:668) ~[zookeeper-3.8.1.jar:3.8.1] at org.apache.zookeeper.ClientCnxn$EventThread.run(ClientCnxn.java:553) ~[zookeeper-3.8.1.jar:3.8.1] Caused by: org.apache.zookeeper.KeeperException$NoNodeException: KeeperErrorCode = NoNode for /ledgers/cookies at org.apache.zookeeper.KeeperException.create(KeeperException.java:118) ~[zookeeper-3.8.1.jar:3.8.1] at org.apache.zookeeper.KeeperException.create(KeeperException.java:54) ~[zookeeper-3.8.1.jar:3.8.1] at org.apache.bookkeeper.discover.ZKRegistrationClient.lambda$getChildren$4(ZKRegistrationClient.java:351) ~[bookkeeper-server-4.17.0-SNAPSHOT.jar:4.17.0-SNAPSHOT] ... 3 more ``` The reason is that no /ledgers/cookies are created in ZK when starting the local bk server. After applying this change, the command works. --- .../java/org/apache/bookkeeper/util/LocalBookKeeper.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java index ca467ab2975..0c793eb4e51 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/LocalBookKeeper.java @@ -18,6 +18,7 @@ package org.apache.bookkeeper.util; import static java.nio.charset.StandardCharsets.UTF_8; +import static org.apache.bookkeeper.server.Main.storageDirectoriesFromConf; import static org.apache.bookkeeper.util.BookKeeperConstants.AVAILABLE_NODE; import static org.apache.bookkeeper.util.BookKeeperConstants.READONLY; @@ -38,8 +39,10 @@ import org.apache.bookkeeper.bookie.Bookie; import org.apache.bookkeeper.bookie.BookieImpl; import org.apache.bookkeeper.bookie.BookieResources; +import org.apache.bookkeeper.bookie.CookieValidation; import org.apache.bookkeeper.bookie.LedgerDirsManager; import org.apache.bookkeeper.bookie.LedgerStorage; +import org.apache.bookkeeper.bookie.LegacyCookieValidation; import org.apache.bookkeeper.bookie.UncleanShutdownDetection; import org.apache.bookkeeper.bookie.UncleanShutdownDetectionImpl; import org.apache.bookkeeper.common.allocator.ByteBufAllocatorWithOomHandler; @@ -526,6 +529,10 @@ private class LocalBookie { LedgerStorage storage = BookieResources.createLedgerStorage( conf, ledgerManager, ledgerDirsManager, indexDirsManager, NullStatsLogger.INSTANCE, allocator); + + CookieValidation cookieValidation = new LegacyCookieValidation(conf, registrationManager); + cookieValidation.checkCookies(storageDirectoriesFromConf(conf)); + UncleanShutdownDetection shutdownManager = new UncleanShutdownDetectionImpl(ledgerDirsManager); final ComponentInfoPublisher componentInfoPublisher = new ComponentInfoPublisher();