{"record":{"id":"0925d8d2f73ae979","repo":"juicedata/juicefs","slug":"found-key-with-same-prefix-s-0925d8","errorCode":null,"errorMessage":"found key with same prefix: %s","messagePattern":"found key with same prefix: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/redis_bak.go","lineNumber":984,"sourceCode":"\nfunc (m *redisMeta) loadParents(ctx Context, msg proto.Message) error {\n\tpipe := m.rdb.Pipeline()\n\tfor _, p := range msg.(*pb.Batch).Parents {\n\t\tpipe.HIncrBy(ctx, m.parentKey(Ino(p.Inode)), Ino(p.Parent).String(), p.Cnt)\n\t\tif pipe.Len() >= redisPipeLimit {\n\t\t\tif err := execPipe(ctx, pipe); err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t}\n\t}\n\treturn execPipe(ctx, pipe)\n}\n\nfunc (m *redisMeta) prepareLoad(ctx Context, opt *LoadOption) error {\n\topt.check()\n\tif _, ok := m.rdb.(*redis.ClusterClient); ok {\n\t\terr := m.scan(ctx, \"*\", func(keys []string) error {\n\t\t\treturn fmt.Errorf(\"found key with same prefix: %s\", keys[0])\n\t\t})\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t} else {\n\t\tdbsize, err := m.rdb.DBSize(ctx).Result()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif dbsize > 0 {\n\t\t\treturn fmt.Errorf(\"database redis://%s is not empty\", m.addr)\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":966,"sourceCodeEnd":1000,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/redis_bak.go#L966-L1000","documentation":"Before restoring metadata (prepareLoad), JuiceFS verifies the target is empty. With a Redis ClusterClient it cannot just check DBSize (per-node), so it scans for any keys sharing the volume's prefix; any found key aborts the load with this error naming the offending key.","triggerScenarios":"Running `juicefs load` (or warmup restore) into a Redis Cluster that already contains keys under the same prefix — typically a previous volume using the same cluster, or loading into the wrong cluster address.","commonSituations":"Loading a backup into a cluster that still holds an old volume's data; pointing --meta at a shared production cluster instead of a fresh one; a prior failed load that partially wrote keys before aborting.","solutions":["Flush the stale keys: run `redis-cli --cluster` FLUSHALL on the target cluster, or delete keys matching the reported prefix.","Point the load at the correct (empty) Redis cluster address.","If a previous load partially failed, clear the prefix and retry the load.","For non-cluster Redis, DBSize is used instead — verify you are actually connecting to a cluster and whether that is intended."],"exampleFix":"// before\njuicefs load -i backup.json redis://stale-cluster:6379/myfs\n// after\nredis-cli -c -h stale-cluster FLUSHALL\njuicefs load -i backup.json redis://stale-cluster:6379/myfs","handlingStrategy":"validation","validationCode":"// pre-check before load (cluster)\nvar found bool\nrdb.ForEachMaster(ctx, func(ctx context.Context, c *redis.Client) error {\n    return c.Scan(ctx, 0, \"*\", 100).Iterator().NextErr == nil && !found && func() error {\n        keys, _ := c.Scan(ctx, 0, \"*\", 10).Result()\n        if len(keys) > 0 { found = true }\n        return nil\n    }()\n})\nif found { return errors.New(\"cluster not empty, aborting load\") }","typeGuard":null,"tryCatchPattern":"if err := load(ctx, meta, f); err != nil {\n    if strings.Contains(err.Error(), \"found key with same prefix\") {\n        log.Fatalf(\"target cluster holds another volume's keys: %v\", err)\n    }\n    return err\n}","preventionTips":["Use a dedicated Redis cluster per volume restore.","Flush the cluster (FLUSHALL) before loading after confirming no live data.","Double-check the --meta URL points at the intended cluster.","Clean up after partially failed loads instead of retrying over leftovers."],"tags":["redis","cluster","load","non-empty-target"],"backgroundTag":"file-already-exists","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"}