From 1ee55ea838a2b98b54a28a5f6b426496e2e36b89 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sat, 11 Aug 2018 10:55:50 +0200 Subject: make wirewatch properly handle (soft) failed transations --- src/exchange/taler-exchange-wirewatch.c | 56 +++++++++++++++++++++++++-------- 1 file changed, 43 insertions(+), 13 deletions(-) (limited to 'src/exchange') diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c index 9de059782..bfdf0529a 100644 --- a/src/exchange/taler-exchange-wirewatch.c +++ b/src/exchange/taler-exchange-wirewatch.c @@ -139,6 +139,17 @@ static void *last_row_off; */ static size_t last_row_off_size; +/** + * Latest row offset seen in this transaction, becomes + * the new #last_row_off upon commit. + */ +static void *latest_row_off; + +/** + * Number of bytes in #latest_row_off. + */ +static size_t latest_row_off_size; + /** * Should we delay the next request to the wire plugin a bit? */ @@ -389,6 +400,28 @@ history_cb (void *cls, "End of list. Committing progress!\n"); qs = db_plugin->commit (db_plugin->cls, session); + if (GNUNET_DB_STATUS_SOFT_ERROR == qs) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got DB soft error for commit\n"); + /* do we need to rollback explicitly on commit failure!? */ + db_plugin->rollback (db_plugin->cls, + session); + /* try again */ + GNUNET_assert (NULL == task); + task = GNUNET_SCHEDULER_add_now (&find_transfers, + NULL); + return GNUNET_OK; /* will be ignored anyway */ + } + if (0 < qs) + { + /* transaction success, update #last_row_off */ + GNUNET_free_non_null (last_row_off); + last_row_off = latest_row_off; + last_row_off_size = latest_row_off_size; + latest_row_off = NULL; + latest_row_off_size = 0; + } GNUNET_break (0 <= qs); if ( (GNUNET_YES == delay) && (test_mode) && @@ -403,9 +436,6 @@ history_cb (void *cls, { wa_pos->delayed_until = GNUNET_TIME_relative_to_absolute (DELAY); - GNUNET_free_non_null (last_row_off); - last_row_off = NULL; - last_row_off_size = 0; wa_pos = wa_pos->next; if (NULL == wa_pos) wa_pos = wa_head; @@ -425,13 +455,13 @@ history_cb (void *cls, TALER_amount2s (&details->amount), details->wtid_s); GNUNET_break (0 != row_off_size); - if (last_row_off_size != row_off_size) + if (latest_row_off_size != row_off_size) { - GNUNET_free_non_null (last_row_off); - last_row_off = GNUNET_malloc (row_off_size); - last_row_off_size = row_off_size; + GNUNET_free_non_null (latest_row_off); + latest_row_off = GNUNET_malloc (row_off_size); + latest_row_off_size = row_off_size; } - memcpy (last_row_off, + memcpy (latest_row_off, row_off, row_off_size); rtc = GNUNET_new (struct RejectContext); @@ -492,13 +522,13 @@ history_cb (void *cls, return GNUNET_SYSERR; } - if (last_row_off_size != row_off_size) + if (latest_row_off_size != row_off_size) { - GNUNET_free_non_null (last_row_off); - last_row_off = GNUNET_malloc (row_off_size); - last_row_off_size = row_off_size; + GNUNET_free_non_null (latest_row_off); + latest_row_off = GNUNET_malloc (row_off_size); + latest_row_off_size = row_off_size; } - memcpy (last_row_off, + memcpy (latest_row_off, row_off, row_off_size); return GNUNET_OK; -- cgit v1.2.3