{"record":{"id":"59089679f061839d","repo":"juicedata/juicefs","slug":"delete-dir-stats","errorCode":null,"errorMessage":"delete dir stats","messagePattern":"delete dir stats","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/tkv.go","lineNumber":539,"sourceCode":"\t\t\t\t\tif len(k) == 9 {\n\t\t\t\t\t\tkeys = append(keys, k)\n\t\t\t\t\t}\n\t\t\t\t\treturn true\n\t\t\t\t})\n\t\t\t\treturn nil\n\t\t\t}, 0)\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"scan dir stats\")\n\t\t\t}\n\t\t\terr = m.txn(Background(), func(tx *kvTxn) error {\n\t\t\t\tfor _, key := range keys {\n\t\t\t\t\ttx.delete(key)\n\t\t\t\t}\n\t\t\t\tm.genLog(tx, time.Now(), \"INIT_ENABLE_DIRSTATS()\")\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"delete dir stats\")\n\t\t\t}\n\t\t}\n\t\tif !old.UserGroupQuota && format.UserGroupQuota {\n\t\t\t// remove user group quota as they are outdated\n\t\t\tuserPrefix := m.fmtKey(\"QU\")\n\t\t\tgroupPrefix := m.fmtKey(\"QG\")\n\t\t\terr := m.txn(Background(), func(tx *kvTxn) error {\n\t\t\t\ttx.deleteKeys(userPrefix)\n\t\t\t\ttx.deleteKeys(groupPrefix)\n\t\t\t\tm.genLog(tx, time.Now(), \"INIT_ENABLE_USERGROUPQUOTA()\")\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn errors.Wrap(err, \"delete user group quota\")\n\t\t\t}\n\t\t}\n\t\tif err = format.update(&old, force); err != nil {\n\t\t\treturn errors.Wrap(err, \"update format\")","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/tkv.go#L521-L557","documentation":"In kvMeta.doInit (pkg/meta/tkv.go:539), after collecting stale dir-stat keys, the code deletes them in a write transaction (also writing an INIT_ENABLE_DIRSTATS changelog); a failure of that write transaction is wrapped as \"delete dir stats\". It occurs when enabling DirStats on an existing KV-engine volume.","triggerScenarios":"Enabling DirStats via `juicefs format --enable-dirstats` (or format update on mount) when the delete transaction fails: write conflicts, transaction too large for TiKV (many stale keys), or store write errors.","commonSituations":"Old volumes with a huge number of dir-stat entries hitting TiKV transaction size limits; read-only or quota-exceeded etcd/Badger backends; concurrent clients racing the format update.","solutions":["Retry the format; if TiKV rejects a too-large transaction, check for 'transaction too large' in the wrapped error and clean stale 'U'-prefix keys in batches manually or upgrade JuiceFS.","Verify the KV backend is writable (disk space, raft availability) and that no conflicting format operation is running concurrently.","Inspect the wrapped cause via `juicefs format` output / client log and address the store-specific error (leader not found, not leader, etc.)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"null","typeGuard":null,"tryCatchPattern":"if err := formatVolume(); err != nil {\n    if strings.Contains(err.Error(), \"delete dir stats\") {\n        // check for 'transaction too large' or store write errors, then retry\n    }\n}","preventionTips":["Keep KV backends writable: check disk space, raft availability, and etcd backend quota before formatting.","Avoid concurrent format/update operations on the same volume.","For huge legacy volumes, clean stale dir-stat keys in batches before toggling the feature."],"tags":["go","kv","tikv","format","dirstats","transaction"],"backgroundTag":"database-write-failed","analyzedSha":"c9a67b23e8e08ec23ec331aa6f1675e2319e921c","analyzedAt":"2026-09-06T17:55:48.476Z","contentChangedAt":"2026-09-06T17:55:48.476Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}