14require_once __DIR__ .
'/Maintenance.php';
24 parent::__construct();
26 $this->
addOption(
'b1',
'Backend 1',
true,
true );
27 $this->
addOption(
'b2',
'Backend 2',
false,
true );
28 $this->
addOption(
'srcdir',
'File source directory',
true,
true );
29 $this->
addOption(
'maxfiles',
'Max files',
false,
true );
30 $this->
addOption(
'quick',
'Avoid operation pre-checks (use doQuickOperations())' );
31 $this->
addOption(
'parallelize',
'"parallelize" flag for doOperations()',
false,
true );
36 $backend = $backendGroup->get( $this->
getOption(
'b1' ) );
40 $backend = $backendGroup->get( $this->
getOption(
'b2' ) );
52 $baseDir =
'mwstore://' . $backend->
getName() .
'/testing-cont1';
53 $backend->
prepare( [
'dir' => $baseDir ] );
56 $dir = opendir( $dirname );
62 while ( ( $file = readdir( $dir ) ) !==
false ) {
63 if ( $file[0] !=
'.' ) {
64 $this->
output(
"Using '$dirname/$file' in operations.\n" );
66 $ops1[] = [
'op' =>
'store',
67 'src' =>
"$dirname/$file",
'dst' => $dst,
'overwrite' => true ];
68 $ops2[] = [
'op' =>
'copy',
69 'src' =>
"$dst",
'dst' =>
"$dst-1",
'overwrite' => true ];
70 $ops3[] = [
'op' =>
'move',
71 'src' => $dst,
'dst' =>
"$dst-2",
'overwrite' => true ];
72 $ops4[] = [
'op' =>
'delete',
'src' =>
"$dst-1" ];
73 $ops5[] = [
'op' =>
'delete',
'src' =>
"$dst-2" ];
75 if ( count( $ops1 ) >= $this->
getOption(
'maxfiles', 20 ) ) {
82 $method = $this->
hasOption(
'quick' ) ?
'doQuickOperations' :
'doOperations';
84 $opts = [
'force' => 1 ];
85 if ( $this->
hasOption(
'parallelize' ) ) {
86 $opts[
'parallelize'] = ( $this->
getOption(
'parallelize' ) ===
'true' );
89 $start = microtime(
true );
90 $status = $backend->$method( $ops1, $opts );
91 $e = ( microtime(
true ) - $start ) * 1000;
92 if ( !$status->isGood() ) {
93 $this->
error( $status );
96 $this->
output( $backend->
getName() .
": Stored " . count( $ops1 ) .
" files in $e ms.\n" );
98 $start = microtime(
true );
99 $status = $backend->$method( $ops2, $opts );
100 $e = ( microtime(
true ) - $start ) * 1000;
101 if ( !$status->isGood() ) {
102 $this->
error( $status );
105 $this->
output( $backend->
getName() .
": Copied " . count( $ops2 ) .
" files in $e ms.\n" );
107 $start = microtime(
true );
108 $status = $backend->$method( $ops3, $opts );
109 $e = ( microtime(
true ) - $start ) * 1000;
110 if ( !$status->isGood() ) {
111 $this->
error( $status );
114 $this->
output( $backend->
getName() .
": Moved " . count( $ops3 ) .
" files in $e ms.\n" );
116 $start = microtime(
true );
117 $status = $backend->$method( $ops4, $opts );
118 $e = ( microtime(
true ) - $start ) * 1000;
119 if ( !$status->isGood() ) {
120 $this->
error( $status );
123 $this->
output( $backend->
getName() .
": Deleted " . count( $ops4 ) .
" files in $e ms.\n" );
125 $start = microtime(
true );
126 $status = $backend->$method( $ops5, $opts );
127 $e = ( microtime(
true ) - $start ) * 1000;
128 if ( !$status->isGood() ) {
129 $this->
error( $status );
132 $this->
output( $backend->
getName() .
": Deleted " . count( $ops5 ) .
" files in $e ms.\n" );
138require_once RUN_MAINTENANCE_IF_MAIN;
wfBaseName( $path, $suffix='')
Return the final portion of a pathname.
Maintenance script to test fileop performance.
__construct()
Default constructor.
doPerfTest(FileBackend $backend)
execute()
Do the actual work.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
hasOption( $name)
Checks to see if a particular option was set.
getOption( $name, $default=null)
Get an option, or return the default.
error( $err, $die=0)
Throw an error to the user.
getServiceContainer()
Returns the main service container.
addDescription( $text)
Set the description text.