Skip to content

Commit

Permalink
Check for final setting enabled in clickhouse (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakwc authored Nov 15, 2024
1 parent 69b29f3 commit 16c54b9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mysql_ch_replicator/clickhouse_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,9 @@ def select(self, table_name, where=None):
for row in rows:
results.append(dict(zip(columns, row)))
return results

def get_system_setting(self, name):
results = self.select('system.settings', f"name = '{name}'")
if not results:
return None
return results[0].get('value', None)
12 changes: 12 additions & 0 deletions mysql_ch_replicator/db_replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,21 @@ def __init__(self, config: Settings, database: str, target_database: str = None,
def create_state(self):
return State(os.path.join(self.config.binlog_replicator.data_dir, self.database, 'state.pckl'))

def validate_database_settings(self):
if not self.initial_only:
final_setting = self.clickhouse_api.get_system_setting('final')
if final_setting != '1':
logger.warning('settings validation failed')
logger.warning(
'\n\n\n !!! WARNING - MISSING REQUIRED CLICKHOUSE SETTING (final) !!!\n\n'
'You need to set <final>1</final> in clickhouse config file\n'
'Otherwise you will get DUPLICATES in your SELECT queries\n\n\n'
)

def run(self):
try:
logger.info('launched db_replicator')
self.validate_database_settings()

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

0 comments on commit 16c54b9

Please sign in to comment.