Skip to content

Commit

Permalink
Change the strategy levelCompactionDynamicLevelBytes is set
Browse files Browse the repository at this point in the history
Signed-off-by: Ameziane H. <[email protected]>
  • Loading branch information
ahamlat committed Dec 17, 2024
1 parent 49fddb3 commit 52446c4
Showing 1 changed file with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.ColumnFamilyOptions;
import org.rocksdb.CompressionType;
import org.rocksdb.ConfigOptions;
import org.rocksdb.DBOptions;
import org.rocksdb.Env;
import org.rocksdb.LRUCache;
import org.rocksdb.Options;
import org.rocksdb.OptionsUtil;
import org.rocksdb.ReadOptions;
import org.rocksdb.RocksDB;
import org.rocksdb.RocksDBException;
Expand Down Expand Up @@ -161,7 +163,13 @@ public RocksDBColumnarKeyValueStorage(
.forEach(trimmedSegments::remove);
columnDescriptors =
trimmedSegments.stream()
.map(segment -> createColumnDescriptor(segment, configuration))
.map(segment -> {
try {
return createColumnDescriptor(segment, configuration);
} catch (RocksDBException e) {
throw new RuntimeException(e);
}
})
.collect(Collectors.toList());

setGlobalOptions(configuration, stats);
Expand All @@ -182,16 +190,41 @@ public RocksDBColumnarKeyValueStorage(
* @return a column family descriptor
*/
private ColumnFamilyDescriptor createColumnDescriptor(
final SegmentIdentifier segment, final RocksDBConfiguration configuration) {

BlockBasedTableConfig basedTableConfig = createBlockBasedTableConfig(segment, configuration);
final SegmentIdentifier segment, final RocksDBConfiguration configuration) throws RocksDBException {

ConfigOptions configOptions = new ConfigOptions();
DBOptions dbOptions = new DBOptions();
List<ColumnFamilyDescriptor> cfDescriptors = new ArrayList<>();

String latestOptionsFileName = OptionsUtil.getLatestOptionsFileName(configuration.getDatabaseDir().toString(), Env.getDefault());
LOG.trace("Latest OPTIONS file detected: " + latestOptionsFileName);

String optionsFilePath = configuration.getDatabaseDir().toString() + "/" + latestOptionsFileName;
OptionsUtil.loadOptionsFromFile(configOptions, optionsFilePath, dbOptions, cfDescriptors);

LOG.trace("RocksDB options loaded successfully from: " + optionsFilePath);

boolean dynamicLevelBytes = true;
if (!cfDescriptors.isEmpty()) {
Optional<ColumnFamilyOptions> matchedCfOptions = Optional.empty();
for (ColumnFamilyDescriptor descriptor : cfDescriptors) {
if (Arrays.equals(descriptor.getName(), segment.getId())) {
matchedCfOptions = Optional.of(descriptor.getOptions());
break;
}
}
if (matchedCfOptions.isPresent()) {
dynamicLevelBytes = matchedCfOptions.get().levelCompactionDynamicLevelBytes();
LOG.trace("dynamicLevelBytes is set to an existing value : " + dynamicLevelBytes);
}
}
BlockBasedTableConfig basedTableConfig = createBlockBasedTableConfig(segment, configuration);

final var options =
new ColumnFamilyOptions()
.setTtl(0)
.setCompressionType(CompressionType.LZ4_COMPRESSION)
.setTableFormatConfig(basedTableConfig);

.setTableFormatConfig(basedTableConfig).setLevelCompactionDynamicLevelBytes(dynamicLevelBytes);
if (segment.containsStaticData()) {
options
.setEnableBlobFiles(true)
Expand Down

0 comments on commit 52446c4

Please sign in to comment.