andresbeckruiz commented on code in PR #359:
URL: https://github.com/apache/cassandra-sidecar/pull/359#discussion_r3508930067


##########
server/src/main/java/org/apache/cassandra/sidecar/job/DurableOperationalJobTracker.java:
##########
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.sidecar.job;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.inject.Inject;
+import com.google.inject.Singleton;
+import org.apache.cassandra.sidecar.common.data.OperationalJobStatus;
+import org.apache.cassandra.sidecar.concurrent.TaskExecutorPool;
+import org.apache.cassandra.sidecar.config.ServiceConfiguration;
+import org.apache.cassandra.sidecar.job.storage.OperationalJobRecord;
+import org.apache.cassandra.sidecar.job.storage.StorageProvider;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * A durable implementation of {@link OperationalJobTracker} that persists job 
state
+ * via a {@link StorageProvider}. A local {@link ConcurrentHashMap} caches live
+ * {@link OperationalJob} references for the current process, since executing 
jobs
+ * with Vert.x promises cannot be reconstituted from storage. Once a job 
completes,
+ * it is removed from the local map, and subsequent lookups are served from 
storage.
+ */
+@Singleton
+public class DurableOperationalJobTracker implements OperationalJobTracker
+{
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(DurableOperationalJobTracker.class);
+    private static final int MAX_STATUS_UPDATE_ATTEMPTS = 2;
+    private static final long RETRY_DELAY_MS = 100;
+
+    private final ConcurrentHashMap<UUID, OperationalJob> liveJobs;
+    private final StorageProvider storageProvider;
+    private final TaskExecutorPool executor;
+
+    @Inject
+    public DurableOperationalJobTracker(ServiceConfiguration 
serviceConfiguration,
+                                        StorageProvider storageProvider,
+                                        TaskExecutorPool executor)
+    {
+        this.liveJobs = new 
ConcurrentHashMap<>(serviceConfiguration.operationalJobTrackerSize());
+        this.storageProvider = storageProvider;

Review Comment:
   The `StorageProvider` will be initialized externally. 
`DurableOperationalJobTracker` assumes it's already initialized and guards 
against unavailability with the `isAvailable()` check added in 
[464f03e](https://github.com/apache/cassandra-sidecar/pull/359/commits/464f03e82124a4a74bc835b995f25f06856bbc6b).
 
   
   The idea is that an operator will choose between the durable or in-memory 
tracker via configuration. I'm deferring these edits to `sidecar.yaml` to a 
follow up PR once the config is actually being used by a cluster-wide 
operation. 



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