{"record":{"id":"b189a0309e9d7ee2","repo":"hyperledger/fabric","slug":"error-while-renaming-dir-s-to-s","errorCode":null,"errorMessage":"error while renaming dir [%s] to [%s]:","messagePattern":"error while renaming dir \\[(.+?)\\] to \\[(.+?)\\]:","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/snapshot.go","lineNumber":151,"sourceCode":"\t\tconfigsHistoryExportSummary, stateDBExportSummary,\n\t); err != nil {\n\t\treturn err\n\t}\n\tlogger.Debugw(\"Generated metadata files\", \"channelID\", l.ledgerID)\n\n\tif err := fileutil.SyncDir(snapshotTempDir); err != nil {\n\t\treturn err\n\t}\n\tslgr := SnapshotsDirForLedger(snapshotsRootDir, l.ledgerID)\n\tif err := os.MkdirAll(slgr, 0o755); err != nil {\n\t\treturn errors.Wrapf(err, \"error while creating final dir for snapshot:%s\", slgr)\n\t}\n\tif err := fileutil.SyncParentDir(slgr); err != nil {\n\t\treturn err\n\t}\n\tslgrht := SnapshotDirForLedgerBlockNum(snapshotsRootDir, l.ledgerID, lastBlockNum)\n\tif err := os.Rename(snapshotTempDir, slgrht); err != nil {\n\t\treturn errors.Wrapf(err, \"error while renaming dir [%s] to [%s]:\", snapshotTempDir, slgrht)\n\t}\n\treturn fileutil.SyncParentDir(slgrht)\n}\n\nfunc (l *kvLedger) generateSnapshotMetadataFiles(\n\tdir string,\n\ttxIDsExportSummary,\n\tconfigsHistoryExportSummary,\n\tstateDBExportSummary map[string][]byte,\n) error {\n\t// generate metadata file\n\tfilesAndHashes := map[string]string{}\n\tfor fileName, hashsum := range txIDsExportSummary {\n\t\tfilesAndHashes[fileName] = hex.EncodeToString(hashsum)\n\t}\n\tfor fileName, hashsum := range configsHistoryExportSummary {\n\t\tfilesAndHashes[fileName] = hex.EncodeToString(hashsum)\n\t}","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/snapshot.go#L133-L169","documentation":"generateSnapshot finalizes a snapshot by atomically renaming the temp directory to its final location <snapshotsRootDir>/<ledgerID>/snapshots/<blockNum>. This error wraps os.Rename failure, meaning the snapshot was generated but could not be moved into place and the temp dir is removed (snapshot is NOT produced).","triggerScenarios":"os.Rename(snapshotTempDir, finalDir) fails: final dir already exists (snapshot for that block number already taken), temp dir removed by concurrent process, or cross-device rename if temp dir is on a different filesystem than the final dir.","commonSituations":"Re-running GenerateSnapshot() for a block height that already has a snapshot; snapshots root on NFS/bind-mount layouts where temp and final paths span devices; cleanup jobs deleting temp dirs mid-generation.","solutions":["Check if a snapshot for that block number already exists at snapshots/<ledgerID>/snapshots/<blockNum> — if so, the snapshot already exists; nothing to do","Ensure temp and final directories live on the same filesystem/volume","Avoid concurrent snapshot generation or external cleanup touching the snapshots dir","Re-run GenerateSnapshot() after resolving; stale temp dirs are cleaned up automatically"],"exampleFix":"// before (risky)\nsnapshots:\n  rootDir: /mnt/nfs/snapshots  # temp subdir on same NFS but different export\n// after\nsnapshots:\n  rootDir: /var/hyperledger/production/snapshots  # single local filesystem","handlingStrategy":"validation","validationCode":"finalDir := filepath.Join(snapshotsRootDir, ledgerID, \"snapshots\", fmt.Sprintf(\"%d\", lastBlockNum))\nif _, err := os.Stat(finalDir); err == nil {\n    return fmt.Errorf(\"snapshot for block %d already exists at %s\", lastBlockNum, finalDir)\n}\ntmpDev, _ := getDev(snapshotsRootDir); finDev, _ := getDev(filepath.Dir(finalDir))\nif tmpDev != finDev { return errors.New(\"temp and final snapshot dirs must be on the same filesystem\") }","typeGuard":null,"tryCatchPattern":"err := ledger.GenerateSnapshot()\nvar le *os.LinkError\nif errors.As(err, &le) && errors.Is(le.Err, syscall.ENOTEMPTY) || errors.Is(le.Err, syscall.EEXIST) {\n    log.Info(\"snapshot already exists for this height; skipping\")\n    return nil\n}","preventionTips":["Check for an existing snapshot at the target block height before generating","Keep the entire snapshots root on one filesystem (avoid NFS span/devices)","Avoid concurrent or scheduled cleanups touching the snapshots dir","Serialize GenerateSnapshot() calls per ledger"],"tags":["filesystem","rename","snapshot","concurrency"],"backgroundTag":"file-rename-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}