Skip to content

Commit

Permalink
e3: indices wal - to reuse etl collector (erigontech#6757)
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Feb 1, 2023
1 parent 8c0774f commit dfca60c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion core/state/recon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (rs *ReconState) Get(table string, key1, key2 []byte, txNum uint64) []byte
if !ok {
return nil
}
i, ok := t.GetHint(reconPair{txNum: txNum, key1: key1, key2: key2}, rs.hints[table])
i, ok := t.Get(reconPair{txNum: txNum, key1: key1, key2: key2})
if !ok {
return nil
}
Expand Down
12 changes: 8 additions & 4 deletions eth/stagedsync/exec3.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,11 +789,10 @@ func reconstituteStep(last bool,
chainConfig *chain.Config, logger log.Logger, genesis *core.Genesis, engine consensus.Engine,
batchSize datasize.ByteSize, s *StageState, blockNum uint64, total uint64,
) error {
var err error
var startOk, endOk bool
startTxNum, endTxNum := as.TxNumRange()
var startBlockNum, endBlockNum uint64 // First block which is not covered by the history snapshot files
if err := chainDb.View(ctx, func(tx kv.Tx) error {
if err := chainDb.View(ctx, func(tx kv.Tx) (err error) {
startOk, startBlockNum, err = rawdbv3.TxNums.FindBlockNum(tx, startTxNum)
if err != nil {
return err
Expand Down Expand Up @@ -870,6 +869,7 @@ func reconstituteStep(last bool,
}
}()
for i := 0; i < workerCount; i++ {
var err error
if roTxs[i], err = db.BeginRo(ctx); err != nil {
return err
}
Expand Down Expand Up @@ -933,21 +933,22 @@ func reconstituteStep(last bool,
"alloc", common.ByteCount(m.Alloc), "sys", common.ByteCount(m.Sys))
if sizeEstimate >= commitThreshold {
t := time.Now()
if err = func() error {
if err := func() error {
lock.Lock()
defer lock.Unlock()
for i := 0; i < workerCount; i++ {
roTxs[i].Rollback()
}
if err := db.Update(ctx, func(tx kv.RwTx) error {
if err = rs.Flush(tx); err != nil {
if err := rs.Flush(tx); err != nil {
return err
}
return nil
}); err != nil {
return err
}
for i := 0; i < workerCount; i++ {
var err error
if roTxs[i], err = db.BeginRo(ctx); err != nil {
return err
}
Expand All @@ -967,6 +968,7 @@ func reconstituteStep(last bool,
var b *types.Block
var txKey [8]byte
getHeaderFunc := func(hash common.Hash, number uint64) (h *types.Header) {
var err error
if err = chainDb.View(ctx, func(tx kv.Tx) error {
h, err = blockReader.Header(ctx, tx, hash, number)
if err != nil {
Expand All @@ -979,6 +981,8 @@ func reconstituteStep(last bool,
}
return h
}

var err error // avoid declare global mutable variable
for bn = startBlockNum; bn <= endBlockNum; bn++ {
t = time.Now()
b, err = blockWithSenders(chainDb, nil, blockReader, bn)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
go 1.18

require (
github.com/ledgerwatch/erigon-lib v0.0.0-20230129035339-c8e1b58da166
github.com/ledgerwatch/erigon-lib v0.0.0-20230201020413-1637be299be5
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da
github.com/ledgerwatch/log/v3 v3.7.0
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down Expand Up @@ -73,6 +73,7 @@ require (
github.com/stretchr/testify v1.8.1
github.com/tendermint/go-amino v0.14.1
github.com/tendermint/tendermint v0.31.12
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e
github.com/tidwall/btree v1.5.0
github.com/ugorji/go/codec v1.1.13
github.com/ugorji/go/codec/codecgen v1.1.13
Expand Down Expand Up @@ -229,7 +230,6 @@ require (
github.com/spacemonkeygo/spacelog v0.0.0-20180420211403-2296661a0572 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/supranational/blst v0.3.10 // indirect
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e // indirect
github.com/valyala/fastrand v1.1.0 // indirect
github.com/valyala/histogram v1.2.0 // indirect
github.com/whyrusleeping/timecache v0.0.0-20160911033111-cfcb2f1abfee // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -555,8 +555,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20230129035339-c8e1b58da166 h1:HLkAsGg52srGtDmu7phHX3/GAU25yWnimNzKKf6CSEo=
github.com/ledgerwatch/erigon-lib v0.0.0-20230129035339-c8e1b58da166/go.mod h1:I3Gbzi7rY6Q5lPvKg2/lcXT5bOTrm+p0lphDmcsAjN8=
github.com/ledgerwatch/erigon-lib v0.0.0-20230201020413-1637be299be5 h1:xhYi19wpt3bjzxsO0J5p3bVnJE0A9Zq31OiNSAZBK/Q=
github.com/ledgerwatch/erigon-lib v0.0.0-20230201020413-1637be299be5/go.mod h1:I3Gbzi7rY6Q5lPvKg2/lcXT5bOTrm+p0lphDmcsAjN8=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da h1:lQQBOHzAUThkymfXJj/m07vAjyMx9XoMMy3OomaeOrA=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230120022649-cd9409a200da/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=
Expand Down

0 comments on commit dfca60c

Please sign in to comment.