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

Change is_range_del_table_empty_ flag to atomic #4801

Closed
wants to merge 2 commits into from

Conversation

abhimadan
Copy link
Contributor

Summary: To avoid a race on the flag, make it an atomic_bool. This
doesn't seem to significantly affect benchmarks.

Test Plan:

  • run readwhilewriting benchmark with db_bench on a DB with
    range tombstones
  • run crashtests with tsan enabled

Summary: To avoid a race on the flag, make it an atomic_bool. This
doesn't seem to significantly affect benchmarks.

Test Plan:
- run readwhilewriting benchmark with db_bench on a DB with
range tombstones
- run crashtests with tsan enabled
@@ -409,7 +409,7 @@ class MemTable {
ConcurrentArena arena_;
std::unique_ptr<MemTableRep> table_;
std::unique_ptr<MemTableRep> range_del_table_;
bool is_range_del_table_empty_;
std::atomic_bool is_range_del_table_empty_;
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like we use std::atomic much more often in the codebase, any idea if there is any difference?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's typedef'd to std::atomic<bool> (see "Type Aliases" section on https://en.cppreference.com/w/cpp/atomic/atomic). I can change it for consistency if you want though.

@abhimadan
Copy link
Contributor Author

Note: this fix is mainly to fix CI annoyances. In practice, this can only happen between a concurrent reader and writer, where the writer issues a DeleteRange that is about to complete as the read is processed. We know the write hasn't completed yet because last_sequence_ hasn't been updated (which has acquire-release ordering that would prevent the flag from being incorrectly read), so we don't make any guarantees about what the reader should see.

@ajkr
Copy link
Contributor

ajkr commented Dec 19, 2018

Thanks for writing down the details.

Copy link
Contributor

@ajkr ajkr left a comment

Choose a reason for hiding this comment

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

lgtm

@abhimadan
Copy link
Contributor Author

Before landing I'm going to change the memory ordering to memory_order_relaxed, since as mentioned, this is only to fix CI annoyances and not because the flag can be incorrectly read in practice.

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.

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

Copy link
Contributor

@miasantreble miasantreble left a comment

Choose a reason for hiding this comment

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

thanks for the quick fix!

@abhimadan abhimadan deleted the safe-memtable-range-dels branch December 20, 2018 01:21
ajkr pushed a commit to ajkr/rocksdb that referenced this pull request Sep 11, 2019
Summary:
To avoid a race on the flag, make it an atomic_bool. This
doesn't seem to significantly affect benchmarks.
Pull Request resolved: facebook#4801

Differential Revision: D13523845

Pulled By: abhimadan

fbshipit-source-id: 3bc29f53c50a4e06cd9f8c6232a4bb221868e055
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

4 participants