Skip to content

Commit d30de09

Browse files
author
info@weblogix.biz
committed
Merge remote-tracking branch 'origin/main' into jklondon/caplintypesnotnil
2 parents a197567 + fe17d1f commit d30de09

File tree

7 files changed

+41
-32
lines changed

7 files changed

+41
-32
lines changed

db/recsplit/recsplit.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636

3737
"github.com/erigontech/erigon/common"
3838
"github.com/erigontech/erigon/common/assert"
39+
"github.com/erigontech/erigon/common/background"
3940
"github.com/erigontech/erigon/common/dir"
4041
"github.com/erigontech/erigon/common/log/v3"
4142
"github.com/erigontech/erigon/common/mmap"
@@ -164,6 +165,8 @@ type RecSplit struct {
164165

165166
noFsync bool // fsync is enabled by default, but tests can manually disable
166167
timings Timings
168+
169+
progress *background.Progress // If set, tracks 0-100%: add-keys fills 0-50%, build fills 50-100%
167170
}
168171

169172
type RecSplitArgs struct {
@@ -395,6 +398,9 @@ func (rs *RecSplit) ResetNextSalt() {
395398
rs.collision = false
396399
rs.keysAdded = 0
397400
rs.salt++
401+
if rs.progress != nil {
402+
rs.progress.Processed.Store(0)
403+
}
398404
if rs.bucketCollector != nil {
399405
rs.bucketCollector.Close()
400406
}
@@ -519,6 +525,9 @@ func (rs *RecSplit) AddKey(key []byte, offset uint64) error {
519525

520526
rs.keysAdded++
521527
rs.prevOffset = offset
528+
if rs.progress != nil && rs.keysAdded%1024 == 0 {
529+
rs.progress.Processed.Add(1024)
530+
}
522531
return nil
523532
}
524533

@@ -790,6 +799,10 @@ func (rs *RecSplit) loadFuncBucket(k, v []byte, _ etl.CurrentTableReader, _ etl.
790799
if err := rs.recsplitCurrentBucket(); err != nil {
791800
return err
792801
}
802+
if rs.progress != nil {
803+
// Build phase fills the 50–100% half: each bucket ≈ bucketSize keys worth.
804+
rs.progress.Processed.Add(uint64(rs.bucketSize))
805+
}
793806
}
794807
rs.currentBucketIdx = bucketIdx
795808
}
@@ -820,6 +833,26 @@ func (rs *RecSplit) buildOffsetEf() error {
820833
return nil
821834
}
822835

836+
// KeyCount returns the number of keys added to the RecSplit.
837+
func (rs *RecSplit) KeyCount() uint64 { return rs.keysAdded }
838+
839+
// BucketCount returns the number of buckets.
840+
func (rs *RecSplit) BucketCount() uint64 { return rs.bucketCount }
841+
842+
// SetProgress wires a single progress tracker covering the full build lifecycle.
843+
// Total = 2*keyExpectedCount; AddKey fills 0→keyExpectedCount (0–50%) and
844+
// the bucket-building phase fills keyExpectedCount→2*keyExpectedCount (50–100%).
845+
// Progress is automatically reset on ResetNextSalt (collision retry).
846+
func (rs *RecSplit) SetProgress(p *background.Progress) {
847+
if p == nil {
848+
return
849+
}
850+
p.Name.Store(&rs.fileName)
851+
p.Processed.Store(0)
852+
p.Total.Store(2 * rs.keyExpectedCount)
853+
rs.progress = p
854+
}
855+
823856
// Build has to be called after all the keys have been added, and it initiates the process
824857
// of building the perfect hash function and writing index into a file
825858
func (rs *RecSplit) Build(ctx context.Context) error {

db/snaptype/type.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,6 @@ func BuildIndex(ctx context.Context, info FileInfo, indexVersion version.Version
492492
}
493493
defer d.Close()
494494

495-
if p != nil {
496-
fname := info.Name()
497-
p.Name.Store(&fname)
498-
p.Total.Store(uint64(d.Count()))
499-
}
500495
cfg.KeyCount = d.Count()
501496
idxVer := indexVersion.Current
502497
cfg.IndexFile = filepath.Join(info.Dir(), info.Type.IdxFileName(idxVer, info.From, info.To))
@@ -515,6 +510,7 @@ func BuildIndex(ctx context.Context, info FileInfo, indexVersion version.Version
515510
defer d.MadvSequential().DisableReadAhead()
516511

517512
for {
513+
rs.SetProgress(p)
518514
g := d.MakeGetter()
519515
var i, offset, nextPos uint64
520516
word := make([]byte, 0, 4096)
@@ -560,11 +556,6 @@ func BuildIndexWithSnapName(ctx context.Context, info FileInfo, cfg recsplit.Rec
560556
}
561557
defer d.Close()
562558

563-
if p != nil {
564-
fname := info.Name()
565-
p.Name.Store(&fname)
566-
p.Total.Store(uint64(d.Count()))
567-
}
568559
cfg.KeyCount = d.Count()
569560
cfg.IndexFile = filepath.Join(info.Dir(), IdxFileName(info.Version, info.From, info.To, info.CaplinTypeString))
570561
rs, err := recsplit.NewRecSplit(cfg, logger)
@@ -577,6 +568,7 @@ func BuildIndexWithSnapName(ctx context.Context, info FileInfo, cfg recsplit.Rec
577568
defer d.MadvSequential().DisableReadAhead()
578569

579570
for {
571+
rs.SetProgress(p)
580572
g := d.MakeGetter()
581573
var i, offset, nextPos uint64
582574
word := make([]byte, 0, 4096)

db/snaptype2/block_types.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,12 +244,6 @@ var (
244244
return fmt.Errorf("TransactionsIdx: at=%d-%d, pre index building, expect: %d, got %d", sn.From, sn.To, expectedCount, d.Count())
245245
}
246246

247-
if p != nil {
248-
name := sn.Name()
249-
p.Name.Store(&name)
250-
p.Total.Store(uint64(d.Count() * 2))
251-
}
252-
253247
txnHashIdx, err := recsplit.NewRecSplit(recsplit.RecSplitArgs{
254248
KeyCount: d.Count(),
255249

@@ -291,6 +285,7 @@ var (
291285
defer bodiesSegment.MadvSequential().DisableReadAhead()
292286

293287
for {
288+
txnHashIdx.SetProgress(p)
294289
g, bodyGetter := d.MakeGetter(), bodiesSegment.MakeGetter()
295290
var ti, offset, nextPos uint64
296291
blockNum := firstBlockNum
@@ -302,10 +297,6 @@ var (
302297
}
303298

304299
for g.HasNext() {
305-
if p != nil {
306-
p.Processed.Add(1)
307-
}
308-
309300
word, nextPos = g.Next(word[:0])
310301
select {
311302
case <-ctx.Done():

db/state/domain.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,7 @@ func buildHashMapAccessor(ctx context.Context, g *seg.Reader, idxPath string, va
12201220
return err
12211221
}
12221222
g.Reset(0)
1223+
rs.SetProgress(p)
12231224
for g.HasNext() {
12241225
word, valPos = g.Next(word[:0])
12251226
if values {
@@ -1234,8 +1235,6 @@ func buildHashMapAccessor(ctx context.Context, g *seg.Reader, idxPath string, va
12341235

12351236
// Skip value
12361237
keyPos, _ = g.Skip()
1237-
1238-
p.Processed.Add(1)
12391238
}
12401239
if err = rs.Build(ctx); err != nil {
12411240
if rs.Collision() {

db/state/history.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,12 +283,12 @@ func (h *History) buildVI(ctx context.Context, historyIdxPath string, hist, efHi
283283
for {
284284
histReader.Reset(0)
285285
iiReader.Reset(0)
286+
rs.SetProgress(p)
286287

287288
valOffset = 0
288289
for iiReader.HasNext() {
289290
keyBuf, _ = iiReader.Next(keyBuf[:0])
290291
valBuf, _ = iiReader.Next(valBuf[:0])
291-
p.Processed.Add(1)
292292

293293
// fmt.Printf("ef key %x\n", keyBuf)
294294

db/state/simple_accessor_builder.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,6 @@ func (s *SimpleAccessorBuilder) Build(ctx context.Context, decomp *seg.Decompres
164164
idxFile, _ := s.parser.AccessorIdxFile(version.V1_0, from, to, uint16(s.indexPos))
165165

166166
keyCount := iidq.Count()
167-
if p != nil {
168-
baseFileName := filepath.Base(idxFile)
169-
p.Name.Store(&baseFileName)
170-
p.Total.Store(keyCount)
171-
}
172167
salt, err := Registry.Salt(s.id)
173168
if err != nil {
174169
return nil, err
@@ -197,16 +192,14 @@ func (s *SimpleAccessorBuilder) Build(ctx context.Context, decomp *seg.Decompres
197192

198193
defer iidq.reader.MadvNormal().DisableReadAhead()
199194
for {
195+
rs.SetProgress(p)
200196
stream := iidq.GetStream(ctx)
201197
defer stream.Close()
202198
for stream.HasNext() {
203199
word, index, offset, err := stream.Next()
204200
if err != nil {
205201
return nil, err
206202
}
207-
if p != nil {
208-
p.Processed.Add(1)
209-
}
210203
key := s.kf.Make(word, index)
211204
if err = rs.AddKey(key, offset); err != nil {
212205
return nil, err
@@ -222,7 +215,6 @@ func (s *SimpleAccessorBuilder) Build(ctx context.Context, decomp *seg.Decompres
222215
if err = rs.Build(ctx); err != nil {
223216
// collision handling
224217
if rs.Collision() {
225-
p.Processed.Store(0)
226218
s.logger.Debug("found collision, trying again", "file", filepath.Base(idxFile), "salt", rs.Salt(), "err", err)
227219
rs.ResetNextSalt()
228220
continue

polygon/heimdall/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ var (
219219
defer d.MadvSequential().DisableReadAhead()
220220

221221
for {
222+
rs.SetProgress(p)
222223
g.Reset(0)
223224
first = true
224225
var i, offset, nextPos uint64
@@ -528,6 +529,7 @@ func buildValueIndex(ctx context.Context, version version.Versions, sn snaptype.
528529
defer d.MadvSequential().DisableReadAhead()
529530

530531
for {
532+
rs.SetProgress(p)
531533
g := d.MakeGetter()
532534
var i, offset, nextPos uint64
533535
var key [8]byte

0 commit comments

Comments
 (0)