Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for final setting enabled in clickhouse #21

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading