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