diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2022-11-16 12:26:18 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-11-16 12:55:50 +0000 |
commit | 31b94b67c87cece2136e3b666eb5e55ef7349e84 (patch) | |
tree | fed98af46ee6fd84123c92611aebf6e2001281ef | |
parent | 4c57f0889744e8d7523f86dffcf41394913033b9 (diff) | |
download | mongo-31b94b67c87cece2136e3b666eb5e55ef7349e84.tar.gz |
SERVER-71305 Legacy shard collection path waits on wrong opTime to be majority committed
-rw-r--r-- | src/mongo/db/s/shard_collection_legacy.cpp | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/mongo/db/s/shard_collection_legacy.cpp b/src/mongo/db/s/shard_collection_legacy.cpp index ae231f35054..c9f48805c80 100644 --- a/src/mongo/db/s/shard_collection_legacy.cpp +++ b/src/mongo/db/s/shard_collection_legacy.cpp @@ -572,9 +572,10 @@ CreateCollectionResponse shardCollection(OperationContext* opCtx, checkCollation(opCtx, request); + bool indexCreated = false; if (request.getImplicitlyCreateIndex().value_or(true)) { // Create the collection locally - shardkeyutil::validateShardKeyIndexExistsOrCreateIfPossible( + indexCreated = shardkeyutil::validateShardKeyIndexExistsOrCreateIfPossible( opCtx, nss, ShardKeyPattern(request.getKey()), @@ -594,12 +595,19 @@ CreateCollectionResponse shardCollection(OperationContext* opCtx, 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)); targetState = calculateTargetState(opCtx, nss, request); |