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

Update TransactionUtil::CheckKeyForConflict to also use timestamps #9162

Closed
wants to merge 1 commit into from

Conversation

riversand963
Copy link
Contributor

Summary:
Existing TransactionUtil::CheckKeyForConflict() performs only seq-based
conflict checking. If user-defined timestamp is enabled, it should perform
conflict checking based on timestamps too.

Update TransactionUtil::CheckKey-related methods to verify the timestamp of the
latest version of a key is smaller than the read timestamp. Note that
CheckKeysForConflict() is not updated since it's used only by optimistic
transaction, and we do not plan to update it in this upcoming batch of diffs.

Existing GetLatestSequenceForKey() returns the sequence of the latest
version of a specific user key. Since we support user-defined timestamp, we
need to update this method to also return the timestamp (if enabled) of the
latest version of the key. This will be needed for snapshot validation.

Differential Revision: D31567960

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31567960

@@ -4409,6 +4422,7 @@ Status DBImpl::GetLatestSequenceForKey(SuperVersion* sv, const Slice& key,

if (*seq != kMaxSequenceNumber) {
// Found a sequence number, no need to check immutable memtables
assert(0 == ts_sz || *timestamp != std::string(ts_sz, '\xff'));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could extend these assertions a bit (and move them out of their corresponding if blocks) to check that if we have not found a sequence number yet, the timestamp has not been updated, e.g.:

assert(!ts_sz || (*seq != kMaxSequenceNumber && *timestamp != std::string(ts_sz, '\xff')) || (*seq == kMaxSequenceNumber && *timestamp == std::string(ts_sz, '\xff')));


std::string key_str;
PutFixed64(&key_str, key);
std::reverse(key_str.begin(), key_str.end());
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious: why do we reverse the key here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We reverse it so that we can do memcmp on key_strs.

@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31567960

…acebook#9162)

Summary:
Pull Request resolved: facebook#9162

Existing TransactionUtil::CheckKeyForConflict() performs only seq-based
conflict checking. If user-defined timestamp is enabled, it should perform
conflict checking based on timestamps too.

Update TransactionUtil::CheckKey-related methods to verify the timestamp of the
latest version of a key is smaller than the read timestamp. Note that
CheckKeysForConflict() is not updated since it's used only by optimistic
transaction, and we do not plan to update it in this upcoming batch of diffs.

Existing GetLatestSequenceForKey() returns the sequence of the latest
version of a specific user key. Since we support user-defined timestamp, we
need to update this method to also return the timestamp (if enabled) of the
latest version of the key. This will be needed for snapshot validation.

Reviewed By: ltamasi

Differential Revision: D31567960

fbshipit-source-id: 8478594f34e10e0e993255d4f715f870511d639f
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D31567960

@riversand963
Copy link
Contributor Author

Thanks @ltamasi for the review!

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 2035798.

@riversand963 riversand963 deleted the export-D31567960 branch November 15, 2021 21:28
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