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

Failed applyOps command does not create an oplog entry even with some successful writes

    • Storage Execution
    • ALL
    • Repl 2016-11-21

      If an applyOps command is run with some valid ops and some invalid ops, the valid ones can be actually applied, but then the applyOps fails and no oplog entries are generated for the writes performed as part of the valid ops.

      The manifestation of the bug is a result of the change from SERVER-17634, so it only affects 3.1.1+.

      Server output:

      [repl writer worker 0] writer worker caught exception:  :: caused by :: 26 Failed to apply insert due to missing collection: { ts: Timestamp 1438736773000|1, h: 2778434085248541821, v: 2, op: "i", ns: "test.foo", o: { _id: ObjectId('55c1618530cd6c7ac35af4b7') } } on: { ts: Timestamp 1438736773000|1, h: 2778434085248541821, v: 2, op: "i", ns: "test.foo", o: { _id: ObjectId('55c1618530cd6c7ac35af4b7') } }
      [repl writer worker 0] Fatal Assertion 16360
      [repl writer worker 0] 
       
       ***aborting after fassert() failure
      

      Repro script:

      // Start up a replica set with at least one secondary
      var rst = new ReplSetTest({nodes: 2});
      rst.startSet();
      rst.initiate();
      
      var t = rst.getPrimary().getDB('test').foo;
      t.drop();
      
      var ops = [
          // The first op is valid and results in one document being written to 'test.foo'
          {op: 'u', ns: t.getFullName(), o2: {_id: 0}},
          // The second op is invalid
          {op: 'f', ns: t.getFullName(), o2: {}}
      ];
      
      // The command fails, but a 'test.foo' collection is created on the primary and a document is inserted into the collection.
      // A 'test.foo' collection is not created on the secondary because the update op is not written to the oplog.
      t.runCommand({applyOps: ops});
      
      // This follow-up insert will cause an fassert on the secondary:
      // 'Failed to apply insert due to missing collection'
      t.insert({});
      
      rst.awaitReplication();
      rst.stopSet();
      

            Assignee:
            backlog-server-execution [DO NOT USE] Backlog - Storage Execution Team
            Reporter:
            kamran.khan Kamran K.
            Votes:
            3 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:
              Resolved: