MediaWiki master
Wikimedia\Rdbms\TransactionManager Class Reference

Public Member Functions

 __construct (?LoggerInterface $logger=null, $profiler=null)
 
 addPostCommitOrIdleCallback (callable $callback, $fname)
 
 addPreCommitOrIdleCallback (callable $callback, $fname)
 
 addToAtomicLevels ( $fname, AtomicSectionIdentifier $sectionId, $savepointId)
 
 assertSessionStatus (IDatabase $db, $fname)
 
 assertTransactionStatus (IDatabase $db, $deprecationLogger, $fname)
 
 cancelAtomic ( $pos)
 
 clearEndCallbacks ()
 
 clearPreEndCallbacks ()
 
 clearSessionError ()
 Unflag the session as needing a reset due to an error.
 
 consumeEndCallbacks ()
 
 countPostCommitOrIdleCallbacks ()
 
 currentAtomicSectionId ()
 
 explicitTrxActive ()
 
 getPositionFromSectionId (?AtomicSectionIdentifier $sectionId=null)
 
 getRecurringCallbacks ()
 
 getTrxId ()
 Get the application-side transaction identifier instance.
 
 isEndCallbacksSuppressed ()
 
 modifyCallbacksForCancel (array $excisedSectionsId, ?AtomicSectionIdentifier $newSectionId=null)
 Update callbacks that were owned by cancelled atomic sections.
 
 nextSavePointId (IDatabase $db, $fname)
 
 onBegin (IDatabase $db, $fname)
 
 onBeginInCriticalSection ( $mode, $fname, $rtt)
 
 onCancelAtomicBeforeCriticalSection (IDatabase $db, $fname)
 
 onCommit (IDatabase $db, $fname, $flush)
 
 onCommitInCriticalSection (IDatabase $db)
 
 onDestruct ()
 
 onEndAtomic (IDatabase $db, $fname)
 
 onEndAtomicInCriticalSection ( $sectionId)
 
 onFlushSnapshot (IDatabase $db, $fname, $flush, $trxRoundFname)
 
 onGetScopedLockAndFlush (IDatabase $db, $fname)
 
 onRollbackInCriticalSection (IDatabase $db)
 
 onSessionLoss (IDatabase $db)
 
 onTransactionResolution (IDatabase $db, callable $callback, $fname)
 
 pendingPreCommitCallbackCallers ()
 List the methods that have precommit callbacks for the current transaction.
 
 pendingWriteAndCallbackCallers ()
 List the methods that have write queries or callbacks for the current transaction.
 
 pendingWriteCallers ()
 
 pendingWriteQueryDuration ( $type=IDatabase::ESTIMATE_TOTAL)
 
 popAtomicLevel ()
 
 reassignCallbacksForSection (AtomicSectionIdentifier $old, AtomicSectionIdentifier $new)
 Hoist callback ownership for callbacks in a section to a parent section.
 
 recordQueryCompletion ( $sql, $startTime, $isPermWrite, $rowCount, $serverName)
 
 resetTrxAtomicLevels ()
 
 runOnTransactionPreCommitCallbacks (IDatabase $db)
 Consume and run any "on transaction pre-commit" callbacks.
 
 sessionStatus ()
 Get the status of the current session (ephemeral server-side state tied to the connection)
 
 setAutomaticAtomic ( $value)
 
 setSessionError (Throwable $sessionError)
 Flag the session as needing a reset due to an error, if not already flagged.
 
 setTransactionError (Throwable $trxError)
 Mark the transaction as requiring rollback (STATUS_TRX_ERROR) due to an error.
 
 setTransactionListener ( $name, ?callable $callback=null)
 
 setTrxEndCallbackSuppression (bool $suppress)
 Whether to disable running of post-COMMIT/ROLLBACK callbacks.
 
 setTrxStatusIgnoredCause (?array $trxStatusIgnoredCause)
 
 setTrxStatusToNone ()
 
 setTrxStatusToOk ()
 
 transactionWritingIn ( $serverName, $domainId, float $startTime)
 
 transactionWritingOut (IDatabase $db, $oldId)
 
 trxCheckBeforeClose (IDatabaseForOwner $db, $fname)
 
 trxLevel ()
 
 trxStatus ()
 
 trxTimestamp ()
 
 turnOnAutomatic ()
 
 updateTrxWriteQueryReport ( $queryVerb, $runtime, $affected, $fname)
 Update the estimated run-time of a query, not counting large row lock times.
 
 writesOrCallbacksPending ()
 
 writesPending ()
 

Public Attributes

const STATUS_SESS_ERROR = 1
 Session is in a error state requiring a reset.
 
const STATUS_SESS_OK = 2
 Session is in a normal state.
 
const STATUS_TRX_ERROR = 1
 Transaction is in a error state requiring a full or savepoint rollback.
 
const STATUS_TRX_NONE = 3
 No transaction is active.
 
const STATUS_TRX_OK = 2
 Transaction is active and in a normal state.
 

Detailed Description

Access: internal
This class should not be used outside of Database

Definition at line 32 of file TransactionManager.php.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\Rdbms\TransactionManager::__construct ( ?LoggerInterface $logger = null,
$profiler = null )

Definition at line 121 of file TransactionManager.php.

Member Function Documentation

◆ addPostCommitOrIdleCallback()

Wikimedia\Rdbms\TransactionManager::addPostCommitOrIdleCallback ( callable $callback,
$fname )

Definition at line 590 of file TransactionManager.php.

◆ addPreCommitOrIdleCallback()

Wikimedia\Rdbms\TransactionManager::addPreCommitOrIdleCallback ( callable $callback,
$fname )
final

Definition at line 598 of file TransactionManager.php.

◆ addToAtomicLevels()

Wikimedia\Rdbms\TransactionManager::addToAtomicLevels ( $fname,
AtomicSectionIdentifier $sectionId,
$savepointId )

Definition at line 372 of file TransactionManager.php.

◆ assertSessionStatus()

Wikimedia\Rdbms\TransactionManager::assertSessionStatus ( IDatabase $db,
$fname )

Definition at line 192 of file TransactionManager.php.

◆ assertTransactionStatus()

Wikimedia\Rdbms\TransactionManager::assertTransactionStatus ( IDatabase $db,
$deprecationLogger,
$fname )

Definition at line 174 of file TransactionManager.php.

◆ cancelAtomic()

Wikimedia\Rdbms\TransactionManager::cancelAtomic ( $pos)

Definition at line 474 of file TransactionManager.php.

◆ clearEndCallbacks()

Wikimedia\Rdbms\TransactionManager::clearEndCallbacks ( )

Definition at line 743 of file TransactionManager.php.

◆ clearPreEndCallbacks()

Wikimedia\Rdbms\TransactionManager::clearPreEndCallbacks ( )

Definition at line 738 of file TransactionManager.php.

◆ clearSessionError()

Wikimedia\Rdbms\TransactionManager::clearSessionError ( )

Unflag the session as needing a reset due to an error.

Definition at line 237 of file TransactionManager.php.

◆ consumeEndCallbacks()

Wikimedia\Rdbms\TransactionManager::consumeEndCallbacks ( )

Definition at line 698 of file TransactionManager.php.

◆ countPostCommitOrIdleCallbacks()

Wikimedia\Rdbms\TransactionManager::countPostCommitOrIdleCallbacks ( )

Definition at line 798 of file TransactionManager.php.

◆ currentAtomicSectionId()

Wikimedia\Rdbms\TransactionManager::currentAtomicSectionId ( )
Returns
AtomicSectionIdentifier|null ID of the topmost atomic section level

Definition at line 362 of file TransactionManager.php.

◆ explicitTrxActive()

Wikimedia\Rdbms\TransactionManager::explicitTrxActive ( )

Definition at line 323 of file TransactionManager.php.

◆ getPositionFromSectionId()

Wikimedia\Rdbms\TransactionManager::getPositionFromSectionId ( ?AtomicSectionIdentifier $sectionId = null)

Definition at line 458 of file TransactionManager.php.

◆ getRecurringCallbacks()

Wikimedia\Rdbms\TransactionManager::getRecurringCallbacks ( )

Definition at line 794 of file TransactionManager.php.

◆ getTrxId()

Wikimedia\Rdbms\TransactionManager::getTrxId ( )

Get the application-side transaction identifier instance.

Returns
?TransactionIdentifier Token for the active transaction; null if there isn't one

Definition at line 135 of file TransactionManager.php.

◆ isEndCallbacksSuppressed()

Wikimedia\Rdbms\TransactionManager::isEndCallbacksSuppressed ( )

Definition at line 790 of file TransactionManager.php.

◆ modifyCallbacksForCancel()

Wikimedia\Rdbms\TransactionManager::modifyCallbacksForCancel ( array $excisedSectionsId,
?AtomicSectionIdentifier $newSectionId = null )

Update callbacks that were owned by cancelled atomic sections.

Callbacks for "on commit" should never be run if they're owned by a section that won't be committed.

Callbacks for "on resolution" need to reflect that the section was rolled back, even if the transaction as a whole commits successfully.

Callbacks for "on section cancel" should already have been consumed, but errors during the cancellation itself can prevent that while still destroying the section. Hoist any such callbacks to the new top section, which we assume will itself have to be cancelled or rolled back to resolve the error.

Parameters
AtomicSectionIdentifier[]$excisedSectionsIdCancelled section IDs
AtomicSectionIdentifier | null$newSectionIdNew top section ID
Exceptions
UnexpectedValueException

Definition at line 668 of file TransactionManager.php.

◆ nextSavePointId()

Wikimedia\Rdbms\TransactionManager::nextSavePointId ( IDatabase $db,
$fname )

Definition at line 524 of file TransactionManager.php.

◆ onBegin()

Wikimedia\Rdbms\TransactionManager::onBegin ( IDatabase $db,
$fname )

Definition at line 378 of file TransactionManager.php.

◆ onBeginInCriticalSection()

Wikimedia\Rdbms\TransactionManager::onBeginInCriticalSection ( $mode,
$fname,
$rtt )
Parameters
string$modeOne of IDatabase::TRANSACTION_* values
string$fnamemethod name
float$rttTrivial query round-trip-delay

Definition at line 807 of file TransactionManager.php.

◆ onCancelAtomicBeforeCriticalSection()

Wikimedia\Rdbms\TransactionManager::onCancelAtomicBeforeCriticalSection ( IDatabase $db,
$fname )

Definition at line 353 of file TransactionManager.php.

◆ onCommit()

Wikimedia\Rdbms\TransactionManager::onCommit ( IDatabase $db,
$fname,
$flush )
Parameters
IDatabase$db
string$fname
string$flushone of IDatabase::FLUSHING_* values
Returns
bool false if the commit should go aborted, true otherwise.

Definition at line 401 of file TransactionManager.php.

◆ onCommitInCriticalSection()

Wikimedia\Rdbms\TransactionManager::onCommitInCriticalSection ( IDatabase $db)

Definition at line 836 of file TransactionManager.php.

◆ onDestruct()

Wikimedia\Rdbms\TransactionManager::onDestruct ( )

Definition at line 543 of file TransactionManager.php.

◆ onEndAtomic()

Wikimedia\Rdbms\TransactionManager::onEndAtomic ( IDatabase $db,
$fname )

Definition at line 439 of file TransactionManager.php.

◆ onEndAtomicInCriticalSection()

Wikimedia\Rdbms\TransactionManager::onEndAtomicInCriticalSection ( $sectionId)

Definition at line 855 of file TransactionManager.php.

◆ onFlushSnapshot()

Wikimedia\Rdbms\TransactionManager::onFlushSnapshot ( IDatabase $db,
$fname,
$flush,
$trxRoundFname )

Definition at line 864 of file TransactionManager.php.

◆ onGetScopedLockAndFlush()

Wikimedia\Rdbms\TransactionManager::onGetScopedLockAndFlush ( IDatabase $db,
$fname )

Definition at line 897 of file TransactionManager.php.

◆ onRollbackInCriticalSection()

Wikimedia\Rdbms\TransactionManager::onRollbackInCriticalSection ( IDatabase $db)

Definition at line 828 of file TransactionManager.php.

◆ onSessionLoss()

Wikimedia\Rdbms\TransactionManager::onSessionLoss ( IDatabase $db)

Definition at line 849 of file TransactionManager.php.

◆ onTransactionResolution()

Wikimedia\Rdbms\TransactionManager::onTransactionResolution ( IDatabase $db,
callable $callback,
$fname )

Definition at line 583 of file TransactionManager.php.

◆ pendingPreCommitCallbackCallers()

Wikimedia\Rdbms\TransactionManager::pendingPreCommitCallbackCallers ( )

List the methods that have precommit callbacks for the current transaction.

Returns
string[]

Definition at line 781 of file TransactionManager.php.

◆ pendingWriteAndCallbackCallers()

Wikimedia\Rdbms\TransactionManager::pendingWriteAndCallbackCallers ( )

List the methods that have write queries or callbacks for the current transaction.

Returns
string[]

Definition at line 761 of file TransactionManager.php.

◆ pendingWriteCallers()

Wikimedia\Rdbms\TransactionManager::pendingWriteCallers ( )

Definition at line 255 of file TransactionManager.php.

◆ pendingWriteQueryDuration()

Wikimedia\Rdbms\TransactionManager::pendingWriteQueryDuration ( $type = IDatabase::ESTIMATE_TOTAL)

Definition at line 295 of file TransactionManager.php.

◆ popAtomicLevel()

Wikimedia\Rdbms\TransactionManager::popAtomicLevel ( )
Returns
bool Whether no levels remain and transaction was started by a popped level

Definition at line 510 of file TransactionManager.php.

◆ reassignCallbacksForSection()

Wikimedia\Rdbms\TransactionManager::reassignCallbacksForSection ( AtomicSectionIdentifier $old,
AtomicSectionIdentifier $new )

Hoist callback ownership for callbacks in a section to a parent section.

All callbacks should have an owner that is present in trxAtomicLevels.

Parameters
AtomicSectionIdentifier$old
AtomicSectionIdentifier$new

Definition at line 628 of file TransactionManager.php.

◆ recordQueryCompletion()

Wikimedia\Rdbms\TransactionManager::recordQueryCompletion ( $sql,
$startTime,
$isPermWrite,
$rowCount,
$serverName )

Definition at line 572 of file TransactionManager.php.

◆ resetTrxAtomicLevels()

Wikimedia\Rdbms\TransactionManager::resetTrxAtomicLevels ( )

Definition at line 318 of file TransactionManager.php.

◆ runOnTransactionPreCommitCallbacks()

Wikimedia\Rdbms\TransactionManager::runOnTransactionPreCommitCallbacks ( IDatabase $db)

Consume and run any "on transaction pre-commit" callbacks.

Parameters
IDatabase$db
Returns
int Number of callbacks attempted
Exceptions
ThrowableAny exception thrown by a callback

Definition at line 716 of file TransactionManager.php.

◆ sessionStatus()

Wikimedia\Rdbms\TransactionManager::sessionStatus ( )

Get the status of the current session (ephemeral server-side state tied to the connection)

Returns
int One of the STATUS_SESSION_* class constants

Definition at line 222 of file TransactionManager.php.

◆ setAutomaticAtomic()

Wikimedia\Rdbms\TransactionManager::setAutomaticAtomic ( $value)

Definition at line 516 of file TransactionManager.php.

◆ setSessionError()

Wikimedia\Rdbms\TransactionManager::setSessionError ( Throwable $sessionError)

Flag the session as needing a reset due to an error, if not already flagged.

Definition at line 230 of file TransactionManager.php.

◆ setTransactionError()

Wikimedia\Rdbms\TransactionManager::setTransactionError ( Throwable $trxError)

Mark the transaction as requiring rollback (STATUS_TRX_ERROR) due to an error.

Definition at line 206 of file TransactionManager.php.

◆ setTransactionListener()

Wikimedia\Rdbms\TransactionManager::setTransactionListener ( $name,
?callable $callback = null )

Definition at line 606 of file TransactionManager.php.

◆ setTrxEndCallbackSuppression()

Wikimedia\Rdbms\TransactionManager::setTrxEndCallbackSuppression ( bool $suppress)

Whether to disable running of post-COMMIT/ROLLBACK callbacks.

Parameters
bool$suppress

Definition at line 618 of file TransactionManager.php.

◆ setTrxStatusIgnoredCause()

Wikimedia\Rdbms\TransactionManager::setTrxStatusIgnoredCause ( ?array $trxStatusIgnoredCause)

Definition at line 213 of file TransactionManager.php.

◆ setTrxStatusToNone()

Wikimedia\Rdbms\TransactionManager::setTrxStatusToNone ( )

Definition at line 168 of file TransactionManager.php.

◆ setTrxStatusToOk()

Wikimedia\Rdbms\TransactionManager::setTrxStatusToOk ( )

Definition at line 162 of file TransactionManager.php.

◆ transactionWritingIn()

Wikimedia\Rdbms\TransactionManager::transactionWritingIn ( $serverName,
$domainId,
float $startTime )

Definition at line 549 of file TransactionManager.php.

◆ transactionWritingOut()

Wikimedia\Rdbms\TransactionManager::transactionWritingOut ( IDatabase $db,
$oldId )

◆ trxCheckBeforeClose()

Wikimedia\Rdbms\TransactionManager::trxCheckBeforeClose ( IDatabaseForOwner $db,
$fname )

◆ trxLevel()

Wikimedia\Rdbms\TransactionManager::trxLevel ( )

Definition at line 126 of file TransactionManager.php.

◆ trxStatus()

Wikimedia\Rdbms\TransactionManager::trxStatus ( )
Returns
int One of the STATUS_TRX_* class constants

Definition at line 158 of file TransactionManager.php.

◆ trxTimestamp()

Wikimedia\Rdbms\TransactionManager::trxTimestamp ( )

Definition at line 151 of file TransactionManager.php.

◆ turnOnAutomatic()

Wikimedia\Rdbms\TransactionManager::turnOnAutomatic ( )

Definition at line 520 of file TransactionManager.php.

◆ updateTrxWriteQueryReport()

Wikimedia\Rdbms\TransactionManager::updateTrxWriteQueryReport ( $queryVerb,
$runtime,
$affected,
$fname )

Update the estimated run-time of a query, not counting large row lock times.

LoadBalancer can be set to rollback transactions that will create huge replication lag. It bases this estimate off of pendingWriteQueryDuration(). Certain simple queries, like inserting a row can take a long time due to row locking. This method uses some simple heuristics to discount those cases.

Parameters
string$queryVerbaction in the write query
float$runtimeTotal runtime, including RTT
int$affectedAffected row count
string$fnamemethod name invoking the action

Definition at line 272 of file TransactionManager.php.

◆ writesOrCallbacksPending()

Wikimedia\Rdbms\TransactionManager::writesOrCallbacksPending ( )

Definition at line 747 of file TransactionManager.php.

◆ writesPending()

Wikimedia\Rdbms\TransactionManager::writesPending ( )

Definition at line 539 of file TransactionManager.php.

Member Data Documentation

◆ STATUS_SESS_ERROR

const Wikimedia\Rdbms\TransactionManager::STATUS_SESS_ERROR = 1

Session is in a error state requiring a reset.

Definition at line 41 of file TransactionManager.php.

◆ STATUS_SESS_OK

const Wikimedia\Rdbms\TransactionManager::STATUS_SESS_OK = 2

Session is in a normal state.

Definition at line 43 of file TransactionManager.php.

◆ STATUS_TRX_ERROR

const Wikimedia\Rdbms\TransactionManager::STATUS_TRX_ERROR = 1

Transaction is in a error state requiring a full or savepoint rollback.

Definition at line 34 of file TransactionManager.php.

◆ STATUS_TRX_NONE

const Wikimedia\Rdbms\TransactionManager::STATUS_TRX_NONE = 3

No transaction is active.

Definition at line 38 of file TransactionManager.php.

◆ STATUS_TRX_OK

const Wikimedia\Rdbms\TransactionManager::STATUS_TRX_OK = 2

Transaction is active and in a normal state.

Definition at line 36 of file TransactionManager.php.


The documentation for this class was generated from the following file: