-
Notifications
You must be signed in to change notification settings - Fork 243
feat(migration): statehistory migration #3658
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
82fc80e
feat(migration): headstate migration
MaksymMalicki 8befd37
chore: self review
MaksymMalicki 496a6a1
feat(migration): statehistory migration
MaksymMalicki cc40fe7
chore: self review
MaksymMalicki 6fdd1c4
chore: self review
MaksymMalicki 8cc9a20
test: test only public API
MaksymMalicki d4d079d
refactor(migration): remove migration/headstate
rodrodros 6e41c00
refactor(migration): move statehistory into state/history
rodrodros 8556425
refactor(migration/state): unify common scaffolding into common pkg
rodrodros 958d81f
refactor(migration/state): use felt.Address instead of felt.Felt
rodrodros 9fd197b
state migration phases under one migration
NazariiDenha 886d3f9
move phases into internal package
NazariiDenha ca4ebb2
add test
NazariiDenha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "github.com/NethermindEth/juno/db" | ||
| "github.com/NethermindEth/juno/migration/pipeline" | ||
| "github.com/NethermindEth/juno/migration/semaphore" | ||
| "github.com/NethermindEth/juno/utils/log" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| type Committer struct { | ||
| logger log.StructuredLogger | ||
| counter Counter | ||
| batchSemaphore semaphore.ResourceSemaphore[db.Batch] | ||
| phaseName string | ||
| } | ||
|
|
||
| var _ pipeline.State[Task, struct{}] = (*Committer)(nil) | ||
|
|
||
| func NewCommitter( | ||
| logger log.StructuredLogger, | ||
| batchSemaphore semaphore.ResourceSemaphore[db.Batch], | ||
| phaseName string, | ||
| ) *Committer { | ||
| return &Committer{ | ||
| logger: logger, | ||
| counter: NewCounter(logger, TimeLogRate, phaseName), | ||
| batchSemaphore: batchSemaphore, | ||
| phaseName: phaseName, | ||
| } | ||
| } | ||
|
|
||
| func (c *Committer) Run(_ int, t Task, _ chan<- struct{}) error { | ||
| defer c.batchSemaphore.Put() | ||
|
|
||
| fields := make([]zap.Field, 0, 4) | ||
| if c.phaseName != "" { | ||
| fields = append(fields, zap.String("phase", c.phaseName)) | ||
| } | ||
| fields = append(fields, | ||
| zap.Int("completedAddrs", t.CompletedAddrs), | ||
| zap.Int("entryCount", t.EntryCount), | ||
| zap.Int("batchSize", t.Batch.Size()), | ||
| ) | ||
| c.logger.Debug("writing batch", fields...) | ||
|
|
||
| byteSize := uint64(t.Batch.Size()) | ||
| if err := t.Batch.Write(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| c.counter.Log(byteSize, t.CompletedAddrs, t.EntryCount) | ||
| return nil | ||
| } | ||
|
|
||
| func (c *Committer) Done(int, chan<- struct{}) error { | ||
| return nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "github.com/NethermindEth/juno/db" | ||
| ) | ||
|
|
||
| const ( | ||
| BatchByteSize = 128 * db.Megabyte | ||
| TargetBatchByteSize = 96 * db.Megabyte | ||
| IngestorCount = 4 | ||
| TimeLogRate = 5 * time.Second | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package common | ||
|
|
||
| import ( | ||
| "math" | ||
| "time" | ||
|
|
||
| "github.com/NethermindEth/juno/db" | ||
| "github.com/NethermindEth/juno/utils/log" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| type Counter struct { | ||
| logger log.StructuredLogger | ||
| timeLogRate time.Duration | ||
| phaseName string | ||
| start time.Time | ||
| size uint64 | ||
| completedAddrs uint64 | ||
| entryCount uint64 | ||
| } | ||
|
|
||
| func NewCounter(logger log.StructuredLogger, timeLogRate time.Duration, phaseName string) Counter { | ||
| if zl, ok := logger.(*log.ZapLogger); ok { | ||
| logger = zl.WithOptions(zap.AddCallerSkip(1)) | ||
| } | ||
| return Counter{ | ||
| logger: logger, | ||
| timeLogRate: timeLogRate, | ||
| phaseName: phaseName, | ||
| start: time.Now(), | ||
| } | ||
| } | ||
|
|
||
| func (c *Counter) Log(byteSize uint64, completedAddrs, entryCount int) { | ||
| c.size += byteSize | ||
| c.completedAddrs += uint64(completedAddrs) | ||
| c.entryCount += uint64(entryCount) | ||
|
|
||
| const cent = 100 | ||
|
|
||
| now := time.Now() | ||
| elapsed := now.Sub(c.start).Seconds() | ||
| if elapsed <= c.timeLogRate.Seconds() { | ||
| return | ||
| } | ||
|
|
||
| mbs := float64(c.size) / float64(db.Megabyte) | ||
| fields := make([]zap.Field, 0, 8) | ||
| if c.phaseName != "" { | ||
| fields = append(fields, zap.String("phase", c.phaseName)) | ||
| } | ||
| fields = append(fields, | ||
| zap.Float64("MB", math.Round(mbs*cent)/cent), | ||
| zap.Float64("MB/s", math.Round(mbs/elapsed*cent)/cent), | ||
| zap.Uint64("completedContracts", c.completedAddrs), | ||
| zap.Float64("completedContracts/s", float64(c.completedAddrs)/elapsed), | ||
| zap.Uint64("entries", c.entryCount), | ||
| zap.Float64("entries/s", float64(c.entryCount)/elapsed), | ||
| zap.Float64("time", elapsed), | ||
| ) | ||
| c.logger.Info("write speed", fields...) | ||
|
|
||
| c.start = now | ||
| c.size = 0 | ||
| c.completedAddrs = 0 | ||
| c.entryCount = 0 | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit (follow-up to @brbrr's earlier rounding request):
MBandMB/sare now rounded to 2 decimals, butcompletedContracts/s,entries/s, andtimeare still emitted at full float precision — which is most of the noise in the example log line. Consider rounding them the same way: