]> git-server-git.apps.pok.os.sepia.ceph.com Git - rocksdb.git/commit
Fix bug caused by releasing snapshot(s) during compaction (#8608)
authorYanqin Jin <yanqin@fb.com>
Wed, 18 Aug 2021 05:13:21 +0000 (22:13 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Wed, 18 Aug 2021 05:14:20 +0000 (22:14 -0700)
commit2b367fa8cc58341ced2e5dae45396783143a6352
treeccb4d81367652c38eb8dab0f06ca21f6e6e34594
parent6878cedcc316e8ea0719e57422843e584a9c964d
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
HISTORY.md
db/compaction/compaction_iterator.cc
db/compaction/compaction_iterator.h
db/compaction/compaction_iterator_test.cc
utilities/transactions/transaction_test.h
utilities/transactions/write_prepared_transaction_test.cc