From b8b4b3c320a49965532f19ae83f8898855f33868 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 26 Sep 2024 18:29:21 +0200 Subject: [PATCH] Fix compression options --- .../core/impl/rocksdb/RocksDBLoader.java | 18 +++++++++++------- .../core/impl/rocksdb/SSTWriter.java | 12 ++++++------ 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/RocksDBLoader.java b/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/RocksDBLoader.java index 6e114b0..6214c88 100644 --- a/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/RocksDBLoader.java +++ b/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/RocksDBLoader.java @@ -150,6 +150,17 @@ public class RocksDBLoader { if (columnOptions.levels().length > 0) { columnFamilyOptions.setNumLevels(columnOptions.levels().length); + + List compressionPerLevel = new ArrayList<>(); + for (ColumnLevelConfig columnLevelConfig : columnOptions.levels()) { + CompressionType compression = columnLevelConfig.compression(); + compressionPerLevel.add(compression); + } + if (compressionPerLevel.size() != columnOptions.levels().length) { + throw it.cavallium.rockserver.core.common.RocksDBException.of(RocksDBErrorType.CONFIG_ERROR, "Database column levels and compression per level count is different! %s != %s".formatted(compressionPerLevel.size(), columnOptions.levels().length)); + } + columnFamilyOptions.setCompressionPerLevel(compressionPerLevel); + var firstLevelOptions = getRocksLevelOptions(columnOptions.levels()[0], refs); columnFamilyOptions.setCompressionType(firstLevelOptions.compressionType); columnFamilyOptions.setCompressionOptions(firstLevelOptions.compressionOptions); @@ -158,13 +169,6 @@ public class RocksDBLoader { .levels()[columnOptions.levels().length - 1], refs); columnFamilyOptions.setBottommostCompressionType(lastLevelOptions.compressionType); columnFamilyOptions.setBottommostCompressionOptions(lastLevelOptions.compressionOptions); - - List compressionPerLevel = new ArrayList<>(); - for (ColumnLevelConfig columnLevelConfig : columnOptions.levels()) { - CompressionType compression = columnLevelConfig.compression(); - compressionPerLevel.add(compression); - } - columnFamilyOptions.setCompressionPerLevel(compressionPerLevel); } else { columnFamilyOptions.setNumLevels(7); List compressionTypes = new ArrayList<>(7); diff --git a/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/SSTWriter.java b/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/SSTWriter.java index 7f0c2b7..2ce878a 100644 --- a/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/SSTWriter.java +++ b/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/SSTWriter.java @@ -49,16 +49,16 @@ public record SSTWriter(RocksDB db, it.cavallium.rockserver.core.impl.ColumnInst .setParanoidFileChecks(false); if (columnConifg != null) { options - .setCompressionType(columnConifg.compressionType()) - .setCompressionOptions(columnConifg.compressionOptions()) - .setBottommostCompressionType(columnConifg.bottommostCompressionType()) - .setBottommostCompressionOptions(columnConifg.bottommostCompressionOptions()) - .setCompressionPerLevel(columnConifg.compressionPerLevel()) .setNumLevels(columnConifg.numLevels()) .setTableFormatConfig(columnConifg.tableFormatConfig()) .setTargetFileSizeBase(columnConifg.targetFileSizeBase()) .setTargetFileSizeMultiplier(columnConifg.targetFileSizeMultiplier()) - .setMaxOpenFiles(-1); + .setMaxOpenFiles(-1) + .setCompressionPerLevel(columnConifg.compressionPerLevel()) + .setCompressionType(columnConifg.compressionType()) + .setCompressionOptions(columnConifg.compressionOptions()) + .setBottommostCompressionType(columnConifg.bottommostCompressionType()) + .setBottommostCompressionOptions(columnConifg.bottommostCompressionOptions()); if (columnConifg.memTableConfig() != null) { options.setMemTableConfig(columnConifg.memTableConfig()); } else {