summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2015-08-20 18:42:03 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2015-08-27 16:01:16 -0400
commit524976c358b7a5d791973dceb91cffb64b14f22e (patch)
treecb3606c1bd7dea6278b554dad1ba9a6d43c75c88
parenta22d9007497151eaf4dfc510dbdfeebc5d735f4c (diff)
downloadmongo-524976c358b7a5d791973dceb91cffb64b14f22e.tar.gz
SERVER-19765 Rename term constants.
-rw-r--r--src/mongo/db/commands/get_last_error.cpp2
-rw-r--r--src/mongo/db/repl/data_replicator.cpp2
-rw-r--r--src/mongo/db/repl/data_replicator_test.cpp6
-rw-r--r--src/mongo/db/repl/oplog.cpp2
-rw-r--r--src/mongo/db/repl/optime.cpp4
-rw-r--r--src/mongo/db/repl/optime.h14
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.cpp2
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.h2
-rw-r--r--src/mongo/db/repl/replication_coordinator_mock.cpp2
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl.cpp2
-rw-r--r--src/mongo/db/repl/topology_coordinator_impl.h2
-rw-r--r--src/mongo/rpc/metadata/repl_set_metadata.h6
12 files changed, 22 insertions, 24 deletions
diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp
index 79ab4e7bf67..02abf3731cd 100644
--- a/src/mongo/db/commands/get_last_error.cpp
+++ b/src/mongo/db/commands/get_last_error.cpp
@@ -168,7 +168,7 @@ public:
// TODO(siyuan) Fix mongos to supply wOpTimeTerm, then parse out that value here
} else {
// TODO(siyuan) Don't use the default term after fixing mongos.
- lastOpTime = repl::OpTime(lastTimestamp, repl::OpTime::kDefaultTerm);
+ lastOpTime = repl::OpTime(lastTimestamp, repl::OpTime::kInitialTerm);
}
OID electionId;
diff --git a/src/mongo/db/repl/data_replicator.cpp b/src/mongo/db/repl/data_replicator.cpp
index 7caa57a29f0..13a39524b03 100644
--- a/src/mongo/db/repl/data_replicator.cpp
+++ b/src/mongo/db/repl/data_replicator.cpp
@@ -1353,7 +1353,7 @@ void DataReplicator::_rollbackOperations(const CallbackArgs& cbData) {
}
invariant(cbData.txn);
- OpTime lastOpTimeWritten(getLastTimestampApplied(), OpTime::kDefaultTerm);
+ OpTime lastOpTimeWritten(getLastTimestampApplied(), OpTime::kInitialTerm);
HostAndPort syncSource = getSyncSource();
auto rollbackStatus = _opts.rollbackFn(cbData.txn, lastOpTimeWritten, syncSource);
if (!rollbackStatus.isOK()) {
diff --git a/src/mongo/db/repl/data_replicator_test.cpp b/src/mongo/db/repl/data_replicator_test.cpp
index d6c5dadfacc..887a7a924bf 100644
--- a/src/mongo/db/repl/data_replicator_test.cpp
+++ b/src/mongo/db/repl/data_replicator_test.cpp
@@ -506,7 +506,7 @@ TEST_F(InitialSyncTest, Failpoint) {
<< "node3:12345")));
Timestamp time1(100, 1);
- OpTime opTime1(time1, OpTime::kDefaultTerm);
+ OpTime opTime1(time1, OpTime::kInitialTerm);
_myLastOpTime = opTime1;
_memberState = MemberState::RS_SECONDARY;
@@ -855,7 +855,7 @@ TEST_F(SteadyStateTest, PauseDataReplicator) {
};
auto& dr = getDR();
- _myLastOpTime = OpTime(operationToApply["ts"].timestamp(), OpTime::kDefaultTerm);
+ _myLastOpTime = OpTime(operationToApply["ts"].timestamp(), OpTime::kInitialTerm);
_memberState = MemberState::RS_SECONDARY;
auto net = getNet();
@@ -935,7 +935,7 @@ TEST_F(SteadyStateTest, ApplyOneOperation) {
barrier.countDownAndWait();
};
- _myLastOpTime = OpTime(operationToApply["ts"].timestamp(), OpTime::kDefaultTerm);
+ _myLastOpTime = OpTime(operationToApply["ts"].timestamp(), OpTime::kInitialTerm);
_memberState = MemberState::RS_SECONDARY;
auto net = getNet();
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 86103ae8804..ebc7e87d5e9 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -147,7 +147,7 @@ std::pair<OpTime, long long> getNextOpTime(OperationContext* txn,
synchronizeOnCappedInFlightResource(txn->lockState(), oplog->ns());
long long hashNew = 0;
- long long term = OpTime::kProtocolVersionV0Term;
+ long long term = OpTime::kUninitializedTerm;
// Fetch term out of the newOpMutex.
if (replicationMode == ReplicationCoordinator::modeReplSet &&
diff --git a/src/mongo/db/repl/optime.cpp b/src/mongo/db/repl/optime.cpp
index 31d83d91e4f..172302b42c1 100644
--- a/src/mongo/db/repl/optime.cpp
+++ b/src/mongo/db/repl/optime.cpp
@@ -66,7 +66,7 @@ void OpTime::append(BSONObjBuilder* builder) const {
builder->append(kTimestampFieldName, _timestamp);
// Don't add term in protocol version 0.
- if (_term != kProtocolVersionV0Term) {
+ if (_term != kUninitializedTerm) {
builder->append(kTermFieldName, _term);
}
}
@@ -79,7 +79,7 @@ StatusWith<OpTime> OpTime::parseFromBSON(const BSONObj& obj) {
// Default to -1 if the term is absent.
long long term;
- status = bsonExtractIntegerFieldWithDefault(obj, kTermFieldName, kProtocolVersionV0Term, &term);
+ status = bsonExtractIntegerFieldWithDefault(obj, kTermFieldName, kUninitializedTerm, &term);
if (!status.isOK())
return status;
diff --git a/src/mongo/db/repl/optime.h b/src/mongo/db/repl/optime.h
index f41b4386c65..c530ca51f97 100644
--- a/src/mongo/db/repl/optime.h
+++ b/src/mongo/db/repl/optime.h
@@ -50,13 +50,13 @@ namespace repl {
class OpTime {
public:
// The term of an OpTime generated by old protocol version.
- static const long long kProtocolVersionV0Term = -1;
+ static const long long kUninitializedTerm = -1;
- // The default term after the first time upgrading from protocol version 0.
+ // The initial term after the first time upgrading from protocol version 0.
//
- // This is also the first term for nodes that were recently started up but have not
+ // This is also the initial term for nodes that were recently started up but have not
// yet joined the cluster, all in protocol version 1.
- static const long long kDefaultTerm = 0;
+ static const long long kInitialTerm = 0;
// Default OpTime, also the smallest one.
OpTime() = default;
@@ -84,7 +84,7 @@ public:
inline bool operator==(const OpTime& rhs) const {
// Only compare timestamp if either of the two OpTimes is generated by old protocol,
// so that (Timestamp(), 0) == (Timestamp(), -1)
- if (_term == kProtocolVersionV0Term || rhs._term == kProtocolVersionV0Term) {
+ if (_term == kUninitializedTerm || rhs._term == kUninitializedTerm) {
return _timestamp == rhs._timestamp;
}
// Compare term first, then the timestamps.
@@ -98,7 +98,7 @@ public:
// the same protocol version to avoid problematic scenarios.
inline bool operator<(const OpTime& rhs) const {
// Only compare timestamp if either of the two OpTimes is generated by old protocol.
- if (_term == kProtocolVersionV0Term || rhs._term == kProtocolVersionV0Term) {
+ if (_term == kUninitializedTerm || rhs._term == kUninitializedTerm) {
return _timestamp < rhs._timestamp;
}
// Compare term first, then the timestamps.
@@ -125,7 +125,7 @@ public:
private:
Timestamp _timestamp;
- long long _term = kDefaultTerm;
+ long long _term = kInitialTerm;
};
} // namespace repl
diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp
index 5227bba929d..8a24088caad 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.cpp
+++ b/src/mongo/db/repl/replication_coordinator_impl.cpp
@@ -728,7 +728,7 @@ Status ReplicationCoordinatorImpl::setLastOptimeForSlave(const OID& rid, const T
getReplicationMode() == modeMasterSlave);
// term == -1 for master-slave
- OpTime opTime(ts, OpTime::kProtocolVersionV0Term);
+ OpTime opTime(ts, OpTime::kUninitializedTerm);
SlaveInfo* slaveInfo = _findSlaveInfoByRID_inlock(rid);
if (slaveInfo) {
if (slaveInfo->opTime < opTime) {
diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h
index c1541a62ff5..6803f9c0004 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.h
+++ b/src/mongo/db/repl/replication_coordinator_impl.h
@@ -1199,7 +1199,7 @@ private:
boost::optional<SnapshotInfo> _currentCommittedSnapshot; // (M)
// The cached current term. It's in sync with the term in topology coordinator.
- long long _cachedTerm = OpTime::kProtocolVersionV0Term; // (M)
+ long long _cachedTerm = OpTime::kUninitializedTerm; // (M)
// Callback Handle used to cancel a scheduled LivenessTimeout callback.
ReplicationExecutor::CallbackHandle _handleLivenessTimeoutCbh; // (M)
diff --git a/src/mongo/db/repl/replication_coordinator_mock.cpp b/src/mongo/db/repl/replication_coordinator_mock.cpp
index 9ee8f1f1885..4148c8833e7 100644
--- a/src/mongo/db/repl/replication_coordinator_mock.cpp
+++ b/src/mongo/db/repl/replication_coordinator_mock.cpp
@@ -353,7 +353,7 @@ bool ReplicationCoordinatorMock::isV1ElectionProtocol() {
void ReplicationCoordinatorMock::summarizeAsHtml(ReplSetHtmlSummary* output) {}
long long ReplicationCoordinatorMock::getTerm() {
- return OpTime::kDefaultTerm;
+ return OpTime::kInitialTerm;
}
Status ReplicationCoordinatorMock::updateTerm(long long term) {
diff --git a/src/mongo/db/repl/topology_coordinator_impl.cpp b/src/mongo/db/repl/topology_coordinator_impl.cpp
index 1c769f3f9ce..a0992569df9 100644
--- a/src/mongo/db/repl/topology_coordinator_impl.cpp
+++ b/src/mongo/db/repl/topology_coordinator_impl.cpp
@@ -113,7 +113,7 @@ void PingStats::miss() {
TopologyCoordinatorImpl::TopologyCoordinatorImpl(Options options)
: _role(Role::follower),
- _term(0),
+ _term(OpTime::kInitialTerm),
_currentPrimaryIndex(-1),
_forceSyncSourceIndex(-1),
_options(std::move(options)),
diff --git a/src/mongo/db/repl/topology_coordinator_impl.h b/src/mongo/db/repl/topology_coordinator_impl.h
index cefe3cb891c..5fc31496f9a 100644
--- a/src/mongo/db/repl/topology_coordinator_impl.h
+++ b/src/mongo/db/repl/topology_coordinator_impl.h
@@ -379,7 +379,7 @@ private:
// This node's election term. The term is used as part of the consensus algorithm to elect
// and maintain one primary (leader) node in the cluster.
- long long _term = 0;
+ long long _term;
// the index of the member we currently believe is primary, if one exists, otherwise -1
int _currentPrimaryIndex;
diff --git a/src/mongo/rpc/metadata/repl_set_metadata.h b/src/mongo/rpc/metadata/repl_set_metadata.h
index c96cd14487a..97d7b4b8da3 100644
--- a/src/mongo/rpc/metadata/repl_set_metadata.h
+++ b/src/mongo/rpc/metadata/repl_set_metadata.h
@@ -100,10 +100,8 @@ public:
}
private:
- repl::OpTime _lastOpCommitted =
- repl::OpTime(Timestamp(0, 0), repl::OpTime::kProtocolVersionV0Term);
- repl::OpTime _lastOpVisible =
- repl::OpTime(Timestamp(0, 0), repl::OpTime::kProtocolVersionV0Term);
+ repl::OpTime _lastOpCommitted = repl::OpTime(Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
+ repl::OpTime _lastOpVisible = repl::OpTime(Timestamp(0, 0), repl::OpTime::kUninitializedTerm);
long long _currentTerm = -1;
long long _configVersion = -1;
int _currentPrimaryIndex = -1;