apache/cassandra · error · IllegalArgumentException

Specifying snapshot name together with --older-than flag is

Error message

Specifying snapshot name together with --older-than flag is not allowed

What it means

When using the --older-than duration filter, clearsnapshot does not allow naming a specific snapshot, since age filtering applies to sets of snapshots. Combining --snapshot with --older-than throws this IllegalArgumentException.

Source

Thrown at src/java/org/apache/cassandra/tools/nodetool/ClearSnapshot.java:73

    @Option(paramLabel = "older_than_timestamp", names = "--older-than-timestamp",
            description = "Clear snapshots older than specified timestamp. It has to be a string in ISO format, for example '2022-12-03T10:15:30Z'")
    private String olderThanTimestamp;

    @Override
    public void execute(NodeProbe probe)
    {
        if (snapshotName.isEmpty() && !clearAllSnapshots)
            throw new IllegalArgumentException("Specify snapshot name or --all");

        if (!snapshotName.isEmpty() && clearAllSnapshots)
            throw new IllegalArgumentException("Specify only one of snapshot name or --all");

        if (olderThan != null && olderThanTimestamp != null)
            throw new IllegalArgumentException("Specify only one of --older-than or --older-than-timestamp");

        if (!snapshotName.isEmpty() && olderThan != null)
            throw new IllegalArgumentException("Specifying snapshot name together with --older-than flag is not allowed");

        if (!snapshotName.isEmpty() && olderThanTimestamp != null)
            throw new IllegalArgumentException("Specifying snapshot name together with --older-than-timestamp flag is not allowed");

        if (olderThanTimestamp != null)
            try
            {
                Instant.parse(olderThanTimestamp);
            }
            catch (DateTimeParseException ex)
            {
                throw new IllegalArgumentException("Parameter --older-than-timestamp has to be a valid instant in ISO format.");
            }

        Long olderThanInSeconds = null;
        if (olderThan != null)
            // fail fast when it is not valid
            olderThanInSeconds = new DurationSpec.LongSecondsBound(olderThan).toSeconds();

View on GitHub (pinned to 88fd0f6a0e)

Solutions

  1. Implement the age check externally: use `nodetool listsnapshots` to inspect snapshot timestamps, then delete by name if old enough
  2. Drop the snapshot name and use --all --older-than <duration> for age-based bulk cleanup
  3. Drop --older-than and delete the named snapshot unconditionally

Example fix

// before
nodetool clearsnapshot --snapshot snap1 --older-than 7d
// after
nodetool clearsnapshot --all --older-than 7d
Defensive patterns

Strategy: validation

Validate before calling

if snapName and olderThan: raise SystemExit("name-based deletion cannot use --older-than")

Try / catch

try { clearSnapshot(); }
catch (IllegalArgumentException e) { /* adjust flags */ }

Prevention

When it happens

Trigger: Running `nodetool clearsnapshot --snapshot snap1 --older-than 7d`.

Common situations: Users wanting to delete a named snapshot only if it is older than some age — not supported; or scripts merging two cleanup code paths.

Understand the failure class

Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.

Related errors


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