summaryrefslogtreecommitdiffstats
path: root/searchcore
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2022-02-18 12:35:49 +0000
committerTor Brede Vekterli <vekterli@yahooinc.com>2022-02-18 15:38:33 +0000
commit885dc3a67da33cb21b7770e798a40f66dc803a5d (patch)
tree464cb276bb8d0203d00d257c70a5ba682e24b4b2 /searchcore
parentab9703f0f3ef1101fb5556aba4fb4704b0ac2753 (diff)
Protect cross-thread polled oldest flushed serial number with mutex
Diffstat (limited to 'searchcore')
-rw-r--r--searchcore/src/tests/proton/flushengine/flushengine_test.cpp19
1 files changed, 12 insertions, 7 deletions
diff --git a/searchcore/src/tests/proton/flushengine/flushengine_test.cpp b/searchcore/src/tests/proton/flushengine/flushengine_test.cpp
index 3bff3649634..7e4980277e7 100644
--- a/searchcore/src/tests/proton/flushengine/flushengine_test.cpp
+++ b/searchcore/src/tests/proton/flushengine/flushengine_test.cpp
@@ -118,7 +118,7 @@ public:
search::SerialNum _currentSerial;
uint32_t _pendingDone;
uint32_t _taskDone;
- std::mutex _lock;
+ mutable std::mutex _lock;
vespalib::CountDownLatch _done;
FlushDoneHistory _flushDoneHistory;
@@ -146,7 +146,7 @@ public:
std::vector<IFlushTarget::SP>
getFlushTargets() override {
{
- std::lock_guard<std::mutex> guard(_lock);
+ std::lock_guard guard(_lock);
_pendingDone += _taskDone;
_taskDone = 0;
}
@@ -160,7 +160,7 @@ public:
// Called once by flush engine thread for each task done
void taskDone() {
- std::lock_guard<std::mutex> guard(_lock);
+ std::lock_guard guard(_lock);
++_taskDone;
}
@@ -168,7 +168,7 @@ public:
// added to flush engine and when one or more flush tasks related
// to flush handler have completed.
void flushDone(search::SerialNum oldestSerial) override {
- std::lock_guard<std::mutex> guard(_lock);
+ std::lock_guard guard(_lock);
LOG(info, "SimpleHandler(%s)::flushDone(%" PRIu64 ")", getName().c_str(), oldestSerial);
_oldestSerial = std::max(_oldestSerial, oldestSerial);
_flushDoneHistory.push_back(oldestSerial);
@@ -179,9 +179,14 @@ public:
}
FlushDoneHistory getFlushDoneHistory() {
- std::lock_guard<std::mutex> guard(_lock);
+ std::lock_guard guard(_lock);
return _flushDoneHistory;
}
+
+ [[nodiscard]] search::SerialNum oldest_serial() const noexcept {
+ std::lock_guard guard(_lock);
+ return _oldestSerial;
+ }
};
void WrappedFlushTask::run()
@@ -440,11 +445,11 @@ struct Fixture
using namespace std::chrono_literals;
for (int pass = 0; pass < 600; ++pass) {
std::this_thread::sleep_for(100ms);
- if (handler._oldestSerial == expOldestSerial) {
+ if (handler.oldest_serial() == expOldestSerial) {
break;
}
}
- EXPECT_EQUAL(expOldestSerial, handler._oldestSerial);
+ EXPECT_EQUAL(expOldestSerial, handler.oldest_serial());
}
};