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

BlobDB: handle the case when OnCompactionCompleted precedes OnFlushCompleted #6341

Closed

Conversation

ltamasi
Copy link
Contributor

@ltamasi ltamasi commented Jan 29, 2020

Summary:
BlobDB keeps track of the mapping between SSTs and blob files using
the OnFlushCompleted and OnCompactionCompleted callbacks of
the Listener interface: upon receiving a flush notification, a link is added
between the newly flushed SST and the corresponding blob file; for
compactions, links are removed for the inputs and added for the outputs.
In certain cases, it is possible for the compaction notification that results
in a link being removed to precede the flush notification that establishes
the link (see #6338).
The earlier code did not handle this case, resulting in assertion failures.
With the patch, BlobDB stores unmatched link removals in a separate set,
and reconciles them with link additions as they arrive.

Test Plan:
Added a unit test that simulates this case.

@ltamasi ltamasi requested a review from siying January 29, 2020 01:36
@ltamasi ltamasi changed the title [WIP] BlobDB: handle race between OnFlushCompleted/OnCompactionCompleted BlobDB: handle the case when OnCompactionCompleted precedes OnFlushCompleted Jan 29, 2020
Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

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

@ltamasi has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@burtonli
Copy link
Contributor

I think handling OnCompactionCompleted precedes OnFlushCompleted inside blob db_impl may create issue for MarkUnreferencedBlobFilesObsolete(). If OnCompactionCompleted arrives first and the blob file happens to be the oldest file (e.g.: the sst file is the only file in the db, and it is triggered compaction by reaching the level base size), then the blob file may be marked as obsolete in BlobDBImpl::ProcessCompactionJobInfo() before OnFlushCompleted call.

I have a proposal to fix the issue by always make sure OnFlushCompleted is always called ahead of OnCompactionBegin and OnCompactionCompleted for the same file, which seems to be a more nature way for other external consumers to built their similar logic like BlobDB. Think about how does an external service to handle a file starts compaction before flushed.
https://github.com/facebook/rocksdb/pull/6342

@ltamasi
Copy link
Contributor Author

ltamasi commented Jan 29, 2020

Considering that this is not a threading issue as originally thought (since the notification for the trivial move compaction deterministically precedes the notification for the flush), it would be better to fix this in RocksDB itself. Closing in favor of #6342 .

@ltamasi ltamasi closed this Jan 29, 2020
@ltamasi
Copy link
Contributor Author

ltamasi commented Jan 29, 2020

I think handling OnCompactionCompleted precedes OnFlushCompleted inside blob db_impl may create issue for MarkUnreferencedBlobFilesObsolete(). If OnCompactionCompleted arrives first and the blob file happens to be the oldest file (e.g.: the sst file is the only file in the db, and it is triggered compaction by reaching the level base size), then the blob file may be marked as obsolete in BlobDBImpl::ProcessCompactionJobInfo() before OnFlushCompleted call.

We actually have protection in place against that but I do agree that this should ideally be fixed in the RocksDB core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants