aratno commented on code in PR #3948:
URL: https://github.com/apache/cassandra/pull/3948#discussion_r1994318617


##########
test/unit/org/apache/cassandra/utils/CassandraGenerators.java:
##########
@@ -413,10 +491,250 @@ public Gen<KeyspaceMetadata> build()
         }
     }
 
+    public static Gen<CachingParams> cachingParamsGen()
+    {
+        return rnd -> {
+            boolean cacheKeys = nextBoolean(rnd);
+            int rowsPerPartitionToCache;
+            switch (SourceDSL.integers().between(1, 3).generate(rnd))
+            {
+                case 1: // ALL
+                    rowsPerPartitionToCache = Integer.MAX_VALUE;
+                    break;
+                case 2: // NONE
+                    rowsPerPartitionToCache = 0;
+                    break;
+                case 3: // num values
+                    rowsPerPartitionToCache = 
Math.toIntExact(rnd.next(Constraint.between(1, Integer.MAX_VALUE - 1)));
+                    break;
+                default:
+                    throw new AssertionError();
+            }
+            return new CachingParams(cacheKeys, rowsPerPartitionToCache);
+        };
+    }
+
+    public enum KnownCompactionAlgo
+    {
+        SizeTiered(SizeTieredCompactionStrategy.class),
+        Leveled(LeveledCompactionStrategy.class),
+        Unified(UnifiedCompactionStrategy.class);

Review Comment:
   No TWCS?



##########
test/unit/org/apache/cassandra/utils/CassandraGenerators.java:
##########
@@ -413,10 +491,250 @@ public Gen<KeyspaceMetadata> build()
         }
     }
 
+    public static Gen<CachingParams> cachingParamsGen()
+    {
+        return rnd -> {
+            boolean cacheKeys = nextBoolean(rnd);
+            int rowsPerPartitionToCache;
+            switch (SourceDSL.integers().between(1, 3).generate(rnd))
+            {
+                case 1: // ALL
+                    rowsPerPartitionToCache = Integer.MAX_VALUE;
+                    break;
+                case 2: // NONE
+                    rowsPerPartitionToCache = 0;
+                    break;
+                case 3: // num values
+                    rowsPerPartitionToCache = 
Math.toIntExact(rnd.next(Constraint.between(1, Integer.MAX_VALUE - 1)));
+                    break;
+                default:
+                    throw new AssertionError();
+            }
+            return new CachingParams(cacheKeys, rowsPerPartitionToCache);
+        };
+    }
+
+    public enum KnownCompactionAlgo
+    {
+        SizeTiered(SizeTieredCompactionStrategy.class),
+        Leveled(LeveledCompactionStrategy.class),
+        Unified(UnifiedCompactionStrategy.class);
+        private final Class<? extends AbstractCompactionStrategy> klass;
+
+        KnownCompactionAlgo(Class<? extends AbstractCompactionStrategy> klass)
+        {
+            this.klass = klass;
+        }
+    }
+
+    public static class CompactionParamsBuilder
+    {
+        private Gen<KnownCompactionAlgo> algoGen = 
SourceDSL.arbitrary().enumValues(KnownCompactionAlgo.class);
+        private Gen<CompactionParams.TombstoneOption> tombstoneOptionGen = 
SourceDSL.arbitrary().enumValues(CompactionParams.TombstoneOption.class);
+        private Gen<Map<String, String>> sizeTieredOptions = rnd -> {
+            if (nextBoolean(rnd)) return Map.of();
+            Map<String, String> options = new HashMap<>();
+            if (nextBoolean(rnd))
+                // computes mb then converts to bytes
+                
options.put(SizeTieredCompactionStrategyOptions.MIN_SSTABLE_SIZE_KEY, 
Long.toString(SourceDSL.longs().between(1, 100).generate(rnd) * 1024L * 1024L));
+            if (nextBoolean(rnd))
+                
options.put(SizeTieredCompactionStrategyOptions.BUCKET_LOW_KEY, 
Double.toString(SourceDSL.doubles().between(0.1, 0.9).generate(rnd)));
+            if (nextBoolean(rnd))
+                
options.put(SizeTieredCompactionStrategyOptions.BUCKET_HIGH_KEY, 
Double.toString(SourceDSL.doubles().between(1.1, 1.9).generate(rnd)));
+            return options;
+        };
+        private Gen<Map<String, String>> leveledOptions = rnd -> {
+            if (nextBoolean(rnd)) return Map.of();
+            Map<String, String> options = new HashMap<>();
+            if (nextBoolean(rnd))
+                options.putAll(sizeTieredOptions.generate(rnd));
+            if (nextBoolean(rnd))
+                // size in mb
+                options.put(LeveledCompactionStrategy.SSTABLE_SIZE_OPTION, 
SourceDSL.integers().between(1, 2_000).generate(rnd).toString());
+            if (nextBoolean(rnd))
+                
options.put(LeveledCompactionStrategy.LEVEL_FANOUT_SIZE_OPTION, 
SourceDSL.integers().between(1, 100).generate(rnd).toString());
+            if (nextBoolean(rnd))
+                
options.put(LeveledCompactionStrategy.SINGLE_SSTABLE_UPLEVEL_OPTION, 
nextBoolean(rnd).toString());
+            return options;
+        };
+        private Gen<Map<String, String>> unifiedOptions = rnd -> {
+            if (nextBoolean(rnd)) return Map.of();
+            Gen<String> storageSizeGen = 
Generators.filter(humanReadableStorageSimple(), s -> 
Controller.MIN_TARGET_SSTABLE_SIZE <= FBUtilities.parseHumanReadableBytes(s));
+            Map<String, String> options = new HashMap<>();
+            if (nextBoolean(rnd))
+                options.put(Controller.BASE_SHARD_COUNT_OPTION, 
SourceDSL.integers().between(1, 10).generate(rnd).toString());
+            if (nextBoolean(rnd))
+                options.put(Controller.FLUSH_SIZE_OVERRIDE_OPTION, 
storageSizeGen.generate(rnd));
+            if (nextBoolean(rnd))
+                options.put(Controller.MAX_SSTABLES_TO_COMPACT_OPTION, 
SourceDSL.integers().between(0, 32).generate(rnd).toString());
+            if (nextBoolean(rnd))
+                options.put(Controller.SSTABLE_GROWTH_OPTION, 
SourceDSL.integers().between(0, 100).generate(rnd) + "%");
+            if (nextBoolean(rnd))
+                options.put(Controller.OVERLAP_INCLUSION_METHOD_OPTION, 
SourceDSL.arbitrary().enumValues(Overlaps.InclusionMethod.class).generate(rnd).name());
+            if (nextBoolean(rnd))
+            {
+                int numLevels = SourceDSL.integers().between(1, 
10).generate(rnd);
+                String[] scalingParams = new String[numLevels];
+                Gen<Integer> levelSize = SourceDSL.integers().between(2, 10);
+                for (int i = 0; i < numLevels; i++)
+                {
+                    String value;
+                    switch (SourceDSL.integers().between(0, 3).generate(rnd))
+                    {
+                        case 0:
+                            value = "N";
+                            break;
+                        case 1:
+                            value = "L" + levelSize.generate(rnd);
+                            break;
+                        case 2:
+                            value = "T" + levelSize.generate(rnd);
+                            break;
+                        case 3:
+                            value = 
SourceDSL.integers().all().generate(rnd).toString();
+                            break;
+                        default:
+                            throw new AssertionError();
+                    }
+                    scalingParams[i] = value;
+                }
+                options.put(Controller.SCALING_PARAMETERS_OPTION, 
String.join(",", scalingParams));
+            }
+            if (nextBoolean(rnd))
+            {
+                // Calculate TARGET then compute the MIN from that.  The issue 
is that there is a hidden relationship
+                // between these 2 fields more complex than simple 
comparability, MIN must be < 70% * TARGET!
+                // See CASSANDRA-20398
+                // 1MiB to 128MiB target
+                long targetBytes = SourceDSL.longs().between(1L << 20, 1L << 
27).generate(rnd);
+                long limit = (long) Math.ceil(targetBytes * Math.sqrt(0.5));
+                long minBytes = SourceDSL.longs().between(1, limit - 
1).generate(rnd);
+                options.put(Controller.MIN_SSTABLE_SIZE_OPTION, minBytes + 
"B");
+                options.put(Controller.TARGET_SSTABLE_SIZE_OPTION, targetBytes 
+ "B");
+            }
+            return options;
+        };
+        public Gen<CompactionParams> build()

Review Comment:
   There are a few other options in AbstractCompactionStrategy that are missing 
here, like tombstone_threshold



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