MediaWiki  REL1_22
FileBackendMultiWrite Class Reference

Proxy backend that mirrors writes to several internal backends. More...

Inheritance diagram for FileBackendMultiWrite:
Collaboration diagram for FileBackendMultiWrite:

List of all members.

Public Member Functions

 __construct (array $config)
 Construct a proxy backend that consists of several internal backends.
 accessibilityCheck (array $paths)
 Check that a set of file paths are usable across all internal backends.
 clearCache (array $paths=null)
 Invalidate any in-process file stat and property cache.
 concatenate (array $params)
 Concatenate a list of storage files into a single file system file.
 consistencyCheck (array $paths)
 Check that a set of files are consistent across all internal backends.
 directoryExists (array $params)
 Check if a directory exists at a given storage path.
 fileExists (array $params)
 Check if a file exists at a storage path in the backend.
 getDirectoryList (array $params)
 Get an iterator to list *all* directories under a storage directory.
 getFileContentsMulti (array $params)
 Like getFileContents() except it takes an array of storage paths and returns a map of storage paths to strings (or null on failure).
 getFileHttpUrl (array $params)
 Return an HTTP URL to a given file that requires no authentication to use.
 getFileList (array $params)
 Get an iterator to list *all* stored files under a storage directory.
 getFileProps (array $params)
 Get the properties of the file at a storage path in the backend.
 getFileSha1Base36 (array $params)
 Get a SHA-1 hash of the file at a storage path in the backend.
 getFileSize (array $params)
 Get the size (bytes) of a file at a storage path in the backend.
 getFileStat (array $params)
 Get quick information about a file at a storage path in the backend.
 getFileTimestamp (array $params)
 Get the last-modified timestamp of the file at a storage path.
 getLocalCopyMulti (array $params)
 Like getLocalCopy() except it takes an array of storage paths and returns a map of storage paths to TempFSFile objects (or null on failure).
 getLocalReferenceMulti (array $params)
 Like getLocalReference() except it takes an array of storage paths and returns a map of storage paths to FSFile objects (or null on failure).
 getScopedLocksForOps (array $ops, Status $status)
 Get an array of scoped locks needed for a batch of file operations.
 resyncFiles (array $paths)
 Check that a set of files are consistent across all internal backends and re-synchronize those files againt the "multi master" if needed.
 streamFile (array $params)
 Stream the file at a storage path in the backend.

Public Attributes

const CHECK_SHA1 = 4
const CHECK_SIZE = 1
const CHECK_TIME = 2

Protected Member Functions

 doClean (array $params)
 doOperationsInternal (array $ops, array $opts)
 doPrepare (array $params)
 doPublish (array $params)
 doQuickOperationsInternal (array $ops)
 doSecure (array $params)
 fileStoragePathsForOps (array $ops)
 Get a list of file storage paths to read or write for a list of operations.
 replicateContainerDirChanges ($path)
 substOpBatchPaths (array $ops, FileBackendStore $backend)
 Substitute the backend name in storage path parameters for a set of operations with that of a given internal backend.
 substOpPaths (array $ops, FileBackendStore $backend)
 Same as substOpBatchPaths() but for a single operation.
 substPaths ($paths, FileBackendStore $backend)
 Substitute the backend of storage paths with an internal backend's name.
 unsubstPaths ($paths)
 Substitute the backend of internal storage paths with the proxy backend's name.

Protected Attributes

 $autoResync = false
Array $backends = array()
 Prioritized list of FileBackendStore objects *.
 $masterIndex = -1
Array $noPushDirConts = array()
 *
 $noPushQuickOps = false
 $syncChecks = 0

Detailed Description

Proxy backend that mirrors writes to several internal backends.

This class defines a multi-write backend. Multiple backends can be registered to this proxy backend and it will act as a single backend. Use this when all access to those backends is through this proxy backend. At least one of the backends must be declared the "master" backend.

Only use this class when transitioning from one storage system to another.

Read operations are only done on the 'master' backend for consistency. Write operations are performed on all backends, in the order defined. If an operation fails on one backend it will be rolled back from the others.

Since:
1.19

Definition at line 42 of file FileBackendMultiWrite.php.


Constructor & Destructor Documentation

Construct a proxy backend that consists of several internal backends.

Locking, journaling, and read-only checks are handled by the proxy backend.

Additional $config params include:

  • backends : Array of backend config and multi-backend settings. Each value is the config used in the constructor of a FileBackendStore class, but with these additional settings:
    • class : The name of the backend class
    • isMultiMaster : This must be set for one backend.
    • template: : If given a backend name, this will use the config of that backend as a template. Values specified here take precedence.
  • syncChecks : Integer bitfield of internal backend sync checks to perform. Possible bits include the FileBackendMultiWrite::CHECK_* constants. There are constants for SIZE, TIME, and SHA1. The checks are done before allowing any file operations.
  • autoResync : Automatically resync the clone backends to the master backend when pre-operation sync checks fail. This should only be used if the master backend is stable and not missing any files. Use "conservative" to limit resyncing to copying newer master backend files over older (or non-existing) clone backend files. Cases that cannot be handled will result in operation abortion.
  • noPushQuickOps : (hack) Only apply doQuickOperations() to the master backend.
  • noPushDirConts : (hack) Only apply directory functions to the master backend.
Parameters:
Array$config
Exceptions:
MWException

Reimplemented from FileBackend.

Definition at line 85 of file FileBackendMultiWrite.php.


Member Function Documentation

Check that a set of file paths are usable across all internal backends.

Parameters:
array$pathsList of storage paths
Returns:
Status

Definition at line 269 of file FileBackendMultiWrite.php.

Invalidate any in-process file stat and property cache.

If $paths is given, then only the cache for those files will be cleared.

Parameters:
array$pathsStorage paths (optional)
Returns:
void

Reimplemented from FileBackend.

Definition at line 611 of file FileBackendMultiWrite.php.

Concatenate a list of storage files into a single file system file.

The target path should refer to a file that is already locked or otherwise safe from modification from other processes. Normally, the file will be a new temp file, which should be adequate.

Parameters:
array$paramsOperation parameters $params include:
  • srcs : ordered source storage paths (e.g. chunk1, chunk2, ...)
  • dst : file system path to 0-byte temp file
  • parallelize : try to do operations in parallel when possible
Returns:
Status

Reimplemented from FileBackend.

Definition at line 517 of file FileBackendMultiWrite.php.

Check that a set of files are consistent across all internal backends.

Parameters:
array$pathsList of storage paths
Returns:
Status

Definition at line 203 of file FileBackendMultiWrite.php.

Check if a directory exists at a given storage path.

Backends using key/value stores will check if the path is a virtual directory, meaning there are files under the given directory.

Storage backends with eventual consistency might return stale data.

Parameters:
array$params$params include:
  • dir : storage directory
Returns:
bool|null Returns null on failure
Since:
1.20

Reimplemented from FileBackend.

Definition at line 596 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::doClean ( array params) [protected]
See also:
FileBackend::clean()

Reimplemented from FileBackend.

Definition at line 505 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::doOperationsInternal ( array ops,
array opts 
) [final, protected]
See also:
FileBackend::doOperations()

Reimplemented from FileBackend.

Definition at line 137 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::doPrepare ( array params) [protected]
See also:
FileBackend::prepare()

Reimplemented from FileBackend.

Definition at line 469 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::doPublish ( array params) [protected]
See also:
FileBackend::publish()

Reimplemented from FileBackend.

Definition at line 493 of file FileBackendMultiWrite.php.

See also:
FileBackend::doQuickOperations()
Since:
1.20

Reimplemented from FileBackend.

Definition at line 436 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::doSecure ( array params) [protected]
See also:
FileBackend::secure()

Reimplemented from FileBackend.

Definition at line 481 of file FileBackendMultiWrite.php.

Check if a file exists at a storage path in the backend.

This returns false if only a directory exists at the path.

Parameters:
array$params$params include:
  • src : source storage path
  • latest : use the latest available data
Returns:
bool|null Returns null on failure

Reimplemented from FileBackend.

Definition at line 523 of file FileBackendMultiWrite.php.

Get a list of file storage paths to read or write for a list of operations.

Parameters:
array$opsSame format as doOperations()
Returns:
Array List of storage paths to files (does not include directories)

Definition at line 351 of file FileBackendMultiWrite.php.

Get an iterator to list *all* directories under a storage directory.

If the directory is of the form "mwstore://backend/container", then all directories in the container will be listed. If the directory is of form "mwstore://backend/container/dir", then all directories directly under that directory will be listed. Results will be storage directories relative to the given directory.

Storage backends with eventual consistency might return stale data.

Failures during iteration can result in FileBackendError exceptions (since 1.22).

Parameters:
array$params$params include:
  • dir : storage directory
  • topOnly : only return direct child dirs of the directory
Returns:
Traversable|Array|null Returns null on failure
Since:
1.20

Reimplemented from FileBackend.

Definition at line 601 of file FileBackendMultiWrite.php.

Like getFileContents() except it takes an array of storage paths and returns a map of storage paths to strings (or null on failure).

The map keys (paths) are in the same order as the provided list of paths.

See also:
FileBackend::getFileContents()
Parameters:
array$params$params include:
  • srcs : list of source storage paths
  • latest : use the latest available data
  • parallelize : try to do operations in parallel when possible
Returns:
Array Map of (path name => string or false on failure)
Since:
1.20

Reimplemented from FileBackend.

Definition at line 543 of file FileBackendMultiWrite.php.

Return an HTTP URL to a given file that requires no authentication to use.

The URL may be pre-authenticated (via some token in the URL) and temporary. This will return null if the backend cannot make an HTTP URL for the file.

This is useful for key/value stores when using scripts that seek around large files and those scripts (and the backend) support HTTP Range headers. Otherwise, one would need to use getLocalReference(), which involves loading the entire file on to local disk.

Parameters:
array$params$params include:
  • src : source storage path
  • ttl : lifetime (seconds) if pre-authenticated; default is 1 day
Returns:
string|null
Since:
1.21

Reimplemented from FileBackend.

Definition at line 591 of file FileBackendMultiWrite.php.

Get an iterator to list *all* stored files under a storage directory.

If the directory is of the form "mwstore://backend/container", then all files in the container will be listed. If the directory is of form "mwstore://backend/container/dir", then all files under that directory will be listed. Results will be storage paths relative to the given directory.

Storage backends with eventual consistency might return stale data.

Failures during iteration can result in FileBackendError exceptions (since 1.22).

Parameters:
array$params$params include:
  • dir : storage directory
  • topOnly : only return direct child files of the directory (since 1.20)
  • adviseStat : set to true if stat requests will be made on the files (since 1.22)
Returns:
Traversable|Array|null Returns null on failure

Reimplemented from FileBackend.

Definition at line 606 of file FileBackendMultiWrite.php.

Get the properties of the file at a storage path in the backend.

This gives the result of FSFile::getProps() on a local copy of the file.

Parameters:
array$params$params include:
  • src : source storage path
  • latest : use the latest available data
Returns:
Array Returns FSFile::placeholderProps() on failure

Reimplemented from FileBackend.

Definition at line 559 of file FileBackendMultiWrite.php.

Get a SHA-1 hash of the file at a storage path in the backend.

Parameters:
array$params$params include:
  • src : source storage path
  • latest : use the latest available data
Returns:
string|bool Hash string or false on failure

Reimplemented from FileBackend.

Definition at line 554 of file FileBackendMultiWrite.php.

Get the size (bytes) of a file at a storage path in the backend.

Parameters:
array$params$params include:
  • src : source storage path
  • latest : use the latest available data
Returns:
integer|bool Returns false on failure

Reimplemented from FileBackend.

Definition at line 533 of file FileBackendMultiWrite.php.

Get quick information about a file at a storage path in the backend.

If the file does not exist, then this returns false. Otherwise, the result is an associative array that includes:

  • mtime : the last-modified timestamp (TS_MW)
  • size : the file size (bytes) Additional values may be included for internal use only.
Parameters:
array$params$params include:
  • src : source storage path
  • latest : use the latest available data
Returns:
Array|bool|null Returns null on failure

Reimplemented from FileBackend.

Definition at line 538 of file FileBackendMultiWrite.php.

Get the last-modified timestamp of the file at a storage path.

Parameters:
array$params$params include:
  • src : source storage path
  • latest : use the latest available data
Returns:
string|bool TS_MW timestamp or false on failure

Reimplemented from FileBackend.

Definition at line 528 of file FileBackendMultiWrite.php.

Like getLocalCopy() except it takes an array of storage paths and returns a map of storage paths to TempFSFile objects (or null on failure).

The map keys (paths) are in the same order as the provided list of paths.

See also:
FileBackend::getLocalCopy()
Parameters:
array$params$params include:
  • srcs : list of source storage paths
  • latest : use the latest available data
  • parallelize : try to do operations in parallel when possible
Returns:
Array Map of (path name => TempFSFile or null on failure)
Since:
1.20

Reimplemented from FileBackend.

Definition at line 580 of file FileBackendMultiWrite.php.

Like getLocalReference() except it takes an array of storage paths and returns a map of storage paths to FSFile objects (or null on failure).

The map keys (paths) are in the same order as the provided list of paths.

See also:
FileBackend::getLocalReference()
Parameters:
array$params$params include:
  • srcs : list of source storage paths
  • latest : use the latest available data
  • parallelize : try to do operations in parallel when possible
Returns:
Array Map of (path name => FSFile or null on failure)
Since:
1.20

Reimplemented from FileBackend.

Definition at line 569 of file FileBackendMultiWrite.php.

Get an array of scoped locks needed for a batch of file operations.

Normally, FileBackend::doOperations() handles locking, unless the 'nonLocking' param is passed in. This function is useful if you want the files to be locked for a broader scope than just when the files are changing. For example, if you need to update DB metadata, you may want to keep the files locked until finished.

See also:
FileBackend::doOperations()
Parameters:
array$opsList of file operations to FileBackend::doOperations()
Status$statusStatus to update on lock/unlock
Returns:
Array List of ScopedFileLocks or null values
Since:
1.20

Reimplemented from FileBackend.

Definition at line 618 of file FileBackendMultiWrite.php.

Parameters:
string$pathStorage path
Returns:
bool Path container should have dir changes pushed to all backends

Definition at line 464 of file FileBackendMultiWrite.php.

Check that a set of files are consistent across all internal backends and re-synchronize those files againt the "multi master" if needed.

Parameters:
array$pathsList of storage paths
Returns:
Status

Definition at line 294 of file FileBackendMultiWrite.php.

Stream the file at a storage path in the backend.

If the file does not exists, an HTTP 404 error will be given. Appropriate HTTP headers (Status, Content-Type, Content-Length) will be sent if streaming began, while none will be sent otherwise. Implementations should flush the output buffer before sending data.

Parameters:
array$params$params include:
  • src : source storage path
  • headers : list of additional HTTP headers to send on success
  • latest : use the latest available data
Returns:
Status

Reimplemented from FileBackend.

Definition at line 564 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::substOpBatchPaths ( array ops,
FileBackendStore backend 
) [protected]

Substitute the backend name in storage path parameters for a set of operations with that of a given internal backend.

Parameters:
array$opsList of file operation arrays
FileBackendStore$backend
Returns:
Array

Definition at line 381 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::substOpPaths ( array ops,
FileBackendStore backend 
) [protected]

Same as substOpBatchPaths() but for a single operation.

Parameters:
array$opsFile operation array
FileBackendStore$backend
Returns:
Array

Definition at line 402 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::substPaths ( paths,
FileBackendStore backend 
) [protected]

Substitute the backend of storage paths with an internal backend's name.

Parameters:
array | string$pathsList of paths or single string path
FileBackendStore$backend
Returns:
Array|string

Definition at line 414 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::unsubstPaths ( paths) [protected]

Substitute the backend of internal storage paths with the proxy backend's name.

Parameters:
array | string$pathsList of paths or single string path
Returns:
Array|string

Definition at line 428 of file FileBackendMultiWrite.php.


Member Data Documentation

FileBackendMultiWrite::$autoResync = false [protected]

Definition at line 46 of file FileBackendMultiWrite.php.

Array FileBackendMultiWrite::$backends = array() [protected]

Prioritized list of FileBackendStore objects *.

Definition at line 43 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::$masterIndex = -1 [protected]

Definition at line 44 of file FileBackendMultiWrite.php.

Array FileBackendMultiWrite::$noPushDirConts = array() [protected]

*

Definition at line 48 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::$noPushQuickOps = false [protected]

Definition at line 49 of file FileBackendMultiWrite.php.

FileBackendMultiWrite::$syncChecks = 0 [protected]

Definition at line 45 of file FileBackendMultiWrite.php.

Definition at line 54 of file FileBackendMultiWrite.php.

Definition at line 52 of file FileBackendMultiWrite.php.

Definition at line 53 of file FileBackendMultiWrite.php.


The documentation for this class was generated from the following file: