MediaWiki master
FileBackendStoreShardListIterator.php
Go to the documentation of this file.
1<?php
23
24use AppendIterator;
25use FilterIterator;
26use Iterator;
28
35abstract class FileBackendStoreShardListIterator extends FilterIterator {
37 protected $backend;
38
40 protected $params;
41
43 protected $container;
44
46 protected $directory;
47
49 protected $multiShardPaths = []; // (rel path => 1)
50
58 public function __construct(
59 FileBackendStore $backend, $container, $dir, array $suffixes, array $params
60 ) {
61 $this->backend = $backend;
62 $this->container = $container;
63 $this->directory = $dir;
64 $this->params = $params;
65
66 $iter = new AppendIterator();
67 foreach ( $suffixes as $suffix ) {
68 $iter->append( $this->listFromShard( $this->container . $suffix ) );
69 }
70
71 parent::__construct( $iter );
72 }
73
74 public function accept(): bool {
75 $inner = $this->getInnerIterator();
76 '@phan-var AppendIterator $inner';
77 $rel = $inner->current(); // path relative to given directory
78 $path = $this->params['dir'] . "/{$rel}"; // full storage path
79 if ( $this->backend->isSingleShardPathInternal( $path ) ) {
80 return true; // path is only on one shard; no issue with duplicates
81 } elseif ( isset( $this->multiShardPaths[$rel] ) ) {
82 // Don't keep listing paths that are on multiple shards
83 return false;
84 } else {
85 $this->multiShardPaths[$rel] = 1;
86
87 return true;
88 }
89 }
90
91 public function rewind(): void {
92 parent::rewind();
93 $this->multiShardPaths = [];
94 }
95
102 abstract protected function listFromShard( $container );
103}
104
106class_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)