Skip to content

Commit d044d57

Browse files
committed
Added timeouts to clickhouse settings
1 parent fb40769 commit d044d57

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

mysql_ch_replicator/clickhouse_api.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
class ClickhouseApi:
3333
MAX_RETRIES = 5
3434
RETRY_INTERVAL = 30
35-
CONNECT_TIMEOUT = 30
36-
SEND_RECEIVE_TIMEOUT = 120
37-
3835
def __init__(self, database: str, clickhouse_settings: ClickhouseSettings):
3936
self.database = database
4037
self.clickhouse_settings = clickhouse_settings
@@ -43,8 +40,8 @@ def __init__(self, database: str, clickhouse_settings: ClickhouseSettings):
4340
port=clickhouse_settings.port,
4441
username=clickhouse_settings.user,
4542
password=clickhouse_settings.password,
46-
connect_timeout=ClickhouseApi.CONNECT_TIMEOUT,
47-
send_receive_timeout=ClickhouseApi.SEND_RECEIVE_TIMEOUT,
43+
connect_timeout=clickhouse_settings.connection_timeout,
44+
send_receive_timeout=clickhouse_settings.send_receive_timeout,
4845
)
4946
self.tables_last_record_version = {} # table_name => last used row version
5047
self.execute_command('SET final = 1;')

mysql_ch_replicator/config.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ class ClickhouseSettings:
3535
port: int = 3306
3636
user: str = 'root'
3737
password: str = ''
38+
connection_timeout: int = 30
39+
send_receive_timeout: int = 120
3840

3941
def validate(self):
4042
if not isinstance(self.host, str):
@@ -49,6 +51,18 @@ def validate(self):
4951
if not isinstance(self.password, str):
5052
raise ValueError(f'clickhouse password should be string and not {stype(self.password)}')
5153

54+
if not isinstance(self.connection_timeout, int):
55+
raise ValueError(f'clickhouse connection_timeout should be int and not {stype(self.connection_timeout)}')
56+
57+
if not isinstance(self.send_receive_timeout, int):
58+
raise ValueError(f'clickhouse send_receive_timeout should be int and not {stype(self.send_receive_timeout)}')
59+
60+
if self.connection_timeout <= 0:
61+
raise ValueError(f'connection timeout should be at least 1 second')
62+
63+
if self.send_receive_timeout <= 0:
64+
raise ValueError(f'send_receive_timeout timeout should be at least 1 second')
65+
5266

5367
@dataclass
5468
class BinlogReplicatorSettings:

0 commit comments

Comments
 (0)