sarankk commented on code in PR #187:
URL: https://github.com/apache/cassandra-sidecar/pull/187#discussion_r1942280897


##########
server/src/main/java/org/apache/cassandra/sidecar/db/schema/SidecarSchema.java:
##########
@@ -203,4 +151,52 @@ 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);
+            }
+            catch (CassandraUnavailableException ignored)
+            {
+                LOGGER.debug("Cql session is not yet available. Skip 
initializing...");
+            }
+            catch (Exception ex)
+            {
+                LOGGER.warn("Failed to initialize schema", ex);
+                if (ex instanceof SidecarSchemaModificationException)
+                {
+                    LOGGER.warn("Failed to modify schema", ex);
+                    metrics.failedModifications.metric.update(1);
+                }
+                metrics.failedInitializations.metric.update(1);
+            }
+
+            if (isInitialized())

Review Comment:
   Should we add this block under finally? to ensure `unschedule` is always 
called 
   
   ```
   finally {
           if (isInitialized())
           {
               LOGGER.info("Sidecar schema is initialized. Stopping 
SchemaSidecarInitializer");
               periodicTaskExecutor.unschedule(this); 
               reportSidecarSchemaInitialized();
           } 
          else
          {
               LOGGER.debug("Sidecar schema is not initialized. Retry in {}", 
delay());
          }
          promise.tryComplete();
      }
   ```



-- 
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]

Reply via email to