Page Menu
Home
In-Portal Phabricator
Search
Configure Global Search
Log In
Files
F727146
D369.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jan 6, 7:45 AM
Size
1 KB
Mime Type
text/x-diff
Expires
Tue, Jan 7, 7:45 AM (3 d, 3 h ago)
Engine
blob
Format
Raw Data
Handle
536977
Attached To
D369: INP-1771 - Change slave lag detection code to use "SHOW SLAVE STATUS" query
D369.diff
View Options
Index: branches/5.2.x/core/kernel/db/db_connection.php
===================================================================
--- branches/5.2.x/core/kernel/db/db_connection.php
+++ branches/5.2.x/core/kernel/db/db_connection.php
@@ -888,28 +888,25 @@
*/
public function getSlaveLag()
{
- // don't use kDBConnection::Query method, since it will create an array of all server processes
- $processes = $this->GetIterator('SHOW PROCESSLIST');
-
- $skip_states = Array (
- 'Waiting for master to send event',
- 'Connecting to master',
- 'Queueing master event to the relay log',
- 'Waiting for master update',
- 'Requesting binlog dump',
- );
-
- // find slave SQL thread
- foreach ($processes as $process) {
- if ( $process['User'] == 'system user' && !in_array($process['State'], $skip_states) ) {
- // this is it, return the time (except -ve)
+ try {
+ $rows = $this->Query('SHOW SLAVE STATUS');
+ }
+ catch ( RuntimeException $e ) {
+ // When "SUPER" or "REPLICATION CLIENT" permission is missing.
+ return 0;
+ }
- return $process['Time'] > 0x7fffffff ? false : $process['Time'];
- }
+ // On the silenced error OR database server isn't configured for a replication.
+ if ( $rows === false || count($rows) !== 1 ) {
+ return 0;
}
- return false;
+ $row = reset($rows);
+
+ // 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;
}
+
}
Event Timeline
Log In to Comment