From fbf17c8650bf83fec8c634154f92a37fbcad9be1 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Thu, 24 Oct 2024 00:26:00 +0200 Subject: [PATCH] Fix reduce range bug --- .../rockserver/core/server/GrpcServer.java | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java b/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java index cd673a1..d1b4e10 100644 --- a/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java +++ b/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java @@ -469,23 +469,22 @@ public class GrpcServer extends Server { @Override public Mono reduceRangeFirstAndLast(GetRangeRequest request) { - return executeSync(() -> { - try (var arena = Arena.ofConfined()) { - it.cavallium.rockserver.core.common.FirstAndLast firstAndLast - = api.reduceRange(arena, - request.getTransactionId(), - request.getColumnId(), - mapKeys(arena, request.getStartKeysInclusiveCount(), request::getStartKeysInclusive), - mapKeys(arena, request.getEndKeysExclusiveCount(), request::getEndKeysExclusive), - request.getReverse(), - RequestType.firstAndLast(), - request.getTimeoutMs() - ); - return FirstAndLast.newBuilder() - .setFirst(unmapKV(firstAndLast.first())) - .setLast(unmapKV(firstAndLast.last())) - .build(); + var arena = Arena.ofAuto(); + return Mono.fromFuture(() -> asyncApi.reduceRangeAsync(arena, request.getTransactionId(), request.getColumnId(), + mapKeys(arena, request.getStartKeysInclusiveCount(), request::getStartKeysInclusive), + mapKeys(arena, request.getEndKeysExclusiveCount(), request::getEndKeysExclusive), + request.getReverse(), + RequestType.firstAndLast(), + request.getTimeoutMs() + )).map(firstAndLast -> { + var resultBuilder = FirstAndLast.newBuilder(); + if (firstAndLast.first() != null) { + resultBuilder.setFirst(unmapKV(firstAndLast.first())); } + if (firstAndLast.last() != null) { + resultBuilder.setLast(unmapKV(firstAndLast.last())); + } + return resultBuilder.build(); }); }