diff --git a/src/main/java/it/cavallium/rockserver/core/Main.java b/src/main/java/it/cavallium/rockserver/core/Main.java index 8acc49c..eb89aeb 100644 --- a/src/main/java/it/cavallium/rockserver/core/Main.java +++ b/src/main/java/it/cavallium/rockserver/core/Main.java @@ -111,21 +111,22 @@ public class Main { clientBuilder.setName(name); try (var connection = clientBuilder.build()) { - LOG.info("Connected to {}", connection); + try { + LOG.info("Connected to {}", connection); - thriftServerBuilder.setClient(connection); - grpcServerBuilder.setClient(connection); + thriftServerBuilder.setClient(connection); + grpcServerBuilder.setClient(connection); - CountDownLatch shutdownLatch = new CountDownLatch(1); - Runtime.getRuntime().addShutdownHook(new Thread(shutdownLatch::countDown)); + CountDownLatch shutdownLatch = new CountDownLatch(1); + Runtime.getRuntime().addShutdownHook(new Thread(shutdownLatch::countDown)); - try (var _ = thriftServerBuilder.build(); - var _ = grpcServerBuilder.build()) { - shutdownLatch.await(); - LOG.info("Shutting down..."); + try (var _ = thriftServerBuilder.build(); var _ = grpcServerBuilder.build()) { + shutdownLatch.await(); + LOG.info("Shutting down..."); + } + } catch (Exception ex) { + LOG.error("Unexpected error", ex); } - } catch (InterruptedException e) { - throw new RuntimeException("Interrupted", e); } LOG.info("Shut down successfully"); } diff --git a/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/TransactionalDB.java b/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/TransactionalDB.java index ee17318..b0e5bf1 100644 --- a/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/TransactionalDB.java +++ b/src/main/java/it/cavallium/rockserver/core/impl/rocksdb/TransactionalDB.java @@ -157,17 +157,23 @@ public sealed interface TransactionalDB extends Closeable { } } try { - db.flushWal(true); + if (db.isOwningHandle()) { + db.flushWal(true); + } } catch (RocksDBException e) { exceptions.add(e); } try (var options = new FlushOptions().setWaitForFlush(true).setAllowWriteStall(true)) { - db.flush(options); + if (db.isOwningHandle()) { + db.flush(options); + } } catch (RocksDBException e) { exceptions.add(e); } try { - db.closeE(); + if (db.isOwningHandle()) { + db.closeE(); + } } catch (RocksDBException e) { exceptions.add(e); } 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 da19a4e..4e52676 100644 --- a/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java +++ b/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java @@ -4,11 +4,8 @@ import static it.cavallium.rockserver.core.common.Utils.toMemorySegment; import com.google.protobuf.ByteString; import com.google.protobuf.Empty; -import com.google.rpc.DebugInfo; -import io.grpc.Metadata; import io.grpc.Status; import io.grpc.netty.NettyServerBuilder; -import io.grpc.protobuf.ProtoUtils; import io.grpc.stub.StreamObserver; import it.cavallium.rockserver.core.client.RocksDBConnection; import it.cavallium.rockserver.core.common.ColumnHashType; @@ -506,17 +503,10 @@ public class GrpcServer extends Server { }; } - private static final Metadata.Key DEBUG_INFO_TRAILER_KEY = - ProtoUtils.keyForProto(DebugInfo.getDefaultInstance()); - private static BiConsumer handleResponseObserver(Function resultMapper, StreamObserver responseObserver) { return (value, ex) -> { if (ex != null) { - Metadata trailers = new Metadata(); - trailers.put(DEBUG_INFO_TRAILER_KEY, DebugInfo.newBuilder() - .setDetail("rockserver grpc execution failed") - .build()); var cause = ex; if (cause instanceof CompletionException completionException) { cause = completionException; @@ -526,7 +516,7 @@ public class GrpcServer extends Server { } var error = Status.INTERNAL.withCause(cause) .withDescription(cause.toString()) - .asException(trailers); + .asException(); responseObserver.onError(error); } else { T mapped;