@@ -125,28 +125,32 @@ def __init__(self, config: Settings, database: str, target_database: str = None,
125125 self .last_touch_time = 0
126126
127127 def run (self ):
128- logger .info ('launched db_replicator' )
129- if self .state .status == Status .RUNNING_REALTIME_REPLICATION :
130- self .run_realtime_replication ()
131- return
132- if self .state .status == Status .PERFORMING_INITIAL_REPLICATION :
128+ try :
129+ logger .info ('launched db_replicator' )
130+ if self .state .status == Status .RUNNING_REALTIME_REPLICATION :
131+ self .run_realtime_replication ()
132+ return
133+ if self .state .status == Status .PERFORMING_INITIAL_REPLICATION :
134+ self .perform_initial_replication ()
135+ self .run_realtime_replication ()
136+ return
137+
138+ logger .info ('recreating database' )
139+ self .clickhouse_api .database = self .target_database_tmp
140+ self .clickhouse_api .recreate_database ()
141+ self .state .tables = self .mysql_api .get_tables ()
142+ self .state .tables = [
143+ table for table in self .state .tables if self .config .is_table_matches (table )
144+ ]
145+ self .state .last_processed_transaction = self .data_reader .get_last_transaction_id ()
146+ self .state .save ()
147+ logger .info (f'last known transaction { self .state .last_processed_transaction } ' )
148+ self .create_initial_structure ()
133149 self .perform_initial_replication ()
134150 self .run_realtime_replication ()
135- return
136-
137- logger .info ('recreating database' )
138- self .clickhouse_api .database = self .target_database_tmp
139- self .clickhouse_api .recreate_database ()
140- self .state .tables = self .mysql_api .get_tables ()
141- self .state .tables = [
142- table for table in self .state .tables if self .config .is_table_matches (table )
143- ]
144- self .state .last_processed_transaction = self .data_reader .get_last_transaction_id ()
145- self .state .save ()
146- logger .info (f'last known transaction { self .state .last_processed_transaction } ' )
147- self .create_initial_structure ()
148- self .perform_initial_replication ()
149- self .run_realtime_replication ()
151+ except Exception :
152+ logger .error (f'unhandled exception' , exc_info = True )
153+ raise
150154
151155 def create_initial_structure (self ):
152156 self .state .status = Status .CREATING_INITIAL_STRUCTURES
@@ -417,7 +421,7 @@ def log_stats_if_required(self):
417421 if curr_time - self .last_dump_stats_time < DbReplicator .STATS_DUMP_INTERVAL :
418422 return
419423 self .last_dump_stats_time = curr_time
420- logger .info (f'statistics: \n { json .dumps (self .stats .__dict__ )} ' )
424+ logger .info (f'stats: { json .dumps (self .stats .__dict__ )} ' )
421425 self .stats = Statistics ()
422426
423427 def upload_records_if_required (self , table_name ):
0 commit comments