{"record":{"id":"aa6648f1cf71e976","repo":"hyperledger/fabric","slug":"no-namespace-or-key-is-found-for-namespace-s-and","errorCode":null,"errorMessage":"no namespace or key is found for namespace %s and key %s with decoded blockNum %d and tranNum %d","messagePattern":"no namespace or key is found for namespace (.+?) and key (.+?) with decoded blockNum (.+?) and tranNum (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"core/ledger/kvledger/history/query_executer.go","lineNumber":84,"sourceCode":"\t}\n\tlogger.Debugf(\"Found history record for namespace:%s key:%s at blockNumTranNum %v:%v\\n\",\n\t\tscanner.namespace, scanner.key, blockNum, tranNum)\n\n\t// Get the transaction from block storage that is associated with this history record\n\ttranEnvelope, err := scanner.blockStore.RetrieveTxByBlockNumTranNum(blockNum, tranNum)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\t// Get the txid, key write value, timestamp, and delete indicator associated with this transaction\n\tqueryResult, err := getKeyModificationFromTran(tranEnvelope, scanner.namespace, scanner.key)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tif queryResult == nil {\n\t\t// should not happen, but make sure there is inconsistency between historydb and statedb\n\t\tlogger.Errorf(\"No namespace or key is found for namespace %s and key %s with decoded blockNum %d and tranNum %d\", scanner.namespace, scanner.key, blockNum, tranNum)\n\t\treturn nil, errors.Errorf(\"no namespace or key is found for namespace %s and key %s with decoded blockNum %d and tranNum %d\", scanner.namespace, scanner.key, blockNum, tranNum)\n\t}\n\tlogger.Debugf(\"Found historic key value for namespace:%s key:%s from transaction %s\",\n\t\tscanner.namespace, scanner.key, queryResult.(*queryresult.KeyModification).TxId)\n\treturn queryResult, nil\n}\n\nfunc (scanner *historyScanner) Close() {\n\tscanner.dbItr.Release()\n}\n\n// getKeyModificationFromTran inspects a transaction for writes to a given key\nfunc getKeyModificationFromTran(tranEnvelope *common.Envelope, namespace string, key string) (commonledger.QueryResult, error) {\n\tlogger.Debugf(\"Entering getKeyModificationFromTran %s:%s\", namespace, key)\n\n\t// extract action from the envelope\n\tpayload, err := protoutil.UnmarshalPayload(tranEnvelope.Payload)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/ledger/kvledger/history/query_executer.go#L66-L102","documentation":"The history query scanner looked up the statedb value for a historical (namespace, key, blockNum, tranNum) recorded in the history DB, and got no result. This signals inconsistency between historydb and statedb — the history index references a version that no longer exists in state.","triggerScenarios":"Next() on a QueryResultsIterator fetches the value at a recorded block/tran number via queryExecuter and the state DB returns nil — history entries pointing at pruned/rebuilt state, or DBs out of sync.","commonSituations":"State DB rebuilt (e.g. peer node rebuild-dbs) while the history DB kept old entries; LevelDB/CouchDB corruption or partial deletes; history db and state db diverged after failed writes or manual data surgery.","solutions":["Rebuild both state and history DBs together (peer node rebuild-dbs) so they share a consistent version baseline","Restore the peer's ledger data from snapshot or resync from the blockchain to repair the diverged DBs","Check for failed/partial writes (disk issues) that dropped the state entry while keeping history","Identify the mismatched key and confirm via block replay whether the state entry was lost"],"exampleFix":"# before\npeer node rebuild-dbs  # only state rebuilt, history stale\n# after\n# rebuild state AND history together, or wipe both:\nrm -rf ledgersData/stateLeveldb ledgersData/historyLeveldb\npeer node start  # both DBs replay from blockchain consistently","handlingStrategy":"try-catch","validationCode":"// before iterating history, verify the key exists in state at all\n_, err := statedb.GetState(namespace, key)\nif err != nil {\n    return fmt.Errorf(\"state unavailable for history query: %w\", err)\n}","typeGuard":"func hasStateEntry(qe queryExecuter, ns, key string) bool {\n    v, err := qe.getState(ns, key)\n    return err == nil && v != nil\n}","tryCatchPattern":"for scanner.Next() {\n    result, err := scanner.Next()\n    if err != nil {\n        if strings.Contains(err.Error(), \"no namespace or key is found\") {\n            // history/state mismatch: stop iterating, trigger ledger rebuild\n            return nil, ErrHistoryStateInconsistent\n        }\n        return err\n    }\n}","preventionTips":["Always rebuild state AND history DBs together (peer node rebuild-dbs)","Never delete or hand-edit one DB without the other","Monitor for unclean shutdowns and verify DB integrity afterwards","Restore diverged ledgers from snapshot/blockchain replay"],"tags":["fabric","historydb","statedb","data-inconsistency"],"backgroundTag":"history-state-mismatch","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"}