r84546 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r84545‎ | r84546 | r84547 >
Date:19:31, 22 March 2011
Author:ariel
Status:deferred
Tags:
Comment:
add sleep and retry to all mysql commands, to survive momentary db connection issues
Modified paths:
  • /branches/ariel/xmldumps-backup/worker.py (modified) (history)

Diff [purge]

Index: branches/ariel/xmldumps-backup/worker.py
@@ -102,7 +102,10 @@
103103
104104 if (self._chunksEnabled):
105105 self.Stats = PageAndEditStats(wiki,dbName)
106 -
 106+ print "total",self.Stats.totalEdits
 107+ print "total2",self.Stats.totalPages
 108+ if (not self.Stats.totalEdits or not self.Stats.totalPages):
 109+ raise BackupError("Failed to get DB stats, exiting")
107110 if (self._revsPerChunkHistory):
108111 if (len(self._revsPerChunkHistory) == 1):
109112 self._numChunksHistory = self.getNumberOfChunksForXMLDumps(self.Stats.totalEdits, self._pagesPerChunkHistory[0])
@@ -212,20 +215,30 @@
213216
214217 class RunSimpleCommand(object):
215218
216 - def log(self, message, log = None):
217 - if (log):
218 - log.addToLogQueue("%s\n" % message)
 219+ def log(message, logInfo = None):
 220+ if (logInfo):
 221+ logInfo.addToLogQueue("%s\n" % message)
219222
220223 # FIXME rewrite to not use popen2
221 - def runAndReturn(command, log = None):
 224+ def runAndReturn(command, logInfo = None):
222225 """Run a command and return the output as a string.
223226 Raises BackupError on non-zero return code."""
224227 # FIXME convert all these calls so they just use runCommand now
 228+ retval = 1
 229+ retries=0
 230+ maxretries=3
225231 proc = popen2.Popen4(command, 64)
226232 output = proc.fromchild.read()
227233 retval = proc.wait()
 234+ while (retval and retries < maxretries):
 235+ RunSimpleCommand.log("Non-zero return code from '%s'" % command, logInfo)
 236+ time.sleep(5)
 237+ proc = popen2.Popen4(command, 64)
 238+ output = proc.fromchild.read()
 239+ retval = proc.wait()
 240+ retries = retries + 1
228241 if retval:
229 - self.log("Non-zero return code from '%s'" % command, log)
 242+# RunSimpleCommand.log("Non-zero return code from '%s'" % command, logInfo)
230243 raise BackupError("Non-zero return code from '%s'" % command)
231244 else:
232245 return output
@@ -247,6 +260,7 @@
248261
249262 runAndReturn = staticmethod(runAndReturn)
250263 runAndReport = staticmethod(runAndReport)
 264+ log = staticmethod(log)
251265
252266 class PageAndEditStats(object):
253267 def __init__(self, wiki, dbName):
@@ -255,23 +269,43 @@
256270 self.config = wiki.config
257271 self.dbName = dbName
258272 self.dbServerInfo = DbServerInfo(wiki, dbName)
259 - (self.totalPages, totalEdits) = self.getStatistics(config,dbName)
 273+ self.getStatistics(config,dbName)
260274
261275 def getStatistics(self, dbName, ignore):
262 - """Get (cached) statistics for the wiki"""
263 - totalPages = None
264 - totalEdits = None
 276+ """Get statistics for the wiki"""
 277+
265278 query = "select MAX(page_id) from page;"
 279+ results = None
 280+ retries = 0
 281+ maxretries = 5
266282 results = self.dbServerInfo.runSqlAndGetOutput(query)
 283+ while (results == None and retries < maxretries):
 284+ retries = retries + 1
 285+ time.sleep(5)
 286+ results = self.dbServerInfo.runSqlAndGetOutput(query)
 287+ if (not results):
 288+ return(1)
 289+
267290 lines = results.splitlines()
268291 if (lines and lines[1]):
269 - totalPages = int(lines[1])
 292+ self.totalPages = int(lines[1])
 293+ print "totalpages here is ",self.totalPages
270294 query = "select MAX(rev_id) from revision;"
 295+ retries = 0
 296+ results = None
271297 results = self.dbServerInfo.runSqlAndGetOutput(query)
 298+ while (results == None and retries < maxretries):
 299+ retries = retries + 1
 300+ time.sleep(5)
 301+ results = self.dbServerInfo.runSqlAndGetOutput(query)
 302+ if (not results):
 303+ return(1)
 304+
272305 lines = results.splitlines()
273306 if (lines and lines[1]):
274 - totalEdits = int(lines[1])
275 - return(totalPages, totalEdits)
 307+ self.totalEdits = int(lines[1])
 308+ print "totaledits here is ",self.totalEdits
 309+ return(0)
276310
277311 def getTotalPages(self):
278312 return self.totalPages
@@ -723,6 +757,7 @@
724758 self.config.php, self.config.wikiDir, self.dbName))
725759 return RunSimpleCommand.runAndReturn(command, self.log).strip()
726760
 761+ # returns 0 on success, 1 on error
727762 def saveTable(self, table, outfile):
728763 """Dump a table from the current DB with mysqldump, save to a gzipped sql file."""
729764 commands = [ [ "%s" % self.config.mysqldump, "-h",
@@ -748,6 +783,7 @@
749784 [ "%s" % self.config.gzip ] ]
750785 return self.saveCommand(command, outfile)
751786
 787+ # returns 0 on success, 1 on error
752788 def saveCommand(self, commands, outfile):
753789 """For one pipeline of commands, redirect output to a given file."""
754790 commands[-1].extend( [ ">" , outfile ] )
@@ -759,7 +795,9 @@
760796 # be a list (the command name and the various args)
761797 # If the shell option is true, all pipelines will be run under the shell.
762798 def runCommand(self, commandSeriesList, callback=None, arg=None, shell = False):
763 - """Nonzero return code from the shell from any command in any pipeline will raise a BackupError.
 799+ """Nonzero return code from the shell from any command in any pipeline will cause this
 800+ function to print an error message and return 1, indictating error.
 801+ Returns 0 on success.
764802 If a callback function is passed, it will receive lines of
765803 output from the call. If the callback function takes another argument (which will
766804 be passed before the line of output) must be specified by the arg paraemeter.
@@ -778,7 +816,7 @@
779817 for cmd in problemCommands:
780818 errorString = errorString + "%s " % cmd
781819 self.logAndPrint(errorString)
782 - raise BackupError(errorString)
 820+# raise BackupError(errorString)
783821 return 1
784822
785823 def debug(self, stuff):
@@ -1320,7 +1358,15 @@
13211359 return runner.dumpDir.publicPath(self._file())
13221360
13231361 def run(self, runner):
1324 - return runner.saveTable(self._table, self._path(runner))
 1362+ retries = 0
 1363+ # try this initially and see how it goes
 1364+ maxretries = 3
 1365+ error = runner.saveTable(self._table, self._path(runner))
 1366+ while (error and retries < maxretries):
 1367+ retries = retries + 1
 1368+ time.sleep(5)
 1369+ error = runner.saveTable(self._table, self._path(runner))
 1370+ return error
13251371
13261372 def listFiles(self, runner):
13271373 return [self._file()]
@@ -2135,8 +2181,16 @@
21362182 class TitleDump(Dump):
21372183 """This is used by "wikiproxy", a program to add Wikipedia links to BBC news online"""
21382184 def run(self, runner):
2139 - return runner.saveSql("select page_title from page where page_namespace=0;",
2140 - runner.dumpDir.publicPath("all-titles-in-ns0.gz"))
 2185+ retries = 0
 2186+ # try this initially and see how it goes
 2187+ maxretries = 3
 2188+ query="select page_title from page where page_namespace=0;"
 2189+ error = runner.saveSql(query, runner.dumpDir.publicPath("all-titles-in-ns0.gz"))
 2190+ while (error and retries < maxretries):
 2191+ retries = retries + 1
 2192+ time.sleep(5)
 2193+ error = runner.saveSql(query, runner.dumpDir.publicPath("all-titles-in-ns0.gz"))
 2194+ return error
21412195
21422196 def listFiles(self, runner):
21432197 return ["all-titles-in-ns0.gz"]

Status & tagging log