rocksdb/utilities/transactions
Yanqin Jin 2b367fa8cc Fix bug caused by releasing snapshot(s) during compaction (#8608)
Summary:
In debug mode, we are seeing assertion failure as follows

```
db/compaction/compaction_iterator.cc:980: void rocksdb::CompactionIterator::PrepareOutput(): \
Assertion `ikey_.type != kTypeDeletion && ikey_.type != kTypeSingleDeletion' failed.
```

It is caused by releasing earliest snapshot during compaction between the execution of
`NextFromInput()` and `PrepareOutput()`.

In one case, as demonstrated in unit test `WritePreparedTransaction.ReleaseEarliestSnapshotDuringCompaction_WithSD2`,
incorrect result may be returned by a following range scan if we disable assertion, as in opt compilation
level: the SingleDelete marker's sequence number is zeroed out, but the preceding PUT is also
outputted to the SST file after compaction. Due to the logic of DBIter, the PUT will not be
skipped and will be returned by iterator in range scan. https://github.com/facebook/rocksdb/issues/8661 illustrates what happened.

Fix by taking a more conservative approach: make compaction zero out sequence number only
if key is in the earliest snapshot when the compaction starts.

Another assertion failure is
```
Assertion `current_user_key_snapshot_ == last_snapshot' failed.
```

It's caused by releasing the snapshot between the PUT and SingleDelete during compaction.

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

Test Plan: make check

Reviewed By: jay-zhuang

Differential Revision: D30145645

Pulled By: riversand963

fbshipit-source-id: 699f58e66faf70732ad53810ccef43935d3bbe81
2021-08-17 22:14:20 -07:00
..
lock Make EventListener into a Customizable Class (#8473) 2021-07-27 07:47:02 -07:00
optimistic_transaction.cc
optimistic_transaction.h
optimistic_transaction_db_impl.cc
optimistic_transaction_db_impl.h
optimistic_transaction_test.cc
pessimistic_transaction.cc
pessimistic_transaction.h
pessimistic_transaction_db.cc
pessimistic_transaction_db.h
snapshot_checker.cc
transaction_base.cc
transaction_base.h
transaction_db_mutex_impl.cc
transaction_db_mutex_impl.h
transaction_test.cc
transaction_test.h Fix bug caused by releasing snapshot(s) during compaction (#8608) 2021-08-17 22:14:20 -07:00
transaction_util.cc
transaction_util.h
write_prepared_transaction_test.cc Fix bug caused by releasing snapshot(s) during compaction (#8608) 2021-08-17 22:14:20 -07:00
write_prepared_txn.cc Several simple local code clean-ups (#8565) 2021-07-30 12:07:49 -07:00
write_prepared_txn.h
write_prepared_txn_db.cc Several simple local code clean-ups (#8565) 2021-07-30 12:07:49 -07:00
write_prepared_txn_db.h Several simple local code clean-ups (#8565) 2021-07-30 12:07:49 -07:00
write_unprepared_transaction_test.cc
write_unprepared_txn.cc Several simple local code clean-ups (#8565) 2021-07-30 12:07:49 -07:00
write_unprepared_txn.h
write_unprepared_txn_db.cc
write_unprepared_txn_db.h