From cad64767d9fda2c18106f25ef101c2eb5fce15a1 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 11 Jun 2017 01:59:09 +0200 Subject: match GNUnet API rename, work on #5010 --- src/exchange/taler-exchange-aggregator.c | 110 ++++++++++++++++---------- src/exchange/taler-exchange-httpd_db.c | 6 +- src/exchange/taler-exchange-httpd_keystate.c | 40 ++++++---- src/exchange/test_taler_exchange_aggregator.c | 4 +- 4 files changed, 98 insertions(+), 62 deletions(-) (limited to 'src/exchange') diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c index f4573aaf8..d658398ae 100644 --- a/src/exchange/taler-exchange-aggregator.c +++ b/src/exchange/taler-exchange-aggregator.c @@ -732,6 +732,29 @@ static void run_aggregation (void *cls); +/** + * Perform a database commit. If it fails, print a warning. + * + * @param session session to perform the commit for. + * @return status of commit + */ +static enum GNUNET_DB_QueryStatus +commit_or_warn (struct TALER_EXCHANGEDB_Session *session) +{ + enum GNUNET_DB_QueryStatus qs; + + qs = db_plugin->commit (db_plugin->cls, + session); + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + return qs; + GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs) + ? GNUNET_ERROR_TYPE_INFO + : GNUNET_ERROR_TYPE_ERROR, + "Failed to commit database transaction!\n"); + return qs; +} + + /** * Function to be called with the prepared transfer data * when closing a reserve. @@ -782,13 +805,7 @@ prepare_close_cb (void *cls, } /* finally commit */ - if (GNUNET_OK != - db_plugin->commit (db_plugin->cls, - ctc->session)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to commit database transaction!\n"); - } + (void) commit_or_warn (ctc->session); GNUNET_free (ctc->type); GNUNET_free (ctc); ctc = NULL; @@ -948,13 +965,7 @@ expired_reserve_cb (void *cls, return GNUNET_SYSERR; } /* Reserve balance was almost zero; just commit */ - if (GNUNET_OK != - db_plugin->commit (db_plugin->cls, - session)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to commit database transaction!\n"); - } + (void) commit_or_warn (session); task = GNUNET_SCHEDULER_add_now (&run_reserve_closures, NULL); return GNUNET_SYSERR; @@ -1191,13 +1202,7 @@ run_aggregation (void *cls) au->additional_rows[i])) ret = GNUNET_SYSERR; /* commit */ - if (GNUNET_OK != - db_plugin->commit (db_plugin->cls, - session)) - { - GNUNET_log (GNUNET_ERROR_TYPE_WARNING, - "Failed to commit database transaction!\n"); - } + (void) commit_or_warn (session); GNUNET_free_non_null (au->additional_rows); if (NULL != au->wire) json_decref (au->wire); @@ -1336,6 +1341,8 @@ prepare_cb (void *cls, au = NULL; return; } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Stored wire transfer out instructions\n"); if (NULL != au->wire) { json_decref (au->wire); @@ -1346,22 +1353,31 @@ prepare_cb (void *cls, /* Now we can finally commit the overall transaction, as we are again consistent if all of this passes. */ - if (GNUNET_OK != - db_plugin->commit (db_plugin->cls, - session)) + switch (commit_or_warn (session)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Failed to commit database transaction!\n"); + case GNUNET_DB_STATUS_SOFT_ERROR: /* try again */ task = GNUNET_SCHEDULER_add_now (&run_aggregation, NULL); return; + case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); + global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Preparation complete, switching to transfer mode\n"); + /* run alternative task: actually do wire transfer! */ + task = GNUNET_SCHEDULER_add_now (&run_transfers, + NULL); + return; + default: + GNUNET_break (0); + global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Preparation complete, switching to transfer mode\n"); - /* run alternative task: actually do wire transfer! */ - task = GNUNET_SCHEDULER_add_now (&run_transfers, - NULL); } @@ -1411,24 +1427,32 @@ wire_confirm_cb (void *cls, } GNUNET_free (wpd); wpd = NULL; - if (GNUNET_OK != - db_plugin->commit (db_plugin->cls, - session)) + switch (commit_or_warn (session)) { - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Failed to commit database transaction!\n"); + case GNUNET_DB_STATUS_SOFT_ERROR: /* try again */ task = GNUNET_SCHEDULER_add_now (&run_aggregation, NULL); return; + case GNUNET_DB_STATUS_HARD_ERROR: + GNUNET_break (0); + global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; + case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Wire transfer complete\n"); + /* continue with #run_transfers(), just to guard + against the unlikely case that there are more. */ + task = GNUNET_SCHEDULER_add_now (&run_transfers, + NULL); + return; + default: + GNUNET_break (0); + global_ret = GNUNET_SYSERR; + GNUNET_SCHEDULER_shutdown (); + return; } - GNUNET_log (GNUNET_ERROR_TYPE_INFO, - "Wire transfer complete\n"); - /* continue with #run_transfers(), just to guard - against the unlikely case that there are more. */ - task = GNUNET_SCHEDULER_add_now (&run_transfers, - NULL); - } diff --git a/src/exchange/taler-exchange-httpd_db.c b/src/exchange/taler-exchange-httpd_db.c index 51e1ef50e..71f82e9d5 100644 --- a/src/exchange/taler-exchange-httpd_db.c +++ b/src/exchange/taler-exchange-httpd_db.c @@ -46,7 +46,7 @@ #define START_TRANSACTION(session,connection) \ { /* start new scope, will be ended by COMMIT_TRANSACTION() */\ unsigned int transaction_retries = 0; \ - int transaction_commit_result; \ + enum GNUNET_DB_QueryStatus transaction_commit_result; \ transaction_start_label: /* we will use goto for retries */ \ if (GNUNET_OK != \ TEH_plugin->start (TEH_plugin->cls, \ @@ -71,13 +71,13 @@ transaction_start_label: /* we will use goto for retries */ \ transaction_commit_result = \ TEH_plugin->commit (TEH_plugin->cls, \ session); \ - if (GNUNET_SYSERR == transaction_commit_result) \ + if (GNUNET_DB_STATUS_HARD_ERROR == transaction_commit_result) \ { \ TALER_LOG_WARNING ("Transaction commit failed in %s\n", __FUNCTION__); \ return TEH_RESPONSE_reply_commit_error (connection, \ TALER_EC_DB_COMMIT_FAILED_HARD); \ } \ - if (GNUNET_NO == transaction_commit_result) \ + if (GNUNET_DB_STATUS_SOFT_ERROR == transaction_commit_result) \ { \ TALER_LOG_WARNING ("Transaction commit failed in %s\n", __FUNCTION__); \ if (transaction_retries++ <= MAX_TRANSACTION_COMMIT_RETRIES) \ diff --git a/src/exchange/taler-exchange-httpd_keystate.c b/src/exchange/taler-exchange-httpd_keystate.c index 3f81b2e33..6fc55a0b0 100644 --- a/src/exchange/taler-exchange-httpd_keystate.c +++ b/src/exchange/taler-exchange-httpd_keystate.c @@ -331,7 +331,9 @@ reload_keys_denom_iter (void *cls, struct GNUNET_TIME_Absolute expire_deposit; struct GNUNET_HashCode denom_key_hash; struct TALER_EXCHANGEDB_Session *session; + unsigned int thresh; int res; + enum GNUNET_DB_QueryStatus qs; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loading denomination key `%s'\n", @@ -361,8 +363,6 @@ reload_keys_denom_iter (void *cls, if (NULL != revocation_master_sig) { - unsigned int thresh = 0; - GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Adding denomination key `%s' to revokation set\n", alias); @@ -373,11 +373,13 @@ reload_keys_denom_iter (void *cls, /* Try to insert DKI into DB until we succeed; note that if the DB failure is persistent, we need to die, as we cannot continue without the DKI being in the DB). */ - res = GNUNET_SYSERR; - while (GNUNET_OK != res) + thresh = 0; + qs = GNUNET_DB_STATUS_SOFT_ERROR; + while (0 > qs) { thresh++; - if (thresh > 16) + if ( (thresh > 16) || + (GNUNET_DB_STATUS_HARD_ERROR == qs) ) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Giving up, this is fatal. Committing suicide via SIGTERM.\n"); @@ -409,8 +411,8 @@ reload_keys_denom_iter (void *cls, session); break; /* already in is also OK! */ } - res = TEH_plugin->commit (TEH_plugin->cls, - session); + qs = TEH_plugin->commit (TEH_plugin->cls, + session); } GNUNET_assert (0 == json_array_append_new (ctx->payback_array, @@ -440,12 +442,22 @@ reload_keys_denom_iter (void *cls, if (NULL == session) return GNUNET_SYSERR; /* Try to insert DKI into DB until we succeed; note that if the DB - failure is persistent, this code may loop forever (as there is no - sane alternative, we cannot continue without the DKI being in the - DB). */ - res = GNUNET_SYSERR; - while (GNUNET_OK != res) + failure is persistent, we die, as we cannot continue without the + DKI being in the DB). */ + qs = GNUNET_DB_STATUS_SOFT_ERROR; + thresh = 0; + while (0 > qs) { + thresh++; + if ( (thresh > 16) || + (GNUNET_DB_STATUS_HARD_ERROR == qs) ) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Giving up, this is fatal. Committing suicide via SIGTERM.\n"); + handle_signal (SIGTERM); + return GNUNET_SYSERR; + } + res = TEH_plugin->start (TEH_plugin->cls, session); if (GNUNET_OK != res) @@ -485,8 +497,8 @@ reload_keys_denom_iter (void *cls, session); continue; } - res = TEH_plugin->commit (TEH_plugin->cls, - session); + qs = TEH_plugin->commit (TEH_plugin->cls, + session); /* If commit succeeded, we're done, otherwise we retry; this time without logging, as theroetically commits can fail in a transactional DB due to concurrent activities that diff --git a/src/exchange/test_taler_exchange_aggregator.c b/src/exchange/test_taler_exchange_aggregator.c index 57cb9d3c7..6eaa09320 100644 --- a/src/exchange/test_taler_exchange_aggregator.c +++ b/src/exchange/test_taler_exchange_aggregator.c @@ -450,7 +450,7 @@ do_deposit (struct Command *cmd) plugin->insert_deposit (plugin->cls, session, &deposit)) || - (GNUNET_OK != + (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != plugin->commit (plugin->cls, session)) ) ret = GNUNET_SYSERR; @@ -1148,7 +1148,7 @@ run (void *cls) session, &dpk, &issue)) || - (GNUNET_OK != + (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != plugin->commit (plugin->cls, session)) ) { -- cgit v1.2.3