Load zstd

This commit is contained in:
Andrea Cavalli 2024-09-26 23:51:30 +02:00
parent b8b4b3c320
commit 34ff4bf9a2
2 changed files with 24 additions and 2 deletions

View File

@ -55,6 +55,18 @@ public class RocksDBLoader {
} catch (IOException e) { } catch (IOException e) {
RocksDB.loadLibrary(); 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 { private static Path loadLibraryFromJarToTemp(final Path tmpDir) throws IOException {

View File

@ -56,9 +56,9 @@ public record SSTWriter(RocksDB db, it.cavallium.rockserver.core.impl.ColumnInst
.setMaxOpenFiles(-1) .setMaxOpenFiles(-1)
.setCompressionPerLevel(columnConifg.compressionPerLevel()) .setCompressionPerLevel(columnConifg.compressionPerLevel())
.setCompressionType(columnConifg.compressionType()) .setCompressionType(columnConifg.compressionType())
.setCompressionOptions(columnConifg.compressionOptions()) .setCompressionOptions(cloneCompressionOptions(columnConifg.compressionOptions()))
.setBottommostCompressionType(columnConifg.bottommostCompressionType()) .setBottommostCompressionType(columnConifg.bottommostCompressionType())
.setBottommostCompressionOptions(columnConifg.bottommostCompressionOptions()); .setBottommostCompressionOptions(cloneCompressionOptions(columnConifg.bottommostCompressionOptions()));
if (columnConifg.memTableConfig() != null) { if (columnConifg.memTableConfig() != null) {
options.setMemTableConfig(columnConifg.memTableConfig()); options.setMemTableConfig(columnConifg.memTableConfig());
} else { } else {
@ -83,6 +83,16 @@ public record SSTWriter(RocksDB db, it.cavallium.rockserver.core.impl.ColumnInst
return sstWriter; 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 { public void put(byte[] key, byte[] value) throws RocksDBException {
try { try {
sstFileWriter.put(key, value); sstFileWriter.put(key, value);