private $mLoadMonitorClass, $mLoadMonitor;
/**
- * @param array $params with keys:
+ * @param array $params Array with keys:
* servers Required. Array of server info structures.
* loadMonitor Name of a class used to fetch server lag and load.
* @throws MWException
);
}
- /**
- * Deprecated function, typo in function name
- *
- * @deprecated since 1.18
- * @param DatabaseBase $conn
- */
- function closeConnecton( $conn ) {
- wfDeprecated( __METHOD__, '1.18' );
- $this->closeConnection( $conn );
- }
-
/**
* Close a connection
* Using this function makes sure the LoadBalancer knows the connection is closed.
}
}
+ /**
+ * @return bool Whether a master connection is already open
+ * @since 1.24
+ */
+ function hasMasterConnection() {
+ return $this->isOpen( $this->getWriterIndex() );
+ }
+
/**
* Determine if there are any pending changes that need to be rolled back
* or committed.
$maxLag = -1;
$host = '';
$maxIndex = 0;
- if ( $this->getServerCount() > 1 ) { // no replication = no lag
+
+ if ( $this->getServerCount() <= 1 ) { // no replication = no lag
+ return array( $host, $maxLag, $maxIndex );
+ }
+
+ // Try to get the max lag info from the server cache
+ $key = 'loadbalancer:maxlag:cluster:' . $this->mServers[0]['host'];
+ $cache = ObjectCache::newAccelerator( array(), 'hash' );
+ $maxLagInfo = $cache->get( $key ); // (host, lag, index)
+
+ // Fallback to connecting to each slave and getting the lag
+ if ( !$maxLagInfo ) {
foreach ( $this->mServers as $i => $conn ) {
+ if ( $i == $this->getWriterIndex() ) {
+ continue; // nothing to check
+ }
$conn = false;
if ( $wiki === false ) {
$conn = $this->getAnyOpenConnection( $i );
$maxIndex = $i;
}
}
+ $maxLagInfo = array( $host, $maxLag, $maxIndex );
+ $cache->set( $key, $maxLagInfo, 5 );
}
- return array( $host, $maxLag, $maxIndex );
+ return $maxLagInfo;
}
/**