Skip to content
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

feat: Make add piece idempotent #8160

Merged
merged 6 commits into from
Mar 2, 2022
Merged

feat: Make add piece idempotent #8160

merged 6 commits into from
Mar 2, 2022

Conversation

aarshkshah1992
Copy link
Contributor

@aarshkshah1992 aarshkshah1992 commented Feb 21, 2022

Related Issues

filecoin-project/boost#282

Proposed Changes

A very common deal making error we encounter is that Boost/Markets makes a call to AddPiece and then restarts.
If it restarts before it's able to persist the fact that it's already called AddPiece, it will call AddPiece again for the same piece. In this case, the existing API returns an error as it's not idempotent.

This PR allows the user to call AddPiece multiple times for the same piece but ensures that it's handed off to the sealing subsystem only once.

It also makes the method respect the given context.

Additional Info

Checklist

Before you mark the PR ready for review, please make sure that:

  • All commits have a clear commit message.
  • The PR title is in the form of of <PR type>: <area>: <change being made>
    • example: 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, test
    • area: api, chain, state, vm, data transfer, market, mempool, message, block production, multisig, networking, paychan, proving, sealing, wallet, deps
  • This PR has tests for new functionality or change in behaviour
  • If new user-facing features are introduced, clear usage guidelines and / or documentation updates should be included in https://lotus.filecoin.io or Discussion Tutorials.
  • CI is green

}, 1)

m.pendingPieces[proposalCID(deal)] = &pendingPiece{
doneCh := make(chan struct{}, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
doneCh := make(chan struct{}, 1)
doneCh := make(chan struct{})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep this for safety, dosen't hurt because the code that writes to this is called sync by the sealer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never really write to this channel, just close it, which doesn't block.

type pendingPiece struct {
doneCh chan struct{}
resp atomic.Value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think resp needs to be an atomic value - the doneCh prevents concurrent access

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. fixed.

extern/storage-sealing/input.go Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Feb 21, 2022

Codecov Report

Merging #8160 (8e62fec) into master (214c32d) will decrease coverage by 0.06%.
The diff coverage is 55.00%.

❗ Current head 8e62fec differs from pull request most recent head f0f2b3e. Consider uploading reports for the commit f0f2b3e to get more accurate results

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #8160      +/-   ##
==========================================
- Coverage   39.49%   39.42%   -0.07%     
==========================================
  Files         666      666              
  Lines       72516    72519       +3     
==========================================
- Hits        28637    28589      -48     
- Misses      38932    38961      +29     
- Partials     4947     4969      +22     
Impacted Files Coverage Δ
extern/storage-sealing/sealing.go 78.88% <ø> (ø)
extern/storage-sealing/input.go 51.52% <55.00%> (-1.71%) ⬇️
chain/events/message_cache.go 87.50% <0.00%> (-12.50%) ⬇️
extern/sector-storage/worker_tracked.go 79.46% <0.00%> (-7.15%) ⬇️
markets/retrievaladapter/client_blockstore.go 62.50% <0.00%> (-6.25%) ⬇️
storage/wdpost_sched.go 77.45% <0.00%> (-5.89%) ⬇️
miner/miner.go 55.40% <0.00%> (-2.96%) ⬇️
chain/beacon/beacon.go 50.66% <0.00%> (-2.67%) ⬇️
chain/events/events_height.go 68.90% <0.00%> (-2.53%) ⬇️
chain/events/events_called.go 83.90% <0.00%> (-1.96%) ⬇️
... and 16 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 214c32d...f0f2b3e. Read the comment docs.

Comment on lines 316 to 322
select {
case <-pp.doneCh:
res := pp.resp
return api.SectorOffset{Sector: res.sn, Offset: res.offset.Padded()}, res.err
case <-ctx.Done():
return api.SectorOffset{}, ctx.Err()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could put this into a helper method (e.g. waitResp) on pendingPiece for readability, and dedupe the same bit of code below.

}, 1)

m.pendingPieces[proposalCID(deal)] = &pendingPiece{
doneCh := make(chan struct{}, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We never really write to this channel, just close it, which doesn't block.

extern/storage-sealing/input.go Show resolved Hide resolved
@aarshkshah1992
Copy link
Contributor Author

@magik6k Have addressed your review.

@jennijuju
Copy link
Member

Please update the pr title as instructed in the pr template before merging

@magik6k magik6k changed the title Make add piece idempotent feat: Make add piece idempotent Mar 2, 2022
@magik6k magik6k merged commit 6d464c4 into master Mar 2, 2022
@magik6k magik6k deleted the fix/addpiece-idempotent branch March 2, 2022 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants