54 public static function attempt( array $performOps, array $opts ) {
57 $n = count( $performOps );
58 if ( $n > self::MAX_BATCH_SIZE ) {
59 $status->fatal(
'backend-fail-batchsize', $n, self::MAX_BATCH_SIZE );
64 $ignoreErrors = !empty( $opts[
'force'] );
65 $maxConcurrency = $opts[
'concurrency'] ?? 1;
73 foreach ( $performOps as $index => $fileOp ) {
74 $backendName = $fileOp->getBackend()->getName();
77 if ( $fileOp->dependsOn( $curBatchDeps )
78 || count( $curBatch ) >= $maxConcurrency
79 || ( $backendName !== $lastBackend && count( $curBatch ) )
81 $pPerformOps[] = $curBatch;
85 $lastBackend = $backendName;
86 $curBatch[$index] = $fileOp;
88 $curBatchDeps = $fileOp->applyDependencies( $curBatchDeps );
90 $oldPredicates = $predicates;
91 $subStatus = $fileOp->precheck( $predicates );
92 $status->merge( $subStatus );
93 if ( !$subStatus->isOK() ) {
95 $status->success[$index] =
false;
97 if ( !$ignoreErrors ) {
103 if ( count( $curBatch ) ) {
104 $pPerformOps[] = $curBatch;
107 if ( $ignoreErrors ) {
108 $status->setResult(
true, $status->value );
130 foreach ( $pPerformOps as $performOpsBatch ) {
134 foreach ( $performOpsBatch as $i => $fileOp ) {
135 $status->success[$i] =
false;
136 ++$status->failCount;
137 $fileOp->logFailure(
'attempt_aborted' );
146 $backend = reset( $performOpsBatch )->getBackend();
150 foreach ( $performOpsBatch as $i => $fileOp ) {
151 if ( !isset( $status->success[$i] ) ) {
154 $subStatus = ( count( $performOpsBatch ) > 1 )
155 ? $fileOp->attemptAsync()
156 : $fileOp->attempt();
158 $opHandles[$i] = $subStatus->value;
160 $statuses[$i] = $subStatus;
165 $statuses += $backend->executeOpHandlesInternal( $opHandles );
167 foreach ( $performOpsBatch as $i => $fileOp ) {
168 if ( !isset( $status->success[$i] ) ) {
169 $subStatus = $statuses[$i];
170 $status->
merge( $subStatus );
171 if ( $subStatus->isOK() ) {
172 $status->success[$i] =
true;
173 ++$status->successCount;
175 $status->success[$i] =
false;
176 ++$status->failCount;
FileBackendStore helper class for performing asynchronous file operations.
Helper class for representing batch file operations.
static runParallelBatches(array $pPerformOps, StatusValue $status)
Attempt a list of file operations sub-batches in series.
static attempt(array $performOps, array $opts)
Attempt to perform a series of file operations.
static newDependencies()
Get a new empty dependency tracking array for paths read/written to.
static newPredicates()
Get a new empty predicates array for precheck()
Generic operation result class Has warning/error list, boolean status and arbitrary value.
merge( $other, $overwriteValue=false)
Merge another status object into this one.
static newGood( $value=null)
Factory function for good results.