diff options
author | Jason Rassi <rassi@10gen.com> | 2015-03-09 13:24:07 -0400 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-03-09 17:28:24 -0400 |
commit | 568052f3aa85a803fbced9b848688892fdbe0290 (patch) | |
tree | 655f501e990263b43f337b068506b1ad70d0ee41 | |
parent | a56f29e60d872bb6334a24dd732d500b3ae52b48 (diff) | |
download | mongo-568052f3aa85a803fbced9b848688892fdbe0290.tar.gz |
SERVER-17499 Unify GodScope and fromDBDirectClient bool
-rw-r--r-- | src/mongo/db/auth/authz_session_external_state_d.cpp | 5 | ||||
-rw-r--r-- | src/mongo/db/client.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/client.h | 6 | ||||
-rw-r--r-- | src/mongo/db/dbdirectclient.cpp | 26 | ||||
-rw-r--r-- | src/mongo/db/instance.cpp | 23 | ||||
-rw-r--r-- | src/mongo/db/instance.h | 3 | ||||
-rw-r--r-- | src/mongo/db/operation_context.h | 6 | ||||
-rw-r--r-- | src/mongo/db/operation_context_impl.cpp | 4 | ||||
-rw-r--r-- | src/mongo/db/operation_context_impl.h | 2 | ||||
-rw-r--r-- | src/mongo/db/operation_context_noop.h | 4 | ||||
-rw-r--r-- | src/mongo/db/query/find.cpp | 12 | ||||
-rw-r--r-- | src/mongo/db/query/find.h | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl.cpp | 2 | ||||
-rw-r--r-- | src/mongo/dbtests/querytests.cpp | 2 | ||||
-rw-r--r-- | src/mongo/s/s_only.cpp | 2 |
15 files changed, 40 insertions, 67 deletions
diff --git a/src/mongo/db/auth/authz_session_external_state_d.cpp b/src/mongo/db/auth/authz_session_external_state_d.cpp index 8411384f342..dc78555b707 100644 --- a/src/mongo/db/auth/authz_session_external_state_d.cpp +++ b/src/mongo/db/auth/authz_session_external_state_d.cpp @@ -55,8 +55,9 @@ namespace mongo { } bool AuthzSessionExternalStateMongod::shouldIgnoreAuthChecks() const { - // TODO(spencer): get "isGod" from OperationContext - return cc().isGod() || AuthzSessionExternalStateServerCommon::shouldIgnoreAuthChecks(); + // TODO(spencer): get "isInDirectClient" from OperationContext + return cc().isInDirectClient() || + AuthzSessionExternalStateServerCommon::shouldIgnoreAuthChecks(); } } // namespace mongo diff --git a/src/mongo/db/client.cpp b/src/mongo/db/client.cpp index 7c8a1c2cdf8..f1230fd5cd4 100644 --- a/src/mongo/db/client.cpp +++ b/src/mongo/db/client.cpp @@ -128,7 +128,7 @@ namespace { _desc(desc), _threadId(boost::this_thread::get_id()), _connectionId(p ? p->connectionId() : 0), - _god(0), + _inDirectClient(false), _txn(NULL), _lastOp(0), _shutdown(false) { @@ -137,8 +137,6 @@ namespace { } Client::~Client() { - _god = 0; - if ( ! inShutdown() ) { // we can't clean up safely once we're in shutdown { diff --git a/src/mongo/db/client.h b/src/mongo/db/client.h index 9f8951927e9..d2e3102a36d 100644 --- a/src/mongo/db/client.h +++ b/src/mongo/db/client.h @@ -223,8 +223,8 @@ namespace mongo { const OperationContext* getOperationContext() const { return _txn; } // TODO(spencer): SERVER-10228 SERVER-14779 Remove this/move it fully into OperationContext. - bool isGod() const { return _god; } /* this is for map/reduce writes */ - bool setGod(bool newVal) { const bool prev = _god; _god = newVal; return prev; } + bool isInDirectClient() const { return _inDirectClient; } + void setInDirectClient(bool newVal) { _inDirectClient = newVal; } void setRemoteID(const OID& rid) { _remoteId = rid; } // Only used for master/slave OID getRemoteID() const { return _remoteId; } // Only used for master/slave @@ -248,7 +248,7 @@ namespace mongo { mutable SpinLock _lock; // Whether this client is running as DBDirectClient - bool _god; + bool _inDirectClient; // If != NULL, then contains the currently active OperationContext OperationContext* _txn; diff --git a/src/mongo/db/dbdirectclient.cpp b/src/mongo/db/dbdirectclient.cpp index b0d673b5de1..a99b66bea6c 100644 --- a/src/mongo/db/dbdirectclient.cpp +++ b/src/mongo/db/dbdirectclient.cpp @@ -48,20 +48,21 @@ namespace mongo { namespace { - class GodScope { - MONGO_DISALLOW_COPYING(GodScope); + class DirectClientScope { + MONGO_DISALLOW_COPYING(DirectClientScope); public: - GodScope(OperationContext* txn) : _txn(txn) { - _prev = _txn->getClient()->setGod(true); + explicit DirectClientScope(OperationContext* txn) + : _txn(txn), _prev(_txn->getClient()->isInDirectClient()) { + _txn->getClient()->setInDirectClient(true); } - ~GodScope() { - _txn->getClient()->setGod(_prev); + ~DirectClientScope() { + _txn->getClient()->setInDirectClient(_prev); } private: - bool _prev; - OperationContext* _txn; + OperationContext* const _txn; + const bool _prev; }; } // namespace @@ -119,14 +120,13 @@ namespace mongo { Message& response, bool assertOk, string* actualServer) { - - GodScope gs(_txn); + DirectClientScope directClientScope(_txn); if (lastError._get()) { lastError.startRequest(toSend, lastError._get()); } DbResponse dbResponse; - assembleResponse(_txn, toSend, dbResponse, dummyHost, true); + assembleResponse(_txn, toSend, dbResponse, dummyHost); verify(dbResponse.response); // can get rid of this if we make response handling smarter @@ -137,13 +137,13 @@ namespace mongo { } void DBDirectClient::say(Message& toSend, bool isRetry, string* actualServer) { - GodScope gs(_txn); + DirectClientScope directClientScope(_txn); if (lastError._get()) { lastError.startRequest(toSend, lastError._get()); } DbResponse dbResponse; - assembleResponse(_txn, toSend, dbResponse, dummyHost, true); + assembleResponse(_txn, toSend, dbResponse, dummyHost); } auto_ptr<DBClientCursor> DBDirectClient::query(const string& ns, diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index a41248b3103..c45339aaf36 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -126,8 +126,7 @@ namespace mongo { bool receivedGetMore(OperationContext* txn, DbResponse& dbresponse, Message& m, - CurOp& curop, - bool fromDBDirectClient); + CurOp& curop); int nloggedsome = 0; #define LOGWITHRATELIMIT if( ++nloggedsome < 1000 || nloggedsome % 100 == 0 ) @@ -195,8 +194,7 @@ namespace mongo { static bool receivedQuery(OperationContext* txn, Client& c, DbResponse& dbresponse, - Message& m, - bool fromDBDirectClient) { + Message& m) { bool ok = true; MSGID responseTo = m.header().getId(); @@ -217,7 +215,7 @@ namespace mongo { audit::logQueryAuthzCheck(client, ns, q.query, status.code()); uassertStatusOK(status); } - dbresponse.exhaustNS = runQuery(txn, m, q, ns, op, *resp, fromDBDirectClient); + dbresponse.exhaustNS = runQuery(txn, m, q, ns, op, *resp); verify( !resp->empty() ); } catch ( SendStaleConfigException& e ){ @@ -298,8 +296,7 @@ namespace mongo { void assembleResponse( OperationContext* txn, Message& m, DbResponse& dbresponse, - const HostAndPort& remote, - bool fromDBDirectClient ) { + const HostAndPort& remote) { // before we lock... int op = m.operation(); bool isCommand = false; @@ -307,7 +304,7 @@ namespace mongo { DbMessage dbmsg(m); Client& c = *txn->getClient(); - if (!txn->isGod()) { + if (!txn->getClient()->isInDirectClient()) { c.getAuthorizationSession()->startRequest(txn); // We should not be holding any locks at this point @@ -400,10 +397,10 @@ namespace mongo { logger::LogSeverity::Debug(1)); if ( op == dbQuery ) { - receivedQuery(txn, c , dbresponse, m, fromDBDirectClient ); + receivedQuery(txn, c , dbresponse, m); } else if ( op == dbGetMore ) { - if ( ! receivedGetMore(txn, dbresponse, m, currentOp, fromDBDirectClient) ) + if ( ! receivedGetMore(txn, dbresponse, m, currentOp) ) shouldLog = true; } else if ( op == dbMsg ) { @@ -741,8 +738,7 @@ namespace mongo { bool receivedGetMore(OperationContext* txn, DbResponse& dbresponse, Message& m, - CurOp& curop, - bool fromDBDirectClient) { + CurOp& curop) { bool ok = true; DbMessage d(m); @@ -792,8 +788,7 @@ namespace mongo { curop, pass, exhaust, - &isCursorAuthorized, - fromDBDirectClient); + &isCursorAuthorized); } catch ( AssertionException& e ) { if ( isCursorAuthorized ) { diff --git a/src/mongo/db/instance.h b/src/mongo/db/instance.h index 9b42cfc32f0..e7aa31b9f86 100644 --- a/src/mongo/db/instance.h +++ b/src/mongo/db/instance.h @@ -70,8 +70,7 @@ namespace mongo { void assembleResponse( OperationContext* txn, Message& m, DbResponse& dbresponse, - const HostAndPort &client, - bool fromDBDirectClient = false ); + const HostAndPort &client ); void maybeCreatePidFile(); diff --git a/src/mongo/db/operation_context.h b/src/mongo/db/operation_context.h index f12bdcea6b6..763e8da0353 100644 --- a/src/mongo/db/operation_context.h +++ b/src/mongo/db/operation_context.h @@ -110,12 +110,6 @@ namespace mongo { virtual std::string getNS() const = 0; /** - * Returns true if this operation is under a GodScope. Only used by DBDirectClient. - * TODO(spencer): SERVER-10228 Remove this - */ - virtual bool isGod() const = 0; - - /** * Returns the client under which this context runs. */ virtual Client* getClient() const = 0; diff --git a/src/mongo/db/operation_context_impl.cpp b/src/mongo/db/operation_context_impl.cpp index 9bd9f987ffb..b22a3e64101 100644 --- a/src/mongo/db/operation_context_impl.cpp +++ b/src/mongo/db/operation_context_impl.cpp @@ -95,10 +95,6 @@ namespace mongo { return getCurOp()->getNS(); } - bool OperationContextImpl::isGod() const { - return getClient()->isGod(); - } - Client* OperationContextImpl::getClient() const { return _client; } diff --git a/src/mongo/db/operation_context_impl.h b/src/mongo/db/operation_context_impl.h index 29eaa91dffa..e2310208f2a 100644 --- a/src/mongo/db/operation_context_impl.h +++ b/src/mongo/db/operation_context_impl.h @@ -54,8 +54,6 @@ namespace mongo { unsigned long long progressMeterTotal, int secondsBetween); - virtual bool isGod() const; - virtual std::string getNS() const; virtual Client* getClient() const; diff --git a/src/mongo/db/operation_context_noop.h b/src/mongo/db/operation_context_noop.h index ca567bd25e2..101a39d69ac 100644 --- a/src/mongo/db/operation_context_noop.h +++ b/src/mongo/db/operation_context_noop.h @@ -95,10 +95,6 @@ namespace mongo { return true; } - virtual bool isGod() const { - return false; - } - virtual std::string getNS() const { return std::string(); }; diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index 67867835c31..dac50778085 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -188,8 +188,7 @@ namespace mongo { CurOp& curop, int pass, bool& exhaust, - bool* isCursorAuthorized, - bool fromDBDirectClient) { + bool* isCursorAuthorized) { // For testing, we may want to fail if we receive a getmore. if (MONGO_FAIL_POINT(failReceivedGetmore)) { @@ -285,7 +284,7 @@ namespace mongo { *isCursorAuthorized = true; // Restore the RecoveryUnit if we need to. - if (fromDBDirectClient) { + if (txn->getClient()->isInDirectClient()) { if (cc->hasRecoveryUnit()) invariant(txn->recoveryUnit() == cc->getUnownedRecoveryUnit()); } @@ -436,7 +435,7 @@ namespace mongo { << endl; if (PlanExecutor::IS_EOF == state && (queryOptions & QueryOption_CursorTailable)) { - if (!fromDBDirectClient) { + if (!txn->getClient()->isInDirectClient()) { // Don't stash the RU. Get a new one on the next getMore. ruSwapper.reset(); delete cc->releaseOwnedRecoveryUnit(); @@ -579,8 +578,7 @@ namespace mongo { QueryMessage& q, const NamespaceString& nss, CurOp& curop, - Message &result, - bool fromDBDirectClient) { + Message &result) { // Validate the namespace. uassert(16256, str::stream() << "Invalid ns [" << nss.ns() << "]", nss.isValid()); @@ -886,7 +884,7 @@ namespace mongo { pq.getFilter()); ccId = cc->cursorid(); - if (fromDBDirectClient) { + if (txn->getClient()->isInDirectClient()) { cc->setUnownedRecoveryUnit(txn->recoveryUnit()); } else if (state == PlanExecutor::IS_EOF && pq.getOptions().tailable) { diff --git a/src/mongo/db/query/find.h b/src/mongo/db/query/find.h index 0b5d8024756..b2bd7881ec3 100644 --- a/src/mongo/db/query/find.h +++ b/src/mongo/db/query/find.h @@ -65,8 +65,7 @@ namespace mongo { CurOp& curop, int pass, bool& exhaust, - bool* isCursorAuthorized, - bool fromDBDirectClient); + bool* isCursorAuthorized); /** * Run the query 'q' and place the result in 'result'. @@ -76,7 +75,6 @@ namespace mongo { QueryMessage& q, const NamespaceString& ns, CurOp& curop, - Message &result, - bool fromDBDirectClient); + Message &result); } // namespace mongo diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 25eb1d1300f..66fc496f2b3 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -1241,7 +1241,7 @@ namespace { Status ReplicationCoordinatorImpl::checkCanServeReadsFor(OperationContext* txn, const NamespaceString& ns, bool slaveOk) { - if (txn->isGod()) { + if (txn->getClient()->isInDirectClient()) { return Status::OK(); } if (canAcceptWritesForDatabase(ns.db())) { diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp index 728424e56b4..b2b79021ad7 100644 --- a/src/mongo/dbtests/querytests.cpp +++ b/src/mongo/dbtests/querytests.cpp @@ -1509,7 +1509,7 @@ namespace QueryTests { QueryMessage queryMessage( dbMessage ); Message result; string exhaust = runQuery( &_txn, message, queryMessage, NamespaceString(ns()), - *cc().curop(), result, false ); + *cc().curop(), result ); ASSERT( exhaust.size() ); ASSERT_EQUALS( string( ns() ), exhaust ); } diff --git a/src/mongo/s/s_only.cpp b/src/mongo/s/s_only.cpp index fcd923c964b..378a2b5d18b 100644 --- a/src/mongo/s/s_only.cpp +++ b/src/mongo/s/s_only.cpp @@ -73,7 +73,7 @@ namespace mongo { ClientBasic(p), _desc(desc), _connectionId(), - _god(0), + _inDirectClient(false), _lastOp(0), _shutdown(false) { } |