diff options
author | Marcos José Grillo Ramírez <marcos.grillo@mongodb.com> | 2020-08-12 19:52:59 +0200 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-08-20 14:07:53 +0000 |
commit | bc3233c1ff791a91cb85cff6439969f394068d31 (patch) | |
tree | 07f22259edcc2ef611dfec78f1c998197d25b2f8 | |
parent | e54d83a72d47c17241196618d70db35c05e8243a (diff) | |
download | mongo-bc3233c1ff791a91cb85cff6439969f394068d31.tar.gz |
SERVER-50272 Make RoutingTableHistory movable
-rw-r--r-- | src/mongo/s/catalog_cache.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/chunk_manager.cpp | 6 | ||||
-rw-r--r-- | src/mongo/s/chunk_manager.h | 31 | ||||
-rw-r--r-- | src/mongo/s/write_ops/chunk_manager_targeter.cpp | 20 |
4 files changed, 13 insertions, 50 deletions
diff --git a/src/mongo/s/catalog_cache.cpp b/src/mongo/s/catalog_cache.cpp index 8330c76f74b..fd4ef9f5d06 100644 --- a/src/mongo/s/catalog_cache.cpp +++ b/src/mongo/s/catalog_cache.cpp @@ -668,9 +668,9 @@ void CatalogCache::_scheduleCollectionRefresh(WithLock lk, setOperationShouldBlockBehindCatalogCacheRefresh(opCtx.get(), false); // TODO(SERVER-49876): remove clang-tidy NOLINT comments. - if (existingRoutingInfo && newRoutingInfo && // NOLINT(bugprone-use-after-move) - existingRoutingInfo->getSequenceNumber() == // NOLINT(bugprone-use-after-move) - newRoutingInfo->getSequenceNumber()) { // NOLINT(bugprone-use-after-move) + if (existingRoutingInfo && newRoutingInfo && // NOLINT(bugprone-use-after-move) + existingRoutingInfo->getVersion() == // NOLINT(bugprone-use-after-move) + newRoutingInfo->getVersion()) { // NOLINT(bugprone-use-after-move) // If the routingInfo hasn't changed, we need to manually reset stale shards. newRoutingInfo->setAllShardsRefreshed(); } diff --git a/src/mongo/s/chunk_manager.cpp b/src/mongo/s/chunk_manager.cpp index 49ba0907017..3107a05a7a0 100644 --- a/src/mongo/s/chunk_manager.cpp +++ b/src/mongo/s/chunk_manager.cpp @@ -49,9 +49,6 @@ namespace mongo { namespace { -// Used to generate sequence numbers to assign to each newly created RoutingTableHistory -AtomicWord<unsigned> nextCMSequenceNumber(0); - bool allElementsAreOfType(BSONType type, const BSONObj& obj) { for (auto&& elem : obj) { if (elem.type() != type) { @@ -309,8 +306,7 @@ RoutingTableHistory::RoutingTableHistory(NamespaceString nss, std::unique_ptr<CollatorInterface> defaultCollator, bool unique, ChunkMap chunkMap) - : _sequenceNumber(nextCMSequenceNumber.addAndFetch(1)), - _nss(std::move(nss)), + : _nss(std::move(nss)), _uuid(uuid), _shardKeyPattern(shardKeyPattern), _defaultCollator(std::move(defaultCollator)), diff --git a/src/mongo/s/chunk_manager.h b/src/mongo/s/chunk_manager.h index 77c636c0043..a5863b064b2 100644 --- a/src/mongo/s/chunk_manager.h +++ b/src/mongo/s/chunk_manager.h @@ -136,6 +136,9 @@ class RoutingTableHistory : public std::enable_shared_from_this<RoutingTableHist RoutingTableHistory& operator=(const RoutingTableHistory&) = delete; public: + RoutingTableHistory(RoutingTableHistory&&) = default; + RoutingTableHistory& operator=(RoutingTableHistory&&) = default; + /** * Makes an instance with a routing table for collection "nss", sharded on * "shardKeyPattern". @@ -165,13 +168,6 @@ public: */ std::shared_ptr<RoutingTableHistory> makeUpdated(const std::vector<ChunkType>& changedChunks); - /** - * Returns an increasing number of the reload sequence number of this chunk manager. - */ - unsigned long long getSequenceNumber() const { - return _sequenceNumber; - } - const NamespaceString& getns() const { return _nss; } @@ -274,24 +270,20 @@ private: ChunkVersion _getVersion(const ShardId& shardName, bool throwOnStaleShard) const; - // The shard versioning mechanism hinges on keeping track of the number of times we reload - // ChunkManagers. - const unsigned long long _sequenceNumber; - // Namespace to which this routing information corresponds - const NamespaceString _nss; + NamespaceString _nss; // The invariant UUID of the collection. This is optional in 3.6, except in change streams. - const boost::optional<UUID> _uuid; + boost::optional<UUID> _uuid; // The key pattern used to shard the collection - const ShardKeyPattern _shardKeyPattern; + ShardKeyPattern _shardKeyPattern; // Default collation to use for routing data queries for this collection - const std::unique_ptr<CollatorInterface> _defaultCollator; + std::unique_ptr<CollatorInterface> _defaultCollator; // Whether the sharding key is unique - const bool _unique; + bool _unique; // Map from the max for each chunk to an entry describing the chunk. The union of all chunks' // ranges must cover the complete space from [MinKey, MaxKey). @@ -314,13 +306,6 @@ public: ChunkManager(std::shared_ptr<RoutingTableHistory> rt, boost::optional<Timestamp> clusterTime) : _rt(std::move(rt)), _clusterTime(std::move(clusterTime)) {} - /** - * Returns an increasing number of the reload sequence number of this chunk manager. - */ - unsigned long long getSequenceNumber() const { - return _rt->getSequenceNumber(); - } - const NamespaceString& getns() const { return _rt->getns(); } diff --git a/src/mongo/s/write_ops/chunk_manager_targeter.cpp b/src/mongo/s/write_ops/chunk_manager_targeter.cpp index f8bada7ced4..ec79a4ec1e4 100644 --- a/src/mongo/s/write_ops/chunk_manager_targeter.cpp +++ b/src/mongo/s/write_ops/chunk_manager_targeter.cpp @@ -335,24 +335,6 @@ bool isMetadataDifferent(const ChunkManager* managerA, return !databaseVersion::equal(dbVersionA, dbVersionB); } -/** - * Whether or not the manager/primary pair was changed or refreshed from a previous version - * of the metadata. - */ -bool wasMetadataRefreshed(const ChunkManager* managerA, - const DatabaseVersion dbVersionA, - const ChunkManager* managerB, - const DatabaseVersion dbVersionB) { - if (isMetadataDifferent(managerA, dbVersionA, managerB, dbVersionB)) - return true; - - if (managerA) { - return managerA->getSequenceNumber() != managerB->getSequenceNumber(); - } - - return false; -} - } // namespace ChunkManagerTargeter::ChunkManagerTargeter(OperationContext* opCtx, @@ -728,7 +710,7 @@ void ChunkManagerTargeter::refreshIfNeeded(OperationContext* opCtx, bool* wasCha // If we couldn't target, we might need to refresh if we haven't remotely refreshed // the metadata since we last got it from the cache. - bool alreadyRefreshed = wasMetadataRefreshed( + bool alreadyRefreshed = isMetadataDifferent( lastManager, lastDbVersion, _routingInfo->cm(), _routingInfo->db().databaseVersion()); // If didn't already refresh the targeting information, refresh it |