[88983] trunk/base/src/cregistry/registry.c

cal at macports.org cal at macports.org
Sun Jan 15 18:02:01 PST 2012


Revision: 88983
          http://trac.macports.org/changeset/88983
Author:   cal at macports.org
Date:     2012-01-15 18:02:01 -0800 (Sun, 15 Jan 2012)
Log Message:
-----------
cregistry: If ROLLBACK fails with SQLITE_BUSY, it will always do so

See http://www.sqlite.org/lang_transaction.html, section
"The ROLLBACK will fail with an error code SQLITE_BUSY ..."
Since MacPorts is single-threaded, nobody can/will finalize the pending queries,
causing this to become an endless loop, if rollback fails.

Also finalize another query early so we have no open queries during updating the
database.

Modified Paths:
--------------
    trunk/base/src/cregistry/registry.c

Modified: trunk/base/src/cregistry/registry.c
===================================================================
--- trunk/base/src/cregistry/registry.c	2012-01-16 01:56:13 UTC (rev 88982)
+++ trunk/base/src/cregistry/registry.c	2012-01-16 02:02:01 UTC (rev 88983)
@@ -230,6 +230,9 @@
                 }
             } while (r == SQLITE_BUSY);
 
+            sqlite3_finalize(stmt);
+            stmt = NULL;
+
             if (result) {
                 result &= update_db(reg->db, errPtr);
             }
@@ -372,7 +375,7 @@
 /**
  * Helper function for `reg_commit` and `reg_rollback`.
  */
-static int reg_end(reg_registry* reg, const char* query, reg_error* errPtr) {
+static int reg_end(reg_registry* reg, const char* query, reg_error* errPtr, int is_rollback) {
     if (!(reg->status & reg_transacting)) {
         reg_throw(errPtr, REG_MISUSE, "couldn't end transaction because no "
                 "transaction is open");
@@ -384,7 +387,7 @@
             if (r == SQLITE_OK) {
                 return 1;
             }
-        } while (r == SQLITE_BUSY);
+        } while (r == SQLITE_BUSY && !is_rollback);
         reg_sqlite_error(reg->db, errPtr, NULL);
         return 0;
     }
@@ -399,7 +402,7 @@
  * @return             true if success; false if failure
  */
 int reg_commit(reg_registry* reg, reg_error* errPtr) {
-    if (reg_end(reg, "COMMIT", errPtr)) {
+    if (reg_end(reg, "COMMIT", errPtr, 0)) {
         reg->status &= ~(reg_transacting | reg_can_write);
         return 1;
     } else {
@@ -416,7 +419,7 @@
  * @return             true if success; false if failure
  */
 int reg_rollback(reg_registry* reg, reg_error* errPtr) {
-    if (reg_end(reg, "ROLLBACK", errPtr)) {
+    if (reg_end(reg, "ROLLBACK", errPtr, 1)) {
         reg->status &= ~(reg_transacting | reg_can_write);
         return 1;
     } else {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macports-changes/attachments/20120115/7b698586/attachment.html>


More information about the macports-changes mailing list