Update containsKey

This commit is contained in:
Andrea Cavalli 2022-01-26 21:30:08 +01:00
parent 574a35907d
commit 5615c8019a

View File

@ -356,18 +356,6 @@ public class LLLocalDictionary implements LLDictionary {
}); });
} }
private Mono<Boolean> containsKey(@Nullable LLSnapshot snapshot, Mono<Send<Buffer>> keyMono) {
return keyMono
.publishOn(dbScheduler)
.handle((keySend, sink) -> {
try (var key = keySend.receive()) {
sink.next(containsKey(snapshot, key));
} catch (Throwable ex) {
sink.error(ex);
}
});
}
private boolean containsKey(@Nullable LLSnapshot snapshot, Buffer key) throws RocksDBException { private boolean containsKey(@Nullable LLSnapshot snapshot, Buffer key) throws RocksDBException {
startedContains.increment(); startedContains.increment();
try { try {
@ -553,10 +541,16 @@ public class LLLocalDictionary implements LLDictionary {
private Mono<Send<Buffer>> getPreviousData(Mono<Send<Buffer>> keyMono, LLDictionaryResultType resultType, private Mono<Send<Buffer>> getPreviousData(Mono<Send<Buffer>> keyMono, LLDictionaryResultType resultType,
boolean existsAlmostCertainly) { boolean existsAlmostCertainly) {
return switch (resultType) { return switch (resultType) {
case PREVIOUS_VALUE_EXISTENCE -> this case PREVIOUS_VALUE_EXISTENCE -> keyMono
.containsKey(null, keyMono) .publishOn(dbScheduler)
.single() .handle((keySend, sink) -> {
.map((Boolean bool) -> LLUtils.booleanToResponseByteBuffer(alloc, bool)); try (var key = keySend.receive()) {
var contained = containsKey(null, key);
sink.next(LLUtils.booleanToResponseByteBuffer(alloc, contained));
} catch (RocksDBException ex) {
sink.error(ex);
}
});
case PREVIOUS_VALUE -> keyMono case PREVIOUS_VALUE -> keyMono
.publishOn(dbScheduler) .publishOn(dbScheduler)
.handle((keySend, sink) -> { .handle((keySend, sink) -> {