From 01040e4573077484f6ade320d349d7b11e77152e Mon Sep 17 00:00:00 2001 From: epriestley Date: Sun, 3 Jul 2016 14:13:06 -0700 Subject: [PATCH] Correctly disinguish between "0 seconds behind master" and "not replicating" Summary: Fixes T11159. We get two different values here (`NULL` and `0`) with different meanings. Test Plan: - Ran `STOP SLAVE;`. - Saw this: {F1710181} - Ran `START SLAVE;`. - Back to normal. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11159 Differential Revision: https://secure.phabricator.com/D16225 --- .../cluster/PhabricatorDatabaseRef.php | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/infrastructure/cluster/PhabricatorDatabaseRef.php b/src/infrastructure/cluster/PhabricatorDatabaseRef.php index f8ca7a79a8..02777fb7a7 100644 --- a/src/infrastructure/cluster/PhabricatorDatabaseRef.php +++ b/src/infrastructure/cluster/PhabricatorDatabaseRef.php @@ -12,6 +12,7 @@ final class PhabricatorDatabaseRef const REPLICATION_MASTER_REPLICA = 'master-replica'; const REPLICATION_REPLICA_NONE = 'replica-none'; const REPLICATION_SLOW = 'replica-slow'; + const REPLICATION_NOT_REPLICATING = 'not-replicating'; const KEY_REFS = 'cluster.db.refs'; const KEY_INDIVIDUAL = 'cluster.db.individual'; @@ -196,13 +197,18 @@ final class PhabricatorDatabaseRef self::REPLICATION_REPLICA_NONE => array( 'icon' => 'fa-download', 'color' => 'red', - 'label' => pht('Not Replicating'), + 'label' => pht('Not A Replica'), ), self::REPLICATION_SLOW => array( 'icon' => 'fa-hourglass', 'color' => 'red', 'label' => pht('Slow Replication'), ), + self::REPLICATION_NOT_REPLICATING => array( + 'icon' => 'fa-exclamation-triangle', + 'color' => 'red', + 'label' => pht('Not Replicating'), + ), ); } @@ -330,14 +336,19 @@ final class PhabricatorDatabaseRef } if ($is_replica) { - $latency = (int)idx($replica_status, 'Seconds_Behind_Master'); - $ref->setReplicaDelay($latency); - if ($latency > 30) { - $ref->setReplicaStatus(self::REPLICATION_SLOW); - $ref->setReplicaMessage( - pht( - 'This replica is lagging far behind the master. Data is at '. - 'risk!')); + $latency = idx($replica_status, 'Seconds_Behind_Master'); + if (!strlen($latency)) { + $ref->setReplicaStatus(self::REPLICATION_NOT_REPLICATING); + } else { + $latency = (int)$latency; + $ref->setReplicaDelay($latency); + if ($latency > 30) { + $ref->setReplicaStatus(self::REPLICATION_SLOW); + $ref->setReplicaMessage( + pht( + 'This replica is lagging far behind the master. Data is at '. + 'risk!')); + } } } }