r110073 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110072‎ | r110073 | r110074 >
Date:20:17, 26 January 2012
Author:aaron
Status:ok (Comments)
Tags:filebackend, swift 
Comment:
Further reduced RTTs in SwiftFileBackend by making "file already exists" checks use the stat cache, typically already set in FileOp::doPrecheck(). FileBackendBase::doOperationsInternal() already clears the cache after locking (and before FileOp::attemptBatch) for consistency.
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/SwiftFileBackend.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/filerepo/backend/SwiftFileBackend.php
@@ -108,13 +108,11 @@
109109 // (a) Check the destination container and object
110110 try {
111111 $dContObj = $this->getContainer( $dstCont );
112 - if ( empty( $params['overwrite'] ) ) {
113 - $destObj = $dContObj->create_object( $dstRel );
114 - // Check if the object already exists (fields populated)
115 - if ( $destObj->last_modified ) {
116 - $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
117 - return $status;
118 - }
 112+ if ( empty( $params['overwrite'] ) &&
 113+ $this->fileExists( array( 'src' => $params['dst'], 'latest' => 1 ) ) )
 114+ {
 115+ $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
 116+ return $status;
119117 }
120118 } catch ( NoSuchContainerException $e ) {
121119 $status->fatal( 'backend-fail-create', $params['dst'] );
@@ -172,13 +170,11 @@
173171 // (a) Check the destination container and object
174172 try {
175173 $dContObj = $this->getContainer( $dstCont );
176 - if ( empty( $params['overwrite'] ) ) {
177 - $destObj = $dContObj->create_object( $dstRel );
178 - // Check if the object already exists (fields populated)
179 - if ( $destObj->last_modified ) {
180 - $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
181 - return $status;
182 - }
 174+ if ( empty( $params['overwrite'] ) &&
 175+ $this->fileExists( array( 'src' => $params['dst'], 'latest' => 1 ) ) )
 176+ {
 177+ $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
 178+ return $status;
183179 }
184180 } catch ( NoSuchContainerException $e ) {
185181 $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
@@ -249,13 +245,11 @@
250246 try {
251247 $sContObj = $this->getContainer( $srcCont );
252248 $dContObj = $this->getContainer( $dstCont );
253 - if ( empty( $params['overwrite'] ) ) {
254 - $destObj = $dContObj->create_object( $dstRel );
255 - // Check if the object already exists (fields populated)
256 - if ( $destObj->last_modified ) {
257 - $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
258 - return $status;
259 - }
 249+ if ( empty( $params['overwrite'] ) &&
 250+ $this->fileExists( array( 'src' => $params['dst'], 'latest' => 1 ) ) )
 251+ {
 252+ $status->fatal( 'backend-fail-alreadyexists', $params['dst'] );
 253+ return $status;
260254 }
261255 } catch ( NoSuchContainerException $e ) {
262256 $status->fatal( 'backend-fail-copy', $params['src'], $params['dst'] );
@@ -478,13 +472,16 @@
479473 return false; // invalid storage path
480474 }
481475
 476+ if ( !$this->fileExists( $params ) ) {
 477+ return null;
 478+ }
 479+
482480 $data = false;
483481 try {
484 - $container = $this->getContainer( $srcCont );
485 - $obj = $container->get_object( $srcRel );
 482+ $sContObj = $this->getContainer( $srcCont );
 483+ $obj = new CF_Object( $sContObj, $srcRel, false, false ); // skip HEAD request
486484 $data = $obj->read( $this->headersFromParams( $params ) );
487485 } catch ( NoSuchContainerException $e ) {
488 - } catch ( NoSuchObjectException $e ) {
489486 } catch ( InvalidResponseException $e ) {
490487 } catch ( Exception $e ) { // some other exception?
491488 $this->logException( $e, __METHOD__, $params );
@@ -587,10 +584,14 @@
588585 return null;
589586 }
590587
 588+ if ( !$this->fileExists( $params ) ) {
 589+ return null;
 590+ }
 591+
591592 $tmpFile = null;
592593 try {
593 - $cont = $this->getContainer( $srcCont );
594 - $obj = $cont->get_object( $srcRel );
 594+ $sContObj = $this->getContainer( $srcCont );
 595+ $obj = new CF_Object( $sContObj, $srcRel, false, false ); // skip HEAD
595596 // Get source file extension
596597 $ext = FileBackend::extensionFromPath( $srcRel );
597598 // Create a new temporary file...
@@ -606,8 +607,6 @@
607608 }
608609 } catch ( NoSuchContainerException $e ) {
609610 $tmpFile = null;
610 - } catch ( NoSuchObjectException $e ) {
611 - $tmpFile = null;
612611 } catch ( InvalidResponseException $e ) {
613612 $tmpFile = null;
614613 } catch ( Exception $e ) { // some other exception?

Comments

#Comment by Reedy (talk | contribs)   17:29, 27 January 2012

emptyemptyemptyemptyemptyempty

#Comment by Aaron Schulz (talk | contribs)   00:02, 28 January 2012

"Empty considered useful".

#Comment by Tim Starling (talk | contribs)   03:36, 1 February 2012

Optional boolean parameters which default to false are one of the few acceptable applications of empty(). Aaron added lots of them in the FileBackend project, probably just to annoy empty-haters ;)

Status & tagging log