r107147 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107146‎ | r107147 | r107148 >
Date:09:43, 23 December 2011
Author:aaron
Status:ok
Tags:
Comment:
* Added 'latest' parameter to functions that get information about a file. This will get the latest version among all storage nodes. Non-distributed backends can ignore this.
* In doOperations(), ignore 'nonLocking' unless 'ignoreErrors' is set. Split out a doOperationsInternal() function so the sanity check could go in doOperations().
* Moved getFileList() down a bit.
* Documentation tweaks.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FileBackend.php (modified) (history)
  • /trunk/phase3/includes/filerepo/backend/FileBackendMultiWrite.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/FileBackendMultiWrite.php
@@ -10,6 +10,8 @@
1111 * registered to this proxy backend and it will act as a single backend.
1212 * Use this when all access to those backends is through this proxy backend.
1313 * At least one of the backends must be declared the "master" backend.
 14+ *
 15+ * Only use this class when transitioning from one storage system to another.
1416 *
1517 * The order that the backends are defined sets the priority of which
1618 * backend is read from or written to first. Functions like fileExists()
@@ -62,7 +64,10 @@
6365 }
6466 }
6567
66 - final public function doOperations( array $ops, array $opts = array() ) {
 68+ /**
 69+ * @see FileBackendBase::doOperationsInternal()
 70+ */
 71+ final protected function doOperationsInternal( array $ops, array $opts ) {
6772 $status = Status::newGood();
6873
6974 $performOps = array(); // list of FileOp objects
@@ -145,6 +150,9 @@
146151 }
147152 }
148153
 154+ /**
 155+ * @see FileBackendBase::prepare()
 156+ */
149157 function prepare( array $params ) {
150158 $status = Status::newGood();
151159 foreach ( $this->backends as $backend ) {
@@ -154,6 +162,9 @@
155163 return $status;
156164 }
157165
 166+ /**
 167+ * @see FileBackendBase::secure()
 168+ */
158169 function secure( array $params ) {
159170 $status = Status::newGood();
160171 foreach ( $this->backends as $backend ) {
@@ -163,6 +174,9 @@
164175 return $status;
165176 }
166177
 178+ /**
 179+ * @see FileBackendBase::clean()
 180+ */
167181 function clean( array $params ) {
168182 $status = Status::newGood();
169183 foreach ( $this->backends as $backend ) {
@@ -172,6 +186,9 @@
173187 return $status;
174188 }
175189
 190+ /**
 191+ * @see FileBackendBase::fileExists()
 192+ */
176193 function fileExists( array $params ) {
177194 # Hit all backends in case of failed operations (out of sync)
178195 foreach ( $this->backends as $backend ) {
@@ -183,12 +200,18 @@
184201 return false;
185202 }
186203
 204+ /**
 205+ * @see FileBackendBase::getFileTimestamp()
 206+ */
187207 function getFileTimestamp( array $params ) {
188208 // Skip non-master for consistent timestamps
189209 $realParams = $this->substOpPaths( $params, $backend );
190210 return $this->backends[$this->masterIndex]->getFileTimestamp( $realParams );
191211 }
192212
 213+ /**
 214+ * @see FileBackendBase::getFileSha1Base36()
 215+ */
193216 function getFileSha1Base36( array $params ) {
194217 # Hit all backends in case of failed operations (out of sync)
195218 foreach ( $this->backends as $backend ) {
@@ -201,6 +224,9 @@
202225 return false;
203226 }
204227
 228+ /**
 229+ * @see FileBackendBase::getFileProps()
 230+ */
205231 function getFileProps( array $params ) {
206232 # Hit all backends in case of failed operations (out of sync)
207233 foreach ( $this->backends as $backend ) {
@@ -213,6 +239,9 @@
214240 return null;
215241 }
216242
 243+ /**
 244+ * @see FileBackendBase::streamFile()
 245+ */
217246 function streamFile( array $params ) {
218247 $status = Status::newGood();
219248 foreach ( $this->backends as $backend ) {
@@ -234,6 +263,9 @@
235264 return $status;
236265 }
237266
 267+ /**
 268+ * @see FileBackendBase::getLocalReference()
 269+ */
238270 function getLocalReference( array $params ) {
239271 # Hit all backends in case of failed operations (out of sync)
240272 foreach ( $this->backends as $backend ) {
@@ -246,6 +278,9 @@
247279 return null;
248280 }
249281
 282+ /**
 283+ * @see FileBackendBase::getLocalCopy()
 284+ */
250285 function getLocalCopy( array $params ) {
251286 # Hit all backends in case of failed operations (out of sync)
252287 foreach ( $this->backends as $backend ) {
@@ -258,6 +293,9 @@
259294 return null;
260295 }
261296
 297+ /**
 298+ * @see FileBackendBase::getFileList()
 299+ */
262300 function getFileList( array $params ) {
263301 foreach ( $this->backends as $index => $backend ) {
264302 # Get results from the first backend
Index: trunk/phase3/includes/filerepo/backend/FileBackend.php
@@ -128,11 +128,15 @@
129129 * exists at the destination that has the same
130130 * contents as the new contents to be written there.
131131 *
132 - * $opts is an associative of options, including:
 132+ * $opts is an associative of boolean flags, including:
 133+ * 'ignoreErrors' : Errors that would normally cause a rollback do not.
 134+ * The remaining operations are still attempted if any fail.
133135 * 'nonLocking' : No locks are acquired for the operations.
134136 * This can increase performance for non-critical writes.
135 - * 'ignoreErrors' : Serious errors that would normally cause a rollback
136 - * do not. The remaining operations are still attempted.
 137+ * This has no effect unless the 'ignoreErrors' flag is set.
 138+ * 'allowStale' : Don't require the latest available data.
 139+ * This can increase performance for non-critical writes.
 140+ * This has no effect unless the 'ignoreErrors' flag is set.
137141 *
138142 * Return value:
139143 * This returns a Status, which contains all warnings and fatals that occured
@@ -144,9 +148,20 @@
145149 * @param $opts Array Batch operation options
146150 * @return Status
147151 */
148 - abstract public function doOperations( array $ops, array $opts = array() );
 152+ final public function doOperations( array $ops, array $opts = array() ) {
 153+ if ( empty( $opts['ignoreErrors'] ) ) { // sanity
 154+ unset( $opts['nonLocking'] );
 155+ unset( $opts['allowStale'] );
 156+ }
 157+ return $this->doOperationsInternal( $ops, $opts );
 158+ }
149159
150160 /**
 161+ * @see FileBackendBase::doOperations()
 162+ */
 163+ abstract protected function doOperationsInternal( array $ops, array $opts );
 164+
 165+ /**
151166 * Same as doOperations() except it takes a single operation.
152167 * If you are doing a batch of operations that should either
153168 * all succeed or all fail, then use that function instead.
@@ -296,7 +311,8 @@
297312 * Check if a file exists at a storage path in the backend.
298313 *
299314 * $params include:
300 - * src : source storage path
 315+ * src : source storage path
 316+ * latest : use the latest available data
301317 *
302318 * @param $params Array
303319 * @return bool
@@ -307,7 +323,8 @@
308324 * Get a SHA-1 hash of the file at a storage path in the backend.
309325 *
310326 * $params include:
311 - * src : source storage path
 327+ * src : source storage path
 328+ * latest : use the latest available data
312329 *
313330 * @param $params Array
314331 * @return string|false Hash string or false on failure
@@ -318,7 +335,8 @@
319336 * Get the last-modified timestamp of the file at a storage path.
320337 *
321338 * $params include:
322 - * src : source storage path
 339+ * src : source storage path
 340+ * latest : use the latest available data
323341 *
324342 * @param $params Array
325343 * @return string|false TS_MW timestamp or false on failure
@@ -330,7 +348,8 @@
331349 * Returns FSFile::placeholderProps() on failure.
332350 *
333351 * $params include:
334 - * src : source storage path
 352+ * src : source storage path
 353+ * latest : use the latest available data
335354 *
336355 * @param $params Array
337356 * @return Array
@@ -346,6 +365,7 @@
347366 * $params include:
348367 * src : source storage path
349368 * headers : additional HTTP headers to send on success
 369+ * latest : use the latest available data
350370 *
351371 * @param $params Array
352372 * @return Status
@@ -353,20 +373,6 @@
354374 abstract public function streamFile( array $params );
355375
356376 /**
357 - * Get an iterator to list out all object files under a storage directory.
358 - * If the directory is of the form "mwstore://container", then all items in
359 - * the container should be listed. If of the form "mwstore://container/dir",
360 - * then all items under that container directory should be listed.
361 - * Results should be storage paths relative to the given directory.
362 - *
363 - * $params include:
364 - * dir : storage path directory
365 - *
366 - * @return Traversable|Array|null Returns null on failure
367 - */
368 - abstract public function getFileList( array $params );
369 -
370 - /**
371377 * Returns a file system file, identical to the file at a storage path.
372378 * The file returned is either:
373379 * a) A local copy of the file at a storage path in the backend.
@@ -379,7 +385,8 @@
380386 * In that later case, there are copies of the file that must stay in sync.
381387 *
382388 * $params include:
383 - * src : source storage path
 389+ * src : source storage path
 390+ * latest : use the latest available data
384391 *
385392 * @param $params Array
386393 * @return FSFile|null Returns null on failure
@@ -392,7 +399,8 @@
393400 * Temporary files may be purged when the file object falls out of scope.
394401 *
395402 * $params include:
396 - * src : source storage path
 403+ * src : source storage path
 404+ * latest : use the latest available data
397405 *
398406 * @param $params Array
399407 * @return TempFSFile|null Returns null on failure
@@ -400,6 +408,20 @@
401409 abstract public function getLocalCopy( array $params );
402410
403411 /**
 412+ * Get an iterator to list out all object files under a storage directory.
 413+ * If the directory is of the form "mwstore://container", then all items in
 414+ * the container should be listed. If of the form "mwstore://container/dir",
 415+ * then all items under that container directory should be listed.
 416+ * Results should be storage paths relative to the given directory.
 417+ *
 418+ * $params include:
 419+ * dir : storage path directory
 420+ *
 421+ * @return Traversable|Array|null Returns null on failure
 422+ */
 423+ abstract public function getFileList( array $params );
 424+
 425+ /**
404426 * Lock the files at the given storage paths in the backend.
405427 * This will either lock all the files or none (on failure).
406428 *
@@ -700,6 +722,8 @@
701723
702724 /**
703725 * Return a list of FileOp objects from a list of operations.
 726+ * Do not call this function from places outside FileBackend.
 727+ *
704728 * The result must have the same number of items as the input.
705729 * An exception is thrown if an unsupported operation is requested.
706730 *
@@ -729,14 +753,15 @@
730754 }
731755
732756 /**
733 - * @see FileBackendBase::doOperations()
 757+ * @see FileBackendBase::doOperationsInternal()
734758 */
735 - final public function doOperations( array $ops, array $opts = array() ) {
 759+ protected function doOperationsInternal( array $ops, array $opts ) {
736760 $status = Status::newGood();
737761
738762 // Build up a list of FileOps...
739763 $performOps = $this->getOperations( $ops );
740764
 765+ // Acquire any locks as needed...
741766 if ( empty( $opts['nonLocking'] ) ) {
742767 // Build up a list of files to lock...
743768 $filesLockEx = $filesLockSh = array();

Sign-offs

UserFlagDate
Nikerabbitinspected13:43, 23 December 2011

Status & tagging log