{"record":{"id":"0241167012506bc0","repo":"juicedata/juicefs","slug":"create-table-chunk-chunk-ref-delslices-s","errorCode":null,"errorMessage":"create table chunk, chunk_ref, delslices: %s","messagePattern":"create table chunk, chunk_ref, delslices: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/sql.go","lineNumber":589,"sourceCode":"\terr := m.db.Sync2(beans...)\n\tif err != nil && strings.Contains(err.Error(), \"Duplicate key\") {\n\t\terr = nil\n\t}\n\treturn err\n}\n\nfunc (m *dbMeta) syncAllTables() error {\n\tif err := m.syncTable(new(setting), new(counter)); err != nil {\n\t\treturn fmt.Errorf(\"create table setting, counter: %s\", err)\n\t}\n\tif err := m.syncTable(new(edge)); err != nil {\n\t\treturn fmt.Errorf(\"create table edge: %s\", err)\n\t}\n\tif err := m.syncTable(new(node), new(symlink), new(xattr)); err != nil {\n\t\treturn fmt.Errorf(\"create table node, symlink, xattr: %s\", err)\n\t}\n\tif err := m.syncTable(new(chunk), new(sliceRef), new(delslices)); err != nil {\n\t\treturn fmt.Errorf(\"create table chunk, chunk_ref, delslices: %s\", err)\n\t}\n\tif err := m.syncTable(new(session2), new(sustained), new(delfile)); err != nil {\n\t\treturn fmt.Errorf(\"create table session2, sustaind, delfile: %s\", err)\n\t}\n\tif err := m.syncTable(new(flock), new(plock), new(dirQuota), new(userGroupQuota)); err != nil {\n\t\treturn fmt.Errorf(\"create table flock, plock, dirQuota, userGroupQuota: %s\", err)\n\t}\n\tif err := m.syncTable(new(dirStats)); err != nil {\n\t\treturn fmt.Errorf(\"create table dirStats: %s\", err)\n\t}\n\tif err := m.syncTable(new(detachedNode)); err != nil {\n\t\treturn fmt.Errorf(\"create table detachedNode: %s\", err)\n\t}\n\tif err := m.syncTable(new(acl)); err != nil {\n\t\treturn fmt.Errorf(\"create table acl: %s\", err)\n\t}\n\tif err := m.syncTable(new(delegationToken)); err != nil {\n\t\treturn fmt.Errorf(\"create table delegationToken: %s\", err)","sourceCodeStart":571,"sourceCodeEnd":607,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/sql.go#L571-L607","documentation":"syncAllTables (pkg/meta/sql.go:588) creates/auto-migrates the data-tracking tables `chunk`, `sliceRef`, and `delslices` via xorm Sync2; failure is wrapped as \"create table chunk, chunk_ref, delslices: %s\". These tables map file chunks to object-storage slices and track reference counts. A failure here aborts metadata initialization after the earlier tables were created, leaving a partially initialized schema.","triggerScenarios":"Metadata engine initialization when Sync2 on chunk/sliceRef/delslices fails: DDL privileges removed after earlier tables were made, DB connection dropped mid-migration, or index-creation limits exceeded on the DB server.","commonSituations":"Connection timeout on a slow remote DB mid-init; MySQL index key-length limits hit with certain charsets; read-replica mistakenly used as the metadata target.","solutions":["Check the wrapped inner error; for timeout errors retry after confirming DB health, since Sync2 is idempotent.","Verify the target is a primary/writable instance, not a read replica.","Grant CREATE/ALTER/INDEX privileges to the database user.","For MySQL key-length errors, use utf8mb4 with adequate innodb_large_prefix settings or a supported server version.","Re-run initialization; already-created tables are skipped by Sync2."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Preflight connectivity + writability so mid-init drops are unlikely\n//   mysqladmin -h <host> -P <port> -u <user> -p ping\n//   SELECT 1;  -- run via the app credentials\n// Also confirm the target is a primary: SHOW VARIABLES LIKE 'read_only'; -- must be OFF","typeGuard":null,"tryCatchPattern":"if err := initMeta(); err != nil {\n    if strings.Contains(err.Error(), \"create table chunk, chunk_ref, delslices\") {\n        if isTransient(err) { // timeout / connection reset\n            return retryWithBackoff(initMeta, 3)\n        }\n        return fmt.Errorf(\"chunk table DDL failed: %w\", err)\n    }\n    return err\n}","preventionTips":["Point the meta URL at the primary instance, never a read replica.","Use a DB connection with adequate timeout for schema creation on remote/high-latency networks.","Keep the DB user's INDEX privilege so Sync2 can create required indexes on chunk tables.","Use supported charset settings (utf8mb4, adequate index prefix limits) on MySQL."],"tags":["database","schema-migration","ddl","chunks"],"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-14T05:17:10.506Z"}