Use more method references
This commit is contained in:
parent
a3d1207d76
commit
d2e7c56f06
@ -643,11 +643,21 @@ public class LLUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Mono<Void> finalizeResource(Resource<?> resource) {
|
public static Mono<Void> finalizeResource(Resource<?> resource) {
|
||||||
return Mono.fromRunnable(() -> LLUtils.closeResource(resource));
|
return Mono.fromRunnable(() -> LLUtils.finalizeResourceNow(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Mono<Void> finalizeResource(SimpleResource resource) {
|
public static Mono<Void> finalizeResource(SimpleResource resource) {
|
||||||
return Mono.fromRunnable(() -> LLUtils.closeResource(resource));
|
return Mono.fromRunnable(resource::close);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void finalizeResourceNow(Resource<?> resource) {
|
||||||
|
if (resource.isAccessible()) {
|
||||||
|
resource.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void finalizeResourceNow(SimpleResource resource) {
|
||||||
|
resource.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <V> Flux<V> handleDiscard(Flux<V> flux) {
|
public static <V> Flux<V> handleDiscard(Flux<V> flux) {
|
||||||
@ -869,7 +879,7 @@ public class LLUtils {
|
|||||||
newCurr = null;
|
newCurr = null;
|
||||||
}
|
}
|
||||||
return new Delta<>(newPrev, newCurr);
|
return new Delta<>(newPrev, newCurr);
|
||||||
}), delta -> Mono.fromRunnable(delta::close));
|
}), LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <R, V> boolean isDeltaChanged(Delta<V> delta) {
|
public static <R, V> boolean isDeltaChanged(Delta<V> delta) {
|
||||||
|
@ -4,6 +4,7 @@ import com.google.common.primitives.Ints;
|
|||||||
import it.cavallium.dbengine.database.LLKeyValueDatabaseStructure;
|
import it.cavallium.dbengine.database.LLKeyValueDatabaseStructure;
|
||||||
import it.cavallium.dbengine.database.LLSingleton;
|
import it.cavallium.dbengine.database.LLSingleton;
|
||||||
import it.cavallium.dbengine.database.LLSnapshot;
|
import it.cavallium.dbengine.database.LLSnapshot;
|
||||||
|
import it.cavallium.dbengine.database.LLUtils;
|
||||||
import it.cavallium.dbengine.database.serialization.SerializationException;
|
import it.cavallium.dbengine.database.serialization.SerializationException;
|
||||||
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -23,7 +24,7 @@ public class DatabaseInt implements LLKeyValueDatabaseStructure {
|
|||||||
var resultMono = singleton.get(snapshot);
|
var resultMono = singleton.get(snapshot);
|
||||||
return Mono.usingWhen(resultMono,
|
return Mono.usingWhen(resultMono,
|
||||||
result -> Mono.fromSupplier(() -> serializer.deserialize(result)),
|
result -> Mono.fromSupplier(() -> serializer.deserialize(result)),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import com.google.common.primitives.Longs;
|
|||||||
import it.cavallium.dbengine.database.LLKeyValueDatabaseStructure;
|
import it.cavallium.dbengine.database.LLKeyValueDatabaseStructure;
|
||||||
import it.cavallium.dbengine.database.LLSingleton;
|
import it.cavallium.dbengine.database.LLSingleton;
|
||||||
import it.cavallium.dbengine.database.LLSnapshot;
|
import it.cavallium.dbengine.database.LLSnapshot;
|
||||||
|
import it.cavallium.dbengine.database.LLUtils;
|
||||||
import it.cavallium.dbengine.database.UpdateReturnMode;
|
import it.cavallium.dbengine.database.UpdateReturnMode;
|
||||||
import it.cavallium.dbengine.database.serialization.SerializationException;
|
import it.cavallium.dbengine.database.serialization.SerializationException;
|
||||||
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
||||||
@ -33,7 +34,7 @@ public class DatabaseLong implements LLKeyValueDatabaseStructure {
|
|||||||
return serializer.deserialize(result);
|
return serializer.deserialize(result);
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +81,7 @@ public class DatabaseLong implements LLKeyValueDatabaseStructure {
|
|||||||
}, updateReturnMode);
|
}, updateReturnMode);
|
||||||
return Mono.usingWhen(resultMono,
|
return Mono.usingWhen(resultMono,
|
||||||
result -> Mono.fromSupplier(result::readLong),
|
result -> Mono.fromSupplier(result::readLong),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
).single();
|
).single();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
return Mono.usingWhen(dictionary
|
return Mono.usingWhen(dictionary
|
||||||
.get(resolveSnapshot(snapshot), Mono.fromCallable(() -> serializeKeySuffixToKey(keySuffix))),
|
.get(resolveSnapshot(snapshot), Mono.fromCallable(() -> serializeKeySuffixToKey(keySuffix))),
|
||||||
value -> Mono.fromCallable(() -> deserializeValue(keySuffix, value)),
|
value -> Mono.fromCallable(() -> deserializeValue(keySuffix, value)),
|
||||||
value -> Mono.fromRunnable(value::close));
|
LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -283,7 +283,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
var valueMono = Mono.fromCallable(() -> serializeValue(value)).single();
|
var valueMono = Mono.fromCallable(() -> serializeValue(value)).single();
|
||||||
return Mono.usingWhen(dictionary.put(keyMono, valueMono, LLDictionaryResultType.VOID),
|
return Mono.usingWhen(dictionary.put(keyMono, valueMono, LLDictionaryResultType.VOID),
|
||||||
v -> Mono.empty(),
|
v -> Mono.empty(),
|
||||||
v -> Mono.fromRunnable(v::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
var keyMono = Mono.fromCallable(() -> serializeKeySuffixToKey(keySuffix));
|
var keyMono = Mono.fromCallable(() -> serializeKeySuffixToKey(keySuffix));
|
||||||
return Mono.usingWhen(dictionary.update(keyMono, getSerializedUpdater(updater), updateReturnMode),
|
return Mono.usingWhen(dictionary.update(keyMono, getSerializedUpdater(updater), updateReturnMode),
|
||||||
result -> Mono.fromCallable(() -> deserializeValue(keySuffix, result)),
|
result -> Mono.fromCallable(() -> deserializeValue(keySuffix, result)),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +355,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
var valueMono = Mono.fromCallable(() -> serializeValue(value));
|
var valueMono = Mono.fromCallable(() -> serializeValue(value));
|
||||||
return Mono.usingWhen(dictionary.put(keyMono, valueMono, LLDictionaryResultType.PREVIOUS_VALUE),
|
return Mono.usingWhen(dictionary.put(keyMono, valueMono, LLDictionaryResultType.PREVIOUS_VALUE),
|
||||||
valueBuf -> Mono.fromCallable(() -> deserializeValue(keySuffix, valueBuf)),
|
valueBuf -> Mono.fromCallable(() -> deserializeValue(keySuffix, valueBuf)),
|
||||||
valueBuf -> Mono.fromRunnable(valueBuf::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +366,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
return Mono
|
return Mono
|
||||||
.usingWhen(dictionary.put(keyMono, valueMono, LLDictionaryResultType.PREVIOUS_VALUE),
|
.usingWhen(dictionary.put(keyMono, valueMono, LLDictionaryResultType.PREVIOUS_VALUE),
|
||||||
valueBuf -> Mono.fromCallable(() -> deserializeValue(keySuffix, valueBuf)),
|
valueBuf -> Mono.fromCallable(() -> deserializeValue(keySuffix, valueBuf)),
|
||||||
valueBuf -> Mono.fromRunnable(valueBuf::close)
|
LLUtils::finalizeResource
|
||||||
)
|
)
|
||||||
.map(oldValue -> !Objects.equals(oldValue, value))
|
.map(oldValue -> !Objects.equals(oldValue, value))
|
||||||
.defaultIfEmpty(value != null);
|
.defaultIfEmpty(value != null);
|
||||||
@ -377,7 +377,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
var keyMono = Mono.fromCallable(() -> serializeKeySuffixToKey(keySuffix));
|
var keyMono = Mono.fromCallable(() -> serializeKeySuffixToKey(keySuffix));
|
||||||
return dictionary
|
return dictionary
|
||||||
.remove(keyMono, LLDictionaryResultType.VOID)
|
.remove(keyMono, LLDictionaryResultType.VOID)
|
||||||
.doOnNext(Resource::close)
|
.doOnNext(LLUtils::finalizeResourceNow)
|
||||||
.then();
|
.then();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,7 +386,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
var keyMono = Mono.fromCallable(() -> serializeKeySuffixToKey(keySuffix));
|
var keyMono = Mono.fromCallable(() -> serializeKeySuffixToKey(keySuffix));
|
||||||
return Mono.usingWhen(dictionary.remove(keyMono, LLDictionaryResultType.PREVIOUS_VALUE),
|
return Mono.usingWhen(dictionary.remove(keyMono, LLDictionaryResultType.PREVIOUS_VALUE),
|
||||||
valueBuf -> Mono.fromCallable(() -> deserializeValue(keySuffix, valueBuf)),
|
valueBuf -> Mono.fromCallable(() -> deserializeValue(keySuffix, valueBuf)),
|
||||||
valueBuf -> Mono.fromRunnable(valueBuf::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -535,7 +535,7 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
} else {
|
} else {
|
||||||
Mono<LLRange> boundedRangeMono = Mono.usingWhen(rangeMono,
|
Mono<LLRange> boundedRangeMono = Mono.usingWhen(rangeMono,
|
||||||
range -> Mono.fromCallable(() -> getPatchedRange(range, keyMin, keyMax)),
|
range -> Mono.fromCallable(() -> getPatchedRange(range, keyMin, keyMax)),
|
||||||
range -> Mono.fromRunnable(range::close));
|
LLUtils::finalizeResource);
|
||||||
return getAllValues(snapshot, boundedRangeMono, reverse, smallRange);
|
return getAllValues(snapshot, boundedRangeMono, reverse, smallRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -580,12 +580,12 @@ public class DatabaseMapDictionary<T, U> extends DatabaseMapDictionaryDeep<T, U,
|
|||||||
} else if (range.isSingle()) {
|
} else if (range.isSingle()) {
|
||||||
return dictionary
|
return dictionary
|
||||||
.remove(Mono.fromCallable(range::getSingleUnsafe), LLDictionaryResultType.VOID)
|
.remove(Mono.fromCallable(range::getSingleUnsafe), LLDictionaryResultType.VOID)
|
||||||
.doOnNext(Resource::close)
|
.doOnNext(LLUtils::finalizeResourceNow)
|
||||||
.then();
|
.then();
|
||||||
} else {
|
} else {
|
||||||
return dictionary.setRange(rangeMono, Flux.empty(), false);
|
return dictionary.setRange(rangeMono, Flux.empty(), false);
|
||||||
}
|
}
|
||||||
}, ResourceSupport::close);
|
}, LLUtils::finalizeResourceNow);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -421,12 +421,12 @@ public class DatabaseMapDictionaryDeep<T, U, US extends DatabaseStage<U>> extend
|
|||||||
} else if (range.isSingle()) {
|
} else if (range.isSingle()) {
|
||||||
return dictionary
|
return dictionary
|
||||||
.remove(Mono.fromCallable(range::getSingleUnsafe), LLDictionaryResultType.VOID)
|
.remove(Mono.fromCallable(range::getSingleUnsafe), LLDictionaryResultType.VOID)
|
||||||
.doOnNext(Resource::close)
|
.doOnNext(LLUtils::finalizeResourceNow)
|
||||||
.then();
|
.then();
|
||||||
} else {
|
} else {
|
||||||
return dictionary.setRange(rangeMono, Flux.empty(), false);
|
return dictionary.setRange(rangeMono, Flux.empty(), false);
|
||||||
}
|
}
|
||||||
}, ResourceSupport::close);
|
}, LLUtils::finalizeResourceNow);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected T deserializeSuffix(@NotNull Buffer keySuffix) throws SerializationException {
|
protected T deserializeSuffix(@NotNull Buffer keySuffix) throws SerializationException {
|
||||||
|
@ -113,7 +113,7 @@ public class DatabaseMapSingle<U> extends ResourceSupport<DatabaseStage<U>, Data
|
|||||||
public Mono<U> get(@Nullable CompositeSnapshot snapshot) {
|
public Mono<U> get(@Nullable CompositeSnapshot snapshot) {
|
||||||
return Mono.usingWhen(dictionary.get(resolveSnapshot(snapshot), keyMono),
|
return Mono.usingWhen(dictionary.get(resolveSnapshot(snapshot), keyMono),
|
||||||
buf -> Mono.fromSupplier(() -> deserializeValue(buf)),
|
buf -> Mono.fromSupplier(() -> deserializeValue(buf)),
|
||||||
buf -> Mono.fromRunnable(buf::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -122,7 +122,7 @@ public class DatabaseMapSingle<U> extends ResourceSupport<DatabaseStage<U>, Data
|
|||||||
return Mono.usingWhen(dictionary
|
return Mono.usingWhen(dictionary
|
||||||
.put(keyMono, Mono.fromCallable(() -> serializeValue(value)), LLDictionaryResultType.PREVIOUS_VALUE),
|
.put(keyMono, Mono.fromCallable(() -> serializeValue(value)), LLDictionaryResultType.PREVIOUS_VALUE),
|
||||||
buf -> Mono.fromSupplier(() -> deserializeValue(buf)),
|
buf -> Mono.fromSupplier(() -> deserializeValue(buf)),
|
||||||
buf -> Mono.fromRunnable(buf::close));
|
LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -147,7 +147,7 @@ public class DatabaseMapSingle<U> extends ResourceSupport<DatabaseStage<U>, Data
|
|||||||
}, updateReturnMode);
|
}, updateReturnMode);
|
||||||
return Mono.usingWhen(resultMono,
|
return Mono.usingWhen(resultMono,
|
||||||
result -> Mono.fromSupplier(() -> deserializeValue(result)),
|
result -> Mono.fromSupplier(() -> deserializeValue(result)),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,7 +174,7 @@ public class DatabaseMapSingle<U> extends ResourceSupport<DatabaseStage<U>, Data
|
|||||||
public Mono<U> clearAndGetPrevious() {
|
public Mono<U> clearAndGetPrevious() {
|
||||||
return Mono.usingWhen(dictionary.remove(keyMono, LLDictionaryResultType.PREVIOUS_VALUE),
|
return Mono.usingWhen(dictionary.remove(keyMono, LLDictionaryResultType.PREVIOUS_VALUE),
|
||||||
result -> Mono.fromSupplier(() -> deserializeValue(result)),
|
result -> Mono.fromSupplier(() -> deserializeValue(result)),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ public class DatabaseSingleton<U> extends ResourceSupport<DatabaseStage<U>, Data
|
|||||||
var resultMono = singleton.get(resolveSnapshot(snapshot));
|
var resultMono = singleton.get(resolveSnapshot(snapshot));
|
||||||
return Mono.usingWhen(resultMono,
|
return Mono.usingWhen(resultMono,
|
||||||
result -> Mono.fromSupplier(() -> this.deserializeValue(result)),
|
result -> Mono.fromSupplier(() -> this.deserializeValue(result)),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ public class DatabaseSingleton<U> extends ResourceSupport<DatabaseStage<U>, Data
|
|||||||
.last();
|
.last();
|
||||||
return Mono.usingWhen(resultMono,
|
return Mono.usingWhen(resultMono,
|
||||||
result -> Mono.fromSupplier(() -> this.deserializeValue(result)),
|
result -> Mono.fromSupplier(() -> this.deserializeValue(result)),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,7 +146,7 @@ public class DatabaseSingleton<U> extends ResourceSupport<DatabaseStage<U>, Data
|
|||||||
}, updateReturnMode);
|
}, updateReturnMode);
|
||||||
return Mono.usingWhen(resultMono,
|
return Mono.usingWhen(resultMono,
|
||||||
result -> Mono.fromSupplier(() -> this.deserializeValue(result)),
|
result -> Mono.fromSupplier(() -> this.deserializeValue(result)),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +181,7 @@ public class DatabaseSingleton<U> extends ResourceSupport<DatabaseStage<U>, Data
|
|||||||
var resultMono = Flux.concat(singleton.get(null), singleton.set(Mono.empty()).then(Mono.empty())).last();
|
var resultMono = Flux.concat(singleton.get(null), singleton.set(Mono.empty()).then(Mono.empty())).last();
|
||||||
return Mono.usingWhen(resultMono,
|
return Mono.usingWhen(resultMono,
|
||||||
result -> Mono.fromSupplier(() -> this.deserializeValue(result)),
|
result -> Mono.fromSupplier(() -> this.deserializeValue(result)),
|
||||||
result -> Mono.fromRunnable(result::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +258,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
public Mono<Buffer> get(@Nullable LLSnapshot snapshot, Mono<Buffer> keyMono) {
|
public Mono<Buffer> get(@Nullable LLSnapshot snapshot, Mono<Buffer> keyMono) {
|
||||||
return Mono.usingWhen(keyMono,
|
return Mono.usingWhen(keyMono,
|
||||||
key -> runOnDb(false, () -> this.getSync(snapshot, key)),
|
key -> runOnDb(false, () -> this.getSync(snapshot, key)),
|
||||||
key -> Mono.fromRunnable(key::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -329,7 +329,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
} finally {
|
} finally {
|
||||||
endedContains.increment();
|
endedContains.increment();
|
||||||
}
|
}
|
||||||
}), range -> Mono.fromRunnable(range::close));
|
}), LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean containsKey(@Nullable LLSnapshot snapshot, Buffer key) throws RocksDBException {
|
private boolean containsKey(@Nullable LLSnapshot snapshot, Buffer key) throws RocksDBException {
|
||||||
@ -454,7 +454,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
}
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}), key -> Mono.fromRunnable(key::close));
|
}), LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("DuplicatedCode")
|
@SuppressWarnings("DuplicatedCode")
|
||||||
@ -492,7 +492,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
}
|
}
|
||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
}), key -> Mono.fromRunnable(key::close));
|
}), LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -516,7 +516,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
} catch (RocksDBException ex) {
|
} catch (RocksDBException ex) {
|
||||||
throw new RocksDBException("Failed to delete: " + ex.getMessage());
|
throw new RocksDBException("Failed to delete: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}), key -> Mono.fromRunnable(key::close));
|
}), LLUtils::finalizeResource);
|
||||||
// Read the previous data, then delete the data, then return the previous data
|
// Read the previous data, then delete the data, then return the previous data
|
||||||
return Flux.concat(previousDataMono, removeMono).singleOrEmpty();
|
return Flux.concat(previousDataMono, removeMono).singleOrEmpty();
|
||||||
}
|
}
|
||||||
@ -526,7 +526,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
case PREVIOUS_VALUE_EXISTENCE -> Mono.usingWhen(keyMono, key -> runOnDb(false, () -> {
|
case PREVIOUS_VALUE_EXISTENCE -> Mono.usingWhen(keyMono, key -> runOnDb(false, () -> {
|
||||||
var contained = containsKey(null, key);
|
var contained = containsKey(null, key);
|
||||||
return LLUtils.booleanToResponseByteBuffer(alloc, contained);
|
return LLUtils.booleanToResponseByteBuffer(alloc, contained);
|
||||||
}), key -> Mono.fromRunnable(key::close));
|
}), LLUtils::finalizeResource);
|
||||||
case PREVIOUS_VALUE -> Mono.usingWhen(keyMono, key -> runOnDb(false, () -> {
|
case PREVIOUS_VALUE -> Mono.usingWhen(keyMono, key -> runOnDb(false, () -> {
|
||||||
assert !Schedulers.isInNonBlockingThread() : "Called getPreviousData in a nonblocking thread";
|
assert !Schedulers.isInNonBlockingThread() : "Called getPreviousData in a nonblocking thread";
|
||||||
Buffer result;
|
Buffer result;
|
||||||
@ -540,7 +540,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
}
|
}
|
||||||
logger.trace(MARKER_ROCKSDB, "Read {}: {}", () -> toStringSafe(key), () -> toStringSafe(result));
|
logger.trace(MARKER_ROCKSDB, "Read {}: {}", () -> toStringSafe(key), () -> toStringSafe(result));
|
||||||
return result;
|
return result;
|
||||||
}), key -> Mono.fromRunnable(key::close));
|
}), LLUtils::finalizeResource);
|
||||||
case VOID -> Mono.empty();
|
case VOID -> Mono.empty();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -671,7 +671,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
for (var mappedInput : mappedInputs) {
|
for (var mappedInput : mappedInputs) {
|
||||||
mappedInput.getT3().ifPresent(Resource::close);
|
mappedInput.getT3().ifPresent(LLUtils::finalizeResourceNow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -761,7 +761,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
});
|
});
|
||||||
return Flux.usingWhen(iteratorMono,
|
return Flux.usingWhen(iteratorMono,
|
||||||
iterator -> iterator.flux().subscribeOn(dbRScheduler, false),
|
iterator -> iterator.flux().subscribeOn(dbRScheduler, false),
|
||||||
iterator -> Mono.fromRunnable(iterator::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -780,7 +780,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
return Flux.usingWhen(
|
return Flux.usingWhen(
|
||||||
iteratorMono,
|
iteratorMono,
|
||||||
iterator -> iterator.flux().subscribeOn(dbRScheduler, false),
|
iterator -> iterator.flux().subscribeOn(dbRScheduler, false),
|
||||||
iterator -> Mono.fromRunnable(iterator::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -821,7 +821,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
});
|
});
|
||||||
return Flux.usingWhen(iteratorMono,
|
return Flux.usingWhen(iteratorMono,
|
||||||
iterator -> iterator.flux().subscribeOn(dbRScheduler, false),
|
iterator -> iterator.flux().subscribeOn(dbRScheduler, false),
|
||||||
iterator -> Mono.fromRunnable(iterator::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -860,7 +860,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.subscribeOn(dbRScheduler),
|
.subscribeOn(dbRScheduler),
|
||||||
range -> Mono.fromRunnable(range::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -880,7 +880,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
});
|
});
|
||||||
return Flux.usingWhen(iteratorMono,
|
return Flux.usingWhen(iteratorMono,
|
||||||
iterator -> iterator.flux().subscribeOn(dbRScheduler),
|
iterator -> iterator.flux().subscribeOn(dbRScheduler),
|
||||||
iterator -> Mono.fromRunnable(iterator::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,7 +891,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}), key -> Mono.fromRunnable(key::close)).flux();
|
}), LLUtils::finalizeResource).flux();
|
||||||
}
|
}
|
||||||
|
|
||||||
private record RocksObjTuple<T extends AbstractNativeReference, U extends Resource<?>>(T t1, U t2) implements SafeCloseable {
|
private record RocksObjTuple<T extends AbstractNativeReference, U extends Resource<?>>(T t1, U t2) implements SafeCloseable {
|
||||||
@ -969,7 +969,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
} catch (RocksDBException ex) {
|
} catch (RocksDBException ex) {
|
||||||
throw new RocksDBException("Failed to set a range: " + ex.getMessage());
|
throw new RocksDBException("Failed to set a range: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}), range -> Mono.fromRunnable(range::close))
|
}), LLUtils::finalizeResource)
|
||||||
.thenMany(entries.window(MULTI_GET_WINDOW))
|
.thenMany(entries.window(MULTI_GET_WINDOW))
|
||||||
.flatMap(keysWindowFlux -> keysWindowFlux
|
.flatMap(keysWindowFlux -> keysWindowFlux
|
||||||
.collectList()
|
.collectList()
|
||||||
@ -1199,7 +1199,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
} catch (RocksDBException ex) {
|
} catch (RocksDBException ex) {
|
||||||
throw new RocksDBException("Failed to get size of range: " + ex.getMessage());
|
throw new RocksDBException("Failed to get size of range: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}), range -> Mono.fromRunnable(range::close));
|
}), LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1228,7 +1228,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
} catch (RocksDBException ex) {
|
} catch (RocksDBException ex) {
|
||||||
throw new RocksDBException("Failed to get one entry: " + ex.getMessage());
|
throw new RocksDBException("Failed to get one entry: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}), range -> Mono.fromRunnable(range::close));
|
}), LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1253,7 +1253,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
} catch (RocksDBException ex) {
|
} catch (RocksDBException ex) {
|
||||||
throw new RocksDBException("Failed to get one key: " + ex.getMessage());
|
throw new RocksDBException("Failed to get one key: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
}), range -> Mono.fromRunnable(range::close));
|
}), LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private long fastSizeAll(@Nullable LLSnapshot snapshot) throws RocksDBException {
|
private long fastSizeAll(@Nullable LLSnapshot snapshot) throws RocksDBException {
|
||||||
@ -1387,7 +1387,7 @@ public class LLLocalDictionary implements LLDictionary {
|
|||||||
return LLEntry.of(key, value);
|
return LLEntry.of(key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}), range -> Mono.fromRunnable(range::close));
|
}), LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -151,7 +151,7 @@ public class LLLocalSingleton implements LLSingleton {
|
|||||||
case GET_OLD_VALUE -> ((UpdateAtomicResultPrevious) result).previous();
|
case GET_OLD_VALUE -> ((UpdateAtomicResultPrevious) result).previous();
|
||||||
};
|
};
|
||||||
}).onErrorMap(cause -> new IOException("Failed to read or write", cause)),
|
}).onErrorMap(cause -> new IOException("Failed to read or write", cause)),
|
||||||
keySend -> Mono.fromRunnable(keySend::close));
|
LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -166,7 +166,7 @@ public class LLLocalSingleton implements LLSingleton {
|
|||||||
}
|
}
|
||||||
return ((UpdateAtomicResultDelta) result).delta();
|
return ((UpdateAtomicResultDelta) result).delta();
|
||||||
}).onErrorMap(cause -> new IOException("Failed to read or write", cause)),
|
}).onErrorMap(cause -> new IOException("Failed to read or write", cause)),
|
||||||
keySend -> Mono.fromRunnable(keySend::close));
|
LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -184,7 +184,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
.fromCallable(() -> snapshots.get(resolveSnapshot(snapshot)).get(kShr(key)))
|
.fromCallable(() -> snapshots.get(resolveSnapshot(snapshot)).get(kShr(key)))
|
||||||
.map(this::kkB)
|
.map(this::kkB)
|
||||||
.onErrorMap(cause -> new IOException("Failed to read", cause)),
|
.onErrorMap(cause -> new IOException("Failed to read", cause)),
|
||||||
key -> Mono.fromRunnable(key::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -238,7 +238,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
var oldVal = oldRef.get();
|
var oldVal = oldRef.get();
|
||||||
return LLDelta.of(oldVal != null ? kkB(oldRef.get()) : null, newValue != null ? kkB(newValue) : null);
|
return LLDelta.of(oldVal != null ? kkB(oldRef.get()) : null, newValue != null ? kkB(newValue) : null);
|
||||||
}),
|
}),
|
||||||
key -> Mono.fromRunnable(key::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.onErrorMap(cause -> new IOException("Failed to read", cause)),
|
.onErrorMap(cause -> new IOException("Failed to read", cause)),
|
||||||
key -> Mono.fromRunnable(key::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +330,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
})
|
})
|
||||||
.map(entry -> LLEntry.of(kkB(entry.getKey()), kkB(entry.getValue())));
|
.map(entry -> LLEntry.of(kkB(entry.getKey()), kkB(entry.getValue())));
|
||||||
}
|
}
|
||||||
}, range -> Mono.fromRunnable(range::close));
|
}, LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -362,7 +362,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, range -> Mono.fromRunnable(range::close));
|
}, LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -397,7 +397,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
.map(this::kkB);
|
.map(this::kkB);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
range -> Mono.fromRunnable(range::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,7 +434,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, range -> Mono.fromRunnable(range::close));
|
}, LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("RedundantCast")
|
@SuppressWarnings("RedundantCast")
|
||||||
@ -466,7 +466,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
.map(this::kkB);
|
.map(this::kkB);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, range -> Mono.fromRunnable(range::close));
|
}, LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -503,7 +503,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then();
|
.then();
|
||||||
}, range -> Mono.fromRunnable(range::close));
|
}, LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isInsideRange(BLRange range, ByteList key) {
|
private boolean isInsideRange(BLRange range, ByteList key) {
|
||||||
@ -528,7 +528,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
@Override
|
@Override
|
||||||
public Mono<Boolean> isRangeEmpty(@Nullable LLSnapshot snapshot, Mono<LLRange> rangeMono, boolean fillCache) {
|
public Mono<Boolean> isRangeEmpty(@Nullable LLSnapshot snapshot, Mono<LLRange> rangeMono, boolean fillCache) {
|
||||||
return getRangeKeys(snapshot, rangeMono, false, false)
|
return getRangeKeys(snapshot, rangeMono, false, false)
|
||||||
.doOnNext(Resource::close)
|
.doOnNext(LLUtils::finalizeResourceNow)
|
||||||
.count()
|
.count()
|
||||||
.map(count -> count == 0);
|
.map(count -> count == 0);
|
||||||
}
|
}
|
||||||
@ -537,7 +537,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
public Mono<Long> sizeRange(@Nullable LLSnapshot snapshot, Mono<LLRange> rangeMono, boolean fast) {
|
public Mono<Long> sizeRange(@Nullable LLSnapshot snapshot, Mono<LLRange> rangeMono, boolean fast) {
|
||||||
return Mono.usingWhen(rangeMono,
|
return Mono.usingWhen(rangeMono,
|
||||||
range -> Mono.fromCallable(() -> (long) mapSlice(snapshot, range).size()),
|
range -> Mono.fromCallable(() -> (long) mapSlice(snapshot, range).size()),
|
||||||
range -> Mono.fromRunnable(range::close)
|
LLUtils::finalizeResource
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -587,7 +587,7 @@ public class LLMemoryDictionary implements LLDictionary {
|
|||||||
.map(entry -> LLEntry.of(kkB(entry.getKey()), kkB(entry.getValue())));
|
.map(entry -> LLEntry.of(kkB(entry.getKey()), kkB(entry.getValue())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, range -> Mono.fromRunnable(range::close));
|
}, LLUtils::finalizeResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -74,7 +74,7 @@ public class CountMultiSearcher implements MultiSearcher {
|
|||||||
.take(queryParams2.limitLong(), true);
|
.take(queryParams2.limitLong(), true);
|
||||||
|
|
||||||
return new LuceneSearchResult(totalHitsCount, mergedFluxes, () -> {
|
return new LuceneSearchResult(totalHitsCount, mergedFluxes, () -> {
|
||||||
resultsToDrop.forEach(SimpleResource::close);
|
resultsToDrop.forEach(LLUtils::finalizeResourceNow);
|
||||||
try {
|
try {
|
||||||
indexSearchers.close();
|
indexSearchers.close();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user