diff options
author | Tommaso Tocci <tommaso.tocci@mongodb.com> | 2022-12-04 01:07:01 +0100 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-12-04 09:48:57 +0000 |
commit | 62c6074e3342169809d5c01fd62452c082667c88 (patch) | |
tree | 13dabbea1336994b904cef457c58aaf25d1dbb12 | |
parent | 69cc757bea9f7d62cfea7309cebaaa55a95a3a3a (diff) | |
download | mongo-62c6074e3342169809d5c01fd62452c082667c88.tar.gz |
SERVER-71759 dataSize command doesn't yield
-rw-r--r-- | src/mongo/db/commands/dbcommands.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/src/mongo/db/commands/dbcommands.cpp b/src/mongo/db/commands/dbcommands.cpp index 1b20f38ae52..08aec5b0c0d 100644 --- a/src/mongo/db/commands/dbcommands.cpp +++ b/src/mongo/db/commands/dbcommands.cpp @@ -295,13 +295,19 @@ public: bool estimate = jsobj["estimate"].trueValue(); const NamespaceString nss(ns); - AutoGetCollectionForReadCommand collection(opCtx, nss); + AutoGetCollectionForReadCommand autoColl(opCtx, nss); + const auto& collection = autoColl.getCollection(); - const auto collDesc = - CollectionShardingState::get(opCtx, nss)->getCollectionDescription(opCtx); + if (!collection) { + // Collection does not exist + result.appendNumber("size", 0); + result.appendNumber("numObjects", 0); + result.append("millis", timer.millis()); + return true; + } - if (collDesc.isSharded()) { - const ShardKeyPattern shardKeyPattern(collDesc.getKeyPattern()); + if (collection.isSharded()) { + const ShardKeyPattern shardKeyPattern(collection.getShardKeyPattern()); uassert(ErrorCodes::BadValue, "keyPattern must be empty or must be an object that equals the shard key", keyPattern.isEmpty() || @@ -319,10 +325,7 @@ public: max = shardKeyPattern.normalizeShardKey(max); } - long long numRecords = 0; - if (collection) { - numRecords = collection->numRecords(opCtx); - } + const long long numRecords = collection->numRecords(opCtx); if (numRecords == 0) { result.appendNumber("size", 0); @@ -342,7 +345,7 @@ public: return 1; } exec = InternalPlanner::collectionScan( - opCtx, &collection.getCollection(), PlanYieldPolicy::YieldPolicy::INTERRUPT_ONLY); + opCtx, &collection, PlanYieldPolicy::YieldPolicy::YIELD_AUTO); } else if (min.isEmpty() || max.isEmpty()) { errmsg = "only one of min or max specified"; return false; @@ -353,7 +356,7 @@ public: } auto shardKeyIdx = findShardKeyPrefixedIndex(opCtx, - *collection, + collection, collection->getIndexCatalog(), keyPattern, /*requireSingleKey=*/true); @@ -368,12 +371,12 @@ public: max = Helpers::toKeyFormat(kp.extendRangeBound(max, false)); exec = InternalPlanner::shardKeyIndexScan(opCtx, - &collection.getCollection(), + &collection, *shardKeyIdx, min, max, BoundInclusion::kIncludeStartKeyOnly, - PlanYieldPolicy::YieldPolicy::INTERRUPT_ONLY); + PlanYieldPolicy::YieldPolicy::YIELD_AUTO); } CurOpFailpointHelpers::waitWhileFailPointEnabled( |