MediaWiki master
FileBackendStoreShardListIterator.php
Go to the documentation of this file.
1<?php
9
10use AppendIterator;
11use FilterIterator;
12use Iterator;
14
21abstract 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
92class_alias( FileBackendStoreShardListIterator::class, 'FileBackendStoreShardListIterator' );
Base class for all backends using particular storage medium.
FileBackendStore helper function to handle listings that span container shards.
listFromShard( $container)
Get the list for a given container shard.
__construct(FileBackendStore $backend, $container, $dir, array $suffixes, array $params)