diff options
author | David Storch <david.storch@10gen.com> | 2016-10-18 17:48:07 -0400 |
---|---|---|
committer | David Storch <david.storch@10gen.com> | 2016-10-20 15:44:40 -0400 |
commit | 315f92405c5f5e5f4159ccbb55b0352cfe235852 (patch) | |
tree | 1d00ff8e50968e79936c19154170248bbbdd2672 /src/mongo/db/repair_database.cpp | |
parent | 278bdb38318f84e0019982e4124e05ac22db05d2 (diff) | |
download | mongo-315f92405c5f5e5f4159ccbb55b0352cfe235852.tar.gz |
SERVER-26659 only use stricter key pattern validation for v:2 or new index builds
This now follows the same rules which we will use in 3.4 for
rejecting unknown top-level options in the index spec. These
rules ensure a smooth upgrade, even in the presence of bad
index metadata produced on an older server version.
Diffstat (limited to 'src/mongo/db/repair_database.cpp')
-rw-r--r-- | src/mongo/db/repair_database.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/mongo/db/repair_database.cpp b/src/mongo/db/repair_database.cpp index 9172b2f3a1d..dde257369eb 100644 --- a/src/mongo/db/repair_database.cpp +++ b/src/mongo/db/repair_database.cpp @@ -75,6 +75,7 @@ Status rebuildIndexesOnCollection(OperationContext* txn, const string& name = indexNames[i]; BSONObj spec = cce->getIndexSpec(txn, name); + IndexVersion newIndexVersion = IndexVersion::kV0; { BSONObjBuilder bob; @@ -85,12 +86,13 @@ Status rebuildIndexesOnCollection(OperationContext* txn, static_cast<IndexVersion>(indexSpecElem.numberInt()); if (IndexVersion::kV0 == indexVersion) { // We automatically upgrade v=0 indexes to v=1 indexes. - bob.append(IndexDescriptor::kIndexVersionFieldName, - static_cast<int>(IndexVersion::kV1)); + newIndexVersion = IndexVersion::kV1; } else { - bob.append(IndexDescriptor::kIndexVersionFieldName, - static_cast<int>(indexVersion)); + newIndexVersion = indexVersion; } + + bob.append(IndexDescriptor::kIndexVersionFieldName, + static_cast<int>(newIndexVersion)); } else { bob.append(indexSpecElem); } @@ -100,7 +102,7 @@ Status rebuildIndexesOnCollection(OperationContext* txn, } const BSONObj key = spec.getObjectField("key"); - const Status keyStatus = validateKeyPattern(key); + const Status keyStatus = validateKeyPattern(key, newIndexVersion); if (!keyStatus.isOK()) { return Status( ErrorCodes::CannotCreateIndex, |