From 11b1d800dc1c626356362cd44ace7004eecbd052 Mon Sep 17 00:00:00 2001 From: Andrea Cavalli Date: Sun, 6 Oct 2024 13:03:42 +0200 Subject: [PATCH] Fix thrift server not starting, more logs --- src/main/java/it/cavallium/rockserver/core/Main.java | 4 +++- .../java/it/cavallium/rockserver/core/TestGrpcLoop.java | 1 + .../it/cavallium/rockserver/core/client/LoggingClient.java | 2 ++ .../it/cavallium/rockserver/core/server/GrpcServer.java | 6 +++++- .../java/it/cavallium/rockserver/core/server/Server.java | 4 +++- .../it/cavallium/rockserver/core/server/ThriftServer.java | 4 ++++ 6 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/cavallium/rockserver/core/Main.java b/src/main/java/it/cavallium/rockserver/core/Main.java index eb89aeb..5efc43a 100644 --- a/src/main/java/it/cavallium/rockserver/core/Main.java +++ b/src/main/java/it/cavallium/rockserver/core/Main.java @@ -120,7 +120,9 @@ public class Main { CountDownLatch shutdownLatch = new CountDownLatch(1); Runtime.getRuntime().addShutdownHook(new Thread(shutdownLatch::countDown)); - try (var _ = thriftServerBuilder.build(); var _ = grpcServerBuilder.build()) { + try (var thrift = thriftServerBuilder.build(); var grpc = grpcServerBuilder.build()) { + thrift.start(); + grpc.start(); shutdownLatch.await(); LOG.info("Shutting down..."); } diff --git a/src/main/java/it/cavallium/rockserver/core/TestGrpcLoop.java b/src/main/java/it/cavallium/rockserver/core/TestGrpcLoop.java index 366c887..b6801a5 100644 --- a/src/main/java/it/cavallium/rockserver/core/TestGrpcLoop.java +++ b/src/main/java/it/cavallium/rockserver/core/TestGrpcLoop.java @@ -21,6 +21,7 @@ public class TestGrpcLoop { public static void main(String[] args) throws IOException, InterruptedException { var embeddedDB = new EmbeddedConnection(null, "main", null); var server = new GrpcServer(embeddedDB, new InetSocketAddress("localhost", 12345)); + server.start(); var clientB = new ClientBuilder(); clientB.setHttpAddress(new Utils.HostAndPort("localhost", 12345)); clientB.setName("local"); diff --git a/src/main/java/it/cavallium/rockserver/core/client/LoggingClient.java b/src/main/java/it/cavallium/rockserver/core/client/LoggingClient.java index 53d721e..8966efc 100644 --- a/src/main/java/it/cavallium/rockserver/core/client/LoggingClient.java +++ b/src/main/java/it/cavallium/rockserver/core/client/LoggingClient.java @@ -56,6 +56,7 @@ public class LoggingClient implements RocksDBConnection { @Override public R requestSync(RocksDBAPICommand req) { + logger.trace("Request input (sync): {}", req); R result; try { result = syncApi.requestSync(req); @@ -78,6 +79,7 @@ public class LoggingClient implements RocksDBConnection { @Override public CompletableFuture requestAsync(RocksDBAPICommand req) { + logger.trace("Request input (async): {}", req); return asyncApi.requestAsync(req).whenComplete((result, e) -> { if (e != null) { logger.trace("Request failed: {} Error: {}", req, e.getMessage()); 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 edc4ab3..e4766a8 100644 --- a/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java +++ b/src/main/java/it/cavallium/rockserver/core/server/GrpcServer.java @@ -94,10 +94,14 @@ public class GrpcServer extends Server { .maxInboundMessageSize(512 * 1024 * 1024) .addService(grpc) .build(); - server.start(); LOG.info("GRPC RocksDB server is listening at " + socketAddress); } + @Override + public void start() throws IOException { + server.start(); + } + private final class GrpcServerImpl extends RocksDBServiceImplBase { private final RocksDBAsyncAPI asyncApi; diff --git a/src/main/java/it/cavallium/rockserver/core/server/Server.java b/src/main/java/it/cavallium/rockserver/core/server/Server.java index c4fc7d6..3e72227 100644 --- a/src/main/java/it/cavallium/rockserver/core/server/Server.java +++ b/src/main/java/it/cavallium/rockserver/core/server/Server.java @@ -5,7 +5,7 @@ import it.cavallium.rockserver.core.client.RocksDBConnection; import java.io.Closeable; import java.io.IOException; -public class Server implements Closeable { +public abstract class Server implements Closeable { private final RocksDBConnection client; @@ -17,6 +17,8 @@ public class Server implements Closeable { return client; } + public abstract void start() throws IOException; + @Override public void close() throws IOException { client.close(); diff --git a/src/main/java/it/cavallium/rockserver/core/server/ThriftServer.java b/src/main/java/it/cavallium/rockserver/core/server/ThriftServer.java index 77a1dd0..6741eba 100644 --- a/src/main/java/it/cavallium/rockserver/core/server/ThriftServer.java +++ b/src/main/java/it/cavallium/rockserver/core/server/ThriftServer.java @@ -57,6 +57,10 @@ public class ThriftServer extends Server { } } + public void start() { + thriftThread.start(); + } + private static @NotNull List<@NotNull Keys> keysToRecords(Arena arena, @NotNull List<@NotNull List< @NotNull ByteBuffer>> keysMulti) { return keysMulti.stream().map(keys -> keysToRecord(arena, keys)).toList(); }