diff options
author | Marko Kreen | 2011-12-09 08:31:21 +0000 |
---|---|---|
committer | Marko Kreen | 2011-12-09 08:31:21 +0000 |
commit | 56b368d1bfea6674fc078b9bc33981ff6de34320 (patch) | |
tree | 8bb2b00792e915c6e4a973773450a6031cf1a0d8 | |
parent | 7a8c702d865196477e4bf42db62d468452f824cc (diff) |
londiste repair: add --apply flag
this will auto-apply fixes, instead writing them out.
-rwxr-xr-x | python/londiste.py | 8 | ||||
-rw-r--r-- | python/londiste/repair.py | 22 |
2 files changed, 25 insertions, 5 deletions
diff --git a/python/londiste.py b/python/londiste.py index f486332f..5ce717b9 100755 --- a/python/londiste.py +++ b/python/londiste.py @@ -110,8 +110,6 @@ class Londiste(skytools.DBScript): help = "add: include add possible tables") g.add_option("--dest-table", help = "add: redirect changes to different table") - g.add_option("--force", action="store_true", - help = "add: ignore table differences, repair: ignore lag") g.add_option("--expect-sync", action="store_true", dest="expect_sync", help = "add: no copy needed", default=False) g.add_option("--skip-truncate", action="store_true", dest="skip_truncate", @@ -138,7 +136,13 @@ class Londiste(skytools.DBScript): help="don't merge tables from source queues", default=False) g.add_option("--max-parallel-copy", type = "int", help="max number of parallel copy processes") + p.add_option_group(g) + g = optparse.OptionGroup(p, "other options options") + g.add_option("--force", action="store_true", + help = "add: ignore table differences, repair: ignore lag") + g.add_option("--apply", action = "store_true", + help="repair: apply fixes automatically") p.add_option_group(g) return p diff --git a/python/londiste/repair.py b/python/londiste/repair.py index 101fe6e0..6b9e2280 100644 --- a/python/londiste/repair.py +++ b/python/londiste/repair.py @@ -25,10 +25,23 @@ class Repairer(Syncer): total_dst = 0 pkey_list = [] common_fields = [] + apply_curs = None + + def init_optparse(self, p=None): + """Initialize cmdline switches.""" + p = super(Repairer, self).init_optparse(p) + p.add_option("--apply", action="store_true", help="apply fixes") + return p def process_sync(self, src_tbl, dst_tbl, src_db, dst_db): """Actual comparision.""" + apply_db = None + + if self.options.apply: + apply_db = self.get_database('db', cache='applydb', autocommit=1) + self.apply_curs = apply_db.cursor() + src_curs = src_db.cursor() dst_curs = dst_db.cursor() @@ -226,9 +239,12 @@ class Repairer(Syncer): def show_fix(self, tbl, q, desc): """Print/write/apply repair sql.""" - self.log.debug("missed %s: %s" % (desc, q)) - fn = "fix.%s.sql" % tbl - open(fn, "a").write("%s\n" % q) + self.log.info("missed %s: %s" % (desc, q)) + if self.apply_curs: + self.apply_curs.execute(q) + else: + fn = "fix.%s.sql" % tbl + open(fn, "a").write("%s\n" % q) def addeq(self, list, f, v): """Add quoted SET.""" |