Skip to content

Commit

Permalink
Added timeouts to clickhouse settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bakwc committed Nov 5, 2024
1 parent fb40769 commit d044d57
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 2 additions & 5 deletions mysql_ch_replicator/clickhouse_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@
class ClickhouseApi:
MAX_RETRIES = 5
RETRY_INTERVAL = 30
CONNECT_TIMEOUT = 30
SEND_RECEIVE_TIMEOUT = 120

def __init__(self, database: str, clickhouse_settings: ClickhouseSettings):
self.database = database
self.clickhouse_settings = clickhouse_settings
Expand All @@ -43,8 +40,8 @@ def __init__(self, database: str, clickhouse_settings: ClickhouseSettings):
port=clickhouse_settings.port,
username=clickhouse_settings.user,
password=clickhouse_settings.password,
connect_timeout=ClickhouseApi.CONNECT_TIMEOUT,
send_receive_timeout=ClickhouseApi.SEND_RECEIVE_TIMEOUT,
connect_timeout=clickhouse_settings.connection_timeout,
send_receive_timeout=clickhouse_settings.send_receive_timeout,
)
self.tables_last_record_version = {} # table_name => last used row version
self.execute_command('SET final = 1;')
Expand Down
14 changes: 14 additions & 0 deletions mysql_ch_replicator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class ClickhouseSettings:
port: int = 3306
user: str = 'root'
password: str = ''
connection_timeout: int = 30
send_receive_timeout: int = 120

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

if not isinstance(self.connection_timeout, int):
raise ValueError(f'clickhouse connection_timeout should be int and not {stype(self.connection_timeout)}')

if not isinstance(self.send_receive_timeout, int):
raise ValueError(f'clickhouse send_receive_timeout should be int and not {stype(self.send_receive_timeout)}')

if self.connection_timeout <= 0:
raise ValueError(f'connection timeout should be at least 1 second')

if self.send_receive_timeout <= 0:
raise ValueError(f'send_receive_timeout timeout should be at least 1 second')


@dataclass
class BinlogReplicatorSettings:
Expand Down

0 comments on commit d044d57

Please sign in to comment.