diff options
author | jadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-05-29 21:03:13 +0000 |
---|---|---|
committer | jadmanski <jadmanski@592f7852-d20e-0410-864c-8624ca9c26a4> | 2008-05-29 21:03:13 +0000 |
commit | f844c6d50505d53523dd71d963f2d3812a271a23 (patch) | |
tree | e431959831e8a8dcef4b372539371b5d408faf75 | |
parent | ce3f8f18f749a82a303f8243dff06477995677ba (diff) |
Risk: Medium
Visibility: Should eliminate missing results errors due to the final
reparse failing because of intermittent db issues.
Adds an autoretry to the transactions used for the final reparse.
Signed-off-by: John Admanski <jadmanski@google.com>
git-svn-id: svn://test.kernel.org/autotest/trunk@1567 592f7852-d20e-0410-864c-8624ca9c26a4
-rw-r--r-- | tko/db.py | 24 | ||||
-rwxr-xr-x | tko/parse.py | 8 |
2 files changed, 22 insertions, 10 deletions
@@ -78,11 +78,15 @@ class db_sql: time.sleep(delay) - def _run_with_retry(self, function, *args, **dargs): + def run_with_retry(self, function, *args, **dargs): """Call function(*args, **dargs) until either it passes - without an operational error, or a timeout is reached. This - is intended for internal use with database functions, not - for generic use.""" + without an operational error, or a timeout is reached. + This will re-connect to the database, so it is NOT safe + to use this inside of a database transaction. + + It can be safely used with transactions, but the + transaction start & end must be completely contained + within the call to 'function'.""" OperationalError = _get_error_class("OperationalError") success = False @@ -188,7 +192,10 @@ class db_sql: return self.cur.fetchall() # run the query, re-trying after operational errors - return self._run_with_retry(exec_sql) + if self.autocommit: + return self.run_with_retry(exec_sql) + else: + return exec_sql() def select_sql(self, fields, table, sql, values): @@ -204,7 +211,10 @@ class db_sql: return self.cur.fetchall() # run the query, re-trying after operational errors - return self._run_with_retry(exec_sql) + if self.autocommit: + return self.run_with_retry(exec_sql) + else: + return exec_sql() def _exec_sql_with_commit(self, sql, values, commit): @@ -213,7 +223,7 @@ class db_sql: def exec_sql(): self.cur.execute(sql, values) self.con.commit() - self._run_with_retry(exec_sql) + self.run_with_retry(exec_sql) else: # take one shot at running the query self.cur.execute(sql, values) diff --git a/tko/parse.py b/tko/parse.py index 1b96bab6..6d88d833 100755 --- a/tko/parse.py +++ b/tko/parse.py @@ -140,8 +140,9 @@ def parse_path(db, path, level, reparse, mail_on_failure): jobpath = os.path.join(path, machine) jobname = "%s/%s" % (os.path.basename(path), machine) try: - parse_one(db, jobname, jobpath, reparse, - mail_on_failure) + db.run_with_retry(parse_one, db, jobname, + path, reparse, + mail_on_failure) except Exception: traceback.print_exc() continue @@ -150,7 +151,8 @@ def parse_path(db, path, level, reparse, mail_on_failure): job_elements = path.split("/")[-level:] jobname = "/".join(job_elements) try: - parse_one(db, jobname, path, reparse, mail_on_failure) + db.run_with_retry(parse_one, db, jobname, path, + reparse, mail_on_failure) except Exception: traceback.print_exc() |