/**
* Actually any "on transaction pre-commit" callbacks.
*
+ * This method should not be used outside of Database/LoadBalancer
+ *
* @since 1.22
*/
- protected function runOnTransactionPreCommitCallbacks() {
+ public function runOnTransactionPreCommitCallbacks() {
$e = $ePrior = null; // last exception
do { // callbacks may add callbacks :)
$callbacks = $this->mTrxPreCommitCallbacks;
public function commitMasterChanges( $fname = __METHOD__, array $options = [] ) {
$limit = isset( $options['maxWriteDuration'] ) ? $options['maxWriteDuration'] : 0;
+ // Run pre-commit callbacks to keep them out of the COMMIT step. If one errors out here
+ // then all DB transactions can be rolled back before anything was committed yet.
+ $this->forEachLBCallMethod( 'runPreCommitCallbacks' );
+
$this->logMultiDbTransaction();
$this->forEachLB( function ( LoadBalancer $lb ) use ( $limit ) {
$lb->forEachOpenConnection( function ( IDatabase $db ) use ( $limit ) {
}
}
+ /**
+ * Call runOnTransactionPreCommitCallbacks() on all DB handles
+ *
+ * This method should not be used outside of LBFactory/LoadBalancer
+ *
+ * @since 1.28
+ */
+ public function runPreCommitCallbacks() {
+ $masterIndex = $this->getWriterIndex();
+ foreach ( $this->mConns as $conns2 ) {
+ if ( empty( $conns2[$masterIndex] ) ) {
+ continue;
+ }
+ /** @var DatabaseBase $conn */
+ foreach ( $conns2[$masterIndex] as $conn ) {
+ if ( $conn->trxLevel() && $conn->writesOrCallbacksPending() ) {
+ $conn->runOnTransactionPreCommitCallbacks();
+ }
+ }
+ }
+ }
+
/**
* @return bool Whether a master connection is already open
* @since 1.24