summaryrefslogtreecommitdiff
path: root/src/mongo/db/operation_context.h
diff options
context:
space:
mode:
authorAndy Schwerin <schwerin@mongodb.com>2015-05-22 15:24:52 -0400
committerAndy Schwerin <schwerin@mongodb.com>2015-05-29 10:28:03 -0400
commit4ea38c308da292f43e29d32b1b53b7324db0bafe (patch)
tree22d166a388262ae5837d0c4e44f42748194e3e47 /src/mongo/db/operation_context.h
parent5c2d133871b2ad2adf6c617364d036ca25261f2d (diff)
downloadmongo-4ea38c308da292f43e29d32b1b53b7324db0bafe.tar.gz
SERVER-14995 Move operation id, lockState and client fields to OperationContext.
They have been moved from OperationContextImpl. Furthermore, the CurOp stack is now attached to OperationContext, instead of Client. With this change, an operation's lifetime is governed by the lifetime of an OperationContext object. The "_active" field of CurOp is therefore no longer meaingful. This required fixing the lifetime of OperationContext in a few places. A future change will adjust operation lifetime timing to time the lifetime of the OperationContext object, as well.
Diffstat (limited to 'src/mongo/db/operation_context.h')
-rw-r--r--src/mongo/db/operation_context.h23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/mongo/db/operation_context.h b/src/mongo/db/operation_context.h
index 0717745e858..e3c28ef2c05 100644
--- a/src/mongo/db/operation_context.h
+++ b/src/mongo/db/operation_context.h
@@ -31,7 +31,6 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/base/status.h"
#include "mongo/db/storage/recovery_unit.h"
-#include "mongo/db/concurrency/locker.h"
#include "mongo/db/concurrency/d_concurrency.h"
#include "mongo/db/write_concern_options.h"
#include "mongo/util/decorable.h"
@@ -40,6 +39,7 @@ namespace mongo {
class Client;
class CurOp;
+ class Locker;
class ProgressMeter;
class StringData;
class WriteUnitOfWork;
@@ -68,7 +68,7 @@ namespace mongo {
kFailedUnitOfWork // in a unit of work that has failed and must be aborted
};
- virtual ~OperationContext() { }
+ virtual ~OperationContext() = default;
/**
* Interface for durability. Caller DOES NOT own pointer.
@@ -101,7 +101,7 @@ namespace mongo {
/**
* Interface for locking. Caller DOES NOT own pointer.
*/
- virtual Locker* lockState() const = 0;
+ Locker* lockState() const { return _locker; }
// --- operation level info? ---
@@ -132,16 +132,14 @@ namespace mongo {
/**
* Returns the client under which this context runs.
*/
- virtual Client* getClient() const = 0;
+ Client* getClient() const;
virtual uint64_t getRemainingMaxTimeMicros() const = 0;
/**
* Returns the operation ID associated with this operation.
- * WARNING: Due to SERVER-14995, this OpID is not guaranteed to stay the same for the
- * lifetime of this OperationContext.
*/
- virtual unsigned int getOpID() const = 0;
+ unsigned int getOpID() const { return _opId; }
/**
* @return true if this instance is primary for this namespace
@@ -170,12 +168,21 @@ namespace mongo {
virtual bool writesAreReplicated() const = 0;
protected:
- OperationContext() { }
+ OperationContext(Client* client,
+ unsigned int opId,
+ Locker* locker);
RecoveryUnitState _ruState = kNotInUnitOfWork;
private:
friend class WriteUnitOfWork;
+ Client* const _client;
+ const unsigned int _opId;
+
+ // The lifetime of locker is managed by subclasses of OperationContext, so it is not
+ // safe to access _locker in the destructor of OperationContext.
+ Locker* const _locker;
+
WriteConcernOptions _writeConcern;
};