summaryrefslogtreecommitdiff
path: root/src/mongo
diff options
context:
space:
mode:
authorJudah Schvimer <judah@mongodb.com>2017-11-07 16:11:52 -0500
committerJudah Schvimer <judah@mongodb.com>2017-11-08 16:38:22 -0500
commit26a5d0070ba4a4b9f7e9a5b68f58a0fa75f9e6d3 (patch)
tree0739316b39c935ae58fb64cf038eac457b2226b9 /src/mongo
parent68035d80f3b382e591fa381ee44550d920a6d432 (diff)
downloadmongo-26a5d0070ba4a4b9f7e9a5b68f58a0fa75f9e6d3.tar.gz
SERVER-31805 provide option to Cloner to preserve UUIDs
Diffstat (limited to 'src/mongo')
-rw-r--r--src/mongo/db/catalog/coll_mod.cpp18
-rw-r--r--src/mongo/db/cloner.cpp23
-rw-r--r--src/mongo/db/cloner.h10
-rw-r--r--src/mongo/db/commands/clone_collection.cpp3
-rw-r--r--src/mongo/db/repl/rollback_source_impl.cpp3
5 files changed, 44 insertions, 13 deletions
diff --git a/src/mongo/db/catalog/coll_mod.cpp b/src/mongo/db/catalog/coll_mod.cpp
index cc945f541ad..2100adf8164 100644
--- a/src/mongo/db/catalog/coll_mod.cpp
+++ b/src/mongo/db/catalog/coll_mod.cpp
@@ -55,12 +55,17 @@
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/sharding_initialization.h"
+#include "mongo/util/fail_point_service.h"
#include "mongo/util/log.h"
namespace mongo {
namespace {
+// Causes the server to hang when it attempts to assign UUIDs to the provided database (or all
+// databases if none are provided).
+MONGO_FP_DECLARE(hangBeforeDatabaseUpgrade);
+
struct CollModRequest {
const IndexDescriptor* idx = nullptr;
BSONElement indexExpireAfterSeconds = {};
@@ -627,6 +632,19 @@ void updateUUIDSchemaVersion(OperationContext* opCtx, bool upgrade) {
for (auto it = dbNames.begin(); it != dbNames.end(); ++it) {
auto dbName = *it;
+
+ MONGO_FAIL_POINT_BLOCK(hangBeforeDatabaseUpgrade, customArgs) {
+ const auto& data = customArgs.getData();
+ const auto dbElem = data["database"];
+ if (!dbElem || dbElem.checkAndGetStringData() == dbName) {
+ log() << "collMod - hangBeforeDatabaseUpgrade fail point enabled for " << dbName
+ << ". Blocking until fail point is disabled.";
+ while (MONGO_FAIL_POINT(hangBeforeDatabaseUpgrade)) {
+ mongo::sleepsecs(1);
+ }
+ }
+ }
+
_updateDatabaseUUIDSchemaVersion(opCtx, dbName, dbToCollToUUID[dbName], upgrade);
}
const WriteConcernOptions writeConcern(WriteConcernOptions::kMajority,
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 0e222c785a9..7ab9d368df1 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -421,14 +421,15 @@ bool Cloner::copyCollection(OperationContext* opCtx,
const string& ns,
const BSONObj& query,
string& errmsg,
- bool shouldCopyIndexes) {
+ bool shouldCopyIndexes,
+ CollectionOptions::ParseKind optionsParser) {
const NamespaceString nss(ns);
const string dbname = nss.db().toString();
// config
BSONObj filter = BSON("name" << nss.coll().toString());
list<BSONObj> collList = _conn->getCollectionInfos(dbname, filter);
- BSONObj options;
+ BSONObjBuilder optionsBob;
bool shouldCreateCollection = false;
if (!collList.empty()) {
@@ -452,9 +453,16 @@ bool Cloner::copyCollection(OperationContext* opCtx,
}
if (col["options"].isABSONObj()) {
- options = col["options"].Obj();
+ optionsBob.appendElements(col["options"].Obj());
+ }
+ if ((optionsParser == CollectionOptions::parseForStorage) && col["info"].isABSONObj()) {
+ auto info = col["info"].Obj();
+ if (info.hasField("uuid")) {
+ optionsBob.append(info.getField("uuid"));
+ }
}
}
+ BSONObj options = optionsBob.obj();
auto sourceIndexes = _conn->getIndexSpecs(nss.ns(), QueryOption_SlaveOk);
auto idIndexSpec = getIdIndexSpec(sourceIndexes);
@@ -474,13 +482,8 @@ bool Cloner::copyCollection(OperationContext* opCtx,
WriteUnitOfWork wunit(opCtx);
const bool createDefaultIndexes = true;
- Status status = userCreateNS(opCtx,
- db,
- ns,
- options,
- CollectionOptions::parseForCommand,
- createDefaultIndexes,
- idIndexSpec);
+ Status status = userCreateNS(
+ opCtx, db, ns, options, optionsParser, createDefaultIndexes, idIndexSpec);
if (!status.isOK()) {
errmsg = status.toString();
// abort write unit of work
diff --git a/src/mongo/db/cloner.h b/src/mongo/db/cloner.h
index 6c8cc255b12..796fbe57dad 100644
--- a/src/mongo/db/cloner.h
+++ b/src/mongo/db/cloner.h
@@ -35,6 +35,7 @@
#include "mongo/base/disallow_copying.h"
#include "mongo/client/dbclientinterface.h"
+#include "mongo/db/catalog/collection_options.h"
namespace mongo {
@@ -69,11 +70,18 @@ public:
std::set<std::string>* clonedColls,
std::vector<BSONObj> collectionsToClone = std::vector<BSONObj>());
+ /**
+ * Copies a collection. The optionsParser indicates how to parse the collection options. If
+ * 'parseForCommand' is provided, then the UUID is ignored and a new UUID is generated. If
+ * 'parseForStorage' is provided, then the UUID will be preserved and parsed out of the
+ * options.
+ */
bool copyCollection(OperationContext* opCtx,
const std::string& ns,
const BSONObj& query,
std::string& errmsg,
- bool copyIndexes);
+ bool copyIndexes,
+ CollectionOptions::ParseKind optionsParser);
// 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
diff --git a/src/mongo/db/commands/clone_collection.cpp b/src/mongo/db/commands/clone_collection.cpp
index e5d1d7196f6..5746348dfc1 100644
--- a/src/mongo/db/commands/clone_collection.cpp
+++ b/src/mongo/db/commands/clone_collection.cpp
@@ -150,7 +150,8 @@ public:
cloner.setConnection(std::move(myconn));
- return cloner.copyCollection(opCtx, collection, query, errmsg, copyIndexes);
+ return cloner.copyCollection(
+ opCtx, collection, query, errmsg, copyIndexes, CollectionOptions::parseForCommand);
}
} cmdCloneCollection;
diff --git a/src/mongo/db/repl/rollback_source_impl.cpp b/src/mongo/db/repl/rollback_source_impl.cpp
index 5de7dde2337..902892dd133 100644
--- a/src/mongo/db/repl/rollback_source_impl.cpp
+++ b/src/mongo/db/repl/rollback_source_impl.cpp
@@ -93,7 +93,8 @@ void RollbackSourceImpl::copyCollectionFromRemote(OperationContext* opCtx,
uassert(15909,
str::stream() << "replSet rollback error resyncing collection " << nss.ns() << ' '
<< errmsg,
- cloner.copyCollection(opCtx, nss.ns(), BSONObj(), errmsg, true));
+ cloner.copyCollection(
+ opCtx, nss.ns(), BSONObj(), errmsg, true, CollectionOptions::parseForStorage));
}
StatusWith<BSONObj> RollbackSourceImpl::getCollectionInfoByUUID(const std::string& db,