{"record":{"id":"2ed820e640c01d59","repo":"hyperledger/fabric","slug":"error-while-creating-final-dir-for-snapshot-s","errorCode":null,"errorMessage":"error while creating final dir for snapshot:%s","messagePattern":"error while creating final dir for snapshot:(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/ledger/kvledger/snapshot.go","lineNumber":144,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\tlogger.Debugw(\"Exported public state and private state hashes\", \"channelID\", l.ledgerID)\n\n\tif err := l.generateSnapshotMetadataFiles(\n\t\tsnapshotTempDir, txIDsExportSummary,\n\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","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/snapshot.go#L126-L162","documentation":"After staging the snapshot in a temp dir, generateSnapshot creates the ledger's final snapshots directory via os.MkdirAll before renaming the temp dir into it. This error wraps an os.MkdirAll failure on the per-ledger snapshots directory.","triggerScenarios":"GenerateSnapshot() reaching the finalize step while the target per-ledger snapshots dir cannot be created: path permission issues, a file existing where the directory should be, or disk errors.","commonSituations":"A regular file named like the ledger snapshots dir blocks creation (e.g. leftover from a failed run or bad copy); read-only volume became read-only mid-operation (disk error remount).","solutions":["Inspect the path <snapshotsRootDir>/<ledgerID>/snapshots — remove any conflicting file and fix permissions","Check dmesg/mount for the filesystem going read-only and remount read-write","Ensure consistent ownership of the snapshots root directory by the peer user","Delete partially created snapshot dirs and re-run GenerateSnapshot()"],"exampleFix":"// diagnosis\nls -la /var/hyperledger/production/snapshots/<ledgerID>\n// if 'snapshots' is a file\nrm /var/hyperledger/production/snapshots/<ledgerID>/snapshots\n// then re-run GenerateSnapshot()","handlingStrategy":"validation","validationCode":"slgr := filepath.Join(snapshotsRootDir, ledgerID, \"snapshots\")\nif fi, err := os.Stat(slgr); err == nil && !fi.IsDir() {\n    return fmt.Errorf(\"%s exists as a file; remove it before snapshotting\", slgr)\n}","typeGuard":null,"tryCatchPattern":"err := ledger.GenerateSnapshot()\nvar pe *fs.PathError\nif err != nil && errors.As(err, &pe) && errors.Is(pe.Err, syscall.EROFS) {\n    log.Error(\"snapshots filesystem went read-only; remount and retry\")\n}","preventionTips":["Do not place files where per-ledger snapshot dirs are created","Monitor mounts for read-only remounts (disk errors)","Keep snapshots root owned solely by the peer user","Clean up failed snapshot runs before retrying"],"tags":["filesystem","mkdir","snapshot","permissions"],"backgroundTag":"mkdir-permission-denied","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"}