aboutsummaryrefslogtreecommitdiffstats
path: root/includes/deferred
diff options
context:
space:
mode:
authorAaron Schulz <aschulz@wikimedia.org>2019-03-21 14:05:35 -0700
committerAaron Schulz <aschulz@wikimedia.org>2019-03-21 14:07:51 -0700
commit17080453a1a94d317247197b639472f87e2aaa03 (patch)
tree14faba21db4a0dc2f60dfaad6228c0fa437adfb4 /includes/deferred
parentacd7c48f12ea1eca1abbe3a3d1ee4e57bac9b3b2 (diff)
downloadmediawikicore-17080453a1a94d317247197b639472f87e2aaa03.tar.gz
mediawikicore-17080453a1a94d317247197b639472f87e2aaa03.zip
Support more coupled DBs in AtomicSectionUpdate/AutoCommitUpdate
This is useful for updating a secondary database based on a commit to the main one, especially for using auto-commit. Change-Id: Iad9084d2fb0490ecdfd5fcc97db33bfbcbfa5d21
Diffstat (limited to 'includes/deferred')
-rw-r--r--includes/deferred/AtomicSectionUpdate.php18
-rw-r--r--includes/deferred/AutoCommitUpdate.php18
-rw-r--r--includes/deferred/MWCallableUpdate.php4
3 files changed, 30 insertions, 10 deletions
diff --git a/includes/deferred/AtomicSectionUpdate.php b/includes/deferred/AtomicSectionUpdate.php
index 8b62989b53ab..69f09e392868 100644
--- a/includes/deferred/AtomicSectionUpdate.php
+++ b/includes/deferred/AtomicSectionUpdate.php
@@ -15,18 +15,22 @@ class AtomicSectionUpdate implements DeferrableUpdate, DeferrableCallback {
private $callback;
/**
- * @param IDatabase $dbw
+ * @param IDatabase $dbw DB handle; update aborts if a transaction now this rolls back
* @param string $fname Caller name (usually __METHOD__)
* @param callable $callback
+ * @param IDatabase[] $conns Abort if a transaction now on one of these rolls back [optional]
* @see IDatabase::doAtomicSection()
*/
- public function __construct( IDatabase $dbw, $fname, callable $callback ) {
+ public function __construct( IDatabase $dbw, $fname, callable $callback, array $conns = [] ) {
$this->dbw = $dbw;
$this->fname = $fname;
$this->callback = $callback;
-
- if ( $this->dbw->trxLevel() ) {
- $this->dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
+ // Register DB connections for which uncommitted changes are related to this update
+ $conns[] = $dbw;
+ foreach ( $conns as $conn ) {
+ if ( $conn->trxLevel() ) {
+ $conn->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
+ }
}
}
@@ -36,6 +40,10 @@ class AtomicSectionUpdate implements DeferrableUpdate, DeferrableCallback {
}
}
+ /**
+ * @private This method is public so that it works with onTransactionResolution()
+ * @param int $trigger
+ */
public function cancelOnRollback( $trigger ) {
if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
$this->callback = null;
diff --git a/includes/deferred/AutoCommitUpdate.php b/includes/deferred/AutoCommitUpdate.php
index 85071576b078..ddfd98716d8d 100644
--- a/includes/deferred/AutoCommitUpdate.php
+++ b/includes/deferred/AutoCommitUpdate.php
@@ -15,17 +15,21 @@ class AutoCommitUpdate implements DeferrableUpdate, DeferrableCallback {
private $callback;
/**
- * @param IDatabase $dbw
+ * @param IDatabase $dbw DB handle; update aborts if a transaction now this rolls back
* @param string $fname Caller name (usually __METHOD__)
* @param callable $callback Callback that takes (IDatabase, method name string)
+ * @param IDatabase[] $conns Abort if a transaction now on one of these rolls back [optional]
*/
- public function __construct( IDatabase $dbw, $fname, callable $callback ) {
+ public function __construct( IDatabase $dbw, $fname, callable $callback, array $conns = [] ) {
$this->dbw = $dbw;
$this->fname = $fname;
$this->callback = $callback;
-
- if ( $this->dbw->trxLevel() ) {
- $this->dbw->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
+ // Register DB connections for which uncommitted changes are related to this update
+ $conns[] = $dbw;
+ foreach ( $conns as $conn ) {
+ if ( $conn->trxLevel() ) {
+ $conn->onTransactionResolution( [ $this, 'cancelOnRollback' ], $fname );
+ }
}
}
@@ -50,6 +54,10 @@ class AutoCommitUpdate implements DeferrableUpdate, DeferrableCallback {
}
}
+ /**
+ * @private This method is public so that it works with onTransactionResolution()
+ * @param int $trigger
+ */
public function cancelOnRollback( $trigger ) {
if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
$this->callback = null;
diff --git a/includes/deferred/MWCallableUpdate.php b/includes/deferred/MWCallableUpdate.php
index 9803b7a491b1..efca406881cd 100644
--- a/includes/deferred/MWCallableUpdate.php
+++ b/includes/deferred/MWCallableUpdate.php
@@ -35,6 +35,10 @@ class MWCallableUpdate implements DeferrableUpdate, DeferrableCallback {
}
}
+ /**
+ * @private This method is public so that it works with onTransactionResolution()
+ * @param int $trigger
+ */
public function cancelOnRollback( $trigger ) {
if ( $trigger === IDatabase::TRIGGER_ROLLBACK ) {
$this->callback = null;