From a3941d555542f3ddd68e933b9f99015425b4be01 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 21 Oct 2025 10:34:30 -0500 Subject: [PATCH] CNDB-15759: add unified_compaction.scaling_parameter_persistence flag --- .../db/compaction/unified/Controller.java | 14 +++++++ .../db/compaction/unified/ControllerTest.java | 37 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/src/java/org/apache/cassandra/db/compaction/unified/Controller.java b/src/java/org/apache/cassandra/db/compaction/unified/Controller.java index cf59f410c15f..af0a596604a3 100644 --- a/src/java/org/apache/cassandra/db/compaction/unified/Controller.java +++ b/src/java/org/apache/cassandra/db/compaction/unified/Controller.java @@ -264,6 +264,14 @@ public abstract class Controller static final boolean ALLOW_UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION = Boolean.parseBoolean(System.getProperty(ALLOW_UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION_PROPERTY)); static final boolean DEFAULT_ALLOW_UNSAFE_AGGRESSIVE_SSTABLE_EXPIRATION = false; + /** + * System property to control writing scaling parameters to JSON configuration file. + * When set to true (default), the controller will persist scaling parameters and flush size to disk. + * When set to false, persistence is disabled. + */ + public static final String SCALING_PARAMETER_PERSISTENCE_PROPERTY = PREFIX + "scaling_parameter_persistence"; + public static final boolean SCALING_PARAMETER_PERSISTENCE = Boolean.parseBoolean(System.getProperty(SCALING_PARAMETER_PERSISTENCE_PROPERTY, "true")); + /** * This property allows seperate defaults for vector and non-vector tables. If this property is set to true * and the table has a {@link VectorType}, the "vector" defaults are used over the regular defaults. For instance, @@ -439,6 +447,12 @@ public static File getControllerConfigPath(TableMetadata metadata) public static void storeOptions(TableMetadata metadata, int[] scalingParameters, long flushSizeBytes) { + if (!SCALING_PARAMETER_PERSISTENCE) + { + logger.debug("Scaling parameter persistence is disabled via {}. Skipping write to disk.", SCALING_PARAMETER_PERSISTENCE_PROPERTY); + return; + } + if (SchemaConstants.isSystemKeyspace(metadata.keyspace)) return; File f = getControllerConfigPath(metadata); diff --git a/test/unit/org/apache/cassandra/db/compaction/unified/ControllerTest.java b/test/unit/org/apache/cassandra/db/compaction/unified/ControllerTest.java index 84c7c57627b4..5120e89b1d7b 100644 --- a/test/unit/org/apache/cassandra/db/compaction/unified/ControllerTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/unified/ControllerTest.java @@ -914,4 +914,41 @@ public void testGetLargestFactorizedShardCount() assertEquals(1, controller.getLargestFactorizedShardCount(-1.0)); assertEquals(1, controller.getLargestFactorizedShardCount(-100.0)); } + + @Test + public void testScalingParameterPersistenceEnabled() + { + // Verify that by default (SCALING_PARAMETER_PERSISTENCE = true), storeOptions creates a file + assertTrue("Scaling parameter persistence should be enabled by default", Controller.SCALING_PARAMETER_PERSISTENCE); + + TableMetadata testMetadata = standardCFMD("test_ks", "test_table").build(); + int[] scalingParameters = new int[] { 0, 2, 4 }; + long flushSize = 100 << 20; // 100 MB + + // Store the options - should create a file when persistence is enabled + Controller.storeOptions(testMetadata, scalingParameters, flushSize); + + // Verify the file was created + org.apache.cassandra.io.util.File configPath = Controller.getControllerConfigPath(testMetadata); + assertTrue("Config file should exist when persistence is enabled", configPath.exists()); + + // Clean up + configPath.delete(); + } + + @Test + public void testScalingParameterPersistenceSystemKeyspace() + { + // Verify that system keyspaces never write config files regardless of persistence setting + TableMetadata systemMetadata = standardCFMD("system", "test_table").build(); + int[] scalingParameters = new int[] { 0, 2, 4 }; + long flushSize = 100 << 20; // 100 MB + + // Store the options - should not create a file for system keyspace + Controller.storeOptions(systemMetadata, scalingParameters, flushSize); + + // Verify the file was NOT created + org.apache.cassandra.io.util.File configPath = Controller.getControllerConfigPath(systemMetadata); + assertFalse("Config file should not exist for system keyspace", configPath.exists()); + } }