{"record":{"id":"868efd3d678ae5ba","repo":"dgraph-io/badger","slug":"cannot-use-getsequence-with-manageddb-true","errorCode":null,"errorMessage":"Cannot use GetSequence with managedDB=true.","messagePattern":"Cannot use GetSequence with managedDB=true\\.","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"db.go","lineNumber":1429,"sourceCode":"\t\tvar buf [8]byte\n\t\tbinary.BigEndian.PutUint64(buf[:], lease)\n\t\tif err = txn.SetEntry(NewEntry(seq.key, buf[:])); err != nil {\n\t\t\treturn err\n\t\t}\n\t\tseq.leased = lease\n\t\treturn nil\n\t})\n}\n\n// GetSequence would initiate a new sequence object, generating it from the stored lease, if\n// available, in the database. Sequence can be used to get a list of monotonically increasing\n// integers. Multiple sequences can be created by providing different keys. Bandwidth sets the\n// size of the lease, determining how many Next() requests can be served from memory.\n//\n// GetSequence is not supported on ManagedDB. Calling this would result in a panic.\nfunc (db *DB) GetSequence(key []byte, bandwidth uint64) (*Sequence, error) {\n\tif db.opt.managedTxns {\n\t\tpanic(\"Cannot use GetSequence with managedDB=true.\")\n\t}\n\tif db.opt.ReadOnly {\n\t\tpanic(\"Cannot use GetSequence in read-only mode.\")\n\t}\n\n\tswitch {\n\tcase len(key) == 0:\n\t\treturn nil, ErrEmptyKey\n\tcase bandwidth == 0:\n\t\treturn nil, ErrZeroBandwidth\n\t}\n\tseq := &Sequence{\n\t\tdb:        db,\n\t\tkey:       key,\n\t\tnext:      0,\n\t\tleased:    0,\n\t\tbandwidth: bandwidth,\n\t}","sourceCodeStart":1411,"sourceCodeEnd":1447,"githubUrl":"https://github.com/dgraph-io/badger/blob/2a001d466f6b71a917319a1db41f99860e16e269/db.go#L1411-L1447","documentation":"GetSequence is not supported on managed-database mode because badger manages transaction timestamps itself there, conflicting with sequence leases. Calling db.GetSequence while opt.managedTxns is true panics instead of returning an error.","triggerScenarios":"Calling db.GetSequence(key, bandwidth) on a DB opened via OpenManaged (or Options with managed txn mode).","commonSituations":"Mixing OpenManaged (used with Dgraph or manual timestamp control) with application-level sequence generation.","solutions":["Use Open instead of OpenManaged if you need GetSequence","In managed mode, implement sequences via badger.Sequence alternatives: your own counter key in a transaction (read-modify-write)","Only call GetSequence when !db.opt.managedTxns"],"exampleFix":"// before\ndb, _ := badger.OpenManaged(opt)\nseq, _ := db.GetSequence([]byte(\"k\"), 100) // panics\n// after\ndb, _ := badger.Open(opt) // non-managed\nseq, _ := db.GetSequence([]byte(\"k\"), 100)","handlingStrategy":"validation","validationCode":"if db.opt.managedTxns { return errors.New(\"GetSequence unavailable in managed mode\") }","typeGuard":null,"tryCatchPattern":"defer func() {\n    if r := recover(); r != nil {\n        if strings.Contains(fmt.Sprint(r), \"GetSequence with managedDB\") { /* fallback counter */ }\n    }\n}()","preventionTips":["Open with OpenManaged only when you manage timestamps","Centralize sequence creation and assert non-managed mode","In managed mode use your own txn-based counter key"],"tags":["badger","panic","sequence","managed-db"],"backgroundTag":"unsupported-api-in-mode","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"}