[FileBackend] Added "ratefile" option for backend copy script.
authorAaron <aschulz@wikimedia.org>
Mon, 9 Jul 2012 23:30:44 +0000 (16:30 -0700)
committerAaron <aschulz@wikimedia.org>
Tue, 10 Jul 2012 17:24:37 +0000 (10:24 -0700)
* This can be used to control the concurrency dynamically.

Change-Id: I7ebdbffa144928f559c34c4a4684b03597f616ce

maintenance/copyFileBackend.php

index 530b5ca..78ffb20 100644 (file)
@@ -42,6 +42,7 @@ class CopyFileBackend extends Maintenance {
                $this->addOption( 'dst', 'Backend where files should be copied to', true, true );
                $this->addOption( 'containers', 'Pipe separated list of containers', true, true );
                $this->addOption( 'subdir', 'Only do items in this child directory', false, true );
+               $this->addOption( 'ratefile', 'File to check periodically for batch size.', false, true );
                $this->setBatchSize( 50 );
        }
 
@@ -51,6 +52,8 @@ class CopyFileBackend extends Maintenance {
                $containers = explode( '|', $this->getOption( 'containers' ) );
                $subDir = $this->getOption( rtrim( 'subdir', '/' ), '' );
 
+               $rateFile = $this->getOption( 'ratefile' );
+
                $count = 0;
                foreach ( $containers as $container ) {
                        if ( $subDir != '' ) {
@@ -69,6 +72,11 @@ class CopyFileBackend extends Maintenance {
 
                        $batchPaths = array();
                        foreach ( $srcPathsRel as $srcPathRel ) {
+                               // Check up on the rate file periodically to adjust the concurrency
+                               if ( $rateFile && ( !$count || ( $count % 500 ) == 0 ) ) {
+                                       $this->mBatchSize = max( 1, (int)file_get_contents( $rateFile ) );
+                                       $this->output( "Batch size is now {$this->mBatchSize}.\n" );
+                               }
                                $batchPaths[$srcPathRel] = 1; // remove duplicates
                                if ( count( $batchPaths ) >= $this->mBatchSize ) {
                                        $this->copyFileBatch( array_keys( $batchPaths ), $backendRel, $src, $dst );