MediaWiki  REL1_19
FileOp Class Reference

Helper class for representing operations with transaction support. More...

Inheritance diagram for FileOp:

List of all members.

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

Detailed Description

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.

Since:
1.19

Definition at line 18 of file FileOp.php.


Constructor & Destructor Documentation

FileOp::__construct ( FileBackendStore backend,
array $  params 
) [final]

Build a new file operation transaction.

$backend FileBackendStore $params Array

Exceptions:
MWException

Definition at line 47 of file FileOp.php.

References $backend, $params, and allowedParams().

Here is the call graph for this function:


Member Function Documentation

FileOp::allowedParams ( ) [protected]

Get the file operation parameters.

Returns:
Array (required params list, optional params list)

Reimplemented in DeleteFileOp, MoveFileOp, CopyFileOp, CreateFileOp, and StoreFileOp.

Definition at line 229 of file FileOp.php.

Referenced by __construct().

Here is the caller graph for this function:

FileOp::allowStaleReads ( ) [final, protected]

Allow stale data for file reads and existence checks.

Returns:
void

Definition at line 70 of file FileOp.php.

FileOp::attempt ( ) [final]

Attempt the operation, backing up files as needed; this must be reversible.

Returns:
Status

Definition at line 209 of file FileOp.php.

References doAttempt(), failed(), logFailure(), Status\newFatal(), and STATE_ATTEMPTED.

Here is the call graph for this function:

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

Parameters:
$performOpsArray List of FileOp operations
$optsArray Batch operation options
Returns:
Status

Definition at line 93 of file FileOp.php.

References $n, Status\newGood(), and newPredicates().

Referenced by FileBackendMultiWrite\doOperationsInternal(), and FileBackendStore\doOperationsInternal().

Here is the call graph for this function:

Here is the caller graph for this function:

FileOp::doAttempt ( ) [protected]
Returns:
Status

Reimplemented in DeleteFileOp, MoveFileOp, CopyFileOp, CreateFileOp, and StoreFileOp.

Definition at line 261 of file FileOp.php.

References Status\newGood().

Referenced by attempt().

Here is the call graph for this function:

Here is the caller graph for this function:

FileOp::doPrecheck ( array &$  predicates) [protected]
Returns:
Status

Reimplemented in DeleteFileOp, MoveFileOp, CopyFileOp, CreateFileOp, and StoreFileOp.

Definition at line 254 of file FileOp.php.

References Status\newGood().

Referenced by precheck().

Here is the call graph for this function:

Here is the caller graph for this function:

FileOp::failed ( ) [final]

Check if this operation failed precheck() or attempt()

Returns:
bool

Definition at line 173 of file FileOp.php.

Referenced by attempt(), and precheck().

Here is the caller graph for this function:

FileOp::fileExists ( source,
array $  predicates 
) [final, protected]

Check if a file will exist in storage when this operation is attempted.

Parameters:
$sourcestring Storage path
$predicatesArray
Returns:
bool

Definition at line 321 of file FileOp.php.

References $params.

Referenced by CopyFileOp\doPrecheck(), MoveFileOp\doPrecheck(), DeleteFileOp\doPrecheck(), and precheckDestExistence().

Here is the caller graph for this function:

FileOp::fileSha1 ( source,
array $  predicates 
) [final, protected]

Get the SHA-1 of a file in storage when this operation is attempted.

Parameters:
$sourcestring Storage path
$predicatesArray
Returns:
string|false

Definition at line 337 of file FileOp.php.

References $params.

Referenced by precheckDestExistence().

Here is the caller graph for this function:

FileOp::getParam ( name) [final]

Get the value of the parameter with the given name.

Parameters:
$namestring
Returns:
mixed Returns null if the parameter is not set

Definition at line 164 of file FileOp.php.

Referenced by CreateFileOp\doPrecheck(), DeleteFileOp\doPrecheck(), and precheckDestExistence().

Here is the caller graph for this function:

FileOp::getSourceSha1Base36 ( ) [protected]

precheckDestExistence() helper function to get the source file SHA-1.

Subclasses should overwride this iff the source is not in storage.

Returns:
string|false Returns false on failure

Reimplemented in CreateFileOp, and StoreFileOp.

Definition at line 310 of file FileOp.php.

Referenced by precheckDestExistence().

Here is the caller graph for this function:

FileOp::logFailure ( action) [final, protected]

Log a file operation failure and preserve any temp files.

Parameters:
$actionstring
Returns:
void

Definition at line 352 of file FileOp.php.

References $params, and wfDebugLog().

Referenced by attempt().

Here is the call graph for this function:

Here is the caller graph for this function:

static FileOp::newPredicates ( ) [static, final]

Get a new empty predicates array for precheck()

Returns:
Array

Definition at line 182 of file FileOp.php.

Referenced by attemptBatch().

Here is the caller graph for this function:

FileOp::precheck ( array &$  predicates) [final]

Check preconditions of the operation without writing anything.

Parameters:
$predicatesArray
Returns:
Status

Definition at line 192 of file FileOp.php.

References doPrecheck(), failed(), Status\newFatal(), and STATE_CHECKED.

Here is the call graph for this function:

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.

Parameters:
$predicatesArray
Returns:
Status

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().

Here is the call graph for this function:

Here is the caller graph for this function:

Get a list of storage paths written to for this operation.

Returns:
Array

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.

Returns:
Array

Reimplemented in MoveFileOp, and CopyFileOp.

Definition at line 238 of file FileOp.php.


Member Data Documentation

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.

FileOp::$failed = false [protected]

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.

Definition at line 34 of file FileOp.php.

Referenced by attempt().

Definition at line 33 of file FileOp.php.

Referenced by precheck().

const FileOp::STATE_NEW = 1

Definition at line 32 of file FileOp.php.

Definition at line 38 of file FileOp.php.


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