Skip to content

Commit 40276b1

Browse files
authored
Moved retention period to config file (#128)
1 parent ebc9eec commit 40276b1

File tree

4 files changed

+11
-3
lines changed

4 files changed

+11
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ clickhouse:
148148
binlog_replicator:
149149
data_dir: '/home/user/binlog/'
150150
records_per_file: 100000
151+
binlog_retention_period: 43200 # optional, how long to keep binlog files in seconds, default 12 hours
151152

152153
databases: 'database_name_pattern_*'
153154
tables: '*'
@@ -196,6 +197,7 @@ types_mapping: # optional
196197
- `log_level` - log level, default is `info`, you can set to `debug` to get maximum information (allowed values are `debug`, `info`, `warning`, `error`, `critical`)
197198
- `optimize_interval` - interval (seconds) between automatic `OPTIMIZE table FINAL` calls. Default 86400 (1 day). This is required to perform all merges guaranteed and avoid increasing of used storage and decreasing performance.
198199
- `auto_restart_interval` - interval (seconds) between automatic db_replicator restart. Default 3600 (1 hour). This is done to reduce memory usage.
200+
- `binlog_retention_period` - how long to keep binlog files in seconds. Default 43200 (12 hours). This setting controls how long the local binlog files are retained before being automatically cleaned up.
199201
- `indexes` - you may want to add some indexes to accelerate performance, eg. ngram index for full-test search, etc. To apply indexes you need to start replication from scratch.
200202
- `http_host`, `http_port` - http endpoint to control replication, use `/docs` for abailable commands
201203
- `types_mappings` - custom types mapping, eg. you can map char(36) to UUID instead of String, etc.

mysql_ch_replicator/binlog_replicator.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,6 @@ def save(self):
340340
class BinlogReplicator:
341341
SAVE_UPDATE_INTERVAL = 60
342342
BINLOG_CLEAN_INTERVAL = 5 * 60
343-
BINLOG_RETENTION_PERIOD = 12 * 60 * 60
344343
READ_LOG_INTERVAL = 0.3
345344

346345
def __init__(self, settings: Settings):
@@ -378,7 +377,7 @@ def clear_old_binlog_if_required(self):
378377
return
379378

380379
self.last_binlog_clear_time = curr_time
381-
self.data_writer.remove_old_files(curr_time - BinlogReplicator.BINLOG_RETENTION_PERIOD)
380+
self.data_writer.remove_old_files(curr_time - self.replicator_settings.binlog_retention_period)
382381

383382
@classmethod
384383
def _try_parse_db_name_from_query(cls, query: str) -> str:

mysql_ch_replicator/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def validate(self):
7575
class BinlogReplicatorSettings:
7676
data_dir: str = 'binlog'
7777
records_per_file: int = 100000
78+
binlog_retention_period: int = 43200 # 12 hours in seconds
7879

7980
def validate(self):
8081
if not isinstance(self.data_dir, str):
@@ -86,6 +87,12 @@ def validate(self):
8687
if self.records_per_file <= 0:
8788
raise ValueError('binlog_replicator records_per_file should be positive')
8889

90+
if not isinstance(self.binlog_retention_period, int):
91+
raise ValueError(f'binlog_replicator binlog_retention_period should be int and not {stype(self.binlog_retention_period)}')
92+
93+
if self.binlog_retention_period <= 0:
94+
raise ValueError('binlog_replicator binlog_retention_period should be positive')
95+
8996

9097
class Settings:
9198
DEFAULT_LOG_LEVEL = 'info'

tests_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
mysql:
32
host: 'localhost'
43
port: 9306
@@ -14,6 +13,7 @@ clickhouse:
1413
binlog_replicator:
1514
data_dir: '/app/binlog/'
1615
records_per_file: 100000
16+
binlog_retention_period: 43200 # 12 hours in seconds
1717

1818
databases: '*test*'
1919
log_level: 'debug'

0 commit comments

Comments
 (0)