yifan-c commented on code in PR #187:
URL: https://github.com/apache/cassandra-sidecar/pull/187#discussion_r1943874261
##########
server/src/main/java/org/apache/cassandra/sidecar/db/schema/SidecarSchema.java:
##########
@@ -203,4 +144,49 @@ protected boolean shouldCreateSchema(AbstractSchema schema)
}
return true;
}
+
+ /**
+ * Initializer that retries until sidecar schema is initialized. Once
initialized, it un-schedules itself.
+ */
+ private class SidecarSchemaInitializer implements PeriodicTask
+ {
+ @Override
+ public DurationSpec delay()
+ {
+ return INITIALIZATION_LOOP_DELAY;
+ }
+
+ @Override
+ public void execute(Promise<Void> promise)
+ {
+ try
+ {
+ Session session = cqlSessionProvider.get();
+ isInitialized = sidecarInternalKeyspace.initialize(session,
SidecarSchema.this::shouldCreateSchema);
+
+ if (isInitialized)
+ {
+ LOGGER.info("Sidecar schema is initialized. Stopping
SchemaSidecarInitializer");
+ periodicTaskExecutor.unschedule(this);
+ reportSidecarSchemaInitialized();
+ }
+ }
+ catch (Exception ex)
+ {
+ LOGGER.warn("Failed to initialize schema. Retry in {}",
delay(), ex);
+ if (ex instanceof CassandraUnavailableException)
+ {
+ LOGGER.debug("Cql session is not yet available. Skip
initializing...");
+ return; // do not count Cassandra unavailable as failure
+ }
+ else if (ex instanceof SidecarSchemaModificationException)
+ {
+ LOGGER.warn("Failed to modify schema", ex);
+ metrics.failedModifications.metric.update(1);
+ }
+ metrics.failedInitializations.metric.update(1);
+ }
+ promise.tryComplete();
Review Comment:
I will let the executor to catch and mark the promise as failed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]