comparison src/c/urweb.c @ 2178:c76a9712334c

Database-server reconnection for MySQL
author Adam Chlipala <adam@chlipala.net>
date Sat, 17 Oct 2015 11:31:22 -0400
parents 00cf8214c2e3
children d87d72b6e299 1e3ba868f8bf
comparison
equal deleted inserted replaced
2177:00cf8214c2e3 2178:c76a9712334c
811 uw_error(ctx, FATAL, "Error reopening database connection"); 811 uw_error(ctx, FATAL, "Error reopening database connection");
812 } 812 }
813 813
814 void uw_try_reconnecting_and_restarting(uw_context ctx) { 814 void uw_try_reconnecting_and_restarting(uw_context ctx) {
815 uw_try_reconnecting(ctx); 815 uw_try_reconnecting(ctx);
816 uw_error(ctx, UNLIMITED_RETRY, "Restarting transaction after fixing database connection"); 816 uw_error(ctx, BOUNDED_RETRY, "Restarting transaction after fixing database connection");
817 } 817 }
818 818
819 void uw_ensure_transaction(uw_context ctx) { 819 void uw_ensure_transaction(uw_context ctx) {
820 if (!ctx->transaction_started && !ctx->at_most_one_query) { 820 if (!ctx->transaction_started && !ctx->at_most_one_query) {
821 if (!ctx->db || ctx->app->db_begin(ctx, ctx->could_write_db)) { 821 if (!ctx->db || ctx->app->db_begin(ctx, ctx->could_write_db)) {
824 if (ctx->app->db_begin(ctx, ctx->could_write_db)) 824 if (ctx->app->db_begin(ctx, ctx->could_write_db))
825 uw_error(ctx, FATAL, "Error running SQL BEGIN"); 825 uw_error(ctx, FATAL, "Error running SQL BEGIN");
826 } 826 }
827 827
828 ctx->transaction_started = 1; 828 ctx->transaction_started = 1;
829 } 829 } else if (ctx->at_most_one_query && !ctx->db)
830 uw_try_reconnecting(ctx);
830 } 831 }
831 832
832 uw_Basis_client uw_Basis_self(uw_context ctx) { 833 uw_Basis_client uw_Basis_self(uw_context ctx) {
833 if (ctx->client == NULL) 834 if (ctx->client == NULL)
834 uw_error(ctx, FATAL, "Call to Basis.self() from page that has only server-side code"); 835 uw_error(ctx, FATAL, "Call to Basis.self() from page that has only server-side code");