Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

Commit

Permalink
Small refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
MBkkt committed Oct 2, 2023
1 parent e8c0135 commit 862422b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
9 changes: 2 additions & 7 deletions core/index/index_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1204,9 +1204,7 @@ void IndexWriter::Clear(uint64_t tick) {

to_commit.ctx = SwitchFlushContext();
// Ensure there are no active struct update operations
std::unique_lock ctx_lock{to_commit.ctx->pending_.Mutex()};
to_commit.ctx->pending_.Wait(ctx_lock);
ctx_lock.unlock();
to_commit.ctx->pending_.Wait();

Abort(); // Abort any already opened transaction
ApplyFlush(std::move(to_commit));
Expand Down Expand Up @@ -1823,11 +1821,8 @@ IndexWriter::PendingContext IndexWriter::PrepareFlush(const CommitInfo& info) {

// noexcept block: I'm not sure is it really necessary or not
auto ctx = SwitchFlushContext();
// TODO(MBkkt) It looks like lock mutex_ completely unnecessary
// ensure there are no active struct update operations
std::unique_lock lock{ctx->pending_.Mutex()};
ctx->pending_.Wait(lock);
lock.unlock();
ctx->pending_.Wait();
// Stage 0
// wait for any outstanding segments to settle to ensure that any rollbacks
// are properly tracked in 'modification_queries_'
Expand Down
7 changes: 3 additions & 4 deletions core/index/index_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,15 +826,14 @@ class IndexWriter : private util::noncopyable {
}
}

void Wait(std::unique_lock<std::mutex>& lock) noexcept {
IRS_ASSERT(lock.mutex() == &m_);
IRS_ASSERT(lock.owns_lock());
void Wait() noexcept {
if (counter_.fetch_sub(1, std::memory_order_acq_rel) != 1) {
std::unique_lock lock{m_};
do {
cv_.wait(lock);
// relaxed probably enough
} while (counter_.load(std::memory_order_acquire) != 0);
}
// We can put acquire here and remove above, but is it worth?
counter_.store(1, std::memory_order_relaxed);
}

Expand Down

0 comments on commit 862422b

Please sign in to comment.