summaryrefslogtreecommitdiff
path: root/src/mongo/db/repl/replication_coordinator_impl.h
diff options
context:
space:
mode:
authorSiyuan Zhou <siyuan.zhou@mongodb.com>2019-01-21 19:11:41 -0500
committerSiyuan Zhou <siyuan.zhou@mongodb.com>2019-01-24 22:49:49 -0500
commitd1933f0b1b88c4c2ad0f2fdd6ab106f7eeacddfa (patch)
treef28cbc8eb44fa4363c9824e0e772014c0306f433 /src/mongo/db/repl/replication_coordinator_impl.h
parentec4520d72b2a4ff6ba980e913c988b11e7d188a4 (diff)
downloadmongo-d1933f0b1b88c4c2ad0f2fdd6ab106f7eeacddfa.tar.gz
SERVER-38282 Yield locks for prepared transactions on stepdown.
Diffstat (limited to 'src/mongo/db/repl/replication_coordinator_impl.h')
-rw-r--r--src/mongo/db/repl/replication_coordinator_impl.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/mongo/db/repl/replication_coordinator_impl.h b/src/mongo/db/repl/replication_coordinator_impl.h
index a987b27e0d4..be46d90817d 100644
--- a/src/mongo/db/repl/replication_coordinator_impl.h
+++ b/src/mongo/db/repl/replication_coordinator_impl.h
@@ -474,6 +474,21 @@ private:
void startKillOpThread();
/**
+ * On stepdown, we need to kill all write operations and all transactional operations,
+ * so that unprepared and prepared transactions can release or yield their locks.
+ * The required ordering between stepdown steps is:
+ * 1) Enqueue RSTL in X mode.
+ * 2) Kill all write operations and operations with S locks
+ * 3) Abort unprepared transactions.
+ * 4) Repeat step 2) and 3) until the stepdown thread can acquire RSTL.
+ * 5) Yield locks of all prepared transactions.
+ *
+ * Since prepared transactions don't hold RSTL, step 1) to step 3) make sure all
+ * running transactions that may hold RSTL finish, get killed or yield their locks,
+ * so that we can acquire RSTL at step 4). Holding the locks of prepared transactions
+ * until step 5) guarantees if any conflict operations (e.g. DDL operations) failed
+ * to be killed for any reason, we will get a deadlock instead of a silent data corruption.
+ *
* Loops continuously to kill all user operations that have global lock except in IS mode.
* And, aborts all stashed (inactive) transactions.
* Terminates once killSignaled is set true.