{"record":{"id":"c262481397350854","repo":"nathanmarz/storm","slug":"version-already-exists-or-data-already-exists","errorCode":null,"errorMessage":"Version already exists or data already exists","messagePattern":"Version already exists or data already exists","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"storm-core/src/jvm/backtype/storm/utils/VersionedStore.java","lineNumber":85,"sourceCode":"        for(Long v: all) {\n            if(v <= maxVersion) return v;\n        }\n        return null;\n    }\n\n    public String createVersion() throws IOException {\n        Long mostRecent = mostRecentVersion();\n        long version = Time.currentTimeMillis();\n        if(mostRecent!=null && version <= mostRecent) {\n            version = mostRecent + 1;\n        }\n        return createVersion(version);\n    }\n\n    public String createVersion(long version) throws IOException {\n        String ret = versionPath(version);\n        if(getAllVersions().contains(version))\n            throw new RuntimeException(\"Version already exists or data already exists\");\n        else\n            return ret;\n    }\n\n    public void failVersion(String path) throws IOException {\n        deleteVersion(validateAndGetVersion(path));\n    }\n\n    public void deleteVersion(long version) throws IOException {\n        File versionFile = new File(versionPath(version));\n        File tokenFile = new File(tokenPath(version));\n        \n        if(versionFile.exists()) {\n            FileUtils.forceDelete(versionFile);\n        }\n        if(tokenFile.exists()) {\n            FileUtils.forceDelete(tokenFile);\n        }        ","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/nathanmarz/storm/blob/cdb116e942666973bc4eaa0df098d5bab82739e7/storm-core/src/jvm/backtype/storm/utils/VersionedStore.java#L67-L103","documentation":"VersionedStore.createVersion computes the path for a requested version and refuses it if that version already appears in getAllVersions() — i.e. a version directory/token already exists in the store. It throws RuntimeException to protect against overwriting an existing snapshot/transaction version.","triggerScenarios":"Calling createVersion(long) (or the Long overload that delegates) with a version number previously created, or creating the same version concurrently from two processes/threads; retrying a create after a previous partially-successful attempt left the version directory on disk.","commonSituations":"Two workers or a failed-then-retried job both try to commit the same transaction id to a shared HDFS/state store; clock-derived or counter-derived versions reused after a crash; replaying a job without cleaning the store directory.","solutions":["Check existing versions first and pick a new version: if (store.getAllVersions().contains(v)) v = nextFreeVersion().","On concurrent writers, derive the version from a shared monotonic source (zookeeper transaction id) so attempts don't collide.","Clean up failed/incomplete versions (store.failVersion(path) or delete leftover dirs) before retrying the same version.","If the existing version is a stale leftover of the same data, delete the directory and recreate."],"exampleFix":"// before\nString path = store.createVersion(txid); // throws if txid already committed\n// after\nif (store.getAllVersions().contains(txid)) {\n    LOG.info(\"Version \" + txid + \" already committed, skipping\");\n    return;\n}\nString path = store.createVersion(txid);","handlingStrategy":"validation","validationCode":"if (store.getAllVersions().contains(txid)) {\n    throw new IllegalStateException(\"Version \" + txid + \" already exists; skipping or choose a new version\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    String path = store.createVersion(txid);\n} catch (RuntimeException e) {\n    if (e.getMessage().contains(\"already exists\")) {\n        // treat as already-committed, recover idempotently\n    } else throw e;\n}","preventionTips":["Make version creation idempotent: check getAllVersions() before creating","Use a single writer or a shared monotonic source (zookeeper txid) for version numbers","Clean up failed versions via failVersion before retrying the same version"],"tags":["java","storage","versioning","storm"],"backgroundTag":"file-already-exists","analyzedSha":"cdb116e942666973bc4eaa0df098d5bab82739e7","analyzedAt":"2026-09-12T14:30:00.714Z","contentChangedAt":"2026-09-12T14:30:00.714Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}