summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/db/repl')
-rw-r--r--src/mongo/db/repl/oplog.cpp40
-rw-r--r--src/mongo/db/repl/oplog.h18
2 files changed, 49 insertions, 9 deletions
diff --git a/src/mongo/db/repl/oplog.cpp b/src/mongo/db/repl/oplog.cpp
index 1d131d0af1e..5e6e78418f1 100644
--- a/src/mongo/db/repl/oplog.cpp
+++ b/src/mongo/db/repl/oplog.cpp
@@ -347,13 +347,14 @@ void logOpInitiate(OperationContext* txn, const BSONObj& obj) {
d delete / remove
u update
*/
-void logOp(OperationContext* txn,
- const char* opstr,
- const char* ns,
- const BSONObj& obj,
- BSONObj* patt,
- bool* b,
- bool fromMigrate) {
+static void logOpInternal(OperationContext* txn,
+ const char* opstr,
+ const char* ns,
+ const BSONObj& obj,
+ BSONObj* patt,
+ bool* b,
+ bool fromMigrate,
+ bool isDeleteInMigratingChunk) {
if (getGlobalReplicationCoordinator()->isReplEnabled()) {
_logOp(txn, opstr, ns, 0, obj, patt, b, fromMigrate);
}
@@ -363,13 +364,36 @@ void logOp(OperationContext* txn,
// rollback-safe logOp listeners
//
getGlobalAuthorizationManager()->logOp(txn, opstr, ns, obj, patt, b);
- logOpForSharding(txn, opstr, ns, obj, patt, fromMigrate);
+ logOpForSharding(txn, opstr, ns, obj, patt, fromMigrate || !isDeleteInMigratingChunk);
logOpForDbHash(txn, ns);
if (strstr(ns, ".system.js")) {
Scope::storedFuncMod(txn);
}
}
+void logOp(OperationContext* txn,
+ const char* opstr,
+ const char* ns,
+ const BSONObj& obj,
+ BSONObj* patt,
+ bool* b,
+ bool fromMigrate) {
+ if (MONGO_unlikely(opstr[0] == 'd' && opstr[1] == '\0')) {
+ severe() << "logOp called with opstr == 'd'; use logDeleteOp instead";
+ invariant(*opstr != 'd');
+ }
+ logOpInternal(txn, opstr, ns, obj, patt, b, fromMigrate, false);
+}
+
+void logDeleteOp(OperationContext* txn,
+ const char* ns,
+ const BSONObj& idDoc,
+ bool fromMigrate,
+ bool isInMigratingChunk) {
+ bool justOne = true;
+ logOpInternal(txn, "d", ns, idDoc, NULL, &justOne, fromMigrate, isInMigratingChunk);
+}
+
OpTime writeOpsToOplog(OperationContext* txn, const std::deque<BSONObj>& ops) {
ReplicationCoordinator* replCoord = getGlobalReplicationCoordinator();
OpTime lastOptime;
diff --git a/src/mongo/db/repl/oplog.h b/src/mongo/db/repl/oplog.h
index f6f7bc3c82a..8f9038deaa1 100644
--- a/src/mongo/db/repl/oplog.h
+++ b/src/mongo/db/repl/oplog.h
@@ -62,7 +62,6 @@ static const int OPLOG_VERSION = 2;
@param opstr
"i" insert
"u" update
- "d" delete
"c" db cmd
"n" no-op
"db" declares presence of a database (ns is set to the db name + '.')
@@ -71,6 +70,8 @@ static const int OPLOG_VERSION = 2;
the object itself. In that case, we provide also 'fullObj' which is the
image of the object _after_ the mutation logged here was applied.
+ Deletes are logged using logDeleteOp, below.
+
See _logOp() in oplog.cpp for more details.
*/
void logOp(OperationContext* txn,
@@ -81,6 +82,21 @@ void logOp(OperationContext* txn,
bool* b = NULL,
bool fromMigrate = false);
+/**
+ * Log a single document delete to the local oplog.
+ *
+ * "ns" is the fully qualified collection name.
+ * "idDoc" is a document containing the primary key (_id) for the deleted document.
+ * "fromMigrate" is as in "logOp".
+ * "isInMigratingChunk" should be set to the value that isInMigratingChunk() would have returned on
+ * the deleted document, before it was deleted.
+ */
+void logDeleteOp(OperationContext* txn,
+ const char* ns,
+ const BSONObj& idDoc,
+ bool fromMigrate,
+ bool isInMigratingChunk);
+
// Log an empty no-op operation to the local oplog
void logKeepalive(OperationContext* txn);