Daniel Kinzler has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/401594 )
Change subject: Simplify logic for replica selection with groups
......................................................................
Simplify logic for replica selection with groups
Change-Id: I835a25235b88f54eb5e8d4f0afb0df5d55bcc8b9
---
M includes/libs/rdbms/loadbalancer/LoadBalancer.php
1 file changed, 18 insertions(+), 15 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/94/401594/1
diff --git a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
index daa70a4..716a660 100644
--- a/includes/libs/rdbms/loadbalancer/LoadBalancer.php
+++ b/includes/libs/rdbms/loadbalancer/LoadBalancer.php
@@ -627,6 +627,15 @@
return $ok;
}
+ /**
+ * @param int $i
+ * @param array $groups
+ * @param bool $domain
+ * @param int $flags
+ *
+ * @return bool|null|Database|DBNoWriteWrapper|IDatabase
+ * @throws DBConnectionError
+ */
public function getConnection( $i, $groups = [], $domain = false,
$flags = 0 ) {
$requestedIndex = $i;
@@ -639,17 +648,18 @@
$domain = false; // local connection requested
}
- $groups = ( $groups === false || $groups === [] )
- ? [ false ] // check one "group": the generic pool
- : (array)$groups;
-
$masterOnly = ( $i == self::DB_MASTER || $i ==
$this->getWriterIndex() );
$oldConnsOpened = $this->connsOpened; // connections open now
+
+ $this->mLastError = 'Unknown error'; // reset error string
if ( $i == self::DB_MASTER ) {
$i = $this->getWriterIndex();
} elseif ( $i == self::DB_REPLICA ) {
- # Try to find an available server in any the query
groups (in order)
+ $groups = (array)$groups;
+ $groups[] = false; // always check the default group.
+
+ // Try to find an available server in any the query
groups (in order)
foreach ( $groups as $group ) {
$groupIndex = $this->getReaderIndex( $group,
$domain );
if ( $groupIndex !== false ) {
@@ -657,18 +667,11 @@
break;
}
}
- }
- # Operation-based index
- if ( $i == self::DB_REPLICA ) {
- $this->mLastError = 'Unknown error'; // reset error
string
- # Try the general server pool if $groups are
unavailable.
- $i = ( $groups === [ false ] )
- ? false // don't bother with this if that is
what was tried above
- : $this->getReaderIndex( false, $domain );
- # Couldn't find a working server in getReaderIndex()?
- if ( $i === false ) {
+ // nothing found!
+ if ( $i == self::DB_REPLICA ) {
$this->mLastError = 'No working replica DB
server: ' . $this->mLastError;
+
// Throw an exception
$this->reportConnectionError();
return null; // not reached
--
To view, visit https://gerrit.wikimedia.org/r/401594
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I835a25235b88f54eb5e8d4f0afb0df5d55bcc8b9
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Daniel Kinzler <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits