summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2015-03-09 13:24:07 -0400
committerJason Rassi <rassi@10gen.com>2015-03-09 17:21:23 -0400
commit0c388e562f6b1549b583486b151164df17b37d94 (patch)
treed4faf8b27722398c9885b8bade3c32efc94e43fe /src/mongo
parente6491d77039d58197aa3cf63323a0b6d47f6b859 (diff)
downloadmongo-0c388e562f6b1549b583486b151164df17b37d94.tar.gz
SERVER-17499 Unify GodScope and fromDBDirectClient bool
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/auth/authz_session_external_state_d.cpp5
-rw-r--r--src/mongo/db/client.cpp4
-rw-r--r--src/mongo/db/client.h6
-rw-r--r--src/mongo/db/dbdirectclient.cpp26
-rw-r--r--src/mongo/db/instance.cpp23
-rw-r--r--src/mongo/db/instance.h3
-rw-r--r--src/mongo/db/operation_context.h6
-rw-r--r--src/mongo/db/operation_context_impl.cpp4
-rw-r--r--src/mongo/db/operation_context_impl.h2
-rw-r--r--src/mongo/db/operation_context_noop.h4
-rw-r--r--src/mongo/db/query/find.cpp12
-rw-r--r--src/mongo/db/query/find.h6
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp2
-rw-r--r--src/mongo/dbtests/querytests.cpp2
-rw-r--r--src/mongo/s/s_only.cpp2
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 9b6d10e8067..7f89e797e0b 100644
--- a/src/mongo/db/client.cpp
+++ b/src/mongo/db/client.cpp
@@ -129,7 +129,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) {
@@ -138,8 +138,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 da62bca48d1..b83ce05c9c0 100644
--- a/src/mongo/db/client.h
+++ b/src/mongo/db/client.h
@@ -220,8 +220,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; }
// Only used for master/slave
void setRemoteID(const OID& rid) { _remoteId = rid; }
@@ -249,7 +249,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 3d50bb98e4b..b20fdf07092 100644
--- a/src/mongo/db/dbdirectclient.cpp
+++ b/src/mongo/db/dbdirectclient.cpp
@@ -49,20 +49,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
@@ -120,14 +121,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
@@ -138,13 +138,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 dd176413f01..96a9fa496b8 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 ff9e973fa13..89ab86afb9d 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 6d95e494d5d..356db253596 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 9ab5f5496d4..32f62d454d7 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 ea6034bf053..0a24af2fdd6 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 d00af18aaa1..212562ab6c3 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());
@@ -879,7 +877,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 3740fec5aa2..7401ac9d99c 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -1237,7 +1237,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 441903bd4ab..049c6db8ba0 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -1508,7 +1508,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 b4e3b2112a9..0f7dab81b72 100644
--- a/src/mongo/s/s_only.cpp
+++ b/src/mongo/s/s_only.cpp
@@ -68,7 +68,7 @@ namespace mongo {
ClientBasic(p),
_desc(desc),
_connectionId(),
- _god(0),
+ _inDirectClient(false),
_lastOp(0),
_shutdown(false) {
}