aboutsummaryrefslogtreecommitdiff
path: root/src/exchangedb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2024-11-10 17:22:31 +0100
committerChristian Grothoff <christian@grothoff.org>2024-11-10 17:22:44 +0100
commit9508cb1806608274262f70efee9d43630b81ccd3 (patch)
treea475e295aa36dd165278bd36a2a75d2ff3469512 /src/exchangedb
parent0e68462e9040c2cbb536d0b0f797fa2e7aab064a (diff)
ensure we do not start if the database version is outdated (#9203)
Diffstat (limited to 'src/exchangedb')
-rw-r--r--src/exchangedb/exchangedb_plugin.c12
-rw-r--r--src/exchangedb/perf_deposits_get_ready.c3
-rw-r--r--src/exchangedb/perf_get_link_data.c3
-rw-r--r--src/exchangedb/perf_reserves_in_insert.c3
-rw-r--r--src/exchangedb/perf_select_refunds_by_coin.c3
-rw-r--r--src/exchangedb/pg_create_tables.c4
-rw-r--r--src/exchangedb/pg_preflight.c65
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c70
-rw-r--r--src/exchangedb/test_exchangedb.c3
9 files changed, 89 insertions, 77 deletions
diff --git a/src/exchangedb/exchangedb_plugin.c b/src/exchangedb/exchangedb_plugin.c
index 68a916b4e..747a2ad1b 100644
--- a/src/exchangedb/exchangedb_plugin.c
+++ b/src/exchangedb/exchangedb_plugin.c
@@ -25,7 +25,8 @@
struct TALER_EXCHANGEDB_Plugin *
-TALER_EXCHANGEDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
+TALER_EXCHANGEDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ bool skip_preflight)
{
char *plugin_name;
char *lib_name;
@@ -52,6 +53,15 @@ TALER_EXCHANGEDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
plugin->library_name = lib_name;
else
GNUNET_free (lib_name);
+ if ( (! skip_preflight) &&
+ (GNUNET_OK !=
+ plugin->preflight (plugin->cls)) )
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Database not ready. Try running taler-exchange-dbinit!\n");
+ TALER_EXCHANGEDB_plugin_unload (plugin);
+ return NULL;
+ }
return plugin;
}
diff --git a/src/exchangedb/perf_deposits_get_ready.c b/src/exchangedb/perf_deposits_get_ready.c
index 0018bbbd2..316f45e6c 100644
--- a/src/exchangedb/perf_deposits_get_ready.c
+++ b/src/exchangedb/perf_deposits_get_ready.c
@@ -216,7 +216,8 @@ run (void *cls)
struct TALER_EXCHANGEDB_CoinDepositInformation);
if (NULL ==
- (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg,
+ true)))
{
GNUNET_break (0);
result = 77;
diff --git a/src/exchangedb/perf_get_link_data.c b/src/exchangedb/perf_get_link_data.c
index f2c612e16..4e00d0a0b 100644
--- a/src/exchangedb/perf_get_link_data.c
+++ b/src/exchangedb/perf_get_link_data.c
@@ -225,7 +225,8 @@ run (void *cls)
struct TALER_EXCHANGEDB_Refresh);
if (NULL ==
- (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg,
+ true)))
{
GNUNET_break (0);
result = 77;
diff --git a/src/exchangedb/perf_reserves_in_insert.c b/src/exchangedb/perf_reserves_in_insert.c
index f05c2800f..6e3837fc7 100644
--- a/src/exchangedb/perf_reserves_in_insert.c
+++ b/src/exchangedb/perf_reserves_in_insert.c
@@ -86,7 +86,8 @@ run (void *cls)
unsigned long long sqrs[sizeof (batches) / sizeof(*batches)];
if (NULL ==
- (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg,
+ true)))
{
GNUNET_break (0);
result = 77;
diff --git a/src/exchangedb/perf_select_refunds_by_coin.c b/src/exchangedb/perf_select_refunds_by_coin.c
index cb216109d..fc22652b6 100644
--- a/src/exchangedb/perf_select_refunds_by_coin.c
+++ b/src/exchangedb/perf_select_refunds_by_coin.c
@@ -240,7 +240,8 @@ run (void *cls)
ZR_BLK (&cbc);
if (NULL ==
- (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg,
+ true)))
{
GNUNET_break (0);
result = 77;
diff --git a/src/exchangedb/pg_create_tables.c b/src/exchangedb/pg_create_tables.c
index 8788f0018..03a8db756 100644
--- a/src/exchangedb/pg_create_tables.c
+++ b/src/exchangedb/pg_create_tables.c
@@ -60,6 +60,7 @@ TEH_PG_create_tables (void *cls,
struct GNUNET_PQ_Context *tconn;
tconn = pg->conn;
+ pg->prep_gen++;
pg->conn = conn;
PREPARE (pg,
"create_tables",
@@ -71,7 +72,10 @@ TEH_PG_create_tables (void *cls,
GNUNET_PQ_eval_prepared_non_select (conn,
"create_tables",
params))
+ {
+ GNUNET_break (0);
ret = GNUNET_SYSERR;
+ }
}
GNUNET_PQ_disconnect (conn);
return ret;
diff --git a/src/exchangedb/pg_preflight.c b/src/exchangedb/pg_preflight.c
index c30a9651e..2640b1243 100644
--- a/src/exchangedb/pg_preflight.c
+++ b/src/exchangedb/pg_preflight.c
@@ -27,6 +27,69 @@
#include "plugin_exchangedb_postgres.h"
+/**
+ * Connect to the database if the connection does not exist yet
+ * and check that we are ready to operate.
+ *
+ * @param pg the plugin-specific state
+ * @return #GNUNET_OK on success
+ */
+static enum GNUNET_GenericReturnValue
+internal_setup (struct PostgresClosure *pg)
+{
+ if (NULL == pg->conn)
+ {
+#if AUTO_EXPLAIN
+ /* Enable verbose logging to see where queries do not
+ properly use indices */
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_try_execute ("LOAD 'auto_explain';"),
+ GNUNET_PQ_make_try_execute ("SET auto_explain.log_min_duration=50;"),
+ GNUNET_PQ_make_try_execute ("SET auto_explain.log_timing=TRUE;"),
+ GNUNET_PQ_make_try_execute ("SET auto_explain.log_analyze=TRUE;"),
+ /* https://wiki.postgresql.org/wiki/Serializable suggests to really
+ force the default to 'serializable' if SSI is to be used. */
+ GNUNET_PQ_make_try_execute (
+ "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE;"),
+ GNUNET_PQ_make_try_execute ("SET enable_sort=OFF;"),
+ GNUNET_PQ_make_try_execute ("SET enable_seqscan=OFF;"),
+ GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
+ /* Mergejoin causes issues, see Postgres #18380 */
+ GNUNET_PQ_make_try_execute ("SET enable_mergejoin=OFF;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+#else
+ struct GNUNET_PQ_ExecuteStatement es[] = {
+ GNUNET_PQ_make_try_execute (
+ "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE;"),
+ GNUNET_PQ_make_try_execute ("SET enable_sort=OFF;"),
+ GNUNET_PQ_make_try_execute ("SET enable_seqscan=OFF;"),
+ /* Mergejoin causes issues, see Postgres #18380 */
+ GNUNET_PQ_make_try_execute ("SET enable_mergejoin=OFF;"),
+ GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
+ GNUNET_PQ_EXECUTE_STATEMENT_END
+ };
+#endif
+ struct GNUNET_PQ_Context *db_conn;
+
+ db_conn = GNUNET_PQ_connect_with_cfg2 (pg->cfg,
+ "exchangedb-postgres",
+ "exchange-", /* load_path_suffix */
+ es,
+ NULL /* prepared statements */,
+ GNUNET_PQ_FLAG_CHECK_CURRENT);
+ if (NULL == db_conn)
+ return GNUNET_SYSERR;
+
+ pg->prep_gen++;
+ pg->conn = db_conn;
+ }
+ if (NULL == pg->transaction_name)
+ GNUNET_PQ_reconnect_if_down (pg->conn);
+ return GNUNET_OK;
+}
+
+
enum GNUNET_GenericReturnValue
TEH_PG_preflight (void *cls)
{
@@ -37,7 +100,7 @@ TEH_PG_preflight (void *cls)
};
if (GNUNET_OK !=
- TEH_PG_internal_setup (pg))
+ internal_setup (pg))
return GNUNET_SYSERR;
if (NULL == pg->transaction_name)
return GNUNET_OK; /* all good */
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index 7626759e2..c30a0e478 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -259,67 +259,6 @@
/**
- * Connect to the database if the connection does not exist yet.
- *
- * @param pg the plugin-specific state
- * @return #GNUNET_OK on success
- */
-enum GNUNET_GenericReturnValue
-TEH_PG_internal_setup (struct PostgresClosure *pg)
-{
- if (NULL == pg->conn)
- {
-#if AUTO_EXPLAIN
- /* Enable verbose logging to see where queries do not
- properly use indices */
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_try_execute ("LOAD 'auto_explain';"),
- GNUNET_PQ_make_try_execute ("SET auto_explain.log_min_duration=50;"),
- GNUNET_PQ_make_try_execute ("SET auto_explain.log_timing=TRUE;"),
- GNUNET_PQ_make_try_execute ("SET auto_explain.log_analyze=TRUE;"),
- /* https://wiki.postgresql.org/wiki/Serializable suggests to really
- force the default to 'serializable' if SSI is to be used. */
- GNUNET_PQ_make_try_execute (
- "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE;"),
- GNUNET_PQ_make_try_execute ("SET enable_sort=OFF;"),
- GNUNET_PQ_make_try_execute ("SET enable_seqscan=OFF;"),
- GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
- /* Mergejoin causes issues, see Postgres #18380 */
- GNUNET_PQ_make_try_execute ("SET enable_mergejoin=OFF;"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-#else
- struct GNUNET_PQ_ExecuteStatement es[] = {
- GNUNET_PQ_make_try_execute (
- "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE;"),
- GNUNET_PQ_make_try_execute ("SET enable_sort=OFF;"),
- GNUNET_PQ_make_try_execute ("SET enable_seqscan=OFF;"),
- /* Mergejoin causes issues, see Postgres #18380 */
- GNUNET_PQ_make_try_execute ("SET enable_mergejoin=OFF;"),
- GNUNET_PQ_make_try_execute ("SET search_path TO exchange;"),
- GNUNET_PQ_EXECUTE_STATEMENT_END
- };
-#endif
- struct GNUNET_PQ_Context *db_conn;
-
- db_conn = GNUNET_PQ_connect_with_cfg (pg->cfg,
- "exchangedb-postgres",
- NULL,
- es,
- NULL);
- if (NULL == db_conn)
- return GNUNET_SYSERR;
-
- pg->prep_gen++;
- pg->conn = db_conn;
- }
- if (NULL == pg->transaction_name)
- GNUNET_PQ_reconnect_if_down (pg->conn);
- return GNUNET_OK;
-}
-
-
-/**
* Initialize Postgres database subsystem.
*
* @param cls a configuration instance
@@ -428,15 +367,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls)
GNUNET_free (pg);
return NULL;
}
- if (GNUNET_OK !=
- TEH_PG_internal_setup (pg))
- {
- GNUNET_free (pg->exchange_url);
- GNUNET_free (pg->currency);
- GNUNET_free (pg->sql_dir);
- GNUNET_free (pg);
- return NULL;
- }
plugin = GNUNET_new (struct TALER_EXCHANGEDB_Plugin);
plugin->cls = pg;
plugin->do_reserve_open
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index fc79d6ba6..b63a7ce8d 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -1235,7 +1235,8 @@ run (void *cls)
ZR_BLK (&cbc);
ZR_BLK (&cbc2);
if (NULL ==
- (plugin = TALER_EXCHANGEDB_plugin_load (cfg)))
+ (plugin = TALER_EXCHANGEDB_plugin_load (cfg,
+ true)))
{
result = 77;
return;