summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog/index_key_validate.cpp
diff options
context:
space:
mode:
authorGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-07-29 21:00:16 -0400
committerGregory Wlodarek <gregory.wlodarek@mongodb.com>2019-07-29 21:06:47 -0400
commit0d6d248c39a5b4e43eefc9320b5dec3229cfcfdb (patch)
tree1fb67633d3c9c551341dbf41efb47a80c6392553 /src/mongo/db/catalog/index_key_validate.cpp
parent47d0308cd596c6d40d6a3069379be1bdaf51d47b (diff)
downloadmongo-0d6d248c39a5b4e43eefc9320b5dec3229cfcfdb.tar.gz
SERVER-41696 Remove the 'ns' field from index specs
Diffstat (limited to 'src/mongo/db/catalog/index_key_validate.cpp')
-rw-r--r--src/mongo/db/catalog/index_key_validate.cpp57
1 files changed, 14 insertions, 43 deletions
diff --git a/src/mongo/db/catalog/index_key_validate.cpp b/src/mongo/db/catalog/index_key_validate.cpp
index 2bc450516fb..83c6812f5b1 100644
--- a/src/mongo/db/catalog/index_key_validate.cpp
+++ b/src/mongo/db/catalog/index_key_validate.cpp
@@ -40,7 +40,6 @@
#include "mongo/base/status.h"
#include "mongo/base/status_with.h"
-#include "mongo/db/catalog/disable_index_spec_namespace_generation_gen.h"
#include "mongo/db/field_ref.h"
#include "mongo/db/index/index_descriptor.h"
#include "mongo/db/index/wildcard_key_generator.h"
@@ -255,7 +254,6 @@ BSONObj removeUnknownFields(const BSONObj& indexSpec) {
StatusWith<BSONObj> validateIndexSpec(
OperationContext* opCtx,
const BSONObj& indexSpec,
- const NamespaceString& expectedNamespace,
const ServerGlobalParams::FeatureCompatibility& featureCompatibility) {
bool hasKeyPatternField = false;
bool hasIndexNameField = false;
@@ -327,28 +325,6 @@ StatusWith<BSONObj> validateIndexSpec(
hasIndexNameField = true;
} else if (IndexDescriptor::kNamespaceFieldName == indexSpecElemFieldName) {
- if (indexSpecElem.type() != BSONType::String) {
- return {ErrorCodes::TypeMismatch,
- str::stream()
- << "The field '" << IndexDescriptor::kNamespaceFieldName
- << "' must be a string, but got " << typeName(indexSpecElem.type())};
- }
-
- StringData ns = indexSpecElem.valueStringData();
- if (ns.empty()) {
- return {ErrorCodes::BadValue,
- str::stream() << "The field '" << IndexDescriptor::kNamespaceFieldName
- << "' cannot be an empty string"};
- }
-
- if (ns != expectedNamespace.ns()) {
- return {ErrorCodes::BadValue,
- str::stream()
- << "The value of the field '" << IndexDescriptor::kNamespaceFieldName
- << "' (" << ns << ") doesn't match the namespace '" << expectedNamespace
- << "'"};
- }
-
hasNamespaceField = true;
} else if (IndexDescriptor::kIndexVersionFieldName == indexSpecElemFieldName) {
if (!indexSpecElem.isNumber()) {
@@ -485,29 +461,24 @@ StatusWith<BSONObj> validateIndexSpec(
<< static_cast<int>(*resolvedIndexVersion)};
}
- if (!hasNamespaceField || !hasVersionField) {
- BSONObjBuilder bob;
+ BSONObj modifiedSpec = indexSpec;
- // Only generate the 'ns' field for the index spec if it's missing it and if the server test
- // parameter to disable the generation isn't enabled.
- if (!hasNamespaceField && !disableIndexSpecNamespaceGeneration.load()) {
- // We create a new index specification with the 'ns' field set as 'expectedNamespace' if
- // the field was omitted.
- bob.append(IndexDescriptor::kNamespaceFieldName, expectedNamespace.ns());
- }
-
- if (!hasVersionField) {
- // We create a new index specification with the 'v' field set as 'defaultIndexVersion'
- // if the field was omitted.
- bob.append(IndexDescriptor::kIndexVersionFieldName,
- static_cast<int>(*resolvedIndexVersion));
- }
+ // Ignore any 'ns' field in the index spec because this field is dropped post-4.0. Don't remove
+ // the field during repair, as repair may run on old data files (version 3.6 and 4.0) that
+ // require the field to be present.
+ if (hasNamespaceField && !storageGlobalParams.repair) {
+ modifiedSpec = modifiedSpec.removeField(IndexDescriptor::kNamespaceFieldName);
+ }
- bob.appendElements(indexSpec);
- return bob.obj();
+ if (!hasVersionField) {
+ // We create a new index specification with the 'v' field set as 'defaultIndexVersion' if
+ // the field was omitted.
+ BSONObj versionObj = BSON(IndexDescriptor::kIndexVersionFieldName
+ << static_cast<int>(*resolvedIndexVersion));
+ modifiedSpec = modifiedSpec.addField(versionObj.firstElement());
}
- return indexSpec;
+ return modifiedSpec;
}
Status validateIdIndexSpec(const BSONObj& indexSpec) {