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


##########
src/java/org/apache/cassandra/db/compression/CompressionDictionaryManager.java:
##########
@@ -0,0 +1,346 @@
+/*
+ * 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.nio.ByteBuffer;
+import java.util.Map;
+import javax.annotation.Nullable;
+
+import com.google.common.annotations.VisibleForTesting;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.cassandra.config.DatabaseDescriptor;
+import org.apache.cassandra.db.ColumnFamilyStore;
+import 
org.apache.cassandra.db.compression.ICompressionDictionaryTrainer.TrainingStatus;
+import org.apache.cassandra.schema.CompressionParams;
+import org.apache.cassandra.schema.SystemDistributedKeyspace;
+import org.apache.cassandra.utils.MBeanWrapper;
+import org.apache.cassandra.utils.MBeanWrapper.OnException;
+
+public class CompressionDictionaryManager implements 
CompressionDictionaryManagerMBean,
+                                                     
ICompressionDictionaryCache,
+                                                     
ICompressionDictionaryEventHandler,
+                                                     AutoCloseable
+{
+    private static final Logger logger = 
LoggerFactory.getLogger(CompressionDictionaryManager.class);
+
+    private final String keyspaceName;
+    private final String tableName;
+    private volatile boolean mbeanRegistered;
+    private volatile boolean isEnabled;
+
+    // Components
+    private final ICompressionDictionaryEventHandler eventHandler;
+    private final ICompressionDictionaryCache cache;
+    private final ICompressionDictionaryScheduler scheduler;
+    private ICompressionDictionaryTrainer trainer = null;
+
+    public CompressionDictionaryManager(ColumnFamilyStore columnFamilyStore, 
boolean registerBookkeeping)
+    {
+        this.keyspaceName = columnFamilyStore.keyspace.getName();
+        this.tableName = columnFamilyStore.getTableName();
+
+        this.isEnabled = 
columnFamilyStore.metadata().params.compression.isDictionaryCompressionEnabled();
+        this.cache = new CompressionDictionaryCache();
+        this.eventHandler = new 
CompressionDictionaryEventHandler(columnFamilyStore, cache);
+        this.scheduler = new CompressionDictionaryScheduler(keyspaceName, 
tableName, cache, isEnabled);
+        if (isEnabled)
+        {
+            // Initialize components
+            this.trainer = ICompressionDictionaryTrainer.create(keyspaceName, 
tableName,
+                                                                
columnFamilyStore.metadata().params.compression,
+                                                                
createTrainingConfig());
+            trainer.setDictionaryTrainedListener(this::handleNewDictionary);
+
+            scheduler.scheduleRefreshTask();
+
+            trainer.start(false);
+        }
+
+        if (registerBookkeeping)
+        {
+            MBeanWrapper.instance.registerMBean(this, mbeanName(keyspaceName, 
tableName));
+        }
+        mbeanRegistered = registerBookkeeping;
+    }
+
+    static String mbeanName(String keyspaceName, String tableName)
+    {
+        return 
"org.apache.cassandra.db.compression:type=CompressionDictionaryManager" +

Review Comment:
   ok. 



##########
conf/cassandra.yaml:
##########
@@ -617,6 +617,54 @@ counter_cache_save_period: 7200s
 # Disabled by default, meaning all keys are going to be saved
 # counter_cache_keys_to_save: 100
 
+# Dictionary compression settings for ZSTD dictionary-based compression
+# These settings control the automatic training and caching of compression 
dictionaries
+# for tables that use ZSTD dictionary compression.
+
+# How often to refresh compression dictionaries across the cluster.
+# During refresh, nodes will check for newer dictionary versions and update 
their caches.
+# Min unit: s
+compression_dictionary_refresh_interval: 3600s
+
+# Initial delay before starting the first dictionary refresh cycle after node 
startup.
+# This prevents all nodes from refreshing simultaneously when the cluster 
starts.
+# Min unit: s
+compression_dictionary_refresh_initial_delay: 10s
+
+# Maximum number of compression dictionaries to cache per table.
+# Each table using dictionary compression can have multiple dictionaries cached
+# (current version plus recently used versions for reading older SSTables).
+compression_dictionary_cache_size: 10
+
+# How long to keep compression dictionaries in the cache before they expire.
+# Expired dictionaries will be removed from memory but can be reloaded if 
needed.
+# Min unit: s
+compression_dictionary_cache_expire: 3600s
+
+# Dictionary training configuration (advanced settings)
+# These settings control how compression dictionaries are trained from sample 
data.
+
+# Maximum size of a trained compression dictionary in bytes.
+# Larger dictionaries may provide better compression but use more memory.
+# Min unit: B
+compression_dictionary_training_max_dictionary_size: 65536

Review Comment:
   Agreed.



##########
conf/cassandra.yaml:
##########
@@ -617,6 +617,54 @@ counter_cache_save_period: 7200s
 # Disabled by default, meaning all keys are going to be saved
 # counter_cache_keys_to_save: 100
 
+# Dictionary compression settings for ZSTD dictionary-based compression

Review Comment:
   Make sense. Moved the section to the bottom and replicated to the 
`cassandra_latest.yaml` too (at the end).



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