]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/commitdiff
backupdb.did_create_directory: use REPLACE INTO, not INSERT INTO + ignore error
authorBrian Warner <warner@lothar.com>
Wed, 28 Apr 2010 05:08:03 +0000 (22:08 -0700)
committerBrian Warner <warner@lothar.com>
Wed, 28 Apr 2010 05:08:03 +0000 (22:08 -0700)
This handles the case where we upload a new tahoe directory for a
previously-processed local directory, possibly creating a new dircap (if the
metadata had changed). Now we replace the old dirhash->dircap record. The
previous behavior left the old record in place (with the old dircap and
timestamps), so we'd never stop creating new directories and never converge
on a null backup.

src/allmydata/scripts/backupdb.py

index f5e3e07350366fc9de7458be17753588451325a4..f134e1420e49b3178d78bbec783101958602c841 100644 (file)
@@ -353,14 +353,11 @@ class BackupDB_v2:
 
     def did_create_directory(self, dircap, dirhash):
         now = time.time()
-        try:
-            self.cursor.execute("INSERT INTO directories VALUES (?,?,?,?)",
-                                (dirhash, dircap, now, now))
-        except (self.sqlite_module.IntegrityError,
-                self.sqlite_module.OperationalError):
-            # dirhash was already added: maybe they did mkdir and called us
-            # even though we told them the didn't have to
-            pass
+        # if the dirhash is already present (i.e. we've re-uploaded an
+        # existing directory, possibly replacing the dircap with a new one),
+        # update the record in place. Otherwise create a new record.)
+        self.cursor.execute("REPLACE INTO directories VALUES (?,?,?,?)",
+                            (dirhash, dircap, now, now))
         self.connection.commit()
 
     def did_check_directory_healthy(self, dircap, results):