3 * Proxy backend that mirrors writes to several internal backends.
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.
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.
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
21 * @ingroup FileBackend
25 * @brief Proxy backend that mirrors writes to several internal backends.
27 * This class defines a multi-write backend. Multiple backends can be
28 * registered to this proxy backend and it will act as a single backend.
29 * Use this when all access to those backends is through this proxy backend.
30 * At least one of the backends must be declared the "master" backend.
32 * Only use this class when transitioning from one storage system to another.
34 * Read operations are only done on the 'master' backend for consistency.
35 * Write operations are performed on all backends, starting with the master.
36 * This makes a best-effort to have transactional semantics, but since requests
37 * may sometimes fail, the use of "autoResync" or background scripts to fix
38 * inconsistencies is important.
40 * @ingroup FileBackend
43 class FileBackendMultiWrite
extends FileBackend
{
44 /** @var FileBackendStore[] Prioritized list of FileBackendStore objects */
45 protected $backends = [];
47 /** @var int Index of master backend */
48 protected $masterIndex = -1;
49 /** @var int Index of read affinity backend */
50 protected $readIndex = -1;
52 /** @var int Bitfield */
53 protected $syncChecks = 0;
54 /** @var string|bool */
55 protected $autoResync = false;
58 protected $asyncWrites = false;
60 /* Possible internal backend consistency checks */
66 * Construct a proxy backend that consists of several internal backends.
67 * Locking, journaling, and read-only checks are handled by the proxy backend.
69 * Additional $config params include:
70 * - backends : Array of backend config and multi-backend settings.
71 * Each value is the config used in the constructor of a
72 * FileBackendStore class, but with these additional settings:
73 * - class : The name of the backend class
74 * - isMultiMaster : This must be set for one backend.
75 * - readAffinity : Use this for reads without 'latest' set.
76 * - syncChecks : Integer bitfield of internal backend sync checks to perform.
77 * Possible bits include the FileBackendMultiWrite::CHECK_* constants.
78 * There are constants for SIZE, TIME, and SHA1.
79 * The checks are done before allowing any file operations.
80 * - autoResync : Automatically resync the clone backends to the master backend
81 * when pre-operation sync checks fail. This should only be used
82 * if the master backend is stable and not missing any files.
83 * Use "conservative" to limit resyncing to copying newer master
84 * backend files over older (or non-existing) clone backend files.
85 * Cases that cannot be handled will result in operation abortion.
86 * - replication : Set to 'async' to defer file operations on the non-master backends.
87 * This will apply such updates post-send for web requests. Note that
88 * any checks from "syncChecks" are still synchronous.
90 * @param array $config
91 * @throws FileBackendError
93 public function __construct( array $config ) {
94 parent
::__construct( $config );
95 $this->syncChecks
= isset( $config['syncChecks'] )
96 ?
$config['syncChecks']
98 $this->autoResync
= isset( $config['autoResync'] )
99 ?
$config['autoResync']
101 $this->asyncWrites
= isset( $config['replication'] ) && $config['replication'] === 'async';
102 // Construct backends here rather than via registration
103 // to keep these backends hidden from outside the proxy.
105 foreach ( $config['backends'] as $index => $config ) {
106 $name = $config['name'];
107 if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates
108 throw new LogicException( "Two or more backends defined with the name $name." );
110 $namesUsed[$name] = 1;
111 // Alter certain sub-backend settings for sanity
112 unset( $config['readOnly'] ); // use proxy backend setting
113 unset( $config['fileJournal'] ); // use proxy backend journal
114 unset( $config['lockManager'] ); // lock under proxy backend
115 $config['domainId'] = $this->domainId
; // use the proxy backend wiki ID
116 if ( !empty( $config['isMultiMaster'] ) ) {
117 if ( $this->masterIndex
>= 0 ) {
118 throw new LogicException( 'More than one master backend defined.' );
120 $this->masterIndex
= $index; // this is the "master"
121 $config['fileJournal'] = $this->fileJournal
; // log under proxy backend
123 if ( !empty( $config['readAffinity'] ) ) {
124 $this->readIndex
= $index; // prefer this for reads
126 // Create sub-backend object
127 if ( !isset( $config['class'] ) ) {
128 throw new InvalidArgumentException( 'No class given for a backend config.' );
130 $class = $config['class'];
131 $this->backends
[$index] = new $class( $config );
133 if ( $this->masterIndex
< 0 ) { // need backends and must have a master
134 throw new LogicException( 'No master backend defined.' );
136 if ( $this->readIndex
< 0 ) {
137 $this->readIndex
= $this->masterIndex
; // default
141 final protected function doOperationsInternal( array $ops, array $opts ) {
142 $status = $this->newStatus();
144 $mbe = $this->backends
[$this->masterIndex
]; // convenience
146 // Try to lock those files for the scope of this function...
148 if ( empty( $opts['nonLocking'] ) ) {
149 // Try to lock those files for the scope of this function...
150 /** @noinspection PhpUnusedLocalVariableInspection */
151 $scopeLock = $this->getScopedLocksForOps( $ops, $status );
152 if ( !$status->isOK() ) {
153 return $status; // abort
156 // Clear any cache entries (after locks acquired)
158 $opts['preserveCache'] = true; // only locked files are cached
159 // Get the list of paths to read/write...
160 $relevantPaths = $this->fileStoragePathsForOps( $ops );
161 // Check if the paths are valid and accessible on all backends...
162 $status->merge( $this->accessibilityCheck( $relevantPaths ) );
163 if ( !$status->isOK() ) {
164 return $status; // abort
166 // Do a consistency check to see if the backends are consistent...
167 $syncStatus = $this->consistencyCheck( $relevantPaths );
168 if ( !$syncStatus->isOK() ) {
169 wfDebugLog( 'FileOperation', static::class .
170 " failed sync check: " . FormatJson
::encode( $relevantPaths ) );
171 // Try to resync the clone backends to the master on the spot...
172 if ( $this->autoResync
=== false
173 ||
!$this->resyncFiles( $relevantPaths, $this->autoResync
)->isOK()
175 $status->merge( $syncStatus );
177 return $status; // abort
180 // Actually attempt the operation batch on the master backend...
181 $realOps = $this->substOpBatchPaths( $ops, $mbe );
182 $masterStatus = $mbe->doOperations( $realOps, $opts );
183 $status->merge( $masterStatus );
184 // Propagate the operations to the clone backends if there were no unexpected errors
185 // and if there were either no expected errors or if the 'force' option was used.
186 // However, if nothing succeeded at all, then don't replicate any of the operations.
187 // If $ops only had one operation, this might avoid backend sync inconsistencies.
188 if ( $masterStatus->isOK() && $masterStatus->successCount
> 0 ) {
189 foreach ( $this->backends
as $index => $backend ) {
190 if ( $index === $this->masterIndex
) {
191 continue; // done already
194 $realOps = $this->substOpBatchPaths( $ops, $backend );
195 if ( $this->asyncWrites
&& !$this->hasVolatileSources( $ops ) ) {
196 // Bind $scopeLock to the callback to preserve locks
197 DeferredUpdates
::addCallableUpdate(
198 function () use ( $backend, $realOps, $opts, $scopeLock, $relevantPaths ) {
199 wfDebugLog( 'FileOperationReplication',
200 "'{$backend->getName()}' async replication; paths: " .
201 FormatJson
::encode( $relevantPaths ) );
202 $backend->doOperations( $realOps, $opts );
206 wfDebugLog( 'FileOperationReplication',
207 "'{$backend->getName()}' sync replication; paths: " .
208 FormatJson
::encode( $relevantPaths ) );
209 $status->merge( $backend->doOperations( $realOps, $opts ) );
213 // Make 'success', 'successCount', and 'failCount' fields reflect
214 // the overall operation, rather than all the batches for each backend.
215 // Do this by only using success values from the master backend's batch.
216 $status->success
= $masterStatus->success
;
217 $status->successCount
= $masterStatus->successCount
;
218 $status->failCount
= $masterStatus->failCount
;
224 * Check that a set of files are consistent across all internal backends
226 * @param array $paths List of storage paths
227 * @return StatusValue
229 public function consistencyCheck( array $paths ) {
230 $status = $this->newStatus();
231 if ( $this->syncChecks
== 0 ||
count( $this->backends
) <= 1 ) {
232 return $status; // skip checks
235 // Preload all of the stat info in as few round trips as possible...
236 foreach ( $this->backends
as $backend ) {
237 $realPaths = $this->substPaths( $paths, $backend );
238 $backend->preloadFileStat( [ 'srcs' => $realPaths, 'latest' => true ] );
241 $mBackend = $this->backends
[$this->masterIndex
];
242 foreach ( $paths as $path ) {
243 $params = [ 'src' => $path, 'latest' => true ];
244 $mParams = $this->substOpPaths( $params, $mBackend );
245 // Stat the file on the 'master' backend
246 $mStat = $mBackend->getFileStat( $mParams );
247 if ( $this->syncChecks
& self
::CHECK_SHA1
) {
248 $mSha1 = $mBackend->getFileSha1Base36( $mParams );
252 // Check if all clone backends agree with the master...
253 foreach ( $this->backends
as $index => $cBackend ) {
254 if ( $index === $this->masterIndex
) {
257 $cParams = $this->substOpPaths( $params, $cBackend );
258 $cStat = $cBackend->getFileStat( $cParams );
259 if ( $mStat ) { // file is in master
260 if ( !$cStat ) { // file should exist
261 $status->fatal( 'backend-fail-synced', $path );
264 if ( $this->syncChecks
& self
::CHECK_SIZE
) {
265 if ( $cStat['size'] != $mStat['size'] ) { // wrong size
266 $status->fatal( 'backend-fail-synced', $path );
270 if ( $this->syncChecks
& self
::CHECK_TIME
) {
271 $mTs = wfTimestamp( TS_UNIX
, $mStat['mtime'] );
272 $cTs = wfTimestamp( TS_UNIX
, $cStat['mtime'] );
273 if ( abs( $mTs - $cTs ) > 30 ) { // outdated file somewhere
274 $status->fatal( 'backend-fail-synced', $path );
278 if ( $this->syncChecks
& self
::CHECK_SHA1
) {
279 if ( $cBackend->getFileSha1Base36( $cParams ) !== $mSha1 ) { // wrong SHA1
280 $status->fatal( 'backend-fail-synced', $path );
284 } else { // file is not in master
285 if ( $cStat ) { // file should not exist
286 $status->fatal( 'backend-fail-synced', $path );
296 * Check that a set of file paths are usable across all internal backends
298 * @param array $paths List of storage paths
299 * @return StatusValue
301 public function accessibilityCheck( array $paths ) {
302 $status = $this->newStatus();
303 if ( count( $this->backends
) <= 1 ) {
304 return $status; // skip checks
307 foreach ( $paths as $path ) {
308 foreach ( $this->backends
as $backend ) {
309 $realPath = $this->substPaths( $path, $backend );
310 if ( !$backend->isPathUsableInternal( $realPath ) ) {
311 $status->fatal( 'backend-fail-usable', $path );
320 * Check that a set of files are consistent across all internal backends
321 * and re-synchronize those files against the "multi master" if needed.
323 * @param array $paths List of storage paths
324 * @param string|bool $resyncMode False, True, or "conservative"; see __construct()
325 * @return StatusValue
327 public function resyncFiles( array $paths, $resyncMode = true ) {
328 $status = $this->newStatus();
330 $mBackend = $this->backends
[$this->masterIndex
];
331 foreach ( $paths as $path ) {
332 $mPath = $this->substPaths( $path, $mBackend );
333 $mSha1 = $mBackend->getFileSha1Base36( [ 'src' => $mPath, 'latest' => true ] );
334 $mStat = $mBackend->getFileStat( [ 'src' => $mPath, 'latest' => true ] );
335 if ( $mStat === null ||
( $mSha1 !== false && !$mStat ) ) { // sanity
336 $status->fatal( 'backend-fail-internal', $this->name
);
337 wfDebugLog( 'FileOperation', __METHOD__
338 . ': File is not available on the master backend' );
339 continue; // file is not available on the master backend...
341 // Check of all clone backends agree with the master...
342 foreach ( $this->backends
as $index => $cBackend ) {
343 if ( $index === $this->masterIndex
) {
346 $cPath = $this->substPaths( $path, $cBackend );
347 $cSha1 = $cBackend->getFileSha1Base36( [ 'src' => $cPath, 'latest' => true ] );
348 $cStat = $cBackend->getFileStat( [ 'src' => $cPath, 'latest' => true ] );
349 if ( $cStat === null ||
( $cSha1 !== false && !$cStat ) ) { // sanity
350 $status->fatal( 'backend-fail-internal', $cBackend->getName() );
351 wfDebugLog( 'FileOperation', __METHOD__
.
352 ': File is not available on the clone backend' );
353 continue; // file is not available on the clone backend...
355 if ( $mSha1 === $cSha1 ) {
356 // already synced; nothing to do
357 } elseif ( $mSha1 !== false ) { // file is in master
358 if ( $resyncMode === 'conservative'
359 && $cStat && $cStat['mtime'] > $mStat['mtime']
361 $status->fatal( 'backend-fail-synced', $path );
362 continue; // don't rollback data
364 $fsFile = $mBackend->getLocalReference(
365 [ 'src' => $mPath, 'latest' => true ] );
366 $status->merge( $cBackend->quickStore(
367 [ 'src' => $fsFile->getPath(), 'dst' => $cPath ]
369 } elseif ( $mStat === false ) { // file is not in master
370 if ( $resyncMode === 'conservative' ) {
371 $status->fatal( 'backend-fail-synced', $path );
372 continue; // don't delete data
374 $status->merge( $cBackend->quickDelete( [ 'src' => $cPath ] ) );
379 if ( !$status->isOK() ) {
380 wfDebugLog( 'FileOperation', static::class .
381 " failed to resync: " . FormatJson
::encode( $paths ) );
388 * Get a list of file storage paths to read or write for a list of operations
390 * @param array $ops Same format as doOperations()
391 * @return array List of storage paths to files (does not include directories)
393 protected function fileStoragePathsForOps( array $ops ) {
395 foreach ( $ops as $op ) {
396 if ( isset( $op['src'] ) ) {
397 // For things like copy/move/delete with "ignoreMissingSource" and there
398 // is no source file, nothing should happen and there should be no errors.
399 if ( empty( $op['ignoreMissingSource'] )
400 ||
$this->fileExists( [ 'src' => $op['src'] ] )
402 $paths[] = $op['src'];
405 if ( isset( $op['srcs'] ) ) {
406 $paths = array_merge( $paths, $op['srcs'] );
408 if ( isset( $op['dst'] ) ) {
409 $paths[] = $op['dst'];
413 return array_values( array_unique( array_filter( $paths, 'FileBackend::isStoragePath' ) ) );
417 * Substitute the backend name in storage path parameters
418 * for a set of operations with that of a given internal backend.
420 * @param array $ops List of file operation arrays
421 * @param FileBackendStore $backend
424 protected function substOpBatchPaths( array $ops, FileBackendStore
$backend ) {
425 $newOps = []; // operations
426 foreach ( $ops as $op ) {
427 $newOp = $op; // operation
428 foreach ( [ 'src', 'srcs', 'dst', 'dir' ] as $par ) {
429 if ( isset( $newOp[$par] ) ) { // string or array
430 $newOp[$par] = $this->substPaths( $newOp[$par], $backend );
440 * Same as substOpBatchPaths() but for a single operation
442 * @param array $ops File operation array
443 * @param FileBackendStore $backend
446 protected function substOpPaths( array $ops, FileBackendStore
$backend ) {
447 $newOps = $this->substOpBatchPaths( [ $ops ], $backend );
453 * Substitute the backend of storage paths with an internal backend's name
455 * @param array|string $paths List of paths or single string path
456 * @param FileBackendStore $backend
457 * @return array|string
459 protected function substPaths( $paths, FileBackendStore
$backend ) {
461 '!^mwstore://' . preg_quote( $this->name
, '!' ) . '/!',
462 StringUtils
::escapeRegexReplacement( "mwstore://{$backend->getName()}/" ),
463 $paths // string or array
468 * Substitute the backend of internal storage paths with the proxy backend's name
470 * @param array|string $paths List of paths or single string path
471 * @return array|string
473 protected function unsubstPaths( $paths ) {
475 '!^mwstore://([^/]+)!',
476 StringUtils
::escapeRegexReplacement( "mwstore://{$this->name}" ),
477 $paths // string or array
482 * @param array $ops File operations for FileBackend::doOperations()
483 * @return bool Whether there are file path sources with outside lifetime/ownership
485 protected function hasVolatileSources( array $ops ) {
486 foreach ( $ops as $op ) {
487 if ( $op['op'] === 'store' && !isset( $op['srcRef'] ) ) {
488 return true; // source file might be deleted anytime after do*Operations()
495 protected function doQuickOperationsInternal( array $ops ) {
496 $status = $this->newStatus();
497 // Do the operations on the master backend; setting StatusValue fields...
498 $realOps = $this->substOpBatchPaths( $ops, $this->backends
[$this->masterIndex
] );
499 $masterStatus = $this->backends
[$this->masterIndex
]->doQuickOperations( $realOps );
500 $status->merge( $masterStatus );
501 // Propagate the operations to the clone backends...
502 foreach ( $this->backends
as $index => $backend ) {
503 if ( $index === $this->masterIndex
) {
504 continue; // done already
507 $realOps = $this->substOpBatchPaths( $ops, $backend );
508 if ( $this->asyncWrites
&& !$this->hasVolatileSources( $ops ) ) {
509 DeferredUpdates
::addCallableUpdate(
510 function () use ( $backend, $realOps ) {
511 $backend->doQuickOperations( $realOps );
515 $status->merge( $backend->doQuickOperations( $realOps ) );
518 // Make 'success', 'successCount', and 'failCount' fields reflect
519 // the overall operation, rather than all the batches for each backend.
520 // Do this by only using success values from the master backend's batch.
521 $status->success
= $masterStatus->success
;
522 $status->successCount
= $masterStatus->successCount
;
523 $status->failCount
= $masterStatus->failCount
;
528 protected function doPrepare( array $params ) {
529 return $this->doDirectoryOp( 'prepare', $params );
532 protected function doSecure( array $params ) {
533 return $this->doDirectoryOp( 'secure', $params );
536 protected function doPublish( array $params ) {
537 return $this->doDirectoryOp( 'publish', $params );
540 protected function doClean( array $params ) {
541 return $this->doDirectoryOp( 'clean', $params );
545 * @param string $method One of (doPrepare,doSecure,doPublish,doClean)
546 * @param array $params Method arguments
547 * @return StatusValue
549 protected function doDirectoryOp( $method, array $params ) {
550 $status = $this->newStatus();
552 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
553 $masterStatus = $this->backends
[$this->masterIndex
]->$method( $realParams );
554 $status->merge( $masterStatus );
556 foreach ( $this->backends
as $index => $backend ) {
557 if ( $index === $this->masterIndex
) {
558 continue; // already done
561 $realParams = $this->substOpPaths( $params, $backend );
562 if ( $this->asyncWrites
) {
563 DeferredUpdates
::addCallableUpdate(
564 function () use ( $backend, $method, $realParams ) {
565 $backend->$method( $realParams );
569 $status->merge( $backend->$method( $realParams ) );
576 public function concatenate( array $params ) {
577 $status = $this->newStatus();
578 // We are writing to an FS file, so we don't need to do this per-backend
579 $index = $this->getReadIndexFromParams( $params );
580 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
582 $status->merge( $this->backends
[$index]->concatenate( $realParams ) );
587 public function fileExists( array $params ) {
588 $index = $this->getReadIndexFromParams( $params );
589 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
591 return $this->backends
[$index]->fileExists( $realParams );
594 public function getFileTimestamp( array $params ) {
595 $index = $this->getReadIndexFromParams( $params );
596 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
598 return $this->backends
[$index]->getFileTimestamp( $realParams );
601 public function getFileSize( array $params ) {
602 $index = $this->getReadIndexFromParams( $params );
603 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
605 return $this->backends
[$index]->getFileSize( $realParams );
608 public function getFileStat( array $params ) {
609 $index = $this->getReadIndexFromParams( $params );
610 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
612 return $this->backends
[$index]->getFileStat( $realParams );
615 public function getFileXAttributes( array $params ) {
616 $index = $this->getReadIndexFromParams( $params );
617 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
619 return $this->backends
[$index]->getFileXAttributes( $realParams );
622 public function getFileContentsMulti( array $params ) {
623 $index = $this->getReadIndexFromParams( $params );
624 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
626 $contentsM = $this->backends
[$index]->getFileContentsMulti( $realParams );
628 $contents = []; // (path => FSFile) mapping using the proxy backend's name
629 foreach ( $contentsM as $path => $data ) {
630 $contents[$this->unsubstPaths( $path )] = $data;
636 public function getFileSha1Base36( array $params ) {
637 $index = $this->getReadIndexFromParams( $params );
638 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
640 return $this->backends
[$index]->getFileSha1Base36( $realParams );
643 public function getFileProps( array $params ) {
644 $index = $this->getReadIndexFromParams( $params );
645 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
647 return $this->backends
[$index]->getFileProps( $realParams );
650 public function streamFile( array $params ) {
651 $index = $this->getReadIndexFromParams( $params );
652 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
654 return $this->backends
[$index]->streamFile( $realParams );
657 public function getLocalReferenceMulti( array $params ) {
658 $index = $this->getReadIndexFromParams( $params );
659 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
661 $fsFilesM = $this->backends
[$index]->getLocalReferenceMulti( $realParams );
663 $fsFiles = []; // (path => FSFile) mapping using the proxy backend's name
664 foreach ( $fsFilesM as $path => $fsFile ) {
665 $fsFiles[$this->unsubstPaths( $path )] = $fsFile;
671 public function getLocalCopyMulti( array $params ) {
672 $index = $this->getReadIndexFromParams( $params );
673 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
675 $tempFilesM = $this->backends
[$index]->getLocalCopyMulti( $realParams );
677 $tempFiles = []; // (path => TempFSFile) mapping using the proxy backend's name
678 foreach ( $tempFilesM as $path => $tempFile ) {
679 $tempFiles[$this->unsubstPaths( $path )] = $tempFile;
685 public function getFileHttpUrl( array $params ) {
686 $index = $this->getReadIndexFromParams( $params );
687 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
689 return $this->backends
[$index]->getFileHttpUrl( $realParams );
692 public function directoryExists( array $params ) {
693 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
695 return $this->backends
[$this->masterIndex
]->directoryExists( $realParams );
698 public function getDirectoryList( array $params ) {
699 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
701 return $this->backends
[$this->masterIndex
]->getDirectoryList( $realParams );
704 public function getFileList( array $params ) {
705 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
707 return $this->backends
[$this->masterIndex
]->getFileList( $realParams );
710 public function getFeatures() {
711 return $this->backends
[$this->masterIndex
]->getFeatures();
714 public function clearCache( array $paths = null ) {
715 foreach ( $this->backends
as $backend ) {
716 $realPaths = is_array( $paths ) ?
$this->substPaths( $paths, $backend ) : null;
717 $backend->clearCache( $realPaths );
721 public function preloadCache( array $paths ) {
722 $realPaths = $this->substPaths( $paths, $this->backends
[$this->readIndex
] );
723 $this->backends
[$this->readIndex
]->preloadCache( $realPaths );
726 public function preloadFileStat( array $params ) {
727 $index = $this->getReadIndexFromParams( $params );
728 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
730 return $this->backends
[$index]->preloadFileStat( $realParams );
733 public function getScopedLocksForOps( array $ops, StatusValue
$status ) {
734 $realOps = $this->substOpBatchPaths( $ops, $this->backends
[$this->masterIndex
] );
735 $fileOps = $this->backends
[$this->masterIndex
]->getOperationsInternal( $realOps );
736 // Get the paths to lock from the master backend
737 $paths = $this->backends
[$this->masterIndex
]->getPathsToLockForOpsInternal( $fileOps );
738 // Get the paths under the proxy backend's name
740 LockManager
::LOCK_UW
=> $this->unsubstPaths( $paths[LockManager
::LOCK_UW
] ),
741 LockManager
::LOCK_EX
=> $this->unsubstPaths( $paths[LockManager
::LOCK_EX
] )
744 // Actually acquire the locks
745 return $this->getScopedFileLocks( $pbPaths, 'mixed', $status );
749 * @param array $params
750 * @return int The master or read affinity backend index, based on $params['latest']
752 protected function getReadIndexFromParams( array $params ) {
753 return !empty( $params['latest'] ) ?
$this->masterIndex
: $this->readIndex
;