dgraph-io/badger · critical

While setting banned keys: %w

Error message

While setting banned keys: %w

What it means

During Open, badger initializes banned namespaces (reserved key prefixes) from disk. If that step fails, Open wraps the underlying error with "While setting banned keys: %w", meaning the DB could not be set up safely and startup is aborted.

Source

Thrown at db.go:394

	db.orc.nextTxnTs = db.MaxVersion()
	db.opt.Infof("Set nextTxnTs to %d", db.orc.nextTxnTs)

	if err = db.vlog.open(db); err != nil {
		return db, y.Wrapf(err, "During db.vlog.open")
	}

	// Let's advance nextTxnTs to one more than whatever we observed via
	// replaying the logs.
	db.orc.txnMark.Done(db.orc.nextTxnTs)
	// In normal mode, we must update readMark so older versions of keys can be removed during
	// compaction when run in offline mode via the flatten tool.
	db.orc.readMark.Done(db.orc.nextTxnTs)
	db.orc.incrementNextTs()

	go db.threshold.listenForValueThresholdUpdate()

	if err := db.initBannedNamespaces(); err != nil {
		return db, fmt.Errorf("While setting banned keys: %w", err)
	}

	db.closers.writes = z.NewCloser(1)
	go db.doWrites(db.closers.writes)

	if !db.opt.InMemory && !db.opt.ReadOnly {
		db.closers.valueGC = z.NewCloser(1)
		go db.vlog.waitOnGC(db.closers.valueGC)
	}

	db.closers.pub = z.NewCloser(1)
	go db.pub.listenForUpdates(db.closers.pub)

	valueDirLockGuard = nil
	dirLockGuard = nil
	manifestFile = nil
	return db, nil
}

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Inspect the wrapped error (%w) for the root cause (permissions vs corruption)
  2. Fix permissions so the DB user can read/write the data directory
  3. Restore from backup if internal files are corrupted
  4. If the directory is disposable, remove it and reopen to start fresh

Example fix

// before
db, err := badger.Open(opt) // err: While setting banned keys: ...
// after
if err != nil {
    if os.IsPermission(errors.Unwrap(err)) { fixPermissions(dir) }
    return err // or restore from backup
}
Defensive patterns

Strategy: try-catch

Validate before calling

if fi, err := os.Stat(dir); err != nil || !fi.IsDir() {
    return fmt.Errorf("badger dir unreadable: %w", err)
}

Try / catch

db, err := badger.Open(opt)
if err != nil {
    var pe *fs.PathError
    if errors.As(err, &pe) { /* fix perms/path */ }
    log.Fatalf("open failed: %v", err) // inspect errors.Unwrap
}

Prevention

When it happens

Trigger: Calling badger.Open on a directory whose key-registry/banned-namespace files are unreadable, corrupted, or not writable during initBannedNamespaces().

Common situations: Corrupted or partially deleted DB directory; permission problems on the data dir; restoring a directory missing internal files; disk I/O failures.

Related errors


AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05). Data as JSON: /api/errors/105a8707a6aff8c8. Report an issue: GitHub.