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-unsubscr...@cassandra.apache.org

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


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

Reply via email to