diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-03-01 14:12:14 -0500 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2017-03-02 10:47:38 -0500 |
commit | 0c7ab1cdd8c6a1cde4c5b2ccb1feef4300d29708 (patch) | |
tree | 304fcac70e1a91ef3c62addb67e0a694108e8ae2 | |
parent | 4a61e8533c00f991106f44eb7154b78060234c9c (diff) | |
download | mongo-0c7ab1cdd8c6a1cde4c5b2ccb1feef4300d29708.tar.gz |
SERVER-20854 Pull the diff tracker's query generation logic outside of the template
-rw-r--r-- | src/mongo/db/s/metadata_loader.cpp | 4 | ||||
-rw-r--r-- | src/mongo/s/chunk_diff.cpp | 23 | ||||
-rw-r--r-- | src/mongo/s/chunk_diff.h | 14 | ||||
-rw-r--r-- | src/mongo/s/chunk_manager.cpp | 6 |
4 files changed, 18 insertions, 29 deletions
diff --git a/src/mongo/db/s/metadata_loader.cpp b/src/mongo/db/s/metadata_loader.cpp index 762b1382412..2a57f654d84 100644 --- a/src/mongo/db/s/metadata_loader.cpp +++ b/src/mongo/db/s/metadata_loader.cpp @@ -183,9 +183,9 @@ Status MetadataLoader::_initChunks(OperationContext* txn, ns, &metadata->_chunksMap, &metadata->_collVersion, &versionMap, shard); try { - // Get any new chunks. + const auto diffQuery = SCMConfigDiffTracker::createConfigDiffQuery(NamespaceString(ns), + metadata->_collVersion); std::vector<ChunkType> chunks; - const auto diffQuery = differ.configDiffQuery(); Status status = catalogClient->getChunks(txn, diffQuery.query, diffQuery.sort, diff --git a/src/mongo/s/chunk_diff.cpp b/src/mongo/s/chunk_diff.cpp index 6e065a44e9a..90ec41b8923 100644 --- a/src/mongo/s/chunk_diff.cpp +++ b/src/mongo/s/chunk_diff.cpp @@ -32,6 +32,7 @@ #include "mongo/s/chunk_diff.h" +#include "mongo/db/namespace_string.h" #include "mongo/db/s/collection_metadata.h" #include "mongo/s/catalog/type_chunk.h" #include "mongo/s/chunk_version.h" @@ -169,36 +170,26 @@ int ConfigDiffTracker<ValType>::calculateConfigDiff(OperationContext* txn, return _validDiffs; } -template <class ValType> -typename ConfigDiffTracker<ValType>::QueryAndSort ConfigDiffTracker<ValType>::configDiffQuery() - const { +ConfigDiffTrackerBase::QueryAndSort ConfigDiffTrackerBase::createConfigDiffQuery( + const NamespaceString& nss, ChunkVersion collectionVersion) { // The query has to find all the chunks $gte the current max version. Currently, any splits and // merges will increment the current max version. BSONObjBuilder queryB; - queryB.append(ChunkType::ns(), _ns); + queryB.append(ChunkType::ns(), nss.ns()); { BSONObjBuilder tsBuilder(queryB.subobjStart(ChunkType::DEPRECATED_lastmod())); - tsBuilder.appendTimestamp("$gte", _maxVersion->toLong()); + tsBuilder.appendTimestamp("$gte", collectionVersion.toLong()); tsBuilder.done(); } // NOTE: IT IS IMPORTANT FOR CONSISTENCY THAT WE SORT BY ASC VERSION, IN ORDER TO HANDLE CURSOR - // YIELDING BETWEEN CHUNKS BEING MIGRATED. + // YIELDING BETWEEN CHUNKS BEING MIGRATED // // This ensures that changes to chunk version (which will always be higher) will always come // *after* our current position in the chunk cursor. - QueryAndSort queryObj(queryB.obj(), BSON(ChunkType::DEPRECATED_lastmod() << 1)); - - LOG(2) << "major version query from " << *_maxVersion << " and over " - << _maxShardVersions->size() << " shards is " << queryObj; - - return queryObj; -} - -std::string ConfigDiffTrackerBase::QueryAndSort::toString() const { - return str::stream() << "query: " << query << ", sort: " << sort; + return QueryAndSort{queryB.obj(), BSON(ChunkType::DEPRECATED_lastmod() << 1)}; } // Ensures that these instances of the template are compiled diff --git a/src/mongo/s/chunk_diff.h b/src/mongo/s/chunk_diff.h index cf691358f38..9ea6ed5b62e 100644 --- a/src/mongo/s/chunk_diff.h +++ b/src/mongo/s/chunk_diff.h @@ -46,13 +46,15 @@ public: * Structure repsenting the generated query and sort order for a chunk diffing operation. */ struct QueryAndSort { - QueryAndSort(BSONObj inQuery, BSONObj inSort) : query(inQuery), sort(inSort) {} - - std::string toString() const; - const BSONObj query; const BSONObj sort; }; + + /** + * Returns the query needed to find incremental changes to a collection from the config server. + */ + static QueryAndSort createConfigDiffQuery(const NamespaceString& nss, + ChunkVersion collectionVersion); }; /** @@ -103,10 +105,6 @@ public: // Returns the number of diffs processed, or -1 if the diffs were inconsistent. int calculateConfigDiff(OperationContext* txn, const std::vector<ChunkType>& chunks); - // Returns the query needed to find new changes to a collection from the config server - // Needed only if a custom connection is required to the config server - QueryAndSort configDiffQuery() const; - protected: /** * Determines which chunks are actually being remembered by our RangeMap. Allows individual diff --git a/src/mongo/s/chunk_manager.cpp b/src/mongo/s/chunk_manager.cpp index be9ee5a25eb..75f2cc7c11c 100644 --- a/src/mongo/s/chunk_manager.cpp +++ b/src/mongo/s/chunk_manager.cpp @@ -243,13 +243,13 @@ bool ChunkManager::_load(OperationContext* txn, << oldChunkMap.size() << " chunks"; } + // Get the diff query required + const auto diffQuery = CMConfigDiffTracker::createConfigDiffQuery(_nss, _version); + // Attach a diff tracker for the versioned chunk data CMConfigDiffTracker differ(_nss.ns(), &chunkMap, &_version, shardVersions, this); // Diff tracker should *always* find at least one chunk if collection exists - // Get the diff query required - auto diffQuery = differ.configDiffQuery(); - repl::OpTime opTime; std::vector<ChunkType> chunks; uassertStatusOK(Grid::get(txn)->catalogClient(txn)->getChunks( |