Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-48081

Malformed document validators can cause a secondary to fail on oplog application

    • Type: Icon: Bug Bug
    • Resolution: Won't Fix
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • ALL
    • Hide
      diff --git a/jstests/noPassthrough/invalid_collection_validator_at_startup.js b/jstests/noPassthrough/invalid_collection_validator_at_startup.js
      index 2d453345a0..21a9e97e63 100644
      --- a/jstests/noPassthrough/invalid_collection_validator_at_startup.js
      +++ b/jstests/noPassthrough/invalid_collection_validator_at_startup.js
      @@ -12,13 +12,20 @@ const collName = "collectionWithMalformedValidator";
      
       // Create a collection with an invalid regex using a fail point.
       (function createCollectionWithMalformedValidator() {
      -    const conn = MongoRunner.runMongod({dbpath: dbpath});
      -    assert.neq(null, conn, "mongod was unable to start up");
      +    // const conn = MongoRunner.runMongod({dbpath: dbpath});
      +    // assert.neq(null, conn, "mongod was unable to start up");
      
      -    const testDB = conn.getDB("test");
      +    const rst = new ReplSetTest({
      +        nodes: 3,
      +    });
      +    rst.startSet();
      +    rst.initiate();
      +
      +    // const testDB = conn.getDB("test");
      +    const testDB = rst.getPrimary().getDB("test");
           assert.commandWorked(testDB[collName].insert({a: "hello world"}));
      
      -    assert.commandWorked(conn.adminCommand(
      +    assert.commandWorked(testDB.adminCommand(
               {configureFailPoint: 'allowSettingMalformedCollectionValidators', mode: 'alwaysOn'}));
      
           // Invalid because '*' indicates that repetitions should be allowed but it's preceded by a
      @@ -29,13 +36,21 @@ const collName = "collectionWithMalformedValidator";
           assert.commandWorked(
               testDB.runCommand({collMod: collName, validator: {email: {$regex: invalidRegex}}}));
      
      -    MongoRunner.stopMongod(conn);
      +    // MongoRunner.stopMongod(conn);
      +    rst.stopSet();
       })();
      
       (function startUpWithMalformedValidator() {
      -    const conn = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true});
      -    assert.neq(null, conn, "mongod was unable to start up");
      -    const testDB = conn.getDB("test");
      +    // const conn = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true});
      +    // assert.neq(null, conn, "mongod was unable to start up");
      +    // const testDB = conn.getDB("test");
      +    const rst = new ReplSetTest({
      +        nodes: 3,
      +        nodeOptions: {noCleanData: true},
      +    });
      +    rst.startSet();
      +    rst.initiate();
      +    const testDB = rst.getPrimary().getDB("test");
      
           // Check that we logged a startup warning.
           const cmdRes = assert.commandWorked(testDB.adminCommand({getLog: "startupWarnings"}));
      @@ -48,6 +63,7 @@ const collName = "collectionWithMalformedValidator";
           assert.commandWorked(testDB.someOtherCollection.insert({a: 1}));
           assert.eq(testDB.someOtherCollection.find().itcount(), 1);
      
      -    MongoRunner.stopMongod(conn);
      +    // MongoRunner.stopMongod(conn);
      +    rst.stopSet();
       })();
       })();
      
      
      Show
      diff --git a/jstests/noPassthrough/invalid_collection_validator_at_startup.js b/jstests/noPassthrough/invalid_collection_validator_at_startup.js index 2d453345a0..21a9e97e63 100644 --- a/jstests/noPassthrough/invalid_collection_validator_at_startup.js +++ b/jstests/noPassthrough/invalid_collection_validator_at_startup.js @@ -12,13 +12,20 @@ const collName = "collectionWithMalformedValidator"; // Create a collection with an invalid regex using a fail point. (function createCollectionWithMalformedValidator() { - const conn = MongoRunner.runMongod({dbpath: dbpath}); - assert.neq(null, conn, "mongod was unable to start up"); + // const conn = MongoRunner.runMongod({dbpath: dbpath}); + // assert.neq(null, conn, "mongod was unable to start up"); - const testDB = conn.getDB("test"); + const rst = new ReplSetTest({ + nodes: 3, + }); + rst.startSet(); + rst.initiate(); + + // const testDB = conn.getDB("test"); + const testDB = rst.getPrimary().getDB("test"); assert.commandWorked(testDB[collName].insert({a: "hello world"})); - assert.commandWorked(conn.adminCommand( + assert.commandWorked(testDB.adminCommand( {configureFailPoint: 'allowSettingMalformedCollectionValidators', mode: 'alwaysOn'})); // Invalid because '*' indicates that repetitions should be allowed but it's preceded by a @@ -29,13 +36,21 @@ const collName = "collectionWithMalformedValidator"; assert.commandWorked( testDB.runCommand({collMod: collName, validator: {email: {$regex: invalidRegex}}})); - MongoRunner.stopMongod(conn); + // MongoRunner.stopMongod(conn); + rst.stopSet(); })(); (function startUpWithMalformedValidator() { - const conn = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true}); - assert.neq(null, conn, "mongod was unable to start up"); - const testDB = conn.getDB("test"); + // const conn = MongoRunner.runMongod({dbpath: dbpath, noCleanData: true}); + // assert.neq(null, conn, "mongod was unable to start up"); + // const testDB = conn.getDB("test"); + const rst = new ReplSetTest({ + nodes: 3, + nodeOptions: {noCleanData: true}, + }); + rst.startSet(); + rst.initiate(); + const testDB = rst.getPrimary().getDB("test"); // Check that we logged a startup warning. const cmdRes = assert.commandWorked(testDB.adminCommand({getLog: "startupWarnings"})); @@ -48,6 +63,7 @@ const collName = "collectionWithMalformedValidator"; assert.commandWorked(testDB.someOtherCollection.insert({a: 1})); assert.eq(testDB.someOtherCollection.find().itcount(), 1); - MongoRunner.stopMongod(conn); + // MongoRunner.stopMongod(conn); + rst.stopSet(); })(); })();
    • Query 2020-11-30, Query 2020-12-14, Query 2020-12-28, Query 2021-01-11, Query 2021-01-25

      Found as part of SERVER-45514, which is testing that we can upgrade a replica set with a persisted document validator that is considered invalid in the "latest" binVersion (4.4 in this case). If one of the secondaries is lagging behind and does not yet apply the "create" oplog entry, then upon upgrade the secondary will fassert on oplog application.

      Note that there are two distinct paths to a failure. One is the case described above, where a node is catching up after upgrade and encounters the malformed doc validator. The second is when the node starts up and already has the entry for the "create". In that case, it will happily build the in-memory Collection state with a non-OK validator, however any subsequent inserts to that collection will fail on oplog application.

            Assignee:
            ted.tuckman@mongodb.com Ted Tuckman
            Reporter:
            nicholas.zolnierz@mongodb.com Nicholas Zolnierz
            Votes:
            0 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved: