{"record":{"id":"bd7dd0f27c9321e1","repo":"juicedata/juicefs","slug":"remove-dir-stats","errorCode":null,"errorMessage":"remove dir stats","messagePattern":"remove dir stats","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/redis.go","lineNumber":355,"sourceCode":"\tbody, err := m.rdb.Get(ctx, m.setting()).Bytes()\n\tif err != nil && err != redis.Nil {\n\t\treturn err\n\t}\n\tif err == nil {\n\t\tvar old Format\n\t\terr = json.Unmarshal(body, &old)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"existing format is broken: %s\", err)\n\t\t}\n\t\tif !old.DirStats && format.DirStats {\n\t\t\t// remove dir stats as they are outdated\n\t\t\t_, err := m.rdb.TxPipelined(ctx, func(pipe redis.Pipeliner) error {\n\t\t\t\tpipe.Del(ctx, m.dirUsedInodesKey(), m.dirUsedSpaceKey())\n\t\t\t\tm.genLog(ctx, pipe, 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, \"remove 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\t_, err := m.rdb.TxPipelined(ctx, func(pipe redis.Pipeliner) error {\n\t\t\t\tpipe.Del(ctx, m.userQuotaKey(), m.userQuotaUsedSpaceKey(), m.userQuotaUsedInodesKey(),\n\t\t\t\t\tm.groupQuotaKey(), m.groupQuotaUsedSpaceKey(), m.groupQuotaUsedInodesKey())\n\t\t\t\tm.genLog(ctx, pipe, 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, \"remove 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\")\n\t\t}\n\t}","sourceCodeStart":337,"sourceCodeEnd":373,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/redis.go#L337-L373","documentation":"This error is returned from redisMeta.doInit when the format update path tries to remove legacy dir-stat keys (dirUsedInodesKey/dirUsedSpaceKey) inside a Redis transaction and the TxPipelined call fails. JuiceFS disables dir stats when upgrading from a format that had them, and removal of the obsolete counters must succeed for init to proceed.","triggerScenarios":"Mounting (doInit) against a Redis metadata URL whose stored format previously had DirStats enabled but the new format disables it (`juicefs config --dir-stats false` or format downgrade), and the Redis transaction DELing the dir-stat keys fails (connection error, READONLY replica, cluster MOVED error, etc.).","commonSituations":"Pointing at a read-only Redis replica during a format change; Redis cluster topology changes mid-init; network blips between client and Redis while upgrading format settings.","solutions":["Retry the mount once Redis connectivity is restored; doInit re-runs the removal transaction.","Verify the Redis instance is writable (not a READONLY replica) and that the key exists on the primary in cluster mode.","Check Redis logs for OOM or maxmemory errors blocking writes.","If the keys are already gone, confirm the format was updated and the mount will skip this branch."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Confirm the Redis endpoint is writable before mounting:\nif err := rdb.Ping(ctx).Err(); err != nil { return err }\n// role_check via INFO replication: skip READONLY replicas","typeGuard":null,"tryCatchPattern":"if err := doInit(ctx, format); err != nil {\n    if strings.Contains(err.Error(), \"remove dir stats\") {\n        time.Sleep(backoff); return doInit(ctx, format) // transient Redis failure\n    }\n    return err\n}","preventionTips":["Point mounts at the Redis primary, never a READONLY replica.","Check Redis maxmemory/OOM logs before format changes.","Verify format changes via `juicefs status` before mounting clients.","Use stable Redis cluster topology (no failover mid-mount)."],"tags":["go","redis","metadata","format-update"],"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"}