summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Adam Chlipala <adam@chlipala.net>2010-12-04 11:15:20 -0500
committerGravatar Adam Chlipala <adam@chlipala.net>2010-12-04 11:15:20 -0500
commitae6417be71abf3da25f7708d3ead977a03417e31 (patch)
treec60abe4025d03517d3a685076e32aa3fc48093a0 /src
parent686b727ebba1749f1936cfc39a7b6b1f1f6ebc0a (diff)
New argument to transactional free functions, to specify whether we are about to retry
Diffstat (limited to 'src')
-rw-r--r--src/c/request.c16
-rw-r--r--src/c/urweb.c17
2 files changed, 17 insertions, 16 deletions
diff --git a/src/c/request.c b/src/c/request.c
index 52006e85..ae46326d 100644
--- a/src/c/request.c
+++ b/src/c/request.c
@@ -19,8 +19,8 @@
void *memmem(const void *b1, size_t len1, const void *b2, size_t len2);
-static int try_rollback(uw_context ctx, void *logger_data, uw_logger log_error) {
- int r = uw_rollback(ctx);
+static int try_rollback(uw_context ctx, int will_retry, void *logger_data, uw_logger log_error) {
+ int r = uw_rollback(ctx, will_retry);
if (r) {
log_error(logger_data, "Error running SQL ROLLBACK\n");
@@ -102,13 +102,13 @@ void uw_request_init(uw_app *app, void *logger_data, uw_logger log_error, uw_log
for (fk = uw_initialize(ctx); fk == UNLIMITED_RETRY; fk = uw_initialize(ctx)) {
log_debug(logger_data, "Unlimited retry during init: %s\n", uw_error_message(ctx));
- uw_rollback(ctx);
+ uw_rollback(ctx, 1);
uw_reset(ctx);
}
if (fk != SUCCESS) {
log_error(logger_data, "Failed to initialize database! %s\n", uw_error_message(ctx));
- uw_rollback(ctx);
+ uw_rollback(ctx, 0);
exit(1);
}
@@ -403,7 +403,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx,
else {
log_error(logger_data, "Fatal error (out of retries): %s\n", uw_error_message(ctx));
- try_rollback(ctx, logger_data, log_error);
+ try_rollback(ctx, 0, logger_data, log_error);
if (!had_error && uw_get_app(ctx)->on_error) {
had_error = 1;
@@ -424,7 +424,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx,
else if (fk == FATAL) {
log_error(logger_data, "Fatal error: %s\n", uw_error_message(ctx));
- try_rollback(ctx, logger_data, log_error);
+ try_rollback(ctx, 0, logger_data, log_error);
if (uw_get_app(ctx)->on_error && !had_error) {
had_error = 1;
@@ -443,7 +443,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx,
} else {
log_error(logger_data, "Unknown uw_handle return code!\n");
- try_rollback(ctx, logger_data, log_error);
+ try_rollback(ctx, 0, logger_data, log_error);
if (uw_get_app(ctx)->on_error && !had_error) {
had_error = 1;
@@ -458,7 +458,7 @@ request_result uw_request(uw_request_context rc, uw_context ctx,
}
}
- if (try_rollback(ctx, logger_data, log_error))
+ if (try_rollback(ctx, 1, logger_data, log_error))
return FAILED;
uw_reset_keep_request(ctx);
diff --git a/src/c/urweb.c b/src/c/urweb.c
index bdaa877f..91c6f6b3 100644
--- a/src/c/urweb.c
+++ b/src/c/urweb.c
@@ -390,7 +390,8 @@ typedef struct input {
typedef struct {
void *data;
- uw_callback commit, rollback, free;
+ uw_callback commit, rollback;
+ uw_callback_with_retry free;
} transactional;
typedef struct {
@@ -2902,7 +2903,7 @@ uw_unit uw_Basis_send(uw_context ctx, uw_Basis_channel chn, uw_Basis_string msg)
return uw_unit_v;
}
-int uw_rollback(uw_context ctx) {
+int uw_rollback(uw_context ctx, int will_retry) {
int i;
cleanup *cl;
@@ -2920,7 +2921,7 @@ int uw_rollback(uw_context ctx) {
for (i = ctx->used_transactionals-1; i >= 0; --i)
if (ctx->transactionals[i].free)
- ctx->transactionals[i].free(ctx->transactionals[i].data);
+ ctx->transactionals[i].free(ctx->transactionals[i].data, will_retry);
return ctx->app ? ctx->app->db_rollback(ctx) : 0;
}
@@ -2929,7 +2930,7 @@ void uw_commit(uw_context ctx) {
int i;
if (uw_has_error(ctx)) {
- uw_rollback(ctx);
+ uw_rollback(ctx, 0);
return;
}
@@ -2938,7 +2939,7 @@ void uw_commit(uw_context ctx) {
if (ctx->transactionals[i].commit) {
ctx->transactionals[i].commit(ctx->transactionals[i].data);
if (uw_has_error(ctx)) {
- uw_rollback(ctx);
+ uw_rollback(ctx, 0);
return;
}
}
@@ -2948,7 +2949,7 @@ void uw_commit(uw_context ctx) {
if (ctx->transactionals[i].commit) {
ctx->transactionals[i].commit(ctx->transactionals[i].data);
if (uw_has_error(ctx)) {
- uw_rollback(ctx);
+ uw_rollback(ctx, 0);
return;
}
}
@@ -2972,7 +2973,7 @@ void uw_commit(uw_context ctx) {
for (i = ctx->used_transactionals-1; i >= 0; --i)
if (ctx->transactionals[i].free)
- ctx->transactionals[i].free(ctx->transactionals[i].data);
+ ctx->transactionals[i].free(ctx->transactionals[i].data, 0);
// Splice script data into appropriate part of page
if (ctx->returning_indirectly || ctx->script_header[0] == 0) {
@@ -3012,7 +3013,7 @@ void uw_commit(uw_context ctx) {
size_t uw_transactionals_max = SIZE_MAX;
void uw_register_transactional(uw_context ctx, void *data, uw_callback commit, uw_callback rollback,
- uw_callback free) {
+ uw_callback_with_retry free) {
if (ctx->used_transactionals >= ctx->n_transactionals) {
if (ctx->used_transactionals+1 > uw_transactionals_max)
uw_error(ctx, FATAL, "Exceeded limit on number of transactionals");