{"record":{"id":"8ef78be1c5a7192d","repo":"dgraph-io/dgraph","slug":"cannot-load-schema-after-streaming-data","errorCode":null,"errorMessage":"cannot load schema after streaming data","messagePattern":"cannot load schema after streaming data","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"worker/import.go","lineNumber":498,"sourceCode":"\t// Receive the first message to check the Forward flag.\n\t// If Forward is true, this node is the leader and should forward the stream to its followers.\n\t// If Forward is false, the node just writes and flushes the data.\n\tforwardReq, err := stream.Recv()\n\tif err != nil {\n\t\treturn err\n\t}\n\n\tglog.Infof(\"[import] received forward flag: %v\", forwardReq.Forward)\n\treturn streamInGroup(stream, forwardReq.Forward)\n}\n\n// postStreamProcessing handles the post-stream processing of data received from the buffer into the local BadgerDB.\n// It loads the schema, updates the membership state, informs zero about tablets, resets caches, applies initial schema,\n// applies initial types, and resets the GQL schema store.\nfunc postStreamProcessing(ctx context.Context) error {\n\tglog.Info(\"[import:flush] post stream processing\")\n\tif err := schema.LoadFromDb(ctx); err != nil {\n\t\treturn errors.Wrapf(err, \"cannot load schema after streaming data\")\n\t}\n\tif err := UpdateMembershipState(ctx); err != nil {\n\t\treturn errors.Wrapf(err, \"cannot update membership state after streaming data\")\n\t}\n\n\tgr.informZeroAboutTablets()\n\tposting.ResetCache()\n\tResetAclCache()\n\tgroups().applyInitialSchema()\n\tgroups().applyInitialTypes()\n\tResetGQLSchemaStore()\n\tglog.Info(\"[import:flush] post stream processing done\")\n\treturn nil\n}\n\n// streamInGroup handles the streaming of data within a group.\n// This function is called on both leader and follower nodes with different behaviors:\n// - Leader (forward=true): The leader node receives data and forwards it to all group members","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/worker/import.go#L480-L516","documentation":"After an external snapshot stream is flushed into BadgerDB, postStreamProcessing reloads the in-memory schema from the freshly written postings via schema.LoadFromDb. If that load fails, the node's schema state would be inconsistent with the restored data, so the error wraps the underlying cause.","triggerScenarios":"schema.LoadFromDb fails right after streaming snapshot data — typically due to Badger/IO errors reading the posting layer, corrupted or partially flushed snapshot data, or the context being canceled mid-load.","commonSituations":"Disk full or corruption during snapshot restore; node crashed/restarted during a previous import leaving partial data; context canceled because the import caller timed out.","solutions":["Inspect the wrapped cause (errors.Cause) and fix the underlying Badger/IO issue (disk space, permissions, corruption).","Re-run the external snapshot import from a clean snapshot to get consistent data.","Check node disk health and Badger directory for leftover/partial files.","Increase client timeout so the post-processing context is not canceled."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":"// check disk space and context before import post-processing\nif freeDisk(postingsDir) < requiredBytes { return errors.New(\"insufficient disk for snapshot restore\") }\nif ctx.Err() != nil { return ctx.Err() }","typeGuard":null,"tryCatchPattern":"if err := runImport(ctx); err != nil {\n    var wrapped interface{ Cause() error }\n    if errors.As(err, &target) && strings.Contains(err.Error(), \"cannot load schema after streaming\") {\n        // inspect root cause: badger/IO failure; consider full re-import\n    }\n}","preventionTips":["Monitor disk space on Badger directories before/during imports","Avoid canceling import contexts during flush/post-processing","Use journal drains and clean snapshots so partial data cannot corrupt schema load"],"tags":["storage","badger","schema","import"],"backgroundTag":"schema-load-failure","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}