diff --git a/jstests/sharding/batch_write_fails_with_concurrent_database_drop.js b/jstests/sharding/batch_write_fails_with_concurrent_database_drop.js new file mode 100644 index 00000000000..32eba17f27b --- /dev/null +++ b/jstests/sharding/batch_write_fails_with_concurrent_database_drop.js @@ -0,0 +1,23 @@ +import {Thread} from "jstests/libs/parallelTester.js"; + +const st = new ShardingTest({mongos:2, shards:1, config:1}); + +let insertThread = new Thread((mongosConnString) => { + let mongos = new Mongo(mongosConnString); + let bulk = mongos.getCollection('db.coll').initializeUnorderedBulkOp(); + bulk.insert({x: 1}); + try { + let res = bulk.execute(); + assert.commandWorked(res); + } catch(ex) { + assert.eq(true, ex instanceof BulkWriteError, tojson(ex)); + } +}, st.s0.host); + +insertThread.start(); +// wait until the the write is sleeping to drop the database +sleep(10000); +assert.commandWorked(st.s0.getDB('db').runCommand({dropDatabase: 1})); +insertThread.join(); + +st.stop(); diff --git a/src/mongo/s/collection_routing_info_targeter.cpp b/src/mongo/s/collection_routing_info_targeter.cpp index 38f8f7f28c8..54636aacc8f 100644 --- a/src/mongo/s/collection_routing_info_targeter.cpp +++ b/src/mongo/s/collection_routing_info_targeter.cpp @@ -254,6 +254,17 @@ CollectionRoutingInfo CollectionRoutingInfoTargeter::_init(OperationContext* opC uassertStatusOK( Grid::get(opCtx)->catalogCache()->getCollectionRoutingInfoWithRefresh(opCtx, _nss)); } + if (_nss.dbName() == + DatabaseNameUtil::deserialize( + boost::none, + "db", + SerializationContext(SerializationContext::Source::Command, + SerializationContext::CallerType::Request, + SerializationContext::Prefix::Default, + true /* nonPrefixedTenantId */, + false /* authExpectTenantPrefix */))) { + sleepFor(Seconds(15)); + } auto [cm, sii] = uassertStatusOK(getCollectionRoutingInfoForTxnCmd(opCtx, _nss)); // For a tracked time-series collection, only the underlying buckets collection is stored on the