summaryrefslogtreecommitdiff
path: root/src/mongo/bson
diff options
context:
space:
mode:
authorJustin Seyster <justin.seyster@mongodb.com>2018-06-28 12:19:52 -0400
committerJustin Seyster <justin.seyster@mongodb.com>2018-06-28 17:13:49 -0400
commit3702862f8a5c26080bc995448207e5d8fd33b0ad (patch)
treebb191ceeead47ded50dc8e785b451163d394ed1c /src/mongo/bson
parentc41426385e88d1b8cd08b5fa39f445e184f86dc1 (diff)
downloadmongo-3702862f8a5c26080bc995448207e5d8fd33b0ad.tar.gz
Revert "SERVER-34975 Treat an OID-embedded timestamp as unsigned."
This reverts commit a9deb701a7533b566a2eb703aff70bf2f03b147c.
Diffstat (limited to 'src/mongo/bson')
-rw-r--r--src/mongo/bson/oid.cpp4
-rw-r--r--src/mongo/bson/oid.h7
-rw-r--r--src/mongo/bson/oid_test.cpp6
3 files changed, 11 insertions, 6 deletions
diff --git a/src/mongo/bson/oid.cpp b/src/mongo/bson/oid.cpp
index ca9c6e558a9..26d90d97bad 100644
--- a/src/mongo/bson/oid.cpp
+++ b/src/mongo/bson/oid.cpp
@@ -162,6 +162,10 @@ void OID::init(Date_t date, bool max) {
std::memcpy(_view().view(kInstanceUniqueOffset), &rest, kInstanceUniqueSize + kIncrementSize);
}
+time_t OID::asTimeT() const {
+ return getTimestamp();
+}
+
std::string OID::toString() const {
return toHexLower(_data, kOIDSize);
}
diff --git a/src/mongo/bson/oid.h b/src/mongo/bson/oid.h
index 7f4f31a4369..4474a12dbe2 100644
--- a/src/mongo/bson/oid.h
+++ b/src/mongo/bson/oid.h
@@ -176,8 +176,9 @@ public:
*/
void initFromTermNumber(int64_t term);
+ time_t asTimeT() const;
Date_t asDateT() const {
- return Date_t::fromMillisSinceEpoch(getTimestamp() * 1000LL);
+ return Date_t::fromMillisSinceEpoch(asTimeT() * 1000LL);
}
// True iff the OID is not empty
@@ -197,8 +198,8 @@ public:
static unsigned getMachineId(); // used by the 'features' command
static void regenMachineId();
- // Timestamp is a 4-byte positive integer so we use uint32_t
- typedef uint32_t Timestamp;
+ // Timestamp is 4 bytes so we just use int32_t
+ typedef int32_t Timestamp;
// Wrappers so we can return stuff by value.
struct InstanceUnique {
diff --git a/src/mongo/bson/oid_test.cpp b/src/mongo/bson/oid_test.cpp
index 6d34d6a5808..8be156ae41d 100644
--- a/src/mongo/bson/oid_test.cpp
+++ b/src/mongo/bson/oid_test.cpp
@@ -109,7 +109,7 @@ TEST(Basic, Deserialize) {
0xDEu,
0xADu,
0xBEu,
- 0xEFu, // timestamp is 3735928559 (unsigned)
+ 0xEFu, // timestamp is -559038737 (signed)
0x00u,
0x00u,
0x00u,
@@ -122,7 +122,7 @@ TEST(Basic, Deserialize) {
OID o1 = OID::from(OIDbytes);
- ASSERT_EQUALS(o1.getTimestamp(), 3735928559);
+ ASSERT_EQUALS(o1.getTimestamp(), -559038737);
OID::InstanceUnique u = o1.getInstanceUnique();
for (std::size_t i = 0; i < OID::kInstanceUniqueSize; ++i) {
ASSERT_EQUALS(u.bytes[i], 0x00u);
@@ -158,7 +158,7 @@ TEST(Basic, FromTerm) {
auto oidHead = oidStr.substr(0, 8);
auto oidTail = oidStr.substr(oidStr.length() - 1);
- ASSERT_EQUALS("ffffffff", oidHead);
+ ASSERT_EQUALS("7fffffff", oidHead);
ASSERT_EQUALS(term, std::stoi(oidTail));
}
}