Repository navigation
Add connection reestablisher to mysql and postgres dictionary pools - #71101
Conversation
|
This is an automated comment for commit 5427be7 with description of existing statuses. It's updated for the latest CI running ✅ Click here to open a full report in a separate page Successful checks
|
| - `table` – Name of the table and schema if exists. | ||
| - `connection_string` – Connection string. | ||
| - `invalidate_query` – Query for checking the dictionary status. Optional parameter. Read more in the section [Refreshing dictionary data using LIFETIME](#refreshing-dictionary-data-using-lifetime). | ||
| - `bg_reconnect` – Reconnect to replica in background if connection fails. Optional parameter. |
There was a problem hiding this comment.
| - `bg_reconnect` – Reconnect to replica in background if connection fails. Optional parameter. | |
| - `background_reconnect` – Reconnect to replica in background if connection fails. Optional parameter. |
There was a problem hiding this comment.
Is there any specific reason why the name should be shortened? The full one looks cleaner. Also, please change the rest of the usage.
There was a problem hiding this comment.
no specific reason I think, we can change it...
| @@ -1,3 +1,5 @@ | |||
| #include "Common/Exception.h" | |||
There was a problem hiding this comment.
| #include "Common/Exception.h" | |
| #include <Common/Exception.h> |
| if (dns_cache_updater) | ||
| dns_cache_updater->start(); | ||
|
|
||
| auto replicas_reconnector = ReplicasReconnector::init(global_context); |
There was a problem hiding this comment.
Passing the whole global_context looks a bit scary. Maybe we can create a task in BackgroundSchedulePool and pass it to the ReplicasReconnector along with a server setting?
There was a problem hiding this comment.
we don't hold on global context actually - ReplicasReconnector::init is a static function initializing a singleton (probably I've invented an "initializable singleton" pattern here :) ) - inside this function ReplicasReconnector constructor is called which uses global_context to create a task, that's all. Regarding saving bg_reconnect_mysql_dict_interval server setting I'm not sure, because config can be changed run-time - then we will need to synchronize possible change of this setting from config update task - which seems inconvenient...
| std::unique_ptr<ReplicasReconnector> ret(new ReplicasReconnector(context)); | ||
| instance_ptr(ret.get()); |
There was a problem hiding this comment.
Isn't it a memory leak or double-free? The ret object is being destroyed after leaving this function scope.
There was a problem hiding this comment.
ReplicasReconnector::init() is returning this std::unique_ptr<ReplicasReconnector> to Server::main local variable, so it undergoes RVO copy elision and nothing is destroyed at this point. And local variable in Server::main keeps this singleton alive during server's lifetime and destroys it when Server::main is finished - it's the whole point of "initializable singleton" - to keep its lifetime under control.
| static ReplicasReconnector * instance_ptr = nullptr; | ||
|
|
||
| if (deinitialize) | ||
| { | ||
| instance_ptr = nullptr; | ||
| return instance_ptr; | ||
| } |
There was a problem hiding this comment.
We can make is a class field and move the deinitialization to a separate method.
There was a problem hiding this comment.
It seems more convenient to keep it centralized and compact - it serves 3 functions - singleton initialization, deinitialization and access, and this function is never accessed outside... but probably having less "if's" is better and less obfuscated... I'll take a look...
| for (auto it = reconnectors.cbegin(); !emergency_stop && it != reconnectors.end();) | ||
| { | ||
| lock.unlock(); | ||
| bool res = (*it)(interval_milliseconds); |
There was a problem hiding this comment.
try ... catch to be safe?
There was a problem hiding this comment.
oh, yeah, or we're risking killing the thread... thanks
|
The tests are extremely flaky: https://s3.amazonaws.com/clickhouse-test-reports/0/2467a49811ab830db479ab26fb41a266916aeeb3/integration_tests__asan__old_analyzer__[1_6].html I'm reverting it temporarily. Please reintroduce when fixed |
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Reestablish connection to MySQL and Postgres dictionary replicas in background so it wouldn't delay requests to corresponding dictionaries.
closes https://github.com/ClickHouse/product/issues/1161
CI Settings (Only check the boxes if you know what you are doing):