diff options
author | Charlie Swanson <cswanson310@gmail.com> | 2016-07-15 12:24:57 -0400 |
---|---|---|
committer | Charlie Swanson <cswanson310@gmail.com> | 2016-07-18 18:50:58 -0400 |
commit | e420c60e6c6fcdf1ba0d65d58e41ab85c09c0f51 (patch) | |
tree | 7ef9ca5fee9898fcf983ab03d0176bccc1449aa4 /src/mongo/db/storage/bson_collection_catalog_entry.cpp | |
parent | 8a487d846954ff28df781bab07257694cacfd6aa (diff) | |
download | mongo-e420c60e6c6fcdf1ba0d65d58e41ab85c09c0f51.tar.gz |
SERVER-23073 Reliably detect concurrent changes to $out collection.
A $out stage will write to a temporary collection, and then rename into
the target collection. If the original collection is sharded, has its
options changed, or changes its indexes during processing, the
aggregation should fail.
This change removes any race conditions around detecting these changes.
Diffstat (limited to 'src/mongo/db/storage/bson_collection_catalog_entry.cpp')
-rw-r--r-- | src/mongo/db/storage/bson_collection_catalog_entry.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/mongo/db/storage/bson_collection_catalog_entry.cpp b/src/mongo/db/storage/bson_collection_catalog_entry.cpp index d5a0c7da6cc..7837e898b56 100644 --- a/src/mongo/db/storage/bson_collection_catalog_entry.cpp +++ b/src/mongo/db/storage/bson_collection_catalog_entry.cpp @@ -216,8 +216,14 @@ void BSONCollectionCatalogEntry::MetaData::rename(StringData toNS) { for (size_t i = 0; i < indexes.size(); i++) { BSONObj spec = indexes[i].spec; BSONObjBuilder b; - b.append("ns", toNS); - b.appendElementsUnique(spec); + // Add the fields in the same order they were in the original specification. + for (auto&& elem : spec) { + if (elem.fieldNameStringData() == "ns") { + b.append("ns", toNS); + } else { + b.append(elem); + } + } indexes[i].spec = b.obj(); } } |