# HG changeset patch # User Adam Chlipala # Date 1387995103 18000 # Node ID 9f3597979e98747e4d0261dc0caba7a4c99a22fa # Parent 1484ba36206260ffc65d1857a14dc347c015d782 Tweaking handling of database transactions diff -r 1484ba362062 -r 9f3597979e98 src/c/cgi.c --- 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) { diff -r 1484ba362062 -r 9f3597979e98 src/c/fastcgi.c --- 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) { diff -r 1484ba362062 -r 9f3597979e98 src/c/http.c --- 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) { diff -r 1484ba362062 -r 9f3597979e98 src/c/urweb.c --- 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[] = "\n\n"; @@ -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));