diff options
20 files changed, 66 insertions, 699 deletions
diff --git a/jstests/sharding/ssv_config_check.js b/jstests/sharding/ssv_config_check.js index 48d7f2eac70..0163e521c65 100644 --- a/jstests/sharding/ssv_config_check.js +++ b/jstests/sharding/ssv_config_check.js @@ -1,6 +1,5 @@ /** - * Test that setShardVersion should not reject a configdb string with the same - * replica set name, but with a member list that is not strictly the same. + * Test that setShardVersion fails if sent to the config server. */ (function() { "use strict"; @@ -17,19 +16,6 @@ var directConn = new Mongo(st.rs0.getPrimary().host); var adminDB = directConn.getDB('admin'); var configStr = adminDB.runCommand({getShardVersion: 'test.user'}).configServer; -var alternateConfigStr = configStr.substring(0, configStr.lastIndexOf(',')); - -var shardDoc = st.s.getDB('config').shards.findOne(); - -jsTest.log("Verify that the obsolete init form of setShardVersion succeeds on shards."); -assert.commandWorked(adminDB.runCommand({ - setShardVersion: '', - init: true, - authoritative: true, - configdb: alternateConfigStr, - shard: shardDoc._id, - shardHost: shardDoc.host -})); var configAdmin = st.c0.getDB('admin'); diff --git a/jstests/sharding/update_immutable_fields.js b/jstests/sharding/update_immutable_fields.js index 8b5d4a02d9a..27a97fdbf82 100644 --- a/jstests/sharding/update_immutable_fields.js +++ b/jstests/sharding/update_immutable_fields.js @@ -7,36 +7,12 @@ var st = new ShardingTest({shards: 2, mongos: 1}); var mongos = st.s; var config = mongos.getDB("config"); var coll = mongos.getCollection(jsTestName() + ".coll1"); -var shard0 = st.shard0; assert.commandWorked(config.adminCommand({enableSharding: coll.getDB() + ""})); st.ensurePrimaryShard(coll.getDB().getName(), st.shard0.shardName); assert.commandWorked(config.adminCommand({shardCollection: "" + coll, key: {a: 1}})); -var getDirectShardedConn = function(st, collName) { - var shardConnWithVersion = new Mongo(st.shard0.host); - - var configConnStr = st._configDB; - - var maxChunk = - st.s0.getCollection("config.chunks").find({ns: collName}).sort({lastmod: -1}).next(); - - var ssvInitCmd = { - setShardVersion: collName, - authoritative: true, - configdb: configConnStr, - version: maxChunk.lastmod, - shard: st.shard0.shardName, - versionEpoch: maxChunk.lastmodEpoch - }; - - printjson(ssvInitCmd); - assert.commandWorked(shardConnWithVersion.getDB("admin").runCommand(ssvInitCmd)); - - return shardConnWithVersion; -}; - -var shard0Coll = getDirectShardedConn(st, coll.getFullName()).getCollection(coll.getFullName()); +const shard0Coll = st.shard0.getCollection(coll.getFullName()); // Full shard key in save assert.commandWorked(shard0Coll.save({_id: 1, a: 1})); @@ -55,11 +31,5 @@ assert.commandWorked(shard0Coll.update({_id: 1}, {a: 1})); // Update existing doc ($set), same shard key value assert.commandWorked(shard0Coll.update({_id: 1}, {$set: {a: 1}})); -// Error when trying to update a shard key outside of a transaction. -assert.commandFailedWithCode(shard0Coll.update({_id: 1, a: 1}, {_id: 1, a: 2}), - ErrorCodes.IllegalOperation); -assert.commandFailedWithCode(shard0Coll.update({_id: 1, a: 1}, {"$set": {a: 2}}), - ErrorCodes.IllegalOperation); - st.stop(); })(); diff --git a/jstests/sharding/version2.js b/jstests/sharding/version2.js index 87a4eb9915a..74880d8ccfd 100644 --- a/jstests/sharding/version2.js +++ b/jstests/sharding/version2.js @@ -26,7 +26,7 @@ assert.commandWorked(a.runCommand({ printjson(s.config.chunks.findOne()); -assert.eq(a.runCommand({"getShardVersion": "alleyinsider.foo", configdb: s._configDB}).mine.t, 1); +assert.eq(a.runCommand({"getShardVersion": "alleyinsider.foo", configdb: s._configDB}).mine.t, 0); assert.eq(a.runCommand({"getShardVersion": "alleyinsider.foo", configdb: s._configDB}).global.t, 1); // From a different client @@ -39,35 +39,5 @@ assert.eq(a2.runCommand({"getShardVersion": "alleyinsider.foo", configdb: s._con 0, "a2 mine 1"); -function simpleFindOne() { - return a2.getMongo().getDB("alleyinsider").foo.findOne(); -} - -var barEpoch = s.getDB('config').chunks.findOne({ns: 'alleyinsider.bar'}).lastmodEpoch; -assert.commandWorked(a2.runCommand({ - setShardVersion: "alleyinsider.bar", - configdb: s._configDB, - version: new Timestamp(1, 0), - versionEpoch: barEpoch, - shard: s.shard0.shardName, - authoritative: true -}), - "setShardVersion bar temp"); - -assert.throws(simpleFindOne, [], "should complain about not in sharded mode 1"); - -// the only way that setSharVersion passes is if the shard agrees with the version -// the shard takes its version from config directly -// TODO bump timestamps in config -// assert(a2.runCommand({ "setShardVersion": "alleyinsider.foo", configdb: s._configDB, version: -// 2 }).ok == 1, "setShardVersion a2-1"); - -// simpleFindOne(); // now should run ok - -// assert(a2.runCommand({ "setShardVersion": "alleyinsider.foo", configdb: s._configDB, version: -// 3 }).ok == 1, "setShardVersion a2-2"); - -// simpleFindOne(); // newer version is ok - s.stop(); })(); diff --git a/src/mongo/client/dbclient_rs.cpp b/src/mongo/client/dbclient_rs.cpp index e37232c3750..342c9faa952 100644 --- a/src/mongo/client/dbclient_rs.cpp +++ b/src/mongo/client/dbclient_rs.cpp @@ -818,8 +818,6 @@ DBClientConnection* DBClientReplicaSet::selectNodeUsingTags( if (!_lastSlaveOkConn->authenticatedDuringConnect()) { _authConnection(_lastSlaveOkConn.get()); } - } else { - // Mongos pooled connections are authenticated through ShardingConnectionHook::onCreate() } LOGV2_DEBUG(20140, diff --git a/src/mongo/db/s/SConscript b/src/mongo/db/s/SConscript index 29c1f10e8d3..e25c82936b9 100644 --- a/src/mongo/db/s/SConscript +++ b/src/mongo/db/s/SConscript @@ -15,7 +15,6 @@ env.Library( 'collection_sharding_state.cpp', 'database_sharding_state.cpp', 'operation_sharding_state.cpp', - 'sharded_connection_info.cpp', 'sharding_migration_critical_section.cpp', 'sharding_state.cpp', 'transaction_coordinator_curop.cpp', diff --git a/src/mongo/db/s/collection_sharding_runtime.cpp b/src/mongo/db/s/collection_sharding_runtime.cpp index 255910a1151..f2495a376a6 100644 --- a/src/mongo/db/s/collection_sharding_runtime.cpp +++ b/src/mongo/db/s/collection_sharding_runtime.cpp @@ -36,7 +36,6 @@ #include "mongo/base/checked_cast.h" #include "mongo/db/catalog_raii.h" #include "mongo/db/s/operation_sharding_state.h" -#include "mongo/db/s/sharded_connection_info.h" #include "mongo/db/s/sharding_runtime_d_params_gen.h" #include "mongo/db/s/sharding_state.h" #include "mongo/logv2/log.h" @@ -76,22 +75,14 @@ boost::optional<ChunkVersion> getOperationReceivedVersion(OperationContext* opCt const NamespaceString& nss) { auto& oss = OperationShardingState::get(opCtx); - // If there is a version attached to the OperationContext, use it as the received version, - // otherwise get the received version from the ShardedConnectionInfo + // If there is a version attached to the OperationContext, use it as the received version. if (oss.hasShardVersion()) { return oss.getShardVersion(nss); - } else if (auto const info = ShardedConnectionInfo::get(opCtx->getClient(), false)) { - auto connectionShardVersion = info->getVersion(nss.ns()); - - // For backwards compatibility with map/reduce, which can access up to 2 sharded collections - // in a single call, the lack of version for a namespace on the collection must be treated - // as UNSHARDED - return connectionShardVersion.value_or(ChunkVersion::UNSHARDED()); } - // There is no shard version information on either 'opCtx' or 'client'. This means that the - // operation represented by 'opCtx' is unversioned, and the shard version is always OK for - // unversioned operations + // There is no shard version information on the 'opCtx'. This means that the operation + // represented by 'opCtx' is unversioned, and the shard version is always OK for unversioned + // operations. return boost::none; } diff --git a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp index e669d3478f4..f490baf6bac 100644 --- a/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp +++ b/src/mongo/db/s/config/sharding_catalog_manager_collection_operations.cpp @@ -375,14 +375,13 @@ void sendSSVToAllShards(OperationContext* opCtx, const NamespaceString& nss) { for (const auto& shardEntry : allShards) { const auto& shard = uassertStatusOK(shardRegistry->getShard(opCtx, shardEntry.getName())); - SetShardVersionRequest ssv = SetShardVersionRequest::makeForVersioningNoPersist( - shardRegistry->getConfigServerConnectionString(), - shardEntry.getName(), - fassert(28781, ConnectionString::parse(shardEntry.getHost())), - nss, - ChunkVersion::DROPPED(), - true /* isAuthoritative */, - true /* forceRefresh */); + SetShardVersionRequest ssv(shardRegistry->getConfigServerConnectionString(), + shardEntry.getName(), + fassert(28781, ConnectionString::parse(shardEntry.getHost())), + nss, + ChunkVersion::DROPPED(), + true /* isAuthoritative */, + true /* forceRefresh */); auto ssvResult = shard->runCommandWithFixedRetryAttempts( opCtx, diff --git a/src/mongo/db/s/get_shard_version_command.cpp b/src/mongo/db/s/get_shard_version_command.cpp index 3152256e894..bcf64b692c3 100644 --- a/src/mongo/db/s/get_shard_version_command.cpp +++ b/src/mongo/db/s/get_shard_version_command.cpp @@ -38,7 +38,6 @@ #include "mongo/db/catalog_raii.h" #include "mongo/db/commands.h" #include "mongo/db/s/collection_sharding_runtime.h" -#include "mongo/db/s/sharded_connection_info.h" #include "mongo/db/s/sharding_state.h" #include "mongo/s/grid.h" #include "mongo/util/str.h" @@ -93,14 +92,9 @@ public: "configServer", Grid::get(opCtx)->shardRegistry()->getConfigServerConnectionString().toString()); - ShardedConnectionInfo* const sci = ShardedConnectionInfo::get(opCtx->getClient(), false); - result.appendBool("inShardedMode", sci != nullptr); - - if (sci && sci->getVersion(nss.ns())) { - result.appendTimestamp("mine", sci->getVersion(nss.ns())->toLong()); - } else { - result.appendTimestamp("mine", 0); - } + // Legacy boolean related to sharded connections. To remove in 4.8. + result.appendBool("inShardedMode", false); + result.appendTimestamp("mine", 0); AutoGetCollection autoColl( opCtx, nss, MODE_IS, AutoGetCollection::ViewMode::kViewsPermitted); diff --git a/src/mongo/db/s/migration_source_manager.cpp b/src/mongo/db/s/migration_source_manager.cpp index eaa36da5f83..c89a4e9a4db 100644 --- a/src/mongo/db/s/migration_source_manager.cpp +++ b/src/mongo/db/s/migration_source_manager.cpp @@ -97,13 +97,12 @@ void refreshRecipientRoutingTable(OperationContext* opCtx, ShardId toShard, const HostAndPort& toShardHost, const ChunkVersion& newCollVersion) { - SetShardVersionRequest ssv = SetShardVersionRequest::makeForVersioningNoPersist( - Grid::get(opCtx)->shardRegistry()->getConfigServerConnectionString(), - toShard, - ConnectionString(toShardHost), - nss, - newCollVersion, - false); + SetShardVersionRequest ssv(Grid::get(opCtx)->shardRegistry()->getConfigServerConnectionString(), + toShard, + ConnectionString(toShardHost), + nss, + newCollVersion, + false); const executor::RemoteCommandRequest request( toShardHost, diff --git a/src/mongo/db/s/operation_sharding_state.cpp b/src/mongo/db/s/operation_sharding_state.cpp index b5e01ee4dff..58351127f90 100644 --- a/src/mongo/db/s/operation_sharding_state.cpp +++ b/src/mongo/db/s/operation_sharding_state.cpp @@ -32,7 +32,6 @@ #include "mongo/db/s/operation_sharding_state.h" #include "mongo/db/operation_context.h" -#include "mongo/db/s/sharded_connection_info.h" namespace mongo { namespace { @@ -62,11 +61,7 @@ OperationShardingState& OperationShardingState::get(OperationContext* opCtx) { } bool OperationShardingState::isOperationVersioned(OperationContext* opCtx) { - const auto client = opCtx->getClient(); - - // Shard version information received from mongos may either be attached to the Client or - // directly to the OperationContext - return ShardedConnectionInfo::get(client, false) || get(opCtx).hasShardVersion(); + return get(opCtx).hasShardVersion(); } void OperationShardingState::setAllowImplicitCollectionCreation( diff --git a/src/mongo/db/s/set_shard_version_command.cpp b/src/mongo/db/s/set_shard_version_command.cpp index bb334dfaf8f..014d3bd73c0 100644 --- a/src/mongo/db/s/set_shard_version_command.cpp +++ b/src/mongo/db/s/set_shard_version_command.cpp @@ -44,7 +44,6 @@ #include "mongo/db/s/collection_sharding_runtime.h" #include "mongo/db/s/migration_source_manager.h" #include "mongo/db/s/shard_filtering_metadata_refresh.h" -#include "mongo/db/s/sharded_connection_info.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/views/view_catalog.h" #include "mongo/logv2/log.h" @@ -97,33 +96,20 @@ public: uassertStatusOK(shardingState->canAcceptShardedCommands()); // Steps - // 1. As long as the command does not have noConnectionVersioning set, register a - // ShardedConnectionInfo for this client connection (this is for clients using - // ShardConnection). Registering the ShardedConnectionInfo guarantees that we will check - // the shardVersion on all requests from this client connection. The connection's version - // will be updated on each subsequent setShardVersion sent on this connection. + // 1. Set the `authoritative` and `forceRefresh` variables from the command object. // - // 2. If we have received the init form of setShardVersion, vacuously return true. - // The init form of setShardVersion was used to initialize sharding awareness on a shard, - // but was made obsolete in v3.4 by making nodes sharding-aware when they are added to a - // cluster. The init form was kept in v3.4 shards for compatibility with mixed-version - // 3.2/3.4 clusters, but was deprecated and made to vacuously return true in v3.6. - // - // 3. Validate all command parameters against the info in our ShardingState, and return an + // 2. Validate all command parameters against the info in our ShardingState, and return an // error if they do not match. // - // 4. If the sent shardVersion is compatible with our shardVersion, update the shardVersion - // in this client's ShardedConnectionInfo if needed. + // 3. If the sent shardVersion is compatible with our shardVersion, return. // - // 5. If the sent shardVersion indicates a drop, jump to step 7. + // 4. If the sent shardVersion indicates a drop, jump to step 6. // - // 6. If the sent shardVersion is staler than ours, return a stale config error. + // 5. If the sent shardVersion is staler than ours, return a stale config error. // - // 7. If the sent shardVersion is newer than ours (or indicates a drop), reload our metadata - // and compare the sent shardVersion with what we reloaded. If the versions are now - // compatible, update the shardVersion in this client's ShardedConnectionInfo, as in - // step 4. If the sent shardVersion is staler than what we reloaded, return a stale - // config error, as in step 6. + // 6. If the sent shardVersion is newer than ours (or indicates a drop), reload our metadata + // and compare the sent shardVersion with what we reloaded. If the sent shardVersion is + // staler than what we reloaded, return a stale config error, as in step 5. // Step 1 @@ -137,28 +123,9 @@ public: // refresh or b) wait for a refresh to be started after it has entered the // getCollectionRoutingInfoWithRefresh function const bool forceRefresh = cmdObj.getBoolField("forceRefresh"); - const bool noConnectionVersioning = cmdObj.getBoolField("noConnectionVersioning"); - - ShardedConnectionInfo dummyInfo; - ShardedConnectionInfo* info; - if (noConnectionVersioning) { - info = &dummyInfo; - } else { - info = ShardedConnectionInfo::get(client, true); - } // Step 2 - // The init form of setShardVersion was deprecated in v3.6. For backwards compatibility with - // pre-v3.6 mongos, return true. - const auto isInit = cmdObj["init"].trueValue(); - if (isInit) { - result.append("initialized", true); - return true; - } - - // Step 3 - // Validate shardName parameter. const auto shardName = cmdObj["shard"].str(); const auto storedShardName = shardingState->shardId().toString(); @@ -196,17 +163,7 @@ public: const ChunkVersion requestedVersion = uassertStatusOK( ChunkVersion::parseLegacyWithField(cmdObj, SetShardVersionRequest::kVersion)); - // Step 4 - - const auto connectionVersionOrNotSet = info->getVersion(nss.ns()); - - // For backwards compatibility, calling SSV for a namespace which is sharded, but doesn't - // have version set on the connection requires the call to fail and require the - // "need_authoritative" flag to be set on the response. Treating unset connection versions - // as UNSHARDED is the legacy way to achieve this purpose. - const auto connectionVersion = - (connectionVersionOrNotSet ? *connectionVersionOrNotSet : ChunkVersion::UNSHARDED()); - connectionVersion.appendLegacyWithField(&result, "oldVersion"); + // Step 3 { boost::optional<AutoGetDb> autoDb; @@ -240,32 +197,10 @@ public: }(); if (requestedVersion.isWriteCompatibleWith(collectionShardVersion)) { - // MongoS and MongoD agree on what is the collection's shard version - // - // Now we should update the connection's version if it's not compatible with the - // request's version. This could happen if the shard's metadata has changed, but - // the remote client has already refreshed its view of the metadata since the last - // time it sent anything over this connection. - if (!connectionVersion.isWriteCompatibleWith(requestedVersion)) { - if (connectionVersion < collectionShardVersion && - connectionVersion.epoch() == collectionShardVersion.epoch()) { - // A migration occurred - info->setVersion(nss.ns(), requestedVersion); - } else if (authoritative) { - // The collection was dropped and recreated or had its shard key refined. - info->setVersion(nss.ns(), requestedVersion); - } else { - result.append("ns", nss.ns()); - result.appendBool("need_authoritative", true); - errmsg = str::stream() << "verifying drop on '" << nss.ns() << "'"; - return false; - } - } - return true; } - // Step 5 + // Step 4 const bool isDropRequested = !requestedVersion.isSet() && collectionShardVersion.isSet(); @@ -283,18 +218,7 @@ public: } else { // Not Dropping - // Step 6 - - // TODO: Refactor all of this - if (requestedVersion < connectionVersion && - requestedVersion.epoch() == connectionVersion.epoch()) { - errmsg = str::stream() << "this connection already had a newer version " - << "of collection '" << nss.ns() << "'"; - result.append("ns", nss.ns()); - requestedVersion.appendLegacyWithField(&result, "newVersion"); - collectionShardVersion.appendLegacyWithField(&result, "globalVersion"); - return false; - } + // Step 5 // TODO: Refactor all of this if (requestedVersion < collectionShardVersion && @@ -340,7 +264,7 @@ public: } } - // Step 7 + // Step 6 // Note: The forceRefresh flag controls whether we make sure to do our // own refresh or if we're okay with joining another thread @@ -421,7 +345,6 @@ public: } } - info->setVersion(nss.ns(), requestedVersion); return true; } diff --git a/src/mongo/db/s/sharded_connection_info.cpp b/src/mongo/db/s/sharded_connection_info.cpp deleted file mode 100644 index 4d15e94b825..00000000000 --- a/src/mongo/db/s/sharded_connection_info.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * 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 - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * 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 Server Side 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::kSharding - -#include "mongo/platform/basic.h" - -#include "mongo/db/s/sharded_connection_info.h" - -#include "mongo/db/client.h" -#include "mongo/logv2/log.h" - -namespace mongo { -namespace { - -const auto clientSCI = Client::declareDecoration<boost::optional<ShardedConnectionInfo>>(); - -} // namespace - -ShardedConnectionInfo::ShardedConnectionInfo() = default; - -ShardedConnectionInfo::~ShardedConnectionInfo() = default; - -ShardedConnectionInfo* ShardedConnectionInfo::get(Client* client, bool create) { - auto& current = clientSCI(client); - - if (!current && create) { - LOGV2_DEBUG(22060, 1, "Entering shard mode for connection"); - current.emplace(); - } - - return current ? ¤t.value() : nullptr; -} - -void ShardedConnectionInfo::reset(Client* client) { - clientSCI(client) = boost::none; -} - -boost::optional<ChunkVersion> ShardedConnectionInfo::getVersion(const std::string& ns) const { - NSVersionMap::const_iterator it = _versions.find(ns); - if (it != _versions.end()) { - return it->second; - } else { - return boost::none; - } -} - -void ShardedConnectionInfo::setVersion(const std::string& ns, const ChunkVersion& version) { - _versions[ns] = version; -} - -} // namespace mongo diff --git a/src/mongo/db/s/sharded_connection_info.h b/src/mongo/db/s/sharded_connection_info.h deleted file mode 100644 index e96cf41e49b..00000000000 --- a/src/mongo/db/s/sharded_connection_info.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (C) 2018-present MongoDB, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the Server Side Public License, version 1, - * as published by MongoDB, Inc. - * - * 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 - * Server Side Public License for more details. - * - * You should have received a copy of the Server Side Public License - * along with this program. If not, see - * <http://www.mongodb.com/licensing/server-side-public-license>. - * - * 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 Server Side 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 <boost/optional.hpp> -#include <map> -#include <string> - -#include "mongo/s/chunk_version.h" - -namespace mongo { - -class Client; - -/** - * There is one instance of these per each connection from mongos. Holds version state for each - * namespace. - */ -class ShardedConnectionInfo { - ShardedConnectionInfo(const ShardedConnectionInfo&) = delete; - ShardedConnectionInfo& operator=(const ShardedConnectionInfo&) = delete; - -public: - ShardedConnectionInfo(); - ~ShardedConnectionInfo(); - - static ShardedConnectionInfo* get(Client* client, bool create); - static void reset(Client* client); - - /** - * Returns the shard version associated with the specified namespace on this connection. If no - * version is associated with the namespace returns boost::none. - */ - boost::optional<ChunkVersion> getVersion(const std::string& ns) const; - - /** - * Assigns a new version on the connection to the specified namespace. - */ - void setVersion(const std::string& ns, const ChunkVersion& version); - -private: - typedef std::map<std::string, ChunkVersion> NSVersionMap; - - // Map from a namespace string to the chunk version with which this connection has been - // initialized for the specified namespace - NSVersionMap _versions; -}; - - -} // namespace mongo diff --git a/src/mongo/db/s/unset_sharding_command.cpp b/src/mongo/db/s/unset_sharding_command.cpp index 2b530b00fb5..a3b0d9705e5 100644 --- a/src/mongo/db/s/unset_sharding_command.cpp +++ b/src/mongo/db/s/unset_sharding_command.cpp @@ -37,12 +37,12 @@ #include "mongo/db/auth/privilege.h" #include "mongo/db/commands.h" #include "mongo/db/operation_context.h" -#include "mongo/db/s/sharded_connection_info.h" #include "mongo/util/str.h" namespace mongo { namespace { +// No-op command; deprecated as of v4.6. class UnsetShardingCommand : public BasicCommand { public: UnsetShardingCommand() : BasicCommand("unsetSharding") {} @@ -75,7 +75,6 @@ public: const std::string& dbname, const BSONObj& cmdObj, BSONObjBuilder& result) override { - ShardedConnectionInfo::reset(opCtx->getClient()); return true; } diff --git a/src/mongo/db/service_entry_point_common.cpp b/src/mongo/db/service_entry_point_common.cpp index e2ab277467f..68118644988 100644 --- a/src/mongo/db/service_entry_point_common.cpp +++ b/src/mongo/db/service_entry_point_common.cpp @@ -73,7 +73,6 @@ #include "mongo/db/repl/storage_interface.h" #include "mongo/db/run_op_kill_cursors.h" #include "mongo/db/s/operation_sharding_state.h" -#include "mongo/db/s/sharded_connection_info.h" #include "mongo/db/s/sharding_state.h" #include "mongo/db/s/transaction_coordinator_factory.h" #include "mongo/db/service_entry_point_common.h" @@ -1732,14 +1731,6 @@ DbResponse ServiceEntryPointCommon::handleRequest(OperationContext* opCtx, currentOp.done(); forceLog = true; } else { - if (!opCtx->getClient()->isInDirectClient()) { - uassert(18663, - str::stream() << "legacy writeOps not longer supported for " - << "versioned connections, ns: " << nsString.ns() - << ", op: " << networkOpToString(op), - !ShardedConnectionInfo::get(&c, false)); - } - if (!nsString.isValid()) { uassert(16257, str::stream() << "Invalid ns [" << ns << "]", false); } else if (op == dbInsert) { diff --git a/src/mongo/s/config_server_test_fixture.cpp b/src/mongo/s/config_server_test_fixture.cpp index 6f774f08f74..e098bc0fa1c 100644 --- a/src/mongo/s/config_server_test_fixture.cpp +++ b/src/mongo/s/config_server_test_fixture.cpp @@ -417,7 +417,6 @@ void ConfigServerTestFixture::expectSetShardVersion( SetShardVersionRequest ssv = assertGet(SetShardVersionRequest::parseFromBSON(request.cmdObj)); - ASSERT(!ssv.isInit()); ASSERT(ssv.isAuthoritative()); ASSERT_EQ(expectedShard.getHost(), ssv.getShardConnectionString().toString()); ASSERT_EQ(expectedNs.toString(), ssv.getNS().ns()); diff --git a/src/mongo/s/request_types/set_shard_version_request.cpp b/src/mongo/s/request_types/set_shard_version_request.cpp index f05fa4093f3..72fa066452e 100644 --- a/src/mongo/s/request_types/set_shard_version_request.cpp +++ b/src/mongo/s/request_types/set_shard_version_request.cpp @@ -46,7 +46,6 @@ const char kCmdName[] = "setShardVersion"; const char kConfigServer[] = "configdb"; const char kShardName[] = "shard"; const char kShardConnectionString[] = "shardHost"; -const char kInit[] = "init"; const char kForceRefresh[] = "forceRefresh"; const char kAuthoritative[] = "authoritative"; const char kNoConnectionVersioning[] = "noConnectionVersioning"; @@ -57,22 +56,12 @@ constexpr StringData SetShardVersionRequest::kVersion; SetShardVersionRequest::SetShardVersionRequest(ConnectionString configServer, ShardId shardName, - ConnectionString shardConnectionString) - : _init(true), - _isAuthoritative(true), - _configServer(std::move(configServer)), - _shardName(std::move(shardName)), - _shardCS(std::move(shardConnectionString)) {} - -SetShardVersionRequest::SetShardVersionRequest(ConnectionString configServer, - ShardId shardName, ConnectionString shardConnectionString, NamespaceString nss, ChunkVersion version, bool isAuthoritative, bool forceRefresh) - : _init(false), - _isAuthoritative(isAuthoritative), + : _isAuthoritative(isAuthoritative), _forceRefresh(forceRefresh), _configServer(std::move(configServer)), _shardName(std::move(shardName)), @@ -82,46 +71,6 @@ SetShardVersionRequest::SetShardVersionRequest(ConnectionString configServer, SetShardVersionRequest::SetShardVersionRequest() = default; -SetShardVersionRequest SetShardVersionRequest::makeForInit( - const ConnectionString& configServer, - const ShardId& shardName, - const ConnectionString& shardConnectionString) { - return SetShardVersionRequest(configServer, shardName, shardConnectionString); -} - -SetShardVersionRequest SetShardVersionRequest::makeForVersioning( - const ConnectionString& configServer, - const ShardId& shardName, - const ConnectionString& shardConnectionString, - const NamespaceString& nss, - const ChunkVersion& nssVersion, - bool isAuthoritative, - bool forceRefresh) { - invariant(nss.isValid()); - return SetShardVersionRequest(configServer, - shardName, - shardConnectionString, - nss, - nssVersion, - isAuthoritative, - forceRefresh); -} - -SetShardVersionRequest SetShardVersionRequest::makeForVersioningNoPersist( - const ConnectionString& configServer, - const ShardId& shardName, - const ConnectionString& shard, - const NamespaceString& nss, - const ChunkVersion& nssVersion, - bool isAuthoritative, - bool forceRefresh) { - auto ssv = makeForVersioning( - configServer, shardName, shard, nss, nssVersion, isAuthoritative, forceRefresh); - ssv._noConnectionVersioning = true; - - return ssv; -} - StatusWith<SetShardVersionRequest> SetShardVersionRequest::parseFromBSON(const BSONObj& cmdObj) { SetShardVersionRequest request; @@ -148,12 +97,6 @@ StatusWith<SetShardVersionRequest> SetShardVersionRequest::parseFromBSON(const B } { - Status status = bsonExtractBooleanFieldWithDefault(cmdObj, kInit, false, &request._init); - if (!status.isOK()) - return status; - } - - { Status status = bsonExtractBooleanFieldWithDefault( cmdObj, kForceRefresh, false, &request._forceRefresh); if (!status.isOK()) @@ -168,19 +111,6 @@ StatusWith<SetShardVersionRequest> SetShardVersionRequest::parseFromBSON(const B } { - Status status = bsonExtractBooleanFieldWithDefault( - cmdObj, kNoConnectionVersioning, false, &request._noConnectionVersioning); - if (!status.isOK()) - return status; - } - - if (request.isInit()) { - return request; - } - - // Only initialize the version information if this is not an "init" request - - { std::string ns; Status status = bsonExtractStringField(cmdObj, kCmdName, &ns); if (!status.isOK()) @@ -210,37 +140,25 @@ StatusWith<SetShardVersionRequest> SetShardVersionRequest::parseFromBSON(const B BSONObj SetShardVersionRequest::toBSON() const { BSONObjBuilder cmdBuilder; - cmdBuilder.append(kCmdName, _init ? "" : _nss.get().ns()); - cmdBuilder.append(kInit, _init); + cmdBuilder.append(kCmdName, _nss.get().ns()); cmdBuilder.append(kForceRefresh, _forceRefresh); cmdBuilder.append(kAuthoritative, _isAuthoritative); - // 'configdb' field is only included for v3.4 backwards compatibility + // TODO (SERVER-47440): Remove adding config server to BSON once v4.4 parsing is + // removed. cmdBuilder.append(kConfigServer, _configServer.toString()); cmdBuilder.append(kShardName, _shardName.toString()); cmdBuilder.append(kShardConnectionString, _shardCS.toString()); - if (_init) { - // Always include a 30 second timeout on sharding state initialization, to work around - // SERVER-21458. - cmdBuilder.append(QueryRequest::cmdOptionMaxTimeMS, 30000); - } else { - _version->appendLegacyWithField(&cmdBuilder, kVersion); - } - - if (_noConnectionVersioning) { - cmdBuilder.append(kNoConnectionVersioning, true); - } + _version->appendLegacyWithField(&cmdBuilder, kVersion); return cmdBuilder.obj(); } const NamespaceString& SetShardVersionRequest::getNS() const { - invariant(!_init); return _nss.get(); } const ChunkVersion SetShardVersionRequest::getNSVersion() const { - invariant(!_init); return _version.get(); } diff --git a/src/mongo/s/request_types/set_shard_version_request.h b/src/mongo/s/request_types/set_shard_version_request.h index 59e571b20c4..70c5ee678e3 100644 --- a/src/mongo/s/request_types/set_shard_version_request.h +++ b/src/mongo/s/request_types/set_shard_version_request.h @@ -50,50 +50,13 @@ class SetShardVersionRequest { public: static constexpr StringData kVersion = "version"_sd; - /** - * Constructs a new set shard version request, which is of the "init" type, meaning it has no - * namespace or version information associated with it and the init flag is set. - * The constructed request will not contain the "noConnectionVersioning" field, which means that - * the entire connection will be marked as "versioned" on the mongod side. DO NOT USE when - * sending through the TaskExecutor, which pools connections without consideration for which - * are marked as sharded. - */ - static SetShardVersionRequest makeForInit(const ConnectionString& configServer, - const ShardId& shardName, - const ConnectionString& shardConnectionString); - - /** - * Constructs a new set shard version request, which is of the "versioning" type, meaning it has - * both initialization data and namespace and version information associated with it. - * - * The constructed request will not contain the "noConnectionVersioning" field, which means that - * the entire connection will be marked as "versioned" on the mongod side. DO NOT USE when - * sending through the TaskExecutor, which pools connections without consideration for which - * are marked as sharded. - */ - static SetShardVersionRequest makeForVersioning(const ConnectionString& configServer, - const ShardId& shardName, - const ConnectionString& shard, - const NamespaceString& nss, - const ChunkVersion& nssVersion, - bool isAuthoritative, - bool forceRefresh = false); - - /** - * Constructs a new set shard version request, which is of the "versioning" type, meaning it has - * both initialization data and namespace and version information associated with it. In - * addition, the request will contain the "noConnectionVersioning" field, which means that the - * connection WILL NOT be marked as "versioned". DO NOT USE except on connections only used - * with operations that do per-operation versioning, and do not depend on the connection being - * marked as sharded. - */ - static SetShardVersionRequest makeForVersioningNoPersist(const ConnectionString& configServer, - const ShardId& shardName, - const ConnectionString& shard, - const NamespaceString& nss, - const ChunkVersion& nssVersion, - bool isAuthoritative, - bool forceRefresh = false); + SetShardVersionRequest(ConnectionString configServer, + ShardId shardName, + ConnectionString shardConnectionString, + NamespaceString nss, + ChunkVersion version, + bool isAuthoritative, + bool forceRefresh = false); /** * Parses an SSV request from a set shard version command. @@ -106,16 +69,6 @@ public: BSONObj toBSON() const; /** - * Returns whether this is an "init" type of request, where we only have the config server - * information and the identity that the targeted shard should assume or it contains namespace - * version as well. If this value is true, it is illegal to access anything other than the - * config server, shard name and shard connection string fields. - */ - bool isInit() const { - return _init; - } - - /** * Returns whether this request should force the version to be set instead of it being reloaded * and recalculated from the metadata. */ @@ -154,41 +107,19 @@ public: */ const ChunkVersion getNSVersion() const; - /** - * Returns whether this setShardVersion request should be persisted on the connection or it - * should only be used to initialize the namespace in the global sharding state. - */ - bool getNoConnectionVersioning() const { - return _noConnectionVersioning; - } - private: - SetShardVersionRequest(ConnectionString configServer, - ShardId shardName, - ConnectionString shardConnectionString); - - SetShardVersionRequest(ConnectionString configServer, - ShardId shardName, - ConnectionString shardConnectionString, - NamespaceString nss, - ChunkVersion version, - bool isAuthoritative, - bool forceRefresh = false); - SetShardVersionRequest(); - bool _init{false}; bool _isAuthoritative{false}; bool _forceRefresh{false}; - bool _noConnectionVersioning{false}; - // Only required for v3.4 backwards compatibility. + // TODO (SERVER-47440): Remove this parameter once the v4.4 SetShardVersion command stops + // parsing it. ConnectionString _configServer; ShardId _shardName; ConnectionString _shardCS; - // These values are only set if _init is false boost::optional<NamespaceString> _nss; boost::optional<ChunkVersion> _version; }; diff --git a/src/mongo/s/request_types/set_shard_version_request_test.cpp b/src/mongo/s/request_types/set_shard_version_request_test.cpp index 59003730f98..2f1a2e880ca 100644 --- a/src/mongo/s/request_types/set_shard_version_request_test.cpp +++ b/src/mongo/s/request_types/set_shard_version_request_test.cpp @@ -46,53 +46,6 @@ const ConnectionString configCS = ConnectionString::forReplicaSet( const ConnectionString shardCS = ConnectionString::forReplicaSet( "ShardRS", {HostAndPort{"shardHost1:12345"}, HostAndPort{"shardHost2:12345"}}); -TEST(SetShardVersionRequest, ParseInitMissingAuthoritative) { - SetShardVersionRequest request = assertGet( - SetShardVersionRequest::parseFromBSON(BSON("setShardVersion" - << "" - << "init" << true << "shard" - << "TestShard" - << "shardHost" << shardCS.toString()))); - - ASSERT(request.isInit()); - ASSERT(!request.isAuthoritative()); - ASSERT(!request.getNoConnectionVersioning()); - ASSERT_EQ(request.getShardName(), "TestShard"); - ASSERT_EQ(request.getShardConnectionString().toString(), shardCS.toString()); -} - -TEST(SetShardVersionRequest, ParseInitWithAuthoritative) { - SetShardVersionRequest request = - assertGet(SetShardVersionRequest::parseFromBSON( - BSON("setShardVersion" - << "" - << "init" << true << "authoritative" << true << "shard" - << "TestShard" - << "shardHost" << shardCS.toString()))); - - ASSERT(request.isInit()); - ASSERT(request.isAuthoritative()); - ASSERT(!request.getNoConnectionVersioning()); - ASSERT_EQ(request.getShardName(), "TestShard"); - ASSERT_EQ(request.getShardConnectionString().toString(), shardCS.toString()); -} - -TEST(SetShardVersionRequest, ParseInitNoConnectionVersioning) { - SetShardVersionRequest request = - assertGet(SetShardVersionRequest::parseFromBSON( - BSON("setShardVersion" - << "" - << "init" << true << "authoritative" << true << "shard" - << "TestShard" - << "shardHost" << shardCS.toString() << "noConnectionVersioning" << true))); - - ASSERT(request.isInit()); - ASSERT(request.isAuthoritative()); - ASSERT(request.getNoConnectionVersioning()); - ASSERT_EQ(request.getShardName(), "TestShard"); - ASSERT_EQ(request.getShardConnectionString().toString(), shardCS.toString()); -} - TEST(SetShardVersionRequest, ParseFull) { const ChunkVersion chunkVersion(1, 2, OID::gen()); @@ -105,10 +58,8 @@ TEST(SetShardVersionRequest, ParseFull) { << "shardHost" << shardCS.toString() << "version" << Timestamp(chunkVersion.toLong()) << "versionEpoch" << chunkVersion.epoch()))); - ASSERT(!request.isInit()); ASSERT(!request.shouldForceRefresh()); ASSERT(!request.isAuthoritative()); - ASSERT(!request.getNoConnectionVersioning()); ASSERT_EQ(request.getShardName(), "TestShard"); ASSERT_EQ(request.getShardConnectionString().toString(), shardCS.toString()); ASSERT_EQ(request.getNS().toString(), "db.coll"); @@ -130,10 +81,8 @@ TEST(SetShardVersionRequest, ParseFullWithAuthoritative) { << Timestamp(chunkVersion.toLong()) << "versionEpoch" << chunkVersion.epoch() << "authoritative" << true))); - ASSERT(!request.isInit()); ASSERT(!request.shouldForceRefresh()); ASSERT(request.isAuthoritative()); - ASSERT(!request.getNoConnectionVersioning()); ASSERT_EQ(request.getShardName(), "TestShard"); ASSERT_EQ(request.getShardConnectionString().toString(), shardCS.toString()); ASSERT_EQ(request.getNS().toString(), "db.coll"); @@ -155,10 +104,8 @@ TEST(SetShardVersionRequest, ParseFullNoConnectionVersioning) { << Timestamp(chunkVersion.toLong()) << "versionEpoch" << chunkVersion.epoch() << "noConnectionVersioning" << true))); - ASSERT(!request.isInit()); ASSERT(!request.shouldForceRefresh()); ASSERT(!request.isAuthoritative()); - ASSERT(request.getNoConnectionVersioning()); ASSERT_EQ(request.getShardName(), "TestShard"); ASSERT_EQ(request.getShardConnectionString().toString(), shardCS.toString()); ASSERT_EQ(request.getNS().toString(), "db.coll"); @@ -197,36 +144,14 @@ TEST(SetShardVersionRequest, ParseFullNSContainsDBOnly) { ASSERT_EQ(ErrorCodes::InvalidNamespace, ssvStatus.getStatus().code()); } -TEST(SetShardVersionRequest, ToSSVCommandInit) { - SetShardVersionRequest ssv = - SetShardVersionRequest::makeForInit(configCS, ShardId("TestShard"), shardCS); - - ASSERT(ssv.isInit()); - ASSERT(!ssv.shouldForceRefresh()); - ASSERT(ssv.isAuthoritative()); - ASSERT(!ssv.getNoConnectionVersioning()); - ASSERT_EQ(ssv.getShardName(), "TestShard"); - ASSERT_EQ(ssv.getShardConnectionString().toString(), shardCS.toString()); - - ASSERT_BSONOBJ_EQ(ssv.toBSON(), - BSON("setShardVersion" - << "" - << "init" << true << "forceRefresh" << false << "authoritative" << true - << "configdb" << configCS.toString() << "shard" - << "TestShard" - << "shardHost" << shardCS.toString() << "maxTimeMS" << 30000)); -} - TEST(SetShardVersionRequest, ToSSVCommandFull) { const ChunkVersion chunkVersion(1, 2, OID::gen()); - SetShardVersionRequest ssv = SetShardVersionRequest::makeForVersioning( + SetShardVersionRequest ssv( configCS, ShardId("TestShard"), shardCS, NamespaceString("db.coll"), chunkVersion, false); - ASSERT(!ssv.isInit()); ASSERT(!ssv.shouldForceRefresh()); ASSERT(!ssv.isAuthoritative()); - ASSERT(!ssv.getNoConnectionVersioning()); ASSERT_EQ(ssv.getShardName(), "TestShard"); ASSERT_EQ(ssv.getShardConnectionString().toString(), shardCS.toString()); ASSERT_EQ(ssv.getNS().ns(), "db.coll"); @@ -235,8 +160,8 @@ TEST(SetShardVersionRequest, ToSSVCommandFull) { ASSERT_BSONOBJ_EQ(ssv.toBSON(), BSON("setShardVersion" << "db.coll" - << "init" << false << "forceRefresh" << false << "authoritative" << false - << "configdb" << configCS.toString() << "shard" + << "forceRefresh" << false << "authoritative" << false << "configdb" + << configCS.toString() << "shard" << "TestShard" << "shardHost" << shardCS.toString() << "version" << Timestamp(chunkVersion.toLong()) << "versionEpoch" @@ -246,13 +171,11 @@ TEST(SetShardVersionRequest, ToSSVCommandFull) { TEST(SetShardVersionRequest, ToSSVCommandFullAuthoritative) { const ChunkVersion chunkVersion(1, 2, OID::gen()); - SetShardVersionRequest ssv = SetShardVersionRequest::makeForVersioning( + SetShardVersionRequest ssv( configCS, ShardId("TestShard"), shardCS, NamespaceString("db.coll"), chunkVersion, true); - ASSERT(!ssv.isInit()); ASSERT(!ssv.shouldForceRefresh()); ASSERT(ssv.isAuthoritative()); - ASSERT(!ssv.getNoConnectionVersioning()); ASSERT_EQ(ssv.getShardName(), "TestShard"); ASSERT_EQ(ssv.getShardConnectionString().toString(), shardCS.toString()); ASSERT_EQ(ssv.getNS().ns(), "db.coll"); @@ -261,8 +184,8 @@ TEST(SetShardVersionRequest, ToSSVCommandFullAuthoritative) { ASSERT_BSONOBJ_EQ(ssv.toBSON(), BSON("setShardVersion" << "db.coll" - << "init" << false << "forceRefresh" << false << "authoritative" << true - << "configdb" << configCS.toString() << "shard" + << "forceRefresh" << false << "authoritative" << true << "configdb" + << configCS.toString() << "shard" << "TestShard" << "shardHost" << shardCS.toString() << "version" << Timestamp(chunkVersion.toLong()) << "versionEpoch" @@ -272,19 +195,16 @@ TEST(SetShardVersionRequest, ToSSVCommandFullAuthoritative) { TEST(SetShardVersionRequest, ToSSVCommandFullForceRefresh) { const ChunkVersion chunkVersion(1, 2, OID::gen()); - SetShardVersionRequest ssv = - SetShardVersionRequest::makeForVersioning(configCS, - ShardId("TestShard"), - shardCS, - NamespaceString("db.coll"), - chunkVersion, - false, - true); + SetShardVersionRequest ssv(configCS, + ShardId("TestShard"), + shardCS, + NamespaceString("db.coll"), + chunkVersion, + false, + true); - ASSERT(!ssv.isInit()); ASSERT(ssv.shouldForceRefresh()); ASSERT(!ssv.isAuthoritative()); - ASSERT(!ssv.getNoConnectionVersioning()); ASSERT_EQ(ssv.getShardName(), "TestShard"); ASSERT_EQ(ssv.getShardConnectionString().toString(), shardCS.toString()); ASSERT_EQ(ssv.getNS().ns(), "db.coll"); @@ -293,72 +213,13 @@ TEST(SetShardVersionRequest, ToSSVCommandFullForceRefresh) { ASSERT_BSONOBJ_EQ(ssv.toBSON(), BSON("setShardVersion" << "db.coll" - << "init" << false << "forceRefresh" << true << "authoritative" << false - << "configdb" << configCS.toString() << "shard" + << "forceRefresh" << true << "authoritative" << false << "configdb" + << configCS.toString() << "shard" << "TestShard" << "shardHost" << shardCS.toString() << "version" << Timestamp(chunkVersion.toLong()) << "versionEpoch" << chunkVersion.epoch())); } -TEST(SetShardVersionRequest, ToSSVCommandFullNoConnectionVersioning) { - const ChunkVersion chunkVersion(1, 2, OID::gen()); - - SetShardVersionRequest ssv = SetShardVersionRequest::makeForVersioningNoPersist( - configCS, ShardId("TestShard"), shardCS, NamespaceString("db.coll"), chunkVersion, true); - - ASSERT(!ssv.isInit()); - ASSERT(!ssv.shouldForceRefresh()); - ASSERT(ssv.isAuthoritative()); - ASSERT(ssv.getNoConnectionVersioning()); - ASSERT_EQ(ssv.getShardName(), "TestShard"); - ASSERT_EQ(ssv.getShardConnectionString().toString(), shardCS.toString()); - ASSERT_EQ(ssv.getNS().ns(), "db.coll"); - ASSERT_BSONOBJ_EQ(ssv.getNSVersion().toBSON(), chunkVersion.toBSON()); - - ASSERT_BSONOBJ_EQ(ssv.toBSON(), - BSON("setShardVersion" - << "db.coll" - << "init" << false << "forceRefresh" << false << "authoritative" << true - << "configdb" << configCS.toString() << "shard" - << "TestShard" - << "shardHost" << shardCS.toString() << "version" - << Timestamp(chunkVersion.toLong()) << "versionEpoch" - << chunkVersion.epoch() << "noConnectionVersioning" << true)); -} - -TEST(SetShardVersionRequest, ToSSVCommandFullNoConnectionVersioningForceRefresh) { - const ChunkVersion chunkVersion(1, 2, OID::gen()); - - SetShardVersionRequest ssv = - SetShardVersionRequest::makeForVersioningNoPersist(configCS, - ShardId("TestShard"), - shardCS, - NamespaceString("db.coll"), - chunkVersion, - false, - true); - - ASSERT(!ssv.isInit()); - ASSERT(ssv.shouldForceRefresh()); - ASSERT(!ssv.isAuthoritative()); - ASSERT(ssv.getNoConnectionVersioning()); - ASSERT_EQ(ssv.getShardName(), "TestShard"); - ASSERT_EQ(ssv.getShardConnectionString().toString(), shardCS.toString()); - ASSERT_EQ(ssv.getNS().ns(), "db.coll"); - ASSERT_BSONOBJ_EQ(ssv.getNSVersion().toBSON(), chunkVersion.toBSON()); - - ASSERT_BSONOBJ_EQ(ssv.toBSON(), - BSON("setShardVersion" - << "db.coll" - << "init" << false << "forceRefresh" << true << "authoritative" << false - << "configdb" << configCS.toString() << "shard" - << "TestShard" - << "shardHost" << shardCS.toString() << "version" - << Timestamp(chunkVersion.toLong()) << "versionEpoch" - << chunkVersion.epoch() << "noConnectionVersioning" << true)); -} - - } // namespace } // namespace mongo diff --git a/src/mongo/s/sharding_router_test_fixture.cpp b/src/mongo/s/sharding_router_test_fixture.cpp index c4114df7138..b4aff842805 100644 --- a/src/mongo/s/sharding_router_test_fixture.cpp +++ b/src/mongo/s/sharding_router_test_fixture.cpp @@ -459,7 +459,6 @@ void ShardingTestFixture::expectSetShardVersion(const HostAndPort& expectedHost, SetShardVersionRequest ssv = assertGet(SetShardVersionRequest::parseFromBSON(request.cmdObj)); - ASSERT(!ssv.isInit()); ASSERT(ssv.isAuthoritative()); ASSERT_EQ(expectedShard.getHost(), ssv.getShardConnectionString().toString()); ASSERT_EQ(expectedNs, ssv.getNS()); |