Skip to content

Commit 73e22ca

Browse files
authored
ISSUE2620: RocksDB log path configurable
RocksDB configuration now allows a new value "dbStorage_rocksDB_logPath" which allows the log files to be separated from the data storage. When not set, Bookkeeper has no change in behavior. Descriptions of the changes in this PR: ### Motivation (Explain: why you're making that change, what is the problem you're trying to solve) ### Changes (Describe: what changes you have made) Master Issue: #<master-issue-number> Reviewers: Enrico Olivelli <eolivelli@gmail.com>, lipenghui <penghui@apache.org>, Matteo Merli <mmerli@apache.org> This closes apache#2698 from dinghram/RocksDBLogPath and squashes the following commits: bd8e212 [Don Inghram] Issue2620-RocksDB log path configurable: conf eeba052 [Don Inghram] Issue2620-RocksDB log path configurable
1 parent 034ef85 commit 73e22ca

File tree

8 files changed

+37
-21
lines changed

8 files changed

+37
-21
lines changed

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/DbLedgerStorage.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@ public static void readLedgerIndexEntries(long ledgerId, ServerConfiguration ser
314314
String ledgerBasePath = ledgerDirs.get(dirIndex).toString();
315315

316316
EntryLocationIndex entryLocationIndex = new EntryLocationIndex(serverConf,
317-
(path, dbConfigType, conf1) -> new KeyValueStorageRocksDB(path, DbConfigType.Small, conf1, true),
317+
(basePath, subPath, dbConfigType, conf1) ->
318+
new KeyValueStorageRocksDB(basePath, subPath, DbConfigType.Small, conf1, true),
318319
ledgerBasePath, NullStatsLogger.INSTANCE);
319320
try {
320321
long lastEntryId = entryLocationIndex.getLastEntryInLedger(ledgerId);

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/EntryLocationIndex.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
import java.io.Closeable;
2626
import java.io.IOException;
27-
import java.nio.file.FileSystems;
2827
import java.util.Map.Entry;
2928
import java.util.Set;
3029
import java.util.concurrent.TimeUnit;
@@ -54,8 +53,7 @@ public class EntryLocationIndex implements Closeable {
5453

5554
public EntryLocationIndex(ServerConfiguration conf, KeyValueStorageFactory storageFactory, String basePath,
5655
StatsLogger stats) throws IOException {
57-
String locationsDbPath = FileSystems.getDefault().getPath(basePath, "locations").toFile().toString();
58-
locationsDb = storageFactory.newKeyValueStorage(locationsDbPath, DbConfigType.Huge, conf);
56+
locationsDb = storageFactory.newKeyValueStorage(basePath, "locations", DbConfigType.Huge, conf);
5957

6058
this.stats = new EntryLocationIndexStats(
6159
stats,

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/KeyValueStorageFactory.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum DbConfigType {
3737
Huge // Used for location index, lots of writes and much bigger dataset
3838
}
3939

40-
KeyValueStorage newKeyValueStorage(String path, DbConfigType dbConfigType, ServerConfiguration conf)
40+
KeyValueStorage newKeyValueStorage(String defaultBasePath, String subPath, DbConfigType dbConfigType,
41+
ServerConfiguration conf)
4142
throws IOException;
4243
}

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/KeyValueStorageRocksDB.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
//CHECKSTYLE.ON: IllegalImport
2828

2929
import java.io.IOException;
30+
import java.nio.file.FileSystems;
31+
import java.nio.file.Files;
32+
import java.nio.file.Path;
3033
import java.util.Map.Entry;
3134
import java.util.concurrent.TimeUnit;
3235

@@ -55,8 +58,8 @@
5558
*/
5659
public class KeyValueStorageRocksDB implements KeyValueStorage {
5760

58-
static KeyValueStorageFactory factory = (path, dbConfigType, conf) -> new KeyValueStorageRocksDB(path, dbConfigType,
59-
conf);
61+
static KeyValueStorageFactory factory = (defaultBasePath, subPath, dbConfigType, conf) ->
62+
new KeyValueStorageRocksDB(defaultBasePath, subPath, dbConfigType, conf);
6063

6164
private final RocksDB db;
6265

@@ -68,6 +71,7 @@ public class KeyValueStorageRocksDB implements KeyValueStorage {
6871

6972
private final WriteBatch emptyBatch;
7073

74+
private static final String ROCKSDB_LOG_PATH = "dbStorage_rocksDB_logPath";
7175
private static final String ROCKSDB_LOG_LEVEL = "dbStorage_rocksDB_logLevel";
7276
private static final String ROCKSDB_LZ4_COMPRESSION_ENABLED = "dbStorage_rocksDB_lz4CompressionEnabled";
7377
private static final String ROCKSDB_WRITE_BUFFER_SIZE_MB = "dbStorage_rocksDB_writeBufferSizeMB";
@@ -79,11 +83,13 @@ public class KeyValueStorageRocksDB implements KeyValueStorage {
7983
private static final String ROCKSDB_NUM_FILES_IN_LEVEL0 = "dbStorage_rocksDB_numFilesInLevel0";
8084
private static final String ROCKSDB_MAX_SIZE_IN_LEVEL1_MB = "dbStorage_rocksDB_maxSizeInLevel1MB";
8185

82-
public KeyValueStorageRocksDB(String path, DbConfigType dbConfigType, ServerConfiguration conf) throws IOException {
83-
this(path, dbConfigType, conf, false);
86+
public KeyValueStorageRocksDB(String basePath, String subPath, DbConfigType dbConfigType, ServerConfiguration conf)
87+
throws IOException {
88+
this(basePath, subPath, dbConfigType, conf, false);
8489
}
8590

86-
public KeyValueStorageRocksDB(String path, DbConfigType dbConfigType, ServerConfiguration conf, boolean readOnly)
91+
public KeyValueStorageRocksDB(String basePath, String subPath, DbConfigType dbConfigType, ServerConfiguration conf,
92+
boolean readOnly)
8793
throws IOException {
8894
try {
8995
RocksDB.loadLibrary();
@@ -150,6 +156,16 @@ public KeyValueStorageRocksDB(String path, DbConfigType dbConfigType, ServerConf
150156
options.setTableFormatConfig(tableOptions);
151157
}
152158

159+
// Configure file path
160+
String logPath = conf.getString(ROCKSDB_LOG_PATH, "");
161+
if (!logPath.isEmpty()) {
162+
Path logPathSetting = FileSystems.getDefault().getPath(logPath, subPath);
163+
Files.createDirectories(logPathSetting);
164+
log.info("RocksDB<{}> log path: {}", subPath, logPathSetting);
165+
options.setDbLogDir(logPathSetting.toString());
166+
}
167+
String path = FileSystems.getDefault().getPath(basePath, subPath).toFile().toString();
168+
153169
// Configure log level
154170
String logLevel = conf.getString(ROCKSDB_LOG_LEVEL, "info");
155171
switch (logLevel) {

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/LedgerMetadataIndex.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727

2828
import java.io.Closeable;
2929
import java.io.IOException;
30-
import java.nio.file.FileSystems;
3130
import java.util.AbstractMap.SimpleEntry;
3231
import java.util.Arrays;
3332
import java.util.Map.Entry;
@@ -66,8 +65,7 @@ public class LedgerMetadataIndex implements Closeable {
6665

6766
public LedgerMetadataIndex(ServerConfiguration conf, KeyValueStorageFactory storageFactory, String basePath,
6867
StatsLogger stats) throws IOException {
69-
String ledgersPath = FileSystems.getDefault().getPath(basePath, "ledgers").toFile().toString();
70-
ledgersDb = storageFactory.newKeyValueStorage(ledgersPath, DbConfigType.Small, conf);
68+
ledgersDb = storageFactory.newKeyValueStorage(basePath, "ledgers", DbConfigType.Small, conf);
7169

7270
ledgers = new ConcurrentLongHashMap<>();
7371
ledgersCount = new AtomicInteger();

bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/LocationsIndexRebuildOp.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,11 @@ public void initiate() throws IOException {
7373
new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold())));
7474
Set<Long> entryLogs = entryLogger.getEntryLogsSet();
7575

76-
String locationsDbPath = FileSystems.getDefault().getPath(basePath, "locations").toFile().toString();
77-
7876
Set<Long> activeLedgers = getActiveLedgers(conf, KeyValueStorageRocksDB.factory, basePath);
7977
LOG.info("Found {} active ledgers in ledger manager", activeLedgers.size());
8078

81-
KeyValueStorage newIndex = KeyValueStorageRocksDB.factory.newKeyValueStorage(locationsDbPath, DbConfigType.Huge,
82-
conf);
79+
KeyValueStorage newIndex = KeyValueStorageRocksDB.factory.newKeyValueStorage(basePath, "locations",
80+
DbConfigType.Huge, conf);
8381

8482
int totalEntryLogs = entryLogs.size();
8583
int completedEntryLogs = 0;

bookkeeper-server/src/test/java/org/apache/bookkeeper/bookie/storage/ldb/KeyValueStorageTest.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import com.google.common.collect.Lists;
2727

2828
import java.io.File;
29+
import java.nio.file.Files;
30+
import java.nio.file.Paths;
2931
import java.util.Arrays;
3032
import java.util.Collection;
3133
import java.util.List;
@@ -35,6 +37,7 @@
3537
import org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorage.CloseableIterator;
3638
import org.apache.bookkeeper.bookie.storage.ldb.KeyValueStorageFactory.DbConfigType;
3739
import org.apache.bookkeeper.conf.ServerConfiguration;
40+
import org.apache.commons.io.FileUtils;
3841
import org.junit.Test;
3942
import org.junit.runner.RunWith;
4043
import org.junit.runners.Parameterized;
@@ -71,10 +74,10 @@ private static byte[] toArray(long n) {
7174

7275
@Test
7376
public void simple() throws Exception {
74-
File tmpDir = File.createTempFile("bookie", "test");
75-
tmpDir.delete();
77+
File tmpDir = Files.createTempDirectory("junitTemporaryFolder").toFile();
78+
Files.createDirectory(Paths.get(tmpDir.toString(), "subDir"));
7679

77-
KeyValueStorage db = storageFactory.newKeyValueStorage(tmpDir.getAbsolutePath(), DbConfigType.Small,
80+
KeyValueStorage db = storageFactory.newKeyValueStorage(tmpDir.toString(), "subDir", DbConfigType.Small,
7881
configuration);
7982

8083
assertEquals(null, db.getFloor(toArray(3)));
@@ -167,6 +170,6 @@ public void simple() throws Exception {
167170
batch.close();
168171

169172
db.close();
170-
tmpDir.delete();
173+
FileUtils.deleteDirectory(tmpDir);
171174
}
172175
}

conf/bk_server.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ ledgerDirectories=/tmp/bk-data
719719
# dbStorage_rocksDB_numLevels=-1
720720
# dbStorage_rocksDB_numFilesInLevel0=4
721721
# dbStorage_rocksDB_maxSizeInLevel1MB=256
722+
# dbStorage_rocksDB_logPath=
722723

723724

724725
############################################## Metadata Services ##############################################

0 commit comments

Comments
 (0)