dgraph-io/badger · error

Empty value: %+v

Error message

Empty value: %+v

What it means

This error is thrown during a value-log read (value.go:218) when the LSM tree says the key is still present (not discarded) but the returned ValueStruct carries a zero-length value, which should be impossible for a vlog-backed entry. It means the on-disk metadata pointing into the value log is inconsistent or truncated, so the read cannot return valid data.

Source

Thrown at value.go:218

		if count%100000 == 0 {
			vlog.opt.Debugf("Processing entry %d", count)
		}

		if isDeletedOrExpired(e.meta, e.ExpiresAt) {
			return nil
		}

		vs, err := vlog.db.get(e.Key)
		if err != nil {
			return err
		}
		if discardEntry(e, vs, vlog.db) {
			return nil
		}

		// Value is still present in value log.
		if len(vs.Value) == 0 {
			return fmt.Errorf("Empty value: %+v", vs)
		}
		var vp valuePointer
		vp.Decode(vs.Value)

		// If the entry found from the LSM Tree points to a newer vlog file, don't do anything.
		if vp.Fid > f.fid {
			return nil
		}
		// If the entry found from the LSM Tree points to an offset greater than the one
		// read from vlog, don't do anything.
		if vp.Offset > e.offset {
			return nil
		}
		// If the entry read from LSM Tree and vlog file point to the same vlog file and offset,
		// insert them back into the DB.
		// NOTE: It might be possible that the entry read from the LSM Tree points to
		// an older vlog file. See the comments in the else part.
		if vp.Fid == f.fid && vp.Offset == e.offset {

View on GitHub (pinned to 2a001d466f)

Solutions

  1. Restore the data files from a known-good backup (LSM tree and .vlog files must come from the same snapshot).
  2. Run badger StreamView/iterator to salvage readable keys, or use the badger 'db.ReplayValueLog' style recovery tooling for the affected vlog file.
  3. Check whether value log files were truncated (compare sizes against value pointers); truncate/repair the offending .vlog with the badger repair tool if available.
  4. If data is disposable, delete the affected .vlog files and let badger GC/rebuild, accepting loss of values still only in the vlog.
  5. Verify the same badger library version is used for writing and reading the data directory.

Example fix

// before: copying DB dir partially
$ cp dbdir/MANIFEST dbdir/KEYREGISTRY dbdir/*.sst /backup/
// after: copy everything atomically (LSM + value log together)
$ badger backup --dir dbdir -f backup.bak
# or stop writes and copy the entire dbdir including *.vlog files
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: verify the data directory is complete and consistent before opening
func checkVlogIntegrity(dir string) error {
    matches, err := filepath.Glob(filepath.Join(dir, "*.vlog"))
    if err != nil || len(matches) == 0 { return fmt.Errorf("no vlog files in %s", dir) }
    for _, m := range matches {
        fi, err := os.Stat(m)
        if err != nil || fi.Size() < 20 { return fmt.Errorf("vlog file %s missing or truncated", m) }
    }
    return nil
}

Type guard

func isEmptyValue(vs badger.ValueStruct) bool { return len(vs.Value) == 0 } // treat as corruption signal, not empty data

Try / catch

err := db.View(func(txn *badger.Txn) error {
    item, err := txn.Get(key)
    if err != nil { return err }
    return item.Value(func(v []byte) error {
        if len(v) == 0 { return fmt.Errorf("corrupt empty value for key %q", key) }
        return process(v)
    })
})
if err != nil {
    // fall back to backup/restore path; do not blind-retry
    restoreFromBackup(dbDir)
}

Prevention

When it happens

Trigger: Calling db.Get()/Txn.Get() on a key whose entry in the LSM points to the value log while vs.Value is empty; happens when value-log data was truncated/corrupted (e.g. crash without sync, partial file copy, badger.ValueLogMode misuse) or LSM/vlog files got out of sync.

Common situations: Restoring a database by copying only some files (LSM without vlog or vice versa), disk corruption or truncation after power loss, running an older badger version against data written by a newer one, manual deletion of .vlog files.

Related errors


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