{"record":{"id":"1470d5b3b1462fa1","repo":"dgraph-io/dgraph","slug":"while-updating-persisted-query-s-type","errorCode":null,"errorMessage":"while updating persisted query's type","messagePattern":"while updating persisted query's type","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upgrade/change_v21.03.0.go","lineNumber":432,"sourceCode":"\tif err := update(entry); err != nil {\n\t\treturn errors.Wrap(err, \"while updating persisted query's schema\")\n\t}\n\n\t// Update the type.\n\ttu := pb.TypeUpdate{\n\t\tTypeName: x.AttrInRootNamespace(\"dgraph.graphql.persisted_query\"),\n\t\tFields:   []*pb.SchemaUpdate{&su},\n\t}\n\tdata, err = proto.Marshal(&tu)\n\tif err != nil {\n\t\treturn err\n\t}\n\tentry = &badger.Entry{}\n\tentry.Key = x.TypeKey(x.AttrInRootNamespace(\"dgraph.graphql.persisted_query\"))\n\tentry.Value = data\n\tentry.UserMeta = posting.BitSchemaPosting\n\tif err := update(entry); err != nil {\n\t\treturn errors.Wrap(err, \"while updating persisted query's type\")\n\t}\n\treturn nil\n}\n\n// OfflineUpgradeFrom2011To2103 upgrades a p directory restored from backup of 20.11 to the changes\n// in 21.03. It fixes the cors, schema and drops the deprecated types/predicates.\nfunc OfflineUpgradeFrom2011To2103(db *badger.DB) error {\n\tif err := fixPersistedQuery(db); err != nil {\n\t\treturn errors.Wrapf(err, \"while upgrading persisted query\")\n\t}\n\treturn errors.Wrapf(fixCors(db), \"while upgrading cors\")\n}\n","sourceCodeStart":414,"sourceCodeEnd":445,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/upgrade/change_v21.03.0.go#L414-L445","documentation":"This is the sibling failure in fixPersistedQuery: after updating the p_query schema, the function writes a new type entry for dgraph.graphql.persisted_query. A badger write failure on the TypeKey entry is wrapped with this message.","triggerScenarios":"During OfflineUpgradeFrom2011To2103, badger.DB.Write fails for the entry keyed by TypeKey(dgraph.graphql.persisted_query) — e.g. disk full, DB closed, badger internal error.","commonSituations":"Offline migration of a 20.11 backup to 21.03; badger lock contention; storage exhaustion on the node performing the upgrade.","solutions":["Inspect the wrapped badger error and fix the underlying cause (disk space, permissions, lock).","Verify the server is fully stopped before running the offline upgrade so the p directory is not locked.","Re-restore from backup and rerun the upgrade if the type entry is corrupt.","Keep a pre-upgrade copy of the p directory to allow a clean retry."],"exampleFix":"// before\ndf -h # disk full -> write fails\n# after freeing space\ndgraph upgrade offline -w v21.03.0 -d ./p","handlingStrategy":"try-catch","validationCode":"// Sanity-check write access and space before running the upgrade\nif fi, err := os.Statfs(pDir); err == nil && fi.Bavail*uint64(fi.Bsize) < 1<<30 {\n\tlog.Fatal(\"less than 1GB free; upgrade writes may fail\")\n}","typeGuard":"func isPersistedQueryTypeWriteErr(err error) bool {\n\treturn err != nil && strings.Contains(err.Error(), \"while updating persisted query's type\")\n}","tryCatchPattern":"if err := upgrade.OfflineUpgradeFrom2011To2103(db); err != nil {\n\tlog.Fatalf(\"type update failed: %+v\", err)\n}","preventionTips":["Ensure >1GB free space on the p-directory volume","Run upgrades with the server stopped to avoid lock contention","Verify badger directory integrity with dgraph debug first","Retry from a clean re-restore if entries were partially written"],"tags":["badger","migration","persisted-query","offline-upgrade"],"backgroundTag":"offline-schema-upgrade-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}