MediaWiki
REL1_24
|
00001 <?php 00024 require_once __DIR__ . '/Maintenance.php'; 00025 00031 class PopulateBloomFilter extends Maintenance { 00032 public function __construct() { 00033 parent::__construct(); 00034 $this->addOption( 'cache', 'Bloom cache store name', true, true ); 00035 $this->addOption( 'filter', 'Bloom filter name', true, true ); 00036 $this->addOption( 'domain', 'Bloom filter domain', true, true ); 00037 $this->addOption( 'delay', 'Sleep delay between batches (us)', false, true ); 00038 $this->mDescription = "Populate the specified bloom filter"; 00039 } 00040 00041 public function execute() { 00042 $type = $this->getOption( 'filter' ); 00043 $domain = $this->getOption( 'domain' ); 00044 $bcache = BloomCache::get( $this->getOption( 'cache' ) ); 00045 $delay = $this->getOption( 'delay', 1e5 ); 00046 00047 if ( !method_exists( "BloomFilter{$type}", 'merge' ) ) { 00048 $this->error( "No \"BloomFilter{$type}::merge\" method found.", 1 ); 00049 } 00050 00051 $virtualKey = "$domain:$type"; 00052 $status = $bcache->getStatus( $virtualKey ); 00053 if ( $status == false ) { 00054 $this->error( "Could not query virtual bloom filter '$virtualKey'.", 1 ); 00055 } 00056 00057 $startTime = microtime( true ); 00058 $this->output( "Current timestamp is '$startTime'.\n" ); 00059 $this->output( "Current filter timestamp is '{$status['asOfTime']}'.\n" ); 00060 00061 do { 00062 $status = call_user_func_array( 00063 array( "BloomFilter{$type}", 'merge' ), 00064 array( $bcache, $domain, $virtualKey, $status ) 00065 ); 00066 if ( $status == false ) { 00067 $this->error( "Could not query virtual bloom filter '$virtualKey'.", 1 ); 00068 } 00069 $this->output( "Filter updated to timestamp '{$status['asOfTime']}'.\n" ); 00070 usleep( $delay ); 00071 } while ( $status['asOfTime'] && $status['asOfTime'] < $startTime ); 00072 00073 $this->output( "Done, filter $type of domain $domain reached time '$startTime'.\n" ); 00074 } 00075 } 00076 00077 $maintClass = "PopulateBloomFilter"; 00078 require_once RUN_MAINTENANCE_IF_MAIN;