diff options
author | Christian Grothoff <christian@grothoff.org> | 2016-11-17 15:53:16 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2016-11-17 15:53:16 +0100 |
commit | e140ca9dcef9bd86f9c9214872107693ef8c441c (patch) | |
tree | 170cd7378b25cdcc7e3452f0b6953c1f1551550d /src/exchange/taler-exchange-httpd_db.c | |
parent | bb7c58921eb56d464ed2b8a3a6fbbed9c82919d8 (diff) | |
download | exchange-e140ca9dcef9bd86f9c9214872107693ef8c441c.tar.gz exchange-e140ca9dcef9bd86f9c9214872107693ef8c441c.tar.bz2 exchange-e140ca9dcef9bd86f9c9214872107693ef8c441c.zip |
handle more nicely the case that concurrent withdraws have changed history, causing us to see a different balance just before the commit; in this case, just retry the transaction; this should fix #4794
Diffstat (limited to 'src/exchange/taler-exchange-httpd_db.c')
-rw-r--r-- | src/exchange/taler-exchange-httpd_db.c | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/src/exchange/taler-exchange-httpd_db.c b/src/exchange/taler-exchange-httpd_db.c index 848d28822..2c6e90656 100644 --- a/src/exchange/taler-exchange-httpd_db.c +++ b/src/exchange/taler-exchange-httpd_db.c @@ -92,6 +92,27 @@ transaction_start_label: /* we will use goto for retries */ \ /** + * Code to include to retry a transaction, must only be used in between + * #START_TRANSACTION and #COMMIT_TRANSACTION. + * + * @param session session handle + * @param connection connection handle + */ +#define RETRY_TRANSACTION(session,connection) \ + do { \ + TEH_plugin->rollback (TEH_plugin->cls, \ + session); \ + if (transaction_retries++ <= MAX_TRANSACTION_COMMIT_RETRIES) \ + goto transaction_start_label; \ + TALER_LOG_WARNING ("Transaction commit failed %u times in %s\n", \ + transaction_retries, \ + __FUNCTION__); \ + return TEH_RESPONSE_reply_commit_error (connection, \ + TALER_EC_DB_COMMIT_FAILED_ON_RETRY); \ + } while (0) + + +/** * Calculate the total value of all transactions performed. * Stores @a off plus the cost of all transactions in @a tl * in @a ret. @@ -647,6 +668,7 @@ execute_reserve_withdraw_transaction (struct MHD_Connection *connection, struct TALER_Amount value; struct TALER_Amount fee_withdraw; int res; + int ret; /* Check if balance is sufficient */ START_TRANSACTION (session, connection); @@ -794,10 +816,10 @@ execute_reserve_withdraw_transaction (struct MHD_Connection *connection, collectable.reserve_pub = *reserve; collectable.h_coin_envelope = *h_blind; collectable.reserve_sig = *signature; - if (GNUNET_OK != - TEH_plugin->insert_withdraw_info (TEH_plugin->cls, - session, - &collectable)) + ret = TEH_plugin->insert_withdraw_info (TEH_plugin->cls, + session, + &collectable); + if (GNUNET_SYSERR == ret) { GNUNET_break (0); TEH_plugin->rollback (TEH_plugin->cls, @@ -805,6 +827,8 @@ execute_reserve_withdraw_transaction (struct MHD_Connection *connection, return TEH_RESPONSE_reply_internal_db_error (connection, TALER_EC_WITHDRAW_DB_STORE_ERROR); } + if (GNUNET_NO == ret) + RETRY_TRANSACTION(session, connection); COMMIT_TRANSACTION (session, connection); return TEH_RESPONSE_reply_reserve_withdraw_success (connection, |