From e77ccd03906bd2db068136bb383976f714b3289e Mon Sep 17 00:00:00 2001 From: Marcello Stanisci Date: Wed, 15 Jan 2020 12:34:54 +0100 Subject: Preflight checks: put preflight check inside exchangedb start() function, and provide a preflight method for auditordb. --- src/exchangedb/plugin_exchangedb_postgres.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'src/exchangedb/plugin_exchangedb_postgres.c') diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index e4caec2d5..a657b405b 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -78,7 +78,7 @@ /** - * Handle for a database session (per-thread, for transactions). + * Handler for a database session (per-thread, for transactions). */ struct TALER_EXCHANGEDB_Session { @@ -1711,6 +1711,17 @@ postgres_get_session (void *cls) return session; } +/** + * Do a pre-flight check that we are not in an uncommitted transaction. + * If we are, try to commit the previous transaction and output a warning. + * Does not return anything, as we will continue regardless of the outcome. + * + * @param cls the `struct PostgresClosure` with the plugin-specific state + * @param session the database connection + */ +static void +postgres_preflight (void *cls, + struct TALER_EXCHANGEDB_Session *session); /** * Start a transaction. @@ -1731,6 +1742,9 @@ postgres_start (void *cls, GNUNET_PQ_EXECUTE_STATEMENT_END }; + postgres_preflight (cls, + session); + (void) cls; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting transaction on %p\n", @@ -1813,7 +1827,7 @@ postgres_preflight (void *cls, struct TALER_EXCHANGEDB_Session *session) { struct GNUNET_PQ_ExecuteStatement es[] = { - GNUNET_PQ_make_execute ("COMMIT"), + GNUNET_PQ_make_execute ("ROLLBACK"), GNUNET_PQ_EXECUTE_STATEMENT_END }; -- cgit v1.2.3