Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/kernel/db/db_connection.php
Show First 20 Lines • Show All 882 Lines • ▼ Show 20 Line(s) | |||||
/** | /** | ||||
* Get slave replication lag. It will only work if the DB user has the PROCESS privilege. | * Get slave replication lag. It will only work if the DB user has the PROCESS privilege. | ||||
* | * | ||||
* @return int | * @return int | ||||
* @access public | * @access public | ||||
*/ | */ | ||||
public function getSlaveLag() | public function getSlaveLag() | ||||
{ | { | ||||
// don't use kDBConnection::Query method, since it will create an array of all server processes | try { | ||||
$processes = $this->GetIterator('SHOW PROCESSLIST'); | $rows = $this->Query('SHOW SLAVE STATUS'); | ||||
} | |||||
catch ( RuntimeException $e ) { | |||||
// When "SUPER" or "REPLICATION CLIENT" permission is missing. | |||||
return 0; | |||||
} | |||||
$skip_states = Array ( | // On the silenced error OR database server isn't configured for a replication. | ||||
'Waiting for master to send event', | if ( $rows === false || count($rows) !== 1 ) { | ||||
'Connecting to master', | return 0; | ||||
'Queueing master event to the relay log', | } | ||||
'Waiting for master update', | |||||
'Requesting binlog dump', | |||||
); | |||||
// find slave SQL thread | $row = reset($rows); | ||||
foreach ($processes as $process) { | |||||
if ( $process['User'] == 'system user' && !in_array($process['State'], $skip_states) ) { | |||||
// this is it, return the time (except -ve) | |||||
return $process['Time'] > 0x7fffffff ? false : $process['Time']; | // When slave is too busy catching up with a master we'll get a NULL/empty string here. | ||||
} | return is_numeric($row['Seconds_Behind_Master']) ? $row['Seconds_Behind_Master'] : false; | ||||
} | } | ||||
return false; | |||||
} | |||||
} | } | ||||
class kDBConnectionDebug extends kDBConnection { | class kDBConnectionDebug extends kDBConnection { | ||||
protected $_profileSQLs = false; | protected $_profileSQLs = false; | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 488 Lines • Show Last 20 Lines |