1
2
3 """Compares tables in replication set.
4
5 Currently just does count(1) on both sides.
6 """
7
8 import sys, os, time, skytools
9
10 __all__ = ['Comparator']
11
12 from syncer import Syncer
13
16 """Actual comparision."""
17
18 src_curs = src_db.cursor()
19 dst_curs = dst_db.cursor()
20
21 self.log.info('Counting %s' % tbl)
22
23 q = "select count(1) from only _TABLE_"
24 q = self.cf.get('compare_sql', q)
25 q = q.replace('_TABLE_', tbl)
26
27 self.log.debug("srcdb: " + q)
28 src_curs.execute(q)
29 src_row = src_curs.fetchone()
30 src_str = ", ".join(map(str, src_row))
31 self.log.info("srcdb: res = %s" % src_str)
32
33 self.log.debug("dstdb: " + q)
34 dst_curs.execute(q)
35 dst_row = dst_curs.fetchone()
36 dst_str = ", ".join(map(str, dst_row))
37 self.log.info("dstdb: res = %s" % dst_str)
38
39 if src_str != dst_str:
40 self.log.warning("%s: Results do not match!" % tbl)
41
42 if __name__ == '__main__':
43 script = Comparator(sys.argv[1:])
44 script.start()
45