{"record":{"id":"99cfdce7bf7b4858","repo":"dgraph-io/dgraph","slug":"failed-to-open-badgerdb-at-v-v","errorCode":null,"errorMessage":"failed to open BadgerDB at [%v]: %v","messagePattern":"failed to open BadgerDB at \\[(.+?)\\]: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/dgraphimport/import_client.go","lineNumber":184,"sourceCode":"func streamSnapshotForGroup(ctx context.Context, dc api.DgraphClient, pdir string, groupId uint32) error {\n\tglog.Infof(\"Opening stream for group %d from directory %s\", groupId, pdir)\n\n\t// Initialize stream with the server\n\tout, err := dc.StreamExtSnapshot(ctx)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to start external snapshot stream for group %d: %w\", groupId, err)\n\t}\n\tdefer func() {\n\t\t_ = out.CloseSend()\n\t}()\n\n\t// Open the BadgerDB instance at the specified directory\n\topt := badger.DefaultOptions(pdir)\n\topt.ReadOnly = true\n\tps, err := badger.OpenManaged(opt)\n\tif err != nil {\n\t\tglog.Errorf(\"failed to open BadgerDB at [%s]: %v\", pdir, err)\n\t\treturn fmt.Errorf(\"failed to open BadgerDB at [%v]: %v\", pdir, err)\n\t}\n\tdefer func() {\n\t\tif err := ps.Close(); err != nil {\n\t\t\tglog.Warningf(\"[import] Error closing BadgerDB: %v\", err)\n\t\t}\n\t}()\n\n\t// Send group ID as the first message in the stream\n\tglog.Infof(\"[import] Sending request for streaming external snapshot for group ID [%v]\", groupId)\n\tgroupReq := &api.StreamExtSnapshotRequest{GroupId: groupId}\n\tif err := out.Send(groupReq); err != nil {\n\t\treturn fmt.Errorf(\"failed to send request for group ID [%v] to the server: %w\", groupId, err)\n\t}\n\tif _, err := out.Recv(); err != nil {\n\t\treturn fmt.Errorf(\"failed to receive response for group ID [%v] from the server: %w\", groupId, err)\n\t}\n\n\tglog.Infof(\"[import] Group [%v]: Received ACK for sending group request\", groupId)","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/dgraphimport/import_client.go#L166-L202","documentation":"Returned when badger.OpenManaged fails to open the posting-directory BadgerDB in read-only mode before streaming. The import client logs the same error with glog and wraps it for the caller. The pdir is a posting directory exported from the cluster, so a bad path or lock file blocks the entire group stream.","triggerScenarios":"badger.OpenManaged(opt) with a non-existent or wrong pdir path; another process still holds the BADGER.lock (e.g. a live Alpha using that directory); corrupted key-value files; read-only filesystem; badger version mismatch between writer and reader.","commonSituations":"Pointing the importer at the wrong directory (typo, wrong group's pdir); trying to open a directory in use by a running Alpha; export copied with missing/empty files; opening with a newer badger library than the one that wrote the data.","solutions":["Verify pdir exists and is the correct group's posting directory (ls the dir, check for KEYREGISTRY/MANIFEST files).","Ensure no other process (running Alpha or previous import) holds the directory lock; stop it or copy the directory.","Check the filesystem is writable enough for lock/temp files even in ReadOnly mode.","Match the badger library version to the one that produced the export.","If corrupted, re-export the pdir from the cluster."],"exampleFix":"// before\nopt := badger.DefaultOptions(pdir)\nps, err := badger.OpenManaged(opt)\n// after\nif _, err := os.Stat(filepath.Join(pdir, \"MANIFEST\")); err != nil {\n\treturn fmt.Errorf(\"invalid badger dir %q: run export first\", pdir)\n}\nopt := badger.DefaultOptions(pdir)\nopt.ReadOnly = true\nps, err := badger.OpenManaged(opt)\nif err != nil {\n\treturn fmt.Errorf(\"failed to open BadgerDB at [%v]: %v\", pdir, err)\n}","handlingStrategy":"validation","validationCode":"func validateBadgerDir(pdir string) error {\n\tinfo, err := os.Stat(pdir)\n\tif err != nil || !info.IsDir() {\n\t\treturn fmt.Errorf(\"pdir %q missing or not a directory\", pdir)\n\t}\n\tfor _, f := range []string{\"MANIFEST\", \"KEYREGISTRY\"} {\n\t\tif _, err := os.Stat(filepath.Join(pdir, f)); err != nil {\n\t\t\treturn fmt.Errorf(\"pdir %q missing %s; re-run export\", pdir, f)\n\t\t}\n\t}\n\t// lock probe: opening read-only will fail if another process holds the dir\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"ps, err := badger.OpenManaged(opt)\nif err != nil {\n\tif strings.Contains(err.Error(), \"lock\") {\n\t\treturn fmt.Errorf(\"another process holds %q; stop Alpha or copy dir\", pdir)\n\t}\n\treturn fmt.Errorf(\"failed to open BadgerDB at [%v]: %v\", pdir, err)\n}","preventionTips":["Confirm pdir path per group before opening.","Never open a pdir that a live Alpha is using; copy or stop it first.","Check available disk space and filesystem permissions.","Use the badger library version that matches the export's format version."],"tags":["badger","filesystem","snapshot-import","configuration"],"backgroundTag":"badger-db-open-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}