[tahoe-lafs-trac-stream] [tahoe-lafs] #1865: backup has over-general exception swallowing that leads to assertion failures.
tahoe-lafs
trac at tahoe-lafs.org
Sun Nov 18 07:06:26 UTC 2012
#1865: backup has over-general exception swallowing that leads to assertion
failures.
--------------------------+--------------------------------
Reporter: nejucomo | Owner: davidsarah
Type: defect | Status: new
Priority: normal | Milestone: undecided
Component: unknown | Version: 1.9.2
Resolution: | Keywords: error tahoe-backup
Launchpad Bug: |
--------------------------+--------------------------------
Comment (by zooko):
Here's a patch which I think will do the right thing while not catching
exceptions that it shouldn't catch. This is safe in sqlite, because sqlite
always locks whole tables. For databases with finer-grained transactions,
it would be necessary to use isolation level "serializable" or stricter
for this to be safe.
{{{
diff --git a/src/allmydata/scripts/backupdb.py
b/src/allmydata/scripts/backupdb.py
index 75ee0d9..8eed692 100644
--- a/src/allmydata/scripts/backupdb.py
+++ b/src/allmydata/scripts/backupdb.py
@@ -247,14 +247,12 @@ class BackupDB_v2:
# sqlite has "INSERT ON CONFLICT REPLACE", but not mysql
# So we use INSERT, ignore any error, then a SELECT
c = self.cursor
- try:
- c.execute("INSERT INTO caps (filecap) VALUES (?)",
(filecap,))
- except (self.sqlite_module.IntegrityError,
self.sqlite_module.OperationalError):
- # sqlite3 on sid gives IntegrityError
- # pysqlite2 (which we don't use, so maybe no longer relevant)
on dapper gives OperationalError
- pass
c.execute("SELECT fileid FROM caps WHERE filecap=?", (filecap,))
foundrow = c.fetchone()
+ if foundrow is None:
+ c.execute("INSERT INTO caps (filecap) VALUES (?)",
(filecap,))
+ c.execute("SELECT fileid FROM caps WHERE filecap=?",
(filecap,))
+ foundrow = c.fetchone()
assert foundrow
fileid = foundrow[0]
return fileid
}}}
--
Ticket URL: <https://tahoe-lafs.org/trac/tahoe-lafs/ticket/1865#comment:1>
tahoe-lafs <https://tahoe-lafs.org>
secure decentralized storage
More information about the tahoe-lafs-trac-stream
mailing list