Skip to content

Commit

Permalink
Fixes for Cottontail DB Adapter (#260)
Browse files Browse the repository at this point in the history
* CottontailSelector.existsEntity() properly handles NOT_FOUND exception. Fixes #255

* Connection output is less verbose. What is logged is logged at DEBUG level now. Addresses #258

* Initialization steps are now wrapped in a try...catch block, which should prevent failing components from killing the CLI. Addresses #257

* More fine-grained try...catch blocks, so that we know exactly, which component failed.

* Removed try...catch around server.start()

Co-authored-by: Ralph Gasser <[email protected]>
Former-commit-id: d9efa6b
  • Loading branch information
silvanheller and ppanopticon authored Feb 10, 2022
1 parent ac56496 commit 7cc93f2
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GRPCEndpoint {

private static final Logger LOGGER = LogManager.getLogger();

public static void start() {
public static void start() throws IOException {

if (!Config.sharedConfig().getApi().getEnableGRPC()) {
return;
Expand All @@ -27,17 +27,12 @@ public static void start() {
int port = Config.sharedConfig().getApi().getGrpcPort();

LOGGER.info("Starting GRPC Endpoint at port {}", port);

server = ServerBuilder.forPort(port).addService(new CineastQueryService(APIEndpoint.retrievalLogic)) //FIXME this should come from a more reasonable location
.addService(new CineastExtractionService()).addService(new CineastManagementService()).build();

try {
server.start();
} catch (IOException e) {
}

server.start();
}


public static void stop() {
if (server == null || server.isShutdown()) {
return;
Expand All @@ -51,5 +46,4 @@ public static void stop() {
}
server.shutdownNow();
}

}
24 changes: 19 additions & 5 deletions cineast-api/src/main/java/org/vitrivr/cineast/api/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,26 @@ public static void main(String[] args) {
}
}

/* Start Cineast API endpoint. */
APIEndpoint.getInstance().start();
GRPCEndpoint.start();
/* Start API endpoint. */
try {
APIEndpoint.getInstance().start();
} catch (Throwable e) {
System.err.println("Failed to initialize API endpoint due to an exception: " + e.getMessage());
}

/* Start gRPC endpoint. */
try {
GRPCEndpoint.start();
} catch (Throwable e) {
System.err.println("Failed to initialize gRPC endpoint due to an exception: " + e.getMessage());
}

/* Initalize Monitoring */
PrometheusServer.initialize();
/* Initialize Monitoring */
try {
PrometheusServer.initialize();
} catch (Throwable e) {
System.err.println("Failed to initialize Monitoring due to an exception: " + e.getMessage());
}

/* Start Cineast CLI in interactive mode (blocking). */
CLI.start(CineastCli.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static org.vitrivr.cineast.core.util.CineastConstants.GENERIC_ID_COLUMN_QUALIFIER;
import static org.vitrivr.cineast.core.util.CineastConstants.KEY_COL_NAME;

import io.grpc.Status.Code;
import io.grpc.StatusRuntimeException;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -344,8 +345,13 @@ public boolean existsEntity(String name) {
final AboutEntity about = new AboutEntity(this.cottontail.fqnInput(name));
try (final TupleIterator results = this.cottontail.client.about(about)) {
return results.hasNext();
} catch (StatusRuntimeException e) {
if (e.getStatus().getCode() != Code.NOT_FOUND) {
LOGGER.error("Error occurred during query execution in existsEntity(): {}!", e.getMessage());
}
return false;
} catch (Exception e) {
LOGGER.error("Failed to close TupleIterator!", e);
LOGGER.error("Error occurred during query execution in existsEntity(): {}!", e.getMessage());
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ private static ManagedChannel createChannel(String host, int port) {
final NettyChannelBuilder builder = NettyChannelBuilder.forAddress(host, port).usePlaintext();
final ManagedChannel channel = builder.build();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
LOGGER.info("Closing connection to Cottontail DB.");
LOGGER.debug("Closing connection to Cottontail DB.");
channel.shutdownNow();
}));
watch.stop();
LOGGER.info("Connected to Cottontail DB in {} ms at {}:{}", watch.getTime(TimeUnit.MILLISECONDS), host, port);
LOGGER.debug("Connected to Cottontail DB in {} ms at {}:{}", watch.getTime(TimeUnit.MILLISECONDS), host, port);
return channel;
}

Expand All @@ -91,11 +91,7 @@ public CottontailWrapper(String host, int port) {
this.client = new SimpleClient(sharedChannel(host, port));
boolean pingSuccessful = this.client.ping();
watch.stop();
if (pingSuccessful) {
LOGGER.info("Connected to Cottontail in {} ms at {}:{}", watch.getTime(TimeUnit.MILLISECONDS), host, port);
} else {
LOGGER.warn("Could not connect to Cottontail at {}:{}", host, port);
}
if (!pingSuccessful) LOGGER.warn("Could not ping Cottontail DB instance at {}:{}", host, port);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ public static void main(String[] args) {
System.exit(1);
}

/* Initalize Monitoring */
PrometheusServer.initialize();
/* Initialize Monitoring */
try {
PrometheusServer.initialize();
} catch (Throwable e) {
System.err.println("Failed to initialize Monitoring due to an exception: " + e.getMessage());
}

if (args.length == 1) {
CLI.start(CineastCli.class);
Expand Down

0 comments on commit 7cc93f2

Please sign in to comment.