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

Add an option to toggle timestamp based validation for the whole DB #12857

Closed
wants to merge 2 commits into from

Conversation

jowlyzhang
Copy link
Contributor

As titled. This PR adds a TransactionDBOptions field enable_udt_validation to allow user to toggle the timestamp based validation behavior across the whole DB. When it is true, which is the default value and the existing behavior. A recap of what this behavior is: GetForUpdate does timestamp based conflict checking to make sure no other transaction has committed a version of the key tagged with a timestamp equal to or newer than the calling transaction's read_timestamp_ the user set via SetReadTimestampForValidation. When this field is set to false, we disable timestamp based validation for the whole DB. MyRocks find it hard to find a read timestamp for this validation API, so we added this flexibility.

Test plan:
Added unit test

@facebook-github-bot
Copy link
Contributor

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

@jowlyzhang jowlyzhang requested a review from ltamasi July 25, 2024 01:04
Copy link
Contributor

@ltamasi ltamasi left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the patch @jowlyzhang !

Comment on lines 193 to 195
if (!enable_udt_validation && kMaxTxnTimestamp != read_timestamp_) {
return Status::InvalidArgument(
"read_timestamp is set but timestamp validation is disabled for the "
"DB");
} else if (enable_udt_validation && !do_validate &&
kMaxTxnTimestamp != read_timestamp_) {
return Status::InvalidArgument(
"If do_validate is false then GetForUpdate with read_timestamp is not "
"defined.");
} else if (do_validate && kMaxTxnTimestamp == read_timestamp_) {
} else if (enable_udt_validation && do_validate &&
kMaxTxnTimestamp == read_timestamp_) {
return Status::InvalidArgument("read_timestamp must be set for validation");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor but some repeated checks could be eliminated via nesting:

if (!enable_udt_validation) {
   if (kMaxTxnTimestamp != read_timestamp_) {
      // ...
   }
} else {
   if (!do_validate) {
      if (kMaxTxnTimestamp != read_timestamp_) {
         // ...
      }
   } else {
      if (kMaxTxnTimestamp == read_timestamp_) {
         // ...
      }
   }
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I feel it would be nice to proactively make the same change in GetEntityForUpdate too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks a lot for this suggestion! I included this into a SanityCheckReadTimestamp method to be shared by them too.

Comment on lines +589 to +606
// do_validate and set snapshot, execute sequence number based conflict
// checking and skip timestamp based conflict checking.
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to test (using parallel txns) that timestamp based conflicts are not caught if the new option is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good idea! I added a test to write some out of order timestamps.

@facebook-github-bot
Copy link
Contributor

@jowlyzhang has updated the pull request. You must reimport the pull request before landing.

@facebook-github-bot
Copy link
Contributor

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

@jowlyzhang
Copy link
Contributor Author

LGTM, thanks for the patch @jowlyzhang !

@ltamasi thanks a lot for the review! Sorry for the delayed response.

@facebook-github-bot
Copy link
Contributor

@jowlyzhang merged this pull request in 24d86f7.

@jowlyzhang jowlyzhang deleted the db_no_udt_validation branch August 2, 2024 20:13
jowlyzhang added a commit that referenced this pull request Aug 5, 2024
…12857)

Summary:
As titled. This PR adds a `TransactionDBOptions` field `enable_udt_validation` to allow user to toggle the timestamp based validation behavior across the whole DB. When it is true, which is the default value and the existing behavior. A recap of what this behavior is: `GetForUpdate` does timestamp based conflict checking to make sure no other transaction has committed a version of the key tagged with a timestamp equal to or newer than the calling transaction's `read_timestamp_` the user set via `SetReadTimestampForValidation`. When this field is set to false, we disable timestamp based validation for the whole DB. MyRocks find it hard to find a read timestamp for this validation API, so we added this flexibility.

Pull Request resolved: #12857

Test Plan: Added unit test

Reviewed By: ltamasi

Differential Revision: D60194134

Pulled By: jowlyzhang

fbshipit-source-id: b8507f8ddc37fc7a2948cf492ce5c599ae646fef
jowlyzhang added a commit that referenced this pull request Aug 7, 2024
…12857)

Summary:
As titled. This PR adds a `TransactionDBOptions` field `enable_udt_validation` to allow user to toggle the timestamp based validation behavior across the whole DB. When it is true, which is the default value and the existing behavior. A recap of what this behavior is: `GetForUpdate` does timestamp based conflict checking to make sure no other transaction has committed a version of the key tagged with a timestamp equal to or newer than the calling transaction's `read_timestamp_` the user set via `SetReadTimestampForValidation`. When this field is set to false, we disable timestamp based validation for the whole DB. MyRocks find it hard to find a read timestamp for this validation API, so we added this flexibility.

Pull Request resolved: #12857

Test Plan: Added unit test

Reviewed By: ltamasi

Differential Revision: D60194134

Pulled By: jowlyzhang

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