98 parent::__construct( $config );
99 $this->syncChecks = isset( $config[
'syncChecks'] )
100 ? $config[
'syncChecks']
102 $this->autoResync = isset( $config[
'autoResync'] )
103 ? $config[
'autoResync']
105 $this->asyncWrites = isset( $config[
'replication'] ) && $config[
'replication'] ===
'async';
109 foreach ( $config[
'backends']
as $index => $config ) {
110 if ( isset( $config[
'template'] ) ) {
115 $name = $config[
'name'];
116 if ( isset( $namesUsed[
$name] ) ) {
117 throw new FileBackendError(
"Two or more backends defined with the name $name." );
119 $namesUsed[
$name] = 1;
121 unset( $config[
'readOnly'] );
122 unset( $config[
'fileJournal'] );
123 unset( $config[
'lockManager'] );
125 if ( !empty( $config[
'isMultiMaster'] ) ) {
126 if ( $this->masterIndex >= 0 ) {
129 $this->masterIndex = $index;
132 if ( !empty( $config[
'readAffinity'] ) ) {
133 $this->readIndex = $index;
136 if ( !isset( $config[
'class'] ) ) {
139 $class = $config[
'class'];
140 $this->backends[$index] =
new $class( $config );
142 if ( $this->masterIndex < 0 ) {
145 if ( $this->readIndex < 0 ) {
157 if ( empty( $opts[
'nonLocking'] ) ) {
167 $opts[
'preserveCache'] =
true;
177 if ( !$syncStatus->isOK() ) {
178 wfDebugLog(
'FileOperation', get_class( $this ) .
181 if ( $this->autoResync ===
false
182 || !$this->
resyncFiles( $relevantPaths, $this->autoResync )->isOK()
191 $masterStatus = $mbe->doOperations( $realOps, $opts );
192 $status->merge( $masterStatus );
197 if ( $masterStatus->isOK() && $masterStatus->successCount > 0 ) {
198 foreach ( $this->backends
as $index => $backend ) {
199 if ( $index === $this->masterIndex ) {
207 function()
use ( $backend, $realOps, $opts, $scopeLock, $relevantPaths ) {
209 "'{$backend->getName()}' async replication; paths: " .
211 $backend->doOperations( $realOps, $opts );
216 "'{$backend->getName()}' sync replication; paths: " .
218 $status->merge( $backend->doOperations( $realOps, $opts ) );
225 $status->success = $masterStatus->success;
226 $status->successCount = $masterStatus->successCount;
227 $status->failCount = $masterStatus->failCount;
240 if ( $this->syncChecks == 0 || count( $this->backends ) <= 1 ) {
245 foreach ( $this->backends
as $backend ) {
246 $realPaths = $this->
substPaths( $paths, $backend );
247 $backend->preloadFileStat( [
'srcs' => $realPaths,
'latest' =>
true ] );
255 $mStat = $mBackend->getFileStat( $mParams );
256 if ( $this->syncChecks & self::CHECK_SHA1 ) {
257 $mSha1 = $mBackend->getFileSha1Base36( $mParams );
262 foreach ( $this->backends
as $index => $cBackend ) {
263 if ( $index === $this->masterIndex ) {
267 $cStat = $cBackend->getFileStat( $cParams );
270 $status->fatal(
'backend-fail-synced', $path );
273 if ( $this->syncChecks & self::CHECK_SIZE ) {
274 if ( $cStat[
'size'] != $mStat[
'size'] ) {
275 $status->fatal(
'backend-fail-synced', $path );
279 if ( $this->syncChecks & self::CHECK_TIME ) {
282 if ( abs( $mTs - $cTs ) > 30 ) {
283 $status->fatal(
'backend-fail-synced', $path );
287 if ( $this->syncChecks & self::CHECK_SHA1 ) {
288 if ( $cBackend->getFileSha1Base36( $cParams ) !== $mSha1 ) {
289 $status->fatal(
'backend-fail-synced', $path );
295 $status->fatal(
'backend-fail-synced', $path );
312 if ( count( $this->backends ) <= 1 ) {
317 foreach ( $this->backends
as $backend ) {
318 $realPath = $this->
substPaths( $path, $backend );
319 if ( !$backend->isPathUsableInternal( $realPath ) ) {
320 $status->fatal(
'backend-fail-usable', $path );
341 $mPath = $this->
substPaths( $path, $mBackend );
342 $mSha1 = $mBackend->getFileSha1Base36( [
'src' => $mPath,
'latest' =>
true ] );
343 $mStat = $mBackend->getFileStat( [
'src' => $mPath,
'latest' =>
true ] );
344 if ( $mStat === null || ( $mSha1 !==
false && !$mStat ) ) {
345 $status->fatal(
'backend-fail-internal', $this->
name );
347 .
': File is not available on the master backend' );
351 foreach ( $this->backends
as $index => $cBackend ) {
352 if ( $index === $this->masterIndex ) {
355 $cPath = $this->
substPaths( $path, $cBackend );
356 $cSha1 = $cBackend->getFileSha1Base36( [
'src' => $cPath,
'latest' =>
true ] );
357 $cStat = $cBackend->getFileStat( [
'src' => $cPath,
'latest' =>
true ] );
358 if ( $cStat === null || ( $cSha1 !==
false && !$cStat ) ) {
359 $status->fatal(
'backend-fail-internal', $cBackend->getName() );
361 ': File is not available on the clone backend' );
364 if ( $mSha1 === $cSha1 ) {
366 } elseif ( $mSha1 !==
false ) {
367 if ( $resyncMode ===
'conservative'
368 && $cStat && $cStat[
'mtime'] > $mStat[
'mtime']
370 $status->fatal(
'backend-fail-synced', $path );
373 $fsFile = $mBackend->getLocalReference(
374 [
'src' => $mPath,
'latest' =>
true ] );
375 $status->merge( $cBackend->quickStore(
376 [
'src' => $fsFile->getPath(),
'dst' => $cPath ]
378 } elseif ( $mStat ===
false ) {
379 if ( $resyncMode ===
'conservative' ) {
380 $status->fatal(
'backend-fail-synced', $path );
383 $status->merge( $cBackend->quickDelete( [
'src' => $cPath ] ) );
389 wfDebugLog(
'FileOperation', get_class( $this ) .
404 foreach ( $ops
as $op ) {
405 if ( isset( $op[
'src'] ) ) {
408 if ( empty( $op[
'ignoreMissingSource'] )
409 || $this->
fileExists( [
'src' => $op[
'src'] ] )
411 $paths[] = $op[
'src'];
414 if ( isset( $op[
'srcs'] ) ) {
415 $paths = array_merge( $paths, $op[
'srcs'] );
417 if ( isset( $op[
'dst'] ) ) {
418 $paths[] = $op[
'dst'];
422 return array_values( array_unique( array_filter( $paths,
'FileBackend::isStoragePath' ) ) );
435 foreach ( $ops
as $op ) {
437 foreach ( [
'src',
'srcs',
'dst',
'dir' ]
as $par ) {
438 if ( isset( $newOp[$par] ) ) {
439 $newOp[$par] = $this->
substPaths( $newOp[$par], $backend );
470 '!^mwstore://' . preg_quote( $this->
name,
'!' ) .
'/!',
471 StringUtils::escapeRegexReplacement(
"mwstore://{$backend->getName()}/" ),
484 '!^mwstore://([^/]+)!',
485 StringUtils::escapeRegexReplacement(
"mwstore://{$this->name}" ),
495 foreach ( $ops
as $op ) {
496 if ( $op[
'op'] ===
'store' && !isset( $op[
'srcRef'] ) ) {
507 $realOps = $this->
substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
509 $status->merge( $masterStatus );
511 foreach ( $this->backends
as $index => $backend ) {
512 if ( $index === $this->masterIndex ) {
519 function()
use ( $backend, $realOps ) {
520 $backend->doQuickOperations( $realOps );
524 $status->merge( $backend->doQuickOperations( $realOps ) );
530 $status->success = $masterStatus->success;
531 $status->successCount = $masterStatus->successCount;
532 $status->failCount = $masterStatus->failCount;
561 $realParams = $this->
substOpPaths( $params, $this->backends[$this->masterIndex] );
563 $status->merge( $masterStatus );
565 foreach ( $this->backends
as $index => $backend ) {
566 if ( $index === $this->masterIndex ) {
571 if ( $this->asyncWrites ) {
573 function()
use ( $backend, $method, $realParams ) {
574 $backend->$method( $realParams );
578 $status->merge( $backend->$method( $realParams ) );
588 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
590 return $this->backends[$index]->concatenate( $realParams );
595 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
597 return $this->backends[$index]->fileExists( $realParams );
602 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
604 return $this->backends[$index]->getFileTimestamp( $realParams );
609 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
611 return $this->backends[$index]->getFileSize( $realParams );
616 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
618 return $this->backends[$index]->getFileStat( $realParams );
623 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
625 return $this->backends[$index]->getFileXAttributes( $realParams );
630 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
632 $contentsM = $this->backends[$index]->getFileContentsMulti( $realParams );
635 foreach ( $contentsM
as $path => $data ) {
644 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
646 return $this->backends[$index]->getFileSha1Base36( $realParams );
651 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
653 return $this->backends[$index]->getFileProps( $realParams );
658 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
660 return $this->backends[$index]->streamFile( $realParams );
665 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
667 $fsFilesM = $this->backends[$index]->getLocalReferenceMulti( $realParams );
670 foreach ( $fsFilesM
as $path => $fsFile ) {
679 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
681 $tempFilesM = $this->backends[$index]->getLocalCopyMulti( $realParams );
684 foreach ( $tempFilesM
as $path => $tempFile ) {
693 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
695 return $this->backends[$index]->getFileHttpUrl( $realParams );
699 $realParams = $this->
substOpPaths( $params, $this->backends[$this->masterIndex] );
705 $realParams = $this->
substOpPaths( $params, $this->backends[$this->masterIndex] );
711 $realParams = $this->
substOpPaths( $params, $this->backends[$this->masterIndex] );
721 foreach ( $this->backends
as $backend ) {
722 $realPaths = is_array( $paths ) ? $this->
substPaths( $paths, $backend ) : null;
723 $backend->clearCache( $realPaths );
728 $realPaths = $this->
substPaths( $paths, $this->backends[$this->readIndex] );
734 $realParams = $this->
substOpPaths( $params, $this->backends[$index] );
736 return $this->backends[$index]->preloadFileStat( $realParams );
740 $realOps = $this->
substOpBatchPaths( $ops, $this->backends[$this->masterIndex] );
743 $paths = $this->backends[
$this->masterIndex]->getPathsToLockForOpsInternal( $fileOps );
getFileSha1Base36(array $params)
the array() calling protocol came about after MediaWiki 1.4rc1.
FileBackendStore[] $backends
Prioritized list of FileBackendStore objects.
getFileTimestamp(array $params)
substOpPaths(array $ops, FileBackendStore $backend)
Same as substOpBatchPaths() but for a single operation.
substOpBatchPaths(array $ops, FileBackendStore $backend)
Substitute the backend name in storage path parameters for a set of operations with that of a given i...
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
getScopedLocksForOps(array $ops, Status $status)
concatenate(array $params)
Generic operation result class Has warning/error list, boolean status and arbitrary value...
getFileList(array $params)
accessibilityCheck(array $paths)
Check that a set of file paths are usable across all internal backends.
clearCache(array $paths=null)
getDirectoryList(array $params)
getFileProps(array $params)
fileStoragePathsForOps(array $ops)
Get a list of file storage paths to read or write for a list of operations.
directoryExists(array $params)
doQuickOperationsInternal(array $ops)
static addCallableUpdate($callable, $type=self::POSTSEND)
Add a callable update.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
consistencyCheck(array $paths)
Check that a set of files are consistent across all internal backends.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
File backend exception for checked exceptions (e.g.
getLocalCopyMulti(array $params)
substPaths($paths, FileBackendStore $backend)
Substitute the backend of storage paths with an internal backend's name.
int $readIndex
Index of read affinity backend.
getLocalReferenceMulti(array $params)
getFileSize(array $params)
streamFile(array $params)
doOperationsInternal(array $ops, array $opts)
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getReadIndexFromParams(array $params)
getFileStat(array $params)
getFileHttpUrl(array $params)
string $name
Unique backend name.
Base class for all backends using particular storage medium.
preloadFileStat(array $params)
hasVolatileSources(array $ops)
resyncFiles(array $paths, $resyncMode=true)
Check that a set of files are consistent across all internal backends and re-synchronize those files ...
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
preloadCache(array $paths)
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at name
Proxy backend that mirrors writes to several internal backends.
Base class for all file backend classes (including multi-write backends).
fileExists(array $params)
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set $status
__construct(array $config)
Construct a proxy backend that consists of several internal backends.
getFileContentsMulti(array $params)
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
string $wikiId
Unique wiki name.
getFileXAttributes(array $params)
int $masterIndex
Index of master backend.
doDirectoryOp($method, array $params)
unsubstPaths($paths)
Substitute the backend of internal storage paths with the proxy backend's name.
static newGood($value=null)
Factory function for good results.
getScopedFileLocks(array $paths, $type, Status $status, $timeout=0)
Lock the files at the given storage paths in the backend.