summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTommaso Tocci <tommaso.tocci@mongodb.com>2021-04-30 21:12:43 +0200
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-05-01 12:06:51 +0000
commite345b88ddca4ec85dc59768647be2e531e490e04 (patch)
treeae63b4d2022cf64fd2012add578a6495edc0b9a0
parentf20694e185d58d347fff7c8bf8ab791fcbc45f65 (diff)
downloadmongo-e345b88ddca4ec85dc59768647be2e531e490e04.tar.gz
SERVER-56556 create collection coordinator waits on wrong opTime to be mojority committe
-rw-r--r--src/mongo/db/s/create_collection_coordinator.cpp14
-rw-r--r--src/mongo/db/s/shard_key_util.cpp5
-rw-r--r--src/mongo/db/s/shard_key_util.h4
3 files changed, 16 insertions, 7 deletions
diff --git a/src/mongo/db/s/create_collection_coordinator.cpp b/src/mongo/db/s/create_collection_coordinator.cpp
index e55caf6674f..a03877475c4 100644
--- a/src/mongo/db/s/create_collection_coordinator.cpp
+++ b/src/mongo/db/s/create_collection_coordinator.cpp
@@ -603,7 +603,7 @@ void CreateCollectionCoordinator::_createCollectionAndIndexes(OperationContext*
return;
}
- shardkeyutil::validateShardKeyIndexExistsOrCreateIfPossible(
+ const auto indexCreated = shardkeyutil::validateShardKeyIndexExistsOrCreateIfPossible(
opCtx,
nss(),
*_shardKeyPattern,
@@ -611,12 +611,18 @@ void CreateCollectionCoordinator::_createCollectionAndIndexes(OperationContext*
_doc.getUnique().value_or(false),
shardkeyutil::ValidationBehaviorsShardCollection(opCtx));
+ auto replClientInfo = repl::ReplClientInfo::forClient(opCtx->getClient());
+
+ if (!indexCreated) {
+ replClientInfo.setLastOpToSystemLastOpTime(opCtx);
+ }
// Wait until the index is majority written, to prevent having the collection commited to the
// config server, but the index creation rolled backed on stepdowns.
WriteConcernResult ignoreResult;
- auto latestOpTime = repl::ReplClientInfo::forClient(opCtx->getClient()).getLastOp();
- uassertStatusOK(waitForWriteConcern(
- opCtx, latestOpTime, ShardingCatalogClient::kMajorityWriteConcern, &ignoreResult));
+ uassertStatusOK(waitForWriteConcern(opCtx,
+ replClientInfo.getLastOp(),
+ ShardingCatalogClient::kMajorityWriteConcern,
+ &ignoreResult));
_collectionUUID = *getUUIDFromPrimaryShard(opCtx, nss());
}
diff --git a/src/mongo/db/s/shard_key_util.cpp b/src/mongo/db/s/shard_key_util.cpp
index 018164565ba..1f78b3f8cd4 100644
--- a/src/mongo/db/s/shard_key_util.cpp
+++ b/src/mongo/db/s/shard_key_util.cpp
@@ -179,7 +179,7 @@ bool validShardKeyIndexExists(OperationContext* opCtx,
return hasUsefulIndexForKey;
}
-void validateShardKeyIndexExistsOrCreateIfPossible(OperationContext* opCtx,
+bool validateShardKeyIndexExistsOrCreateIfPossible(OperationContext* opCtx,
const NamespaceString& nss,
const ShardKeyPattern& shardKeyPattern,
const boost::optional<BSONObj>& defaultCollation,
@@ -187,7 +187,7 @@ void validateShardKeyIndexExistsOrCreateIfPossible(OperationContext* opCtx,
const ShardKeyValidationBehaviors& behaviors) {
if (validShardKeyIndexExists(
opCtx, nss, shardKeyPattern, defaultCollation, unique, behaviors)) {
- return;
+ return false;
}
@@ -199,6 +199,7 @@ void validateShardKeyIndexExistsOrCreateIfPossible(OperationContext* opCtx,
// whenever a migrate occurs. If the collection has a default collation, explicitly send
// the simple collation as part of the createIndex request.
behaviors.createShardKeyIndex(nss, shardKeyPattern.toBSON(), defaultCollation, unique);
+ return true;
}
std::vector<BSONObj> ValidationBehaviorsShardCollection::loadIndexes(
diff --git a/src/mongo/db/s/shard_key_util.h b/src/mongo/db/s/shard_key_util.h
index 6d7a41db58e..cbce71b0540 100644
--- a/src/mongo/db/s/shard_key_util.h
+++ b/src/mongo/db/s/shard_key_util.h
@@ -142,8 +142,10 @@ private:
*
* 5. If the collection is empty and we are not refining the collection's shard key, and it's
* still possible to create an index on the proposed key, we go ahead and do so.
+ *
+ * Returns true if the index has been created, false otherwise.
*/
-void validateShardKeyIndexExistsOrCreateIfPossible(OperationContext* opCtx,
+bool validateShardKeyIndexExistsOrCreateIfPossible(OperationContext* opCtx,
const NamespaceString& nss,
const ShardKeyPattern& shardKeyPattern,
const boost::optional<BSONObj>& defaultCollation,