- if ( $i == 0 ) { # Master
- $lagTimes[$i] = 0;
- } elseif ( false !== ( $conn = $this->parent->getAnyOpenConnection( $i ) ) ) {
- $lagTimes[$i] = $conn->getLag();
- } elseif ( false !== ( $conn = $this->parent->openConnection( $i, $wiki ) ) ) {
- $lagTimes[$i] = $conn->getLag();
+ if ( $i == $this->parent->getWriterIndex() ) {
+ $lagTimes[$i] = 0; // master always has no lag
+ continue;
+ }
+
+ $conn = $this->parent->getAnyOpenConnection( $i );
+ if ( $conn ) {
+ $close = false; // already open
+ } else {
+ $conn = $this->parent->openConnection( $i, $wiki );
+ $close = true; // new connection
+ }
+
+ if ( !$conn ) {
+ $lagTimes[$i] = false;
+ $host = $this->parent->getServerName( $i );
+ wfDebugLog( 'replication', __METHOD__ . ": host $host (#$i) is unreachable" );
+ continue;
+ }
+
+ $lagTimes[$i] = $conn->getLag();
+ if ( $lagTimes[$i] === false ) {
+ $host = $this->parent->getServerName( $i );
+ wfDebugLog( 'replication', __METHOD__ . ": host $host (#$i) is not replicating?" );
+ }
+
+ if ( $close ) {