From fa7fd8764729e7de2fe536dde8facf0f1d4b83aa Mon Sep 17 00:00:00 2001 From: Aryeh Gregor Date: Tue, 18 Mar 2008 13:18:06 +0000 Subject: [PATCH] Don't require commandLine.inc when not using the command line; instead, move wfWaitForSlaves() to GlobalFunctions.php, which is where I expected it to be to begin with. That appears, sensibly, to be loaded by all code paths. While I'm there, add some documentation. --- includes/GlobalFunctions.php | 30 ++++++++++++++++++++++++++++++ maintenance/commandLine.inc | 24 ------------------------ maintenance/populateCategory.inc | 2 -- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 71b135f7ad..7acd3e85c1 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -2437,7 +2437,37 @@ function wfMaxlagError( $host, $lag, $maxLag ) { /** * Throws an E_USER_NOTICE saying that $function is deprecated * @param string $function + * @return null */ function wfDeprecated( $function ) { trigger_error( "Use of $function is deprecated", E_USER_NOTICE ); } + +/** + * Sleep until the worst slave's replication lag is less than or equal to + * $maxLag, in seconds. Use this when updating very large numbers of rows, as + * in maintenance scripts, to avoid causing too much lag. Of course, this is + * a no-op if there are no slaves. + * + * Every time the function has to wait for a slave, it will print a message to + * that effect (and then sleep for a little while), so it's probably not best + * to use this outside maintenance scripts in its present form. + * + * @param int $maxLag + * @return null + */ +function wfWaitForSlaves( $maxLag ) { + global $wgLoadBalancer; + if( $maxLag ) { + list( $host, $lag ) = $wgLoadBalancer->getMaxLag(); + while( $lag > $maxLag ) { + $name = @gethostbyaddr( $host ); + if( $name !== false ) { + $host = $name; + } + print "Waiting for $host (lagged $lag seconds)...\n"; + sleep($maxLag); + list( $host, $lag ) = $wgLoadBalancer->getMaxLag(); + } + } +} diff --git a/maintenance/commandLine.inc b/maintenance/commandLine.inc index f7bb53ff5a..0bdfe1365a 100644 --- a/maintenance/commandLine.inc +++ b/maintenance/commandLine.inc @@ -236,27 +236,3 @@ require_once( "$IP/includes/Setup.php" ); require_once( "$IP/install-utils.inc" ); $wgTitle = null; # Much much faster startup than creating a title object set_time_limit(0); - -// -------------------------------------------------------------------- -// Functions -// -------------------------------------------------------------------- - -function wfWaitForSlaves( $maxLag ) { - global $wgLoadBalancer; - if ( $maxLag ) { - list( $host, $lag ) = $wgLoadBalancer->getMaxLag(); - while ( $lag > $maxLag ) { - $name = @gethostbyaddr( $host ); - if ( $name !== false ) { - $host = $name; - } - print "Waiting for $host (lagged $lag seconds)...\n"; - sleep($maxLag); - list( $host, $lag ) = $wgLoadBalancer->getMaxLag(); - } - } -} - - - -?> diff --git a/maintenance/populateCategory.inc b/maintenance/populateCategory.inc index 497f4b5776..f17e5e827f 100644 --- a/maintenance/populateCategory.inc +++ b/maintenance/populateCategory.inc @@ -4,8 +4,6 @@ * @author Simetrical */ -require_once "commandLine.inc"; - define( 'REPORTING_INTERVAL', 1000 ); function populateCategory( $begin, $maxlag, $throttle, $force ) { -- 2.20.1