Skip to content

Commit

Permalink
Handle create sharded table without rf and show error in case rf=n mi…
Browse files Browse the repository at this point in the history
…ssing
  • Loading branch information
donhardman committed Dec 25, 2024
1 parent 70716c4 commit 6d3d7a8
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Plugin/Sharding/Payload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('/(?P<key>rf|shards)\s*=\s*(?P<value>[\'"]?\d+[\'"]?)/', $request->payload)
) || stripos($request->payload, 'drop') === 0
Expand All @@ -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.');
}
Expand Down

0 comments on commit 6d3d7a8

Please sign in to comment.