summaryrefslogtreecommitdiff
path: root/src/mongo/db/logical_clock_test.cpp
diff options
context:
space:
mode:
authorADAM David Alan Martin <adam.martin@10gen.com>2017-05-03 13:14:53 -0400
committerADAM David Alan Martin <adam.martin@10gen.com>2017-05-03 13:14:53 -0400
commitb7c013aa097b2d999ad3f942cdfce130558ef40f (patch)
tree04e39ddadd003bff628faeea9b7bf0fb812465e9 /src/mongo/db/logical_clock_test.cpp
parent606b3930d1ca73f0184f4b29bb52917cc15e94cf (diff)
downloadmongo-b7c013aa097b2d999ad3f942cdfce130558ef40f.tar.gz
Revert "SERVER-28562 Move LogicalTime HMAC computation outside collection lock"
This reverts commit 1a6c4ecddfa4bb7a7275dc4b1bf5b79222aa4b72.
Diffstat (limited to 'src/mongo/db/logical_clock_test.cpp')
-rw-r--r--src/mongo/db/logical_clock_test.cpp76
1 files changed, 60 insertions, 16 deletions
diff --git a/src/mongo/db/logical_clock_test.cpp b/src/mongo/db/logical_clock_test.cpp
index dd259b7d7e2..7a9b2fc4a9b 100644
--- a/src/mongo/db/logical_clock_test.cpp
+++ b/src/mongo/db/logical_clock_test.cpp
@@ -37,6 +37,8 @@
#include "mongo/db/logical_clock_test_fixture.h"
#include "mongo/db/logical_time.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
+#include "mongo/db/signed_logical_time.h"
+#include "mongo/db/time_proof_service.h"
#include "mongo/stdx/memory.h"
#include "mongo/unittest/unittest.h"
#include "mongo/util/clock_source_mock.h"
@@ -54,10 +56,10 @@ TEST_F(LogicalClockTest, roundtrip) {
Timestamp tX(1);
auto time = LogicalTime(tX);
- getClock()->setClusterTimeFromTrustedSource(time);
+ getClock()->initClusterTimeFromTrustedSource(time);
auto storedTime(getClock()->getClusterTime());
- ASSERT_TRUE(storedTime == time);
+ ASSERT_TRUE(storedTime.getTime() == time);
}
// Verify the reserve ticks functionality.
@@ -67,10 +69,10 @@ TEST_F(LogicalClockTest, reserveTicks) {
auto t1 = getClock()->reserveTicks(1);
auto t2(getClock()->getClusterTime());
- ASSERT_TRUE(t1 == t2);
+ ASSERT_TRUE(t1 == t2.getTime());
// Make sure we synchronized with the wall clock.
- ASSERT_TRUE(t2.asTimestamp().getSecs() == 10);
+ ASSERT_TRUE(t2.getTime().asTimestamp().getSecs() == 10);
auto t3 = getClock()->reserveTicks(1);
t1.addTicks(1);
@@ -85,9 +87,9 @@ TEST_F(LogicalClockTest, reserveTicks) {
ASSERT_TRUE(t3 == t1);
// Ensure overflow to a new second.
- auto initTimeSecs = getClock()->getClusterTime().asTimestamp().getSecs();
+ auto initTimeSecs = getClock()->getClusterTime().getTime().asTimestamp().getSecs();
getClock()->reserveTicks((1U << 31) - 1);
- auto newTimeSecs = getClock()->getClusterTime().asTimestamp().getSecs();
+ auto newTimeSecs = getClock()->getClusterTime().getTime().asTimestamp().getSecs();
ASSERT_TRUE(newTimeSecs == initTimeSecs + 1);
}
@@ -95,8 +97,10 @@ TEST_F(LogicalClockTest, reserveTicks) {
TEST_F(LogicalClockTest, advanceClusterTime) {
auto t1 = getClock()->reserveTicks(1);
t1.addTicks(100);
- ASSERT_OK(getClock()->advanceClusterTime(t1));
- ASSERT_TRUE(t1 == getClock()->getClusterTime());
+ SignedLogicalTime l1 = makeSignedLogicalTime(t1);
+ ASSERT_OK(getClock()->advanceClusterTimeFromTrustedSource(l1));
+ auto l2(getClock()->getClusterTime());
+ ASSERT_TRUE(l1.getTime() == l2.getTime());
}
// Verify rate limiter rejects logical times whose seconds values are too far ahead.
@@ -108,9 +112,11 @@ TEST_F(LogicalClockTest, RateLimiterRejectsLogicalTimesTooFarAhead) {
durationCount<Seconds>(LogicalClock::kMaxAcceptableLogicalClockDrift) +
10, // Add 10 seconds to ensure limit is exceeded.
1);
- LogicalTime t1(tooFarAheadTimestamp);
+ SignedLogicalTime l1 = makeSignedLogicalTime(LogicalTime(tooFarAheadTimestamp));
- ASSERT_EQ(ErrorCodes::ClusterTimeFailsRateLimiter, getClock()->advanceClusterTime(t1));
+ ASSERT_EQ(ErrorCodes::ClusterTimeFailsRateLimiter, getClock()->advanceClusterTime(l1));
+ ASSERT_EQ(ErrorCodes::ClusterTimeFailsRateLimiter,
+ getClock()->advanceClusterTimeFromTrustedSource(l1));
}
// Verify cluster time can be initialized to a very old time.
@@ -122,9 +128,47 @@ TEST_F(LogicalClockTest, InitFromTrustedSourceCanAcceptVeryOldLogicalTime) {
durationCount<Seconds>(getMockClockSourceTime().toDurationSinceEpoch()) -
(durationCount<Seconds>(LogicalClock::kMaxAcceptableLogicalClockDrift) * 5));
auto veryOldTime = LogicalTime(veryOldTimestamp);
- getClock()->setClusterTimeFromTrustedSource(veryOldTime);
+ getClock()->initClusterTimeFromTrustedSource(veryOldTime);
- ASSERT_TRUE(getClock()->getClusterTime() == veryOldTime);
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() == veryOldTime);
+}
+
+// A clock with no TimeProofService should reject new times in advanceClusterTime.
+TEST_F(LogicalClockTest, AdvanceClusterTimeFailsWithoutTimeProofService) {
+ LogicalTime initialTime(Timestamp(10));
+ getClock()->initClusterTimeFromTrustedSource(initialTime);
+
+ unsetTimeProofService();
+
+ SignedLogicalTime l1 = makeSignedLogicalTime(LogicalTime(Timestamp(100)));
+ ASSERT_EQ(ErrorCodes::CannotVerifyAndSignLogicalTime, getClock()->advanceClusterTime(l1));
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() == initialTime);
+
+ resetTimeProofService();
+
+ SignedLogicalTime l2 = makeSignedLogicalTime(LogicalTime(Timestamp(200)));
+ ASSERT_OK(getClock()->advanceClusterTime(l2));
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() == l2.getTime());
+}
+
+// A clock with no TimeProofService can still advance its time through certain methods.
+TEST_F(LogicalClockTest, CertainMethodsCanAdvanceClockWithoutTimeProofService) {
+ unsetTimeProofService();
+
+ LogicalTime t1(Timestamp(100));
+ getClock()->initClusterTimeFromTrustedSource(t1);
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() == t1);
+
+ auto t2 = getClock()->reserveTicks(1);
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() == t2);
+
+ LogicalTime t3(Timestamp(300));
+ ASSERT_OK(getClock()->signAndAdvanceClusterTime(t3));
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() == t3);
+
+ SignedLogicalTime l4 = makeSignedLogicalTime(LogicalTime(Timestamp(400)));
+ ASSERT_OK(getClock()->advanceClusterTimeFromTrustedSource(l4));
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() == l4.getTime());
}
// Verify writes to the oplog advance cluster time.
@@ -132,12 +176,12 @@ TEST_F(LogicalClockTest, WritesToOplogAdvanceClusterTime) {
Timestamp tX(1);
auto initialTime = LogicalTime(tX);
- getClock()->setClusterTimeFromTrustedSource(initialTime);
- ASSERT_TRUE(getClock()->getClusterTime() == initialTime);
+ getClock()->initClusterTimeFromTrustedSource(initialTime);
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() == initialTime);
getDBClient()->insert(kDummyNamespaceString, BSON("x" << 1));
- ASSERT_TRUE(getClock()->getClusterTime() > initialTime);
- ASSERT_EQ(getClock()->getClusterTime().asTimestamp(),
+ ASSERT_TRUE(getClock()->getClusterTime().getTime() > initialTime);
+ ASSERT_EQ(getClock()->getClusterTime().getTime().asTimestamp(),
replicationCoordinator()->getMyLastAppliedOpTime().getTimestamp());
}