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 LogicException
93 public function __construct( array $config ) {
94 parent
::__construct( $config );
95 $this->syncChecks
= $config['syncChecks'] ?? self
::CHECK_SIZE
;
96 $this->autoResync
= $config['autoResync'] ??
false;
97 $this->asyncWrites
= isset( $config['replication'] ) && $config['replication'] === 'async';
98 // Construct backends here rather than via registration
99 // to keep these backends hidden from outside the proxy.
101 foreach ( $config['backends'] as $index => $config ) {
102 $name = $config['name'];
103 if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates
104 throw new LogicException( "Two or more backends defined with the name $name." );
106 $namesUsed[$name] = 1;
107 // Alter certain sub-backend settings for sanity
108 unset( $config['readOnly'] ); // use proxy backend setting
109 unset( $config['fileJournal'] ); // use proxy backend journal
110 unset( $config['lockManager'] ); // lock under proxy backend
111 $config['domainId'] = $this->domainId
; // use the proxy backend wiki ID
112 if ( !empty( $config['isMultiMaster'] ) ) {
113 if ( $this->masterIndex
>= 0 ) {
114 throw new LogicException( 'More than one master backend defined.' );
116 $this->masterIndex
= $index; // this is the "master"
117 $config['fileJournal'] = $this->fileJournal
; // log under proxy backend
119 if ( !empty( $config['readAffinity'] ) ) {
120 $this->readIndex
= $index; // prefer this for reads
122 // Create sub-backend object
123 if ( !isset( $config['class'] ) ) {
124 throw new InvalidArgumentException( 'No class given for a backend config.' );
126 $class = $config['class'];
127 $this->backends
[$index] = new $class( $config );
129 if ( $this->masterIndex
< 0 ) { // need backends and must have a master
130 throw new LogicException( 'No master backend defined.' );
132 if ( $this->readIndex
< 0 ) {
133 $this->readIndex
= $this->masterIndex
; // default
137 final protected function doOperationsInternal( array $ops, array $opts ) {
138 $status = $this->newStatus();
140 $mbe = $this->backends
[$this->masterIndex
]; // convenience
142 // Try to lock those files for the scope of this function...
144 if ( empty( $opts['nonLocking'] ) ) {
145 // Try to lock those files for the scope of this function...
146 /** @noinspection PhpUnusedLocalVariableInspection */
147 $scopeLock = $this->getScopedLocksForOps( $ops, $status );
148 if ( !$status->isOK() ) {
149 return $status; // abort
152 // Clear any cache entries (after locks acquired)
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
162 // Do a consistency check to see if the backends are consistent...
163 $syncStatus = $this->consistencyCheck( $relevantPaths );
164 if ( !$syncStatus->isOK() ) {
165 wfDebugLog( 'FileOperation', static::class .
166 " failed sync check: " . FormatJson
::encode( $relevantPaths ) );
167 // Try to resync the clone backends to the master on the spot...
168 if ( $this->autoResync
=== false
169 ||
!$this->resyncFiles( $relevantPaths, $this->autoResync
)->isOK()
171 $status->merge( $syncStatus );
173 return $status; // abort
176 // Actually attempt the operation batch on the master backend...
177 $realOps = $this->substOpBatchPaths( $ops, $mbe );
178 $masterStatus = $mbe->doOperations( $realOps, $opts );
179 $status->merge( $masterStatus );
180 // Propagate the operations to the clone backends if there were no unexpected errors
181 // and everything didn't fail due to predicted errors. If $ops only had one operation,
182 // this might avoid backend sync inconsistencies.
183 if ( $masterStatus->isOK() && $masterStatus->successCount
> 0 ) {
184 foreach ( $this->backends
as $index => $backend ) {
185 if ( $index === $this->masterIndex
) {
186 continue; // done already
189 $realOps = $this->substOpBatchPaths( $ops, $backend );
190 if ( $this->asyncWrites
&& !$this->hasVolatileSources( $ops ) ) {
191 // Bind $scopeLock to the callback to preserve locks
192 DeferredUpdates
::addCallableUpdate(
193 function () use ( $backend, $realOps, $opts, $scopeLock, $relevantPaths ) {
194 wfDebugLog( 'FileOperationReplication',
195 "'{$backend->getName()}' async replication; paths: " .
196 FormatJson
::encode( $relevantPaths ) );
197 $backend->doOperations( $realOps, $opts );
201 wfDebugLog( 'FileOperationReplication',
202 "'{$backend->getName()}' sync replication; paths: " .
203 FormatJson
::encode( $relevantPaths ) );
204 $status->merge( $backend->doOperations( $realOps, $opts ) );
208 // Make 'success', 'successCount', and 'failCount' fields reflect
209 // the overall operation, rather than all the batches for each backend.
210 // Do this by only using success values from the master backend's batch.
211 $status->success
= $masterStatus->success
;
212 $status->successCount
= $masterStatus->successCount
;
213 $status->failCount
= $masterStatus->failCount
;
219 * Check that a set of files are consistent across all internal backends
221 * @param array $paths List of storage paths
222 * @return StatusValue
224 public function consistencyCheck( array $paths ) {
225 $status = $this->newStatus();
226 if ( $this->syncChecks
== 0 ||
count( $this->backends
) <= 1 ) {
227 return $status; // skip checks
230 // Preload all of the stat info in as few round trips as possible...
231 foreach ( $this->backends
as $backend ) {
232 $realPaths = $this->substPaths( $paths, $backend );
233 $backend->preloadFileStat( [ 'srcs' => $realPaths, 'latest' => true ] );
236 $mBackend = $this->backends
[$this->masterIndex
];
237 foreach ( $paths as $path ) {
238 $params = [ 'src' => $path, 'latest' => true ];
239 $mParams = $this->substOpPaths( $params, $mBackend );
240 // Stat the file on the 'master' backend
241 $mStat = $mBackend->getFileStat( $mParams );
242 if ( $this->syncChecks
& self
::CHECK_SHA1
) {
243 $mSha1 = $mBackend->getFileSha1Base36( $mParams );
247 // Check if all clone backends agree with the master...
248 foreach ( $this->backends
as $index => $cBackend ) {
249 if ( $index === $this->masterIndex
) {
252 $cParams = $this->substOpPaths( $params, $cBackend );
253 $cStat = $cBackend->getFileStat( $cParams );
254 if ( $mStat ) { // file is in master
255 if ( !$cStat ) { // file should exist
256 $status->fatal( 'backend-fail-synced', $path );
259 if ( ( $this->syncChecks
& self
::CHECK_SIZE
)
260 && $cStat['size'] != $mStat['size']
262 $status->fatal( 'backend-fail-synced', $path );
265 if ( $this->syncChecks
& self
::CHECK_TIME
) {
266 $mTs = wfTimestamp( TS_UNIX
, $mStat['mtime'] );
267 $cTs = wfTimestamp( TS_UNIX
, $cStat['mtime'] );
268 if ( abs( $mTs - $cTs ) > 30 ) { // outdated file somewhere
269 $status->fatal( 'backend-fail-synced', $path );
274 ( $this->syncChecks
& self
::CHECK_SHA1
) &&
275 $cBackend->getFileSha1Base36( $cParams ) !== $mSha1
277 $status->fatal( 'backend-fail-synced', $path );
280 } elseif ( $cStat ) { // file is not in master; file should not exist
281 $status->fatal( 'backend-fail-synced', $path );
290 * Check that a set of file paths are usable across all internal backends
292 * @param array $paths List of storage paths
293 * @return StatusValue
295 public function accessibilityCheck( array $paths ) {
296 $status = $this->newStatus();
297 if ( count( $this->backends
) <= 1 ) {
298 return $status; // skip checks
301 foreach ( $paths as $path ) {
302 foreach ( $this->backends
as $backend ) {
303 $realPath = $this->substPaths( $path, $backend );
304 if ( !$backend->isPathUsableInternal( $realPath ) ) {
305 $status->fatal( 'backend-fail-usable', $path );
314 * Check that a set of files are consistent across all internal backends
315 * and re-synchronize those files against the "multi master" if needed.
317 * @param array $paths List of storage paths
318 * @param string|bool $resyncMode False, True, or "conservative"; see __construct()
319 * @return StatusValue
321 public function resyncFiles( array $paths, $resyncMode = true ) {
322 $status = $this->newStatus();
324 $mBackend = $this->backends
[$this->masterIndex
];
325 foreach ( $paths as $path ) {
326 $mPath = $this->substPaths( $path, $mBackend );
327 $mSha1 = $mBackend->getFileSha1Base36( [ 'src' => $mPath, 'latest' => true ] );
328 $mStat = $mBackend->getFileStat( [ 'src' => $mPath, 'latest' => true ] );
329 if ( $mStat === null ||
( $mSha1 !== false && !$mStat ) ) { // sanity
330 $status->fatal( 'backend-fail-internal', $this->name
);
331 wfDebugLog( 'FileOperation', __METHOD__
332 . ': File is not available on the master backend' );
333 continue; // file is not available on the master backend...
335 // Check of all clone backends agree with the master...
336 foreach ( $this->backends
as $index => $cBackend ) {
337 if ( $index === $this->masterIndex
) {
340 $cPath = $this->substPaths( $path, $cBackend );
341 $cSha1 = $cBackend->getFileSha1Base36( [ 'src' => $cPath, 'latest' => true ] );
342 $cStat = $cBackend->getFileStat( [ 'src' => $cPath, 'latest' => true ] );
343 if ( $cStat === null ||
( $cSha1 !== false && !$cStat ) ) { // sanity
344 $status->fatal( 'backend-fail-internal', $cBackend->getName() );
345 wfDebugLog( 'FileOperation', __METHOD__
.
346 ': File is not available on the clone backend' );
347 continue; // file is not available on the clone backend...
349 if ( $mSha1 === $cSha1 ) {
350 // already synced; nothing to do
351 } elseif ( $mSha1 !== false ) { // file is in master
352 if ( $resyncMode === 'conservative'
353 && $cStat && $cStat['mtime'] > $mStat['mtime']
355 $status->fatal( 'backend-fail-synced', $path );
356 continue; // don't rollback data
358 $fsFile = $mBackend->getLocalReference(
359 [ 'src' => $mPath, 'latest' => true ] );
360 $status->merge( $cBackend->quickStore(
361 [ 'src' => $fsFile->getPath(), 'dst' => $cPath ]
363 } elseif ( $mStat === false ) { // file is not in master
364 if ( $resyncMode === 'conservative' ) {
365 $status->fatal( 'backend-fail-synced', $path );
366 continue; // don't delete data
368 $status->merge( $cBackend->quickDelete( [ 'src' => $cPath ] ) );
373 if ( !$status->isOK() ) {
374 wfDebugLog( 'FileOperation', static::class .
375 " failed to resync: " . FormatJson
::encode( $paths ) );
382 * Get a list of file storage paths to read or write for a list of operations
384 * @param array $ops Same format as doOperations()
385 * @return array List of storage paths to files (does not include directories)
387 protected function fileStoragePathsForOps( array $ops ) {
389 foreach ( $ops as $op ) {
390 if ( isset( $op['src'] ) ) {
391 // For things like copy/move/delete with "ignoreMissingSource" and there
392 // is no source file, nothing should happen and there should be no errors.
393 if ( empty( $op['ignoreMissingSource'] )
394 ||
$this->fileExists( [ 'src' => $op['src'] ] )
396 $paths[] = $op['src'];
399 if ( isset( $op['srcs'] ) ) {
400 $paths = array_merge( $paths, $op['srcs'] );
402 if ( isset( $op['dst'] ) ) {
403 $paths[] = $op['dst'];
407 return array_values( array_unique( array_filter( $paths, 'FileBackend::isStoragePath' ) ) );
411 * Substitute the backend name in storage path parameters
412 * for a set of operations with that of a given internal backend.
414 * @param array $ops List of file operation arrays
415 * @param FileBackendStore $backend
418 protected function substOpBatchPaths( array $ops, FileBackendStore
$backend ) {
419 $newOps = []; // operations
420 foreach ( $ops as $op ) {
421 $newOp = $op; // operation
422 foreach ( [ 'src', 'srcs', 'dst', 'dir' ] as $par ) {
423 if ( isset( $newOp[$par] ) ) { // string or array
424 $newOp[$par] = $this->substPaths( $newOp[$par], $backend );
434 * Same as substOpBatchPaths() but for a single operation
436 * @param array $ops File operation array
437 * @param FileBackendStore $backend
440 protected function substOpPaths( array $ops, FileBackendStore
$backend ) {
441 $newOps = $this->substOpBatchPaths( [ $ops ], $backend );
447 * Substitute the backend of storage paths with an internal backend's name
449 * @param array|string $paths List of paths or single string path
450 * @param FileBackendStore $backend
451 * @return array|string
453 protected function substPaths( $paths, FileBackendStore
$backend ) {
455 '!^mwstore://' . preg_quote( $this->name
, '!' ) . '/!',
456 StringUtils
::escapeRegexReplacement( "mwstore://{$backend->getName()}/" ),
457 $paths // string or array
462 * Substitute the backend of internal storage paths with the proxy backend's name
464 * @param array|string $paths List of paths or single string path
465 * @return array|string
467 protected function unsubstPaths( $paths ) {
469 '!^mwstore://([^/]+)!',
470 StringUtils
::escapeRegexReplacement( "mwstore://{$this->name}" ),
471 $paths // string or array
476 * @param array $ops File operations for FileBackend::doOperations()
477 * @return bool Whether there are file path sources with outside lifetime/ownership
479 protected function hasVolatileSources( array $ops ) {
480 foreach ( $ops as $op ) {
481 if ( $op['op'] === 'store' && !isset( $op['srcRef'] ) ) {
482 return true; // source file might be deleted anytime after do*Operations()
489 protected function doQuickOperationsInternal( array $ops ) {
490 $status = $this->newStatus();
491 // Do the operations on the master backend; setting StatusValue fields...
492 $realOps = $this->substOpBatchPaths( $ops, $this->backends
[$this->masterIndex
] );
493 $masterStatus = $this->backends
[$this->masterIndex
]->doQuickOperations( $realOps );
494 $status->merge( $masterStatus );
495 // Propagate the operations to the clone backends...
496 foreach ( $this->backends
as $index => $backend ) {
497 if ( $index === $this->masterIndex
) {
498 continue; // done already
501 $realOps = $this->substOpBatchPaths( $ops, $backend );
502 if ( $this->asyncWrites
&& !$this->hasVolatileSources( $ops ) ) {
503 DeferredUpdates
::addCallableUpdate(
504 function () use ( $backend, $realOps ) {
505 $backend->doQuickOperations( $realOps );
509 $status->merge( $backend->doQuickOperations( $realOps ) );
512 // Make 'success', 'successCount', and 'failCount' fields reflect
513 // the overall operation, rather than all the batches for each backend.
514 // Do this by only using success values from the master backend's batch.
515 $status->success
= $masterStatus->success
;
516 $status->successCount
= $masterStatus->successCount
;
517 $status->failCount
= $masterStatus->failCount
;
522 protected function doPrepare( array $params ) {
523 return $this->doDirectoryOp( 'prepare', $params );
526 protected function doSecure( array $params ) {
527 return $this->doDirectoryOp( 'secure', $params );
530 protected function doPublish( array $params ) {
531 return $this->doDirectoryOp( 'publish', $params );
534 protected function doClean( array $params ) {
535 return $this->doDirectoryOp( 'clean', $params );
539 * @param string $method One of (doPrepare,doSecure,doPublish,doClean)
540 * @param array $params Method arguments
541 * @return StatusValue
543 protected function doDirectoryOp( $method, array $params ) {
544 $status = $this->newStatus();
546 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
547 $masterStatus = $this->backends
[$this->masterIndex
]->$method( $realParams );
548 $status->merge( $masterStatus );
550 foreach ( $this->backends
as $index => $backend ) {
551 if ( $index === $this->masterIndex
) {
552 continue; // already done
555 $realParams = $this->substOpPaths( $params, $backend );
556 if ( $this->asyncWrites
) {
557 DeferredUpdates
::addCallableUpdate(
558 function () use ( $backend, $method, $realParams ) {
559 $backend->$method( $realParams );
563 $status->merge( $backend->$method( $realParams ) );
570 public function concatenate( array $params ) {
571 $status = $this->newStatus();
572 // We are writing to an FS file, so we don't need to do this per-backend
573 $index = $this->getReadIndexFromParams( $params );
574 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
576 $status->merge( $this->backends
[$index]->concatenate( $realParams ) );
581 public function fileExists( array $params ) {
582 $index = $this->getReadIndexFromParams( $params );
583 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
585 return $this->backends
[$index]->fileExists( $realParams );
588 public function getFileTimestamp( array $params ) {
589 $index = $this->getReadIndexFromParams( $params );
590 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
592 return $this->backends
[$index]->getFileTimestamp( $realParams );
595 public function getFileSize( array $params ) {
596 $index = $this->getReadIndexFromParams( $params );
597 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
599 return $this->backends
[$index]->getFileSize( $realParams );
602 public function getFileStat( array $params ) {
603 $index = $this->getReadIndexFromParams( $params );
604 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
606 return $this->backends
[$index]->getFileStat( $realParams );
609 public function getFileXAttributes( array $params ) {
610 $index = $this->getReadIndexFromParams( $params );
611 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
613 return $this->backends
[$index]->getFileXAttributes( $realParams );
616 public function getFileContentsMulti( array $params ) {
617 $index = $this->getReadIndexFromParams( $params );
618 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
620 $contentsM = $this->backends
[$index]->getFileContentsMulti( $realParams );
622 $contents = []; // (path => FSFile) mapping using the proxy backend's name
623 foreach ( $contentsM as $path => $data ) {
624 $contents[$this->unsubstPaths( $path )] = $data;
630 public function getFileSha1Base36( array $params ) {
631 $index = $this->getReadIndexFromParams( $params );
632 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
634 return $this->backends
[$index]->getFileSha1Base36( $realParams );
637 public function getFileProps( array $params ) {
638 $index = $this->getReadIndexFromParams( $params );
639 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
641 return $this->backends
[$index]->getFileProps( $realParams );
644 public function streamFile( array $params ) {
645 $index = $this->getReadIndexFromParams( $params );
646 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
648 return $this->backends
[$index]->streamFile( $realParams );
651 public function getLocalReferenceMulti( array $params ) {
652 $index = $this->getReadIndexFromParams( $params );
653 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
655 $fsFilesM = $this->backends
[$index]->getLocalReferenceMulti( $realParams );
657 $fsFiles = []; // (path => FSFile) mapping using the proxy backend's name
658 foreach ( $fsFilesM as $path => $fsFile ) {
659 $fsFiles[$this->unsubstPaths( $path )] = $fsFile;
665 public function getLocalCopyMulti( array $params ) {
666 $index = $this->getReadIndexFromParams( $params );
667 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
669 $tempFilesM = $this->backends
[$index]->getLocalCopyMulti( $realParams );
671 $tempFiles = []; // (path => TempFSFile) mapping using the proxy backend's name
672 foreach ( $tempFilesM as $path => $tempFile ) {
673 $tempFiles[$this->unsubstPaths( $path )] = $tempFile;
679 public function getFileHttpUrl( array $params ) {
680 $index = $this->getReadIndexFromParams( $params );
681 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
683 return $this->backends
[$index]->getFileHttpUrl( $realParams );
686 public function directoryExists( array $params ) {
687 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
689 return $this->backends
[$this->masterIndex
]->directoryExists( $realParams );
692 public function getDirectoryList( array $params ) {
693 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
695 return $this->backends
[$this->masterIndex
]->getDirectoryList( $realParams );
698 public function getFileList( array $params ) {
699 $realParams = $this->substOpPaths( $params, $this->backends
[$this->masterIndex
] );
701 return $this->backends
[$this->masterIndex
]->getFileList( $realParams );
704 public function getFeatures() {
705 return $this->backends
[$this->masterIndex
]->getFeatures();
708 public function clearCache( array $paths = null ) {
709 foreach ( $this->backends
as $backend ) {
710 $realPaths = is_array( $paths ) ?
$this->substPaths( $paths, $backend ) : null;
711 $backend->clearCache( $realPaths );
715 public function preloadCache( array $paths ) {
716 $realPaths = $this->substPaths( $paths, $this->backends
[$this->readIndex
] );
717 $this->backends
[$this->readIndex
]->preloadCache( $realPaths );
720 public function preloadFileStat( array $params ) {
721 $index = $this->getReadIndexFromParams( $params );
722 $realParams = $this->substOpPaths( $params, $this->backends
[$index] );
724 return $this->backends
[$index]->preloadFileStat( $realParams );
727 public function getScopedLocksForOps( array $ops, StatusValue
$status ) {
728 $realOps = $this->substOpBatchPaths( $ops, $this->backends
[$this->masterIndex
] );
729 $fileOps = $this->backends
[$this->masterIndex
]->getOperationsInternal( $realOps );
730 // Get the paths to lock from the master backend
731 $paths = $this->backends
[$this->masterIndex
]->getPathsToLockForOpsInternal( $fileOps );
732 // Get the paths under the proxy backend's name
734 LockManager
::LOCK_UW
=> $this->unsubstPaths( $paths[LockManager
::LOCK_UW
] ),
735 LockManager
::LOCK_EX
=> $this->unsubstPaths( $paths[LockManager
::LOCK_EX
] )
738 // Actually acquire the locks
739 return $this->getScopedFileLocks( $pbPaths, 'mixed', $status );
743 * @param array $params
744 * @return int The master or read affinity backend index, based on $params['latest']
746 protected function getReadIndexFromParams( array $params ) {
747 return !empty( $params['latest'] ) ?
$this->masterIndex
: $this->readIndex
;