Implement extension registration from an extension.json file
[mediawiki.git] / maintenance / populateBloomCache.php
blob40ad5fc6496007f0cff5332834d26b25df50e088
1 <?php
2 /**
3 * Script to populate a bloom filter with a BloomFilter* class
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Maintenance
24 require_once __DIR__ . '/Maintenance.php';
26 /**
27 * Script to populate a bloom filter with a BloomFilter* class
29 * @ingroup Maintenance
31 class PopulateBloomFilter extends Maintenance {
32 public function __construct() {
33 parent::__construct();
34 $this->addOption( 'cache', 'Bloom cache store name', true, true );
35 $this->addOption( 'filter', 'Bloom filter name', true, true );
36 $this->addOption( 'domain', 'Bloom filter domain', true, true );
37 $this->addOption( 'delay', 'Sleep delay between batches (us)', false, true );
38 $this->mDescription = "Populate the specified bloom filter";
41 public function execute() {
42 $type = $this->getOption( 'filter' );
43 $domain = $this->getOption( 'domain' );
44 $bcache = BloomCache::get( $this->getOption( 'cache' ) );
45 $delay = $this->getOption( 'delay', 1e5 );
47 if ( !method_exists( "BloomFilter{$type}", 'merge' ) ) {
48 $this->error( "No \"BloomFilter{$type}::merge\" method found.", 1 );
51 $virtualKey = "$domain:$type";
52 $status = $bcache->getStatus( $virtualKey );
53 if ( $status == false ) {
54 $this->error( "Could not query virtual bloom filter '$virtualKey'.", 1 );
57 $startTime = microtime( true );
58 $this->output( "Current timestamp is '$startTime'.\n" );
59 $this->output( "Current filter timestamp is '{$status['asOfTime']}'.\n" );
61 do {
62 $status = call_user_func_array(
63 array( "BloomFilter{$type}", 'merge' ),
64 array( $bcache, $domain, $virtualKey, $status )
66 if ( $status == false ) {
67 $this->error( "Could not query virtual bloom filter '$virtualKey'.", 1 );
69 $this->output( "Filter updated to timestamp '{$status['asOfTime']}'.\n" );
70 usleep( $delay );
71 } while ( $status['asOfTime'] && $status['asOfTime'] < $startTime );
73 $this->output( "Done, filter $type of domain $domain reached time '$startTime'.\n" );
77 $maintClass = "PopulateBloomFilter";
78 require_once RUN_MAINTENANCE_IF_MAIN;