diff options
author | Håvard Pettersen <havardpe@yahooinc.com> | 2022-05-24 10:04:14 +0000 |
---|---|---|
committer | Håvard Pettersen <havardpe@yahooinc.com> | 2022-05-24 10:07:17 +0000 |
commit | ad73f43f0bfe2c59009c024065c7b25192cadc29 (patch) | |
tree | afd57dd859d6d8f0ad1f928ae07031ac6bf76b1c /storage | |
parent | f3c40af9152d7c6eb9616073626551cef258a52d (diff) |
use separate lock for stats
Diffstat (limited to 'storage')
-rw-r--r-- | storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.cpp | 10 | ||||
-rw-r--r-- | storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.h | 21 |
2 files changed, 25 insertions, 6 deletions
diff --git a/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.cpp b/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.cpp index a6b3a028512..df1c0de36cc 100644 --- a/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.cpp +++ b/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.cpp @@ -1183,7 +1183,7 @@ FileStorHandlerImpl::Stripe::release(const document::Bucket & bucket, } Clock::time_point now_ts = Clock::now(); double latency = std::chrono::duration<double, std::milli>(now_ts - start_time).count(); - _active_operations_stats.operation_done(latency); + _active_operations_stats.guard().stats().operation_done(latency); if (!entry._exclusiveLock && entry._sharedLocks.empty()) { _lockedBuckets.erase(iter); // No more locks held } @@ -1221,7 +1221,7 @@ FileStorHandlerImpl::Stripe::lock(const monitor_guard &, const document::Bucket (void) inserted; assert(inserted.second); } - _active_operations_stats.operation_started(); + _active_operations_stats.guard().stats().operation_started(); } bool @@ -1259,10 +1259,10 @@ FileStorHandlerImpl::Stripe::operationIsInhibited(const monitor_guard & guard, c ActiveOperationsStats FileStorHandlerImpl::Stripe::get_active_operations_stats(bool reset_min_max) const { - std::lock_guard guard(*_lock); - auto result = _active_operations_stats; + auto guard = _active_operations_stats.guard(); + auto result = guard.stats(); if (reset_min_max) { - _active_operations_stats.reset_min_max(); + guard.stats().reset_min_max(); } return result; } diff --git a/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.h b/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.h index c4b229418a1..a3667e93fff 100644 --- a/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.h +++ b/storage/src/vespa/storage/persistence/filestorage/filestorhandlerimpl.h @@ -98,6 +98,25 @@ public: SharedLocks _sharedLocks; }; + class SafeActiveOperationsStats { + private: + std::unique_ptr<std::mutex> _lock; + ActiveOperationsStats _stats; + struct ctor_tag {}; + public: + class Guard { + private: + std::lock_guard<std::mutex> _guard; + ActiveOperationsStats &_stats; + public: + Guard(Guard &&) = delete; + Guard(std::mutex &lock, ActiveOperationsStats &stats_in, ctor_tag) : _guard(lock), _stats(stats_in) {} + ActiveOperationsStats &stats() { return _stats; } + }; + SafeActiveOperationsStats() : _lock(std::make_unique<std::mutex>()), _stats() {} + Guard guard() { return Guard(*_lock, _stats, ctor_tag()); } + }; + Stripe(const FileStorHandlerImpl & owner, MessageSender & messageSender); Stripe(Stripe &&) noexcept; Stripe(const Stripe &) = delete; @@ -170,7 +189,7 @@ public: atomic_size_t _cached_queue_size; LockedBuckets _lockedBuckets; uint32_t _active_merges; - mutable ActiveOperationsStats _active_operations_stats; + mutable SafeActiveOperationsStats _active_operations_stats; }; class BucketLock : public FileStorHandler::BucketLockInterface { |