summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/sharding_state.cpp
diff options
context:
space:
mode:
authorMaria van Keulen <maria@mongodb.com>2017-03-07 12:00:08 -0500
committerMaria van Keulen <maria@mongodb.com>2017-03-07 12:00:08 -0500
commit589a5c169ced8f6e9ddcd3d182ae1b75db6b7d79 (patch)
treec7a090ffdd56a91ae677e2492c61b820af44f964 /src/mongo/db/s/sharding_state.cpp
parent3cba97198638df3750e3b455e2ad57af7ee536ae (diff)
downloadmongo-589a5c169ced8f6e9ddcd3d182ae1b75db6b7d79.tar.gz
SERVER-27938 Rename all OperationContext variables to opCtx
This commit is an automated rename of all whole word instances of txn, _txn, and txnPtr to opCtx, _opCtx, and opCtxPtr, respectively in all .cpp and .h files in src/mongo.
Diffstat (limited to 'src/mongo/db/s/sharding_state.cpp')
-rw-r--r--src/mongo/db/s/sharding_state.cpp102
1 files changed, 52 insertions, 50 deletions
diff --git a/src/mongo/db/s/sharding_state.cpp b/src/mongo/db/s/sharding_state.cpp
index 57fda772fb4..567877c216a 100644
--- a/src/mongo/db/s/sharding_state.cpp
+++ b/src/mongo/db/s/sharding_state.cpp
@@ -119,17 +119,17 @@ void updateShardIdentityConfigStringCB(const string& setName, const string& newC
}
}
-bool haveLocalShardingInfo(OperationContext* txn, const string& ns) {
- if (!ShardingState::get(txn)->enabled()) {
+bool haveLocalShardingInfo(OperationContext* opCtx, const string& ns) {
+ if (!ShardingState::get(opCtx)->enabled()) {
return false;
}
- const auto& oss = OperationShardingState::get(txn);
+ const auto& oss = OperationShardingState::get(opCtx);
if (oss.hasShardVersion()) {
return true;
}
- const auto& sci = ShardedConnectionInfo::get(txn->getClient(), false);
+ const auto& sci = ShardedConnectionInfo::get(opCtx->getClient(), false);
if (sci && !sci->getVersion(ns).isStrictlyEqualTo(ChunkVersion::UNSHARDED())) {
return true;
}
@@ -179,10 +179,10 @@ Status ShardingState::canAcceptShardedCommands() const {
}
}
-ConnectionString ShardingState::getConfigServer(OperationContext* txn) {
+ConnectionString ShardingState::getConfigServer(OperationContext* opCtx) {
invariant(enabled());
stdx::lock_guard<stdx::mutex> lk(_mutex);
- return Grid::get(txn)->shardRegistry()->getConfigServerConnectionString();
+ return Grid::get(opCtx)->shardRegistry()->getConfigServerConnectionString();
}
string ShardingState::getShardName() {
@@ -191,23 +191,23 @@ string ShardingState::getShardName() {
return _shardName;
}
-void ShardingState::shutDown(OperationContext* txn) {
+void ShardingState::shutDown(OperationContext* opCtx) {
stdx::unique_lock<stdx::mutex> lk(_mutex);
if (enabled()) {
grid.getExecutorPool()->shutdownAndJoin();
- grid.catalogClient(txn)->shutDown(txn);
+ grid.catalogClient(opCtx)->shutDown(opCtx);
}
}
-Status ShardingState::updateConfigServerOpTimeFromMetadata(OperationContext* txn) {
+Status ShardingState::updateConfigServerOpTimeFromMetadata(OperationContext* opCtx) {
if (!enabled()) {
// Nothing to do if sharding state has not been initialized.
return Status::OK();
}
- boost::optional<repl::OpTime> opTime = rpc::ConfigServerMetadata::get(txn).getOpTime();
+ boost::optional<repl::OpTime> opTime = rpc::ConfigServerMetadata::get(opCtx).getOpTime();
if (opTime) {
- if (!AuthorizationSession::get(txn->getClient())
+ if (!AuthorizationSession::get(opCtx->getClient())
->isAuthorizedForActionsOnResource(ResourcePattern::forClusterResource(),
ActionType::internal)) {
return Status(ErrorCodes::Unauthorized, "Unauthorized to update config opTime");
@@ -219,14 +219,14 @@ Status ShardingState::updateConfigServerOpTimeFromMetadata(OperationContext* txn
return Status::OK();
}
-CollectionShardingState* ShardingState::getNS(const std::string& ns, OperationContext* txn) {
+CollectionShardingState* ShardingState::getNS(const std::string& ns, OperationContext* opCtx) {
stdx::lock_guard<stdx::mutex> lk(_mutex);
CollectionShardingStateMap::iterator it = _collections.find(ns);
if (it == _collections.end()) {
auto inserted =
_collections.insert(make_pair(ns,
stdx::make_unique<CollectionShardingState>(
- txn->getServiceContext(), NamespaceString(ns))));
+ opCtx->getServiceContext(), NamespaceString(ns))));
invariant(inserted.second);
it = std::move(inserted.first);
}
@@ -254,18 +254,18 @@ void ShardingState::scheduleCleanup(const NamespaceString& nss) {
_scheduleWorkFn(nss);
}
-Status ShardingState::onStaleShardVersion(OperationContext* txn,
+Status ShardingState::onStaleShardVersion(OperationContext* opCtx,
const NamespaceString& nss,
const ChunkVersion& expectedVersion) {
- invariant(!txn->lockState()->isLocked());
+ invariant(!opCtx->lockState()->isLocked());
invariant(enabled());
LOG(2) << "metadata refresh requested for " << nss.ns() << " at shard version "
<< expectedVersion;
// Ensure any ongoing migrations have completed
- auto& oss = OperationShardingState::get(txn);
- oss.waitForMigrationCriticalSectionSignal(txn);
+ auto& oss = OperationShardingState::get(opCtx);
+ oss.waitForMigrationCriticalSectionSignal(opCtx);
ChunkVersion collectionShardVersion;
@@ -274,9 +274,9 @@ Status ShardingState::onStaleShardVersion(OperationContext* txn,
ScopedCollectionMetadata currentMetadata;
{
- AutoGetCollection autoColl(txn, nss, MODE_IS);
+ AutoGetCollection autoColl(opCtx, nss, MODE_IS);
- currentMetadata = CollectionShardingState::get(txn, nss)->getMetadata();
+ currentMetadata = CollectionShardingState::get(opCtx, nss)->getMetadata();
if (currentMetadata) {
collectionShardVersion = currentMetadata->getShardVersion();
}
@@ -290,23 +290,23 @@ Status ShardingState::onStaleShardVersion(OperationContext* txn,
}
auto refreshStatusAndVersion =
- _refreshMetadata(txn, nss, (currentMetadata ? currentMetadata.getMetadata() : nullptr));
+ _refreshMetadata(opCtx, nss, (currentMetadata ? currentMetadata.getMetadata() : nullptr));
return refreshStatusAndVersion.getStatus();
}
-Status ShardingState::refreshMetadataNow(OperationContext* txn,
+Status ShardingState::refreshMetadataNow(OperationContext* opCtx,
const NamespaceString& nss,
ChunkVersion* latestShardVersion) {
ScopedCollectionMetadata currentMetadata;
{
- AutoGetCollection autoColl(txn, nss, MODE_IS);
+ AutoGetCollection autoColl(opCtx, nss, MODE_IS);
- currentMetadata = CollectionShardingState::get(txn, nss)->getMetadata();
+ currentMetadata = CollectionShardingState::get(opCtx, nss)->getMetadata();
}
auto refreshLatestShardVersionStatus =
- _refreshMetadata(txn, nss, currentMetadata.getMetadata());
+ _refreshMetadata(opCtx, nss, currentMetadata.getMetadata());
if (!refreshLatestShardVersionStatus.isOK()) {
return refreshLatestShardVersionStatus.getStatus();
}
@@ -317,7 +317,7 @@ Status ShardingState::refreshMetadataNow(OperationContext* txn,
// NOTE: This method can be called inside a database lock so it should never take any database
// locks, perform I/O, or any long running operations.
-Status ShardingState::initializeFromShardIdentity(OperationContext* txn,
+Status ShardingState::initializeFromShardIdentity(OperationContext* opCtx,
const ShardIdentityType& shardIdentity) {
invariant(serverGlobalParams.clusterRole == ClusterRole::ShardServer);
@@ -360,7 +360,7 @@ Status ShardingState::initializeFromShardIdentity(OperationContext* txn,
ShardedConnectionInfo::addHook();
try {
- Status status = _globalInit(txn, configSvrConnStr, generateDistLockProcessId(txn));
+ Status status = _globalInit(opCtx, configSvrConnStr, generateDistLockProcessId(opCtx));
if (status.isOK()) {
log() << "initialized sharding components";
_setInitializationState(InitializationState::kInitialized);
@@ -398,7 +398,7 @@ void ShardingState::_setInitializationState(InitializationState newState) {
_initializationState.store(static_cast<uint32_t>(newState));
}
-StatusWith<bool> ShardingState::initializeShardingAwarenessIfNeeded(OperationContext* txn) {
+StatusWith<bool> ShardingState::initializeShardingAwarenessIfNeeded(OperationContext* opCtx) {
// In sharded readOnly mode, we ignore the shardIdentity document on disk and instead *require*
// a shardIdentity document to be passed through --overrideShardIdentity.
if (storageGlobalParams.readOnly) {
@@ -413,7 +413,7 @@ StatusWith<bool> ShardingState::initializeShardingAwarenessIfNeeded(OperationCon
if (!swOverrideShardIdentity.isOK()) {
return swOverrideShardIdentity.getStatus();
}
- auto status = initializeFromShardIdentity(txn, swOverrideShardIdentity.getValue());
+ auto status = initializeFromShardIdentity(opCtx, swOverrideShardIdentity.getValue());
if (!status.isOK()) {
return status;
}
@@ -448,12 +448,12 @@ StatusWith<bool> ShardingState::initializeShardingAwarenessIfNeeded(OperationCon
}
// Load the shardIdentity document from disk.
- invariant(!txn->lockState()->isLocked());
+ invariant(!opCtx->lockState()->isLocked());
BSONObj shardIdentityBSON;
bool foundShardIdentity = false;
try {
- AutoGetCollection autoColl(txn, NamespaceString::kConfigCollectionNamespace, MODE_IS);
- foundShardIdentity = Helpers::findOne(txn,
+ AutoGetCollection autoColl(opCtx, NamespaceString::kConfigCollectionNamespace, MODE_IS);
+ foundShardIdentity = Helpers::findOne(opCtx,
autoColl.getCollection(),
BSON("_id" << ShardIdentityType::IdName),
shardIdentityBSON);
@@ -477,7 +477,7 @@ StatusWith<bool> ShardingState::initializeShardingAwarenessIfNeeded(OperationCon
if (!swShardIdentity.isOK()) {
return swShardIdentity.getStatus();
}
- auto status = initializeFromShardIdentity(txn, swShardIdentity.getValue());
+ auto status = initializeFromShardIdentity(opCtx, swShardIdentity.getValue());
if (!status.isOK()) {
return status;
}
@@ -496,8 +496,10 @@ StatusWith<bool> ShardingState::initializeShardingAwarenessIfNeeded(OperationCon
}
StatusWith<ChunkVersion> ShardingState::_refreshMetadata(
- OperationContext* txn, const NamespaceString& nss, const CollectionMetadata* metadataForDiff) {
- invariant(!txn->lockState()->isLocked());
+ OperationContext* opCtx,
+ const NamespaceString& nss,
+ const CollectionMetadata* metadataForDiff) {
+ invariant(!opCtx->lockState()->isLocked());
invariant(enabled());
@@ -533,8 +535,8 @@ StatusWith<ChunkVersion> ShardingState::_refreshMetadata(
<< (metadataForDiff ? metadataForDiff->getCollVersion().toString() : "(empty)");
remoteMetadata = stdx::make_unique<CollectionMetadata>();
- status = MetadataLoader::makeCollectionMetadata(txn,
- grid.catalogClient(txn),
+ status = MetadataLoader::makeCollectionMetadata(opCtx,
+ grid.catalogClient(opCtx),
nss.ns(),
getShardName(),
metadataForDiff,
@@ -550,21 +552,21 @@ StatusWith<ChunkVersion> ShardingState::_refreshMetadata(
}
// Exclusive collection lock needed since we're now changing the metadata
- ScopedTransaction transaction(txn, MODE_IX);
- AutoGetCollection autoColl(txn, nss, MODE_IX, MODE_X);
+ ScopedTransaction transaction(opCtx, MODE_IX);
+ AutoGetCollection autoColl(opCtx, nss, MODE_IX, MODE_X);
- auto css = CollectionShardingState::get(txn, nss);
+ auto css = CollectionShardingState::get(opCtx, nss);
if (!status.isOK()) {
invariant(status == ErrorCodes::NamespaceNotFound);
- css->refreshMetadata(txn, nullptr);
+ css->refreshMetadata(opCtx, nullptr);
log() << "MetadataLoader took " << t.millis() << " ms and did not find the namespace";
return ChunkVersion::UNSHARDED();
}
- css->refreshMetadata(txn, std::move(remoteMetadata));
+ css->refreshMetadata(opCtx, std::move(remoteMetadata));
auto metadata = css->getMetadata();
@@ -588,11 +590,11 @@ boost::optional<NamespaceString> ShardingState::getActiveDonateChunkNss() {
return _activeMigrationsRegistry.getActiveDonateChunkNss();
}
-BSONObj ShardingState::getActiveMigrationStatusReport(OperationContext* txn) {
- return _activeMigrationsRegistry.getActiveMigrationStatusReport(txn);
+BSONObj ShardingState::getActiveMigrationStatusReport(OperationContext* opCtx) {
+ return _activeMigrationsRegistry.getActiveMigrationStatusReport(opCtx);
}
-void ShardingState::appendInfo(OperationContext* txn, BSONObjBuilder& builder) {
+void ShardingState::appendInfo(OperationContext* opCtx, BSONObjBuilder& builder) {
const bool isEnabled = enabled();
builder.appendBool("enabled", isEnabled);
if (!isEnabled)
@@ -620,19 +622,19 @@ void ShardingState::appendInfo(OperationContext* txn, BSONObjBuilder& builder) {
versionB.done();
}
-bool ShardingState::needCollectionMetadata(OperationContext* txn, const string& ns) {
+bool ShardingState::needCollectionMetadata(OperationContext* opCtx, const string& ns) {
if (!enabled())
return false;
- Client* client = txn->getClient();
+ Client* client = opCtx->getClient();
// Shard version information received from mongos may either by attached to the Client or
// directly to the OperationContext.
return ShardedConnectionInfo::get(client, false) ||
- OperationShardingState::get(txn).hasShardVersion();
+ OperationShardingState::get(opCtx).hasShardVersion();
}
-Status ShardingState::updateShardIdentityConfigString(OperationContext* txn,
+Status ShardingState::updateShardIdentityConfigString(OperationContext* opCtx,
const std::string& newConnectionString) {
BSONObj updateObj(ShardIdentityType::createConfigServerUpdateObject(newConnectionString));
@@ -643,9 +645,9 @@ Status ShardingState::updateShardIdentityConfigString(OperationContext* txn,
updateReq.setLifecycle(&updateLifecycle);
try {
- AutoGetOrCreateDb autoDb(txn, NamespaceString::kConfigCollectionNamespace.db(), MODE_X);
+ AutoGetOrCreateDb autoDb(opCtx, NamespaceString::kConfigCollectionNamespace.db(), MODE_X);
- auto result = update(txn, autoDb.getDb(), updateReq);
+ auto result = update(opCtx, autoDb.getDb(), updateReq);
if (result.numMatched == 0) {
warning() << "failed to update config string of shard identity document because "
<< "it does not exist. This shard could have been removed from the cluster";