diff --git a/mysql_ch_replicator/clickhouse_api.py b/mysql_ch_replicator/clickhouse_api.py index f3de7e2..0622ad5 100644 --- a/mysql_ch_replicator/clickhouse_api.py +++ b/mysql_ch_replicator/clickhouse_api.py @@ -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) diff --git a/mysql_ch_replicator/db_replicator.py b/mysql_ch_replicator/db_replicator.py index 3787a3b..96bad0c 100644 --- a/mysql_ch_replicator/db_replicator.py +++ b/mysql_ch_replicator/db_replicator.py @@ -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 1 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