Preflight checks:

put preflight check inside exchangedb start()
function, and provide a preflight method for
auditordb.
This commit is contained in:
Marcello Stanisci 2020-01-15 12:34:54 +01:00
parent 4547bfb318
commit e77ccd0390
No known key found for this signature in database
GPG Key ID: 8D526861953F4C0F
4 changed files with 59 additions and 5 deletions

View File

@ -372,8 +372,8 @@ handle_mhd_request (void *cls,
{ "/version", MHD_HTTP_METHOD_GET, "application/json", { "/version", MHD_HTTP_METHOD_GET, "application/json",
NULL, 0, NULL, 0,
&handle_version, MHD_HTTP_OK }, &handle_version, MHD_HTTP_OK },
/* Landing page, for now tells humans to go away (FIXME: replace /* Landing page, for now tells humans to go away
with auditor's welcome page!) */ * (NOTE: ideally, the reverse proxy will respond with a nicer page) */
{ "/", MHD_HTTP_METHOD_GET, "text/plain", { "/", MHD_HTTP_METHOD_GET, "text/plain",
"Hello, I'm the Taler auditor. This HTTP server is not for humans.\n", 0, "Hello, I'm the Taler auditor. This HTTP server is not for humans.\n", 0,
&TAH_MHD_handler_static_response, MHD_HTTP_OK }, &TAH_MHD_handler_static_response, MHD_HTTP_OK },

View File

@ -70,7 +70,6 @@ TAH_DB_run_transaction (struct MHD_Connection *connection,
"failed to establish session with database"); "failed to establish session with database");
return GNUNET_SYSERR; return GNUNET_SYSERR;
} }
// TAH_plugin->preflight (TAH_plugin->cls, session); // FIXME: needed?
for (unsigned int retries = 0; retries < MAX_TRANSACTION_COMMIT_RETRIES; for (unsigned int retries = 0; retries < MAX_TRANSACTION_COMMIT_RETRIES;
retries++) retries++)
{ {

View File

@ -62,6 +62,8 @@ struct TALER_AUDITORDB_Session
* Postgres connection handle. * Postgres connection handle.
*/ */
struct GNUNET_PQ_Context *conn; struct GNUNET_PQ_Context *conn;
const char *transaction_name;
}; };
@ -1012,6 +1014,43 @@ postgres_get_session (void *cls)
return session; 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_AUDITORDB_Session *session)
{
struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_execute ("ROLLBACK"),
GNUNET_PQ_EXECUTE_STATEMENT_END
};
(void) cls;
if (NULL == session->transaction_name)
return; /* all good */
if (GNUNET_OK ==
GNUNET_PQ_exec_statements (session->conn,
es))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"BUG: Preflight check committed transaction `%s'!\n",
session->transaction_name);
}
else
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"BUG: Preflight check failed to commit transaction `%s'!\n",
session->transaction_name);
}
session->transaction_name = NULL;
}
/** /**
* Start a transaction. * Start a transaction.
@ -1029,6 +1068,8 @@ postgres_start (void *cls,
GNUNET_PQ_EXECUTE_STATEMENT_END GNUNET_PQ_EXECUTE_STATEMENT_END
}; };
postgres_preflight (cls,
session);
(void) cls; (void) cls;
if (GNUNET_OK != if (GNUNET_OK !=
GNUNET_PQ_exec_statements (session->conn, GNUNET_PQ_exec_statements (session->conn,

View File

@ -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 struct TALER_EXCHANGEDB_Session
{ {
@ -1711,6 +1711,17 @@ postgres_get_session (void *cls)
return session; 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. * Start a transaction.
@ -1731,6 +1742,9 @@ postgres_start (void *cls,
GNUNET_PQ_EXECUTE_STATEMENT_END GNUNET_PQ_EXECUTE_STATEMENT_END
}; };
postgres_preflight (cls,
session);
(void) cls; (void) cls;
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Starting transaction on %p\n", "Starting transaction on %p\n",
@ -1813,7 +1827,7 @@ postgres_preflight (void *cls,
struct TALER_EXCHANGEDB_Session *session) struct TALER_EXCHANGEDB_Session *session)
{ {
struct GNUNET_PQ_ExecuteStatement es[] = { struct GNUNET_PQ_ExecuteStatement es[] = {
GNUNET_PQ_make_execute ("COMMIT"), GNUNET_PQ_make_execute ("ROLLBACK"),
GNUNET_PQ_EXECUTE_STATEMENT_END GNUNET_PQ_EXECUTE_STATEMENT_END
}; };