This is an automated email from the ASF dual-hosted git repository.

shoothzj pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new d7b2df4745 Fix RocksDB configuration path handling on Windows (#4407)
d7b2df4745 is described below

commit d7b2df47452cc296a1b3c0b6a9d018d3dd3cc5e9
Author: ZhangJian He <[email protected]>
AuthorDate: Fri May 31 11:45:50 2024 +0800

    Fix RocksDB configuration path handling on Windows (#4407)
    
    ### Motivation
    
    This PR addresses the issue where RocksDB configurations fail to correctly 
resolve paths on Windows systems in the `ServerConfiguration` class.
    
    ### Changes
    
    - Updated `ServerConfiguration.java` to utilize `java.nio.file.Paths` for 
path normalization and resolution.
    - Refactored the `getDefaultRocksDBConf`, `getEntryLocationRocksdbConf`, 
and `getLedgerMetadataRocksdbConf` methods to use a new method `getFilePath`.
    
    Signed-off-by: ZhangJian He <[email protected]>
---
 .../bookkeeper/conf/ServerConfiguration.java       | 39 ++++++++++++----------
 1 file changed, 21 insertions(+), 18 deletions(-)

diff --git 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
index 7785bfae0b..cb731060c4 100644
--- 
a/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
+++ 
b/bookkeeper-server/src/main/java/org/apache/bookkeeper/conf/ServerConfiguration.java
@@ -24,6 +24,7 @@ import com.google.common.base.Strings;
 import com.google.common.collect.Lists;
 import java.io.File;
 import java.net.URL;
+import java.nio.file.Paths;
 import java.util.concurrent.TimeUnit;
 import org.apache.bookkeeper.bookie.FileChannelProvider;
 import org.apache.bookkeeper.bookie.InterleavedLedgerStorage;
@@ -4049,12 +4050,8 @@ public class ServerConfiguration extends 
AbstractConfiguration<ServerConfigurati
      * @return String configured default rocksdb conf.
      */
     public String getDefaultRocksDBConf() {
-        String defaultPath = "conf/default_rocksdb.conf";
-        URL defURL = getClass().getClassLoader().getResource(defaultPath);
-        if (defURL != null) {
-            defaultPath = defURL.getPath();
-        }
-        return getString(DEFAULT_ROCKSDB_CONF, defaultPath);
+        String filePath = getFilePath("conf/default_rocksdb.conf");
+        return getString(DEFAULT_ROCKSDB_CONF, filePath);
     }
 
     /**
@@ -4073,12 +4070,8 @@ public class ServerConfiguration extends 
AbstractConfiguration<ServerConfigurati
      * @return String configured entry Location rocksdb conf.
      */
     public String getEntryLocationRocksdbConf() {
-        String defaultPath = "conf/entry_location_rocksdb.conf";
-        URL defURL = getClass().getClassLoader().getResource(defaultPath);
-        if (defURL != null) {
-            defaultPath = defURL.getPath();
-        }
-        return getString(ENTRY_LOCATION_ROCKSDB_CONF, defaultPath);
+        String filePath = getFilePath("conf/entry_location_rocksdb.conf");
+        return getString(ENTRY_LOCATION_ROCKSDB_CONF, filePath);
     }
 
     /**
@@ -4097,12 +4090,8 @@ public class ServerConfiguration extends 
AbstractConfiguration<ServerConfigurati
      * @return String configured ledger metadata rocksdb conf.
      */
     public String getLedgerMetadataRocksdbConf() {
-        String defaultPath = "conf/ledger_metadata_rocksdb.conf";
-        URL defURL = getClass().getClassLoader().getResource(defaultPath);
-        if (defURL != null) {
-            defaultPath = defURL.getPath();
-        }
-        return getString(LEDGER_METADATA_ROCKSDB_CONF, defaultPath);
+        String filePath = getFilePath("conf/ledger_metadata_rocksdb.conf");
+        return getString(LEDGER_METADATA_ROCKSDB_CONF, filePath);
     }
 
     /**
@@ -4155,4 +4144,18 @@ public class ServerConfiguration extends 
AbstractConfiguration<ServerConfigurati
     public long getMaxBatchReadSize() {
         return this.getLong(MAX_BATCH_READ_SIZE, DEFAULT_MAX_BATCH_READ_SIZE);
     }
+
+    /**
+     * Get the path of a file from resources.
+     *
+     * @param fileName the name of the file to get the path for.
+     * @return String the absolute path of the file.
+     */
+    private String getFilePath(String fileName) {
+        URL resourceURL = getClass().getClassLoader().getResource(fileName);
+        if (resourceURL != null) {
+            return Paths.get(resourceURL.getPath()).toString();
+        }
+        return "";
+    }
 }

Reply via email to