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 ) .
179 " failed sync check: " . FormatJson::encode( $relevantPaths ) );
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 ) {
206 DeferredUpdates::addCallableUpdate(
207 function()
use ( $backend, $realOps, $opts, $scopeLock, $relevantPaths ) {
209 "'{$backend->getName()}' async replication; paths: " .
210 FormatJson::encode( $relevantPaths ) );
211 $backend->doOperations( $realOps, $opts );
216 "'{$backend->getName()}' sync replication; paths: " .
217 FormatJson::encode( $relevantPaths ) );
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 );
273 if ( $this->syncChecks & self::CHECK_SIZE ) {
274 if ( $cStat[
'size'] != $mStat[
'size'] ) {
279 if ( $this->syncChecks & self::CHECK_TIME ) {
282 if ( abs( $mTs - $cTs ) > 30 ) {
287 if ( $this->syncChecks & self::CHECK_SHA1 ) {
288 if ( $cBackend->getFileSha1Base36( $cParams ) !== $mSha1 ) {
312 if ( count( $this->backends ) <= 1 ) {
317 foreach ( $this->backends
as $backend ) {
318 $realPath = $this->
substPaths( $path, $backend );
319 if ( !$backend->isPathUsableInternal( $realPath ) ) {
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']
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' ) {
383 $status->merge( $cBackend->quickDelete( [
'src' => $cPath ] ) );
389 wfDebugLog(
'FileOperation', get_class( $this ) .
390 " failed to resync: " . FormatJson::encode( $paths ) );
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,
'!' ) .
'/!',
484 '!^mwstore://([^/]+)!',
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 ) {
518 DeferredUpdates::addCallableUpdate(
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 ) {
572 DeferredUpdates::addCallableUpdate(
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 );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
const TS_UNIX
Unix time - the number of seconds since 1970-01-01 00:00:00 UTC.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
File backend exception for checked exceptions (e.g.
Proxy backend that mirrors writes to several internal backends.
FileBackendStore[] $backends
Prioritized list of FileBackendStore objects.
fileExists(array $params)
Check if a file exists at a storage path in the backend.
getLocalReferenceMulti(array $params)
Like getLocalReference() except it takes an array of storage paths and returns a map of storage paths...
getLocalCopyMulti(array $params)
Like getLocalCopy() except it takes an array of storage paths and returns a map of storage paths to T...
consistencyCheck(array $paths)
Check that a set of files are consistent across all internal backends.
getFileSha1Base36(array $params)
Get a SHA-1 hash of the file at a storage path in the backend.
int $readIndex
Index of read affinity backend.
clearCache(array $paths=null)
Invalidate any in-process file stat and property cache.
getFileStat(array $params)
Get quick information about a file at a storage path in the backend.
getFileContentsMulti(array $params)
Like getFileContents() except it takes an array of storage paths and returns a map of storage paths t...
preloadCache(array $paths)
Preload persistent file stat cache and property cache into in-process cache.
resyncFiles(array $paths, $resyncMode=true)
Check that a set of files are consistent across all internal backends and re-synchronize those files ...
getDirectoryList(array $params)
Get an iterator to list all directories under a storage directory.
__construct(array $config)
Construct a proxy backend that consists of several internal backends.
getFileList(array $params)
Get an iterator to list all stored files under a storage directory.
getScopedLocksForOps(array $ops, Status $status)
Get an array of scoped locks needed for a batch of file operations.
getReadIndexFromParams(array $params)
doOperationsInternal(array $ops, array $opts)
streamFile(array $params)
Stream the file at a storage path in the backend.
int $masterIndex
Index of master backend.
accessibilityCheck(array $paths)
Check that a set of file paths are usable across all internal backends.
getFeatures()
Get the a bitfield of extra features supported by the backend medium.
hasVolatileSources(array $ops)
fileStoragePathsForOps(array $ops)
Get a list of file storage paths to read or write for a list of operations.
concatenate(array $params)
Concatenate a list of storage files into a single file system file.
doQuickOperationsInternal(array $ops)
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...
getFileProps(array $params)
Get the properties of the file at a storage path in the backend.
doDirectoryOp( $method, array $params)
getFileHttpUrl(array $params)
Return an HTTP URL to a given file that requires no authentication to use.
preloadFileStat(array $params)
Preload file stat information (concurrently if possible) into in-process cache.
getFileSize(array $params)
Get the size (bytes) of a file at a storage path in the backend.
getFileXAttributes(array $params)
Get metadata about a file at a storage path in the backend.
substPaths( $paths, FileBackendStore $backend)
Substitute the backend of storage paths with an internal backend's name.
directoryExists(array $params)
Check if a directory exists at a given storage path.
getFileTimestamp(array $params)
Get the last-modified timestamp of the file at a storage path.
unsubstPaths( $paths)
Substitute the backend of internal storage paths with the proxy backend's name.
Base class for all backends using particular storage medium.
Base class for all file backend classes (including multi-write backends).
string $name
Unique backend name.
string $wikiId
Unique wiki name.
getScopedFileLocks(array $paths, $type, Status $status, $timeout=0)
Lock the files at the given storage paths in the backend.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
static escapeRegexReplacement( $string)
Escape a string to make it suitable for inclusion in a preg_replace() replacement parameter.
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
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
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
the array() calling protocol came about after MediaWiki 1.4rc1.
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
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