Skip to content

Commit

Permalink
seg: split segments field - on 2 fields guarded by 2 different mute…
Browse files Browse the repository at this point in the history
…xes (#12380)

FYI: Next step will be: replace `visibleMutex` by `atomic.Pointer`
  • Loading branch information
AskAlexSharov authored Oct 25, 2024
1 parent 9756fc7 commit f5b768d
Show file tree
Hide file tree
Showing 8 changed files with 443 additions and 536 deletions.
355 changes: 172 additions & 183 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"log"
"runtime"
"testing"
"time"

Expand Down Expand Up @@ -231,5 +232,8 @@ func (t *blsToExecutionChangeTestSuite) TestProcessMessage() {
}

func TestBlsToExecutionChangeTestSuite(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("fix me on win please")
}
suite.Run(t, new(blsToExecutionChangeTestSuite))
}
2 changes: 2 additions & 0 deletions erigon-lib/downloader/snaptype/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ const MinCoreEnum = 1
const MinBorEnum = 4
const MinCaplinEnum = 8

const MaxEnum = 11

var CaplinEnums = struct {
Enums
BeaconBlocks,
Expand Down
38 changes: 19 additions & 19 deletions turbo/snapshotsync/freezeblocks/block_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ func (r *BlockReader) HeaderByHash(ctx context.Context, tx kv.Getter, hash commo
defer segmentRotx.Close()

buf := make([]byte, 128)
segments := segmentRotx.VisibleSegments
segments := segmentRotx.segments
for i := len(segments) - 1; i >= 0; i-- {
h, err = r.headerFromSnapshotByHash(hash, segments[i], buf)
if err != nil {
Expand Down Expand Up @@ -851,7 +851,7 @@ func (r *BlockReader) blockWithSenders(ctx context.Context, tx kv.Getter, hash c
txnSeg, ok, release := r.sn.ViewSingleFile(coresnaptype.Transactions, blockHeight)
if !ok {
if dbgLogs {
log.Info(dbgPrefix+"no transactions file for this block num", "r.sn.BlocksAvailable()", r.sn.BlocksAvailable(), "r.sn.indicesReady", r.sn.indicesReady.Load())
log.Info(dbgPrefix+"no transactions file for this block num", "r.sn.BlocksAvailable()", r.sn.BlocksAvailable())
}
return
}
Expand Down Expand Up @@ -1170,7 +1170,7 @@ func (r *BlockReader) TxnLookup(_ context.Context, tx kv.Getter, txnHash common.

txns := r.sn.ViewType(coresnaptype.Transactions)
defer txns.Close()
_, blockNum, ok, err := r.txnByHash(txnHash, txns.VisibleSegments, nil)
_, blockNum, ok, err := r.txnByHash(txnHash, txns.segments, nil)
if err != nil {
return 0, false, err
}
Expand Down Expand Up @@ -1355,7 +1355,7 @@ func (r *BlockReader) EventLookup(ctx context.Context, tx kv.Getter, txnHash com
segs := r.borSn.ViewType(borsnaptype.BorEvents)
defer segs.Close()

blockNum, ok, err := r.borBlockByEventHash(txnHash, segs.VisibleSegments, nil)
blockNum, ok, err := r.borBlockByEventHash(txnHash, segs.segments, nil)
if err != nil {
return 0, false, err
}
Expand Down Expand Up @@ -1414,8 +1414,8 @@ func (r *BlockReader) BorStartEventID(ctx context.Context, tx kv.Tx, hash common
segments := r.borSn.ViewType(borsnaptype.BorEvents)
defer segments.Close()

for i := len(segments.VisibleSegments) - 1; i >= 0; i-- {
sn := segments.VisibleSegments[i]
for i := len(segments.segments) - 1; i >= 0; i-- {
sn := segments.segments[i]
if sn.from > blockHeight {
continue
}
Expand Down Expand Up @@ -1494,8 +1494,8 @@ func (r *BlockReader) EventsByBlock(ctx context.Context, tx kv.Tx, hash common.H

var buf []byte
result := []rlp.RawValue{}
for i := len(segments.VisibleSegments) - 1; i >= 0; i-- {
sn := segments.VisibleSegments[i]
for i := len(segments.segments) - 1; i >= 0; i-- {
sn := segments.segments[i]
if sn.from > blockHeight {
continue
}
Expand Down Expand Up @@ -1536,7 +1536,7 @@ func (r *BlockReader) EventsByIdFromSnapshot(from uint64, to time.Time, limit in
var result []*heimdall.EventRecordWithTime
maxTime := false

for _, sn := range segments.VisibleSegments {
for _, sn := range segments.segments {
idxBorTxnHash := sn.src.Index()

if idxBorTxnHash == nil || idxBorTxnHash.KeyCount() == 0 {
Expand Down Expand Up @@ -1609,12 +1609,12 @@ func (r *BlockReader) LastFrozenEventId() uint64 {
segments := r.borSn.ViewType(borsnaptype.BorEvents)
defer segments.Close()

if len(segments.VisibleSegments) == 0 {
if len(segments.segments) == 0 {
return 0
}
// find the last segment which has a built index
var lastSegment *VisibleSegment
visibleSegments := segments.VisibleSegments
visibleSegments := segments.segments
for i := len(visibleSegments) - 1; i >= 0; i-- {
if visibleSegments[i].src.Index() != nil {
gg := visibleSegments[i].src.MakeGetter()
Expand Down Expand Up @@ -1648,7 +1648,7 @@ func (r *BlockReader) LastFrozenEventBlockNum() uint64 {
segmentsRotx := r.borSn.ViewType(borsnaptype.BorEvents)
defer segmentsRotx.Close()

segments := segmentsRotx.VisibleSegments
segments := segmentsRotx.segments
if len(segments) == 0 {
return 0
}
Expand Down Expand Up @@ -1710,14 +1710,14 @@ func (r *BlockReader) LastFrozenSpanId() uint64 {
segments := r.borSn.ViewType(borsnaptype.BorSpans)
defer segments.Close()

if len(segments.VisibleSegments) == 0 {
if len(segments.segments) == 0 {
return 0
}
// find the last segment which has a built index
var lastSegment *VisibleSegment
for i := len(segments.VisibleSegments) - 1; i >= 0; i-- {
if segments.VisibleSegments[i].src.Index() != nil {
lastSegment = segments.VisibleSegments[i]
for i := len(segments.segments) - 1; i >= 0; i-- {
if segments.segments[i].src.Index() != nil {
lastSegment = segments.segments[i]
break
}
}
Expand Down Expand Up @@ -1754,7 +1754,7 @@ func (r *BlockReader) Span(ctx context.Context, tx kv.Getter, spanId uint64) ([]
segmentsRotx := r.borSn.ViewType(borsnaptype.BorSpans)
defer segmentsRotx.Close()

segments := segmentsRotx.VisibleSegments
segments := segmentsRotx.segments
for i := len(segments) - 1; i >= 0; i-- {
sn := segments[i]
idx := sn.src.Index()
Expand Down Expand Up @@ -1863,7 +1863,7 @@ func (r *BlockReader) Checkpoint(ctx context.Context, tx kv.Getter, checkpointId
segmentsRotx := r.borSn.ViewType(borsnaptype.BorCheckpoints)
defer segmentsRotx.Close()

segments := segmentsRotx.VisibleSegments
segments := segmentsRotx.segments
for i := len(segments) - 1; i >= 0; i-- {
sn := segments[i]
index := sn.src.Index()
Expand Down Expand Up @@ -1895,7 +1895,7 @@ func (r *BlockReader) LastFrozenCheckpointId() uint64 {

defer segmentsRotx.Close()

segments := segmentsRotx.VisibleSegments
segments := segmentsRotx.segments
if len(segments) == 0 {
return 0
}
Expand Down
Loading

0 comments on commit f5b768d

Please sign in to comment.