dgraph-io/badger · error
errTruncate
errTruncate
Error message
Do truncate
What it means
errTruncate is a sentinel error meaning a value-log entry header or checksum was invalid in a way that requires truncating the corrupt tail of the file. It is returned by header parsing (e.g. when a key length exceeds uint16, an impossible value) and consumed by the memtable replay loop, which breaks out of the loop on errTruncate or io.ErrUnexpectedEOF so replay can proceed with the intact prefix of the log. It signals corruption of the value log tail, commonly after an unclean shutdown mid-write.
Source
Thrown at value.go:57
bitValuePointer byte = 1 << 1 // Set if the value is NOT stored directly next to key.
bitDiscardEarlierVersions byte = 1 << 2 // Set if earlier versions can be discarded.
// Set if item shouldn't be discarded via compactions (used by merge operator)
bitMergeEntry byte = 1 << 3
// The MSB 2 bits are for transactions.
bitTxn byte = 1 << 6 // Set if the entry is part of a txn.
bitFinTxn byte = 1 << 7 // Set if the entry is to indicate end of txn in value log.
mi int64 = 1 << 20 //nolint:unused
// size of vlog header.
// +----------------+------------------+
// | keyID(8 bytes) | baseIV(12 bytes)|
// +----------------+------------------+
vlogHeaderSize = 20
)
var errStop = errors.New("Stop iteration")
var errTruncate = errors.New("Do truncate")
type logEntry func(e Entry, vp valuePointer) error
type safeRead struct {
k []byte
v []byte
recordOffset uint32
lf *logFile
}
// hashReader implements io.Reader, io.ByteReader interfaces. It also keeps track of the number
// bytes read. The hashReader writes to h (hash) what it reads from r.
type hashReader struct {
r io.Reader
h hash.Hash32
bytesRead int // Number of bytes read.
}View on GitHub (pinned to 2a001d466f)
Solutions
- Let the existing replay path handle it: the read loop stops at errTruncate and Badger's truncate logic (opt value log truncation) discards the corrupt tail on open
- Reopen with the value-log-replay/truncate option enabled so the damaged tail is removed automatically
- If the error persists, back up the .vlog files and follow the Badger troubleshooting docs for value log corruption
- Investigate the cause — power loss, killed process, or disk faults — to avoid repeated corruption
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at value.go:57 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of dgraph-io/badger@2a001d466f (2026-09-05).
Data as JSON: /api/errors/0466aca4b0c3c414.
Report an issue: GitHub.