diff options
Diffstat (limited to 'src/exchangedb')
-rw-r--r-- | src/exchangedb/Makefile.am | 4 | ||||
-rw-r--r-- | src/exchangedb/exchange-0000.sql (renamed from src/exchangedb/0000.sql) | 0 | ||||
-rw-r--r-- | src/exchangedb/exchange-0001.sql (renamed from src/exchangedb/0001.sql) | 54 | ||||
-rw-r--r-- | src/exchangedb/exchangedb_plugin.c | 6 | ||||
-rw-r--r-- | src/exchangedb/plugin_exchangedb_postgres.c | 77 |
5 files changed, 56 insertions, 85 deletions
diff --git a/src/exchangedb/Makefile.am b/src/exchangedb/Makefile.am index e7ac4d719..37809f6b4 100644 --- a/src/exchangedb/Makefile.am +++ b/src/exchangedb/Makefile.am @@ -15,8 +15,8 @@ pkgcfg_DATA = \ sqldir = $(prefix)/share/taler/sql/exchange/ sql_DATA = \ - 0000.sql \ - 0001.sql \ + exchange-0000.sql \ + exchange-0001.sql \ drop0000.sql EXTRA_DIST = \ diff --git a/src/exchangedb/0000.sql b/src/exchangedb/exchange-0000.sql index 1483e2015..1483e2015 100644 --- a/src/exchangedb/0000.sql +++ b/src/exchangedb/exchange-0000.sql diff --git a/src/exchangedb/0001.sql b/src/exchangedb/exchange-0001.sql index 8e7ea0bf5..02dc68cf4 100644 --- a/src/exchangedb/0001.sql +++ b/src/exchangedb/exchange-0001.sql @@ -42,7 +42,7 @@ CREATE TABLE IF NOT EXISTS denominations ,fee_refund_val INT8 NOT NULL ,fee_refund_frac INT4 NOT NULL ); -CREATE INDEX denominations_expire_legal_index +CREATE INDEX IF NOT EXISTS denominations_expire_legal_index ON denominations (expire_legal); @@ -65,18 +65,18 @@ CREATE TABLE IF NOT EXISTS reserves ,gc_date INT8 NOT NULL ); -- index on reserves table (TODO: useless due to primary key!?) -CREATE INDEX reserves_reserve_pub_index +CREATE INDEX IF NOT EXISTS reserves_reserve_pub_index ON reserves (reserve_pub); -- index for get_expired_reserves -CREATE INDEX reserves_expiration_index +CREATE INDEX IF NOT EXISTS reserves_expiration_index ON reserves (expiration_date ,current_balance_val ,current_balance_frac ); -- index for reserve GC operations -CREATE INDEX reserves_gc_index +CREATE INDEX IF NOT EXISTS reserves_gc_index ON reserves (gc_date); -- reserves_in table collects the transactions which transfer funds @@ -94,12 +94,12 @@ CREATE TABLE IF NOT EXISTS reserves_in ,PRIMARY KEY (reserve_pub, wire_reference) ); -- Create indices on reserves_in -CREATE INDEX reserves_in_execution_index +CREATE INDEX IF NOT EXISTS reserves_in_execution_index ON reserves_in (exchange_account_section ,execution_date ); -CREATE INDEX reserves_in_exchange_account_serial +CREATE INDEX IF NOT EXISTS reserves_in_exchange_account_serial ON reserves_in (exchange_account_section, reserve_in_serial_id DESC @@ -116,7 +116,7 @@ CREATE TABLE IF NOT EXISTS reserves_close ,amount_frac INT4 NOT NULL ,closing_fee_val INT8 NOT NULL ,closing_fee_frac INT4 NOT NULL); -CREATE INDEX reserves_close_by_reserve +CREATE INDEX IF NOT EXISTS reserves_close_by_reserve ON reserves_close (reserve_pub); -- Table with the withdraw operations that have been performed on a reserve. @@ -137,13 +137,13 @@ CREATE TABLE IF NOT EXISTS reserves_out ,amount_with_fee_frac INT4 NOT NULL ); -- Index blindcoins(reserve_pub) for get_reserves_out statement -CREATE INDEX reserves_out_reserve_pub_index +CREATE INDEX IF NOT EXISTS reserves_out_reserve_pub_index ON reserves_out (reserve_pub); -CREATE INDEX reserves_out_execution_date +CREATE INDEX IF NOT EXISTS reserves_out_execution_date ON reserves_out (execution_date); -CREATE INDEX reserves_out_for_get_withdraw_info +CREATE INDEX IF NOT EXISTS reserves_out_for_get_withdraw_info ON reserves_out (denom_pub_hash ,h_blind_ev @@ -155,7 +155,7 @@ CREATE TABLE IF NOT EXISTS known_coins ,denom_pub_hash BYTEA NOT NULL REFERENCES denominations (denom_pub_hash) ON DELETE CASCADE ,denom_sig BYTEA NOT NULL ); -CREATE INDEX known_coins_by_denomination +CREATE INDEX IF NOT EXISTS known_coins_by_denomination ON known_coins (denom_pub_hash); -- Table with the commitments made when melting a coin. */ @@ -168,7 +168,7 @@ CREATE TABLE IF NOT EXISTS refresh_commitments ,amount_with_fee_frac INT4 NOT NULL ,noreveal_index INT4 NOT NULL ); -CREATE INDEX refresh_commitments_old_coin_pub_index +CREATE INDEX IF NOT EXISTS refresh_commitments_old_coin_pub_index ON refresh_commitments (old_coin_pub); -- Table with the revelations about the new coins that are to be created @@ -188,7 +188,7 @@ CREATE TABLE IF NOT EXISTS refresh_revealed_coins ,PRIMARY KEY (rc, newcoin_index) ,UNIQUE (h_coin_ev) ); -CREATE INDEX refresh_revealed_coins_coin_pub_index +CREATE INDEX IF NOT EXISTS refresh_revealed_coins_coin_pub_index ON refresh_revealed_coins (denom_pub_hash); -- Table with the transfer keys of a refresh operation; includes @@ -203,7 +203,7 @@ CREATE TABLE IF NOT EXISTS refresh_transfer_keys -- for get_link (not sure if this helps, as there should be very few -- transfer_pubs per rc, but at least in theory this helps the ORDER BY -- clause. -CREATE INDEX refresh_transfer_keys_coin_tpub +CREATE INDEX IF NOT EXISTS refresh_transfer_keys_coin_tpub ON refresh_transfer_keys (rc ,transfer_pub @@ -228,14 +228,14 @@ CREATE TABLE IF NOT EXISTS deposits ,UNIQUE (coin_pub, merchant_pub, h_contract_terms) ); -- Index for get_deposit_for_wtid and get_deposit_statement */ -CREATE INDEX deposits_coin_pub_merchant_contract_index +CREATE INDEX IF NOT EXISTS deposits_coin_pub_merchant_contract_index ON deposits (coin_pub ,merchant_pub ,h_contract_terms ); -- Index for deposits_get_ready -CREATE INDEX deposits_get_ready_index +CREATE INDEX IF NOT EXISTS deposits_get_ready_index ON deposits (tiny ,done @@ -243,7 +243,7 @@ CREATE INDEX deposits_get_ready_index ,refund_deadline ); -- Index for deposits_iterate_matching -CREATE INDEX deposits_iterate_matching +CREATE INDEX IF NOT EXISTS deposits_iterate_matching ON deposits (merchant_pub ,h_wire @@ -265,7 +265,7 @@ CREATE TABLE IF NOT EXISTS refunds ,amount_with_fee_frac INT4 NOT NULL ,PRIMARY KEY (coin_pub, merchant_pub, h_contract_terms, rtransaction_id) ); -CREATE INDEX refunds_coin_pub_index +CREATE INDEX IF NOT EXISTS refunds_coin_pub_index ON refunds (coin_pub); -- This table contains the data for @@ -287,7 +287,7 @@ CREATE TABLE IF NOT EXISTS aggregation_tracking ,wtid_raw BYTEA CONSTRAINT wire_out_ref REFERENCES wire_out(wtid_raw) ON DELETE CASCADE DEFERRABLE ); -- Index for lookup_transactions statement on wtid -CREATE INDEX aggregation_tracking_wtid_index +CREATE INDEX IF NOT EXISTS aggregation_tracking_wtid_index ON aggregation_tracking (wtid_raw); -- Table for the wire fees. @@ -302,7 +302,7 @@ CREATE TABLE IF NOT EXISTS wire_fee ,master_sig BYTEA NOT NULL CHECK (LENGTH(master_sig)=64) ,PRIMARY KEY (wire_method, start_date) ); -CREATE INDEX wire_fee_gc_index +CREATE INDEX IF NOT EXISTS wire_fee_gc_index ON wire_fee (end_date); -- Table for /recoup information @@ -317,13 +317,13 @@ CREATE TABLE IF NOT EXISTS recoup ,timestamp INT8 NOT NULL ,h_blind_ev BYTEA NOT NULL REFERENCES reserves_out (h_blind_ev) ON DELETE CASCADE ); -CREATE INDEX recoup_by_coin_index +CREATE INDEX IF NOT EXISTS recoup_by_coin_index ON recoup (coin_pub); -CREATE INDEX recoup_by_h_blind_ev +CREATE INDEX IF NOT EXISTS recoup_by_h_blind_ev ON recoup (h_blind_ev); -CREATE INDEX recoup_for_by_reserve +CREATE INDEX IF NOT EXISTS recoup_for_by_reserve ON recoup (coin_pub ,h_blind_ev @@ -340,13 +340,13 @@ CREATE TABLE IF NOT EXISTS recoup_refresh ,timestamp INT8 NOT NULL ,h_blind_ev BYTEA NOT NULL REFERENCES refresh_revealed_coins (h_coin_ev) ON DELETE CASCADE ); -CREATE INDEX recoup_refresh_by_coin_index +CREATE INDEX IF NOT EXISTS recoup_refresh_by_coin_index ON recoup_refresh (coin_pub); -CREATE INDEX recoup_refresh_by_h_blind_ev +CREATE INDEX IF NOT EXISTS recoup_refresh_by_h_blind_ev ON recoup_refresh (h_blind_ev); -CREATE INDEX recoup_refresh_for_by_reserve +CREATE INDEX IF NOT EXISTS recoup_refresh_for_by_reserve ON recoup_refresh (coin_pub ,h_blind_ev @@ -360,7 +360,7 @@ CREATE TABLE IF NOT EXISTS prewire ,buf BYTEA NOT NULL ); -- Index for wire_prepare_data_get and gc_prewire statement -CREATE INDEX prepare_iteration_index +CREATE INDEX IF NOT EXISTS prepare_iteration_index ON prewire (finished); diff --git a/src/exchangedb/exchangedb_plugin.c b/src/exchangedb/exchangedb_plugin.c index 8e61f860b..f4c2eea99 100644 --- a/src/exchangedb/exchangedb_plugin.c +++ b/src/exchangedb/exchangedb_plugin.c @@ -35,7 +35,6 @@ TALER_EXCHANGEDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg) { char *plugin_name; char *lib_name; - struct GNUNET_CONFIGURATION_Handle *cfg_dup; struct TALER_EXCHANGEDB_Plugin *plugin; if (GNUNET_SYSERR == @@ -53,13 +52,12 @@ TALER_EXCHANGEDB_plugin_load (const struct GNUNET_CONFIGURATION_Handle *cfg) "libtaler_plugin_exchangedb_%s", plugin_name); GNUNET_free (plugin_name); - cfg_dup = GNUNET_CONFIGURATION_dup (cfg); - plugin = GNUNET_PLUGIN_load (lib_name, cfg_dup); + plugin = GNUNET_PLUGIN_load (lib_name, + (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/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 4d0b1bb6a..9df2fe770 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -109,10 +109,9 @@ struct PostgresClosure pthread_key_t db_conn_threadlocal; /** - * Database connection string, as read from - * the configuration. + * Our configuration. */ - char *connection_cfg_str; + const struct GNUNET_CONFIGURATION_Handle *cfg; /** * Directory with SQL statements to run to create tables. @@ -158,16 +157,12 @@ postgres_drop_tables (void *cls) { struct PostgresClosure *pc = cls; struct GNUNET_PQ_Context *conn; - char *drop_dir; - - GNUNET_asprintf (&drop_dir, - "%sdrop", - pc->sql_dir); - conn = GNUNET_PQ_connect (pc->connection_cfg_str, - drop_dir, - NULL, - NULL); - GNUNET_free (drop_dir); + + conn = GNUNET_PQ_connect_with_cfg (pc->cfg, + "exchangedb-postgres", + "drop", + NULL, + NULL); if (NULL == conn) return GNUNET_SYSERR; GNUNET_PQ_disconnect (conn); @@ -187,10 +182,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, + "exchangedb-postgres", + "exchange-", + NULL, + NULL); if (NULL == conn) return GNUNET_SYSERR; GNUNET_PQ_disconnect (conn); @@ -1387,10 +1383,11 @@ postgres_get_session (void *cls) GNUNET_PQ_PREPARED_STATEMENT_END }; - db_conn = GNUNET_PQ_connect (pc->connection_cfg_str, - NULL, - es, - ps); + db_conn = GNUNET_PQ_connect_with_cfg (pc->cfg, + "exchangedb-postgres", + NULL, + es, + ps); } if (NULL == db_conn) return NULL; @@ -5371,10 +5368,11 @@ postgres_gc (void *cls) GNUNET_PQ_PREPARED_STATEMENT_END }; - conn = GNUNET_PQ_connect (pg->connection_cfg_str, - NULL, - NULL, - ps); + conn = GNUNET_PQ_connect_with_cfg (pg->cfg, + "exchangedb-postgres", + NULL, + NULL, + ps); } if (NULL == conn) return GNUNET_SYSERR; @@ -7212,12 +7210,12 @@ postgres_select_deposits_missing_wire (void *cls, void * libtaler_plugin_exchangedb_postgres_init (void *cls) { - struct GNUNET_CONFIGURATION_Handle *cfg = cls; + const struct GNUNET_CONFIGURATION_Handle *cfg = cls; struct PostgresClosure *pg; struct TALER_EXCHANGEDB_Plugin *plugin; - const char *ec; pg = GNUNET_new (struct PostgresClosure); + pg->cfg = cfg; pg->main_self = pthread_self (); /* loaded while single-threaded! */ if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_filename (cfg, @@ -7239,28 +7237,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) GNUNET_free (pg); return NULL; } - ec = getenv ("TALER_EXCHANGEDB_POSTGRES_CONFIG"); - if (NULL != ec) - { - pg->connection_cfg_str = GNUNET_strdup (ec); - } - else - { - if (GNUNET_OK != - GNUNET_CONFIGURATION_get_value_string (cfg, - "exchangedb-postgres", - "CONFIG", - &pg->connection_cfg_str)) - { - GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, - "exchangedb-postgres", - "CONFIG"); - GNUNET_free (pg->sql_dir); - GNUNET_free (pg); - return NULL; - } - } - if ( (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "exchangedb", @@ -7276,7 +7252,6 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, "exchangedb", "LEGAL/IDLE_RESERVE_EXPIRATION_TIME"); - GNUNET_free (pg->connection_cfg_str); GNUNET_free (pg->sql_dir); GNUNET_free (pg); return NULL; @@ -7290,7 +7265,6 @@ libtaler_plugin_exchangedb_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; @@ -7406,7 +7380,6 @@ libtaler_plugin_exchangedb_postgres_done (void *cls) /* If we launched a session for the main thread, kill it here before we unload */ db_conn_destroy (pg->main_session); - GNUNET_free (pg->connection_cfg_str); GNUNET_free (pg->sql_dir); GNUNET_free (pg->currency); GNUNET_free (pg); |