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

106 lines
3.3 KiB
Java
Raw Normal View History

2020-12-07 22:15:18 +01:00
package it.cavallium.dbengine.database;
2022-03-16 13:47:56 +01:00
import io.netty5.buffer.api.Buffer;
import io.netty5.buffer.api.BufferAllocator;
import io.netty5.buffer.api.Send;
import it.cavallium.dbengine.client.BadBlock;
import it.cavallium.dbengine.database.disk.BinarySerializationFunction;
2021-11-08 10:49:59 +01:00
import it.cavallium.dbengine.database.serialization.KVSerializationFunction;
2021-08-22 21:23:22 +02:00
import it.cavallium.dbengine.database.serialization.SerializationFunction;
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;
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
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
Mono<Buffer> get(@Nullable LLSnapshot snapshot, Mono<Buffer> key);
2020-12-07 22:15:18 +01:00
Mono<Buffer> put(Mono<Buffer> key, Mono<Buffer> value, LLDictionaryResultType resultType);
2020-12-07 22:15:18 +01:00
2021-05-02 19:18:15 +02:00
Mono<UpdateMode> getUpdateMode();
default Mono<Buffer> update(Mono<Buffer> key,
BinarySerializationFunction updater,
2022-03-02 18:33:58 +01:00
UpdateReturnMode updateReturnMode) {
2021-05-08 03:09:00 +02:00
return this
2022-03-02 18:33:58 +01:00
.updateAndGetDelta(key, updater)
2021-08-29 23:18:03 +02:00
.transform(prev -> LLUtils.resolveLLDelta(prev, updateReturnMode));
2021-05-08 03:09:00 +02:00
}
Mono<LLDelta> updateAndGetDelta(Mono<Buffer> key, BinarySerializationFunction updater);
2021-02-06 19:21:31 +01:00
2021-03-14 03:13:19 +01:00
Mono<Void> clear();
Mono<Buffer> remove(Mono<Buffer> key, LLDictionaryResultType resultType);
2020-12-07 22:15:18 +01:00
2022-05-21 15:28:52 +02:00
Flux<OptionalBuf> getMulti(@Nullable LLSnapshot snapshot, Flux<Buffer> keys);
2020-12-07 22:15:18 +01:00
Mono<Void> putMulti(Flux<LLEntry> entries);
2020-12-07 22:15:18 +01:00
<K> Flux<Boolean> updateMulti(Flux<K> keys, Flux<Buffer> serializedKeys,
KVSerializationFunction<K, @Nullable Buffer, @Nullable Buffer> updateFunction);
2021-07-17 11:52:08 +02:00
Flux<LLEntry> getRange(@Nullable LLSnapshot snapshot,
Mono<LLRange> range,
2022-03-24 23:56:23 +01:00
boolean reverse,
boolean smallRange);
Flux<List<LLEntry>> getRangeGrouped(@Nullable LLSnapshot snapshot,
Mono<LLRange> range,
2022-03-24 23:56:23 +01:00
int prefixLength,
boolean smallRange);
Flux<Buffer> getRangeKeys(@Nullable LLSnapshot snapshot,
Mono<LLRange> range,
2022-03-24 23:56:23 +01:00
boolean reverse,
boolean smallRange);
Flux<List<Buffer>> getRangeKeysGrouped(@Nullable LLSnapshot snapshot,
Mono<LLRange> range,
2022-03-24 23:56:23 +01:00
int prefixLength,
boolean smallRange);
Flux<Buffer> getRangeKeyPrefixes(@Nullable LLSnapshot snapshot,
Mono<LLRange> range,
2022-03-24 23:56:23 +01:00
int prefixLength,
boolean smallRange);
Flux<BadBlock> badBlocks(Mono<LLRange> range);
Mono<Void> setRange(Mono<LLRange> range, Flux<LLEntry> entries, boolean smallRange);
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,
Function<LLEntry, Mono<LLEntry>> entriesReplacer,
2022-03-24 23:56:23 +01:00
boolean smallRange) {
return Mono.defer(() -> {
if (canKeysChange) {
return this
.setRange(range, this
2022-03-24 23:56:23 +01:00
.getRange(null, range, false, smallRange)
.flatMap(entriesReplacer), smallRange);
} else {
2022-03-24 23:56:23 +01:00
return this.putMulti(this.getRange(null, range, false, smallRange).flatMap(entriesReplacer));
}
});
2021-01-30 00:24:55 +01:00
}
2020-12-07 22:15:18 +01:00
Mono<Boolean> isRangeEmpty(@Nullable LLSnapshot snapshot, Mono<LLRange> range, boolean fillCache);
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
Mono<LLEntry> getOne(@Nullable LLSnapshot snapshot, Mono<LLRange> range);
Mono<Buffer> getOneKey(@Nullable LLSnapshot snapshot, Mono<LLRange> range);
Mono<LLEntry> removeOne(Mono<LLRange> range);
2020-12-07 22:15:18 +01:00
}