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

Change comparison order so all Dates sort before all Timestamps

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.8.0-rc5
    • Component/s: Querying
    • Labels:
    • Backwards Compatibility:
      Minor Change
    • Operating System:
      ALL
    • Steps To Reproduce:
      Hide

      var t = db.server3304;
       
      // this will cause an assertion in the mongod process
      t.drop();
      t.save({a: new Date(0)});
      t.find({a: new Timestamp()});

      Show
      var t = db.server3304;   // this will cause an assertion in the mongod process t.drop(); t.save({a: new Date(0)}); t.find({a: new Timestamp()});

      Description

      Queries (including range queries) on one type will no longer match values of the other type. Previously the comparison depended on which type was on the left hand side, which is incompatible with a total ordering.

      Original title: mongod assertion when attempt is made to compare a Date to a Timestamp

      The assertion will happen when the collection contains a Date and the query filter is using a Timestamp, but not the other way around.

      Here's the assertion and stack trace from a mongod running version 2.4.7.

      Fri Nov  1 09:54:12.974 [conn2] Assertion: 13111:wrong type for field (a) 17 != 9
      0x10044c66b 0x10042601e 0x1004260dd 0x100401380 0x10005ce97 0x1002227ec 0x100218a03 0x1002191da 0x1002236c2 0x1002238e0 0x10019b3f0 0x100239e0f 0x10014d796 0x100147ae5 0x100148a0c 0x1001492dc 0x10024093e 0x10024113f 0x1001ee28f 0x10000b802 
       0   mongod                              0x000000010044c66b _ZN5mongo15printStackTraceERSo + 43
       1   mongod                              0x000000010042601e _ZN5mongo11msgassertedEiPKc + 174
       2   mongod                              0x00000001004260dd _ZN5mongo11msgassertedEiRKSs + 29
       3   mongod                              0x0000000100401380 _ZNK5mongo11BSONElement3chkEi + 800
       4   mongod                              0x000000010005ce97 _ZN5mongo20compareElementValuesERKNS_11BSONElementES2_ + 679
       5   mongod                              0x00000001002227ec _ZNK5mongo7Matcher11valuesMatchERKNS_11BSONElementES3_iRKNS_14ElementMatcherE + 100
       6   mongod                              0x0000000100218a03 _ZNK5mongo7Matcher13matchesDottedEPKcRKNS_11BSONElementERKNS_7BSONObjEiRKNS_14ElementMatcherEbPNS_12MatchDetailsE + 3459
       7   mongod                              0x00000001002191da _ZNK5mongo7Matcher7matchesERKNS_7BSONObjEPNS_12MatchDetailsE + 314
       8   mongod                              0x00000001002236c2 _ZNK5mongo19CoveredIndexMatcher7matchesERKNS_7BSONObjERKNS_7DiskLocEPNS_12MatchDetailsEb + 450
       9   mongod                              0x00000001002238e0 _ZNK5mongo19CoveredIndexMatcher14matchesCurrentEPNS_6CursorEPNS_12MatchDetailsE + 212
       10  mongod                              0x000000010019b3f0 _ZN5mongo6Cursor14currentMatchesEPNS_12MatchDetailsE + 56
       11  mongod                              0x0000000100239e0f _ZN5mongo8runCountEPKcRKNS_7BSONObjERSsRi + 1455
       12  mongod                              0x000000010014d796 _ZN5mongo8CmdCount3runERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 268
       13  mongod                              0x0000000100147ae5 _ZN5mongo12_execCommandEPNS_7CommandERKSsRNS_7BSONObjEiRSsRNS_14BSONObjBuilderEb + 37
       14  mongod                              0x0000000100148a0c _ZN5mongo7Command11execCommandEPS0_RNS_6ClientEiPKcRNS_7BSONObjERNS_14BSONObjBuilderEb + 2516
       15  mongod                              0x00000001001492dc _ZN5mongo12_runCommandsEPKcRNS_7BSONObjERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 1036
       16  mongod                              0x000000010024093e _ZN5mongo11runCommandsEPKcRNS_7BSONObjERNS_5CurOpERNS_11_BufBuilderINS_16TrivialAllocatorEEERNS_14BSONObjBuilderEbi + 46
       17  mongod                              0x000000010024113f _ZN5mongo8runQueryERNS_7MessageERNS_12QueryMessageERNS_5CurOpES1_ + 1551
       18  mongod                              0x00000001001ee28f _ZN5mongo16assembleResponseERNS_7MessageERNS_10DbResponseERKNS_11HostAndPortE + 1519
       19  mongod                              0x000000010000b802 _ZN5mongo16MyMessageHandler7processERNS_7MessageEPNS_21AbstractMessagingPortEPNS_9LastErrorE + 198
      Fri Nov  1 09:54:12.991 [conn2] Count with ns: test.server3304 and query: { a: Timestamp 0|0 } failed with exception: 13111 wrong type for field (a) 17 != 9 code: 13111
      

      1. server3304.js
        0.4 kB
        Benety Goh

        Issue Links

          Activity

          Hide
          mjc@wiredtiger.com Michael Cahill added a comment -

          Is https://github.com/mongodb/mongo/pull/764 a reasonable way to address this issue?

          It is causing problems in testing the WiredTiger storage engine because the type3.js test causes comparison between a Date and a Timestamp.

          Thanks!

          Show
          mjc@wiredtiger.com Michael Cahill added a comment - Is https://github.com/mongodb/mongo/pull/764 a reasonable way to address this issue? It is causing problems in testing the WiredTiger storage engine because the type3.js test causes comparison between a Date and a Timestamp. Thanks!
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

          Message: SERVER-3304 Clean up index between inserting a Timestamp and a Date

          This should be unnecessary once SERVER-3304 is resolved.
          Branch: master
          https://github.com/mongodb/mongo/commit/017d360814e366b7c2a91b2320b45db49d158358

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'} Message: SERVER-3304 Clean up index between inserting a Timestamp and a Date This should be unnecessary once SERVER-3304 is resolved. Branch: master https://github.com/mongodb/mongo/commit/017d360814e366b7c2a91b2320b45db49d158358
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

          Message: SERVER-3304 Clean up index between inserting a Timestamp and a Date

          This should be unnecessary once SERVER-3304 is resolved.
          Branch: master
          https://github.com/mongodb/mongo/commit/017d360814e366b7c2a91b2320b45db49d158358

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'} Message: SERVER-3304 Clean up index between inserting a Timestamp and a Date This should be unnecessary once SERVER-3304 is resolved. Branch: master https://github.com/mongodb/mongo/commit/017d360814e366b7c2a91b2320b45db49d158358
          Hide
          xgen-internal-githook Githook User added a comment -

          Author:

          {u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

          Message: Make BSONObj::woCompare a total ordering

          Changes:

          • Date and Timestamp are now distinct with all Dates before all Timestamps.
          • Numeric comparisons now correctly handle Doubles and Long > 2**53.
          • CodeWScope doesn't strcmp BSONObjs or strings which may contain NULs.

          There should be no changes in any of the cases where woCompare defined a
          correct total ordering before. The new behavior matches the ordering defined
          by KeyString.

          Related tickets:

          Changes to the comparison function for aggregation will be handled separately
          as SERVER-16708.
          Branch: master
          https://github.com/mongodb/mongo/commit/f58fa5f78a91ce36d8e31d6730ebfdaa6cc1d5ab

          Show
          xgen-internal-githook Githook User added a comment - Author: {u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'} Message: Make BSONObj::woCompare a total ordering Changes: Date and Timestamp are now distinct with all Dates before all Timestamps. Numeric comparisons now correctly handle Doubles and Long > 2**53. CodeWScope doesn't strcmp BSONObjs or strings which may contain NULs. There should be no changes in any of the cases where woCompare defined a correct total ordering before. The new behavior matches the ordering defined by KeyString. Related tickets: SERVER-3304 Error comparing Date and Timestamp SERVER-3719 Total ordering over Longs and Doubles SERVER-7804 CodeWScope comparisons are broken SERVER-16632 Change WiredTiger index key format Changes to the comparison function for aggregation will be handled separately as SERVER-16708 . Branch: master https://github.com/mongodb/mongo/commit/f58fa5f78a91ce36d8e31d6730ebfdaa6cc1d5ab

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: