aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-12-09 14:05:23 +0100
committerChristian Grothoff <christian@grothoff.org>2021-12-09 14:05:23 +0100
commita7b4cc97ecfe2452064c8ac2f05b8d7890c8576b (patch)
treedc533e6d26b32d686240dca39f30b0d7f5aba4a7 /src
parentce28d3b8e4aa513336030468cd08e9cb66718273 (diff)
downloadexchange-a7b4cc97ecfe2452064c8ac2f05b8d7890c8576b.tar.xz
minimize idle in transaction from wirewatcher
Diffstat (limited to 'src')
-rw-r--r--src/exchange/taler-exchange-wirewatch.c58
1 files changed, 41 insertions, 17 deletions
diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c
index 6e2cd1ee1..8f69ba7b1 100644
--- a/src/exchange/taler-exchange-wirewatch.c
+++ b/src/exchange/taler-exchange-wirewatch.c
@@ -125,6 +125,11 @@ struct WireAccount
*/
bool delay;
+ /**
+ * Did we start a transaction yet?
+ */
+ bool started_transaction;
+
};
@@ -293,7 +298,7 @@ add_account_cb (void *cls,
*
* @return #GNUNET_OK on success
*/
-static int
+static enum GNUNET_GenericReturnValue
exchange_serve_process_config (void)
{
if (GNUNET_OK !=
@@ -473,7 +478,7 @@ do_commit (struct WireAccount *wa)
* @param json raw JSON response
* @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration
*/
-static int
+static enum GNUNET_GenericReturnValue
history_cb (void *cls,
unsigned int http_status,
enum TALER_ErrorCode ec,
@@ -495,9 +500,13 @@ history_cb (void *cls,
(unsigned int) ec,
http_status);
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "End of list. Committing progress!\n");
- do_commit (wa);
+ if (wa->started_transaction)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "End of list. Committing progress!\n");
+ wa->started_transaction = false;
+ do_commit (wa);
+ }
return GNUNET_OK; /* will be ignored anyway */
}
if (serial_id < wa->latest_row_off)
@@ -507,7 +516,11 @@ history_cb (void *cls,
"Serial ID %llu not monotonic (got %llu before). Failing!\n",
(unsigned long long) serial_id,
(unsigned long long) wa->latest_row_off);
- db_plugin->rollback (db_plugin->cls);
+ if (wa->started_transaction)
+ {
+ wa->started_transaction = false;
+ db_plugin->rollback (db_plugin->cls);
+ }
GNUNET_SCHEDULER_shutdown ();
wa->hh = NULL;
return GNUNET_SYSERR;
@@ -521,10 +534,31 @@ history_cb (void *cls,
(unsigned long long) wa->shard_end);
wa->latest_row_off = serial_id - 1;
wa->delay = false;
- do_commit (wa);
+ if (wa->started_transaction)
+ {
+ wa->started_transaction = false;
+ do_commit (wa);
+ }
+ else
+ GNUNET_break (0); /* how did this happen */
wa->hh = NULL;
return GNUNET_SYSERR;
}
+ if (! wa->started_transaction)
+ {
+ if (GNUNET_OK !=
+ db_plugin->start_read_committed (db_plugin->cls,
+ "wirewatch check for incoming wire transfers"))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Failed to start database transaction!\n");
+ global_ret = EXIT_FAILURE;
+ GNUNET_SCHEDULER_shutdown ();
+ wa->hh = NULL;
+ return GNUNET_SYSERR;
+ }
+ wa->started_transaction = true;
+ }
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Adding wire transfer over %s with (hashed) subject `%s'\n",
TALER_amount2s (&details->amount),
@@ -645,16 +679,6 @@ find_transfers (void *cls)
break;
}
}
- if (GNUNET_OK !=
- db_plugin->start_read_committed (db_plugin->cls,
- "wirewatch check for incoming wire transfers"))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Failed to start database transaction!\n");
- global_ret = EXIT_FAILURE;
- GNUNET_SCHEDULER_shutdown ();
- return;
- }
limit = GNUNET_MIN (wa_pos->batch_size,
wa_pos->shard_end - wa_pos->batch_start);