Made some FileBackendMultiWrite docs more accurate
[lhc/web/wiklou.git] / includes / filebackend / FileBackendMultiWrite.php
1 <?php
2 /**
3 * Proxy backend that mirrors writes to several internal backends.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup FileBackend
22 * @author Aaron Schulz
23 */
24
25 /**
26 * @brief Proxy backend that mirrors writes to several internal backends.
27 *
28 * This class defines a multi-write backend. Multiple backends can be
29 * registered to this proxy backend and it will act as a single backend.
30 * Use this when all access to those backends is through this proxy backend.
31 * At least one of the backends must be declared the "master" backend.
32 *
33 * Only use this class when transitioning from one storage system to another.
34 *
35 * Read operations are only done on the 'master' backend for consistency.
36 * Write operations are performed on all backends, starting with the master.
37 * This makes a best-effort to have transactional semantics, but since requests
38 * may sometimes fail, the use of "autoResync" or background scripts to fix
39 * inconsistencies is important.
40 *
41 * @ingroup FileBackend
42 * @since 1.19
43 */
44 class FileBackendMultiWrite extends FileBackend {
45 /** @var array Prioritized list of FileBackendStore objects.
46 * array of (backend index => backends)
47 */
48 protected $backends = array();
49
50 /** @var int Index of master backend */
51 protected $masterIndex = -1;
52
53 /** @var int Bitfield */
54 protected $syncChecks = 0;
55
56 /** @var string|bool */
57 protected $autoResync = false;
58
59 /** @var array */
60 protected $noPushDirConts = array();
61
62 /** @var bool */
63 protected $noPushQuickOps = false;
64
65 /* Possible internal backend consistency checks */
66 const CHECK_SIZE = 1;
67 const CHECK_TIME = 2;
68 const CHECK_SHA1 = 4;
69
70 /**
71 * Construct a proxy backend that consists of several internal backends.
72 * Locking, journaling, and read-only checks are handled by the proxy backend.
73 *
74 * Additional $config params include:
75 * - backends : Array of backend config and multi-backend settings.
76 * Each value is the config used in the constructor of a
77 * FileBackendStore class, but with these additional settings:
78 * - class : The name of the backend class
79 * - isMultiMaster : This must be set for one backend.
80 * - template: : If given a backend name, this will use
81 * the config of that backend as a template.
82 * Values specified here take precedence.
83 * - syncChecks : Integer bitfield of internal backend sync checks to perform.
84 * Possible bits include the FileBackendMultiWrite::CHECK_* constants.
85 * There are constants for SIZE, TIME, and SHA1.
86 * The checks are done before allowing any file operations.
87 * - autoResync : Automatically resync the clone backends to the master backend
88 * when pre-operation sync checks fail. This should only be used
89 * if the master backend is stable and not missing any files.
90 * Use "conservative" to limit resyncing to copying newer master
91 * backend files over older (or non-existing) clone backend files.
92 * Cases that cannot be handled will result in operation abortion.
93 * - noPushQuickOps : (hack) Only apply doQuickOperations() to the master backend.
94 * - noPushDirConts : (hack) Only apply directory functions to the master backend.
95 *
96 * @param array $config
97 * @throws FileBackendError
98 */
99 public function __construct( array $config ) {
100 parent::__construct( $config );
101 $this->syncChecks = isset( $config['syncChecks'] )
102 ? $config['syncChecks']
103 : self::CHECK_SIZE;
104 $this->autoResync = isset( $config['autoResync'] )
105 ? $config['autoResync']
106 : false;
107 $this->noPushQuickOps = isset( $config['noPushQuickOps'] )
108 ? $config['noPushQuickOps']
109 : false;
110 $this->noPushDirConts = isset( $config['noPushDirConts'] )
111 ? $config['noPushDirConts']
112 : array();
113 // Construct backends here rather than via registration
114 // to keep these backends hidden from outside the proxy.
115 $namesUsed = array();
116 foreach ( $config['backends'] as $index => $config ) {
117 if ( isset( $config['template'] ) ) {
118 // Config is just a modified version of a registered backend's.
119 // This should only be used when that config is used only by this backend.
120 $config = $config + FileBackendGroup::singleton()->config( $config['template'] );
121 }
122 $name = $config['name'];
123 if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates
124 throw new FileBackendError( "Two or more backends defined with the name $name." );
125 }
126 $namesUsed[$name] = 1;
127 // Alter certain sub-backend settings for sanity
128 unset( $config['readOnly'] ); // use proxy backend setting
129 unset( $config['fileJournal'] ); // use proxy backend journal
130 unset( $config['lockManager'] ); // lock under proxy backend
131 $config['wikiId'] = $this->wikiId; // use the proxy backend wiki ID
132 if ( !empty( $config['isMultiMaster'] ) ) {
133 if ( $this->masterIndex >= 0 ) {
134 throw new FileBackendError( 'More than one master backend defined.' );
135 }
136 $this->masterIndex = $index; // this is the "master"
137 $config['fileJournal'] = $this->fileJournal; // log under proxy backend
138 }
139 // Create sub-backend object
140 if ( !isset( $config['class'] ) ) {
141 throw new FileBackendError( 'No class given for a backend config.' );
142 }
143 $class = $config['class'];
144 $this->backends[$index] = new $class( $config );
145 }
146 if ( $this->masterIndex < 0 ) { // need backends and must have a master
147 throw new FileBackendError( 'No master backend defined.' );
148 }
149 }
150
151 final protected function doOperationsInternal( array $ops, array $opts ) {
152 $status = Status::newGood();
153
154 $mbe = $this->backends[$this->masterIndex]; // convenience
155
156 // Try to lock those files for the scope of this function...
157 if ( empty( $opts['nonLocking'] ) ) {
158 // Try to lock those files for the scope of this function...
159 $scopeLock = $this->getScopedLocksForOps( $ops, $status );
160 if ( !$status->isOK() ) {
161 return $status; // abort
162 }
163 }
164 // Clear any cache entries (after locks acquired)
165 $this->clearCache();
166 $opts['preserveCache'] = true; // only locked files are cached
167 // Get the list of paths to read/write...
168 $relevantPaths = $this->fileStoragePathsForOps( $ops );
169 // Check if the paths are valid and accessible on all backends...
170 $status->merge( $this->accessibilityCheck( $relevantPaths ) );
171 if ( !$status->isOK() ) {
172 return $status; // abort
173 }
174 // Do a consistency check to see if the backends are consistent...
175 $syncStatus = $this->consistencyCheck( $relevantPaths );
176 if ( !$syncStatus->isOK() ) {
177 wfDebugLog( 'FileOperation', get_class( $this ) .
178 " failed sync check: " . FormatJson::encode( $relevantPaths ) );
179 // Try to resync the clone backends to the master on the spot...
180 if ( !$this->autoResync || !$this->resyncFiles( $relevantPaths )->isOK() ) {
181 $status->merge( $syncStatus );
182
183 return $status; // abort
184 }
185 }
186 // Actually attempt the operation batch on the master backend...
187 $realOps = $this->substOpBatchPaths( $ops, $mbe );
188 $masterStatus = $mbe->doOperations( $realOps, $opts );
189 $status->merge( $masterStatus );
190 // Propagate the operations to the clone backends if there were no unexpected errors
191 // and if there were either no expected errors or if the 'force' option was used.
192 // However, if nothing succeeded at all, then don't replicate any of the operations.
193 // If $ops only had one operation, this might avoid backend sync inconsistencies.
194 if ( $masterStatus->isOK() && $masterStatus->successCount > 0 ) {
195 foreach ( $this->backends as $index => $backend ) {
196 if ( $index !== $this->masterIndex ) { // not done already
197 $realOps = $this->substOpBatchPaths( $ops, $backend );
198 $status->merge( $backend->doOperations( $realOps, $opts ) );
199 }
200 }
201 }
202 // Make 'success', 'successCount', and 'failCount' fields reflect
203 // the overall operation, rather than all the batches for each backend.
204 // Do this by only using success values from the master backend's batch.
205 $status->success = $masterStatus->success;
206 $status->successCount = $masterStatus->successCount;
207 $status->failCount = $masterStatus->failCount;
208
209 return $status;
210 }
211
212 /**
213 * Check that a set of files are consistent across all internal backends
214 *
215 * @param array $paths List of storage paths
216 * @return Status
217 */
218 public function consistencyCheck( array $paths ) {
219 $status = Status::newGood();
220 if ( $this->syncChecks == 0 || count( $this->backends ) <= 1 ) {
221 return $status; // skip checks
222 }
223
224 $mBackend = $this->backends[$this->masterIndex];
225 foreach ( $paths as $path ) {
226 $params = array( 'src' => $path, 'latest' => true );
227 $mParams = $this->substOpPaths( $params, $mBackend );
228 // Stat the file on the 'master' backend
229 $mStat = $mBackend->getFileStat( $mParams );
230 if ( $this->syncChecks & self::CHECK_SHA1 ) {
231 $mSha1 = $mBackend->getFileSha1Base36( $mParams );
232 } else {
233 $mSha1 = false;
234 }
235 // Check if all clone backends agree with the master...
236 foreach ( $this->backends as $index => $cBackend ) {
237 if ( $index === $this->masterIndex ) {
238 continue; // master
239 }
240 $cParams = $this->substOpPaths( $params, $cBackend );
241 $cStat = $cBackend->getFileStat( $cParams );
242 if ( $mStat ) { // file is in master
243 if ( !$cStat ) { // file should exist
244 $status->fatal( 'backend-fail-synced', $path );
245 continue;
246 }
247 if ( $this->syncChecks & self::CHECK_SIZE ) {
248 if ( $cStat['size'] != $mStat['size'] ) { // wrong size
249 $status->fatal( 'backend-fail-synced', $path );
250 continue;
251 }
252 }
253 if ( $this->syncChecks & self::CHECK_TIME ) {
254 $mTs = wfTimestamp( TS_UNIX, $mStat['mtime'] );
255 $cTs = wfTimestamp( TS_UNIX, $cStat['mtime'] );
256 if ( abs( $mTs - $cTs ) > 30 ) { // outdated file somewhere
257 $status->fatal( 'backend-fail-synced', $path );
258 continue;
259 }
260 }
261 if ( $this->syncChecks & self::CHECK_SHA1 ) {
262 if ( $cBackend->getFileSha1Base36( $cParams ) !== $mSha1 ) { // wrong SHA1
263 $status->fatal( 'backend-fail-synced', $path );
264 continue;
265 }
266 }
267 } else { // file is not in master
268 if ( $cStat ) { // file should not exist
269 $status->fatal( 'backend-fail-synced', $path );
270 }
271 }
272 }
273 }
274
275 return $status;
276 }
277
278 /**
279 * Check that a set of file paths are usable across all internal backends
280 *
281 * @param array $paths List of storage paths
282 * @return Status
283 */
284 public function accessibilityCheck( array $paths ) {
285 $status = Status::newGood();
286 if ( count( $this->backends ) <= 1 ) {
287 return $status; // skip checks
288 }
289
290 foreach ( $paths as $path ) {
291 foreach ( $this->backends as $backend ) {
292 $realPath = $this->substPaths( $path, $backend );
293 if ( !$backend->isPathUsableInternal( $realPath ) ) {
294 $status->fatal( 'backend-fail-usable', $path );
295 }
296 }
297 }
298
299 return $status;
300 }
301
302 /**
303 * Check that a set of files are consistent across all internal backends
304 * and re-synchronize those files against the "multi master" if needed.
305 *
306 * @param array $paths List of storage paths
307 * @return Status
308 */
309 public function resyncFiles( array $paths ) {
310 $status = Status::newGood();
311
312 $mBackend = $this->backends[$this->masterIndex];
313 foreach ( $paths as $path ) {
314 $mPath = $this->substPaths( $path, $mBackend );
315 $mSha1 = $mBackend->getFileSha1Base36( array( 'src' => $mPath, 'latest' => true ) );
316 $mStat = $mBackend->getFileStat( array( 'src' => $mPath, 'latest' => true ) );
317 if ( $mStat === null || ( $mSha1 !== false && !$mStat ) ) { // sanity
318 $status->fatal( 'backend-fail-internal', $this->name );
319 wfDebugLog( 'FileOperation', __METHOD__
320 . ': File is not available on the master backend' );
321 continue; // file is not available on the master backend...
322 }
323 // Check of all clone backends agree with the master...
324 foreach ( $this->backends as $index => $cBackend ) {
325 if ( $index === $this->masterIndex ) {
326 continue; // master
327 }
328 $cPath = $this->substPaths( $path, $cBackend );
329 $cSha1 = $cBackend->getFileSha1Base36( array( 'src' => $cPath, 'latest' => true ) );
330 $cStat = $cBackend->getFileStat( array( 'src' => $cPath, 'latest' => true ) );
331 if ( $cStat === null || ( $cSha1 !== false && !$cStat ) ) { // sanity
332 $status->fatal( 'backend-fail-internal', $cBackend->getName() );
333 wfDebugLog( 'FileOperation', __METHOD__ .
334 ': File is not available on the clone backend' );
335 continue; // file is not available on the clone backend...
336 }
337 if ( $mSha1 === $cSha1 ) {
338 // already synced; nothing to do
339 } elseif ( $mSha1 !== false ) { // file is in master
340 if ( $this->autoResync === 'conservative'
341 && $cStat && $cStat['mtime'] > $mStat['mtime']
342 ) {
343 $status->fatal( 'backend-fail-synced', $path );
344 continue; // don't rollback data
345 }
346 $fsFile = $mBackend->getLocalReference(
347 array( 'src' => $mPath, 'latest' => true ) );
348 $status->merge( $cBackend->quickStore(
349 array( 'src' => $fsFile->getPath(), 'dst' => $cPath )
350 ) );
351 } elseif ( $mStat === false ) { // file is not in master
352 if ( $this->autoResync === 'conservative' ) {
353 $status->fatal( 'backend-fail-synced', $path );
354 continue; // don't delete data
355 }
356 $status->merge( $cBackend->quickDelete( array( 'src' => $cPath ) ) );
357 }
358 }
359 }
360
361 return $status;
362 }
363
364 /**
365 * Get a list of file storage paths to read or write for a list of operations
366 *
367 * @param array $ops Same format as doOperations()
368 * @return array List of storage paths to files (does not include directories)
369 */
370 protected function fileStoragePathsForOps( array $ops ) {
371 $paths = array();
372 foreach ( $ops as $op ) {
373 if ( isset( $op['src'] ) ) {
374 // For things like copy/move/delete with "ignoreMissingSource" and there
375 // is no source file, nothing should happen and there should be no errors.
376 if ( empty( $op['ignoreMissingSource'] )
377 || $this->fileExists( array( 'src' => $op['src'] ) )
378 ) {
379 $paths[] = $op['src'];
380 }
381 }
382 if ( isset( $op['srcs'] ) ) {
383 $paths = array_merge( $paths, $op['srcs'] );
384 }
385 if ( isset( $op['dst'] ) ) {
386 $paths[] = $op['dst'];
387 }
388 }
389
390 return array_values( array_unique( array_filter( $paths, 'FileBackend::isStoragePath' ) ) );
391 }
392
393 /**
394 * Substitute the backend name in storage path parameters
395 * for a set of operations with that of a given internal backend.
396 *
397 * @param array $ops List of file operation arrays
398 * @param FileBackendStore $backend
399 * @return array
400 */
401 protected function substOpBatchPaths( array $ops, FileBackendStore $backend ) {
402 $newOps = array(); // operations
403 foreach ( $ops as $op ) {
404 $newOp = $op; // operation
405 foreach ( array( 'src', 'srcs', 'dst', 'dir' ) as $par ) {
406 if ( isset( $newOp[$par] ) ) { // string or array
407 $newOp[$par] = $this->substPaths( $newOp[$par], $backend );
408 }
409 }
410 $newOps[] = $newOp;
411 }
412
413 return $newOps;
414 }
415
416 /**
417 * Same as substOpBatchPaths() but for a single operation
418 *
419 * @param array $ops File operation array
420 * @param FileBackendStore $backend
421 * @return array
422 */
423 protected function substOpPaths( array $ops, FileBackendStore $backend ) {
424 $newOps = $this->substOpBatchPaths( array( $ops ), $backend );
425
426 return $newOps[0];
427 }
428
429 /**
430 * Substitute the backend of storage paths with an internal backend's name
431 *
432 * @param array|string $paths List of paths or single string path
433 * @param FileBackendStore $backend
434 * @return array|string
435 */
436 protected function substPaths( $paths, FileBackendStore $backend ) {
437 return preg_replace(
438 '!^mwstore://' . preg_quote( $this->name, '!' ) . '/!',
439 StringUtils::escapeRegexReplacement( "mwstore://{$backend->getName()}/" ),
440 $paths // string or array
441 );
442 }
443
444 /**
445 * Substitute the backend of internal storage paths with the proxy backend's name
446 *
447 * @param array|string $paths List of paths or single string path
448 * @return array|string
449 */
450 protected function unsubstPaths( $paths ) {
451 return preg_replace(
452 '!^mwstore://([^/]+)!',
453 StringUtils::escapeRegexReplacement( "mwstore://{$this->name}" ),
454 $paths // string or array
455 );
456 }
457
458 protected function doQuickOperationsInternal( array $ops ) {
459 $status = Status::newGood();
460 // Do the operations on the master backend; setting Status fields...
461 $realOps = $this->substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
462 $masterStatus = $this->backends[$this->masterIndex]->doQuickOperations( $realOps );
463 $status->merge( $masterStatus );
464 // Propagate the operations to the clone backends...
465 if ( !$this->noPushQuickOps ) {
466 foreach ( $this->backends as $index => $backend ) {
467 if ( $index !== $this->masterIndex ) { // not done already
468 $realOps = $this->substOpBatchPaths( $ops, $backend );
469 $status->merge( $backend->doQuickOperations( $realOps ) );
470 }
471 }
472 }
473 // Make 'success', 'successCount', and 'failCount' fields reflect
474 // the overall operation, rather than all the batches for each backend.
475 // Do this by only using success values from the master backend's batch.
476 $status->success = $masterStatus->success;
477 $status->successCount = $masterStatus->successCount;
478 $status->failCount = $masterStatus->failCount;
479
480 return $status;
481 }
482
483 /**
484 * @param string $path Storage path
485 * @return bool Path container should have dir changes pushed to all backends
486 */
487 protected function replicateContainerDirChanges( $path ) {
488 list( , $shortCont, ) = self::splitStoragePath( $path );
489
490 return !in_array( $shortCont, $this->noPushDirConts );
491 }
492
493 protected function doPrepare( array $params ) {
494 $status = Status::newGood();
495 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
496 foreach ( $this->backends as $index => $backend ) {
497 if ( $replicate || $index == $this->masterIndex ) {
498 $realParams = $this->substOpPaths( $params, $backend );
499 $status->merge( $backend->doPrepare( $realParams ) );
500 }
501 }
502
503 return $status;
504 }
505
506 protected function doSecure( array $params ) {
507 $status = Status::newGood();
508 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
509 foreach ( $this->backends as $index => $backend ) {
510 if ( $replicate || $index == $this->masterIndex ) {
511 $realParams = $this->substOpPaths( $params, $backend );
512 $status->merge( $backend->doSecure( $realParams ) );
513 }
514 }
515
516 return $status;
517 }
518
519 protected function doPublish( array $params ) {
520 $status = Status::newGood();
521 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
522 foreach ( $this->backends as $index => $backend ) {
523 if ( $replicate || $index == $this->masterIndex ) {
524 $realParams = $this->substOpPaths( $params, $backend );
525 $status->merge( $backend->doPublish( $realParams ) );
526 }
527 }
528
529 return $status;
530 }
531
532 protected function doClean( array $params ) {
533 $status = Status::newGood();
534 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
535 foreach ( $this->backends as $index => $backend ) {
536 if ( $replicate || $index == $this->masterIndex ) {
537 $realParams = $this->substOpPaths( $params, $backend );
538 $status->merge( $backend->doClean( $realParams ) );
539 }
540 }
541
542 return $status;
543 }
544
545 public function concatenate( array $params ) {
546 // We are writing to an FS file, so we don't need to do this per-backend
547 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
548
549 return $this->backends[$this->masterIndex]->concatenate( $realParams );
550 }
551
552 public function fileExists( array $params ) {
553 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
554
555 return $this->backends[$this->masterIndex]->fileExists( $realParams );
556 }
557
558 public function getFileTimestamp( array $params ) {
559 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
560
561 return $this->backends[$this->masterIndex]->getFileTimestamp( $realParams );
562 }
563
564 public function getFileSize( array $params ) {
565 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
566
567 return $this->backends[$this->masterIndex]->getFileSize( $realParams );
568 }
569
570 public function getFileStat( array $params ) {
571 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
572
573 return $this->backends[$this->masterIndex]->getFileStat( $realParams );
574 }
575
576 public function getFileXAttributes( array $params ) {
577 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
578
579 return $this->backends[$this->masterIndex]->getFileXAttributes( $realParams );
580 }
581
582 public function getFileContentsMulti( array $params ) {
583 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
584 $contentsM = $this->backends[$this->masterIndex]->getFileContentsMulti( $realParams );
585
586 $contents = array(); // (path => FSFile) mapping using the proxy backend's name
587 foreach ( $contentsM as $path => $data ) {
588 $contents[$this->unsubstPaths( $path )] = $data;
589 }
590
591 return $contents;
592 }
593
594 public function getFileSha1Base36( array $params ) {
595 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
596
597 return $this->backends[$this->masterIndex]->getFileSha1Base36( $realParams );
598 }
599
600 public function getFileProps( array $params ) {
601 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
602
603 return $this->backends[$this->masterIndex]->getFileProps( $realParams );
604 }
605
606 public function streamFile( array $params ) {
607 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
608
609 return $this->backends[$this->masterIndex]->streamFile( $realParams );
610 }
611
612 public function getLocalReferenceMulti( array $params ) {
613 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
614 $fsFilesM = $this->backends[$this->masterIndex]->getLocalReferenceMulti( $realParams );
615
616 $fsFiles = array(); // (path => FSFile) mapping using the proxy backend's name
617 foreach ( $fsFilesM as $path => $fsFile ) {
618 $fsFiles[$this->unsubstPaths( $path )] = $fsFile;
619 }
620
621 return $fsFiles;
622 }
623
624 public function getLocalCopyMulti( array $params ) {
625 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
626 $tempFilesM = $this->backends[$this->masterIndex]->getLocalCopyMulti( $realParams );
627
628 $tempFiles = array(); // (path => TempFSFile) mapping using the proxy backend's name
629 foreach ( $tempFilesM as $path => $tempFile ) {
630 $tempFiles[$this->unsubstPaths( $path )] = $tempFile;
631 }
632
633 return $tempFiles;
634 }
635
636 public function getFileHttpUrl( array $params ) {
637 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
638
639 return $this->backends[$this->masterIndex]->getFileHttpUrl( $realParams );
640 }
641
642 public function directoryExists( array $params ) {
643 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
644
645 return $this->backends[$this->masterIndex]->directoryExists( $realParams );
646 }
647
648 public function getDirectoryList( array $params ) {
649 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
650
651 return $this->backends[$this->masterIndex]->getDirectoryList( $realParams );
652 }
653
654 public function getFileList( array $params ) {
655 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
656
657 return $this->backends[$this->masterIndex]->getFileList( $realParams );
658 }
659
660 public function getFeatures() {
661 return $this->backends[$this->masterIndex]->getFeatures();
662 }
663
664 public function clearCache( array $paths = null ) {
665 foreach ( $this->backends as $backend ) {
666 $realPaths = is_array( $paths ) ? $this->substPaths( $paths, $backend ) : null;
667 $backend->clearCache( $realPaths );
668 }
669 }
670
671 public function preloadCache( array $paths ) {
672 $realPaths = $this->substPaths( $paths, $this->backends[$this->masterIndex] );
673 $this->backends[$this->masterIndex]->preloadCache( $realPaths );
674 }
675
676 public function preloadFileStat( array $params ) {
677 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
678 return $this->backends[$this->masterIndex]->preloadFileStat( $realParams );
679 }
680
681 public function getScopedLocksForOps( array $ops, Status $status ) {
682 $realOps = $this->substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
683 $fileOps = $this->backends[$this->masterIndex]->getOperationsInternal( $realOps );
684 // Get the paths to lock from the master backend
685 $paths = $this->backends[$this->masterIndex]->getPathsToLockForOpsInternal( $fileOps );
686 // Get the paths under the proxy backend's name
687 $pbPaths = array(
688 LockManager::LOCK_UW => $this->unsubstPaths( $paths[LockManager::LOCK_UW] ),
689 LockManager::LOCK_EX => $this->unsubstPaths( $paths[LockManager::LOCK_EX] )
690 );
691
692 // Actually acquire the locks
693 return array( $this->getScopedFileLocks( $pbPaths, 'mixed', $status ) );
694 }
695 }