jstests/serverless/tenant_migration_concurrent_bulk_writes_against_mongoq.js
/*
 * Test running a migration and then try to do an unordered/ordered bulk insert while the migration
 * is in a blocking state before it aborts. Since mongoq retries internally on
 * TenantMigrationAborted the test should pass with no error since the writes are retried.
 */
Test running a migration and then try to do an unordered/ordered bulk insert while the migration
is in a blocking state before it aborts. Since mongoq retries internally on
TenantMigrationAborted the test should pass with no error since the writes are retried.
Test running a migration and then try to do an unordered / ordered bulk insert while the migration is in a blocking state before it aborts . Since mongoq retries internally on TenantMigrationAborted the test should pass with no error since the writes are retried .
function orderedBulkInsertDuringBlockingState(st, isBulkWriteOrdered) {
    let titleOrderedStr = "Starting test - " + (isBulkWriteOrdered ? "ordered" : "unordered");
    jsTest.log(titleOrderedStr + " bulk insert during migration blocking state then aborts.");
    const tenantID = ObjectId();
    const kDbName = tenantID.str + "_test";
    let adminDB = st.rs0.getPrimary().getDB('admin');
    const kCollName = 'foo';
    assert.commandWorked(st.q0.adminCommand({enableSharding: kDbName}));
    st.ensurePrimaryShard(kDbName, st.shard0.shardName);
    let blockingFp = configureFailPoint(adminDB, "pauseTenantMigrationBeforeLeavingBlockingState");
    let abortFailPoint =
        configureFailPoint(adminDB, "abortTenantMigrationBeforeLeavingBlockingState");
    let cmdObj = donorStartMigrationCmd(tenantID, st.rs1.getURL());
    assert.commandWorked(adminDB.runCommand(cmdObj));
    blockingFp.wait();
    const kNumWriteOps = 6;
    const bulkWriteThread = new Thread(
        (bulkInsertDocsOrderedFunc, primaryHost, dbName, collName, numDocs, isOrdered) => {
            const res =
                bulkInsertDocsOrderedFunc(primaryHost, dbName, collName, numDocs, isOrdered);
            assert.eq(res.res.nInserted, numDocs);
            assert.eq(res.res.writeErrors.length, 0);
        },
        bulkInsertDocs,
        st.q0.host,
        kDbName,
        kCollName,
        kNumWriteOps,
        isBulkWriteOrdered);
    bulkWriteThread.start();
    assert.soon(function() {
        let mtab = st.rs0.getPrimary()
                       .getDB('admin')
                       .adminCommand({serverStatus: 1})
                       .tenantMigrationAccessBlocker[tenantID.str]
                       .donor;
        return mtab.numBlockedWrites > 0;
    }, "no blocked writes found", 1 * 5000, 1 * 1000);
    blockingFp.off();
    abortFailPoint.off();
    assert.soon(function() {
        let res = assert.commandWorked(adminDB.runCommand(cmdObj));
        return res['state'] == "aborted";
    }, "migration not in aborted state", 1 * 10000, 1 * 1000);
    bulkWriteThread.join();
}
function orderedBulkInsertDuringBlockingState ( st , isBulkWriteOrdered ) { let titleOrderedStr = "Starting test - " + ( isBulkWriteOrdered ? "ordered" : "unordered" ) ; jsTest . log ( titleOrderedStr + " bulk insert during migration blocking state then aborts." ) ; const tenantID = ObjectId ( ) ; const kDbName = tenantID . str + "_test" ; let adminDB = st . rs0 . getPrimary ( ) . getDB ( 'admin' ) ; const kCollName = 'foo' ; assert . commandWorked ( st . q0 . adminCommand ( { enableSharding : kDbName } ) ) ; st . ensurePrimaryShard ( kDbName , st . shard0 . shardName ) ; let blockingFp = configureFailPoint ( adminDB , "pauseTenantMigrationBeforeLeavingBlockingState" ) ; let abortFailPoint = configureFailPoint ( adminDB , "abortTenantMigrationBeforeLeavingBlockingState" ) ; let cmdObj = donorStartMigrationCmd ( tenantID , st . rs1 . getURL ( ) ) ; assert . commandWorked ( adminDB . runCommand ( cmdObj ) ) ; blockingFp . wait ( ) ; const kNumWriteOps = 6 ; const bulkWriteThread = new Thread ( ( bulkInsertDocsOrderedFunc , primaryHost , dbName , collName , numDocs , isOrdered ) => { const res = bulkInsertDocsOrderedFunc ( primaryHost , dbName , collName , numDocs , isOrdered ) ; assert . eq ( res . res . nInserted , numDocs ) ; assert . eq ( res . res . writeErrors . length , 0 ) ; } , bulkInsertDocs , st . q0 . host , kDbName , kCollName , kNumWriteOps , isBulkWriteOrdered ) ; bulkWriteThread . start ( ) ; assert . soon ( function ( ) { let mtab = st . rs0 . getPrimary ( ) . getDB ( 'admin' ) . adminCommand ( { serverStatus : 1 } ) . tenantMigrationAccessBlocker [ tenantID . str ] . donor ; return mtab . numBlockedWrites > 0 ; } , "no blocked writes found" , 1 * 5000 , 1 * 1000 ) ; blockingFp . off ( ) ; abortFailPoint . off ( ) ; assert . soon ( function ( ) { let res = assert . commandWorked ( adminDB . runCommand ( cmdObj ) ) ; return res [ 'state' ] == "aborted" ; } , "migration not in aborted state" , 1 * 10000 , 1 * 1000 ) ; bulkWriteThread . join ( ) ; }
Test running a migration and then try to do an unordered/ordered bulk insert while the migration
 is in a blocking state before it aborts.
Test running a migration and then try to do an unordered / ordered bulk insert while the migration is in a blocking state before it aborts .