r110269 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110268‎ | r110269 | r110270 >
Date:08:00, 30 January 2012
Author:aaron
Status:ok
Tags:filebackend 
Comment:
* r108353: Made FileBackendMultiWrite consistency checks configurable.
* Removed redundant code from r110259 and added a comment to isValidContainerName().
Modified paths:
  • /trunk/phase3/includes/filerepo/backend/FSFileBackend.php (modified) (history)
  • /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/FileBackend.php
@@ -1422,6 +1422,7 @@
14231423 final protected static function isValidContainerName( $container ) {
14241424 // This accounts for Swift and S3 restrictions while leaving room
14251425 // for things like '.xxx' (hex shard chars) or '.seg' (segments).
 1426+ // This disallows directory separators or traversal characters.
14261427 // Note that matching strings URL encode to the same string;
14271428 // in Swift, the length restriction is *after* URL encoding.
14281429 return preg_match( '/^[a-z0-9][a-z0-9-_]{0,199}$/i', $container );
Index: trunk/phase3/includes/filerepo/backend/FileBackendMultiWrite.php
@@ -24,7 +24,12 @@
2525 /** @var Array Prioritized list of FileBackendStore objects */
2626 protected $backends = array(); // array of (backend index => backends)
2727 protected $masterIndex = -1; // integer; index of master backend
 28+ protected $syncChecks = 0; // integer bitfield
2829
 30+ /* Possible internal backend consistency checks */
 31+ const CHECK_SIZE = 1;
 32+ const CHECK_TIME = 2;
 33+
2934 /**
3035 * Construct a proxy backend that consists of several internal backends.
3136 * Additional $config params include:
@@ -33,6 +38,9 @@
3439 * FileBackendStore class, but with these additional settings:
3540 * 'class' : The name of the backend class
3641 * 'isMultiMaster' : This must be set for one backend.
 42+ * 'syncChecks' : Integer bitfield of internal backend sync checks to perform.
 43+ * Possible bits include self::CHECK_SIZE and self::CHECK_TIME.
 44+ * The checks are done before allowing any file operations.
3745 * @param $config Array
3846 */
3947 public function __construct( array $config ) {
@@ -61,6 +69,9 @@
6270 if ( $this->masterIndex < 0 ) { // need backends and must have a master
6371 throw new MWException( 'No master backend defined.' );
6472 }
 73+ $this->syncChecks = isset( $config['syncChecks'] )
 74+ ? $config['syncChecks']
 75+ : self::CHECK_SIZE;
6576 }
6677
6778 /**
@@ -156,6 +167,9 @@
157168 */
158169 public function consistencyCheck( array $paths ) {
159170 $status = Status::newGood();
 171+ if ( $this->syncChecks == 0 ) {
 172+ return $status; // skip checks
 173+ }
160174
161175 $mBackend = $this->backends[$this->masterIndex];
162176 foreach ( array_unique( $paths ) as $path ) {
@@ -171,13 +185,20 @@
172186 if ( $mStat ) { // file is in master
173187 if ( !$cStat ) { // file should exist
174188 $status->fatal( 'backend-fail-synced', $path );
175 - } elseif ( $cStat['size'] != $mStat['size'] ) { // wrong size
176 - $status->fatal( 'backend-fail-synced', $path );
177 - } else {
 189+ continue;
 190+ }
 191+ if ( $this->syncChecks & self::CHECK_SIZE ) {
 192+ if ( $cStat['size'] != $mStat['size'] ) { // wrong size
 193+ $status->fatal( 'backend-fail-synced', $path );
 194+ continue;
 195+ }
 196+ }
 197+ if ( $this->syncChecks & self::CHECK_TIME ) {
178198 $mTs = wfTimestamp( TS_UNIX, $mStat['mtime'] );
179199 $cTs = wfTimestamp( TS_UNIX, $cStat['mtime'] );
180200 if ( abs( $mTs - $cTs ) > 30 ) { // outdated file somewhere
181201 $status->fatal( 'backend-fail-synced', $path );
 202+ continue;
182203 }
183204 }
184205 } else { // file is not in master
Index: trunk/phase3/includes/filerepo/backend/FSFileBackend.php
@@ -58,16 +58,6 @@
5959 }
6060
6161 /**
62 - * @see FileBackendStore::resolveContainerName()
63 - */
64 - protected function resolveContainerName( $container ) {
65 - if ( $container !== '.' ) {
66 - return $container; // container is not a traversal
67 - }
68 - return null;
69 - }
70 -
71 - /**
7262 * @see FileBackendStore::resolveContainerPath()
7363 */
7464 protected function resolveContainerPath( $container, $relStoragePath ) {

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r108353In FileBackend:...aaron08:40, 8 January 2012
r110259In FileBackendBase/FileBackend:...aaron21:28, 29 January 2012

Status & tagging log