diff options
author | Geert Bosch <geert@mongodb.com> | 2015-10-26 18:32:35 -0400 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2015-10-30 14:44:31 -0400 |
commit | 9ac7b65d0e33ac778a0c9febf96f04ee54570fbc (patch) | |
tree | 02c8556cf99fe3d0d527a5106c086879ae626977 /src/mongo | |
parent | 01b3082f3deb7bb6fed0b1e5e2fdc22cbcbb8f5a (diff) | |
download | mongo-9ac7b65d0e33ac778a0c9febf96f04ee54570fbc.tar.gz |
SERVER-21160: revert woCompare to using unsigned comparison for Timestamp
Diffstat (limited to 'src/mongo')
-rw-r--r-- | src/mongo/bson/bson_obj_test.cpp | 6 | ||||
-rw-r--r-- | src/mongo/bson/bsonelement.cpp | 4 | ||||
-rw-r--r-- | src/mongo/bson/timestamp.h | 4 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_value_test.cpp | 7 | ||||
-rw-r--r-- | src/mongo/db/storage/key_string_test.cpp | 4 |
5 files changed, 20 insertions, 5 deletions
diff --git a/src/mongo/bson/bson_obj_test.cpp b/src/mongo/bson/bson_obj_test.cpp index 07735eb6025..278b344a784 100644 --- a/src/mongo/bson/bson_obj_test.cpp +++ b/src/mongo/bson/bson_obj_test.cpp @@ -41,6 +41,12 @@ TEST(BSONObjToString, EmptyArray) { ASSERT_EQUALS(text, o1_str); } +TEST(BSONObjCompare, Timestamp) { + ASSERT_LT(BSON("" << Timestamp(0, 3)), BSON("" << Timestamp(~0U, 2))); + ASSERT_GT(BSON("" << Timestamp(2, 3)), BSON("" << Timestamp(2, 2))); + ASSERT_EQ(BSON("" << Timestamp(3ULL)), BSON("" << Timestamp(0, 3))); +} + TEST(BSONObjCompare, NumberDouble) { ASSERT_LT(BSON("" << 0.0), BSON("" << 1.0)); ASSERT_LT(BSON("" << -1.0), BSON("" << 0.0)); diff --git a/src/mongo/bson/bsonelement.cpp b/src/mongo/bson/bsonelement.cpp index f728998d62c..5eb40a6bd73 100644 --- a/src/mongo/bson/bsonelement.cpp +++ b/src/mongo/bson/bsonelement.cpp @@ -867,9 +867,9 @@ int compareElementValues(const BSONElement& l, const BSONElement& r) { case bsonTimestamp: // unsigned compare for timestamps - note they are not really dates but (ordinal + // time_t) - if (l.date() < r.date()) + if (l.timestamp() < r.timestamp()) return -1; - return l.date() == r.date() ? 0 : 1; + return l.timestamp() == r.timestamp() ? 0 : 1; case Date: // Signed comparisons for Dates. { diff --git a/src/mongo/bson/timestamp.h b/src/mongo/bson/timestamp.h index 47e2bf936e7..1dc04973efb 100644 --- a/src/mongo/bson/timestamp.h +++ b/src/mongo/bson/timestamp.h @@ -58,9 +58,7 @@ public: Timestamp(Seconds s, unsigned increment) : Timestamp(s.count(), increment) {} - Timestamp(unsigned a, unsigned b) : i(b), secs(a) { - dassert(secs <= static_cast<unsigned>(std::numeric_limits<int>::max())); - } + Timestamp(unsigned a, unsigned b) : i(b), secs(a) {} Timestamp() = default; diff --git a/src/mongo/db/pipeline/document_value_test.cpp b/src/mongo/db/pipeline/document_value_test.cpp index cf7e9b00cc2..d77c7ac0039 100644 --- a/src/mongo/db/pipeline/document_value_test.cpp +++ b/src/mongo/db/pipeline/document_value_test.cpp @@ -651,6 +651,11 @@ public: ASSERT(Timestamp(777) == value.getTimestamp()); ASSERT_EQUALS(mongo::bsonTimestamp, value.getType()); assertRoundTrips(value); + + value = Value(Timestamp(~0U, 3)); + ASSERT(Timestamp(~0U, 3) == value.getTimestamp()); + ASSERT_EQUALS(mongo::bsonTimestamp, value.getType()); + assertRoundTrips(value); } }; @@ -1525,6 +1530,8 @@ public: // Timestamp. assertComparison(0, Timestamp(1234), Timestamp(1234)); assertComparison(-1, Timestamp(4), Timestamp(1234)); + // High bit set. + assertComparison(1, Timestamp(~0U, 2), Timestamp(0, 3)); // Cross-type comparisons. Listed in order of canonical types. assertComparison(-1, Value(mongo::MINKEY), Value()); diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp index 7cccd712c67..9dfa3104040 100644 --- a/src/mongo/db/storage/key_string_test.cpp +++ b/src/mongo/db/storage/key_string_test.cpp @@ -152,6 +152,7 @@ TEST(KeyStringTest, AllTypesSimple) { << "a")))); ROUNDTRIP(BSON("" << 5)); ROUNDTRIP(BSON("" << Timestamp(123123, 123))); + ROUNDTRIP(BSON("" << Timestamp(~0U, 3))); ROUNDTRIP(BSON("" << 1235123123123LL)); } @@ -312,6 +313,7 @@ TEST(KeyStringTest, Timestamp) { BSONObj b = BSON("" << Timestamp(1234, 1)); BSONObj c = BSON("" << Timestamp(1234, 2)); BSONObj d = BSON("" << Timestamp(1235, 1)); + BSONObj e = BSON("" << Timestamp(~0U, 0)); { ROUNDTRIP(a); @@ -326,10 +328,12 @@ TEST(KeyStringTest, Timestamp) { KeyString kb(b, ALL_ASCENDING); KeyString kc(c, ALL_ASCENDING); KeyString kd(d, ALL_ASCENDING); + KeyString ke(e, ALL_ASCENDING); ASSERT(ka.compare(kb) < 0); ASSERT(kb.compare(kc) < 0); ASSERT(kc.compare(kd) < 0); + ASSERT(kd.compare(ke) < 0); } { |