package it.cavallium.dbengine.database; import io.net5.buffer.api.Buffer; import io.net5.buffer.api.BufferAllocator; import io.net5.buffer.api.Send; import it.cavallium.dbengine.client.BadBlock; import it.cavallium.dbengine.database.serialization.KVSerializationFunction; import it.cavallium.dbengine.database.serialization.SerializationFunction; import java.util.List; import java.util.Optional; import java.util.function.Function; import org.jetbrains.annotations.Nullable; import org.warp.commonutils.concurrency.atomicity.NotAtomic; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @SuppressWarnings("unused") @NotAtomic public interface LLDictionary extends LLKeyValueDatabaseStructure { String getColumnName(); BufferAllocator getAllocator(); Mono> get(@Nullable LLSnapshot snapshot, Mono> key, boolean existsAlmostCertainly); default Mono> get(@Nullable LLSnapshot snapshot, Mono> key) { return get(snapshot, key, false); } Mono> put(Mono> key, Mono> value, LLDictionaryResultType resultType); Mono getUpdateMode(); default Mono> update(Mono> key, SerializationFunction<@Nullable Send, @Nullable Buffer> updater, UpdateReturnMode updateReturnMode, boolean existsAlmostCertainly) { return this .updateAndGetDelta(key, updater, existsAlmostCertainly) .transform(prev -> LLUtils.resolveLLDelta(prev, updateReturnMode)); } default Mono> update(Mono> key, SerializationFunction<@Nullable Send, @Nullable Buffer> updater, UpdateReturnMode returnMode) { return update(key, updater, returnMode, false); } Mono> updateAndGetDelta(Mono> key, SerializationFunction<@Nullable Send, @Nullable Buffer> updater, boolean existsAlmostCertainly); default Mono> updateAndGetDelta(Mono> key, SerializationFunction<@Nullable Send, @Nullable Buffer> updater) { return updateAndGetDelta(key, updater, false); } Mono clear(); Mono> remove(Mono> key, LLDictionaryResultType resultType); Flux> getMulti(@Nullable LLSnapshot snapshot, Flux> keys, boolean existsAlmostCertainly); default Flux> getMulti(@Nullable LLSnapshot snapshot, Flux> keys) { return getMulti(snapshot, keys, false); } Flux> putMulti(Flux> entries, boolean getOldValues); Flux updateMulti(Flux keys, Flux> serializedKeys, KVSerializationFunction, @Nullable Buffer> updateFunction); Flux> getRange(@Nullable LLSnapshot snapshot, Mono> range, boolean existsAlmostCertainly); default Flux> getRange(@Nullable LLSnapshot snapshot, Mono> range) { return getRange(snapshot, range, false); } Flux>> getRangeGrouped(@Nullable LLSnapshot snapshot, Mono> range, int prefixLength, boolean existsAlmostCertainly); default Flux>> getRangeGrouped(@Nullable LLSnapshot snapshot, Mono> range, int prefixLength) { return getRangeGrouped(snapshot, range, prefixLength, false); } Flux> getRangeKeys(@Nullable LLSnapshot snapshot, Mono> range); Flux>> getRangeKeysGrouped(@Nullable LLSnapshot snapshot, Mono> range, int prefixLength); Flux> getRangeKeyPrefixes(@Nullable LLSnapshot snapshot, Mono> range, int prefixLength); Flux badBlocks(Mono> range); Mono setRange(Mono> range, Flux> entries); default Mono replaceRange(Mono> range, boolean canKeysChange, Function, Mono>> entriesReplacer, boolean existsAlmostCertainly) { return Mono.defer(() -> { if (canKeysChange) { return this .setRange(range, this .getRange(null, range, existsAlmostCertainly) .flatMap(entriesReplacer) ); } else { return this .putMulti(this .getRange(null, range, existsAlmostCertainly) .flatMap(entriesReplacer), false) .then(); } }); } default Mono replaceRange(Mono> range, boolean canKeysChange, Function, Mono>> entriesReplacer) { return replaceRange(range, canKeysChange, entriesReplacer, false); } Mono isRangeEmpty(@Nullable LLSnapshot snapshot, Mono> range); Mono sizeRange(@Nullable LLSnapshot snapshot, Mono> range, boolean fast); Mono> getOne(@Nullable LLSnapshot snapshot, Mono> range); Mono> getOneKey(@Nullable LLSnapshot snapshot, Mono> range); Mono> removeOne(Mono> range); }