summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-03-13 15:56:45 -0400
committerEliot Horowitz <eliot@10gen.com>2014-03-14 09:32:48 -0400
commit8dd9cf06d7df65baf16eac7725e837c8303eef07 (patch)
treed64362d4854afafd3d6072519a02df47dcbe6498
parent1ceeb84bd0b170bb367e8f78be53d2f075007cb5 (diff)
downloadmongo-8dd9cf06d7df65baf16eac7725e837c8303eef07.tar.gz
SERVER-12662: Two background index builds in parallel with unique key constraint violations crashes secondary
-rw-r--r--src/mongo/db/index.cpp21
-rw-r--r--src/mongo/db/instance.cpp23
-rw-r--r--src/mongo/db/pdfile.cpp6
3 files changed, 32 insertions, 18 deletions
diff --git a/src/mongo/db/index.cpp b/src/mongo/db/index.cpp
index c2e536739a1..9ce80e6deba 100644
--- a/src/mongo/db/index.cpp
+++ b/src/mongo/db/index.cpp
@@ -324,6 +324,8 @@ namespace mongo {
getDur().writingInt(dfh->versionMinor) = PDFILE_VERSION_MINOR_24_AND_NEWER;
}
+ extern BSONObj id_obj; // { _id : 1 }
+
bool prepareToBuildIndex(const BSONObj& io,
bool mayInterrupt,
bool god,
@@ -395,10 +397,10 @@ namespace mongo {
all be treated as the same pattern.
*/
if ( IndexDetails::isIdIndexPattern(key) ) {
- if( !god ) {
- ensureHaveIdIndex( sourceNS.c_str(), mayInterrupt );
- return false;
- }
+ //if( !god ) {
+ //ensureHaveIdIndex( sourceNS.c_str(), mayInterrupt );
+ //return false;
+ //}
}
else {
/* is buildIndexes:false set for this replica set member?
@@ -437,7 +439,14 @@ namespace mongo {
}
// idea is to put things we use a lot earlier
b.append("v", v);
- b.append(o["key"]);
+ if ( IndexDetails::isIdIndexPattern(o["key"].Obj()) ) {
+ b.append("name", "_id_");
+ b.append("key", id_obj);
+ }
+ else {
+ b.append( "name", o["name"] );
+ b.append(o["key"]);
+ }
if( o["unique"].trueValue() )
b.appendBool("unique", true); // normalize to bool true in case was int 1 or something...
b.append(o["ns"]);
@@ -448,7 +457,7 @@ namespace mongo {
while ( i.more() ) {
BSONElement e = i.next();
string s = e.fieldName();
- if( s != "_id" && s != "v" && s != "ns" && s != "unique" && s != "key" )
+ if( s != "_id" && s != "v" && s != "ns" && s != "unique" && s != "key" && s != "name" )
b.append(e);
}
}
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index 926cdeecdb6..b95bcb1bfea 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -792,16 +792,19 @@ namespace mongo {
}
}
- theDataFileMgr.insertWithObjMod(ns,
- // May be modified in the call to add an _id field.
- js,
- // Only permit interrupting an (index build) insert if the
- // insert comes from a socket client request rather than a
- // parent operation using the client interface. The parent
- // operation might not support interrupts.
- cc().curop()->parent() == NULL,
- false);
- logOp("i", ns, js);
+ DiskLoc dl = theDataFileMgr.
+ insertWithObjMod(ns,
+ // May be modified in the call to add an _id field.
+ js,
+ // Only permit interrupting an (index build) insert if the
+ // insert comes from a socket client request rather than a
+ // parent operation using the client interface. The parent
+ // operation might not support interrupts.
+ cc().curop()->parent() == NULL,
+ false);
+ if (!dl.isNull()) {
+ logOp("i", ns, js);
+ }
}
NOINLINE_DECL void insertMulti(bool keepGoing, const char *ns, vector<BSONObj>& objs, CurOp& op) {
diff --git a/src/mongo/db/pdfile.cpp b/src/mongo/db/pdfile.cpp
index b397061c397..7aaa24a9fbc 100644
--- a/src/mongo/db/pdfile.cpp
+++ b/src/mongo/db/pdfile.cpp
@@ -1316,8 +1316,10 @@ namespace mongo {
void DataFileMgr::insertAndLog( const char *ns, const BSONObj &o, bool god, bool fromMigrate ) {
BSONObj tmp = o;
- insertWithObjMod( ns, tmp, false, god );
- logOp( "i", ns, tmp, 0, 0, fromMigrate );
+ DiskLoc loc = insertWithObjMod( ns, tmp, false, god );
+ if (!loc.isNull()) {
+ logOp( "i", ns, tmp, 0, 0, fromMigrate );
+ }
}
/** @param o the object to insert. can be modified to add _id and thus be an in/out param