diff options
Diffstat (limited to 'src/mongo/s/catalog/replset/replset_dist_lock_manager.h')
-rw-r--r-- | src/mongo/s/catalog/replset/replset_dist_lock_manager.h | 166 |
1 files changed, 82 insertions, 84 deletions
diff --git a/src/mongo/s/catalog/replset/replset_dist_lock_manager.h b/src/mongo/s/catalog/replset/replset_dist_lock_manager.h index 4e042e2fa41..1779925b8ec 100644 --- a/src/mongo/s/catalog/replset/replset_dist_lock_manager.h +++ b/src/mongo/s/catalog/replset/replset_dist_lock_manager.h @@ -43,88 +43,86 @@ namespace mongo { - class ServiceContext; - - class ReplSetDistLockManager final : public DistLockManager { - public: - ReplSetDistLockManager(ServiceContext* globalContext, - StringData processID, - std::unique_ptr<DistLockCatalog> catalog, - stdx::chrono::milliseconds pingInterval, - stdx::chrono::milliseconds lockExpiration); - - virtual ~ReplSetDistLockManager(); - - virtual void startUp() override; - virtual void shutDown() override; - - virtual StatusWith<DistLockManager::ScopedDistLock> lock( - StringData name, - StringData whyMessage, - stdx::chrono::milliseconds waitFor, - stdx::chrono::milliseconds lockTryInterval) override; - - protected: - - virtual void unlock(const DistLockHandle& lockSessionID) override; - - virtual Status checkStatus(const DistLockHandle& lockSessionID) override; - - private: - - /** - * Queue a lock to be unlocked asynchronously with retry until it doesn't error. - */ - void queueUnlock(const DistLockHandle& lockSessionID); - - /** - * Periodically pings and checks if there are locks queued that needs unlocking. - */ - void doTask(); - - /** - * Returns true if shutDown was called. - */ - bool isShutDown(); - - /** - * Returns true if the current process that owns the lock has no fresh pings since - * the lock expiration threshold. - */ - StatusWith<bool> canOvertakeLock(const LocksType lockDoc); - - // - // All member variables are labeled with one of the following codes indicating the - // synchronization rules for accessing them. - // - // (F) Self synchronizing. - // (M) Must hold _mutex for access. - // (I) Immutable, no synchronization needed. - // (S) Can only be called inside startUp/shutDown. - // - - ServiceContext* const _serviceContext; // (F) - - const std::string _processID; // (I) - const std::unique_ptr<DistLockCatalog> _catalog; // (I) - const stdx::chrono::milliseconds _pingInterval; // (I) - const stdx::chrono::milliseconds _lockExpiration; // (I) - - stdx::mutex _mutex; - std::unique_ptr<stdx::thread> _execThread; // (S) - - // Contains the list of locks queued for unlocking. Cases when unlock operation can - // be queued include: - // 1. First attempt on unlocking resulted in an error. - // 2. Attempting to grab or overtake a lock resulted in an error where we are uncertain - // whether the modification was actually applied or not, and call unlock to make - // sure that it was cleaned up. - std::deque<DistLockHandle> _unlockList; // (M) - - bool _isShutDown = false; // (M) - stdx::condition_variable _shutDownCV; // (M) - - // Map of lockName to last ping information. - std::unordered_map<std::string, DistLockPingInfo> _pingHistory; // (M) - }; +class ServiceContext; + +class ReplSetDistLockManager final : public DistLockManager { +public: + ReplSetDistLockManager(ServiceContext* globalContext, + StringData processID, + std::unique_ptr<DistLockCatalog> catalog, + stdx::chrono::milliseconds pingInterval, + stdx::chrono::milliseconds lockExpiration); + + virtual ~ReplSetDistLockManager(); + + virtual void startUp() override; + virtual void shutDown() override; + + virtual StatusWith<DistLockManager::ScopedDistLock> lock( + StringData name, + StringData whyMessage, + stdx::chrono::milliseconds waitFor, + stdx::chrono::milliseconds lockTryInterval) override; + +protected: + virtual void unlock(const DistLockHandle& lockSessionID) override; + + virtual Status checkStatus(const DistLockHandle& lockSessionID) override; + +private: + /** + * Queue a lock to be unlocked asynchronously with retry until it doesn't error. + */ + void queueUnlock(const DistLockHandle& lockSessionID); + + /** + * Periodically pings and checks if there are locks queued that needs unlocking. + */ + void doTask(); + + /** + * Returns true if shutDown was called. + */ + bool isShutDown(); + + /** + * Returns true if the current process that owns the lock has no fresh pings since + * the lock expiration threshold. + */ + StatusWith<bool> canOvertakeLock(const LocksType lockDoc); + + // + // All member variables are labeled with one of the following codes indicating the + // synchronization rules for accessing them. + // + // (F) Self synchronizing. + // (M) Must hold _mutex for access. + // (I) Immutable, no synchronization needed. + // (S) Can only be called inside startUp/shutDown. + // + + ServiceContext* const _serviceContext; // (F) + + const std::string _processID; // (I) + const std::unique_ptr<DistLockCatalog> _catalog; // (I) + const stdx::chrono::milliseconds _pingInterval; // (I) + const stdx::chrono::milliseconds _lockExpiration; // (I) + + stdx::mutex _mutex; + std::unique_ptr<stdx::thread> _execThread; // (S) + + // Contains the list of locks queued for unlocking. Cases when unlock operation can + // be queued include: + // 1. First attempt on unlocking resulted in an error. + // 2. Attempting to grab or overtake a lock resulted in an error where we are uncertain + // whether the modification was actually applied or not, and call unlock to make + // sure that it was cleaned up. + std::deque<DistLockHandle> _unlockList; // (M) + + bool _isShutDown = false; // (M) + stdx::condition_variable _shutDownCV; // (M) + + // Map of lockName to last ping information. + std::unordered_map<std::string, DistLockPingInfo> _pingHistory; // (M) +}; } |