diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-11-10 17:22:31 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-11-10 17:22:44 +0100 |
commit | 9508cb1806608274262f70efee9d43630b81ccd3 (patch) | |
tree | a475e295aa36dd165278bd36a2a75d2ff3469512 | |
parent | 0e68462e9040c2cbb536d0b0f797fa2e7aab064a (diff) |
ensure we do not start if the database version is outdated (#9203)
28 files changed, 200 insertions, 155 deletions
diff --git a/src/auditor/report-lib.c b/src/auditor/report-lib.c index 3ca2912a7..7b6ceea86 100644 --- a/src/auditor/report-lib.c +++ b/src/auditor/report-lib.c @@ -634,7 +634,8 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c) } } if (NULL == - (TALER_ARL_edb = TALER_EXCHANGEDB_plugin_load (TALER_ARL_cfg))) + (TALER_ARL_edb = TALER_EXCHANGEDB_plugin_load (TALER_ARL_cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize exchange database plugin.\n"); @@ -642,7 +643,8 @@ TALER_ARL_init (const struct GNUNET_CONFIGURATION_Handle *c) return GNUNET_SYSERR; } if (NULL == - (TALER_ARL_adb = TALER_AUDITORDB_plugin_load (TALER_ARL_cfg))) + (TALER_ARL_adb = TALER_AUDITORDB_plugin_load (TALER_ARL_cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize auditor database plugin.\n"); diff --git a/src/auditor/taler-auditor-dbinit.c b/src/auditor/taler-auditor-dbinit.c index 9b4026ec6..311959a40 100644 --- a/src/auditor/taler-auditor-dbinit.c +++ b/src/auditor/taler-auditor-dbinit.c @@ -66,7 +66,8 @@ run (void *cls, (void) args; (void) cfgfile; if (NULL == - (plugin = TALER_AUDITORDB_plugin_load (cfg))) + (plugin = TALER_AUDITORDB_plugin_load (cfg, + true))) { fprintf (stderr, "Failed to initialize database plugin.\n"); diff --git a/src/auditor/taler-auditor-httpd.c b/src/auditor/taler-auditor-httpd.c index 3ae0176b5..a7864e98b 100644 --- a/src/auditor/taler-auditor-httpd.c +++ b/src/auditor/taler-auditor-httpd.c @@ -353,7 +353,7 @@ handle_mhd_request (void *cls, "application/json", NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_DEPOSIT_CONFIRMATION }, + .table = TALER_AUDITORDB_DEPOSIT_CONFIRMATION }, { "/monitoring/amount-arithmetic-inconsistency", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -362,7 +362,7 @@ handle_mhd_request (void *cls, "application/json", NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY }, + .table = TALER_AUDITORDB_AMOUNT_ARITHMETIC_INCONSISTENCY }, { "/monitoring/amount-arithmetic-inconsistency", MHD_HTTP_METHOD_PATCH, @@ -382,12 +382,12 @@ handle_mhd_request (void *cls, "application/json", NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_COIN_INCONSISTENCY }, + .table = TALER_AUDITORDB_COIN_INCONSISTENCY }, { "/monitoring/coin-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_COIN_INCONSISTENCY }, + .table = TALER_AUDITORDB_COIN_INCONSISTENCY }, { "/monitoring/row-inconsistency", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -401,7 +401,7 @@ handle_mhd_request (void *cls, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_ROW_INCONSISTENCY }, + .table = TALER_AUDITORDB_ROW_INCONSISTENCY }, { "/monitoring/bad-sig-losses", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -418,7 +418,7 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_BAD_SIG_LOSSES }, + .table = TALER_AUDITORDB_BAD_SIG_LOSSES }, { "/monitoring/closure-lags", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -429,13 +429,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_CLOSURE_LAGS }, + .table = TALER_AUDITORDB_CLOSURE_LAGS }, { "/monitoring/closure-lags", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_CLOSURE_LAGS }, + .table = TALER_AUDITORDB_CLOSURE_LAGS }, { "/monitoring/emergency", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -446,13 +446,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_EMERGENCY }, + .table = TALER_AUDITORDB_EMERGENCY }, { "/monitoring/emergency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_EMERGENCY }, + .table = TALER_AUDITORDB_EMERGENCY }, { "/monitoring/refreshes-hanging", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -463,13 +463,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_REFRESHES_HANGING }, + .table = TALER_AUDITORDB_REFRESHES_HANGING }, { "/monitoring/refreshes-hanging", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_REFRESHES_HANGING }, + .table = TALER_AUDITORDB_REFRESHES_HANGING }, { "/monitoring/denomination-key-validity-withdraw-inconsistency", MHD_HTTP_METHOD_GET, "application/json", @@ -482,14 +482,16 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY }, + .table = TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY} + , { "/monitoring/denomination-key-validity-withdraw-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY }, + .table = TALER_AUDITORDB_DENOMINATION_KEY_VALIDITY_WITHDRAW_INCONSISTENCY} + , { "/monitoring/reserve-balance-insufficient-inconsistency", MHD_HTTP_METHOD_GET, "application/json", @@ -502,14 +504,14 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY }, + .table = TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY }, { "/monitoring/reserve-balance-insufficient-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY }, + .table = TALER_AUDITORDB_RESERVE_BALANCE_INSUFFICIENT_INCONSISTENCY }, { "/monitoring/purse-not-closed-inconsistencies", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -520,13 +522,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCY }, + .table = TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCY }, { "/monitoring/purse-not-closed-inconsistencies", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCY }, + .table = TALER_AUDITORDB_PURSE_NOT_CLOSED_INCONSISTENCY }, { "/monitoring/emergency-by-count", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -537,13 +539,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_EMERGENCY_BY_COUNT }, + .table = TALER_AUDITORDB_EMERGENCY_BY_COUNT }, { "/monitoring/emergency-by-count", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_EMERGENCY_BY_COUNT }, + .table = TALER_AUDITORDB_EMERGENCY_BY_COUNT }, { "/monitoring/reserve-in-inconsistency", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -554,13 +556,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY }, + .table = TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY }, { "/monitoring/reserve-in-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY }, + .table = TALER_AUDITORDB_RESERVE_IN_INCONSISTENCY }, { "/monitoring/reserve-not-closed-inconsistency", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -571,13 +573,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY }, + .table = TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY }, { "/monitoring/reserve-not-closed-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY }, + .table = TALER_AUDITORDB_RESERVE_NOT_CLOSED_INCONSISTENCY }, { "/monitoring/denominations-without-sigs", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -588,13 +590,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIG }, + .table = TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIG }, { "/monitoring/denominations-without-sigs", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIG }, + .table = TALER_AUDITORDB_DENOMINATIONS_WITHOUT_SIG }, { "/monitoring/misattribution-in-inconsistency", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -605,13 +607,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY }, + .table = TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY }, { "/monitoring/misattribution-in-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY }, + .table = TALER_AUDITORDB_MISATTRIBUTION_IN_INCONSISTENCY }, { "/monitoring/reserves", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -637,7 +639,7 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_DENOMINATION_PENDING }, + .table = TALER_AUDITORDB_DENOMINATION_PENDING }, { "/monitoring/historic-reserve-summary", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -653,13 +655,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY }, + .table = TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY }, { "/monitoring/wire-format-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY }, + .table = TALER_AUDITORDB_WIRE_FORMAT_INCONSISTENCY }, { "/monitoring/wire-out-inconsistency", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -670,13 +672,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY }, + .table = TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY }, { "/monitoring/wire-out-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY }, + .table = TALER_AUDITORDB_WIRE_OUT_INCONSISTENCY }, { "/monitoring/reserve-balance-summary-wrong-inconsistency", MHD_HTTP_METHOD_GET, "application/json", @@ -689,14 +691,14 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY }, + .table = TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY }, { "/monitoring/reserve-balance-summary-wrong-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY }, + .table = TALER_AUDITORDB_RESERVE_BALANCE_SUMMARY_WRONG_INCONSISTENCY }, { "/monitoring/row-minor-inconsistencies", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -707,13 +709,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_ROW_MINOR_INCONSISTENCY }, + .table = TALER_AUDITORDB_ROW_MINOR_INCONSISTENCY }, { "/monitoring/row-minor-inconsistencies", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_ROW_MINOR_INCONSISTENCY }, + .table = TALER_AUDITORDB_ROW_MINOR_INCONSISTENCY }, { "/monitoring/fee-time-inconsistency", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -724,13 +726,13 @@ handle_mhd_request (void *cls, NULL, 0, &TAH_delete_handler_generic, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_FEE_TIME_INCONSISTENCY }, + .table = TALER_AUDITORDB_FEE_TIME_INCONSISTENCY }, { "/monitoring/fee-time-inconsistency", MHD_HTTP_METHOD_PATCH, "application/json", NULL, 0, &TAH_patch_handler_generic_suppressed, MHD_HTTP_OK, true, - .table = TALER_AUDITORDB_FEE_TIME_INCONSISTENCY }, + .table = TALER_AUDITORDB_FEE_TIME_INCONSISTENCY }, { "/monitoring/balances", MHD_HTTP_METHOD_GET, "application/json", NULL, 0, @@ -893,7 +895,7 @@ not_found: } #define NOT_FOUND \ - "<html><title>404: not found</title><body>auditor endpoints have been moved to /monitoring/...</body></html>" + "<html><title>404: not found</title><body>auditor endpoints have been moved to /monitoring/...</body></html>" return TALER_MHD_reply_static (connection, MHD_HTTP_NOT_FOUND, "text/html", @@ -913,14 +915,16 @@ static enum GNUNET_GenericReturnValue auditor_serve_process_config (void) { if (NULL == - (TAH_plugin = TALER_AUDITORDB_plugin_load (cfg))) + (TAH_plugin = TALER_AUDITORDB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem to interact with auditor database\n"); return GNUNET_SYSERR; } if (NULL == - (TAH_eplugin = TALER_EXCHANGEDB_plugin_load (cfg))) + (TAH_eplugin = TALER_EXCHANGEDB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem to query exchange database\n"); diff --git a/src/auditor/taler-auditor-sync.c b/src/auditor/taler-auditor-sync.c index e49eb8047..d7f45e384 100644 --- a/src/auditor/taler-auditor-sync.c +++ b/src/auditor/taler-auditor-sync.c @@ -523,13 +523,15 @@ static void setup (struct GNUNET_CONFIGURATION_Handle *src_cfg, struct GNUNET_CONFIGURATION_Handle *dst_cfg) { - src = TALER_EXCHANGEDB_plugin_load (src_cfg); + src = TALER_EXCHANGEDB_plugin_load (src_cfg, + false); if (NULL == src) { global_ret = EXIT_NOTINSTALLED; return; } - dst = TALER_EXCHANGEDB_plugin_load (dst_cfg); + dst = TALER_EXCHANGEDB_plugin_load (dst_cfg, + false); if (NULL == dst) { global_ret = EXIT_NOTINSTALLED; diff --git a/src/auditordb/auditordb_plugin.c b/src/auditordb/auditordb_plugin.c index 635247aa3..7aaeabf7b 100644 --- a/src/auditordb/auditordb_plugin.c +++ b/src/auditordb/auditordb_plugin.c @@ -25,7 +25,8 @@ struct TALER_AUDITORDB_Plugin * -TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg) +TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg, + bool skip_preflight) { char *plugin_name; char *lib_name; @@ -52,6 +53,15 @@ TALER_AUDITORDB_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-auditor-dbinit!\n"); + TALER_AUDITORDB_plugin_unload (plugin); + return NULL; + } return plugin; } diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index 6cbc0bf7b..4b3bf8c92 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -315,11 +315,12 @@ setup_connection (struct PostgresClosure *pg) GNUNET_PQ_reconnect_if_down (pg->conn); return GNUNET_OK; } - db_conn = GNUNET_PQ_connect_with_cfg (pg->cfg, - "auditordb-postgres", - NULL, - es, - NULL); + db_conn = GNUNET_PQ_connect_with_cfg2 (pg->cfg, + "auditordb-postgres", + "auditor-", + es, + NULL, /* prepared statements */ + GNUNET_PQ_FLAG_CHECK_CURRENT); if (NULL == db_conn) return GNUNET_SYSERR; pg->conn = db_conn; @@ -346,15 +347,10 @@ postgres_preflight (void *cls) GNUNET_PQ_EXECUTE_STATEMENT_END }; - if (NULL == pg->conn) - { - if (GNUNET_OK != - setup_connection (pg)) - { - GNUNET_break (0); - return GNUNET_SYSERR; - } - } + if ( (NULL == pg->conn) && + (GNUNET_OK != + setup_connection (pg)) ) + return GNUNET_SYSERR; if (NULL == pg->transaction_name) return GNUNET_OK; /* all good */ if (GNUNET_OK == @@ -524,8 +520,6 @@ libtaler_plugin_auditordb_postgres_init (void *cls) return NULL; } - // MARK: CRUD - plugin = GNUNET_new (struct TALER_AUDITORDB_Plugin); plugin->cls = pg; plugin->preflight = &postgres_preflight; diff --git a/src/benchmark/taler-aggregator-benchmark.c b/src/benchmark/taler-aggregator-benchmark.c index 889c12cda..5fb9d1412 100644 --- a/src/benchmark/taler-aggregator-benchmark.c +++ b/src/benchmark/taler-aggregator-benchmark.c @@ -450,7 +450,8 @@ run (void *cls, global_ret = EXIT_NOTCONFIGURED; return; } - plugin = TALER_EXCHANGEDB_plugin_load (cfg); + plugin = TALER_EXCHANGEDB_plugin_load (cfg, + false); if (NULL == plugin) { global_ret = EXIT_NOTCONFIGURED; diff --git a/src/exchange-tools/taler-exchange-dbinit.c b/src/exchange-tools/taler-exchange-dbinit.c index 5fb587feb..bd2c8d541 100644 --- a/src/exchange-tools/taler-exchange-dbinit.c +++ b/src/exchange-tools/taler-exchange-dbinit.c @@ -80,7 +80,8 @@ run (void *cls, (void) cfgfile; if (NULL == - (plugin = TALER_EXCHANGEDB_plugin_load (cfg))) + (plugin = TALER_EXCHANGEDB_plugin_load (cfg, + true))) { fprintf (stderr, "Failed to initialize database plugin.\n"); diff --git a/src/exchange/taler-exchange-aggregator.c b/src/exchange/taler-exchange-aggregator.c index e490c94f3..bc3a4e9b1 100644 --- a/src/exchange/taler-exchange-aggregator.c +++ b/src/exchange/taler-exchange-aggregator.c @@ -329,7 +329,8 @@ parse_aggregator_config (void) } if (NULL == - (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg))) + (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem\n"); diff --git a/src/exchange/taler-exchange-closer.c b/src/exchange/taler-exchange-closer.c index 70c86658e..a24f8387b 100644 --- a/src/exchange/taler-exchange-closer.c +++ b/src/exchange/taler-exchange-closer.c @@ -151,7 +151,8 @@ parse_closer_config (void) } if (NULL == - (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg))) + (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem\n"); diff --git a/src/exchange/taler-exchange-drain.c b/src/exchange/taler-exchange-drain.c index cb6ccd516..52de43be9 100644 --- a/src/exchange/taler-exchange-drain.c +++ b/src/exchange/taler-exchange-drain.c @@ -134,7 +134,8 @@ parse_drain_config (void) GNUNET_free (master_public_key_str); } if (NULL == - (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg))) + (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem\n"); diff --git a/src/exchange/taler-exchange-expire.c b/src/exchange/taler-exchange-expire.c index 22b3da622..248e4d2d4 100644 --- a/src/exchange/taler-exchange-expire.c +++ b/src/exchange/taler-exchange-expire.c @@ -137,7 +137,8 @@ static enum GNUNET_GenericReturnValue parse_expire_config (void) { if (NULL == - (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg))) + (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem\n"); diff --git a/src/exchange/taler-exchange-httpd.c b/src/exchange/taler-exchange-httpd.c index e93663357..b3a80efa7 100644 --- a/src/exchange/taler-exchange-httpd.c +++ b/src/exchange/taler-exchange-httpd.c @@ -2382,7 +2382,8 @@ exchange_serve_process_config (const char *cfg_fn) for (unsigned int i = 0; i<MAX_DB_RETRIES; i++) { - TEH_plugin = TALER_EXCHANGEDB_plugin_load (TEH_cfg); + TEH_plugin = TALER_EXCHANGEDB_plugin_load (TEH_cfg, + false); if (NULL != TEH_plugin) break; GNUNET_log (GNUNET_ERROR_TYPE_WARNING, diff --git a/src/exchange/taler-exchange-router.c b/src/exchange/taler-exchange-router.c index c20795edf..306a0e1f6 100644 --- a/src/exchange/taler-exchange-router.c +++ b/src/exchange/taler-exchange-router.c @@ -198,7 +198,8 @@ parse_wirewatch_config (void) } if (NULL == - (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg))) + (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem\n"); diff --git a/src/exchange/taler-exchange-transfer.c b/src/exchange/taler-exchange-transfer.c index 399220e49..6726a46dd 100644 --- a/src/exchange/taler-exchange-transfer.c +++ b/src/exchange/taler-exchange-transfer.c @@ -283,7 +283,8 @@ parse_transfer_config (void) return GNUNET_SYSERR; } if (NULL == - (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg))) + (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem\n"); diff --git a/src/exchange/taler-exchange-wirewatch.c b/src/exchange/taler-exchange-wirewatch.c index a7d97cc63..c1f7f5d75 100644 --- a/src/exchange/taler-exchange-wirewatch.c +++ b/src/exchange/taler-exchange-wirewatch.c @@ -345,7 +345,8 @@ exchange_serve_process_config (void) return GNUNET_SYSERR; } if (NULL == - (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg))) + (db_plugin = TALER_EXCHANGEDB_plugin_load (cfg, + false))) { GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize DB subsystem\n"); 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; diff --git a/src/include/taler_auditordb_lib.h b/src/include/taler_auditordb_lib.h index 882e37e11..49f3bc011 100644 --- a/src/include/taler_auditordb_lib.h +++ b/src/include/taler_auditordb_lib.h @@ -151,10 +151,14 @@ enum TALER_AUDITORDB_DeletableSuppressableTables * Initialize the plugin. * * @param cfg configuration to use + * @param skip_preflight true if we should skip the usual + * preflight check which assures us that the DB is actually + * operational; only taler-auditor-dbinit should use true here. * @return NULL on failure */ struct TALER_AUDITORDB_Plugin * -TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg); +TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg, + bool skip_preflight); /** diff --git a/src/include/taler_exchangedb_lib.h b/src/include/taler_exchangedb_lib.h index fdedfa056..825578c95 100644 --- a/src/include/taler_exchangedb_lib.h +++ b/src/include/taler_exchangedb_lib.h @@ -32,20 +32,25 @@ * Initialize the plugin. * * @param cfg configuration to use + * @param skip_preflight true if we should skip the usual + * preflight check which assures us that the DB is actually + * operational; only taler-exchange-dbinit should use true here. * @return NULL on failure */ 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); /** * Shutdown the plugin. * - * @param plugin plugin to unload + * @param[in] plugin plugin to unload */ void TALER_EXCHANGEDB_plugin_unload (struct TALER_EXCHANGEDB_Plugin *plugin); + /** * Information about an account from the configuration. */ diff --git a/src/testing/testing_api_cmd_insert_deposit.c b/src/testing/testing_api_cmd_insert_deposit.c index 2816758a6..51ec6d80b 100644 --- a/src/testing/testing_api_cmd_insert_deposit.c +++ b/src/testing/testing_api_cmd_insert_deposit.c @@ -362,7 +362,8 @@ TALER_TESTING_cmd_insert_deposit ( } else { - ids->plugin = TALER_EXCHANGEDB_plugin_load (db_cfg); + ids->plugin = TALER_EXCHANGEDB_plugin_load (db_cfg, + false); pluginc = ids->plugin; db_cfgc = db_cfg; } |