Files
mongo/jstests/sharding/drop_database_before_write_is_targeted.js
Antonio Fuschetto fa341e1f21 SERVER-83146 Bulk write operation might fail with NamespaceNotFound
GitOrigin-RevId: 9eea1836e47c9ee7ae5287669961eb44776a8d18
2023-12-12 15:11:46 +00:00

41 lines
1.4 KiB
JavaScript

/**
* Verify that the write operation succeeds despite the database being dropped after the implicit
* creation and before the operation is targeted by the router.
*
* @tags: [
* # TODO (SERVER-84043): Requires the mongos to define the fail point. Enable multiversion
* # once 8.0 becomes last LTS.
* multiversion_incompatible
* ]
*/
import {configureFailPoint} from 'jstests/libs/fail_point_util.js';
import {Thread} from 'jstests/libs/parallelTester.js';
const dbName = 'test';
const collNS = dbName + '.foo';
const st = new ShardingTest({mongos: 1, shards: 1, config: 1});
// Pause the write operation after creating the database but before the operation is actually
// targeted by the router.
let failPoint = configureFailPoint(st.s, 'waitForDatabaseToBeDropped');
let insertThread = new Thread((mongosConnString, collNS) => {
let mongos = new Mongo(mongosConnString);
assert.commandWorked(mongos.getCollection(collNS).insert({}));
}, st.s0.host, collNS);
// Perform a write operation, the database is implicitly created then the operation is paused.
insertThread.start();
failPoint.wait();
// Before the router targets the write operation, the database is dropped.
assert.commandWorked(st.s0.getDB(dbName).runCommand({dropDatabase: 1}));
failPoint.off();
// The first targeting fails, then the database is recreated and the new targeting succeeds.
insertThread.join();
st.stop();