diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-07-18 16:13:54 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-07-21 22:14:51 -0400 |
commit | ea026e685bc90c102e2305e21b8bdc096475b49b (patch) | |
tree | 9399e67cc27fd5700892ae5b28ec4aca6912440a /src/mongo/db/s/metadata_manager.h | |
parent | 0c8085729e7062202bd66076e2ca7751aa338ab6 (diff) | |
download | mongo-ea026e685bc90c102e2305e21b8bdc096475b49b.tar.gz |
SERVER-24569 Maintain rangesToClean and metadataInUse on chunk migrations
This change rewrites the collection metadata refresh mechanism and puts it
entirely under the metadata manager.
Diffstat (limited to 'src/mongo/db/s/metadata_manager.h')
-rw-r--r-- | src/mongo/db/s/metadata_manager.h | 48 |
1 files changed, 37 insertions, 11 deletions
diff --git a/src/mongo/db/s/metadata_manager.h b/src/mongo/db/s/metadata_manager.h index 5953ccb9fdf..319db8180fb 100644 --- a/src/mongo/db/s/metadata_manager.h +++ b/src/mongo/db/s/metadata_manager.h @@ -57,10 +57,27 @@ public: ScopedCollectionMetadata getActiveMetadata(); /** - * Changes the active metadata and if there are current users of the current metadata, - * puts it in the _metadataInUse set. + * Uses the contents of the specified metadata as a way to purge any pending chunks. */ - void setActiveMetadata(std::unique_ptr<CollectionMetadata> newMetadata); + void refreshActiveMetadata(std::unique_ptr<CollectionMetadata> newMetadata); + + /** + * Puts the specified range on the list of chunks, which are being received so that the range + * deleter process will not clean the partially migrated data. + */ + void beginReceive(const ChunkRange& range); + + /* + * Removes a range from the list of chunks, which are being received. Used externally to + * indicate that a chunk migration failed. + */ + void forgetReceive(const ChunkRange& range); + + /** + * Gets copy of the set of chunk ranges which are being received for this collection. This + * method is intended for testing purposes only and should not be used in any production code. + */ + RangeMap getCopyOfReceivingChunks(); /** * Adds a new range to be cleaned up. @@ -74,9 +91,10 @@ public: void removeRangeToClean(const ChunkRange& range); /** - * Gets copy of _rangesToClean map (see below). + * Gets copy of the set of chunk ranges which are scheduled for cleanup. This method is intended + * for testing purposes only and should not be used in any production code. */ - std::map<BSONObj, ChunkRange> getCopyOfRanges(); + RangeMap getCopyOfRangesToClean(); /* * Appends information on all the chunk ranges in rangesToClean to builder. @@ -94,6 +112,7 @@ private: CollectionMetadataTracker(std::unique_ptr<CollectionMetadata> m); std::unique_ptr<CollectionMetadata> metadata; + uint32_t usageCounter{0}; }; @@ -106,6 +125,11 @@ private: void _addRangeToClean_inlock(const ChunkRange& range); void _removeRangeToClean_inlock(const ChunkRange& range); + void _setActiveMetadata_inlock(std::unique_ptr<CollectionMetadata> newMetadata); + + // Mutex to protect the state below + stdx::mutex _managerLock; + // Holds the collection metadata, which is currently active std::unique_ptr<CollectionMetadataTracker> _activeMetadataTracker; @@ -113,12 +137,12 @@ private: // by still active server operations or cursors std::list<std::unique_ptr<CollectionMetadataTracker>> _metadataInUse; - // Contains the information of which ranges of sharding keys need to - // be deleted from the shard. The map is from the minimum value of the - // range to be deleted (e.g. BSON("key" << 0)) to the entire chunk range. - std::map<BSONObj, ChunkRange> _rangesToClean; + // Chunk ranges which are currently assumed to be transferred to the shard. Indexed by the min + // key of the range. + RangeMap _receivingChunks; - stdx::mutex _managerLock; + // Set of ranges to be deleted. Indexed by the min key of the range. + RangeMap _rangesToClean; }; class ScopedCollectionMetadata { @@ -146,7 +170,9 @@ public: CollectionMetadata* operator->(); CollectionMetadata* getMetadata(); - /** True if the ScopedCollectionMetadata stores a metadata (is not empty) */ + /** + * True if the ScopedCollectionMetadata stores a metadata (is not empty) + */ operator bool() const; private: |