diff options
author | Eric Milkie <milkie@10gen.com> | 2015-04-06 09:10:57 -0400 |
---|---|---|
committer | Eric Milkie <milkie@10gen.com> | 2015-04-07 16:25:34 -0400 |
commit | 0f58d1037bcbfbf932e73e623772c4f815c361ad (patch) | |
tree | ae7ea2cf29830f0dc39e326142ddc1b6bc468804 /src/mongo/db | |
parent | 72543912dca4117e1deb45a56c599657a1bf747c (diff) | |
download | mongo-0f58d1037bcbfbf932e73e623772c4f815c361ad.tar.gz |
SERVER-17880 Rename OpTime to Timestamp
Diffstat (limited to 'src/mongo/db')
97 files changed, 1057 insertions, 967 deletions
diff --git a/src/mongo/db/auth/privilege_parser.h b/src/mongo/db/auth/privilege_parser.h index 66349199492..aec390e3973 100644 --- a/src/mongo/db/auth/privilege_parser.h +++ b/src/mongo/db/auth/privilege_parser.h @@ -32,7 +32,6 @@ #include <vector> #include "mongo/base/string_data.h" -#include "mongo/bson/bson_field.h" #include "mongo/db/jsobj.h" #include "mongo/s/bson_serializable.h" diff --git a/src/mongo/db/clientcursor.h b/src/mongo/db/clientcursor.h index 554fb0e7076..86d8bc0b7bb 100644 --- a/src/mongo/db/clientcursor.h +++ b/src/mongo/db/clientcursor.h @@ -136,9 +136,9 @@ namespace mongo { // void updateSlaveLocation(OperationContext* txn); - void slaveReadTill( const OpTime& t ) { _slaveReadTill = t; } + void slaveReadTill( const Timestamp& t ) { _slaveReadTill = t; } /** Just for testing. */ - OpTime getSlaveReadTill() const { return _slaveReadTill; } + Timestamp getSlaveReadTill() const { return _slaveReadTill; } // // Query-specific functionality that may be adapted for the PlanExecutor. @@ -250,7 +250,7 @@ namespace mongo { bool _isNoTimeout; // TODO: document better. - OpTime _slaveReadTill; + Timestamp _slaveReadTill; // How long has the cursor been idle? int _idleAgeMillis; diff --git a/src/mongo/db/commands/fsync.cpp b/src/mongo/db/commands/fsync.cpp index 8a2329c7f95..ac63457aa15 100644 --- a/src/mongo/db/commands/fsync.cpp +++ b/src/mongo/db/commands/fsync.cpp @@ -30,6 +30,7 @@ #include "mongo/db/commands/fsync.h" +#include <boost/thread/condition.hpp> #include <iostream> #include <sstream> #include <string> diff --git a/src/mongo/db/commands/get_last_error.cpp b/src/mongo/db/commands/get_last_error.cpp index 2a376a369a4..065fc484d58 100644 --- a/src/mongo/db/commands/get_last_error.cpp +++ b/src/mongo/db/commands/get_last_error.cpp @@ -130,7 +130,7 @@ namespace mongo { Client& c = *txn->getClient(); if (repl::getGlobalReplicationCoordinator()->getReplicationMode() == repl::ReplicationCoordinator::modeReplSet) { - const OpTime lastOp = repl::ReplClientInfo::forClient(c).getLastOp(); + const Timestamp lastOp = repl::ReplClientInfo::forClient(c).getLastOp(); if (!lastOp.isNull()) { result.append("lastOp", lastOp); } @@ -139,8 +139,8 @@ namespace mongo { // for sharding; also useful in general for debugging result.appendNumber( "connectionId" , c.getConnectionId() ); - OpTime lastOpTime; - BSONField<OpTime> wOpTimeField("wOpTime"); + Timestamp lastOpTime; + BSONField<Timestamp> wOpTimeField("wOpTime"); FieldParser::FieldState extracted = FieldParser::extract(cmdObj, wOpTimeField, &lastOpTime, &errmsg); if (!extracted) { diff --git a/src/mongo/db/dbcommands.cpp b/src/mongo/db/dbcommands.cpp index 6fa03e9909a..297dd866f7d 100644 --- a/src/mongo/db/dbcommands.cpp +++ b/src/mongo/db/dbcommands.cpp @@ -1397,9 +1397,9 @@ namespace mongo { }; namespace { - void appendGLEHelperData(BSONObjBuilder& bob, const OpTime& opTime, const OID& oid) { + void appendGLEHelperData(BSONObjBuilder& bob, const Timestamp& opTime, const OID& oid) { BSONObjBuilder subobj(bob.subobjStart(kGLEStatsFieldName)); - subobj.appendTimestamp(kGLEStatsLastOpTimeFieldName, opTime.asDate()); + subobj.append(kGLEStatsLastOpTimeFieldName, opTime); subobj.appendOID(kGLEStatsElectionIdFieldName, const_cast<OID*>(&oid)); subobj.done(); } diff --git a/src/mongo/db/field_parser.cpp b/src/mongo/db/field_parser.cpp index a53714afadb..1dbca72c2c7 100644 --- a/src/mongo/db/field_parser.cpp +++ b/src/mongo/db/field_parser.cpp @@ -162,16 +162,16 @@ namespace mongo { } FieldParser::FieldState FieldParser::extract( BSONObj doc, - const BSONField<OpTime>& field, - OpTime* out, + const BSONField<Timestamp>& field, + Timestamp* out, string* errMsg ) { return extract( doc[field.name()], field, out, errMsg ); } FieldParser::FieldState FieldParser::extract( BSONElement elem, - const BSONField<OpTime>& field, - OpTime* out, + const BSONField<Timestamp>& field, + Timestamp* out, string* errMsg ) { if (elem.eoo()) { @@ -184,8 +184,8 @@ namespace mongo { } } - if (elem.type() == Timestamp) { - *out = elem._opTime(); + if (elem.type() == bsonTimestamp) { + *out = elem.timestamp(); return FIELD_SET; } diff --git a/src/mongo/db/field_parser.h b/src/mongo/db/field_parser.h index 92a3df37e39..2b8da3eaa0a 100644 --- a/src/mongo/db/field_parser.h +++ b/src/mongo/db/field_parser.h @@ -30,7 +30,6 @@ #include <string> -#include "mongo/bson/bson_field.h" #include "mongo/db/jsobj.h" #include "mongo/s/bson_serializable.h" #include "mongo/util/time_support.h" @@ -107,13 +106,13 @@ namespace mongo { std::string* errMsg = NULL ); static FieldState extract( BSONObj doc, - const BSONField<OpTime>& field, - OpTime* out, + const BSONField<Timestamp>& field, + Timestamp* out, std::string* errMsg = NULL ); static FieldState extract( BSONElement elem, - const BSONField<OpTime>& field, - OpTime* out, + const BSONField<Timestamp>& field, + Timestamp* out, std::string* errMsg = NULL ); static FieldState extract( BSONObj doc, diff --git a/src/mongo/db/field_parser_test.cpp b/src/mongo/db/field_parser_test.cpp index 9e3f974c915..902b6548e64 100644 --- a/src/mongo/db/field_parser_test.cpp +++ b/src/mongo/db/field_parser_test.cpp @@ -30,7 +30,6 @@ #include <vector> #include <map> -#include "mongo/bson/bson_field.h" #include "mongo/db/field_parser.h" #include "mongo/db/jsobj.h" #include "mongo/unittest/unittest.h" diff --git a/src/mongo/db/global_optime.cpp b/src/mongo/db/global_timestamp.cpp index 664838a179c..f6cf646ba7e 100644 --- a/src/mongo/db/global_optime.cpp +++ b/src/mongo/db/global_timestamp.cpp @@ -28,15 +28,17 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault -#include "mongo/db/global_optime.h" +#include <boost/thread.hpp> + +#include "mongo/db/global_timestamp.h" #include "mongo/util/concurrency/mutex.h" #include "mongo/util/log.h" namespace { - mongo::mutex globalOptimeMutex; - mongo::OpTime globalOpTime(0, 0); + mongo::mutex globalTimestampMutex; + mongo::Timestamp globalTimestamp(0, 0); - bool skewed(const mongo::OpTime& val) { + bool skewed(const mongo::Timestamp& val) { if (val.getInc() & 0x80000000) { mongo::warning() << "clock skew detected prev: " << val.getSecs() << " now: " << (unsigned) time(0) << std::endl; @@ -48,33 +50,33 @@ namespace { } namespace mongo { - void setGlobalOptime(const OpTime& newTime) { - boost::lock_guard<boost::mutex> lk(globalOptimeMutex); - globalOpTime = newTime; + void setGlobalTimestamp(const Timestamp& newTime) { + boost::lock_guard<boost::mutex> lk(globalTimestampMutex); + globalTimestamp = newTime; } - OpTime getLastSetOptime() { - boost::lock_guard<boost::mutex> lk(globalOptimeMutex); - return globalOpTime; + Timestamp getLastSetTimestamp() { + boost::lock_guard<boost::mutex> lk(globalTimestampMutex); + return globalTimestamp; } - OpTime getNextGlobalOptime() { - boost::lock_guard<boost::mutex> lk(globalOptimeMutex); + Timestamp getNextGlobalTimestamp() { + boost::lock_guard<boost::mutex> lk(globalTimestampMutex); const unsigned now = (unsigned) time(0); - const unsigned globalSecs = globalOpTime.getSecs(); + const unsigned globalSecs = globalTimestamp.getSecs(); if ( globalSecs == now ) { - globalOpTime = OpTime(globalSecs, globalOpTime.getInc() + 1); + globalTimestamp = Timestamp(globalSecs, globalTimestamp.getInc() + 1); } else if ( now < globalSecs ) { - globalOpTime = OpTime(globalSecs, globalOpTime.getInc() + 1); + globalTimestamp = Timestamp(globalSecs, globalTimestamp.getInc() + 1); // separate function to keep out of the hot code path - fassert(17449, !skewed(globalOpTime)); + fassert(17449, !skewed(globalTimestamp)); } else { - globalOpTime = OpTime(now, 1); + globalTimestamp = Timestamp(now, 1); } - return globalOpTime; + return globalTimestamp; } } diff --git a/src/mongo/db/global_optime.h b/src/mongo/db/global_timestamp.h index acb6e2d0ae6..d39a5364fd5 100644 --- a/src/mongo/db/global_optime.h +++ b/src/mongo/db/global_timestamp.h @@ -28,18 +28,18 @@ #pragma once -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" namespace mongo { - void setGlobalOptime(const OpTime& newTime); + void setGlobalTimestamp(const Timestamp& newTime); /** - * Returns the value of the global OpTime generated last time or set. + * Returns the value of the global Timestamp generated last time or set. */ - OpTime getLastSetOptime(); + Timestamp getLastSetTimestamp(); /** - * Generates a new and unique OpTime. + * Generates a new and unique Timestamp. */ - OpTime getNextGlobalOptime(); + Timestamp getNextGlobalTimestamp(); } diff --git a/src/mongo/db/hasher_test.cpp b/src/mongo/db/hasher_test.cpp index 1d52e8815b0..02351127c48 100644 --- a/src/mongo/db/hasher_test.cpp +++ b/src/mongo/db/hasher_test.cpp @@ -345,7 +345,7 @@ namespace { BSONObj o = BSON( "check" << Date_t( 0x5566778811223344LL ) ); ASSERT_EQUALS( hashIt( o ), 4476222765095560467LL ); - o = builder1.append( "check", OpTime(0x55667788LL, 0x11223344LL) ).obj(); + o = builder1.append( "check", Timestamp(0x55667788LL, 0x11223344LL) ).obj(); ASSERT_EQUALS( hashIt( o ), 4873046866288452390LL ); o = BSON( "check" << Date_t( 0 ) ); diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp index 1c49b54c3a1..0595cf83ede 100644 --- a/src/mongo/db/instance.cpp +++ b/src/mongo/db/instance.cpp @@ -59,7 +59,7 @@ #include "mongo/db/exec/delete.h" #include "mongo/db/exec/update.h" #include "mongo/db/service_context.h" -#include "mongo/db/global_optime.h" +#include "mongo/db/global_timestamp.h" #include "mongo/db/instance.h" #include "mongo/db/introspect.h" #include "mongo/db/json.h" @@ -828,7 +828,7 @@ namespace { int pass = 0; bool exhaust = false; QueryResult::View msgdata = 0; - OpTime last; + Timestamp last; while( 1 ) { bool isCursorAuthorized = false; try { @@ -846,10 +846,10 @@ namespace { } if (pass == 0) { - last = getLastSetOptime(); + last = getLastSetTimestamp(); } else { - repl::waitUpToOneSecondForOptimeChange(last); + repl::waitUpToOneSecondForTimestampChange(last); } } diff --git a/src/mongo/db/jsobj.h b/src/mongo/db/jsobj.h index 83bb1d80879..6a4e962b683 100644 --- a/src/mongo/db/jsobj.h +++ b/src/mongo/db/jsobj.h @@ -43,7 +43,7 @@ #include "mongo/platform/basic.h" #include "mongo/bson/util/builder.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/bson/bsontypes.h" #include "mongo/bson/oid.h" #include "mongo/bson/bsonelement.h" @@ -52,5 +52,4 @@ #include "mongo/bson/bsonobjbuilder.h" #include "mongo/bson/ordering.h" #include "mongo/base/string_data.h" -#include "mongo/bson/bson_db.h" diff --git a/src/mongo/db/json.cpp b/src/mongo/db/json.cpp index 6369ddfe50a..8fca4e77190 100644 --- a/src/mongo/db/json.cpp +++ b/src/mongo/db/json.cpp @@ -555,7 +555,7 @@ namespace mongo { if (!readToken(RBRACE)) { return parseError("Expecting '}'"); } - builder.append(fieldName, OpTime(seconds, count)); + builder.append(fieldName, Timestamp(seconds, count)); return Status::OK(); } @@ -815,7 +815,7 @@ namespace mongo { if (!readToken(RPAREN)) { return parseError("Expecting ')'"); } - builder.append(fieldName, OpTime(seconds, count)); + builder.append(fieldName, Timestamp(seconds, count)); return Status::OK(); } diff --git a/src/mongo/db/lasterror.h b/src/mongo/db/lasterror.h index 60cd9c1eae2..778a1653bb3 100644 --- a/src/mongo/db/lasterror.h +++ b/src/mongo/db/lasterror.h @@ -43,6 +43,7 @@ namespace mongo { static const char kUpsertedFieldName[] = "upserted"; static const char kGLEStatsFieldName[] = "$gleStats"; static const char kGLEStatsLastOpTimeFieldName[] = "lastOpTime"; + static const char kGLEStatsLastOpTimeTermFieldName[] = "lastOpTimeTerm"; static const char kGLEStatsElectionIdFieldName[] = "electionId"; struct LastError { diff --git a/src/mongo/db/ops/SConscript b/src/mongo/db/ops/SConscript index f16faacf6e1..5c0018803a5 100644 --- a/src/mongo/db/ops/SConscript +++ b/src/mongo/db/ops/SConscript @@ -69,7 +69,7 @@ env.Library( ], LIBDEPS=[ '$BUILD_DIR/mongo/expressions', - '$BUILD_DIR/mongo/global_optime', + '$BUILD_DIR/mongo/global_timestamp', 'update_common', ], ) diff --git a/src/mongo/db/ops/insert.cpp b/src/mongo/db/ops/insert.cpp index f410962b5b3..715895830da 100644 --- a/src/mongo/db/ops/insert.cpp +++ b/src/mongo/db/ops/insert.cpp @@ -29,7 +29,7 @@ */ #include "mongo/db/ops/insert.h" -#include "mongo/db/global_optime.h" +#include "mongo/db/global_timestamp.h" #include "mongo/util/mongoutils/str.h" namespace mongo { @@ -53,7 +53,7 @@ namespace mongo { while ( i.more() ) { BSONElement e = i.next(); - if ( e.type() == Timestamp && e.timestampValue() == 0 ) { + if ( e.type() == bsonTimestamp && e.timestampValue() == 0 ) { // we replace Timestamp(0,0) at the top level with a correct value // in the fast pass, we just mark that we want to swap hasTimestampToFix = true; @@ -122,8 +122,8 @@ namespace mongo { if ( hadId && e.fieldNameStringData() == "_id" ) { // no-op } - else if ( e.type() == Timestamp && e.timestampValue() == 0 ) { - b.append( e.fieldName(), getNextGlobalOptime() ); + else if ( e.type() == bsonTimestamp && e.timestampValue() == 0 ) { + b.append( e.fieldName(), getNextGlobalTimestamp() ); } else { b.append( e ); diff --git a/src/mongo/db/ops/modifier_current_date.cpp b/src/mongo/db/ops/modifier_current_date.cpp index aa683a5404f..f38cc4e4441 100644 --- a/src/mongo/db/ops/modifier_current_date.cpp +++ b/src/mongo/db/ops/modifier_current_date.cpp @@ -30,7 +30,7 @@ #include "mongo/base/error_codes.h" #include "mongo/bson/mutable/document.h" -#include "mongo/db/global_optime.h" +#include "mongo/db/global_timestamp.h" #include "mongo/db/ops/field_checker.h" #include "mongo/db/ops/log_builder.h" #include "mongo/db/ops/path_support.h" @@ -210,7 +210,7 @@ namespace mongo { elemToSet = _typeIsDate ? doc.makeElementDate(lastPart, Date_t()) : - doc.makeElementTimestamp(lastPart, OpTime()); + doc.makeElementTimestamp(lastPart, Timestamp()); if (!elemToSet.ok()) { return Status(ErrorCodes::InternalError, "can't create new element"); @@ -246,7 +246,7 @@ namespace mongo { return s; } else { - Status s = elemToSet.setValueTimestamp(getNextGlobalOptime()); + Status s = elemToSet.setValueTimestamp(getNextGlobalTimestamp()); if (!s.isOK()) return s; } diff --git a/src/mongo/db/ops/modifier_current_date_test.cpp b/src/mongo/db/ops/modifier_current_date_test.cpp index 512c857bc1b..51eb4a79659 100644 --- a/src/mongo/db/ops/modifier_current_date_test.cpp +++ b/src/mongo/db/ops/modifier_current_date_test.cpp @@ -43,7 +43,7 @@ namespace { using mongo::LogBuilder; using mongo::ModifierCurrentDate; using mongo::ModifierInterface; - using mongo::OpTime; + using mongo::Timestamp; using mongo::Status; using mongo::StringData; using mongo::fromjson; @@ -220,7 +220,7 @@ namespace { ASSERT_FALSE(execInfo.noOp); ASSERT_EQUALS("a", execInfo.fieldRef[0]->dottedField()); - mongo::OpTime ts; + mongo::Timestamp ts; BSONObj olderDateObj = BSON("a" << ts); ASSERT_OK(mod.apply()); ASSERT_FALSE(doc.isInPlaceModeEnabled()); @@ -305,7 +305,7 @@ namespace { ASSERT_FALSE(execInfo.noOp); ASSERT_EQUALS("a", execInfo.fieldRef[0]->dottedField()); - mongo::OpTime ts; + mongo::Timestamp ts; BSONObj olderDateObj = BSON("a" << ts); ASSERT_OK(mod.apply()); ASSERT_TRUE(doc.isInPlaceModeEnabled()); //Same Size as Date @@ -327,7 +327,7 @@ namespace { ASSERT_FALSE(execInfo.noOp); ASSERT_EQUALS("a.b", execInfo.fieldRef[0]->dottedField()); - mongo::OpTime ts; + mongo::Timestamp ts; BSONObj olderDateObj = BSON("a" << BSON( "b" << ts)); ASSERT_OK(mod.apply()); ASSERT_TRUE(doc.isInPlaceModeEnabled()); //Same Size as Date @@ -349,7 +349,7 @@ namespace { ASSERT_FALSE(execInfo.noOp); ASSERT_EQUALS("a.b", execInfo.fieldRef[0]->dottedField()); - mongo::OpTime ts; + mongo::Timestamp ts; BSONObj olderDateObj = BSON("a" << BSON( "b" << ts)); ASSERT_OK(mod.apply()); ASSERT_FALSE(doc.isInPlaceModeEnabled()); diff --git a/src/mongo/db/ops/modifier_object_replace.cpp b/src/mongo/db/ops/modifier_object_replace.cpp index dc714b52105..5ebbb4bd342 100644 --- a/src/mongo/db/ops/modifier_object_replace.cpp +++ b/src/mongo/db/ops/modifier_object_replace.cpp @@ -30,7 +30,7 @@ #include "mongo/base/error_codes.h" #include "mongo/bson/mutable/document.h" -#include "mongo/db/global_optime.h" +#include "mongo/db/global_timestamp.h" #include "mongo/db/ops/log_builder.h" #include "mongo/util/mongoutils/str.h" @@ -47,14 +47,15 @@ namespace mongo { BSONElement e = i.next(); // Skip _id field -- we do not replace it - if (e.type() == Timestamp && e.fieldNameStringData() != idFieldName) { - // performance note, this locks a mutex: + if (e.type() == bsonTimestamp && e.fieldNameStringData() != idFieldName) { + // TODO(emilkie): This is not endian-safe. unsigned long long ×tamp = *(reinterpret_cast<unsigned long long*>( const_cast<char *>(e.value()))); if (timestamp == 0) { - OpTime ts(getNextGlobalOptime()); - timestamp = ts.asDate(); + // performance note, this locks a mutex: + Timestamp ts(getNextGlobalTimestamp()); + timestamp = ts.asULL(); } } } diff --git a/src/mongo/db/ops/modifier_object_replace_test.cpp b/src/mongo/db/ops/modifier_object_replace_test.cpp index 77946d11e05..3a5de50fead 100644 --- a/src/mongo/db/ops/modifier_object_replace_test.cpp +++ b/src/mongo/db/ops/modifier_object_replace_test.cpp @@ -34,7 +34,7 @@ #include "mongo/bson/mutable/algorithm.h" #include "mongo/bson/mutable/document.h" #include "mongo/bson/mutable/mutable_bson_test_utils.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/jsobj.h" #include "mongo/db/json.h" #include "mongo/db/ops/log_builder.h" diff --git a/src/mongo/db/pipeline/document_value_test.cpp b/src/mongo/db/pipeline/document_value_test.cpp index 28e63419242..0deb17f7341 100644 --- a/src/mongo/db/pipeline/document_value_test.cpp +++ b/src/mongo/db/pipeline/document_value_test.cpp @@ -375,7 +375,7 @@ namespace DocumentTests { append("codeWScope", BSONCodeWScope("asdf", BSONObj())); append("codeWScopeWScope", BSONCodeWScope("asdf", BSON("one" << 1))); append("int", 1); - append("timestamp", OpTime()); + append("timestamp", Timestamp()); append("long", 1LL); append("very long", 1LL << 40); append("maxkey", MAXKEY); @@ -533,12 +533,12 @@ namespace DocumentTests { }; /** Timestamp type. */ - class Timestamp { + class JSTimestamp { public: void run() { - Value value = Value( OpTime( 777 ) ); - ASSERT( OpTime( 777 ) == value.getTimestamp() ); - ASSERT_EQUALS( mongo::Timestamp, value.getType() ); + Value value = Value( Timestamp( 777 ) ); + ASSERT( Timestamp( 777 ) == value.getTimestamp() ); + ASSERT_EQUALS( mongo::bsonTimestamp, value.getType() ); assertRoundTrips( value ); } }; @@ -1024,7 +1024,7 @@ namespace DocumentTests { */ class TimestampToDate : public ToDateBase { Value value() { - return Value( OpTime( 777, 666 ) ); + return Value( Timestamp( 777, 666 ) ); } long long expected() { return 777 * 1000; } }; @@ -1076,9 +1076,9 @@ namespace DocumentTests { /** Coerce timestamp to string. */ class TimestampToString : public ToStringBase { Value value() { - return Value( OpTime( 1, 2 ) ); + return Value( Timestamp( 1, 2 ) ); } - string expected() { return OpTime( 1, 2 ).toStringPretty(); } + string expected() { return Timestamp( 1, 2 ).toStringPretty(); } }; /** Coerce date to string. */ @@ -1111,8 +1111,8 @@ namespace DocumentTests { class TimestampToTimestamp { public: void run() { - Value value = Value( OpTime( 1010 ) ); - ASSERT( OpTime( 1010 ) == value.coerceToTimestamp() ); + Value value = Value( Timestamp( 1010 ) ); + ASSERT( Timestamp( 1010 ) == value.coerceToTimestamp() ); } }; @@ -1272,8 +1272,8 @@ namespace DocumentTests { assertComparison( -1, fromjson( "{'':/a/}" ), fromjson( "{'':/aa/}" ) ); // Timestamp. - assertComparison( 0, OpTime( 1234 ), OpTime( 1234 ) ); - assertComparison( -1, OpTime( 4 ), OpTime( 1234 ) ); + assertComparison( 0, Timestamp( 1234 ), Timestamp( 1234 ) ); + assertComparison( -1, Timestamp( 4 ), Timestamp( 1234 ) ); // Cross-type comparisons. Listed in order of canonical types. assertComparison(-1, Value(mongo::MINKEY), Value()); @@ -1291,8 +1291,8 @@ namespace DocumentTests { assertComparison(-1, Value(BSONBinData("", 0, MD5Type)), Value(mongo::OID())); assertComparison(-1, Value(mongo::OID()), Value(false)); assertComparison(-1, Value(false), Value(Date_t(0))); - assertComparison(-1, Value(Date_t(0)), Value(OpTime())); - assertComparison(-1, Value(OpTime()), Value(BSONRegEx(""))); + assertComparison(-1, Value(Date_t(0)), Value(Timestamp())); + assertComparison(-1, Value(Timestamp()), Value(BSONRegEx(""))); assertComparison(-1, Value(BSONRegEx("")), Value(BSONDBRef("", mongo::OID()))); assertComparison(-1, Value(BSONDBRef("", mongo::OID())), Value(BSONCode(""))); assertComparison(-1, Value(BSONCode("")), Value(BSONCodeWScope("", BSONObj()))); @@ -1303,11 +1303,11 @@ namespace DocumentTests { void assertComparison( int expectedResult, const T& a, const U& b ) { assertComparison( expectedResult, BSON( "" << a ), BSON( "" << b ) ); } - void assertComparison( int expectedResult, const OpTime& a, const OpTime& b ) { + void assertComparison( int expectedResult, const Timestamp& a, const Timestamp& b ) { BSONObjBuilder first; - first.appendTimestamp( "", a.asDate() ); + first.append( "", a ); BSONObjBuilder second; - second.appendTimestamp( "", b.asDate() ); + second.append( "", b ); assertComparison( expectedResult, first.obj(), second.obj() ); } int sign(int cmp) { @@ -1433,7 +1433,7 @@ namespace DocumentTests { add<Value::String>(); add<Value::StringWithNull>(); add<Value::Date>(); - add<Value::Timestamp>(); + add<Value::JSTimestamp>(); add<Value::EmptyDocument>(); add<Value::EmptyArray>(); add<Value::Array>(); diff --git a/src/mongo/db/pipeline/value.cpp b/src/mongo/db/pipeline/value.cpp index f96e8c0aeca..8ef22166e84 100644 --- a/src/mongo/db/pipeline/value.cpp +++ b/src/mongo/db/pipeline/value.cpp @@ -56,7 +56,7 @@ namespace mongo { case MaxKey: case jstOID: case Date: - case Timestamp: + case bsonTimestamp: case EOO: case jstNULL: case Undefined: @@ -199,8 +199,8 @@ namespace mongo { _storage.intValue = elem.numberInt(); break; - case Timestamp: - _storage.timestampValue = elem._opTime().asDate(); + case bsonTimestamp: + _storage.timestampValue = elem.timestamp().asULL(); break; case NumberLong: @@ -289,7 +289,7 @@ namespace mongo { case String: return builder << val.getStringData(); case Bool: return builder << val.getBool(); case Date: return builder << Date_t(val.getDate()); - case Timestamp: return builder << val.getTimestamp(); + case bsonTimestamp: return builder << val.getTimestamp(); case Object: return builder << val.getDocument(); case Symbol: return builder << BSONSymbol(val.getStringData()); case Code: return builder << BSONCode(val.getStringData()); @@ -347,7 +347,7 @@ namespace mongo { case Date: case RegEx: case Symbol: - case Timestamp: + case bsonTimestamp: return true; case EOO: @@ -425,7 +425,7 @@ namespace mongo { case Date: return getDate(); - case Timestamp: + case bsonTimestamp: return getTimestamp().getSecs() * 1000LL; default: @@ -502,7 +502,7 @@ namespace mongo { case String: return getStringData().toString(); - case Timestamp: + case bsonTimestamp: return getTimestamp().toStringPretty(); case Date: @@ -521,9 +521,9 @@ namespace mongo { } // switch(getType()) } - OpTime Value::coerceToTimestamp() const { + Timestamp Value::coerceToTimestamp() const { switch(getType()) { - case Timestamp: + case bsonTimestamp: return getTimestamp(); default: @@ -578,7 +578,7 @@ namespace mongo { case Bool: return rL.getBool() - rR.getBool(); - case Timestamp: // unsigned + case bsonTimestamp: // unsigned return cmp(rL._storage.timestampValue, rR._storage.timestampValue); case Date: // signed @@ -705,7 +705,7 @@ namespace mongo { boost::hash_combine(seed, getBool()); break; - case Timestamp: + case bsonTimestamp: case Date: BOOST_STATIC_ASSERT(sizeof(_storage.dateValue) == sizeof(_storage.timestampValue)); boost::hash_combine(seed, _storage.dateValue); @@ -864,7 +864,7 @@ namespace mongo { case Bool: case Date: case NumberInt: - case Timestamp: + case bsonTimestamp: case NumberLong: case jstNULL: case Undefined: @@ -897,7 +897,7 @@ namespace mongo { case jstNULL: return out << "null"; case Undefined: return out << "undefined"; case Date: return out << tmToISODateString(val.coerceToTm()); - case Timestamp: return out << val.getTimestamp().toString(); + case bsonTimestamp: return out << val.getTimestamp().toString(); case Object: return out << val.getDocument().toString(); case Array: { out << "["; @@ -948,7 +948,7 @@ namespace mongo { case NumberDouble: buf.appendNum(_storage.doubleValue); break; case Bool: buf.appendChar(_storage.boolValue); break; case Date: buf.appendNum(_storage.dateValue); break; - case Timestamp: buf.appendStruct(getTimestamp()); break; + case bsonTimestamp: buf.appendStruct(getTimestamp()); break; // types that are like strings case String: @@ -1019,7 +1019,7 @@ namespace mongo { case NumberDouble: return Value(buf.read<double>()); case Bool: return Value(bool(buf.read<char>())); case Date: return Value(Date_t(buf.read<long long>())); - case Timestamp: return Value(buf.read<OpTime>()); + case bsonTimestamp: return Value(buf.read<Timestamp>()); // types that are like strings case String: diff --git a/src/mongo/db/pipeline/value.h b/src/mongo/db/pipeline/value.h index dc10ea3246e..4e30c30564d 100644 --- a/src/mongo/db/pipeline/value.h +++ b/src/mongo/db/pipeline/value.h @@ -72,7 +72,7 @@ namespace mongo { explicit Value(int value) : _storage(NumberInt, value) {} explicit Value(long long value) : _storage(NumberLong, value) {} explicit Value(double value) : _storage(NumberDouble, value) {} - explicit Value(const OpTime& value) : _storage(Timestamp, value) {} + explicit Value(const Timestamp& value) : _storage(bsonTimestamp, value) {} explicit Value(const OID& value) : _storage(jstOID, value) {} explicit Value(StringData value) : _storage(String, value) {} explicit Value(const std::string& value) : _storage(String, StringData(value)) {} @@ -150,7 +150,7 @@ namespace mongo { OID getOid() const; bool getBool() const; long long getDate() const; // in milliseconds - OpTime getTimestamp() const; + Timestamp getTimestamp() const; const char* getRegex() const; const char* getRegexFlags() const; std::string getSymbol() const; @@ -189,7 +189,7 @@ namespace mongo { int coerceToInt() const; long long coerceToLong() const; double coerceToDouble() const; - OpTime coerceToTimestamp() const; + Timestamp coerceToTimestamp() const; long long coerceToDate() const; time_t coerceToTimeT() const; tm coerceToTm() const; // broken-out time struct (see man gmtime) @@ -326,8 +326,8 @@ namespace mongo { return _storage.dateValue; } - inline OpTime Value::getTimestamp() const { - verify(getType() == Timestamp); + inline Timestamp Value::getTimestamp() const { + verify(getType() == bsonTimestamp); return Date_t(_storage.timestampValue); } diff --git a/src/mongo/db/pipeline/value_internal.h b/src/mongo/db/pipeline/value_internal.h index 910728019ce..834c2e7d1d6 100644 --- a/src/mongo/db/pipeline/value_internal.h +++ b/src/mongo/db/pipeline/value_internal.h @@ -37,7 +37,7 @@ #include "mongo/bson/oid.h" #include "mongo/util/debug_util.h" #include "mongo/util/intrusive_counter.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" namespace mongo { @@ -81,7 +81,7 @@ namespace mongo { ValueStorage(BSONType t, int i) { zero(); type = t; intValue = i; } ValueStorage(BSONType t, long long l) { zero(); type = t; longValue = l; } ValueStorage(BSONType t, double d) { zero(); type = t; doubleValue = d; } - ValueStorage(BSONType t, OpTime r) { zero(); type = t; timestampValue = r.asDate(); } + ValueStorage(BSONType t, Timestamp r) { zero(); type = t; timestampValue = r.asULL(); } ValueStorage(BSONType t, bool b) { zero(); type = t; boolValue = b; } ValueStorage(BSONType t, const Document& d) { zero(); type = t; putDocument(d); } ValueStorage(BSONType t, const RCVector* a) { zero(); type = t; putVector(a); } diff --git a/src/mongo/db/query/find.cpp b/src/mongo/db/query/find.cpp index fb6218fc800..a6a13db1fc8 100644 --- a/src/mongo/db/query/find.cpp +++ b/src/mongo/db/query/find.cpp @@ -377,7 +377,7 @@ namespace mongo { } // If we're replaying the oplog, we save the last time that we read. - OpTime slaveReadTill; + Timestamp slaveReadTill; // What number result are we starting at? Used to fill out the reply. startingResult = cc->pos(); @@ -401,8 +401,8 @@ namespace mongo { // Possibly note slave's position in the oplog. if (queryOptions & QueryOption_OplogReplay) { BSONElement e = obj["ts"]; - if (Date == e.type() || Timestamp == e.type()) { - slaveReadTill = e._opTime(); + if (Date == e.type() || bsonTimestamp == e.type()) { + slaveReadTill = e.timestamp(); } } @@ -615,7 +615,7 @@ namespace mongo { int numResults = 0; // If we're replaying the oplog, we save the last time that we read. - OpTime slaveReadTill; + Timestamp slaveReadTill; BSONObj obj; PlanExecutor::ExecState state; @@ -634,8 +634,8 @@ namespace mongo { // Possibly note slave's position in the oplog. if (pq.isOplogReplay()) { BSONElement e = obj["ts"]; - if (Date == e.type() || Timestamp == e.type()) { - slaveReadTill = e._opTime(); + if (Date == e.type() || bsonTimestamp == e.type()) { + slaveReadTill = e.timestamp(); } } diff --git a/src/mongo/db/query/get_executor.cpp b/src/mongo/db/query/get_executor.cpp index 6e3af1c474b..202be486a68 100644 --- a/src/mongo/db/query/get_executor.cpp +++ b/src/mongo/db/query/get_executor.cpp @@ -556,8 +556,8 @@ namespace { // See if the RecordStore supports the oplogStartHack const BSONElement tsElem = extractOplogTsOptime(tsExpr); - if (tsElem.type() == Timestamp) { - StatusWith<RecordId> goal = oploghack::keyForOptime(tsElem._opTime()); + if (tsElem.type() == bsonTimestamp) { + StatusWith<RecordId> goal = oploghack::keyForOptime(tsElem.timestamp()); if (goal.isOK()) { startLoc = collection->getRecordStore()->oplogStartHack(txn, goal.getValue()); } diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index e8d797785de..725740ec022 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -90,7 +90,7 @@ env.Library('repl_coordinator_impl', '$BUILD_DIR/mongo/db/common', '$BUILD_DIR/mongo/db/index/index_descriptor', '$BUILD_DIR/mongo/fail_point', - '$BUILD_DIR/mongo/global_optime', + '$BUILD_DIR/mongo/global_timestamp', '$BUILD_DIR/mongo/server_options_core', '$BUILD_DIR/mongo/service_context', '$BUILD_DIR/mongo/util/net/command_status', diff --git a/src/mongo/db/repl/bgsync.cpp b/src/mongo/db/repl/bgsync.cpp index ad2833df368..7cdd1d42a2a 100644 --- a/src/mongo/db/repl/bgsync.cpp +++ b/src/mongo/db/repl/bgsync.cpp @@ -228,7 +228,7 @@ namespace { // find a target to sync from the last optime fetched - OpTime lastOpTimeFetched; + Timestamp lastOpTimeFetched; { boost::unique_lock<boost::mutex> lock(_mutex); lastOpTimeFetched = _lastOpTimeFetched; @@ -354,7 +354,7 @@ namespace { { boost::unique_lock<boost::mutex> lock(_mutex); _lastFetchedHash = o["h"].numberLong(); - _lastOpTimeFetched = o["ts"]._opTime(); + _lastOpTimeFetched = o["ts"].timestamp(); LOG(3) << "lastOpTimeFetched: " << _lastOpTimeFetched.toStringPretty(); } } @@ -402,7 +402,7 @@ namespace { sleepsecs(2); return true; } - OpTime theirTS = theirLastOp["ts"]._opTime(); + Timestamp theirTS = theirLastOp["ts"].timestamp(); if (theirTS < _lastOpTimeFetched) { log() << "we are ahead of the sync source, will try to roll back"; syncRollback(txn, _replCoord->getMyLastOptime(), &r, _replCoord); @@ -420,7 +420,7 @@ namespace { } BSONObj o = r.nextSafe(); - OpTime ts = o["ts"]._opTime(); + Timestamp ts = o["ts"].timestamp(); long long hash = o["h"].numberLong(); if( ts != _lastOpTimeFetched || hash != _lastFetchedHash ) { log() << "our last op time fetched: " << _lastOpTimeFetched.toStringPretty(); @@ -447,7 +447,7 @@ namespace { _pause = true; _syncSourceHost = HostAndPort(); - _lastOpTimeFetched = OpTime(0,0); + _lastOpTimeFetched = Timestamp(0,0); _lastFetchedHash = 0; _appliedBufferCondition.notify_all(); _pausedCondition.notify_all(); diff --git a/src/mongo/db/repl/bgsync.h b/src/mongo/db/repl/bgsync.h index 8a36e572abe..7537e0e8606 100644 --- a/src/mongo/db/repl/bgsync.h +++ b/src/mongo/db/repl/bgsync.h @@ -131,7 +131,7 @@ namespace repl { // _mutex protects all of the class variables except _syncSourceReader and _buffer mutable boost::mutex _mutex; - OpTime _lastOpTimeFetched; + Timestamp _lastOpTimeFetched; // lastAppliedHash is used to generate a new hash for the following op, when primary. long long _lastAppliedHash; diff --git a/src/mongo/db/repl/freshness_checker.cpp b/src/mongo/db/repl/freshness_checker.cpp index 3f533e28f6e..ebe3d59b67b 100644 --- a/src/mongo/db/repl/freshness_checker.cpp +++ b/src/mongo/db/repl/freshness_checker.cpp @@ -33,7 +33,7 @@ #include "mongo/db/repl/freshness_checker.h" #include "mongo/base/status.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/repl/member_heartbeat_data.h" #include "mongo/db/repl/replica_set_config.h" #include "mongo/db/repl/replication_executor.h" @@ -47,7 +47,7 @@ namespace mongo { namespace repl { FreshnessChecker::Algorithm::Algorithm( - OpTime lastOpTimeApplied, + Timestamp lastOpTimeApplied, const ReplicaSetConfig& rsConfig, int selfIndex, const std::vector<HostAndPort>& targets) : @@ -88,7 +88,7 @@ namespace repl { BSONObjBuilder freshCmdBuilder; freshCmdBuilder.append("replSetFresh", 1); freshCmdBuilder.append("set", _rsConfig.getReplSetName()); - freshCmdBuilder.append("opTime", Date_t(_lastOpTimeApplied.asDate())); + freshCmdBuilder.append("opTime", Date_t(_lastOpTimeApplied.asULL())); freshCmdBuilder.append("who", selfConfig.getHostAndPort().toString()); freshCmdBuilder.appendIntOrLL("cfgver", _rsConfig.getConfigVersion()); freshCmdBuilder.append("id", selfConfig.getId()); @@ -169,7 +169,7 @@ namespace repl { _abortReason = FresherNodeFound; return; } - OpTime remoteTime(res["opTime"].date()); + Timestamp remoteTime(res["opTime"].date()); if (remoteTime == _lastOpTimeApplied) { _abortReason = FreshnessTie; } @@ -216,7 +216,7 @@ namespace repl { StatusWith<ReplicationExecutor::EventHandle> FreshnessChecker::start( ReplicationExecutor* executor, - const OpTime& lastOpTimeApplied, + const Timestamp& lastOpTimeApplied, const ReplicaSetConfig& currentConfig, int selfIndex, const std::vector<HostAndPort>& targets, diff --git a/src/mongo/db/repl/freshness_checker.h b/src/mongo/db/repl/freshness_checker.h index 71f82cb86d3..3570ee8b051 100644 --- a/src/mongo/db/repl/freshness_checker.h +++ b/src/mongo/db/repl/freshness_checker.h @@ -32,7 +32,7 @@ #include <vector> #include "mongo/base/disallow_copying.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/repl/replica_set_config.h" #include "mongo/db/repl/replication_executor.h" #include "mongo/db/repl/scatter_gather_algorithm.h" @@ -59,7 +59,7 @@ namespace repl { class Algorithm : public ScatterGatherAlgorithm { public: - Algorithm(OpTime lastOpTimeApplied, + Algorithm(Timestamp lastOpTimeApplied, const ReplicaSetConfig& rsConfig, int selfIndex, const std::vector<HostAndPort>& targets); @@ -84,8 +84,8 @@ namespace repl { // Number of failed voter responses so far. int _failedVoterResponses; - // Last OpTime applied by the caller; used in the Fresh command - const OpTime _lastOpTimeApplied; + // Last Timestamp applied by the caller; used in the Fresh command + const Timestamp _lastOpTimeApplied; // Config to use for this check const ReplicaSetConfig _rsConfig; @@ -124,7 +124,7 @@ namespace repl { **/ StatusWith<ReplicationExecutor::EventHandle> start( ReplicationExecutor* executor, - const OpTime& lastOpTimeApplied, + const Timestamp& lastOpTimeApplied, const ReplicaSetConfig& currentConfig, int selfIndex, const std::vector<HostAndPort>& targets, diff --git a/src/mongo/db/repl/freshness_checker_test.cpp b/src/mongo/db/repl/freshness_checker_test.cpp index 362b4746606..2a7480e8d56 100644 --- a/src/mongo/db/repl/freshness_checker_test.cpp +++ b/src/mongo/db/repl/freshness_checker_test.cpp @@ -59,7 +59,7 @@ namespace { class FreshnessCheckerTest : public mongo::unittest::Test { protected: - void startTest(const OpTime& lastOpTimeApplied, + void startTest(const Timestamp& lastOpTimeApplied, const ReplicaSetConfig& currentConfig, int selfIndex, const std::vector<HostAndPort>& hosts); @@ -80,7 +80,7 @@ namespace { private: void freshnessCheckerRunner(const ReplicationExecutor::CallbackData& data, - const OpTime& lastOpTimeApplied, + const Timestamp& lastOpTimeApplied, const ReplicaSetConfig& currentConfig, int selfIndex, const std::vector<HostAndPort>& hosts); @@ -120,12 +120,12 @@ namespace { } const BSONObj makeFreshRequest(const ReplicaSetConfig& rsConfig, - OpTime lastOpTimeApplied, + Timestamp lastOpTimeApplied, int selfIndex) { const MemberConfig& myConfig = rsConfig.getMemberAt(selfIndex); return BSON("replSetFresh" << 1 << "set" << rsConfig.getReplSetName() << - "opTime" << Date_t(lastOpTimeApplied.asDate()) << + "opTime" << Date_t(lastOpTimeApplied.asULL()) << "who" << myConfig.getHostAndPort().toString() << "cfgver" << rsConfig.getConfigVersion() << "id" << myConfig.getId()); @@ -135,7 +135,7 @@ namespace { // for correct concurrency operation. void FreshnessCheckerTest::freshnessCheckerRunner( const ReplicationExecutor::CallbackData& data, - const OpTime& lastOpTimeApplied, + const Timestamp& lastOpTimeApplied, const ReplicaSetConfig& currentConfig, int selfIndex, const std::vector<HostAndPort>& hosts) { @@ -149,7 +149,7 @@ namespace { _checkerDoneEvent = assertGet(evh); } - void FreshnessCheckerTest::startTest(const OpTime& lastOpTimeApplied, + void FreshnessCheckerTest::startTest(const Timestamp& lastOpTimeApplied, const ReplicaSetConfig& currentConfig, int selfIndex, const std::vector<HostAndPort>& hosts) { @@ -176,9 +176,9 @@ namespace { std::vector<HostAndPort> hosts; hosts.push_back(config.getMemberAt(1).getHostAndPort()); - const BSONObj freshRequest = makeFreshRequest(config, OpTime(0,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(0,0), 0); - startTest(OpTime(0, 0), config, 0, hosts); + startTest(Timestamp(0, 0), config, 0, hosts); const Date_t startDate = _net->now(); _net->enterNetwork(); for (size_t i = 0; i < hosts.size(); ++i) { @@ -195,7 +195,7 @@ namespace { "set" << "rs0" << "who" << "h1" << "cfgver" << 1 << - "opTime" << Date_t(OpTime(0,0).asDate())), + "opTime" << Date_t(Timestamp(0,0).asULL())), Milliseconds(8)))); } _net->runUntil(startDate + 10); @@ -218,7 +218,7 @@ namespace { hosts.push_back(config.getMemberAt(1).getHostAndPort()); startTest( - OpTime(0, 0), + Timestamp(0, 0), config, 0, hosts); @@ -244,9 +244,9 @@ namespace { std::vector<HostAndPort> hosts; hosts.push_back(config.getMemberAt(1).getHostAndPort()); - const BSONObj freshRequest = makeFreshRequest(config, OpTime(10,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(10,0), 0); - startTest(OpTime(10, 0), config, 0, hosts); + startTest(Timestamp(10, 0), config, 0, hosts); const Date_t startDate = _net->now(); _net->enterNetwork(); for (size_t i = 0; i < hosts.size(); ++i) { @@ -264,7 +264,7 @@ namespace { "who" << "h1" << "cfgver" << 1 << "fresher" << true << - "opTime" << Date_t(OpTime(0,0).asDate())), + "opTime" << Date_t(Timestamp(0,0).asULL())), Milliseconds(8)))); } _net->runUntil(startDate + 10); @@ -290,9 +290,9 @@ namespace { std::vector<HostAndPort> hosts; hosts.push_back(config.getMemberAt(1).getHostAndPort()); - const BSONObj freshRequest = makeFreshRequest(config, OpTime(0,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(0,0), 0); - startTest(OpTime(0, 0), config, 0, hosts); + startTest(Timestamp(0, 0), config, 0, hosts); const Date_t startDate = _net->now(); _net->enterNetwork(); for (size_t i = 0; i < hosts.size(); ++i) { @@ -309,7 +309,7 @@ namespace { "set" << "rs0" << "who" << "h1" << "cfgver" << 1 << - "opTime" << Date_t(OpTime(10,0).asDate())), + "opTime" << Date_t(Timestamp(10,0).asULL())), Milliseconds(8)))); } _net->runUntil(startDate + 10); @@ -334,9 +334,9 @@ namespace { std::vector<HostAndPort> hosts; hosts.push_back(config.getMemberAt(1).getHostAndPort()); - const BSONObj freshRequest = makeFreshRequest(config, OpTime(10,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(10,0), 0); - startTest(OpTime(10, 0), config, 0, hosts); + startTest(Timestamp(10, 0), config, 0, hosts); const Date_t startDate = _net->now(); _net->enterNetwork(); for (size_t i = 0; i < hosts.size(); ++i) { @@ -381,9 +381,9 @@ namespace { std::vector<HostAndPort> hosts; hosts.push_back(config.getMemberAt(1).getHostAndPort()); - const BSONObj freshRequest = makeFreshRequest(config, OpTime(10,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(10,0), 0); - startTest(OpTime(10, 0), config, 0, hosts); + startTest(Timestamp(10, 0), config, 0, hosts); const Date_t startDate = _net->now(); _net->enterNetwork(); for (size_t i = 0; i < hosts.size(); ++i) { @@ -402,7 +402,7 @@ namespace { "cfgver" << 1 << "veto" << true << "errmsg" << "I'd rather you didn't" << - "opTime" << Date_t(OpTime(0,0).asDate())), + "opTime" << Date_t(Timestamp(0,0).asULL())), Milliseconds(8)))); } _net->runUntil(startDate + 10); @@ -443,9 +443,9 @@ namespace { hosts.push_back(mem->getHostAndPort()); } - const BSONObj freshRequest = makeFreshRequest(config, OpTime(10,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(10,0), 0); - startTest(OpTime(10, 0), config, 0, hosts); + startTest(Timestamp(10, 0), config, 0, hosts); const Date_t startDate = _net->now(); unordered_set<HostAndPort> seen; _net->enterNetwork(); @@ -462,7 +462,7 @@ namespace { "set" << "rs0" << "who" << target.toString() << "cfgver" << 1 << - "opTime" << Date_t(OpTime(0,0).asDate()); + "opTime" << Date_t(Timestamp(0,0).asULL()); if (target.host() == "h1") { responseBuilder << "fresher" << true; } @@ -505,9 +505,9 @@ namespace { hosts.push_back(mem->getHostAndPort()); } - const BSONObj freshRequest = makeFreshRequest(config, OpTime(10,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(10,0), 0); - startTest(OpTime(10, 0), config, 0, hosts); + startTest(Timestamp(10, 0), config, 0, hosts); const Date_t startDate = _net->now(); unordered_set<HostAndPort> seen; _net->enterNetwork(); @@ -526,7 +526,7 @@ namespace { "set" << "rs0" << "who" << target.toString() << "cfgver" << 1 << - "opTime" << Date_t(OpTime(20,0).asDate()); + "opTime" << Date_t(Timestamp(20,0).asULL()); _net->scheduleResponse( noi, startDate + 20, @@ -541,7 +541,7 @@ namespace { "set" << "rs0" << "who" << target.toString() << "cfgver" << 1 << - "opTime" << Date_t(OpTime(10,0).asDate()); + "opTime" << Date_t(Timestamp(10,0).asULL()); _net->scheduleResponse( noi, startDate + 10, @@ -581,9 +581,9 @@ namespace { hosts.push_back(mem->getHostAndPort()); } - const BSONObj freshRequest = makeFreshRequest(config, OpTime(10,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(10,0), 0); - startTest(OpTime(10, 0), config, 0, hosts); + startTest(Timestamp(10, 0), config, 0, hosts); const Date_t startDate = _net->now(); unordered_set<HostAndPort> seen; _net->enterNetwork(); @@ -604,7 +604,7 @@ namespace { responseBuilder << "opTime" << 3; } else { - responseBuilder << "opTime" << Date_t(OpTime(0,0).asDate()); + responseBuilder << "opTime" << Date_t(Timestamp(0,0).asULL()); } _net->scheduleResponse( noi, @@ -643,9 +643,9 @@ namespace { hosts.push_back(mem->getHostAndPort()); } - const BSONObj freshRequest = makeFreshRequest(config, OpTime(10,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(10,0), 0); - startTest(OpTime(10, 0), config, 0, hosts); + startTest(Timestamp(10, 0), config, 0, hosts); const Date_t startDate = _net->now(); unordered_set<HostAndPort> seen; _net->enterNetwork(); @@ -662,7 +662,7 @@ namespace { "set" << "rs0" << "who" << target.toString() << "cfgver" << 1 << - "opTime" << Date_t(OpTime(0,0).asDate()); + "opTime" << Date_t(Timestamp(0,0).asULL()); if (target.host() == "h1") { responseBuilder << "veto" << true << "errmsg" << "I'd rather you didn't"; } @@ -706,9 +706,9 @@ namespace { hosts.push_back(mem->getHostAndPort()); } - const BSONObj freshRequest = makeFreshRequest(config, OpTime(10,0), 0); + const BSONObj freshRequest = makeFreshRequest(config, Timestamp(10,0), 0); - startTest(OpTime(10, 0), config, 0, hosts); + startTest(Timestamp(10, 0), config, 0, hosts); const Date_t startDate = _net->now(); unordered_set<HostAndPort> seen; _net->enterNetwork(); @@ -729,7 +729,7 @@ namespace { "cfgver" << 1 << "veto" << true << "errmsg" << "I'd rather you didn't" << - "opTime" << Date_t(OpTime(10,0).asDate()); + "opTime" << Date_t(Timestamp(10,0).asULL()); _net->scheduleResponse( noi, startDate + 20, @@ -744,7 +744,7 @@ namespace { "set" << "rs0" << "who" << target.toString() << "cfgver" << 1 << - "opTime" << Date_t(OpTime(10,0).asDate()); + "opTime" << Date_t(Timestamp(10,0).asULL()); _net->scheduleResponse( noi, startDate + 10, @@ -785,10 +785,10 @@ namespace { hosts.push_back(mem->getHostAndPort()); } - const OpTime lastOpTimeApplied(10,0); + const Timestamp lastOpTimeApplied(10,0); const BSONObj freshRequest = makeFreshRequest(config, lastOpTimeApplied, 0); - startTest(OpTime(10, 0), config, 0, hosts); + startTest(Timestamp(10, 0), config, 0, hosts); const Date_t startDate = _net->now(); unordered_set<HostAndPort> seen; _net->enterNetwork(); @@ -812,7 +812,7 @@ namespace { "set" << "rs0" << "who" << target.toString() << "cfgver" << 1 << - "opTime" << Date_t(OpTime(0,0).asDate()); + "opTime" << Date_t(Timestamp(0,0).asULL()); _net->scheduleResponse( noi, startDate + 10, @@ -832,7 +832,7 @@ namespace { public: virtual void setUp() { int selfConfigIndex = 0; - OpTime lastOpTimeApplied(100, 0); + Timestamp lastOpTimeApplied(100, 0); ReplicaSetConfig config; config.initialize(BSON("_id" << "rs0" << @@ -876,14 +876,14 @@ namespace { ResponseStatus lessFresh() { BSONObjBuilder bb; bb.append("ok", 1.0); - bb.appendDate("opTime", OpTime(10, 0).asDate()); + bb.appendDate("opTime", Timestamp(10, 0).asULL()); return ResponseStatus(NetworkInterfaceMock::Response(bb.obj(), Milliseconds(10))); } ResponseStatus moreFreshViaOpTime() { BSONObjBuilder bb; bb.append("ok", 1.0); - bb.appendDate("opTime", OpTime(110, 0).asDate()); + bb.appendDate("opTime", Timestamp(110, 0).asULL()); return ResponseStatus(NetworkInterfaceMock::Response(bb.obj(), Milliseconds(10))); } @@ -905,7 +905,7 @@ namespace { ResponseStatus tiedForFreshness() { BSONObjBuilder bb; bb.append("ok", 1.0); - bb.appendDate("opTime", OpTime(100, 0).asDate()); + bb.appendDate("opTime", Timestamp(100, 0).asULL()); return ResponseStatus(NetworkInterfaceMock::Response(bb.obj(), Milliseconds(10))); } diff --git a/src/mongo/db/repl/initial_sync.cpp b/src/mongo/db/repl/initial_sync.cpp index 494094862ba..2af2810db29 100644 --- a/src/mongo/db/repl/initial_sync.cpp +++ b/src/mongo/db/repl/initial_sync.cpp @@ -48,7 +48,7 @@ namespace repl { /* initial oplog application, during initial sync, after cloning. */ - void InitialSync::oplogApplication(OperationContext* txn, const OpTime& endOpTime) { + void InitialSync::oplogApplication(OperationContext* txn, const Timestamp& endOpTime) { if (replSetForceInitialSyncFailure > 0) { log() << "test code invoked, forced InitialSync failure: " << replSetForceInitialSyncFailure; diff --git a/src/mongo/db/repl/initial_sync.h b/src/mongo/db/repl/initial_sync.h index 69e99524b3e..593cefa3acf 100644 --- a/src/mongo/db/repl/initial_sync.h +++ b/src/mongo/db/repl/initial_sync.h @@ -46,7 +46,7 @@ namespace repl { /** * applies up to endOpTime, fetching missing documents as needed. */ - void oplogApplication(OperationContext* txn, const OpTime& endOpTime); + void oplogApplication(OperationContext* txn, const Timestamp& endOpTime); }; // Used for ReplSetTest testing. diff --git a/src/mongo/db/repl/master_slave.cpp b/src/mongo/db/repl/master_slave.cpp index b0ab3cb5037..2165b91da3d 100644 --- a/src/mongo/db/repl/master_slave.cpp +++ b/src/mongo/db/repl/master_slave.cpp @@ -119,8 +119,9 @@ namespace repl { uassert( 10119 , "only source='main' allowed for now with replication", sourceName() == "main" ); BSONElement e = o.getField("syncedTo"); if ( !e.eoo() ) { - uassert( 10120 , "bad sources 'syncedTo' field value", e.type() == Date || e.type() == Timestamp ); - OpTime tmp( e.date() ); + uassert(10120, "bad sources 'syncedTo' field value", + e.type() == Date || e.type() == bsonTimestamp); + Timestamp tmp( e.date() ); syncedTo = tmp; } @@ -156,7 +157,7 @@ namespace repl { if ( !only.empty() ) b.append("only", only); if ( !syncedTo.isNull() ) - b.appendTimestamp("syncedTo", syncedTo.asDate()); + b.append("syncedTo", syncedTo); BSONObjBuilder dbsNextPassBuilder; int n = 0; @@ -453,7 +454,7 @@ namespace repl { } } } - syncedTo = OpTime(); + syncedTo = Timestamp(); addDbNextPass.clear(); save(txn); } @@ -512,13 +513,13 @@ namespace repl { static DatabaseIgnorer ___databaseIgnorer; - void DatabaseIgnorer::doIgnoreUntilAfter( const string &db, const OpTime &futureOplogTime ) { + void DatabaseIgnorer::doIgnoreUntilAfter( const string &db, const Timestamp &futureOplogTime ) { if ( futureOplogTime > _ignores[ db ] ) { _ignores[ db ] = futureOplogTime; } } - bool DatabaseIgnorer::ignoreAt( const string &db, const OpTime ¤tOplogTime ) { + bool DatabaseIgnorer::ignoreAt( const string &db, const Timestamp ¤tOplogTime ) { if ( _ignores[ db ].isNull() ) { return false; } @@ -541,7 +542,7 @@ namespace repl { return true; } BSONElement ts = op.getField( "ts" ); - if ( ( ts.type() == Date || ts.type() == Timestamp ) && ___databaseIgnorer.ignoreAt( db, ts.date() ) ) { + if ( ( ts.type() == Date || ts.type() == bsonTimestamp ) && ___databaseIgnorer.ignoreAt( db, ts.date() ) ) { // Database is ignored due to a previous indication that it is // missing from master after optime "ts". return false; @@ -551,7 +552,7 @@ namespace repl { return true; } - OpTime lastTime; + Timestamp lastTime; bool dbOk = false; { // This is always a GlobalWrite lock (so no ns/db used from the context) @@ -564,9 +565,10 @@ namespace repl { BSONObj last = oplogReader.findOne( this->ns().c_str(), Query().sort( BSON( "$natural" << -1 ) ) ); if ( !last.isEmpty() ) { - BSONElement ts = last.getField( "ts" ); - massert( 14032, "Invalid 'ts' in remote log", ts.type() == Date || ts.type() == Timestamp ); - lastTime = OpTime( ts.date() ); + BSONElement ts = last.getField( "ts" ); + massert(14032, "Invalid 'ts' in remote log", + ts.type() == Date || ts.type() == bsonTimestamp); + lastTime = Timestamp( ts.date() ); } BSONObj info; @@ -782,8 +784,9 @@ namespace repl { BSONObj last = oplogReader.findOne( _ns.c_str(), Query( b.done() ).sort( BSON( "$natural" << -1 ) ) ); if ( !last.isEmpty() ) { BSONElement ts = last.getField( "ts" ); - massert( 10386 , "non Date ts found: " + last.toString(), ts.type() == Date || ts.type() == Timestamp ); - syncedTo = OpTime( ts.date() ); + massert(10386, "non Date ts found: " + last.toString(), + ts.type() == Date || ts.type() == bsonTimestamp); + syncedTo = Timestamp( ts.date() ); } } @@ -878,7 +881,7 @@ namespace repl { } BSONObjBuilder gte; - gte.appendTimestamp("$gte", syncedTo.asDate()); + gte.append("$gte", syncedTo); BSONObjBuilder query; query.append("ts", gte.done()); if ( !only.empty() ) { @@ -931,11 +934,11 @@ namespace repl { return okResultCode; } - OpTime nextOpTime; + Timestamp nextOpTime; { BSONObj op = oplogReader.next(); BSONElement ts = op.getField("ts"); - if ( ts.type() != Date && ts.type() != Timestamp ) { + if ( ts.type() != Date && ts.type() != bsonTimestamp ) { string err = op.getStringField("$err"); if ( !err.empty() ) { // 13051 is "tailable cursor requested on non capped collection" @@ -954,7 +957,7 @@ namespace repl { } } - nextOpTime = OpTime( ts.date() ); + nextOpTime = Timestamp( ts.date() ); LOG(2) << "first op time received: " << nextOpTime.toString() << '\n'; if ( initial ) { LOG(1) << "initial run\n"; @@ -967,7 +970,7 @@ namespace repl { verify(false); } oplogReader.putBack( op ); // op will be processed in the loop below - nextOpTime = OpTime(); // will reread the op below + nextOpTime = Timestamp(); // will reread the op below } else if ( nextOpTime != syncedTo ) { // didn't get what we queried for - error log() @@ -1033,15 +1036,15 @@ namespace repl { while( 1 ) { BSONElement ts = op.getField("ts"); - if( !( ts.type() == Date || ts.type() == Timestamp ) ) { + if( !( ts.type() == Date || ts.type() == bsonTimestamp ) ) { log() << "sync error: problem querying remote oplog record" << endl; log() << "op: " << op.toString() << endl; log() << "halting replication" << endl; replInfo = replAllDead = "sync error: no ts found querying remote oplog record"; throw SyncException(); } - OpTime last = nextOpTime; - nextOpTime = OpTime( ts.date() ); + Timestamp last = nextOpTime; + nextOpTime = Timestamp( ts.date() ); if ( !( last < nextOpTime ) ) { log() << "sync error: last applied optime at slave >= nextOpTime from master" << endl; log() << " last: " << last.toStringLong() << endl; diff --git a/src/mongo/db/repl/master_slave.h b/src/mongo/db/repl/master_slave.h index 117e26d08a1..4a05efd48b9 100644 --- a/src/mongo/db/repl/master_slave.h +++ b/src/mongo/db/repl/master_slave.h @@ -135,7 +135,7 @@ namespace repl { std::string only; // only a certain db. note that in the sources collection, this may not be changed once you start replicating. /* the last time point we have already synced up to (in the remote/master's oplog). */ - OpTime syncedTo; + Timestamp syncedTo; int nClonedThisPass; @@ -176,19 +176,19 @@ namespace repl { /** * Helper class used to set and query an ignore state for a named database. - * The ignore state will expire after a specified OpTime. + * The ignore state will expire after a specified Timestamp. */ class DatabaseIgnorer { public: /** Indicate that operations for 'db' should be ignored until after 'futureOplogTime' */ - void doIgnoreUntilAfter( const std::string &db, const OpTime &futureOplogTime ); + void doIgnoreUntilAfter( const std::string &db, const Timestamp &futureOplogTime ); /** * Query ignore state of 'db'; if 'currentOplogTime' is after the ignore * limit, the ignore state will be cleared. */ - bool ignoreAt( const std::string &db, const OpTime ¤tOplogTime ); + bool ignoreAt( const std::string &db, const Timestamp ¤tOplogTime ); private: - std::map< std::string, OpTime > _ignores; + std::map< std::string, Timestamp > _ignores; }; } // namespace repl diff --git a/src/mongo/db/repl/member_heartbeat_data.cpp b/src/mongo/db/repl/member_heartbeat_data.cpp index 8ca22c40649..5ae8f1fbffc 100644 --- a/src/mongo/db/repl/member_heartbeat_data.cpp +++ b/src/mongo/db/repl/member_heartbeat_data.cpp @@ -47,8 +47,8 @@ namespace repl { _authIssue(false) { _lastResponse.setState(MemberState::RS_UNKNOWN); - _lastResponse.setElectionTime(OpTime()); - _lastResponse.setOpTime(OpTime()); + _lastResponse.setElectionTime(Timestamp()); + _lastResponse.setOpTime(Timestamp()); } void MemberHeartbeatData::setUpValues(Date_t now, @@ -88,8 +88,8 @@ namespace repl { _lastResponse = ReplSetHeartbeatResponse(); _lastResponse.setState(MemberState::RS_DOWN); - _lastResponse.setElectionTime(OpTime()); - _lastResponse.setOpTime(OpTime()); + _lastResponse.setElectionTime(Timestamp()); + _lastResponse.setOpTime(Timestamp()); _lastResponse.setHbMsg(heartbeatMessage); _lastResponse.setSyncingTo(""); } @@ -102,8 +102,8 @@ namespace repl { _lastResponse = ReplSetHeartbeatResponse(); _lastResponse.setState(MemberState::RS_UNKNOWN); - _lastResponse.setElectionTime(OpTime()); - _lastResponse.setOpTime(OpTime()); + _lastResponse.setElectionTime(Timestamp()); + _lastResponse.setOpTime(Timestamp()); _lastResponse.setHbMsg(""); _lastResponse.setSyncingTo(""); } diff --git a/src/mongo/db/repl/member_heartbeat_data.h b/src/mongo/db/repl/member_heartbeat_data.h index 624c572d33f..b54c3e539d8 100644 --- a/src/mongo/db/repl/member_heartbeat_data.h +++ b/src/mongo/db/repl/member_heartbeat_data.h @@ -28,7 +28,7 @@ #pragma once -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/repl/member_state.h" #include "mongo/db/repl/repl_set_heartbeat_response.h" #include "mongo/util/time_support.h" @@ -54,11 +54,11 @@ namespace repl { } const std::string& getLastHeartbeatMsg() const { return _lastResponse.getHbMsg(); } const std::string& getSyncSource() const { return _lastResponse.getSyncingTo(); } - OpTime getOpTime() const { return _lastResponse.getOpTime(); } + Timestamp getOpTime() const { return _lastResponse.getOpTime(); } int getConfigVersion() const { return _lastResponse.getVersion(); } bool hasAuthIssue() const { return _authIssue; } - OpTime getElectionTime() const { return _lastResponse.getElectionTime(); } + Timestamp getElectionTime() const { return _lastResponse.getElectionTime(); } // Returns true if the last heartbeat data explicilty stated that the node // is not electable. diff --git a/src/mongo/db/repl/minvalid.cpp b/src/mongo/db/repl/minvalid.cpp index 5553747147a..c648dcd5fa7 100644 --- a/src/mongo/db/repl/minvalid.cpp +++ b/src/mongo/db/repl/minvalid.cpp @@ -32,7 +32,7 @@ #include "mongo/db/repl/minvalid.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/concurrency/d_concurrency.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/jsobj.h" @@ -63,7 +63,7 @@ namespace { Helpers::putSingleton(txn, minvalidNS, BSON("$set" << initialSyncFlag)); } - void setMinValid(OperationContext* ctx, OpTime ts) { + void setMinValid(OperationContext* ctx, Timestamp ts) { ScopedTransaction transaction(ctx, MODE_IX); Lock::DBLock dblk(ctx->lockState(), "local", MODE_X); Helpers::putSingleton(ctx, minvalidNS, BSON("$set" << BSON("ts" << ts))); @@ -84,16 +84,16 @@ namespace { return false; } - OpTime getMinValid(OperationContext* txn) { + Timestamp getMinValid(OperationContext* txn) { ScopedTransaction transaction(txn, MODE_IS); Lock::DBLock dblk(txn->lockState(), "local", MODE_IS); Lock::CollectionLock lk(txn->lockState(), minvalidNS, MODE_IS); BSONObj mv; bool found = Helpers::getSingleton(txn, minvalidNS, mv); if (found) { - return mv["ts"]._opTime(); + return mv["ts"].timestamp(); } - return OpTime(); + return Timestamp(); } } diff --git a/src/mongo/db/repl/minvalid.h b/src/mongo/db/repl/minvalid.h index 7bbe7c39c69..853c96b6c27 100644 --- a/src/mongo/db/repl/minvalid.h +++ b/src/mongo/db/repl/minvalid.h @@ -31,7 +31,7 @@ namespace mongo { class BSONObj; class OperationContext; - class OpTime; + class Timestamp; namespace repl { @@ -57,11 +57,11 @@ namespace repl { bool getInitialSyncFlag(); /** - * The minValid optime value is the earliest (minimum) OpTime that must be applied in order to + * The minValid value is the earliest (minimum) Timestamp that must be applied in order to * consider the dataset consistent. Do not allow client reads if our last applied operation is * before the minValid time. */ - void setMinValid(OperationContext* ctx, OpTime ts); - OpTime getMinValid(OperationContext* txn); + void setMinValid(OperationContext* ctx, Timestamp ts); + Timestamp getMinValid(OperationContext* txn); } } diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp index ae387139c9a..7c90e58c8a5 100644 --- a/src/mongo/db/repl/oplog.cpp +++ b/src/mongo/db/repl/oplog.cpp @@ -52,7 +52,7 @@ #include "mongo/db/dbdirectclient.h" #include "mongo/db/dbhelpers.h" #include "mongo/db/service_context.h" -#include "mongo/db/global_optime.h" +#include "mongo/db/global_timestamp.h" #include "mongo/db/index_builder.h" #include "mongo/db/namespace_string.h" #include "mongo/db/op_observer.h" @@ -91,7 +91,7 @@ namespace { Database* _localDB = nullptr; Collection* _localOplogCollection = nullptr; - // Synchronizes the section where a new OpTime is generated and when it actually + // Synchronizes the section where a new Timestamp is generated and when it actually // appears in the oplog. mongo::mutex newOpMutex; boost::condition newOptimeNotifier; @@ -115,13 +115,13 @@ namespace { * function registers the new optime with the storage system and the replication coordinator, * and provides no facility to revert those registrations on rollback. */ - std::pair<OpTime, long long> getNextOpTime(OperationContext* txn, + std::pair<Timestamp, long long> getNextOpTime(OperationContext* txn, Collection* oplog, const char* ns, ReplicationCoordinator* replCoord, const char* opstr) { boost::lock_guard<boost::mutex> lk(newOpMutex); - OpTime ts = getNextGlobalOptime(); + Timestamp ts = getNextGlobalTimestamp(); newOptimeNotifier.notify_all(); fassert(28560, oplog->getRecordStore()->oplogDiskLocRegister(txn, ts)); @@ -151,7 +151,7 @@ namespace { } replCoord->setMyLastOptime(ts); - return std::pair<OpTime,long long>(ts, hashNew); + return std::pair<Timestamp,long long>(ts, hashNew); } /** @@ -259,7 +259,7 @@ namespace { _localOplogCollection); } - std::pair<OpTime, long long> slot = getNextOpTime(txn, + std::pair<Timestamp, long long> slot = getNextOpTime(txn, _localOplogCollection, ns, replCoord, @@ -270,7 +270,7 @@ namespace { */ BSONObjBuilder b(256); - b.appendTimestamp("ts", slot.first.asDate()); + b.append("ts", slot.first); b.append("h", slot.second); b.append("v", OPLOG_VERSION); b.append("op", opstr); @@ -296,9 +296,9 @@ namespace { ReplClientInfo::forClient(txn->getClient()).setLastOp( slot.first ); } - OpTime writeOpsToOplog(OperationContext* txn, const std::deque<BSONObj>& ops) { + Timestamp writeOpsToOplog(OperationContext* txn, const std::deque<BSONObj>& ops) { ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator(); - OpTime lastOptime = replCoord->getMyLastOptime(); + Timestamp lastOptime = replCoord->getMyLastOptime(); invariant(!ops.empty()); MONGO_WRITE_CONFLICT_RETRY_LOOP_BEGIN { @@ -323,7 +323,7 @@ namespace { it != ops.end(); ++it) { const BSONObj& op = *it; - const OpTime ts = op["ts"]._opTime(); + const Timestamp ts = op["ts"].timestamp(); checkOplogInsert(_localOplogCollection->insertDocument(txn, op, false)); @@ -669,19 +669,19 @@ namespace { return Status::OK(); } - void waitUpToOneSecondForOptimeChange(const OpTime& referenceTime) { + void waitUpToOneSecondForTimestampChange(const Timestamp& referenceTime) { boost::unique_lock<boost::mutex> lk(newOpMutex); - while (referenceTime == getLastSetOptime()) { + while (referenceTime == getLastSetTimestamp()) { if (!newOptimeNotifier.timed_wait(lk, boost::posix_time::seconds(1))) return; } } - void setNewOptime(const OpTime& newTime) { + void setNewOptime(const Timestamp& newTime) { boost::lock_guard<boost::mutex> lk(newOpMutex); - setGlobalOptime(newTime); + setGlobalTimestamp(newTime); newOptimeNotifier.notify_all(); } diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h index 49e9175f0d9..f587ae074df 100644 --- a/src/mongo/db/repl/oplog.h +++ b/src/mongo/db/repl/oplog.h @@ -43,7 +43,7 @@ namespace mongo { class Database; class NamespaceString; class OperationContext; - class OpTime; + class Timestamp; class RecordId; namespace repl { @@ -58,7 +58,7 @@ namespace repl { // used internally by replication secondaries after they have applied ops. Updates the global // optime. // Returns the optime for the last op inserted. - OpTime writeOpsToOplog(OperationContext* txn, + Timestamp writeOpsToOplog(OperationContext* txn, const std::deque<BSONObj>& ops); extern std::string rsOplogName; @@ -104,9 +104,9 @@ namespace repl { bool convertUpdateToUpsert = false); /** - * Waits one second for the OpTime from the oplog to change. + * Waits one second for the Timestamp from the oplog to change. */ - void waitUpToOneSecondForOptimeChange(const OpTime& referenceTime); + void waitUpToOneSecondForTimestampChange(const Timestamp& referenceTime); /** * Initializes the global OpTime with the value from the timestamp of the last oplog entry. @@ -116,7 +116,7 @@ namespace repl { /** * Sets the global OpTime to be 'newTime'. */ - void setNewOptime(const OpTime& newTime); + void setNewOptime(const Timestamp& newTime); /** * Detects the current replication mode and sets the "_oplogCollectionName" accordingly. diff --git a/src/mongo/db/repl/oplogreader.cpp b/src/mongo/db/repl/oplogreader.cpp index 9746d975fda..0301cbb0311 100644 --- a/src/mongo/db/repl/oplogreader.cpp +++ b/src/mongo/db/repl/oplogreader.cpp @@ -130,9 +130,9 @@ namespace repl { cursor.reset( _conn->query( ns, query, 0, 0, fields, _tailingQueryOptions ).release() ); } - void OplogReader::tailingQueryGTE(const char *ns, OpTime optime, const BSONObj* fields ) { + void OplogReader::tailingQueryGTE(const char *ns, Timestamp optime, const BSONObj* fields ) { BSONObjBuilder gte; - gte.appendTimestamp("$gte", optime.asDate()); + gte.append("$gte", optime); BSONObjBuilder query; query.append("ts", gte.done()); tailingQuery(ns, query.done(), fields); @@ -143,10 +143,10 @@ namespace repl { } void OplogReader::connectToSyncSource(OperationContext* txn, - OpTime lastOpTimeFetched, + Timestamp lastOpTimeFetched, ReplicationCoordinator* replCoord) { - const OpTime sentinel(Milliseconds(curTimeMillis64()).total_seconds(), 0); - OpTime oldestOpTimeSeen = sentinel; + const Timestamp sentinel(Milliseconds(curTimeMillis64()).total_seconds(), 0); + Timestamp oldestOpTimeSeen = sentinel; invariant(conn() == NULL); @@ -190,7 +190,7 @@ namespace repl { // fetched op. Otherwise, we have fallen off the back of that source's oplog. BSONObj remoteOldestOp(findOne(rsOplogName.c_str(), Query())); BSONElement tsElem(remoteOldestOp["ts"]); - if (tsElem.type() != Timestamp) { + if (tsElem.type() != bsonTimestamp) { // This member's got a bad op in its oplog. warning() << "oplog invalid format on node " << candidate.toString(); resetConnection(); @@ -198,7 +198,7 @@ namespace repl { Date_t(curTimeMillis64() + 600*1000)); continue; } - OpTime remoteOldOpTime = tsElem._opTime(); + Timestamp remoteOldOpTime = tsElem.timestamp(); if (lastOpTimeFetched < remoteOldOpTime) { // We're too stale to use this sync source. diff --git a/src/mongo/db/repl/oplogreader.h b/src/mongo/db/repl/oplogreader.h index d8639ee8530..bf089450535 100644 --- a/src/mongo/db/repl/oplogreader.h +++ b/src/mongo/db/repl/oplogreader.h @@ -99,10 +99,10 @@ namespace repl { void tailingQuery(const char *ns, const BSONObj& query, const BSONObj* fields=0); - void tailingQueryGTE(const char *ns, OpTime t, const BSONObj* fields=0); + void tailingQueryGTE(const char *ns, Timestamp t, const BSONObj* fields=0); /* Do a tailing query, but only send the ts field back. */ - void ghostQueryGTE(const char *ns, OpTime t) { + void ghostQueryGTE(const char *ns, Timestamp t) { const BSONObj fields = BSON("ts" << 1 << "_id" << 0); return tailingQueryGTE(ns, t, &fields); } @@ -146,7 +146,7 @@ namespace repl { * This function may throw DB exceptions. */ void connectToSyncSource(OperationContext* txn, - OpTime lastOpTimeFetched, + Timestamp lastOpTimeFetched, ReplicationCoordinator* replCoord); }; diff --git a/src/mongo/db/repl/optime.h b/src/mongo/db/repl/optime.h new file mode 100644 index 00000000000..4ceee222475 --- /dev/null +++ b/src/mongo/db/repl/optime.h @@ -0,0 +1,83 @@ +/** +* Copyright (C) 2015 MongoDB Inc. +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU Affero General Public License, version 3, +* as published by the Free Software Foundation. +* +* 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 +* GNU Affero General Public License for more details. +* +* You should have received a copy of the GNU Affero General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* 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 GNU Affero General 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. +*/ + +#pragma once + +#include <tuple> +#include <utility> + +#include "mongo/bson/timestamp.h" + +namespace mongo { +namespace repl { + + class OpTime { + public: + OpTime() = default; + OpTime(Timestamp ts, long long term) : _timestamp(std::move(ts)), _term(term) {} + + Timestamp getTimestamp() const { + return _timestamp; + } + + long long getTerm() const { + return _term; + } + + private: + Timestamp _timestamp; + long long _term = -1; + }; + + inline bool operator==(const OpTime& lhs, const OpTime& rhs) { + return std::tie(lhs.opTime, lhs.term) == std::tie(rhs.opTime, rhs.term); + } + + inline bool operator<(const OpTime& lhs, const OpTime& rhs) { + // Compare term first, then the opTimes. + return std::tie(lhs.term, lhs.opTime) < std::tie(rhs.term, rhs.opTime); + } + + inline bool operator!=(const OpTime& lhs, const OpTime& rhs) { + return !(lhs == rhs); + } + + inline bool operator<=(const OpTime& lhs, const OpTime& rhs) { + return lhs < rhs || lhs == rhs; + } + + inline bool operator>(const OpTime& lhs, const OpTime& rhs) { + return !(lhs <= rhs); + } + + inline bool operator>=(const OpTime& lhs, const OpTime& rhs) { + return !(lhs < rhs); + } + +} // namespace repl +} // namespace mongo diff --git a/src/mongo/db/repl/repl_client_info.h b/src/mongo/db/repl/repl_client_info.h index 3aa0c73b66f..d7a748f8641 100644 --- a/src/mongo/db/repl/repl_client_info.h +++ b/src/mongo/db/repl/repl_client_info.h @@ -29,7 +29,7 @@ #pragma once #include "mongo/bson/oid.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/client.h" namespace mongo { @@ -43,15 +43,15 @@ namespace repl { public: static const Client::Decoration<ReplClientInfo> forClient; - void setLastOp(OpTime op) { _lastOp = op; } - OpTime getLastOp() const { return _lastOp; } + void setLastOp(Timestamp op) { _lastOp = op; } + Timestamp getLastOp() const { return _lastOp; } // Only used for master/slave void setRemoteID(OID rid) { _remoteId = rid; } OID getRemoteID() const { return _remoteId; } private: - OpTime _lastOp = OpTime(); + Timestamp _lastOp = Timestamp(); OID _remoteId = OID(); }; diff --git a/src/mongo/db/repl/repl_set_heartbeat_response.cpp b/src/mongo/db/repl/repl_set_heartbeat_response.cpp index 4e968ef0175..8dac175ddf9 100644 --- a/src/mongo/db/repl/repl_set_heartbeat_response.cpp +++ b/src/mongo/db/repl/repl_set_heartbeat_response.cpp @@ -90,13 +90,13 @@ namespace { builder->append(kOkFieldName, 1.0); if (_opTimeSet) { - builder->appendDate(kOpTimeFieldName, _opTime.asDate()); + builder->appendDate(kOpTimeFieldName, _opTime.asULL()); } if (_timeSet) { *builder << kTimeFieldName << _time.total_seconds(); } if (_electionTimeSet) { - builder->appendDate(kElectionTimeFieldName, _electionTime.asDate()); + builder->appendDate(kElectionTimeFieldName, _electionTime.asULL()); } if (_configSet) { *builder << kConfigFieldName << _config.toBSON(); @@ -178,13 +178,13 @@ namespace { if (electionTimeElement.eoo()) { _electionTimeSet = false; } - else if (electionTimeElement.type() == Timestamp) { + else if (electionTimeElement.type() == bsonTimestamp) { _electionTimeSet = true; - _electionTime = electionTimeElement._opTime(); + _electionTime = electionTimeElement.timestamp(); } else if (electionTimeElement.type() == Date) { _electionTimeSet = true; - _electionTime = OpTime(electionTimeElement.date()); + _electionTime = Timestamp(electionTimeElement.date()); } else { return Status(ErrorCodes::TypeMismatch, str::stream() << "Expected \"" << @@ -212,13 +212,13 @@ namespace { if (opTimeElement.eoo()) { _opTimeSet = false; } - else if (opTimeElement.type() == Timestamp) { + else if (opTimeElement.type() == bsonTimestamp) { _opTimeSet = true; - _opTime = opTimeElement._opTime(); + _opTime = opTimeElement.timestamp(); } else if (opTimeElement.type() == Date) { _opTimeSet = true; - _opTime = OpTime(opTimeElement.date()); + _opTime = Timestamp(opTimeElement.date()); } else { return Status(ErrorCodes::TypeMismatch, str::stream() << "Expected \"" << @@ -329,7 +329,7 @@ namespace { return _state; } - OpTime ReplSetHeartbeatResponse::getElectionTime() const { + Timestamp ReplSetHeartbeatResponse::getElectionTime() const { invariant(_electionTimeSet); return _electionTime; } @@ -344,7 +344,7 @@ namespace { return _time; } - OpTime ReplSetHeartbeatResponse::getOpTime() const { + Timestamp ReplSetHeartbeatResponse::getOpTime() const { invariant(_opTimeSet); return _opTime; } diff --git a/src/mongo/db/repl/repl_set_heartbeat_response.h b/src/mongo/db/repl/repl_set_heartbeat_response.h index a5629fbc3bf..94692d7f27c 100644 --- a/src/mongo/db/repl/repl_set_heartbeat_response.h +++ b/src/mongo/db/repl/repl_set_heartbeat_response.h @@ -78,14 +78,14 @@ namespace repl { bool hasState() const { return _stateSet; } MemberState getState() const; bool hasElectionTime() const { return _electionTimeSet; } - OpTime getElectionTime() const; + Timestamp getElectionTime() const; bool hasIsElectable() const { return _electableSet; } bool isElectable() const; const std::string& getHbMsg() const { return _hbmsg; } bool hasTime() const { return _timeSet; } Seconds getTime() const; bool hasOpTime() const { return _opTimeSet; } - OpTime getOpTime() const; + Timestamp getOpTime() const; const std::string& getSyncingTo() const { return _syncingTo; } int getVersion() const { return _version; } bool hasConfig() const { return _configSet; } @@ -122,9 +122,9 @@ namespace repl { void setState(MemberState state) { _stateSet = true; _state = state; } /** - * Sets the optional "electionTime" field to the given OpTime. + * Sets the optional "electionTime" field to the given Timestamp. */ - void setElectionTime(OpTime time) { _electionTimeSet = true; _electionTime = time; } + void setElectionTime(Timestamp time) { _electionTimeSet = true; _electionTime = time; } /** * Sets _electable to "electable" and sets _electableSet to true to indicate @@ -147,7 +147,7 @@ namespace repl { * Sets _opTime to "time" and sets _opTimeSet to true to indicate that the value * of _opTime has been modified. */ - void setOpTime(OpTime time) { _opTimeSet = true; _opTime = time; } + void setOpTime(Timestamp time) { _opTimeSet = true; _opTime = time; } /** * Sets _syncingTo to "syncingTo". @@ -166,13 +166,13 @@ namespace repl { private: bool _electionTimeSet; - OpTime _electionTime; + Timestamp _electionTime; bool _timeSet; Seconds _time; // Seconds since UNIX epoch. bool _opTimeSet; - OpTime _opTime; + Timestamp _opTime; bool _electableSet; bool _electable; diff --git a/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp b/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp index 71003ab4fec..05e634fbc03 100644 --- a/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp +++ b/src/mongo/db/repl/repl_set_heartbeat_response_test.cpp @@ -124,7 +124,7 @@ namespace { ASSERT_EQUALS(hbResponseObj.toString(), hbResponseObjRoundTripChecker.toBSON().toString()); // set electionTime - hbResponse.setElectionTime(OpTime(10,0)); + hbResponse.setElectionTime(Timestamp(10,0)); ++fieldsSet; ASSERT_EQUALS(false, hbResponse.hasState()); ASSERT_EQUALS(true, hbResponse.hasElectionTime()); @@ -139,14 +139,14 @@ namespace { ASSERT_EQUALS("", hbResponse.getHbMsg()); ASSERT_EQUALS("", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); hbResponseObj = hbResponse.toBSON(); ASSERT_EQUALS(fieldsSet, hbResponseObj.nFields()); ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj); ASSERT_EQUALS(Status::OK(), initializeResult); @@ -168,16 +168,16 @@ namespace { ASSERT_EQUALS("", hbResponse.getHbMsg()); ASSERT_EQUALS("", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); hbResponseObj = hbResponse.toBSON(); ASSERT_EQUALS(fieldsSet, hbResponseObj.nFields()); ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponseObj["opTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); + ASSERT_EQUALS(Timestamp(0,10), hbResponseObj["opTime"].timestamp()); initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj); ASSERT_EQUALS(Status::OK(), initializeResult); @@ -199,8 +199,8 @@ namespace { ASSERT_EQUALS("", hbResponse.getHbMsg()); ASSERT_EQUALS("", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); ASSERT_EQUALS(10, hbResponse.getTime().total_seconds()); hbResponseObj = hbResponse.toBSON(); @@ -208,8 +208,8 @@ namespace { ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponseObj["opTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); + ASSERT_EQUALS(Timestamp(0,10), hbResponseObj["opTime"].timestamp()); ASSERT_EQUALS(10, hbResponseObj["time"].numberLong()); initializeResult = hbResponseObjRoundTripChecker.initialize(hbResponseObj); @@ -232,8 +232,8 @@ namespace { ASSERT_EQUALS("", hbResponse.getHbMsg()); ASSERT_EQUALS("", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); ASSERT_EQUALS(10, hbResponse.getTime().total_seconds()); ASSERT_EQUALS(true, hbResponse.isElectable()); @@ -242,8 +242,8 @@ namespace { ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponseObj["opTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); + ASSERT_EQUALS(Timestamp(0,10), hbResponseObj["opTime"].timestamp()); ASSERT_EQUALS(10, hbResponseObj["time"].numberLong()); ASSERT_EQUALS(true, hbResponseObj["e"].trueValue()); @@ -268,8 +268,8 @@ namespace { ASSERT_EQUALS("", hbResponse.getHbMsg()); ASSERT_EQUALS("", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); ASSERT_EQUALS(10, hbResponse.getTime().total_seconds()); ASSERT_EQUALS(true, hbResponse.isElectable()); ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString()); @@ -279,8 +279,8 @@ namespace { ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponseObj["opTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); + ASSERT_EQUALS(Timestamp(0,10), hbResponseObj["opTime"].timestamp()); ASSERT_EQUALS(10, hbResponseObj["time"].numberLong()); ASSERT_EQUALS(true, hbResponseObj["e"].trueValue()); ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString()); @@ -307,8 +307,8 @@ namespace { ASSERT_EQUALS("", hbResponse.getHbMsg()); ASSERT_EQUALS("", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); ASSERT_EQUALS(10, hbResponse.getTime().total_seconds()); ASSERT_EQUALS(true, hbResponse.isElectable()); ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString()); @@ -318,8 +318,8 @@ namespace { ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponseObj["opTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); + ASSERT_EQUALS(Timestamp(0,10), hbResponseObj["opTime"].timestamp()); ASSERT_EQUALS(10, hbResponseObj["time"].numberLong()); ASSERT_EQUALS(true, hbResponseObj["e"].trueValue()); ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString()); @@ -347,8 +347,8 @@ namespace { ASSERT_EQUALS("", hbResponse.getHbMsg()); ASSERT_EQUALS("", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); ASSERT_EQUALS(10, hbResponse.getTime().total_seconds()); ASSERT_EQUALS(true, hbResponse.isElectable()); ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString()); @@ -358,8 +358,8 @@ namespace { ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponseObj["opTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); + ASSERT_EQUALS(Timestamp(0,10), hbResponseObj["opTime"].timestamp()); ASSERT_EQUALS(10, hbResponseObj["time"].numberLong()); ASSERT_EQUALS(true, hbResponseObj["e"].trueValue()); ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString()); @@ -389,8 +389,8 @@ namespace { ASSERT_EQUALS("", hbResponse.getHbMsg()); ASSERT_EQUALS("", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); ASSERT_EQUALS(10, hbResponse.getTime().total_seconds()); ASSERT_EQUALS(true, hbResponse.isElectable()); ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString()); @@ -400,8 +400,8 @@ namespace { ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponseObj["opTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); + ASSERT_EQUALS(Timestamp(0,10), hbResponseObj["opTime"].timestamp()); ASSERT_EQUALS(10, hbResponseObj["time"].numberLong()); ASSERT_EQUALS(true, hbResponseObj["e"].trueValue()); ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString()); @@ -432,8 +432,8 @@ namespace { ASSERT_EQUALS("", hbResponse.getHbMsg()); ASSERT_EQUALS("syncTarget", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); ASSERT_EQUALS(10, hbResponse.getTime().total_seconds()); ASSERT_EQUALS(true, hbResponse.isElectable()); ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString()); @@ -443,8 +443,8 @@ namespace { ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponseObj["opTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); + ASSERT_EQUALS(Timestamp(0,10), hbResponseObj["opTime"].timestamp()); ASSERT_EQUALS(10, hbResponseObj["time"].numberLong()); ASSERT_EQUALS(true, hbResponseObj["e"].trueValue()); ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString()); @@ -475,8 +475,8 @@ namespace { ASSERT_EQUALS("lub dub", hbResponse.getHbMsg()); ASSERT_EQUALS("syncTarget", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); ASSERT_EQUALS(10, hbResponse.getTime().total_seconds()); ASSERT_EQUALS(true, hbResponse.isElectable()); ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString()); @@ -486,8 +486,8 @@ namespace { ASSERT_EQUALS("rs0", hbResponseObj["set"].String()); ASSERT_EQUALS("lub dub", hbResponseObj["hbmsg"].String()); ASSERT_EQUALS(1, hbResponseObj["v"].Number()); - ASSERT_EQUALS(OpTime(10,0), hbResponseObj["electionTime"]._opTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponseObj["opTime"]._opTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponseObj["electionTime"].timestamp()); + ASSERT_EQUALS(Timestamp(0,10), hbResponseObj["opTime"].timestamp()); ASSERT_EQUALS(10, hbResponseObj["time"].numberLong()); ASSERT_EQUALS(true, hbResponseObj["e"].trueValue()); ASSERT_EQUALS(config.toBSON().toString(), hbResponseObj["config"].Obj().toString()); @@ -518,8 +518,8 @@ namespace { ASSERT_EQUALS("lub dub", hbResponse.getHbMsg()); ASSERT_EQUALS("syncTarget", hbResponse.getSyncingTo()); ASSERT_EQUALS(1, hbResponse.getVersion()); - ASSERT_EQUALS(OpTime(10,0), hbResponse.getElectionTime()); - ASSERT_EQUALS(OpTime(0,10), hbResponse.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), hbResponse.getElectionTime()); + ASSERT_EQUALS(Timestamp(0,10), hbResponse.getOpTime()); ASSERT_EQUALS(10, hbResponse.getTime().total_seconds()); ASSERT_EQUALS(true, hbResponse.isElectable()); ASSERT_EQUALS(config.toBSON().toString(), hbResponse.getConfig().toBSON().toString()); @@ -724,7 +724,7 @@ namespace { ReplSetHeartbeatResponse hbResp; std::string msg = "still initializing"; Status result = hbResp.initialize(BSON("ok" << 1.0 << - "opTime" << OpTime())); + "opTime" << Timestamp())); ASSERT_EQUALS(ErrorCodes::NoSuchKey, result.code()); ASSERT_TRUE(stringContains(result.reason(), "\"v\"")) << result.reason() << " doesn't contain 'v' field required error msg"; diff --git a/src/mongo/db/repl/replication_coordinator.h b/src/mongo/db/repl/replication_coordinator.h index 06e541ac06e..934ccedb531 100644 --- a/src/mongo/db/repl/replication_coordinator.h +++ b/src/mongo/db/repl/replication_coordinator.h @@ -44,7 +44,7 @@ namespace mongo { class IndexDescriptor; class NamespaceString; class OperationContext; - class OpTime; + class Timestamp; struct WriteConcernOptions; namespace repl { @@ -172,7 +172,7 @@ namespace repl { * ErrorCodes::Interrupted if the operation was killed with killop() */ virtual StatusAndDuration awaitReplication(const OperationContext* txn, - const OpTime& ts, + const Timestamp& ts, const WriteConcernOptions& writeConcern) = 0; /** @@ -246,7 +246,7 @@ namespace repl { * Updates our internal tracking of the last OpTime applied for the given slave * identified by "rid". Only valid to call in master/slave mode */ - virtual Status setLastOptimeForSlave(const OID& rid, const OpTime& ts) = 0; + virtual Status setLastOptimeForSlave(const OID& rid, const Timestamp& ts) = 0; /** * Updates our internal tracking of the last OpTime applied to this node. @@ -256,7 +256,7 @@ namespace repl { * that after calls to resetLastOpTimeFromOplog(), the minimum acceptable value for "ts" is * reset based on the contents of the oplog, and may go backwards due to rollback. */ - virtual void setMyLastOptime(const OpTime& ts) = 0; + virtual void setMyLastOptime(const Timestamp& ts) = 0; /** * Same as above, but used during places we need to zero our last optime. @@ -271,7 +271,7 @@ namespace repl { /** * Returns the last optime recorded by setMyLastOptime. */ - virtual OpTime getMyLastOptime() const = 0; + virtual Timestamp getMyLastOptime() const = 0; /** * Retrieves and returns the current election id, which is a unique id that is local to @@ -443,7 +443,7 @@ namespace repl { HostAndPort who; // host and port of the member that sent the replSetFresh command unsigned id; // replSet id of the member that sent the replSetFresh command int cfgver; // replSet config version that the member who sent the command thinks it has - OpTime opTime; // last optime seen by the member who sent the replSetFresh command + Timestamp opTime; // last optime seen by the member who sent the replSetFresh command }; /* @@ -503,7 +503,7 @@ namespace repl { /** * Returns a vector of members that have applied the operation with OpTime 'op'. */ - virtual std::vector<HostAndPort> getHostsWrittenTo(const OpTime& op) = 0; + virtual std::vector<HostAndPort> getHostsWrittenTo(const Timestamp& op) = 0; /** * Returns a vector of the members other than ourself in the replica set, as specified in @@ -554,7 +554,7 @@ namespace repl { * Committed means a majority of the voting nodes of the config are known to have the * operation in their oplogs. This implies such ops will never be rolled back. */ - virtual OpTime getLastCommittedOpTime() const = 0; + virtual Timestamp getLastCommittedOpTime() const = 0; protected: diff --git a/src/mongo/db/repl/replication_coordinator_external_state.h b/src/mongo/db/repl/replication_coordinator_external_state.h index 7734d119040..07fa9ed921a 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state.h +++ b/src/mongo/db/repl/replication_coordinator_external_state.h @@ -31,7 +31,7 @@ #include <boost/scoped_ptr.hpp> #include "mongo/base/disallow_copying.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/util/time_support.h" namespace mongo { @@ -114,13 +114,13 @@ namespace repl { /** * Sets the global opTime to be 'newTime'. */ - virtual void setGlobalOpTime(const OpTime& newTime) = 0; + virtual void setGlobalTimestamp(const Timestamp& newTime) = 0; /** * Gets the last optime of an operation performed on this host, from stable * storage. */ - virtual StatusWith<OpTime> loadLastOpTime(OperationContext* txn) = 0; + virtual StatusWith<Timestamp> loadLastOpTime(OperationContext* txn) = 0; /** * Returns the HostAndPort of the remote client connected to us that initiated the operation diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp index 824aac77634..6a83bba6d50 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.cpp @@ -186,38 +186,38 @@ namespace { } } - void ReplicationCoordinatorExternalStateImpl::setGlobalOpTime(const OpTime& newTime) { + void ReplicationCoordinatorExternalStateImpl::setGlobalTimestamp(const Timestamp& newTime) { setNewOptime(newTime); } - StatusWith<OpTime> ReplicationCoordinatorExternalStateImpl::loadLastOpTime( + StatusWith<Timestamp> ReplicationCoordinatorExternalStateImpl::loadLastOpTime( OperationContext* txn) { try { BSONObj oplogEntry; if (!Helpers::getLast(txn, rsOplogName.c_str(), oplogEntry)) { - return StatusWith<OpTime>( + return StatusWith<Timestamp>( ErrorCodes::NoMatchingDocument, str::stream() << "Did not find any entries in " << rsOplogName); } BSONElement tsElement = oplogEntry[tsFieldName]; if (tsElement.eoo()) { - return StatusWith<OpTime>( + return StatusWith<Timestamp>( ErrorCodes::NoSuchKey, str::stream() << "Most recent entry in " << rsOplogName << " missing \"" << tsFieldName << "\" field"); } - if (tsElement.type() != Timestamp) { - return StatusWith<OpTime>( + if (tsElement.type() != bsonTimestamp) { + return StatusWith<Timestamp>( ErrorCodes::TypeMismatch, str::stream() << "Expected type of \"" << tsFieldName << "\" in most recent " << rsOplogName << " entry to have type Timestamp, but found " << typeName(tsElement.type())); } - return StatusWith<OpTime>(tsElement._opTime()); + return StatusWith<Timestamp>(tsElement.timestamp()); } catch (const DBException& ex) { - return StatusWith<OpTime>(ex.toStatus()); + return StatusWith<Timestamp>(ex.toStatus()); } } diff --git a/src/mongo/db/repl/replication_coordinator_external_state_impl.h b/src/mongo/db/repl/replication_coordinator_external_state_impl.h index 3d1c7bef733..482b143f629 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_impl.h +++ b/src/mongo/db/repl/replication_coordinator_external_state_impl.h @@ -54,8 +54,8 @@ namespace repl { virtual bool isSelf(const HostAndPort& host); virtual StatusWith<BSONObj> loadLocalConfigDocument(OperationContext* txn); virtual Status storeLocalConfigDocument(OperationContext* txn, const BSONObj& config); - virtual void setGlobalOpTime(const OpTime& newTime); - virtual StatusWith<OpTime> loadLastOpTime(OperationContext* txn); + virtual void setGlobalTimestamp(const Timestamp& newTime); + virtual StatusWith<Timestamp> loadLastOpTime(OperationContext* txn); virtual HostAndPort getClientHostAndPort(const OperationContext* txn); virtual void closeConnections(); virtual void killAllUserOperations(OperationContext* txn); diff --git a/src/mongo/db/repl/replication_coordinator_external_state_mock.cpp b/src/mongo/db/repl/replication_coordinator_external_state_mock.cpp index e308bc2588e..bd4e194c5fc 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_mock.cpp +++ b/src/mongo/db/repl/replication_coordinator_external_state_mock.cpp @@ -108,16 +108,16 @@ namespace repl { _localRsConfigDocument = localConfigDocument; } - void ReplicationCoordinatorExternalStateMock::setGlobalOpTime(const OpTime& newTime) { + void ReplicationCoordinatorExternalStateMock::setGlobalTimestamp(const Timestamp& newTime) { } - StatusWith<OpTime> ReplicationCoordinatorExternalStateMock::loadLastOpTime( + StatusWith<Timestamp> ReplicationCoordinatorExternalStateMock::loadLastOpTime( OperationContext* txn) { return _lastOpTime; } void ReplicationCoordinatorExternalStateMock::setLastOpTime( - const StatusWith<OpTime>& lastApplied) { + const StatusWith<Timestamp>& lastApplied) { _lastOpTime = lastApplied; } diff --git a/src/mongo/db/repl/replication_coordinator_external_state_mock.h b/src/mongo/db/repl/replication_coordinator_external_state_mock.h index 2f86ebc4d77..8f4366b7e17 100644 --- a/src/mongo/db/repl/replication_coordinator_external_state_mock.h +++ b/src/mongo/db/repl/replication_coordinator_external_state_mock.h @@ -28,12 +28,14 @@ #pragma once +#include <boost/thread.hpp> +#include <boost/thread/condition.hpp> #include <vector> #include "mongo/base/disallow_copying.h" #include "mongo/base/status_with.h" #include "mongo/bson/oid.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/jsobj.h" #include "mongo/db/repl/replication_coordinator_external_state.h" #include "mongo/util/net/hostandport.h" @@ -58,8 +60,8 @@ namespace repl { virtual HostAndPort getClientHostAndPort(const OperationContext* txn); virtual StatusWith<BSONObj> loadLocalConfigDocument(OperationContext* txn); virtual Status storeLocalConfigDocument(OperationContext* txn, const BSONObj& config); - virtual void setGlobalOpTime(const OpTime& newTime); - virtual StatusWith<OpTime> loadLastOpTime(OperationContext* txn); + virtual void setGlobalTimestamp(const Timestamp& newTime); + virtual StatusWith<Timestamp> loadLastOpTime(OperationContext* txn); virtual void closeConnections(); virtual void killAllUserOperations(OperationContext* txn); virtual void clearShardingState(); @@ -86,7 +88,7 @@ namespace repl { /** * Sets the return value for subsequent calls to loadLastOpTimeApplied. */ - void setLastOpTime(const StatusWith<OpTime>& lastApplied); + void setLastOpTime(const StatusWith<Timestamp>& lastApplied); /** * Sets the return value for subsequent calls to storeLocalConfigDocument(). @@ -102,7 +104,7 @@ namespace repl { private: StatusWith<BSONObj> _localRsConfigDocument; - StatusWith<OpTime> _lastOpTime; + StatusWith<Timestamp> _lastOpTime; std::vector<HostAndPort> _selfHosts; bool _canAcquireGlobalSharedLock; Status _storeLocalConfigDocumentStatus; diff --git a/src/mongo/db/repl/replication_coordinator_impl.cpp b/src/mongo/db/repl/replication_coordinator_impl.cpp index 3ee5b1227ea..4f9e9514509 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl.cpp @@ -37,7 +37,7 @@ #include "mongo/base/status.h" #include "mongo/db/concurrency/d_concurrency.h" -#include "mongo/db/global_optime.h" +#include "mongo/db/global_timestamp.h" #include "mongo/db/index/index_descriptor.h" #include "mongo/db/operation_context_noop.h" #include "mongo/db/repl/check_quorum_for_config_change.h" @@ -109,7 +109,7 @@ namespace { */ WaiterInfo(std::vector<WaiterInfo*>* _list, unsigned int _opID, - const OpTime* _opTime, + const Timestamp* _opTime, const WriteConcernOptions* _writeConcern, boost::condition_variable* _condVar) : list(_list), master(true), @@ -127,7 +127,7 @@ namespace { std::vector<WaiterInfo*>* list; bool master; // Set to false to indicate that stepDown was called while waiting const unsigned int opID; - const OpTime* opTime; + const Timestamp* opTime; const WriteConcernOptions* writeConcern; boost::condition_variable* condVar; }; @@ -213,7 +213,7 @@ namespace { fassertFailedNoTrace(28545); } - StatusWith<OpTime> lastOpTimeStatus = _externalState->loadLastOpTime(txn); + StatusWith<Timestamp> lastOpTimeStatus = _externalState->loadLastOpTime(txn); // Use a callback here, because _finishLoadLocalConfig calls isself() which requires // that the server's networking layer be up and running and accepting connections, which @@ -230,7 +230,7 @@ namespace { void ReplicationCoordinatorImpl::_finishLoadLocalConfig( const ReplicationExecutor::CallbackData& cbData, const ReplicaSetConfig& localConfig, - const StatusWith<OpTime>& lastOpTimeStatus) { + const StatusWith<Timestamp>& lastOpTimeStatus) { if (!cbData.status.isOK()) { LOG(1) << "Loading local replica set configuration failed due to " << cbData.status; return; @@ -266,7 +266,7 @@ namespace { // Do not check optime, if this node is an arbiter. bool isArbiter = myIndex.getValue() != -1 && localConfig.getMemberAt(myIndex.getValue()).isArbiter(); - OpTime lastOpTime(0, 0); + Timestamp lastOpTime(0, 0); if (!isArbiter) { if (!lastOpTimeStatus.isOK()) { warning() << "Failed to load timestamp of most recently applied operation; " << @@ -282,7 +282,7 @@ namespace { const PostMemberStateUpdateAction action = _setCurrentRSConfig_inlock(localConfig, myIndex.getValue()); _setMyLastOptime_inlock(&lk, lastOpTime, false); - _externalState->setGlobalOpTime(lastOpTime); + _externalState->setGlobalTimestamp(lastOpTime); if (lk.owns_lock()) { lk.unlock(); } @@ -575,7 +575,7 @@ namespace { } void ReplicationCoordinatorImpl::_updateSlaveInfoOptime_inlock(SlaveInfo* slaveInfo, - OpTime ts) { + Timestamp ts) { slaveInfo->opTime = ts; @@ -646,7 +646,7 @@ namespace { } Status ReplicationCoordinatorImpl::setLastOptimeForSlave(const OID& rid, - const OpTime& ts) { + const Timestamp& ts) { boost::unique_lock<boost::mutex> lock(_mutex); massert(28576, "Received an old style replication progress update, which is only used for Master/" @@ -682,18 +682,18 @@ namespace { _replExecutor.wait(cbh.getValue()); } - void ReplicationCoordinatorImpl::setMyLastOptime(const OpTime& ts) { + void ReplicationCoordinatorImpl::setMyLastOptime(const Timestamp& ts) { boost::unique_lock<boost::mutex> lock(_mutex); _setMyLastOptime_inlock(&lock, ts, false); } void ReplicationCoordinatorImpl::resetMyLastOptime() { boost::unique_lock<boost::mutex> lock(_mutex); - _setMyLastOptime_inlock(&lock, OpTime(), true); + _setMyLastOptime_inlock(&lock, Timestamp(), true); } void ReplicationCoordinatorImpl::_setMyLastOptime_inlock( - boost::unique_lock<boost::mutex>* lock, const OpTime& ts, bool isRollbackAllowed) { + boost::unique_lock<boost::mutex>* lock, const Timestamp& ts, bool isRollbackAllowed) { invariant(lock->owns_lock()); SlaveInfo* mySlaveInfo = &_slaveInfo[_getMyIndexInSlaveInfo_inlock()]; invariant(isRollbackAllowed || mySlaveInfo->opTime <= ts); @@ -709,18 +709,18 @@ namespace { _externalState->forwardSlaveProgress(); // Must do this outside _mutex } - OpTime ReplicationCoordinatorImpl::getMyLastOptime() const { + Timestamp ReplicationCoordinatorImpl::getMyLastOptime() const { boost::lock_guard<boost::mutex> lock(_mutex); return _getMyLastOptime_inlock(); } - OpTime ReplicationCoordinatorImpl::_getMyLastOptime_inlock() const { + Timestamp ReplicationCoordinatorImpl::_getMyLastOptime_inlock() const { return _slaveInfo[_getMyIndexInSlaveInfo_inlock()].opTime; } Status ReplicationCoordinatorImpl::setLastOptime_forTest(long long cfgVer, long long memberId, - const OpTime& ts) { + const Timestamp& ts) { boost::lock_guard<boost::mutex> lock(_mutex); invariant(_getReplicationMode_inlock() == modeReplSet); @@ -824,7 +824,7 @@ namespace { } bool ReplicationCoordinatorImpl::_doneWaitingForReplication_inlock( - const OpTime& opTime, const WriteConcernOptions& writeConcern) { + const Timestamp& opTime, const WriteConcernOptions& writeConcern) { Status status = _checkIfWriteConcernCanBeSatisfied_inlock(writeConcern); if (!status.isOK()) { return true; @@ -850,7 +850,7 @@ namespace { } } - bool ReplicationCoordinatorImpl::_haveNumNodesReachedOpTime_inlock(const OpTime& opTime, + bool ReplicationCoordinatorImpl::_haveNumNodesReachedOpTime_inlock(const Timestamp& opTime, int numNodes) { if (_getMyLastOptime_inlock() < opTime) { // Secondaries that are for some reason ahead of us should not allow us to @@ -861,7 +861,7 @@ namespace { for (SlaveInfoVector::iterator it = _slaveInfo.begin(); it != _slaveInfo.end(); ++it) { - const OpTime& slaveTime = it->opTime; + const Timestamp& slaveTime = it->opTime; if (slaveTime >= opTime) { --numNodes; } @@ -874,13 +874,13 @@ namespace { } bool ReplicationCoordinatorImpl::_haveTaggedNodesReachedOpTime_inlock( - const OpTime& opTime, const ReplicaSetTagPattern& tagPattern) { + const Timestamp& opTime, const ReplicaSetTagPattern& tagPattern) { ReplicaSetTagMatch matcher(tagPattern); for (SlaveInfoVector::iterator it = _slaveInfo.begin(); it != _slaveInfo.end(); ++it) { - const OpTime& slaveTime = it->opTime; + const Timestamp& slaveTime = it->opTime; if (slaveTime >= opTime) { // This node has reached the desired optime, now we need to check if it is a part // of the tagPattern. @@ -899,7 +899,7 @@ namespace { ReplicationCoordinator::StatusAndDuration ReplicationCoordinatorImpl::awaitReplication( const OperationContext* txn, - const OpTime& opTime, + const Timestamp& opTime, const WriteConcernOptions& writeConcern) { Timer timer; boost::unique_lock<boost::mutex> lock(_mutex); @@ -924,7 +924,7 @@ namespace { const Timer* timer, boost::unique_lock<boost::mutex>* lock, const OperationContext* txn, - const OpTime& opTime, + const Timestamp& opTime, const WriteConcernOptions& writeConcern) { const Mode replMode = _getReplicationMode_inlock(); @@ -1951,7 +1951,7 @@ namespace { case kActionWinElection: { boost::unique_lock<boost::mutex> lk(_mutex); _electionId = OID::gen(); - _topCoord->processWinElection(_electionId, getNextGlobalOptime()); + _topCoord->processWinElection(_electionId, getNextGlobalTimestamp()); _isWaitingForDrainToComplete = true; const PostMemberStateUpdateAction nextAction = _updateMemberStateFromTopologyCoordinator_inlock(); @@ -2049,7 +2049,7 @@ namespace { invariant(_settings.usingReplSets()); _cancelHeartbeats(); _setConfigState_inlock(kConfigSteady); - OpTime myOptime = _getMyLastOptime_inlock(); // Must get this before changing our config. + Timestamp myOptime = _getMyLastOptime_inlock(); // Must get this before changing our config. _topCoord->updateConfig( newConfig, myIndex, @@ -2146,7 +2146,7 @@ namespace { return self.shouldBuildIndexes(); } - std::vector<HostAndPort> ReplicationCoordinatorImpl::getHostsWrittenTo(const OpTime& op) { + std::vector<HostAndPort> ReplicationCoordinatorImpl::getHostsWrittenTo(const Timestamp& op) { std::vector<HostAndPort> hosts; boost::lock_guard<boost::mutex> lk(_mutex); for (size_t i = 0; i < _slaveInfo.size(); ++i) { @@ -2305,8 +2305,8 @@ namespace { } void ReplicationCoordinatorImpl::resetLastOpTimeFromOplog(OperationContext* txn) { - StatusWith<OpTime> lastOpTimeStatus = _externalState->loadLastOpTime(txn); - OpTime lastOpTime(0, 0); + StatusWith<Timestamp> lastOpTimeStatus = _externalState->loadLastOpTime(txn); + Timestamp lastOpTime(0, 0); if (!lastOpTimeStatus.isOK()) { warning() << "Failed to load timestamp of most recently applied operation; " << lastOpTimeStatus.getStatus(); @@ -2316,7 +2316,7 @@ namespace { } boost::unique_lock<boost::mutex> lk(_mutex); _setMyLastOptime_inlock(&lk, lastOpTime, true); - _externalState->setGlobalOpTime(lastOpTime); + _externalState->setGlobalTimestamp(lastOpTime); } void ReplicationCoordinatorImpl::_shouldChangeSyncSource( @@ -2355,7 +2355,7 @@ namespace { invariant(tagPattern.isOK()); ReplicaSetTagMatch matcher{tagPattern.getValue()}; - std::vector<OpTime> votingNodesOpTimes; + std::vector<Timestamp> votingNodesOpTimes; for (const auto& sI : _slaveInfo) { auto memberConfig = _rsConfig.findMemberByID(sI.memberId); @@ -2375,7 +2375,7 @@ namespace { _lastCommittedOpTime = votingNodesOpTimes[(votingNodesOpTimes.size() - 1) / 2]; } - OpTime ReplicationCoordinatorImpl::getLastCommittedOpTime() const { + Timestamp ReplicationCoordinatorImpl::getLastCommittedOpTime() const { boost::unique_lock<boost::mutex> lk(_mutex); return _lastCommittedOpTime; } diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h index a66043ac23e..970d6c877f1 100644 --- a/src/mongo/db/repl/replication_coordinator_impl.h +++ b/src/mongo/db/repl/replication_coordinator_impl.h @@ -35,7 +35,7 @@ #include <vector> #include "mongo/base/status.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/service_context.h" #include "mongo/db/repl/member_state.h" #include "mongo/db/repl/replica_set_config.h" @@ -110,7 +110,7 @@ namespace repl { virtual ReplicationCoordinator::StatusAndDuration awaitReplication( const OperationContext* txn, - const OpTime& ts, + const Timestamp& ts, const WriteConcernOptions& writeConcern); virtual ReplicationCoordinator::StatusAndDuration awaitReplicationOfLastOpForClient( @@ -135,15 +135,15 @@ namespace repl { virtual bool shouldIgnoreUniqueIndex(const IndexDescriptor* idx); - virtual Status setLastOptimeForSlave(const OID& rid, const OpTime& ts); + virtual Status setLastOptimeForSlave(const OID& rid, const Timestamp& ts); - virtual void setMyLastOptime(const OpTime& ts); + virtual void setMyLastOptime(const Timestamp& ts); virtual void resetMyLastOptime(); virtual void setMyHeartbeatMessage(const std::string& msg); - virtual OpTime getMyLastOptime() const; + virtual Timestamp getMyLastOptime() const; virtual OID getElectionId(); @@ -208,7 +208,7 @@ namespace repl { virtual bool buildsIndexes(); - virtual std::vector<HostAndPort> getHostsWrittenTo(const OpTime& op); + virtual std::vector<HostAndPort> getHostsWrittenTo(const Timestamp& op); virtual std::vector<HostAndPort> getOtherNodesInReplSet() const; @@ -226,7 +226,7 @@ namespace repl { virtual bool shouldChangeSyncSource(const HostAndPort& currentSource); - virtual OpTime getLastCommittedOpTime() const; + virtual Timestamp getLastCommittedOpTime() const; // ================== Test support API =================== @@ -245,7 +245,7 @@ namespace repl { /** * Simple wrapper around _setLastOptime_inlock to make it easier to test. */ - Status setLastOptime_forTest(long long cfgVer, long long memberId, const OpTime& ts); + Status setLastOptime_forTest(long long cfgVer, long long memberId, const Timestamp& ts); private: @@ -296,7 +296,7 @@ namespace repl { // Struct that holds information about nodes in this replication group, mainly used for // tracking replication progress for write concern satisfaction. struct SlaveInfo { - OpTime opTime; // Our last known OpTime that this slave has replicated to. + Timestamp opTime; // Our last known OpTime that this slave has replicated to. HostAndPort hostAndPort; // Client address of the slave. int memberId; // Id of the node in the replica set config, or -1 if we're not a replSet. OID rid; // RID of the node. @@ -331,7 +331,7 @@ namespace repl { * and wakes up any threads waiting for replication that now have their write concern * satisfied. */ - void _updateSlaveInfoOptime_inlock(SlaveInfo* slaveInfo, OpTime ts); + void _updateSlaveInfoOptime_inlock(SlaveInfo* slaveInfo, Timestamp ts); /** * Returns the index into _slaveInfo where data corresponding to ourself is stored. @@ -430,25 +430,25 @@ namespace repl { const Timer* timer, boost::unique_lock<boost::mutex>* lock, const OperationContext* txn, - const OpTime& ts, + const Timestamp& ts, const WriteConcernOptions& writeConcern); /* * Returns true if the given writeConcern is satisfied up to "optime" or is unsatisfiable. */ - bool _doneWaitingForReplication_inlock(const OpTime& opTime, + bool _doneWaitingForReplication_inlock(const Timestamp& opTime, const WriteConcernOptions& writeConcern); /** * Helper for _doneWaitingForReplication_inlock that takes an integer write concern. */ - bool _haveNumNodesReachedOpTime_inlock(const OpTime& opTime, int numNodes); + bool _haveNumNodesReachedOpTime_inlock(const Timestamp& opTime, int numNodes); /** * Helper for _doneWaitingForReplication_inlock that takes a tag pattern representing a * named write concern mode. */ - bool _haveTaggedNodesReachedOpTime_inlock(const OpTime& opTime, + bool _haveTaggedNodesReachedOpTime_inlock(const Timestamp& opTime, const ReplicaSetTagPattern& tagPattern); Status _checkIfWriteConcernCanBeSatisfied_inlock( @@ -479,7 +479,7 @@ namespace repl { int _getMyId_inlock() const; - OpTime _getMyLastOptime_inlock() const; + Timestamp _getMyLastOptime_inlock() const; /** @@ -514,7 +514,7 @@ namespace repl { * "isRollbackAllowed" is true. */ void _setMyLastOptime_inlock(boost::unique_lock<boost::mutex>* lock, - const OpTime& ts, + const Timestamp& ts, bool isRollbackAllowed); /** @@ -541,7 +541,7 @@ namespace repl { * * Updates the optime associated with the member at "memberIndex" in our config. */ - void _updateOpTimeFromHeartbeat_inlock(int memberIndex, OpTime optime); + void _updateOpTimeFromHeartbeat_inlock(int memberIndex, Timestamp optime); /** * Starts a heartbeat for each member in the current config. Called within the executor @@ -591,7 +591,7 @@ namespace repl { */ void _finishLoadLocalConfig(const ReplicationExecutor::CallbackData& cbData, const ReplicaSetConfig& localConfig, - const StatusWith<OpTime>& lastOpTimeStatus); + const StatusWith<Timestamp>& lastOpTimeStatus); /** * Callback that finishes the work of processReplSetInitiate() inside the replication @@ -888,7 +888,7 @@ namespace repl { AtomicUInt32 _canServeNonLocalReads; // (S) // OpTime of the latest committed operation. Matches the concurrency level of _slaveInfo. - OpTime _lastCommittedOpTime; // (M) + Timestamp _lastCommittedOpTime; // (M) }; } // namespace repl diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect.cpp index 57d150b8e48..dffe1e3793f 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_elect.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_elect.cpp @@ -120,9 +120,9 @@ namespace { invariant(_rsConfig.getMemberAt(_selfIndex).isElectable()); - OpTime lastOpTimeApplied(_getMyLastOptime_inlock()); + Timestamp lastOpTimeApplied(_getMyLastOptime_inlock()); - if (lastOpTimeApplied == OpTime()) { + if (lastOpTimeApplied == Timestamp()) { log() << "not trying to elect self, " "do not yet have a complete set of data from any point in time"; return; diff --git a/src/mongo/db/repl/replication_coordinator_impl_elect_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_elect_test.cpp index b7674970363..5ea30666316 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_elect_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_elect_test.cpp @@ -99,7 +99,7 @@ namespace { net->scheduleResponse(noi, net->now(), makeResponseStatus( BSON("ok" << 1 << "fresher" << false << - "opTime" << Date_t(OpTime(0, 0).asDate()) << + "opTime" << Date_t(Timestamp(0, 0).asULL()) << "veto" << false))); } else { @@ -149,7 +149,7 @@ namespace { ASSERT(getReplCoord()->getMemberState().secondary()) << getReplCoord()->getMemberState().toString(); - getReplCoord()->setMyLastOptime(OpTime(10,0)); + getReplCoord()->setMyLastOptime(Timestamp(10,0)); NetworkInterfaceMock* net = getNet(); net->enterNetwork(); @@ -210,7 +210,7 @@ namespace { )); assertStartSuccess(configObj, HostAndPort("node1", 12345)); OperationContextNoop txn; - getReplCoord()->setMyLastOptime(OpTime (100, 1)); + getReplCoord()->setMyLastOptime(Timestamp (100, 1)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); startCapturingLogMessages(); simulateSuccessfulElection(); @@ -231,7 +231,7 @@ namespace { ReplicaSetConfig config = assertMakeRSConfig(configObj); OperationContextNoop txn; - OpTime time1(100, 1); + Timestamp time1(100, 1); getReplCoord()->setMyLastOptime(time1); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -278,7 +278,7 @@ namespace { ReplicaSetConfig config = assertMakeRSConfig(configObj); OperationContextNoop txn; - OpTime time1(100, 1); + Timestamp time1(100, 1); getReplCoord()->setMyLastOptime(time1); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); @@ -326,7 +326,7 @@ namespace { BSON("_id" << 5 << "host" << "node5:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100,0)); + getReplCoord()->setMyLastOptime(Timestamp(100,0)); // set hbreconfig to hang while in progress getExternalState()->setStoreLocalConfigDocumentToHang(true); diff --git a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp index 9ec647d8dee..ab278b5c7b7 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_heartbeat.cpp @@ -126,7 +126,7 @@ namespace { const bool isUnauthorized = (responseStatus.code() == ErrorCodes::Unauthorized) || (responseStatus.code() == ErrorCodes::AuthenticationFailed); const Date_t now = _replExecutor.now(); - const OpTime lastApplied = getMyLastOptime(); // Locks and unlocks _mutex. + const Timestamp lastApplied = getMyLastOptime(); // Locks and unlocks _mutex. Milliseconds networkTime(0); StatusWith<ReplSetHeartbeatResponse> hbStatusResponse(hbResponse); @@ -177,7 +177,7 @@ namespace { } void ReplicationCoordinatorImpl::_updateOpTimeFromHeartbeat_inlock(int targetIndex, - OpTime optime) { + Timestamp optime) { invariant(_selfIndex >= 0); invariant(targetIndex >= 0); diff --git a/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp index 7b1b8f8ff20..f29a830bb6f 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_reconfig_test.cpp @@ -92,7 +92,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); BSONObjBuilder result; @@ -123,7 +123,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); BSONObjBuilder result; @@ -151,7 +151,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); BSONObjBuilder result; @@ -207,7 +207,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); Status status(ErrorCodes::InternalError, "Not Set"); @@ -243,7 +243,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); Status status(ErrorCodes::InternalError, "Not Set"); @@ -281,7 +281,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); Status status(ErrorCodes::InternalError, "Not Set"); @@ -316,7 +316,7 @@ namespace { init(); start(HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); // initiate Status status(ErrorCodes::InternalError, "Not Set"); @@ -354,7 +354,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345"))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); Status status(ErrorCodes::InternalError, "Not Set"); @@ -391,7 +391,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100,0)); + getReplCoord()->setMyLastOptime(Timestamp(100,0)); simulateSuccessfulElection(); ASSERT_TRUE(getReplCoord()->getMemberState().primary()); @@ -443,7 +443,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100,0)); + getReplCoord()->setMyLastOptime(Timestamp(100,0)); simulateSuccessfulElection(); ASSERT_TRUE(getReplCoord()->getMemberState().primary()); @@ -502,7 +502,7 @@ namespace { BSON("_id" << 2 << "host" << "node2:12345") )), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); // fail before forced BSONObjBuilder result; diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index 550ef262f62..d7fcffc6ed6 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -406,7 +406,7 @@ namespace { TEST_F(ReplCoordTest, AwaitReplicationNoReplEnabled) { init(""); OperationContextNoop txn; - OpTime time(100, 1); + Timestamp time(100, 1); WriteConcernOptions writeConcern; writeConcern.wTimeout = WriteConcernOptions::kNoWaiting; @@ -424,7 +424,7 @@ namespace { settings.master = true; init(settings); OperationContextNoop txn; - OpTime time(100, 1); + Timestamp time(100, 1); WriteConcernOptions writeConcern; writeConcern.wTimeout = WriteConcernOptions::kNoWaiting; @@ -449,7 +449,7 @@ namespace { HostAndPort("node1", 12345)); OperationContextNoop txn; - OpTime time(100, 1); + Timestamp time(100, 1); WriteConcernOptions writeConcern; writeConcern.wTimeout = WriteConcernOptions::kNoWaiting; @@ -462,7 +462,7 @@ namespace { ASSERT_EQUALS(ErrorCodes::NotMaster, statusAndDur.status); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); statusAndDur = getReplCoord()->awaitReplication(&txn, time, writeConcern); @@ -480,11 +480,11 @@ namespace { BSON("host" << "node4:12345" << "_id" << 3))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); - OpTime time1(100, 1); - OpTime time2(100, 2); + Timestamp time1(100, 1); + Timestamp time2(100, 2); WriteConcernOptions writeConcern; writeConcern.wTimeout = WriteConcernOptions::kNoWaiting; @@ -555,11 +555,11 @@ namespace { "multiDCAndRack" << BSON("dc" << 2 << "rack" << 3)))), HostAndPort("node0")); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); - OpTime time1(100, 1); - OpTime time2(100, 2); + Timestamp time1(100, 1); + Timestamp time2(100, 2); // Test invalid write concern WriteConcernOptions invalidWriteConcern; @@ -643,7 +643,7 @@ namespace { _result(ReplicationCoordinator::StatusAndDuration( Status::OK(), ReplicationCoordinator::Milliseconds(0))) {} - void setOpTime(const OpTime& ot) { + void setOpTime(const Timestamp& ot) { _optime = ot; } @@ -681,7 +681,7 @@ namespace { ReplicationCoordinatorImpl* _replCoord; bool _finished; - OpTime _optime; + Timestamp _optime; WriteConcernOptions _writeConcern; ReplicationCoordinator::StatusAndDuration _result; boost::scoped_ptr<boost::thread> _thread; @@ -697,13 +697,13 @@ namespace { BSON("host" << "node3:12345" << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); ReplicationAwaiter awaiter(getReplCoord(), &txn); - OpTime time1(100, 1); - OpTime time2(100, 2); + Timestamp time1(100, 1); + Timestamp time2(100, 2); WriteConcernOptions writeConcern; writeConcern.wTimeout = WriteConcernOptions::kNoTimeout; @@ -748,13 +748,13 @@ namespace { BSON("host" << "node3:12345" << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); ReplicationAwaiter awaiter(getReplCoord(), &txn); - OpTime time1(100, 1); - OpTime time2(100, 2); + Timestamp time1(100, 1); + Timestamp time2(100, 2); WriteConcernOptions writeConcern; writeConcern.wTimeout = 50; @@ -781,13 +781,13 @@ namespace { BSON("host" << "node3:12345" << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); ReplicationAwaiter awaiter(getReplCoord(), &txn); - OpTime time1(100, 1); - OpTime time2(100, 2); + Timestamp time1(100, 1); + Timestamp time2(100, 2); WriteConcernOptions writeConcern; writeConcern.wTimeout = WriteConcernOptions::kNoTimeout; @@ -817,13 +817,13 @@ namespace { BSON("host" << "node3:12345" << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); ReplicationAwaiter awaiter(getReplCoord(), &txn); - OpTime time1(100, 1); - OpTime time2(100, 2); + Timestamp time1(100, 1); + Timestamp time2(100, 2); WriteConcernOptions writeConcern; writeConcern.wTimeout = WriteConcernOptions::kNoTimeout; @@ -893,13 +893,13 @@ namespace { BSON("_id" << 2 << "host" << "node3"))), HostAndPort("node1")); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); ReplicationAwaiter awaiter(getReplCoord(), &txn); - OpTime time1(100, 1); - OpTime time2(100, 2); + Timestamp time1(100, 1); + Timestamp time2(100, 2); WriteConcernOptions writeConcern; writeConcern.wTimeout = WriteConcernOptions::kNoTimeout; @@ -947,7 +947,7 @@ namespace { TEST_F(StepDownTest, StepDownNotPrimary) { OperationContextReplMock txn; - OpTime optime1(100, 1); + Timestamp optime1(100, 1); // All nodes are caught up getReplCoord()->setMyLastOptime(optime1); ASSERT_OK(getReplCoord()->setLastOptime_forTest(1, 1, optime1)); @@ -960,7 +960,7 @@ namespace { TEST_F(StepDownTest, StepDownTimeoutAcquiringGlobalLock) { OperationContextReplMock txn; - OpTime optime1(100, 1); + Timestamp optime1(100, 1); // All nodes are caught up getReplCoord()->setMyLastOptime(optime1); ASSERT_OK(getReplCoord()->setLastOptime_forTest(1, 1, optime1)); @@ -978,7 +978,7 @@ namespace { TEST_F(StepDownTest, StepDownNoWaiting) { OperationContextReplMock txn; - OpTime optime1(100, 1); + Timestamp optime1(100, 1); // All nodes are caught up getReplCoord()->setMyLastOptime(optime1); ASSERT_OK(getReplCoord()->setLastOptime_forTest(1, 1, optime1)); @@ -1114,8 +1114,8 @@ namespace { TEST_F(StepDownTest, StepDownNotCaughtUp) { OperationContextReplMock txn; - OpTime optime1(100, 1); - OpTime optime2(100, 2); + Timestamp optime1(100, 1); + Timestamp optime2(100, 2); // No secondary is caught up getReplCoord()->setMyLastOptime(optime2); ASSERT_OK(getReplCoord()->setLastOptime_forTest(1, 1, optime1)); @@ -1156,8 +1156,8 @@ namespace { TEST_F(StepDownTest, StepDownCatchUp) { OperationContextReplMock txn; - OpTime optime1(100, 1); - OpTime optime2(100, 2); + Timestamp optime1(100, 1); + Timestamp optime2(100, 2); // No secondary is caught up getReplCoord()->setMyLastOptime(optime2); ASSERT_OK(getReplCoord()->setLastOptime_forTest(1, 1, optime1)); @@ -1204,8 +1204,8 @@ namespace { TEST_F(StepDownTest, InterruptStepDown) { OperationContextNoopWithInterrupt txn; - OpTime optime1(100, 1); - OpTime optime2(100, 2); + Timestamp optime1(100, 1); + Timestamp optime2(100, 2); // No secondary is caught up getReplCoord()->setMyLastOptime(optime2); ASSERT_OK(getReplCoord()->setLastOptime_forTest(1, 1, optime1)); @@ -1278,9 +1278,9 @@ namespace { BSON("_id" << 1 << "host" << "test2:1234") << BSON("_id" << 2 << "host" << "test3:1234"))), HostAndPort("test1", 1234)); - OpTime optime1(100, 1); - OpTime optime2(100, 2); - OpTime optime3(2, 1); + Timestamp optime1(100, 1); + Timestamp optime2(100, 2); + Timestamp optime3(2, 1); getReplCoord()->setMyLastOptime(optime1); ASSERT_OK(getReplCoord()->setLastOptime_forTest(1, 1, optime2)); ASSERT_OK(getReplCoord()->setLastOptime_forTest(1, 2, optime3)); @@ -1299,12 +1299,12 @@ namespace { long long memberId = entry["memberId"].Number(); memberIds.insert(memberId); if (memberId == 0) { - ASSERT_EQUALS(optime1, entry["optime"]._opTime()); + ASSERT_EQUALS(optime1, entry["optime"].timestamp()); } else if (memberId == 1) { - ASSERT_EQUALS(optime2, entry["optime"]._opTime()); + ASSERT_EQUALS(optime2, entry["optime"].timestamp()); } else { ASSERT_EQUALS(2, memberId); - ASSERT_EQUALS(optime3, entry["optime"]._opTime()); + ASSERT_EQUALS(optime3, entry["optime"].timestamp()); } } ASSERT_EQUALS(3U, memberIds.size()); // Make sure we saw all 3 nodes @@ -1321,7 +1321,7 @@ namespace { HostAndPort("test2", 1234)); OperationContextNoop txn; getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); // Can't unset maintenance mode if it was never set to begin with. Status status = getReplCoord()->setMaintenanceMode(false); @@ -1404,8 +1404,8 @@ namespace { HostAndPort("node1", 12345)); OperationContextNoop txn; - OpTime time1(100, 1); - OpTime time2(100, 2); + Timestamp time1(100, 1); + Timestamp time2(100, 2); getReplCoord()->setMyLastOptime(time2); ASSERT_OK(getReplCoord()->setLastOptime_forTest(2, 1, time1)); @@ -1434,8 +1434,8 @@ namespace { OperationContextNoop txn; OID client = OID::gen(); - OpTime time1(100, 1); - OpTime time2(100, 2); + Timestamp time1(100, 1); + Timestamp time2(100, 2); getExternalState()->setClientHostAndPort(clientHost); HandshakeArgs handshake; @@ -1579,12 +1579,12 @@ namespace { BSON("host" << "node3:12345" << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 0)); + getReplCoord()->setMyLastOptime(Timestamp(100, 0)); simulateSuccessfulElection(); - OpTime time1(100, 1); - OpTime time2(100, 2); - OpTime staleTime(10, 0); + Timestamp time1(100, 1); + Timestamp time2(100, 2); + Timestamp staleTime(10, 0); getReplCoord()->setMyLastOptime(time1); WriteConcernOptions writeConcern; @@ -1678,10 +1678,10 @@ namespace { BSON("host" << "node3:12345" << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 2)); + getReplCoord()->setMyLastOptime(Timestamp(100, 2)); simulateSuccessfulElection(); - OpTime time(100, 2); + Timestamp time(100, 2); // 3 nodes waiting for time WriteConcernOptions writeConcern; @@ -1748,10 +1748,10 @@ namespace { BSON("host" << "node3:12345" << "_id" << 2))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 2)); + getReplCoord()->setMyLastOptime(Timestamp(100, 2)); simulateSuccessfulElection(); - OpTime time(100, 2); + Timestamp time(100, 2); // 3 nodes waiting for time WriteConcernOptions writeConcern; @@ -1805,10 +1805,10 @@ namespace { BSON("host" << "node5:12345" << "_id" << 4))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - getReplCoord()->setMyLastOptime(OpTime(100, 1)); + getReplCoord()->setMyLastOptime(Timestamp(100, 1)); simulateSuccessfulElection(); - OpTime time(100, 2); + Timestamp time(100, 2); ASSERT_OK(getReplCoord()->setLastOptime_forTest(2, 1, time)); ASSERT_OK(getReplCoord()->setLastOptime_forTest(2, 2, time)); @@ -1878,7 +1878,7 @@ namespace { "arbiterOnly" << true))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - OpTime time(100, 0); + Timestamp time(100, 0); getReplCoord()->setMyLastOptime(time); simulateSuccessfulElection(); @@ -1919,8 +1919,8 @@ namespace { "arbiterOnly" << true))), HostAndPort("node1", 12345)); ASSERT(getReplCoord()->setFollowerMode(MemberState::RS_SECONDARY)); - OpTime zero(0, 0); - OpTime time(100, 0); + Timestamp zero(0, 0); + Timestamp time(100, 0); getReplCoord()->setMyLastOptime(time); simulateSuccessfulElection(); @@ -1935,7 +1935,7 @@ namespace { // Set a new, later OpTime. - OpTime newTime = OpTime(100, 1); + Timestamp newTime = Timestamp(100, 1); getReplCoord()->setMyLastOptime(newTime); ASSERT_OK(getReplCoord()->setLastOptime_forTest(2, 3, newTime)); ASSERT_EQUALS(time, getReplCoord()->getLastCommittedOpTime()); diff --git a/src/mongo/db/repl/replication_coordinator_mock.cpp b/src/mongo/db/repl/replication_coordinator_mock.cpp index e0efd70392e..99bda38afc0 100644 --- a/src/mongo/db/repl/replication_coordinator_mock.cpp +++ b/src/mongo/db/repl/replication_coordinator_mock.cpp @@ -81,7 +81,7 @@ namespace repl { ReplicationCoordinator::StatusAndDuration ReplicationCoordinatorMock::awaitReplication( const OperationContext* txn, - const OpTime& ts, + const Timestamp& ts, const WriteConcernOptions& writeConcern) { // TODO return StatusAndDuration(Status::OK(), Milliseconds(0)); @@ -123,7 +123,7 @@ namespace repl { return false; } - Status ReplicationCoordinatorMock::setLastOptimeForSlave(const OID& rid, const OpTime& ts) { + Status ReplicationCoordinatorMock::setLastOptimeForSlave(const OID& rid, const Timestamp& ts) { return Status::OK(); } @@ -131,13 +131,13 @@ namespace repl { // TODO } - void ReplicationCoordinatorMock::setMyLastOptime(const OpTime& ts) {} + void ReplicationCoordinatorMock::setMyLastOptime(const Timestamp& ts) {} void ReplicationCoordinatorMock::resetMyLastOptime() {} - OpTime ReplicationCoordinatorMock::getMyLastOptime() const { + Timestamp ReplicationCoordinatorMock::getMyLastOptime() const { // TODO - return OpTime(); + return Timestamp(); } @@ -256,7 +256,7 @@ namespace repl { return true; } - std::vector<HostAndPort> ReplicationCoordinatorMock::getHostsWrittenTo(const OpTime& op) { + std::vector<HostAndPort> ReplicationCoordinatorMock::getHostsWrittenTo(const Timestamp& op) { return std::vector<HostAndPort>(); } @@ -295,8 +295,8 @@ namespace repl { invariant(false); } - OpTime ReplicationCoordinatorMock::getLastCommittedOpTime() const { - return OpTime(); + Timestamp ReplicationCoordinatorMock::getLastCommittedOpTime() const { + return Timestamp(); } } // namespace repl diff --git a/src/mongo/db/repl/replication_coordinator_mock.h b/src/mongo/db/repl/replication_coordinator_mock.h index d0a40f1414c..2ec2b344c34 100644 --- a/src/mongo/db/repl/replication_coordinator_mock.h +++ b/src/mongo/db/repl/replication_coordinator_mock.h @@ -66,7 +66,7 @@ namespace repl { virtual ReplicationCoordinator::StatusAndDuration awaitReplication( const OperationContext* txn, - const OpTime& ts, + const Timestamp& ts, const WriteConcernOptions& writeConcern); virtual ReplicationCoordinator::StatusAndDuration awaitReplicationOfLastOpForClient( @@ -91,15 +91,15 @@ namespace repl { virtual bool shouldIgnoreUniqueIndex(const IndexDescriptor* idx); - virtual Status setLastOptimeForSlave(const OID& rid, const OpTime& ts); + virtual Status setLastOptimeForSlave(const OID& rid, const Timestamp& ts); - virtual void setMyLastOptime(const OpTime& ts); + virtual void setMyLastOptime(const Timestamp& ts); virtual void resetMyLastOptime(); virtual void setMyHeartbeatMessage(const std::string& msg); - virtual OpTime getMyLastOptime() const; + virtual Timestamp getMyLastOptime() const; virtual OID getElectionId(); @@ -164,7 +164,7 @@ namespace repl { virtual bool buildsIndexes(); - virtual std::vector<HostAndPort> getHostsWrittenTo(const OpTime& op); + virtual std::vector<HostAndPort> getHostsWrittenTo(const Timestamp& op); virtual std::vector<HostAndPort> getOtherNodesInReplSet() const; @@ -180,7 +180,7 @@ namespace repl { virtual bool shouldChangeSyncSource(const HostAndPort& currentSource); - virtual OpTime getLastCommittedOpTime() const; + virtual Timestamp getLastCommittedOpTime() const; private: const ReplSettings _settings; diff --git a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp index 2479c5d4724..808bffe819c 100644 --- a/src/mongo/db/repl/replication_coordinator_test_fixture.cpp +++ b/src/mongo/db/repl/replication_coordinator_test_fixture.cpp @@ -191,7 +191,7 @@ namespace { net->scheduleResponse(noi, net->now(), makeResponseStatus( BSON("ok" << 1 << "fresher" << false << - "opTime" << Date_t(OpTime(0, 0).asDate()) << + "opTime" << Date_t(Timestamp(0, 0).asULL()) << "veto" << false))); } else if (request.cmdObj.firstElement().fieldNameStringData() == "replSetElect") { diff --git a/src/mongo/db/repl/replication_info.cpp b/src/mongo/db/repl/replication_info.cpp index 8d064089244..dfba98f56aa 100644 --- a/src/mongo/db/repl/replication_info.cpp +++ b/src/mongo/db/repl/replication_info.cpp @@ -186,7 +186,7 @@ namespace repl { uassert(17347, "Problem reading earliest entry from oplog", Helpers::getSingleton(txn, oplogNS.c_str(), o)); - result.append("earliestOptime", o["ts"]._opTime()); + result.append("earliestOptime", o["ts"].timestamp()); return result.obj(); } } oplogInfoServerStatus; diff --git a/src/mongo/db/repl/replset_commands.cpp b/src/mongo/db/repl/replset_commands.cpp index a86ee0e1379..8f090862013 100644 --- a/src/mongo/db/repl/replset_commands.cpp +++ b/src/mongo/db/repl/replset_commands.cpp @@ -729,7 +729,7 @@ namespace { "numeric type, but found " << typeName(cfgverElement.type()), cfgverElement.isNumber()); parsedArgs.cfgver = cfgverElement.safeNumberLong(); - parsedArgs.opTime = OpTime(cmdObj["opTime"].Date()); + parsedArgs.opTime = Timestamp(cmdObj["opTime"].Date()); status = getGlobalReplicationCoordinator()->processReplSetFresh(parsedArgs, &result); return appendCommandStatus(result, status); diff --git a/src/mongo/db/repl/rs_initialsync.cpp b/src/mongo/db/repl/rs_initialsync.cpp index 6fdf3e72190..1380ae190c9 100644 --- a/src/mongo/db/repl/rs_initialsync.cpp +++ b/src/mongo/db/repl/rs_initialsync.cpp @@ -32,7 +32,7 @@ #include "mongo/db/repl/rs_initialsync.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/bson/util/bson_extract.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_manager_global.h" @@ -207,7 +207,7 @@ namespace { bool _initialSyncApplyOplog( OperationContext* ctx, repl::SyncTail& syncer, OplogReader* r) { - const OpTime startOpTime = getGlobalReplicationCoordinator()->getMyLastOptime(); + const Timestamp startOpTime = getGlobalReplicationCoordinator()->getMyLastOptime(); BSONObj lastOp; try { // It may have been a long time since we last used this connection to @@ -234,7 +234,7 @@ namespace { return false; } - OpTime stopOpTime = lastOp["ts"]._opTime(); + Timestamp stopOpTime = lastOp["ts"].timestamp(); // If we already have what we need then return. if (stopOpTime == startOpTime) @@ -333,7 +333,7 @@ namespace { truncateAndResetOplog(&txn, replCoord, bgsync); OplogReader r; - OpTime now(Milliseconds(curTimeMillis64()).total_seconds(), 0); + Timestamp now(Milliseconds(curTimeMillis64()).total_seconds(), 0); while (r.getHost().empty()) { // We must prime the sync source selector so that it considers all candidates regardless @@ -391,7 +391,7 @@ namespace { std::deque<BSONObj> ops; ops.push_back(lastOp); - OpTime lastOptime = writeOpsToOplog(&txn, ops); + Timestamp lastOptime = writeOpsToOplog(&txn, ops); ReplClientInfo::forClient(txn.getClient()).setLastOp(lastOptime); replCoord->setMyLastOptime(lastOptime); setNewOptime(lastOptime); @@ -443,7 +443,7 @@ namespace { { ScopedTransaction scopedXact(&txn, MODE_IX); AutoGetDb autodb(&txn, "local", MODE_X); - OpTime lastOpTimeWritten(getGlobalReplicationCoordinator()->getMyLastOptime()); + Timestamp lastOpTimeWritten(getGlobalReplicationCoordinator()->getMyLastOptime()); log() << "set minValid=" << lastOpTimeWritten; // Initial sync is now complete. Flag this by setting minValid to the last thing diff --git a/src/mongo/db/repl/rs_rollback.cpp b/src/mongo/db/repl/rs_rollback.cpp index 22870e6de7e..0d1f4f79929 100644 --- a/src/mongo/db/repl/rs_rollback.cpp +++ b/src/mongo/db/repl/rs_rollback.cpp @@ -146,7 +146,7 @@ namespace { set<string> collectionsToResync; - OpTime commonPoint; + Timestamp commonPoint; RecordId commonPointOurDiskloc; int rbid; // remote server's current rollback sequence # @@ -286,9 +286,9 @@ namespace { if (oplogCursor.get() == NULL || !oplogCursor->more()) throw RSFatalException("remote oplog empty or unreadable"); - OpTime ourTime = ourObj["ts"]._opTime(); + Timestamp ourTime = ourObj["ts"].timestamp(); BSONObj theirObj = oplogCursor->nextSafe(); - OpTime theirTime = theirObj["ts"]._opTime(); + Timestamp theirTime = theirObj["ts"].timestamp(); long long diff = static_cast<long long>(ourTime.getSecs()) - static_cast<long long>(theirTime.getSecs()); @@ -328,7 +328,7 @@ namespace { throw RSFatalException("RS100 reached beginning of remote oplog [2]"); } theirObj = oplogCursor->nextSafe(); - theirTime = theirObj["ts"]._opTime(); + theirTime = theirObj["ts"].timestamp(); if (PlanExecutor::ADVANCED != exec->getNext(&ourObj, &ourLoc)) { severe() << "rollback error RS101 reached beginning of local oplog"; @@ -337,7 +337,7 @@ namespace { log() << " ourTime: " << ourTime.toStringLong(); throw RSFatalException("RS101 reached beginning of local oplog [1]"); } - ourTime = ourObj["ts"]._opTime(); + ourTime = ourObj["ts"].timestamp(); } else if (theirTime > ourTime) { if (!oplogCursor->more()) { @@ -349,7 +349,7 @@ namespace { throw RSFatalException("RS100 reached beginning of remote oplog [1]"); } theirObj = oplogCursor->nextSafe(); - theirTime = theirObj["ts"]._opTime(); + theirTime = theirObj["ts"].timestamp(); } else { // theirTime < ourTime @@ -361,7 +361,7 @@ namespace { log() << " ourTime: " << ourTime.toStringLong(); throw RSFatalException("RS101 reached beginning of local oplog [2]"); } - ourTime = ourObj["ts"]._opTime(); + ourTime = ourObj["ts"].timestamp(); } } } @@ -449,7 +449,7 @@ namespace { // we have items we are writing that aren't from a point-in-time. thus best not to come // online until we get to that point in freshness. - OpTime minValid = newMinValid["ts"]._opTime(); + Timestamp minValid = newMinValid["ts"].timestamp(); log() << "minvalid=" << minValid.toStringLong(); setMinValid(txn, minValid); @@ -499,7 +499,7 @@ namespace { err = "can't get minvalid from sync source"; } else { - OpTime minValid = newMinValid["ts"]._opTime(); + Timestamp minValid = newMinValid["ts"].timestamp(); log() << "minvalid=" << minValid.toStringLong(); setMinValid(txn, minValid); } @@ -807,13 +807,13 @@ namespace { } // namespace void syncRollback(OperationContext* txn, - OpTime lastOpTimeApplied, + Timestamp lastOpTimeApplied, OplogReader* oplogreader, ReplicationCoordinator* replCoord) { // check that we are at minvalid, otherwise we cannot rollback as we may be in an // inconsistent state { - OpTime minvalid = getMinValid(txn); + Timestamp minvalid = getMinValid(txn); if( minvalid > lastOpTimeApplied ) { severe() << "need to rollback, but in inconsistent state" << endl; log() << "minvalid: " << minvalid.toString() << " our last optime: " diff --git a/src/mongo/db/repl/rs_rollback.h b/src/mongo/db/repl/rs_rollback.h index 8c5644f816a..55f1b887d92 100644 --- a/src/mongo/db/repl/rs_rollback.h +++ b/src/mongo/db/repl/rs_rollback.h @@ -30,7 +30,7 @@ namespace mongo { class OperationContext; - class OpTime; + class Timestamp; namespace repl { class OplogReader; @@ -59,7 +59,7 @@ namespace repl { */ void syncRollback(OperationContext* txn, - OpTime lastOpTimeWritten, + Timestamp lastOpTimeWritten, OplogReader* oplogreader, ReplicationCoordinator* replCoord); diff --git a/src/mongo/db/repl/sync_source_feedback.h b/src/mongo/db/repl/sync_source_feedback.h index 0e3fccccfac..054f6d6b183 100644 --- a/src/mongo/db/repl/sync_source_feedback.h +++ b/src/mongo/db/repl/sync_source_feedback.h @@ -31,7 +31,7 @@ #include <boost/scoped_ptr.hpp> #include <boost/thread/mutex.hpp> -#include <boost/thread/condition_variable.hpp> +#include <boost/thread/condition.hpp> #include "mongo/client/constants.h" #include "mongo/client/dbclientcursor.h" diff --git a/src/mongo/db/repl/sync_tail.cpp b/src/mongo/db/repl/sync_tail.cpp index 7b6349a1738..40f70579704 100644 --- a/src/mongo/db/repl/sync_tail.cpp +++ b/src/mongo/db/repl/sync_tail.cpp @@ -266,7 +266,7 @@ namespace repl { } // Doles out all the work to the writer pool threads and waits for them to complete - OpTime SyncTail::multiApply(OperationContext* txn, std::deque<BSONObj>& ops) { + Timestamp SyncTail::multiApply(OperationContext* txn, std::deque<BSONObj>& ops) { if (getGlobalServiceContext()->getGlobalStorageEngine()->isMmapV1()) { // Use a ThreadPool to prefetch all the operations in a batch. @@ -297,13 +297,13 @@ namespace repl { applyOps(writerVectors); if (inShutdown()) { - return OpTime(); + return Timestamp(); } if (mustAwaitCommit) { txn->recoveryUnit()->goingToAwaitCommit(); } - OpTime lastOpTime = writeOpsToOplog(txn, ops); + Timestamp lastOpTime = writeOpsToOplog(txn, ops); // Wait for journal before setting last op time if any op in batch had j:true if (mustAwaitCommit) { txn->recoveryUnit()->awaitCommit(); @@ -359,12 +359,12 @@ namespace repl { (*writerVectors)[hash % writerVectors->size()].push_back(*it); } } - void SyncTail::oplogApplication(OperationContext* txn, const OpTime& endOpTime) { + void SyncTail::oplogApplication(OperationContext* txn, const Timestamp& endOpTime) { _applyOplogUntil(txn, endOpTime); } /* applies oplog from "now" until endOpTime using the applier threads for initial sync*/ - void SyncTail::_applyOplogUntil(OperationContext* txn, const OpTime& endOpTime) { + void SyncTail::_applyOplogUntil(OperationContext* txn, const Timestamp& endOpTime) { unsigned long long bytesApplied = 0; unsigned long long entriesApplied = 0; while (true) { @@ -376,7 +376,7 @@ namespace repl { // Check if we reached the end const BSONObj currentOp = ops.back(); - const OpTime currentOpTime = currentOp["ts"]._opTime(); + const Timestamp currentOpTime = currentOp["ts"].timestamp(); // When we reach the end return this batch if (currentOpTime == endOpTime) { @@ -406,7 +406,7 @@ namespace repl { bytesApplied += ops.getSize(); entriesApplied += ops.getDeque().size(); - const OpTime lastOpTime = multiApply(txn, ops.getDeque()); + const Timestamp lastOpTime = multiApply(txn, ops.getDeque()); if (inShutdown()) { return; @@ -442,7 +442,7 @@ namespace { return; } - OpTime minvalid = getMinValid(txn); + Timestamp minvalid = getMinValid(txn); if (minvalid > replCoord->getMyLastOptime()) { return; } @@ -495,7 +495,7 @@ namespace { const int slaveDelaySecs = replCoord->getSlaveDelaySecs().total_seconds(); if (!ops.empty() && slaveDelaySecs > 0) { const BSONObj& lastOp = ops.getDeque().back(); - const unsigned int opTimestampSecs = lastOp["ts"]._opTime().getSecs(); + const unsigned int opTimestampSecs = lastOp["ts"].timestamp().getSecs(); // Stop the batch as the lastOp is too new to be applied. If we continue // on, we can get ops that are way ahead of the delay and this will @@ -527,7 +527,7 @@ namespace { // Set minValid to the last op to be applied in this next batch. // This will cause this node to go into RECOVERING state // if we should crash and restart before updating the oplog - OpTime minValid = lastOp["ts"]._opTime(); + Timestamp minValid = lastOp["ts"].timestamp(); setMinValid(&txn, minValid); multiApply(&txn, ops.getDeque()); } @@ -617,7 +617,7 @@ namespace { // ignore slaveDelay if the box is still initializing. once // it becomes secondary we can worry about it. if( slaveDelaySecs > 0 && replCoord->getMemberState().secondary() ) { - const OpTime ts = lastOp["ts"]._opTime(); + const Timestamp ts = lastOp["ts"].timestamp(); long long a = ts.getSecs(); long long b = time(0); long long lag = b - a; diff --git a/src/mongo/db/repl/sync_tail.h b/src/mongo/db/repl/sync_tail.h index 5932634362e..68e5f546845 100644 --- a/src/mongo/db/repl/sync_tail.h +++ b/src/mongo/db/repl/sync_tail.h @@ -57,7 +57,7 @@ namespace repl { /** * Runs _applyOplogUntil(stopOpTime) */ - virtual void oplogApplication(OperationContext* txn, const OpTime& stopOpTime); + virtual void oplogApplication(OperationContext* txn, const Timestamp& stopOpTime); void oplogApplication(); bool peek(BSONObj* obj); @@ -101,14 +101,14 @@ namespace repl { // Prefetch and write a deque of operations, using the supplied function. // Initial Sync and Sync Tail each use a different function. // Returns the last OpTime applied. - OpTime multiApply(OperationContext* txn, std::deque<BSONObj>& ops); + Timestamp multiApply(OperationContext* txn, std::deque<BSONObj>& ops); /** * Applies oplog entries until reaching "endOpTime". * * NOTE:Will not transition or check states */ - void _applyOplogUntil(OperationContext* txn, const OpTime& endOpTime); + void _applyOplogUntil(OperationContext* txn, const Timestamp& endOpTime); private: BackgroundSyncInterface* _networkQueue; diff --git a/src/mongo/db/repl/topology_coordinator.h b/src/mongo/db/repl/topology_coordinator.h index 1da4aa09642..fe8edd37333 100644 --- a/src/mongo/db/repl/topology_coordinator.h +++ b/src/mongo/db/repl/topology_coordinator.h @@ -41,7 +41,7 @@ namespace mongo { class OperationContext; - class OpTime; + class Timestamp; namespace repl { @@ -117,7 +117,7 @@ namespace repl { /** * Chooses and sets a new sync source, based on our current knowledge of the world. */ - virtual HostAndPort chooseNewSyncSource(Date_t now, const OpTime& lastOpApplied) = 0; + virtual HostAndPort chooseNewSyncSource(Date_t now, const Timestamp& lastOpApplied) = 0; /** * Suppresses selecting "host" as sync source until "until". @@ -185,21 +185,21 @@ namespace repl { // produces a reply to a replSetSyncFrom command virtual void prepareSyncFromResponse(const ReplicationExecutor::CallbackData& data, const HostAndPort& target, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, BSONObjBuilder* response, Status* result) = 0; // produce a reply to a replSetFresh command virtual void prepareFreshResponse(const ReplicationCoordinator::ReplSetFreshArgs& args, Date_t now, - OpTime lastOpApplied, + Timestamp lastOpApplied, BSONObjBuilder* response, Status* result) = 0; // produce a reply to a received electCmd virtual void prepareElectResponse(const ReplicationCoordinator::ReplSetElectArgs& args, Date_t now, - OpTime lastOpApplied, + Timestamp lastOpApplied, BSONObjBuilder* response, Status* result) = 0; @@ -207,14 +207,14 @@ namespace repl { virtual Status prepareHeartbeatResponse(Date_t now, const ReplSetHeartbeatArgs& args, const std::string& ourSetName, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, ReplSetHeartbeatResponse* response) = 0; // produce a reply to a status request virtual void prepareStatusResponse(const ReplicationExecutor::CallbackData& data, Date_t now, unsigned uptime, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, BSONObjBuilder* response, Status* result) = 0; @@ -246,7 +246,7 @@ namespace repl { virtual void updateConfig(const ReplicaSetConfig& newConfig, int selfIndex, Date_t now, - OpTime lastOpApplied) = 0; + Timestamp lastOpApplied) = 0; /** * Prepares a heartbeat request appropriate for sending to "target", assuming the @@ -296,7 +296,7 @@ namespace repl { Milliseconds networkRoundTripTime, const HostAndPort& target, const StatusWith<ReplSetHeartbeatResponse>& hbResponse, - OpTime myLastOpApplied) = 0; + Timestamp myLastOpApplied) = 0; /** * If getRole() == Role::candidate and this node has not voted too recently, updates the @@ -312,7 +312,7 @@ namespace repl { * Exactly one of either processWinElection or processLoseElection must be called if * processHeartbeatResponse returns StartElection, to exit candidate mode. */ - virtual void processWinElection(OID electionId, OpTime electionOpTime) = 0; + virtual void processWinElection(OID electionId, Timestamp electionOpTime) = 0; /** * Performs state updates associated with losing an election. @@ -332,7 +332,7 @@ namespace repl { * * Returns whether or not the step down succeeded. */ - virtual bool stepDown(Date_t until, bool force, OpTime lastOpApplied) = 0; + virtual bool stepDown(Date_t until, bool force, Timestamp lastOpApplied) = 0; /** * Sometimes a request to step down comes in (like via a heartbeat), but we don't have the @@ -348,7 +348,7 @@ namespace repl { * Considers whether or not this node should stand for election, and returns true * if the node has transitioned to candidate role as a result of the call. */ - virtual bool checkShouldStandForElection(Date_t now, const OpTime& lastOpApplied) = 0; + virtual bool checkShouldStandForElection(Date_t now, const Timestamp& lastOpApplied) = 0; /** * Set the outgoing heartbeat message from self diff --git a/src/mongo/db/repl/topology_coordinator_impl.cpp b/src/mongo/db/repl/topology_coordinator_impl.cpp index 7e964ef0d8b..1d019eec216 100644 --- a/src/mongo/db/repl/topology_coordinator_impl.cpp +++ b/src/mongo/db/repl/topology_coordinator_impl.cpp @@ -149,7 +149,7 @@ namespace { } HostAndPort TopologyCoordinatorImpl::chooseNewSyncSource(Date_t now, - const OpTime& lastOpApplied) { + const Timestamp& lastOpApplied) { // If we are primary, then we aren't syncing from anyone (else). if (_iAmPrimary()) { return HostAndPort(); @@ -211,23 +211,23 @@ namespace { // Find primary's oplog time. Reject sync candidates that are more than // maxSyncSourceLagSecs seconds behind. - OpTime primaryOpTime; + Timestamp primaryOpTime; if (_currentPrimaryIndex != -1) { primaryOpTime = _hbdata[_currentPrimaryIndex].getOpTime(); } else { // choose a time that will exclude no candidates, since we don't see a primary - primaryOpTime = OpTime(_maxSyncSourceLagSecs.total_seconds(), 0); + primaryOpTime = Timestamp(_maxSyncSourceLagSecs.total_seconds(), 0); } if (primaryOpTime.getSecs() < static_cast<unsigned int>(_maxSyncSourceLagSecs.total_seconds())) { // erh - I think this means there was just a new election // and we don't yet know the new primary's optime - primaryOpTime = OpTime(_maxSyncSourceLagSecs.total_seconds(), 0); + primaryOpTime = Timestamp(_maxSyncSourceLagSecs.total_seconds(), 0); } - OpTime oldestSyncOpTime(primaryOpTime.getSecs() - _maxSyncSourceLagSecs.total_seconds(), 0); + Timestamp oldestSyncOpTime(primaryOpTime.getSecs() - _maxSyncSourceLagSecs.total_seconds(), 0); int closestIndex = -1; @@ -348,7 +348,7 @@ namespace { void TopologyCoordinatorImpl::prepareSyncFromResponse( const ReplicationExecutor::CallbackData& data, const HostAndPort& target, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, BSONObjBuilder* response, Status* result) { if (data.status == ErrorCodes::CallbackCanceled) { @@ -442,7 +442,7 @@ namespace { void TopologyCoordinatorImpl::prepareFreshResponse( const ReplicationCoordinator::ReplSetFreshArgs& args, const Date_t now, - const OpTime lastOpApplied, + const Timestamp lastOpApplied, BSONObjBuilder* response, Status* result) { @@ -478,7 +478,7 @@ namespace { else if (args.opTime < _latestKnownOpTime(lastOpApplied)) { weAreFresher = true; } - response->appendDate("opTime", lastOpApplied.asDate()); + response->appendDate("opTime", lastOpApplied.asULL()); response->append("fresher", weAreFresher); std::string errmsg; @@ -493,7 +493,7 @@ namespace { bool TopologyCoordinatorImpl::_shouldVetoMember( const ReplicationCoordinator::ReplSetFreshArgs& args, const Date_t& now, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, std::string* errmsg) const { if (_rsConfig.getConfigVersion() < args.cfgver) { @@ -564,7 +564,7 @@ namespace { void TopologyCoordinatorImpl::prepareElectResponse( const ReplicationCoordinator::ReplSetElectArgs& args, const Date_t now, - const OpTime lastOpApplied, + const Timestamp lastOpApplied, BSONObjBuilder* response, Status* result) { @@ -648,7 +648,7 @@ namespace { Date_t now, const ReplSetHeartbeatArgs& args, const std::string& ourSetName, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, ReplSetHeartbeatResponse* response) { if (args.getProtocolVersion() != 1) { @@ -802,7 +802,7 @@ namespace { Milliseconds networkRoundTripTime, const HostAndPort& target, const StatusWith<ReplSetHeartbeatResponse>& hbResponse, - OpTime myLastOpApplied) { + Timestamp myLastOpApplied) { const MemberState originalState = getMemberState(); PingStats& hbStats = _pings[target]; @@ -928,7 +928,7 @@ namespace { int updatedConfigIndex, const MemberState& originalState, Date_t now, - const OpTime& lastOpApplied) { + const Timestamp& lastOpApplied) { // This method has two interrelated responsibilities, performed in two phases. // @@ -970,13 +970,13 @@ namespace { _rsConfig.getMemberAt(_currentPrimaryIndex); const MemberConfig& highestPriorityMember = _rsConfig.getMemberAt(highestPriorityIndex); - const OpTime highestPriorityMemberOptime = highestPriorityIndex == _selfIndex ? + const Timestamp highestPriorityMemberOptime = highestPriorityIndex == _selfIndex ? lastOpApplied : _hbdata[highestPriorityIndex].getOpTime(); if ((highestPriorityMember.getPriority() > currentPrimaryMember.getPriority()) && _isOpTimeCloseEnoughToLatestToElect(highestPriorityMemberOptime, lastOpApplied)) { - const OpTime latestOpTime = _latestKnownOpTime(lastOpApplied); + const Timestamp latestOpTime = _latestKnownOpTime(lastOpApplied); if (_iAmPrimary()) { if (_stepDownPending) { @@ -1050,7 +1050,7 @@ namespace { // If we are also primary, this is a problem. Determine who should step down. if (_iAmPrimary()) { - OpTime remoteElectionTime = _hbdata[remotePrimaryIndex].getElectionTime(); + Timestamp remoteElectionTime = _hbdata[remotePrimaryIndex].getElectionTime(); log() << "another primary seen with election time " << remoteElectionTime << " my election time is " << _electionTime; @@ -1122,7 +1122,7 @@ namespace { } bool TopologyCoordinatorImpl::checkShouldStandForElection( - Date_t now, const OpTime& lastOpApplied) { + Date_t now, const Timestamp& lastOpApplied) { if (_currentPrimaryIndex != -1) { return false; } @@ -1170,8 +1170,8 @@ namespace { } bool TopologyCoordinatorImpl::_isOpTimeCloseEnoughToLatestToElect( - const OpTime& otherOpTime, const OpTime& ourLastOpApplied) const { - const OpTime latestKnownOpTime = _latestKnownOpTime(ourLastOpApplied); + const Timestamp& otherOpTime, const Timestamp& ourLastOpApplied) const { + const Timestamp latestKnownOpTime = _latestKnownOpTime(ourLastOpApplied); // Use addition instead of subtraction to avoid overflow. return otherOpTime.getSecs() + 10 >= (latestKnownOpTime.getSecs()); } @@ -1184,8 +1184,8 @@ namespace { return false; } - OpTime TopologyCoordinatorImpl::_latestKnownOpTime(OpTime ourLastOpApplied) const { - OpTime latest = ourLastOpApplied; + Timestamp TopologyCoordinatorImpl::_latestKnownOpTime(Timestamp ourLastOpApplied) const { + Timestamp latest = ourLastOpApplied; for (std::vector<MemberHeartbeatData>::const_iterator it = _hbdata.begin(); it != _hbdata.end(); @@ -1198,7 +1198,7 @@ namespace { continue; } - OpTime optime = it->getOpTime(); + Timestamp optime = it->getOpTime(); if (optime > latest) { latest = optime; @@ -1221,7 +1221,7 @@ namespace { } int TopologyCoordinatorImpl::_getHighestPriorityElectableIndex( - Date_t now, OpTime lastOpApplied) const { + Date_t now, Timestamp lastOpApplied) const { int maxIndex = -1; for (int currentIndex = 0; currentIndex < _rsConfig.getNumMembers(); currentIndex++) { UnelectableReasonMask reason = currentIndex == _selfIndex ? @@ -1236,7 +1236,7 @@ namespace { } void TopologyCoordinatorImpl::changeMemberState_forTest(const MemberState& newMemberState, - OpTime electionTime) { + Timestamp electionTime) { invariant(_selfIndex != -1); if (newMemberState == getMemberState()) return; @@ -1262,7 +1262,7 @@ namespace { ReplicaSetConfig(), -1, Date_t(), - OpTime()); + Timestamp()); break; default: severe() << "Cannot switch to state " << newMemberState; @@ -1287,7 +1287,7 @@ namespace { if (primaryIndex != -1) { ReplSetHeartbeatResponse hbResponse; hbResponse.setState(MemberState::RS_PRIMARY); - hbResponse.setElectionTime(OpTime()); + hbResponse.setElectionTime(Timestamp()); hbResponse.setOpTime(_hbdata[primaryIndex].getOpTime()); hbResponse.setSyncingTo(""); hbResponse.setHbMsg(""); @@ -1311,7 +1311,7 @@ namespace { const ReplicationExecutor::CallbackData& data, Date_t now, unsigned selfUptime, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, BSONObjBuilder* response, Status* result) { if (data.status == ErrorCodes::CallbackCanceled) { @@ -1577,7 +1577,7 @@ namespace { } } - OpTime TopologyCoordinatorImpl::getElectionTime() const { + Timestamp TopologyCoordinatorImpl::getElectionTime() const { return _electionTime; } @@ -1631,7 +1631,7 @@ namespace { void TopologyCoordinatorImpl::updateConfig(const ReplicaSetConfig& newConfig, int selfIndex, Date_t now, - OpTime lastOpApplied) { + Timestamp lastOpApplied) { invariant(_role != Role::candidate); invariant(selfIndex < newConfig.getNumMembers()); @@ -1689,7 +1689,7 @@ namespace { TopologyCoordinatorImpl::UnelectableReasonMask TopologyCoordinatorImpl::_getUnelectableReason( int index, - const OpTime& lastOpApplied) const { + const Timestamp& lastOpApplied) const { invariant(index != _selfIndex); const MemberConfig& memberConfig = _rsConfig.getMemberAt(index); const MemberHeartbeatData& hbData = _hbdata[index]; @@ -1715,7 +1715,7 @@ namespace { TopologyCoordinatorImpl::UnelectableReasonMask TopologyCoordinatorImpl::_getMyUnelectableReason( const Date_t now, - const OpTime lastApplied) const { + const Timestamp lastApplied) const { UnelectableReasonMask result = None; if (lastApplied.isNull()) { @@ -1838,7 +1838,7 @@ namespace { return _pings[host].getMillis(); } - void TopologyCoordinatorImpl::_setElectionTime(const OpTime& newElectionTime) { + void TopologyCoordinatorImpl::_setElectionTime(const Timestamp& newElectionTime) { _electionTime = newElectionTime; } @@ -1913,7 +1913,7 @@ namespace { void TopologyCoordinatorImpl::processWinElection( OID electionId, - OpTime electionOpTime) { + Timestamp electionOpTime) { invariant(_role == Role::candidate); _electionTime = electionOpTime; _electionId = electionId; @@ -1926,7 +1926,7 @@ namespace { void TopologyCoordinatorImpl::processLoseElection() { invariant(_role == Role::candidate); const HostAndPort syncSourceAddress = getSyncSourceAddress(); - _electionTime = OpTime(0, 0); + _electionTime = Timestamp(0, 0); _electionId = OID(); _role = Role::follower; @@ -1937,7 +1937,7 @@ namespace { } } - bool TopologyCoordinatorImpl::stepDown(Date_t until, bool force, OpTime lastOpApplied) { + bool TopologyCoordinatorImpl::stepDown(Date_t until, bool force, Timestamp lastOpApplied) { bool canStepDown = force; for (int i = 0; !canStepDown && i < _rsConfig.getNumMembers(); ++i) { if (i == _selfIndex) { @@ -2051,7 +2051,7 @@ namespace { } invariant(currentMemberIndex != _selfIndex); - OpTime currentOpTime = _hbdata[currentMemberIndex].getOpTime(); + Timestamp currentOpTime = _hbdata[currentMemberIndex].getOpTime(); if (currentOpTime.isNull()) { // Haven't received a heartbeat from the sync source yet, so can't tell if we should // change. diff --git a/src/mongo/db/repl/topology_coordinator_impl.h b/src/mongo/db/repl/topology_coordinator_impl.h index 3e9c9a48c18..e8d0d42a46a 100644 --- a/src/mongo/db/repl/topology_coordinator_impl.h +++ b/src/mongo/db/repl/topology_coordinator_impl.h @@ -31,7 +31,7 @@ #include <string> #include <vector> -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/repl/member_heartbeat_data.h" #include "mongo/db/repl/member_state.h" #include "mongo/db/repl/replica_set_config.h" @@ -127,7 +127,7 @@ namespace repl { virtual int getMaintenanceCount() const; virtual void setForceSyncSourceIndex(int index); virtual HostAndPort chooseNewSyncSource(Date_t now, - const OpTime& lastOpApplied); + const Timestamp& lastOpApplied); virtual void blacklistSyncSource(const HostAndPort& host, Date_t until); virtual void unblacklistSyncSource(const HostAndPort& host, Date_t now); virtual void clearSyncSourceBlacklist(); @@ -138,28 +138,28 @@ namespace repl { virtual void adjustMaintenanceCountBy(int inc); virtual void prepareSyncFromResponse(const ReplicationExecutor::CallbackData& data, const HostAndPort& target, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, BSONObjBuilder* response, Status* result); virtual void prepareFreshResponse(const ReplicationCoordinator::ReplSetFreshArgs& args, Date_t now, - OpTime lastOpApplied, + Timestamp lastOpApplied, BSONObjBuilder* response, Status* result); virtual void prepareElectResponse(const ReplicationCoordinator::ReplSetElectArgs& args, Date_t now, - OpTime lastOpApplied, + Timestamp lastOpApplied, BSONObjBuilder* response, Status* result); virtual Status prepareHeartbeatResponse(Date_t now, const ReplSetHeartbeatArgs& args, const std::string& ourSetName, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, ReplSetHeartbeatResponse* response); virtual void prepareStatusResponse(const ReplicationExecutor::CallbackData& data, Date_t now, unsigned uptime, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, BSONObjBuilder* response, Status* result); virtual void fillIsMasterForReplSet(IsMasterResponse* response); @@ -167,7 +167,7 @@ namespace repl { virtual void updateConfig(const ReplicaSetConfig& newConfig, int selfIndex, Date_t now, - OpTime lastOpApplied); + Timestamp lastOpApplied); virtual std::pair<ReplSetHeartbeatArgs, Milliseconds> prepareHeartbeatRequest( Date_t now, const std::string& ourSetName, @@ -177,13 +177,13 @@ namespace repl { Milliseconds networkRoundTripTime, const HostAndPort& target, const StatusWith<ReplSetHeartbeatResponse>& hbResponse, - OpTime myLastOpApplied); + Timestamp myLastOpApplied); virtual bool voteForMyself(Date_t now); - virtual void processWinElection(OID electionId, OpTime electionOpTime); + virtual void processWinElection(OID electionId, Timestamp electionOpTime); virtual void processLoseElection(); - virtual bool checkShouldStandForElection(Date_t now, const OpTime& lastOpApplied); + virtual bool checkShouldStandForElection(Date_t now, const Timestamp& lastOpApplied); virtual void setMyHeartbeatMessage(const Date_t now, const std::string& message); - virtual bool stepDown(Date_t until, bool force, OpTime lastOpApplied); + virtual bool stepDown(Date_t until, bool force, Timestamp lastOpApplied); virtual bool stepDownIfPending(); virtual Date_t getStepDownTime() const; @@ -195,10 +195,10 @@ namespace repl { // Changes _memberState to newMemberState. Only for testing. void changeMemberState_forTest(const MemberState& newMemberState, - OpTime electionTime = OpTime(0,0)); + Timestamp electionTime = Timestamp(0,0)); // Sets "_electionTime" to "newElectionTime". Only for testing. - void _setElectionTime(const OpTime& newElectionTime); + void _setElectionTime(const Timestamp& newElectionTime); // Sets _currentPrimaryIndex to the given index. Should only be used in unit tests! // TODO(spencer): Remove this once we can easily call for an election in unit tests to @@ -206,7 +206,7 @@ namespace repl { void _setCurrentPrimaryForTest(int primaryIndex); // Returns _electionTime. Only used in unittests. - OpTime getElectionTime() const; + Timestamp getElectionTime() const; // Returns _electionId. Only used in unittests. OID getElectionId() const; @@ -242,7 +242,7 @@ namespace repl { // If we veto, the errmsg will be filled in with a reason bool _shouldVetoMember(const ReplicationCoordinator::ReplSetFreshArgs& args, const Date_t& now, - const OpTime& lastOpApplied, + const Timestamp& lastOpApplied, std::string* errmsg) const; // Returns the index of the member with the matching id, or -1 if none match. @@ -253,18 +253,18 @@ namespace repl { // Is otherOpTime close enough (within 10 seconds) to the latest known optime to qualify // for an election - bool _isOpTimeCloseEnoughToLatestToElect(const OpTime& otherOpTime, - const OpTime& ourLastOpApplied) const; + bool _isOpTimeCloseEnoughToLatestToElect(const Timestamp& otherOpTime, + const Timestamp& ourLastOpApplied) const; // Returns reason why "self" member is unelectable UnelectableReasonMask _getMyUnelectableReason( const Date_t now, - const OpTime lastOpApplied) const; + const Timestamp lastOpApplied) const; // Returns reason why memberIndex is unelectable UnelectableReasonMask _getUnelectableReason( int memberIndex, - const OpTime& lastOpApplied) const; + const Timestamp& lastOpApplied) const; // Returns the nice text of why the node is unelectable std::string _getUnelectableReasonString(UnelectableReasonMask ur) const; @@ -273,10 +273,10 @@ namespace repl { bool _iAmPrimary() const; // Scans through all members that are 'up' and return the latest known optime. - OpTime _latestKnownOpTime(OpTime ourLastOpApplied) const; + Timestamp _latestKnownOpTime(Timestamp ourLastOpApplied) const; // Scans the electable set and returns the highest priority member index - int _getHighestPriorityElectableIndex(Date_t now, OpTime lastOpApplied) const; + int _getHighestPriorityElectableIndex(Date_t now, Timestamp lastOpApplied) const; // Returns true if "one" member is higher priority than "two" member bool _isMemberHigherPriority(int memberOneIndex, int memberTwoIndex) const; @@ -294,7 +294,7 @@ namespace repl { int updatedConfigIndex, const MemberState& originalState, Date_t now, - const OpTime& lastOpApplied); + const Timestamp& lastOpApplied); /** * Updates _hbdata based on the newConfig, ensuring that every member in the newConfig @@ -325,7 +325,7 @@ namespace repl { // result of an election. OID _electionId; // The time at which the current PRIMARY was elected. - OpTime _electionTime; + Timestamp _electionTime; // the index of the member we currently believe is primary, if one exists, otherwise -1 int _currentPrimaryIndex; diff --git a/src/mongo/db/repl/topology_coordinator_impl_test.cpp b/src/mongo/db/repl/topology_coordinator_impl_test.cpp index 2ec2cd2b89c..ce99ca62ee9 100644 --- a/src/mongo/db/repl/topology_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/topology_coordinator_impl_test.cpp @@ -83,7 +83,7 @@ namespace { needle)); } - void makeSelfPrimary(const OpTime& electionOpTime = OpTime(0,0)) { + void makeSelfPrimary(const Timestamp& electionOpTime = Timestamp(0,0)) { getTopoCoord().changeMemberState_forTest(MemberState::RS_PRIMARY, electionOpTime); getTopoCoord()._setCurrentPrimaryForTest(_selfIndex); } @@ -100,7 +100,7 @@ namespace { void updateConfig(BSONObj cfg, int selfIndex, Date_t now = Date_t(-1), - OpTime lastOp = OpTime()) { + Timestamp lastOp = Timestamp()) { ReplicaSetConfig config; ASSERT_OK(config.initialize(cfg)); ASSERT_OK(config.validate()); @@ -121,9 +121,9 @@ namespace { const HostAndPort& member, const std::string& setName, MemberState memberState, - OpTime electionTime, - OpTime lastOpTimeSender, - OpTime lastOpTimeReceiver) { + Timestamp electionTime, + Timestamp lastOpTimeSender, + Timestamp lastOpTimeReceiver) { return _receiveHeartbeatHelper(Status::OK(), member, setName, @@ -137,14 +137,14 @@ namespace { HeartbeatResponseAction receiveDownHeartbeat( const HostAndPort& member, const std::string& setName, - OpTime lastOpTimeReceiver, + Timestamp lastOpTimeReceiver, ErrorCodes::Error errcode = ErrorCodes::HostUnreachable) { return _receiveHeartbeatHelper(Status(errcode, ""), member, setName, MemberState::RS_UNKNOWN, - OpTime(), - OpTime(), + Timestamp(), + Timestamp(), lastOpTimeReceiver, Milliseconds(0)); } @@ -152,15 +152,15 @@ namespace { HeartbeatResponseAction heartbeatFromMember(const HostAndPort& member, const std::string& setName, MemberState memberState, - OpTime lastOpTimeSender, + Timestamp lastOpTimeSender, Milliseconds roundTripTime = Milliseconds(0)) { return _receiveHeartbeatHelper(Status::OK(), member, setName, memberState, - OpTime(), + Timestamp(), lastOpTimeSender, - OpTime(), + Timestamp(), roundTripTime); } @@ -170,9 +170,9 @@ namespace { const HostAndPort& member, const std::string& setName, MemberState memberState, - OpTime electionTime, - OpTime lastOpTimeSender, - OpTime lastOpTimeReceiver, + Timestamp electionTime, + Timestamp lastOpTimeSender, + Timestamp lastOpTimeReceiver, Milliseconds roundTripTime) { StatusWith<ReplSetHeartbeatResponse> hbResponse = StatusWith<ReplSetHeartbeatResponse>(responseStatus); @@ -204,7 +204,7 @@ namespace { TEST_F(TopoCoordTest, ChooseSyncSourceBasic) { // if we do not have an index in the config, we should get an empty syncsource - HostAndPort newSyncSource = getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + HostAndPort newSyncSource = getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_TRUE(newSyncSource.empty()); updateConfig(BSON("_id" << "rs0" << @@ -217,49 +217,49 @@ namespace { setSelfMemberState(MemberState::RS_SECONDARY); // member h2 is the furthest ahead - heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, OpTime(1,0)); - heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, OpTime(0,0)); + heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, Timestamp(1,0)); + heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, Timestamp(0,0)); // We start with no sync source ASSERT(getTopoCoord().getSyncSourceAddress().empty()); // Fail due to insufficient number of pings - newSyncSource = getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + newSyncSource = getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(getTopoCoord().getSyncSourceAddress(), newSyncSource); ASSERT(getTopoCoord().getSyncSourceAddress().empty()); // Record 2nd round of pings to allow choosing a new sync source; all members equidistant - heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, OpTime(1,0)); - heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, OpTime(0,0)); + heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, Timestamp(1,0)); + heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, Timestamp(0,0)); // Should choose h2, since it is furthest ahead - newSyncSource = getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + newSyncSource = getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(getTopoCoord().getSyncSourceAddress(), newSyncSource); ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress()); // h3 becomes further ahead, so it should be chosen - heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, OpTime(2,0)); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, Timestamp(2,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h3"), getTopoCoord().getSyncSourceAddress()); // h3 becomes an invalid candidate for sync source; should choose h2 again - heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_RECOVERING, OpTime(2,0)); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_RECOVERING, Timestamp(2,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress()); // h3 back in SECONDARY and ahead - heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, OpTime(2,0)); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, Timestamp(2,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h3"), getTopoCoord().getSyncSourceAddress()); // h3 goes down - receiveDownHeartbeat(HostAndPort("h3"), "rs0", OpTime()); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + receiveDownHeartbeat(HostAndPort("h3"), "rs0", Timestamp()); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress()); // h3 back up and ahead - heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, OpTime(2,0)); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, Timestamp(2,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h3"), getTopoCoord().getSyncSourceAddress()); } @@ -282,43 +282,43 @@ namespace { 0); setSelfMemberState(MemberState::RS_SECONDARY); - OpTime lastOpTimeWeApplied = OpTime(100,0); + Timestamp lastOpTimeWeApplied = Timestamp(100,0); heartbeatFromMember(HostAndPort("h1"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(700)); + Timestamp(501, 0), Milliseconds(700)); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(600)); + Timestamp(501, 0), Milliseconds(600)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(500)); + Timestamp(501, 0), Milliseconds(500)); heartbeatFromMember(HostAndPort("h4"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(400)); + Timestamp(501, 0), Milliseconds(400)); heartbeatFromMember(HostAndPort("h5"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(300)); + Timestamp(501, 0), Milliseconds(300)); // This node is lagged further than maxSyncSourceLagSeconds. heartbeatFromMember(HostAndPort("h6"), "rs0", MemberState::RS_SECONDARY, - OpTime(499, 0), Milliseconds(200)); + Timestamp(499, 0), Milliseconds(200)); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); heartbeatFromMember(HostAndPort("hprimary"), "rs0", MemberState::RS_PRIMARY, - OpTime(600, 0), Milliseconds(100)); + Timestamp(600, 0), Milliseconds(100)); ASSERT_EQUALS(7, getCurrentPrimaryIndex()); // Record 2nd round of pings to allow choosing a new sync source heartbeatFromMember(HostAndPort("h1"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(700)); + Timestamp(501, 0), Milliseconds(700)); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(600)); + Timestamp(501, 0), Milliseconds(600)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(500)); + Timestamp(501, 0), Milliseconds(500)); heartbeatFromMember(HostAndPort("h4"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(400)); + Timestamp(501, 0), Milliseconds(400)); heartbeatFromMember(HostAndPort("h5"), "rs0", MemberState::RS_SECONDARY, - OpTime(501, 0), Milliseconds(300)); + Timestamp(501, 0), Milliseconds(300)); heartbeatFromMember(HostAndPort("h6"), "rs0", MemberState::RS_SECONDARY, - OpTime(499, 0), Milliseconds(200)); + Timestamp(499, 0), Milliseconds(200)); heartbeatFromMember(HostAndPort("hprimary"), "rs0", MemberState::RS_PRIMARY, - OpTime(600, 0), Milliseconds(100)); + Timestamp(600, 0), Milliseconds(100)); // Should choose primary first; it's closest getTopoCoord().chooseNewSyncSource(now()++, lastOpTimeWeApplied); @@ -326,7 +326,7 @@ namespace { // Primary goes far far away heartbeatFromMember(HostAndPort("hprimary"), "rs0", MemberState::RS_PRIMARY, - OpTime(600, 0), Milliseconds(100000000)); + Timestamp(600, 0), Milliseconds(100000000)); // Should choose h4. (if an arbiter has an oplog, it's a valid sync source) // h6 is not considered because it is outside the maxSyncLagSeconds window, @@ -334,29 +334,29 @@ namespace { ASSERT_EQUALS(HostAndPort("h4"), getTopoCoord().getSyncSourceAddress()); // h4 goes down; should choose h1 - receiveDownHeartbeat(HostAndPort("h4"), "rs0", OpTime()); + receiveDownHeartbeat(HostAndPort("h4"), "rs0", Timestamp()); getTopoCoord().chooseNewSyncSource(now()++, lastOpTimeWeApplied); ASSERT_EQUALS(HostAndPort("h1"), getTopoCoord().getSyncSourceAddress()); // Primary and h1 go down; should choose h6 - receiveDownHeartbeat(HostAndPort("h1"), "rs0", OpTime()); - receiveDownHeartbeat(HostAndPort("hprimary"), "rs0", OpTime()); + receiveDownHeartbeat(HostAndPort("h1"), "rs0", Timestamp()); + receiveDownHeartbeat(HostAndPort("hprimary"), "rs0", Timestamp()); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); getTopoCoord().chooseNewSyncSource(now()++, lastOpTimeWeApplied); ASSERT_EQUALS(HostAndPort("h6"), getTopoCoord().getSyncSourceAddress()); // h6 goes down; should choose h5 - receiveDownHeartbeat(HostAndPort("h6"), "rs0", OpTime()); + receiveDownHeartbeat(HostAndPort("h6"), "rs0", Timestamp()); getTopoCoord().chooseNewSyncSource(now()++, lastOpTimeWeApplied); ASSERT_EQUALS(HostAndPort("h5"), getTopoCoord().getSyncSourceAddress()); // h5 goes down; should choose h3 - receiveDownHeartbeat(HostAndPort("h5"), "rs0", OpTime()); + receiveDownHeartbeat(HostAndPort("h5"), "rs0", Timestamp()); getTopoCoord().chooseNewSyncSource(now()++, lastOpTimeWeApplied); ASSERT_EQUALS(HostAndPort("h3"), getTopoCoord().getSyncSourceAddress()); // h3 goes down; no sync source candidates remain - receiveDownHeartbeat(HostAndPort("h3"), "rs0", OpTime()); + receiveDownHeartbeat(HostAndPort("h3"), "rs0", Timestamp()); getTopoCoord().chooseNewSyncSource(now()++, lastOpTimeWeApplied); ASSERT(getTopoCoord().getSyncSourceAddress().empty()); } @@ -375,27 +375,27 @@ namespace { setSelfMemberState(MemberState::RS_SECONDARY); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(100)); + Timestamp(1, 0), Milliseconds(100)); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(100)); + Timestamp(1, 0), Milliseconds(100)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(0, 0), Milliseconds(300)); + Timestamp(0, 0), Milliseconds(300)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(0, 0), Milliseconds(300)); + Timestamp(0, 0), Milliseconds(300)); // No primary situation: should choose no sync source. - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT(getTopoCoord().getSyncSourceAddress().empty()); // Add primary ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_PRIMARY, - OpTime(0, 0), Milliseconds(300)); + Timestamp(0, 0), Milliseconds(300)); ASSERT_EQUALS(2, getCurrentPrimaryIndex()); // h3 is primary and should be chosen as sync source, despite being further away than h2 // and the primary (h3) being behind our most recently applied optime - getTopoCoord().chooseNewSyncSource(now()++, OpTime(10,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(10,0)); ASSERT_EQUALS(HostAndPort("h3"), getTopoCoord().getSyncSourceAddress()); } @@ -412,20 +412,20 @@ namespace { setSelfMemberState(MemberState::RS_SECONDARY); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(100)); + Timestamp(1, 0), Milliseconds(100)); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(100)); + Timestamp(1, 0), Milliseconds(100)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(0, 0), Milliseconds(300)); + Timestamp(0, 0), Milliseconds(300)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(0, 0), Milliseconds(300)); + Timestamp(0, 0), Milliseconds(300)); // No primary situation: should choose h2 sync source. - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress()); // Become primary - makeSelfPrimary(OpTime(3.0)); + makeSelfPrimary(Timestamp(3.0)); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); // Check sync source @@ -445,27 +445,27 @@ namespace { // two rounds of heartbeat pings from each member heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(300)); + Timestamp(1, 0), Milliseconds(300)); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(300)); + Timestamp(1, 0), Milliseconds(300)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); // force should overrule other defaults - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h3"), getTopoCoord().getSyncSourceAddress()); getTopoCoord().setForceSyncSourceIndex(1); // force should cause shouldChangeSyncSource() to return true // even if the currentSource is the force target ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(HostAndPort("h2"), now())); ASSERT_TRUE(getTopoCoord().shouldChangeSyncSource(HostAndPort("h3"), now())); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress()); // force should only work for one call to chooseNewSyncSource - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h3"), getTopoCoord().getSyncSourceAddress()); } @@ -481,25 +481,25 @@ namespace { setSelfMemberState(MemberState::RS_SECONDARY); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(300)); + Timestamp(1, 0), Milliseconds(300)); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(300)); + Timestamp(1, 0), Milliseconds(300)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h3"), getTopoCoord().getSyncSourceAddress()); Date_t expireTime = 100; getTopoCoord().blacklistSyncSource(HostAndPort("h3"), expireTime); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); // Should choose second best choice now that h3 is blacklisted. ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress()); // After time has passed, should go back to original sync source - getTopoCoord().chooseNewSyncSource(expireTime, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(expireTime, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h3"), getTopoCoord().getSyncSourceAddress()); } @@ -516,27 +516,27 @@ namespace { setSelfMemberState(MemberState::RS_SECONDARY); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_PRIMARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_PRIMARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); ASSERT_EQUALS(1, getCurrentPrimaryIndex()); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress()); Date_t expireTime = 100; getTopoCoord().blacklistSyncSource(HostAndPort("h2"), expireTime); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); // Can't choose any sync source now. ASSERT(getTopoCoord().getSyncSourceAddress().empty()); // After time has passed, should go back to the primary - getTopoCoord().chooseNewSyncSource(expireTime, OpTime(0,0)); + getTopoCoord().chooseNewSyncSource(expireTime, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h2"), getTopoCoord().getSyncSourceAddress()); } @@ -553,38 +553,38 @@ namespace { // Generate enough heartbeats to select a sync source below heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(300)); + Timestamp(1, 0), Milliseconds(300)); heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(300)); + Timestamp(1, 0), Milliseconds(300)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, - OpTime(2, 0), Milliseconds(100)); + Timestamp(2, 0), Milliseconds(100)); ASSERT_EQUALS(HostAndPort("h3"), - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0))); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0))); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); // Good state setup done // Mark nodes down, ensure that we have no source and are secondary - receiveDownHeartbeat(HostAndPort("h2"), "rs0", OpTime(), ErrorCodes::NetworkTimeout); - receiveDownHeartbeat(HostAndPort("h3"), "rs0", OpTime(), ErrorCodes::NetworkTimeout); - ASSERT_TRUE(getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)).empty()); + receiveDownHeartbeat(HostAndPort("h2"), "rs0", Timestamp(), ErrorCodes::NetworkTimeout); + receiveDownHeartbeat(HostAndPort("h3"), "rs0", Timestamp(), ErrorCodes::NetworkTimeout); + ASSERT_TRUE(getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)).empty()); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); // Mark nodes down + unauth, ensure that we have no source and are secondary - receiveDownHeartbeat(HostAndPort("h2"), "rs0", OpTime(), ErrorCodes::NetworkTimeout); - receiveDownHeartbeat(HostAndPort("h3"), "rs0", OpTime(), ErrorCodes::Unauthorized); - ASSERT_TRUE(getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)).empty()); + receiveDownHeartbeat(HostAndPort("h2"), "rs0", Timestamp(), ErrorCodes::NetworkTimeout); + receiveDownHeartbeat(HostAndPort("h3"), "rs0", Timestamp(), ErrorCodes::Unauthorized); + ASSERT_TRUE(getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)).empty()); ASSERT_EQUALS(MemberState::RS_RECOVERING, getTopoCoord().getMemberState().s); // Having an auth error but with another node up should bring us out of RECOVERING HeartbeatResponseAction action = receiveUpHeartbeat(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(0, 0), - OpTime(2, 0), - OpTime(2, 0)); + Timestamp(0, 0), + Timestamp(2, 0), + Timestamp(2, 0)); ASSERT_EQUALS(MemberState::RS_SECONDARY, getTopoCoord().getMemberState().s); // Test that the heartbeat that brings us from RECOVERING to SECONDARY doesn't initiate // an election (SERVER-17164) @@ -600,12 +600,12 @@ namespace { BSON("_id" << 30 << "host" << "h3"))), -1); ASSERT_NO_ACTION(heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, - OpTime(1, 0), Milliseconds(300)).getAction()); + Timestamp(1, 0), Milliseconds(300)).getAction()); } TEST_F(TopoCoordTest, PrepareSyncFromResponse) { - OpTime staleOpTime(1, 1); - OpTime ourOpTime(staleOpTime.getSecs() + 11, 1); + Timestamp staleOpTime(1, 1); + Timestamp ourOpTime(staleOpTime.getSecs() + 11, 1); Status result = Status::OK(); BSONObjBuilder response; @@ -689,7 +689,7 @@ namespace { result.reason()); // Try to sync from a member that is down - receiveDownHeartbeat(HostAndPort("h4"), "rs0", OpTime()); + receiveDownHeartbeat(HostAndPort("h4"), "rs0", Timestamp()); BSONObjBuilder response7; getTopoCoord().prepareSyncFromResponse( @@ -731,12 +731,12 @@ namespace { BSONObj response10Obj = response10.obj(); ASSERT_FALSE(response10Obj.hasField("warning")); ASSERT_EQUALS(HostAndPort("h6").toString(), response10Obj["prevSyncTarget"].String()); - receiveDownHeartbeat(HostAndPort("h6"), "rs0", OpTime()); - HostAndPort syncSource = getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + receiveDownHeartbeat(HostAndPort("h6"), "rs0", Timestamp()); + HostAndPort syncSource = getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h6"), syncSource); // Try to sync from a member that is unauth'd - receiveDownHeartbeat(HostAndPort("h5"), "rs0", OpTime(), ErrorCodes::Unauthorized); + receiveDownHeartbeat(HostAndPort("h5"), "rs0", Timestamp(), ErrorCodes::Unauthorized); BSONObjBuilder response11; getTopoCoord().prepareSyncFromResponse( @@ -753,7 +753,7 @@ namespace { getTopoCoord().prepareSyncFromResponse( cbData(), HostAndPort("h6"), ourOpTime, &response12, &result); ASSERT_OK(result); - syncSource = getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + syncSource = getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); ASSERT_EQUALS(HostAndPort("h6"), syncSource); } @@ -771,8 +771,8 @@ namespace { Date_t heartbeatTime = 5000; Seconds uptimeSecs(10); Date_t curTime = heartbeatTime + uptimeSecs.total_milliseconds(); - OpTime electionTime(1, 2); - OpTime oplogProgress(3, 4); + Timestamp electionTime(1, 2); + Timestamp oplogProgress(3, 4); std::string setName = "mySet"; updateConfig(BSON("_id" << setName << @@ -793,7 +793,7 @@ namespace { Milliseconds(0), member, hbResponse, - OpTime(0,0)); + Timestamp(0,0)); member = HostAndPort("test1:1234"); ReplSetHeartbeatResponse hb; @@ -810,7 +810,7 @@ namespace { Milliseconds(4000), member, hbResponse, - OpTime(0,0)); + Timestamp(0,0)); makeSelfPrimary(); // Now node 0 is down, node 1 is up, and for node 2 we have no heartbeat data yet. @@ -841,9 +841,9 @@ namespace { ASSERT_EQUALS(MemberState::RS_DOWN, member0Status["state"].numberInt()); ASSERT_EQUALS("(not reachable/healthy)", member0Status["stateStr"].str()); ASSERT_EQUALS(0, member0Status["uptime"].numberInt()); - ASSERT_EQUALS(OpTime(), OpTime(member0Status["optime"].timestampValue())); + ASSERT_EQUALS(Timestamp(), Timestamp(member0Status["optime"].timestampValue())); ASSERT_TRUE(member0Status.hasField("optimeDate")); - ASSERT_EQUALS(Date_t(OpTime().getSecs() * 1000ULL), + ASSERT_EQUALS(Date_t(Timestamp().getSecs() * 1000ULL), member0Status["optimeDate"].Date().millis); ASSERT_EQUALS(heartbeatTime, member0Status["lastHeartbeat"].date()); ASSERT_EQUALS(Date_t(), member0Status["lastHeartbeatRecv"].date()); @@ -856,7 +856,7 @@ namespace { ASSERT_EQUALS(MemberState(MemberState::RS_SECONDARY).toString(), member1Status["stateStr"].String()); ASSERT_EQUALS(uptimeSecs.total_seconds(), member1Status["uptime"].numberInt()); - ASSERT_EQUALS(oplogProgress, OpTime(member1Status["optime"].timestampValue())); + ASSERT_EQUALS(oplogProgress, Timestamp(member1Status["optime"].timestampValue())); ASSERT_TRUE(member1Status.hasField("optimeDate")); ASSERT_EQUALS(Date_t(oplogProgress.getSecs() * 1000ULL), member1Status["optimeDate"].Date().millis); @@ -888,7 +888,7 @@ namespace { ASSERT_EQUALS(MemberState(MemberState::RS_PRIMARY).toString(), selfStatus["stateStr"].str()); ASSERT_EQUALS(uptimeSecs.total_seconds(), selfStatus["uptime"].numberInt()); - ASSERT_EQUALS(oplogProgress, OpTime(selfStatus["optime"].timestampValue())); + ASSERT_EQUALS(oplogProgress, Timestamp(selfStatus["optime"].timestampValue())); ASSERT_TRUE(selfStatus.hasField("optimeDate")); ASSERT_EQUALS(Date_t(oplogProgress.getSecs() * 1000ULL), selfStatus["optimeDate"].Date().millis); @@ -903,7 +903,7 @@ namespace { Date_t heartbeatTime = 5000; Seconds uptimeSecs(10); Date_t curTime = heartbeatTime + uptimeSecs.total_milliseconds(); - OpTime oplogProgress(3, 4); + Timestamp oplogProgress(3, 4); std::string setName = "mySet"; updateConfig(BSON("_id" << setName << @@ -928,9 +928,9 @@ namespace { TEST_F(TopoCoordTest, PrepareFreshResponse) { ReplicationCoordinator::ReplSetFreshArgs args; - OpTime freshestOpTime(15, 10); - OpTime ourOpTime(10, 10); - OpTime staleOpTime(1, 1); + Timestamp freshestOpTime(15, 10); + Timestamp ourOpTime(10, 10); + Timestamp staleOpTime(1, 1); Status internalErrorStatus(ErrorCodes::InternalError, "didn't set status"); // if we do not have an index in the config, we should get ErrorCodes::ReplicaSetNotFound @@ -978,7 +978,7 @@ namespace { ASSERT_OK(status1); BSONObj response1 = responseBuilder1.obj(); ASSERT_EQUALS("config version stale", response1["info"].String()); - ASSERT_EQUALS(ourOpTime, OpTime(response1["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response1["opTime"].timestampValue())); ASSERT_TRUE(response1["fresher"].Bool()); ASSERT_FALSE(response1["veto"].Bool()); ASSERT_FALSE(response1.hasField("errmsg")); @@ -993,7 +993,7 @@ namespace { getTopoCoord().prepareFreshResponse(args, Date_t(), ourOpTime, &responseBuilder2, &status2); ASSERT_OK(status2); BSONObj response2 = responseBuilder2.obj(); - ASSERT_EQUALS(ourOpTime, OpTime(response2["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response2["opTime"].timestampValue())); ASSERT_FALSE(response2["fresher"].Bool()); ASSERT_TRUE(response2["veto"].Bool()); ASSERT_EQUALS("replSet couldn't find member with id 0", response2["errmsg"].String()); @@ -1011,7 +1011,7 @@ namespace { ASSERT_OK(status3); BSONObj response3 = responseBuilder3.obj(); ASSERT_FALSE(response3.hasField("info")); - ASSERT_EQUALS(ourOpTime, OpTime(response3["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response3["opTime"].timestampValue())); ASSERT_FALSE(response3["fresher"].Bool()); ASSERT_TRUE(response3["veto"].Bool()); ASSERT_EQUALS("I am already primary, h1:27017 can try again once I've stepped down", @@ -1029,7 +1029,7 @@ namespace { ASSERT_OK(status4); BSONObj response4 = responseBuilder4.obj(); ASSERT_FALSE(response4.hasField("info")); - ASSERT_EQUALS(ourOpTime, OpTime(response4["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response4["opTime"].timestampValue())); ASSERT_FALSE(response4["fresher"].Bool()); ASSERT_TRUE(response4["veto"].Bool()); ASSERT_EQUALS( @@ -1049,7 +1049,7 @@ namespace { ASSERT_OK(status5); BSONObj response5 = responseBuilder5.obj(); ASSERT_FALSE(response5.hasField("info")); - ASSERT_EQUALS(ourOpTime, OpTime(response5["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response5["opTime"].timestampValue())); ASSERT_FALSE(response5["fresher"].Bool()); ASSERT_TRUE(response5["veto"].Bool()); ASSERT(response5["errmsg"].String().find("h1:27017 has lower priority of 1 than") != @@ -1059,7 +1059,7 @@ namespace { args.id = 40; args.who = HostAndPort("h3"); - receiveDownHeartbeat(HostAndPort("h3"), "rs0", OpTime()); + receiveDownHeartbeat(HostAndPort("h3"), "rs0", Timestamp()); BSONObjBuilder responseBuilder6; Status status6 = internalErrorStatus; @@ -1067,7 +1067,7 @@ namespace { ASSERT_OK(status6); BSONObj response6 = responseBuilder6.obj(); ASSERT_FALSE(response6.hasField("info")); - ASSERT_EQUALS(ourOpTime, OpTime(response6["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response6["opTime"].timestampValue())); ASSERT_FALSE(response6["fresher"].Bool()); ASSERT_TRUE(response6["veto"].Bool()); ASSERT_NE(std::string::npos, response6["errmsg"].String().find( @@ -1085,7 +1085,7 @@ namespace { ASSERT_OK(status7); BSONObj response7 = responseBuilder7.obj(); ASSERT_FALSE(response7.hasField("info")); - ASSERT_EQUALS(ourOpTime, OpTime(response7["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response7["opTime"].timestampValue())); ASSERT_FALSE(response7["fresher"].Bool()); ASSERT_TRUE(response7["veto"].Bool()); ASSERT_NE(std::string::npos, response7["errmsg"].String().find( @@ -1101,7 +1101,7 @@ namespace { ASSERT_OK(status8); BSONObj response8 = responseBuilder8.obj(); ASSERT_FALSE(response8.hasField("info")); - ASSERT_EQUALS(ourOpTime, OpTime(response8["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response8["opTime"].timestampValue())); ASSERT_FALSE(response8["fresher"].Bool()); ASSERT_TRUE(response8["veto"].Bool()); ASSERT_NE(std::string::npos, response8["errmsg"].String().find( @@ -1117,7 +1117,7 @@ namespace { ASSERT_OK(status9); BSONObj response9 = responseBuilder9.obj(); ASSERT_FALSE(response9.hasField("info")); - ASSERT_EQUALS(ourOpTime, OpTime(response9["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response9["opTime"].timestampValue())); ASSERT_FALSE(response9["fresher"].Bool()); ASSERT_TRUE(response9["veto"].Bool()); ASSERT_NE(std::string::npos, response9["errmsg"].String().find( @@ -1139,7 +1139,7 @@ namespace { ASSERT_OK(status10); BSONObj response10 = responseBuilder10.obj(); ASSERT_FALSE(response10.hasField("info")); - ASSERT_EQUALS(ourOpTime, OpTime(response10["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response10["opTime"].timestampValue())); ASSERT_TRUE(response10["fresher"].Bool()); ASSERT_TRUE(response10["veto"].Bool()); ASSERT_TRUE(response10.hasField("errmsg")); @@ -1149,7 +1149,7 @@ namespace { args.id = 40; args.who = HostAndPort("h3"); - receiveDownHeartbeat(HostAndPort("h2"), "rs0", OpTime()); + receiveDownHeartbeat(HostAndPort("h2"), "rs0", Timestamp()); heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, ourOpTime); BSONObjBuilder responseBuilder11; @@ -1159,7 +1159,7 @@ namespace { ASSERT_OK(status11); BSONObj response11 = responseBuilder11.obj(); ASSERT_FALSE(response11.hasField("info")) << response11.toString(); - ASSERT_EQUALS(ourOpTime, OpTime(response11["opTime"].timestampValue())); + ASSERT_EQUALS(ourOpTime, Timestamp(response11["opTime"].timestampValue())); ASSERT_FALSE(response11["fresher"].Bool()) << response11.toString(); ASSERT_FALSE(response11["veto"].Bool()) << response11.toString(); ASSERT_FALSE(response11.hasField("errmsg")) << response11.toString(); @@ -1219,7 +1219,7 @@ namespace { _target, StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::ExceededTimeLimit, "Took too long"), - OpTime(0, 0)); // We've never applied anything. + Timestamp(0, 0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); @@ -1261,7 +1261,7 @@ namespace { Milliseconds(400), // Spent 0.4 of the 0.5 seconds in the network. target(), StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::NodeNotFound, "Bad DNS?"), - OpTime(0, 0)); // We've never applied anything. + Timestamp(0, 0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); // Because the first retry failed without timing out, we expect to retry immediately. @@ -1295,7 +1295,7 @@ namespace { }; TEST_F(HeartbeatResponseHighVerbosityTest, UpdateHeartbeatDataNodeBelivesWeAreDown) { - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); // request heartbeat std::pair<ReplSetHeartbeatArgs, Milliseconds> request = @@ -1321,7 +1321,7 @@ namespace { } TEST_F(HeartbeatResponseHighVerbosityTest, UpdateHeartbeatDataMemberNotInConfig) { - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); // request heartbeat std::pair<ReplSetHeartbeatArgs, Milliseconds> request = @@ -1346,7 +1346,7 @@ namespace { } TEST_F(HeartbeatResponseHighVerbosityTest, UpdateHeartbeatDataSameConfig) { - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); // request heartbeat std::pair<ReplSetHeartbeatArgs, Milliseconds> request = @@ -1385,7 +1385,7 @@ namespace { } TEST_F(HeartbeatResponseHighVerbosityTest, UpdateHeartbeatDataOldConfig) { - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); // request heartbeat std::pair<ReplSetHeartbeatArgs, Milliseconds> request = @@ -1438,7 +1438,7 @@ namespace { Milliseconds(400), // Spent 0.4 of the 0.5 second in the network. target(), StatusWith<ReplSetHeartbeatResponse>(reconfigResponse), - OpTime(0, 0)); // We've never applied anything. + Timestamp(0, 0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::Reconfig, action.getAction()); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); ASSERT_EQUALS(Date_t(firstRequestDate() + 6500), action.getNextHeartbeatStartDate()); @@ -1450,7 +1450,7 @@ namespace { // make self primary ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - makeSelfPrimary(OpTime(5,0)); + makeSelfPrimary(Timestamp(5,0)); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); ReplSetHeartbeatResponse electedMoreRecentlyResponse; @@ -1458,7 +1458,7 @@ namespace { electedMoreRecentlyResponse.setSetName("rs0"); electedMoreRecentlyResponse.setState(MemberState::RS_PRIMARY); electedMoreRecentlyResponse.setElectable(true); - electedMoreRecentlyResponse.setElectionTime(OpTime(3,0)); + electedMoreRecentlyResponse.setElectionTime(Timestamp(3,0)); electedMoreRecentlyResponse.setVersion(5); HeartbeatResponseAction action = getTopoCoord().processHeartbeatResponse( @@ -1466,7 +1466,7 @@ namespace { Milliseconds(400), // Spent 0.4 of the 0.5 second in the network. target(), StatusWith<ReplSetHeartbeatResponse>(electedMoreRecentlyResponse), - OpTime(0,0)); // We've never applied anything. + Timestamp(0,0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::StepDownRemotePrimary, action.getAction()); ASSERT_EQUALS(1, action.getPrimaryConfigIndex()); ASSERT_EQUALS(Date_t(firstRequestDate() + 6500), action.getNextHeartbeatStartDate()); @@ -1479,7 +1479,7 @@ namespace { // acknowledge the other member so that we see a majority HeartbeatResponseAction action = receiveDownHeartbeat(HostAndPort("host3"), "rs0", - OpTime(100, 0)); + Timestamp(100, 0)); ASSERT_NO_ACTION(action.getAction()); // make us PRIMARY @@ -1490,7 +1490,7 @@ namespace { electedMoreRecentlyResponse.setSetName("rs0"); electedMoreRecentlyResponse.setState(MemberState::RS_PRIMARY); electedMoreRecentlyResponse.setElectable(false); - electedMoreRecentlyResponse.setElectionTime(OpTime(10,0)); + electedMoreRecentlyResponse.setElectionTime(Timestamp(10,0)); electedMoreRecentlyResponse.setVersion(5); action = getTopoCoord().processHeartbeatResponse( @@ -1498,7 +1498,7 @@ namespace { Milliseconds(400), // Spent 0.4 of the 0.5 second in the network. target(), StatusWith<ReplSetHeartbeatResponse>(electedMoreRecentlyResponse), - OpTime(0, 0)); // We've never applied anything. + Timestamp(0, 0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::StepDownSelf, action.getAction()); ASSERT_EQUALS(0, action.getPrimaryConfigIndex()); ASSERT_EQUALS(Date_t(firstRequestDate() + 6500), action.getNextHeartbeatStartDate()); @@ -1516,8 +1516,8 @@ namespace { // action. // acknowledge the other member so that we see a majority - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(300,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(300,0); HeartbeatResponseAction action = receiveUpHeartbeat(HostAndPort("host3"), "rs0", MemberState::RS_SECONDARY, @@ -1564,7 +1564,7 @@ namespace { Milliseconds(100), // Spent 0.1 of the 0.3 seconds in the network. target(), StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::NodeNotFound, "Bad DNS?"), - OpTime(0, 0)); // We've never applied anything. + Timestamp(0, 0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); // Because this is the second retry, rather than retry again, we expect to wait for the @@ -1578,7 +1578,7 @@ namespace { // make self primary ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - makeSelfPrimary(OpTime(5,0)); + makeSelfPrimary(Timestamp(5,0)); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); ReplSetHeartbeatResponse electedMoreRecentlyResponse; @@ -1586,7 +1586,7 @@ namespace { electedMoreRecentlyResponse.setSetName("rs0"); electedMoreRecentlyResponse.setState(MemberState::RS_PRIMARY); electedMoreRecentlyResponse.setElectable(true); - electedMoreRecentlyResponse.setElectionTime(OpTime(3,0)); + electedMoreRecentlyResponse.setElectionTime(Timestamp(3,0)); electedMoreRecentlyResponse.setVersion(5); HeartbeatResponseAction action = getTopoCoord().processHeartbeatResponse( @@ -1594,7 +1594,7 @@ namespace { Milliseconds(400), // Spent 0.4 of the 0.5 second in the network. target(), StatusWith<ReplSetHeartbeatResponse>(electedMoreRecentlyResponse), - OpTime(0,0)); // We've never applied anything. + Timestamp(0,0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::StepDownRemotePrimary, action.getAction()); ASSERT_EQUALS(1, action.getPrimaryConfigIndex()); ASSERT_EQUALS(Date_t(firstRequestDate() + 7000), action.getNextHeartbeatStartDate()); @@ -1607,7 +1607,7 @@ namespace { // acknowledge the other member so that we see a majority HeartbeatResponseAction action = receiveDownHeartbeat(HostAndPort("host3"), "rs0", - OpTime(100, 0)); + Timestamp(100, 0)); ASSERT_NO_ACTION(action.getAction()); // make us PRIMARY @@ -1618,7 +1618,7 @@ namespace { electedMoreRecentlyResponse.setSetName("rs0"); electedMoreRecentlyResponse.setState(MemberState::RS_PRIMARY); electedMoreRecentlyResponse.setElectable(false); - electedMoreRecentlyResponse.setElectionTime(OpTime(10,0)); + electedMoreRecentlyResponse.setElectionTime(Timestamp(10,0)); electedMoreRecentlyResponse.setVersion(5); action = getTopoCoord().processHeartbeatResponse( @@ -1626,7 +1626,7 @@ namespace { Milliseconds(400), // Spent 0.4 of the 0.5 second in the network. target(), StatusWith<ReplSetHeartbeatResponse>(electedMoreRecentlyResponse), - OpTime(0, 0)); // We've never applied anything. + Timestamp(0, 0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::StepDownSelf, action.getAction()); ASSERT_EQUALS(0, action.getPrimaryConfigIndex()); ASSERT_EQUALS(Date_t(firstRequestDate() + 7000), action.getNextHeartbeatStartDate()); @@ -1644,8 +1644,8 @@ namespace { // action. // acknowledge the other member so that we see a majority - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(300,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(300,0); HeartbeatResponseAction action = receiveUpHeartbeat(HostAndPort("host3"), "rs0", MemberState::RS_SECONDARY, @@ -1698,7 +1698,7 @@ namespace { target, StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::ExceededTimeLimit, "Took too long"), - OpTime(0, 0)); // We've never applied anything. + Timestamp(0, 0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); @@ -1716,7 +1716,7 @@ namespace { target(), StatusWith<ReplSetHeartbeatResponse>(ErrorCodes::ExceededTimeLimit, "Took too long"), - OpTime(0, 0)); // We've never applied anything. + Timestamp(0, 0)); // We've never applied anything. ASSERT_EQUALS(HeartbeatResponseAction::NoAction, action.getAction()); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); @@ -1725,8 +1725,8 @@ namespace { } TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataNewPrimary) { - OpTime election = OpTime(5,0); - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp election = Timestamp(5,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -1741,9 +1741,9 @@ namespace { } TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataTwoPrimariesNewOneOlder) { - OpTime election = OpTime(5,0); - OpTime election2 = OpTime(4,0); - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp election = Timestamp(5,0); + Timestamp election2 = Timestamp(4,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -1768,9 +1768,9 @@ namespace { } TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataTwoPrimariesNewOneNewer) { - OpTime election = OpTime(4,0); - OpTime election2 = OpTime(5,0); - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp election = Timestamp(4,0); + Timestamp election2 = Timestamp(5,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -1796,10 +1796,10 @@ namespace { TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataTwoPrimariesIncludingMeNewOneOlder) { ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - makeSelfPrimary(OpTime(5,0)); + makeSelfPrimary(Timestamp(5,0)); - OpTime election = OpTime(4,0); - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp election = Timestamp(4,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -1828,9 +1828,9 @@ namespace { 0); setSelfMemberState(MemberState::RS_SECONDARY); - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(13,0); - OpTime slightlyLessFreshLastOpTimeApplied = OpTime(3,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(13,0); + Timestamp slightlyLessFreshLastOpTimeApplied = Timestamp(3,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -1864,7 +1864,7 @@ namespace { BSON("_id" << 2 << "host" << "host3:27017" << "priority" << 3)) << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); - OpTime election = OpTime(1000,0); + Timestamp election = Timestamp(1000,0); getTopoCoord().setFollowerMode(MemberState::RS_SECONDARY); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); @@ -1909,8 +1909,8 @@ namespace { BSON("_id" << 2 << "host" << "host3:27017" << "priority" << 3)) << "settings" << BSON("heartbeatTimeoutSecs" << 5)), 0); - OpTime election = OpTime(1000,0); - OpTime staleTime = OpTime(0,0); + Timestamp election = Timestamp(1000,0); + Timestamp staleTime = Timestamp(0,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); makeSelfPrimary(election); @@ -1938,8 +1938,8 @@ namespace { 0); setSelfMemberState(MemberState::RS_SECONDARY); - OpTime election = OpTime(1000,0); - OpTime stale = OpTime(0,0); + Timestamp election = Timestamp(1000,0); + Timestamp stale = Timestamp(0,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -1961,10 +1961,10 @@ namespace { TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataTwoPrimariesIncludingMeNewOneNewer) { ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - makeSelfPrimary(OpTime(2,0)); + makeSelfPrimary(Timestamp(2,0)); - OpTime election = OpTime(4,0); - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp election = Timestamp(4,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -1987,8 +1987,8 @@ namespace { TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataPrimaryDownNoMajority) { setSelfMemberState(MemberState::RS_SECONDARY); - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(300,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(300,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -2017,8 +2017,8 @@ namespace { BSON("_id" << 2 << "host" << "host3:27017"))), 0); - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(300,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(300,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -2048,8 +2048,8 @@ namespace { TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataPrimaryDownMajorityButIAmStarting) { setSelfMemberState(MemberState::RS_STARTUP); - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(300,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(300,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -2078,8 +2078,8 @@ namespace { TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataPrimaryDownMajorityButIAmRecovering) { setSelfMemberState(MemberState::RS_RECOVERING); - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(300,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(300,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -2100,8 +2100,8 @@ namespace { TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataPrimaryDownMajorityButIHaveStepdownWait) { setSelfMemberState(MemberState::RS_SECONDARY); - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(300,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(300,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -2141,8 +2141,8 @@ namespace { BSON("_id" << 2 << "host" << "host3:27017"))), 0); - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(300,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(300,0); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host3"), "rs0", @@ -2171,8 +2171,8 @@ namespace { TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataPrimaryDownMajority) { setSelfMemberState(MemberState::RS_SECONDARY); - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(399,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(399,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -2215,8 +2215,8 @@ namespace { now() += 30000; // we need to be more than LastVote::leaseTime from the start of time or // else some Date_t math goes horribly awry - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(130,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(130,0); OID round = OID::gen(); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); @@ -2285,9 +2285,9 @@ namespace { now() += 30000; // we need to be more than LastVote::leaseTime from the start of time or // else some Date_t math goes horribly awry - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(100,0); - OpTime fresherOpApplied = OpTime(200,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(100,0); + Timestamp fresherOpApplied = Timestamp(200,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -2313,7 +2313,7 @@ namespace { ASSERT_EQUALS(HeartbeatResponseAction::StartElection, nextAction.getAction()); ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); - OpTime originalElectionTime = getTopoCoord().getElectionTime(); + Timestamp originalElectionTime = getTopoCoord().getElectionTime(); OID originalElectionId = getTopoCoord().getElectionId(); // prepare an incoming fresh command ReplicationCoordinator::ReplSetFreshArgs freshArgs; @@ -2329,7 +2329,7 @@ namespace { freshArgs, now()++, lastOpTimeApplied, &freshResponseBuilder, &result); BSONObj response = freshResponseBuilder.obj(); ASSERT_OK(result); - ASSERT_EQUALS(lastOpTimeApplied, OpTime(response["opTime"].timestampValue())); + ASSERT_EQUALS(lastOpTimeApplied, Timestamp(response["opTime"].timestampValue())); ASSERT_FALSE(response["fresher"].trueValue()); ASSERT_FALSE(response["veto"].trueValue()); ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); @@ -2349,7 +2349,7 @@ namespace { result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); getTopoCoord().prepareElectResponse( - electArgs, now()++, OpTime(), &electResponseBuilder, &result); + electArgs, now()++, Timestamp(), &electResponseBuilder, &result); stopCapturingLogMessages(); response = electResponseBuilder.obj(); ASSERT_OK(result); @@ -2380,7 +2380,7 @@ namespace { // now lose election and ensure _electionTime and _electionId are 0'd out getTopoCoord().processLoseElection(); ASSERT_EQUALS(OID(), getTopoCoord().getElectionId()); - ASSERT_EQUALS(OpTime(0,0), getTopoCoord().getElectionTime()); + ASSERT_EQUALS(Timestamp(0,0), getTopoCoord().getElectionTime()); ASSERT_TRUE(TopologyCoordinator::Role::follower == getTopoCoord().getRole()); ASSERT_EQUALS(2, getCurrentPrimaryIndex()); } @@ -2403,9 +2403,9 @@ namespace { now() += 30000; // we need to be more than LastVote::leaseTime from the start of time or // else some Date_t math goes horribly awry - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(100,0); - OpTime fresherLastOpTimeApplied = OpTime(200,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(100,0); + Timestamp fresherLastOpTimeApplied = Timestamp(200,0); OID round = OID::gen(); OID remoteRound = OID::gen(); @@ -2447,7 +2447,7 @@ namespace { freshArgs, now()++, lastOpTimeApplied, &freshResponseBuilder, &result); BSONObj response = freshResponseBuilder.obj(); ASSERT_OK(result); - ASSERT_EQUALS(lastOpTimeApplied, OpTime(response["opTime"].timestampValue())); + ASSERT_EQUALS(lastOpTimeApplied, Timestamp(response["opTime"].timestampValue())); ASSERT_FALSE(response["fresher"].trueValue()); ASSERT_FALSE(response["veto"].trueValue()); ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); @@ -2472,7 +2472,7 @@ namespace { result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); getTopoCoord().prepareElectResponse( - electArgs, now()++, OpTime(), &electResponseBuilder, &result); + electArgs, now()++, Timestamp(), &electResponseBuilder, &result); stopCapturingLogMessages(); response = electResponseBuilder.obj(); ASSERT_OK(result); @@ -2500,9 +2500,9 @@ namespace { now() += 30000; // we need to be more than LastVote::leaseTime from the start of time or // else some Date_t math goes horribly awry - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(100,0); - OpTime fresherLastOpTimeApplied = OpTime(200,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(100,0); + Timestamp fresherLastOpTimeApplied = Timestamp(200,0); OID round = OID::gen(); OID remoteRound = OID::gen(); @@ -2551,7 +2551,7 @@ namespace { freshArgs, now()++, lastOpTimeApplied, &freshResponseBuilder, &result); BSONObj response = freshResponseBuilder.obj(); ASSERT_OK(result); - ASSERT_EQUALS(lastOpTimeApplied, OpTime(response["opTime"].timestampValue())); + ASSERT_EQUALS(lastOpTimeApplied, Timestamp(response["opTime"].timestampValue())); ASSERT_FALSE(response["fresher"].trueValue()); ASSERT_TRUE(response["veto"].trueValue()) << response["errmsg"]; ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); @@ -2568,7 +2568,7 @@ namespace { result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); getTopoCoord().prepareElectResponse( - electArgs, now()++, OpTime(), &electResponseBuilder, &result); + electArgs, now()++, Timestamp(), &electResponseBuilder, &result); stopCapturingLogMessages(); response = electResponseBuilder.obj(); ASSERT_OK(result); @@ -2594,8 +2594,8 @@ namespace { setSelfMemberState(MemberState::RS_SECONDARY); - OpTime election = OpTime(400,0); - OpTime lastOpTimeApplied = OpTime(300,0); + Timestamp election = Timestamp(400,0); + Timestamp lastOpTimeApplied = Timestamp(300,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), @@ -2634,21 +2634,21 @@ namespace { TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataRelinquishPrimaryDueToNodeDisappearing) { // become PRIMARY ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); - makeSelfPrimary(OpTime(2,0)); + makeSelfPrimary(Timestamp(2,0)); ASSERT_EQUALS(0, getCurrentPrimaryIndex()); // become aware of other nodes - heartbeatFromMember(HostAndPort("host2"), "rs0", MemberState::RS_SECONDARY, OpTime(1,0)); - heartbeatFromMember(HostAndPort("host2"), "rs0", MemberState::RS_SECONDARY, OpTime(1,0)); - heartbeatFromMember(HostAndPort("host3"), "rs0", MemberState::RS_SECONDARY, OpTime(0,0)); - heartbeatFromMember(HostAndPort("host3"), "rs0", MemberState::RS_SECONDARY, OpTime(0,0)); + heartbeatFromMember(HostAndPort("host2"), "rs0", MemberState::RS_SECONDARY, Timestamp(1,0)); + heartbeatFromMember(HostAndPort("host2"), "rs0", MemberState::RS_SECONDARY, Timestamp(1,0)); + heartbeatFromMember(HostAndPort("host3"), "rs0", MemberState::RS_SECONDARY, Timestamp(0,0)); + heartbeatFromMember(HostAndPort("host3"), "rs0", MemberState::RS_SECONDARY, Timestamp(0,0)); // lose that awareness and be sure we are going to stepdown HeartbeatResponseAction nextAction = receiveDownHeartbeat(HostAndPort("host2"), "rs0", - OpTime(100, 0)); + Timestamp(100, 0)); ASSERT_NO_ACTION(nextAction.getAction()); - nextAction = receiveDownHeartbeat(HostAndPort("host3"), "rs0", OpTime(100, 0)); + nextAction = receiveDownHeartbeat(HostAndPort("host3"), "rs0", Timestamp(100, 0)); ASSERT_EQUALS(HeartbeatResponseAction::StepDownSelf, nextAction.getAction()); ASSERT_EQUALS(0, nextAction.getPrimaryConfigIndex()); // Doesn't actually do the stepdown until stepDownIfPending is called @@ -2661,8 +2661,8 @@ namespace { } TEST_F(HeartbeatResponseTest, UpdateHeartbeatDataRemoteDoesNotExist) { - OpTime election = OpTime(5,0); - OpTime lastOpTimeApplied = OpTime(3,0); + Timestamp election = Timestamp(5,0); + Timestamp lastOpTimeApplied = Timestamp(3,0); ASSERT_EQUALS(-1, getCurrentPrimaryIndex()); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host9"), @@ -2717,7 +2717,7 @@ namespace { BSONObjBuilder responseBuilder; Status result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now += 60000, OpTime(), &responseBuilder, &result); + getTopoCoord().prepareElectResponse(args, now += 60000, Timestamp(), &responseBuilder, &result); stopCapturingLogMessages(); BSONObj response = responseBuilder.obj(); ASSERT_OK(result); @@ -2730,7 +2730,7 @@ namespace { // Make sure nay votes, do not prevent subsequent yeas (the way a yea vote would) args.set = "rs0"; BSONObjBuilder responseBuilder2; - getTopoCoord().prepareElectResponse(args, now++, OpTime(), &responseBuilder2, &result); + getTopoCoord().prepareElectResponse(args, now++, Timestamp(), &responseBuilder2, &result); BSONObj response2 = responseBuilder2.obj(); ASSERT_EQUALS(1, response2["vote"].Int()); ASSERT_EQUALS(round, response2["round"].OID()); @@ -2747,7 +2747,7 @@ namespace { BSONObjBuilder responseBuilder; Status result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now += 60000, OpTime(), &responseBuilder, &result); + getTopoCoord().prepareElectResponse(args, now += 60000, Timestamp(), &responseBuilder, &result); stopCapturingLogMessages(); BSONObj response = responseBuilder.obj(); ASSERT_OK(result); @@ -2759,7 +2759,7 @@ namespace { // Make sure nay votes, do not prevent subsequent yeas (the way a yea vote would) args.cfgver = 10; BSONObjBuilder responseBuilder2; - getTopoCoord().prepareElectResponse(args, now++, OpTime(), &responseBuilder2, &result); + getTopoCoord().prepareElectResponse(args, now++, Timestamp(), &responseBuilder2, &result); BSONObj response2 = responseBuilder2.obj(); ASSERT_EQUALS(1, response2["vote"].Int()); ASSERT_EQUALS(round, response2["round"].OID()); @@ -2776,7 +2776,7 @@ namespace { BSONObjBuilder responseBuilder; Status result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now += 60000, OpTime(), &responseBuilder, &result); + getTopoCoord().prepareElectResponse(args, now += 60000, Timestamp(), &responseBuilder, &result); stopCapturingLogMessages(); BSONObj response = responseBuilder.obj(); ASSERT_OK(result); @@ -2788,7 +2788,7 @@ namespace { // Make sure nay votes, do not prevent subsequent yeas (the way a yea vote would) args.cfgver = 10; BSONObjBuilder responseBuilder2; - getTopoCoord().prepareElectResponse(args, now++, OpTime(), &responseBuilder2, &result); + getTopoCoord().prepareElectResponse(args, now++, Timestamp(), &responseBuilder2, &result); BSONObj response2 = responseBuilder2.obj(); ASSERT_EQUALS(1, response2["vote"].Int()); ASSERT_EQUALS(round, response2["round"].OID()); @@ -2805,7 +2805,7 @@ namespace { BSONObjBuilder responseBuilder; Status result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now += 60000, OpTime(), &responseBuilder, &result); + getTopoCoord().prepareElectResponse(args, now += 60000, Timestamp(), &responseBuilder, &result); stopCapturingLogMessages(); BSONObj response = responseBuilder.obj(); ASSERT_OK(result); @@ -2816,7 +2816,7 @@ namespace { // Make sure nay votes, do not prevent subsequent yeas (the way a yea vote would) args.whoid = 1; BSONObjBuilder responseBuilder2; - getTopoCoord().prepareElectResponse(args, now++, OpTime(), &responseBuilder2, &result); + getTopoCoord().prepareElectResponse(args, now++, Timestamp(), &responseBuilder2, &result); BSONObj response2 = responseBuilder2.obj(); ASSERT_EQUALS(1, response2["vote"].Int()); ASSERT_EQUALS(round, response2["round"].OID()); @@ -2835,7 +2835,7 @@ namespace { BSONObjBuilder responseBuilder; Status result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now += 60000, OpTime(), &responseBuilder, &result); + getTopoCoord().prepareElectResponse(args, now += 60000, Timestamp(), &responseBuilder, &result); stopCapturingLogMessages(); BSONObj response = responseBuilder.obj(); ASSERT_OK(result); @@ -2846,7 +2846,7 @@ namespace { // Make sure nay votes, do not prevent subsequent yeas (the way a yea vote would) getTopoCoord()._setCurrentPrimaryForTest(-1); BSONObjBuilder responseBuilder2; - getTopoCoord().prepareElectResponse(args, now++, OpTime(), &responseBuilder2, &result); + getTopoCoord().prepareElectResponse(args, now++, Timestamp(), &responseBuilder2, &result); BSONObj response2 = responseBuilder2.obj(); ASSERT_EQUALS(1, response2["vote"].Int()); ASSERT_EQUALS(round, response2["round"].OID()); @@ -2864,7 +2864,7 @@ namespace { BSONObjBuilder responseBuilder; Status result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now += 60000, OpTime(), &responseBuilder, &result); + getTopoCoord().prepareElectResponse(args, now += 60000, Timestamp(), &responseBuilder, &result); stopCapturingLogMessages(); BSONObj response = responseBuilder.obj(); ASSERT_OK(result); @@ -2875,7 +2875,7 @@ namespace { // Make sure nay votes, do not prevent subsequent yeas (the way a yea vote would) getTopoCoord()._setCurrentPrimaryForTest(-1); BSONObjBuilder responseBuilder2; - getTopoCoord().prepareElectResponse(args, now++, OpTime(), &responseBuilder2, &result); + getTopoCoord().prepareElectResponse(args, now++, Timestamp(), &responseBuilder2, &result); BSONObj response2 = responseBuilder2.obj(); ASSERT_EQUALS(1, response2["vote"].Int()); ASSERT_EQUALS(round, response2["round"].OID()); @@ -2894,7 +2894,7 @@ namespace { BSONObjBuilder responseBuilder; Status result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now += 60000, OpTime(), &responseBuilder, &result); + getTopoCoord().prepareElectResponse(args, now += 60000, Timestamp(), &responseBuilder, &result); stopCapturingLogMessages(); BSONObj response = responseBuilder.obj(); ASSERT_OK(result); @@ -2905,7 +2905,7 @@ namespace { // Make sure nay votes, do not prevent subsequent yeas (the way a yea vote would) args.whoid = 3; BSONObjBuilder responseBuilder2; - getTopoCoord().prepareElectResponse(args, now++, OpTime(), &responseBuilder2, &result); + getTopoCoord().prepareElectResponse(args, now++, Timestamp(), &responseBuilder2, &result); BSONObj response2 = responseBuilder2.obj(); ASSERT_EQUALS(1, response2["vote"].Int()); ASSERT_EQUALS(round, response2["round"].OID()); @@ -2920,13 +2920,13 @@ namespace { args.cfgver = 10; args.whoid = 1; - receiveDownHeartbeat(HostAndPort("h3"), "rs0", OpTime()); - receiveDownHeartbeat(HostAndPort("h2"), "rs0", OpTime()); + receiveDownHeartbeat(HostAndPort("h3"), "rs0", Timestamp()); + receiveDownHeartbeat(HostAndPort("h2"), "rs0", Timestamp()); BSONObjBuilder responseBuilder; Status result = Status::OK(); startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now += 60000, OpTime(), &responseBuilder, &result); + getTopoCoord().prepareElectResponse(args, now += 60000, Timestamp(), &responseBuilder, &result); stopCapturingLogMessages(); BSONObj response = responseBuilder.obj(); ASSERT_EQUALS(1, response["vote"].Int()); @@ -2945,7 +2945,7 @@ namespace { BSONObjBuilder responseBuilder1; Status result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now += 60000, OpTime(), &responseBuilder1, &result); + getTopoCoord().prepareElectResponse(args, now += 60000, Timestamp(), &responseBuilder1, &result); stopCapturingLogMessages(); BSONObj response1 = responseBuilder1.obj(); ASSERT_OK(result); @@ -2958,7 +2958,7 @@ namespace { BSONObjBuilder responseBuilder2; startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now, OpTime(), &responseBuilder2, &result); + getTopoCoord().prepareElectResponse(args, now, Timestamp(), &responseBuilder2, &result); stopCapturingLogMessages(); BSONObj response2 = responseBuilder2.obj(); ASSERT_OK(result); @@ -2972,7 +2972,7 @@ namespace { BSONObjBuilder responseBuilder3; startCapturingLogMessages(); - getTopoCoord().prepareElectResponse(args, now++, OpTime(), &responseBuilder3, &result); + getTopoCoord().prepareElectResponse(args, now++, Timestamp(), &responseBuilder3, &result); stopCapturingLogMessages(); BSONObj response3 = responseBuilder3.obj(); ASSERT_OK(result); @@ -2985,7 +2985,7 @@ namespace { ReplicationCoordinator::ReplSetElectArgs args; BSONObjBuilder response; Status status = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); - getTopoCoord().prepareElectResponse(args, now(), OpTime(), &response, &status); + getTopoCoord().prepareElectResponse(args, now(), Timestamp(), &response, &status); ASSERT_EQUALS(ErrorCodes::ReplicaSetNotFound, status); ASSERT_EQUALS("Cannot participate in election because not initialized", status.reason()); } @@ -3102,7 +3102,7 @@ namespace { BSONObjBuilder response; getTopoCoord().prepareSyncFromResponse(cbData(), HostAndPort("host2:27017"), - OpTime(0,0), + Timestamp(0,0), &response, &result); ASSERT_EQUALS(ErrorCodes::ShutdownInProgress, result); @@ -3116,7 +3116,7 @@ namespace { getTopoCoord().prepareStatusResponse(cbData(), Date_t(0), 0, - OpTime(0,0), + Timestamp(0,0), &response, &result); ASSERT_EQUALS(ErrorCodes::ShutdownInProgress, result); @@ -3139,7 +3139,7 @@ namespace { } void prepareHeartbeatResponse(const ReplSetHeartbeatArgs& args, - OpTime lastOpApplied, + Timestamp lastOpApplied, ReplSetHeartbeatResponse* response, Status* result) { *result = getTopoCoord().prepareHeartbeatResponse(now()++, @@ -3159,7 +3159,7 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); // prepare response and check the results - prepareHeartbeatResponse(args, OpTime(0,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(0,0), &response, &result); ASSERT_EQUALS(ErrorCodes::BadValue, result); ASSERT_EQUALS("replset: incompatible replset protocol version: 3", result.reason()); ASSERT_EQUALS("", response.getHbMsg()); @@ -3173,7 +3173,7 @@ namespace { args.setSenderId(10); ReplSetHeartbeatResponse response; Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); - prepareHeartbeatResponse(args, OpTime(0,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(0,0), &response, &result); ASSERT_EQUALS(ErrorCodes::BadValue, result); ASSERT(result.reason().find("from member with the same member ID as our self")) << "Actual string was \"" << result.reason() << '"'; @@ -3189,7 +3189,7 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); startCapturingLogMessages(); - prepareHeartbeatResponse(args, OpTime(0,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(0,0), &response, &result); stopCapturingLogMessages(); ASSERT_EQUALS(ErrorCodes::InconsistentReplicaSetNames, result); ASSERT(result.reason().find("repl set names do not match")) << "Actual string was \"" << @@ -3211,12 +3211,12 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); // prepare response and check the results - prepareHeartbeatResponse(args, OpTime(0,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(0,0), &response, &result); ASSERT_OK(result); ASSERT_FALSE(response.isElectable()); ASSERT_TRUE(response.isReplSet()); ASSERT_EQUALS(MemberState::RS_SECONDARY, response.getState().s); - ASSERT_EQUALS(OpTime(0,0), response.getOpTime()); + ASSERT_EQUALS(Timestamp(0,0), response.getOpTime()); ASSERT_EQUALS(Seconds(0).total_milliseconds(), response.getTime().total_milliseconds()); ASSERT_EQUALS("", response.getHbMsg()); ASSERT_EQUALS("rs0", response.getReplicaSetName()); @@ -3234,12 +3234,12 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); // prepare response and check the results - prepareHeartbeatResponse(args, OpTime(0,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(0,0), &response, &result); ASSERT_OK(result); ASSERT_FALSE(response.isElectable()); ASSERT_TRUE(response.isReplSet()); ASSERT_EQUALS(MemberState::RS_SECONDARY, response.getState().s); - ASSERT_EQUALS(OpTime(0,0), response.getOpTime()); + ASSERT_EQUALS(Timestamp(0,0), response.getOpTime()); ASSERT_EQUALS(Seconds(0).total_milliseconds(), response.getTime().total_milliseconds()); ASSERT_EQUALS("", response.getHbMsg()); ASSERT_EQUALS("rs0", response.getReplicaSetName()); @@ -3257,13 +3257,13 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); // prepare response and check the results - prepareHeartbeatResponse(args, OpTime(0,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(0,0), &response, &result); ASSERT_OK(result); ASSERT_TRUE(response.hasConfig()); ASSERT_FALSE(response.isElectable()); ASSERT_TRUE(response.isReplSet()); ASSERT_EQUALS(MemberState::RS_SECONDARY, response.getState().s); - ASSERT_EQUALS(OpTime(0,0), response.getOpTime()); + ASSERT_EQUALS(Timestamp(0,0), response.getOpTime()); ASSERT_EQUALS(Seconds(0).total_milliseconds(), response.getTime().total_milliseconds()); ASSERT_EQUALS("", response.getHbMsg()); ASSERT_EQUALS("rs0", response.getReplicaSetName()); @@ -3281,13 +3281,13 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); // prepare response and check the results - prepareHeartbeatResponse(args, OpTime(0,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(0,0), &response, &result); ASSERT_OK(result); ASSERT_FALSE(response.hasConfig()); ASSERT_FALSE(response.isElectable()); ASSERT_TRUE(response.isReplSet()); ASSERT_EQUALS(MemberState::RS_SECONDARY, response.getState().s); - ASSERT_EQUALS(OpTime(0,0), response.getOpTime()); + ASSERT_EQUALS(Timestamp(0,0), response.getOpTime()); ASSERT_EQUALS(Seconds(0).total_milliseconds(), response.getTime().total_milliseconds()); ASSERT_EQUALS("", response.getHbMsg()); ASSERT_EQUALS("rs0", response.getReplicaSetName()); @@ -3305,12 +3305,12 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); // prepare response and check the results - prepareHeartbeatResponse(args, OpTime(0,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(0,0), &response, &result); ASSERT_OK(result); ASSERT_FALSE(response.isElectable()); ASSERT_TRUE(response.isReplSet()); ASSERT_EQUALS(MemberState::RS_SECONDARY, response.getState().s); - ASSERT_EQUALS(OpTime(0,0), response.getOpTime()); + ASSERT_EQUALS(Timestamp(0,0), response.getOpTime()); ASSERT_EQUALS(Seconds(0).total_milliseconds(), response.getTime().total_milliseconds()); ASSERT_EQUALS("", response.getHbMsg()); ASSERT_EQUALS("rs0", response.getReplicaSetName()); @@ -3320,7 +3320,7 @@ namespace { TEST_F(PrepareHeartbeatResponseTest, PrepareHeartbeatResponseSenderUp) { // set up args and acknowledge sender - heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, OpTime(0,0)); + heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, Timestamp(0,0)); ReplSetHeartbeatArgs args; args.setProtocolVersion(1); args.setConfigVersion(1); @@ -3330,13 +3330,13 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); // prepare response and check the results - prepareHeartbeatResponse(args, OpTime(100,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(100,0), &response, &result); ASSERT_OK(result); // this change to true because we can now see a majority, unlike in the previous cases ASSERT_TRUE(response.isElectable()); ASSERT_TRUE(response.isReplSet()); ASSERT_EQUALS(MemberState::RS_SECONDARY, response.getState().s); - ASSERT_EQUALS(OpTime(100,0), response.getOpTime()); + ASSERT_EQUALS(Timestamp(100,0), response.getOpTime()); ASSERT_EQUALS(Seconds(0).total_milliseconds(), response.getTime().total_milliseconds()); ASSERT_EQUALS("", response.getHbMsg()); ASSERT_EQUALS("rs0", response.getReplicaSetName()); @@ -3355,14 +3355,14 @@ namespace { Status result = getTopoCoord().prepareHeartbeatResponse(now()++, args, "rs0", - OpTime(0,0), + Timestamp(0,0), &response); ASSERT_OK(result); // this change to true because we can now see a majority, unlike in the previous cases ASSERT_FALSE(response.isElectable()); ASSERT_TRUE(response.isReplSet()); ASSERT_EQUALS(MemberState::RS_STARTUP, response.getState().s); - ASSERT_EQUALS(OpTime(0,0), response.getOpTime()); + ASSERT_EQUALS(Timestamp(0,0), response.getOpTime()); ASSERT_EQUALS(Seconds(0).total_milliseconds(), response.getTime().total_milliseconds()); ASSERT_EQUALS("", response.getHbMsg()); ASSERT_EQUALS("", response.getReplicaSetName()); @@ -3370,8 +3370,8 @@ namespace { } TEST_F(PrepareHeartbeatResponseTest, PrepareHeartbeatResponseAsPrimary) { - makeSelfPrimary(OpTime(10,0)); - heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, OpTime(0,0)); + makeSelfPrimary(Timestamp(10,0)); + heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, Timestamp(0,0)); ReplSetHeartbeatArgs args; args.setProtocolVersion(1); @@ -3382,14 +3382,14 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); // prepare response and check the results - prepareHeartbeatResponse(args, OpTime(11,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(11,0), &response, &result); ASSERT_OK(result); // electable because we are already primary ASSERT_TRUE(response.isElectable()); ASSERT_TRUE(response.isReplSet()); ASSERT_EQUALS(MemberState::RS_PRIMARY, response.getState().s); - ASSERT_EQUALS(OpTime(11,0), response.getOpTime()); - ASSERT_EQUALS(OpTime(10,0), response.getElectionTime()); + ASSERT_EQUALS(Timestamp(11,0), response.getOpTime()); + ASSERT_EQUALS(Timestamp(10,0), response.getElectionTime()); ASSERT_EQUALS(Seconds(0).total_milliseconds(), response.getTime().total_milliseconds()); ASSERT_EQUALS("", response.getHbMsg()); ASSERT_EQUALS("rs0", response.getReplicaSetName()); @@ -3398,11 +3398,11 @@ namespace { TEST_F(PrepareHeartbeatResponseTest, PrepareHeartbeatResponseWithSyncSource) { // get a sync source - heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, OpTime(0,0)); - heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, OpTime(0,0)); - heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, OpTime(1,0)); - heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, OpTime(1,0)); - getTopoCoord().chooseNewSyncSource(now()++, OpTime(0,0)); + heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, Timestamp(0,0)); + heartbeatFromMember(HostAndPort("h3"), "rs0", MemberState::RS_SECONDARY, Timestamp(0,0)); + heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, Timestamp(1,0)); + heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, Timestamp(1,0)); + getTopoCoord().chooseNewSyncSource(now()++, Timestamp(0,0)); // set up args ReplSetHeartbeatArgs args; @@ -3414,12 +3414,12 @@ namespace { Status result(ErrorCodes::InternalError, "prepareHeartbeatResponse didn't set result"); // prepare response and check the results - prepareHeartbeatResponse(args, OpTime(100,0), &response, &result); + prepareHeartbeatResponse(args, Timestamp(100,0), &response, &result); ASSERT_OK(result); ASSERT_TRUE(response.isElectable()); ASSERT_TRUE(response.isReplSet()); ASSERT_EQUALS(MemberState::RS_SECONDARY, response.getState().s); - ASSERT_EQUALS(OpTime(100,0), response.getOpTime()); + ASSERT_EQUALS(Timestamp(100,0), response.getOpTime()); ASSERT_EQUALS(Seconds(0).total_milliseconds(), response.getTime().total_milliseconds()); // changed to a syncing message because our sync source changed recently ASSERT_EQUALS("syncing from: h2:27017", response.getHbMsg()); @@ -3453,7 +3453,7 @@ namespace { "version" << 1 << "members" << BSON_ARRAY( BSON("_id" << 1 << "host" << "hself" << "priority" << 0)))); - getTopoCoord().updateConfig(cfg, 0, now()++, OpTime()); + getTopoCoord().updateConfig(cfg, 0, now()++, Timestamp()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); ASSERT_FALSE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); @@ -3480,7 +3480,7 @@ namespace { "members" << BSON_ARRAY( BSON("_id" << 1 << "host" << "hself" << "priority" << 0)))); - getTopoCoord().updateConfig(cfg, 0, now()++, OpTime()); + getTopoCoord().updateConfig(cfg, 0, now()++, Timestamp()); ASSERT_EQUALS(MemberState::RS_STARTUP2, getTopoCoord().getMemberState().s); // despite being the only node, we are unelectable, so we should not become a candidate @@ -3556,7 +3556,7 @@ namespace { ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); // win election and primary - getTopoCoord().processWinElection(OID::gen(), OpTime(0,0)); + getTopoCoord().processWinElection(OID::gen(), Timestamp(0,0)); ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); @@ -3586,7 +3586,7 @@ namespace { ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); // win election and primary - getTopoCoord().processWinElection(OID::gen(), OpTime(0,0)); + getTopoCoord().processWinElection(OID::gen(), Timestamp(0,0)); ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); @@ -3617,7 +3617,7 @@ namespace { ASSERT_TRUE(TopologyCoordinator::Role::candidate == getTopoCoord().getRole()); // win election and primary - getTopoCoord().processWinElection(OID::gen(), OpTime(0,0)); + getTopoCoord().processWinElection(OID::gen(), Timestamp(0,0)); ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); @@ -3631,7 +3631,7 @@ namespace { BSON("_id" << 2 << "host" << "host3:27017"))), 0, Date_t(-1), - OpTime(10,0)); + Timestamp(10,0)); ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); @@ -3646,7 +3646,7 @@ namespace { "tags" << BSON("dc" << "NA" << "rack" << "rack1")))), 0, Date_t(-1), - OpTime(10,0)); + Timestamp(10,0)); ASSERT_TRUE(TopologyCoordinator::Role::leader == getTopoCoord().getRole()); ASSERT_EQUALS(MemberState::RS_PRIMARY, getTopoCoord().getMemberState().s); } @@ -3676,8 +3676,8 @@ namespace { } TEST_F(HeartbeatResponseTest, ReconfigBetweenHeartbeatRequestAndRepsonse) { - OpTime election = OpTime(14,0); - OpTime lastOpTimeApplied = OpTime(13,0); + Timestamp election = Timestamp(14,0); + Timestamp lastOpTimeApplied = Timestamp(13,0); // all three members up and secondaries setSelfMemberState(MemberState::RS_SECONDARY); @@ -3727,8 +3727,8 @@ namespace { } TEST_F(HeartbeatResponseTest, ReconfigNodeRemovedBetweenHeartbeatRequestAndRepsonse) { - OpTime election = OpTime(14,0); - OpTime lastOpTimeApplied = OpTime(13,0); + Timestamp election = Timestamp(14,0); + Timestamp lastOpTimeApplied = Timestamp(13,0); // all three members up and secondaries setSelfMemberState(MemberState::RS_SECONDARY); @@ -3793,10 +3793,10 @@ namespace { TEST_F(HeartbeatResponseTest, ShouldChangeSyncSourceFresherHappierMemberExists) { // In this test, the TopologyCoordinator should tell us to change sync sources away from // "host2" and to "host3" since "host2" is more than maxSyncSourceLagSecs(30) behind "host3" - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(4,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(4,0); // ahead by more than maxSyncSourceLagSecs (30) - OpTime fresherLastOpTimeApplied = OpTime(3005,0); + Timestamp fresherLastOpTimeApplied = Timestamp(3005,0); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), "rs0", @@ -3826,10 +3826,10 @@ namespace { // "host2" and to "host3" despite "host2" being more than maxSyncSourceLagSecs(30) behind // "host3", since "host3" is blacklisted // Then, confirm that unblacklisting only works if time has passed the blacklist time. - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(400,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(400,0); // ahead by more than maxSyncSourceLagSecs (30) - OpTime fresherLastOpTimeApplied = OpTime(3005,0); + Timestamp fresherLastOpTimeApplied = Timestamp(3005,0); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), "rs0", @@ -3867,10 +3867,10 @@ namespace { // In this test, the TopologyCoordinator should not tell us to change sync sources away from // "host2" and to "host3" despite "host2" being more than maxSyncSourceLagSecs(30) behind // "host3", since "host3" is down - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(400,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(400,0); // ahead by more than maxSyncSourceLagSecs (30) - OpTime fresherLastOpTimeApplied = OpTime(3005,0); + Timestamp fresherLastOpTimeApplied = Timestamp(3005,0); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), "rs0", @@ -3898,10 +3898,10 @@ namespace { // In this test, the TopologyCoordinator should not tell us to change sync sources away from // "host2" and to "host3" despite "host2" being more than maxSyncSourceLagSecs(30) behind // "host3", since "host3" is in a non-readable mode (RS_ROLLBACK) - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(4,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(4,0); // ahead by more than maxSyncSourceLagSecs (30) - OpTime fresherLastOpTimeApplied = OpTime(3005,0); + Timestamp fresherLastOpTimeApplied = Timestamp(3005,0); HeartbeatResponseAction nextAction = receiveUpHeartbeat(HostAndPort("host2"), "rs0", @@ -3927,10 +3927,10 @@ namespace { // In this test, the TopologyCoordinator should not tell us to change sync sources away from // "host2" and to "host3" despite "host2" being more than maxSyncSourceLagSecs(30) behind // "host3", since "host3" does not build indexes - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(4,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(4,0); // ahead by more than maxSyncSourceLagSecs (30) - OpTime fresherLastOpTimeApplied = OpTime(3005,0); + Timestamp fresherLastOpTimeApplied = Timestamp(3005,0); updateConfig(BSON("_id" << "rs0" << "version" << 6 << @@ -3963,10 +3963,10 @@ namespace { // In this test, the TopologyCoordinator should tell us to change sync sources away from // "host2" and to "host3" despite "host3" not building indexes because we do not build // indexes either and "host2" is more than maxSyncSourceLagSecs(30) behind "host3" - OpTime election = OpTime(0,0); - OpTime lastOpTimeApplied = OpTime(4,0); + Timestamp election = Timestamp(0,0); + Timestamp lastOpTimeApplied = Timestamp(4,0); // ahead by more than maxSyncSourceLagSecs (30) - OpTime fresherLastOpTimeApplied = OpTime(3005,0); + Timestamp fresherLastOpTimeApplied = Timestamp(3005,0); updateConfig(BSON("_id" << "rs0" << "version" << 7 << @@ -4009,8 +4009,8 @@ namespace { 0); setSelfMemberState(MemberState::RS_SECONDARY); - heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_PRIMARY, OpTime(1,0)); - ASSERT_FALSE(getTopoCoord().checkShouldStandForElection(now()++, OpTime(0,0))); + heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_PRIMARY, Timestamp(1,0)); + ASSERT_FALSE(getTopoCoord().checkShouldStandForElection(now()++, Timestamp(0,0))); } TEST_F(TopoCoordTest, CheckShouldStandForElectionNotCloseEnoughToLastOptime) { @@ -4023,8 +4023,8 @@ namespace { 0); setSelfMemberState(MemberState::RS_SECONDARY); - heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, OpTime(10000,0)); - ASSERT_FALSE(getTopoCoord().checkShouldStandForElection(now()++, OpTime(100,0))); + heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, Timestamp(10000,0)); + ASSERT_FALSE(getTopoCoord().checkShouldStandForElection(now()++, Timestamp(100,0))); } TEST_F(TopoCoordTest, VoteForMyselfFailsWhileNotCandidate) { @@ -4053,7 +4053,7 @@ namespace { TEST_F(TopoCoordTest, UnelectableIfAbsentFromConfig) { logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3)); startCapturingLogMessages(); - ASSERT_FALSE(getTopoCoord().checkShouldStandForElection(now()++, OpTime(10,0))); + ASSERT_FALSE(getTopoCoord().checkShouldStandForElection(now()++, Timestamp(10,0))); stopCapturingLogMessages(); ASSERT_EQUALS(1, countLogLinesContaining("not a member of a valid replica set config")); logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Log()); @@ -4068,7 +4068,7 @@ namespace { BSON("_id" << 30 << "host" << "h3"))), 0); setSelfMemberState(MemberState::RS_SECONDARY); - heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, OpTime(100,0)); + heartbeatFromMember(HostAndPort("h2"), "rs0", MemberState::RS_SECONDARY, Timestamp(100,0)); // vote for another node OID remoteRound = OID::gen(); @@ -4083,7 +4083,7 @@ namespace { BSONObjBuilder electResponseBuilder; Status result = Status(ErrorCodes::InternalError, "status not set by prepareElectResponse"); getTopoCoord().prepareElectResponse( - electArgs, now()++, OpTime(100,0), &electResponseBuilder, &result); + electArgs, now()++, Timestamp(100,0), &electResponseBuilder, &result); BSONObj response = electResponseBuilder.obj(); ASSERT_OK(result); std::cout << response; @@ -4092,7 +4092,7 @@ namespace { logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Debug(3)); startCapturingLogMessages(); - ASSERT_FALSE(getTopoCoord().checkShouldStandForElection(now()++, OpTime(10,0))); + ASSERT_FALSE(getTopoCoord().checkShouldStandForElection(now()++, Timestamp(10,0))); stopCapturingLogMessages(); ASSERT_EQUALS(1, countLogLinesContaining("I recently voted for ")); logger::globalLogDomain()->setMinimumLoggedSeverity(logger::LogSeverity::Log()); diff --git a/src/mongo/db/repl/update_position_args.cpp b/src/mongo/db/repl/update_position_args.cpp index 78b08bfc483..39b0aa762f9 100644 --- a/src/mongo/db/repl/update_position_args.cpp +++ b/src/mongo/db/repl/update_position_args.cpp @@ -40,7 +40,7 @@ namespace repl { UpdatePositionArgs::UpdateInfo::UpdateInfo( - const OID& anRid, const OpTime& aTs, long long aCfgver, long long aMemberId) + const OID& anRid, const Timestamp& aTs, long long aCfgver, long long aMemberId) : rid(anRid), ts(aTs), cfgver(aCfgver), memberId(aMemberId) {} namespace { @@ -93,8 +93,8 @@ namespace { if (!status.isOK()) return status; - OpTime ts; - status = bsonExtractOpTimeField(entry, kOpTimeFieldName, &ts); + Timestamp ts; + status = bsonExtractTimestampField(entry, kOpTimeFieldName, &ts); if (!status.isOK()) return status; diff --git a/src/mongo/db/repl/update_position_args.h b/src/mongo/db/repl/update_position_args.h index 9d9afebced2..e0fb6ebf805 100644 --- a/src/mongo/db/repl/update_position_args.h +++ b/src/mongo/db/repl/update_position_args.h @@ -44,10 +44,10 @@ namespace repl { class UpdatePositionArgs { public: struct UpdateInfo { - UpdateInfo(const OID& anRid, const OpTime& aTs, long long aCfgver, long long aMemberId); + UpdateInfo(const OID& anRid, const Timestamp& aTs, long long aCfgver, long long aMemberId); OID rid; - OpTime ts; + Timestamp ts; long long cfgver; long long memberId; }; diff --git a/src/mongo/db/storage/index_entry_comparison.h b/src/mongo/db/storage/index_entry_comparison.h index f12ea85c4f2..c1415c2fba2 100644 --- a/src/mongo/db/storage/index_entry_comparison.h +++ b/src/mongo/db/storage/index_entry_comparison.h @@ -30,9 +30,7 @@ #include <vector> -#include "mongo/bson/bsonelement.h" -#include "mongo/bson/bsonobj.h" -#include "mongo/bson/ordering.h" +#include "mongo/db/jsobj.h" #include "mongo/db/record_id.h" namespace mongo { diff --git a/src/mongo/db/storage/key_string.cpp b/src/mongo/db/storage/key_string.cpp index 13e7711a217..2b3391e1d42 100644 --- a/src/mongo/db/storage/key_string.cpp +++ b/src/mongo/db/storage/key_string.cpp @@ -143,7 +143,7 @@ namespace mongo { case jstOID: return CType::kOID; case Bool: return CType::kBool; case Date: return CType::kDate; - case Timestamp: return CType::kTimestamp; + case bsonTimestamp: return CType::kTimestamp; case RegEx: return CType::kRegEx; case DBRef: return CType::kDBRef; @@ -363,7 +363,7 @@ namespace mongo { _append(endian::nativeToBig(encoded), invert); } - void KeyString::_appendTimestamp(OpTime val, bool invert) { + void KeyString::_appendTimestamp(Timestamp val, bool invert) { _append(CType::kTimestamp, invert); _append(endian::nativeToBig(val.asLL()), invert); } @@ -558,7 +558,7 @@ namespace mongo { break; } case NumberInt: _appendNumberInt(elem._numberInt(), invert); break; - case Timestamp: _appendTimestamp(elem._opTime(), invert); break; + case bsonTimestamp: _appendTimestamp(elem.timestamp(), invert); break; case NumberLong: _appendNumberLong(elem._numberLong(), invert); break; default: @@ -740,7 +740,7 @@ namespace mongo { break; case CType::kTimestamp: - *stream << OpTime(endian::bigToNative(readType<uint64_t>(reader, inverted))); + *stream << Timestamp(endian::bigToNative(readType<uint64_t>(reader, inverted))); break; case CType::kOID: diff --git a/src/mongo/db/storage/key_string.h b/src/mongo/db/storage/key_string.h index 50b05141818..5bd9cf7c8a9 100644 --- a/src/mongo/db/storage/key_string.h +++ b/src/mongo/db/storage/key_string.h @@ -31,9 +31,8 @@ #include "mongo/bson/bsonobj.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/bson/bsonmisc.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/bson/ordering.h" -#include "mongo/bson/bson_db.h" #include "mongo/db/record_id.h" namespace mongo { @@ -248,7 +247,7 @@ namespace mongo { void _appendBool(bool val, bool invert); void _appendDate(Date_t val, bool invert); - void _appendTimestamp(OpTime val, bool invert); + void _appendTimestamp(Timestamp val, bool invert); void _appendOID(OID val, bool invert); void _appendString(StringData val, bool invert); void _appendSymbol(StringData val, bool invert); diff --git a/src/mongo/db/storage/key_string_test.cpp b/src/mongo/db/storage/key_string_test.cpp index 5d122844aeb..267f1ba6501 100644 --- a/src/mongo/db/storage/key_string_test.cpp +++ b/src/mongo/db/storage/key_string_test.cpp @@ -150,7 +150,7 @@ TEST(KeyStringTest, AllTypesSimple) { ROUNDTRIP(BSON("" << BSONCode("abc_code"))); ROUNDTRIP(BSON("" << BSONCodeWScope("def_code", BSON("x_scope" << "a")))); ROUNDTRIP(BSON("" << 5)); - ROUNDTRIP(BSON("" << OpTime(123123, 123))); + ROUNDTRIP(BSON("" << Timestamp(123123, 123))); ROUNDTRIP(BSON("" << 1235123123123LL)); } @@ -310,12 +310,12 @@ TEST(KeyStringTest, RecordIdOrder2Double) { ASSERT_LESS_THAN(a, c); } -TEST(KeyStringTest, OpTime) { +TEST(KeyStringTest, Timestamp) { - BSONObj a = BSON("" << OpTime(0, 0)); - BSONObj b = BSON("" << OpTime(1234, 1)); - BSONObj c = BSON("" << OpTime(1234, 2)); - BSONObj d = BSON("" << OpTime(1235, 1)); + BSONObj a = BSON("" << Timestamp(0, 0)); + BSONObj b = BSON("" << Timestamp(1234, 1)); + BSONObj c = BSON("" << Timestamp(1234, 2)); + BSONObj d = BSON("" << Timestamp(1235, 1)); { ROUNDTRIP(a); diff --git a/src/mongo/db/storage/mmap_v1/btree/key.cpp b/src/mongo/db/storage/mmap_v1/btree/key.cpp index 0ee18f614ac..c49e944ceb3 100644 --- a/src/mongo/db/storage/mmap_v1/btree/key.cpp +++ b/src/mongo/db/storage/mmap_v1/btree/key.cpp @@ -65,7 +65,7 @@ namespace mongo { return 0; case Bool: return *l.value() - *r.value(); - case Timestamp: + case bsonTimestamp: case Date: // unsigned dates for old version if ( l.date() < r.date() ) diff --git a/src/mongo/db/storage/mmap_v1/dur_preplogbuffer.cpp b/src/mongo/db/storage/mmap_v1/dur_preplogbuffer.cpp index 1a0d03d96a4..73583a77ef7 100644 --- a/src/mongo/db/storage/mmap_v1/dur_preplogbuffer.cpp +++ b/src/mongo/db/storage/mmap_v1/dur_preplogbuffer.cpp @@ -39,6 +39,7 @@ #include "mongo/platform/basic.h" #include <boost/shared_ptr.hpp> +#include <boost/thread.hpp> #include "mongo/db/storage/mmap_v1/aligned_builder.h" #include "mongo/db/storage/mmap_v1/durable_mapped_file.h" diff --git a/src/mongo/db/storage/oplog_hack.cpp b/src/mongo/db/storage/oplog_hack.cpp index 0bee74310f7..b25268e4271 100644 --- a/src/mongo/db/storage/oplog_hack.cpp +++ b/src/mongo/db/storage/oplog_hack.cpp @@ -34,7 +34,7 @@ #include <limits> #include "mongo/bson/bson_validate.h" -#include "mongo/bson/optime.h" +#include "mongo/bson/timestamp.h" #include "mongo/db/jsobj.h" #include "mongo/db/record_id.h" #include "mongo/util/debug_util.h" @@ -42,7 +42,7 @@ namespace mongo { namespace oploghack { - StatusWith<RecordId> keyForOptime(const OpTime& opTime) { + StatusWith<RecordId> keyForOptime(const Timestamp& opTime) { // Make sure secs and inc wouldn't be negative if treated as signed. This ensures that they // don't sort differently when put in a RecordId. It also avoids issues with Null/Invalid // RecordIds @@ -71,10 +71,10 @@ namespace oploghack { const BSONElement elem = obj["ts"]; if (elem.eoo()) return StatusWith<RecordId>(ErrorCodes::BadValue, "no ts field"); - if (elem.type() != Timestamp) + if (elem.type() != bsonTimestamp) return StatusWith<RecordId>(ErrorCodes::BadValue, "ts must be a Timestamp"); - return keyForOptime(elem._opTime()); + return keyForOptime(elem.timestamp()); } } // namespace oploghack diff --git a/src/mongo/db/storage/oplog_hack.h b/src/mongo/db/storage/oplog_hack.h index 20708c1db4c..92138959304 100644 --- a/src/mongo/db/storage/oplog_hack.h +++ b/src/mongo/db/storage/oplog_hack.h @@ -33,15 +33,15 @@ namespace mongo { class RecordId; - class OpTime; + class Timestamp; namespace oploghack { /** - * Converts OpTime to a RecordId in an unspecified manor that is safe to use as the key to in a - * RecordStore. + * Converts Timestamp to a RecordId in an unspecified manor that is safe to use as the key to + * in a RecordStore. */ - StatusWith<RecordId> keyForOptime(const OpTime& opTime); + StatusWith<RecordId> keyForOptime(const Timestamp& opTime); /** * data and len must be the arguments from RecordStore::insert() on an oplog collection. diff --git a/src/mongo/db/storage/record_store.h b/src/mongo/db/storage/record_store.h index 48e5aec5e06..f0a09eb67fd 100644 --- a/src/mongo/db/storage/record_store.h +++ b/src/mongo/db/storage/record_store.h @@ -343,7 +343,7 @@ namespace mongo { * they are ordered. */ virtual Status oplogDiskLocRegister( OperationContext* txn, - const OpTime& opTime ) { + const Timestamp& opTime ) { return Status::OK(); } diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp index ee440b67216..c53686fa623 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.cpp @@ -863,7 +863,7 @@ namespace { } Status WiredTigerRecordStore::oplogDiskLocRegister( OperationContext* txn, - const OpTime& opTime ) { + const Timestamp& opTime ) { StatusWith<RecordId> loc = oploghack::keyForOptime( opTime ); if ( !loc.isOK() ) return loc.getStatus(); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h index 6defe3552fa..5447425ca9b 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store.h @@ -182,7 +182,7 @@ namespace mongo { const RecordId& startingPosition) const; virtual Status oplogDiskLocRegister( OperationContext* txn, - const OpTime& opTime ); + const Timestamp& opTime ); virtual void updateStatsAfterRepair(OperationContext* txn, long long numRecords, diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp index b944e38329d..d8f8d6cc016 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_record_store_test.cpp @@ -515,7 +515,7 @@ namespace { StatusWith<RecordId> insertBSON(scoped_ptr<OperationContext>& opCtx, scoped_ptr<RecordStore>& rs, - const OpTime& opTime) { + const Timestamp& opTime) { BSONObj obj = BSON( "ts" << opTime ); WriteUnitOfWork wuow(opCtx.get()); WiredTigerRecordStore* wrs = checked_cast<WiredTigerRecordStore*>(rs.get()); @@ -540,33 +540,33 @@ namespace { scoped_ptr<OperationContext> opCtx(harnessHelper.newOperationContext()); // always illegal - ASSERT_EQ(insertBSON(opCtx, rs, OpTime(2,-1)).getStatus(), + ASSERT_EQ(insertBSON(opCtx, rs, Timestamp(2,-1)).getStatus(), ErrorCodes::BadValue); { - BSONObj obj = BSON("not_ts" << OpTime(2,1)); + BSONObj obj = BSON("not_ts" << Timestamp(2,1)); ASSERT_EQ(rs->insertRecord(opCtx.get(), obj.objdata(), obj.objsize(), false ).getStatus(), ErrorCodes::BadValue); - obj = BSON( "ts" << "not an OpTime" ); + obj = BSON( "ts" << "not a Timestamp" ); ASSERT_EQ(rs->insertRecord(opCtx.get(), obj.objdata(), obj.objsize(), false ).getStatus(), ErrorCodes::BadValue); } // currently dasserts - // ASSERT_EQ(insertBSON(opCtx, rs, BSON("ts" << OpTime(-2,1))).getStatus(), + // ASSERT_EQ(insertBSON(opCtx, rs, BSON("ts" << Timestamp(-2,1))).getStatus(), // ErrorCodes::BadValue); // success cases - ASSERT_EQ(insertBSON(opCtx, rs, OpTime(1,1)).getValue(), + ASSERT_EQ(insertBSON(opCtx, rs, Timestamp(1,1)).getValue(), RecordId(1,1)); - ASSERT_EQ(insertBSON(opCtx, rs, OpTime(1,2)).getValue(), + ASSERT_EQ(insertBSON(opCtx, rs, Timestamp(1,2)).getValue(), RecordId(1,2)); - ASSERT_EQ(insertBSON(opCtx, rs, OpTime(2,2)).getValue(), + ASSERT_EQ(insertBSON(opCtx, rs, Timestamp(2,2)).getValue(), RecordId(2,2)); } @@ -628,7 +628,7 @@ namespace { scoped_ptr<OperationContext> opCtx(harnessHelper.newOperationContext()); - BSONObj obj = BSON( "ts" << OpTime(2,-1) ); + BSONObj obj = BSON( "ts" << Timestamp(2,-1) ); { WriteUnitOfWork wuow( opCtx.get() ); ASSERT_OK(rs->insertRecord(opCtx.get(), obj.objdata(), @@ -746,7 +746,7 @@ namespace { RecordId _oplogOrderInsertOplog( OperationContext* txn, scoped_ptr<RecordStore>& rs, int inc ) { - OpTime opTime = OpTime(5,inc); + Timestamp opTime = Timestamp(5,inc); WiredTigerRecordStore* wrs = checked_cast<WiredTigerRecordStore*>(rs.get()); Status status = wrs->oplogDiskLocRegister( txn, opTime ); ASSERT_OK( status ); diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp index 12c3380e760..7673bcddbac 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_session_cache.cpp @@ -31,6 +31,8 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage +#include <boost/thread.hpp> + #include "mongo/db/storage/wiredtiger/wiredtiger_session_cache.h" #include "mongo/db/storage/wiredtiger/wiredtiger_kv_engine.h" diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp index 8d61fb17712..5d0affb7305 100644 --- a/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp +++ b/src/mongo/db/storage/wiredtiger/wiredtiger_size_storer.cpp @@ -31,6 +31,7 @@ #define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kStorage +#include <boost/thread.hpp> #include <wiredtiger.h> #include "mongo/bson/bsonobj.h" diff --git a/src/mongo/db/write_concern.cpp b/src/mongo/db/write_concern.cpp index 8b1b7334813..a16352b34fc 100644 --- a/src/mongo/db/write_concern.cpp +++ b/src/mongo/db/write_concern.cpp @@ -191,7 +191,7 @@ namespace mongo { } Status waitForWriteConcern( OperationContext* txn, - const OpTime& replOpTime, + const Timestamp& replOpTime, WriteConcernResult* result ) { const WriteConcernOptions& writeConcern = txn->getWriteConcern(); diff --git a/src/mongo/db/write_concern.h b/src/mongo/db/write_concern.h index c287d1ff8fd..0f375c9c069 100644 --- a/src/mongo/db/write_concern.h +++ b/src/mongo/db/write_concern.h @@ -94,7 +94,7 @@ namespace mongo { * Returns UnknownReplWriteConcern if the wMode specified was not enforceable */ Status waitForWriteConcern( OperationContext* txn, - const OpTime& replOpTime, + const Timestamp& replOpTime, WriteConcernResult* result ); diff --git a/src/mongo/db/write_concern_options.cpp b/src/mongo/db/write_concern_options.cpp index 5c0102ebc4a..50bf9cad040 100644 --- a/src/mongo/db/write_concern_options.cpp +++ b/src/mongo/db/write_concern_options.cpp @@ -27,9 +27,9 @@ #include "mongo/db/write_concern_options.h" -#include "mongo/bson/bson_field.h" #include "mongo/client/dbclientinterface.h" #include "mongo/db/field_parser.h" +#include "mongo/db/jsobj.h" namespace mongo { |