From b9ccfbd66b192e11766f4129bae65c16fddffc5a Mon Sep 17 00:00:00 2001 From: Joseph Date: Fri, 18 Nov 2022 11:18:45 -0500 Subject: some modifications, there is one error which display (no function matches the given name and argument types) --- .../perf_exchangedb_reserves_in_insert.c | 195 +++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 src/exchangedb/perf_exchangedb_reserves_in_insert.c (limited to 'src/exchangedb/perf_exchangedb_reserves_in_insert.c') diff --git a/src/exchangedb/perf_exchangedb_reserves_in_insert.c b/src/exchangedb/perf_exchangedb_reserves_in_insert.c new file mode 100644 index 00000000..6c91b6bc --- /dev/null +++ b/src/exchangedb/perf_exchangedb_reserves_in_insert.c @@ -0,0 +1,195 @@ +/* + This file is part of TALER + Copyright (C) 2014-2022 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 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 + TALER; see the file COPYING. If not, see +*/ +/** + * @file exchangedb/test_exchangedb_by_j.c + * @brief test cases for DB interaction functions + * @author Joseph Xu + */ +#include "platform.h" +#include "taler_exchangedb_lib.h" +#include "taler_json_lib.h" +#include "taler_exchangedb_plugin.h" + +/** + * Global result from the testcase. + */ +static int result; + +/** + * Report line of error if @a cond is true, and jump to label "drop". + */ +#define FAILIF(cond) \ + do { \ + if (! (cond)) { break;} \ + GNUNET_break (0); \ + goto drop; \ + } while (0) + + +/** + * Initializes @a ptr with random data. + */ +#define RND_BLK(ptr) \ + GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_WEAK, ptr, sizeof (*ptr)) + +/** + * Initializes @a ptr with zeros. + */ +#define ZR_BLK(ptr) \ + memset (ptr, 0, sizeof (*ptr)) + + +/** + * Currency we use. Must match test-exchange-db-*.conf. + */ +#define CURRENCY "EUR" + +/** + * Database plugin under test. + */ +static struct TALER_EXCHANGEDB_Plugin *plugin; + + +/** + * Main function that will be run by the scheduler. + * + * @param cls closure with config + */ +static void +run (void *cls) +{ + struct GNUNET_CONFIGURATION_Handle *cfg = cls; + const uint32_t num_partitions = 10; + + if (NULL == + (plugin = TALER_EXCHANGEDB_plugin_load (cfg))) + { + GNUNET_break (0); + result = 77; + return; + } + (void) plugin->drop_tables (plugin->cls); + if (GNUNET_OK != + plugin->create_tables (plugin->cls)) + { + GNUNET_break (0); + result = 77; + goto cleanup; + } + if (GNUNET_OK != + plugin->setup_partitions (plugin->cls, + num_partitions)) + { + GNUNET_break (0); + result = 77; + goto cleanup; + } + + for (unsigned int i = 0; i< 8; i++) + { + static unsigned int batches[] = {1, 1, 0, 2, 4, 16, 64, 256}; + const char *sndr = "payto://x-taler-bank/localhost:8080/1"; + struct TALER_Amount value; + unsigned int batch_size = batches[i]; + struct GNUNET_TIME_Absolute now; + struct GNUNET_TIME_Timestamp ts; + struct GNUNET_TIME_Relative duration; + struct TALER_ReservePublicKeyP reserve_pub; + + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":1.000010", + &value)); + now = GNUNET_TIME_absolute_get (); + ts = GNUNET_TIME_timestamp_get (); + plugin->start (plugin->cls, + "test_by_exchange_j"); + for (unsigned int k = 0; kreserves_in_insert (plugin->cls, + &reserve_pub, + &value, + ts, + sndr, + "section", + 4)); + } + plugin->commit (plugin->cls); + duration = GNUNET_TIME_absolute_get_duration (now); + fprintf (stdout, + "for a batchsize equal to %d it took %s\n", + batch_size, + GNUNET_STRINGS_relative_time_to_string (duration, + GNUNET_NO) ); + } +drop: + GNUNET_break (GNUNET_OK == + plugin->drop_tables (plugin->cls)); +cleanup: + TALER_EXCHANGEDB_plugin_unload (plugin); + plugin = NULL; +} + + +int +main (int argc, + char *const argv[]) +{ + const char *plugin_name; + char *config_filename; + char *testname; + struct GNUNET_CONFIGURATION_Handle *cfg; + + (void) argc; + result = -1; + if (NULL == (plugin_name = strrchr (argv[0], (int) '-'))) + { + GNUNET_break (0); + return -1; + } + GNUNET_log_setup (argv[0], + "WARNING", + NULL); + plugin_name++; + (void) GNUNET_asprintf (&testname, + "test-exchange-db-%s", + plugin_name); + (void) GNUNET_asprintf (&config_filename, + "%s.conf", + testname); + fprintf (stdout, + "Using config: %s\n", + config_filename); + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_OK != + GNUNET_CONFIGURATION_parse (cfg, + config_filename)) + { + GNUNET_break (0); + GNUNET_free (config_filename); + GNUNET_free (testname); + return 2; + } + GNUNET_SCHEDULER_run (&run, + cfg); + GNUNET_CONFIGURATION_destroy (cfg); + GNUNET_free (config_filename); + GNUNET_free (testname); + return result; +} + +/* end of test_exchangedb_by_j.c */ -- cgit v1.2.3 From eba2a5d90c1dbc2e5121e404ac4154dc70d9cace Mon Sep 17 00:00:00 2001 From: Joseph Date: Mon, 21 Nov 2022 10:37:50 -0500 Subject: new batch insertion code --- .../perf_exchangedb_reserves_in_insert.c | 4 ++ src/exchangedb/pg_batch_reserves_in_insert.c | 64 +++++++++++----------- src/exchangedb/test-exchange-db-postgres.conf | 2 +- src/exchangedb/test_exchangedb_by_j.c | 10 +++- 4 files changed, 43 insertions(+), 37 deletions(-) (limited to 'src/exchangedb/perf_exchangedb_reserves_in_insert.c') diff --git a/src/exchangedb/perf_exchangedb_reserves_in_insert.c b/src/exchangedb/perf_exchangedb_reserves_in_insert.c index 6c91b6bc..9a0ec094 100644 --- a/src/exchangedb/perf_exchangedb_reserves_in_insert.c +++ b/src/exchangedb/perf_exchangedb_reserves_in_insert.c @@ -114,6 +114,8 @@ run (void *cls) &value)); now = GNUNET_TIME_absolute_get (); ts = GNUNET_TIME_timestamp_get (); + for (unsigned int r=0;r<10;r++) + { plugin->start (plugin->cls, "test_by_exchange_j"); for (unsigned int k = 0; kcommit (plugin->cls); + } duration = GNUNET_TIME_absolute_get_duration (now); fprintf (stdout, "for a batchsize equal to %d it took %s\n", @@ -136,6 +139,7 @@ run (void *cls) GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO) ); } + result = 0; drop: GNUNET_break (GNUNET_OK == plugin->drop_tables (plugin->cls)); diff --git a/src/exchangedb/pg_batch_reserves_in_insert.c b/src/exchangedb/pg_batch_reserves_in_insert.c index fd056e0c..4a1a2792 100644 --- a/src/exchangedb/pg_batch_reserves_in_insert.c +++ b/src/exchangedb/pg_batch_reserves_in_insert.c @@ -62,13 +62,12 @@ notify_on_reserve (struct PostgresClosure *pg, enum GNUNET_DB_QueryStatus TEH_PG_batch_reserves_in_insert (void *cls, - const struct TALER_EXCHANGEDB_ReserveInInfo *reserves, - unsigned int reserves_length, - enum GNUNET_DB_QueryStatus *results) + const struct TALER_EXCHANGEDB_ReserveInInfo *reserves, + unsigned int reserves_length, + enum GNUNET_DB_QueryStatus *results) { struct PostgresClosure *pg = cls; enum GNUNET_DB_QueryStatus qs1; - struct TALER_EXCHANGEDB_Reserve reserve; struct GNUNET_TIME_Timestamp expiry; struct GNUNET_TIME_Timestamp gc; struct TALER_PaytoHashP h_payto; @@ -78,7 +77,14 @@ TEH_PG_batch_reserves_in_insert (void *cls, struct GNUNET_TIME_Timestamp reserve_expiration = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time); - reserve.pub = reserves->reserve_pub; + PREPARE (pg, + "reserve_create", + "SELECT " + "out_reserve_found AS conflicted" + ",transaction_duplicate" + ",ruuid AS reserve_uuid" + " FROM batch_reserves_in" + " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);"); expiry = GNUNET_TIME_absolute_to_timestamp ( GNUNET_TIME_absolute_add (reserves->execution_time.abs_time, pg->idle_reserve_expiration_time)); @@ -95,21 +101,22 @@ TEH_PG_batch_reserves_in_insert (void *cls, time; we do this before adding the actual transaction to "reserves_in", as for a new reserve it can't be a duplicate 'add' operation, and as the 'add' operation needs the reserve entry as a foreign key. */ + for (unsigned int i=0;ireserve_pub), /*$1*/ + GNUNET_PQ_query_param_auto_from_type (&reserve->reserve_pub), /*$1*/ GNUNET_PQ_query_param_timestamp (&expiry), /*$4*/ GNUNET_PQ_query_param_timestamp (&gc), /*$5*/ - GNUNET_PQ_query_param_uint64 (&reserves->wire_reference), /*6*/ - TALER_PQ_query_param_amount (&reserves->balance), /*7+8*/ - GNUNET_PQ_query_param_string (reserves->exchange_account_name), /*9*/ - GNUNET_PQ_query_param_timestamp (&reserves->execution_time), /*10*/ + GNUNET_PQ_query_param_uint64 (&reserve->wire_reference), /*6*/ + TALER_PQ_query_param_amount (&reserve->balance), /*7+8*/ + GNUNET_PQ_query_param_string (reserve->exchange_account_name), /*9*/ + GNUNET_PQ_query_param_timestamp (&reserve->execution_time), /*10*/ GNUNET_PQ_query_param_auto_from_type (&h_payto), /*11*/ - GNUNET_PQ_query_param_string (reserves->sender_account_details),/*12*/ + GNUNET_PQ_query_param_string (reserve->sender_account_details),/*12*/ GNUNET_PQ_query_param_timestamp (&reserve_expiration),/*13*/ GNUNET_PQ_query_param_end }; - /* We should get all our results into results[]*/ struct GNUNET_PQ_ResultSpec rs[] = { GNUNET_PQ_result_spec_uint64 ("reserve_uuid", @@ -121,32 +128,23 @@ TEH_PG_batch_reserves_in_insert (void *cls, GNUNET_PQ_result_spec_end }; - - GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Reserve does not exist; creating a new one\n"); + TALER_payto_hash (reserve->sender_account_details, + &h_payto); /* Note: query uses 'on conflict do nothing' */ - PREPARE (pg, - "reserve_create", - "SELECT " - "out_reserve_found AS conflicted" - ",transaction_duplicate" - ",ruuid AS reserve_uuid" - " FROM batch_reserves_in" - " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);"); - qs1 = GNUNET_PQ_eval_prepared_singleton_select (pg->conn, "reserve_create", params, rs); - - if (qs1 < 0) - return qs1; + return qs1; + notify_on_reserve (pg, + &reserve->reserve_pub); + GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs1); + results[i] = (transaction_duplicate) + ? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS + : GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; + if ( (! conflicted) && transaction_duplicate) + TEH_PG_rollback(pg); } - if ((int)conflicted == 0 && (int)transaction_duplicate == 1) - TEH_PG_rollback(pg); - notify_on_reserve (pg, - &reserves->reserve_pub); - - return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT; + return reserves_length; } diff --git a/src/exchangedb/test-exchange-db-postgres.conf b/src/exchangedb/test-exchange-db-postgres.conf index 05104cb7..92bdde39 100644 --- a/src/exchangedb/test-exchange-db-postgres.conf +++ b/src/exchangedb/test-exchange-db-postgres.conf @@ -7,7 +7,7 @@ BASE_URL = http://localhost/ [exchangedb-postgres] #The connection string the plugin has to use for connecting to the database -CONFIG = postgres:///talercheck +CONFIG = postgres://dab:test@localhost/talercheck # Where are the SQL files to setup our tables? SQL_DIR = $DATADIR/sql/exchange/ diff --git a/src/exchangedb/test_exchangedb_by_j.c b/src/exchangedb/test_exchangedb_by_j.c index 831416b4..b2f6ddeb 100644 --- a/src/exchangedb/test_exchangedb_by_j.c +++ b/src/exchangedb/test_exchangedb_by_j.c @@ -114,8 +114,10 @@ run (void *cls) &value)); now = GNUNET_TIME_absolute_get (); ts = GNUNET_TIME_timestamp_get (); - plugin->start (plugin->cls, - "test_by_j"); + for (unsigned int r=0;r<10;r++) + { + plugin->start_read_committed (plugin->cls, + "test_by_j"); for (unsigned int k = 0; kbatch_reserves_in_insert (plugin->cls, reserves, batch_size, results)); plugin->commit (plugin->cls); + } duration = GNUNET_TIME_absolute_get_duration (now); fprintf (stdout, "for a batchsize equal to %d it took %s\n", @@ -141,6 +144,7 @@ run (void *cls) GNUNET_STRINGS_relative_time_to_string (duration, GNUNET_NO) ); } + result = 0; drop: GNUNET_break (GNUNET_OK == plugin->drop_tables (plugin->cls)); -- cgit v1.2.3