apache/cassandra · warning

Unable to parse as valid value for shard count

Error message

Unable to parse {} as valid value for shard count

What it means

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.

Solutions

  1. Set memtable_shard_count to a plain integer, e.g. -Dmemtable_shard_count=8
  2. Check for quoting/whitespace issues in cassandra-env.sh or the service unit that injects JVM_OPTS
  3. Remove the property to use the automatically derived shard count
  4. Confirm at startup via the subsequent log line 'Requested setting shard count to ...' that parsing succeeded

Example fix

// before
JVM_OPTS="$JVM_OPTS -Dmemtable_shard_count=2.5"
// after
JVM_OPTS="$JVM_OPTS -Dmemtable_shard_count=3"
Defensive patterns

Strategy: validation

Validate before calling

// validate the system property at startup
String v = System.getProperty("memtable_shard_count");
if (v != null) Integer.parseInt(v.trim()); // throws early with a clear message

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of apache/cassandra@88fd0f6a0e (2026-09-10). Data as JSON: /api/errors/d579462aab9f9940. Report an issue: GitHub.

Appendix: source

Thrown at src/java/org/apache/cassandra/db/memtable/AbstractShardedMemtable.java:82

    private static class ShardedMemtableConfig implements ShardedMemtableConfigMXBean
    {
        @Override
        public void setDefaultShardCount(String shardCount)
        {
            if ("auto".equalsIgnoreCase(shardCount))
            {
                defaultShardCount = FBUtilities.getAvailableProcessors();
            }
            else
            {
                try
                {
                    defaultShardCount = Integer.parseInt(shardCount);
                }
                catch (NumberFormatException ex)
                {
                    logger.warn("Unable to parse {} as valid value for shard count", shardCount);
                    return;
                }
            }
            logger.info("Requested setting shard count to {}; set to: {}", shardCount, defaultShardCount);
        }

        @Override
        public String getDefaultShardCount()
        {
            return Integer.toString(defaultShardCount);
        }
    }

    public static int getDefaultShardCount()
    {
        return defaultShardCount;
    }
}

View on GitHub (pinned to 88fd0f6a0e)