Skip to content

Commit 3edeea2

Browse files
jordistEvergreen Agent
authored andcommitted
SERVER-82811 ShardsvrProcessInterface::dropCollection should accept NamespaceNotFound errors due to the database having been dropped
1 parent 8749786 commit 3edeea2

File tree

2 files changed

+39
-23
lines changed

2 files changed

+39
-23
lines changed

jstests/noPassthrough/out_cleans_up_temp_collections_sharding.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ function failFn_dropDbAndSigKill() {
6565
failFn_sigkill();
6666
}
6767

68+
function failFn_dropDbAndKillOp() {
69+
testDB.dropDatabase();
70+
failFn_killOp();
71+
}
72+
6873
function testFn(timeseries, failFn) {
6974
assert.eq(0, getTempCollections().length);
7075

@@ -117,6 +122,10 @@ assert.commandWorked(sourceColl.insert({x: 1}));
117122
jsTest.log("Running test with normal collection and killOp");
118123
testFn(false, failFn_killOp);
119124

125+
jsTest.log("Running test with normal collection and dropDbAndkillOp");
126+
testFn(false, failFn_dropDbAndKillOp);
127+
assert.commandWorked(sourceColl.insert({x: 1}));
128+
120129
jsTest.log("Running test with timeseries collection and SIGKILL");
121130
testFn(true, failFn_sigkill);
122131

src/mongo/db/pipeline/process_interface/shardsvr_process_interface.cpp

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -459,29 +459,36 @@ void ShardServerProcessInterface::dropCollection(OperationContext* opCtx,
459459
// Build and execute the _shardsvrDropCollection command against the primary shard of the given
460460
// database.
461461
sharding::router::DBPrimaryRouter router(opCtx->getServiceContext(), ns.dbName());
462-
router.route(
463-
opCtx,
464-
"ShardServerProcessInterface::dropCollection",
465-
[&](OperationContext* opCtx, const CachedDatabaseInfo& cdb) {
466-
ShardsvrDropCollection dropCollectionCommand(ns);
467-
BSONObj cmdObj = CommandHelpers::appendMajorityWriteConcern(
468-
dropCollectionCommand.toBSON({}), opCtx->getWriteConcern());
469-
auto response = executeCommandAgainstDatabasePrimary(
470-
opCtx,
471-
ns.dbName(),
472-
cdb,
473-
cmdObj,
474-
ReadPreferenceSetting(ReadPreference::PrimaryOnly),
475-
Shard::RetryPolicy::kIdempotent);
476-
uassertStatusOKWithContext(response.swResponse,
477-
str::stream() << "failed while running command " << cmdObj);
478-
auto result = response.swResponse.getValue().data;
479-
uassertStatusOKWithContext(getStatusFromCommandResult(result),
480-
str::stream() << "failed while running command " << cmdObj);
481-
uassertStatusOKWithContext(
482-
getWriteConcernStatusFromCommandResult(result),
483-
str::stream() << "write concern failed while running command " << cmdObj);
484-
});
462+
try {
463+
router.route(opCtx,
464+
"ShardServerProcessInterface::dropCollection",
465+
[&](OperationContext* opCtx, const CachedDatabaseInfo& cdb) {
466+
ShardsvrDropCollection dropCollectionCommand(ns);
467+
BSONObj cmdObj = CommandHelpers::appendMajorityWriteConcern(
468+
dropCollectionCommand.toBSON({}), opCtx->getWriteConcern());
469+
auto response = executeCommandAgainstDatabasePrimary(
470+
opCtx,
471+
ns.dbName(),
472+
cdb,
473+
cmdObj,
474+
ReadPreferenceSetting(ReadPreference::PrimaryOnly),
475+
Shard::RetryPolicy::kIdempotent);
476+
uassertStatusOKWithContext(response.swResponse,
477+
str::stream() << "failed while running command "
478+
<< cmdObj);
479+
auto result = response.swResponse.getValue().data;
480+
uassertStatusOKWithContext(getStatusFromCommandResult(result),
481+
str::stream() << "failed while running command "
482+
<< cmdObj);
483+
uassertStatusOKWithContext(
484+
getWriteConcernStatusFromCommandResult(result),
485+
str::stream()
486+
<< "write concern failed while running command " << cmdObj);
487+
});
488+
} catch (const ExceptionFor<ErrorCodes::NamespaceNotFound>&) {
489+
// The database might have been dropped by a different operation, so the collection no
490+
// longer exists.
491+
}
485492
}
486493

487494
void ShardServerProcessInterface::dropTempCollection(OperationContext* opCtx,

0 commit comments

Comments
 (0)