blob: 23324cf0fd738e51a52da9dea517bef015e40b0d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#! /usr/bin/env python
"""Compares tables in replication set.
Currently just does count(1) on both sides.
"""
import sys, skytools
__all__ = ['Comparator']
from londiste.syncer import Syncer
class Comparator(Syncer):
"""Simple checker based in Syncer.
When tables are in sync runs simple SQL query on them.
"""
def process_sync(self, tbl, src_db, dst_db):
"""Actual comparision."""
src_curs = src_db.cursor()
dst_curs = dst_db.cursor()
self.log.info('Counting %s' % tbl)
q = "select count(1) from only _TABLE_"
q = self.cf.get('compare_sql', q)
q = q.replace('_TABLE_', skytools.quote_fqident(tbl))
self.log.debug("srcdb: " + q)
src_curs.execute(q)
src_row = src_curs.fetchone()
src_str = ", ".join(map(str, src_row))
self.log.info("srcdb: res = %s" % src_str)
self.log.debug("dstdb: " + q)
dst_curs.execute(q)
dst_row = dst_curs.fetchone()
dst_str = ", ".join(map(str, dst_row))
self.log.info("dstdb: res = %s" % dst_str)
if src_str != dst_str:
self.log.warning("%s: Results do not match!" % tbl)
if __name__ == '__main__':
script = Comparator(sys.argv[1:])
script.start()
|