londiste compare: calculate checksum
authorMarko Kreen <markokr@gmail.com>
Wed, 23 Jun 2010 14:11:03 +0000 (17:11 +0300)
committerMarko Kreen <markokr@gmail.com>
Wed, 23 Jun 2010 14:11:03 +0000 (17:11 +0300)
Also allow specify format string.

Patch by Hannu Krosing

python/londiste/compare.py

index 23324cf0fd738e51a52da9dea517bef015e40b0d..a52d24bed975be1aada74179e32b3b6b285a5880 100644 (file)
@@ -23,21 +23,24 @@ class Comparator(Syncer):
 
         self.log.info('Counting %s' % tbl)
 
-        q = "select count(1) from only _TABLE_"
+        q = "select count(1) as cnt, sum(hashtext(t.*::text)) as chksum from only _TABLE_ t"
         q = self.cf.get('compare_sql', q)
         q = q.replace('_TABLE_', skytools.quote_fqident(tbl))
 
+        f = "%(cnt)d rows, checksum=%(chksum)s"
+        f = self.cf.get('compare_fmt', f)
+
         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)
+        src_str = f % src_row
+        self.log.info("srcdb: %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)
+        dst_str = f % dst_row
+        self.log.info("dstdb: %s" % dst_str)
 
         if src_str != dst_str:
             self.log.warning("%s: Results do not match!" % tbl)