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

WritePrepared: reduce prepared_mutex_ overhead #5420

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions utilities/transactions/write_prepared_txn_db.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,21 +399,27 @@ void WritePreparedTxnDB::CheckPreparedAgainstMax(SequenceNumber new_max,
"CheckPreparedAgainstMax prepared_txns_.empty() %d top: %" PRIu64,
prepared_txns_.empty(),
prepared_txns_.empty() ? 0 : prepared_txns_.top());
while (!prepared_txns_.empty() && prepared_txns_.top() <= new_max) {
const SequenceNumber prepared_top = prepared_txns_.top();
const bool empty = prepared_top == kMaxSequenceNumber;
// Preliminary check to avoid the synchronization cost
if (!empty && prepared_top <= new_max) {
if (locked) {
// Needed to avoid double locking in pop().
prepared_txns_.push_pop_mutex()->Unlock();
}
WriteLock wl(&prepared_mutex_);
auto to_be_popped = prepared_txns_.top();
delayed_prepared_.insert(to_be_popped);
ROCKS_LOG_WARN(info_log_,
"prepared_mutex_ overhead %" PRIu64 " (prep=%" PRIu64
" new_max=%" PRIu64,
static_cast<uint64_t>(delayed_prepared_.size()),
to_be_popped, new_max);
prepared_txns_.pop();
delayed_prepared_empty_.store(false, std::memory_order_release);
// Need to fetch feresh values of ::top after mutex is acquired
Copy link
Contributor

Choose a reason for hiding this comment

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

"fresh" values

while (!prepared_txns_.empty() && prepared_txns_.top() <= new_max) {
auto to_be_popped = prepared_txns_.top();
delayed_prepared_.insert(to_be_popped);
ROCKS_LOG_WARN(info_log_,
"prepared_mutex_ overhead %" PRIu64 " (prep=%" PRIu64
" new_max=%" PRIu64,
static_cast<uint64_t>(delayed_prepared_.size()),
to_be_popped, new_max);
prepared_txns_.pop();
delayed_prepared_empty_.store(false, std::memory_order_release);
}
if (locked) {
prepared_txns_.push_pop_mutex()->Lock();
}
Expand Down
2 changes: 1 addition & 1 deletion utilities/transactions/write_prepared_txn_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ class AddPreparedCallback : public PreReleaseCallback {
uint64_t log_number, size_t index,
size_t total) override {
assert(index < total);
// To reduce lock intention with the conccurrent prepare requests, lock on
// To reduce lock intention with the concurrent prepare requests, lock on
Copy link
Contributor

Choose a reason for hiding this comment

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

Lock contention?

Also, I don't know if I'd call it lock contention because it looks like you actually increase lock contention by holding the lock for longer periods of time (whereas before, it was shorter, but more frequent). I think you're just saving CPU?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps I can say "reduce lock acquisition cost".

// the first callback and unlock on the last.
const bool do_lock = !two_write_queues_ || index == 0;
const bool do_unlock = !two_write_queues_ || index + 1 == total;
Expand Down