dgraph-io/badger · error
ErrBannedKey
ErrBannedKey
Error message
Key is using the banned prefix
What it means
ErrBannedKey is returned when a read/write key belongs to a banned namespace. When WithNamespaceOffset is configured, the uint64 namespace extracted at that offset is checked against db.bannedNamespaces (db.go:1945) and banned namespaces are rejected on both reads and writes.
Source
Thrown at errors.go:47
// ErrConflict is returned when a transaction conflicts with another transaction. This can
// happen if the read rows had been updated concurrently by another transaction.
ErrConflict = stderrors.New("Transaction Conflict. Please retry")
// ErrReadOnlyTxn is returned if an update function is called on a read-only transaction.
ErrReadOnlyTxn = stderrors.New("No sets or deletes are allowed in a read-only transaction")
// ErrDiscardedTxn is returned if a previously discarded transaction is reused.
ErrDiscardedTxn = stderrors.New("This transaction has been discarded. Create a new one")
// ErrEmptyKey is returned if an empty key is passed on an update function.
ErrEmptyKey = stderrors.New("Key cannot be empty")
// ErrInvalidKey is returned if the key has a special !badger! prefix,
// reserved for internal usage.
ErrInvalidKey = stderrors.New("Key is using a reserved !badger! prefix")
// ErrBannedKey is returned if the read/write key belongs to any banned namespace.
ErrBannedKey = stderrors.New("Key is using the banned prefix")
// ErrThresholdZero is returned if threshold is set to zero, and value log GC is called.
// In such a case, GC can't be run.
ErrThresholdZero = stderrors.New(
"Value log GC can't run because threshold is set to zero")
// ErrNoRewrite is returned if a call for value log GC doesn't result in a log file rewrite.
ErrNoRewrite = stderrors.New(
"Value log GC attempt didn't result in any cleanup")
// ErrRejected is returned if a value log GC is called either while another GC is running, or
// after DB::Close has been called.
ErrRejected = stderrors.New("Value log GC request rejected")
// ErrInvalidRequest is returned if the user request is invalid.
ErrInvalidRequest = stderrors.New("Invalid request")
// ErrManagedTxn is returned if the user tries to use an API which isn'tView on GitHub (pinned to 2a001d466f)
Solutions
- Stop issuing keys for banned namespaces in the application layer
- Remove the namespace from the banned list with SetBannedNamespaces if the ban was unintended
- Ensure keys are at least NamespaceOffset+8 bytes long so the namespace is read correctly
Example fix
// before
key := makeTenantKey(tenantID, k) // tenantID may be banned
rerr := txn.Get(key) // ErrBannedKey
// after
if banned[tenantID] {
return fmt.Errorf("tenant %d is banned", tenantID)
}
rerr := txn.Get(makeTenantKey(tenantID, k)) Defensive patterns
Strategy: validation
Validate before calling
if len(key) < db.opt.NamespaceOffset+8 {
return errors.New("key too short to carry namespace")
}
ns := binary.BigEndian.Uint64(key[db.opt.NamespaceOffset:])
if banned.Has(ns) {
return fmt.Errorf("namespace %d is banned", ns)
} Try / catch
if _, err := txn.Get(key); err != nil {
if errors.Is(err, badger.ErrBannedKey) {
return ErrTenantBlocked
}
return err
} Prevention
- Check the banned-namespace set in the application before touching the DB
- Keep keys long enough for NamespaceOffset + 8 bytes
- Coordinate bans between ops tooling and application config
When it happens
Trigger: Any Set/Get/Delete whose key, at opt.NamespaceOffset, encodes a namespace previously registered via db.SetBannedNamespaces; keys shorter than NamespaceOffset+8 may also misbehave in that check.
Common situations: Multi-tenant setups banning a tenant's namespace (e.g. after abuse or data deletion) while old application code still sends that tenant's keys.
Related errors
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/27822da52984e993.
Report an issue: GitHub.