hyperledger/fabric · critical
Could not truncate current file to known size in db: %s
Error message
Could not truncate current file to known size in db: %s
What it means
Panic when currentFileWriter.truncateFile cannot truncate the current block file to latestFileSize recorded in the DB checkpoint, ensuring the file length matches committed data. A mismatch means uncommitted bytes from a crash would be appended to, so startup aborts.
Source
Thrown at common/ledger/blkstorage/blockfile_mgr.go:129
panic(fmt.Sprintf("Could not build blockfilesInfo info from block files: %s", err))
}
logger.Debugf("Info constructed by scanning the blocks dir = %s", spew.Sdump(blockfilesInfo))
} else {
logger.Debug(`Syncing block information from block storage (if needed)`)
syncBlockfilesInfoFromFS(rootDir, blockfilesInfo)
}
err = mgr.saveBlkfilesInfo(blockfilesInfo, true)
if err != nil {
panic(fmt.Sprintf("Could not save next block file info to db: %s", err))
}
currentFileWriter, err := newBlockfileWriter(deriveBlockfilePath(rootDir, blockfilesInfo.latestFileNumber))
if err != nil {
panic(fmt.Sprintf("Could not open writer to current file: %s", err))
}
err = currentFileWriter.truncateFile(blockfilesInfo.latestFileSize)
if err != nil {
panic(fmt.Sprintf("Could not truncate current file to known size in db: %s", err))
}
if mgr.index, err = newBlockIndex(indexConfig, indexStore); err != nil {
panic(fmt.Sprintf("error in block index: %s", err))
}
mgr.blockfilesInfo = blockfilesInfo
bsi, err := loadBootstrappingSnapshotInfo(rootDir)
if err != nil {
return nil, err
}
mgr.bootstrappingSnapshotInfo = bsi
mgr.currentFileWriter = currentFileWriter
mgr.blkfilesInfoCond = sync.NewCond(&sync.Mutex{})
if err := mgr.syncIndex(); err != nil {
return nil, err
}
View on GitHub (pinned to 2736b63f8f)
Solutions
- Restore the block files to match the index DB checkpoint (same backup) so the recorded latestFileSize is valid
- If the FS is the source of truth, reset/sync the index DB (delete index so the peer rescans with constructBlockfilesInfo)
- Fix permissions and filesystem health, then restart the peer
Example fix
// before: restoring chains files from an older backup than the index DB // after: restore both dirs atomically from one snapshot // systemctl stop peer && rsync -a snapshot/ledgersData/ ledgersData/ && systemctl start peer
Defensive patterns
Strategy: validation
Validate before calling
fi, err := os.Stat(deriveBlockfilePath(rootDir, latestFileNumber))
if err != nil { return err }
if fi.Size() < recordedLatestFileSize {
return fmt.Errorf("block file %d smaller (%d) than db checkpoint (%d)", latestFileNumber, fi.Size(), recordedLatestFileSize)
} Try / catch
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("truncate to checkpoint size failed: %v", r)
}
}() Prevention
- Restore index DB and block files from the same backup point
- Take backups only when the peer is stopped
- Keep block files writable by the peer user
- Monitor storage for I/O errors
When it happens
Trigger: truncateFile fails (I/O error, permission denied, file shorter/absent, read-only fs) aligning the block file to blockfilesInfo.latestFileSize in newBlockfileMgr.
Common situations: Block file missing or shrunk after a partial restore/backup mismatch (DB says file is 50MB, FS has 10MB); disk errors; permission issues on the chains dir.
Related errors
- Error in decoding varint bytes [%#v]
- error retrieving file info for file number %d
- Error creating block storage root dir [%s]: %s
- Could not get block file info for current block file from db
- Could not build blockfilesInfo info from block files: %s
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/884e1093a570fbb1.
Report an issue: GitHub.