Merge "Kill 'newmessageslink' and 'newmessagesdifflink' messages"
[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 return $status; // abort
171 }
172 }
173 // Actually attempt the operation batch on the master backend...
174 $realOps = $this->substOpBatchPaths( $ops, $mbe );
175 $masterStatus = $mbe->doOperations( $realOps, $opts );
176 $status->merge( $masterStatus );
177 // Propagate the operations to the clone backends if there were no unexpected errors
178 // and if there were either no expected errors or if the 'force' option was used.
179 // However, if nothing succeeded at all, then don't replicate any of the operations.
180 // If $ops only had one operation, this might avoid backend sync inconsistencies.
181 if ( $masterStatus->isOK() && $masterStatus->successCount > 0 ) {
182 foreach ( $this->backends as $index => $backend ) {
183 if ( $index !== $this->masterIndex ) { // not done already
184 $realOps = $this->substOpBatchPaths( $ops, $backend );
185 $status->merge( $backend->doOperations( $realOps, $opts ) );
186 }
187 }
188 }
189 // Make 'success', 'successCount', and 'failCount' fields reflect
190 // the overall operation, rather than all the batches for each backend.
191 // Do this by only using success values from the master backend's batch.
192 $status->success = $masterStatus->success;
193 $status->successCount = $masterStatus->successCount;
194 $status->failCount = $masterStatus->failCount;
195
196 return $status;
197 }
198
199 /**
200 * Check that a set of files are consistent across all internal backends
201 *
202 * @param array $paths List of storage paths
203 * @return Status
204 */
205 public function consistencyCheck( array $paths ) {
206 $status = Status::newGood();
207 if ( $this->syncChecks == 0 || count( $this->backends ) <= 1 ) {
208 return $status; // skip checks
209 }
210
211 $mBackend = $this->backends[$this->masterIndex];
212 foreach ( $paths as $path ) {
213 $params = array( 'src' => $path, 'latest' => true );
214 $mParams = $this->substOpPaths( $params, $mBackend );
215 // Stat the file on the 'master' backend
216 $mStat = $mBackend->getFileStat( $mParams );
217 if ( $this->syncChecks & self::CHECK_SHA1 ) {
218 $mSha1 = $mBackend->getFileSha1Base36( $mParams );
219 } else {
220 $mSha1 = false;
221 }
222 // Check if all clone backends agree with the master...
223 foreach ( $this->backends as $index => $cBackend ) {
224 if ( $index === $this->masterIndex ) {
225 continue; // master
226 }
227 $cParams = $this->substOpPaths( $params, $cBackend );
228 $cStat = $cBackend->getFileStat( $cParams );
229 if ( $mStat ) { // file is in master
230 if ( !$cStat ) { // file should exist
231 $status->fatal( 'backend-fail-synced', $path );
232 continue;
233 }
234 if ( $this->syncChecks & self::CHECK_SIZE ) {
235 if ( $cStat['size'] != $mStat['size'] ) { // wrong size
236 $status->fatal( 'backend-fail-synced', $path );
237 continue;
238 }
239 }
240 if ( $this->syncChecks & self::CHECK_TIME ) {
241 $mTs = wfTimestamp( TS_UNIX, $mStat['mtime'] );
242 $cTs = wfTimestamp( TS_UNIX, $cStat['mtime'] );
243 if ( abs( $mTs - $cTs ) > 30 ) { // outdated file somewhere
244 $status->fatal( 'backend-fail-synced', $path );
245 continue;
246 }
247 }
248 if ( $this->syncChecks & self::CHECK_SHA1 ) {
249 if ( $cBackend->getFileSha1Base36( $cParams ) !== $mSha1 ) { // wrong SHA1
250 $status->fatal( 'backend-fail-synced', $path );
251 continue;
252 }
253 }
254 } else { // file is not in master
255 if ( $cStat ) { // file should not exist
256 $status->fatal( 'backend-fail-synced', $path );
257 }
258 }
259 }
260 }
261
262 return $status;
263 }
264
265 /**
266 * Check that a set of file paths are usable across all internal backends
267 *
268 * @param array $paths List of storage paths
269 * @return Status
270 */
271 public function accessibilityCheck( array $paths ) {
272 $status = Status::newGood();
273 if ( count( $this->backends ) <= 1 ) {
274 return $status; // skip checks
275 }
276
277 foreach ( $paths as $path ) {
278 foreach ( $this->backends as $backend ) {
279 $realPath = $this->substPaths( $path, $backend );
280 if ( !$backend->isPathUsableInternal( $realPath ) ) {
281 $status->fatal( 'backend-fail-usable', $path );
282 }
283 }
284 }
285
286 return $status;
287 }
288
289 /**
290 * Check that a set of files are consistent across all internal backends
291 * and re-synchronize those files againt the "multi master" if needed.
292 *
293 * @param array $paths List of storage paths
294 * @return Status
295 */
296 public function resyncFiles( array $paths ) {
297 $status = Status::newGood();
298
299 $mBackend = $this->backends[$this->masterIndex];
300 foreach ( $paths as $path ) {
301 $mPath = $this->substPaths( $path, $mBackend );
302 $mSha1 = $mBackend->getFileSha1Base36( array( 'src' => $mPath, 'latest' => true ) );
303 $mStat = $mBackend->getFileStat( array( 'src' => $mPath, 'latest' => true ) );
304 if ( $mStat === null || ( $mSha1 !== false && !$mStat ) ) { // sanity
305 $status->fatal( 'backend-fail-internal', $this->name );
306 continue; // file is not available on the master backend...
307 }
308 // Check of all clone backends agree with the master...
309 foreach ( $this->backends as $index => $cBackend ) {
310 if ( $index === $this->masterIndex ) {
311 continue; // master
312 }
313 $cPath = $this->substPaths( $path, $cBackend );
314 $cSha1 = $cBackend->getFileSha1Base36( array( 'src' => $cPath, 'latest' => true ) );
315 $cStat = $cBackend->getFileStat( array( 'src' => $cPath, 'latest' => true ) );
316 if ( $cStat === null || ( $cSha1 !== false && !$cStat ) ) { // sanity
317 $status->fatal( 'backend-fail-internal', $cBackend->getName() );
318 continue; // file is not available on the clone backend...
319 }
320 if ( $mSha1 === $cSha1 ) {
321 // already synced; nothing to do
322 } elseif ( $mSha1 !== false ) { // file is in master
323 if ( $this->autoResync === 'conservative'
324 && $cStat && $cStat['mtime'] > $mStat['mtime'] )
325 {
326 $status->fatal( 'backend-fail-synced', $path );
327 continue; // don't rollback data
328 }
329 $fsFile = $mBackend->getLocalReference(
330 array( 'src' => $mPath, 'latest' => true ) );
331 $status->merge( $cBackend->quickStore(
332 array( 'src' => $fsFile->getPath(), 'dst' => $cPath )
333 ) );
334 } elseif ( $mStat === false ) { // file is not in master
335 if ( $this->autoResync === 'conservative' ) {
336 $status->fatal( 'backend-fail-synced', $path );
337 continue; // don't delete data
338 }
339 $status->merge( $cBackend->quickDelete( array( 'src' => $cPath ) ) );
340 }
341 }
342 }
343
344 return $status;
345 }
346
347 /**
348 * Get a list of file storage paths to read or write for a list of operations
349 *
350 * @param array $ops Same format as doOperations()
351 * @return Array List of storage paths to files (does not include directories)
352 */
353 protected function fileStoragePathsForOps( array $ops ) {
354 $paths = array();
355 foreach ( $ops as $op ) {
356 if ( isset( $op['src'] ) ) {
357 // For things like copy/move/delete with "ignoreMissingSource" and there
358 // is no source file, nothing should happen and there should be no errors.
359 if ( empty( $op['ignoreMissingSource'] )
360 || $this->fileExists( array( 'src' => $op['src'] ) ) )
361 {
362 $paths[] = $op['src'];
363 }
364 }
365 if ( isset( $op['srcs'] ) ) {
366 $paths = array_merge( $paths, $op['srcs'] );
367 }
368 if ( isset( $op['dst'] ) ) {
369 $paths[] = $op['dst'];
370 }
371 }
372 return array_values( array_unique( array_filter( $paths, 'FileBackend::isStoragePath' ) ) );
373 }
374
375 /**
376 * Substitute the backend name in storage path parameters
377 * for a set of operations with that of a given internal backend.
378 *
379 * @param array $ops List of file operation arrays
380 * @param FileBackendStore $backend
381 * @return Array
382 */
383 protected function substOpBatchPaths( array $ops, FileBackendStore $backend ) {
384 $newOps = array(); // operations
385 foreach ( $ops as $op ) {
386 $newOp = $op; // operation
387 foreach ( array( 'src', 'srcs', 'dst', 'dir' ) as $par ) {
388 if ( isset( $newOp[$par] ) ) { // string or array
389 $newOp[$par] = $this->substPaths( $newOp[$par], $backend );
390 }
391 }
392 $newOps[] = $newOp;
393 }
394 return $newOps;
395 }
396
397 /**
398 * Same as substOpBatchPaths() but for a single operation
399 *
400 * @param array $ops File operation array
401 * @param FileBackendStore $backend
402 * @return Array
403 */
404 protected function substOpPaths( array $ops, FileBackendStore $backend ) {
405 $newOps = $this->substOpBatchPaths( array( $ops ), $backend );
406 return $newOps[0];
407 }
408
409 /**
410 * Substitute the backend of storage paths with an internal backend's name
411 *
412 * @param array|string $paths List of paths or single string path
413 * @param FileBackendStore $backend
414 * @return Array|string
415 */
416 protected function substPaths( $paths, FileBackendStore $backend ) {
417 return preg_replace(
418 '!^mwstore://' . preg_quote( $this->name ) . '/!',
419 StringUtils::escapeRegexReplacement( "mwstore://{$backend->getName()}/" ),
420 $paths // string or array
421 );
422 }
423
424 /**
425 * Substitute the backend of internal storage paths with the proxy backend's name
426 *
427 * @param array|string $paths List of paths or single string path
428 * @return Array|string
429 */
430 protected function unsubstPaths( $paths ) {
431 return preg_replace(
432 '!^mwstore://([^/]+)!',
433 StringUtils::escapeRegexReplacement( "mwstore://{$this->name}" ),
434 $paths // string or array
435 );
436 }
437
438 protected function doQuickOperationsInternal( array $ops ) {
439 $status = Status::newGood();
440 // Do the operations on the master backend; setting Status fields...
441 $realOps = $this->substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
442 $masterStatus = $this->backends[$this->masterIndex]->doQuickOperations( $realOps );
443 $status->merge( $masterStatus );
444 // Propagate the operations to the clone backends...
445 if ( !$this->noPushQuickOps ) {
446 foreach ( $this->backends as $index => $backend ) {
447 if ( $index !== $this->masterIndex ) { // not done already
448 $realOps = $this->substOpBatchPaths( $ops, $backend );
449 $status->merge( $backend->doQuickOperations( $realOps ) );
450 }
451 }
452 }
453 // Make 'success', 'successCount', and 'failCount' fields reflect
454 // the overall operation, rather than all the batches for each backend.
455 // Do this by only using success values from the master backend's batch.
456 $status->success = $masterStatus->success;
457 $status->successCount = $masterStatus->successCount;
458 $status->failCount = $masterStatus->failCount;
459 return $status;
460 }
461
462 /**
463 * @param string $path Storage path
464 * @return bool Path container should have dir changes pushed to all backends
465 */
466 protected function replicateContainerDirChanges( $path ) {
467 list( , $shortCont, ) = self::splitStoragePath( $path );
468 return !in_array( $shortCont, $this->noPushDirConts );
469 }
470
471 protected function doPrepare( array $params ) {
472 $status = Status::newGood();
473 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
474 foreach ( $this->backends as $index => $backend ) {
475 if ( $replicate || $index == $this->masterIndex ) {
476 $realParams = $this->substOpPaths( $params, $backend );
477 $status->merge( $backend->doPrepare( $realParams ) );
478 }
479 }
480 return $status;
481 }
482
483 protected function doSecure( array $params ) {
484 $status = Status::newGood();
485 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
486 foreach ( $this->backends as $index => $backend ) {
487 if ( $replicate || $index == $this->masterIndex ) {
488 $realParams = $this->substOpPaths( $params, $backend );
489 $status->merge( $backend->doSecure( $realParams ) );
490 }
491 }
492 return $status;
493 }
494
495 protected function doPublish( array $params ) {
496 $status = Status::newGood();
497 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
498 foreach ( $this->backends as $index => $backend ) {
499 if ( $replicate || $index == $this->masterIndex ) {
500 $realParams = $this->substOpPaths( $params, $backend );
501 $status->merge( $backend->doPublish( $realParams ) );
502 }
503 }
504 return $status;
505 }
506
507 protected function doClean( array $params ) {
508 $status = Status::newGood();
509 $replicate = $this->replicateContainerDirChanges( $params['dir'] );
510 foreach ( $this->backends as $index => $backend ) {
511 if ( $replicate || $index == $this->masterIndex ) {
512 $realParams = $this->substOpPaths( $params, $backend );
513 $status->merge( $backend->doClean( $realParams ) );
514 }
515 }
516 return $status;
517 }
518
519 public function concatenate( array $params ) {
520 // We are writing to an FS file, so we don't need to do this per-backend
521 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
522 return $this->backends[$this->masterIndex]->concatenate( $realParams );
523 }
524
525 public function fileExists( array $params ) {
526 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
527 return $this->backends[$this->masterIndex]->fileExists( $realParams );
528 }
529
530 public function getFileTimestamp( array $params ) {
531 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
532 return $this->backends[$this->masterIndex]->getFileTimestamp( $realParams );
533 }
534
535 public function getFileSize( array $params ) {
536 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
537 return $this->backends[$this->masterIndex]->getFileSize( $realParams );
538 }
539
540 public function getFileStat( array $params ) {
541 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
542 return $this->backends[$this->masterIndex]->getFileStat( $realParams );
543 }
544
545 public function getFileContentsMulti( array $params ) {
546 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
547 $contentsM = $this->backends[$this->masterIndex]->getFileContentsMulti( $realParams );
548
549 $contents = array(); // (path => FSFile) mapping using the proxy backend's name
550 foreach ( $contentsM as $path => $data ) {
551 $contents[$this->unsubstPaths( $path )] = $data;
552 }
553 return $contents;
554 }
555
556 public function getFileSha1Base36( array $params ) {
557 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
558 return $this->backends[$this->masterIndex]->getFileSha1Base36( $realParams );
559 }
560
561 public function getFileProps( array $params ) {
562 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
563 return $this->backends[$this->masterIndex]->getFileProps( $realParams );
564 }
565
566 public function streamFile( array $params ) {
567 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
568 return $this->backends[$this->masterIndex]->streamFile( $realParams );
569 }
570
571 public function getLocalReferenceMulti( array $params ) {
572 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
573 $fsFilesM = $this->backends[$this->masterIndex]->getLocalReferenceMulti( $realParams );
574
575 $fsFiles = array(); // (path => FSFile) mapping using the proxy backend's name
576 foreach ( $fsFilesM as $path => $fsFile ) {
577 $fsFiles[$this->unsubstPaths( $path )] = $fsFile;
578 }
579 return $fsFiles;
580 }
581
582 public function getLocalCopyMulti( array $params ) {
583 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
584 $tempFilesM = $this->backends[$this->masterIndex]->getLocalCopyMulti( $realParams );
585
586 $tempFiles = array(); // (path => TempFSFile) mapping using the proxy backend's name
587 foreach ( $tempFilesM as $path => $tempFile ) {
588 $tempFiles[$this->unsubstPaths( $path )] = $tempFile;
589 }
590 return $tempFiles;
591 }
592
593 public function getFileHttpUrl( array $params ) {
594 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
595 return $this->backends[$this->masterIndex]->getFileHttpUrl( $realParams );
596 }
597
598 public function directoryExists( array $params ) {
599 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
600 return $this->backends[$this->masterIndex]->directoryExists( $realParams );
601 }
602
603 public function getDirectoryList( array $params ) {
604 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
605 return $this->backends[$this->masterIndex]->getDirectoryList( $realParams );
606 }
607
608 public function getFileList( array $params ) {
609 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
610 return $this->backends[$this->masterIndex]->getFileList( $realParams );
611 }
612
613 public function clearCache( array $paths = null ) {
614 foreach ( $this->backends as $backend ) {
615 $realPaths = is_array( $paths ) ? $this->substPaths( $paths, $backend ) : null;
616 $backend->clearCache( $realPaths );
617 }
618 }
619
620 public function getScopedLocksForOps( array $ops, Status $status ) {
621 $realOps = $this->substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
622 $fileOps = $this->backends[$this->masterIndex]->getOperationsInternal( $realOps );
623 // Get the paths to lock from the master backend
624 $paths = $this->backends[$this->masterIndex]->getPathsToLockForOpsInternal( $fileOps );
625 // Get the paths under the proxy backend's name
626 $pbPaths = array(
627 LockManager::LOCK_UW => $this->unsubstPaths( $paths[LockManager::LOCK_UW] ),
628 LockManager::LOCK_EX => $this->unsubstPaths( $paths[LockManager::LOCK_EX] )
629 );
630 // Actually acquire the locks
631 return array( $this->getScopedFileLocks( $pbPaths, 'mixed', $status ) );
632 }
633 }