* This is more consistent with the name flushReplicaSnapshots().
* Also add it to IDatabase, which defines the modern OLTP methods
of DatabaseBase. This methods is useful for callers that get
locks or wait for a replica DB to catch up before querying it.
Change-Id: Ia31e480bb9ccf461bf05ede4278920918eec4f16
return $this->__call( __FUNCTION__, func_get_args() );
}
+ public function flushSnapshot( $fname = __METHOD__ ) {
+ return $this->__call( __FUNCTION__, func_get_args() );
+ }
+
public function listTables( $prefix = null, $fname = __METHOD__ ) {
return $this->__call( __FUNCTION__, func_get_args() );
}
}
}
- public function clearSnapshot( $fname = __METHOD__ ) {
+ public function flushSnapshot( $fname = __METHOD__ ) {
if ( $this->writesOrCallbacksPending() || $this->explicitTrxActive() ) {
// This only flushes transactions to clear snapshots, not to write data
throw new DBUnexpectedError(
* will cause a warning, unless the current transaction was started
* automatically because of the DBO_TRX flag.
*
- * @param string $fname
+ * @param string $fname Calling function name
* @param string $mode A situationally valid IDatabase::TRANSACTION_* constant [optional]
* @throws DBError
*/
* throwing an Exception is preferrable, using a pre-installed error handler to trigger
* rollback (in any case, failure to issue COMMIT will cause rollback server-side).
*
- * @param string $fname
+ * @param string $fname Calling function name
* @param string $flush Flush flag, set to a situationally valid IDatabase::FLUSHING_*
* constant to disable warnings about calling rollback when no transaction is in
* progress. This will silently break any ongoing explicit transaction. Only set the
*/
public function rollback( $fname = __METHOD__, $flush = '' );
+ /**
+ * Commit any transaction but error out if writes or callbacks are pending
+ *
+ * This is intended for clearing out REPEATABLE-READ snapshots so that callers can
+ * see a new point-in-time of the database. This is useful when one of many transaction
+ * rounds finished and significant time will pass in the script's lifetime. It is also
+ * useful to call on a replica DB after waiting on replication to catch up to the master.
+ *
+ * @param string $fname Calling function name
+ * @throws DBUnexpectedError
+ * @since 1.28
+ */
+ public function flushSnapshot( $fname = __METHOD__ );
+
/**
* List all tables on the database
*
function ( DatabaseBase $conn ) use ( $fname, &$failures ) {
$conn->setTrxEndCallbackSuppression( true );
try {
- $conn->clearSnapshot( $fname );
+ $conn->flushSnapshot( $fname );
} catch ( DBError $e ) {
MWExceptionHandler::logException( $e );
$failures[] = "{$conn->getServer()}: {$e->getMessage()}";
if ( $conn->writesOrCallbacksPending() ) {
$conn->commit( $fname, $conn::FLUSHING_ALL_PEERS );
} elseif ( $restore ) {
- $conn->clearSnapshot( $fname );
+ $conn->flushSnapshot( $fname );
}
} catch ( DBError $e ) {
MWExceptionHandler::logException( $e );
*/
public function flushReplicaSnapshots( $fname = __METHOD__ ) {
$this->forEachOpenReplicaConnection( function ( DatabaseBase $conn ) {
- $conn->clearSnapshot( __METHOD__ );
+ $conn->flushSnapshot( __METHOD__ );
} );
}
}
/**
- * @covers DatabaseBase::clearSnapshot()
+ * @covers DatabaseBase::flushSnapshot()
*/
- public function testClearSnapshot() {
+ public function testFlushSnapshot() {
$db = $this->db;
- $db->clearSnapshot( __METHOD__ ); // ok
- $db->clearSnapshot( __METHOD__ ); // ok
+ $db->flushSnapshot( __METHOD__ ); // ok
+ $db->flushSnapshot( __METHOD__ ); // ok
$db->setFlag( DBO_TRX, $db::REMEMBER_PRIOR );
$db->query( 'SELECT 1', __METHOD__ );
$this->assertTrue( (bool)$db->trxLevel(), "Transaction started." );
- $db->clearSnapshot( __METHOD__ ); // ok
+ $db->flushSnapshot( __METHOD__ ); // ok
$db->restoreFlags( $db::RESTORE_PRIOR );
$this->assertFalse( (bool)$db->trxLevel(), "Transaction cleared." );