Skip to content

Commit

Permalink
dl: don't close roSnapshots objects while files download (erigontec…
Browse files Browse the repository at this point in the history
  • Loading branch information
AskAlexSharov authored Jul 31, 2024
1 parent 9cf1b2a commit 14c5d26
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 36 deletions.
13 changes: 0 additions & 13 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,6 @@ func TruncateCanonicalHash(tx kv.RwTx, blockFrom uint64, markChainAsBad bool) er
return nil
}

// IsCanonicalHashDeprecated determines whether a header with the given hash is on the canonical chain.
func IsCanonicalHashDeprecated(db kv.Getter, hash common.Hash) (bool, *uint64, error) {
number := ReadHeaderNumber(db, hash)
if number == nil {
return false, nil, nil
}
canonicalHash, err := ReadCanonicalHash(db, *number)
if err != nil {
return false, nil, err
}
return canonicalHash != (common.Hash{}) && canonicalHash == hash, number, nil
}

func IsCanonicalHash(db kv.Getter, hash common.Hash, number uint64) (bool, error) {
canonicalHash, err := ReadCanonicalHash(db, number)
if err != nil {
Expand Down
22 changes: 13 additions & 9 deletions turbo/snapshotsync/freezeblocks/block_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,13 +436,15 @@ func (s *RoSnapshots) idxAvailability() uint64 {
// - user must be able: delete any snapshot file and Erigon will self-heal by re-downloading
// - RPC return Nil for historical blocks if snapshots are not open
func (s *RoSnapshots) OptimisticReopenWithDB(db kv.RoDB) {
_ = db.View(context.Background(), func(tx kv.Tx) error {
snList, _, err := rawdb.ReadSnapshots(tx)
var snList []string
_ = db.View(context.Background(), func(tx kv.Tx) (err error) {
snList, _, err = rawdb.ReadSnapshots(tx)
if err != nil {
return err
}
return s.ReopenList(snList, true)
return nil
})
_ = s.ReopenList(snList, true)
}

func (s *RoSnapshots) LS() {
Expand Down Expand Up @@ -484,6 +486,8 @@ func (s *RoSnapshots) Files() (list []string) {
}

func (s *RoSnapshots) OpenFiles() (list []string) {
log.Warn("[dbg] OpenFiles")
defer log.Warn("[dbg] OpenFiles end")
s.segments.Scan(func(segtype snaptype.Enum, value *segments) bool {
value.lock.RLock()
defer value.lock.RUnlock()
Expand Down Expand Up @@ -2068,7 +2072,7 @@ func (m *Merger) filesByRange(snapshots *RoSnapshots, from, to uint64) (map[snap
func (m *Merger) filesByRangeOfType(view *View, from, to uint64, snapshotType snaptype.Type) []string {
paths := make([]string, 0)

for _, sn := range view.Segments(snapshotType) {
for _, sn := range view.segments(snapshotType) {
if sn.from < from {
continue
}
Expand Down Expand Up @@ -2305,16 +2309,16 @@ func (s *RoSnapshots) ViewSingleFile(t snaptype.Type, blockNum uint64) (segment
return nil, false, noop
}

func (v *View) Segments(t snaptype.Type) []*Segment {
func (v *View) segments(t snaptype.Type) []*Segment {
if s, ok := v.s.segments.Get(t.Enum()); ok {
return s.segments
}
return nil
}

func (v *View) Headers() []*Segment { return v.Segments(coresnaptype.Headers) }
func (v *View) Bodies() []*Segment { return v.Segments(coresnaptype.Bodies) }
func (v *View) Txs() []*Segment { return v.Segments(coresnaptype.Transactions) }
func (v *View) Headers() []*Segment { return v.segments(coresnaptype.Headers) }
func (v *View) Bodies() []*Segment { return v.segments(coresnaptype.Bodies) }
func (v *View) Txs() []*Segment { return v.segments(coresnaptype.Transactions) }

func (v *View) Segment(t snaptype.Type, blockNum uint64) (*Segment, bool) {
if s, ok := v.s.segments.Get(t.Enum()); ok {
Expand All @@ -2329,7 +2333,7 @@ func (v *View) Segment(t snaptype.Type, blockNum uint64) (*Segment, bool) {
}

func (v *View) Ranges() (ranges []Range) {
for _, sn := range v.Segments(v.baseSegType) {
for _, sn := range v.segments(v.baseSegType) {
ranges = append(ranges, sn.Range)
}

Expand Down
8 changes: 4 additions & 4 deletions turbo/snapshotsync/freezeblocks/bor_snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,10 @@ func (v *BorView) Close() {
v.base.Close()
}

func (v *BorView) Events() []*Segment { return v.base.Segments(borsnaptype.BorEvents) }
func (v *BorView) Spans() []*Segment { return v.base.Segments(borsnaptype.BorSpans) }
func (v *BorView) Checkpoints() []*Segment { return v.base.Segments(borsnaptype.BorCheckpoints) }
func (v *BorView) Milestones() []*Segment { return v.base.Segments(borsnaptype.BorMilestones) }
func (v *BorView) Events() []*Segment { return v.base.segments(borsnaptype.BorEvents) }
func (v *BorView) Spans() []*Segment { return v.base.segments(borsnaptype.BorSpans) }
func (v *BorView) Checkpoints() []*Segment { return v.base.segments(borsnaptype.BorCheckpoints) }
func (v *BorView) Milestones() []*Segment { return v.base.segments(borsnaptype.BorMilestones) }

func (v *BorView) EventsSegment(blockNum uint64) (*Segment, bool) {
return v.base.Segment(borsnaptype.BorEvents, blockNum)
Expand Down
10 changes: 0 additions & 10 deletions turbo/snapshotsync/snapshotsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,6 @@ func WaitForDownloader(ctx context.Context, logPrefix string, headerchain, blobs
return nil
}

if headerchain {
snapshots.Close()
if cc.Bor != nil {
borSnapshots.Close()
}
}

//Corner cases:
// - Erigon generated file X with hash H1. User upgraded Erigon. New version has preverified file X with hash H2. Must ignore H2 (don't send to Downloader)
// - Erigon "download once": means restart/upgrade/downgrade must not download files (and will be fast)
Expand Down Expand Up @@ -357,9 +350,6 @@ func WaitForDownloader(ctx context.Context, logPrefix string, headerchain, blobs

}

// TODO: https://github.com/erigontech/erigon/issues/11271
time.Sleep(10 * time.Second)

downloadStartTime := time.Now()
const logInterval = 20 * time.Second
logEvery := time.NewTicker(logInterval)
Expand Down

0 comments on commit 14c5d26

Please sign in to comment.