Fix thrift server not starting, more logs

This commit is contained in:
Andrea Cavalli 2024-10-06 13:03:42 +02:00
parent bee5f5f189
commit 11b1d800dc
6 changed files with 18 additions and 3 deletions

View File

@ -120,7 +120,9 @@ public class Main {
CountDownLatch shutdownLatch = new CountDownLatch(1); CountDownLatch shutdownLatch = new CountDownLatch(1);
Runtime.getRuntime().addShutdownHook(new Thread(shutdownLatch::countDown)); 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(); shutdownLatch.await();
LOG.info("Shutting down..."); LOG.info("Shutting down...");
} }

View File

@ -21,6 +21,7 @@ public class TestGrpcLoop {
public static void main(String[] args) throws IOException, InterruptedException { public static void main(String[] args) throws IOException, InterruptedException {
var embeddedDB = new EmbeddedConnection(null, "main", null); var embeddedDB = new EmbeddedConnection(null, "main", null);
var server = new GrpcServer(embeddedDB, new InetSocketAddress("localhost", 12345)); var server = new GrpcServer(embeddedDB, new InetSocketAddress("localhost", 12345));
server.start();
var clientB = new ClientBuilder(); var clientB = new ClientBuilder();
clientB.setHttpAddress(new Utils.HostAndPort("localhost", 12345)); clientB.setHttpAddress(new Utils.HostAndPort("localhost", 12345));
clientB.setName("local"); clientB.setName("local");

View File

@ -56,6 +56,7 @@ public class LoggingClient implements RocksDBConnection {
@Override @Override
public <R> R requestSync(RocksDBAPICommand<R> req) { public <R> R requestSync(RocksDBAPICommand<R> req) {
logger.trace("Request input (sync): {}", req);
R result; R result;
try { try {
result = syncApi.requestSync(req); result = syncApi.requestSync(req);
@ -78,6 +79,7 @@ public class LoggingClient implements RocksDBConnection {
@Override @Override
public <R> CompletableFuture<R> requestAsync(RocksDBAPICommand<R> req) { public <R> CompletableFuture<R> requestAsync(RocksDBAPICommand<R> req) {
logger.trace("Request input (async): {}", req);
return asyncApi.requestAsync(req).whenComplete((result, e) -> { return asyncApi.requestAsync(req).whenComplete((result, e) -> {
if (e != null) { if (e != null) {
logger.trace("Request failed: {} Error: {}", req, e.getMessage()); logger.trace("Request failed: {} Error: {}", req, e.getMessage());

View File

@ -94,10 +94,14 @@ public class GrpcServer extends Server {
.maxInboundMessageSize(512 * 1024 * 1024) .maxInboundMessageSize(512 * 1024 * 1024)
.addService(grpc) .addService(grpc)
.build(); .build();
server.start();
LOG.info("GRPC RocksDB server is listening at " + socketAddress); 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 class GrpcServerImpl extends RocksDBServiceImplBase {
private final RocksDBAsyncAPI asyncApi; private final RocksDBAsyncAPI asyncApi;

View File

@ -5,7 +5,7 @@ import it.cavallium.rockserver.core.client.RocksDBConnection;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
public class Server implements Closeable { public abstract class Server implements Closeable {
private final RocksDBConnection client; private final RocksDBConnection client;
@ -17,6 +17,8 @@ public class Server implements Closeable {
return client; return client;
} }
public abstract void start() throws IOException;
@Override @Override
public void close() throws IOException { public void close() throws IOException {
client.close(); client.close();

View File

@ -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) { 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(); return keysMulti.stream().map(keys -> keysToRecord(arena, keys)).toList();
} }