jstests/core/txns/libs/prepare_helpers.js
/**
     * Waits for the oplog to be truncated, proving that once a transaction finishes its oplog
     * entries can be reclaimed.
     */
Waits for the oplog to be truncated, proving that once a transaction finishes its oplog
entries can be reclaimed.
Waits for the oplog to be truncated proving that once a transaction finishes its oplog entries can be reclaimed .
function awaitOplogTruncation(replSet) {
        print(`Waiting for oplog to shrink to ${oplogSizeMB} MB`);
        const primary = replSet.getPrimary();
        const primaryOplog = primary.getDB("local").oplog.rs;
        const secondary = replSet.getSecondary();
        const secondaryOplog = secondary.getDB("local").oplog.rs;
        print("Add writes after transaction finished to trigger oplog reclamation");
        const tenKB = new Array(10 * 1024).join("a");
        const coll = primary.getDB("awaitOplogTruncation").awaitOplogTruncation;
        const numNodes = replSet.nodeList().length;
        for (let i = 0; i < 20; i++) {
            assert.commandWorked(coll.insert({tenKB: tenKB}, {writeConcern: {w: numNodes}}));
        }
        for (let [nodeName, oplog] of [["primary", primaryOplog], ["secondary", secondaryOplog]]) {
            assert.soon(function() {
                const dataSize = oplog.dataSize();
                const prepareEntryRemoved = (oplog.findOne({prepare: true}) === null);
                print(`${nodeName} oplog dataSize: ${dataSize},` +
                      ` prepare entry removed: ${prepareEntryRemoved}`);
                if (dataSize < 1.1 * oplogSizeBytes && prepareEntryRemoved) {
                    return true;
                }
                assert.commandWorked(coll.insert({tenKB: tenKB}, {writeConcern: {w: numNodes}}));
                return false;
            }, `waiting for ${nodeName} oplog reclamation`, ReplSetTest.kDefaultTimeoutMS, 1000);
        }
    }
function awaitOplogTruncation ( replSet ) { print ( ` ${ oplogSizeMB } ` ) ; const primary = replSet . getPrimary ( ) ; const primaryOplog = primary . getDB ( "local" ) . oplog . rs ; const secondary = replSet . getSecondary ( ) ; const secondaryOplog = secondary . getDB ( "local" ) . oplog . rs ; print ( "Add writes after transaction finished to trigger oplog reclamation" ) ; const tenKB = new Array ( 10 * 1024 ) . join ( "a" ) ; const coll = primary . getDB ( "awaitOplogTruncation" ) . awaitOplogTruncation ; const numNodes = replSet . nodeList ( ) . length ; for ( let i = 0 ; i < 20 ; i ++ ) { assert . commandWorked ( coll . insert ( { tenKB : tenKB } , { writeConcern : { w : numNodes } } ) ) ; } for ( let [ nodeName , oplog ] of [ [ "primary" , primaryOplog ] , [ "secondary" , secondaryOplog ] ] ) { assert . soon ( function ( ) { const dataSize = oplog . dataSize ( ) ; const prepareEntryRemoved = ( oplog . findOne ( { prepare : true } ) === null ) ; print ( ` ${ nodeName } ${ dataSize } ` + ` ${ prepareEntryRemoved } ` ) ; if ( dataSize < 1.1 * oplogSizeBytes && prepareEntryRemoved ) { return true ; } assert . commandWorked ( coll . insert ( { tenKB : tenKB } , { writeConcern : { w : numNodes } } ) ) ; return false ; } , ` ${ nodeName } ` , ReplSetTest . kDefaultTimeoutMS , 1000 ) ; } }
Waits for the oplog to be truncated, proving that once a transaction finishes its oplog
 entries can be reclaimed.
Waits for the oplog to be truncated proving that once a transaction finishes its oplog entries can be reclaimed .
// Old entries are reclaimed when oplog size reaches new milestone. With a 1MB oplog, // milestones are every 0.1 MB (see WiredTigerRecordStore::OplogStones::OplogStones) so // write about 0.2 MB to be certain. // The oplog milestone system allows the oplog to grow to 110% its max size.