Skip to content

Commit c04dbe3

Browse files
committed
Check for final setting enabled in clickhouse
1 parent 69b29f3 commit c04dbe3

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

mysql_ch_replicator/clickhouse_api.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,9 @@ def select(self, table_name, where=None):
187187
for row in rows:
188188
results.append(dict(zip(columns, row)))
189189
return results
190+
191+
def get_system_setting(self, name):
192+
results = self.select('system.settings', f"name = '{name}'")
193+
if not results:
194+
return None
195+
return results[0].get('value', None)

mysql_ch_replicator/db_replicator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,21 @@ def __init__(self, config: Settings, database: str, target_database: str = None,
136136
def create_state(self):
137137
return State(os.path.join(self.config.binlog_replicator.data_dir, self.database, 'state.pckl'))
138138

139+
def validate_database_settings(self):
140+
if not self.initial_only:
141+
final_setting = self.clickhouse_api.get_system_setting('final')
142+
if final_setting != '1':
143+
logger.warning('settings validation failed')
144+
logger.warning(
145+
'\n\n\n !!! WARNING - MISSING REQUIRED CLICKHOUSE SETTING (final) !!!\n\n'
146+
'You need to set <final>1</final> in clickhouse config file\n'
147+
'Otherwise you will get DUPLICATES in your SELECT queries\n\n\n'
148+
)
149+
139150
def run(self):
140151
try:
141152
logger.info('launched db_replicator')
153+
self.validate_database_settings()
142154

143155
if self.state.status != Status.NONE:
144156
# ensure target database still exists

0 commit comments

Comments
 (0)