summaryrefslogtreecommitdiff
path: root/src/mongo/db/catalog
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2016-11-06 01:33:50 -0400
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2016-11-06 01:33:50 -0400
commitd23e79eb9e69bd746416d9f674dfaee59457c887 (patch)
tree7ae8940e36d5ae51bb4eadd1318860ca212e8c3f /src/mongo/db/catalog
parent0ac04999faae1d2fc0e10972aaf21082a2e48c8f (diff)
downloadmongo-d23e79eb9e69bd746416d9f674dfaee59457c887.tar.gz
Revert "SERVER-26202 Relax index constraints in oplog application"
This reverts commit f00448255bbb24c07e2f55e7e229f19e316350a6.
Diffstat (limited to 'src/mongo/db/catalog')
-rw-r--r--src/mongo/db/catalog/collection.cpp10
-rw-r--r--src/mongo/db/catalog/index_catalog.cpp34
-rw-r--r--src/mongo/db/catalog/index_catalog.h9
-rw-r--r--src/mongo/db/catalog/index_create.cpp8
4 files changed, 21 insertions, 40 deletions
diff --git a/src/mongo/db/catalog/collection.cpp b/src/mongo/db/catalog/collection.cpp
index 757077efb56..60b8ce717a1 100644
--- a/src/mongo/db/catalog/collection.cpp
+++ b/src/mongo/db/catalog/collection.cpp
@@ -674,7 +674,10 @@ StatusWith<RecordId> Collection::updateDocument(OperationContext* txn,
IndexAccessMethod* iam = ii.accessMethod(descriptor);
InsertDeleteOptions options;
- IndexCatalog::prepareInsertDeleteOptions(txn, descriptor, &options);
+ options.logIfError = false;
+ options.dupsAllowed =
+ !(KeyPattern::isIdKeyPattern(descriptor->keyPattern()) || descriptor->unique()) ||
+ repl::getGlobalReplicationCoordinator()->shouldIgnoreUniqueIndex(descriptor);
UpdateTicket* updateTicket = new UpdateTicket();
updateTickets.mutableMap()[descriptor] = updateTicket;
Status ret = iam->validateUpdate(txn,
@@ -1102,10 +1105,7 @@ public:
// There's no need to compute the prefixes of the indexed fields that cause the
// index to be multikey when validating the index keys.
MultikeyPaths* multikeyPaths = nullptr;
- iam->getKeys(recordBson,
- IndexAccessMethod::GetKeysMode::kEnforceConstraints,
- &documentKeySet,
- multikeyPaths);
+ iam->getKeys(recordBson, &documentKeySet, multikeyPaths);
if (!descriptor->isMultikey(_txn) && documentKeySet.size() > 1) {
string msg = str::stream() << "Index " << descriptor->indexName()
diff --git a/src/mongo/db/catalog/index_catalog.cpp b/src/mongo/db/catalog/index_catalog.cpp
index ffbfea515fd..f8d3a04f4c1 100644
--- a/src/mongo/db/catalog/index_catalog.cpp
+++ b/src/mongo/db/catalog/index_catalog.cpp
@@ -1249,12 +1249,23 @@ const IndexDescriptor* IndexCatalog::refreshEntry(OperationContext* txn,
// ---------------------------
+namespace {
+bool isDupsAllowed(IndexDescriptor* desc) {
+ bool isUnique = desc->unique() || KeyPattern::isIdKeyPattern(desc->keyPattern());
+ if (!isUnique)
+ return true;
+
+ return repl::getGlobalReplicationCoordinator()->shouldIgnoreUniqueIndex(desc);
+}
+}
+
Status IndexCatalog::_indexFilteredRecords(OperationContext* txn,
IndexCatalogEntry* index,
const std::vector<BsonRecord>& bsonRecords,
int64_t* keysInsertedOut) {
InsertDeleteOptions options;
- prepareInsertDeleteOptions(txn, index->descriptor(), &options);
+ options.logIfError = false;
+ options.dupsAllowed = isDupsAllowed(index->descriptor());
for (auto bsonRecord : bsonRecords) {
int64_t inserted;
@@ -1295,8 +1306,8 @@ Status IndexCatalog::_unindexRecord(OperationContext* txn,
bool logIfError,
int64_t* keysDeletedOut) {
InsertDeleteOptions options;
- prepareInsertDeleteOptions(txn, index->descriptor(), &options);
options.logIfError = logIfError;
+ options.dupsAllowed = isDupsAllowed(index->descriptor());
// For unindex operations, dupsAllowed=false really means that it is safe to delete anything
// that matches the key, without checking the RecordID, since dups are impossible. We need
@@ -1365,25 +1376,6 @@ BSONObj IndexCatalog::fixIndexKey(const BSONObj& key) {
return key;
}
-void IndexCatalog::prepareInsertDeleteOptions(OperationContext* txn,
- const IndexDescriptor* desc,
- InsertDeleteOptions* options) {
- auto replCoord = repl::ReplicationCoordinator::get(txn);
- if (replCoord->shouldRelaxIndexConstraints(NamespaceString(desc->parentNS()))) {
- options->getKeysMode = IndexAccessMethod::GetKeysMode::kRelaxConstraints;
- } else {
- options->getKeysMode = IndexAccessMethod::GetKeysMode::kEnforceConstraints;
- }
-
- // Don't allow dups for Id key. Allow dups for non-unique keys or when constraints relaxed.
- if (KeyPattern::isIdKeyPattern(desc->keyPattern())) {
- options->dupsAllowed = false;
- } else {
- options->dupsAllowed = !desc->unique() ||
- options->getKeysMode == IndexAccessMethod::GetKeysMode::kRelaxConstraints;
- }
-}
-
StatusWith<BSONObj> IndexCatalog::_fixIndexSpec(OperationContext* txn,
Collection* collection,
const BSONObj& spec) {
diff --git a/src/mongo/db/catalog/index_catalog.h b/src/mongo/db/catalog/index_catalog.h
index 4016b7860d4..bd0c919076a 100644
--- a/src/mongo/db/catalog/index_catalog.h
+++ b/src/mongo/db/catalog/index_catalog.h
@@ -48,7 +48,6 @@ class Collection;
class IndexDescriptor;
class IndexAccessMethod;
-struct InsertDeleteOptions;
/**
* how many: 1 per Collection
@@ -338,14 +337,6 @@ public:
static BSONObj fixIndexKey(const BSONObj& key);
- /**
- * Fills out 'options' in order to indicate whether to allow dups or relax
- * index constraints, as needed by replication.
- */
- static void prepareInsertDeleteOptions(OperationContext* txn,
- const IndexDescriptor* desc,
- InsertDeleteOptions* options);
-
private:
static const BSONObj _idObj; // { _id : 1 }
diff --git a/src/mongo/db/catalog/index_create.cpp b/src/mongo/db/catalog/index_create.cpp
index d71d26b13b7..823dacff550 100644
--- a/src/mongo/db/catalog/index_create.cpp
+++ b/src/mongo/db/catalog/index_create.cpp
@@ -215,11 +215,9 @@ StatusWith<std::vector<BSONObj>> MultiIndexBlock::init(const std::vector<BSONObj
const IndexDescriptor* descriptor = index.block->getEntry()->descriptor();
- IndexCatalog::prepareInsertDeleteOptions(_txn, descriptor, &index.options);
- index.options.dupsAllowed = index.options.dupsAllowed || _ignoreUnique;
- if (_ignoreUnique) {
- index.options.getKeysMode = IndexAccessMethod::GetKeysMode::kRelaxConstraints;
- }
+ index.options.logIfError = false; // logging happens elsewhere if needed.
+ index.options.dupsAllowed = !descriptor->unique() || _ignoreUnique ||
+ repl::getGlobalReplicationCoordinator()->shouldIgnoreUniqueIndex(descriptor);
log() << "build index on: " << ns << " properties: " << descriptor->toString();
if (index.bulk)