From c52c530428fbbe0cae1293ad6605c3ab7be2a281 Mon Sep 17 00:00:00 2001 From: Eric Milkie Date: Thu, 28 Apr 2016 10:39:38 -0400 Subject: SERVER-23919 gather all collection names at the start of initial sync --- src/mongo/db/cloner.h | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/mongo/db/cloner.h') diff --git a/src/mongo/db/cloner.h b/src/mongo/db/cloner.h index 8a5cb691375..7b091e4f29b 100644 --- a/src/mongo/db/cloner.h +++ b/src/mongo/db/cloner.h @@ -30,6 +30,9 @@ #pragma once +#include +#include + #include "mongo/base/disallow_copying.h" #include "mongo/client/dbclientinterface.h" #include "mongo/s/catalog/catalog_manager.h" @@ -54,12 +57,18 @@ public: /** * Copies an entire database from the specified host. + * clonedColls: when not-null, the function will return with this populated with a list of + * the collections that were cloned. This is for the user-facing clone command. + * collectionsToClone: When opts.createCollections is false, this list reflects the collections + * that are cloned. When opts.createCollections is true, this parameter is + * ignored and the collection list is fetched from the remote via _conn. */ Status copyDb(OperationContext* txn, const std::string& toDBName, const std::string& masterHost, const CloneOptions& opts, - std::set* clonedColls); + std::set* clonedColls, + std::vector collectionsToClone = std::vector()); bool copyCollection(OperationContext* txn, const std::string& ns, @@ -67,6 +76,17 @@ public: std::string& errmsg, bool copyIndexes); + // Filters a database's collection list and removes collections that should not be cloned. + // CloneOptions should be populated with a fromDB and a list of collections to ignore, which + // will be filtered out. + StatusWith> filterCollectionsForClone( + const CloneOptions& opts, const std::list& initialCollections); + + // Executes 'createCollection' for each collection specified in 'collections', in 'dbName'. + Status createCollectionsForDb(OperationContext* txn, + const std::vector& collections, + const std::string& dbName); + private: void copy(OperationContext* txn, const std::string& toDBName, @@ -99,6 +119,8 @@ private: * holding a distributed lock (such as movePrimary). Indicates that we need to * be periodically checking to see if the catalog manager has swapped and fail * if it has so that we don't block the mongos that initiated the command. + * createCollections - When 'true', will fetch a list of collections from the remote and create + * them. When 'false', assumes collections have already been created ahead of time. */ struct CloneOptions { std::string fromDB; @@ -111,6 +133,7 @@ struct CloneOptions { bool syncData = true; bool syncIndexes = true; bool checkForCatalogChange = false; + bool createCollections = true; }; } // namespace mongo -- cgit v1.2.1