rocksdb/utilities/transactions
Yanqin Jin d13825e586 Add rollback_deletion_type_callback to TxnDBOptions (#9873)
Summary:
This PR does not affect write-committed.

Add a member, `rollback_deletion_type_callback` to TransactionDBOptions
so that a write-prepared transaction, when rolling back, can call this
callback to decide if a `Delete` or `SingleDelete` should be used to
cancel a prior `Put` written to the database during prepare phase.

The purpose of this PR is to prevent mixing `Delete` and `SingleDelete`
for the same key, causing undefined behaviors. Without this PR, the
following can happen:

```
// The application always issues SingleDelete when deleting keys.

txn1->Put('a');
txn1->Prepare(); // writes to memtable and potentially gets flushed/compacted to Lmax
txn1->Rollback();  // inserts DELETE('a')

txn2->Put('a');
txn2->Commit();  // writes to memtable and potentially gets flushed/compacted
```

In the database, we may have
```
L0:   [PUT('a', s=100)]
L1:   [DELETE('a', s=90)]
Lmax: [PUT('a', s=0)]
```

If a compaction compacts L0 and L1, then we have
```
L1:    [PUT('a', s=100)]
Lmax:  [PUT('a', s=0)]
```

If a future transaction issues a SingleDelete, we have
```
L0:    [SD('a', s=110)]
L1:    [PUT('a', s=100)]
Lmax:  [PUT('a', s=0)]
```

Then, a compaction including L0, L1 and Lmax leads to
```
Lmax:  [PUT('a', s=0)]
```

which is incorrect.

Similar bugs reported and addressed in
https://github.com/cockroachdb/pebble/issues/1255. Based on our team's
current priority, we have decided to take this approach for now. We may
come back and revisit in the future.

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

Test Plan: make check

Reviewed By: ltamasi

Differential Revision: D35762170

Pulled By: riversand963

fbshipit-source-id: b28d56eefc786b53c9844b9ef4a7807acdd82c8d
2022-04-20 18:57:32 -07:00
..
lock Meta-internal folly integration with F14FastMap (#9546) 2022-04-13 07:34:01 -07:00
optimistic_transaction_db_impl.cc Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433) 2020-02-20 12:09:57 -08:00
optimistic_transaction_db_impl.h Revise APIs related to user-defined timestamp (#8946) 2022-02-01 22:19:01 -08:00
optimistic_transaction_test.cc MemTableList::TrimHistory now use allocated bytes (#9020) 2021-12-02 11:45:39 -08:00
optimistic_transaction.cc Add further tests to ASSERT_STATUS_CHECKED (2) (#7698) 2020-12-09 21:21:16 -08:00
optimistic_transaction.h Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433) 2020-02-20 12:09:57 -08:00
pessimistic_transaction_db.cc Support user-defined timestamps in write-committed txns (#9629) 2022-03-08 16:20:59 -08:00
pessimistic_transaction_db.h Support user-defined timestamps in write-committed txns (#9629) 2022-03-08 16:20:59 -08:00
pessimistic_transaction.cc Support user-defined timestamps in write-committed txns (#9629) 2022-03-08 16:20:59 -08:00
pessimistic_transaction.h Support user-defined timestamps in write-committed txns (#9629) 2022-03-08 16:20:59 -08:00
snapshot_checker.cc Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433) 2020-02-20 12:09:57 -08:00
transaction_base.cc Support WBWI for keys having timestamps (#9603) 2022-02-22 14:23:01 -08:00
transaction_base.h Support user-defined timestamps in write-committed txns (#9629) 2022-03-08 16:20:59 -08:00
transaction_db_mutex_impl.cc Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433) 2020-02-20 12:09:57 -08:00
transaction_db_mutex_impl.h Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433) 2020-02-20 12:09:57 -08:00
transaction_test.cc Disallow commit-time-batch for write-prepared/write-unprepared txn conditionally (#9794) 2022-04-05 11:10:20 -07:00
transaction_test.h Support user-defined timestamps in write-committed txns (#9629) 2022-03-08 16:20:59 -08:00
transaction_util.cc Update TransactionUtil::CheckKeyForConflict to also use timestamps (#9162) 2021-11-15 12:52:18 -08:00
transaction_util.h Update TransactionUtil::CheckKeyForConflict to also use timestamps (#9162) 2021-11-15 12:52:18 -08:00
write_committed_transaction_ts_test.cc Fix clang-analyze by adding assertion (#9682) 2022-03-09 10:13:02 -08:00
write_prepared_transaction_test.cc Add rollback_deletion_type_callback to TxnDBOptions (#9873) 2022-04-20 18:57:32 -07:00
write_prepared_txn_db.cc Add rollback_deletion_type_callback to TxnDBOptions (#9873) 2022-04-20 18:57:32 -07:00
write_prepared_txn_db.h Add rollback_deletion_type_callback to TxnDBOptions (#9873) 2022-04-20 18:57:32 -07:00
write_prepared_txn.cc Add rollback_deletion_type_callback to TxnDBOptions (#9873) 2022-04-20 18:57:32 -07:00
write_prepared_txn.h Replace namespace name "rocksdb" with ROCKSDB_NAMESPACE (#6433) 2020-02-20 12:09:57 -08:00
write_unprepared_transaction_test.cc Move slow valgrind tests behind -DROCKSDB_FULL_VALGRIND_RUN (#8475) 2021-07-07 11:14:05 -07:00
write_unprepared_txn_db.cc Add further tests to ASSERT_STATUS_CHECKED (2) (#7698) 2020-12-09 21:21:16 -08:00
write_unprepared_txn_db.h WriteUnPrepared: Pass in correct subbatch count during rollback (#6463) 2020-02-28 11:19:32 -08:00
write_unprepared_txn.cc Disallow commit-time-batch for write-prepared/write-unprepared txn conditionally (#9794) 2022-04-05 11:10:20 -07:00
write_unprepared_txn.h Replace tracked_keys with a new LockTracker interface in TransactionDB (#7013) 2020-08-06 12:38:00 -07:00