summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Rassi <rassi@10gen.com>2014-02-28 12:03:21 -0500
committerJason Rassi <rassi@10gen.com>2014-02-28 13:50:58 -0500
commit4d51c9ac8769223b5c2db1383325318d31f141b6 (patch)
tree605ebeff4cf927c3b4f607d9d6aa2f69e1e7f536 /src
parent944807590b5d7a6a5b7b53f02bd032faf9406507 (diff)
downloadmongo-4d51c9ac8769223b5c2db1383325318d31f141b6.tar.gz
SERVER-10879 Index spec equality check should test all index options
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/structure/catalog/index_details.cpp44
1 files changed, 39 insertions, 5 deletions
diff --git a/src/mongo/db/structure/catalog/index_details.cpp b/src/mongo/db/structure/catalog/index_details.cpp
index 8c2cb50a60e..81b5b71b2ee 100644
--- a/src/mongo/db/structure/catalog/index_details.cpp
+++ b/src/mongo/db/structure/catalog/index_details.cpp
@@ -64,6 +64,8 @@ namespace mongo {
}
bool IndexDetails::areIndexOptionsEquivalent(const BSONObj& newSpec ) const {
+ // Handle the special cases first.
+
if ( dropDups() != newSpec["dropDups"].trueValue() ) {
return false;
}
@@ -74,17 +76,49 @@ namespace mongo {
return false;
}
- // Note: { _id: 1 } or { _id: -1 } implies unique: true.
if ( !isIdIndex() &&
unique() != newSpec["unique"].trueValue() ) {
+ // Note: { _id: 1 } or { _id: -1 } implies unique: true.
return false;
}
- const BSONElement existingExpireSecs =
- info.obj().getField("expireAfterSeconds");
- const BSONElement newExpireSecs = newSpec["expireAfterSeconds"];
+ // Then compare the rest of the options.
+
+ std::map<StringData, BSONElement> existingOptionsMap;
+ BSONObjIterator existingSpecIt( info.obj() );
+ while ( existingSpecIt.more() ) {
+ const BSONElement e = existingSpecIt.next();
+ StringData fieldName = e.fieldNameStringData();
+ if ( fieldName == "key" ||
+ fieldName == "ns" ||
+ fieldName == "name" ||
+ fieldName == "v" ||
+ fieldName == "dropDups" ||
+ fieldName == "sparse" ||
+ fieldName == "unique" ) {
+ continue;
+ }
+ existingOptionsMap[ fieldName ] = e;
+ }
+
+ std::map<StringData, BSONElement> newOptionsMap;
+ BSONObjIterator newSpecIt( newSpec );
+ while ( newSpecIt.more() ) {
+ const BSONElement e = newSpecIt.next();
+ StringData fieldName = e.fieldNameStringData();
+ if ( fieldName == "key" ||
+ fieldName == "ns" ||
+ fieldName == "name" ||
+ fieldName == "v" ||
+ fieldName == "dropDups" ||
+ fieldName == "sparse" ||
+ fieldName == "unique" ) {
+ continue;
+ }
+ newOptionsMap[ fieldName ] = e;
+ }
- return existingExpireSecs == newExpireSecs;
+ return existingOptionsMap == newOptionsMap;
}
}