diff --git a/state/history.go b/state/history.go index 3e03e382816..bed7d0bcd3b 100644 --- a/state/history.go +++ b/state/history.go @@ -565,8 +565,6 @@ func (hc *HistoryContext) GetNoState(key []byte, txNum uint64) ([]byte, bool, ui return true }) if found { - var txKey [8]byte - binary.BigEndian.PutUint64(txKey[:], foundTxNum) var historyItem *ctxItem var ok bool var search ctxItem @@ -575,6 +573,8 @@ func (hc *HistoryContext) GetNoState(key []byte, txNum uint64) ([]byte, bool, ui if historyItem, ok = hc.historyFiles.Get(&search); !ok { return nil, false, 0, fmt.Errorf("no %s file found for [%x]", hc.h.filenameBase, key) } + var txKey [8]byte + binary.BigEndian.PutUint64(txKey[:], foundTxNum) offset := historyItem.reader.Lookup2(txKey[:], key) //fmt.Printf("offset = %d, txKey=[%x], key=[%x]\n", offset, txKey[:], key) g := historyItem.getter diff --git a/state/inverted_index.go b/state/inverted_index.go index f902aebf6af..96acc595348 100644 --- a/state/inverted_index.go +++ b/state/inverted_index.go @@ -46,6 +46,7 @@ type InvertedIndex struct { indexTable string // Needs to be table with DupSort tx kv.RwTx txNum uint64 + txNumBytes [8]byte files *btree.BTreeG[*filesItem] } @@ -121,6 +122,7 @@ func (ii *InvertedIndex) openFiles() error { ii.files.Ascend(func(item *filesItem) bool { datPath := filepath.Join(ii.dir, fmt.Sprintf("%s.%d-%d.ef", ii.filenameBase, item.startTxNum/ii.aggregationStep, item.endTxNum/ii.aggregationStep)) if item.decompressor, err = compress.NewDecompressor(datPath); err != nil { + log.Debug("InvertedIndex.openFiles: %w, %s", err, datPath) return false } idxPath := filepath.Join(ii.dir, fmt.Sprintf("%s.%d-%d.efi", ii.filenameBase, item.startTxNum/ii.aggregationStep, item.endTxNum/ii.aggregationStep)) @@ -130,6 +132,7 @@ func (ii *InvertedIndex) openFiles() error { } } if item.index, err = recsplit.OpenIndex(idxPath); err != nil { + log.Debug("InvertedIndex.openFiles: %w, %s", err, datPath) return false } totalKeys += item.index.KeyCount() @@ -163,15 +166,14 @@ func (ii *InvertedIndex) SetTx(tx kv.RwTx) { func (ii *InvertedIndex) SetTxNum(txNum uint64) { ii.txNum = txNum + binary.BigEndian.PutUint64(ii.txNumBytes[:], ii.txNum) } func (ii *InvertedIndex) add(key, indexKey []byte) error { - var txKey [8]byte - binary.BigEndian.PutUint64(txKey[:], ii.txNum) - if err := ii.tx.Put(ii.indexKeysTable, txKey[:], key); err != nil { + if err := ii.tx.Put(ii.indexKeysTable, ii.txNumBytes[:], key); err != nil { return err } - if err := ii.tx.Put(ii.indexTable, indexKey, txKey[:]); err != nil { + if err := ii.tx.Put(ii.indexTable, indexKey, ii.txNumBytes[:]); err != nil { return err } return nil @@ -258,6 +260,10 @@ func (it *InvertedIterator) advanceInDb() { } } else { _, v, err = it.cursor.NextDup() + if err != nil { + // TODO pass error properly around + panic(err) + } } for ; err == nil && v != nil; _, v, err = it.cursor.NextDup() { n := binary.BigEndian.Uint64(v)