{"record":{"id":"864b9a13d1cfdf15","repo":"hyperledger/fabric","slug":"internal-leveldb-error-while-iterating-for-txids","errorCode":null,"errorMessage":"internal leveldb error while iterating for txids","messagePattern":"internal leveldb error while iterating for txids","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/ledger/blkstorage/blockindex.go","lineNumber":307,"sourceCode":"}\n\nfunc (index *blockIndex) exportUniqueTxIDs(dir string, newHashFunc snapshot.NewHashFunc) (map[string][]byte, error) {\n\tif !index.isAttributeIndexed(IndexableAttrTxID) {\n\t\treturn nil, errors.New(\"transaction IDs not maintained in index\")\n\t}\n\n\tdbItr, err := index.db.GetIterator([]byte{txIDIdxKeyPrefix}, []byte{txIDIdxKeyPrefix + 1})\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tdefer dbItr.Release()\n\n\tvar previousTxID string\n\tvar numTxIDs uint64 = 0\n\tvar dataFile *snapshot.FileWriter\n\tfor dbItr.Next() {\n\t\tif err := dbItr.Error(); err != nil {\n\t\t\treturn nil, errors.Wrap(err, \"internal leveldb error while iterating for txids\")\n\t\t}\n\t\ttxID, err := retrieveTxID(dbItr.Key())\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\t// duplicate TxID may be present in the index\n\t\tif previousTxID == txID {\n\t\t\tcontinue\n\t\t}\n\t\tpreviousTxID = txID\n\t\tif numTxIDs == 0 { // first iteration, create the data file\n\t\t\tdataFile, err = snapshot.CreateFile(filepath.Join(dir, snapshotDataFileName), snapshotFileFormat, newHashFunc)\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tdefer dataFile.Close()\n\t\t}\n\t\tif err := dataFile.EncodeString(txID); err != nil {","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/ledger/blkstorage/blockindex.go#L289-L325","documentation":"While iterating the txID index range in exportUniqueTxIDs, the LevelDB iterator returned an error (dbItr.Error() != nil). The error is wrapped as an internal leveldb iteration failure; the underlying cause is carried by the wrap.","triggerScenarios":"LevelDB underlying store corruption, I/O errors (disk full, permission issues on the index directory), or a store closed/compacting concurrently while the iterator advances during snapshot export.","commonSituations":"Disk-full or I/O failures on the peer's ledger data volume, corrupted index DB after an unclean shutdown, running snapshot export while another process deletes or repairs the index DB.","solutions":["Inspect the wrapped cause in the error chain for the actual leveldb error (I/O, corruption, closed DB).","Check disk space and filesystem health on the ledger data directory.","If the index DB is corrupted, rebuild it: stop the peer, remove the index directory, and let the peer reindex or rejoin the channel.","Retry snapshot export after the peer has fully started and no other maintenance process holds the DB."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"txIDs, err := index.exportUniqueTxIDs(dir, hashFunc)\nif err != nil {\n    var cause error\n    errors.As(err, &cause)\n    if errors.Is(cause, syscall.ENOSPC) || errors.Is(cause, syscall.EIO) {\n        return fmt.Errorf(\"storage problem during txID export: %w\", cause) // fix disk, then retry\n    }\n    return err // corruption path: rebuild index instead of retrying\n}","preventionTips":["Monitor disk free space and I/O health on the ledger data volume.","Do not run index repair/cleanup concurrently with snapshot export.","Take consistent backups only after a clean peer shutdown."],"tags":["leveldb","ledger","snapshot","io"],"backgroundTag":"leveldb-iteration-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}