jstests/noPassthrough/query_yields_catch_index_corruption.js
// entry (thanks to the "skipUnindexingDocumentWhenDeleted" failpoint).
entry (thanks to the "skipUnindexingDocumentWhenDeleted" failpoint).
entry ( thanks to the " skipUnindexingDocumentWhenDeleted " failpoint ) .
function createDanglingIndexEntry(doc) {
    assert.commandWorked(coll.insert(doc));
    assert.commandWorked(coll.remove(doc));
    const validateRes = assert.commandWorked(coll.validate());
    assert.eq(false, validateRes.valid);
    assert.commandFailedWithCode(coll.update(doc, {$set: {c: 1}}),
                                 ErrorCodes.DataCorruptionDetected);
    const session = db.getMongo().startSession();
    const sessionDB = session.getDatabase(dbName);
    session.startTransaction();
    assert.throwsWithCode(() => {
        sessionDB[collName].find(doc).toArray();
    }, ErrorCodes.DataCorruptionDetected);
    session.abortTransaction_forTesting();
}
function createDanglingIndexEntry ( doc ) { assert . commandWorked ( coll . insert ( doc ) ) ; assert . commandWorked ( coll . remove ( doc ) ) ; const validateRes = assert . commandWorked ( coll . validate ( ) ) ; assert . eq ( false , validateRes . valid ) ; assert . commandFailedWithCode ( coll . update ( doc , { $set : { c : 1 } } ) , ErrorCodes . DataCorruptionDetected ) ; const session = db . getMongo ( ) . startSession ( ) ; const sessionDB = session . getDatabase ( dbName ) ; session . startTransaction ( ) ; assert . throwsWithCode ( ( ) => { sessionDB [ collName ] . find ( doc ) . toArray ( ) ; } , ErrorCodes . DataCorruptionDetected ) ; session . abortTransaction_forTesting ( ) ; }
entry (thanks to the "skipUnindexingDocumentWhenDeleted" failpoint).
entry ( thanks to the " skipUnindexingDocumentWhenDeleted " failpoint ) .
// Validation should now fail. // A query that accesses the now dangling index entry should fail with a // "DataCorruptionDetected" error. Most reads will not detect this problem because they ignore // prepare conflicts by default and that exempts them from checking this assertion. Only writes // and reads in multi-document transactions enforce prepare conflicts and should encounter this // assertion.