juicedata/juicefs · error

invalid key %s

Error message

invalid key %s

What it means

While cleaning up delayed slice deletions, entries in the delSlices hash are keyed by "<sliceId>_<timestamp>". A key that does not split into exactly two underscore-separated parts cannot be parsed, so cleanup aborts with this error rather than acting on an unknown key format.

Source

Thrown at pkg/meta/redis.go:4116

		close(delKeys)
	}()

	var ss []Slice
	var rs []*redis.IntCmd
	for key := range delKeys {
		var clean bool
		task := func(tx *redis.Tx) error {
			ss = ss[:0]
			rs = rs[:0]
			val, err := tx.HGet(ctx, m.delSlices(), key).Result()
			if err == redis.Nil {
				return nil
			} else if err != nil {
				return err
			}
			ps := strings.Split(key, "_")
			if len(ps) != 2 {
				return fmt.Errorf("invalid key %s", key)
			}
			ts, err := strconv.ParseInt(ps[1], 10, 64)
			if err != nil {
				return fmt.Errorf("invalid key %s, fail to parse timestamp", key)
			}

			m.decodeDelayedSlices([]byte(val), &ss)
			clean, err = scan(ss, ts)
			if err != nil {
				return err
			}
			if clean {
				_, err = tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error {
					for _, s := range ss {
						rs = append(rs, pipe.HIncrBy(ctx, m.sliceRefs(), m.sliceKey(s.Id, s.Size), -1))
					}
					pipe.HDel(ctx, m.delSlices(), key)
					id, err := strconv.ParseUint(ps[0], 10, 64)

View on GitHub (pinned to c9a67b23e8)

Solutions

  1. Inspect the offending key with redis-cli HKEYS on the delSlices hash and identify where it came from.
  2. If it is foreign data (another app sharing the Redis DB), move the app to its own DB index or key prefix.
  3. If it is stale/unknown and its slices are accounted for, remove the hash entry deliberately and re-run cleanup.
  4. Ensure all clients run a JuiceFS version using the same delSlices key format.
Defensive patterns

Strategy: validation

Validate before calling

for _, k := range hashKeys {
    if len(strings.Split(k, "_")) != 2 { fmt.Printf("malformed delSlices key %q — inspect before cleanup\n", k) }
}

Try / catch

if err := cleanup(ctx); err != nil && strings.Contains(err.Error(), "invalid key") {
    logger.Errorf("foreign/corrupt metadata key detected: %v", err)
    // halt automated cleanup, reconcile manually
}

Prevention

When it happens

Trigger: A foreign or manually inserted entry inside the delSlices hash, or a value written under a different key convention (e.g. by a different code path or old/new client mismatch) encountered during delayed-slice cleanup scan.

Common situations: Manual Redis surgery on metadata keys; entries left by a very old JuiceFS version with a different key scheme; accidental key collisions from sharing a Redis DB with other applications.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


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