{"record":{"id":"4c193f18918b7088","repo":"apache/cassandra","slug":"snapshot-s-for-s-s-already-exists","errorCode":null,"errorMessage":"Snapshot %s for %s.%s already exists.","messagePattern":"Snapshot (.+?) for (.+?)\\.(.+?) already exists\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/java/org/apache/cassandra/service/snapshot/SnapshotManager.java","lineNumber":587,"sourceCode":"     *\n     * @param task task to process\n     */\n    private synchronized void prePopulateSnapshots(TakeSnapshotTask task)\n    {\n        Map<ColumnFamilyStore, TableSnapshot> snapshotsToCreate = task.getSnapshotsToCreate();\n        Map<ColumnFamilyStore, TableSnapshot> snapshotsToOverwrite = new HashMap<>();\n        List<TableSnapshot> toCreate = new ArrayList<>(snapshotsToCreate.values());\n\n        for (TableSnapshot existingSnapshot : snapshots)\n        {\n            for (Map.Entry<ColumnFamilyStore, TableSnapshot> toCreateEntry : snapshotsToCreate.entrySet())\n            {\n                TableSnapshot snapshotToCreate = toCreateEntry.getValue();\n                if (existingSnapshot.equals(toCreateEntry.getValue()))\n                {\n                    if (!task.options.ephemeral)\n                    {\n                        throw new RuntimeException(format(\"Snapshot %s for %s.%s already exists.\",\n                                                          snapshotToCreate.getTag(),\n                                                          snapshotToCreate.getKeyspaceName(),\n                                                          snapshotToCreate.getTableName()));\n                    }\n\n                    toCreate.remove(toCreateEntry.getValue());\n                    snapshotsToOverwrite.put(toCreateEntry.getKey(), existingSnapshot);\n                }\n            }\n        }\n\n        snapshotsToCreate.putAll(snapshotsToOverwrite);\n\n        snapshots.addAll(toCreate);\n    }\n\n    private static ScheduledExecutorPlus createSnapshotCleanupExecutor()\n    {","sourceCodeStart":569,"sourceCodeEnd":605,"githubUrl":"https://github.com/apache/cassandra/blob/88fd0f6a0eaed8943f05ac9e8f947882b8ddc8f1/src/java/org/apache/cassandra/service/snapshot/SnapshotManager.java#L569-L605","documentation":"prePopulateSnapshots detects that a non-ephemeral snapshot with the same computed identity (tag + keyspace + table, matching manifest) already exists and refuses to create a duplicate. Ephemeral snapshots that collide are silently dropped instead.","triggerScenarios":"Calling takeSnapshot with a tag that resolves to the same snapshot name for a table that already has that snapshot; re-running an idempotent script with the same explicit tag; named snapshot taken twice before clearing.","commonSituations":"Backup scripts with fixed tag names (e.g. 'daily') run twice; operators re-issue the same nodetool snapshot command; timestamp-generated names colliding within the same second.","solutions":["Use a different snapshot tag, or include a timestamp component so each run resolves to a unique name.","Clear the existing snapshot first (nodetool clearsnapshot -t <tag>) then retake it.","Treat the error as 'snapshot already taken' and skip the operation if idempotency is desired.","If ephemeral behavior is appropriate, mark the snapshot as ephemeral so the collision is dropped rather than thrown."],"exampleFix":"// before\nnodetool snapshot -t daily-backup ks1\n// after (unique per run)\nnodetool snapshot -t daily-backup-$(date +%Y%m%d%H%M%S) ks1","handlingStrategy":"validation","validationCode":"boolean isUniqueTag(SnapshotManager mgr, String ks, String tbl, String tag) { return mgr.getSnapshots(ks, tbl).stream().noneMatch(s -> s.getTag().equals(tag)); }","typeGuard":null,"tryCatchPattern":"try { takeSnapshot(tag, ks, tbl); } catch (RuntimeException e) { if (e.getMessage().contains(\"already exists\")) { /* treat as success */ } else throw e; }","preventionTips":["Generate unique tags with timestamps per run","Avoid fixed tag names in recurring backup scripts","Clear old snapshots with the same tag before retaking"],"tags":["snapshot","duplicate","conflict","idempotency"],"backgroundTag":"file-already-exists","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"}