support canceling ongoing CompactFiles#13687
support canceling ongoing CompactFiles#13687virajthakur wants to merge 8 commits intofacebook:mainfrom
Conversation
Summary: Test Plan: Reviewers: Subscribers: Tasks: Tags:
…ect DisableManualCompactions logic
|
@virajthakur has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
There was a problem hiding this comment.
Pull Request Overview
Adds support for canceling ongoing manual CompactFiles() operations by introducing a cancellation flag, wiring it into the compaction logic, and exercising it in a new test.
- Introduce
std::atomic<bool>* canceledinCompactionOptionswith default initialization. - Update
DBImpl::CompactFilesImplto check the new cancel flag alongside existing pause logic. - Add
TestCancelCompactFilesindb_test2.ccand fix minor typos/removals in test files.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| include/rocksdb/options.h | Added canceled flag to CompactionOptions and initialized it to nullptr. |
| db/db_impl/db_impl_compaction_flush.cc | Wired the cancel flag into CompactFilesImpl and registered a syncpoint callback. |
| db/db_test2.cc | Removed unused header, fixed typo, and added TestCancelCompactFiles. |
Comments suppressed due to low confidence (4)
include/rocksdb/options.h:2229
- [nitpick] Using a raw pointer for the cancellation flag can lead to dangling pointers if
CompactionOptionsis copied or the referenced atomic goes out of scope. Consider owning anstd::atomic<bool>directly or using a safer handle (e.g.,std::optional<std::reference_wrapper<std::atomic<bool>>>) to manage lifetime.
std::atomic<bool>* canceled;
include/rocksdb/options.h:2229
- Document that the
atomic<bool>* canceledpointer must remain valid for the entire duration of the compaction to avoid undefined behavior.
std::atomic<bool>* canceled;
db/db_test2.cc:5693
- [nitpick] Variable name
disable_compactionis a bit generic; consider renaming todisable_manual_compactionfor clarity.
bool disable_compaction = false;
db/db_impl/db_impl_compaction_flush.cc:1443
- Add a unit test where
CompactionOptions.canceledremainsnullptrto verify that compaction proceeds normally and no null-pointer dereference occurs.
(compact_options.canceled &&
…cksdb into viraj-compactfiles-cancel
|
@virajthakur has updated the pull request. You must reimport the pull request before landing. |
|
@virajthakur has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@virajthakur has updated the pull request. You must reimport the pull request before landing. |
|
@virajthakur has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
| ROCKSDB_NAMESPACE::EnvOptions(), options}; | ||
|
|
||
| // ingest large SST files | ||
| std::vector<std::string> external_sst_file_names; |
There was a problem hiding this comment.
I see that we are ingesting files for this test. This seems to be the same as what TestCompactFiles do and this is totally fine.
Just FYI in case you want to just call PUTs, flush them and call CompactFiles() on those SST files without knowing the file names in advance.
rocksdb/db/db_with_timestamp_compaction_test.cc
Lines 298 to 320 in 2dcfc54
|
@virajthakur has updated the pull request. You must reimport the pull request before landing. |
|
@virajthakur has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
|
@virajthakur merged this pull request in 4bdfb7e. |
|
IIUC, this only cancels CompactFiles() before compaction starts running. We should be able to cancel an ongoing compaction similar to CompactRange(): rocksdb/db/db_impl/db_impl_compaction_flush.cc Line 4214 in 4bdfb7e |
Summary: Add an atomic bool to CompactionOptions to cancel an ongoing CompactFiles() operation, in the same fashion we do for CompactRange(). Pull Request resolved: facebook#13687 Test Plan: ./db_test2 --gtest_filter=DBTest2.TestCancelCompactFiles Reviewed By: jaykorean Differential Revision: D76538529 Pulled By: virajthakur fbshipit-source-id: 77db5b4fb4cbd5280584834df28e51a72b084dab
Add an atomic bool to CompactionOptions to cancel an ongoing CompactFiles() operation, in the same fashion we do for CompactRange().
Test Plan: ./db_test2 --gtest_filter=DBTest2.TestCancelCompactFiles