r104422 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104421‎ | r104422 | r104423 >
Date:11:53, 28 November 2011
Author:ariel
Status:deferred
Tags:
Comment:
config option determines when locks for maxrevid phase are stale; cmd line option to clean up stale locks encountered during run
Modified paths:
  • /branches/ariel/xmldumps-backup/incrementals/IncrDumpLib.py (modified) (history)
  • /branches/ariel/xmldumps-backup/incrementals/generatemaxrevids.py (modified) (history)

Diff [purge]

Index: branches/ariel/xmldumps-backup/incrementals/IncrDumpLib.py
@@ -10,6 +10,7 @@
1111 import subprocess
1212 from subprocess import Popen, PIPE
1313 import shutil
 14+import time
1415
1516 class ContentFile(object):
1617 def __init__(self, config, date, wikiName):
@@ -114,6 +115,18 @@
115116 except:
116117 return False
117118
 119+ def isStaleLock(self):
 120+ if not self.isLocked():
 121+ return False
 122+ try:
 123+ timestamp = os.stat(self.lockFile.getPath()).st_mtime
 124+ except:
 125+ return False
 126+ if (time.time() - timestamp) > self._config.staleInterval:
 127+ return True
 128+ else:
 129+ return False
 130+
118131 def unlock(self):
119132 os.remove(self.lockFile.getPath())
120133
@@ -161,6 +174,7 @@
162175 "webroot": "http://localhost/dumps/incr",
163176 "fileperms": "0640",
164177 "delay": "43200",
 178+ "maxrevidstaleinterval": "3600",
165179 #"database": {
166180 "user": "root",
167181 "password": "",
@@ -206,6 +220,8 @@
207221 self.fileperms = int(self.fileperms,0)
208222 self.delay = self.conf.get("output", "delay")
209223 self.delay = int(self.delay,0)
 224+ self.staleInterval = self.conf.get("output", "maxrevidstaleinterval")
 225+ self.staleInterval = int(self.staleInterval,0)
210226
211227 if not self.conf.has_section('tools'):
212228 self.conf.add_section('tools')
Index: branches/ariel/xmldumps-backup/incrementals/generatemaxrevids.py
@@ -40,11 +40,12 @@
4141 return exists(self.maxRevIdFile.getPath())
4242
4343 class MaxIDDump(object):
44 - def __init__(self,config, date, verbose):
 44+ def __init__(self,config, date, verbose, cleanupStale):
4545 self._config = config
4646 self.date = date
4747 self.incrDir = IncrementDir(self._config, self.date)
4848 self.verbose = verbose
 49+ self.cleanupStale = cleanupStale
4950
5051 def doOneWiki(self, w):
5152 success = True
@@ -52,7 +53,23 @@
5354 if not exists(self.incrDir.getIncDir(w)):
5455 os.makedirs(self.incrDir.getIncDir(w))
5556 lock = MaxRevIDLock(self._config, self.date, w)
56 - if lock.getLock():
 57+ lockResult = lock.getLock()
 58+ if not lockResult:
 59+ if (self.verbose):
 60+ print "failed to get lock for wiki", w
 61+ if lock.isStaleLock():
 62+ if (self.verbose):
 63+ print "lock is stale for wiki", w
 64+ # this option should be given to one process only, or you could have trouble.
 65+ if (self.cleanupStale):
 66+ lock.unlock()
 67+ lockResult = lock.getLock()
 68+ if (self.verbose):
 69+ print "stale lock removed and trying again to get for wiki", w
 70+ if lockResult:
 71+ if (self.verbose):
 72+ print "got lock ",lock.lockFile.getFileName()
 73+ print "checking max rev id for wiki", w
5774 try:
5875 maxRevID = MaxRevID(self._config, w, self.date)
5976 if not maxRevID.exists():
@@ -66,10 +83,10 @@
6784 else:
6885 if (self.verbose):
6986 print "Wiki ", w, "failed to get lock."
70 - traceback.print_exc(file=sys.stdout)
 87+ success = False
7188 if success:
7289 if (self.verbose):
73 - print "Success! Wiki", w, "adds/changes dump complete."
 90+ print "Success! Wiki", w, "rev max id for adds/changes dump complete."
7491 return success
7592
7693 def doRunOnAllWikis(self):
@@ -96,11 +113,13 @@
97114 print message
98115 print "Usage: python generateincrementals.py [options] [wikidbname]"
99116 print "Options: --configfile, --date, --verbose"
100 - print "--configfile: Specify an alternate config file to read. Default file is 'dumpincr.conf' in the current directory."
101 - print "--date: (Re)run incremental of a given date (use with care)."
102 - print "--verbose: Print error messages and other informative messages (normally the"
103 - print " script runs silently)."
104 - print "wikiname: Run the dumps only for the specific wiki."
 117+ print "--configfile: Specify an alternate config file to read. Default file is 'dumpincr.conf' in the current directory."
 118+ print "--cleanupstale: Clean up stale lock files as they are encountered. Only one process running should ever have this"
 119+ print " option set."
 120+ print "--date: (Re)run incremental of a given date (use with care)."
 121+ print "--verbose: Print error messages and other informative messages (normally the"
 122+ print " script runs silently)."
 123+ print "wikiname: Run the dumps only for the specific wiki."
105124 sys.exit(1)
106125
107126 if __name__ == "__main__":
@@ -108,10 +127,11 @@
109128 result = False
110129 date = None
111130 verbose = False
 131+ cleanupStale = False
112132
113133 try:
114134 (options, remainder) = getopt.gnu_getopt(sys.argv[1:], "",
115 - ['date=', 'configfile=', 'verbose' ])
 135+ ['date=', 'configfile=', 'verbose', 'cleanupstale' ])
116136 except:
117137 usage("Unknown option specified")
118138
@@ -122,6 +142,8 @@
123143 configFile = val
124144 elif opt == "--verbose":
125145 verbose = True
 146+ elif opt == "--cleanupstale":
 147+ cleanupStale = True
126148
127149 if (configFile):
128150 config = Config(configFile)
@@ -131,7 +153,7 @@
132154 if not date:
133155 date = TimeUtils.today()
134156
135 - dump = MaxIDDump(config, date, verbose)
 157+ dump = MaxIDDump(config, date, verbose, cleanupStale)
136158 if len(remainder) > 0:
137159 dump.doOneWiki(remainder[0])
138160 else:

Status & tagging log