Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Non-Blocking Manual Compactions (CompactRange) (#597) #656

Merged
merged 1 commit into from
Sep 18, 2023

Conversation

udi-speedb
Copy link
Contributor

Add a new option to CompactRangeOptions, a callback object. By defaut, the callback is empty so CompactRange() will be blocking (as it is now). If the callback is set, the callback object's callback method will be called upon completion with the completion status.

@udi-speedb udi-speedb linked an issue Aug 29, 2023 that may be closed by this pull request
@ofriedma
Copy link
Contributor

@udi-speedb please add example file how to use the new non blocking compaction feature

@ofriedma
Copy link
Contributor

please use port::Thread and not std::thread for spawning threads, so the on thread start callback will work on those threads

@udi-speedb
Copy link
Contributor Author

please use port::Thread and not std::thread for spawning threads, so the on thread start callback will work on those threads

Done. Please just note that I have made the ThreadWithCb::joinable() a const method (same as std::thread::joinable()) (I am calling this method from a const method of mine).

@udi-speedb udi-speedb force-pushed the 597-make-compactrange-non-blocking branch from ad48fb2 to 9a686a1 Compare August 30, 2023 05:12
@udi-speedb
Copy link
Contributor Author

@udi-speedb please add example file how to use the new non blocking compaction feature

Done

@udi-speedb udi-speedb force-pushed the 597-make-compactrange-non-blocking branch from 980510e to 2c93929 Compare August 30, 2023 08:57
@ofriedma
Copy link
Contributor

@udi-speedb add a unit test for closing the db before compact range has been completed

@udi-speedb
Copy link
Contributor Author

@udi-speedb add a unit test for closing the db before compact range has been completed

As we have discussed, it will be the user's responsibility to wait for all non-blocking CompactRange() calls to have their respective callbacks called. Thereafter, the Close() shouldn't have any issues joining the internal threads.
I will add a note about that in the CompactRange()'s documentation.

using ValidateCompletionStatusFunc =
std::function<void(ROCKSDB_NAMESPACE::Status completion_status)>;

void DefaultCompletionStatusValidation(Status completion_status,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

above this line you added the ROCKSDB_NAMESPACE:: , please use it here or remove it from the other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed in new code that I have added, however, there are many places in the db_compaction_test.cc that use "ROCKSDB_NAMESPACE::" which I will not touch to avoid unnecessary code changes that are irrelevant to this PR.

@@ -134,32 +386,70 @@ class DBCompactionTestWithParam
bool exclusive_manual_compaction_;
};

class DBCompactionTestWithParamWithMCC
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is MCC?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manual Compaction Control

threads_.push_back(std::move(thread));
}

void CompactRangeThreadsMngr::CleanupCompletedThreads() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think joinable() will always return true, because we have never called join().

@@ -622,6 +622,10 @@ Status DBImpl::CloseHelper() {
cfd->UnrefAndTryDelete();
}

// Wait for all non-blocking manual compactions that may still be in progress.
// Do it only after cleaning up all compaction-related activity above.
compact_range_threads_mngr_.Shutdown();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great

@@ -2756,6 +2773,8 @@ class DBImpl : public DB {
// The number of LockWAL called without matching UnlockWAL call.
// See also lock_wal_write_token_
uint32_t lock_wal_count_;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe add a small comment here about the manual/range compaction thread manager

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please notice

} else {
fprintf(stderr,
"Non-Blocking CompactRange() Didn't Complete Successfuly in "
"Time: %d\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe print the status message?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is std::future::future_status which is an enum, what status message should I print?


// An optional completion callback to allow for non-blocking (async) operation
// Default: Empty (Blocking)
std::shared_ptr<CompactRangeCompletedCbIf> async_completion_cb;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

async_completion_cb, maybe use another name, what if we will want to add Async PUT for example?

@@ -36,7 +36,7 @@ class ThreadWithCb {
}

ThreadWithCb() {}
bool joinable() { return thread_.joinable(); }
bool joinable() const { return thread_.joinable(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@ofriedma ofriedma added the enhancement New feature or request label Sep 4, 2023
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add license here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed this file

Copy link
Contributor

@ofriedma ofriedma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before merge please add comments


} // namespace

class DBCompactionTestWithMCC : public DBCompactionTest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a note what is MCC.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -2756,6 +2773,8 @@ class DBImpl : public DB {
// The number of LockWAL called without matching UnlockWAL call.
// See also lock_wal_write_token_
uint32_t lock_wal_count_;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please notice

Add a new option to CompactRangeOptions, a callback object. By defaut,
the callback is empty so CompactRange() will be blocking (as it is now).
If the callback is set, the callback object's callback method will be
called upon completion with the completion status.
@udi-speedb udi-speedb force-pushed the 597-make-compactrange-non-blocking branch from 129e3d6 to 3cf02ac Compare September 6, 2023 12:23
@Yuval-Ariel Yuval-Ariel merged commit ea3da8e into main Sep 18, 2023
2 checks passed
@Yuval-Ariel Yuval-Ariel deleted the 597-make-compactrange-non-blocking branch September 18, 2023 12:22
udi-speedb added a commit that referenced this pull request Nov 23, 2023
Add a new option to CompactRangeOptions, a callback object. By default,
the callback is empty so CompactRange() will be blocking (as it is now).
If the callback is set, the callback object's callback method will be
called upon completion with the completion status.
udi-speedb added a commit that referenced this pull request Dec 6, 2023
Add a new option to CompactRangeOptions, a callback object. By default,
the callback is empty so CompactRange() will be blocking (as it is now).
If the callback is set, the callback object's callback method will be
called upon completion with the completion status.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make compactRange() non-blocking
3 participants