From 9e7f22667e5549a05638916aab352540bba2082c Mon Sep 17 00:00:00 2001 From: ledgerwatch Date: Wed, 6 Jul 2022 06:42:40 +0100 Subject: [PATCH] [erigon2.2] FinishTx to aggregate with delay (to avoid MDBX panic) (#513) * Add temporary table for Plain state reconstitution * Add 2 more temp tables * FinishTx with delay * Fix search in history Co-authored-by: Alexey Sharp --- state/aggregator.go | 4 ++++ state/state_recon.go | 8 +++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/state/aggregator.go b/state/aggregator.go index 180ca935a..e0e3bda64 100644 --- a/state/aggregator.go +++ b/state/aggregator.go @@ -681,6 +681,10 @@ func (a *Aggregator) FinishTx() error { } closeAll := true step := a.txNum / a.aggregationStep + if step == 0 { + return nil + } + step-- // Leave one step worth in the DB collation, err := a.collate(step, step*a.aggregationStep, (step+1)*a.aggregationStep, a.rwTx) if err != nil { return err diff --git a/state/state_recon.go b/state/state_recon.go index 0c83c436b..816804b57 100644 --- a/state/state_recon.go +++ b/state/state_recon.go @@ -58,21 +58,17 @@ func (d *Domain) MakeContext() *DomainContext { } func (dc *DomainContext) GetNoState(key []byte, txNum uint64) ([]byte, bool, uint64, error) { - var search filesItem - search.startTxNum = txNum - search.endTxNum = txNum var foundTxNum uint64 var foundEndTxNum uint64 var foundStartTxNum uint64 var found bool var anyItem bool var maxTxNum uint64 - dc.files[EfHistory].AscendGreaterOrEqual(&search, func(i btree.Item) bool { + dc.files[EfHistory].Ascend(func(i btree.Item) bool { item := i.(*filesItem) if item.index.Empty() { return true } - anyItem = true offset := item.indexReader.Lookup(key) g := item.getter g.Reset(offset) @@ -88,6 +84,7 @@ func (dc *DomainContext) GetNoState(key []byte, txNum uint64) ([]byte, bool, uin } else { maxTxNum = ef.Max() } + anyItem = true } return true }) @@ -95,6 +92,7 @@ func (dc *DomainContext) GetNoState(key []byte, txNum uint64) ([]byte, bool, uin var txKey [8]byte binary.BigEndian.PutUint64(txKey[:], foundTxNum) var historyItem *filesItem + var search filesItem search.startTxNum = foundStartTxNum search.endTxNum = foundEndTxNum if i := dc.files[History].Get(&search); i != nil {