Storage Engine API
locker_noop.h
Go to the documentation of this file.
1 
29 #pragma once
30 
32 
33 namespace mongo {
34 
40 class LockerNoop : public Locker {
41 public:
43 
44  virtual bool isNoop() const {
45  return true;
46  }
47 
48  virtual ClientState getClientState() const {
49  MONGO_UNREACHABLE;
50  }
51 
52  virtual LockerId getId() const {
53  MONGO_UNREACHABLE;
54  }
55 
56  stdx::thread::id getThreadId() const override {
57  MONGO_UNREACHABLE;
58  }
59 
61  MONGO_UNREACHABLE;
62  }
63 
64  void unsetThreadId() override {
65  MONGO_UNREACHABLE;
66  }
67 
68  void setSharedLocksShouldTwoPhaseLock(bool sharedLocksShouldTwoPhaseLock) override {
69  MONGO_UNREACHABLE;
70  }
71 
72  void setMaxLockTimeout(Milliseconds maxTimeout) override {
73  MONGO_UNREACHABLE;
74  }
75 
76  bool hasMaxLockTimeout() override {
77  MONGO_UNREACHABLE;
78  }
79 
80  void unsetMaxLockTimeout() override {
81  MONGO_UNREACHABLE;
82  }
83 
84  virtual LockResult lockGlobal(OperationContext* opCtx, LockMode mode) {
85  MONGO_UNREACHABLE;
86  }
87 
88  virtual LockResult lockGlobal(LockMode mode) {
89  MONGO_UNREACHABLE;
90  }
91 
92  virtual LockResult lockGlobalBegin(OperationContext* opCtx, LockMode mode, Date_t deadline) {
93  MONGO_UNREACHABLE;
94  }
95 
96  virtual LockResult lockGlobalBegin(LockMode mode, Date_t deadline) {
97  MONGO_UNREACHABLE;
98  }
99 
100  virtual LockResult lockGlobalComplete(OperationContext* opCtx, Date_t deadline) {
101  MONGO_UNREACHABLE;
102  }
103 
104  virtual LockResult lockGlobalComplete(Date_t deadline) {
105  MONGO_UNREACHABLE;
106  }
107 
108  virtual void lockMMAPV1Flush() {
109  MONGO_UNREACHABLE;
110  }
111 
112  virtual bool unlockGlobal() {
113  MONGO_UNREACHABLE;
114  }
115 
117  MONGO_UNREACHABLE;
118  }
119 
120  virtual void beginWriteUnitOfWork() {}
121 
122  virtual void endWriteUnitOfWork() {}
123 
124  virtual bool inAWriteUnitOfWork() const {
125  MONGO_UNREACHABLE;
126  }
127 
128  virtual LockResult lock(OperationContext* opCtx,
129  ResourceId resId,
130  LockMode mode,
131  Date_t deadline,
132  bool checkDeadlock) {
133  return LockResult::LOCK_OK;
134  }
135 
136  virtual LockResult lock(ResourceId resId, LockMode mode, Date_t deadline, bool checkDeadlock) {
137  return LockResult::LOCK_OK;
138  }
139 
140  virtual void downgrade(ResourceId resId, LockMode newMode) {
141  MONGO_UNREACHABLE;
142  }
143 
144  virtual bool unlock(ResourceId resId) {
145  return true;
146  }
147 
148  virtual LockMode getLockMode(ResourceId resId) const {
149  MONGO_UNREACHABLE;
150  }
151 
152  virtual bool isLockHeldForMode(ResourceId resId, LockMode mode) const {
153  return true;
154  }
155 
156  virtual bool isDbLockedForMode(StringData dbName, LockMode mode) const {
157  return true;
158  }
159 
160  virtual bool isCollectionLockedForMode(StringData ns, LockMode mode) const {
161  return true;
162  }
163 
164  virtual ResourceId getWaitingResource() const {
165  MONGO_UNREACHABLE;
166  }
167 
168  virtual void getLockerInfo(LockerInfo* lockerInfo) const {
169  MONGO_UNREACHABLE;
170  }
171 
172  virtual boost::optional<LockerInfo> getLockerInfo() const {
173  return boost::none;
174  }
175 
176  virtual bool saveLockStateAndUnlock(LockSnapshot* stateOut) {
177  MONGO_UNREACHABLE;
178  }
179 
180  virtual void restoreLockState(OperationContext* opCtx, const LockSnapshot& stateToRestore) {
181  MONGO_UNREACHABLE;
182  }
183  virtual void restoreLockState(const LockSnapshot& stateToRestore) {
184  MONGO_UNREACHABLE;
185  }
186 
187  virtual void releaseTicket() {
188  MONGO_UNREACHABLE;
189  }
190 
191  virtual void reacquireTicket(OperationContext* opCtx) {
192  MONGO_UNREACHABLE;
193  }
194 
195  virtual void dump() const {
196  MONGO_UNREACHABLE;
197  }
198 
199  virtual bool isW() const {
200  MONGO_UNREACHABLE;
201  }
202 
203  virtual bool isR() const {
204  MONGO_UNREACHABLE;
205  }
206 
207  virtual bool isLocked() const {
208  // This is necessary because replication makes decisions based on the answer to this, and
209  // we wrote unit tests to test the behavior specifically when this returns "false".
210  return false;
211  }
212 
213  virtual bool isWriteLocked() const {
214  return true;
215  }
216 
217  virtual bool isReadLocked() const {
218  return true;
219  }
220 
221  virtual bool hasLockPending() const {
222  MONGO_UNREACHABLE;
223  }
224 
225  bool isGlobalLockedRecursively() override {
226  return false;
227  }
228 };
229 
230 } // namespace mongo
virtual bool hasLockPending() const
Pending means we are currently trying to get a lock (could be the parallel batch writer lock)...
Definition: locker_noop.h:221
Interface for acquiring locks.
Definition: locker.h:47
void unsetMaxLockTimeout() override
Clears the max lock timeout override set by setMaxLockTimeout() above.
Definition: locker_noop.h:80
virtual void reacquireTicket(OperationContext *opCtx)
Reacquires a ticket for the Locker.
Definition: locker_noop.h:191
virtual LockResult lockGlobalComplete(Date_t deadline)
Definition: locker_noop.h:104
Collection *const const NamespaceString & ns
Definition: collection_info_cache_impl.cpp:53
virtual bool isDbLockedForMode(StringData dbName, LockMode mode) const
Definition: locker_noop.h:156
virtual void downgrade(ResourceId resId, LockMode newMode)
Downgrades the specified resource&#39;s lock mode without changing the reference count.
Definition: locker_noop.h:140
virtual bool unlockGlobal()
Decrements the reference count on the global lock.
Definition: locker_noop.h:112
Copyright (C) 2014 MongoDB Inc.
Definition: bson_collection_catalog_entry.cpp:38
virtual bool isR() const
Definition: locker_noop.h:203
uint64_t LockerId
Definition: lock_manager_defs.h:246
virtual void getLockerInfo(LockerInfo *lockerInfo) const
Definition: locker_noop.h:168
virtual LockResult lockGlobal(LockMode mode)
Definition: locker_noop.h:88
Returns information and locking statistics for this instance of the locker.
Definition: locker.h:319
virtual void dump() const
Definition: locker_noop.h:195
virtual LockMode getLockMode(ResourceId resId) const
Retrieves the mode in which a lock is held or checks whether the lock held for a particular resource ...
Definition: locker_noop.h:148
Uniquely identifies a lockable resource.
Definition: lock_manager_defs.h:176
virtual void endWriteUnitOfWork()
Definition: locker_noop.h:122
virtual LockResult lock(OperationContext *opCtx, ResourceId resId, LockMode mode, Date_t deadline, bool checkDeadlock)
Acquires lock on the specified resource in the specified mode and returns the outcome of the operatio...
Definition: locker_noop.h:128
virtual LockerId getId() const
Definition: locker_noop.h:52
virtual LockResult lockGlobalBegin(LockMode mode, Date_t deadline)
Definition: locker_noop.h:96
virtual bool isNoop() const
Returns true if this is an instance of LockerNoop.
Definition: locker_noop.h:44
void setMaxLockTimeout(Milliseconds maxTimeout) override
This is useful to ensure that potential deadlocks do not occur.
Definition: locker_noop.h:72
LockResult
Return values for the locking functions of the lock manager.
Definition: lock_manager_defs.h:99
LockMode
Lock modes.
Definition: lock_manager_defs.h:59
virtual void restoreLockState(OperationContext *opCtx, const LockSnapshot &stateToRestore)
Re-locks all locks whose state was stored in &#39;stateToRestore&#39;.
Definition: locker_noop.h:180
virtual void releaseTicket()
Releases the ticket associated with the Locker.
Definition: locker_noop.h:187
ClientState
State for reporting the number of active and queued reader and writer clients.
Definition: locker.h:79
virtual boost::optional< LockerInfo > getLockerInfo() const
Returns boost::none if this is an instance of LockerNoop, or a populated LockerInfo otherwise...
Definition: locker_noop.h:172
virtual void beginWriteUnitOfWork()
beginWriteUnitOfWork/endWriteUnitOfWork are called at the start and end of WriteUnitOfWorks.
Definition: locker_noop.h:120
virtual void restoreLockState(const LockSnapshot &stateToRestore)
Definition: locker_noop.h:183
virtual LockResult lockGlobalBegin(OperationContext *opCtx, LockMode mode, Date_t deadline)
Requests the global lock to be acquired in the specified mode.
Definition: locker_noop.h:92
virtual bool isWriteLocked() const
Definition: locker_noop.h:213
LockerNoop()
Definition: locker_noop.h:42
virtual bool isLocked() const
Definition: locker_noop.h:207
virtual bool isLockHeldForMode(ResourceId resId, LockMode mode) const
Definition: locker_noop.h:152
The lock request was granted and is now on the granted list for the specified resource.
Definition: lock_manager_defs.h:104
stdx::thread::id getThreadId() const override
Get a platform-specific thread identifier of the thread which owns the this locker for tracing purpos...
Definition: locker_noop.h:56
virtual ResourceId getWaitingResource() const
Returns the resource that this locker is waiting/blocked on (if any).
Definition: locker_noop.h:164
virtual ClientState getClientState() const
Return whether client is holding any locks (active), or is queued on any locks or waiting for a ticke...
Definition: locker_noop.h:48
virtual LockResult lock(ResourceId resId, LockMode mode, Date_t deadline, bool checkDeadlock)
Calling lock without an OperationContext does not allow LOCK_WAITING states to be interrupted...
Definition: locker_noop.h:136
virtual bool saveLockStateAndUnlock(LockSnapshot *stateOut)
Retrieves all locks held by this transaction, other than RESOURCE_MUTEX locks, and what mode they&#39;re ...
Definition: locker_noop.h:176
virtual bool isCollectionLockedForMode(StringData ns, LockMode mode) const
Definition: locker_noop.h:160
virtual LockResult lockGlobalComplete(OperationContext *opCtx, Date_t deadline)
Calling lockGlobalComplete without an OperationContext does not allow the lock acquisition to be inte...
Definition: locker_noop.h:100
virtual bool unlock(ResourceId resId)
Releases a lock previously acquired through a lock call.
Definition: locker_noop.h:144
LockSnapshot captures the state of all resources that are locked, what modes they&#39;re locked in...
Definition: locker.h:342
virtual LockResult lockGlobal(OperationContext *opCtx, LockMode mode)
This should be the first method invoked for a particular Locker object.
Definition: locker_noop.h:84
virtual void lockMMAPV1Flush()
This method is used only in the MMAP V1 storage engine, otherwise it is a no-op.
Definition: locker_noop.h:108
bool hasMaxLockTimeout() override
Returns whether this Locker has a maximum lock timeout set.
Definition: locker_noop.h:76
virtual bool inAWriteUnitOfWork() const
Definition: locker_noop.h:124
void updateThreadIdToCurrentThread() override
Updates any cached thread id values to represent the current thread.
Definition: locker_noop.h:60
Collection *const OperationContext *const opCtx
Definition: collection_impl.cpp:80
Locker, which cannot be used to lock/unlock resources and just returns true for checks for whether a ...
Definition: locker_noop.h:40
void unsetThreadId() override
Clears any cached thread id values.
Definition: locker_noop.h:64
virtual bool isW() const
Definition: locker_noop.h:199
virtual void downgradeGlobalXtoSForMMAPV1()
This is only necessary for the MMAP V1 engine and in particular, the fsyncLock command which needs to...
Definition: locker_noop.h:116
void setSharedLocksShouldTwoPhaseLock(bool sharedLocksShouldTwoPhaseLock) override
Indicate that shared locks should participate in two-phase locking for this Locker instance...
Definition: locker_noop.h:68
virtual bool isReadLocked() const
Definition: locker_noop.h:217
bool isGlobalLockedRecursively() override
Definition: locker_noop.h:225