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

104 lines
3.4 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;
2022-03-16 13:47:56 +01:00
import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.api.BufferAllocator;
import it.cavallium.dbengine.database.LLRange;
2021-11-12 02:05:44 +01:00
import it.cavallium.dbengine.database.LLUtils;
2022-05-12 19:14:27 +02:00
import it.cavallium.dbengine.database.disk.rocksdb.RocksIteratorObj;
2021-10-20 01:51:34 +02:00
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.WriteBatch;
import org.rocksdb.WriteOptions;
public sealed interface RocksDBColumn permits AbstractRocksDBColumn {
/**
* This method should not modify or move the writerIndex/readerIndex of the buffers inside the range
*/
2022-05-12 19:14:27 +02:00
@NotNull RocksIteratorObj newRocksIterator(boolean allowNettyDirect,
ReadOptions readOptions,
LLRange range,
boolean reverse) throws RocksDBException;
default byte @Nullable [] get(@NotNull ReadOptions readOptions,
2021-11-12 02:05:44 +01:00
byte[] key,
boolean existsAlmostCertainly)
throws RocksDBException {
var allocator = getAllocator();
try (var keyBuf = allocator.allocate(key.length)) {
keyBuf.writeBytes(key);
2022-03-16 19:19:26 +01:00
try (var result = this.get(readOptions, keyBuf)) {
if (result == null) {
return null;
}
return LLUtils.toArray(result);
2021-11-12 02:05:44 +01:00
}
}
}
2021-10-20 01:51:34 +02:00
@Nullable
Buffer get(@NotNull ReadOptions readOptions, Buffer key) throws RocksDBException;
2021-10-20 01:51:34 +02:00
boolean exists(@NotNull ReadOptions readOptions, Buffer key) throws RocksDBException;
2021-10-20 01:51:34 +02:00
boolean mayExists(@NotNull ReadOptions readOptions, Buffer key) throws RocksDBException;
2022-04-19 23:23:12 +02:00
void put(@NotNull WriteOptions writeOptions, Buffer key, Buffer value) throws RocksDBException;
2021-10-20 01:51:34 +02:00
default void put(@NotNull WriteOptions writeOptions, byte[] key, byte[] value) throws RocksDBException {
2021-11-12 02:05:44 +01:00
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
}
}
}
@NotNull RocksIteratorObj newIterator(@NotNull ReadOptions readOptions, @Nullable Buffer min, @Nullable Buffer max);
2021-10-20 01:51:34 +02:00
@NotNull UpdateAtomicResult updateAtomic(@NotNull ReadOptions readOptions,
@NotNull WriteOptions writeOptions,
2022-05-12 19:14:27 +02:00
Buffer key,
BinarySerializationFunction updater,
2022-03-02 18:33:58 +01:00
UpdateAtomicResultMode returnMode) throws RocksDBException, IOException;
2021-10-20 01:51:34 +02: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-10-20 01:51:34 +02: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;
2021-10-20 01:51:34 +02:00
void suggestCompactRange() throws RocksDBException;
void compactRange(byte[] begin, byte[] end, CompactRangeOptions options) throws RocksDBException;
2021-10-20 01:51:34 +02:00
void flush(FlushOptions options) throws RocksDBException;
2021-10-20 01:51:34 +02:00
void flushWal(boolean sync) throws RocksDBException;
long getLongProperty(String property) throws RocksDBException;
ColumnFamilyHandle getColumnFamilyHandle();
2021-10-20 01:51:34 +02:00
BufferAllocator getAllocator();
MeterRegistry getMeterRegistry();
2021-10-20 01:51:34 +02:00
boolean supportsTransactions();
void forceCompaction(int volumeId) throws RocksDBException;
2021-10-20 01:51:34 +02:00
}