Skip to content

Commit

Permalink
Chain ranged export: rework and address current shortcomings
Browse files Browse the repository at this point in the history
This commit moderately refactors the ranged export code. It addresses several
problems:
  * Code does not finish cleanly and things hang on ctrl-c
  * Same block is read multiple times in a row (artificially increasing cached blockstore metrics to 50%)
  * It is unclear whether there are additional races (a single worker quits when reaching height 0)

The changes:

  * Use a FIFO instead of stack: this is likely going to be more memory
    friendly as the slice capacity will evolve as needed as we remove elements
    from the head (previous stack would allocate a very large amount of memory)
  * We avoid a probably not small amount of allocations by not using unnecessary pointers
  * Flow is a bit simplified so that context cancellation correctly shuts-down workers
  and drains channels.
  * We ensure all work is finished before terminating the work, something that might
  have been broken in some edge cases previous.

Initial testing shows the code is currently about 5% faster.
  • Loading branch information
hsanjuan committed Feb 2, 2023
1 parent 5b736a4 commit ea5eb52
Show file tree
Hide file tree
Showing 8 changed files with 374 additions and 274 deletions.
4 changes: 2 additions & 2 deletions api/api_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ 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
ChainExportRange(ctx context.Context, head, tail types.TipSetKey, cfg ChainExportConfig) (<-chan []byte, error) //perm:read

ChainExportRangeInternal(ctx context.Context, head, tail types.TipSetKey, cfg *ChainExportConfig) error //perm:read
ChainExportRangeInternal(ctx context.Context, head, tail types.TipSetKey, cfg ChainExportConfig) error //perm:read

// ChainPrune prunes the stored chain state and garbage collects; only supported if you
// are using the splitstore
Expand Down
30 changes: 14 additions & 16 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,10 @@ func (m *MsgUuidMapType) UnmarshalJSON(b []byte) error {
return nil
}

// ChainExportConfig holds configuration for chain ranged exports.
type ChainExportConfig struct {
WriteBufferSize int
Workers int64
NumWorkers int
CacheSize int
IncludeMessages bool
IncludeReceipts bool
Expand Down
4 changes: 2 additions & 2 deletions api/v0api/full.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ 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 *api.ChainExportConfig) (<-chan []byte, error) //perm:read
ChainExportRange(ctx context.Context, head, tail types.TipSetKey, cfg api.ChainExportConfig) (<-chan []byte, error) //perm:read

ChainExportRangeInternal(ctx context.Context, head, tail types.TipSetKey, cfg *api.ChainExportConfig) error //perm:read
ChainExportRangeInternal(ctx context.Context, head, tail types.TipSetKey, cfg api.ChainExportConfig) error //perm:read

// MethodGroup: Beacon
// The Beacon method group contains methods for interacting with the random beacon (DRAND)
Expand Down
22 changes: 10 additions & 12 deletions api/v0api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ea5eb52

Please sign in to comment.