Mercurial > urweb
comparison src/c/urweb.c @ 1938:d02c1a0d8082
Proper handling of serialization failures during SQL COMMIT
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Mon, 23 Dec 2013 15:59:17 +0000 |
parents | 6745eafff617 |
children | c52365a4ce41 |
comparison
equal
deleted
inserted
replaced
1937:94f9570671f0 | 1938:d02c1a0d8082 |
---|---|
3251 return NULL; | 3251 return NULL; |
3252 | 3252 |
3253 return s; | 3253 return s; |
3254 } | 3254 } |
3255 | 3255 |
3256 void uw_commit(uw_context ctx) { | 3256 int uw_commit(uw_context ctx) { |
3257 int i; | 3257 int i; |
3258 char *sig; | 3258 char *sig; |
3259 | 3259 |
3260 if (uw_has_error(ctx)) { | 3260 if (uw_has_error(ctx)) { |
3261 uw_rollback(ctx, 0); | 3261 uw_rollback(ctx, 0); |
3262 return; | 3262 return 0; |
3263 } | 3263 } |
3264 | 3264 |
3265 for (i = ctx->used_transactionals-1; i >= 0; --i) | 3265 for (i = ctx->used_transactionals-1; i >= 0; --i) |
3266 if (ctx->transactionals[i].rollback != NULL) | 3266 if (ctx->transactionals[i].rollback != NULL) |
3267 if (ctx->transactionals[i].commit) { | 3267 if (ctx->transactionals[i].commit) { |
3268 ctx->transactionals[i].commit(ctx->transactionals[i].data); | 3268 ctx->transactionals[i].commit(ctx->transactionals[i].data); |
3269 if (uw_has_error(ctx)) { | 3269 if (uw_has_error(ctx)) { |
3270 uw_rollback(ctx, 0); | 3270 uw_rollback(ctx, 0); |
3271 return; | 3271 return 0; |
3272 } | 3272 } |
3273 } | 3273 } |
3274 | 3274 |
3275 for (i = ctx->used_transactionals-1; i >= 0; --i) | 3275 for (i = ctx->used_transactionals-1; i >= 0; --i) |
3276 if (ctx->transactionals[i].rollback == NULL) | 3276 if (ctx->transactionals[i].rollback == NULL) |
3277 if (ctx->transactionals[i].commit) { | 3277 if (ctx->transactionals[i].commit) { |
3278 ctx->transactionals[i].commit(ctx->transactionals[i].data); | 3278 ctx->transactionals[i].commit(ctx->transactionals[i].data); |
3279 if (uw_has_error(ctx)) { | 3279 if (uw_has_error(ctx)) { |
3280 uw_rollback(ctx, 0); | 3280 uw_rollback(ctx, 0); |
3281 return; | 3281 return 0; |
3282 } | 3282 } |
3283 } | 3283 } |
3284 | 3284 |
3285 if (ctx->transaction_started && ctx->app->db_commit(ctx)) { | 3285 if (ctx->transaction_started) { |
3286 uw_set_error_message(ctx, "Error running SQL COMMIT"); | 3286 int code =ctx->app->db_commit(ctx); |
3287 return; | 3287 |
3288 if (code) { | |
3289 if (code == -1) { | |
3290 uw_rollback(ctx, 1); | |
3291 return 1; | |
3292 } | |
3293 | |
3294 for (i = ctx->used_transactionals-1; i >= 0; --i) | |
3295 if (ctx->transactionals[i].free) | |
3296 ctx->transactionals[i].free(ctx->transactionals[i].data, 0); | |
3297 | |
3298 uw_set_error_message(ctx, "Error running SQL COMMIT"); | |
3299 return 0; | |
3300 } | |
3288 } | 3301 } |
3289 | 3302 |
3290 for (i = 0; i < ctx->used_deltas; ++i) { | 3303 for (i = 0; i < ctx->used_deltas; ++i) { |
3291 delta *d = &ctx->deltas[i]; | 3304 delta *d = &ctx->deltas[i]; |
3292 client *c = find_client(d->client); | 3305 client *c = find_client(d->client); |
3388 memcpy(sig, realsig, 2*uw_hash_blocksize); | 3401 memcpy(sig, realsig, 2*uw_hash_blocksize); |
3389 sig = find_sig(sig); | 3402 sig = find_sig(sig); |
3390 } while (sig); | 3403 } while (sig); |
3391 } | 3404 } |
3392 } | 3405 } |
3406 | |
3407 return 0; | |
3393 } | 3408 } |
3394 | 3409 |
3395 | 3410 |
3396 size_t uw_transactionals_max = SIZE_MAX; | 3411 size_t uw_transactionals_max = SIZE_MAX; |
3397 | 3412 |