diff options
33 files changed, 111 insertions, 177 deletions
diff --git a/src/mongo/client/parallel.cpp b/src/mongo/client/parallel.cpp index 9102eb417b1..11ee0a32e42 100644 --- a/src/mongo/client/parallel.cpp +++ b/src/mongo/client/parallel.cpp @@ -566,8 +566,8 @@ namespace mongo { verify( ! primary || shard == *primary ); // Setup conn - if ( !state->conn ){ - state->conn.reset( new ShardConnection( shard, ns, manager ) ); + if (!state->conn) { + state->conn.reset(new ShardConnection(shard.getConnString(), ns, manager)); } const DBClientBase* rawConn = state->conn->getRawConn(); diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript index 90e8cfc91cd..aa3583ddb4a 100644 --- a/src/mongo/s/SConscript +++ b/src/mongo/s/SConscript @@ -7,7 +7,6 @@ Import("env") # env.Library('base', ['mongo_version_range.cpp', - 'type_database.cpp', 'type_locks.cpp', 'type_lockpings.cpp', 'type_config_version.cpp', @@ -29,10 +28,6 @@ env.CppUnitTest('type_config_version_test', 'type_config_version_test.cpp', LIBDEPS=['base', '$BUILD_DIR/mongo/db/common']) -env.CppUnitTest('type_database_test', 'type_database_test.cpp', - LIBDEPS=['base', - '$BUILD_DIR/mongo/db/common']) - env.CppUnitTest('type_locks_test', 'type_locks_test.cpp', LIBDEPS=['base', '$BUILD_DIR/mongo/db/common']) diff --git a/src/mongo/s/balance.cpp b/src/mongo/s/balance.cpp index bcceea3d366..6e52b7e1346 100644 --- a/src/mongo/s/balance.cpp +++ b/src/mongo/s/balance.cpp @@ -354,8 +354,7 @@ namespace mongo { return; } - auto_ptr<ChunkType> chunk(new ChunkType()); - chunkRes.getValue().cloneTo(chunk.get()); + auto_ptr<ChunkType> chunk(new ChunkType(chunkRes.getValue())); allChunkMinimums.insert(chunk->getMin().getOwned()); OwnedPointerVector<ChunkType>*& chunkList = diff --git a/src/mongo/s/balancer_policy.cpp b/src/mongo/s/balancer_policy.cpp index e8b0461da99..e35356e9653 100644 --- a/src/mongo/s/balancer_policy.cpp +++ b/src/mongo/s/balancer_policy.cpp @@ -372,7 +372,7 @@ namespace mongo { // since we have to move all chunks, lets just do in order for ( unsigned i=0; i<chunks.size(); i++ ) { const ChunkType& chunkToMove = *chunks[i]; - if (chunkToMove.isJumboSet() && chunkToMove.getJumbo()) { + if (chunkToMove.getJumbo()) { numJumboChunks++; continue; } @@ -424,7 +424,7 @@ namespace mongo { << " is not on a shard with the right tag: " << tag << endl; - if (chunk.isJumboSet() && chunk.getJumbo()) { + if (chunk.getJumbo()) { warning() << "chunk " << chunk << " is jumbo, so cannot be moved" << endl; continue; } @@ -497,7 +497,7 @@ namespace mongo { if (distribution.getTagForChunk(chunk) != tag) continue; - if (chunk.isJumboSet() && chunk.getJumbo()) { + if (chunk.getJumbo()) { numJumboChunks++; continue; } diff --git a/src/mongo/s/catalog/SConscript b/src/mongo/s/catalog/SConscript index f8ae4049b1b..9479cc7c109 100644 --- a/src/mongo/s/catalog/SConscript +++ b/src/mongo/s/catalog/SConscript @@ -9,6 +9,7 @@ env.Library( 'type_changelog.cpp', 'type_chunk.cpp', 'type_collection.cpp', + 'type_database.cpp', 'type_settings.cpp', 'type_shard.cpp' ], @@ -40,6 +41,7 @@ env.CppUnitTest( 'type_changelog_test.cpp', 'type_chunk_test.cpp', 'type_collection_test.cpp', + 'type_database_test.cpp', 'type_settings_test.cpp', 'type_shard_test.cpp' ], diff --git a/src/mongo/s/catalog/catalog_cache.cpp b/src/mongo/s/catalog/catalog_cache.cpp index 03238143af5..67563bcb002 100644 --- a/src/mongo/s/catalog/catalog_cache.cpp +++ b/src/mongo/s/catalog/catalog_cache.cpp @@ -34,8 +34,8 @@ #include "mongo/base/status_with.h" #include "mongo/s/catalog/catalog_manager.h" +#include "mongo/s/catalog/type_database.h" #include "mongo/s/config.h" -#include "mongo/s/type_database.h" namespace mongo { diff --git a/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp b/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp index a97dc9e773e..73ce0f9a07d 100644 --- a/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp +++ b/src/mongo/s/catalog/legacy/catalog_manager_legacy.cpp @@ -50,6 +50,7 @@ #include "mongo/s/catalog/type_changelog.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/catalog/type_collection.h" +#include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog/type_settings.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/chunk_manager.h" @@ -60,7 +61,6 @@ #include "mongo/s/dist_lock_manager.h" #include "mongo/s/legacy_dist_lock_manager.h" #include "mongo/s/shard_key_pattern.h" -#include "mongo/s/type_database.h" #include "mongo/s/write_ops/batched_command_request.h" #include "mongo/s/write_ops/batched_command_response.h" #include "mongo/stdx/memory.h" @@ -269,6 +269,10 @@ namespace { } // namespace + CatalogManagerLegacy::CatalogManagerLegacy() = default; + + CatalogManagerLegacy::~CatalogManagerLegacy() = default; + Status CatalogManagerLegacy::init(const ConnectionString& configDBCS) { // Initialization should not happen more than once invariant(!_configServerConnectionString.isValid()); @@ -471,8 +475,9 @@ namespace { << ", other mongoses may not see the collection as sharded immediately"; break; } + try { - ShardConnection conn(dbPrimary, ns); + ShardConnection conn(dbPrimary.getConnString(), ns); bool isVersionSet = conn.setVersion(); conn.done(); if (!isVersionSet) { @@ -487,6 +492,7 @@ namespace { << " on shard primary " << dbPrimary << causedBy(e); } + sleepsecs(i); } diff --git a/src/mongo/s/catalog/legacy/catalog_manager_legacy.h b/src/mongo/s/catalog/legacy/catalog_manager_legacy.h index c9c9f440262..b30cab8f20b 100644 --- a/src/mongo/s/catalog/legacy/catalog_manager_legacy.h +++ b/src/mongo/s/catalog/legacy/catalog_manager_legacy.h @@ -34,17 +34,19 @@ #include "mongo/bson/bsonobj.h" #include "mongo/client/dbclientinterface.h" #include "mongo/s/catalog/catalog_manager.h" -#include "mongo/s/dist_lock_manager.h" namespace mongo { + class DistLockManager; + + /** * Implements the catalog manager using the legacy 3-config server protocol. */ class CatalogManagerLegacy : public CatalogManager { public: - CatalogManagerLegacy() = default; - virtual ~CatalogManagerLegacy() = default; + CatalogManagerLegacy(); + virtual ~CatalogManagerLegacy(); /** * Initializes the catalog manager with the hosts, which will be used as a configuration @@ -133,10 +135,12 @@ namespace mongo { */ size_t _getShardCount(const BSONObj& query = {}) const; + // Parsed config server hosts, as specified on the command line. ConnectionString _configServerConnectionString; std::vector<ConnectionString> _configServers; + // Distribted lock manager singleton. std::unique_ptr<DistLockManager> _distLockManager; }; diff --git a/src/mongo/s/catalog/legacy/config_upgrade.cpp b/src/mongo/s/catalog/legacy/config_upgrade.cpp index a68963b161f..d4f34ae64de 100644 --- a/src/mongo/s/catalog/legacy/config_upgrade.cpp +++ b/src/mongo/s/catalog/legacy/config_upgrade.cpp @@ -39,13 +39,13 @@ #include "mongo/s/catalog/catalog_manager.h" #include "mongo/s/catalog/legacy/cluster_client_internal.h" #include "mongo/s/catalog/type_collection.h" +#include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog/type_settings.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/dist_lock_manager.h" #include "mongo/s/grid.h" #include "mongo/s/mongo_version_range.h" #include "mongo/s/type_config_version.h" -#include "mongo/s/type_database.h" #include "mongo/stdx/functional.h" #include "mongo/util/assert_util.h" #include "mongo/util/log.h" diff --git a/src/mongo/s/catalog/type_chunk.cpp b/src/mongo/s/catalog/type_chunk.cpp index 03765bd5982..6598b80b889 100644 --- a/src/mongo/s/catalog/type_chunk.cpp +++ b/src/mongo/s/catalog/type_chunk.cpp @@ -53,12 +53,6 @@ namespace mongo { const BSONField<Date_t> ChunkType::DEPRECATED_lastmod("lastmod"); const BSONField<OID> ChunkType::DEPRECATED_epoch("lastmodEpoch"); - ChunkType::ChunkType() { - clear(); - } - - ChunkType::~ChunkType() { - } StatusWith<ChunkType> ChunkType::fromBSON(const BSONObj& source) { ChunkType chunk; @@ -100,12 +94,16 @@ namespace mongo { { bool chunkJumbo; - Status status = bsonExtractBooleanFieldWithDefault(source, - jumbo.name(), - false, - &chunkJumbo); - if (!status.isOK()) return status; - chunk._jumbo = chunkJumbo; + Status status = bsonExtractBooleanField(source, jumbo.name(), &chunkJumbo); + if (status.isOK()) { + chunk._jumbo = chunkJumbo; + } + else if (status == ErrorCodes::NoSuchKey) { + // Jumbo status is missing, so it will be presumed false + } + else { + return status; + } } // @@ -202,26 +200,7 @@ namespace mongo { } void ChunkType::clear() { - _name.reset(); - _ns.reset(); - _min.reset(); - _max.reset(); - _version.reset(); - _shard.reset(); - _jumbo.reset(); - } - - void ChunkType::cloneTo(ChunkType* other) const { - invariant(other); - other->clear(); - - other->_name = _name; - other->_ns = _ns; - other->_min = _min->getOwned(); - other->_max = _max->getOwned(); - other->_version = _version; - other->_shard = _shard; - other->_jumbo = _jumbo; + *this = ChunkType(); } std::string ChunkType::toString() const { @@ -258,7 +237,7 @@ namespace mongo { _shard = shard; } - void ChunkType::setJumbo(const bool jumbo) { + void ChunkType::setJumbo(bool jumbo) { _jumbo = jumbo; } diff --git a/src/mongo/s/catalog/type_chunk.h b/src/mongo/s/catalog/type_chunk.h index a53c256b6c0..ada95edc2e1 100644 --- a/src/mongo/s/catalog/type_chunk.h +++ b/src/mongo/s/catalog/type_chunk.h @@ -78,8 +78,6 @@ namespace mongo { static const BSONField<Date_t> DEPRECATED_lastmod; static const BSONField<OID> DEPRECATED_epoch; - ChunkType(); - ~ChunkType(); /** * Constructs a new ChunkType object from BSON. @@ -104,28 +102,19 @@ namespace mongo { void clear(); /** - * Copies all the fields present in 'this' to 'other'. - */ - void cloneTo(ChunkType* other) const; - - /** * Returns a std::string representation of the current internal state. */ std::string toString() const; - bool isNameSet() const { return _name.is_initialized(); } const std::string& getName() const { return _name.get(); } void setName(const std::string& name); - bool isNSSet() const { return _ns.is_initialized(); } const std::string& getNS() const { return _ns.get(); } void setNS(const std::string& name); - bool isMinSet() const { return _min.is_initialized(); } const BSONObj& getMin() const { return _min.get(); } void setMin(const BSONObj& min); - bool isMaxSet() const { return _max.is_initialized(); } const BSONObj& getMax() const { return _max.get(); } void setMax(const BSONObj& max); @@ -133,13 +122,11 @@ namespace mongo { const ChunkVersion& getVersion() const { return _version.get(); } void setVersion(const ChunkVersion& version); - bool isShardSet() const { return _shard.is_initialized(); } const std::string& getShard() const { return _shard.get(); } void setShard(const std::string& shard); - bool isJumboSet() const { return _jumbo.is_initialized(); } - bool getJumbo() const { return _jumbo.get(); } - void setJumbo(const bool); + bool getJumbo() const { return _jumbo.get_value_or(false); } + void setJumbo(bool jumbo); private: diff --git a/src/mongo/s/catalog/type_chunk_test.cpp b/src/mongo/s/catalog/type_chunk_test.cpp index 98c474020a4..db86f9fe809 100644 --- a/src/mongo/s/catalog/type_chunk_test.cpp +++ b/src/mongo/s/catalog/type_chunk_test.cpp @@ -32,7 +32,6 @@ #include "mongo/base/status_with.h" #include "mongo/db/jsobj.h" -#include "mongo/s/chunk_version.h" #include "mongo/unittest/unittest.h" #include "mongo/util/time_support.h" diff --git a/src/mongo/s/type_database.cpp b/src/mongo/s/catalog/type_database.cpp index 86e46762a11..222f46cf301 100644 --- a/src/mongo/s/type_database.cpp +++ b/src/mongo/s/catalog/type_database.cpp @@ -28,7 +28,7 @@ #include "mongo/platform/basic.h" -#include "mongo/s/type_database.h" +#include "mongo/s/catalog/type_database.h" #include "mongo/base/status_with.h" #include "mongo/bson/bsonobj.h" @@ -47,10 +47,6 @@ namespace mongo { const BSONField<bool> DatabaseType::sharded("partitioned"); - DatabaseType::DatabaseType() { - clear(); - } - StatusWith<DatabaseType> DatabaseType::fromBSON(const BSONObj& source) { DatabaseType dbt; @@ -106,12 +102,6 @@ namespace mongo { return builder.obj(); } - void DatabaseType::clear() { - _name.reset(); - _primary.reset(); - _sharded.reset(); - } - std::string DatabaseType::toString() const { return toBSON().toString(); } diff --git a/src/mongo/s/type_database.h b/src/mongo/s/catalog/type_database.h index cbecfd490f4..95735903307 100644 --- a/src/mongo/s/type_database.h +++ b/src/mongo/s/catalog/type_database.h @@ -55,8 +55,6 @@ namespace mongo { static const BSONField<bool> sharded; - DatabaseType(); - /** * Constructs a new DatabaseType object from BSON. Also does validation of the contents. */ @@ -74,11 +72,6 @@ namespace mongo { BSONObj toBSON() const; /** - * Clears the internal state. - */ - void clear(); - - /** * Returns a std::string representation of the current internal state. */ std::string toString() const; diff --git a/src/mongo/s/type_database_test.cpp b/src/mongo/s/catalog/type_database_test.cpp index b0132c34a88..db7f9be9575 100644 --- a/src/mongo/s/type_database_test.cpp +++ b/src/mongo/s/catalog/type_database_test.cpp @@ -30,7 +30,7 @@ #include "mongo/base/status_with.h" #include "mongo/db/jsobj.h" -#include "mongo/s/type_database.h" +#include "mongo/s/catalog/type_database.h" #include "mongo/unittest/unittest.h" namespace { diff --git a/src/mongo/s/chunk_diff-inl.h b/src/mongo/s/chunk_diff-inl.h index 5b6ea336840..59692b1fdfa 100644 --- a/src/mongo/s/chunk_diff-inl.h +++ b/src/mongo/s/chunk_diff-inl.h @@ -34,7 +34,6 @@ #include "mongo/logger/logger.h" #include "mongo/logger/logstream_builder.h" #include "mongo/s/catalog/type_chunk.h" -#include "mongo/s/chunk_version.h" #include "mongo/util/concurrency/thread_name.h" namespace mongo { diff --git a/src/mongo/s/chunk_version.h b/src/mongo/s/chunk_version.h index 959c1aaa737..258097ec9cf 100644 --- a/src/mongo/s/chunk_version.h +++ b/src/mongo/s/chunk_version.h @@ -29,7 +29,6 @@ #pragma once #include "mongo/db/jsobj.h" -#include "mongo/s/bson_serializable.h" namespace mongo { @@ -46,7 +45,7 @@ namespace mongo { * TODO: This is a "manual type" but, even so, still needs to comform to what's * expected from types. */ - struct ChunkVersion : public BSONSerializable { + struct ChunkVersion { union { struct { @@ -412,17 +411,7 @@ namespace mongo { b.append( prefix + "Epoch", _epoch ); } - // - // bson serializable interface implementation - // (toBSON and toString were implemented above) - // - - virtual bool isValid(std::string* errMsg) const { - // TODO is there any check we want to do here? - return true; - } - - virtual BSONObj toBSON() const { + BSONObj toBSON() const { // ChunkVersion wants to be an array. BSONArrayBuilder b; b.appendTimestamp(_combined); @@ -430,7 +419,7 @@ namespace mongo { return b.arr(); } - virtual bool parseBSON(const BSONObj& source, std::string* errMsg) { + bool parseBSON(const BSONObj& source, std::string* errMsg) { // ChunkVersion wants to be an array. BSONArray arrSource = static_cast<BSONArray>(source); @@ -447,7 +436,7 @@ namespace mongo { return true; } - virtual void clear() { + void clear() { _minor = 0; _major = 0; _epoch = OID(); diff --git a/src/mongo/s/client/shard_connection.cpp b/src/mongo/s/client/shard_connection.cpp index abce4b04db2..b4bda6824c2 100644 --- a/src/mongo/s/client/shard_connection.cpp +++ b/src/mongo/s/client/shard_connection.cpp @@ -410,22 +410,6 @@ namespace { void usingAShardConnection(const string& addr); - ShardConnection::ShardConnection(const Shard * s, const string& ns, ChunkManagerPtr manager) - : _addr(s->getConnString()), - _ns(ns), - _manager(manager) { - - _init(); - } - - ShardConnection::ShardConnection(const Shard& s, const string& ns, ChunkManagerPtr manager) - : _addr(s.getConnString()), - _ns(ns), - _manager( manager ) { - - _init(); - } - ShardConnection::ShardConnection(const string& addr, const string& ns, ChunkManagerPtr manager) : _addr(addr), _ns(ns), diff --git a/src/mongo/s/client/shard_connection.h b/src/mongo/s/client/shard_connection.h index ff280ddd774..5bb77ffbb84 100644 --- a/src/mongo/s/client/shard_connection.h +++ b/src/mongo/s/client/shard_connection.h @@ -37,14 +37,11 @@ namespace mongo { class ChunkManager; - class Shard; - typedef boost::shared_ptr<ChunkManager> ChunkManagerPtr; + class ShardConnection : public AScopedConnection { public: - ShardConnection(const Shard* s, const std::string& ns, ChunkManagerPtr manager = ChunkManagerPtr()); - ShardConnection(const Shard& s, const std::string& ns, ChunkManagerPtr manager = ChunkManagerPtr()); ShardConnection(const std::string& addr, const std::string& ns, ChunkManagerPtr manager = ChunkManagerPtr()); ~ShardConnection(); diff --git a/src/mongo/s/collection_metadata_test.cpp b/src/mongo/s/collection_metadata_test.cpp index c60e9605058..68e2eefabe5 100644 --- a/src/mongo/s/collection_metadata_test.cpp +++ b/src/mongo/s/collection_metadata_test.cpp @@ -676,7 +676,6 @@ namespace { ASSERT_EQUALS( version.majorVersion(), newVersion.majorVersion() ); ASSERT_EQUALS( version.minorVersion() + 1, newVersion.minorVersion() ); - chunk.clear(); ASSERT( cloned->getNextChunk(BSON("a" << MINKEY), &chunk) ); ASSERT( chunk.getMin().woCompare( BSON("a" << 10) ) == 0 ); ASSERT( chunk.getMax().woCompare( BSON("a" << 14) ) == 0 ); diff --git a/src/mongo/s/commands/cluster_remove_shard_cmd.cpp b/src/mongo/s/commands/cluster_remove_shard_cmd.cpp index 2b00a2403d9..e8e7f217928 100644 --- a/src/mongo/s/commands/cluster_remove_shard_cmd.cpp +++ b/src/mongo/s/commands/cluster_remove_shard_cmd.cpp @@ -38,10 +38,8 @@ #include "mongo/db/operation_context.h" #include "mongo/s/catalog/catalog_manager.h" #include "mongo/s/catalog/type_chunk.h" -#include "mongo/s/catalog/type_shard.h" #include "mongo/s/grid.h" #include "mongo/s/client/shard.h" -#include "mongo/s/type_database.h" #include "mongo/util/log.h" namespace mongo { diff --git a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp index 2f286e696b2..02c5253fc0a 100644 --- a/src/mongo/s/commands/cluster_shard_collection_cmd.cpp +++ b/src/mongo/s/commands/cluster_shard_collection_cmd.cpp @@ -173,7 +173,7 @@ namespace { return false; } - //the rest of the checks require a connection to the primary db + // The rest of the checks require a connection to the primary db ScopedDbConnection conn(config->getPrimary().getConnString()); //check that collection is not capped diff --git a/src/mongo/s/commands/commands_public.cpp b/src/mongo/s/commands/commands_public.cpp index 1486c1e757f..e13530baba3 100644 --- a/src/mongo/s/commands/commands_public.cpp +++ b/src/mongo/s/commands/commands_public.cpp @@ -178,7 +178,7 @@ namespace { private: bool _passthrough(const string& db, DBConfigPtr conf, const BSONObj& cmdObj , int options , BSONObjBuilder& result ) { - ShardConnection conn( conf->getPrimary() , "" ); + ShardConnection conn(conf->getPrimary().getConnString(), ""); BSONObj res; bool ok = conn->runCommand( db , cmdObj , res , passOptions() ? options : 0 ); if ( ! ok && res["code"].numberInt() == SendStaleConfigCode ) { @@ -1040,7 +1040,7 @@ namespace { BSONObjBuilder& result) const { BSONObj res; - ShardConnection conn(shard, ns); + ShardConnection conn(shard.getConnString(), ns); bool ok = conn->runCommand(conf->name(), cmdObj, res); conn.done(); @@ -1281,7 +1281,7 @@ namespace { int size = 32; for ( set<Shard>::iterator i=shards.begin(), end=shards.end() ; i != end; ++i ) { - ShardConnection conn( *i , fullns ); + ShardConnection conn(i->getConnString(), fullns); BSONObj res; bool ok = conn->runCommand( conf->name() , cmdObj , res, options ); conn.done(); @@ -1872,7 +1872,7 @@ namespace { if (!shardedOutput) { LOG(1) << "MR with single shard output, NS=" << finalColLong << " primary=" << confOut->getPrimary() << endl; - ShardConnection conn( confOut->getPrimary() , finalColLong ); + ShardConnection conn(confOut->getPrimary().getConnString(), finalColLong); ok = conn->runCommand( outDB , finalCmd.obj() , singleResult ); BSONObj counts = singleResult.getObjectField("counts"); @@ -2486,7 +2486,7 @@ namespace { int queryOptions) { // Temporary hack. See comment on declaration for details. - ShardConnection conn( conf->getPrimary() , "" ); + ShardConnection conn(conf->getPrimary().getConnString(), ""); BSONObj result = aggRunCommand(conn.get(), conf->name(), cmd, queryOptions); conn.done(); diff --git a/src/mongo/s/config.cpp b/src/mongo/s/config.cpp index e8dd8e60d44..bd9c633b126 100644 --- a/src/mongo/s/config.cpp +++ b/src/mongo/s/config.cpp @@ -45,6 +45,7 @@ #include "mongo/s/catalog/catalog_manager.h" #include "mongo/s/catalog/type_collection.h" #include "mongo/s/catalog/type_chunk.h" +#include "mongo/s/catalog/type_database.h" #include "mongo/s/catalog/type_settings.h" #include "mongo/s/catalog/type_shard.h" #include "mongo/s/chunk_manager.h" @@ -53,7 +54,6 @@ #include "mongo/s/cluster_write.h" #include "mongo/s/grid.h" #include "mongo/s/server.h" -#include "mongo/s/type_database.h" #include "mongo/s/type_locks.h" #include "mongo/s/type_lockpings.h" #include "mongo/s/type_tags.h" diff --git a/src/mongo/s/d_merge.cpp b/src/mongo/s/d_merge.cpp index aa5676ce1b6..40090693063 100644 --- a/src/mongo/s/d_merge.cpp +++ b/src/mongo/s/d_merge.cpp @@ -46,7 +46,6 @@ namespace mongo { - using std::auto_ptr; using std::endl; using std::string; using mongoutils::str::stream; @@ -163,11 +162,10 @@ namespace mongo { itChunk.setNS( nss.ns() ); itChunk.setShard( shardingState.getShardName() ); - while ( itChunk.getMax().woCompare( maxKey ) < 0 && - metadata->getNextChunk( itChunk.getMax(), &itChunk ) ) { - auto_ptr<ChunkType> saved( new ChunkType ); - itChunk.cloneTo( saved.get() ); - chunksToMerge.mutableVector().push_back( saved.release() ); + while (itChunk.getMax().woCompare(maxKey) < 0 && + metadata->getNextChunk(itChunk.getMax(), &itChunk)) { + + chunksToMerge.mutableVector().push_back(new ChunkType(itChunk)); } if ( chunksToMerge.empty() ) { @@ -387,8 +385,7 @@ namespace mongo { const ChunkType* chunkToMerge = *chunksToMerge.begin(); // Fill in details not tracked by metadata - ChunkType mergedChunk; - chunkToMerge->cloneTo( &mergedChunk ); + ChunkType mergedChunk = *chunkToMerge; mergedChunk.setName( Chunk::genID( chunkToMerge->getNS(), chunkToMerge->getMin() ) ); mergedChunk.setMax( ( *chunksToMerge.vector().rbegin() )->getMax() ); mergedChunk.setVersion( newMergedVersion ); diff --git a/src/mongo/s/d_state.cpp b/src/mongo/s/d_state.cpp index 89a9dcc5809..c409aad00d9 100644 --- a/src/mongo/s/d_state.cpp +++ b/src/mongo/s/d_state.cpp @@ -51,7 +51,6 @@ #include "mongo/db/operation_context.h" #include "mongo/db/repl/replication_coordinator_global.h" #include "mongo/db/wire_version.h" -#include "mongo/s/chunk_version.h" #include "mongo/s/catalog/legacy/catalog_manager_legacy.h" #include "mongo/s/client/shard_connection.h" #include "mongo/s/client/sharding_connection_hook.h" diff --git a/src/mongo/s/metadata_loader_test.cpp b/src/mongo/s/metadata_loader_test.cpp index 54ae860cbe5..ed227b7aa36 100644 --- a/src/mongo/s/metadata_loader_test.cpp +++ b/src/mongo/s/metadata_loader_test.cpp @@ -487,9 +487,10 @@ namespace { // Infer namespace, shard, epoch, keypattern from first chunk const ChunkType* firstChunk = *( chunks.vector().begin() ); - string ns = firstChunk->isNSSet() ? firstChunk->getNS() : "foo.bar"; - string shardName = firstChunk->isShardSet() ? firstChunk->getShard() : "shard0000"; - OID epoch = firstChunk->getVersion().epoch(); + + const string ns = firstChunk->getNS(); + const string shardName = firstChunk->getShard(); + const OID epoch = firstChunk->getVersion().epoch(); BSONObjBuilder keyPatternB; BSONObjIterator keyPatternIt( firstChunk->getMin() ); @@ -510,22 +511,18 @@ namespace { _dummyConfig->insert( CollectionType::ConfigNS, coll.toBSON() ); ChunkVersion version( 1, 0, epoch ); - for ( vector<ChunkType*>::const_iterator it = chunks.vector().begin(); - it != chunks.vector().end(); ++it ) { - - ChunkType chunk; - ( *it )->cloneTo( &chunk ); - chunk.setName( OID::gen().toString() ); - if ( !chunk.isShardSet() ) chunk.setShard( shardName ); - if ( !chunk.isNSSet() ) chunk.setNS( ns ); - if ( !chunk.isVersionSet() ) { - chunk.setVersion( version ); + for (const auto chunkVal : chunks.vector()) { + ChunkType chunk(*chunkVal); + + chunk.setName(OID::gen().toString()); + if (!chunk.isVersionSet()) { + chunk.setVersion(version); version.incMajor(); } ASSERT(chunk.validate().isOK()); - _dummyConfig->insert( ChunkType::ConfigNS, chunk.toBSON() ); + _dummyConfig->insert(ChunkType::ConfigNS, chunk.toBSON()); } Status status = loader().makeCollectionMetadata(catalogManager(), @@ -547,6 +544,8 @@ namespace { TEST_F(MultipleMetadataFixture, PromotePendingNA) { auto_ptr<ChunkType> chunk( new ChunkType() ); + chunk->setNS("foo.bar"); + chunk->setShard("shard0000"); chunk->setMin( BSON( "x" << MINKEY ) ); chunk->setMax( BSON( "x" << 0 ) ); chunk->setVersion( ChunkVersion( 1, 0, OID::gen() ) ); @@ -581,7 +580,10 @@ namespace { TEST_F(MultipleMetadataFixture, PromotePendingNAVersion) { OID epoch = OID::gen(); + auto_ptr<ChunkType> chunk( new ChunkType() ); + chunk->setNS("foo.bar"); + chunk->setShard("shard0000"); chunk->setMin( BSON( "x" << MINKEY ) ); chunk->setMax( BSON( "x" << 0 ) ); chunk->setVersion( ChunkVersion( 1, 1, epoch ) ); @@ -625,17 +627,23 @@ namespace { OwnedPointerVector<ChunkType> chunks; auto_ptr<ChunkType> chunk( new ChunkType() ); + chunk->setNS("foo.bar"); + chunk->setShard("shard0000"); chunk->setMin( BSON( "x" << MINKEY ) ); chunk->setMax( BSON( "x" << 0 ) ); chunk->setVersion( ChunkVersion( 1, 0, epoch ) ); chunks.mutableVector().push_back( chunk.release() ); chunk.reset( new ChunkType() ); + chunk->setNS("foo.bar"); + chunk->setShard("shard0000"); chunk->setMin( BSON( "x" << 10 ) ); chunk->setMax( BSON( "x" << 20 ) ); chunks.mutableVector().push_back( chunk.release() ); chunk.reset( new ChunkType() ); + chunk->setNS("foo.bar"); + chunk->setShard("shard0000"); chunk->setMin( BSON( "x" << 30 ) ); chunk->setMax( BSON( "x" << MAXKEY ) );\ chunks.mutableVector().push_back( chunk.release() ); @@ -648,7 +656,10 @@ namespace { // chunks.clear(); + chunk.reset( new ChunkType() ); + chunk->setNS("foo.bar"); + chunk->setShard("shard0000"); chunk->setMin( BSON( "x" << 0 ) ); chunk->setMax( BSON( "x" << 10 ) ); chunk->setVersion( ChunkVersion( 1, 0, epoch ) ); @@ -701,6 +712,8 @@ namespace { OwnedPointerVector<ChunkType> chunks; auto_ptr<ChunkType> chunk( new ChunkType() ); + chunk->setNS("foo.bar"); + chunk->setShard("shard0000"); chunk->setMin( BSON( "x" << MINKEY ) ); chunk->setMax( BSON( "x" << 0 ) ); chunk->setVersion( ChunkVersion( 1, 0, epoch ) ); @@ -715,7 +728,10 @@ namespace { // chunks.clear(); + chunk.reset( new ChunkType() ); + chunk->setNS("foo.bar"); + chunk->setShard("shard0000"); chunk->setMin( BSON( "x" << 15 ) ); chunk->setMax( BSON( "x" << MAXKEY ) ); chunk->setVersion( ChunkVersion( 1, 0, epoch ) ); diff --git a/src/mongo/s/strategy.cpp b/src/mongo/s/strategy.cpp index acffa2e79e1..fb1aaa32faa 100644 --- a/src/mongo/s/strategy.cpp +++ b/src/mongo/s/strategy.cpp @@ -113,7 +113,7 @@ namespace mongo { shard.reset( new Shard( *shards.begin() ) ); } - ShardConnection dbcon( *shard , r.getns() ); + ShardConnection dbcon(shard->getConnString(), r.getns()); DBClientBase &c = dbcon.conn(); string actualServer; @@ -515,7 +515,8 @@ namespace mongo { BSONObj shardResult; try { - ShardConnection conn(primaryShard, ""); + ShardConnection conn(primaryShard.getConnString(), ""); + // TODO: this can throw a stale config when mongos is not up-to-date -- fix. if (!conn->runCommand(db, command, shardResult, options)) { conn.done(); diff --git a/src/mongo/s/version_manager.cpp b/src/mongo/s/version_manager.cpp index 60d66c57cba..102bd720643 100644 --- a/src/mongo/s/version_manager.cpp +++ b/src/mongo/s/version_manager.cpp @@ -302,24 +302,26 @@ namespace mongo { conf->getChunkManagerOrPrimary(ns, manager, primary); - if (manager) + if (manager) { officialSequenceNumber = manager->getSequenceNumber(); + } // Check this manager against the reference manager - if( manager ){ + if (manager) { + const Shard shard = Shard::make(conn->getServerAddress()); - Shard shard = Shard::make( conn->getServerAddress() ); if (refManager && !refManager->compatibleWith(*manager, shard.getName())) { const ChunkVersion refVersion(refManager->getVersion(shard.getName())); const ChunkVersion currentVersion(manager->getVersion(shard.getName())); + string msg(str::stream() << "manager (" - << currentVersion.toString() - << " : " << manager->getSequenceNumber() << ") " - << "not compatible with reference manager (" - << refVersion.toString() - << " : " << refManager->getSequenceNumber() << ") " - << "on shard " << shard.getName() - << " (" << shard.getAddress().toString() << ")"); + << currentVersion.toString() + << " : " << manager->getSequenceNumber() << ") " + << "not compatible with reference manager (" + << refVersion.toString() + << " : " << refManager->getSequenceNumber() << ") " + << "on shard " << shard.getName() + << " (" << shard.getAddress().toString() << ")"); throw SendStaleConfigException(ns, msg, @@ -327,9 +329,9 @@ namespace mongo { currentVersion); } } - else if( refManager ){ + else if (refManager) { + const Shard shard = Shard::make(conn->getServerAddress()); - Shard shard = Shard::make(conn->getServerAddress()); string msg( str::stream() << "not sharded (" << ( (manager.get() == 0) ? string( "<none>" ) : str::stream() << manager->getSequenceNumber() ) @@ -360,12 +362,12 @@ namespace mongo { } } - // Now that we're sure we're sending SSV and not to a single config server, get the shard - Shard shard = Shard::make(conn->getServerAddress()); + const Shard shard = Shard::make(conn->getServerAddress()); ChunkVersion version = ChunkVersion(0, 0, OID()); - if (manager) + if (manager) { version = manager->getVersion(shard.getName()); + } LOG(1) << "setting shard version of " << version << " for " << ns << " on shard " << shard.toString(); diff --git a/src/mongo/s/write_ops/batched_delete_request.h b/src/mongo/s/write_ops/batched_delete_request.h index 122d488c707..3bcbfb48e49 100644 --- a/src/mongo/s/write_ops/batched_delete_request.h +++ b/src/mongo/s/write_ops/batched_delete_request.h @@ -36,7 +36,6 @@ #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" #include "mongo/s/bson_serializable.h" -#include "mongo/s/chunk_version.h" #include "mongo/s/write_ops/batched_delete_document.h" #include "mongo/s/write_ops/batched_request_metadata.h" diff --git a/src/mongo/s/write_ops/batched_insert_request.h b/src/mongo/s/write_ops/batched_insert_request.h index b183c269610..a1be831497d 100644 --- a/src/mongo/s/write_ops/batched_insert_request.h +++ b/src/mongo/s/write_ops/batched_insert_request.h @@ -36,7 +36,6 @@ #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" #include "mongo/s/bson_serializable.h" -#include "mongo/s/chunk_version.h" #include "mongo/s/write_ops/batched_request_metadata.h" namespace mongo { diff --git a/src/mongo/s/write_ops/batched_update_request.h b/src/mongo/s/write_ops/batched_update_request.h index 78cf58c5c01..38633fc1079 100644 --- a/src/mongo/s/write_ops/batched_update_request.h +++ b/src/mongo/s/write_ops/batched_update_request.h @@ -36,7 +36,6 @@ #include "mongo/db/jsobj.h" #include "mongo/db/namespace_string.h" #include "mongo/s/bson_serializable.h" -#include "mongo/s/chunk_version.h" #include "mongo/s/write_ops/batched_request_metadata.h" #include "mongo/s/write_ops/batched_update_document.h" diff --git a/src/mongo/util/compress.cpp b/src/mongo/util/compress.cpp index b06135d6dde..92bbbafbefc 100644 --- a/src/mongo/util/compress.cpp +++ b/src/mongo/util/compress.cpp @@ -28,9 +28,11 @@ * then also delete it in the license file. */ +#include "mongo/platform/basic.h" + #include "mongo/util/compress.h" -#include "snappy.h" +#include <snappy.h> namespace mongo { |