From f62270ced27b7267d42369b3ba6cdc0808c9e4ca Mon Sep 17 00:00:00 2001 From: Don Hardman <59067742+donhardman@users.noreply.github.com> Date: Wed, 6 Dec 2023 20:40:15 +0700 Subject: [PATCH] Use vip http port by default when available and add test (#97) --- composer.lock | 108 ++++++++--------- src/Lib/ManticoreConfig.php | 8 +- tests/backup-works-with-max-connections.rec | 121 ++++++++++++++++++++ tests/config/manticore-vip.conf | 12 ++ 4 files changed, 192 insertions(+), 57 deletions(-) create mode 100644 tests/backup-works-with-max-connections.rec create mode 100644 tests/config/manticore-vip.conf diff --git a/composer.lock b/composer.lock index 0643b27..a18ae17 100644 --- a/composer.lock +++ b/composer.lock @@ -326,16 +326,16 @@ }, { "name": "nikic/php-parser", - "version": "v4.16.0", + "version": "v4.17.1", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17" + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17", - "reference": "19526a33fb561ef417e822e85f08a00db4059c17", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", + "reference": "a6303e50c90c355c7eeee2c4a8b27fe8dc8fef1d", "shasum": "" }, "require": { @@ -376,9 +376,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0" + "source": "https://github.com/nikic/PHP-Parser/tree/v4.17.1" }, - "time": "2023-06-25T14:52:30+00:00" + "time": "2023-08-13T19:53:39+00:00" }, { "name": "phar-io/manifest", @@ -493,16 +493,16 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.23.0", + "version": "1.24.4", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "a2b24135c35852b348894320d47b3902a94bc494" + "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/a2b24135c35852b348894320d47b3902a94bc494", - "reference": "a2b24135c35852b348894320d47b3902a94bc494", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/6bd0c26f3786cd9b7c359675cb789e35a8e07496", + "reference": "6bd0c26f3786cd9b7c359675cb789e35a8e07496", "shasum": "" }, "require": { @@ -534,22 +534,22 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.23.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.24.4" }, - "time": "2023-07-23T22:17:56+00:00" + "time": "2023-11-26T18:29:22+00:00" }, { "name": "phpstan/phpstan", - "version": "1.10.26", + "version": "1.10.47", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "5d660cbb7e1b89253a47147ae44044f49832351f" + "reference": "84dbb33b520ea28b6cf5676a3941f4bae1c1ff39" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/5d660cbb7e1b89253a47147ae44044f49832351f", - "reference": "5d660cbb7e1b89253a47147ae44044f49832351f", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/84dbb33b520ea28b6cf5676a3941f4bae1c1ff39", + "reference": "84dbb33b520ea28b6cf5676a3941f4bae1c1ff39", "shasum": "" }, "require": { @@ -598,20 +598,20 @@ "type": "tidelift" } ], - "time": "2023-07-19T12:44:37+00:00" + "time": "2023-12-01T15:19:17+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.27", + "version": "9.2.29", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1" + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/b0a88255cb70d52653d80c890bd7f38740ea50d1", - "reference": "b0a88255cb70d52653d80c890bd7f38740ea50d1", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/6a3a87ac2bbe33b25042753df8195ba4aa534c76", + "reference": "6a3a87ac2bbe33b25042753df8195ba4aa534c76", "shasum": "" }, "require": { @@ -668,7 +668,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", - "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.27" + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.29" }, "funding": [ { @@ -676,7 +676,7 @@ "type": "github" } ], - "time": "2023-07-26T13:44:30+00:00" + "time": "2023-09-19T04:57:46+00:00" }, { "name": "phpunit/php-file-iterator", @@ -921,16 +921,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.6.10", + "version": "9.6.15", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328" + "reference": "05017b80304e0eb3f31d90194a563fd53a6021f1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/a6d351645c3fe5a30f5e86be6577d946af65a328", - "reference": "a6d351645c3fe5a30f5e86be6577d946af65a328", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/05017b80304e0eb3f31d90194a563fd53a6021f1", + "reference": "05017b80304e0eb3f31d90194a563fd53a6021f1", "shasum": "" }, "require": { @@ -945,7 +945,7 @@ "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", - "phpunit/php-code-coverage": "^9.2.13", + "phpunit/php-code-coverage": "^9.2.28", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -1004,7 +1004,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.10" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.6.15" }, "funding": [ { @@ -1020,7 +1020,7 @@ "type": "tidelift" } ], - "time": "2023-07-10T04:04:23+00:00" + "time": "2023-12-01T16:55:19+00:00" }, { "name": "sebastian/cli-parser", @@ -1528,16 +1528,16 @@ }, { "name": "sebastian/global-state", - "version": "5.0.5", + "version": "5.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/global-state.git", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2" + "reference": "bde739e7565280bda77be70044ac1047bc007e34" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/0ca8db5a5fc9c8646244e629625ac486fa286bf2", - "reference": "0ca8db5a5fc9c8646244e629625ac486fa286bf2", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/bde739e7565280bda77be70044ac1047bc007e34", + "reference": "bde739e7565280bda77be70044ac1047bc007e34", "shasum": "" }, "require": { @@ -1580,7 +1580,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/global-state/issues", - "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.5" + "source": "https://github.com/sebastianbergmann/global-state/tree/5.0.6" }, "funding": [ { @@ -1588,7 +1588,7 @@ "type": "github" } ], - "time": "2022-02-14T08:28:10+00:00" + "time": "2023-08-02T09:26:13+00:00" }, { "name": "sebastian/lines-of-code", @@ -1988,32 +1988,32 @@ }, { "name": "slevomat/coding-standard", - "version": "8.13.4", + "version": "8.14.1", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322" + "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/4b2af2fb17773656d02fbfb5d18024ebd19fe322", - "reference": "4b2af2fb17773656d02fbfb5d18024ebd19fe322", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/fea1fd6f137cc84f9cba0ae30d549615dbc6a926", + "reference": "fea1fd6f137cc84f9cba0ae30d549615dbc6a926", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7 || ^1.0", "php": "^7.2 || ^8.0", - "phpstan/phpdoc-parser": "^1.23.0", + "phpstan/phpdoc-parser": "^1.23.1", "squizlabs/php_codesniffer": "^3.7.1" }, "require-dev": { "phing/phing": "2.17.4", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.10.26", - "phpstan/phpstan-deprecation-rules": "1.1.3", - "phpstan/phpstan-phpunit": "1.3.13", + "phpstan/phpstan": "1.10.37", + "phpstan/phpstan-deprecation-rules": "1.1.4", + "phpstan/phpstan-phpunit": "1.3.14", "phpstan/phpstan-strict-rules": "1.5.1", - "phpunit/phpunit": "7.5.20|8.5.21|9.6.8|10.2.6" + "phpunit/phpunit": "8.5.21|9.6.8|10.3.5" }, "type": "phpcodesniffer-standard", "extra": { @@ -2037,7 +2037,7 @@ ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/8.13.4" + "source": "https://github.com/slevomat/coding-standard/tree/8.14.1" }, "funding": [ { @@ -2049,7 +2049,7 @@ "type": "tidelift" } ], - "time": "2023-07-25T10:28:55+00:00" + "time": "2023-10-08T07:28:08+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -2110,16 +2110,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" + "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", - "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/b2ad5003ca10d4ee50a12da31de12a5774ba6b96", + "reference": "b2ad5003ca10d4ee50a12da31de12a5774ba6b96", "shasum": "" }, "require": { @@ -2148,7 +2148,7 @@ "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", "support": { "issues": "https://github.com/theseer/tokenizer/issues", - "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + "source": "https://github.com/theseer/tokenizer/tree/1.2.2" }, "funding": [ { @@ -2156,7 +2156,7 @@ "type": "github" } ], - "time": "2021-07-28T10:34:58+00:00" + "time": "2023-11-20T00:12:19+00:00" } ], "aliases": [], @@ -2168,5 +2168,5 @@ "php": ">=8.1" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/src/Lib/ManticoreConfig.php b/src/Lib/ManticoreConfig.php index 7841225..5e084be 100644 --- a/src/Lib/ManticoreConfig.php +++ b/src/Lib/ManticoreConfig.php @@ -96,7 +96,6 @@ protected function parse(string $config): void { $this->$property = $value; } } - $this->setupEndpoints($endpoints); } @@ -123,8 +122,11 @@ protected function parse(string $config): void { * @return void */ protected function setupEndpoints(array $endpoints): void { + $vipOnly = array_filter($endpoints, fn ($v) => $v['proto'] === '_vip' || $v['proto'] === 'http_vip'); $httpOnly = array_filter($endpoints, fn ($v) => $v['proto'] === 'http'); - if ($httpOnly) { + if ($vipOnly) { + $endpoint = $vipOnly[array_key_first($vipOnly)]; + } elseif ($httpOnly) { $endpoint = $httpOnly[array_key_first($httpOnly)]; } else { $endpoint = $endpoints[0] ?? null; @@ -134,7 +136,7 @@ protected function setupEndpoints(array $endpoints): void { return; } - ['proto' => $this->proto, 'host' => $this->host, 'port' => $this->port] = $endpoint; + ['host' => $this->host, 'port' => $this->port] = $endpoint; } /** diff --git a/tests/backup-works-with-max-connections.rec b/tests/backup-works-with-max-connections.rec new file mode 100644 index 0000000..bea81d0 --- /dev/null +++ b/tests/backup-works-with-max-connections.rec @@ -0,0 +1,121 @@ +––– input ––– +cp tests/config/manticore-vip.conf /etc/manticoresearch/manticore.conf +––– output ––– +––– input ––– +searchd +––– output ––– +Manticore %{SEMVER} %{COMMITDATE} dev (columnar %{SEMVER} #!/[a-f0-9]{7}@[0-9]{6}/!#) (secondary %{SEMVER} #!/[a-f0-9]{7}@[0-9]{6}/!#) (knn %{SEMVER} #!/[a-f0-9]{7}@[0-9]{6}/!#) +Copyright (c) 2001-2016, Andrew Aksyonoff +Copyright (c) 2008-2016, Sphinx Technologies Inc (http://sphinxsearch.com) +Copyright (c) 2017-%{YEAR}, Manticore Software LTD (https://manticoresearch.com) +[#!/[0-9]{2}:[0-9]{2}\.[0-9]{3}/!#] [#!/[0-9]+/!#] using config file '/etc/manticoresearch/manticore.conf' (#!/[0-9]+/!# chars)... +starting daemon version '%{SEMVER} %{COMMITDATE} dev (columnar %{SEMVER} %{COMMITDATE}) (secondary %{SEMVER} %{COMMITDATE}) (knn %{SEMVER} %{COMMITDATE})' ... +listening on %{IPADDR}:9312 for sphinx and http(s) +listening on %{IPADDR}:9306 for mysql +listening on %{IPADDR}:9307 for VIP mysql +listening on %{IPADDR}:9308 for sphinx and http(s) +listening on %{IPADDR}:9313 for VIP sphinx and http(s) +––– input ––– +manticore-backup --version +––– output ––– +Copyright (c) %{YEAR}, Manticore Software LTD (https://manticoresearch.com) +Manticore Backup version: %{SEMVER} +––– block: init-database ––– +––– input ––– +curl localhost:9312/sql?mode=raw -d 'query=debug sleep 10' & +––– output ––– +[1] %{NUMBER} +––– input ––– +mysql -h0 -P9307 -e 'show tables' +––– output ––– ++---------------------+-------------+ +| Index | Type | ++---------------------+-------------+ +| distributed_index | distributed | +| rt_with_columnar | rt | +| rt_without_columnar | rt | ++---------------------+-------------+ +––– input ––– +mysql -h0 -P9307 -e 'show create table distributed_index' +––– output ––– ++-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ +| Table | Create Table | ++-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ +| distributed_index | CREATE TABLE distributed_index type='distributed' local='rt_with_columnar' agent='127.0.0.1:9312:plain_with_columnar, plain_without_columnar' | ++-------------------+-----------------------------------------------------------------------------------------------------------------------------------------------+ +––– input ––– +mysql -h0 -P9307 -e 'show create table rt_with_columnar' +––– output ––– ++------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| Table | Create Table | ++------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +| rt_with_columnar | CREATE TABLE rt_with_columnar ( +id bigint, +title text, +category_id integer, +price float, +description string attribute engine='columnar', +attributes json, +tags multi +) | ++------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ +––– input ––– +mysql -h0 -P9307 -e 'show create table rt_without_columnar' +––– output ––– ++---------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ +| Table | Create Table | ++---------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ +| rt_without_columnar | CREATE TABLE rt_without_columnar ( +id bigint, +title text, +category_id integer, +price float, +description string attribute, +attributes json, +tags multi +) | ++---------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------+ +––– input ––– +ls -lt /tmp/backup-* +––– output ––– +ls: cannot access '/tmp/backup-*': No such file or directory +––– input ––– +manticore-backup --backup-dir=/tmp +––– output ––– +Copyright (c) %{YEAR}, Manticore Software LTD (https://manticoresearch.com) +Manticore config file: /etc/manticoresearch/manticore.conf +Tables to backup: all tables +Backup dir: /tmp +Manticore config +endpoint = http://%{IPADDR}:9313 +Manticore versions: +manticore: %{SEMVER} %{COMMITDATE} dev +columnar: %{SEMVER} %{COMMITDATE} +secondary: %{SEMVER} %{COMMITDATE} +knn: %{SEMVER} %{COMMITDATE} +buddy: %{SEMVER} +%{DATETIME} [Info] Starting the backup... +%{DATETIME} [Info] Backing up config files... +%{DATETIME} [Info] config files - OK +%{DATETIME} [Info] Backing up global state files... +%{DATETIME} [Info] global state files – OK +%{DATETIME} [Info] Backing up tables... +%{DATETIME} [Info] distributed_index (distributed)... +%{DATETIME} [Info] SKIP +%{DATETIME} [Info] rt_with_columnar (rt) [2.897K]... +%{DATETIME} [Info] OK +%{DATETIME} [Info] rt_without_columnar (rt) [2.771K]... +%{DATETIME} [Info] OK +%{DATETIME} [Info] Running sync +%{DATETIME} [Info] OK +%{DATETIME} [Info] You can find backup here: /tmp/backup-#!/[0-9]{14}/!# +%{DATETIME} [Info] Elapsed time: #!/[0-9]+/!#.#!/[0-9]+/!#s +%{DATETIME} [Info] Done +––– input ––– +ls -lh /tmp/backup-* +––– output ––– +total 16K +%{FILEPERMS} %{NUMBER} root root 4.0K #!/[a-zA-Z]{3}/!# #!/[0-9]{1,2}/!# #!/[0-9]{2}:[0-9]{2}/!# config +%{FILEPERMS} %{NUMBER} root root 4.0K #!/[a-zA-Z]{3}/!# #!/[0-9]{1,2}/!# #!/[0-9]{2}:[0-9]{2}/!# data +%{FILEPERMS} %{NUMBER} root root 4.0K #!/[a-zA-Z]{3}/!# #!/[0-9]{1,2}/!# #!/[0-9]{2}:[0-9]{2}/!# state +%{FILEPERMS} %{NUMBER} root root %{NUMBER} #!/[a-zA-Z]{3}/!# #!/[0-9]{1,2}/!# #!/[0-9]{2}:[0-9]{2}/!# versions.json diff --git a/tests/config/manticore-vip.conf b/tests/config/manticore-vip.conf new file mode 100644 index 0000000..f155126 --- /dev/null +++ b/tests/config/manticore-vip.conf @@ -0,0 +1,12 @@ +searchd { + listen = 127.0.0.1:9312 + listen = 127.0.0.1:9306:mysql + listen = 127.0.0.1:9307:mysql_vip + listen = 127.0.0.1:9308:http + listen = 127.0.0.1:9313:http_vip + log = /var/log/manticore/searchd.log + query_log = /var/log/manticore/query.log + pid_file = /var/run/manticore/searchd.pid + data_dir = /var/lib/manticore + max_connections = 1 +}