MediaWiki REL1_39
FileBackendStoreShardListIterator.php
Go to the documentation of this file.
1<?php
28abstract 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(): bool {
68 $inner = $this->getInnerIterator();
69 '@phan-var AppendIterator $inner';
70 $rel = $inner->current(); // path relative to given directory
71 $path = $this->params['dir'] . "/{$rel}"; // full storage path
72 if ( $this->backend->isSingleShardPathInternal( $path ) ) {
73 return true; // path is only on one shard; no issue with duplicates
74 } elseif ( isset( $this->multiShardPaths[$rel] ) ) {
75 // Don't keep listing paths that are on multiple shards
76 return false;
77 } else {
78 $this->multiShardPaths[$rel] = 1;
79
80 return true;
81 }
82 }
83
84 public function rewind(): void {
85 parent::rewind();
86 $this->multiShardPaths = [];
87 }
88
95 abstract protected function listFromShard( $container );
96}
FileBackendStore helper function to handle listings that span container shards.
__construct(FileBackendStore $backend, $container, $dir, array $suffixes, array $params)
listFromShard( $container)
Get the list for a given container shard.
Base class for all backends using particular storage medium.