{"record":{"id":"9bcee356d23eb233","repo":"juicedata/juicefs","slug":"set-quota-usage-for-file-s-please-repair-it-lat","errorCode":null,"errorMessage":"set quota usage for file(%s), please repair it later","messagePattern":"set quota usage for file\\((.+?)\\), please repair it later","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/quota.go","lineNumber":683,"sourceCode":"\t\tMaxInodes:  quota.MaxInodes,\n\t\tUsedSpace:  -1,\n\t\tUsedInodes: -1,\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\tif created && qtype == DirQuotaType {\n\t\treturn m.calcDirQuotaUsage(ctx, Ino(key), dpath, strict)\n\t} else if scan && (qtype == UserQuotaType || qtype == GroupQuotaType) {\n\t\treturn m.ScanUserGroupUsage(ctx)\n\t} else {\n\t\treturn nil\n\t}\n}\n\nfunc (m *baseMeta) calcDirQuotaUsage(ctx Context, ino Ino, dpath string, strict bool) error {\n\twrapErr := func(e error) error {\n\t\treturn errors.Wrapf(e, \"set quota usage for file(%s), please repair it later\", dpath)\n\t}\n\n\tvar sum Summary\n\tif st := m.GetSummary(ctx, ino, &sum, true, strict); st != 0 {\n\t\treturn wrapErr(st)\n\t}\n\n\t_, err := m.en.doSetQuota(ctx, DirQuotaType, uint64(ino), &Quota{\n\t\tUsedSpace:  int64(sum.Size) - align4K(0),\n\t\tUsedInodes: int64(sum.Dirs+sum.Files) - 1,\n\t\tMaxSpace:   -1,\n\t\tMaxInodes:  -1,\n\t})\n\tif err != nil {\n\t\treturn wrapErr(err)\n\t}\n\treturn nil\n}","sourceCodeStart":665,"sourceCodeEnd":701,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/quota.go#L665-L701","documentation":"Raised by baseMeta.calcDirQuotaUsage when recalculating a directory's quota usage fails partway — most commonly because GetSummary on some file/inode returned a non-zero status. The wrap message includes the path of the file at which the calculation failed and explicitly tells the operator to repair quota usage later, because the quota accounting for that subtree is now incomplete/inaccurate.","triggerScenarios":"Calling code that recalculates directory quotas (quota repair/reload, e.g. after enabling dir quotas or running `juicefs quota`) when m.GetSummary(ctx, ino, &sum, true, strict) returns a non-zero status for some inode under the directory, or a later per-file usage update fails — wrapErr is invoked with the path of the offending file.","commonSituations":"Enabling directory quotas on a large tree where an underlying file fails to summarize (e.g. deleted concurrently, metadata inconsistent); quota usage drift after crashes; corrupted dir stat counters discovered during strict checks.","solutions":["Run `juicefs quota <meta-url> <path> --set ...` or the quota repair flow after fixing the underlying cause so usage is recalculated.","Unwrap the error to identify the exact file (path is embedded in the message) and inspect/repair that inode's metadata.","Check for concurrent modification (deletion/renames) during recalculation and re-run when the tree is quiet.","Verify metadata engine consistency; restore from a metadata backup if usage counters are corrupt."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before enabling quotas, verify the tree summarises cleanly:\nvar s Summary\nif st := m.GetSummary(ctx, rootIno, &s, true, false); st != 0 {\n    // resolve summary errors before recalculating quotas\n}","typeGuard":"inner := stderrors.Unwrap(err) // reveals the per-file status behind the wrap","tryCatchPattern":"if err := calcDirQuotaUsage(ctx, ino, dpath, true); err != nil {\n    logger.Warnf(\"%v; schedule quota repair\", err)\n    // queue repair: juicefs quota <meta> <path> check\n}","preventionTips":["Run quota checks (`juicefs quota ... check`) regularly to catch drift early.","Avoid heavy concurrent modifications while recalculating quota usage.","Enable quotas on a quiet tree; schedule recalcs off-peak.","Restore quota counters from metadata backup if corruption is suspected."],"tags":["go","metadata","quota","wrapped-error"],"backgroundTag":"internal-invariant-violation","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}