{"record":{"id":"0c5fb31ceb010e3d","repo":"juicedata/juicefs","slug":"database-s-s-is-not-empty-0c5fb3","errorCode":null,"errorMessage":"database %s://%s is not empty","messagePattern":"database (.+?)://(.+?) is not empty","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/tkv_bak.go","lineNumber":86,"sourceCode":"}\n\nfunc (m *kvMeta) load(ctx Context, typ int, opt *LoadOption, val proto.Message) error {\n\treturn errors.New(\"not implemented, use kvMeta.LoadMetaV2 instead\")\n}\n\nfunc (m *kvMeta) prepareLoad(ctx Context, opt *LoadOption) error {\n\topt.check()\n\n\tvar exist bool\n\terr := m.txn(ctx, func(tx *kvTxn) error {\n\t\texist = tx.exist(m.fmtKey())\n\t\treturn nil\n\t})\n\tif err != nil {\n\t\treturn err\n\t}\n\tif exist {\n\t\treturn fmt.Errorf(\"database %s://%s is not empty\", m.Name(), m.addr)\n\t}\n\treturn nil\n}\n\nfunc printSums(sums map[int]*atomic.Uint64) string {\n\tvar p string\n\tfor typ, sum := range sums {\n\t\tp += fmt.Sprintf(\"%d num: %d\\n\", typ, sum.Load())\n\t}\n\treturn p\n}\n\nfunc (m *kvMeta) dumpCounters(ctx Context, opt *DumpOption, ch chan<- *dumpedResult) error {\n\treturn m.txn(ctx, func(tx *kvTxn) error {\n\t\tcounters := make([]*pb.Counter, 0, len(counterNames)+1)\n\t\tif m.getFormat().ChangeLog {\n\t\t\tmaxKey := m.findLastLogKey(tx)\n\t\t\tif maxKey > 0 {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/tkv_bak.go#L68-L104","documentation":"JuiceFS's `load` (metadata restore) refuses to write into a TKV (etcd/TiKV/etc.) database that already contains data. After scanning for existing keys in the target metadata engine, `prepareLoad` returns this error to protect an existing volume's metadata from being overwritten or merged by a partial load.","triggerScenarios":"Running `juicefs load` (or restore from backup) against a metadata URL whose database already has keys — e.g. a volume was formatted or mounted before, or a previous load partially completed and left data behind.","commonSituations":"Pointing `load` at a live volume's metadata instead of an empty DB; reusing a Redis/SQL/etcd instance that hosts other volumes; retrying a failed load without clearing the destination; wrong `--prefix` so leftover keys from another logical volume are detected.","solutions":["Verify you are loading into the intended (empty) metadata URL; check the address and prefix","Inspect the target DB and delete existing keys of that volume (e.g. FLUSHDB for a dedicated Redis, drop the schema/table for SQL, delete the etcd prefix) only if the data is disposable","Restore into a fresh database/instance and remount clients with the new URL","If a previous load left partial data, remove its keys before retrying"],"exampleFix":"// before\n$ juicefs load redis://old-host/1 dump.bin\nFATAL: database redis://old-host:6379/1 is not empty\n// after\n$ redis-cli -h old-host -n 1 FLUSHDB   # only if data is disposable\n$ juicefs load redis://old-host/1 dump.bin","handlingStrategy":"validation","validationCode":"// Check the target DB is empty before loading (etcd example)\nout, err := clientv3.New(clientv3.Config{Endpoints: []string{\"host:2379\"}}).Get(ctx, \"\", clientv3.WithPrefix(), clientv3.WithKeysOnly(), clientv3.WithCountOnly())\nif err != nil { log.Fatal(err) }\nif out.Count > 0 { log.Fatal(\"target metadata DB is not empty; choose an empty DB or clear it first\") }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always load into a freshly created database or a cleared prefix","Label production metadata instances and never point load/restore at live volumes","Use a dedicated prefix per volume and script the cleanup between load attempts","Snapshot the current DB before clearing anything"],"tags":["juicefs","metadata","load","etcd","tkv"],"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"}