CavalliumDBEngine/src/main/java/it/cavallium/dbengine/database/disk/RocksDBColumn.java

92 lines
3.0 KiB
Java
Raw Normal View History

2021-10-20 01:51:34 +02:00
package it.cavallium.dbengine.database.disk;
import io.micrometer.core.instrument.MeterRegistry;
2021-10-20 01:51:34 +02:00
import io.net5.buffer.api.Buffer;
import io.net5.buffer.api.BufferAllocator;
import io.net5.buffer.api.Send;
2021-11-12 02:05:44 +01:00
import it.cavallium.dbengine.database.LLUtils;
2021-10-20 01:51:34 +02:00
import it.cavallium.dbengine.database.serialization.SerializationFunction;
import java.io.IOException;
import java.util.List;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.rocksdb.ColumnFamilyHandle;
import org.rocksdb.CompactRangeOptions;
import org.rocksdb.FlushOptions;
import org.rocksdb.ReadOptions;
import org.rocksdb.RocksDBException;
import org.rocksdb.RocksIterator;
import org.rocksdb.WriteBatch;
import org.rocksdb.WriteOptions;
public sealed interface RocksDBColumn permits AbstractRocksDBColumn {
2021-11-12 02:05:44 +01:00
default byte @Nullable [] get(@NotNull ReadOptions readOptions,
byte[] key,
boolean existsAlmostCertainly)
throws RocksDBException {
var allocator = getAllocator();
try (var keyBuf = allocator.allocate(key.length)) {
keyBuf.writeBytes(key);
2022-03-02 18:33:58 +01:00
var result = this.get(readOptions, keyBuf);
2021-11-12 02:05:44 +01:00
if (result == null) {
return null;
}
2021-12-12 02:17:36 +01:00
return LLUtils.toArray(result);
2021-11-12 02:05:44 +01:00
}
}
2021-10-20 01:51:34 +02:00
@Nullable
2022-03-02 18:33:58 +01:00
Buffer get(@NotNull ReadOptions readOptions, Buffer key) throws RocksDBException;
2021-10-20 01:51:34 +02:00
2021-12-12 02:17:36 +01:00
boolean exists(@NotNull ReadOptions readOptions, Buffer key) throws RocksDBException;
2021-10-20 01:51:34 +02:00
2021-12-12 02:17:36 +01:00
void put(@NotNull WriteOptions writeOptions, Buffer key,
Buffer value) throws RocksDBException;
2021-10-20 01:51:34 +02:00
2021-11-12 02:05:44 +01:00
default void put(@NotNull WriteOptions writeOptions, byte[] key, byte[] value)
throws RocksDBException {
var allocator = getAllocator();
try (var keyBuf = allocator.allocate(key.length)) {
keyBuf.writeBytes(key);
try (var valBuf = allocator.allocate(value.length)) {
valBuf.writeBytes(value);
2021-12-12 02:17:36 +01:00
this.put(writeOptions, keyBuf, valBuf);
2021-11-12 02:05:44 +01:00
}
}
}
2021-10-20 01:51:34 +02:00
@NotNull RocksIterator newIterator(@NotNull ReadOptions readOptions);
@NotNull UpdateAtomicResult updateAtomic(@NotNull ReadOptions readOptions, @NotNull WriteOptions writeOptions,
2021-11-08 16:33:41 +01:00
Send<Buffer> keySend, SerializationFunction<@Nullable Send<Buffer>, @Nullable Buffer> updater,
2022-03-02 18:33:58 +01:00
UpdateAtomicResultMode returnMode) throws RocksDBException, IOException;
2021-10-20 01:51:34 +02:00
2021-12-12 02:17:36 +01:00
void delete(WriteOptions writeOptions, Buffer key) throws RocksDBException;
2021-10-20 01:51:34 +02:00
void delete(WriteOptions writeOptions, byte[] key) throws RocksDBException;
2021-11-12 02:05:44 +01:00
List<byte[]> multiGetAsList(ReadOptions readOptions, List<byte[]> keys) throws RocksDBException;
2021-10-20 01:51:34 +02:00
void write(WriteOptions writeOptions, WriteBatch writeBatch) throws RocksDBException;
void suggestCompactRange() throws RocksDBException;
void compactRange(byte[] begin, byte[] end, CompactRangeOptions options) throws RocksDBException;
void flush(FlushOptions options) throws RocksDBException;
void flushWal(boolean sync) throws RocksDBException;
long getLongProperty(String property) throws RocksDBException;
ColumnFamilyHandle getColumnFamilyHandle();
BufferAllocator getAllocator();
MeterRegistry getMeterRegistry();
2021-10-20 01:51:34 +02:00
boolean supportsTransactions();
}