dgraph-io/badger · error
Cannot use GetSequence with managedDB=true.
Error message
Cannot use GetSequence with managedDB=true.
What it means
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.
Source
Thrown at db.go:1429
var buf [8]byte
binary.BigEndian.PutUint64(buf[:], lease)
if err = txn.SetEntry(NewEntry(seq.key, buf[:])); err != nil {
return err
}
seq.leased = lease
return nil
})
}
// GetSequence would initiate a new sequence object, generating it from the stored lease, if
// available, in the database. Sequence can be used to get a list of monotonically increasing
// integers. Multiple sequences can be created by providing different keys. Bandwidth sets the
// size of the lease, determining how many Next() requests can be served from memory.
//
// GetSequence is not supported on ManagedDB. Calling this would result in a panic.
func (db *DB) GetSequence(key []byte, bandwidth uint64) (*Sequence, error) {
if db.opt.managedTxns {
panic("Cannot use GetSequence with managedDB=true.")
}
if db.opt.ReadOnly {
panic("Cannot use GetSequence in read-only mode.")
}
switch {
case len(key) == 0:
return nil, ErrEmptyKey
case bandwidth == 0:
return nil, ErrZeroBandwidth
}
seq := &Sequence{
db: db,
key: key,
next: 0,
leased: 0,
bandwidth: bandwidth,
}View on GitHub (pinned to 2a001d466f)
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
Example fix
// before
db, _ := badger.OpenManaged(opt)
seq, _ := db.GetSequence([]byte("k"), 100) // panics
// after
db, _ := badger.Open(opt) // non-managed
seq, _ := db.GetSequence([]byte("k"), 100) Defensive patterns
Strategy: validation
Validate before calling
if db.opt.managedTxns { return errors.New("GetSequence unavailable in managed mode") } Try / catch
defer func() {
if r := recover(); r != nil {
if strings.Contains(fmt.Sprint(r), "GetSequence with managedDB") { /* fallback counter */ }
}
}() Prevention
- 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
When it happens
Trigger: Calling db.GetSequence(key, bandwidth) on a DB opened via OpenManaged (or Options with managed txn mode).
Common situations: Mixing OpenManaged (used with Dgraph or manual timestamp control) with application-level sequence generation.
Related errors
- Cannot use GetSequence in read-only mode.
- ErrManagedTxn
- ErrZeroBandwidth
- BlockCacheSize should be set since compression/encryption ar
- Cannot flatten in read-only mode.
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/868efd3d678ae5ba.
Report an issue: GitHub.