r34087 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r34086‎ | r34087 | r34088 >
Date:21:02, 1 May 2008
Author:btongminh
Status:old
Tags:
Comment:
Fixes to timestamp handling of daemon
Modified paths:
  • /trunk/extensions/GlobalUsage/GlobalUsage.sql (modified) (history)
  • /trunk/extensions/GlobalUsage/GlobalUsageDaemon.php (modified) (history)

Diff [purge]

Index: trunk/extensions/GlobalUsage/GlobalUsageDaemon.php
@@ -244,7 +244,13 @@
245245 $this->setTimestamp($wiki, $newTs);
246246
247247 // Return when this function should be called again
248 - return $this->incrementTimestamp($newTs, $interval);
 248+ $waitUntil = wfTimestamp(TS_MW, $this->incrementTimestamp($newTs, $interval));
 249+
 250+ $res = $dbr->select('recentchanges', 'MAX(rc_timestamp) AS r', '', __METHOD__);
 251+ $row = $res->fetchRow();
 252+ $res->free();
 253+ return array($waitUntil, $row['r'] > $waitUntil);
 254+
249255 }
250256
251257 /*
@@ -280,10 +286,12 @@
281287 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
282288 $data = unserialize(curl_exec($curl));
283289 curl_close($curl);
 290+ if (!$data) return false;
284291
285292 $this->namespaces[$wiki] = array();
286293 foreach ($data['query']['namespaces'] as $id => $value)
287294 $this->namespaces[$wiki][$id] = $value['*'];
 295+ return true;
288296 }
289297 }
290298
@@ -341,13 +349,14 @@
342350
343351 // Fetch namespaces
344352 if (!isset($this->namespaces[$wiki]))
345 - $this->fetchNamespaces($wiki);
 353+ if (!$this->fetchNamespaces($wiki))
 354+ die("Could not fetch namespaces for {$wiki}\n");
346355 $dbr = $this->getDatabase($wiki);
347356
348357 while (true) {
349 - $waitUntil = $this->processRecentChanges($wiki, $interval);
 358+ list($waitUntil, $hasMore) = $this->processRecentChanges($wiki, $interval);
350359 while ($waitUntil > time() - $dbr->getLag()) {
351 - $sleepTime = max($waitUntil + $dbr->getLag() - time(), 0);
 360+ $sleepTime = max(wfTimestamp(TS_UNIX, $waitUntil) + $dbr->getLag() - time(), 0);
352361 $this->debug("Sleeping {$sleepTime} seconds: ".
353362 'need to wait until '.wfTimestamp(TS_MW, $waitUntil).
354363 '; now is '.wfTimestamp(TS_MW));
@@ -369,23 +378,38 @@
370379 reset($waitUntil);
371380
372381 $dbr = $this->getDatabase(key($waitUntil));
373 - while (current($waitUntil) > time() - $dbr->getLag()) {
374 - $sleepTime = max(current($waitUntil) + $dbr->getLag() - time(), 0);
375 - $this->debug("Sleeping {$sleepTime} seconds: ".
376 - 'need to wait until '.
377 - wfTimestamp(TS_MW, current($waitUntil)).
378 - '; now is '.wfTimestamp(TS_MW));
379 - sleep($sleepTime);
 382+ if (current($waitUntil) != 0) {
 383+ $waitUntilTime = wfTimestamp(TS_UNIX, current($waitUntil));
 384+ $lag = $dbr->getLag();
 385+ while ($waitUntilTime > time() - $lag) {
 386+ $sleepTime = max($waitUntilTime - time() + $lag, 0);
 387+ $this->debug("Sleeping {$sleepTime} seconds: ".
 388+ 'need to wait until '.current($waitUntil).
 389+ '; now is '.wfTimestamp(TS_MW, time() - $lag));
 390+ sleep($sleepTime);
 391+ }
380392 }
381393
382394 $wiki = key($waitUntil);
383395
384396 // Fetch namespaces
385397 if (!isset($this->namespaces[$wiki]))
386 - $this->fetchNamespaces($wiki);
 398+ if (!$this->fetchNamespaces($wiki)) {
 399+ $this->debug("Could not fetch namespaces for {$wiki}");
 400+ unset($waitUntil[$wiki]);
 401+ continue;
 402+ }
387403
388404 $this->debug("Processing recentchanges for {$wiki}");
389 - $waitUntil[$wiki] = $this->processRecentChanges($wiki, $interval);
 405+ $now = time();
 406+ list($waitUntil[$wiki], $hasMore) = $this->processRecentChanges($wiki, $interval);
 407+ if (!$hasMore) {
 408+ // There are no more entries. Set the timestamp to *now* to avoid locking
 409+ // of other wikis by rarely updated wikis
 410+ $next = substr(substr(wfTimestamp(TS_MW, $now - $dbr->getLag()),
 411+ 0, 14 - $interval).'00000000000000', 0, 14);
 412+ $waitUntil[$wiki] = wfTimestamp(TS_MW, $this->incrementTimestamp($next, $interval));
 413+ }
390414 }
391415 }
392416 }
Index: trunk/extensions/GlobalUsage/GlobalUsage.sql
@@ -16,5 +16,5 @@
1717 -- On gil_is_local change
1818 INDEX (gil_wiki, gil_to),
1919 -- On the special page itself
20 - INDEX (gil_to, gil_is_local),
 20+ INDEX (gil_to, gil_is_local)
2121 ) /*$wgDBTableOptions*/;
\ No newline at end of file

Status & tagging log