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

trace_missing_docs_test.js compares Timestamp instances using < operator in mongo shell

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.6.12, 3.0.8, 3.2.0-rc0
    • Affects Version/s: 2.6.11, 3.0.6, 3.1.9
    • Component/s: Sharding
    • None
    • Fully Compatible
    • ALL
    • Hide
      > var a = Timestamp(1444326827, 10)
      > var b = Timestamp(1444326827, 4)
      > a < b
      true
      
      Show
      > var a = Timestamp(1444326827, 10) > var b = Timestamp(1444326827, 4) > a < b true

      Task
      Logs

      The compareOps function in trace_missing_docs.js compares the optimes of two oplog entries using the JavaScript < operator. This (probably) coerces the objects to strings and compares their string representations.

      var compareOps = function( opA, opB ) {
          if ( opA.ts < opB.ts ) return -1;
          if ( opB.ts < opA.ts ) return 1;
          else return 0;
      }
      
      allOps.sort( compareOps );
      

      The test fails because it expects the insert operation to be first for this shard key, but '10' < '4' causes the delete operation to come first. bsonWoCompare(Timestamp(1444326827, 10), Timestamp(1444326827, 4)) returns 1 as expected, so the fix should be to use the bsonWoCompare() function instead.

      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.938+0000 ----
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.939+0000 Using shard key : { "sk" : 67890 }
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.939+0000 ----
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.939+0000
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.939+0000
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.941+0000 Ops found for doc { "_id" : 12345, "sk" : 67890 } on each shard:
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.941+0000
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.941+0000 {
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.942+0000  "ts" : Timestamp(1444326827, 10),
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.942+0000  "h" : NumberLong(0),
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.942+0000  "v" : 2,
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.942+0000  "op" : "d",
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.942+0000  "ns" : "foo.bar",
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.942+0000  "o" : {
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.942+0000    "_id" : 12345
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.943+0000  },
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.943+0000  "shard" : "shard0000",
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.943+0000  "realTime" : ISODate("2015-10-08T17:53:47Z")
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.943+0000 }
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.943+0000 {
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.943+0000  "ts" : Timestamp(1444326827, 4),
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.943+0000  "h" : NumberLong(0),
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.943+0000  "v" : 2,
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.944+0000  "op" : "i",
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.944+0000  "ns" : "foo.bar",
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.944+0000  "o" : {
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.944+0000    "_id" : 12345,
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.944+0000    "sk" : 67890,
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.944+0000    "hello" : "world"
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.944+0000  },
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.944+0000  "shard" : "shard0000",
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.945+0000  "realTime" : ISODate("2015-10-08T17:53:47Z")
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.945+0000 }
      ...
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.950+0000 2015-10-08T17:53:47.943+0000 E QUERY    [thread1] Error: ["d"] != ["i"] are not equal : undefined :
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.950+0000 doassert@src/mongo/shell/assert.js:15:14
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.950+0000 assert.eq@src/mongo/shell/assert.js:43:5
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.950+0000 testDocMissing@jstests/sharding/trace_missing_docs_test.js:39:1
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.950+0000 @jstests/sharding/trace_missing_docs_test.js:49:1
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.950+0000
      [js_test:trace_missing_docs_test] 2015-10-08T17:53:47.950+0000 failed to load: jstests/sharding/trace_missing_docs_test.js
      

            Assignee:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Reporter:
            max.hirschhorn@mongodb.com Max Hirschhorn
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: