Skip to content

Commit 10411b2

Browse files
committed
fix(sharding): fix drop ctable methods to accept array of tables
- Change addNodeIds, addTables, removeTables to accept array parameters instead of variadic strings - Update all call sites to pass arrays consistently - Prevent errors when detaching tables by ensuring proper argument types
1 parent 1c6161d commit 10411b2

File tree

3 files changed

+24
-21
lines changed

3 files changed

+24
-21
lines changed

src/Plugin/Sharding/Cluster.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,11 @@ public function isActive(): bool {
196196
* Create a cluster by using distributed queue with list of nodes
197197
* This method just add join queries to the queue to all requested nodes
198198
* @param Queue $queue
199+
* @param array<string> $nodeIds
199200
* @param string|null $operationGroup Optional operation group for rollback
200-
* @param string ...$nodeIds
201201
* @return static
202202
*/
203-
public function addNodeIds(Queue $queue, ?string $operationGroup = null, string ...$nodeIds): static {
203+
public function addNodeIds(Queue $queue, array $nodeIds, ?string $operationGroup = null): static {
204204
$galeraOptions = static::GALERA_OPTIONS;
205205
foreach ($nodeIds as $node) {
206206
$this->nodes->add($node);
@@ -235,12 +235,12 @@ public function refresh(): static {
235235
/**
236236
* Enqueue the tables attachments to all nodes of current cluster
237237
* @param Queue $queue
238+
* @param array<string> $tables
238239
* @param string|null $operationGroup Optional operation group for rollback
239-
* @param string ...$tables
240240
* @return int
241241
*/
242-
public function addTables(Queue $queue, ?string $operationGroup = null, string ...$tables): int {
243-
if (!$tables) {
242+
public function addTables(Queue $queue, array $tables, ?string $operationGroup = null): int {
243+
if (empty($tables)) {
244244
throw new \Exception('Tables must be passed to add');
245245
}
246246
$tablesStr = implode(',', $tables);
@@ -252,12 +252,12 @@ public function addTables(Queue $queue, ?string $operationGroup = null, string .
252252
/**
253253
* Enqueue the tables detachement to all nodes of current cluster
254254
* @param Queue $queue
255+
* @param array<string> $tables
255256
* @param string|null $operationGroup Optional operation group for rollback
256-
* @param string ...$tables
257257
* @return int
258258
*/
259-
public function removeTables(Queue $queue, ?string $operationGroup = null, string ...$tables): int {
260-
if (!$tables) {
259+
public function removeTables(Queue $queue, array $tables, ?string $operationGroup = null): int {
260+
if (empty($tables)) {
261261
throw new \Exception('Tables must be passed to remove');
262262
}
263263
$tablesStr = implode(',', $tables);
@@ -341,12 +341,12 @@ public function hasPendingTable(string $table, TableOperation $operation): bool
341341
*/
342342
public function processPendingTables(Queue $queue, ?string $operationGroup = null): static {
343343
if ($this->tablesToDetach->count()) {
344-
$this->removeTables($queue, $operationGroup, ...$this->tablesToDetach);
344+
$this->removeTables($queue, $this->tablesToDetach->toArray(), $operationGroup);
345345
$this->tablesToDetach = new Set;
346346
}
347347

348348
if ($this->tablesToAttach->count()) {
349-
$this->addTables($queue, $operationGroup, ...$this->tablesToAttach);
349+
$this->addTables($queue, $this->tablesToAttach->toArray(), $operationGroup);
350350
$this->tablesToAttach = new Set;
351351
}
352352

src/Plugin/Sharding/Table.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ protected function handleReplication(
400400
$clusterMap[$clusterName] = $cluster;
401401
$waitForId = $cluster->create($queue, $operationGroup);
402402
$queue->setWaitForId($waitForId);
403-
$cluster->addNodeIds($queue, $operationGroup, ...$nodesToJoin);
403+
$cluster->addNodeIds($queue, $nodesToJoin->toArray(), $operationGroup);
404404
$queue->resetWaitForId();
405405
}
406406

@@ -1362,7 +1362,7 @@ private function handleClusteredCleanUp(
13621362
$connectedNode
13631363
);
13641364
$queueIds[] = $cluster->makePrimary($queue);
1365-
$queueIds[] = $cluster->removeTables($queue, $table);
1365+
$queueIds[] = $cluster->removeTables($queue, [$table]);
13661366
$processedTables->add($table);
13671367
}
13681368
}

test/Plugin/Sharding/TestDoubles/TestableCluster.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,32 +131,35 @@ public function remove(?\Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue
131131
/**
132132
* Add node IDs to cluster
133133
* @param \Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue
134-
* @param string ...$nodeIds
134+
* @param array<string> $nodeIds
135+
* @param string|null $operationGroup
135136
* @return static
136137
*/
137-
public function addNodeIds(\Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue, string ...$nodeIds): static {
138-
$this->cluster?->addNodeIds($queue, ...$nodeIds);
138+
public function addNodeIds(\Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue, array $nodeIds, ?string $operationGroup = null): static {
139+
$this->cluster?->addNodeIds($queue, $nodeIds, $operationGroup);
139140
return $this;
140141
}
141142

142143
/**
143144
* Add tables to cluster
144145
* @param \Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue
145-
* @param string ...$tables
146+
* @param array<string> $tables
147+
* @param string|null $operationGroup
146148
* @return int
147149
*/
148-
public function addTables(\Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue, string ...$tables): int {
149-
return $this->cluster?->addTables($queue, ...$tables) ?? 0;
150+
public function addTables(\Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue, array $tables, ?string $operationGroup = null): int {
151+
return $this->cluster?->addTables($queue, $tables, $operationGroup) ?? 0;
150152
}
151153

152154
/**
153155
* Remove tables from cluster
154156
* @param \Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue
155-
* @param string ...$tables
157+
* @param array<string> $tables
158+
* @param string|null $operationGroup
156159
* @return int
157160
*/
158-
public function removeTables(\Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue, string ...$tables): int {
159-
return $this->cluster?->removeTables($queue, ...$tables) ?? 0;
161+
public function removeTables(\Manticoresearch\Buddy\Base\Plugin\Sharding\Queue $queue, array $tables, ?string $operationGroup = null): int {
162+
return $this->cluster?->removeTables($queue, $tables, $operationGroup) ?? 0;
160163
}
161164

162165
/**

0 commit comments

Comments
 (0)