summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Milkie <milkie@10gen.com>2012-10-02 13:13:15 -0400
committerEric Milkie <milkie@10gen.com>2012-10-02 17:46:21 -0400
commitd168d1a3ee648c4dd39de70babed7a9945f75259 (patch)
treea9b535e3c17f82cf5e82a5aedb543bf0abc8650c
parentd2d9f179a17f8b76b014b621bfc7a5bf67733633 (diff)
downloadmongo-d168d1a3ee648c4dd39de70babed7a9945f75259.tar.gz
SERVER-6671 do not ignore special _id unique index
-rw-r--r--src/mongo/db/index.cpp2
-rw-r--r--src/mongo/db/index_update.cpp12
-rw-r--r--src/mongo/db/pdfile.cpp5
-rw-r--r--src/mongo/db/repl/rs.h18
4 files changed, 24 insertions, 13 deletions
diff --git a/src/mongo/db/index.cpp b/src/mongo/db/index.cpp
index 583a2a8afcc..274c3aa37d9 100644
--- a/src/mongo/db/index.cpp
+++ b/src/mongo/db/index.cpp
@@ -437,7 +437,7 @@ namespace mongo {
void IndexChanges::dupCheck(IndexDetails& idx, DiskLoc curObjLoc) {
if (added.empty() ||
!idx.unique() ||
- ignoreUniqueIndexes()) {
+ ignoreUniqueIndex(idx)) {
return;
}
const Ordering ordering = Ordering::make(idx.keyPattern());
diff --git a/src/mongo/db/index_update.cpp b/src/mongo/db/index_update.cpp
index 7924dfbc7df..e8633cf3734 100644
--- a/src/mongo/db/index_update.cpp
+++ b/src/mongo/db/index_update.cpp
@@ -127,7 +127,13 @@ namespace mongo {
BSONObjSet keys;
for ( int i = 0; i < n; i++ ) {
// this call throws on unique constraint violation. we haven't done any writes yet so that is fine.
- fetchIndexInserters(/*out*/keys, inserter, d, i, obj, loc, ignoreUniqueIndexes());
+ fetchIndexInserters(/*out*/keys,
+ inserter,
+ d,
+ i,
+ obj,
+ loc,
+ ignoreUniqueIndex(d->idx(i)));
if( keys.size() > 1 ) {
multi.push_back(i);
multiKeys.push_back(BSONObjSet());
@@ -144,7 +150,7 @@ namespace mongo {
unsigned i = multi[j];
BSONObjSet& keys = multiKeys[j];
IndexDetails& idx = d->idx(i);
- bool dupsAllowed = !idx.unique() || ignoreUniqueIndexes();
+ bool dupsAllowed = !idx.unique() || ignoreUniqueIndex(idx);
IndexInterface& ii = idx.idxInterface();
Ordering ordering = Ordering::make(idx.keyPattern());
d->setIndexIsMultikey(ns, i);
@@ -271,7 +277,7 @@ namespace mongo {
tlog(1) << "fastBuildIndex " << ns << " idxNo:" << idxNo << ' ' << idx.info.obj().toString() << endl;
- bool dupsAllowed = !idx.unique() || ignoreUniqueIndexes();
+ bool dupsAllowed = !idx.unique() || ignoreUniqueIndex(idx);
bool dropDups = idx.dropDups() || inDBRepair;
BSONObj order = idx.keyPattern();
diff --git a/src/mongo/db/pdfile.cpp b/src/mongo/db/pdfile.cpp
index 3c64200f398..aea2b6dbafe 100644
--- a/src/mongo/db/pdfile.cpp
+++ b/src/mongo/db/pdfile.cpp
@@ -1229,6 +1229,8 @@ namespace mongo {
for ( int idxNo = 0; idxNo < d->nIndexes; idxNo++ ) {
if( d->idx(idxNo).unique() ) {
IndexDetails& idx = d->idx(idxNo);
+ if (ignoreUniqueIndex(idx))
+ continue;
BSONObjSet keys;
idx.getKeysFromObject(obj, keys);
BSONObj order = idx.keyPattern();
@@ -1453,8 +1455,7 @@ namespace mongo {
// constraint before allocating space.
if (d->nIndexes &&
d->isCapped() &&
- !god &&
- !ignoreUniqueIndexes()) {
+ !god) {
checkNoIndexConflicts( d, BSONObj( reinterpret_cast<const char *>( obuf ) ) );
}
diff --git a/src/mongo/db/repl/rs.h b/src/mongo/db/repl/rs.h
index 6b6879e0fc1..ac189e05ffc 100644
--- a/src/mongo/db/repl/rs.h
+++ b/src/mongo/db/repl/rs.h
@@ -19,6 +19,7 @@
#pragma once
#include "mongo/db/commands.h"
+#include "mongo/db/index.h"
#include "mongo/db/oplog.h"
#include "mongo/db/oplogreader.h"
#include "mongo/db/repl/rs_config.h"
@@ -670,13 +671,16 @@ namespace mongo {
_hbinfo.health = 1.0;
}
- inline bool ignoreUniqueIndexes() {
- if (theReplSet) {
- // see SERVER-6671
- MemberState ms = theReplSet->state();
- if ((ms == MemberState::RS_STARTUP2) ||
- (ms == MemberState::RS_RECOVERING) ||
- (ms == MemberState::RS_ROLLBACK)) {
+ inline bool ignoreUniqueIndex(IndexDetails& idx) {
+ if (!idx.unique()) return false;
+ if (!theReplSet) return false;
+ // see SERVER-6671
+ MemberState ms = theReplSet->state();
+ if ((ms == MemberState::RS_STARTUP2) ||
+ (ms == MemberState::RS_RECOVERING) ||
+ (ms == MemberState::RS_ROLLBACK)) {
+ // Never ignore _id index
+ if (!idx.isIdIndex()) {
return true;
}
}