Skip to content

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

Merged
Yuval-Ariel merged 1 commit into
mainfrom
597-make-compactrange-non-blocking
Sep 18, 2023
Merged

Support Non-Blocking Manual Compactions (CompactRange) (#597)#656
Yuval-Ariel merged 1 commit into
mainfrom
597-make-compactrange-non-blocking

Conversation

@udi-speedb

Copy link
Copy Markdown
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 requested a review from ofriedma August 29, 2023 13:33
@udi-speedb udi-speedb linked an issue Aug 29, 2023 that may be closed by this pull request
@ofriedma

Copy link
Copy Markdown
Contributor

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

@ofriedma

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@udi-speedb

Copy link
Copy Markdown
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.

Comment thread db/db_compaction_test.cc
using ValidateCompletionStatusFunc =
std::function<void(ROCKSDB_NAMESPACE::Status completion_status)>;

void DefaultCompletionStatusValidation(Status completion_status,

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread db/db_compaction_test.cc
bool exclusive_manual_compaction_;
};

class DBCompactionTestWithParamWithMCC

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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().

Comment thread db/db_impl/db_impl.cc

// 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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

great

Comment thread db/db_impl/db_impl.h
// The number of LockWAL called without matching UnlockWAL call.
// See also lock_wal_write_token_
uint32_t lock_wal_count_;

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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?

Comment thread include/rocksdb/options.h

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

Copy link
Copy Markdown
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?


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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@ofriedma ofriedma left a comment

Copy link
Copy Markdown
Contributor

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

Comment thread db/db_compaction_test.cc

} // namespace

class DBCompactionTestWithMCC : public DBCompactionTest,

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread db/db_impl/db_impl.h
// The number of LockWAL called without matching UnlockWAL call.
// See also lock_wal_write_token_
uint32_t lock_wal_count_;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please notice

@udi-speedb udi-speedb requested a review from ofriedma September 5, 2023 14:23
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
@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