MediaWiki
REL1_19
|
Helper class for representing operations with transaction support. More...
Public Member Functions | |
__construct (FileBackendStore $backend, array $params) | |
Build a new file operation transaction. | |
attempt () | |
Attempt the operation, backing up files as needed; this must be reversible. | |
failed () | |
Check if this operation failed precheck() or attempt() | |
getParam ($name) | |
Get the value of the parameter with the given name. | |
precheck (array &$predicates) | |
Check preconditions of the operation without writing anything. | |
storagePathsChanged () | |
Get a list of storage paths written to for this operation. | |
storagePathsRead () | |
Get a list of storage paths read from for this operation. | |
Static Public Member Functions | |
static | attemptBatch (array $performOps, array $opts) |
Attempt a series of file operations. | |
static | newPredicates () |
Get a new empty predicates array for precheck() | |
Public Attributes | |
const | MAX_BATCH_SIZE = 1000 |
const | STATE_ATTEMPTED = 3 |
const | STATE_CHECKED = 2 |
const | STATE_NEW = 1 |
const | TIME_LIMIT_SEC = 300 |
Protected Member Functions | |
allowedParams () | |
Get the file operation parameters. | |
allowStaleReads () | |
Allow stale data for file reads and existence checks. | |
doAttempt () | |
doPrecheck (array &$predicates) | |
fileExists ($source, array $predicates) | |
Check if a file will exist in storage when this operation is attempted. | |
fileSha1 ($source, array $predicates) | |
Get the SHA-1 of a file in storage when this operation is attempted. | |
getSourceSha1Base36 () | |
precheckDestExistence() helper function to get the source file SHA-1. | |
logFailure ($action) | |
Log a file operation failure and preserve any temp files. | |
precheckDestExistence (array $predicates) | |
Check for errors with regards to the destination file already existing. | |
Protected Attributes | |
$backend | |
$destSameAsSource | |
$failed = false | |
$params = array() | |
$sourceSha1 | |
$state = self::STATE_NEW | |
$useLatest = true |
Helper class for representing operations with transaction support.
Do not use this class from places outside FileBackend.
Methods called from attemptBatch() should avoid throwing exceptions at all costs. FileOp objects should be lightweight in order to support large arrays in memory.
Definition at line 18 of file FileOp.php.
FileOp::__construct | ( | FileBackendStore $ | backend, |
array $ | params | ||
) | [final] |
Build a new file operation transaction.
$backend FileBackendStore $params Array
MWException |
Definition at line 47 of file FileOp.php.
References $backend, $params, and allowedParams().
FileOp::allowedParams | ( | ) | [protected] |
Get the file operation parameters.
Reimplemented in DeleteFileOp, MoveFileOp, CopyFileOp, CreateFileOp, and StoreFileOp.
Definition at line 229 of file FileOp.php.
Referenced by __construct().
FileOp::allowStaleReads | ( | ) | [final, protected] |
Allow stale data for file reads and existence checks.
Definition at line 70 of file FileOp.php.
FileOp::attempt | ( | ) | [final] |
Attempt the operation, backing up files as needed; this must be reversible.
Definition at line 209 of file FileOp.php.
References doAttempt(), failed(), logFailure(), Status\newFatal(), and STATE_ATTEMPTED.
static FileOp::attemptBatch | ( | array $ | performOps, |
array $ | opts | ||
) | [static, final] |
Attempt a series of file operations.
Callers are responsible for handling file locking.
$opts is an array of options, including: 'force' : Errors that would normally cause a rollback do not. The remaining operations are still attempted if any fail. 'allowStale' : Don't require the latest available data. This can increase performance for non-critical writes. This has no effect unless the 'force' flag is set.
The resulting Status will be "OK" unless: a) unexpected operation errors occurred (network partitions, disk full...) b) significant operation errors occured and 'force' was not set
$performOps | Array List of FileOp operations |
$opts | Array Batch operation options |
Definition at line 93 of file FileOp.php.
References $n, Status\newGood(), and newPredicates().
Referenced by FileBackendMultiWrite\doOperationsInternal(), and FileBackendStore\doOperationsInternal().
FileOp::doAttempt | ( | ) | [protected] |
Reimplemented in DeleteFileOp, MoveFileOp, CopyFileOp, CreateFileOp, and StoreFileOp.
Definition at line 261 of file FileOp.php.
References Status\newGood().
Referenced by attempt().
FileOp::doPrecheck | ( | array &$ | predicates | ) | [protected] |
Reimplemented in DeleteFileOp, MoveFileOp, CopyFileOp, CreateFileOp, and StoreFileOp.
Definition at line 254 of file FileOp.php.
References Status\newGood().
Referenced by precheck().
FileOp::failed | ( | ) | [final] |
Check if this operation failed precheck() or attempt()
Definition at line 173 of file FileOp.php.
Referenced by attempt(), and precheck().
FileOp::fileExists | ( | $ | source, |
array $ | predicates | ||
) | [final, protected] |
Check if a file will exist in storage when this operation is attempted.
$source | string Storage path |
$predicates | Array |
Definition at line 321 of file FileOp.php.
References $params.
Referenced by CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), DeleteFileOp\doPrecheck(), and precheckDestExistence().
FileOp::fileSha1 | ( | $ | source, |
array $ | predicates | ||
) | [final, protected] |
Get the SHA-1 of a file in storage when this operation is attempted.
$source | string Storage path |
$predicates | Array |
Definition at line 337 of file FileOp.php.
References $params.
Referenced by precheckDestExistence().
FileOp::getParam | ( | $ | name | ) | [final] |
Get the value of the parameter with the given name.
$name | string |
Definition at line 164 of file FileOp.php.
Referenced by CreateFileOp\doPrecheck(), DeleteFileOp\doPrecheck(), and precheckDestExistence().
FileOp::getSourceSha1Base36 | ( | ) | [protected] |
precheckDestExistence() helper function to get the source file SHA-1.
Subclasses should overwride this iff the source is not in storage.
Reimplemented in CreateFileOp, and StoreFileOp.
Definition at line 310 of file FileOp.php.
Referenced by precheckDestExistence().
FileOp::logFailure | ( | $ | action | ) | [final, protected] |
Log a file operation failure and preserve any temp files.
$action | string |
Definition at line 352 of file FileOp.php.
References $params, and wfDebugLog().
Referenced by attempt().
static FileOp::newPredicates | ( | ) | [static, final] |
Get a new empty predicates array for precheck()
Definition at line 182 of file FileOp.php.
Referenced by attemptBatch().
FileOp::precheck | ( | array &$ | predicates | ) | [final] |
Check preconditions of the operation without writing anything.
$predicates | Array |
Definition at line 192 of file FileOp.php.
References doPrecheck(), failed(), Status\newFatal(), and STATE_CHECKED.
FileOp::precheckDestExistence | ( | array $ | predicates | ) | [protected] |
Check for errors with regards to the destination file already existing.
This also updates the destSameAsSource and sourceSha1 member variables. A bad status will be returned if there is no chance it can be overwritten.
$predicates | Array |
Definition at line 273 of file FileOp.php.
References fileExists(), fileSha1(), getParam(), getSourceSha1Base36(), and Status\newGood().
Referenced by StoreFileOp\doPrecheck(), CreateFileOp\doPrecheck(), CopyFileOp\doPrecheck(), and MoveFileOp\doPrecheck().
Get a list of storage paths written to for this operation.
Reimplemented in DeleteFileOp, MoveFileOp, CopyFileOp, CreateFileOp, and StoreFileOp.
Definition at line 247 of file FileOp.php.
Get a list of storage paths read from for this operation.
Reimplemented in MoveFileOp, and CopyFileOp.
Definition at line 238 of file FileOp.php.
FileOp::$backend [protected] |
Definition at line 22 of file FileOp.php.
Referenced by __construct().
FileOp::$destSameAsSource [protected] |
Definition at line 29 of file FileOp.php.
Definition at line 25 of file FileOp.php.
FileOp::$params = array() [protected] |
Definition at line 20 of file FileOp.php.
Referenced by __construct(), MoveFileOp\doAttempt(), fileExists(), fileSha1(), and logFailure().
FileOp::$sourceSha1 [protected] |
Definition at line 28 of file FileOp.php.
FileOp::$state = self::STATE_NEW [protected] |
Definition at line 24 of file FileOp.php.
FileOp::$useLatest = true [protected] |
Definition at line 26 of file FileOp.php.
const FileOp::MAX_BATCH_SIZE = 1000 |
Definition at line 37 of file FileOp.php.
const FileOp::STATE_ATTEMPTED = 3 |
Definition at line 34 of file FileOp.php.
Referenced by attempt().
const FileOp::STATE_CHECKED = 2 |
Definition at line 33 of file FileOp.php.
Referenced by precheck().
const FileOp::STATE_NEW = 1 |
Definition at line 32 of file FileOp.php.
const FileOp::TIME_LIMIT_SEC = 300 |
Definition at line 38 of file FileOp.php.