r113412 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r113411‎ | r113412 | r113413 >
Date:22:31, 8 March 2012
Author:aaron
Status:ok (Comments)
Tags:
Comment:
[FileBackend] Made doOperations() Status handling align with documentation as well as what FileRepo is essentially expecting when using the 'force' option (it assumes fatals are for total batch failures, not just partial ones). The relevant documentation was also improved.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/FileOp.php (modified) (history)
  • /trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/phpunit/includes/filerepo/FileBackendTest.php
@@ -1034,6 +1034,16 @@
10351035 $this->doTestDoOperations();
10361036 $this->tearDownFiles();
10371037
 1038+ $this->backend = $this->singleBackend;
 1039+ $this->tearDownFiles();
 1040+ $this->doTestDoOperationsFailing();
 1041+ $this->tearDownFiles();
 1042+
 1043+ $this->backend = $this->multiBackend;
 1044+ $this->tearDownFiles();
 1045+ $this->doTestDoOperationsFailing();
 1046+ $this->tearDownFiles();
 1047+
10381048 // @TODO: test some cases where the ops should fail
10391049 }
10401050
@@ -1057,9 +1067,9 @@
10581068
10591069 $status = $this->backend->doOperations( array(
10601070 array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
1061 - // Now: A:<A>, B:<B>, C:<A>, D:<D> (file:<orginal contents>)
 1071+ // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
10621072 array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
1063 - // Now: A:<A>, B:<B>, C:<A>, D:<D>
 1073+ // Now: A:<A>, B:<B>, C:<A>, D:<empty>
10641074 array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD, 'overwrite' => 1 ),
10651075 // Now: A:<A>, B:<B>, C:<empty>, D:<A>
10661076 array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC ),
@@ -1109,6 +1119,68 @@
11101120 "Correct file SHA-1 of $fileC" );
11111121 }
11121122
 1123+ function doTestDoOperationsFailing() {
 1124+ $base = $this->baseStorePath();
 1125+
 1126+ $fileA = "$base/unittest-cont2/a/b/fileA.txt";
 1127+ $fileAContents = '3tqtmoeatmn4wg4qe-mg3qt3 tq';
 1128+ $fileB = "$base/unittest-cont2/a/b/fileB.txt";
 1129+ $fileBContents = 'g-jmq3gpqgt3qtg q3GT ';
 1130+ $fileC = "$base/unittest-cont2/a/b/fileC.txt";
 1131+ $fileCContents = 'eigna[ogmewt 3qt g3qg flew[ag';
 1132+ $fileD = "$base/unittest-cont2/a/b/fileD.txt";
 1133+
 1134+ $this->prepare( array( 'dir' => dirname( $fileA ) ) );
 1135+ $this->backend->create( array( 'dst' => $fileA, 'content' => $fileAContents ) );
 1136+ $this->prepare( array( 'dir' => dirname( $fileB ) ) );
 1137+ $this->backend->create( array( 'dst' => $fileB, 'content' => $fileBContents ) );
 1138+ $this->prepare( array( 'dir' => dirname( $fileC ) ) );
 1139+ $this->backend->create( array( 'dst' => $fileC, 'content' => $fileCContents ) );
 1140+
 1141+ $status = $this->backend->doOperations( array(
 1142+ array( 'op' => 'copy', 'src' => $fileA, 'dst' => $fileC, 'overwrite' => 1 ),
 1143+ // Now: A:<A>, B:<B>, C:<A>, D:<empty> (file:<orginal contents>)
 1144+ array( 'op' => 'copy', 'src' => $fileC, 'dst' => $fileA, 'overwriteSame' => 1 ),
 1145+ // Now: A:<A>, B:<B>, C:<A>, D:<empty>
 1146+ array( 'op' => 'copy', 'src' => $fileB, 'dst' => $fileD, 'overwrite' => 1 ),
 1147+ // Now: A:<A>, B:<B>, C:<A>, D:<B>
 1148+ array( 'op' => 'move', 'src' => $fileC, 'dst' => $fileD ),
 1149+ // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
 1150+ array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileC, 'overwriteSame' => 1 ),
 1151+ // Now: A:<A>, B:<B>, C:<A>, D:<empty> (failed)
 1152+ array( 'op' => 'move', 'src' => $fileB, 'dst' => $fileA, 'overwrite' => 1 ),
 1153+ // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
 1154+ array( 'op' => 'delete', 'src' => $fileD ),
 1155+ // Now: A:<B>, B:<empty>, C:<A>, D:<empty>
 1156+ array( 'op' => 'null' ),
 1157+ // Does nothing
 1158+ ), array( 'force' => 1 ) );
 1159+
 1160+ $this->assertNotEquals( array(), $status->errors, "Operation had warnings" );
 1161+ $this->assertEquals( true, $status->isOK(), "Operation batch succeeded" );
 1162+ $this->assertEquals( 8, count( $status->success ),
 1163+ "Operation batch has correct success array" );
 1164+
 1165+ $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileB ) ),
 1166+ "File does not exist at $fileB" );
 1167+ $this->assertEquals( false, $this->backend->fileExists( array( 'src' => $fileD ) ),
 1168+ "File does not exist at $fileD" );
 1169+
 1170+ $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileA ) ),
 1171+ "File does not exist at $fileA" );
 1172+ $this->assertEquals( true, $this->backend->fileExists( array( 'src' => $fileC ) ),
 1173+ "File exists at $fileC" );
 1174+ $this->assertEquals( $fileBContents,
 1175+ $this->backend->getFileContents( array( 'src' => $fileA ) ),
 1176+ "Correct file contents of $fileA" );
 1177+ $this->assertEquals( strlen( $fileBContents ),
 1178+ $this->backend->getFileSize( array( 'src' => $fileA ) ),
 1179+ "Correct file size of $fileA" );
 1180+ $this->assertEquals( wfBaseConvert( sha1( $fileBContents ), 16, 36, 31 ),
 1181+ $this->backend->getFileSha1Base36( array( 'src' => $fileA ) ),
 1182+ "Correct file SHA-1 of $fileA" );
 1183+ }
 1184+
11131185 public function testGetFileList() {
11141186 $this->backend = $this->singleBackend;
11151187 $this->tearDownFiles();
Index: trunk/phase3/includes/filerepo/backend/FileOp.php
@@ -81,6 +81,10 @@
8282 * 'allowStale' : Don't require the latest available data.
8383 * This can increase performance for non-critical writes.
8484 * This has no effect unless the 'force' flag is set.
 85+ *
 86+ * The resulting Status will be "OK" unless:
 87+ * a) unexpected operation errors occurred (network partitions, disk full...)
 88+ * b) significant operation errors occured and 'force' was not set
8589 *
8690 * @param $performOps Array List of FileOp operations
8791 * @param $opts Array Batch operation options
@@ -115,6 +119,11 @@
116120 }
117121 }
118122
 123+ if ( $ignoreErrors ) {
 124+ # Treat all precheck() fatals as merely warnings
 125+ $status->setResult( true, $status->value );
 126+ }
 127+
119128 // Restart PHP's execution timer and set the timeout to safe amount.
120129 // This handles cases where the operations take a long time or where we are
121130 // already running low on time left. The old timeout is restored afterwards.
Index: trunk/phase3/includes/filerepo/backend/FileBackend.php
@@ -186,8 +186,9 @@
187187 * Return value:
188188 * This returns a Status, which contains all warnings and fatals that occured
189189 * during the operation. The 'failCount', 'successCount', and 'success' members
190 - * will reflect each operation attempted. The status will be "OK" unless any
191 - * of the operations failed and the 'force' parameter was not set.
 190+ * will reflect each operation attempted. The status will be "OK" unless:
 191+ * a) unexpected operation errors occurred (network partitions, disk full...)
 192+ * b) significant operation errors occured and 'force' was not set
192193 *
193194 * @param $ops Array List of operations to execute in order
194195 * @param $opts Array Batch operation options

Follow-up revisions

RevisionCommit summaryAuthorDate
r113413MFT r113412aaron22:34, 8 March 2012
r114374MFT r113412, r113441, r113601, r113617, r113782reedy16:57, 21 March 2012

Comments

#Comment by Aaron Schulz (talk | contribs)   23:00, 8 March 2012

Should fix bug 35054.

Status & tagging log