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

Commit

Permalink
Feature/backport pool (#576)
Browse files Browse the repository at this point in the history
* Feature/use nonpriority pool (#570)

* new thread pool

* fix

* wip

* add static

* attempt to fix compile warning (#569)

the compile option `-fsized-deallocation` should only be used for C++
code, but not for C code. otherwise clang warns with the following
message:
```
warning: command-line option ‘-fsized-deallocation’ is valid for C++/ObjC++ but not for C
```

* Improve thread pool (#571)

* WIP

* WIP

* WIP

* WIP

* Update core/utils/async_utils.cpp

* Separate WaitGroup (#572)

* Separate WaitGroup

* Update core/utils/wait_group.hpp

Co-authored-by: Andrei Lobov <andrei.lobov@arangodb.com>

* Exact count

* fix lints

---------

Co-authored-by: Andrei Lobov <andrei.lobov@arangodb.com>

* Backport and start

* fix

* fix datarace

* fix build

---------

Co-authored-by: Jan <jsteemann@users.noreply.github.com>
Co-authored-by: Valery Mironov <32071355+MBkkt@users.noreply.github.com>
  • Loading branch information
3 people authored Nov 23, 2023
1 parent 43f6ba1 commit 7f3ab26
Show file tree
Hide file tree
Showing 14 changed files with 516 additions and 662 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ if (MSVC)
set(CMAKE_C_FLAGS "/Zc:static_assert- ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "/Zc:static_assert- ${CMAKE_CXX_FLAGS}")
endif ()
else ()
# We want to force clang/gcc to use it, but only for C++ files
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-fsized-deallocation>)
endif ()

# fix strange issue with utf_8_to_32_iterator failing
Expand Down
9 changes: 2 additions & 7 deletions core/index/index_writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1197,9 +1197,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 @@ -1805,11 +1803,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
32 changes: 2 additions & 30 deletions core/index/index_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "utils/object_pool.hpp"
#include "utils/string.hpp"
#include "utils/thread_utils.hpp"
#include "utils/wait_group.hpp"

#include <absl/container/flat_hash_map.h>

Expand Down Expand Up @@ -835,36 +836,7 @@ class IndexWriter : private util::noncopyable {
std::deque<PendingSegmentContext> pending_segments_;
// entries from 'pending_segments_' that are available for reuse
Freelist pending_freelist_;
// TODO(MBkkt) Considered to replace with YACLib in ArangoDB 3.11+ or ...
struct WaitGroup {
std::mutex& Mutex() noexcept { return m_; }

void Add() noexcept { counter_.fetch_add(1, std::memory_order_relaxed); }

void Done() noexcept {
if (counter_.fetch_sub(1, std::memory_order_acq_rel) == 1) {
std::lock_guard lock{m_};
cv_.notify_one();
}
}

void Wait(std::unique_lock<std::mutex>& lock) noexcept {
IRS_ASSERT(lock.mutex() == &m_);
IRS_ASSERT(lock.owns_lock());
if (counter_.fetch_sub(1, std::memory_order_acq_rel) != 1) {
do {
cv_.wait(lock);
// relaxed probably enough
} while (counter_.load(std::memory_order_acquire) != 0);
}
counter_.store(1, std::memory_order_relaxed);
}

private:
std::atomic_size_t counter_{1};
std::mutex m_;
std::condition_variable cv_;
} pending_;
WaitGroup pending_;

// set of segments to be removed from the index upon commit
ConsolidatingSegments segment_mask_;
Expand Down
Loading

0 comments on commit 7f3ab26

Please sign in to comment.