Skip to content

Commit d1a50f9

Browse files
committed
Revert "fix(sharding): prevent node divergence during join"
This reverts commit e098010.
1 parent e9f3f11 commit d1a50f9

2 files changed

Lines changed: 1 addition & 53 deletions

File tree

src/Plugin/Sharding/Cluster.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,24 +247,14 @@ public static function areAllShardingClustersPrimary(Client $client): bool {
247247
* @return static
248248
*/
249249
public function addNodeIds(Queue $queue, array $nodeIds, ?string $operationGroup = null): static {
250-
$baseWaitForId = $queue->getWaitForId();
251250
foreach ($nodeIds as $node) {
252251
$this->nodes->add($node);
253-
// A node that previously held this cluster still has a stale copy persisted on disk
254-
// (cluster state survives a restart). A plain JOIN is then rejected with "cluster
255-
// already exists" and the node never state-transfers the writes it missed while down,
256-
// so it diverges (keeps fewer rows). Drop any local copy first — a no-op on a brand
257-
// new node, tolerated in Queue — then JOIN so the node gets a fresh SST from the
258-
// donor ({$this->nodeId}, the surviving data holder).
259-
$queue->setWaitForId($baseWaitForId);
260-
$deleteId = $queue->add($node, "DELETE CLUSTER {$this->name}", '', $operationGroup);
261-
$queue->setWaitForId($deleteId);
252+
// TODO: the pass is the subject to remove
262253
$query = "JOIN CLUSTER {$this->name} at '{$this->nodeId}' '{$this->name}' as " .
263254
'path';
264255
$rollback = "DELETE CLUSTER {$this->name}";
265256
$queue->add($node, $query, $rollback, $operationGroup);
266257
}
267-
$queue->setWaitForId($baseWaitForId);
268258
return $this;
269259
}
270260

src/Plugin/Sharding/Queue.php

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,6 @@ public function resetWaitForId(): static {
6464
return $this;
6565
}
6666

67-
/**
68-
* Read the wait-for id currently applied to newly added items
69-
* @return int
70-
*/
71-
public function getWaitForId(): int {
72-
return $this->waitForId;
73-
}
74-
7567
/**
7668
* Add new query for requested node to the queue
7769
* @param string $nodeId
@@ -226,14 +218,6 @@ protected function handleQuery(Node $node, array $query): bool {
226218
$status = $this->handleAlterClusterDropTableError($query['query'], $res);
227219
}
228220

229-
// Special handling for DELETE CLUSTER: when we proactively clear a node's stale local
230-
// copy before re-JOIN, a brand-new node has no such cluster ("unknown cluster"). That
231-
// is exactly the desired post-state, not a failure — otherwise the item deadlocks the
232-
// JOIN that waits on it.
233-
if ($status === 'error' && $this->isDeleteClusterQuery($query['query'])) {
234-
$status = $this->handleDeleteClusterError($res);
235-
}
236-
237221
Buddy::debugvv("[{$node->id}] Queue query result [$status]: " . json_encode($res));
238222

239223
$duration = (int)((microtime(true) - $mt) * 1000);
@@ -447,32 +431,6 @@ protected function handleAlterClusterDropTableError(string $query, Struct $error
447431
return 'error';
448432
}
449433

450-
/**
451-
* Whether the query is a DELETE CLUSTER statement
452-
* @param string $query
453-
* @return bool
454-
*/
455-
protected function isDeleteClusterQuery(string $query): bool {
456-
return (bool)preg_match('/^\s*DELETE\s+CLUSTER\s+/i', $query);
457-
}
458-
459-
/**
460-
* A DELETE CLUSTER that fails because the cluster is not present locally has already
461-
* reached its intended state (no stale copy), so treat it as processed.
462-
* @param Struct<int|string,mixed> $errorResult
463-
* @return string
464-
*/
465-
protected function handleDeleteClusterError(Struct $errorResult): string {
466-
/** @var array{error?:string}|array{0?:array{error?:string}} $arr */
467-
$arr = $errorResult;
468-
$error = (string)($arr['error'] ?? ($arr[0]['error'] ?? ''));
469-
if (stripos($error, 'unknown cluster') !== false || stripos($error, 'no such cluster') !== false) {
470-
Buddy::debugvv('DELETE CLUSTER: cluster not present locally, marking as processed');
471-
return 'processed';
472-
}
473-
return 'error';
474-
}
475-
476434
/**
477435
* Handle error for ALTER CLUSTER ADD TABLE by checking if query is still running
478436
* or if tables are already synced in cluster

0 commit comments

Comments
 (0)