2020-12-07 22:15:18 +01:00
|
|
|
package it.cavallium.dbengine.database;
|
|
|
|
|
2021-09-17 16:56:28 +02:00
|
|
|
import io.net5.buffer.api.Buffer;
|
|
|
|
import io.net5.buffer.api.BufferAllocator;
|
|
|
|
import io.net5.buffer.api.Send;
|
2021-06-27 11:58:12 +02:00
|
|
|
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;
|
2021-02-02 00:09:46 +01:00
|
|
|
import java.util.List;
|
2021-07-23 15:20:33 +02:00
|
|
|
import java.util.Optional;
|
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();
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
BufferAllocator getAllocator();
|
2021-03-18 16:19:41 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Send<Buffer>> get(@Nullable LLSnapshot snapshot, Mono<Send<Buffer>> key, boolean existsAlmostCertainly);
|
2021-04-30 19:15:04 +02:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
default Mono<Send<Buffer>> get(@Nullable LLSnapshot snapshot, Mono<Send<Buffer>> key) {
|
2021-03-18 16:19:41 +01:00
|
|
|
return get(snapshot, key, false);
|
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Send<Buffer>> put(Mono<Send<Buffer>> key, Mono<Send<Buffer>> value, LLDictionaryResultType resultType);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-05-02 19:18:15 +02:00
|
|
|
Mono<UpdateMode> getUpdateMode();
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
default Mono<Send<Buffer>> update(Mono<Send<Buffer>> key,
|
|
|
|
SerializationFunction<@Nullable Send<Buffer>, @Nullable Send<Buffer>> updater,
|
2021-05-08 03:09:00 +02:00
|
|
|
UpdateReturnMode updateReturnMode,
|
|
|
|
boolean existsAlmostCertainly) {
|
|
|
|
return this
|
|
|
|
.updateAndGetDelta(key, updater, existsAlmostCertainly)
|
2021-08-29 23:18:03 +02:00
|
|
|
.transform(prev -> LLUtils.resolveLLDelta(prev, updateReturnMode));
|
2021-05-08 03:09:00 +02:00
|
|
|
}
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
default Mono<Send<Buffer>> update(Mono<Send<Buffer>> key,
|
|
|
|
SerializationFunction<@Nullable Send<Buffer>, @Nullable Send<Buffer>> updater,
|
2021-05-08 03:09:00 +02:00
|
|
|
UpdateReturnMode returnMode) {
|
|
|
|
return update(key, updater, returnMode, false);
|
|
|
|
}
|
|
|
|
|
2021-09-08 00:22:39 +02:00
|
|
|
Mono<Send<LLDelta>> updateAndGetDelta(Mono<Send<Buffer>> key,
|
2021-08-29 23:18:03 +02:00
|
|
|
SerializationFunction<@Nullable Send<Buffer>, @Nullable Send<Buffer>> updater,
|
2021-05-08 03:09:00 +02:00
|
|
|
boolean existsAlmostCertainly);
|
2021-03-18 16:19:41 +01:00
|
|
|
|
2021-09-08 00:22:39 +02:00
|
|
|
default Mono<Send<LLDelta>> updateAndGetDelta(Mono<Send<Buffer>> key,
|
2021-08-29 23:18:03 +02:00
|
|
|
SerializationFunction<@Nullable Send<Buffer>, @Nullable Send<Buffer>> 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();
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Send<Buffer>> remove(Mono<Send<Buffer>> key, LLDictionaryResultType resultType);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
<K> Flux<Tuple3<K, Send<Buffer>, Optional<Send<Buffer>>>> getMulti(@Nullable LLSnapshot snapshot,
|
|
|
|
Flux<Tuple2<K, Send<Buffer>>> keys,
|
2021-07-17 11:52:08 +02:00
|
|
|
boolean existsAlmostCertainly);
|
2021-03-18 16:19:41 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
default <K> Flux<Tuple3<K, Send<Buffer>, Optional<Send<Buffer>>>> getMulti(@Nullable LLSnapshot snapshot,
|
|
|
|
Flux<Tuple2<K, Send<Buffer>>> keys) {
|
2021-03-18 16:19:41 +01:00
|
|
|
return getMulti(snapshot, keys, false);
|
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Flux<Send<LLEntry>> putMulti(Flux<Send<LLEntry>> entries, boolean getOldValues);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
<X> Flux<ExtraKeyOperationResult<Send<Buffer>, X>> updateMulti(Flux<Tuple2<Send<Buffer>, X>> entries,
|
|
|
|
BiSerializationFunction<Send<Buffer>, X, Send<Buffer>> updateFunction);
|
2021-07-17 11:52:08 +02:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Flux<Send<LLEntry>> getRange(@Nullable LLSnapshot snapshot, Mono<Send<LLRange>> range, boolean existsAlmostCertainly);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
default Flux<Send<LLEntry>> getRange(@Nullable LLSnapshot snapshot, Mono<Send<LLRange>> range) {
|
2021-03-18 16:19:41 +01:00
|
|
|
return getRange(snapshot, range, false);
|
|
|
|
}
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Flux<List<Send<LLEntry>>> getRangeGrouped(@Nullable LLSnapshot snapshot,
|
|
|
|
Mono<Send<LLRange>> range,
|
2021-03-18 16:19:41 +01:00
|
|
|
int prefixLength,
|
|
|
|
boolean existsAlmostCertainly);
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
default Flux<List<Send<LLEntry>>> getRangeGrouped(@Nullable LLSnapshot snapshot,
|
|
|
|
Mono<Send<LLRange>> range,
|
2021-03-18 16:19:41 +01:00
|
|
|
int prefixLength) {
|
|
|
|
return getRangeGrouped(snapshot, range, prefixLength, false);
|
|
|
|
}
|
2021-02-02 00:09:46 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Flux<Send<Buffer>> getRangeKeys(@Nullable LLSnapshot snapshot, Mono<Send<LLRange>> range);
|
2021-01-30 19:27:59 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Flux<List<Send<Buffer>>> getRangeKeysGrouped(@Nullable LLSnapshot snapshot, Mono<Send<LLRange>> range, int prefixLength);
|
2021-03-14 13:24:46 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Flux<Send<Buffer>> getRangeKeyPrefixes(@Nullable LLSnapshot snapshot, Mono<Send<LLRange>> range, int prefixLength);
|
2021-02-02 00:09:46 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Flux<BadBlock> badBlocks(Mono<Send<LLRange>> range);
|
2021-06-27 11:58:12 +02:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Void> setRange(Mono<Send<LLRange>> range, Flux<Send<LLEntry>> entries);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
default Mono<Void> replaceRange(Mono<Send<LLRange>> range,
|
2021-03-18 16:19:41 +01:00
|
|
|
boolean canKeysChange,
|
2021-08-29 23:18:03 +02:00
|
|
|
Function<Send<LLEntry>, Mono<Send<LLEntry>>> entriesReplacer,
|
2021-03-18 16:19:41 +01:00
|
|
|
boolean existsAlmostCertainly) {
|
2021-02-02 00:09:46 +01:00
|
|
|
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)
|
|
|
|
);
|
2021-02-02 00:09:46 +01:00
|
|
|
} else {
|
|
|
|
return this
|
|
|
|
.putMulti(this
|
2021-03-18 16:19:41 +01:00
|
|
|
.getRange(null, range, existsAlmostCertainly)
|
2021-02-02 00:09:46 +01:00
|
|
|
.flatMap(entriesReplacer), false)
|
|
|
|
.then();
|
|
|
|
}
|
|
|
|
});
|
2021-01-30 00:24:55 +01:00
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
default Mono<Void> replaceRange(Mono<Send<LLRange>> range,
|
2021-03-18 16:19:41 +01:00
|
|
|
boolean canKeysChange,
|
2021-08-29 23:18:03 +02:00
|
|
|
Function<Send<LLEntry>, Mono<Send<LLEntry>>> entriesReplacer) {
|
2021-03-18 16:19:41 +01:00
|
|
|
return replaceRange(range, canKeysChange, entriesReplacer, false);
|
|
|
|
}
|
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Boolean> isRangeEmpty(@Nullable LLSnapshot snapshot, Mono<Send<LLRange>> range);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Long> sizeRange(@Nullable LLSnapshot snapshot, Mono<Send<LLRange>> range, boolean fast);
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Send<LLEntry>> getOne(@Nullable LLSnapshot snapshot, Mono<Send<LLRange>> range);
|
2021-02-02 15:36:11 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Send<Buffer>> getOneKey(@Nullable LLSnapshot snapshot, Mono<Send<LLRange>> range);
|
2021-02-02 15:36:11 +01:00
|
|
|
|
2021-08-29 23:18:03 +02:00
|
|
|
Mono<Send<LLEntry>> removeOne(Mono<Send<LLRange>> range);
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|