Anja Jentzsch has uploaded a new change for review. https://gerrit.wikimedia.org/r/54849
Change subject: rebuildTermSearchKey should wait for slaves. ...................................................................... rebuildTermSearchKey should wait for slaves. rebuildTermSearchKey should sleep if slaves get lagged, in order to avoid locking the database because slaves get too far behind. Change-Id: I9eb2735b688f80e7319c2b73c56cbf6c1ba54fcc Note: This should be backported to the wmf12 branch. --- M repo/includes/store/sql/TermSearchKeyBuilder.php 1 file changed, 27 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Wikibase refs/changes/49/54849/1 diff --git a/repo/includes/store/sql/TermSearchKeyBuilder.php b/repo/includes/store/sql/TermSearchKeyBuilder.php index f6e6248..5c299b4 100644 --- a/repo/includes/store/sql/TermSearchKeyBuilder.php +++ b/repo/includes/store/sql/TermSearchKeyBuilder.php @@ -147,6 +147,10 @@ $total = 0; while ( true ) { + // Make sure we are not running too far ahead of the slaves, + // as that would cause the site to be rendered read only. + $this->waitForSlaves( $dbw ); + $dbw->begin(); $terms = $dbw->select( @@ -191,6 +195,29 @@ } /** + * Wait for slaves (quietly) + * + * @todo: this should be in the Database class. + * @todo: thresholds should be configurable + * + * @author Tim Starling (stolen from recompressTracked.php) + */ + protected function waitForSlaves() { + $lb = wfGetLB(); //TODO: allow foreign DB, get from $this->table + + while ( true ) { + list( $host, $maxLag ) = $lb->getMaxLag(); + if ( $maxLag < 2 ) { + break; + } + + $this->report( "Slaves are lagged by $maxLag seconds, sleeping..." ); + sleep( 5 ); + $this->report( "Resuming..." ); + } + } + + /** * Updates a single row with a newley calculated search key. * The search key is calculated using Term::normalizeText(). * -- To view, visit https://gerrit.wikimedia.org/r/54849 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I9eb2735b688f80e7319c2b73c56cbf6c1ba54fcc Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Wikibase Gerrit-Branch: mw1.21-wmf12 Gerrit-Owner: Anja Jentzsch <anja.jentz...@wikimedia.de> Gerrit-Reviewer: Daniel Kinzler <daniel.kinz...@wikimedia.de> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits