MediaWiki
master
Toggle main menu visibility
FileBackendStoreShardListIterator.php
Go to the documentation of this file.
1
<?php
7
8
namespace
Wikimedia\FileBackend\FileIteration;
9
10
use AppendIterator;
11
use FilterIterator;
12
use Iterator;
13
use Wikimedia\FileBackend\FileBackendStore;
14
21
abstract
class
FileBackendStoreShardListIterator
extends
FilterIterator {
23
protected
$backend
;
24
26
protected
$params
;
27
29
protected
$container
;
30
32
protected
$directory
;
33
35
protected
$multiShardPaths
= [];
// (rel path => 1)
36
44
public
function
__construct
(
45
FileBackendStore
$backend
,
$container
, $dir, array $suffixes, array
$params
46
) {
47
$this->backend =
$backend
;
48
$this->container =
$container
;
49
$this->directory = $dir;
50
$this->params =
$params
;
51
52
$iter =
new
AppendIterator();
53
foreach
( $suffixes as $suffix ) {
54
$iter->append( $this->
listFromShard
( $this->container . $suffix ) );
55
}
56
57
parent::__construct( $iter );
58
}
59
60
public
function
accept
(): bool {
61
$inner = $this->getInnerIterator();
62
'@phan-var AppendIterator $inner'
;
63
$rel = $inner->current();
// path relative to given directory
64
$path
= $this->params[
'dir'
] .
"/{$rel}"
;
// full storage path
65
if
( $this->backend->isSingleShardPathInternal(
$path
) ) {
66
return true;
// path is only on one shard; no issue with duplicates
67
} elseif ( isset( $this->multiShardPaths[$rel] ) ) {
68
// Don't keep listing paths that are on multiple shards
69
return
false
;
70
}
else
{
71
$this->multiShardPaths[$rel] = 1;
72
73
return
true
;
74
}
75
}
76
77
public
function
rewind
(): void {
78
parent::
rewind
();
79
$this->multiShardPaths = [];
80
}
81
88
abstract
protected
function
listFromShard
(
$container
);
89
}
90
92
class_alias( FileBackendStoreShardListIterator::class,
'FileBackendStoreShardListIterator'
);
$path
$path
Definition
NoLocalSettings.php:14
Wikimedia\FileBackend\FileBackendStore
Base class for all backends using particular storage medium.
Definition
FileBackendStore.php:49
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator
FileBackendStore helper function to handle listings that span container shards.
Definition
FileBackendStoreShardListIterator.php:21
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator\listFromShard
listFromShard( $container)
Get the list for a given container shard.
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator\$multiShardPaths
array $multiShardPaths
Definition
FileBackendStoreShardListIterator.php:35
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator\$container
string $container
Full container name.
Definition
FileBackendStoreShardListIterator.php:29
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator\__construct
__construct(FileBackendStore $backend, $container, $dir, array $suffixes, array $params)
Definition
FileBackendStoreShardListIterator.php:44
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator\$directory
string $directory
Resolved relative path.
Definition
FileBackendStoreShardListIterator.php:32
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator\$params
array $params
Definition
FileBackendStoreShardListIterator.php:26
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator\accept
accept()
Definition
FileBackendStoreShardListIterator.php:60
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator\$backend
FileBackendStore $backend
Definition
FileBackendStoreShardListIterator.php:23
Wikimedia\FileBackend\FileIteration\FileBackendStoreShardListIterator\rewind
rewind()
Definition
FileBackendStoreShardListIterator.php:77
includes
libs
FileBackend
FileIteration
FileBackendStoreShardListIterator.php
Generated on
for MediaWiki by
1.18.0