{"record":{"id":"530f8a3483782cdf","repo":"juicedata/juicefs","slug":"database-redis-s-is-not-empty","errorCode":null,"errorMessage":"Database redis://%s is not empty","messagePattern":"Database redis://(.+?) is not empty","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/redis.go","lineNumber":5197,"sourceCode":"\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 {\n\t\t\t\tfor i, r := range rs {\n\t\t\t\t\tif r.Err() != nil {\n\t\t\t\t\t\tlogger.Errorf(\"failed command %d %+v: %s\", i, r, r.Err())\n\t\t\t\t\t\tbreak\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tpanic(err)\n\t\t\t}\n\t\t}\n\t}\n\tdefer func() {","sourceCodeStart":5179,"sourceCodeEnd":5215,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/redis.go#L5179-L5215","documentation":"Returned by LoadMeta (redis.go:5197) for a non-cluster Redis target: DBSize() reports more than 0 keys, so the destination database is not empty. LoadMeta refuses to proceed because loading a dump into a non-empty DB would produce a corrupted merge of two metadata sets.","triggerScenarios":"Running `juicefs load` against a standalone Redis URL whose selected DB already contains keys (e.g. an existing volume's metadata, or leftover keys from a previous load).","commonSituations":"Restoring over a live volume; loading into DB 0 of a shared Redis server; a failed/partial previous load leaving keys behind.","solutions":["Use an empty Redis DB (fresh instance or an unused DB number) as the load target.","If the existing keys are disposable, run FLUSHDB on the target DB and retry.","Verify the Redis URL/DB index in your command points to the intended destination.","If a previous load partially completed, flush and re-load from the original dump to avoid a mixed state."],"exampleFix":"// before\njuicefs load redis://shared:6379/0 backup.json   // DB 0 in use\n// after\nredis-cli -h shared -n 0 flushdb\njuicefs load redis://shared:6379/0 backup.json","handlingStrategy":"validation","validationCode":"// shell: refuse to load into a non-empty DB\ndbsize=$(redis-cli -h target -p 6379 -n 0 dbsize)\n[ \"$dbsize\" = \"0\" ] || { echo \"DB not empty ($dbsize keys)\"; exit 1; }","typeGuard":null,"tryCatchPattern":"if err := meta.LoadMeta(ctx, r); err != nil {\n    if strings.Contains(err.Error(), \"is not empty\") {\n        // pick an empty DB index or FLUSHDB the target, then retry\n    }\n    return err\n}","preventionTips":["Load into a dedicated, empty Redis instance or unused DB index.","FLUSHDB the target before every restore in scripts.","Never point `juicefs load` at a live volume's metadata URL.","After a failed load, flush before retrying — partial keys remain."],"tags":["redis","load","restore","non-empty-database"],"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-14T00:17:10.932Z"}