hangc0276 commented on code in PR #3523:
URL: https://github.com/apache/bookkeeper/pull/3523#discussion_r996781236
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/KeyValueStorageRocksDB.java:
##########
@@ -109,26 +158,129 @@ public KeyValueStorageRocksDB(String basePath, String
subPath, DbConfigType dbCo
dbOptions.setDbLogDir(logPathSetting.toString());
}
String path = FileSystems.getDefault().getPath(basePath,
subPath).toFile().toString();
-
+ this.options = dbOptions;
+ this.columnFamilyDescriptors = cfDescs;
if (readOnly) {
- db = RocksDB.openReadOnly(dbOptions, path, cfDescs, cfHandles);
+ return RocksDB.openReadOnly(dbOptions, path, cfDescs,
cfHandles);
} else {
- db = RocksDB.open(dbOptions, path, cfDescs, cfHandles);
+ return RocksDB.open(dbOptions, path, cfDescs, cfHandles);
}
} catch (RocksDBException e) {
throw new IOException("Error open RocksDB database", e);
}
+ }
- optionSync.setSync(true);
- optionDontSync.setSync(false);
+ private RocksDB initializeRocksDBWithBookieConf(String basePath, String
subPath, DbConfigType dbConfigType,
+ ServerConfiguration conf, boolean
readOnly) throws IOException {
+ Options options = new Options();
+ options.setCreateIfMissing(true);
+
+ if (dbConfigType == DbConfigType.EntryLocation) {
+ /* Set default RocksDB block-cache size to 10% / numberOfLedgers
of direct memory, unless override */
+ int ledgerDirsSize = conf.getLedgerDirNames().length;
+ long defaultRocksDBBlockCacheSizeBytes = maxDirectMemory() /
ledgerDirsSize / 10;
+ long blockCacheSize =
DbLedgerStorage.getLongVariableOrDefault(conf, ROCKSDB_BLOCK_CACHE_SIZE,
+ defaultRocksDBBlockCacheSizeBytes);
+
+ long writeBufferSizeMB = conf.getInt(ROCKSDB_WRITE_BUFFER_SIZE_MB,
64);
+ long sstSizeMB = conf.getInt(ROCKSDB_SST_SIZE_MB, 64);
+ int numLevels = conf.getInt(ROCKSDB_NUM_LEVELS, -1);
+ int numFilesInLevel0 = conf.getInt(ROCKSDB_NUM_FILES_IN_LEVEL0, 4);
+ long maxSizeInLevel1MB =
conf.getLong(ROCKSDB_MAX_SIZE_IN_LEVEL1_MB, 256);
+ int blockSize = conf.getInt(ROCKSDB_BLOCK_SIZE, 64 * 1024);
+ int bloomFilterBitsPerKey =
conf.getInt(ROCKSDB_BLOOM_FILTERS_BITS_PER_KEY, 10);
+ boolean lz4CompressionEnabled =
conf.getBoolean(ROCKSDB_LZ4_COMPRESSION_ENABLED, true);
+ int formatVersion = conf.getInt(ROCKSDB_FORMAT_VERSION, 2);
+
+ if (lz4CompressionEnabled) {
+ options.setCompressionType(CompressionType.LZ4_COMPRESSION);
+ }
+ options.setWriteBufferSize(writeBufferSizeMB * 1024 * 1024);
+ options.setMaxWriteBufferNumber(4);
+ if (numLevels > 0) {
+ options.setNumLevels(numLevels);
+ }
+ options.setLevelZeroFileNumCompactionTrigger(numFilesInLevel0);
+ options.setMaxBytesForLevelBase(maxSizeInLevel1MB * 1024 * 1024);
+ options.setMaxBackgroundJobs(32);
+ options.setIncreaseParallelism(32);
+ options.setMaxTotalWalSize(512 * 1024 * 1024);
+ options.setMaxOpenFiles(-1);
+ options.setTargetFileSizeBase(sstSizeMB * 1024 * 1024);
+
options.setDeleteObsoleteFilesPeriodMicros(TimeUnit.HOURS.toMicros(1));
+
+ this.cache = new LRUCache(blockCacheSize);
+ BlockBasedTableConfig tableOptions = new BlockBasedTableConfig();
+ tableOptions.setBlockSize(blockSize);
+ tableOptions.setBlockCache(cache);
+ tableOptions.setFormatVersion(formatVersion);
+ tableOptions.setChecksumType(ChecksumType.kxxHash);
+ if (bloomFilterBitsPerKey > 0) {
+ tableOptions.setFilterPolicy(new
BloomFilter(bloomFilterBitsPerKey, false));
+ }
- optionCache.setFillCache(true);
- optionDontCache.setFillCache(false);
+ // Options best suited for HDDs
+ tableOptions.setCacheIndexAndFilterBlocks(true);
+ options.setLevelCompactionDynamicLevelBytes(true);
+
+ options.setTableFormatConfig(tableOptions);
+ } else {
+ this.cache = null;
+ }
+
+ // Configure file path
+ String logPath = conf.getString(ROCKSDB_LOG_PATH, "");
+ if (!logPath.isEmpty()) {
+ Path logPathSetting = FileSystems.getDefault().getPath(logPath,
subPath);
+ Files.createDirectories(logPathSetting);
+ log.info("RocksDB<{}> log path: {}", subPath, logPathSetting);
+ options.setDbLogDir(logPathSetting.toString());
+ }
+ String path = FileSystems.getDefault().getPath(basePath,
subPath).toFile().toString();
+
+ // Configure log level
+ String logLevel = conf.getString(ROCKSDB_LOG_LEVEL, "info");
+ switch (logLevel) {
+ case "debug":
+ options.setInfoLogLevel(InfoLogLevel.DEBUG_LEVEL);
+ break;
+ case "info":
+ options.setInfoLogLevel(InfoLogLevel.INFO_LEVEL);
+ break;
+ case "warn":
+ options.setInfoLogLevel(InfoLogLevel.WARN_LEVEL);
+ break;
+ case "error":
+ options.setInfoLogLevel(InfoLogLevel.ERROR_LEVEL);
+ break;
+ default:
+ log.warn("Unrecognized RockDB log level: {}", logLevel);
+ }
+
+ // Keep log files for 1month
+ options.setKeepLogFileNum(30);
+ options.setLogFileTimeToRoll(TimeUnit.DAYS.toSeconds(1));
+ this.options = options;
+ try {
+ if (readOnly) {
+ return RocksDB.openReadOnly(options, path);
+ } else {
+ return RocksDB.open(options, path);
+ }
+ } catch (RocksDBException e) {
+ throw new IOException("Error open RocksDB database", e);
+ }
}
@Override
public void close() throws IOException {
db.close();
+ if (cache != null) {
+ cache.close();
+ }
+ if (options != null) {
Review Comment:
Why do we need this `options` field?
##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/storage/ldb/KeyValueStorageRocksDB.java:
##########
@@ -20,27 +20,44 @@
*/
package org.apache.bookkeeper.bookie.storage.ldb;
+
import static com.google.common.base.Preconditions.checkState;
+//CHECKSTYLE.OFF: IllegalImport
Review Comment:
Why add the checkstyle off?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]