2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*/
|
2004-01-25 13:27:53 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Depends on the database object
|
|
|
|
|
*/
|
2004-08-22 17:24:50 +00:00
|
|
|
require_once( 'Database.php' );
|
2004-07-10 03:09:26 +00:00
|
|
|
|
2004-06-15 15:00:54 +00:00
|
|
|
# Valid database indexes
|
|
|
|
|
# Operation-based indexes
|
2004-08-22 17:24:50 +00:00
|
|
|
define( 'DB_SLAVE', -1 ); # Read from the slave (or only server)
|
|
|
|
|
define( 'DB_MASTER', -2 ); # Write to master (or only server)
|
|
|
|
|
define( 'DB_LAST', -3 ); # Whatever database was used last
|
2004-06-15 15:00:54 +00:00
|
|
|
|
2004-07-18 08:48:43 +00:00
|
|
|
# Obsolete aliases
|
2004-08-22 17:24:50 +00:00
|
|
|
define( 'DB_READ', -1 );
|
|
|
|
|
define( 'DB_WRITE', -2 );
|
2004-07-18 08:48:43 +00:00
|
|
|
|
2004-06-15 15:00:54 +00:00
|
|
|
# Task-based indexes
|
|
|
|
|
# ***NOT USED YET, EXPERIMENTAL***
|
|
|
|
|
# These may be defined in $wgDBservers. If they aren't, the default reader or writer will be used
|
|
|
|
|
# Even numbers are always readers, odd numbers are writers
|
2004-08-22 17:24:50 +00:00
|
|
|
define( 'DB_TASK_FIRST', 1000 ); # First in list
|
|
|
|
|
define( 'DB_SEARCH_R', 1000 ); # Search read
|
|
|
|
|
define( 'DB_SEARCH_W', 1001 ); # Search write
|
|
|
|
|
define( 'DB_ASKSQL_R', 1002 ); # Special:Asksql read
|
|
|
|
|
define( 'DB_WATCHLIST_R', 1004 ); # Watchlist read
|
|
|
|
|
define( 'DB_TASK_LAST', 1004) ; # Last in list
|
2004-06-15 15:00:54 +00:00
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
define( 'MASTER_WAIT_TIMEOUT', 15 ); # Time to wait for a slave to synchronise
|
2004-07-18 08:48:43 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Database load balancing object
|
|
|
|
|
* @todo document
|
|
|
|
|
*/
|
2004-01-25 13:27:53 +00:00
|
|
|
class LoadBalancer {
|
|
|
|
|
/* private */ var $mServers, $mConnections, $mLoads;
|
2004-07-10 03:09:26 +00:00
|
|
|
/* private */ var $mFailFunction;
|
2004-07-24 07:24:04 +00:00
|
|
|
/* private */ var $mForce, $mReadIndex, $mLastIndex;
|
2004-07-18 08:48:43 +00:00
|
|
|
/* private */ var $mWaitForFile, $mWaitForPos;
|
2004-01-25 13:27:53 +00:00
|
|
|
|
|
|
|
|
function LoadBalancer()
|
|
|
|
|
{
|
|
|
|
|
$this->mServers = array();
|
|
|
|
|
$this->mConnections = array();
|
|
|
|
|
$this->mFailFunction = false;
|
|
|
|
|
$this->mReadIndex = -1;
|
|
|
|
|
$this->mForce = -1;
|
2004-07-24 07:24:04 +00:00
|
|
|
$this->mLastIndex = -1;
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
function newFromParams( $servers, $failFunction = false )
|
2004-01-25 13:27:53 +00:00
|
|
|
{
|
|
|
|
|
$lb = new LoadBalancer;
|
2004-07-10 03:09:26 +00:00
|
|
|
$lb->initialise( $servers, $failFunction = false );
|
2004-01-25 13:27:53 +00:00
|
|
|
return $lb;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-10 03:09:26 +00:00
|
|
|
function initialise( $servers, $failFunction = false )
|
2004-01-25 13:27:53 +00:00
|
|
|
{
|
|
|
|
|
$this->mServers = $servers;
|
|
|
|
|
$this->mFailFunction = $failFunction;
|
|
|
|
|
$this->mReadIndex = -1;
|
|
|
|
|
$this->mWriteIndex = -1;
|
|
|
|
|
$this->mForce = -1;
|
|
|
|
|
$this->mConnections = array();
|
2004-07-24 07:24:04 +00:00
|
|
|
$this->mLastIndex = 1;
|
2004-07-10 03:09:26 +00:00
|
|
|
$this->mLoads = array();
|
2004-07-18 08:48:43 +00:00
|
|
|
$this->mWaitForFile = false;
|
|
|
|
|
$this->mWaitForPos = false;
|
2004-07-10 03:09:26 +00:00
|
|
|
|
|
|
|
|
foreach( $servers as $i => $server ) {
|
|
|
|
|
$this->mLoads[$i] = $server['load'];
|
|
|
|
|
}
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Given an array of non-normalised probabilities, this function will select
|
|
|
|
|
* an element and return the appropriate key
|
|
|
|
|
*/
|
2004-01-25 13:27:53 +00:00
|
|
|
function pickRandom( $weights )
|
|
|
|
|
{
|
|
|
|
|
if ( !is_array( $weights ) || count( $weights ) == 0 ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$sum = 0;
|
|
|
|
|
foreach ( $weights as $w ) {
|
|
|
|
|
$sum += $w;
|
|
|
|
|
}
|
2004-06-22 08:54:26 +00:00
|
|
|
$max = mt_getrandmax();
|
|
|
|
|
$rand = mt_rand(0, $max) / $max * $sum;
|
2004-01-25 13:27:53 +00:00
|
|
|
|
|
|
|
|
$sum = 0;
|
|
|
|
|
foreach ( $weights as $i => $w ) {
|
|
|
|
|
$sum += $w;
|
|
|
|
|
if ( $sum >= $rand ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return $i;
|
|
|
|
|
}
|
|
|
|
|
|
2004-07-24 07:24:04 +00:00
|
|
|
function getReaderIndex()
|
2004-01-25 13:27:53 +00:00
|
|
|
{
|
2004-08-07 03:53:19 +00:00
|
|
|
$fname = 'LoadBalancer::getReaderIndex';
|
|
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
2004-07-24 07:24:04 +00:00
|
|
|
$i = false;
|
2004-01-25 13:27:53 +00:00
|
|
|
if ( $this->mForce >= 0 ) {
|
2004-07-24 07:24:04 +00:00
|
|
|
$i = $this->mForce;
|
2004-01-25 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
|
if ( $this->mReadIndex >= 0 ) {
|
2004-07-24 07:24:04 +00:00
|
|
|
$i = $this->mReadIndex;
|
2004-01-25 13:27:53 +00:00
|
|
|
} else {
|
|
|
|
|
# $loads is $this->mLoads except with elements knocked out if they
|
|
|
|
|
# don't work
|
|
|
|
|
$loads = $this->mLoads;
|
|
|
|
|
do {
|
2004-06-22 08:54:26 +00:00
|
|
|
$i = $this->pickRandom( $loads );
|
2004-01-25 13:27:53 +00:00
|
|
|
if ( $i !== false ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
wfDebug( "Using reader #$i: {$this->mServers[$i]['host']}\n" );
|
2004-06-22 08:54:26 +00:00
|
|
|
|
2004-08-07 03:53:19 +00:00
|
|
|
$this->openConnection( $i );
|
2004-07-24 07:24:04 +00:00
|
|
|
|
2004-07-24 08:33:37 +00:00
|
|
|
if ( !$this->isOpen( $i ) ) {
|
2004-01-25 13:27:53 +00:00
|
|
|
unset( $loads[$i] );
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-07-24 08:33:37 +00:00
|
|
|
} while ( $i !== false && !$this->isOpen( $i ) );
|
|
|
|
|
|
|
|
|
|
if ( $this->isOpen( $i ) ) {
|
2004-01-25 13:27:53 +00:00
|
|
|
$this->mReadIndex = $i;
|
2004-07-24 07:24:04 +00:00
|
|
|
} else {
|
|
|
|
|
$i = false;
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-08-07 03:53:19 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-07-24 07:24:04 +00:00
|
|
|
return $i;
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
2004-06-15 15:00:54 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Set the master wait position
|
|
|
|
|
* If a DB_SLAVE connection has been opened already, waits
|
|
|
|
|
* Otherwise sets a variable telling it to wait if such a connection is opened
|
|
|
|
|
*/
|
2004-07-18 08:48:43 +00:00
|
|
|
function waitFor( $file, $pos ) {
|
2004-08-22 17:24:50 +00:00
|
|
|
$fname = 'LoadBalancer::waitFor';
|
2004-08-07 03:53:19 +00:00
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
2004-07-23 12:37:55 +00:00
|
|
|
wfDebug( "User master pos: $file $pos\n" );
|
2004-07-18 08:48:43 +00:00
|
|
|
$this->mWaitForFile = false;
|
|
|
|
|
$this->mWaitForPos = false;
|
|
|
|
|
|
2004-08-07 03:53:19 +00:00
|
|
|
if ( count( $this->mServers ) > 1 ) {
|
|
|
|
|
$this->mWaitForFile = $file;
|
|
|
|
|
$this->mWaitForPos = $pos;
|
2004-07-18 08:48:43 +00:00
|
|
|
|
2004-08-07 03:53:19 +00:00
|
|
|
if ( $this->mReadIndex > 0 ) {
|
|
|
|
|
if ( !$this->doWait( $this->mReadIndex ) ) {
|
|
|
|
|
# Use master instead
|
|
|
|
|
$this->mReadIndex = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
wfProfileOut( $fname );
|
2004-07-18 08:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Wait for a given slave to catch up to the master pos stored in $this
|
|
|
|
|
*/
|
2004-07-18 08:48:43 +00:00
|
|
|
function doWait( $index ) {
|
|
|
|
|
global $wgMemc;
|
|
|
|
|
|
2004-08-07 03:53:19 +00:00
|
|
|
$retVal = false;
|
|
|
|
|
|
2004-08-22 17:24:50 +00:00
|
|
|
$key = 'masterpos:' . $index;
|
2004-07-18 08:48:43 +00:00
|
|
|
$memcPos = $wgMemc->get( $key );
|
|
|
|
|
if ( $memcPos ) {
|
|
|
|
|
list( $file, $pos ) = explode( ' ', $memcPos );
|
|
|
|
|
# If the saved position is later than the requested position, return now
|
|
|
|
|
if ( $file == $this->mWaitForFile && $this->mWaitForPos <= $pos ) {
|
2004-08-07 03:53:19 +00:00
|
|
|
$retVal = true;
|
2004-07-18 08:48:43 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-08-07 03:53:19 +00:00
|
|
|
if ( !$retVal && $this->isOpen( $index ) ) {
|
|
|
|
|
$conn =& $this->mConnections( $index );
|
|
|
|
|
wfDebug( "Waiting for slave #$index to catch up...\n" );
|
|
|
|
|
$result = $conn->masterPosWait( $this->mWaitForFile, $this->mWaitForPos, MASTER_WAIT_TIMEOUT );
|
2004-07-23 12:37:55 +00:00
|
|
|
|
2004-08-07 03:53:19 +00:00
|
|
|
if ( $result == -1 || is_null( $result ) ) {
|
|
|
|
|
# Timed out waiting for slave, use master instead
|
|
|
|
|
wfDebug( "Timed out waiting for slave #$index pos {$this->mWaitForFile} {$this->mWaitForPos}\n" );
|
|
|
|
|
$retVal = false;
|
|
|
|
|
} else {
|
|
|
|
|
$retVal = true;
|
|
|
|
|
wfDebug( "Done\n" );
|
|
|
|
|
}
|
2004-07-23 12:37:55 +00:00
|
|
|
}
|
2004-07-24 07:24:04 +00:00
|
|
|
return $retVal;
|
2004-07-18 08:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Get a connection by index
|
|
|
|
|
*/
|
2004-08-08 01:07:56 +00:00
|
|
|
function &getConnection( $i, $fail = true )
|
2004-01-25 13:27:53 +00:00
|
|
|
{
|
2004-08-22 17:24:50 +00:00
|
|
|
$fname = 'LoadBalancer::getConnection';
|
2004-08-07 03:53:19 +00:00
|
|
|
wfProfileIn( $fname );
|
2004-06-15 15:00:54 +00:00
|
|
|
/*
|
|
|
|
|
# Task-based index
|
|
|
|
|
if ( $i >= DB_TASK_FIRST && $i < DB_TASK_LAST ) {
|
|
|
|
|
if ( $i % 2 ) {
|
|
|
|
|
# Odd index use writer
|
2004-07-18 08:48:43 +00:00
|
|
|
$i = DB_MASTER;
|
2004-06-15 15:00:54 +00:00
|
|
|
} else {
|
|
|
|
|
# Even index use reader
|
2004-07-18 08:48:43 +00:00
|
|
|
$i = DB_SLAVE;
|
2004-06-15 15:00:54 +00:00
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
# Operation-based index
|
2004-07-24 07:24:04 +00:00
|
|
|
if ( $i == DB_SLAVE ) {
|
|
|
|
|
$i = $this->getReaderIndex();
|
2004-07-18 08:48:43 +00:00
|
|
|
} elseif ( $i == DB_MASTER ) {
|
2004-07-24 07:24:04 +00:00
|
|
|
$i = $this->getWriterIndex();
|
2004-06-15 15:00:54 +00:00
|
|
|
} elseif ( $i == DB_LAST ) {
|
2004-07-24 07:24:04 +00:00
|
|
|
# Just use $this->mLastIndex, which should already be set
|
|
|
|
|
$i = $this->mLastIndex;
|
|
|
|
|
if ( $i === -1 ) {
|
2004-06-15 15:00:54 +00:00
|
|
|
# Oh dear, not set, best to use the writer for safety
|
2004-08-07 03:53:19 +00:00
|
|
|
wfDebug( "Warning: DB_LAST used when there was no previous index\n" );
|
2004-07-24 07:24:04 +00:00
|
|
|
$i = $this->getWriterIndex();
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
2004-08-07 03:53:19 +00:00
|
|
|
}
|
2004-07-24 07:24:04 +00:00
|
|
|
# Now we have an explicit index into the servers array
|
2004-08-07 03:53:19 +00:00
|
|
|
$this->openConnection( $i, $fail );
|
|
|
|
|
wfProfileOut( $fname );
|
|
|
|
|
return $this->mConnections[$i];
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Open a connection to the server given by the specified index
|
|
|
|
|
* Index must be an actual index into the array
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function openConnection( $i, $fail = false ) {
|
2004-08-07 03:53:19 +00:00
|
|
|
$fname = 'LoadBalancer::openConnection';
|
|
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
|
2004-07-24 07:24:04 +00:00
|
|
|
if ( !$this->isOpen( $i ) ) {
|
2004-08-07 03:53:19 +00:00
|
|
|
$this->mConnections[$i] = $this->reallyOpenConnection( $this->mServers[$i] );
|
2004-07-24 07:24:04 +00:00
|
|
|
|
|
|
|
|
if ( $i != 0 && $this->mWaitForFile ) {
|
|
|
|
|
if ( !$this->doWait( $i ) ) {
|
|
|
|
|
# Error waiting for this slave, use master instead
|
|
|
|
|
$this->mReadIndex = 0;
|
|
|
|
|
$i = 0;
|
|
|
|
|
if ( !$this->isOpen( 0 ) ) {
|
2004-08-07 03:53:19 +00:00
|
|
|
$this->mConnections[0] = $this->reallyOpenConnection( $this->mServers[0] );
|
2004-07-24 07:24:04 +00:00
|
|
|
}
|
|
|
|
|
wfDebug( "Failed over to {$this->mConnections[0]->mServer}\n" );
|
2004-07-18 08:48:43 +00:00
|
|
|
}
|
2004-06-15 15:00:54 +00:00
|
|
|
}
|
2004-07-24 07:24:04 +00:00
|
|
|
}
|
|
|
|
|
if ( !$this->isOpen( $i ) ) {
|
|
|
|
|
wfDebug( "Failed to connect to database $i at {$this->mServers[$i]['host']}\n" );
|
|
|
|
|
if ( $fail ) {
|
|
|
|
|
$this->reportConnectionError( $this->mConnections[$i] );
|
2004-06-15 15:00:54 +00:00
|
|
|
}
|
2004-07-24 07:24:04 +00:00
|
|
|
$this->mConnections[$i] = false;
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
2004-07-24 07:24:04 +00:00
|
|
|
$this->mLastIndex = $i;
|
2004-08-07 03:53:19 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Test if the specified index represents an open connection
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function isOpen( $index ) {
|
2004-08-08 01:07:56 +00:00
|
|
|
if( !is_integer( $index ) ) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-07-24 08:33:37 +00:00
|
|
|
if ( array_key_exists( $index, $this->mConnections ) && is_object( $this->mConnections[$index] ) &&
|
|
|
|
|
$this->mConnections[$index]->isOpen() )
|
|
|
|
|
{
|
2004-07-24 07:24:04 +00:00
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Really opens a connection
|
|
|
|
|
* @private
|
|
|
|
|
*/
|
|
|
|
|
function reallyOpenConnection( &$server ) {
|
2004-07-10 03:09:26 +00:00
|
|
|
extract( $server );
|
|
|
|
|
# Get class for this database type
|
|
|
|
|
$class = 'Database' . ucfirst( $type );
|
|
|
|
|
if ( !class_exists( $class ) ) {
|
|
|
|
|
require_once( "$class.php" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# Create object
|
2004-07-24 07:24:04 +00:00
|
|
|
return new $class( $host, $user, $password, $dbname, 1, $flags );
|
2004-07-10 03:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
2004-01-25 13:27:53 +00:00
|
|
|
function reportConnectionError( &$conn )
|
|
|
|
|
{
|
2004-08-07 03:53:19 +00:00
|
|
|
$fname = 'LoadBalancer::reportConnectionError';
|
|
|
|
|
wfProfileIn( $fname );
|
|
|
|
|
# Prevent infinite recursion
|
|
|
|
|
|
|
|
|
|
static $reporting = false;
|
|
|
|
|
if ( !$reporting ) {
|
|
|
|
|
$reporting = true;
|
|
|
|
|
if ( !is_object( $conn ) ) {
|
|
|
|
|
$conn = new Database;
|
|
|
|
|
}
|
|
|
|
|
if ( $this->mFailFunction ) {
|
2004-08-08 01:07:56 +00:00
|
|
|
$conn->failFunction( $this->mFailFunction );
|
2004-08-07 03:53:19 +00:00
|
|
|
} else {
|
2004-08-22 17:24:50 +00:00
|
|
|
$conn->failFunction( 'wfEmergencyAbort' );
|
2004-08-07 03:53:19 +00:00
|
|
|
}
|
|
|
|
|
$conn->reportConnectionError();
|
|
|
|
|
$reporting = false;
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
2004-08-07 03:53:19 +00:00
|
|
|
wfProfileOut( $fname );
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
2004-07-24 07:24:04 +00:00
|
|
|
function getWriterIndex()
|
2004-01-25 13:27:53 +00:00
|
|
|
{
|
2004-07-24 07:24:04 +00:00
|
|
|
return 0;
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function force( $i )
|
|
|
|
|
{
|
|
|
|
|
$this->mForce = $i;
|
|
|
|
|
}
|
2004-06-15 15:00:54 +00:00
|
|
|
|
|
|
|
|
function haveIndex( $i )
|
|
|
|
|
{
|
|
|
|
|
return array_key_exists( $i, $this->mServers );
|
|
|
|
|
}
|
2004-07-18 08:48:43 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Get the number of defined servers (not the number of open connections)
|
|
|
|
|
*/
|
2004-07-18 08:48:43 +00:00
|
|
|
function getServerCount() {
|
|
|
|
|
return count( $this->mServers );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Save master pos to the session and to memcached, if the session exists
|
|
|
|
|
*/
|
2004-07-18 08:48:43 +00:00
|
|
|
function saveMasterPos() {
|
|
|
|
|
global $wgSessionStarted;
|
|
|
|
|
if ( $wgSessionStarted && count( $this->mServers ) > 1 ) {
|
|
|
|
|
# If this entire request was served from a slave without opening a connection to the
|
|
|
|
|
# master (however unlikely that may be), then we can fetch the position from the slave.
|
|
|
|
|
if ( empty( $this->mConnections[0] ) ) {
|
|
|
|
|
$conn =& $this->getConnection( DB_SLAVE );
|
|
|
|
|
list( $file, $pos ) = $conn->getSlavePos();
|
2004-07-23 12:37:55 +00:00
|
|
|
wfDebug( "Saving master pos fetched from slave: $file $pos\n" );
|
2004-07-18 08:48:43 +00:00
|
|
|
} else {
|
|
|
|
|
$conn =& $this->getConnection( 0 );
|
|
|
|
|
list( $file, $pos ) = $conn->getMasterPos();
|
2004-07-23 12:37:55 +00:00
|
|
|
wfDebug( "Saving master pos: $file $pos\n" );
|
2004-07-18 08:48:43 +00:00
|
|
|
}
|
|
|
|
|
if ( $file !== false ) {
|
|
|
|
|
$_SESSION['master_log_file'] = $file;
|
|
|
|
|
$_SESSION['master_pos'] = $pos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Loads the master pos from the session, waits for it if necessary
|
|
|
|
|
*/
|
2004-07-18 08:48:43 +00:00
|
|
|
function loadMasterPos() {
|
|
|
|
|
if ( isset( $_SESSION['master_log_file'] ) && isset( $_SESSION['master_pos'] ) ) {
|
|
|
|
|
$this->waitFor( $_SESSION['master_log_file'], $_SESSION['master_pos'] );
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-07-24 07:24:04 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Close all open connections
|
|
|
|
|
*/
|
2004-07-24 07:24:04 +00:00
|
|
|
function closeAll() {
|
|
|
|
|
foreach( $this->mConnections as $i => $conn ) {
|
|
|
|
|
if ( $this->isOpen( $i ) ) {
|
|
|
|
|
$conn->close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function commitAll() {
|
|
|
|
|
foreach( $this->mConnections as $i => $conn ) {
|
|
|
|
|
if ( $this->isOpen( $i ) ) {
|
|
|
|
|
$conn->immediateCommit();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2004-01-25 13:27:53 +00:00
|
|
|
}
|