summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/client/scoped_db_conn_test.cpp3
-rw-r--r--src/mongo/db/commands/find_and_modify.cpp12
-rw-r--r--src/mongo/db/commands/mr.cpp25
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp6
-rw-r--r--src/mongo/db/commands/write_commands/write_commands.cpp4
-rw-r--r--src/mongo/db/db_raii.cpp4
-rw-r--r--src/mongo/db/instance.cpp3
-rw-r--r--src/mongo/db/query/get_executor.cpp2
-rw-r--r--src/mongo/db/range_deleter_db_env.cpp2
-rw-r--r--src/mongo/s/d_migrate.cpp2
-rw-r--r--src/mongo/s/d_state.cpp49
-rw-r--r--src/mongo/s/d_state.h18
-rw-r--r--src/mongo/s/server.cpp2
-rw-r--r--src/mongo/scripting/v8-3.25_db.cpp6
-rw-r--r--src/mongo/scripting/v8_db.cpp7
-rw-r--r--src/mongo/shell/clientAndShell.cpp3
-rw-r--r--src/mongo/unittest/crutch.cpp4
-rw-r--r--src/mongo/util/decorable.h2
18 files changed, 89 insertions, 65 deletions
diff --git a/src/mongo/client/scoped_db_conn_test.cpp b/src/mongo/client/scoped_db_conn_test.cpp
index 1ba4095c90e..f55c666a7f6 100644
--- a/src/mongo/client/scoped_db_conn_test.cpp
+++ b/src/mongo/client/scoped_db_conn_test.cpp
@@ -68,6 +68,7 @@ namespace {
namespace mongo {
+ class Client;
class OperationContext;
// Symbols defined to build the binary correctly.
@@ -94,7 +95,7 @@ namespace mongo {
dbexit(rc, "");
}
- bool haveLocalShardingInfo(const string& ns) {
+ bool haveLocalShardingInfo(Client* client, const string& ns) {
return false;
}
diff --git a/src/mongo/db/commands/find_and_modify.cpp b/src/mongo/db/commands/find_and_modify.cpp
index 9170e5af7a2..f911d6520fd 100644
--- a/src/mongo/db/commands/find_and_modify.cpp
+++ b/src/mongo/db/commands/find_and_modify.cpp
@@ -231,6 +231,8 @@ namespace {
const FindAndModifyRequest& args = parseStatus.getValue();
const NamespaceString& nsString = args.getNamespaceString();
+ auto client = txn->getClient();
+
if (args.isRemove()) {
DeleteRequest request(nsString);
const bool isExplain = true;
@@ -247,7 +249,7 @@ namespace {
AutoGetDb autoDb(txn, dbName, MODE_IX);
Lock::CollectionLock collLock(txn->lockState(), nsString.ns(), MODE_IX);
- ensureShardVersionOKOrThrow(nsString.ns());
+ ensureShardVersionOKOrThrow(client, nsString.ns());
Collection* collection = nullptr;
if (autoDb.getDb()) {
@@ -286,7 +288,7 @@ namespace {
AutoGetDb autoDb(txn, dbName, MODE_IX);
Lock::CollectionLock collLock(txn->lockState(), nsString.ns(), MODE_IX);
- ensureShardVersionOKOrThrow(nsString.ns());
+ ensureShardVersionOKOrThrow(client, nsString.ns());
Collection* collection = nullptr;
if (autoDb.getDb()) {
@@ -344,6 +346,8 @@ namespace {
if (shouldBypassDocumentValidationForCommand(cmdObj))
maybeDisableValidation.emplace(txn);
+ auto client = txn->getClient();
+
// We may encounter a WriteConflictException when creating a collection during an
// upsert, even when holding the exclusive lock on the database (due to other load on
// the system). The query framework should handle all other WriteConflictExceptions,
@@ -368,7 +372,7 @@ namespace {
Lock::CollectionLock collLock(txn->lockState(), nsString.ns(), MODE_IX);
Collection* collection = autoDb.getDb()->getCollection(nsString.ns());
- ensureShardVersionOKOrThrow(nsString.ns());
+ ensureShardVersionOKOrThrow(client, nsString.ns());
Status isPrimary = checkCanAcceptWritesForDatabase(nsString);
if (!isPrimary.isOK()) {
@@ -410,7 +414,7 @@ namespace {
Lock::CollectionLock collLock(txn->lockState(), nsString.ns(), MODE_IX);
Collection* collection = autoDb.getDb()->getCollection(nsString.ns());
- ensureShardVersionOKOrThrow(nsString.ns());
+ ensureShardVersionOKOrThrow(client, nsString.ns());
Status isPrimary = checkCanAcceptWritesForDatabase(nsString);
if (!isPrimary.isOK()) {
diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp
index 9642c03c7c8..5d3cc42d2d5 100644
--- a/src/mongo/db/commands/mr.cpp
+++ b/src/mongo/db/commands/mr.cpp
@@ -573,7 +573,8 @@ namespace mongo {
*
* TODO: make count work with versioning
*/
- unsigned long long _safeCount( // Can't be const b/c count isn't
+ unsigned long long _safeCount( Client* client,
+ // Can't be const b/c count isn't
/* const */ DBDirectClient& db,
const string &ns,
const BSONObj& query = BSONObj(),
@@ -581,7 +582,7 @@ namespace mongo {
int limit = 0,
int skip = 0 )
{
- ShardForceVersionOkModeBlock ignoreVersion; // ignore versioning here
+ ShardForceVersionOkModeBlock ignoreVersion(client); // ignore versioning here
return db.count( ns, query, options, limit, skip );
}
@@ -592,11 +593,13 @@ namespace mongo {
long long State::postProcessCollectionNonAtomic(
OperationContext* txn, CurOp* op, ProgressMeterHolder& pm) {
+ auto client = txn->getClient();
+
if ( _config.outputOptions.finalNamespace == _config.tempNamespace )
- return _safeCount( _db, _config.outputOptions.finalNamespace );
+ return _safeCount( client, _db, _config.outputOptions.finalNamespace );
if (_config.outputOptions.outType == Config::REPLACE ||
- _safeCount(_db, _config.outputOptions.finalNamespace) == 0) {
+ _safeCount(client, _db, _config.outputOptions.finalNamespace) == 0) {
ScopedTransaction transaction(txn, MODE_X);
Lock::GlobalWrite lock(txn->lockState()); // TODO(erh): why global???
@@ -617,7 +620,7 @@ namespace mongo {
else if ( _config.outputOptions.outType == Config::MERGE ) {
// merge: upsert new docs into old collection
{
- const auto count = _safeCount(_db, _config.tempNamespace, BSONObj());
+ const auto count = _safeCount(client, _db, _config.tempNamespace, BSONObj());
stdx::lock_guard<Client> lk(*txn->getClient());
op->setMessage_inlock("m/r: merge post processing",
"M/R Merge Post Processing Progress",
@@ -641,7 +644,7 @@ namespace mongo {
BSONList values;
{
- const auto count = _safeCount(_db, _config.tempNamespace, BSONObj());
+ const auto count = _safeCount(client, _db, _config.tempNamespace, BSONObj());
stdx::lock_guard<Client> lk(*txn->getClient());
op->setMessage_inlock("m/r: reduce post processing",
"M/R Reduce Post Processing Progress",
@@ -684,7 +687,7 @@ namespace mongo {
pm.finished();
}
- return _safeCount( _db, _config.outputOptions.finalNamespace );
+ return _safeCount( txn->getClient(), _db, _config.outputOptions.finalNamespace );
}
/**
@@ -745,7 +748,7 @@ namespace mongo {
}
long long State::incomingDocuments() {
- return _safeCount( _db, _config.ns , _config.filter , QueryOption_SlaveOk , (unsigned) _config.limit );
+ return _safeCount( _txn->getClient(), _db, _config.ns , _config.filter , QueryOption_SlaveOk , (unsigned) _config.limit );
}
State::~State() {
@@ -1305,7 +1308,9 @@ namespace mongo {
if (shouldBypassDocumentValidationForCommand(cmd))
maybeDisableValidation.emplace(txn);
- if (txn->getClient()->isInDirectClient()) {
+ auto client = txn->getClient();
+
+ if (client->isInDirectClient()) {
return appendCommandStatus(result,
Status(ErrorCodes::IllegalOperation,
"Cannot run mapReduce command from eval()"));
@@ -1333,7 +1338,7 @@ namespace mongo {
// Get metadata before we check our version, to make sure it doesn't increment
// in the meantime. Need to do this in the same lock scope as the block.
- if (shardingState.needCollectionMetadata(config.ns)) {
+ if (shardingState.needCollectionMetadata(client, config.ns)) {
collMetadata = shardingState.getCollectionMetadata( config.ns );
}
}
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp
index 1bcc3679b77..2dc1e9a60c9 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -829,7 +829,7 @@ namespace mongo {
ExecInsertsState state(_txn, &request);
normalizeInserts(request, &state.normalizedInserts);
- ShardedConnectionInfo* info = ShardedConnectionInfo::get(false);
+ ShardedConnectionInfo* info = ShardedConnectionInfo::get(_txn->getClient(), false);
if (info) {
if (request.isMetadataSet() && request.getMetadata()->isShardVersionSet()) {
info->setVersion(request.getTargetingNS(),
@@ -889,7 +889,7 @@ namespace mongo {
beginCurrentOp(_txn, updateItem);
incOpStats( updateItem );
- ShardedConnectionInfo* info = ShardedConnectionInfo::get(false);
+ ShardedConnectionInfo* info = ShardedConnectionInfo::get(_txn->getClient(), false);
if (info) {
auto rootRequest = updateItem.getRequest();
if (!updateItem.getUpdate()->getMulti() &&
@@ -933,7 +933,7 @@ namespace mongo {
beginCurrentOp(_txn, removeItem);
incOpStats( removeItem );
- ShardedConnectionInfo* info = ShardedConnectionInfo::get(false);
+ ShardedConnectionInfo* info = ShardedConnectionInfo::get(_txn->getClient(), false);
if (info) {
auto rootRequest = removeItem.getRequest();
if (removeItem.getDelete()->getLimit() == 1 &&
diff --git a/src/mongo/db/commands/write_commands/write_commands.cpp b/src/mongo/db/commands/write_commands/write_commands.cpp
index 5ed36760377..3fbacd52b79 100644
--- a/src/mongo/db/commands/write_commands/write_commands.cpp
+++ b/src/mongo/db/commands/write_commands/write_commands.cpp
@@ -225,7 +225,7 @@ namespace mongo {
AutoGetDb autoDb( txn, nsString.db(), MODE_IX );
Lock::CollectionLock colLock( txn->lockState(), nsString.ns(), MODE_IX );
- ensureShardVersionOKOrThrow( nsString.ns() );
+ ensureShardVersionOKOrThrow( txn->getClient(), nsString.ns() );
// Get a pointer to the (possibly NULL) collection.
Collection* collection = NULL;
@@ -265,7 +265,7 @@ namespace mongo {
AutoGetDb autoDb(txn, nsString.db(), MODE_IX);
Lock::CollectionLock colLock(txn->lockState(), nsString.ns(), MODE_IX);
- ensureShardVersionOKOrThrow( nsString.ns() );
+ ensureShardVersionOKOrThrow( txn->getClient(), nsString.ns() );
// Get a pointer to the (possibly NULL) collection.
Collection* collection = NULL;
diff --git a/src/mongo/db/db_raii.cpp b/src/mongo/db/db_raii.cpp
index b1a6c0037b2..8c190b96f38 100644
--- a/src/mongo/db/db_raii.cpp
+++ b/src/mongo/db/db_raii.cpp
@@ -89,7 +89,7 @@ namespace mongo {
// We have both the DB and collection locked, which the prerequisite to do a stable shard
// version check.
- ensureShardVersionOKOrThrow(ns);
+ ensureShardVersionOKOrThrow(_txn->getClient(), ns);
auto curOp = CurOp::get(_txn);
stdx::lock_guard<Client> lk(*_txn->getClient());
@@ -177,7 +177,7 @@ namespace mongo {
case dbDelete: // here as well.
break;
default:
- ensureShardVersionOKOrThrow(_ns);
+ ensureShardVersionOKOrThrow(_txn->getClient(), _ns);
}
}
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index ab49e399811..342453178d4 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -583,7 +583,8 @@ namespace {
}
else {
if (remote != DBDirectClient::dummyHost) {
- const ShardedConnectionInfo* connInfo = ShardedConnectionInfo::get(false);
+ const ShardedConnectionInfo* connInfo =
+ ShardedConnectionInfo::get(&c, false);
uassert(18663,
str::stream() << "legacy writeOps not longer supported for "
<< "versioned connections, ns: " << nsString.ns()
diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp
index 52e389986ea..ee10d7853f6 100644
--- a/src/mongo/db/query/get_executor.cpp
+++ b/src/mongo/db/query/get_executor.cpp
@@ -635,7 +635,7 @@ namespace {
}
size_t options = QueryPlannerParams::DEFAULT;
- if (shardingState.needCollectionMetadata(nss.ns())) {
+ if (shardingState.needCollectionMetadata(txn->getClient(), nss.ns())) {
options |= QueryPlannerParams::INCLUDE_SHARD_FILTER;
}
return getExecutor(txn, collection, cq.release(), PlanExecutor::YIELD_AUTO, out, options);
diff --git a/src/mongo/db/range_deleter_db_env.cpp b/src/mongo/db/range_deleter_db_env.cpp
index 2641147b26c..69f2cd86d33 100644
--- a/src/mongo/db/range_deleter_db_env.cpp
+++ b/src/mongo/db/range_deleter_db_env.cpp
@@ -74,7 +74,7 @@ namespace mongo {
Client::initThreadIfNotAlready("RangeDeleter");
*deletedDocs = 0;
- ShardForceVersionOkModeBlock forceVersion;
+ ShardForceVersionOkModeBlock forceVersion(txn->getClient());
{
Helpers::RemoveSaver removeSaver("moveChunk",
ns,
diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp
index 24985dd4f81..b124f435cf7 100644
--- a/src/mongo/s/d_migrate.cpp
+++ b/src/mongo/s/d_migrate.cpp
@@ -316,7 +316,7 @@ namespace {
const BSONObj& obj,
BSONObj* patt,
bool notInActiveChunk) {
- ensureShardVersionOKOrThrow(ns);
+ ensureShardVersionOKOrThrow(txn->getClient(), ns);
const char op = opstr[0];
diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp
index 42172bb8b18..805380acaa4 100644
--- a/src/mongo/s/d_state.cpp
+++ b/src/mongo/s/d_state.cpp
@@ -67,11 +67,15 @@
namespace mongo {
+ using boost::optional;
using std::endl;
using std::string;
using std::stringstream;
using std::vector;
+ namespace {
+ const auto clientSCI = Client::declareDecoration<optional<ShardedConnectionInfo>>();
+ } // namespace
bool isMongos() {
return false;
@@ -810,11 +814,11 @@ namespace mongo {
versionB.done();
}
- bool ShardingState::needCollectionMetadata( const string& ns ) const {
+ bool ShardingState::needCollectionMetadata( Client* client, const string& ns ) const {
if ( ! _enabled )
return false;
- if ( ! ShardedConnectionInfo::get( false ) )
+ if ( ! ShardedConnectionInfo::get( client, false ) )
return false;
return true;
@@ -838,24 +842,23 @@ namespace mongo {
// -----ShardedConnectionInfo START ----
- boost::thread_specific_ptr<ShardedConnectionInfo> ShardedConnectionInfo::_tl;
-
ShardedConnectionInfo::ShardedConnectionInfo() {
_forceVersionOk = false;
}
- ShardedConnectionInfo* ShardedConnectionInfo::get( bool create ) {
- ShardedConnectionInfo* info = _tl.get();
- if ( ! info && create ) {
+ ShardedConnectionInfo* ShardedConnectionInfo::get( Client* client, bool create ) {
+ auto& current = clientSCI(client);
+
+ if (!current && create) {
LOG(1) << "entering shard mode for connection" << endl;
- info = new ShardedConnectionInfo();
- _tl.reset( info );
+ current = boost::in_place();
}
- return info;
+
+ return current ? &current.value() : nullptr;
}
- void ShardedConnectionInfo::reset() {
- _tl.reset();
+ void ShardedConnectionInfo::reset(Client* client) {
+ clientSCI(client) = boost::none;
}
const ChunkVersion ShardedConnectionInfo::getVersion( const string& ns ) const {
@@ -899,14 +902,14 @@ namespace mongo {
};
- bool haveLocalShardingInfo( const string& ns ) {
+ bool haveLocalShardingInfo( Client* client, const string& ns ) {
if ( ! shardingState.enabled() )
return false;
if ( ! shardingState.hasVersion( ns ) )
return false;
- return ShardedConnectionInfo::get(false) != NULL;
+ return ShardedConnectionInfo::get(client, false) != NULL;
}
class UnsetShardingCommand : public MongodShardCommand {
@@ -935,7 +938,7 @@ namespace mongo {
int,
string& errmsg,
BSONObjBuilder& result) {
- ShardedConnectionInfo::reset();
+ ShardedConnectionInfo::reset(txn->getClient());
return true;
}
@@ -1027,8 +1030,9 @@ namespace mongo {
// step 1
- LastError::get(txn->getClient()).disable();
- ShardedConnectionInfo* info = ShardedConnectionInfo::get( true );
+ Client* client = txn->getClient();
+ LastError::get(client).disable();
+ ShardedConnectionInfo* info = ShardedConnectionInfo::get( client, true );
bool authoritative = cmdObj.getBoolField( "authoritative" );
@@ -1278,7 +1282,7 @@ namespace mongo {
result.appendTimestamp("global", shardingState.getVersion(ns).toLong());
- ShardedConnectionInfo* const info = ShardedConnectionInfo::get(false);
+ ShardedConnectionInfo* const info = ShardedConnectionInfo::get(txn->getClient(), false);
result.appendBool("inShardedMode", info != NULL);
if (info) {
result.appendTimestamp("mine", info->getVersion(ns).toLong());
@@ -1336,7 +1340,8 @@ namespace mongo {
* @ return true if not in sharded mode
or if version for this client is ok
*/
- static bool shardVersionOk(const string& ns,
+ static bool shardVersionOk(Client* client,
+ const string& ns,
string& errmsg,
ChunkVersion& received,
ChunkVersion& wanted) {
@@ -1350,7 +1355,7 @@ namespace mongo {
return true;
}
- ShardedConnectionInfo* info = ShardedConnectionInfo::get( false );
+ ShardedConnectionInfo* info = ShardedConnectionInfo::get( client, false );
if ( ! info ) {
// this means the client has nothing sharded
@@ -1420,11 +1425,11 @@ namespace mongo {
}
- void ensureShardVersionOKOrThrow(const std::string& ns) {
+ void ensureShardVersionOKOrThrow(Client* client, const std::string& ns) {
string errmsg;
ChunkVersion received;
ChunkVersion wanted;
- if (!shardVersionOk(ns, errmsg, received, wanted)) {
+ if (!shardVersionOk(client, ns, errmsg, received, wanted)) {
StringBuilder sb;
sb << "[" << ns << "] shard version not ok: " << errmsg;
throw SendStaleConfigException(ns, sb.str(), received, wanted);
diff --git a/src/mongo/s/d_state.h b/src/mongo/s/d_state.h
index 9746af2bd30..2337efff8a4 100644
--- a/src/mongo/s/d_state.h
+++ b/src/mongo/s/d_state.h
@@ -29,6 +29,7 @@
#pragma once
+#include "mongo/db/client.h"
#include "mongo/db/jsobj.h"
#include "mongo/s/collection_metadata.h"
#include "mongo/s/chunk_version.h"
@@ -131,7 +132,7 @@ namespace mongo {
// querying support
- bool needCollectionMetadata( const std::string& ns ) const;
+ bool needCollectionMetadata( Client* client, const std::string& ns ) const;
CollectionMetadataPtr getCollectionMetadata( const std::string& ns );
// chunk migrate and split support
@@ -304,13 +305,14 @@ namespace mongo {
*/
class ShardedConnectionInfo {
public:
+
ShardedConnectionInfo();
const ChunkVersion getVersion( const std::string& ns ) const;
void setVersion( const std::string& ns , const ChunkVersion& version );
- static ShardedConnectionInfo* get( bool create );
- static void reset();
+ static ShardedConnectionInfo* get( Client* client, bool create );
+ static void reset( Client* client );
static void addHook();
bool inForceVersionOkMode() const {
@@ -326,13 +328,11 @@ namespace mongo {
typedef std::map<std::string,ChunkVersion> NSVersionMap;
NSVersionMap _versions;
-
- static boost::thread_specific_ptr<ShardedConnectionInfo> _tl;
};
struct ShardForceVersionOkModeBlock {
- ShardForceVersionOkModeBlock() {
- info = ShardedConnectionInfo::get( false );
+ ShardForceVersionOkModeBlock(Client* client) {
+ info = ShardedConnectionInfo::get( client, false );
if ( info )
info->enterForceVersionOkMode();
}
@@ -351,7 +351,7 @@ namespace mongo {
/**
* @return true if we have any shard info for the ns
*/
- bool haveLocalShardingInfo( const std::string& ns );
+ bool haveLocalShardingInfo( Client* client, const std::string& ns );
/**
* Validates whether the shard chunk version for the specified collection is up to date and if
@@ -362,7 +362,7 @@ namespace mongo {
*
* @param ns Complete collection namespace to be cheched.
*/
- void ensureShardVersionOKOrThrow(const std::string& ns);
+ void ensureShardVersionOKOrThrow(Client* client, const std::string& ns);
/**
* If a migration for the chunk in 'ns' where 'obj' lives is occurring, save this log entry
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 2c5aae6f9ad..dfc2684f7d3 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -109,7 +109,7 @@ namespace mongo {
return dbexitCalled;
}
- bool haveLocalShardingInfo( const string& ns ) {
+ bool haveLocalShardingInfo( Client* client, const string& ns ) {
verify( 0 );
return false;
}
diff --git a/src/mongo/scripting/v8-3.25_db.cpp b/src/mongo/scripting/v8-3.25_db.cpp
index 69066dfb2f3..bf8fd9c78a5 100644
--- a/src/mongo/scripting/v8-3.25_db.cpp
+++ b/src/mongo/scripting/v8-3.25_db.cpp
@@ -515,7 +515,8 @@ namespace mongo {
args.This()->ForceSet(scope->v8StringData("_shortName"), args[2]);
args.This()->ForceSet(v8::String::NewFromUtf8(scope->getIsolate(), "_fullName"), args[3]);
- if (haveLocalShardingInfo(toSTLString(args[3]))) {
+ auto context = scope->getOpContext();
+ if (context && haveLocalShardingInfo(context->getClient(), toSTLString(args[3]))) {
return v8AssertionException("can't use sharded collection from db.eval");
}
@@ -636,7 +637,8 @@ namespace mongo {
prop->ToObject()->HasRealNamedProperty(
v8::String::NewFromUtf8(scope->getIsolate(), "_fullName"))) {
// need to check every time that the collection did not get sharded
- if (haveLocalShardingInfo(toSTLString(
+ auto context = scope->getOpContext();
+ if (context && haveLocalShardingInfo(context->getClient(), toSTLString(
prop->ToObject()->GetRealNamedProperty(
v8::String::NewFromUtf8(scope->getIsolate(), "_fullName"))))) {
result.Set(
diff --git a/src/mongo/scripting/v8_db.cpp b/src/mongo/scripting/v8_db.cpp
index 2f9ae8c604e..57f9ce1a3c7 100644
--- a/src/mongo/scripting/v8_db.cpp
+++ b/src/mongo/scripting/v8_db.cpp
@@ -40,6 +40,7 @@
#include "mongo/client/sasl_client_authenticate.h"
#include "mongo/client/sasl_scramsha1_client_conversation.h"
#include "mongo/db/namespace_string.h"
+#include "mongo/db/operation_context.h"
#include "mongo/s/d_state.h"
#include "mongo/scripting/engine_v8.h"
#include "mongo/scripting/v8_utils.h"
@@ -645,7 +646,8 @@ namespace mongo {
args.This()->ForceSet(scope->v8StringData("_shortName"), args[2]);
args.This()->ForceSet(v8::String::New("_fullName"), args[3]);
- if (haveLocalShardingInfo(toSTLString(args[3]))) {
+ auto context = scope->getOpContext();
+ if (context && haveLocalShardingInfo(context->getClient(), toSTLString(args[3]))) {
return v8AssertionException("can't use sharded collection from db.eval");
}
@@ -755,7 +757,8 @@ namespace mongo {
if (prop->IsObject() &&
prop->ToObject()->HasRealNamedProperty(v8::String::New("_fullName"))) {
// need to check every time that the collection did not get sharded
- if (haveLocalShardingInfo(toSTLString(
+ auto context = scope->getOpContext();
+ if (context && haveLocalShardingInfo(context->getClient(), toSTLString(
prop->ToObject()->GetRealNamedProperty(v8::String::New("_fullName"))))) {
return v8AssertionException("can't use sharded collection from db.eval");
}
diff --git a/src/mongo/shell/clientAndShell.cpp b/src/mongo/shell/clientAndShell.cpp
index 3242be39d7c..3a12c54f886 100644
--- a/src/mongo/shell/clientAndShell.cpp
+++ b/src/mongo/shell/clientAndShell.cpp
@@ -44,6 +44,7 @@ namespace mongo {
using std::string;
using std::vector;
+ class Client;
class DBClientBase;
class OperationContext;
@@ -70,7 +71,7 @@ namespace mongo {
return dbexitCalled;
}
- bool haveLocalShardingInfo( const string& ns ) {
+ bool haveLocalShardingInfo( Client* client, const string& ns ) {
return false;
}
diff --git a/src/mongo/unittest/crutch.cpp b/src/mongo/unittest/crutch.cpp
index 59859207e5b..33ca040ee07 100644
--- a/src/mongo/unittest/crutch.cpp
+++ b/src/mongo/unittest/crutch.cpp
@@ -41,6 +41,8 @@
namespace mongo {
+ class Client;
+
bool inShutdown() {
return false;
}
@@ -52,7 +54,7 @@ namespace mongo {
return NULL;
}
- bool haveLocalShardingInfo(const std::string& ns) {
+ bool haveLocalShardingInfo(Client* client, const std::string& ns) {
return false;
}
diff --git a/src/mongo/util/decorable.h b/src/mongo/util/decorable.h
index 7fcb01b5f46..780317e64f9 100644
--- a/src/mongo/util/decorable.h
+++ b/src/mongo/util/decorable.h
@@ -72,7 +72,7 @@ namespace mongo {
template <typename T>
class Decoration {
public:
- Decoration() = default;
+ Decoration() = delete;
T& operator()(D& d) const {
return static_cast<Decorable&>(d)._decorations.getDecoration(_raw);