[FileBackend] Tweaks to speed up backend copy script.
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 12 Jul 2012 17:14:08 +0000 (10:14 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Thu, 12 Jul 2012 18:11:45 +0000 (11:11 -0700)
* Added 'missingonly' option to copy based only on a listing comparison.
* Made copy operation batches use doQuickOperations().

Change-Id: If5657a4c4d895980e27776357bb408b350727382

maintenance/copyFileBackend.php

index 8db0a7f..184bf3d 100644 (file)
@@ -44,6 +44,7 @@ class CopyFileBackend extends Maintenance {
                $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->addOption( 'skiphash', 'Skip SHA-1 sync checks for files' );
+               $this->addOption( 'missingonly', 'Only copy files missing from destination listing' );
                $this->setBatchSize( 50 );
        }
 
@@ -65,12 +66,32 @@ class CopyFileBackend extends Maintenance {
                                $this->output( "Doing container '$container'...\n" );
                        }
 
-                       $dir = $src->getRootStoragePath() . "/$backendRel";
-                       $srcPathsRel = $src->getFileList( array( 'dir' => $dir ) );
+                       $srcPathsRel = $src->getFileList( array(
+                               'dir' => $src->getRootStoragePath() . "/$backendRel" ) );
                        if ( $srcPathsRel === null ) {
                                $this->error( "Could not list files in $container.", 1 ); // die
                        }
 
+                       // Do a listing comparison if specified
+                       if ( $this->hasOption( 'missingonly' ) ) {
+                               $relFilesSrc = array();
+                               $relFilesDst = array();
+                               foreach ( $srcPathsRel as $srcPathRel ) {
+                                       $relFilesSrc[] = $srcPathRel;
+                               }
+                               $dstPathsRel = $dst->getFileList( array(
+                                       'dir' => $dst->getRootStoragePath() . "/$backendRel" ) );
+                               if ( $dstPathsRel === null ) {
+                                       $this->error( "Could not list files in $container.", 1 ); // die
+                               }
+                               foreach ( $dstPathsRel as $dstPathRel ) {
+                                       $relFilesDst[] = $dstPathRel;
+                               }
+                               // Only copy the missing files over in the next loop
+                               $srcPathsRel = array_diff( $relFilesSrc, $relFilesDst );
+                               $this->output( count( $srcPathsRel ) . " file(s) need to be copied.\n" );
+                       }
+
                        $batchPaths = array();
                        foreach ( $srcPathsRel as $srcPathRel ) {
                                // Check up on the rate file periodically to adjust the concurrency
@@ -131,7 +152,7 @@ class CopyFileBackend extends Maintenance {
                }
 
                $t_start = microtime( true );
-               $status = $dst->doOperations( $ops, array( 'nonJournaled' => 1 ) );
+               $status = $dst->doQuickOperations( $ops );
                $ellapsed_ms = floor( ( microtime( true ) - $t_start ) * 1000 );
                if ( !$status->isOK() ) {
                        $this->error( print_r( $status->getErrorsArray(), true ) );