Skip to content

155 proactive wbm flushes - #185

Merged
Yuval-Ariel merged 1 commit into
mainfrom
155-proactive-WBM-flushes
Dec 20, 2022
Merged

155 proactive wbm flushes#185
Yuval-Ariel merged 1 commit into
mainfrom
155-proactive-WBM-flushes

Conversation

@udi-speedb

Copy link
Copy Markdown
Contributor

@isaac-io - This is a preliminary version not yet ready.
However, due to the time pressure, I would really appreciate your review.
Please focus on the production code parts and leave the unit testing part for later.
Thanks

@udi-speedb
udi-speedb requested a review from isaac-io September 29, 2022 10:34
@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch from 6ec1112 to 1be56d4 Compare September 29, 2022 10:35
Comment thread db/db_impl/db_impl_compaction_flush.cc Outdated
Comment thread db/db_impl/db_impl_write.cc Outdated
Comment thread include/rocksdb/listener.h Outdated
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc Outdated
Comment thread memtable/write_buffer_manager.cc Outdated
Comment thread db/db_impl/db_impl_compaction_flush.cc Outdated
Comment thread include/rocksdb/write_buffer_manager.h Outdated
Comment thread include/rocksdb/write_buffer_manager.h Outdated
Comment thread include/rocksdb/write_buffer_manager.h Outdated
@isaac-io
isaac-io force-pushed the main branch 3 times, most recently from 8c57b5d to b2f914c Compare October 26, 2022 13:37
@Guyme Guyme linked an issue Nov 16, 2022 that may be closed by this pull request
@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch 2 times, most recently from 3914832 to ab80cfe Compare November 30, 2022 09:22
@ayulas
ayulas self-requested a review December 5, 2022 04:11
@ayulas

ayulas commented Dec 5, 2022

Copy link
Copy Markdown
Contributor

i left some comments. part of isaac i also thinks but i. didnt repeat

@udi-speedb

udi-speedb commented Dec 5, 2022

Copy link
Copy Markdown
Contributor Author

i left some comments. part of isaac i also thinks but i. didnt repeat

@ayulas - I do not see any comment you have made.

Do you agree with all of Isaac's comments?

@udi-speedb
udi-speedb requested a review from hilikspdb December 5, 2022 04:32
@udi-speedb

Copy link
Copy Markdown
Contributor Author

@hilikspdb - I have added you as a reviewer as well as you are the original designer of the feature and your inputs would be helpful

@ayulas

ayulas commented Dec 5, 2022

Copy link
Copy Markdown
Contributor

ayulas started a review
Pending
memtable/write_buffer_manager.cc
memory_used_.fetch_add(mem, std::memory_order_relaxed);
new_memory_used = ReserveMemWithCache(mem);
} else if (is_enabled) {
auto old_memory_used =
Member
@ayulas ayulas Pending
why we need ReserveMemWithCache to return a value. the ReserveMemWithCache inside set the memory_used_... so why not just in the ShouldInitiateAnotherFlushMemOnly scope not just load the current
memory_used_?

@ayulas Reply...
memtable/write_buffer_manager.cc
#ifndef ROCKSDB_LITE
assert(cache_res_mgr_ != nullptr);
// Use a mutex to protect various data structures. Can be optimized to a
// lock-free solution if it ends up with a performance bottleneck.
std::lock_guardstd::mutex lock(cache_res_mgr_mu_);

size_t new_mem_used = memory_used_.load(std::memory_order_relaxed) + mem;
size_t old_mem_used = memory_used_.load(std::memory_order_relaxed);
Member
@ayulas ayulas Pending
again why you change the current code?

@ayulas Reply...
memtable/write_buffer_manager.cc
} else if (is_enabled) {
[[maybe_unused]] const auto curr_memory_used =
auto old_memory_used =
Member
@ayulas ayulas Pending
as i mention up... why FreeMemWithCache return a value.... you can use load memory_used_ in
ShouldInitiateAnotherFlushMemOnly scope

@ayulas Reply...
memtable/write_buffer_manager.cc
std::unique_lockstd::mutex lock(flushes_initiators_mu_);
assert(IsInitiatorIdxValid(FindInitiator(initiator)) == false);
flush_initiators_.push_back({initiator, request});
num_initiators_ = flush_initiators_.size();
Member
@ayulas ayulas Pending
why you need num_initiators_ at all and not use the flush_initiators_.size() directly?

@ayulas Reply...
memtable/write_buffer_manager.cc
assert(IsInitiatorIdxValid(initiator_idx));

flush_initiators_.erase(flush_initiators_.begin() + initiator_idx);
num_initiators_ = flush_initiators_.size();

Member
@ayulas ayulas Pending
as previous comment

@ayulas Reply...
memtable/write_buffer_manager.cc
InstrumentedMutexUnlock flushes_mu_unlocker(flushes_mu_.get());

      std::unique_lock<std::mutex> initiators_lock(flushes_initiators_mu_);
      assert(next_candidate_initiator_idx_ < flush_initiators_.size());

Member
@ayulas ayulas Pending
the next_candidate_initiator_idx_ is calculate in the CalcNextCandidateInitiatorIdx function that do a module on
flush_initiators_ size so of course if you deregister a DB initiator from the flush_initiators_ container you might have an idx that is equal to the flush_initiators_ size.....
for example you have 3 DBs
the current flush one is idx 1 next is 2 now you deregister idx 1 , next_candidate_initiator_idx_ is 2 (eventhough its not really cause you erase idx 1.. so you will get this assert... i think that the use vector - push and erase depends on insertion vector idx ( next_candidate_initiator_idx_)is a bug

@ayulas Reply...
memtable/write_buffer_manager.cc
// increment & decrement cancel each other with respect to the recalc
++num_running_flushes_;
--num_flushes_to_initiate_;
was_flush_initiated = initiator.cb(kMinFlushSizes[iter]);
Member
@ayulas ayulas Pending
what happened if we have DB that has 2 CFs 1 CFs did small writes and it doesnt do any more. the second CF writes a lot . so it is the massive memory to free. so in that case the second CF memtable will be switch and new LOG (wal file) will be created but the old wal couldn never be released since the CF1 memtable is not going to be collected to be flushed....

Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc Outdated
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc Outdated
Comment thread memtable/write_buffer_manager.cc Outdated
Comment thread memtable/write_buffer_manager.cc Outdated
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc Outdated
@udi-speedb

Copy link
Copy Markdown
Contributor Author

@ayulas - Thanks a lot for the review.

@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch from 8b8945f to 7fcb1d5 Compare December 6, 2022 17:14
Comment thread memtable/write_buffer_manager.cc Outdated
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc Outdated
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc Outdated
Comment thread memtable/write_buffer_manager.cc
Comment thread memtable/write_buffer_manager.cc Outdated
@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch 2 times, most recently from 48b35f3 to 7cdde80 Compare December 7, 2022 17:22
@udi-speedb
udi-speedb removed the request for review from hilikspdb December 7, 2022 18:00
@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch from a748982 to 5362658 Compare December 7, 2022 18:15
@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch 3 times, most recently from ca21af4 to ab70b29 Compare December 11, 2022 13:32
Comment thread db/db_impl/db_impl_compaction_flush.cc Outdated
}
}

if (cfds.empty()) {

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.

actually you should be protected with the
if (total_size_to_flush < min_size_to_flush) {
return false;
}
cause in case no cfds in DB the total_size_to_flush should be 0 so it menas you passed min_size_to_flush 0 and this is a bug... (not related to this )
second i would have cgecked this after taking the InstrumentedMutexLock

@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch from ba91619 to 89d32dd Compare December 12, 2022 14:34
@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch 2 times, most recently from 58ac961 to d333a3f Compare December 12, 2022 19:18
@udi-speedb

Copy link
Copy Markdown
Contributor Author

@Yuval-Ariel - Please run full QA on this branch. Thanks

@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch from 915d071 to a9219b1 Compare December 13, 2022 14:21
{
InstrumentedMutexLock lock(&mutex_);
SelectColumnFamiliesForAtomicFlush(&cfds);

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.

why not check if cfds is empty here and return? why move on?
also as i mention in previous review comment - eventhough you the cfds is not empty if all cfds are with no data you should have exit in total_size_to_flush < min_size_to_flush. so if you needed protect this you have a bug that min_size_to_flush is 0


{
InstrumentedMutexLock lock(&mutex_);

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.

again exit immediately if cfds is empty...

orig_cfd_to_flush = cfd_to_flush;

// A CF was picked. Now see if it should be replaced with a lagging CF
for (auto* cfd : *versions_->GetColumnFamilySet()) {

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.

why you created 2 loops?? you can do it in 1

@udi-speedb

Copy link
Copy Markdown
Contributor Author

@ayulas - I have pushed the changes we have discussed over zoom.
Please take a look and approve the PR so @Yuval-Ariel may start QA.
@yuval - Before you start the QA, please let me know and I will both rebase on latest origin/main and squash all of the commits. Thanks

@ayulas

ayulas commented Dec 18, 2022

Copy link
Copy Markdown
Contributor

i approve. @Yuval-Ariel go ahead

@udi-speedb
udi-speedb force-pushed the 155-proactive-WBM-flushes branch from 5e61136 to 1eaa4f4 Compare December 18, 2022 13:55
@Yuval-Ariel
Yuval-Ariel self-requested a review December 18, 2022 13:56
@Yuval-Ariel
Yuval-Ariel force-pushed the 155-proactive-WBM-flushes branch from 1eaa4f4 to c8d2420 Compare December 18, 2022 19:20
@Yuval-Ariel
Yuval-Ariel merged commit e097334 into main Dec 20, 2022
@Yuval-Ariel
Yuval-Ariel deleted the 155-proactive-WBM-flushes branch May 11, 2023 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WriteBufferManager: proactively initate flush requests when nearing quota

4 participants