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

109 lines
3.7 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 java.util.List;
2020-12-07 22:15:18 +01:00
import java.util.Map.Entry;
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;
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 {
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();
Mono<Boolean> update(ByteBuf key, Function<@Nullable ByteBuf, @Nullable ByteBuf> updater, boolean existsAlmostCertainly);
2021-03-18 16:19:41 +01:00
default Mono<Boolean> update(ByteBuf key, Function<@Nullable ByteBuf, @Nullable ByteBuf> updater) {
2021-03-18 16:19:41 +01:00
return update(key, updater, false);
}
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
Flux<Entry<ByteBuf, ByteBuf>> getMulti(@Nullable LLSnapshot snapshot, Flux<ByteBuf> keys, boolean existsAlmostCertainly);
2021-03-18 16:19:41 +01:00
default Flux<Entry<ByteBuf, ByteBuf>> getMulti(@Nullable LLSnapshot snapshot, Flux<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
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);
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
}