diff options
author | matt dannenberg <matt.dannenberg@10gen.com> | 2015-04-23 09:28:22 -0400 |
---|---|---|
committer | matt dannenberg <matt.dannenberg@10gen.com> | 2015-04-23 09:28:22 -0400 |
commit | 623d5413c322136d75c43c8d48f58b19761b3709 (patch) | |
tree | ac726331f46b7c5b8e2c211836e295fd1ad938cc | |
parent | 4fb40170f58ffab0c03404e8fe9214fe1f3c650c (diff) | |
download | mongo-623d5413c322136d75c43c8d48f58b19761b3709.tar.gz |
Revert "SERVER-18191 make new heartbeat args/response classes for the new election protocol"
This reverts commit 9a7bb551c0d01e53bfd3521d3862c73470c13db1.
-rw-r--r-- | src/mongo/db/repl/SConscript | 2 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp | 125 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_heartbeat_args_v1.h | 108 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_heartbeat_response_v1.cpp | 170 | ||||
-rw-r--r-- | src/mongo/db/repl/repl_set_heartbeat_response_v1.h | 108 |
5 files changed, 0 insertions, 513 deletions
diff --git a/src/mongo/db/repl/SConscript b/src/mongo/db/repl/SConscript index d9b8279d8be..11d5fba1cba 100644 --- a/src/mongo/db/repl/SConscript +++ b/src/mongo/db/repl/SConscript @@ -235,9 +235,7 @@ env.Library('replica_set_messages', 'is_master_response.cpp', 'member_config.cpp', 'repl_set_heartbeat_args.cpp', - 'repl_set_heartbeat_args_v1.cpp', 'repl_set_heartbeat_response.cpp', - 'repl_set_heartbeat_response_v1.cpp', 'replica_set_config.cpp', 'replica_set_tag.cpp', 'update_position_args.cpp', diff --git a/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp b/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp deleted file mode 100644 index 5fbf6090ff8..00000000000 --- a/src/mongo/db/repl/repl_set_heartbeat_args_v1.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/** - * Copyright 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. - */ - -#include "mongo/platform/basic.h" - -#include "mongo/db/repl/repl_set_heartbeat_args_v1.h" - -#include "mongo/bson/util/bson_check.h" -#include "mongo/bson/util/bson_extract.h" -#include "mongo/db/jsobj.h" - -namespace mongo { -namespace repl { - -namespace { - - const std::string kConfigVersionFieldName = "configVersion"; - const std::string kProtocolVersionFieldName = "pv"; - const std::string kSenderIdFieldName = "fromId"; - const std::string kSetNameFieldName = "replSetHeartbeat"; - const std::string kTermFieldName = "term"; - - const std::string kLegalHeartbeatFieldNames[] = { - kProtocolVersionFieldName, - kConfigVersionFieldName, - kSenderIdFieldName, - kSetNameFieldName, - kTermFieldName - }; - -} // namespace - - Status ReplSetHeartbeatArgsV1::initialize(const BSONObj& argsObj) { - Status status = bsonCheckOnlyHasFields("ReplSetHeartbeatArgs", - argsObj, - kLegalHeartbeatFieldNames); - if (!status.isOK()) - return status; - - status = bsonExtractIntegerField(argsObj, kProtocolVersionFieldName, &_protocolVersion); - if (!status.isOK()) - return status; - - status = bsonExtractIntegerField(argsObj, kConfigVersionFieldName, &_configVersion); - if (!status.isOK()) - return status; - - status = bsonExtractIntegerField(argsObj, kSenderIdFieldName, &_senderId); - if (!status.isOK()) - return status; - - status = bsonExtractIntegerField(argsObj, kTermFieldName, &_term); - if (!status.isOK()) - return status; - - status = bsonExtractStringField(argsObj, kSetNameFieldName, &_setName); - if (!status.isOK()) - return status; - - return Status::OK(); - } - - bool ReplSetHeartbeatArgsV1::isInitialized() const { - return _configVersion != -1 && _protocolVersion != -1 && - _senderId != -1 && _term != -1 && !_setName.empty(); - } - - void ReplSetHeartbeatArgsV1::setConfigVersion(long long newVal) { - _configVersion = newVal; - } - - void ReplSetHeartbeatArgsV1::setProtocolVersion(long long newVal) { - _protocolVersion = newVal; - } - - void ReplSetHeartbeatArgsV1::setSenderId(long long newVal) { - _senderId = newVal; - } - - void ReplSetHeartbeatArgsV1::setSetName(std::string newVal) { - _setName = newVal; - } - - void ReplSetHeartbeatArgsV1::setTerm(long long newVal) { - _term = newVal; - } - - BSONObj ReplSetHeartbeatArgsV1::toBSON() const { - invariant(isInitialized()); - BSONObjBuilder builder; - builder.append(kSetNameFieldName, _setName); - builder.appendIntOrLL(kProtocolVersionFieldName, _protocolVersion); - builder.appendIntOrLL(kConfigVersionFieldName, _configVersion); - builder.appendIntOrLL(kSenderIdFieldName, _senderId); - builder.appendIntOrLL(kTermFieldName, _term); - return builder.obj(); - } - -} // namespace repl -} // namespace mongo diff --git a/src/mongo/db/repl/repl_set_heartbeat_args_v1.h b/src/mongo/db/repl/repl_set_heartbeat_args_v1.h deleted file mode 100644 index cc7332b23ce..00000000000 --- a/src/mongo/db/repl/repl_set_heartbeat_args_v1.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * 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 <string> - -#include "mongo/util/net/hostandport.h" - -namespace mongo { - - class BSONObj; - class Status; - -namespace repl { - - /** - * Arguments to the replSetHeartbeat command. - */ - class ReplSetHeartbeatArgsV1 { - public: - /** - * Initializes this ReplSetHeartbeatArgsV1 from the contents of args. - */ - Status initialize(const BSONObj& argsObj); - - /** - * Returns true if all required fields have been initialized. - */ - bool isInitialized() const; - - /** - * Gets the version of the Heartbeat protocol being used by the sender. - */ - long long getProtocolVersion() const { return _protocolVersion; } - - /** - * Gets the ReplSetConfig version number of the sender. - */ - long long getConfigVersion() const { return _configVersion; } - - /** - * Gets the _id of the sender in their ReplSetConfig. - */ - long long getSenderId() const { return _senderId; } - - /** - * Gets the replSet name of the sender's replica set. - */ - std::string getSetName() const { return _setName; } - - /** - * Gets the term the sender believes it to be. - */ - long long getTerm() const { return _term; } - - /** - * The below methods set the value in the method name to 'newVal'. - */ - void setConfigVersion(long long newVal); - void setProtocolVersion(long long newVal); - void setSenderId(long long newVal); - void setSetName(std::string newVal); - void setTerm(long long newVal); - - /** - * Returns a BSONified version of the object. - * Should only be called if the mandatory fields have been set. - * Optional fields are only included if they have been set. - */ - BSONObj toBSON() const; - - private: - // look at the body of the isInitialized() function to see which fields are mandatory - long long _configVersion = -1; - long long _protocolVersion = -1; - long long _senderId = -1; - long long _term = -1; - std::string _setName; - }; - -} // namespace repl -} // namespace mongo diff --git a/src/mongo/db/repl/repl_set_heartbeat_response_v1.cpp b/src/mongo/db/repl/repl_set_heartbeat_response_v1.cpp deleted file mode 100644 index 881bbbccfd8..00000000000 --- a/src/mongo/db/repl/repl_set_heartbeat_response_v1.cpp +++ /dev/null @@ -1,170 +0,0 @@ -/** - * 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. - */ - -#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kReplication - -#include "mongo/platform/basic.h" - -#include "mongo/db/repl/repl_set_heartbeat_response_v1.h" - -#include <string> - -#include "mongo/base/status.h" -#include "mongo/bson/util/bson_check.h" -#include "mongo/bson/util/bson_extract.h" -#include "mongo/db/jsobj.h" -#include "mongo/util/assert_util.h" -#include "mongo/util/log.h" -#include "mongo/util/mongoutils/str.h" - -namespace mongo { -namespace repl { -namespace { - - const std::string kOkFieldName = "ok"; - const std::string kIsReplSetFieldName = "rs"; - const std::string kReplSetFieldName = "set"; - const std::string kMemberStateFieldName = "state"; - const std::string kOpTimeFieldName = "opTime"; - const std::string kSyncSourceFieldName = "syncingTo"; - const std::string kConfigVersionFieldName = "configVersion"; - const std::string kPrimaryIdFieldName = "primaryId"; - const std::string kLastOpCommitFieldName = "lastOpCommitted"; - const std::string kTermFieldName = "term"; - const std::string kConfigFieldName = "config"; - - const std::string kLegalHeartbeatFieldNames[] = { - kOkFieldName, - kIsReplSetFieldName, - kReplSetFieldName, - kMemberStateFieldName, - kOpTimeFieldName, - kSyncSourceFieldName, - kConfigVersionFieldName, - kPrimaryIdFieldName, - kLastOpCommitFieldName, - kTermFieldName, - kConfigFieldName, - }; - -} // namespace - - void ReplSetHeartbeatResponseV1::addToBSON(BSONObjBuilder* builder) const { - builder->append(kOkFieldName, 1.0); - builder->append(kIsReplSetFieldName, _isReplSet); - builder->append(kReplSetFieldName, _setName); - builder->append(kMemberStateFieldName, _state.s); - builder->append(kOpTimeFieldName, _opTime); - builder->append(kSyncSourceFieldName, _syncingTo); - builder->append(kConfigVersionFieldName, _configVersion); - builder->append(kPrimaryIdFieldName, _primaryId); - builder->append(kLastOpCommitFieldName, _lastOpCommitted); - builder->append(kTermFieldName, _term); - if (_configSet) { - builder->append(kConfigFieldName, _config.toBSON()); - } - } - - BSONObj ReplSetHeartbeatResponseV1::toBSON() const { - BSONObjBuilder builder; - addToBSON(&builder); - return builder.obj(); - } - - Status ReplSetHeartbeatResponseV1::initialize(const BSONObj& doc) { - Status status = bsonCheckOnlyHasFields("ReplSetHeartbeatResponse", - doc, - kLegalHeartbeatFieldNames); - if (!status.isOK()) - return status; - - status = bsonExtractBooleanField(doc, kIsReplSetFieldName, &_isReplSet); - if (!status.isOK()) - return status; - - status = bsonExtractStringField(doc, kReplSetFieldName, &_setName); - if (!status.isOK()) - return status; - - long long stateInt; - status = bsonExtractIntegerField(doc, kMemberStateFieldName, &stateInt); - if (!status.isOK()) - return status; - if (stateInt < 0 || stateInt > MemberState::RS_MAX) { - return Status(ErrorCodes::BadValue, str::stream() << "Value for \"" << - kMemberStateFieldName << "\" in response to replSetHeartbeat is " - "out of range; legal values are non-negative and no more than " << - MemberState::RS_MAX); - } - _state = MemberState(static_cast<int>(stateInt)); - - status = bsonExtractTimestampField(doc, kOpTimeFieldName, &_opTime); - if (!status.isOK()) - return status; - - status = bsonExtractStringField(doc, kSyncSourceFieldName, &_syncingTo); - if (!status.isOK()) - return status; - - status = bsonExtractIntegerField(doc, kConfigVersionFieldName, &_configVersion); - if (!status.isOK()) - return status; - - status = bsonExtractIntegerField(doc, kPrimaryIdFieldName, &_primaryId); - if (!status.isOK()) - return status; - - status = bsonExtractTimestampField(doc, kLastOpCommitFieldName, &_lastOpCommitted); - if (!status.isOK()) - return status; - - status = bsonExtractIntegerField(doc, kTermFieldName, &_term); - if (!status.isOK()) - return status; - - const BSONElement rsConfigElement = doc[kConfigFieldName]; - if (rsConfigElement.eoo()) { - _configSet = false; - _config = ReplicaSetConfig(); - return Status::OK(); - } - else if (rsConfigElement.type() != Object) { - return Status(ErrorCodes::TypeMismatch, str::stream() << "Expected \"" << - kConfigFieldName << "\" in response to replSetHeartbeat to have type " - "Object, but found " << typeName(rsConfigElement.type())); - } - _configSet = true; - return _config.initialize(rsConfigElement.Obj()); - } - - ReplicaSetConfig ReplSetHeartbeatResponseV1::getConfig() const { - invariant(_configSet); - return _config; - } -} // namespace repl -} // namespace mongo diff --git a/src/mongo/db/repl/repl_set_heartbeat_response_v1.h b/src/mongo/db/repl/repl_set_heartbeat_response_v1.h deleted file mode 100644 index 3a4381a66a2..00000000000 --- a/src/mongo/db/repl/repl_set_heartbeat_response_v1.h +++ /dev/null @@ -1,108 +0,0 @@ -/** - * 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 <string> - -#include "mongo/db/repl/member_state.h" -#include "mongo/db/repl/replica_set_config.h" -#include "mongo/util/time_support.h" - -namespace mongo { - - class BSONObj; - class BSONObjBuilder; - class Status; - -namespace repl { - - /** - * Response structure for the replSetHeartbeat command. - */ - class ReplSetHeartbeatResponseV1 { - public: - /** - * Initializes this ReplSetHeartbeatResponseV1 from the contents of "doc". - */ - Status initialize(const BSONObj& doc); - - /** - * Appends all non-default values to "builder". - */ - void addToBSON(BSONObjBuilder* builder) const; - - /** - * Returns a BSONObj consisting of all non-default values to "builder". - */ - BSONObj toBSON() const; - - /** - * Returns toBSON().toString() - */ - const std::string toString() const { return toBSON().toString(); } - - bool isReplSet() const { return _isReplSet; } - std::string getReplSetName() const { return _setName; } - MemberState getMemberState() const { return _state; } - Timestamp getOpTime() const { return _opTime; } - std::string getSyncTarget() const { return _syncingTo; } - long long getConfigVersion() const { return _configVersion; } - long long getPrimaryId() const { return _primaryId; } - Timestamp getLastOpCommitted() const { return _lastOpCommitted; } - long long getTerm() const { return _term; } - bool isConfigSet() const { return _configSet; } - ReplicaSetConfig getConfig() const; - - void noteReplSet() { _isReplSet = true; } - void setSetName(std::string name) { _setName = name; } - void setState(MemberState state) { _state = state; } - void setOpTime(Timestamp time) { _opTime = time; } - void setSyncingTo(std::string syncingTo) { _syncingTo = syncingTo; } - void setConfigVersion(long long version) { _configVersion = version; } - void setPrimaryId(long long primaryId) { _primaryId = primaryId; } - void setLastOpCommitted(Timestamp time) { _lastOpCommitted = time; } - void setTerm(long long term) { _term = term; } - void setConfig(const ReplicaSetConfig& config) { _configSet = true; _config = config; } - - private: - MemberState _state; - ReplicaSetConfig _config; - Timestamp _lastOpCommitted; - Timestamp _opTime; - bool _configSet = false; - bool _isReplSet = false; - long long _configVersion = -1; - long long _primaryId = -1; - long long _term = -1; - std::string _setName; - std::string _syncingTo; - }; - -} // namespace repl -} // namespace mongo |