You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/31 03:45:44 UTC

[GitHub] [pulsar] codelipenghui commented on a diff in pull request #18260: [fix][broker] read local cookie when start pulsar standalone

codelipenghui commented on code in PR #18260:
URL: https://github.com/apache/pulsar/pull/18260#discussion_r1009007077


##########
pulsar-metadata/src/main/java/org/apache/pulsar/metadata/bookkeeper/BKCluster.java:
##########
@@ -231,9 +234,29 @@ private ServerConfiguration newServerConfiguration(int index) throws Exception {
             // and 2nd bookie's cookie validation fails
             port = clusterConf.bkPort;
         }
+        File[] cookieDir = dataDir.listFiles((file) -> file.getName().equals("current"));
+        if (cookieDir != null && cookieDir.length > 0) {
+            String existBookieAddr = parseBookieAddressFromeCookie(cookieDir[0]);
+            if (existBookieAddr != null) {
+                baseConf.setAdvertisedAddress(existBookieAddr.split(":")[0]);
+                port = Integer.parseInt(existBookieAddr.split(":")[1]);
+            }
+        }
         return newServerConfiguration(port, dataDir, new File[]{dataDir});
     }
 
+    private String parseBookieAddressFromeCookie(File dir) {
+        Cookie cookie;
+        try {
+            cookie = Cookie.readFromDirectory(dir);
+        } catch (IOException e) {

Review Comment:
   We can just throw out the exception. 
   Otherwise, we will not able to know the details of the IOException



-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org