You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pr@cassandra.apache.org by "nikhilkumawat03 (via GitHub)" <gi...@apache.org> on 2025/07/05 03:12:02 UTC

[PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

nikhilkumawat03 opened a new pull request, #4228:
URL: https://github.com/apache/cassandra/pull/4228

   ### Issue Description:
   
   Fuzz testing revealed a RuntimeException in LeveledManifest.maxBytesForLevel during repair operations when compaction parameters cause the calculated maximum bytes for a level to exceed Long.MAX_VALUE (9,223,372,036,854,775,807). The error occurs with inputs like fanout_size=90, sstable_size_in_mb=1088, and level=8, resulting in Math.pow(90, 8) * 1141899264 ≈ 4.9155 × 10²⁴, which exceeds Long.MAX_VALUE. The issue arises because LeveledCompactionStrategy does not validate these parameters during table creation, allowing invalid configurations to persist until repair.
   
   ### The original error (from LeveledManifest.java):
   `java.lang.RuntimeException: At most 9223372036854775807 bytes may be in a compaction level; your maxSSTableSize must be absurdly high to compute 4.915501902751334E24`
   
   This PR adds proactive validation in LeveledCompactionStrategy.validateOptions to ensure fanout_size and sstable_size_in_mb do not cause an overflow, throwing a ConfigurationException during CREATE TABLE or ALTER TABLE instead of failing later during repair.
    
   ### Example which created issue during fuzz testing ([CASSANDRA-20570](https://issues.apache.org/jira/browse/CASSANDRA-20570))
   
   ```
   CREATE KEYSPACE test WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
   CREATE TABLE test.table1 (k int PRIMARY KEY, v int)
       WITH compaction = {
           'class': 'LeveledCompactionStrategy',
           'fanout_size': '90',
           'sstable_size_in_mb': '1088'
       };
   ```
   Patch by: Nikhil Kumawat;
   Reviewed by: TBD
   JIRA: [CASSANDRA-20570](https://issues.apache.org/jira/browse/CASSANDRA-20570)


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2193514816


##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,34 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize()
+    {
+        try
+        {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+            Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+        }
+        catch (ConfigurationException e)
+        {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+        }
+    }
+
+    @Test
+    public void testValidOptions()
+    {
+        Map<String, String> options = new HashMap<>();
+        options.put("class", "LeveledCompactionStrategy");
+        options.put("fanout_size", "10");
+        options.put("sstable_size_in_mb", "160");
+        LeveledCompactionStrategy.validateOptions(options);

Review Comment:
   Removed this test case as these parameters already covered in CreateTableValidationTest.java indirectly through CQL pipeline and this functionality is kinda covered with 'fanout_size': '90', 'sstable_size_in_mb': '1089' values.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2194746163


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 package org.apache.cassandra.cql3;
+import org.apache.cassandra.exceptions.ConfigurationException;
 

Review Comment:
   Done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2192995687


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,32 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test
+    public void testInvalidCompactionOptions()
+    {
+        try
+        {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +

Review Comment:
   `CreateTableValidationTest` makes sense, or a new test class focused on `LeveledCompactionStrategy` validation



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2191406633


##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test
+    public void testValidOptions() {
+        try {

Review Comment:
   Done



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test
+    public void testValidOptions() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "10");
+            options.put("sstable_size_in_mb", "160");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (Exception e) {

Review Comment:
   Done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2191406918


##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test
+    public void testValidOptions() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "10");
+            options.put("sstable_size_in_mb", "160");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (Exception e) {
+            Assert.fail("fanout_sizeed and sstable_size_in_mb are valid, but threw  " + e.getClass().getName());

Review Comment:
   Done



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");

Review Comment:
   Done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "Maxwell-Guo (via GitHub)" <gi...@apache.org>.
Maxwell-Guo commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2272511156


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -589,15 +595,31 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
         String levelFanoutSize = options.containsKey(LEVEL_FANOUT_SIZE_OPTION) ? options.get(LEVEL_FANOUT_SIZE_OPTION) : String.valueOf(DEFAULT_LEVEL_FANOUT_SIZE);
         try
         {
-            int fanoutSize = Integer.parseInt(levelFanoutSize);
+            fanoutSize = Integer.parseInt(levelFanoutSize);
             if (fanoutSize < 1)
             {
                 throw new ConfigurationException(String.format("%s must be larger than 0, but was %s", LEVEL_FANOUT_SIZE_OPTION, fanoutSize));
             }
         }
         catch (NumberFormatException ex)
         {
-            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
+            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", levelFanoutSize, LEVEL_FANOUT_SIZE_OPTION), ex);
+        }
+
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);

Review Comment:
   should we change to : 
   `BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT - 1);`
   cc @dcapwell 



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "Maxwell-Guo (via GitHub)" <gi...@apache.org>.
Maxwell-Guo commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2192241962


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +606,22 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);
+            BigInteger maxBytes = fanoutPower.multiply(BigInteger.valueOf(maxSSTableSizeInBytes));
+            BigInteger longMaxValue = BigInteger.valueOf(Long.MAX_VALUE);
+            if (maxBytes.compareTo(longMaxValue) > 0)
+                throw new ConfigurationException(String.format("At most %s bytes may be in a compaction level; " +
+                        "your maxSSTableSize must be absurdly high to compute %s", Long.MAX_VALUE, maxBytes));
+        }
+        catch (ArithmeticException ex)
+        {
+            throw new ConfigurationException(String.format("sstable_size_in_mb=%d is too large; resulting bytes exceed Long.MAX_VALUE (%d)", ssSize, Long.MAX_VALUE), ex);

Review Comment:
   what about merge the lines from 574 to 622 to one try catch ? 



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2194740070


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +606,22 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);
+            BigInteger maxBytes = fanoutPower.multiply(BigInteger.valueOf(maxSSTableSizeInBytes));
+            BigInteger longMaxValue = BigInteger.valueOf(Long.MAX_VALUE);
+            if (maxBytes.compareTo(longMaxValue) > 0)
+                throw new ConfigurationException(String.format("At most %s bytes may be in a compaction level; " +
+                        "your maxSSTableSize must be absurdly high to compute %s", Long.MAX_VALUE, maxBytes));
+        }
+        catch (ArithmeticException ex)
+        {
+            throw new ConfigurationException(String.format("sstable_size_in_mb=%d is too large; resulting bytes exceed Long.MAX_VALUE (%d)", ssSize, Long.MAX_VALUE), ex);

Review Comment:
   Hello, we can catch the NumberFormatException but the code won't be able to tell whether NumberFormatException occur due to ssStable or fanoutSize.
   To differentiate it I have created Exception



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2192998642


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,32 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test
+    public void testInvalidCompactionOptions()
+    {
+        try
+        {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+            fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+        }
+        catch (ConfigurationException e)
+        {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+        }
+    }
+
+    @Test
+    public void testValidCompactionOptions()
+    {
+        createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                "'class': 'LeveledCompactionStrategy', " +
+                "'fanout_size': '10', " +

Review Comment:
   there are existing tests that cover this
   
   ```
   $ grep -r fanout_size test/
   test//unit/org/apache/cassandra/cql3/validation/miscellaneous/OverflowTest.java:                    + "AND compaction = { 'class' : 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 10, 'fanout_size' : 5 } "
   test//unit/org/apache/cassandra/SchemaLoader.java:        leveledOptions.put("fanout_size", "5");
   test//unit/org/apache/cassandra/schema/createlike/CreateLikeTest.java:        alterTable("ALTER TABLE " + sourceKs + "." + sourceTb + " WITH compaction = {'class':'LeveledCompactionStrategy', 'sstable_size_in_mb' : 10, 'fanout_size' : 16} ");
   test//unit/org/apache/cassandra/schema/createlike/CreateLikeTest.java:        String tableCompactionLcs = createTable(sourceKs, "CREATE TABLE %s (a text, b int, c int, primary key (a, b)) WITH compaction = {'class' : 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 1, 'fanout_size' : 5};");
   test//unit/org/apache/cassandra/schema/createlike/CreateLikeTest.java:        String tableCopyAndSetLCSCompaction = createTableLike("CREATE TABLE %s LIKE %s WITH compaction = {'class' : 'LeveledCompactionStrategy', 'sstable_size_in_mb' : 10, 'fanout_size' : 16};",
   test//unit/org/apache/cassandra/schema/createlike/CreateLikeTest.java:                                                                                                             "fanout_size", "16")))
   test//unit/org/apache/cassandra/db/compaction/CompactionsCQLTest.java:        createTable("CREATE TABLE %s (id text PRIMARY KEY) WITH compaction = {'class':'LeveledCompactionStrategy', 'sstable_size_in_mb':1, 'fanout_size':5};");
   ```
   
   `test//unit/org/apache/cassandra/db/compaction/CompactionsCQLTest.java` explicitly touches both configs. 
   
   If there is a reason to keep it can we document in the code why this should exist compared to existing tests?



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2193501415


##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {

Review Comment:
   Done



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {

Review Comment:
   Done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "Maxwell-Guo (via GitHub)" <gi...@apache.org>.
Maxwell-Guo commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2194407101


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -16,6 +16,7 @@
  * limitations under the License.
  */
 package org.apache.cassandra.cql3;
+import org.apache.cassandra.exceptions.ConfigurationException;
 

Review Comment:
   please remove unused imports.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "Maxwell-Guo (via GitHub)" <gi...@apache.org>.
Maxwell-Guo commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2272511156


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -589,15 +595,31 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
         String levelFanoutSize = options.containsKey(LEVEL_FANOUT_SIZE_OPTION) ? options.get(LEVEL_FANOUT_SIZE_OPTION) : String.valueOf(DEFAULT_LEVEL_FANOUT_SIZE);
         try
         {
-            int fanoutSize = Integer.parseInt(levelFanoutSize);
+            fanoutSize = Integer.parseInt(levelFanoutSize);
             if (fanoutSize < 1)
             {
                 throw new ConfigurationException(String.format("%s must be larger than 0, but was %s", LEVEL_FANOUT_SIZE_OPTION, fanoutSize));
             }
         }
         catch (NumberFormatException ex)
         {
-            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
+            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", levelFanoutSize, LEVEL_FANOUT_SIZE_OPTION), ex);
+        }
+
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);

Review Comment:
   should we change to : 
   `BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT - 1);`
   we have at most MAX_LEVEL_COUNT level, so should we remove the first level or the 0 level ? then the 
   result is MAX_LEVEL_COUNT - 1 ? am i right ?
   
   cc @dcapwell 



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2193402233


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +606,22 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);
+            BigInteger maxBytes = fanoutPower.multiply(BigInteger.valueOf(maxSSTableSizeInBytes));
+            BigInteger longMaxValue = BigInteger.valueOf(Long.MAX_VALUE);
+            if (maxBytes.compareTo(longMaxValue) > 0)
+                throw new ConfigurationException(String.format("At most %s bytes may be in a compaction level; " +
+                        "your maxSSTableSize must be absurdly high to compute %s", Long.MAX_VALUE, maxBytes));
+        }
+        catch (ArithmeticException ex)
+        {
+            throw new ConfigurationException(String.format("sstable_size_in_mb=%d is too large; resulting bytes exceed Long.MAX_VALUE (%d)", ssSize, Long.MAX_VALUE), ex);

Review Comment:
   @Maxwell-Guo I considered merging the three try-catch blocks into one to reduce code length, but kept them separate for more specific error messages (e.g., distinguishing invalid sstable_size_in_mb vs. fanout_size vs. overflow). Happy to merge into a single try-catch if you prefer a more concise approach—please let me know!



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2191406027


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -569,10 +570,14 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
     {
         Map<String, String> uncheckedOptions = AbstractCompactionStrategy.validateOptions(options);
 
+        int ssSize = 1;
+        int fanoutSize = 1;

Review Comment:
   Done



##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +605,19 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try {

Review Comment:
   Done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "Maxwell-Guo (via GitHub)" <gi...@apache.org>.
Maxwell-Guo commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2192320366


##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,34 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize()
+    {
+        try
+        {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+            Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+        }
+        catch (ConfigurationException e)
+        {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+        }
+    }
+
+    @Test
+    public void testValidOptions()
+    {
+        Map<String, String> options = new HashMap<>();
+        options.put("class", "LeveledCompactionStrategy");
+        options.put("fanout_size", "10");
+        options.put("sstable_size_in_mb", "160");
+        LeveledCompactionStrategy.validateOptions(options);

Review Comment:
   do we really need this test case ?



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,34 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize()
+    {
+        try
+        {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+            Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");

Review Comment:
   see this test case, https://github.com/apache/cassandra/blob/trunk/test/unit/org/apache/cassandra/schema/CreateTableValidationTest.java#L38 
   expectedFailure is more readable . 



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,32 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test
+    public void testInvalidCompactionOptions()
+    {
+        try
+        {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +

Review Comment:
   nit : Formatting issue, should be in the same line as above, or aligned with above



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,32 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test
+    public void testInvalidCompactionOptions()
+    {
+        try
+        {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+            fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+        }
+        catch (ConfigurationException e)
+        {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+        }
+    }
+
+    @Test
+    public void testValidCompactionOptions()
+    {
+        createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                "'class': 'LeveledCompactionStrategy', " +
+                "'fanout_size': '10', " +

Review Comment:
   nit : Formatting issue, should be in the same line as above, or aligned with above



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,32 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test
+    public void testInvalidCompactionOptions()
+    {
+        try
+        {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+            fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+        }
+        catch (ConfigurationException e)
+        {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+        }
+    }
+
+    @Test
+    public void testValidCompactionOptions()
+    {
+        createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                "'class': 'LeveledCompactionStrategy', " +
+                "'fanout_size': '10', " +

Review Comment:
   do we really need this test case ?



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,32 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test
+    public void testInvalidCompactionOptions()
+    {
+        try
+        {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +

Review Comment:
   i think these test cases can be moved to https://github.com/apache/cassandra/blob/trunk/test/unit/org/apache/cassandra/schema/CreateTableValidationTest.java
   



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2191180726


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");

Review Comment:
   nit: less code if you move `fail` to the `try` block rather than require the `return`



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test()
+    public void testValidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '10', " +
+                    "'sstable_size_in_mb': '160'}");
+        }
+        catch (Exception e) {
+            fail("fanout_sizeed and sstable_size_in_mb are valid, but threw  " + e.getClass().getName());

Review Comment:
   can we remove the try/catch?  its cleaner to just let it bubble up than to recatch and loose context.  It also is harder to read as I have to now understand why we are catching



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test
+    public void testValidOptions() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "10");
+            options.put("sstable_size_in_mb", "160");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (Exception e) {
+            Assert.fail("fanout_sizeed and sstable_size_in_mb are valid, but threw  " + e.getClass().getName());

Review Comment:
   can we remove the try/catch?  its cleaner to just let it bubble up than to recatch and loose context.  It also is harder to read as I have to now understand why we are catching



##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -569,10 +570,14 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
     {
         Map<String, String> uncheckedOptions = AbstractCompactionStrategy.validateOptions(options);
 
+        int ssSize = 1;
+        int fanoutSize = 1;

Review Comment:
   can we avoid default values?  Makes me double check they are safe, so if we drop we can let the compiler make sure its safe instead?



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {

Review Comment:
   style: move `{` to the next line



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {

Review Comment:
   style: move `{` to the next line



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {

Review Comment:
   style: move `{` to the next line



##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +605,19 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try {

Review Comment:
   style: move `{` to the next line



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test()
+    public void testValidCompactionOptions()
+    {
+        try {

Review Comment:
   style: move `{` to the next line



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+        }
+        catch (ConfigurationException e) {

Review Comment:
   style: move `{` to the next line



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test
+    public void testValidOptions() {
+        try {

Review Comment:
   style: move `{` to the next line



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test
+    public void testValidOptions() {

Review Comment:
   style: move `{` to the next line



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {

Review Comment:
   style: move `{` to the next line



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");

Review Comment:
   nit, if you move this into the `try` block you can remove the `return`



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test
+    public void testValidOptions() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "10");
+            options.put("sstable_size_in_mb", "160");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (Exception e) {

Review Comment:
   style: move `{` to the next line



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2191405866


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +605,19 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            double maxBytes = Math.pow(fanoutSize, MAX_LEVEL_COUNT) * maxSSTableSizeInBytes;
+            if (Double.isInfinite(maxBytes) || maxBytes > Long.MAX_VALUE)

Review Comment:
   I agree that double’s limited precision could lead to inaccuracies. To address this, I’ve updated the code to use BigInteger for exact integer arithmetic, which eliminates precision loss for this calculation. 
   
   Since the inputs (fanoutSize, ssSize, MAX_LEVEL_COUNT) and the result are all integers, BigInteger is sufficient and avoids the overhead of BigDecimal’s decimal handling.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2347306139


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -589,15 +595,31 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
         String levelFanoutSize = options.containsKey(LEVEL_FANOUT_SIZE_OPTION) ? options.get(LEVEL_FANOUT_SIZE_OPTION) : String.valueOf(DEFAULT_LEVEL_FANOUT_SIZE);
         try
         {
-            int fanoutSize = Integer.parseInt(levelFanoutSize);
+            fanoutSize = Integer.parseInt(levelFanoutSize);
             if (fanoutSize < 1)
             {
                 throw new ConfigurationException(String.format("%s must be larger than 0, but was %s", LEVEL_FANOUT_SIZE_OPTION, fanoutSize));
             }
         }
         catch (NumberFormatException ex)
         {
-            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
+            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", levelFanoutSize, LEVEL_FANOUT_SIZE_OPTION), ex);
+        }
+
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);

Review Comment:
   @Maxwell-Guo I have implemented the suggested changes.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "Maxwell-Guo (via GitHub)" <gi...@apache.org>.
Maxwell-Guo commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2189026035


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +605,19 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            double maxBytes = Math.pow(fanoutSize, MAX_LEVEL_COUNT) * maxSSTableSizeInBytes;
+            if (Double.isInfinite(maxBytes) || maxBytes > Long.MAX_VALUE)

Review Comment:
   I think there may exist some problem here, maxBytes is a double and Long.Max_VALUE is a Long ,there may be a loss of precision when doing comparison. 
    it is better to use decimal 



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2193500601


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,32 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test
+    public void testInvalidCompactionOptions()
+    {
+        try
+        {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +

Review Comment:
   @Maxwell-Guo CQL statement is made in the single line and test case is moved to CreateTableValidationTest.java, @dcapwell I considered LevelCompactionStrategyValidationTest.java but a similar naming convention 'LevelCompactionStrategyTest.java' is used for programmatical 'LevelCompactionStrategy' tests but not for 'CREATE TABLE' statements like test cases. Hence, put the test case in 'CreateTableValidationTest.java'



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2194081948


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +606,22 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);
+            BigInteger maxBytes = fanoutPower.multiply(BigInteger.valueOf(maxSSTableSizeInBytes));
+            BigInteger longMaxValue = BigInteger.valueOf(Long.MAX_VALUE);
+            if (maxBytes.compareTo(longMaxValue) > 0)
+                throw new ConfigurationException(String.format("At most %s bytes may be in a compaction level; " +
+                        "your maxSSTableSize must be absurdly high to compute %s", Long.MAX_VALUE, maxBytes));
+        }
+        catch (ArithmeticException ex)
+        {
+            throw new ConfigurationException(String.format("sstable_size_in_mb=%d is too large; resulting bytes exceed Long.MAX_VALUE (%d)", ssSize, Long.MAX_VALUE), ex);

Review Comment:
   int ssSize = Integer.parseInt(size);
   int fanoutSize = Integer.parseInt(levelFanoutSize);
   
   For above two statements, nn case size or levelFanoutSize statement is not able to parse the 'Integer.parseInt(size)' in this case we are catching NumberFormatException and throwing ConfigurationException respectively.
   
   In above case the code is only catching ConfigurationException ex



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2191406475


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+        }
+        catch (ConfigurationException e) {

Review Comment:
   Done



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test
+    public void testValidOptions() {

Review Comment:
   Done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2191406278


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");

Review Comment:
   Done



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {

Review Comment:
   Done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2193501098


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test()
+    public void testValidCompactionOptions()
+    {
+        try {

Review Comment:
   Done



##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,36 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test()
+    public void testInvalidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+        }
+        catch (ConfigurationException e) {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+            return;
+        }
+        fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+    }
+
+    @Test()
+    public void testValidCompactionOptions()
+    {
+        try {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '10', " +
+                    "'sstable_size_in_mb': '160'}");
+        }
+        catch (Exception e) {
+            fail("fanout_sizeed and sstable_size_in_mb are valid, but threw  " + e.getClass().getName());

Review Comment:
   Done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "Maxwell-Guo (via GitHub)" <gi...@apache.org>.
Maxwell-Guo commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2193882943


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +606,22 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);
+            BigInteger maxBytes = fanoutPower.multiply(BigInteger.valueOf(maxSSTableSizeInBytes));
+            BigInteger longMaxValue = BigInteger.valueOf(Long.MAX_VALUE);
+            if (maxBytes.compareTo(longMaxValue) > 0)
+                throw new ConfigurationException(String.format("At most %s bytes may be in a compaction level; " +
+                        "your maxSSTableSize must be absurdly high to compute %s", Long.MAX_VALUE, maxBytes));
+        }
+        catch (ArithmeticException ex)
+        {
+            throw new ConfigurationException(String.format("sstable_size_in_mb=%d is too large; resulting bytes exceed Long.MAX_VALUE (%d)", ssSize, Long.MAX_VALUE), ex);

Review Comment:
   ```
       try
           {
               // Validate the sstable_size option
               String size = options.containsKey(SSTABLE_SIZE_OPTION) ? options.get(SSTABLE_SIZE_OPTION) : "1";
               int ssSize = Integer.parseInt(size);
               if (ssSize < 1)
               {
                   throw new ConfigurationException(String.format("%s must be larger than 0, but was %s", SSTABLE_SIZE_OPTION, ssSize));
               }
               uncheckedOptions.remove(SSTABLE_SIZE_OPTION);
               // Validate the fanout_size option
               String levelFanoutSize = options.containsKey(LEVEL_FANOUT_SIZE_OPTION) ? options.get(LEVEL_FANOUT_SIZE_OPTION) : String.valueOf(DEFAULT_LEVEL_FANOUT_SIZE);
               int fanoutSize = Integer.parseInt(levelFanoutSize);
               if (fanoutSize < 1)
               {
                   throw new ConfigurationException(String.format("%s must be larger than 0, but was %s", LEVEL_FANOUT_SIZE_OPTION, fanoutSize));
               }
   
               // Validate max Bytes for a level
               long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
               BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);
               BigInteger maxBytes = fanoutPower.multiply(BigInteger.valueOf(maxSSTableSizeInBytes));
               BigInteger longMaxValue = BigInteger.valueOf(Long.MAX_VALUE);
               if (maxBytes.compareTo(longMaxValue) > 0)
                   throw new ConfigurationException(String.format("At most %s bytes may be in a compaction level; " +
                                                                  "your maxSSTableSize must be absurdly high to compute %s", Long.MAX_VALUE, maxBytes));
           }
           catch (ConfigurationException ex)
           {
               throw ex;
           }
   ```
   what about this ?



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "Maxwell-Guo (via GitHub)" <gi...@apache.org>.
Maxwell-Guo commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2194215267


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +606,22 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);
+            BigInteger maxBytes = fanoutPower.multiply(BigInteger.valueOf(maxSSTableSizeInBytes));
+            BigInteger longMaxValue = BigInteger.valueOf(Long.MAX_VALUE);
+            if (maxBytes.compareTo(longMaxValue) > 0)
+                throw new ConfigurationException(String.format("At most %s bytes may be in a compaction level; " +
+                        "your maxSSTableSize must be absurdly high to compute %s", Long.MAX_VALUE, maxBytes));
+        }
+        catch (ArithmeticException ex)
+        {
+            throw new ConfigurationException(String.format("sstable_size_in_mb=%d is too large; resulting bytes exceed Long.MAX_VALUE (%d)", ssSize, Long.MAX_VALUE), ex);

Review Comment:
   you can catch different exception here. I just show you the demo.



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2194081948


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -600,6 +606,22 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
             throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
         }
 
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);
+            BigInteger maxBytes = fanoutPower.multiply(BigInteger.valueOf(maxSSTableSizeInBytes));
+            BigInteger longMaxValue = BigInteger.valueOf(Long.MAX_VALUE);
+            if (maxBytes.compareTo(longMaxValue) > 0)
+                throw new ConfigurationException(String.format("At most %s bytes may be in a compaction level; " +
+                        "your maxSSTableSize must be absurdly high to compute %s", Long.MAX_VALUE, maxBytes));
+        }
+        catch (ArithmeticException ex)
+        {
+            throw new ConfigurationException(String.format("sstable_size_in_mb=%d is too large; resulting bytes exceed Long.MAX_VALUE (%d)", ssSize, Long.MAX_VALUE), ex);

Review Comment:
   int ssSize = Integer.parseInt(size);
   int fanoutSize = Integer.parseInt(levelFanoutSize);
   
   For above two statements, In case size or levelFanoutSize statement is not able to parse the 'Integer.parseInt(size)' in this case we are catching NumberFormatException and throwing ConfigurationException respectively.
   
   In above case the code is only catching ConfigurationException ex



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2193499376


##########
test/unit/org/apache/cassandra/cql3/SimpleQueryTest.java:
##########
@@ -561,6 +564,32 @@ public void testSStableTimestampOrdering() throws Throwable
         assertRows(execute("SELECT * FROM %s WHERE k1=1"), row(1, 1, 2));
     }
 
+    @Test
+    public void testInvalidCompactionOptions()
+    {
+        try
+        {
+            createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                    "'class': 'LeveledCompactionStrategy', " +
+                    "'fanout_size': '90', " +
+                    "'sstable_size_in_mb': '1089'}");
+            fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");
+        }
+        catch (ConfigurationException e)
+        {
+            assertTrue(e.getMessage().contains("your maxSSTableSize must be absurdly high to compute"));
+        }
+    }
+
+    @Test
+    public void testValidCompactionOptions()
+    {
+        createTable("CREATE TABLE %s.test (k int PRIMARY KEY, v int) WITH compaction = {" +
+                "'class': 'LeveledCompactionStrategy', " +
+                "'fanout_size': '10', " +

Review Comment:
   Removed this test case as it is already covering in `est//unit/org/apache/cassandra/db/compaction/CompactionsCQLTest.java`.



##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,34 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize()
+    {
+        try
+        {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+            Assert.fail("fanout_sizeed and sstable_size_in_mb are invalid, but did not throw ConfigurationException");

Review Comment:
   added expectedFailure



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "nikhilkumawat03 (via GitHub)" <gi...@apache.org>.
nikhilkumawat03 commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2193501810


##########
test/unit/org/apache/cassandra/db/compaction/LeveledCompactionStrategyTest.java:
##########
@@ -969,6 +969,36 @@ public void testReduceScopeL0L1() throws IOException
         }
     }
 
+    @Test()
+    public void testInvalidFanoutAndSSTableSize() {
+        try {
+            Map<String, String> options = new HashMap<>();
+            options.put("class", "LeveledCompactionStrategy");
+            options.put("fanout_size", "90");
+            options.put("sstable_size_in_mb", "1089");
+            LeveledCompactionStrategy.validateOptions(options);
+        }
+        catch (ConfigurationException e) {

Review Comment:
   Done



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell closed pull request #4228: CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created
URL: https://github.com/apache/cassandra/pull/4228


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#issuecomment-3647565008

   this was merged


-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org


Re: [PR] CASSANDRA-20570: Fixed Leveled Compaction doesn't validate maxBytesForLevel when the table is altered/created [cassandra]

Posted by "dcapwell (via GitHub)" <gi...@apache.org>.
dcapwell commented on code in PR #4228:
URL: https://github.com/apache/cassandra/pull/4228#discussion_r2282766462


##########
src/java/org/apache/cassandra/db/compaction/LeveledCompactionStrategy.java:
##########
@@ -589,15 +595,31 @@ public static Map<String, String> validateOptions(Map<String, String> options) t
         String levelFanoutSize = options.containsKey(LEVEL_FANOUT_SIZE_OPTION) ? options.get(LEVEL_FANOUT_SIZE_OPTION) : String.valueOf(DEFAULT_LEVEL_FANOUT_SIZE);
         try
         {
-            int fanoutSize = Integer.parseInt(levelFanoutSize);
+            fanoutSize = Integer.parseInt(levelFanoutSize);
             if (fanoutSize < 1)
             {
                 throw new ConfigurationException(String.format("%s must be larger than 0, but was %s", LEVEL_FANOUT_SIZE_OPTION, fanoutSize));
             }
         }
         catch (NumberFormatException ex)
         {
-            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", size, LEVEL_FANOUT_SIZE_OPTION), ex);
+            throw new ConfigurationException(String.format("%s is not a parsable int (base10) for %s", levelFanoutSize, LEVEL_FANOUT_SIZE_OPTION), ex);
+        }
+
+        // Validate max Bytes for a level
+        try
+        {
+            long maxSSTableSizeInBytes = Math.multiplyExact(ssSize, 1024L * 1024L); // Convert MB to Bytes
+            BigInteger fanoutPower = BigInteger.valueOf(fanoutSize).pow(MAX_LEVEL_COUNT);

Review Comment:
   the logic that throws is
   
   ```
   public static long maxBytesForLevel(int level, int levelFanoutSize, long maxSSTableSizeInBytes)
       {
           if (level == 0)
               return 4L * maxSSTableSizeInBytes;
           double bytes = Math.pow(levelFanoutSize, level) * maxSSTableSizeInBytes;
           if (bytes > Long.MAX_VALUE)
               throw new RuntimeException("At most " + Long.MAX_VALUE + " bytes may be in a compaction level; your maxSSTableSize must be absurdly high to compute " + bytes);
           return (long) bytes;
       }
   ```
   
   and 
   
   ```
   // It includes L0, i.e. we support [L0 - L8] levels
   static final int MAX_LEVEL_COUNT = 9;
   ```
   
   So max level is 8 for input, so `Math.pow(levelFanoutSize, 8)` is the largest thing we will see, yet this logic currently does `9`, so yeah `9 - 1` makes sense to me.
   
   



-- 
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: pr-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscribe@cassandra.apache.org
For additional commands, e-mail: pr-help@cassandra.apache.org