From 34ff4bf9a22b2f2197f095ea47fb6c1b54bd7693 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 26 Sep 2024 23:51:30 +0200 Subject: [PATCH] Load zstd --- .../core/impl/rocksdb/RocksDBLoader.java | 12 ++++++++++++ .../rockserver/core/impl/rocksdb/SSTWriter.java | 14 ++++++++++++-- 2 files changed, 24 insertions(+), 2 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 6214c88..b151042 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 @@ -55,6 +55,18 @@ public class RocksDBLoader { } catch (IOException e) { RocksDB.loadLibrary(); } + for (final CompressionType compressionType : CompressionType.values()) { + try { + if (compressionType.getLibraryName() != null) { + System.loadLibrary(compressionType.getLibraryName()); + } + } catch (final UnsatisfiedLinkError e) { + if (compressionType == CompressionType.ZSTD_COMPRESSION) { + throw new IllegalStateException("Can't load ZSTD", e); + } + // since it may be optional, we ignore its loading failure here. + } + } } private static Path loadLibraryFromJarToTemp(final Path tmpDir) throws IOException { 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 2ce878a..072ce05 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 @@ -56,9 +56,9 @@ public record SSTWriter(RocksDB db, it.cavallium.rockserver.core.impl.ColumnInst .setMaxOpenFiles(-1) .setCompressionPerLevel(columnConifg.compressionPerLevel()) .setCompressionType(columnConifg.compressionType()) - .setCompressionOptions(columnConifg.compressionOptions()) + .setCompressionOptions(cloneCompressionOptions(columnConifg.compressionOptions())) .setBottommostCompressionType(columnConifg.bottommostCompressionType()) - .setBottommostCompressionOptions(columnConifg.bottommostCompressionOptions()); + .setBottommostCompressionOptions(cloneCompressionOptions(columnConifg.bottommostCompressionOptions())); if (columnConifg.memTableConfig() != null) { options.setMemTableConfig(columnConifg.memTableConfig()); } else { @@ -83,6 +83,16 @@ public record SSTWriter(RocksDB db, it.cavallium.rockserver.core.impl.ColumnInst return sstWriter; } + private static CompressionOptions cloneCompressionOptions(CompressionOptions compressionOptions) { + return new CompressionOptions() + .setEnabled(compressionOptions.enabled()) + .setMaxDictBytes(compressionOptions.maxDictBytes()) + .setLevel(compressionOptions.level()) + .setStrategy(compressionOptions.strategy()) + .setZStdMaxTrainBytes(compressionOptions.zstdMaxTrainBytes()) + .setWindowBits(compressionOptions.windowBits()); + } + public void put(byte[] key, byte[] value) throws RocksDBException { try { sstFileWriter.put(key, value);