diff options
author | Wenbin Zhu <wenbin.zhu@mongodb.com> | 2021-03-26 21:20:53 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2021-03-31 20:11:20 +0000 |
commit | fef36dd6aa1ca9af511996511dfe757b3d8167fc (patch) | |
tree | 6661c9921b38ff683c861eb2b8c7403cc5e71289 /src/mongo/db/repl | |
parent | 47f28ebf7feb4c37e9bdf07d0356d389c75ad5f3 (diff) | |
download | mongo-fef36dd6aa1ca9af511996511dfe757b3d8167fc.tar.gz |
SERVER-55070 Separate OpTime and WallTime in IDL, aviod parsing entire oplog entry if possible.
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r-- | src/mongo/db/repl/SConscript | 10 | ||||
-rw-r--r-- | src/mongo/db/repl/initial_syncer_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_applier_impl_test.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_entry.h | 8 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_entry.idl | 10 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_entry_test.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_fetcher_test.cpp | 9 | ||||
-rw-r--r-- | src/mongo/db/repl/oplog_interface_remote.cpp | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/optime.cpp | 54 | ||||
-rw-r--r-- | src/mongo/db/repl/optime.h | 20 | ||||
-rw-r--r-- | src/mongo/db/repl/optime_base.idl (renamed from src/mongo/db/repl/optime_and_wall_time_base.idl) | 14 | ||||
-rw-r--r-- | src/mongo/db/repl/optime_extract_test.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_coordinator_impl_test.cpp | 28 | ||||
-rw-r--r-- | src/mongo/db/repl/replication_recovery.cpp | 11 | ||||
-rw-r--r-- | src/mongo/db/repl/rollback_impl.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/repl/sync_source_resolver_test.cpp | 4 |
16 files changed, 98 insertions, 96 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index 9060306c408..ca282bf0c85 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -518,17 +518,17 @@ env.Library( '$BUILD_DIR/mongo/db/exec/document_value/document_value', '$BUILD_DIR/mongo/idl/idl_parser', 'optime', - 'optime_and_wall_time_base', + 'optime_base', ], - LIBDEPS_PRIVATE=[ + LIBDEPS_PRIVATE=[ '$BUILD_DIR/mongo/db/namespace_string', ], ) env.Library( - target='optime_and_wall_time_base', + target='optime_base', source=[ - 'optime_and_wall_time_base.idl', + 'optime_base.idl' ], LIBDEPS=[ '$BUILD_DIR/mongo/base', @@ -1048,7 +1048,7 @@ env.Library( LIBDEPS=[ '$BUILD_DIR/mongo/base', '$BUILD_DIR/mongo/bson/util/bson_extract', - 'optime_and_wall_time_base', + 'optime_base', ], ) diff --git a/src/mongo/db/repl/initial_syncer_test.cpp b/src/mongo/db/repl/initial_syncer_test.cpp index c318f16dd1f..2ac0be9e375 100644 --- a/src/mongo/db/repl/initial_syncer_test.cpp +++ b/src/mongo/db/repl/initial_syncer_test.cpp @@ -2858,7 +2858,7 @@ TEST_F( // Oplog entry associated with the stopTimestamp. processSuccessfulLastOplogEntryFetcherResponse({BSON("ts" << "not a timestamp" - << "t" << 1)}); + << "t" << 1LL)}); // _lastOplogEntryFetcherCallbackAfterCloningData() will shut down the OplogFetcher after // setting the completion status. diff --git a/src/mongo/db/repl/oplog_applier_impl_test.cpp b/src/mongo/db/repl/oplog_applier_impl_test.cpp index f81d3ec3fe8..bf06beebfdb 100644 --- a/src/mongo/db/repl/oplog_applier_impl_test.cpp +++ b/src/mongo/db/repl/oplog_applier_impl_test.cpp @@ -2346,7 +2346,7 @@ TEST_F(OplogApplierImplTest, LogSlowOpApplicationWhenSuccessful) { ASSERT_EQUALS( 1, countBSONFormatLogLinesIsSubset(BSON( - "attr" << BSON("CRUD" << BSON("ts" << Timestamp(1, 1) << "t" << 1 << "v" << 2 << "op" + "attr" << BSON("CRUD" << BSON("ts" << Timestamp(1, 1) << "t" << 1LL << "v" << 2 << "op" << "i" << "ns" << "test.t" diff --git a/src/mongo/db/repl/oplog_entry.h b/src/mongo/db/repl/oplog_entry.h index 7bbea0505bd..be85307b550 100644 --- a/src/mongo/db/repl/oplog_entry.h +++ b/src/mongo/db/repl/oplog_entry.h @@ -178,15 +178,11 @@ public: } void setTimestamp(Timestamp value) & { - getOpTimeAndWallTimeBase().setTimestamp(std::move(value)); + getOpTimeBase().setTimestamp(std::move(value)); } void setTerm(boost::optional<std::int64_t> value) & { - getOpTimeAndWallTimeBase().setTerm(std::move(value)); - } - - void setWallClockTime(Date_t value) & { - getOpTimeAndWallTimeBase().setWallClockTime(std::move(value)); + getOpTimeBase().setTerm(std::move(value)); } void setDestinedRecipient(boost::optional<ShardId> value) { diff --git a/src/mongo/db/repl/oplog_entry.idl b/src/mongo/db/repl/oplog_entry.idl index 2f9d256b59f..7ed58a1d353 100644 --- a/src/mongo/db/repl/oplog_entry.idl +++ b/src/mongo/db/repl/oplog_entry.idl @@ -35,7 +35,7 @@ imports: - "mongo/idl/basic_types.idl" - "mongo/db/logical_session_id.idl" - "mongo/db/pipeline/value.idl" - - "mongo/db/repl/optime_and_wall_time_base.idl" + - "mongo/db/repl/optime_base.idl" - "mongo/db/repl/replication_types.idl" - "mongo/s/sharding_types.idl" @@ -102,9 +102,9 @@ structs: description: A document in which the server stores an oplog entry. inline_chained_structs: true chained_structs: - OperationSessionInfo : OperationSessionInfo + OperationSessionInfo: OperationSessionInfo DurableReplOperation: DurableReplOperation - OpTimeAndWallTimeBase: OpTimeAndWallTimeBase + OpTimeBase: OpTimeBase fields: h: cpp_name: hash @@ -116,6 +116,10 @@ structs: type: safeInt64 default: 2 description: "The version of the oplog" + wall: + cpp_name: wallClockTime + type: date + description: "A wallclock time with MS resolution" fromMigrate: type: bool optional: true diff --git a/src/mongo/db/repl/oplog_entry_test.cpp b/src/mongo/db/repl/oplog_entry_test.cpp index ffb95e8ff1e..c034bd3c517 100644 --- a/src/mongo/db/repl/oplog_entry_test.cpp +++ b/src/mongo/db/repl/oplog_entry_test.cpp @@ -104,16 +104,16 @@ TEST(OplogEntryTest, Create) { ASSERT_EQ(entry.getOpTime(), entryOpTime); } -TEST(OplogEntryTest, OpTimeAndWallTimeBaseNonStrictParsing) { +TEST(OplogEntryTest, OpTimeBaseNonStrictParsing) { const BSONObj oplogEntryExtraField = BSON("ts" << Timestamp(0, 0) << "t" << 0LL << "op" << "c" << "ns" << nss.ns() << "wall" << Date_t() << "o" << BSON("_id" << 1) << "extraField" << 3); - // OpTimeAndWallTimeBase should be successfully created from an OplogEntry, even though it has + // OpTimeBase should be successfully created from an OplogEntry, even though it has // extraneous fields. - UNIT_TEST_INTERNALS_IGNORE_UNUSED_RESULT_WARNINGS(OpTimeAndWallTimeBase::parse( - IDLParserErrorContext("OpTimeAndWallTimeBase"), oplogEntryExtraField)); + UNIT_TEST_INTERNALS_IGNORE_UNUSED_RESULT_WARNINGS( + OpTimeBase::parse(IDLParserErrorContext("OpTimeBase"), oplogEntryExtraField)); // OplogEntryBase should still use strict parsing and throw an error when it has extraneous // fields. diff --git a/src/mongo/db/repl/oplog_fetcher_test.cpp b/src/mongo/db/repl/oplog_fetcher_test.cpp index 5eabd460b8c..83dad6b6138 100644 --- a/src/mongo/db/repl/oplog_fetcher_test.cpp +++ b/src/mongo/db/repl/oplog_fetcher_test.cpp @@ -1115,7 +1115,7 @@ TEST_F(OplogFetcherTest, RemoteFirstOplogEntryWithExtraFieldsReturnsOplogStartMi auto entry = makeNoopOplogEntry(Seconds(456)); // Set the remote node's first oplog entry to include extra fields. - auto remoteFirstOplogEntry = BSON("ts" << Timestamp(1, 0) << "t" << 1 << "extra" + auto remoteFirstOplogEntry = BSON("ts" << Timestamp(1, 0) << "t" << 1LL << "extra" << "field"); _mockServer->insert(nss.ns(), remoteFirstOplogEntry); @@ -1728,8 +1728,10 @@ TEST_F(OplogFetcherTest, CursorId cursorId = 22LL; auto firstEntry = makeNoopOplogEntry(lastFetched); auto metadataObj = makeOplogBatchMetadata(replSetMetadata, oqMetadata); + + auto missingFieldErrorCode = ErrorCodes::duplicateCodeForTest(40414); ASSERT_EQUALS( - ErrorCodes::NoSuchKey, + missingFieldErrorCode, processSingleBatch(makeFirstBatch(cursorId, {firstEntry, BSON("o" << BSON("msg" @@ -1992,7 +1994,8 @@ TEST_F(OplogFetcherTest, ValidateDocumentsReturnsNoSuchKeyIfTimestampIsNotFoundI auto secondEntry = BSON("o" << BSON("msg" << "oplog entry without optime")); - ASSERT_EQUALS(ErrorCodes::NoSuchKey, + auto missingFieldErrorCode = ErrorCodes::duplicateCodeForTest(40414); + ASSERT_EQUALS(missingFieldErrorCode, OplogFetcher::validateDocuments( {firstEntry, secondEntry}, true, diff --git a/src/mongo/db/repl/oplog_interface_remote.cpp b/src/mongo/db/repl/oplog_interface_remote.cpp index 883596318b9..2008daae903 100644 --- a/src/mongo/db/repl/oplog_interface_remote.cpp +++ b/src/mongo/db/repl/oplog_interface_remote.cpp @@ -82,7 +82,7 @@ std::string OplogInterfaceRemote::toString() const { std::unique_ptr<OplogInterface::Iterator> OplogInterfaceRemote::makeIterator() const { const Query query = Query().sort(BSON("$natural" << -1)); - const BSONObj fields = BSON("ts" << 1 << "t" << 1); + const BSONObj fields = BSON("ts" << 1 << "t" << 1LL); return std::unique_ptr<OplogInterface::Iterator>( new OplogIteratorRemote(_getConnection()->query(NamespaceString(_collectionName), query, diff --git a/src/mongo/db/repl/optime.cpp b/src/mongo/db/repl/optime.cpp index 683203a4c88..30a9b9f3d4f 100644 --- a/src/mongo/db/repl/optime.cpp +++ b/src/mongo/db/repl/optime.cpp @@ -37,41 +37,31 @@ #include "mongo/bson/util/bson_extract.h" #include "mongo/db/repl/oplog.h" #include "mongo/db/repl/optime.h" -#include "mongo/db/repl/optime_and_wall_time_base_gen.h" +#include "mongo/db/repl/optime_base_gen.h" namespace mongo { namespace repl { -const char OpTime::kTimestampFieldName[] = "ts"; -const char OpTime::kTermFieldName[] = "t"; -const long long OpTime::kInitialTerm = 0; - // static OpTime OpTime::max() { - return OpTime(Timestamp::max(), std::numeric_limits<decltype(OpTime::_term)>::max()); + return OpTime(Timestamp::max(), std::numeric_limits<long long>::max()); } void OpTime::append(BSONObjBuilder* builder, const std::string& subObjName) const { BSONObjBuilder opTimeBuilder(builder->subobjStart(subObjName)); opTimeBuilder.append(kTimestampFieldName, _timestamp); - opTimeBuilder.append(kTermFieldName, _term); opTimeBuilder.doneFast(); } StatusWith<OpTime> OpTime::parseFromOplogEntry(const BSONObj& obj) { - Timestamp ts; - Status status = bsonExtractTimestampField(obj, kTimestampFieldName, &ts); - if (!status.isOK()) - return status; - - // Default to -1 if the term is absent. - long long term; - status = bsonExtractIntegerFieldWithDefault(obj, kTermFieldName, kUninitializedTerm, &term); - if (!status.isOK()) - return status; - - return OpTime(ts, term); + try { + OpTimeBase base = OpTimeBase::parse(IDLParserErrorContext("OpTimeBase"), obj); + long long term = base.getTerm().value_or(kUninitializedTerm); + return OpTime(base.getTimestamp(), term); + } catch (...) { + return exceptionToStatus(); + } } BSONObj OpTime::toBSON() const { @@ -115,22 +105,26 @@ BSONObj OpTime::asQuery() const { } StatusWith<OpTimeAndWallTime> OpTimeAndWallTime::parseOpTimeAndWallTimeFromOplogEntry( - const BSONObj& bsonObject) { + const BSONObj& obj) { - try { - OpTimeAndWallTimeBase base = OpTimeAndWallTimeBase::parse( - IDLParserErrorContext("OpTimeAndWallTimeBase"), bsonObject); + auto opTimeStatus = OpTime::parseFromOplogEntry(obj); - long long term = OpTime::kUninitializedTerm; + if (!opTimeStatus.isOK()) { + return opTimeStatus.getStatus(); + } - if (base.getTerm()) { - term = base.getTerm().get(); - } + BSONElement wall; + auto wallStatus = bsonExtractTypedField(obj, kWallClockTimeFieldName, BSONType::Date, &wall); - return OpTimeAndWallTime(OpTime(base.getTimestamp(), term), base.getWallClockTime()); - } catch (...) { - return exceptionToStatus(); + if (!wallStatus.isOK()) { + return wallStatus; } + + return OpTimeAndWallTime(opTimeStatus.getValue(), wall.Date()); +} + +OpTimeAndWallTime OpTimeAndWallTime::parse(const BSONObj& obj) { + return uassertStatusOK(parseOpTimeAndWallTimeFromOplogEntry(obj)); } } // namespace repl diff --git a/src/mongo/db/repl/optime.h b/src/mongo/db/repl/optime.h index 9cead491d25..9f999f40a1a 100644 --- a/src/mongo/db/repl/optime.h +++ b/src/mongo/db/repl/optime.h @@ -52,8 +52,8 @@ namespace repl { class OpTime { public: - static const char kTimestampFieldName[]; - static const char kTermFieldName[]; + static constexpr auto kTermFieldName = "t"_sd; + static constexpr auto kTimestampFieldName = "ts"_sd; // The term of an OpTime generated by old protocol version. static constexpr long long kUninitializedTerm = -1; @@ -62,7 +62,7 @@ public: // // This is also the initial term for nodes that were recently started up but have not // yet joined the cluster, all in protocol version 1. - static const long long kInitialTerm; + static constexpr long long kInitialTerm = 0; /** * Returns maximum OpTime value. @@ -161,11 +161,21 @@ private: class OpTimeAndWallTime { public: + static constexpr auto kWallClockTimeFieldName = "wall"_sd; + OpTime opTime = OpTime(); Date_t wallTime = Date_t(); - static StatusWith<OpTimeAndWallTime> parseOpTimeAndWallTimeFromOplogEntry( - const BSONObj& bsonObject); + /** + * Parses OpTime and WallTime from a document. + */ + static StatusWith<OpTimeAndWallTime> parseOpTimeAndWallTimeFromOplogEntry(const BSONObj& obj); + + /** + * Parses OpTime and WallTime from a document. + * Throws an exception on error. + */ + static OpTimeAndWallTime parse(const BSONObj& obj); OpTimeAndWallTime() {} diff --git a/src/mongo/db/repl/optime_and_wall_time_base.idl b/src/mongo/db/repl/optime_base.idl index f444dd07520..755510ae41b 100644 --- a/src/mongo/db/repl/optime_and_wall_time_base.idl +++ b/src/mongo/db/repl/optime_base.idl @@ -25,7 +25,7 @@ # exception statement from all source files in the program, then also delete # it in the license file. -# This IDL file specifies the fields for OpTimeAndWallTimeBase. +# This IDL file specifies the fields for OpTimeBase. global: cpp_namespace: "mongo::repl" @@ -34,10 +34,10 @@ imports: - "mongo/idl/basic_types.idl" structs: - OpTimeAndWallTimeBase: - description: "A document that stores the time-related fields in an oplog entry. Should - never be used directly in server code. Instead, create an instance of - OpTimeAndWallTime." + OpTimeBase: + description: "A document that stores the logical time-related fields in an oplog entry. + Should never be used directly in server code. Instead, create an instance + of OpTime." strict: false fields: ts: @@ -49,7 +49,3 @@ structs: type: long optional: true # The term will no longer be optional, see SERVER-42258. description: "The term of the primary that created the oplog entry" - wall: - cpp_name: wallClockTime - type: date - description: "A wallclock time with MS resolution" diff --git a/src/mongo/db/repl/optime_extract_test.cpp b/src/mongo/db/repl/optime_extract_test.cpp index 9192738a31c..fe47e9ac7a1 100644 --- a/src/mongo/db/repl/optime_extract_test.cpp +++ b/src/mongo/db/repl/optime_extract_test.cpp @@ -40,7 +40,7 @@ using namespace mongo; TEST(ExtractBSON, ExtractOpTimeField) { // Outer object cases. - BSONObj obj = BSON("a" << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "b" + BSONObj obj = BSON("a" << BSON("ts" << Timestamp(10, 0) << "t" << 2LL) << "b" << "notAnObj"); repl::OpTime opTime; ASSERT_OK(bsonExtractOpTimeField(obj, "a", &opTime)); @@ -51,10 +51,10 @@ TEST(ExtractBSON, ExtractOpTimeField) { // Missing timestamp field. obj = BSON("a" << BSON("ts" << "notATimestamp" - << "t" << 2)); + << "t" << 2LL)); ASSERT_EQUALS(ErrorCodes::TypeMismatch, bsonExtractOpTimeField(obj, "a", &opTime)); // Wrong typed timestamp field. - obj = BSON("a" << BSON("t" << 2)); + obj = BSON("a" << BSON("t" << 2LL)); ASSERT_EQUALS(ErrorCodes::NoSuchKey, bsonExtractOpTimeField(obj, "a", &opTime)); // Missing term field. obj = BSON("a" << BSON("ts" << Timestamp(10, 0) << "t" diff --git a/src/mongo/db/repl/replication_coordinator_impl_test.cpp b/src/mongo/db/repl/replication_coordinator_impl_test.cpp index 2410e113f8e..c994c1c3b76 100644 --- a/src/mongo/db/repl/replication_coordinator_impl_test.cpp +++ b/src/mongo/db/repl/replication_coordinator_impl_test.cpp @@ -5980,9 +5980,9 @@ TEST_F(ReplCoordTest, DoNotIgnoreTheContentsOfMetadataWhenItsConfigVersionDoesNo auto lowerConfigVersion = 1; StatusWith<rpc::ReplSetMetadata> metadata = rpc::ReplSetMetadata::readFromMetadata(BSON( rpc::kReplSetMetadataFieldName << BSON( - "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "lastCommittedWall" + "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 2LL) << "lastCommittedWall" << Date_t() + Seconds(100) << "lastOpVisible" - << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "configVersion" + << BSON("ts" << Timestamp(10, 0) << "t" << 2LL) << "configVersion" << lowerConfigVersion << "configTerm" << 2 << "term" << 2 << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata.getValue()); @@ -5993,9 +5993,9 @@ TEST_F(ReplCoordTest, DoNotIgnoreTheContentsOfMetadataWhenItsConfigVersionDoesNo auto higherConfigVersion = 100; StatusWith<rpc::ReplSetMetadata> metadata2 = rpc::ReplSetMetadata::readFromMetadata(BSON( rpc::kReplSetMetadataFieldName << BSON( - "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "lastCommittedWall" + "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 2LL) << "lastCommittedWall" << Date_t() + Seconds(100) << "lastOpVisible" - << BSON("ts" << Timestamp(10, 0) << "t" << 2) << "configVersion" + << BSON("ts" << Timestamp(10, 0) << "t" << 2LL) << "configVersion" << higherConfigVersion << "configTerm" << 2 << "term" << 2 << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata2.getValue()); @@ -6069,9 +6069,9 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr // Higher term, should change. StatusWith<rpc::ReplSetMetadata> metadata = rpc::ReplSetMetadata::readFromMetadata(BSON( rpc::kReplSetMetadataFieldName - << BSON("lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3) + << BSON("lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3LL) << "lastCommittedWall" << Date_t() + Seconds(100) - << "lastOpVisible" << BSON("ts" << Timestamp(10, 0) << "t" << 3) + << "lastOpVisible" << BSON("ts" << Timestamp(10, 0) << "t" << 3LL) << "configVersion" << 2 << "configTerm" << 2 << "term" << 3 << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata.getValue()); @@ -6082,9 +6082,9 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr // Lower term, should not change. StatusWith<rpc::ReplSetMetadata> metadata2 = rpc::ReplSetMetadata::readFromMetadata(BSON( rpc::kReplSetMetadataFieldName - << BSON("lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3) + << BSON("lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3LL) << "lastCommittedWall" << Date_t() + Seconds(100) - << "lastOpVisible" << BSON("ts" << Timestamp(11, 0) << "t" << 3) + << "lastOpVisible" << BSON("ts" << Timestamp(11, 0) << "t" << 3LL) << "configVersion" << 2 << "configTerm" << 2 << "term" << 2 << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata2.getValue()); @@ -6095,9 +6095,9 @@ TEST_F(ReplCoordTest, UpdateTermWhenTheTermFromMetadataIsNewerButNeverUpdateCurr // Same term, should not change. StatusWith<rpc::ReplSetMetadata> metadata3 = rpc::ReplSetMetadata::readFromMetadata(BSON( rpc::kReplSetMetadataFieldName - << BSON("lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3) + << BSON("lastOpCommitted" << BSON("ts" << Timestamp(11, 0) << "t" << 3LL) << "lastCommittedWall" << Date_t() + Seconds(100) - << "lastOpVisible" << BSON("ts" << Timestamp(11, 0) << "t" << 3) + << "lastOpVisible" << BSON("ts" << Timestamp(11, 0) << "t" << 3LL) << "configVersion" << 2 << "configTerm" << 2 << "term" << 3 << "syncSourceIndex" << 1 << "isPrimary" << true))); getReplCoord()->processReplSetMetadata(metadata3.getValue()); @@ -6133,9 +6133,9 @@ TEST_F(ReplCoordTest, // Higher term - should update term but not last committed optime. StatusWith<rpc::ReplSetMetadata> metadata = rpc::ReplSetMetadata::readFromMetadata(BSON( rpc::kReplSetMetadataFieldName << BSON( - "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3) << "lastCommittedWall" + "lastOpCommitted" << BSON("ts" << Timestamp(10, 0) << "t" << 3LL) << "lastCommittedWall" << Date_t() + Seconds(100) << "lastOpVisible" - << BSON("ts" << Timestamp(10, 0) << "t" << 3) << "configVersion" + << BSON("ts" << Timestamp(10, 0) << "t" << 3LL) << "configVersion" << config.getConfigVersion() << "configTerm" << config.getConfigTerm() << "term" << 3 << "syncSourceIndex" << 1 << "isPrimary" << true))); BSONObjBuilder responseBuilder; @@ -6272,9 +6272,9 @@ TEST_F(ReplCoordTest, TermAndLastCommittedOpTimeUpdatedFromHeartbeatWhenArbiter) // commit point via heartbeats. StatusWith<rpc::ReplSetMetadata> metadata = rpc::ReplSetMetadata::readFromMetadata(BSON( rpc::kReplSetMetadataFieldName << BSON( - "lastOpCommitted" << BSON("ts" << Timestamp(10, 1) << "t" << 3) << "lastCommittedWall" + "lastOpCommitted" << BSON("ts" << Timestamp(10, 1) << "t" << 3LL) << "lastCommittedWall" << Date_t() + Seconds(100) << "lastOpVisible" - << BSON("ts" << Timestamp(10, 1) << "t" << 3) << "configVersion" + << BSON("ts" << Timestamp(10, 1) << "t" << 3LL) << "configVersion" << config.getConfigVersion() << "configTerm" << config.getConfigTerm() << "term" << 3 << "syncSourceIndex" << 1 << "isPrimary" << true))); BSONObjBuilder responseBuilder; diff --git a/src/mongo/db/repl/replication_recovery.cpp b/src/mongo/db/repl/replication_recovery.cpp index b954adf4d1f..2355148df65 100644 --- a/src/mongo/db/repl/replication_recovery.cpp +++ b/src/mongo/db/repl/replication_recovery.cpp @@ -677,16 +677,15 @@ void ReplicationRecoveryImpl::_truncateOplogTo(OperationContext* opCtx, } // Parse the response. - auto truncateAfterOplogEntry = - fassert(51766, repl::OplogEntry::parse(truncateAfterOplogEntryBSON.get())); - auto truncateAfterOplogEntryTs = truncateAfterOplogEntry.getTimestamp(); + auto truncateAfterOpTime = + fassert(51766, repl::OpTime::parseFromOplogEntry(truncateAfterOplogEntryBSON.get())); + auto truncateAfterOplogEntryTs = truncateAfterOpTime.getTimestamp(); auto truncateAfterRecordId = RecordId(truncateAfterOplogEntryTs.asULL()); invariant(truncateAfterRecordId <= RecordId(truncateAfterTimestamp.asULL()), str::stream() << "Should have found a oplog entry timestamp lte to " << truncateAfterTimestamp.toString() << ", but instead found " - << redact(truncateAfterOplogEntry.toBSONForLogging()) - << " with timestamp " + << redact(truncateAfterOplogEntryBSON.get()) << " with timestamp " << Timestamp(truncateAfterRecordId.asLong()).toString()); // Truncate the oplog AFTER the oplog entry found to be <= truncateAfterTimestamp. @@ -694,7 +693,7 @@ void ReplicationRecoveryImpl::_truncateOplogTo(OperationContext* opCtx, "Truncating oplog from {truncateAfterOplogEntryTimestamp} (non-inclusive). Truncate " "after point is {oplogTruncateAfterPoint}", "Truncating oplog from truncateAfterOplogEntryTimestamp (non-inclusive)", - "truncateAfterOplogEntryTimestamp"_attr = truncateAfterOplogEntry.getTimestamp(), + "truncateAfterOplogEntryTimestamp"_attr = truncateAfterOplogEntryTs, "oplogTruncateAfterPoint"_attr = truncateAfterTimestamp); if (*stableTimestamp && (**stableTimestamp) > truncateAfterOplogEntryTs) { diff --git a/src/mongo/db/repl/rollback_impl.cpp b/src/mongo/db/repl/rollback_impl.cpp index 2e1493b43e9..1ce1bb85b8e 100644 --- a/src/mongo/db/repl/rollback_impl.cpp +++ b/src/mongo/db/repl/rollback_impl.cpp @@ -1063,11 +1063,11 @@ Status RollbackImpl::_checkAgainstTimeLimit( return Status(ErrorCodes::OplogStartMissing, "no oplog during rollback"); } const auto topOfOplogBSON = topOfOplogSW.getValue().first; - const auto topOfOplog = uassertStatusOK(OplogEntry::parse(topOfOplogBSON)); + const auto topOfOplogOpAndWallTime = OpTimeAndWallTime::parse(topOfOplogBSON); - _rollbackStats.lastLocalOptime = topOfOplog.getOpTime(); + _rollbackStats.lastLocalOptime = topOfOplogOpAndWallTime.opTime; - auto topOfOplogWallTime = topOfOplog.getWallClockTime(); + auto topOfOplogWallTime = topOfOplogOpAndWallTime.wallTime; // We check the difference between the top of the oplog and the first oplog entry after the // common point when computing the rollback time limit. auto firstOpWallClockTimeAfterCommonPoint = diff --git a/src/mongo/db/repl/sync_source_resolver_test.cpp b/src/mongo/db/repl/sync_source_resolver_test.cpp index e2d7c2460cc..8eb83734dea 100644 --- a/src/mongo/db/repl/sync_source_resolver_test.cpp +++ b/src/mongo/db/repl/sync_source_resolver_test.cpp @@ -602,7 +602,7 @@ TEST_F(SyncSourceResolverTest, ASSERT_TRUE(_resolver->isActive()); _scheduleFirstOplogEntryFetcherResponse( - getNet(), _selector.get(), candidate1, candidate2, {BSON("t" << 1)}); + getNet(), _selector.get(), candidate1, candidate2, {BSON("t" << 1LL)}); ASSERT_TRUE(_resolver->isActive()); ASSERT_EQUALS(candidate1, _selector->getLastBlacklistedSyncSource_forTest()); @@ -654,7 +654,7 @@ TEST_F(SyncSourceResolverTest, SyncSourceResolverWillSucceedWithExtraFields) { _selector.get(), candidate1, HostAndPort(), - {BSON("ts" << Timestamp(1, 1) << "t" << 1 << "note" + {BSON("ts" << Timestamp(1, 1) << "t" << 1LL << "note" << "a")}); _resolver->join(); |