{"record":{"id":"69b38285ed6dfd99","repo":"juicedata/juicefs","slug":"only-d-records-inserted-69b382","errorCode":null,"errorMessage":"only %d records inserted","messagePattern":"only (.+?) records inserted","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/sql_bak.go","lineNumber":861,"sourceCode":"\tfor _, st := range stats {\n\t\trows = append(rows, &dirStats{\n\t\t\tInode:      Ino(st.Inode),\n\t\t\tDataLength: st.DataLength,\n\t\t\tUsedInodes: st.UsedInodes,\n\t\t\tUsedSpace:  st.UsedSpace,\n\t\t})\n\t}\n\treturn m.insertRows(rows)\n}\n\nfunc (m *dbMeta) insertRows(beans []interface{}) error {\n\tbatch := m.getTxnBatchNum()\n\tfor len(beans) > 0 {\n\t\tbs := min(batch, len(beans))\n\t\terr := m.txn(func(s *xorm.Session) error {\n\t\t\tn, err := s.Insert(beans[:bs])\n\t\t\tif err == nil && int(n) != bs {\n\t\t\t\terr = fmt.Errorf(\"only %d records inserted\", n)\n\t\t\t}\n\t\t\treturn err\n\t\t})\n\t\tif err != nil {\n\t\t\tlogger.Errorf(\"Write %d beans: %s\", bs, err)\n\t\t\treturn err\n\t\t}\n\t\tbeans = beans[bs:]\n\t}\n\treturn nil\n}\n\nfunc (m *dbMeta) prepareLoad(ctx Context, opt *LoadOption) error {\n\topt.check()\n\tif err := m.checkAddr(); err != nil {\n\t\treturn err\n\t}\n\tif err := m.syncAllTables(); err != nil {","sourceCodeStart":843,"sourceCodeEnd":879,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/sql_bak.go#L843-L879","documentation":"During backup loading (sql_bak.go), records are inserted into the SQL metadata engine in batches inside a transaction. xorm's Insert returns the number of rows affected; if it differs from the batch size, JuiceFS treats the insert as incomplete and fails with this error to avoid silently writing a partial backup. It indicates a partially-failed multi-row insert that the driver did not report as an error.","triggerScenarios":"Calling `juicefs load` (meta.Load/Write fallback path) where `s.Insert(beans[:bs])` returns n < bs, e.g. the database silently skipped rows due to a driver quirk, row-count truncation, or a replaced row counting as fewer affected rows.","commonSituations":"Restoring a large dump into MySQL/PostgreSQL/SQLite where the driver reports affected-row counts differently (e.g. CLIENT_FOUND_ROWS off, upserts counting as 2), or a storage-side constraint swallowed part of the batch.","solutions":["Retry the load; if it recurs, check the target DB's affected-rows semantics and driver DSN flags (e.g. enable CLIENT_FOUND_ROWS on MySQL).","Verify the backup file is not corrupt and the target metadata engine is empty before loading (duplicate keys can change affected-row counts).","Check the database server error log for silently dropped or truncated statements and ensure the table schema matches the dump version.","If a specific engine consistently misreports counts, upgrade JuiceFS and file an issue with the engine type and driver version."],"exampleFix":"// before\nn, err := s.Insert(beans[:bs])\nif err == nil && int(n) != bs {\n    err = fmt.Errorf(\"only %d records inserted\", n)\n}\n// after (operator-side: load into a clean, empty database)\n# ensure target tables are empty first\njuicefs dump sqlite3://old.db out.json\nrm -f new.db && juicefs format sqlite3://new.db vol\njuicefs load sqlite3://new.db out.json","handlingStrategy":"validation","validationCode":"rows, _ := targetDB.Query(\"SELECT COUNT(*) FROM jfs_...\") // confirm target tables are empty before load","typeGuard":null,"tryCatchPattern":"if err := juicefsLoad(metaURL, dumpFile); err != nil { log.Fatalf(\"load failed (partial write possible, re-load into clean DB): %v\", err) }","preventionTips":["Always load into a freshly formatted, empty metadata store","Match driver/DSN flags between environments (CLIENT_FOUND_ROWS)","Validate the dump file with juicefs dump/load round-trip in CI"],"tags":["database","metadata","backup-restore","mysql","postgresql","sqlite"],"backgroundTag":"database-write-failed","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"}