{"record":{"id":"01f61564490c154d","repo":"juicedata/juicefs","slug":"database-redis-s-is-not-empty-01f615","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_bak.go","lineNumber":995,"sourceCode":"\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":977,"sourceCodeEnd":1000,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/redis_bak.go#L977-L1000","documentation":"prepareLoad guards `juicefs load` against overwriting live data: for standalone Redis/Sentinel it checks DBSize and refuses to proceed if the database holds any keys. Loading into a non-empty Redis would corrupt or interleave metadata.","triggerScenarios":"Running `juicefs load -i dump.json redis://host:port/vol` when the target DB already contains keys — a previous volume, another JuiceFS instance, or leftover keys from an aborted load.","commonSituations":"Restoring a backup over an existing volume by mistake; reusing a Redis instance shared with other applications; DB index selection (e.g. redis://host:6379/0 vs /1) pointing at an occupied database.","solutions":["Use a dedicated empty Redis DB: pass a distinct DB index (redis://host:6379/1) or a fresh instance.","Flush the target: redis-cli -n <db> FLUSHDB (confirm nothing else uses it first).","If the leftover keys are from a failed prior load, delete only that volume's prefix keys.","Verify the --meta URL points at the intended host/port/db before loading."],"exampleFix":"// before\njuicefs load -i backup.json redis://10.0.0.5:6379/0   # DB 0 has keys\n// after\nredis-cli -h 10.0.0.5 -n 0 DBSIZE   # verify, then flush if safe\nredis-cli -h 10.0.0.5 -n 0 FLUSHDB\njuicefs load -i backup.json redis://10.0.0.5:6379/0","handlingStrategy":"validation","validationCode":"n, err := rdb.DBSize(ctx).Result()\nif err != nil { return err }\nif n > 0 { return fmt.Errorf(\"abort: target DB has %d keys\", n) }","typeGuard":null,"tryCatchPattern":"if err := load(ctx, meta, f); err != nil {\n    if strings.Contains(err.Error(), \"is not empty\") {\n        log.Fatalf(\"refusing to load into non-empty DB; flush or choose another DB index: %v\", err)\n    }\n    return err\n}","preventionTips":["Dedicate a Redis DB index (or instance) to each restore.","Verify DBSize == 0 before every load.","Do not share a Redis instance between JuiceFS volumes without distinct DB indexes/prefixes.","Confirm the meta URL (host, port, db index) before running load."],"tags":["redis","load","non-empty-database","safety-check"],"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"}