{"record":{"id":"1f3a5dcb68fe439f","repo":"dgraph-io/badger","slug":"manifest-records-table-s-at-level-d-but-maxleve","errorCode":null,"errorMessage":"manifest records table %s at level %d, but MaxLevels is %d","messagePattern":"manifest records table (.+?) at level (.+?), but MaxLevels is (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"levels.go","lineNumber":133,"sourceCode":"\t\t\treturn nil, err\n\t\t}\n\t\tif fileID > maxFileID {\n\t\t\tmaxFileID = fileID\n\t\t}\n\t\tgo func(fname string, tf TableManifest) {\n\t\t\tvar rerr error\n\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\trerr = fmt.Errorf(\"error opening table %s: %v\\n%s\", fname, r, debug.Stack())\n\t\t\t\t}\n\t\t\t\tthrottle.Done(rerr)\n\t\t\t\tnumOpened.Add(1)\n\t\t\t}()\n\t\t\t// tables is sized by opt.MaxLevels, and nothing upstream constrains\n\t\t\t// the level recorded in the manifest, so reject an out-of-range level\n\t\t\t// here rather than letting the append below panic.\n\t\t\tif int(tf.Level) >= len(tables) {\n\t\t\t\trerr = fmt.Errorf(\n\t\t\t\t\t\"manifest records table %s at level %d, but MaxLevels is %d\",\n\t\t\t\t\tfname, tf.Level, len(tables))\n\t\t\t\treturn\n\t\t\t}\n\t\t\tdk, err := db.registry.DataKey(tf.KeyID)\n\t\t\tif err != nil {\n\t\t\t\trerr = y.Wrapf(err, \"Error while reading datakey\")\n\t\t\t\treturn\n\t\t\t}\n\t\t\ttopt := buildTableOptions(db)\n\t\t\t// Explicitly set Compression and DataKey based on how the table was generated.\n\t\t\ttopt.Compression = tf.Compression\n\t\t\ttopt.DataKey = dk\n\n\t\t\tmf, err := z.OpenMmapFile(fname, db.opt.getFileFlags(), 0)\n\t\t\tif err != nil {\n\t\t\t\trerr = y.Wrapf(err, \"Opening file: %q\", fname)\n\t\t\t\treturn","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/levels.go#L115-L151","documentation":"This build adds a guard in table-open code: the per-level tables slice is sized by opt.MaxLevels, and if the MANIFEST records a table at a level >= MaxLevels, appending would panic — so the code returns this error instead. It means the DB was created/tuned with more levels than the current MaxLevels option allows.","triggerScenarios":"Opening a DB whose MANIFEST contains a table on level N while opts.MaxLevels <= N — typically after lowering MaxLevels in options, or opening a directory produced by a different configuration/build.","commonSituations":"Changing badger.DefaultOptions MaxLevels between runs; moving a DB between services with different option files; a manifest written by a fork/patch that allowed higher levels.","solutions":["Raise opts.MaxLevels to at least the level reported in the error message and reopen","Keep MaxLevels consistent (do not lower it) for a given DB directory across deployments","If the high-level table is stray, compact/rewrite the DB with the original configuration, then switch options"],"exampleFix":"// before\nopts := badger.DefaultOptions(dir)\nopts.MaxLevels = 5 // manifest has a table on level 6\n// after\nopts.MaxLevels = 7 // at least one more than the maximum level in MANIFEST","handlingStrategy":"validation","validationCode":"// Go: ensure MaxLevels covers manifest before open\n// parse reported level from the error, or simply set MaxLevels high enough:\nopts.MaxLevels = 7 // default is 7; never lower it for an existing dir","typeGuard":null,"tryCatchPattern":"// Go\ndb, err := badger.Open(opts)\nif err != nil && strings.Contains(err.Error(), \"but MaxLevels is\") {\n    var lvl, max int\n    fmt.Sscanf(err.Error(), \"manifest records table %*s at level %d, but MaxLevels is %d\", &lvl, &max)\n    if lvl >= max { opts.MaxLevels = lvl + 1; db, err = badger.Open(opts) }\n}","preventionTips":["Keep MaxLevels (default 7) unchanged for a DB directory across services","Share one canonical options struct per environment","Document any option changes when migrating directories","Prefer defaults unless you have a specific reason"],"tags":["manifest","maxlevels","configuration"],"backgroundTag":"level-beyond-maxlevels","analyzedSha":"2a001d466f6b71a917319a1db41f99860e16e269","analyzedAt":"2026-09-05T13:00:02.264Z","contentChangedAt":"2026-09-05T13:00:02.264Z","schemaVersion":2},"datasetVersion":"2026-09-12T17:17:11.597Z"}