donau

Donation authority for GNU Taler (experimental)
Log | Files | Refs | Submodules | README | LICENSE

commit 01bf0901ff4e8e97e91d253b2cd91f8c0f576728
parent 3a42b4c8f95b703ab2bfd733059ff0a815dfefc9
Author: Casaburi Johannes <johannes.casaburi@students.bfh.ch>
Date:   Mon,  8 Jan 2024 23:12:18 +0100

[db] fix postgres dbinit

Diffstat:
M.gitignore | 2++
Msrc/donau/donau-httpd_get-charity.c | 8++++----
Msrc/donaudb/pg_lookup_donation_unit.c | 10+++++-----
Msrc/donaudb/pg_lookup_donation_unit.h | 6+++---
Msrc/donaudb/plugin_donaudb_postgres.c | 146++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Msrc/include/donaudb_plugin.h | 2+-
6 files changed, 145 insertions(+), 29 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -15,3 +15,4 @@ src/donau/donau-httpd src/util/donau-config src/testing/test_donau_api_home/.local/ src/donau-tools/donau-dbinit +vgcore.* +\ No newline at end of file diff --git a/src/donau/donau-httpd_get-charity.c b/src/donau/donau-httpd_get-charity.c @@ -69,10 +69,10 @@ DH_handler_charity_get ( enum GNUNET_DB_QueryStatus qs; MHD_RESULT result; - qs = DH_plugin->get_charity (DH_plugin->cls, - charity_id, - &charity_url, - &charity_name); + qs = DH_plugin->lookup_charity (DH_plugin->cls, + charity_id, + &charity_url, + &charity_name); switch (qs) { case GNUNET_DB_STATUS_HARD_ERROR: diff --git a/src/donaudb/pg_lookup_donation_unit.c b/src/donaudb/pg_lookup_donation_unit.c @@ -14,8 +14,8 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donaudb/pg_lookup_donation_unit_key.c - * @brief Implementation of the lookup_donation_unit_key function for Postgres + * @file donaudb/pg_lookup_donation_unit.c + * @brief Implementation of the lookup_donation_unit function for Postgres * @author Johannes Casaburi */ #include "taler/platform.h" @@ -26,7 +26,7 @@ #include "pg_helper.h" enum GNUNET_DB_QueryStatus -DH_PG_lookup_donation_unit_key ( +DH_PG_lookup_donation_unit ( void *cls, const struct DONAU_DonationUnitHashP *h_donation_unit_pub, struct DONAUDB_DonationUnitKeyMetaData *meta) @@ -45,14 +45,14 @@ DH_PG_lookup_donation_unit_key ( }; PREPARE (pg, - "lookup_donation_unit_key", + "lookup_donation_unit", "SELECT" " validity_year" ",amount" " FROM donation_units" " WHERE donation_unit_hash=$1;"); return GNUNET_PQ_eval_prepared_singleton_select (pg->conn, - "lookup_donation_unit_key", + "lookup_donation_unit", params, rs); } diff --git a/src/donaudb/pg_lookup_donation_unit.h b/src/donaudb/pg_lookup_donation_unit.h @@ -14,8 +14,8 @@ TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ /** - * @file donaudb/pg_lookup_donation_unit_key.h - * @brief implementation of the lookup_donation_unit_key function for Postgres + * @file donaudb/pg_lookup_donation_unit.h + * @brief implementation of the lookup_donation_unit function for Postgres * @author Johannes Casaburi */ #ifndef PG_LOOKUP_DONATION_UNIT_KEY_H @@ -33,7 +33,7 @@ * @return transaction status code */ enum GNUNET_DB_QueryStatus -DH_PG_lookup_donation_unit_key ( +DH_PG_lookup_donation_unit ( void *cls, const struct DONAU_DonationUnitHashP *h_donation_unit_pub, struct DONAUDB_DonationUnitKeyMetaData *meta); diff --git a/src/donaudb/plugin_donaudb_postgres.c b/src/donaudb/plugin_donaudb_postgres.c @@ -1,13 +1,13 @@ /* This file is part of TALER - Copyright (C) 2014--2022 Taler Systems SA + Copyright (C) 2024 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. TALER is distributed in the hope that it will be useful, but WITHOUT ANY - WARRANTY; without even the implied warranty of CHARITYABILITY or FITNESS FOR + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with @@ -17,33 +17,54 @@ /** * @file plugin_donaudb_postgres.c * @brief Low-level (statement-level) Postgres database access for the donau - * @author Florian Dold - * @author Christian Grothoff - * @author Sree Harsha Totakura - * @author Marcello Stanisci - * @author Özgür Kesim + * @author Johannes Casaburi */ #include "taler/platform.h" #include <poll.h> #include <pthread.h> #include <libpq-fe.h> #include "taler/taler_error_codes.h" -// #include "taler/taler_dbevents.h" +#include "taler/taler_dbevents.h" #include "taler/taler_pq_lib.h" #include "taler/taler_util.h" #include "taler/taler_json_lib.h" #include "donaudb_plugin.h" -// #include "plugin_donaudb_common.h" -// #include "pg_delete_aggregation_transient.h" -// #include "pg_get_link_data.h" #include "pg_helper.h" +#include "pg_preflight.h" +#include "pg_commit.h" +#include "pg_drop_tables.h" +#include "pg_start.h" +#include "pg_rollback.h" +#include "pg_create_tables.h" +#include "pg_event_listen.h" +#include "pg_event_listen_cancel.h" +#include "pg_event_notify.h" +// #include "pg_get_policy_details.h" +// #include "pg_persist_policy_details.h" +// #include "pg_gc.h" +// #include "pg_begin_shard.h" +// #include "pg_abort_shard.h" +// #include "pg_complete_shard.h" +// #include "pg_release_revolving_shard.h" +// #include "pg_delete_shard_locks.h" +// #include "pg_compute_shard.h" + +#include "pg_add_donation_unit_key.h" +#include "pg_lookup_donation_unit.h" +#include "pg_insert_history_entry.h" +#include "pg_insert_issued_receipt.h" +#include "pg_insert_submitted_receipt.h" +#include "pg_insert_signing_key.h" +#include "pg_lookup_signing_key.h" +#include "pg_lookup_charity.h" +#include "pg_get_charities.h" /** * Set to 1 to enable Postgres auto_explain module. This will * slow down things a _lot_, but also provide extensive logging * in the Postgres database logger for performance analysis. */ -#define AUTO_EXPLAIN 1 +#define AUTO_EXPLAIN 0 /** @@ -86,8 +107,7 @@ DH_PG_internal_setup (struct PostgresClosure *pg) /* 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;") - , + "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 donau;"), @@ -96,8 +116,7 @@ DH_PG_internal_setup (struct PostgresClosure *pg) #else struct GNUNET_PQ_ExecuteStatement es[] = { GNUNET_PQ_make_try_execute ( - "SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE;") - , + "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 autocommit=OFF;"), @@ -137,6 +156,7 @@ libtaler_plugin_donaudb_postgres_init (void *cls) const struct GNUNET_CONFIGURATION_Handle *cfg = cls; struct PostgresClosure *pg; struct DONAUDB_Plugin *plugin; + // unsigned long long dpl; pg = GNUNET_new (struct PostgresClosure); pg->cfg = cfg; @@ -165,6 +185,52 @@ libtaler_plugin_donaudb_postgres_init (void *cls) GNUNET_free (pg); return NULL; } + // if ( (GNUNET_OK != + // GNUNET_CONFIGURATION_get_value_time (cfg, + // "donaudb", + // "IDLE_RESERVE_EXPIRATION_TIME", + // &pg->idle_reserve_expiration_time)) + // || + // (GNUNET_OK != + // GNUNET_CONFIGURATION_get_value_time (cfg, + // "donaudb", + // "LEGAL_RESERVE_EXPIRATION_TIME", + // &pg->legal_reserve_expiration_time)) ) + // { + // GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, + // "donaudb", + // "LEGAL/IDLE_RESERVE_EXPIRATION_TIME"); + // GNUNET_free (pg->donau_url); + // GNUNET_free (pg->sql_dir); + // GNUNET_free (pg); + // return NULL; + // } + // if (GNUNET_OK != + // GNUNET_CONFIGURATION_get_value_time (cfg, + // "donaudb", + // "AGGREGATOR_SHIFT", + // &pg->aggregator_shift)) + // { + // GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, + // "donaudb", + // "AGGREGATOR_SHIFT"); + // } + // if (GNUNET_OK != + // GNUNET_CONFIGURATION_get_value_number (cfg, + // "donaudb", + // "DEFAULT_PURSE_LIMIT", + // &dpl)) + // { + // GNUNET_log_config_missing (GNUNET_ERROR_TYPE_WARNING, + // "donaudb", + // "DEFAULT_PURSE_LIMIT"); + // pg->def_purse_limit = 1; + // } + // else + // { + // pg->def_purse_limit = (uint32_t) dpl; + // } + if (GNUNET_OK != TALER_config_get_currency (cfg, &pg->currency)) @@ -185,6 +251,54 @@ libtaler_plugin_donaudb_postgres_init (void *cls) } plugin = GNUNET_new (struct DONAUDB_Plugin); plugin->cls = pg; + plugin->drop_tables + = &DH_PG_drop_tables; + plugin->commit + = &DH_PG_commit; + plugin->preflight + = &DH_PG_preflight; + // plugin->start_read_committed + // = &DH_PG_start_read_committed; + // plugin->start_read_only + // = &DH_PG_start_read_only; + plugin->start + = &DH_PG_start; + plugin->rollback + = &DH_PG_rollback; + plugin->create_tables + = &DH_PG_create_tables; + plugin->event_listen + = &DH_PG_event_listen; + plugin->event_listen_cancel + = &DH_PG_event_listen_cancel; + plugin->event_notify + = &DH_PG_event_notify; + // plugin->get_policy_details + // = &DH_PG_get_policy_details; + // plugin->persist_policy_details + // = &DH_PG_persist_policy_details; + // plugin->gc + // = &DH_PG_gc; + + // plugin->add_donation_unit_key + // = &DH_PG_add_donation_unit_key; + // plugin->lookup_donation_unit + // = &DH_PG_lookup_donation_unit; + // plugin->insert_history_entry + // = &DH_PG_insert_history_entry; + // plugin->insert_issued_receipt + // = &DH_PG_insert_issued_receipt; + // plugin->insert_submitted_receipt + // = &DH_PG_insert_submitted_receipt; + // plugin->insert_signing_key + // = &DH_PG_insert_signing_key; + // plugin->lookup_signing_key + // = &DH_PG_lookup_signing_key; + plugin->lookup_charity + = &DH_PG_lookup_charity; + plugin->get_charities + = &DH_PG_get_charities; + return plugin; } diff --git a/src/include/donaudb_plugin.h b/src/include/donaudb_plugin.h @@ -349,7 +349,7 @@ struct DONAUDB_Plugin * @return database transaction status */ enum GNUNET_DB_QueryStatus - (*get_charity)( + (*lookup_charity)( void *cls, unsigned long long charity_id, const char *charity_url,