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