Skip to content

Commit

Permalink
Fix RocksDB configuration path handling on Windows (#4407)
Browse files Browse the repository at this point in the history
### 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]>
  • Loading branch information
shoothzj authored May 31, 2024
1 parent 15a5b49 commit d7b2df4
Showing 1 changed file with 21 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -4049,12 +4050,8 @@ public boolean isSkipReplayJournalInvalidRecord() {
* @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);
}

/**
Expand All @@ -4073,12 +4070,8 @@ public ServerConfiguration setDefaultRocksDBConf(String defaultRocksdbConf) {
* @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);
}

/**
Expand All @@ -4097,12 +4090,8 @@ public ServerConfiguration setEntryLocationRocksdbConf(String entryLocationRocks
* @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);
}

/**
Expand Down Expand Up @@ -4155,4 +4144,18 @@ public ServerConfiguration setMaxBatchReadSize(long maxBatchReadSize) {
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 "";
}
}

0 comments on commit d7b2df4

Please sign in to comment.