CavalliumDBEngine/src/main/java/it/cavallium/dbengine/database/LLDictionary.java

143 lines
4.8 KiB
Java
Raw Normal View History

2020-12-07 22:15:18 +01:00
package it.cavallium.dbengine.database;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import it.cavallium.dbengine.client.BadBlock;
2021-08-22 21:23:22 +02:00
import it.cavallium.dbengine.database.serialization.BiSerializationFunction;
import it.cavallium.dbengine.database.serialization.SerializationFunction;
import java.util.List;
2020-12-07 22:15:18 +01:00
import java.util.Map.Entry;
2021-07-23 15:20:33 +02:00
import java.util.Optional;
2021-07-17 11:52:08 +02:00
import java.util.function.BiFunction;
2021-01-30 00:24:55 +01:00
import java.util.function.Function;
2020-12-07 22:15:18 +01:00
import org.jetbrains.annotations.Nullable;
import org.warp.commonutils.concurrency.atomicity.NotAtomic;
2021-01-30 00:24:55 +01:00
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
2021-05-08 03:09:00 +02:00
import reactor.util.function.Tuple2;
2021-07-17 11:52:08 +02:00
import reactor.util.function.Tuple3;
2020-12-07 22:15:18 +01:00
2021-02-03 14:37:02 +01:00
@SuppressWarnings("unused")
2020-12-07 22:15:18 +01:00
@NotAtomic
public interface LLDictionary extends LLKeyValueDatabaseStructure {
2021-06-26 02:35:33 +02:00
String getColumnName();
ByteBufAllocator getAllocator();
2021-03-18 16:19:41 +01:00
Mono<ByteBuf> get(@Nullable LLSnapshot snapshot, Mono<ByteBuf> key, boolean existsAlmostCertainly);
default Mono<ByteBuf> get(@Nullable LLSnapshot snapshot, Mono<ByteBuf> key) {
2021-03-18 16:19:41 +01:00
return get(snapshot, key, false);
}
2020-12-07 22:15:18 +01:00
Mono<ByteBuf> put(Mono<ByteBuf> key, Mono<ByteBuf> value, LLDictionaryResultType resultType);
2020-12-07 22:15:18 +01:00
2021-05-02 19:18:15 +02:00
Mono<UpdateMode> getUpdateMode();
default Mono<ByteBuf> update(Mono<ByteBuf> key,
2021-08-22 21:23:22 +02:00
SerializationFunction<@Nullable ByteBuf, @Nullable ByteBuf> updater,
2021-05-08 03:09:00 +02:00
UpdateReturnMode updateReturnMode,
boolean existsAlmostCertainly) {
return this
.updateAndGetDelta(key, updater, existsAlmostCertainly)
.transform(prev -> LLUtils.resolveDelta(prev, updateReturnMode));
}
default Mono<ByteBuf> update(Mono<ByteBuf> key,
2021-08-22 21:23:22 +02:00
SerializationFunction<@Nullable ByteBuf, @Nullable ByteBuf> updater,
2021-05-08 03:09:00 +02:00
UpdateReturnMode returnMode) {
return update(key, updater, returnMode, false);
}
Mono<Delta<ByteBuf>> updateAndGetDelta(Mono<ByteBuf> key,
2021-08-22 21:23:22 +02:00
SerializationFunction<@Nullable ByteBuf, @Nullable ByteBuf> updater,
2021-05-08 03:09:00 +02:00
boolean existsAlmostCertainly);
2021-03-18 16:19:41 +01:00
default Mono<Delta<ByteBuf>> updateAndGetDelta(Mono<ByteBuf> key,
2021-08-22 21:23:22 +02:00
SerializationFunction<@Nullable ByteBuf, @Nullable ByteBuf> updater) {
2021-05-08 03:09:00 +02:00
return updateAndGetDelta(key, updater, false);
2021-03-18 16:19:41 +01:00
}
2021-02-06 19:21:31 +01:00
2021-03-14 03:13:19 +01:00
Mono<Void> clear();
Mono<ByteBuf> remove(Mono<ByteBuf> key, LLDictionaryResultType resultType);
2020-12-07 22:15:18 +01:00
2021-07-23 15:20:33 +02:00
<K> Flux<Tuple3<K, ByteBuf, Optional<ByteBuf>>> getMulti(@Nullable LLSnapshot snapshot,
2021-07-17 11:52:08 +02:00
Flux<Tuple2<K, ByteBuf>> keys,
boolean existsAlmostCertainly);
2021-03-18 16:19:41 +01:00
2021-07-23 15:20:33 +02:00
default <K> Flux<Tuple3<K, ByteBuf, Optional<ByteBuf>>> getMulti(@Nullable LLSnapshot snapshot, Flux<Tuple2<K, ByteBuf>> keys) {
2021-03-18 16:19:41 +01:00
return getMulti(snapshot, keys, false);
}
2020-12-07 22:15:18 +01:00
2021-08-28 22:42:51 +02:00
Flux<LLEntry> putMulti(Flux<LLEntry> entries, boolean getOldValues);
2020-12-07 22:15:18 +01:00
2021-07-17 11:52:08 +02:00
<X> Flux<ExtraKeyOperationResult<ByteBuf, X>> updateMulti(Flux<Tuple2<ByteBuf, X>> entries,
2021-08-22 21:23:22 +02:00
BiSerializationFunction<ByteBuf, X, ByteBuf> updateFunction);
2021-07-17 11:52:08 +02:00
2021-08-28 22:42:51 +02:00
Flux<LLEntry> getRange(@Nullable LLSnapshot snapshot, Mono<LLRange> range, boolean existsAlmostCertainly);
2020-12-07 22:15:18 +01:00
2021-08-28 22:42:51 +02:00
default Flux<LLEntry> getRange(@Nullable LLSnapshot snapshot, Mono<LLRange> range) {
2021-03-18 16:19:41 +01:00
return getRange(snapshot, range, false);
}
2021-08-28 22:42:51 +02:00
Flux<List<LLEntry>> getRangeGrouped(@Nullable LLSnapshot snapshot,
Mono<LLRange> range,
2021-03-18 16:19:41 +01:00
int prefixLength,
boolean existsAlmostCertainly);
2021-08-28 22:42:51 +02:00
default Flux<List<LLEntry>> getRangeGrouped(@Nullable LLSnapshot snapshot,
Mono<LLRange> range,
2021-03-18 16:19:41 +01:00
int prefixLength) {
return getRangeGrouped(snapshot, range, prefixLength, false);
}
Flux<ByteBuf> getRangeKeys(@Nullable LLSnapshot snapshot, Mono<LLRange> range);
Flux<List<ByteBuf>> getRangeKeysGrouped(@Nullable LLSnapshot snapshot, Mono<LLRange> range, int prefixLength);
2021-03-14 13:24:46 +01:00
Flux<ByteBuf> getRangeKeyPrefixes(@Nullable LLSnapshot snapshot, Mono<LLRange> range, int prefixLength);
Flux<BadBlock> badBlocks(Mono<LLRange> range);
2021-08-28 22:42:51 +02:00
Mono<Void> setRange(Mono<LLRange> range, Flux<LLEntry> entries);
2020-12-07 22:15:18 +01:00
default Mono<Void> replaceRange(Mono<LLRange> range,
2021-03-18 16:19:41 +01:00
boolean canKeysChange,
2021-08-28 22:42:51 +02:00
Function<LLEntry, Mono<LLEntry>> entriesReplacer,
2021-03-18 16:19:41 +01:00
boolean existsAlmostCertainly) {
return Mono.defer(() -> {
if (canKeysChange) {
return this
.setRange(range, this
2021-03-18 16:19:41 +01:00
.getRange(null, range, existsAlmostCertainly)
2021-05-02 19:18:15 +02:00
.flatMap(entriesReplacer)
);
} else {
return this
.putMulti(this
2021-03-18 16:19:41 +01:00
.getRange(null, range, existsAlmostCertainly)
.flatMap(entriesReplacer), false)
.then();
}
});
2021-01-30 00:24:55 +01:00
}
2020-12-07 22:15:18 +01:00
default Mono<Void> replaceRange(Mono<LLRange> range,
2021-03-18 16:19:41 +01:00
boolean canKeysChange,
2021-08-28 22:42:51 +02:00
Function<LLEntry, Mono<LLEntry>> entriesReplacer) {
2021-03-18 16:19:41 +01:00
return replaceRange(range, canKeysChange, entriesReplacer, false);
}
Mono<Boolean> isRangeEmpty(@Nullable LLSnapshot snapshot, Mono<LLRange> range);
2020-12-07 22:15:18 +01:00
Mono<Long> sizeRange(@Nullable LLSnapshot snapshot, Mono<LLRange> range, boolean fast);
2020-12-07 22:15:18 +01:00
2021-08-28 22:42:51 +02:00
Mono<LLEntry> getOne(@Nullable LLSnapshot snapshot, Mono<LLRange> range);
Mono<ByteBuf> getOneKey(@Nullable LLSnapshot snapshot, Mono<LLRange> range);
2021-08-28 22:42:51 +02:00
Mono<LLEntry> removeOne(Mono<LLRange> range);
2020-12-07 22:15:18 +01:00
}