summaryrefslogtreecommitdiff
path: root/src/auditordb
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-02-11 15:40:37 +0100
committerChristian Grothoff <christian@grothoff.org>2020-02-11 15:40:37 +0100
commit3ad698d01865c9f1b5c5aadc2f4d8b0a3658b81c (patch)
tree671de5acc0a13cafe636bf1e220496a5882a8b74 /src/auditordb
parentde0d987e34d426f6ed3593840078442191255587 (diff)
parentcdaf1ce69b5fb56f09bbdc00942b03f039710614 (diff)
downloadexchange-3ad698d01865c9f1b5c5aadc2f4d8b0a3658b81c.tar.gz
exchange-3ad698d01865c9f1b5c5aadc2f4d8b0a3658b81c.tar.bz2
exchange-3ad698d01865c9f1b5c5aadc2f4d8b0a3658b81c.zip
merging
Diffstat (limited to 'src/auditordb')
-rw-r--r--src/auditordb/Makefile.am4
-rw-r--r--src/auditordb/auditor-0000.sql (renamed from src/auditordb/0000.sql)0
-rw-r--r--src/auditordb/auditor-0001.sql (renamed from src/auditordb/0001.sql)4
-rw-r--r--src/auditordb/auditordb_plugin.c5
-rw-r--r--src/auditordb/plugin_auditordb_postgres.c95
5 files changed, 30 insertions, 78 deletions
diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am
index 1378c5496..3efdc200e 100644
--- a/src/auditordb/Makefile.am
+++ b/src/auditordb/Makefile.am
@@ -14,8 +14,8 @@ pkgcfg_DATA = \
sqldir = $(prefix)/share/taler/sql/auditor/
sql_DATA = \
- 0000.sql \
- 0001.sql \
+ auditor-0000.sql \
+ auditor-0001.sql \
drop0000.sql \
restart0000.sql
diff --git a/src/auditordb/0000.sql b/src/auditordb/auditor-0000.sql
index 1483e2015..1483e2015 100644
--- a/src/auditordb/0000.sql
+++ b/src/auditordb/auditor-0000.sql
diff --git a/src/auditordb/0001.sql b/src/auditordb/auditor-0001.sql
index 7f47f0357..3e666519c 100644
--- a/src/auditordb/0001.sql
+++ b/src/auditordb/auditor-0001.sql
@@ -115,7 +115,7 @@ CREATE TABLE IF NOT EXISTS auditor_reserves
,auditor_reserves_rowid BIGSERIAL UNIQUE
,origin_account TEXT
);
-CREATE INDEX auditor_reserves_by_reserve_pub
+CREATE INDEX IF NOT EXISTS auditor_reserves_by_reserve_pub
ON auditor_reserves
(reserve_pub);
-- Table with the sum of the balances of all customer reserves
@@ -203,7 +203,7 @@ CREATE TABLE IF NOT EXISTS auditor_historic_reserve_summary
,reserve_profits_val INT8 NOT NULL
,reserve_profits_frac INT4 NOT NULL
);
-CREATE INDEX auditor_historic_reserve_summary_by_master_pub_start_date
+CREATE INDEX IF NOT EXISTS auditor_historic_reserve_summary_by_master_pub_start_date
ON auditor_historic_reserve_summary
(master_pub
,start_date);
diff --git a/src/auditordb/auditordb_plugin.c b/src/auditordb/auditordb_plugin.c
index 19717fe87..d04e8815a 100644
--- a/src/auditordb/auditordb_plugin.c
+++ b/src/auditordb/auditordb_plugin.c
@@ -35,7 +35,6 @@ TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
{
char *plugin_name;
char *lib_name;
- struct GNUNET_CONFIGURATION_Handle *cfg_dup;
struct TALER_AUDITORDB_Plugin *plugin;
if (GNUNET_SYSERR ==
@@ -53,14 +52,12 @@ TALER_AUDITORDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
"libtaler_plugin_auditordb_%s",
plugin_name);
GNUNET_free (plugin_name);
- cfg_dup = GNUNET_CONFIGURATION_dup (cfg);
plugin = GNUNET_PLUGIN_load (lib_name,
- cfg_dup);
+ (void *) cfg);
if (NULL != plugin)
plugin->library_name = lib_name;
else
GNUNET_free (lib_name);
- GNUNET_CONFIGURATION_destroy (cfg_dup);
return plugin;
}
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c
index 30db303b0..ca07d406b 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -80,15 +80,9 @@ struct PostgresClosure
pthread_key_t db_conn_threadlocal;
/**
- * Directory with SQL statements to run to create tables.
+ * Our configuration.
*/
- char *sql_dir;
-
- /**
- * Database connection string, as read from
- * the configuration.
- */
- char *connection_cfg_str;
+ const struct GNUNET_CONFIGURATION_Handle *cfg;
/**
* Which currency should we assume all amounts to be in?
@@ -114,16 +108,12 @@ postgres_drop_tables (void *cls,
{
struct PostgresClosure *pc = cls;
struct GNUNET_PQ_Context *conn;
- char *exec_dir;
-
- GNUNET_asprintf (&exec_dir,
- (drop_exchangelist) ? "%sdrop" : "%srestart",
- pc->sql_dir);
- conn = GNUNET_PQ_connect (pc->connection_cfg_str,
- exec_dir,
- NULL,
- NULL);
- GNUNET_free (exec_dir);
+
+ conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
+ "auditordb-postgres",
+ (drop_exchangelist) ? "drop" : "restart",
+ NULL,
+ NULL);
if (NULL == conn)
return GNUNET_SYSERR;
GNUNET_PQ_disconnect (conn);
@@ -143,10 +133,11 @@ postgres_create_tables (void *cls)
struct PostgresClosure *pc = cls;
struct GNUNET_PQ_Context *conn;
- conn = GNUNET_PQ_connect (pc->connection_cfg_str,
- pc->sql_dir,
- NULL,
- NULL);
+ conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
+ "auditordb-postgres",
+ "auditor-",
+ NULL,
+ NULL);
if (NULL == conn)
return GNUNET_SYSERR;
GNUNET_PQ_disconnect (conn);
@@ -734,10 +725,11 @@ postgres_get_session (void *cls)
GNUNET_PQ_reconnect_if_down (session->conn);
return session;
}
- db_conn = GNUNET_PQ_connect (pc->connection_cfg_str,
- NULL,
- NULL,
- ps);
+ db_conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
+ "auditordb-postgres",
+ NULL,
+ NULL,
+ ps);
if (NULL == db_conn)
return NULL;
session = GNUNET_new (struct TALER_AUDITORDB_Session);
@@ -897,10 +889,11 @@ postgres_gc (void *cls)
};
now = GNUNET_TIME_absolute_get ();
- conn = GNUNET_PQ_connect (pc->connection_cfg_str,
- NULL,
- NULL,
- ps);
+ conn = GNUNET_PQ_connect_with_cfg (pc->cfg,
+ "auditordb-postgres",
+ NULL,
+ NULL,
+ ps);
if (NULL == conn)
return GNUNET_SYSERR;
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -3244,53 +3237,19 @@ postgres_get_predicted_balance (void *cls,
void *
libtaler_plugin_auditordb_postgres_init (void *cls)
{
- struct GNUNET_CONFIGURATION_Handle *cfg = cls;
+ const struct GNUNET_CONFIGURATION_Handle *cfg = cls;
struct PostgresClosure *pg;
struct TALER_AUDITORDB_Plugin *plugin;
- const char *ec;
pg = GNUNET_new (struct PostgresClosure);
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_filename (cfg,
- "auditordb-postgres",
- "SQL_DIR",
- &pg->sql_dir))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "auditordb-postgres",
- "SQL_DIR");
- GNUNET_free (pg);
- return NULL;
- }
+ pg->cfg = cfg;
if (0 != pthread_key_create (&pg->db_conn_threadlocal,
&db_conn_destroy))
{
TALER_LOG_ERROR ("Cannnot create pthread key.\n");
- GNUNET_free (pg->sql_dir);
GNUNET_free (pg);
return NULL;
}
- ec = getenv ("TALER_AUDITORDB_POSTGRES_CONFIG");
- if (NULL != ec)
- {
- pg->connection_cfg_str = GNUNET_strdup (ec);
- }
- else
- {
- if (GNUNET_OK !=
- GNUNET_CONFIGURATION_get_value_string (cfg,
- "auditordb-postgres",
- "CONFIG",
- &pg->connection_cfg_str))
- {
- GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
- "auditordb-postgres",
- "CONFIG");
- GNUNET_free (pg->sql_dir);
- GNUNET_free (pg);
- return NULL;
- }
- }
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_string (cfg,
"taler",
@@ -3300,8 +3259,6 @@ libtaler_plugin_auditordb_postgres_init (void *cls)
GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR,
"taler",
"CURRENCY");
- GNUNET_free (pg->connection_cfg_str);
- GNUNET_free (pg->sql_dir);
GNUNET_free (pg);
return NULL;
}
@@ -3407,8 +3364,6 @@ libtaler_plugin_auditordb_postgres_done (void *cls)
struct TALER_AUDITORDB_Plugin *plugin = cls;
struct PostgresClosure *pg = plugin->cls;
- GNUNET_free (pg->connection_cfg_str);
- GNUNET_free (pg->sql_dir);
GNUNET_free (pg->currency);
GNUNET_free (pg);
GNUNET_free (plugin);