{"record":{"id":"1310000447c3c0f0","repo":"juicedata/juicefs","slug":"scan-slice-refs","errorCode":null,"errorMessage":"scan slice refs","messagePattern":"scan slice refs","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/sql.go","lineNumber":4134,"sourceCode":"\t}\n\treturn nil\n}\n\nfunc (m *dbMeta) scanPendingSlices(ctx Context, scan pendingSliceScan) error {\n\tif scan == nil {\n\t\treturn nil\n\t}\n\tvar refs []sliceRef\n\terr := m.simpleTxn(ctx, func(tx *xorm.Session) error {\n\t\tif ok, err := tx.IsTableExist(&sliceRef{}); err != nil {\n\t\t\treturn err\n\t\t} else if !ok {\n\t\t\treturn nil\n\t\t}\n\t\treturn tx.Where(\"refs <= 0\").Find(&refs)\n\t})\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"scan slice refs\")\n\t}\n\tfor _, ref := range refs {\n\t\tclean, err := scan(ref.Id, ref.Size)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"scan slice\")\n\t\t}\n\t\tif clean {\n\t\t\t// TODO: m.deleteSlice(ref.Id, ref.Size)\n\t\t\t// avoid lint warning\n\t\t\t_ = clean\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc (m *dbMeta) scanPendingFiles(ctx Context, scan pendingFileScan) error {\n\tif scan == nil {\n\t\treturn nil","sourceCodeStart":4116,"sourceCodeEnd":4152,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/sql.go#L4116-L4152","documentation":"scanPendingSlices lists sliceRef rows whose reference count has dropped to <= 0 so stale slices can be removed. If the SELECT of these slice refs fails, the error is wrapped as \"scan slice refs\" and `juicefs gc` fails.","triggerScenarios":"`juicefs gc` (pending-slice scan) on a SQL volume: `SELECT ... FROM slice_ref WHERE refs <= 0` fails due to connection failure, lock timeout, or missing/corrupt slice_ref table (IsTableExist error propagates here too).","commonSituations":"DB connectivity issues during gc; MySQL wait_timeout killing idle connections mid-scan; table-level corruption; insufficient SELECT privileges added mid-run.","solutions":["Re-run `juicefs gc` after confirming DB connectivity","Fix the underlying DB error shown in the wrapped cause (privileges, locks, connectivity)","Run gc with a stable direct DB connection rather than through flaky proxies","Check table integrity if corruption is suspected"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// verify read access to slice_ref before gc\nrows, err := db.Query(\"SELECT 1 FROM slice_ref LIMIT 1\")","typeGuard":null,"tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"scan slice refs\") {\n    // fix underlying SQL error (cause is wrapped) then re-run gc\n}","preventionTips":["Grant SELECT on slice_ref to the metadata user","Avoid network paths that drop long-lived DB connections","Run `CHECK TABLE`/integrity checks if failures persist"],"tags":["database","gc","sql"],"backgroundTag":"sql-query-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"}