juicedata/juicefs · error

delete dir stats

Error message

delete dir stats

What it means

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.

Source

Thrown at pkg/meta/tkv.go:539

					if len(k) == 9 {
						keys = append(keys, k)
					}
					return true
				})
				return nil
			}, 0)
			if err != nil {
				return errors.Wrap(err, "scan dir stats")
			}
			err = m.txn(Background(), func(tx *kvTxn) error {
				for _, key := range keys {
					tx.delete(key)
				}
				m.genLog(tx, time.Now(), "INIT_ENABLE_DIRSTATS()")
				return nil
			})
			if err != nil {
				return errors.Wrap(err, "delete dir stats")
			}
		}
		if !old.UserGroupQuota && format.UserGroupQuota {
			// remove user group quota as they are outdated
			userPrefix := m.fmtKey("QU")
			groupPrefix := m.fmtKey("QG")
			err := m.txn(Background(), func(tx *kvTxn) error {
				tx.deleteKeys(userPrefix)
				tx.deleteKeys(groupPrefix)
				m.genLog(tx, time.Now(), "INIT_ENABLE_USERGROUPQUOTA()")
				return nil
			})
			if err != nil {
				return errors.Wrap(err, "delete user group quota")
			}
		}
		if err = format.update(&old, force); err != nil {
			return errors.Wrap(err, "update format")

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. 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.
  2. Verify the KV backend is writable (disk space, raft availability) and that no conflicting format operation is running concurrently.
  3. Inspect the wrapped cause via `juicefs format` output / client log and address the store-specific error (leader not found, not leader, etc.).
Defensive patterns

Strategy: retry

Validate before calling

null

Try / catch

if err := formatVolume(); err != nil {
    if strings.Contains(err.Error(), "delete dir stats") {
        // check for 'transaction too large' or store write errors, then retry
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of juicedata/juicefs@c9a67b23e8 (2026-09-06). Data as JSON: /api/errors/59089679f061839d. Report an issue: GitHub.