From 317a70aeb32e9e18f67b1a1be2751ae67f80bd87 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 5 Sep 2021 16:43:56 +0200 Subject: [PATCH] taler-exchange-transfer: ensure batches stay in their range --- src/exchange/taler-exchange-transfer.c | 80 ++++++++++++++++---------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/src/exchange/taler-exchange-transfer.c b/src/exchange/taler-exchange-transfer.c index b93d14600..46093d89c 100644 --- a/src/exchange/taler-exchange-transfer.c +++ b/src/exchange/taler-exchange-transfer.c @@ -325,6 +325,46 @@ static void select_shard (void *cls); +/** + * We are done with the current batch. Commit + * and move on. + */ +static void +batch_done (void) +{ + /* batch done */ + switch (commit_or_warn ()) + { + case GNUNET_DB_STATUS_SOFT_ERROR: + /* try again */ + GNUNET_assert (NULL == task); + task = GNUNET_SCHEDULER_add_now (&run_transfers, + NULL); + return; + case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); + global_ret = EXIT_FAILURE; + GNUNET_SCHEDULER_shutdown (); + return; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + shard->batch_start = shard->batch_end + 1; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Batch complete\n"); + /* continue with #run_transfers(), just to guard + against the unlikely case that there are more. */ + GNUNET_assert (NULL == task); + task = GNUNET_SCHEDULER_add_now (&run_transfers, + NULL); + return; + default: + GNUNET_break (0); + global_ret = EXIT_FAILURE; + GNUNET_SCHEDULER_shutdown (); + return; + } +} + + /** * Function called with the result from the execute step. * On success, we mark the respective wire transfer as finished, @@ -408,36 +448,7 @@ wire_confirm_cb (void *cls, } if (NULL != wpd_head) return; /* wait for other queries to complete */ - /* batch done */ - switch (commit_or_warn ()) - { - case GNUNET_DB_STATUS_SOFT_ERROR: - /* try again */ - GNUNET_assert (NULL == task); - task = GNUNET_SCHEDULER_add_now (&run_transfers, - NULL); - return; - case GNUNET_DB_STATUS_HARD_ERROR: - GNUNET_break (0); - global_ret = EXIT_FAILURE; - GNUNET_SCHEDULER_shutdown (); - return; - case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: - shard->batch_start = shard->batch_end + 1; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Batch complete\n"); - /* continue with #run_transfers(), just to guard - against the unlikely case that there are more. */ - GNUNET_assert (NULL == task); - task = GNUNET_SCHEDULER_add_now (&run_transfers, - NULL); - return; - default: - GNUNET_break (0); - global_ret = EXIT_FAILURE; - GNUNET_SCHEDULER_shutdown (); - return; - } + batch_done (); } @@ -462,6 +473,15 @@ wire_prepare_cb (void *cls, struct WirePrepareData *wpd; (void) cls; + if (rowid >= shard->shard_end) + { + /* skip */ + shard->batch_end = shard->shard_end - 1; + if (NULL != wpd_head) + return; + batch_done (); + return; + } if ( (NULL == wire_method) || (NULL == buf) ) {