PHPSessionHandler: Implement SessionHandlerInterface
[mediawiki.git] / includes / filebackend / FileBackendMultiWrite.php
blob3841f2ed3762fc82796dec8802eed2912676280c
1 <?php
2 /**
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
20 * @file
21 * @ingroup FileBackend
22 * @author Aaron Schulz
25 /**
26 * @brief Proxy backend that mirrors writes to several internal backends.
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.
33 * Only use this class when transitioning from one storage system to another.
35 * Read operations are only done on the 'master' backend for consistency.
36 * Write operations are performed on all backends, starting with the master.
37 * This makes a best-effort to have transactional semantics, but since requests
38 * may sometimes fail, the use of "autoResync" or background scripts to fix
39 * inconsistencies is important.
41 * @ingroup FileBackend
42 * @since 1.19
44 class FileBackendMultiWrite extends FileBackend {
45 /** @var FileBackendStore[] Prioritized list of FileBackendStore objects */
46 protected $backends = array();
48 /** @var int Index of master backend */
49 protected $masterIndex = -1;
50 /** @var int Index of read affinity backend */
51 protected $readIndex = -1;
53 /** @var int Bitfield */
54 protected $syncChecks = 0;
55 /** @var string|bool */
56 protected $autoResync = false;
58 /** @var bool */
59 protected $asyncWrites = false;
61 /* Possible internal backend consistency checks */
62 const CHECK_SIZE = 1;
63 const CHECK_TIME = 2;
64 const CHECK_SHA1 = 4;
66 /**
67 * Construct a proxy backend that consists of several internal backends.
68 * Locking, journaling, and read-only checks are handled by the proxy backend.
70 * Additional $config params include:
71 * - backends : Array of backend config and multi-backend settings.
72 * Each value is the config used in the constructor of a
73 * FileBackendStore class, but with these additional settings:
74 * - class : The name of the backend class
75 * - isMultiMaster : This must be set for one backend.
76 * - readAffinity : Use this for reads without 'latest' set.
77 * - template: : If given a backend name, this will use
78 * the config of that backend as a template.
79 * Values specified here take precedence.
80 * - syncChecks : Integer bitfield of internal backend sync checks to perform.
81 * Possible bits include the FileBackendMultiWrite::CHECK_* constants.
82 * There are constants for SIZE, TIME, and SHA1.
83 * The checks are done before allowing any file operations.
84 * - autoResync : Automatically resync the clone backends to the master backend
85 * when pre-operation sync checks fail. This should only be used
86 * if the master backend is stable and not missing any files.
87 * Use "conservative" to limit resyncing to copying newer master
88 * backend files over older (or non-existing) clone backend files.
89 * Cases that cannot be handled will result in operation abortion.
90 * - replication : Set to 'async' to defer file operations on the non-master backends.
91 * This will apply such updates post-send for web requests. Note that
92 * any checks from "syncChecks" are still synchronous.
94 * @param array $config
95 * @throws FileBackendError
97 public function __construct( array $config ) {
98 parent::__construct( $config );
99 $this->syncChecks = isset( $config['syncChecks'] )
100 ? $config['syncChecks']
101 : self::CHECK_SIZE;
102 $this->autoResync = isset( $config['autoResync'] )
103 ? $config['autoResync']
104 : false;
105 $this->asyncWrites = isset( $config['replication'] ) && $config['replication'] === 'async';
106 // Construct backends here rather than via registration
107 // to keep these backends hidden from outside the proxy.
108 $namesUsed = array();
109 foreach ( $config['backends'] as $index => $config ) {
110 if ( isset( $config['template'] ) ) {
111 // Config is just a modified version of a registered backend's.
112 // This should only be used when that config is used only by this backend.
113 $config = $config + FileBackendGroup::singleton()->config( $config['template'] );
115 $name = $config['name'];
116 if ( isset( $namesUsed[$name] ) ) { // don't break FileOp predicates
117 throw new FileBackendError( "Two or more backends defined with the name $name." );
119 $namesUsed[$name] = 1;
120 // Alter certain sub-backend settings for sanity
121 unset( $config['readOnly'] ); // use proxy backend setting
122 unset( $config['fileJournal'] ); // use proxy backend journal
123 unset( $config['lockManager'] ); // lock under proxy backend
124 $config['wikiId'] = $this->wikiId; // use the proxy backend wiki ID
125 if ( !empty( $config['isMultiMaster'] ) ) {
126 if ( $this->masterIndex >= 0 ) {
127 throw new FileBackendError( 'More than one master backend defined.' );
129 $this->masterIndex = $index; // this is the "master"
130 $config['fileJournal'] = $this->fileJournal; // log under proxy backend
132 if ( !empty( $config['readAffinity'] ) ) {
133 $this->readIndex = $index; // prefer this for reads
135 // Create sub-backend object
136 if ( !isset( $config['class'] ) ) {
137 throw new FileBackendError( 'No class given for a backend config.' );
139 $class = $config['class'];
140 $this->backends[$index] = new $class( $config );
142 if ( $this->masterIndex < 0 ) { // need backends and must have a master
143 throw new FileBackendError( 'No master backend defined.' );
145 if ( $this->readIndex < 0 ) {
146 $this->readIndex = $this->masterIndex; // default
150 final protected function doOperationsInternal( array $ops, array $opts ) {
151 $status = Status::newGood();
153 $mbe = $this->backends[$this->masterIndex]; // convenience
155 // Try to lock those files for the scope of this function...
156 $scopeLock = null;
157 if ( empty( $opts['nonLocking'] ) ) {
158 // Try to lock those files for the scope of this function...
159 /** @noinspection PhpUnusedLocalVariableInspection */
160 $scopeLock = $this->getScopedLocksForOps( $ops, $status );
161 if ( !$status->isOK() ) {
162 return $status; // abort
165 // Clear any cache entries (after locks acquired)
166 $this->clearCache();
167 $opts['preserveCache'] = true; // only locked files are cached
168 // Get the list of paths to read/write...
169 $relevantPaths = $this->fileStoragePathsForOps( $ops );
170 // Check if the paths are valid and accessible on all backends...
171 $status->merge( $this->accessibilityCheck( $relevantPaths ) );
172 if ( !$status->isOK() ) {
173 return $status; // abort
175 // Do a consistency check to see if the backends are consistent...
176 $syncStatus = $this->consistencyCheck( $relevantPaths );
177 if ( !$syncStatus->isOK() ) {
178 wfDebugLog( 'FileOperation', get_class( $this ) .
179 " failed sync check: " . FormatJson::encode( $relevantPaths ) );
180 // Try to resync the clone backends to the master on the spot...
181 if ( !$this->autoResync || !$this->resyncFiles( $relevantPaths )->isOK() ) {
182 $status->merge( $syncStatus );
184 return $status; // abort
187 // Actually attempt the operation batch on the master backend...
188 $realOps = $this->substOpBatchPaths( $ops, $mbe );
189 $masterStatus = $mbe->doOperations( $realOps, $opts );
190 $status->merge( $masterStatus );
191 // Propagate the operations to the clone backends if there were no unexpected errors
192 // and if there were either no expected errors or if the 'force' option was used.
193 // However, if nothing succeeded at all, then don't replicate any of the operations.
194 // If $ops only had one operation, this might avoid backend sync inconsistencies.
195 if ( $masterStatus->isOK() && $masterStatus->successCount > 0 ) {
196 foreach ( $this->backends as $index => $backend ) {
197 if ( $index === $this->masterIndex ) {
198 continue; // done already
201 $realOps = $this->substOpBatchPaths( $ops, $backend );
202 if ( $this->asyncWrites ) {
203 // Bind $scopeLock to the callback to preserve locks
204 DeferredUpdates::addCallableUpdate(
205 function() use ( $backend, $realOps, $opts, $scopeLock ) {
206 $backend->doOperations( $realOps, $opts );
209 } else {
210 $status->merge( $backend->doOperations( $realOps, $opts ) );
214 // Make 'success', 'successCount', and 'failCount' fields reflect
215 // the overall operation, rather than all the batches for each backend.
216 // Do this by only using success values from the master backend's batch.
217 $status->success = $masterStatus->success;
218 $status->successCount = $masterStatus->successCount;
219 $status->failCount = $masterStatus->failCount;
221 return $status;
225 * Check that a set of files are consistent across all internal backends
227 * @param array $paths List of storage paths
228 * @return Status
230 public function consistencyCheck( array $paths ) {
231 $status = Status::newGood();
232 if ( $this->syncChecks == 0 || count( $this->backends ) <= 1 ) {
233 return $status; // skip checks
236 $mBackend = $this->backends[$this->masterIndex];
237 foreach ( $paths as $path ) {
238 $params = array( '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 );
244 } else {
245 $mSha1 = false;
247 // Check if all clone backends agree with the master...
248 foreach ( $this->backends as $index => $cBackend ) {
249 if ( $index === $this->masterIndex ) {
250 continue; // master
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 );
257 continue;
259 if ( $this->syncChecks & self::CHECK_SIZE ) {
260 if ( $cStat['size'] != $mStat['size'] ) { // wrong size
261 $status->fatal( 'backend-fail-synced', $path );
262 continue;
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 );
270 continue;
273 if ( $this->syncChecks & self::CHECK_SHA1 ) {
274 if ( $cBackend->getFileSha1Base36( $cParams ) !== $mSha1 ) { // wrong SHA1
275 $status->fatal( 'backend-fail-synced', $path );
276 continue;
279 } else { // file is not in master
280 if ( $cStat ) { // file should not exist
281 $status->fatal( 'backend-fail-synced', $path );
287 return $status;
291 * Check that a set of file paths are usable across all internal backends
293 * @param array $paths List of storage paths
294 * @return Status
296 public function accessibilityCheck( array $paths ) {
297 $status = Status::newGood();
298 if ( count( $this->backends ) <= 1 ) {
299 return $status; // skip checks
302 foreach ( $paths as $path ) {
303 foreach ( $this->backends as $backend ) {
304 $realPath = $this->substPaths( $path, $backend );
305 if ( !$backend->isPathUsableInternal( $realPath ) ) {
306 $status->fatal( 'backend-fail-usable', $path );
311 return $status;
315 * Check that a set of files are consistent across all internal backends
316 * and re-synchronize those files against the "multi master" if needed.
318 * @param array $paths List of storage paths
319 * @return Status
321 public function resyncFiles( array $paths ) {
322 $status = Status::newGood();
324 $mBackend = $this->backends[$this->masterIndex];
325 foreach ( $paths as $path ) {
326 $mPath = $this->substPaths( $path, $mBackend );
327 $mSha1 = $mBackend->getFileSha1Base36( array( 'src' => $mPath, 'latest' => true ) );
328 $mStat = $mBackend->getFileStat( array( '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 ) {
338 continue; // master
340 $cPath = $this->substPaths( $path, $cBackend );
341 $cSha1 = $cBackend->getFileSha1Base36( array( 'src' => $cPath, 'latest' => true ) );
342 $cStat = $cBackend->getFileStat( array( '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 ( $this->autoResync === '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 array( 'src' => $mPath, 'latest' => true ) );
360 $status->merge( $cBackend->quickStore(
361 array( 'src' => $fsFile->getPath(), 'dst' => $cPath )
362 ) );
363 } elseif ( $mStat === false ) { // file is not in master
364 if ( $this->autoResync === 'conservative' ) {
365 $status->fatal( 'backend-fail-synced', $path );
366 continue; // don't delete data
368 $status->merge( $cBackend->quickDelete( array( 'src' => $cPath ) ) );
373 return $status;
377 * Get a list of file storage paths to read or write for a list of operations
379 * @param array $ops Same format as doOperations()
380 * @return array List of storage paths to files (does not include directories)
382 protected function fileStoragePathsForOps( array $ops ) {
383 $paths = array();
384 foreach ( $ops as $op ) {
385 if ( isset( $op['src'] ) ) {
386 // For things like copy/move/delete with "ignoreMissingSource" and there
387 // is no source file, nothing should happen and there should be no errors.
388 if ( empty( $op['ignoreMissingSource'] )
389 || $this->fileExists( array( 'src' => $op['src'] ) )
391 $paths[] = $op['src'];
394 if ( isset( $op['srcs'] ) ) {
395 $paths = array_merge( $paths, $op['srcs'] );
397 if ( isset( $op['dst'] ) ) {
398 $paths[] = $op['dst'];
402 return array_values( array_unique( array_filter( $paths, 'FileBackend::isStoragePath' ) ) );
406 * Substitute the backend name in storage path parameters
407 * for a set of operations with that of a given internal backend.
409 * @param array $ops List of file operation arrays
410 * @param FileBackendStore $backend
411 * @return array
413 protected function substOpBatchPaths( array $ops, FileBackendStore $backend ) {
414 $newOps = array(); // operations
415 foreach ( $ops as $op ) {
416 $newOp = $op; // operation
417 foreach ( array( 'src', 'srcs', 'dst', 'dir' ) as $par ) {
418 if ( isset( $newOp[$par] ) ) { // string or array
419 $newOp[$par] = $this->substPaths( $newOp[$par], $backend );
422 $newOps[] = $newOp;
425 return $newOps;
429 * Same as substOpBatchPaths() but for a single operation
431 * @param array $ops File operation array
432 * @param FileBackendStore $backend
433 * @return array
435 protected function substOpPaths( array $ops, FileBackendStore $backend ) {
436 $newOps = $this->substOpBatchPaths( array( $ops ), $backend );
438 return $newOps[0];
442 * Substitute the backend of storage paths with an internal backend's name
444 * @param array|string $paths List of paths or single string path
445 * @param FileBackendStore $backend
446 * @return array|string
448 protected function substPaths( $paths, FileBackendStore $backend ) {
449 return preg_replace(
450 '!^mwstore://' . preg_quote( $this->name, '!' ) . '/!',
451 StringUtils::escapeRegexReplacement( "mwstore://{$backend->getName()}/" ),
452 $paths // string or array
457 * Substitute the backend of internal storage paths with the proxy backend's name
459 * @param array|string $paths List of paths or single string path
460 * @return array|string
462 protected function unsubstPaths( $paths ) {
463 return preg_replace(
464 '!^mwstore://([^/]+)!',
465 StringUtils::escapeRegexReplacement( "mwstore://{$this->name}" ),
466 $paths // string or array
470 protected function doQuickOperationsInternal( array $ops ) {
471 $status = Status::newGood();
472 // Do the operations on the master backend; setting Status fields...
473 $realOps = $this->substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
474 $masterStatus = $this->backends[$this->masterIndex]->doQuickOperations( $realOps );
475 $status->merge( $masterStatus );
476 // Propagate the operations to the clone backends...
477 foreach ( $this->backends as $index => $backend ) {
478 if ( $index === $this->masterIndex ) {
479 continue; // done already
482 $realOps = $this->substOpBatchPaths( $ops, $backend );
483 if ( $this->asyncWrites ) {
484 DeferredUpdates::addCallableUpdate(
485 function() use ( $backend, $realOps ) {
486 $backend->doQuickOperations( $realOps );
489 } else {
490 $status->merge( $backend->doQuickOperations( $realOps ) );
493 // Make 'success', 'successCount', and 'failCount' fields reflect
494 // the overall operation, rather than all the batches for each backend.
495 // Do this by only using success values from the master backend's batch.
496 $status->success = $masterStatus->success;
497 $status->successCount = $masterStatus->successCount;
498 $status->failCount = $masterStatus->failCount;
500 return $status;
503 protected function doPrepare( array $params ) {
504 return $this->doDirectoryOp( 'prepare', $params );
507 protected function doSecure( array $params ) {
508 return $this->doDirectoryOp( 'secure', $params );
511 protected function doPublish( array $params ) {
512 return $this->doDirectoryOp( 'publish', $params );
515 protected function doClean( array $params ) {
516 return $this->doDirectoryOp( 'clean', $params );
520 * @param string $method One of (doPrepare,doSecure,doPublish,doClean)
521 * @param array $params Method arguments
522 * @return Status
524 protected function doDirectoryOp( $method, array $params ) {
525 $status = Status::newGood();
527 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
528 $masterStatus = $this->backends[$this->masterIndex]->$method( $realParams );
529 $status->merge( $masterStatus );
531 foreach ( $this->backends as $index => $backend ) {
532 if ( $index === $this->masterIndex ) {
533 continue; // already done
536 $realParams = $this->substOpPaths( $params, $backend );
537 if ( $this->asyncWrites ) {
538 DeferredUpdates::addCallableUpdate(
539 function() use ( $backend, $method, $realParams ) {
540 $backend->$method( $realParams );
543 } else {
544 $status->merge( $backend->$method( $realParams ) );
548 return $status;
551 public function concatenate( array $params ) {
552 // We are writing to an FS file, so we don't need to do this per-backend
553 $index = $this->getReadIndexFromParams( $params );
554 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
556 return $this->backends[$index]->concatenate( $realParams );
559 public function fileExists( array $params ) {
560 $index = $this->getReadIndexFromParams( $params );
561 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
563 return $this->backends[$index]->fileExists( $realParams );
566 public function getFileTimestamp( array $params ) {
567 $index = $this->getReadIndexFromParams( $params );
568 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
570 return $this->backends[$index]->getFileTimestamp( $realParams );
573 public function getFileSize( array $params ) {
574 $index = $this->getReadIndexFromParams( $params );
575 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
577 return $this->backends[$index]->getFileSize( $realParams );
580 public function getFileStat( array $params ) {
581 $index = $this->getReadIndexFromParams( $params );
582 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
584 return $this->backends[$index]->getFileStat( $realParams );
587 public function getFileXAttributes( array $params ) {
588 $index = $this->getReadIndexFromParams( $params );
589 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
591 return $this->backends[$index]->getFileXAttributes( $realParams );
594 public function getFileContentsMulti( array $params ) {
595 $index = $this->getReadIndexFromParams( $params );
596 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
598 $contentsM = $this->backends[$index]->getFileContentsMulti( $realParams );
600 $contents = array(); // (path => FSFile) mapping using the proxy backend's name
601 foreach ( $contentsM as $path => $data ) {
602 $contents[$this->unsubstPaths( $path )] = $data;
605 return $contents;
608 public function getFileSha1Base36( array $params ) {
609 $index = $this->getReadIndexFromParams( $params );
610 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
612 return $this->backends[$index]->getFileSha1Base36( $realParams );
615 public function getFileProps( array $params ) {
616 $index = $this->getReadIndexFromParams( $params );
617 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
619 return $this->backends[$index]->getFileProps( $realParams );
622 public function streamFile( array $params ) {
623 $index = $this->getReadIndexFromParams( $params );
624 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
626 return $this->backends[$index]->streamFile( $realParams );
629 public function getLocalReferenceMulti( array $params ) {
630 $index = $this->getReadIndexFromParams( $params );
631 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
633 $fsFilesM = $this->backends[$index]->getLocalReferenceMulti( $realParams );
635 $fsFiles = array(); // (path => FSFile) mapping using the proxy backend's name
636 foreach ( $fsFilesM as $path => $fsFile ) {
637 $fsFiles[$this->unsubstPaths( $path )] = $fsFile;
640 return $fsFiles;
643 public function getLocalCopyMulti( array $params ) {
644 $index = $this->getReadIndexFromParams( $params );
645 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
647 $tempFilesM = $this->backends[$index]->getLocalCopyMulti( $realParams );
649 $tempFiles = array(); // (path => TempFSFile) mapping using the proxy backend's name
650 foreach ( $tempFilesM as $path => $tempFile ) {
651 $tempFiles[$this->unsubstPaths( $path )] = $tempFile;
654 return $tempFiles;
657 public function getFileHttpUrl( array $params ) {
658 $index = $this->getReadIndexFromParams( $params );
659 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
661 return $this->backends[$index]->getFileHttpUrl( $realParams );
664 public function directoryExists( array $params ) {
665 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
667 return $this->backends[$this->masterIndex]->directoryExists( $realParams );
670 public function getDirectoryList( array $params ) {
671 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
673 return $this->backends[$this->masterIndex]->getDirectoryList( $realParams );
676 public function getFileList( array $params ) {
677 $realParams = $this->substOpPaths( $params, $this->backends[$this->masterIndex] );
679 return $this->backends[$this->masterIndex]->getFileList( $realParams );
682 public function getFeatures() {
683 return $this->backends[$this->masterIndex]->getFeatures();
686 public function clearCache( array $paths = null ) {
687 foreach ( $this->backends as $backend ) {
688 $realPaths = is_array( $paths ) ? $this->substPaths( $paths, $backend ) : null;
689 $backend->clearCache( $realPaths );
693 public function preloadCache( array $paths ) {
694 $realPaths = $this->substPaths( $paths, $this->backends[$this->readIndex] );
695 $this->backends[$this->readIndex]->preloadCache( $realPaths );
698 public function preloadFileStat( array $params ) {
699 $index = $this->getReadIndexFromParams( $params );
700 $realParams = $this->substOpPaths( $params, $this->backends[$index] );
702 return $this->backends[$index]->preloadFileStat( $realParams );
705 public function getScopedLocksForOps( array $ops, Status $status ) {
706 $realOps = $this->substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
707 $fileOps = $this->backends[$this->masterIndex]->getOperationsInternal( $realOps );
708 // Get the paths to lock from the master backend
709 $paths = $this->backends[$this->masterIndex]->getPathsToLockForOpsInternal( $fileOps );
710 // Get the paths under the proxy backend's name
711 $pbPaths = array(
712 LockManager::LOCK_UW => $this->unsubstPaths( $paths[LockManager::LOCK_UW] ),
713 LockManager::LOCK_EX => $this->unsubstPaths( $paths[LockManager::LOCK_EX] )
716 // Actually acquire the locks
717 return $this->getScopedFileLocks( $pbPaths, 'mixed', $status );
721 * @param array $params
722 * @return int The master or read affinity backend index, based on $params['latest']
724 protected function getReadIndexFromParams( array $params ) {
725 return !empty( $params['latest'] ) ? $this->masterIndex : $this->readIndex;