jstests/libs/override_methods/inject_tenant_prefix.js
/**
 * If the command was a batch command where some of the operations failed, modifies the command
 * object so that only failed operations are retried.
 */
If the command was a batch command where some of the operations failed, modifies the command
object so that only failed operations are retried.
If the command was a batch command where some of the operations failed modifies the command object so that only failed operations are retried .
function modifyCmdObjForRetry(cmdObj, resObj) {
    if (!resObj.hasOwnProperty("writeErrors") && ErrorCodes.isTenantMigrationError(resObj.code)) {
        return;
    }
    if (cmdObj.insert) {
        let retryOps = [];
        if (cmdObj.ordered === false) {
            for (let writeError of resObj.writeErrors) {
                if (ErrorCodes.isTenantMigrationError(writeError.code)) {
                    retryOps.push(cmdObj.documents[writeError.index]);
                }
            }
        } else {
            retryOps = cmdObj.documents.slice(resObj.writeErrors[0].index);
        }
        cmdObj.documents = retryOps;
    }
    if (cmdObj.update && !cmdObj.findAndModify && !cmdObj.findandmodify) {
        let retryOps = [];
        if (cmdObj.ordered === false) {
            for (let writeError of resObj.writeErrors) {
                if (ErrorCodes.isTenantMigrationError(writeError.code)) {
                    retryOps.push(cmdObj.updates[writeError.index]);
                }
            }
        } else {
            retryOps = cmdObj.updates.slice(resObj.writeErrors[0].index);
        }
        cmdObj.updates = retryOps;
    }
    if (cmdObj.delete) {
        let retryOps = [];
        if (cmdObj.ordered === false) {
            for (let writeError of resObj.writeErrors) {
                if (ErrorCodes.isTenantMigrationError(writeError.code)) {
                    retryOps.push(cmdObj.deletes[writeError.index]);
                }
            }
        } else {
            retryOps = cmdObj.deletes.slice(resObj.writeErrors[0].index);
        }
        cmdObj.deletes = retryOps;
    }
}
function modifyCmdObjForRetry ( cmdObj , resObj ) { if ( ! resObj . hasOwnProperty ( "writeErrors" ) && ErrorCodes . isTenantMigrationError ( resObj . code ) ) { return ; } if ( cmdObj . insert ) { let retryOps = [ ] ; if ( cmdObj . ordered === false ) { for ( let writeError of resObj . writeErrors ) { if ( ErrorCodes . isTenantMigrationError ( writeError . code ) ) { retryOps . push ( cmdObj . documents [ writeError . index ] ) ; } } } else { retryOps = cmdObj . documents . slice ( resObj . writeErrors [ 0 ] . index ) ; } cmdObj . documents = retryOps ; } if ( cmdObj . update && ! cmdObj . findAndModify && ! cmdObj . findandmodify ) { let retryOps = [ ] ; if ( cmdObj . ordered === false ) { for ( let writeError of resObj . writeErrors ) { if ( ErrorCodes . isTenantMigrationError ( writeError . code ) ) { retryOps . push ( cmdObj . updates [ writeError . index ] ) ; } } } else { retryOps = cmdObj . updates . slice ( resObj . writeErrors [ 0 ] . index ) ; } cmdObj . updates = retryOps ; } if ( cmdObj . delete ) { let retryOps = [ ] ; if ( cmdObj . ordered === false ) { for ( let writeError of resObj . writeErrors ) { if ( ErrorCodes . isTenantMigrationError ( writeError . code ) ) { retryOps . push ( cmdObj . deletes [ writeError . index ] ) ; } } } else { retryOps = cmdObj . deletes . slice ( resObj . writeErrors [ 0 ] . index ) ; } cmdObj . deletes = retryOps ; } }
If the command was a batch command where some of the operations failed, modifies the command
 object so that only failed operations are retried.
If the command was a batch command where some of the operations failed modifies the command object so that only failed operations are retried .
// If we get a top level error without writeErrors, retry the entire command. // findAndModify may also have an update field, but is not a batched command.