Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make RrocksDB checksum type configurable #3793

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class KeyValueStorageRocksDB implements KeyValueStorage {
private static final String ROCKSDB_NUM_FILES_IN_LEVEL0 = "dbStorage_rocksDB_numFilesInLevel0";
private static final String ROCKSDB_MAX_SIZE_IN_LEVEL1_MB = "dbStorage_rocksDB_maxSizeInLevel1MB";
private static final String ROCKSDB_FORMAT_VERSION = "dbStorage_rocksDB_format_version";
private static final String ROCKSDB_CHECKSUM_TYPE = "dbStorage_rocksDB_checksum_type";

public KeyValueStorageRocksDB(String basePath, String subPath, DbConfigType dbConfigType, ServerConfiguration conf)
throws IOException {
Expand Down Expand Up @@ -174,6 +175,7 @@ private RocksDB initializeRocksDBWithBookieConf(String basePath, String subPath,
ServerConfiguration conf, boolean readOnly) throws IOException {
Options options = new Options();
options.setCreateIfMissing(true);
ChecksumType checksumType = ChecksumType.valueOf(conf.getString(ROCKSDB_CHECKSUM_TYPE, "kxxHash"));

if (dbConfigType == DbConfigType.EntryLocation) {
/* Set default RocksDB block-cache size to 10% / numberOfLedgers of direct memory, unless override */
Expand Down Expand Up @@ -214,7 +216,7 @@ private RocksDB initializeRocksDBWithBookieConf(String basePath, String subPath,
tableOptions.setBlockSize(blockSize);
tableOptions.setBlockCache(cache);
tableOptions.setFormatVersion(formatVersion);
tableOptions.setChecksumType(ChecksumType.kxxHash);
tableOptions.setChecksumType(checksumType);
if (bloomFilterBitsPerKey > 0) {
tableOptions.setFilterPolicy(new BloomFilter(bloomFilterBitsPerKey, false));
}
Expand All @@ -226,6 +228,9 @@ private RocksDB initializeRocksDBWithBookieConf(String basePath, String subPath,
options.setTableFormatConfig(tableOptions);
} else {
this.cache = null;
BlockBasedTableConfig tableOptions = new BlockBasedTableConfig();
tableOptions.setChecksumType(checksumType);
options.setTableFormatConfig(tableOptions);
}

// Configure file path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
import java.util.List;
import org.apache.bookkeeper.conf.ServerConfiguration;
import org.junit.Test;
import org.rocksdb.BlockBasedTableConfig;
import org.rocksdb.ChecksumType;
import org.rocksdb.ColumnFamilyDescriptor;
import org.rocksdb.ColumnFamilyOptions;
import org.rocksdb.CompressionType;
Expand Down Expand Up @@ -78,4 +80,37 @@ public void testRocksDBInitiateWithConfigurationFile() throws Exception {
assertEquals(1, familyOptions.maxWriteBufferNumber());
rocksDB.close();
}

@Test
public void testReadChecksumTypeFromBookieConfiguration() throws Exception {
ServerConfiguration configuration = new ServerConfiguration();
configuration.setEntryLocationRocksdbConf("entry_location_rocksdb.conf");
File tmpDir = Files.createTempDirectory("bk-kv-rocksdbtest-conf").toFile();
Files.createDirectory(Paths.get(tmpDir.toString(), "subDir"));
KeyValueStorageRocksDB rocksDB = new KeyValueStorageRocksDB(tmpDir.toString(), "subDir",
KeyValueStorageFactory.DbConfigType.EntryLocation, configuration);
assertNull(rocksDB.getColumnFamilyDescriptors());

Options options = (Options) rocksDB.getOptions();
assertEquals(ChecksumType.kxxHash, ((BlockBasedTableConfig) options.tableFormatConfig()).checksumType());
}

//@Test
public void testReadChecksumTypeFromConfigurationFile() throws Exception {
ServerConfiguration configuration = new ServerConfiguration();
URL url = getClass().getClassLoader().getResource("test_entry_location_rocksdb.conf");
configuration.setEntryLocationRocksdbConf(url.getPath());
File tmpDir = Files.createTempDirectory("bk-kv-rocksdbtest-file").toFile();
Files.createDirectory(Paths.get(tmpDir.toString(), "subDir"));
KeyValueStorageRocksDB rocksDB = new KeyValueStorageRocksDB(tmpDir.toString(), "subDir",
KeyValueStorageFactory.DbConfigType.EntryLocation, configuration);
assertNotNull(rocksDB.getColumnFamilyDescriptors());

List<ColumnFamilyDescriptor> columnFamilyDescriptorList = rocksDB.getColumnFamilyDescriptors();
ColumnFamilyOptions familyOptions = columnFamilyDescriptorList.get(0).getOptions();
// There is a bug in RocksDB, which can't load BlockedBasedTableConfig from Options file.
// https://github.com/facebook/rocksdb/issues/5297
// After the PR: https://github.com/facebook/rocksdb/pull/10826 merge, we can turn on this test.
assertEquals(ChecksumType.kxxHash, ((BlockBasedTableConfig) familyOptions.tableFormatConfig()).checksumType());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,19 @@
write_buffer_size=1024
# set by jni: options.setMaxWriteBufferNumber
max_write_buffer_number=1

[TableOptions/BlockBasedTable "default"]
# set by jni: tableOptions.setBlockSize
block_size=65536
# set by jni: tableOptions.setBlockCache
block_cache=206150041
# set by jni: tableOptions.setFormatVersion
format_version=2
# set by jni: tableOptions.setChecksumType
checksum=kxxHash
# set by jni: tableOptions.setFilterPolicy, bloomfilter:[bits_per_key]:[use_block_based_builder]
filter_policy=rocksdb.BloomFilter:10:false
# set by jni: tableOptions.setCacheIndexAndFilterBlocks
cache_index_and_filter_blocks=true
# set by jni: options.setLevelCompactionDynamicLevelBytes
level_compaction_dynamic_level_bytes=true
6 changes: 5 additions & 1 deletion conf/default_rocksdb.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@

[CFOptions "default"]
# set by jni: options.setLogFileTimeToRoll
log_file_time_to_roll=86400
log_file_time_to_roll=86400

[TableOptions/BlockBasedTable "default"]
# set by jni: tableOptions.setChecksumType
checksum=kxxHash
6 changes: 5 additions & 1 deletion conf/ledger_metadata_rocksdb.conf.default
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@

[CFOptions "default"]
# set by jni: options.setLogFileTimeToRoll
log_file_time_to_roll=86400
log_file_time_to_roll=86400

[TableOptions/BlockBasedTable "default"]
# set by jni: tableOptions.setChecksumType
checksum=kxxHash