(self)
Syncer main function.
Syncer main function.
Syncer main function .
def work(self):
        """Syncer main function."""

        source_query = self.cf.get('source_query')
        target_query = self.cf.get('target_query')
        consumer_query = self.cf.get('consumer_query')
        where_expr = self.cf.get('where_expr')
        extra_connstr = self.cf.get('extra_connstr')

        check = self.cf.get('check_type', 'compare')

        confdb = self.get_database('confdb', autocommit=1)
        curs = confdb.cursor()

        curs.execute(source_query)
        for src_row in curs.fetchall():
            s_host = src_row['hostname']
            s_db = src_row['db_name']

            curs.execute(consumer_query, src_row)
            r = curs.fetchone()
            consumer_name = r['consumer_name']
            queue_name = r['queue_name']

            curs.execute(target_query, src_row)
            for dst_row in curs.fetchall():
                d_db = dst_row['db_name']
                d_host = dst_row['hostname']

                cstr1 = "dbname=%s host=%s %s" % (s_db, s_host, extra_connstr)
                cstr2 = "dbname=%s host=%s %s" % (d_db, d_host, extra_connstr)
                where = where_expr % dst_row

                self.log.info('Source: db=%s host=%s queue=%s consumer=%s' % (
                                  s_db, s_host, queue_name, consumer_name))
                self.log.info('Target: db=%s host=%s where=%s' % (d_db, d_host, where))

                for tbl in self.table_list:
                    src_db, dst_db = self.sync_table(cstr1, cstr2, queue_name, consumer_name, tbl)
                    if check == 'compare':
                        self.do_compare(tbl, src_db, dst_db, where)
                    elif check == 'repair':
                        r = TableRepair(tbl, self.log)
                        r.do_repair(src_db, dst_db, where, 'fix.' + tbl, False)
                    elif check == 'repair-apply':
                        r = TableRepair(tbl, self.log)
                        r.do_repair(src_db, dst_db, where, 'fix.' + tbl, True)
                    elif check == 'compare-repair-apply':
                        ok = self.do_compare(tbl, src_db, dst_db, where)
                        if not ok:
                            r = TableRepair(tbl, self.log)
                            r.do_repair(src_db, dst_db, where, 'fix.' + tbl, True)
                    else:
                        raise Exception('unknown check type')
                    self.reset()
def work ( self ) : source_query = self . cf . get ( 'source_query' ) target_query = self . cf . get ( 'target_query' ) consumer_query = self . cf . get ( 'consumer_query' ) where_expr = self . cf . get ( 'where_expr' ) extra_connstr = self . cf . get ( 'extra_connstr' ) check = self . cf . get ( 'check_type' , 'compare' ) confdb = self . get_database ( 'confdb' , autocommit = 1 ) curs = confdb . cursor ( ) curs . execute ( source_query ) for src_row in curs . fetchall ( ) : s_host = src_row [ 'hostname' ] s_db = src_row [ 'db_name' ] curs . execute ( consumer_query , src_row ) r = curs . fetchone ( ) consumer_name = r [ 'consumer_name' ] queue_name = r [ 'queue_name' ] curs . execute ( target_query , src_row ) for dst_row in curs . fetchall ( ) : d_db = dst_row [ 'db_name' ] d_host = dst_row [ 'hostname' ] cstr1 = "dbname=%s host=%s %s" % ( s_db , s_host , extra_connstr ) cstr2 = "dbname=%s host=%s %s" % ( d_db , d_host , extra_connstr ) where = where_expr % dst_row self . log . info ( 'Source: db=%s host=%s queue=%s consumer=%s' % ( s_db , s_host , queue_name , consumer_name ) ) self . log . info ( 'Target: db=%s host=%s where=%s' % ( d_db , d_host , where ) ) for tbl in self . table_list : src_db , dst_db = self . sync_table ( cstr1 , cstr2 , queue_name , consumer_name , tbl ) if check == 'compare' : self . do_compare ( tbl , src_db , dst_db , where ) elif check == 'repair' : r = TableRepair ( tbl , self . log ) r . do_repair ( src_db , dst_db , where , 'fix.' + tbl , False ) elif check == 'repair-apply' : r = TableRepair ( tbl , self . log ) r . do_repair ( src_db , dst_db , where , 'fix.' + tbl , True ) elif check == 'compare-repair-apply' : ok = self . do_compare ( tbl , src_db , dst_db , where ) if not ok : r = TableRepair ( tbl , self . log ) r . do_repair ( src_db , dst_db , where , 'fix.' + tbl , True ) else : raise Exception ( 'unknown check type' ) self . reset ( )