{"record":{"id":"2218b008b5f13af0","repo":"juicedata/juicefs","slug":"found-key-with-same-prefix-s","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.go","lineNumber":5186,"sourceCode":"\t\txattrs := make(map[string]interface{})\n\t\tfor _, x := range e.Xattrs {\n\t\t\txattrs[x.Name] = unescape(x.Value)\n\t\t}\n\t\tp.HSet(ctx, m.xattrKey(inode), xattrs)\n\t}\n\n\tattr.AccessACL = m.saveACL(loadACL(e.AccessACL), aclMaxId)\n\tattr.DefaultACL = m.saveACL(loadACL(e.DefaultACL), aclMaxId)\n\n\tp.Set(ctx, m.inodeKey(inode), m.marshal(attr), 0)\n\ttryExec()\n}\n\nfunc (m *redisMeta) LoadMeta(r io.Reader) (err error) {\n\tctx := Background()\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\n\tp := m.rdb.TxPipeline()\n\ttryExec := func() {\n\t\tif p.Len() > 1000 {\n\t\t\tif rs, err := p.Exec(ctx); err != nil {","sourceCodeStart":5168,"sourceCodeEnd":5204,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/redis.go#L5168-L5204","documentation":"Returned by LoadMeta (redis.go:5186) when loading a metadata dump into a Redis Cluster: a SCAN finds at least one existing key under the target prefix, meaning the cluster DB is not empty and loading would overwrite or collide with existing data. LoadMeta requires an empty destination, so it aborts with the first colliding key.","triggerScenarios":"Running `juicefs load` (metadata restore) against a Redis Cluster whose keyspace already contains keys with the configured prefix; re-running a load into a cluster that was already loaded once.","commonSituations":"Restoring a backup over an existing volume; accidental load into a production Redis cluster; double-executing a restore script.","solutions":["Point the load at an empty Redis cluster/database (fresh instance or new prefix).","If the existing data is unwanted, flush the keys (FLUSHDB / FLUSHALL, or delete keys under the prefix) and re-run the load.","Load into a different logical DB or use a distinct prefix if sharing a Redis instance.","Double-check the target URL in the command — a typo may have aimed the restore at the wrong cluster."],"exampleFix":"// before\njuicefs load redis-cluster://prod:6379/0 backup.json\n// after: use an empty destination\njuicefs load redis-cluster://restore:6379/0 backup.json","handlingStrategy":"validation","validationCode":"// shell: ensure the target cluster is empty before loading\nkeys=$(redis-cli -c -h restore -p 6379 --scan --count 1000 | head -1)\n[ -z \"$keys\" ] || { echo \"target not empty\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := meta.LoadMeta(ctx, r); err != nil {\n    if strings.Contains(err.Error(), \"found key with same prefix\") {\n        // choose an empty cluster or flush the prefix, then retry\n    }\n    return err\n}","preventionTips":["Always restore into a freshly provisioned Redis cluster.","Check the target URL carefully — typo'd hosts cause loads into production.","Script idempotency: don't re-run a load command that already succeeded.","Use distinct key prefixes when sharing a Redis Cluster among environments."],"tags":["redis","load","restore","cluster"],"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"}