-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Chain ranged export #9192
Chain ranged export #9192
Conversation
Dag | ||
) | ||
|
||
func (s *walkScheduler) work(ctx context.Context, todo *walkTask, results chan *walkResult) error { |
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.
This method needs review
@@ -587,6 +590,80 @@ func (m *ChainModule) ChainGetMessage(ctx context.Context, mc cid.Cid) (*types.M | |||
return cm.VMMessage(), nil | |||
} | |||
|
|||
func (a ChainAPI) ChainExportRangeInternal(ctx context.Context, head, tail types.TipSetKey, cfg *api.ChainExportConfig) error { |
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.
this file needs review
@@ -24,6 +28,35 @@ func (cs *ChainStore) UnionStore() bstore.Blockstore { | |||
return bstore.Union(cs.stateBlockstore, cs.chainBlockstore) | |||
} | |||
|
|||
func (cs *ChainStore) ExportRange(ctx context.Context, head, tail *types.TipSet, messages, receipts, stateroots bool, workers int64, cacheSize int, w io.Writer) error { |
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.
ensure io.Writer is buffered.
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.
Done
cfg *walkSchedulerConfig | ||
} | ||
|
||
func (s *walkScheduler) enqueueIfNew(task *walkTask) { |
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.
no need to pass pointer?
close(s.in) | ||
}() | ||
for { | ||
if n := len(s.stack) - 1; n >= 0 { |
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.
comment: this does depth traversal (using the stack). The two channels (in out), we assume, add backpressure so that stack couldn't grow indifinetely if the disk is not fast enough (not completely sure).
Doing breadth-first search might allow not using the stack, and directly relying on the in channel as FIFO queue.
Dag | ||
) | ||
|
||
func (s *walkScheduler) work(ctx context.Context, todo *walkTask, results chan *walkResult) error { |
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.
try avoid pointers for walkTas and walkResult.
chain/store/snapshot.go
Outdated
} | ||
|
||
pw, ctx := newWalkScheduler(ctx, store, cfg, tasks...) | ||
results := make(chan *walkResult) |
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.
make me a good channel buffer on this shit forrest
chain/store/snapshot.go
Outdated
results <- &walkResult{c: todo.c} | ||
|
||
// extract relevant dags to walk from the block | ||
if todo.taskType == 0 { |
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.
write: Block
chain/store/snapshot.go
Outdated
log.Infow("block export", "height", b.Height) | ||
} | ||
if b.Height == 0 { | ||
log.Infow("GENESIS") |
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.
Perhaps exporting including height 0 crashes... prob not related to this part of the code.
chain/store/snapshot.go
Outdated
pw.startScheduler(ctx) | ||
pw.startWorkers(ctx, results) | ||
|
||
done := make(chan struct{}) |
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.
not used
|
||
done := make(chan struct{}) | ||
var cbErr error | ||
go func() { |
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.
potential goroutine leak if things error somewhere, as close(results) is down below.
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.
chain/store/snapshot.go
Outdated
defer func() { | ||
log.Infow("walkScheduler shutting down") | ||
close(s.out) | ||
// Because the workers may have exited early (due to the context being canceled). | ||
for range s.out { | ||
s.taskWg.Done() | ||
} | ||
// Because the workers may have enqueued additional tasks. | ||
for range s.in { | ||
s.taskWg.Done() | ||
} | ||
// now, the waitgroup should be at 0, and the goroutine that was _waiting_ on it should have exited. | ||
log.Infow("walkScheduler stopped") |
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.
need to re-approach synchronization here. Seems last info message never happens. Things hang on ctrl-c.
At the end of the export the following is printer:
where height goes down to 0. That is very confusing since we are only doing a range export. Are we missing a check to finish on the starting height? |
} | ||
if b.Height%1000 == 0 { | ||
if b.Height%1_000 == 0 { |
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.
hmmm....what does this mean?
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.
emit a log message every 1000 blocks
the underscore is serving as a comma for readability https://go.dev/doc/go1.13#language
One outstanding issue with this PR is that it sometimes cannot be stopped with Ctrl+C |
- will hopfully make things faster by not streaming the export over the json rpc api
ad6ef57
to
0193c97
Compare
We need this before nv18 for stable snapshot service |
@@ -171,6 +171,10 @@ type FullNode interface { | |||
// If oldmsgskip is set, messages from before the requested roots are also not included. | |||
ChainExport(ctx context.Context, nroots abi.ChainEpoch, oldmsgskip bool, tsk types.TipSetKey) (<-chan []byte, error) //perm:read | |||
|
|||
ChainExportRange(ctx context.Context, head, tail types.TipSetKey, cfg *ChainExportConfig) (<-chan []byte, error) //perm:read |
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.
filecoin-project/go-jsonrpc#88 adds support for calling methods on the client.
A callback accepting bytes on the client would be better as that lets you have backpressure, and is arguably more robust in general.
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.
(see https://github.com/filecoin-project/lotus/pull/10027/files for an example of how it's integrated in lotus)
I'm continuing this on #10145 . I'm leaving this branch untouched since we are actually using it in production now (well, a different rebase on v0.19.0). |
Related Issues
Proposed Changes
Additional Info
Checklist
Before you mark the PR ready for review, please make sure that:
<PR type>: <area>: <change being made>
fix: mempool: Introduce a cache for valid signatures
PR type
: fix, feat, INTERFACE BREAKING CHANGE, CONSENSUS BREAKING, build, chore, ci, docs,perf, refactor, revert, style, testarea
: api, chain, state, vm, data transfer, market, mempool, message, block production, multisig, networking, paychan, proving, sealing, wallet, deps