diff options
author | Mathias Stearn <mathias@10gen.com> | 2015-05-11 12:56:33 -0400 |
---|---|---|
committer | Mathias Stearn <mathias@10gen.com> | 2015-05-14 18:55:30 -0400 |
commit | 22de12dd4ac510cd2a37b643eb528673f651e21b (patch) | |
tree | 2ef29d5355e35a2429d7e1d6469e222132f4fdf3 /src/mongo/db | |
parent | b0f3a43bf7f9b4e1bd48c5b823ebe2d5e8fa9055 (diff) | |
download | mongo-22de12dd4ac510cd2a37b643eb528673f651e21b.tar.gz |
SERVER-18227 Propagate all options when creating collections based on others
In addition to the primary goal of propagating the validator, this will also
propagate things like storage-engine specific options and capped settings.
Diffstat (limited to 'src/mongo/db')
-rw-r--r-- | src/mongo/db/catalog/capped_utils.cpp | 6 | ||||
-rw-r--r-- | src/mongo/db/catalog/rename_collection.cpp | 15 | ||||
-rw-r--r-- | src/mongo/db/commands/mr.cpp | 8 | ||||
-rw-r--r-- | src/mongo/db/pipeline/document_source_out.cpp | 15 |
4 files changed, 27 insertions, 17 deletions
diff --git a/src/mongo/db/catalog/capped_utils.cpp b/src/mongo/db/catalog/capped_utils.cpp index 92bbba46d0c..db75964c8c1 100644 --- a/src/mongo/db/catalog/capped_utils.cpp +++ b/src/mongo/db/catalog/capped_utils.cpp @@ -32,6 +32,7 @@ #include "mongo/db/background.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/database.h" #include "mongo/db/catalog/document_validation.h" #include "mongo/db/catalog/index_catalog.h" @@ -127,12 +128,17 @@ namespace { // create new collection { + const auto fromOptions = fromCollection->getCatalogEntry() + ->getCollectionOptions(txn) + .toBSON(); + OldClientContext ctx(txn, toNs); BSONObjBuilder spec; spec.appendBool("capped", true); spec.append("size", size); if (temp) spec.appendBool("temp", true); + spec.appendElementsUnique(fromOptions); WriteUnitOfWork wunit(txn); Status status = userCreateNS(txn, ctx.db(), toNs, spec.done()); diff --git a/src/mongo/db/catalog/rename_collection.cpp b/src/mongo/db/catalog/rename_collection.cpp index ce08118b107..ecf7b5e2515 100644 --- a/src/mongo/db/catalog/rename_collection.cpp +++ b/src/mongo/db/catalog/rename_collection.cpp @@ -189,24 +189,15 @@ namespace { // TODO use a temp collection and unset the temp flag on success. Collection* targetColl = nullptr; { - CollectionOptions options; - options.setNoIdIndex(); - - if (sourceColl->isCapped()) { - const CollectionOptions sourceOpts = - sourceColl->getCatalogEntry()->getCollectionOptions(txn); - - options.capped = true; - options.cappedSize = sourceOpts.cappedSize; - options.cappedMaxDocs = sourceOpts.cappedMaxDocs; - } + CollectionOptions options = sourceColl->getCatalogEntry()->getCollectionOptions(txn); WriteUnitOfWork wunit(txn); // No logOp necessary because the entire renameCollection command is one logOp. bool shouldReplicateWrites = txn->writesAreReplicated(); txn->setReplicatedWrites(false); - targetColl = targetDB->createCollection(txn, target.ns(), options); + targetColl = targetDB->createCollection(txn, target.ns(), options, + false); // _id index build with others later. txn->setReplicatedWrites(shouldReplicateWrites); if (!targetColl) { return Status(ErrorCodes::OutOfDiskSpace, "Failed to create target collection."); diff --git a/src/mongo/db/commands/mr.cpp b/src/mongo/db/commands/mr.cpp index c8612c41dac..54d971dd212 100644 --- a/src/mongo/db/commands/mr.cpp +++ b/src/mongo/db/commands/mr.cpp @@ -38,6 +38,7 @@ #include "mongo/client/parallel.h" #include "mongo/db/auth/authorization_session.h" #include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/collection_catalog_entry.h" #include "mongo/db/catalog/database_holder.h" #include "mongo/db/clientcursor.h" #include "mongo/db/commands.h" @@ -403,13 +404,16 @@ namespace mongo { wuow.commit(); } + CollectionOptions finalOptions; vector<BSONObj> indexesToInsert; { - // copy indexes into temporary storage + // copy indexes and collection options into temporary storage OldClientWriteContext finalCtx(_txn, _config.outputOptions.finalNamespace); Collection* const finalColl = finalCtx.getCollection(); if ( finalColl ) { + finalOptions = finalColl->getCatalogEntry()->getCollectionOptions(_txn); + IndexCatalog::IndexIterator ii = finalColl->getIndexCatalog()->getIndexIterator( _txn, true ); // Iterate over finalColl's indexes. @@ -442,7 +446,7 @@ namespace mongo { Collection* tempColl = tempCtx.getCollection(); invariant(!tempColl); - CollectionOptions options; + CollectionOptions options = finalOptions; options.temp = true; tempColl = tempCtx.db()->createCollection(_txn, _config.tempNamespace, options); diff --git a/src/mongo/db/pipeline/document_source_out.cpp b/src/mongo/db/pipeline/document_source_out.cpp index 93f109e7cff..fb58cb1565a 100644 --- a/src/mongo/db/pipeline/document_source_out.cpp +++ b/src/mongo/db/pipeline/document_source_out.cpp @@ -73,11 +73,20 @@ namespace mongo { << aggOutCounter.addAndFetch(1) )); + // Create output collection, copying options from existing collection if any. { + const auto infos = conn->getCollectionInfos(_outputNs.db().toString(), + BSON("name" << _outputNs.coll())); + const auto options = infos.empty() ? BSONObj() + : infos.front().getObjectField("options"); + + BSONObjBuilder cmd; + cmd << "create" << _tempNs.coll(); + cmd << "temp" << true; + cmd.appendElementsUnique(options); + BSONObj info; - bool ok =conn->runCommand(_outputNs.db().toString(), - BSON("create" << _tempNs.coll() << "temp" << true), - info); + bool ok = conn->runCommand(_outputNs.db().toString(), cmd.done(), info); uassert(16994, str::stream() << "failed to create temporary $out collection '" << _tempNs.ns() << "': " << info.toString(), ok); |