2021-10-20 01:51:34 +02:00
|
|
|
package it.cavallium.dbengine.database.disk;
|
|
|
|
|
2021-10-30 11:13:46 +02:00
|
|
|
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;
|
2022-03-30 15:15:53 +02:00
|
|
|
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;
|
|
|
|
import it.cavallium.dbengine.database.disk.rocksdb.RocksObj;
|
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 {
|
|
|
|
|
2022-03-30 15:15:53 +02:00
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
RocksObj<ReadOptions> readOptions,
|
2022-03-30 15:15:53 +02:00
|
|
|
LLRange range,
|
|
|
|
boolean reverse) throws RocksDBException;
|
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
default byte @Nullable [] get(@NotNull RocksObj<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
|
2022-05-12 19:14:27 +02:00
|
|
|
Buffer get(@NotNull RocksObj<ReadOptions> readOptions, Buffer key) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
boolean exists(@NotNull RocksObj<ReadOptions> readOptions, Buffer key) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
boolean mayExists(@NotNull RocksObj<ReadOptions> readOptions, Buffer key) throws RocksDBException;
|
2022-04-19 23:23:12 +02:00
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
void put(@NotNull RocksObj<WriteOptions> writeOptions, Buffer key, Buffer value) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
default void put(@NotNull RocksObj<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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
@NotNull RocksIteratorObj newIterator(@NotNull RocksObj<ReadOptions> readOptions, @Nullable Buffer min, @Nullable Buffer max);
|
2021-10-20 01:51:34 +02:00
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
@NotNull UpdateAtomicResult updateAtomic(@NotNull RocksObj<ReadOptions> readOptions,
|
|
|
|
@NotNull RocksObj<WriteOptions> writeOptions,
|
|
|
|
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
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
void delete(RocksObj<WriteOptions> writeOptions, Buffer key) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
void delete(RocksObj<WriteOptions> writeOptions, byte[] key) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
List<byte[]> multiGetAsList(RocksObj<ReadOptions> readOptions, List<byte[]> keys) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
void write(RocksObj<WriteOptions> writeOptions, WriteBatch writeBatch) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
|
|
|
|
void suggestCompactRange() throws RocksDBException;
|
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
void compactRange(byte[] begin, byte[] end, RocksObj<CompactRangeOptions> options) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
void flush(RocksObj<FlushOptions> options) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
|
|
|
|
void flushWal(boolean sync) throws RocksDBException;
|
|
|
|
|
|
|
|
long getLongProperty(String property) throws RocksDBException;
|
|
|
|
|
2022-05-12 19:14:27 +02:00
|
|
|
RocksObj<ColumnFamilyHandle> getColumnFamilyHandle();
|
2021-10-20 01:51:34 +02:00
|
|
|
|
|
|
|
BufferAllocator getAllocator();
|
|
|
|
|
2021-10-30 11:13:46 +02:00
|
|
|
MeterRegistry getMeterRegistry();
|
|
|
|
|
2021-10-20 01:51:34 +02:00
|
|
|
boolean supportsTransactions();
|
2022-04-26 17:12:22 +02:00
|
|
|
|
|
|
|
void forceCompaction(int volumeId) throws RocksDBException;
|
2021-10-20 01:51:34 +02:00
|
|
|
}
|