diff options
author | matt dannenberg <matt.dannenberg@10gen.com> | 2015-10-12 08:07:25 -0400 |
---|---|---|
committer | matt dannenberg <matt.dannenberg@10gen.com> | 2015-10-14 05:07:49 -0400 |
commit | c860db7d39f8559054d1cebb83a6838accef8d94 (patch) | |
tree | b3110c22e4afcdf6313144797957c8f6c4efe929 /src/mongo/rpc | |
parent | 7d43b0dba28b4b8e0184579a75c3dddab9d86e1f (diff) | |
download | mongo-c860db7d39f8559054d1cebb83a6838accef8d94.tar.gz |
SERVER-20822 make sync source decisions based on ReplSetMetadata
Diffstat (limited to 'src/mongo/rpc')
-rw-r--r-- | src/mongo/rpc/metadata/repl_set_metadata.cpp | 16 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/repl_set_metadata.h | 21 | ||||
-rw-r--r-- | src/mongo/rpc/metadata/repl_set_metadata_test.cpp | 15 |
3 files changed, 36 insertions, 16 deletions
diff --git a/src/mongo/rpc/metadata/repl_set_metadata.cpp b/src/mongo/rpc/metadata/repl_set_metadata.cpp index aadd520a683..5e9a1e89f77 100644 --- a/src/mongo/rpc/metadata/repl_set_metadata.cpp +++ b/src/mongo/rpc/metadata/repl_set_metadata.cpp @@ -46,6 +46,7 @@ const char kLastOpCommittedFieldName[] = "lastOpCommitted"; const char kLastOpVisibleFieldName[] = "lastOpVisible"; const char kConfigVersionFieldName[] = "configVersion"; const char kPrimaryIndexFieldName[] = "primaryIndex"; +const char kSyncSourceIndexFieldName[] = "syncSourceIndex"; const char kTermFieldName[] = "term"; } // unnamed namespace @@ -58,12 +59,14 @@ ReplSetMetadata::ReplSetMetadata(long long term, OpTime committedOpTime, OpTime visibleOpTime, long long configVersion, - int currentPrimaryIndex) + int currentPrimaryIndex, + int currentSyncSourceIndex) : _lastOpCommitted(std::move(committedOpTime)), _lastOpVisible(std::move(visibleOpTime)), _currentTerm(term), _configVersion(configVersion), - _currentPrimaryIndex(currentPrimaryIndex) {} + _currentPrimaryIndex(currentPrimaryIndex), + _currentSyncSourceIndex(currentSyncSourceIndex) {} StatusWith<ReplSetMetadata> ReplSetMetadata::readFromMetadata(const BSONObj& metadataObj) { BSONElement replMetadataElement; @@ -84,6 +87,11 @@ StatusWith<ReplSetMetadata> ReplSetMetadata::readFromMetadata(const BSONObj& met if (!status.isOK()) return status; + long long syncSourceIndex; + status = bsonExtractIntegerField(replMetadataObj, kSyncSourceIndexFieldName, &syncSourceIndex); + if (!status.isOK()) + return status; + long long term; status = bsonExtractIntegerField(replMetadataObj, kTermFieldName, &term); if (!status.isOK()) @@ -99,7 +107,8 @@ StatusWith<ReplSetMetadata> ReplSetMetadata::readFromMetadata(const BSONObj& met if (!status.isOK()) return status; - return ReplSetMetadata(term, lastOpCommitted, lastOpVisible, configVersion, primaryIndex); + return ReplSetMetadata( + term, lastOpCommitted, lastOpVisible, configVersion, primaryIndex, syncSourceIndex); } Status ReplSetMetadata::writeToMetadata(BSONObjBuilder* builder) const { @@ -109,6 +118,7 @@ Status ReplSetMetadata::writeToMetadata(BSONObjBuilder* builder) const { _lastOpVisible.append(&replMetadataBuilder, kLastOpVisibleFieldName); replMetadataBuilder.append(kConfigVersionFieldName, _configVersion); replMetadataBuilder.append(kPrimaryIndexFieldName, _currentPrimaryIndex); + replMetadataBuilder.append(kSyncSourceIndexFieldName, _currentSyncSourceIndex); replMetadataBuilder.doneFast(); return Status::OK(); diff --git a/src/mongo/rpc/metadata/repl_set_metadata.h b/src/mongo/rpc/metadata/repl_set_metadata.h index 722f3befe3e..3e80afc1f9b 100644 --- a/src/mongo/rpc/metadata/repl_set_metadata.h +++ b/src/mongo/rpc/metadata/repl_set_metadata.h @@ -55,16 +55,18 @@ public: repl::OpTime committedOpTime, repl::OpTime visibleOpTime, long long configVersion, - int currentPrimaryIndex); + int currentPrimaryIndex, + int currentSyncSourceIndex); /** * format: * { * term: 0, - * lastOpCommitted: {ts: Timestamp(0, 0), term: 0} - * lastOpVisible: {ts: Timestamp(0, 0), term: 0} + * lastOpCommitted: {ts: Timestamp(0, 0), term: 0}, + * lastOpVisible: {ts: Timestamp(0, 0), term: 0}, * configVersion: 0, - * primaryIndex: 0 + * primaryIndex: 0, + * syncSourceIndex: 0 * } */ static StatusWith<ReplSetMetadata> readFromMetadata(const BSONObj& doc); @@ -95,11 +97,19 @@ public: * Returns the index of the current primary from the perspective of the sender. * Returns kNoPrimary if there is no primary. */ - long long getPrimaryIndex() const { + int getPrimaryIndex() const { return _currentPrimaryIndex; } /** + * Returns the index of the sync source of the sender. + * Returns -1 if it has no sync source. + */ + int getSyncSourceIndex() const { + return _currentSyncSourceIndex; + } + + /** * Returns the current term from the perspective of the sender. */ long long getTerm() const { @@ -112,6 +122,7 @@ private: long long _currentTerm = -1; long long _configVersion = -1; int _currentPrimaryIndex = kNoPrimary; + int _currentSyncSourceIndex = -1; }; } // namespace rpc diff --git a/src/mongo/rpc/metadata/repl_set_metadata_test.cpp b/src/mongo/rpc/metadata/repl_set_metadata_test.cpp index 499bbeb0b23..68d073be8cb 100644 --- a/src/mongo/rpc/metadata/repl_set_metadata_test.cpp +++ b/src/mongo/rpc/metadata/repl_set_metadata_test.cpp @@ -39,7 +39,7 @@ using repl::OpTime; TEST(ReplResponseMetadataTest, Roundtrip) { OpTime opTime(Timestamp(1234, 100), 5); OpTime opTime2(Timestamp(7777, 100), 6); - ReplSetMetadata metadata(3, opTime, opTime2, 6, 12); + ReplSetMetadata metadata(3, opTime, opTime2, 6, 12, -1); ASSERT_EQ(opTime, metadata.getLastOpCommitted()); ASSERT_EQ(opTime2, metadata.getLastOpVisible()); @@ -47,13 +47,12 @@ TEST(ReplResponseMetadataTest, Roundtrip) { BSONObjBuilder builder; metadata.writeToMetadata(&builder); - BSONObj expectedObj( - BSON(kReplSetMetadataFieldName - << BSON("term" << 3 << "lastOpCommitted" - << BSON("ts" << opTime.getTimestamp() << "t" << opTime.getTerm()) - << "lastOpVisible" - << BSON("ts" << opTime2.getTimestamp() << "t" << opTime2.getTerm()) - << "configVersion" << 6 << "primaryIndex" << 12))); + BSONObj expectedObj(BSON( + kReplSetMetadataFieldName << BSON( + "term" << 3 << "lastOpCommitted" << BSON("ts" << opTime.getTimestamp() << "t" + << opTime.getTerm()) << "lastOpVisible" + << BSON("ts" << opTime2.getTimestamp() << "t" << opTime2.getTerm()) + << "configVersion" << 6 << "primaryIndex" << 12 << "syncSourceIndex" << -1))); BSONObj serializedObj = builder.obj(); ASSERT_EQ(expectedObj, serializedObj); |