{"record":{"id":"64bd71ac5f36ac78","repo":"apache/cassandra","slug":"sample-range-is-invalid","errorCode":null,"errorMessage":"sample range is invalid","messagePattern":"sample range is invalid","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"tools/stress/src/org/apache/cassandra/stress/generate/SeedManager.java","lineNumber":50,"sourceCode":"\n    final Distribution visits;\n    final Generator writes;\n    final Generator reads;\n    final ConcurrentHashMap<Long, Seed> managing = new ConcurrentHashMap<>();\n    final LockedDynamicList<Seed> sampleFrom;\n    final Distribution sample;\n    final long sampleOffset;\n    final int sampleSize;\n    final long sampleMultiplier;\n    final boolean updateSampleImmediately;\n\n    public SeedManager(StressSettings settings)\n    {\n        Distribution tSample = settings.insert.revisit.get();\n        this.sampleOffset = Math.min(tSample.minValue(), tSample.maxValue());\n        long sampleSize = 1 + Math.max(tSample.minValue(), tSample.maxValue()) - sampleOffset;\n        if (sampleOffset < 0 || sampleSize > Integer.MAX_VALUE)\n            throw new IllegalArgumentException(\"sample range is invalid\");\n\n        // need to get a big numerical range even if a small number of discrete values\n        // one plus so we still get variation at the low order numbers as well as high\n        this.sampleMultiplier = 1 + Math.round(Math.pow(10D, 22 - Math.log10(sampleSize)));\n\n        Generator writes, reads;\n        if (settings.generate.sequence != null)\n        {\n            long[] seq = settings.generate.sequence;\n            if (settings.generate.readlookback != null)\n            {\n                LookbackableWriteGenerator series = new LookbackableWriteGenerator(seq[0], seq[1], settings.generate.wrap, settings.generate.readlookback.get(), sampleMultiplier);\n                writes = series;\n                reads = series.reads;\n            }\n            else\n            {\n                writes = reads = new SeriesGenerator(seq[0], seq[1], settings.generate.wrap, sampleMultiplier);","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/tools/stress/src/org/apache/cassandra/stress/generate/SeedManager.java#L32-L68","documentation":"SeedManager validates the sample range derived from the insert 'revisit' distribution at construction. sampleOffset is the min of the distribution's min/max values and sampleSize the span between them; if the distribution can produce negative values or the span exceeds Integer.MAX_VALUE, no valid sample window exists and the constructor throws IllegalArgumentException.","triggerScenarios":"Running cassandra-stress with an insert revisit distribution (e.g. revisit=uniform(-1..10) or a huge range like gaussian(0..3000000000)) whose minimum value is negative or whose min..max span exceeds 2^31-1.","commonSituations":"Typing a revisit/visit distribution spec with negative lower bounds in stress profiles; using enormous distribution ranges to model very large keyspaces; copy-pasted profile YAML with typos in distribution arguments.","solutions":["Fix the revisit distribution so its minimum value is >= 0 and max-min <= Integer.MAX_VALUE","Use a smaller discrete or bounded distribution, e.g. revisit=uniform(1..1000000)","If modeling huge keyspaces, split the stress run into multiple runs with offset ranges instead of one huge distribution"],"exampleFix":"// before\nsettings.insert.revisit = uniform(-100..1000)\n// after\nsettings.insert.revisit = uniform(0..1000)","handlingStrategy":"validation","validationCode":"Distribution t = settings.insert.revisit.get();\nlong offset = Math.min(t.minValue(), t.maxValue());\nlong size = 1 + Math.max(t.minValue(), t.maxValue()) - offset;\nif (offset < 0 || size > Integer.MAX_VALUE) throw new IllegalArgumentException(\"revisit distribution range invalid\");","typeGuard":"boolean isValidSampleRange(Distribution d) { return Math.min(d.minValue(), d.maxValue()) >= 0 && (1 + Math.max(d.minValue(), d.maxValue()) - Math.min(d.minValue(), d.maxValue())) <= Integer.MAX_VALUE; }","tryCatchPattern":"try { SeedManager sm = new SeedManager(settings); } catch (IllegalArgumentException e) { log.error(\"Bad revisit distribution: {}\", e.getMessage()); }","preventionTips":["Keep revisit distribution lower bounds non-negative","Cap distribution spans well below 2^31-1","Validate distribution specs in profile files before running stress"],"tags":["cli","configuration","distribution"],"backgroundTag":"invalid-config-value","analyzedSha":"88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1","analyzedAt":"2026-09-10T07:29:22.284Z","contentChangedAt":"2026-09-10T07:29:22.284Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}