From 17d7db2872953b56c8bc810c8705fb65f5cb05c2 Mon Sep 17 00:00:00 2001 From: Don Hardman Date: Mon, 23 Dec 2024 10:06:35 +0700 Subject: [PATCH] Handle create sharded table without rf and show error in case rf=n missing --- src/Plugin/Sharding/Payload.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Plugin/Sharding/Payload.php b/src/Plugin/Sharding/Payload.php index cdac5aad..22a7755a 100644 --- a/src/Plugin/Sharding/Payload.php +++ b/src/Plugin/Sharding/Payload.php @@ -140,7 +140,6 @@ public static function hasMatch(Request $request): bool { && strpos($request->error, 'P03') === 0 && ( (stripos($request->payload, 'create table') === 0 - && stripos($request->payload, 'rf') !== false && stripos($request->payload, 'shards') !== false && preg_match('/(?Prf|shards)\s*=\s*(?P[\'"]?\d+[\'"]?)/', $request->payload) ) || stripos($request->payload, 'drop') === 0 @@ -152,6 +151,10 @@ public static function hasMatch(Request $request): bool { * @return void */ protected function validate(): void { + if ($this->type === 'create' && !isset($this->options['rf'])) { + throw QueryParseError::create('Sharded table requires `rf=n`'); + } + if (!$this->cluster && $this->type !== 'drop' && $this->options['rf'] > 1) { throw QueryParseError::create('You cannot set rf greater than 1 when creating single node sharded table.'); }