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

[refactor] CurveBS: add some common functions #2826

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
32 changes: 28 additions & 4 deletions src/chunkserver/concurrent_apply/concurrent_apply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,11 @@ void ConcurrentApplyModule::Run(ApplyTaskType type, int index) {
}

void ConcurrentApplyModule::Stop() {
if (!start_.exchange(false)) {
return;
}

LOG(INFO) << "stop ConcurrentApplyModule...";
start_ = false;
auto wakeup = []() {};
for (auto iter : rapplyMap_) {
iter.second->tq.Push(wakeup);
Expand All @@ -145,15 +148,36 @@ void ConcurrentApplyModule::Stop() {
}

void ConcurrentApplyModule::Flush() {
if (!start_.load(std::memory_order_relaxed)) {
return;
}

CountDownEvent event(wconcurrentsize_);
auto flushtask = [&event]() {
event.Signal();
};
auto flushtask = [&event]() { event.Signal(); };

for (int i = 0; i < wconcurrentsize_; i++) {
wapplyMap_[i]->tq.Push(flushtask);
}

event.Wait();
}

void ConcurrentApplyModule::FlushAll() {
if (!start_.load(std::memory_order_relaxed)) {
return;
}

CountDownEvent event(wconcurrentsize_ + rconcurrentsize_);
auto flushtask = [&event]() { event.Signal(); };

for (int i = 0; i < wconcurrentsize_; i++) {
wapplyMap_[i]->tq.Push(flushtask);
}

for (int i = 0; i < rconcurrentsize_; i++) {
rapplyMap_[i]->tq.Push(flushtask);
}

event.Wait();
}

Expand Down
3 changes: 2 additions & 1 deletion src/chunkserver/concurrent_apply/concurrent_apply.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class CURVE_CACHELINE_ALIGNMENT ConcurrentApplyModule {
* Flush: finish all task in write threads
*/
void Flush();
void FlushAll();

void Stop();

Expand All @@ -128,7 +129,7 @@ class CURVE_CACHELINE_ALIGNMENT ConcurrentApplyModule {
explicit TaskThread(size_t capacity) : tq(capacity) {}
};

bool start_;
std::atomic<bool> start_;
int rconcurrentsize_;
int rqueuedepth_;
int wconcurrentsize_;
Expand Down