MediaWiki  master
FileBackendStoreShardListIterator.php
Go to the documentation of this file.
1 <?php
28 abstract class FileBackendStoreShardListIterator extends FilterIterator {
30  protected $backend;
31 
33  protected $params;
34 
36  protected $container;
37 
39  protected $directory;
40 
42  protected $multiShardPaths = []; // (rel path => 1)
43 
51  public function __construct(
52  FileBackendStore $backend, $container, $dir, array $suffixes, array $params
53  ) {
54  $this->backend = $backend;
55  $this->container = $container;
56  $this->directory = $dir;
57  $this->params = $params;
58 
59  $iter = new AppendIterator();
60  foreach ( $suffixes as $suffix ) {
61  $iter->append( $this->listFromShard( $this->container . $suffix ) );
62  }
63 
64  parent::__construct( $iter );
65  }
66 
67  public function accept() {
68  $rel = $this->getInnerIterator()->current(); // path relative to given directory
69  $path = $this->params['dir'] . "/{$rel}"; // full storage path
70  if ( $this->backend->isSingleShardPathInternal( $path ) ) {
71  return true; // path is only on one shard; no issue with duplicates
72  } elseif ( isset( $this->multiShardPaths[$rel] ) ) {
73  // Don't keep listing paths that are on multiple shards
74  return false;
75  } else {
76  $this->multiShardPaths[$rel] = 1;
77 
78  return true;
79  }
80  }
81 
82  public function rewind() {
83  parent::rewind();
84  $this->multiShardPaths = [];
85  }
86 
93  abstract protected function listFromShard( $container );
94 }
FileBackendStoreShardListIterator\$backend
FileBackendStore $backend
Definition: FileBackendStoreShardListIterator.php:30
FileBackendStoreShardListIterator\listFromShard
listFromShard( $container)
Get the list for a given container shard.
FileBackendStoreShardListIterator
FileBackendStore helper function to handle listings that span container shards.
Definition: FileBackendStoreShardListIterator.php:28
FileBackendStoreShardListIterator\rewind
rewind()
Definition: FileBackendStoreShardListIterator.php:82
FileBackendStoreShardListIterator\$params
array $params
Definition: FileBackendStoreShardListIterator.php:33
FileBackendStoreShardListIterator\__construct
__construct(FileBackendStore $backend, $container, $dir, array $suffixes, array $params)
Definition: FileBackendStoreShardListIterator.php:51
FileBackendStore
Base class for all backends using particular storage medium.
Definition: FileBackendStore.php:41
FileBackendStoreShardListIterator\$multiShardPaths
array $multiShardPaths
Definition: FileBackendStoreShardListIterator.php:42
$path
$path
Definition: NoLocalSettings.php:25
FileBackendStoreShardListIterator\$container
string $container
Full container name.
Definition: FileBackendStoreShardListIterator.php:36
FileBackendStoreShardListIterator\accept
accept()
Definition: FileBackendStoreShardListIterator.php:67
FileBackendStoreShardListIterator\$directory
string $directory
Resolved relative path.
Definition: FileBackendStoreShardListIterator.php:39