summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2014-08-18 13:58:41 -0400
committerMathias Stearn <mathias@10gen.com>2014-08-20 13:57:04 -0400
commit081f11c248433f74806b7508555b212bc4ff0164 (patch)
treee0ce411fc56f5a6c17ce6df96cd4b15ceb9576e2 /src
parent4cec893ff09f7688c934c5b9a5792bf1c370974d (diff)
downloadmongo-081f11c248433f74806b7508555b212bc4ff0164.tar.gz
SERVER-14219 logOp implicit collection creation
This patch only logs the creation of collections that will not be deleted on operation failure. This fixes a bug where the collection would be created on master, but if the operation failed, the slaves would not get the logOp that implicitly created the collection leading them to differ from the master.
Diffstat (limited to 'src')
-rw-r--r--src/mongo/db/cloner.cpp12
-rw-r--r--src/mongo/db/commands/create_indexes.cpp3
-rw-r--r--src/mongo/db/commands/write_commands/batch_executor.cpp4
-rw-r--r--src/mongo/db/instance.cpp8
-rw-r--r--src/mongo/s/d_migrate.cpp17
5 files changed, 35 insertions, 9 deletions
diff --git a/src/mongo/db/cloner.cpp b/src/mongo/db/cloner.cpp
index 5c4fe93d63a..d28fd763923 100644
--- a/src/mongo/db/cloner.cpp
+++ b/src/mongo/db/cloner.cpp
@@ -128,6 +128,12 @@ namespace mongo {
createdCollection = true;
collection = db->createCollection( txn, to_collection.ns() );
verify( collection );
+ if (logForRepl) {
+ repl::logOp(txn,
+ "c",
+ (_dbName + ".$cmd").c_str(),
+ BSON("create" << to_collection.coll()));
+ }
wunit.commit();
}
@@ -258,6 +264,12 @@ namespace mongo {
WriteUnitOfWork wunit(txn);
collection = db->createCollection( txn, to_collection.ns() );
invariant(collection);
+ if (logForRepl) {
+ repl::logOp(txn,
+ "c",
+ (toDBName + ".$cmd").c_str(),
+ BSON("create" << to_collection.coll()));
+ }
wunit.commit();
}
diff --git a/src/mongo/db/commands/create_indexes.cpp b/src/mongo/db/commands/create_indexes.cpp
index 3b9af7bc48d..4b5c1a869ba 100644
--- a/src/mongo/db/commands/create_indexes.cpp
+++ b/src/mongo/db/commands/create_indexes.cpp
@@ -144,6 +144,9 @@ namespace mongo {
WriteUnitOfWork wunit(txn);
collection = db->createCollection( txn, ns.ns() );
invariant( collection );
+ if (!fromRepl) {
+ repl::logOp(txn, "c", (dbname + ".$cmd").c_str(), BSON("create" << ns.coll()));
+ }
wunit.commit();
}
diff --git a/src/mongo/db/commands/write_commands/batch_executor.cpp b/src/mongo/db/commands/write_commands/batch_executor.cpp
index e73e06efcb6..452c8155b52 100644
--- a/src/mongo/db/commands/write_commands/batch_executor.cpp
+++ b/src/mongo/db/commands/write_commands/batch_executor.cpp
@@ -942,6 +942,10 @@ namespace mongo {
request->getTargetingNS())));
return false;
}
+ repl::logOp(txn,
+ "c",
+ (database->name() + ".$cmd").c_str(),
+ BSON("create" << nsToCollectionSubstring(request->getTargetingNS())));
wunit.commit();
}
return true;
diff --git a/src/mongo/db/instance.cpp b/src/mongo/db/instance.cpp
index b5886eb5e58..c0da7ea2fc1 100644
--- a/src/mongo/db/instance.cpp
+++ b/src/mongo/db/instance.cpp
@@ -798,6 +798,10 @@ namespace mongo {
WriteUnitOfWork wunit(txn);
collection = ctx.db()->createCollection( txn, targetNS );
verify( collection );
+ repl::logOp(txn,
+ "c",
+ (ctx.db()->name() + ".$cmd").c_str(),
+ BSON("create" << nsToCollectionSubstring(targetNS)));
wunit.commit();
}
@@ -838,6 +842,10 @@ namespace mongo {
if ( !collection ) {
collection = ctx.db()->createCollection( txn, ns );
verify( collection );
+ repl::logOp(txn,
+ "c",
+ (ctx.db()->name() + ".$cmd").c_str(),
+ BSON("create" << nsToCollectionSubstring(ns)));
}
StatusWith<DiskLoc> status = collection->insertDocument( txn, js, true );
diff --git a/src/mongo/s/d_migrate.cpp b/src/mongo/s/d_migrate.cpp
index f0c86759a29..9d7bf98e7e4 100644
--- a/src/mongo/s/d_migrate.cpp
+++ b/src/mongo/s/d_migrate.cpp
@@ -1685,15 +1685,14 @@ namespace mongo {
if ( !collection ) {
string system_namespaces = nsToDatabase(ns) + ".system.namespaces";
BSONObj entry = conn->findOne( system_namespaces, BSON( "name" << ns ) );
- if ( entry["options"].isABSONObj() ) {
- Status status = userCreateNS( txn, db, ns, entry["options"].Obj(), true, 0 );
- if ( !status.isOK() ) {
- warning() << "failed to create collection [" << ns << "] "
- << " with options: " << status;
- }
- }
- else {
- db->createCollection( txn, ns );
+ BSONObj options;
+ if ( entry["options"].isABSONObj() )
+ options = entry["options"].Obj();
+
+ Status status = userCreateNS( txn, db, ns, options, true, false );
+ if ( !status.isOK() ) {
+ warning() << "failed to create collection [" << ns << "] "
+ << " with options " << options << ": " << status;
}
}
ctx.commit();