changeset 1941:9f3597979e98

Tweaking handling of database transactions
author Adam Chlipala <adam@chlipala.net>
date Wed, 25 Dec 2013 13:11:43 -0500
parents 1484ba362062
children a671e5258a2c
files src/c/cgi.c src/c/fastcgi.c src/c/http.c src/c/urweb.c
diffstat 4 files changed, 21 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/c/cgi.c	Wed Dec 25 12:02:42 2013 -0500
+++ b/src/c/cgi.c	Wed Dec 25 13:11:43 2013 -0500
@@ -134,10 +134,11 @@
 }
 
 void uw_do_expunge(uw_context ctx, uw_Basis_client cli, void *data) {
-  do {
-    uw_ensure_transaction(ctx);
-    uw_get_app(ctx)->expunger(ctx, cli);
-  } while (uw_commit(ctx) && (uw_rollback(ctx, 1), 1));
+  uw_ensure_transaction(ctx);
+  uw_get_app(ctx)->expunger(ctx, cli);
+
+  if (uw_commit(ctx))
+    uw_error(ctx, UNLIMITED_RETRY, "Rerunning expunge transaction");
 }
 
 void uw_post_expunge(uw_context ctx, void *data) {
--- a/src/c/fastcgi.c	Wed Dec 25 12:02:42 2013 -0500
+++ b/src/c/fastcgi.c	Wed Dec 25 13:11:43 2013 -0500
@@ -632,10 +632,11 @@
 }
 
 void uw_do_expunge(uw_context ctx, uw_Basis_client cli, void *data) {
-  do {
-    uw_ensure_transaction(ctx);
-    uw_get_app(ctx)->expunger(ctx, cli);
-  } while (uw_commit(ctx) && (uw_rollback(ctx, 1), 1));
+  uw_ensure_transaction(ctx);
+  uw_get_app(ctx)->expunger(ctx, cli);
+
+  if (uw_commit(ctx))
+    uw_error(ctx, UNLIMITED_RETRY, "Rerunning expunge transaction");
 }
 
 void uw_post_expunge(uw_context ctx, void *data) {
--- a/src/c/http.c	Wed Dec 25 12:02:42 2013 -0500
+++ b/src/c/http.c	Wed Dec 25 13:11:43 2013 -0500
@@ -447,10 +447,11 @@
 }
 
 void uw_do_expunge(uw_context ctx, uw_Basis_client cli, void *data) {
-  do {
-    uw_ensure_transaction(ctx);
-    uw_get_app(ctx)->expunger(ctx, cli);
-  } while (uw_commit(ctx) && (uw_rollback(ctx, 1), 1));
+  uw_ensure_transaction(ctx);
+  uw_get_app(ctx)->expunger(ctx, cli);
+
+  if (uw_commit(ctx))
+    uw_error(ctx, UNLIMITED_RETRY, "Rerunning expunge transaction");
 }
 
 void uw_post_expunge(uw_context ctx, void *data) {
--- a/src/c/urweb.c	Wed Dec 25 12:02:42 2013 -0500
+++ b/src/c/urweb.c	Wed Dec 25 13:11:43 2013 -0500
@@ -3225,7 +3225,11 @@
     if (ctx->transactionals[i].free)
       ctx->transactionals[i].free(ctx->transactionals[i].data, will_retry);
 
-  return (ctx->app && ctx->transaction_started) ? ctx->app->db_rollback(ctx) : 0;
+  if (ctx->app && ctx->transaction_started) {
+    ctx->transaction_started = 0;
+    return ctx->app->db_rollback(ctx);
+  } else
+    return 0;
 }
 
 static const char begin_xhtml[] = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">";
@@ -3461,8 +3465,8 @@
         prev->next = next;
       else
         clients_used = next;
-      uw_reset(ctx);
       while (fk == UNLIMITED_RETRY) {
+        uw_reset(ctx);
         fk = uw_expunge(ctx, c->id, c->data);
         if (fk == UNLIMITED_RETRY)
           printf("Unlimited retry during expunge: %s\n", uw_error_message(ctx));