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

140 lines
4.6 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;
import java.util.List;
2020-12-07 22:15:18 +01:00
import java.util.Map.Entry;
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, ByteBuf key, boolean existsAlmostCertainly);
default Mono<ByteBuf> get(@Nullable LLSnapshot snapshot, 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(ByteBuf key, ByteBuf value, LLDictionaryResultType resultType);
2020-12-07 22:15:18 +01:00
2021-05-02 19:18:15 +02:00
Mono<UpdateMode> getUpdateMode();
2021-05-08 03:09:00 +02:00
default Mono<ByteBuf> update(ByteBuf key,
Function<@Nullable ByteBuf, @Nullable ByteBuf> updater,
UpdateReturnMode updateReturnMode,
boolean existsAlmostCertainly) {
return this
.updateAndGetDelta(key, updater, existsAlmostCertainly)
.transform(prev -> LLUtils.resolveDelta(prev, updateReturnMode));
}
default Mono<ByteBuf> update(ByteBuf key,
Function<@Nullable ByteBuf, @Nullable ByteBuf> updater,
UpdateReturnMode returnMode) {
return update(key, updater, returnMode, false);
}
Mono<Delta<ByteBuf>> updateAndGetDelta(ByteBuf key,
Function<@Nullable ByteBuf, @Nullable ByteBuf> updater,
boolean existsAlmostCertainly);
2021-03-18 16:19:41 +01:00
2021-05-08 03:09:00 +02:00
default Mono<Delta<ByteBuf>> updateAndGetDelta(ByteBuf key,
Function<@Nullable ByteBuf, @Nullable ByteBuf> updater) {
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(ByteBuf key, LLDictionaryResultType resultType);
2020-12-07 22:15:18 +01:00
2021-07-17 11:52:08 +02:00
<K> Flux<Tuple3<K, ByteBuf, ByteBuf>> getMulti(@Nullable LLSnapshot snapshot,
Flux<Tuple2<K, ByteBuf>> keys,
boolean existsAlmostCertainly);
2021-03-18 16:19:41 +01:00
2021-07-17 11:52:08 +02:00
default <K> Flux<Tuple3<K, ByteBuf, 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
Flux<Entry<ByteBuf, ByteBuf>> putMulti(Flux<Entry<ByteBuf, ByteBuf>> 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,
BiFunction<ByteBuf, X, ByteBuf> updateFunction);
Flux<Entry<ByteBuf, ByteBuf>> getRange(@Nullable LLSnapshot snapshot, LLRange range, boolean existsAlmostCertainly);
2020-12-07 22:15:18 +01:00
default Flux<Entry<ByteBuf, ByteBuf>> getRange(@Nullable LLSnapshot snapshot, LLRange range) {
2021-03-18 16:19:41 +01:00
return getRange(snapshot, range, false);
}
Flux<List<Entry<ByteBuf, ByteBuf>>> getRangeGrouped(@Nullable LLSnapshot snapshot,
2021-03-18 16:19:41 +01:00
LLRange range,
int prefixLength,
boolean existsAlmostCertainly);
default Flux<List<Entry<ByteBuf, ByteBuf>>> getRangeGrouped(@Nullable LLSnapshot snapshot,
2021-03-18 16:19:41 +01:00
LLRange range,
int prefixLength) {
return getRangeGrouped(snapshot, range, prefixLength, false);
}
Flux<ByteBuf> getRangeKeys(@Nullable LLSnapshot snapshot, LLRange range);
Flux<List<ByteBuf>> getRangeKeysGrouped(@Nullable LLSnapshot snapshot, LLRange range, int prefixLength);
2021-03-14 13:24:46 +01:00
Flux<ByteBuf> getRangeKeyPrefixes(@Nullable LLSnapshot snapshot, LLRange range, int prefixLength);
Flux<BadBlock> badBlocks(LLRange range);
2021-05-02 19:18:15 +02:00
Mono<Void> setRange(LLRange range, Flux<Entry<ByteBuf, ByteBuf>> entries);
2020-12-07 22:15:18 +01:00
2021-03-18 16:19:41 +01:00
default Mono<Void> replaceRange(LLRange range,
boolean canKeysChange,
Function<Entry<ByteBuf, ByteBuf>, Mono<Entry<ByteBuf, ByteBuf>>> 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
2021-03-18 16:19:41 +01:00
default Mono<Void> replaceRange(LLRange range,
boolean canKeysChange,
Function<Entry<ByteBuf, ByteBuf>, Mono<Entry<ByteBuf, ByteBuf>>> entriesReplacer) {
2021-03-18 16:19:41 +01:00
return replaceRange(range, canKeysChange, entriesReplacer, false);
}
2021-01-30 00:24:55 +01:00
Mono<Boolean> isRangeEmpty(@Nullable LLSnapshot snapshot, LLRange range);
2020-12-07 22:15:18 +01:00
2021-01-30 00:24:55 +01:00
Mono<Long> sizeRange(@Nullable LLSnapshot snapshot, LLRange range, boolean fast);
2020-12-07 22:15:18 +01:00
Mono<Entry<ByteBuf, ByteBuf>> getOne(@Nullable LLSnapshot snapshot, LLRange range);
Mono<ByteBuf> getOneKey(@Nullable LLSnapshot snapshot, LLRange range);
Mono<Entry<ByteBuf, ByteBuf>> removeOne(LLRange range);
2020-12-07 22:15:18 +01:00
}