yifan-c commented on code in PR #4399:
URL: https://github.com/apache/cassandra/pull/4399#discussion_r2414917768


##########
src/java/org/apache/cassandra/db/compression/CompressionDictionaryScheduler.java:
##########
@@ -0,0 +1,213 @@
+/*
+ * 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.db.compression;
+
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.TimeUnit;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.concurrent.ScheduledExecutors;
+import org.apache.cassandra.config.DatabaseDescriptor;
+import 
org.apache.cassandra.db.compression.ICompressionDictionaryTrainer.TrainingStatus;
+import org.apache.cassandra.schema.SystemDistributedKeyspace;
+
+/**
+ * Manages scheduled tasks for compression dictionary operations.
+ * <p>
+ * This class handles:
+ * - Periodic refresh of dictionaries from system tables
+ * - Manual training task scheduling and monitoring
+ * - Cleanup of scheduled tasks
+ */
+public class CompressionDictionaryScheduler implements 
ICompressionDictionaryScheduler
+{
+    private static final Logger logger = 
LoggerFactory.getLogger(CompressionDictionaryScheduler.class);
+
+    private final String keyspaceName;
+    private final String tableName;
+    private final ICompressionDictionaryCache cache;
+
+    private volatile ScheduledFuture<?> scheduledRefreshTask;
+    private volatile ScheduledFuture<?> scheduledManualTrainingTask;
+    private volatile boolean isEnabled;
+
+    public CompressionDictionaryScheduler(String keyspaceName,
+                                          String tableName,
+                                          ICompressionDictionaryCache cache,
+                                          boolean isEnabled)
+    {
+        this.keyspaceName = keyspaceName;
+        this.tableName = tableName;
+        this.cache = cache;
+        this.isEnabled = isEnabled;
+    }
+
+    /**
+     * Schedules the periodic dictionary refresh task if not already scheduled.
+     */
+    public void scheduleRefreshTask()
+    {
+        if (scheduledRefreshTask != null)
+            return;
+
+        this.scheduledRefreshTask = 
ScheduledExecutors.scheduledTasks.scheduleWithFixedDelay(
+        this::refreshDictionaryFromSystemTable,
+        
DatabaseDescriptor.getCompressionDictionaryRefreshInitialDelaySeconds(),
+        DatabaseDescriptor.getCompressionDictionaryRefreshIntervalSeconds(),
+        TimeUnit.SECONDS
+        );
+    }
+
+    @Override
+    public void scheduleManualTraining(ManualTrainingOptions options, 
ICompressionDictionaryTrainer trainer)
+    {
+        if (scheduledManualTrainingTask != null)
+        {
+            throw new IllegalStateException("Training already in progress for 
table " + keyspaceName + '.' + tableName);
+        }
+
+        int maxSamplingDurationSeconds = 
options.getMaxSamplingDurationSeconds();
+
+        logger.info("Starting manual dictionary training for {}.{} with max 
sampling duration: {} seconds",
+                    keyspaceName, tableName, maxSamplingDurationSeconds);
+
+        long deadlineMillis = System.currentTimeMillis() + 
TimeUnit.SECONDS.toMillis(maxSamplingDurationSeconds);

Review Comment:
   Addressed



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