{"record":{"id":"d579462aab9f9940","repo":"apache/cassandra","slug":"unable-to-parse-as-valid-value-for-shard-count","errorCode":null,"errorMessage":"Unable to parse {} as valid value for shard count","messagePattern":"Unable to parse (.+?) as valid value for shard count","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/java/org/apache/cassandra/db/memtable/AbstractShardedMemtable.java","lineNumber":82,"sourceCode":"\n    private static class ShardedMemtableConfig implements ShardedMemtableConfigMXBean\n    {\n        @Override\n        public void setDefaultShardCount(String shardCount)\n        {\n            if (\"auto\".equalsIgnoreCase(shardCount))\n            {\n                defaultShardCount = FBUtilities.getAvailableProcessors();\n            }\n            else\n            {\n                try\n                {\n                    defaultShardCount = Integer.parseInt(shardCount);\n                }\n                catch (NumberFormatException ex)\n                {\n                    logger.warn(\"Unable to parse {} as valid value for shard count\", shardCount);\n                    return;\n                }\n            }\n            logger.info(\"Requested setting shard count to {}; set to: {}\", shardCount, defaultShardCount);\n        }\n\n        @Override\n        public String getDefaultShardCount()\n        {\n            return Integer.toString(defaultShardCount);\n        }\n    }\n\n    public static int getDefaultShardCount()\n    {\n        return defaultShardCount;\n    }\n}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/db/memtable/AbstractShardedMemtable.java#L64-L100","documentation":"AbstractShardedMemtable.setDefaultShardCount reads the memtable_shard_count system property / config and parses it as an integer. On NumberFormatException it logs 'Unable to parse ... as valid value for shard count', keeps the previous default, and returns early, so the setting is silently not applied.","triggerScenarios":"Starting Cassandra with -Dmemtable_shard_count set to a non-integer string (letters, units like '8g', commas, empty value) or a value with stray whitespace/characters beyond Integer.parseInt range.","commonSituations":"Hand-edited cassandra-env.sh or JVM_OPTS; copying flags between cluster config scripts with shell quoting errors leaving an empty value; using decimal values like 2.5.","solutions":["Set memtable_shard_count to a plain integer, e.g. -Dmemtable_shard_count=8","Check for quoting/whitespace issues in cassandra-env.sh or the service unit that injects JVM_OPTS","Remove the property to use the automatically derived shard count","Confirm at startup via the subsequent log line 'Requested setting shard count to ...' that parsing succeeded"],"exampleFix":"// before\nJVM_OPTS=\"$JVM_OPTS -Dmemtable_shard_count=2.5\"\n// after\nJVM_OPTS=\"$JVM_OPTS -Dmemtable_shard_count=3\"","handlingStrategy":"validation","validationCode":"// validate the system property at startup\nString v = System.getProperty(\"memtable_shard_count\");\nif (v != null) Integer.parseInt(v.trim()); // throws early with a clear message","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set plain integer values only","Watch for the follow-up 'Requested setting shard count' info line confirming success","Version-control cassandra-env.sh changes","Avoid units or decimals in count-style flags"],"tags":["configuration","memtable","jvm-properties"],"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-17T15:17:12.973Z"}