summaryrefslogtreecommitdiff
path: root/src/mongo/db/client.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/client.h')
-rw-r--r--src/mongo/db/client.h64
1 files changed, 31 insertions, 33 deletions
diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h
index f9de90fe203..94a11fb3080 100644
--- a/src/mongo/db/client.h
+++ b/src/mongo/db/client.h
@@ -36,7 +36,6 @@
#pragma once
-#include <boost/noncopyable.hpp>
#include <boost/scoped_ptr.hpp>
#include <boost/thread/thread.hpp>
@@ -54,7 +53,6 @@
namespace mongo {
- class AuthenticationInfo;
class CurOp;
class Collection;
class AbstractMessagingPort;
@@ -104,11 +102,11 @@ namespace mongo {
public:
AutoGetOrCreateDb(OperationContext* txn, StringData ns, LockMode mode);
- Database* getDb() {
+ Database* getDb() const {
return _db;
}
- bool justCreated() {
+ bool justCreated() const {
return _justCreated;
}
@@ -178,7 +176,7 @@ namespace mongo {
* Inits a thread if that thread has not already been init'd, setting the thread name to
* "desc".
*/
- static void initThreadIfNotAlready(const char *desc) {
+ static void initThreadIfNotAlready(const char* desc) {
if (currentClient.get())
return;
initThread(desc);
@@ -198,17 +196,17 @@ namespace mongo {
*/
bool shutdown();
- std::string clientAddress(bool includePort=false) const;
+ std::string clientAddress(bool includePort = false) const;
CurOp* curop() const { return _curOp; }
const std::string& desc() const { return _desc; }
- void setLastOp( OpTime op ) { _lastOp = op; }
+ void setLastOp(OpTime op) { _lastOp = op; }
OpTime getLastOp() const { return _lastOp; }
// Return a reference to the Locker for this client. Client retains ownership.
Locker* getLocker() const { return _locker.get(); }
/* report what the last operation was. used by getlasterror */
- void appendLastOp( BSONObjBuilder& b ) const;
+ void appendLastOp(BSONObjBuilder& b) const;
void reportState(BSONObjBuilder& builder);
// Ensures stability of the client's OperationContext. When the client is locked,
@@ -226,15 +224,19 @@ namespace mongo {
bool isGod() const { return _god; } /* this is for map/reduce writes */
bool setGod(bool newVal) { const bool prev = _god; _god = newVal; return prev; }
- void setRemoteID(const OID& rid) { _remoteId = rid; } // Only used for master/slave
- OID getRemoteID() const { return _remoteId; } // Only used for master/slave
+ // Only used for master/slave
+ void setRemoteID(const OID& rid) { _remoteId = rid; }
+ OID getRemoteID() const { return _remoteId; }
+
ConnectionId getConnectionId() const { return _connectionId; }
bool isFromUserConnection() const { return _connectionId > 0; }
private:
- Client(const std::string& desc, AbstractMessagingPort *p = 0);
friend class CurOp;
+ Client(const std::string& desc, AbstractMessagingPort *p = 0);
+
+
// Description for the client (e.g. conn8)
const std::string _desc;
@@ -262,16 +264,19 @@ namespace mongo {
// Used by replication
OpTime _lastOp;
- OID _remoteId; // Only used by master-slave
+
+ // Only used by master-slave
+ OID _remoteId;
// Tracks if Client::shutdown() gets called (TODO: Is this necessary?)
bool _shutdown;
public:
- /* Set database we want to use, then, restores when we finish (are out of scope)
- Note this is also helpful if an exception happens as the state if fixed up.
- */
+ /**
+ * Opens the database that we want to use and sets the appropriate namespace on the
+ * current operation.
+ */
class Context {
MONGO_DISALLOW_COPYING(Context);
public:
@@ -295,26 +300,18 @@ namespace mongo {
Context(OperationContext* txn, const std::string& ns, Database * db);
~Context();
- Client* getClient() const { return _client; }
+
Database* db() const { return _db; }
- const char * ns() const { return _ns.c_str(); }
+ const char* ns() const { return _ns.c_str(); }
/** @return if the db was created by this Context */
bool justCreated() const { return _justCreated; }
- /** call before unlocking, so clear any non-thread safe state
- * _db gets restored on the relock
- */
- void unlocked() { _db = 0; }
-
- /** call after going back into the lock, will re-establish non-thread safe stuff */
- void relocked() { _finishInit(); }
-
private:
friend class CurOp;
void _finishInit();
- void checkNotStale() const;
- Client * const _client;
+ void _checkNotStale() const;
+
bool _justCreated;
bool _doVersion;
const std::string _ns;
@@ -325,7 +322,8 @@ namespace mongo {
}; // class Client::Context
- class WriteContext : boost::noncopyable {
+ class WriteContext {
+ MONGO_DISALLOW_COPYING(WriteContext);
public:
WriteContext(OperationContext* opCtx, const std::string& ns);
@@ -335,17 +333,17 @@ namespace mongo {
return _c.db()->getCollection(_nss.ns());
}
- Context& ctx() { return _c; }
-
private:
- OperationContext* _txn;
- NamespaceString _nss;
+ OperationContext* const _txn;
+ const NamespaceString _nss;
+
AutoGetOrCreateDb _autodb;
Lock::CollectionLock _collk;
Context _c;
Collection* _collection;
};
- }; // class Client
+
+ };
/** get the Client object for this thread. */
inline Client& cc() {