summaryrefslogtreecommitdiff
path: root/src/mongo/db
diff options
context:
space:
mode:
authorShreyas Kalyan <shreyas.kalyan@10gen.com>2019-02-21 10:57:45 -0500
committerShreyas Kalyan <shreyas.kalyan@10gen.com>2019-02-25 09:54:06 -0500
commit2d6817c980540cdcd921632a9f4b3dba8120d1f7 (patch)
tree239e7d969333db6407ce5c9dbe6f73cef58b2183 /src/mongo/db
parente932fa2b7af46ddc924f9dcc295b46bdef3e45e2 (diff)
downloadmongo-2d6817c980540cdcd921632a9f4b3dba8120d1f7.tar.gz
SERVER-39557 Migrate server parameters to IDL in src/mongo/db/logical_clock.cpp
Diffstat (limited to 'src/mongo/db')
-rw-r--r--src/mongo/db/SConscript1
-rw-r--r--src/mongo/db/logical_clock.cpp18
-rw-r--r--src/mongo/db/logical_clock.h3
-rw-r--r--src/mongo/db/logical_clock.idl41
-rw-r--r--src/mongo/db/logical_clock_test.cpp31
5 files changed, 60 insertions, 34 deletions
diff --git a/src/mongo/db/SConscript b/src/mongo/db/SConscript
index 699aaeb2f7e..3c5a584d5a1 100644
--- a/src/mongo/db/SConscript
+++ b/src/mongo/db/SConscript
@@ -1787,6 +1787,7 @@ env.Library(
target='logical_clock',
source=[
'logical_clock.cpp',
+ env.Idlc('logical_clock.idl')[0],
],
LIBDEPS=[
'global_settings',
diff --git a/src/mongo/db/logical_clock.cpp b/src/mongo/db/logical_clock.cpp
index 4ca14daae32..8bf4a7e155c 100644
--- a/src/mongo/db/logical_clock.cpp
+++ b/src/mongo/db/logical_clock.cpp
@@ -32,6 +32,7 @@
#include "mongo/platform/basic.h"
#include "mongo/db/logical_clock.h"
+#include "mongo/db/logical_clock_gen.h"
#include "mongo/base/status.h"
#include "mongo/db/global_settings.h"
@@ -43,21 +44,6 @@
namespace mongo {
-constexpr Seconds LogicalClock::kMaxAcceptableLogicalClockDriftSecs;
-
-MONGO_EXPORT_STARTUP_SERVER_PARAMETER(maxAcceptableLogicalClockDriftSecs,
- long long,
- LogicalClock::kMaxAcceptableLogicalClockDriftSecs.count())
- ->withValidator([](const long long& potentialNewValue) {
- if (potentialNewValue <= 0) {
- return Status(ErrorCodes::BadValue,
- str::stream() << "maxAcceptableLogicalClockDriftSecs must be positive, "
- "but attempted to set to: "
- << potentialNewValue);
- }
- return Status::OK();
- });
-
namespace {
const auto getLogicalClock = ServiceContext::declareDecoration<std::unique_ptr<LogicalClock>>();
@@ -173,7 +159,7 @@ void LogicalClock::setClusterTimeFromTrustedSource(LogicalTime newTime) {
Status LogicalClock::_passesRateLimiter_inlock(LogicalTime newTime) {
const unsigned wallClockSecs =
durationCount<Seconds>(_service->getFastClockSource()->now().toDurationSinceEpoch());
- auto maxAcceptableDriftSecs = static_cast<const unsigned>(maxAcceptableLogicalClockDriftSecs);
+ auto maxAcceptableDriftSecs = static_cast<const unsigned>(gMaxAcceptableLogicalClockDriftSecs);
auto newTimeSecs = newTime.asTimestamp().getSecs();
// Both values are unsigned, so compare them first to avoid wrap-around.
diff --git a/src/mongo/db/logical_clock.h b/src/mongo/db/logical_clock.h
index c40db592482..c6cebe983d8 100644
--- a/src/mongo/db/logical_clock.h
+++ b/src/mongo/db/logical_clock.h
@@ -49,9 +49,6 @@ public:
static const uint32_t kMaxSignedInt = ((1U << 31) - 1);
- static constexpr Seconds kMaxAcceptableLogicalClockDriftSecs =
- Seconds(365 * 24 * 60 * 60); // 1 year
-
/**
* Returns the current cluster time if this is a replica set node, otherwise returns a null
* logical time.
diff --git a/src/mongo/db/logical_clock.idl b/src/mongo/db/logical_clock.idl
new file mode 100644
index 00000000000..18eb2e2b2ca
--- /dev/null
+++ b/src/mongo/db/logical_clock.idl
@@ -0,0 +1,41 @@
+# Copyright (C) 2019-present MongoDB, Inc.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the Server Side Public License, version 1,
+# as published by MongoDB, Inc.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# Server Side Public License for more details.
+#
+# You should have received a copy of the Server Side Public License
+# along with this program. If not, see
+# <http://www.mongodb.com/licensing/server-side-public-license>.
+#
+# As a special exception, the copyright holders give permission to link the
+# code of portions of this program with the OpenSSL library under certain
+# conditions as described in each individual source file and distribute
+# linked combinations including the program with the OpenSSL library. You
+# must comply with the Server Side Public License in all respects for
+# all of the code used other than as permitted herein. If you modify file(s)
+# with this exception, you may extend this exception to your version of the
+# file(s), but you are not obligated to do so. If you do not wish to do so,
+# delete this exception statement from your version. If you delete this
+# exception statement from all source files in the program, then also delete
+# it in the license file.
+#
+
+global:
+ cpp_namespace: "mongo"
+
+server_parameters:
+ maxAcceptableLogicalClockDriftSecs:
+ description: "The value defines the maximum difference, in seconds, between the current clusterTime and a new clusterTime. Default value is 1 year."
+ set_at: [ startup ]
+ cpp_vartype: long long
+ cpp_varname: gMaxAcceptableLogicalClockDriftSecs
+ default:
+ expr: (365 * 24 * 60 * 60) # one year
+ validator:
+ gt: 0 \ No newline at end of file
diff --git a/src/mongo/db/logical_clock_test.cpp b/src/mongo/db/logical_clock_test.cpp
index 3b16ba9794f..ac3ddadd45d 100644
--- a/src/mongo/db/logical_clock_test.cpp
+++ b/src/mongo/db/logical_clock_test.cpp
@@ -35,6 +35,7 @@
#include "mongo/bson/timestamp.h"
#include "mongo/db/dbdirectclient.h"
#include "mongo/db/logical_clock.h"
+#include "mongo/db/logical_clock_gen.h"
#include "mongo/db/logical_clock_test_fixture.h"
#include "mongo/db/logical_time.h"
#include "mongo/db/repl/replication_coordinator_mock.h"
@@ -110,7 +111,7 @@ TEST_F(LogicalClockTest, RateLimiterRejectsLogicalTimesTooFarAhead) {
Timestamp tooFarAheadTimestamp(
durationCount<Seconds>(getMockClockSourceTime().toDurationSinceEpoch()) +
- durationCount<Seconds>(LogicalClock::kMaxAcceptableLogicalClockDriftSecs) +
+ kMaxAcceptableLogicalClockDriftSecsDefault +
10, // Add 10 seconds to ensure limit is exceeded.
1);
LogicalTime t1(tooFarAheadTimestamp);
@@ -120,12 +121,12 @@ TEST_F(LogicalClockTest, RateLimiterRejectsLogicalTimesTooFarAhead) {
// Verify cluster time can be initialized to a very old time.
TEST_F(LogicalClockTest, InitFromTrustedSourceCanAcceptVeryOldLogicalTime) {
- setMockClockSourceTime(Date_t::fromMillisSinceEpoch(
- durationCount<Seconds>(LogicalClock::kMaxAcceptableLogicalClockDriftSecs) * 10 * 1000));
+ setMockClockSourceTime(
+ Date_t::fromMillisSinceEpoch(kMaxAcceptableLogicalClockDriftSecsDefault * 10 * 1000));
Timestamp veryOldTimestamp(
durationCount<Seconds>(getMockClockSourceTime().toDurationSinceEpoch()) -
- (durationCount<Seconds>(LogicalClock::kMaxAcceptableLogicalClockDriftSecs) * 5));
+ (kMaxAcceptableLogicalClockDriftSecsDefault * 5));
auto veryOldTime = LogicalTime(veryOldTimestamp);
getClock()->setClusterTimeFromTrustedSource(veryOldTime);
@@ -156,19 +157,19 @@ TEST_F(LogicalClockTest, WallClockSetTooFarInPast) {
auto oneDay = Seconds(24 * 60 * 60);
// Current wall clock and cluster time.
- auto currentSecs = LogicalClock::kMaxAcceptableLogicalClockDriftSecs * 10;
+ auto currentSecs = Seconds(kMaxAcceptableLogicalClockDriftSecsDefault) * 10;
LogicalTime currentTime(Timestamp(currentSecs, 0));
// Set wall clock more than maxAcceptableLogicalClockDriftSecs seconds in the past.
- auto pastSecs = currentSecs - LogicalClock::kMaxAcceptableLogicalClockDriftSecs - oneDay;
+ auto pastSecs = currentSecs - Seconds(kMaxAcceptableLogicalClockDriftSecsDefault) - oneDay;
setMockClockSourceTime(Date_t::fromDurationSinceEpoch(pastSecs));
// If cluster time is either uninitialized or even farther in the past, a write would set
// cluster time more than maxAcceptableLogicalClockDriftSecs in the past.
getDBClient()->insert(kDummyNamespaceString.ns(), BSON("x" << 1));
- ASSERT_TRUE(
- getClock()->getClusterTime() <
- LogicalTime(Timestamp(currentSecs - LogicalClock::kMaxAcceptableLogicalClockDriftSecs, 0)));
+ ASSERT_TRUE(getClock()->getClusterTime() <
+ LogicalTime(Timestamp(
+ currentSecs - Seconds(kMaxAcceptableLogicalClockDriftSecsDefault), 0)));
// Set wall clock to the current time on the affected node.
setMockClockSourceTime(Date_t::fromDurationSinceEpoch(currentSecs));
@@ -187,19 +188,19 @@ TEST_F(LogicalClockTest, WallClockSetTooFarInFuture) {
auto oneDay = Seconds(24 * 60 * 60);
// Current wall clock and cluster time.
- auto currentSecs = LogicalClock::kMaxAcceptableLogicalClockDriftSecs * 10;
+ auto currentSecs = Seconds(kMaxAcceptableLogicalClockDriftSecsDefault) * 10;
LogicalTime currentTime(Timestamp(currentSecs, 0));
// Set wall clock more than maxAcceptableLogicalClockDriftSecs seconds in the future.
- auto futureSecs = currentSecs + LogicalClock::kMaxAcceptableLogicalClockDriftSecs + oneDay;
+ auto futureSecs = currentSecs + Seconds(kMaxAcceptableLogicalClockDriftSecsDefault) + oneDay;
setMockClockSourceTime(Date_t::fromDurationSinceEpoch(futureSecs));
// A write gets through and advances cluster time more than maxAcceptableLogicalClockDriftSecs
// in the future.
getDBClient()->insert(kDummyNamespaceString.ns(), BSON("x" << 1));
- ASSERT_TRUE(
- getClock()->getClusterTime() >
- LogicalTime(Timestamp(currentSecs + LogicalClock::kMaxAcceptableLogicalClockDriftSecs, 0)));
+ ASSERT_TRUE(getClock()->getClusterTime() >
+ LogicalTime(Timestamp(
+ currentSecs + Seconds(kMaxAcceptableLogicalClockDriftSecsDefault), 0)));
// Set wall clock to the current time on the affected node.
setMockClockSourceTime(Date_t::fromDurationSinceEpoch(currentSecs));
@@ -325,7 +326,7 @@ TEST_F(LogicalClockTest, RejectsLogicalTimesGreaterThanMaxTime) {
// The time can't be advanced through metadata to a time greater than the max possible.
// Advance the wall clock close enough to the new value so the rate check is passed.
auto almostMaxSecs =
- Seconds(maxVal) - LogicalClock::kMaxAcceptableLogicalClockDriftSecs + Seconds(10);
+ Seconds(maxVal) - Seconds(kMaxAcceptableLogicalClockDriftSecsDefault) + Seconds(10);
setMockClockSourceTime(Date_t::fromDurationSinceEpoch(almostMaxSecs));
ASSERT_THROWS(getClock()->advanceClusterTime(beyondMaxTime), std::exception);
ASSERT_TRUE(getClock()->getClusterTime() == LogicalTime());