rocksdb/utilities/transactions
Yu Zhang 210c8df820 Use do_validate flag to control timestamp based validation in WriteCommittedTxn::GetForUpdate (#12369)
Summary:
When PR https://github.com/facebook/rocksdb/issues/9629 introduced user-defined timestamp support for `WriteCommittedTxn`, it adds this usage mandate for API `GetForUpdate` when UDT is enabled. The `do_validate` flag has to be true, and user should have already called `Transaction::SetReadTimestampForValidation` to set a read timestamp for validation. The rationale behind this mandate is this:
1) with do_vaildate = true, `GetForUpdate` could verify this relationships: let's denote the user-defined timestamp in db for the key as  `Ts_db` and the read timestamp user set via `Transaction::SetReadTimestampForValidation` as `Ts_read`. UDT based validation will only pass if `Ts_db <= Ts_read`.
5950907a82/utilities/transactions/transaction_util.cc (L141)

2)  Let's denote the committed timestamp set via `Transaction::SetCommitTimestamp` to be `Ts_cmt`. Later `WriteCommitedTxn::Commit` would only pass if this condition is met: `Ts_read < Ts_cmt`. 5950907a82/utilities/transactions/pessimistic_transaction.cc (L431)

Together these two checks can ensure `Ts_db < Ts_cmt` to meet the user-defined timestamp invariant that newer timestamp should have newer sequence number.

The `do_validate` flag was originally intended to make snapshot based validation optional. If it's true, `GetForUpdate` checks no entry is written after the snapshot. If it's false, it will skip this snapshot based validation. In this PR, we are making the UDT based validation configurable too based on this flag instead of mandating it for below reasons: 1) in some cases the users themselves can enforce aformentioned invariant on their side independently, without RocksDB help, for example, if they are managing a monotonically increasing timestamp, and their transactions are only committed in a single thread. So they don't need this UDT based validation and wants to skip it, 2) It also could be expensive or not practical for users to come up with such a read timestamp that is exactly in between their commit timestamp and the db's timestamp. For example, in aformentioned case where a monotonically increasing timestamp is managed, the users would need to access this timestamp both for setting the read timestamp and for setting the commit timestamp. So it's preferable to skip this check too.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/12369

Test Plan: added unit tests

Reviewed By: ltamasi

Differential Revision: D54268920

Pulled By: jowlyzhang

fbshipit-source-id: ca7693796f9bb11f376a2059d91841e51c89435a
2024-03-07 14:58:10 -08:00
..
lock Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
optimistic_transaction.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
optimistic_transaction.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
optimistic_transaction_db_impl.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
optimistic_transaction_db_impl.h Remove 'virtual' when implied by 'override' (#12319) 2024-01-31 13:14:42 -08:00
optimistic_transaction_test.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
pessimistic_transaction.cc Use do_validate flag to control timestamp based validation in WriteCommittedTxn::GetForUpdate (#12369) 2024-03-07 14:58:10 -08:00
pessimistic_transaction.h Remove 'virtual' when implied by 'override' (#12319) 2024-01-31 13:14:42 -08:00
pessimistic_transaction_db.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
pessimistic_transaction_db.h Remove 'virtual' when implied by 'override' (#12319) 2024-01-31 13:14:42 -08:00
snapshot_checker.cc Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
timestamped_snapshot_test.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
transaction_base.cc Set default cf ts sz for a reused transaction (#11685) 2023-08-09 13:49:42 -07:00
transaction_base.h Remove 'virtual' when implied by 'override' (#12319) 2024-01-31 13:14:42 -08:00
transaction_db_mutex_impl.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
transaction_db_mutex_impl.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
transaction_test.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
transaction_test.h Add Transaction::CollapseKey to collapse merge op chains ondemand (#11815) 2023-09-15 10:25:57 -07:00
transaction_util.cc Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
transaction_util.h Remove RocksDB LITE (#11147) 2023-01-27 13:14:19 -08:00
write_committed_transaction_ts_test.cc Use do_validate flag to control timestamp based validation in WriteCommittedTxn::GetForUpdate (#12369) 2024-03-07 14:58:10 -08:00
write_prepared_transaction_test.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
write_prepared_txn.cc Group SST write in flush, compaction and db open with new stats (#11910) 2023-12-29 15:29:23 -08:00
write_prepared_txn.h Remove 'virtual' when implied by 'override' (#12319) 2024-01-31 13:14:42 -08:00
write_prepared_txn_db.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
write_prepared_txn_db.h Deprecate some variants of Get and MultiGet (#12327) 2024-02-16 09:21:06 -08:00
write_unprepared_transaction_test.cc Refactor WriteUnpreparedStressTest to be a unit test (#11424) 2023-05-22 12:31:52 -07:00
write_unprepared_txn.cc Prefer static_cast in place of most reinterpret_cast (#12308) 2024-02-07 10:44:11 -08:00
write_unprepared_txn.h Remove 'virtual' when implied by 'override' (#12319) 2024-01-31 13:14:42 -08:00
write_unprepared_txn_db.cc Run internal cpp modernizer on RocksDB repo (#12398) 2024-03-04 10:08:32 -08:00
write_unprepared_txn_db.h Remove 'virtual' when implied by 'override' (#12319) 2024-01-31 13:14:42 -08:00