{"record":{"id":"2711c081ef710320","repo":"juicedata/juicefs","slug":"update-table-edge-chunk-xattr-sustained-s","errorCode":null,"errorMessage":"update table edge, chunk, xattr, sustained: %s","messagePattern":"update table edge, chunk, xattr, sustained: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/meta/sql.go","lineNumber":776,"sourceCode":"\t\t}\n\t\treturn err\n\t})\n\treturn\n}\n\nfunc (m *dbMeta) doNewSession(sinfo []byte, update bool) error {\n\t// add new table\n\terr := m.syncTable(new(session2), new(delslices), new(dirStats), new(detachedNode), new(dirQuota), new(userGroupQuota), new(acl), new(delegationToken), new(changeLog))\n\tif err != nil {\n\t\treturn fmt.Errorf(\"update table session2, delslices, dirstats, detachedNode, dirQuota, userGroupQuota, acl, changeLog: %s\", err)\n\t}\n\t// add node table\n\tif err = m.syncTable(new(node)); err != nil {\n\t\treturn fmt.Errorf(\"update table node: %s\", err)\n\t}\n\t// add primary key\n\tif err = m.syncTable(new(edge), new(chunk), new(xattr), new(sustained)); err != nil {\n\t\treturn fmt.Errorf(\"update table edge, chunk, xattr, sustained: %s\", err)\n\t}\n\t// update the owner from uint64 to int64\n\tif err = m.syncTable(new(flock), new(plock)); err != nil {\n\t\treturn fmt.Errorf(\"update table flock, plock: %s\", err)\n\t}\n\n\tfor {\n\t\tbeans := session2{Sid: m.sid, Expire: m.expireTime(), Info: sinfo}\n\t\tif update {\n\t\t\treturn m.txn(func(s *xorm.Session) error {\n\t\t\t\t_, err = s.Cols(\"expire\", \"info\").Update(&beans, &session2{Sid: beans.Sid})\n\t\t\t\tif err == nil {\n\t\t\t\t\tm.genLog(Background(), s, time.Now().UnixNano(), \"NEWSESSION(%d,%d,%s)\", m.sid, beans.Expire, logEncode(sinfo))\n\t\t\t\t}\n\t\t\t\treturn err\n\t\t\t})\n\t\t} else {\n\t\t\tif err = m.txn(func(s *xorm.Session) error {","sourceCodeStart":758,"sourceCodeEnd":794,"githubUrl":"https://github.com/juicedata/juicefs/blob/c9a67b23e8e08ec23ec331aa6f1675e2319e921c/pkg/meta/sql.go#L758-L794","documentation":"Same doNewSession upgrade path: syncing edge, chunk, xattr, and sustained tables (to ensure primary keys) is wrapped as 'update table edge, chunk, xattr, sustained: %s' on failure, aborting the mount.","triggerScenarios":"Legacy-volume mount when xorm Sync2 fails on any of edge/chunk/xattr/sustained — duplicate rows blocking primary-key addition, missing ALTER privilege, lock timeout, or dropped DB connection.","commonSituations":"Upgrading an old MySQL volume with large chunk/edge tables under lock-wait timeouts; restricted managed-DB accounts; interrupted previous upgrade leaving inconsistent schema.","solutions":["Grant ALTER/CREATE privileges to the metadata user and retry","Detect and remove duplicate keys in edge/chunk/xattr/sustained tables blocking primary key creation","Increase lock wait timeout (innodb_lock_wait_timeout) for the upgrade on large tables","Restore from metadata backup if a previous upgrade was interrupted and left partial schema"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"-- Check duplicates in upgrade-target tables before mounting\nSELECT inode, COUNT(*) c FROM edge GROUP BY inode, name HAVING c > 1;","typeGuard":null,"tryCatchPattern":"if err := mount(sqlURL); err != nil {\n    log.Fatalf(\"schema upgrade failed; restore backup or fix duplicates: %v\", err)\n}","preventionTips":["Backup metadata before upgrades","Raise innodb_lock_wait_timeout for large-table ALTERs","Upgrade one client at a time"],"tags":["database","sql","schema-upgrade","primary-key"],"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"}