r10020 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r10019‎ | r10020 | r10021 >
Date:22:56, 8 July 2005
Author:vibber
Status:old
Tags:
Comment:
In rebuild, check daemon status and wait if too many items are queued.
Modified paths:
  • /trunk/extensions/MWSearch/luceneUpdate.php (modified) (history)

Diff [purge]

Index: trunk/extensions/MWSearch/luceneUpdate.php
@@ -2,12 +2,13 @@
33
44 // symlink me into maintenance/
55
 6+$options = array( 'skip' );
67 require_once( 'commandLine.inc' );
78
89
910 if( !isset( $args[0] ) ) {
1011 print "Call MWUpdateDaemon remotely for status or updates.\n";
11 - print "Usage: php luceneUpdate.php [database] {status|stop|start|restart|rebuild}\n";
 12+ print "Usage: php luceneUpdate.php [database] [--skip=n] {status|flush|stop|start|restart|rebuild}\n";
1213 exit( -1 );
1314 }
1415
@@ -35,6 +36,9 @@
3637 break;
3738 case 'rebuild':
3839 $builder = new LuceneBuilder();
 40+ if( isset( $options['skip'] ) ) {
 41+ $builder->skip( intval( $options['skip'] ) );
 42+ }
3943 $ret = $builder->rebuildAll();
4044 break;
4145 default:
@@ -57,6 +61,7 @@
5862 function LuceneBuilder() {
5963 $this->db =& wfGetDB( DB_SLAVE );
6064 $this->dbstream =& $this->streamingSlave( $this->db );
 65+ $this->offset = 0;
6166 }
6267
6368 function &streamingSlave( $db ) {
@@ -70,6 +75,10 @@
7176 return $stream;
7277 }
7378
 79+ function skip( $offset ) {
 80+ $this->offset = intval( $offset );
 81+ }
 82+
7483 function init( $max ) {
7584 $this->max = $max;
7685 $this->count = 0;
@@ -94,9 +103,45 @@
95104 $this->count,
96105 $this->max,
97106 $rate );
 107+
 108+ $this->wait();
98109 }
99110 }
100111
 112+ /**
 113+ * See if the daemon's getting overloaded and pause if so
 114+ */
 115+ function wait() {
 116+ $cutoff = 500;
 117+ $waittime = 10;
 118+
 119+ while( true ) {
 120+ $status = MWSearchUpdater::getStatus();
 121+ if( WikiError::isError( $status ) ) {
 122+ echo $status->getMessage() . "\n";
 123+ sleep( $waittime );
 124+ continue;
 125+ }
 126+
 127+ // Updater IS running; 90418 items queued.
 128+ if( !preg_match( '/([0-9]+) items queued/', $status, $matches ) ) {
 129+ // ?! confused
 130+ break;
 131+ }
 132+
 133+ $count = intval( $matches[1] );
 134+ if( $count < $cutoff ) {
 135+ break;
 136+ }
 137+
 138+ printf( "%s: %s\n",
 139+ wfTimestamp( TS_DB ),
 140+ $status );
 141+
 142+ sleep( $waittime );
 143+ }
 144+ }
 145+
101146 function final() {
102147 global $wgDBname;
103148 $now = wfTime();
@@ -120,16 +165,23 @@
121166 $lastError = true;
122167
123168 $maxId = $this->db->selectField( 'page', 'MAX(page_id)', '', $fname );
 169+ $maxId -= $this->offset; // hack for percentages
124170 $this->init( $maxId );
125171 if( $maxId < 1 ) {
126172 echo "Nothing to do.\n";
127173 return;
128174 }
129175
 176+ $limit = array();
 177+ if( $this->offset ) {
 178+ $limit = array( 'LIMIT $offset, 10000000' );
 179+ }
 180+
130181 $result = $this->dbstream->select( array( 'page' ),
131182 array( 'page_namespace', 'page_title', 'page_latest' ),
132183 '',
133 - $fname );
 184+ $fname,
 185+ $limit );
134186
135187 $errorCount = 0;
136188 while( $row = $this->dbstream->fetchObject( $result ) ) {

Status & tagging log