summaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-02-01 16:57:01 +0000
committerHenning Baldersheim <balder@yahoo-inc.com>2021-02-01 16:57:01 +0000
commitfc2e1e4cad358de37758fb95a432c8778765f5f1 (patch)
tree4389e7bf358b0b37fce23247b0c9922a90fafcb2 /storage
parent1ee55333e81ce57989f010c1f1e42e8afa8709d9 (diff)
Use conditional notify instead of sleep.
Diffstat (limited to 'storage')
-rw-r--r--storage/src/tests/persistence/filestorage/filestormanagertest.cpp1
-rw-r--r--storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp27
-rw-r--r--storage/src/vespa/storage/persistence/filestorage/filestormanager.h5
3 files changed, 19 insertions, 14 deletions
diff --git a/storage/src/tests/persistence/filestorage/filestormanagertest.cpp b/storage/src/tests/persistence/filestorage/filestormanagertest.cpp
index beecaddf5e4..5a7a4394da4 100644
--- a/storage/src/tests/persistence/filestorage/filestormanagertest.cpp
+++ b/storage/src/tests/persistence/filestorage/filestormanagertest.cpp
@@ -482,6 +482,7 @@ TEST_F(FileStorManagerTest, sync_waits_for_already_started_tasks) {
executor->sync();
syncComplete = true;
});
+ std::this_thread::sleep_for(100us);
EXPECT_FALSE(syncComplete);
gate.countDown();
thread.join();
diff --git a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp
index 38def4f775e..42f9e876eee 100644
--- a/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp
+++ b/storage/src/vespa/storage/persistence/filestorage/filestormanager.cpp
@@ -82,6 +82,8 @@ FileStorManager(const config::ConfigUri & configUri, spi::PersistenceProvider& p
_filestorHandler(),
_sequencedExecutor(),
_executeLock(),
+ _syncCond(),
+ _notifyAfterExecute(false),
_executeCount(0),
_tasksInExecute(),
_closed(false),
@@ -1003,6 +1005,9 @@ void
FileStorManager::TrackExecutedTasks::run() {
std::lock_guard guard(_manager._executeLock);
_manager._tasksInExecute.erase(_serialNum);
+ if (_manager._notifyAfterExecute) {
+ _manager._syncCond.notify_all();
+ }
}
std::unique_ptr<spi::BucketTask>
@@ -1016,28 +1021,26 @@ FileStorManager::execute(const spi::Bucket &bucket, std::unique_ptr<spi::BucketT
return task;
}
+namespace {
bool
-FileStorManager::areTaskCompleteUntil(size_t limit) const
-{
- std::lock_guard guard(_executeLock);
- for (size_t serial : _tasksInExecute) {
+areTasksCompleteUntil(const vespalib::hash_set<size_t> &inFlight, size_t limit) {
+ for (size_t serial : inFlight) {
if (serial < limit) {
return false;
}
}
return true;
}
+}
void
FileStorManager::sync() {
- size_t serialNumLimit;
- {
- std::lock_guard guard(_executeLock);
- serialNumLimit = _executeCount;
- }
- while ( ! areTaskCompleteUntil(serialNumLimit)) {
- std::this_thread::sleep_for(100us);
- }
+ std::unique_lock guard(_executeLock);
+ _notifyAfterExecute = true;
+ _syncCond.wait(guard, [this, limit=_executeCount]() {
+ return areTasksCompleteUntil(_tasksInExecute, limit);
+ });
+ _notifyAfterExecute = false;
}
} // storage
diff --git a/storage/src/vespa/storage/persistence/filestorage/filestormanager.h b/storage/src/vespa/storage/persistence/filestorage/filestormanager.h
index da47ed64f4a..fea1b9c7ea6 100644
--- a/storage/src/vespa/storage/persistence/filestorage/filestormanager.h
+++ b/storage/src/vespa/storage/persistence/filestorage/filestormanager.h
@@ -72,7 +72,9 @@ class FileStorManager : public StorageLinkQueued,
std::shared_ptr<FileStorMetrics> _metrics;
std::unique_ptr<FileStorHandler> _filestorHandler;
std::unique_ptr<vespalib::ISequencedTaskExecutor> _sequencedExecutor;
- mutable std::mutex _executeLock;
+ std::mutex _executeLock;
+ std::condition_variable _syncCond;
+ bool _notifyAfterExecute;
size_t _executeCount;
vespalib::hash_set<size_t> _tasksInExecute;
@@ -82,7 +84,6 @@ class FileStorManager : public StorageLinkQueued,
std::unique_ptr<vespalib::IDestructorCallback> _bucketExecutorRegistration;
ServiceLayerHostInfoReporter _host_info_reporter;
std::unique_ptr<vespalib::IDestructorCallback> _resource_usage_listener_registration;
- bool areTaskCompleteUntil(size_t serialNum) const;
class TrackExecutedTasks;
public:
FileStorManager(const config::ConfigUri &, spi::PersistenceProvider&,