From bbcce33c6d95724aa09524a1e68334015d6c45ae Mon Sep 17 00:00:00 2001 From: Don Hardman Date: Thu, 31 Aug 2023 10:15:20 +0700 Subject: [PATCH] Use hook for creating sharded table to make it clean --- src/Lib/QueryProcessor.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Lib/QueryProcessor.php b/src/Lib/QueryProcessor.php index c254373d..a95639b4 100644 --- a/src/Lib/QueryProcessor.php +++ b/src/Lib/QueryProcessor.php @@ -14,6 +14,7 @@ use Exception; use Manticoresearch\Buddy\Base\Exception\SQLQueryCommandNotSupported; use Manticoresearch\Buddy\Base\Network\EventHandler; +use Manticoresearch\Buddy\Base\Sharding\Thread as ShardingThread; use Manticoresearch\Buddy\Core\ManticoreSearch\Client as HTTPClient; use Manticoresearch\Buddy\Core\ManticoreSearch\Settings as ManticoreSettings; use Manticoresearch\Buddy\Core\ManticoreSearch\Settings; @@ -199,6 +200,7 @@ public static function detectPluginPrefixFromRequest(Request $request): string { */ protected static function getHooks(): array { return [ + // Happens when we installed the external plugin [ 'manticoresoftware/buddy-plugin-plugin', 'installed', @@ -207,6 +209,7 @@ function () { EventHandler::setShouldExit(true); }, ], + // Happens when we remove the plugin [ 'manticoresoftware/buddy-plugin-plugin', 'deleted', @@ -215,6 +218,14 @@ function () { EventHandler::setShouldExit(true); }, ], + // Happens when we run create table with shards in options + [ + 'manticoresoftware/buddy-plugin-create-table', + 'shard', + function (array $args) { + ShardingThread::instance()->execute('shard', $args); + }, + ], ]; } }