From c86c92200c331f0099ab95edd35b9f73c177b72b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 27 Nov 2022 21:43:55 +0100 Subject: -db tests pass again --- src/exchangedb/0002-deposits.sql | 8 +-- src/exchangedb/0002-reserves_out.sql | 20 +++++++- src/exchangedb/exchange-0001.sql | 11 ++-- .../perf_exchangedb_reserves_in_insert.c | 46 ++++++++--------- src/exchangedb/test_exchangedb.c | 10 ++-- src/exchangedb/test_exchangedb_by_j.c | 58 ++++++++++------------ 6 files changed, 77 insertions(+), 76 deletions(-) (limited to 'src/exchangedb') diff --git a/src/exchangedb/0002-deposits.sql b/src/exchangedb/0002-deposits.sql index 679103c45..92210afa3 100644 --- a/src/exchangedb/0002-deposits.sql +++ b/src/exchangedb/0002-deposits.sql @@ -404,22 +404,22 @@ INSERT INTO exchange_tables ,'exchange-0002' ,'create' ,TRUE - ,FALSE), + ,TRUE), ('deposits_by_ready' ,'exchange-0002' ,'constrain' ,TRUE - ,FALSE), + ,TRUE), ('deposits_for_matching' ,'exchange-0002' ,'create' ,TRUE - ,FALSE), + ,TRUE), ('deposits_for_matching' ,'exchange-0002' ,'constrain' ,TRUE - ,FALSE), + ,TRUE), ('deposits' ,'exchange-0002' ,'master' diff --git a/src/exchangedb/0002-reserves_out.sql b/src/exchangedb/0002-reserves_out.sql index 77112f504..25d717a52 100644 --- a/src/exchangedb/0002-reserves_out.sql +++ b/src/exchangedb/0002-reserves_out.sql @@ -132,14 +132,25 @@ BEGIN ,table_name ,partition_suffix ); +END $$; + + +CREATE FUNCTION constrain_table_reserves_out_by_reserve( + IN partition_suffix VARCHAR DEFAULT NULL +) +RETURNS VOID +LANGUAGE plpgsql +AS $$ +DECLARE + table_name VARCHAR DEFAULT 'reserves_out_by_reserve'; +BEGIN table_name = concat_ws('_', table_name, partition_suffix); EXECUTE FORMAT ( 'CREATE INDEX ' || table_name || '_main_index ' 'ON ' || table_name || ' ' '(reserve_uuid);' ); -END -$$; +END $$; CREATE FUNCTION reserves_out_by_reserve_insert_trigger() @@ -217,6 +228,11 @@ INSERT INTO exchange_tables ,'create' ,TRUE ,FALSE), + ('reserves_out_by_reserve' + ,'exchange-0002' + ,'constrain' + ,TRUE + ,FALSE), ('reserves_out' ,'exchange-0002' ,'master' diff --git a/src/exchangedb/exchange-0001.sql b/src/exchangedb/exchange-0001.sql index 49b5f8b78..5ce38c286 100644 --- a/src/exchangedb/exchange-0001.sql +++ b/src/exchangedb/exchange-0001.sql @@ -177,7 +177,7 @@ BEGIN 'SELECT exchange.%s_table_%s (%s)'::text ,rec.action ,rec.name - ,0 + ,quote_literal('0') ); IF (rec.by_range OR (num_partitions = 0)) @@ -189,7 +189,7 @@ BEGIN EXECUTE FORMAT( 'CREATE TABLE exchange.%s_default' ' PARTITION OF %s' - ' FOR DEFAULT' + ' DEFAULT' ,rec.name ,rec.name ); @@ -238,14 +238,15 @@ BEGIN ,rec.name ); ELSE - IF (num_partitions = 0) + IF ( (num_partitions = 0) OR + (rec.by_range) ) THEN -- Constrain default table EXECUTE FORMAT( 'SELECT exchange.%s_table_%s (%s)'::text ,rec.action ,rec.name - ,'default' + ,quote_literal('default') ); ELSE -- Constrain each partition @@ -254,7 +255,7 @@ BEGIN 'SELECT exchange.%s_table_%s (%s)'::text ,rec.action ,rec.name - ,i + ,quote_literal(i) ); END LOOP; END IF; diff --git a/src/exchangedb/perf_exchangedb_reserves_in_insert.c b/src/exchangedb/perf_exchangedb_reserves_in_insert.c index 9a0ec0944..fc2a00089 100644 --- a/src/exchangedb/perf_exchangedb_reserves_in_insert.c +++ b/src/exchangedb/perf_exchangedb_reserves_in_insert.c @@ -83,21 +83,14 @@ run (void *cls) } (void) plugin->drop_tables (plugin->cls); if (GNUNET_OK != - plugin->create_tables (plugin->cls)) + plugin->create_tables (plugin->cls, + true, + num_partitions)) { 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}; @@ -114,23 +107,23 @@ 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; kreserves_in_insert (plugin->cls, - &reserve_pub, - &value, - ts, - sndr, - "section", - 4)); - } - plugin->commit (plugin->cls); + 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, @@ -196,4 +189,5 @@ main (int argc, return result; } + /* end of test_exchangedb_by_j.c */ diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 111ee9365..eb258f002 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -1245,13 +1245,9 @@ run (void *cls) } (void) plugin->drop_tables (plugin->cls); if (GNUNET_OK != - plugin->create_tables (plugin->cls)) - { - result = 77; - goto cleanup; - } - if (GNUNET_OK != - plugin->setup_partitions (plugin->cls, num_partitions)) + plugin->create_tables (plugin->cls, + true, + num_partitions)) { result = 77; goto cleanup; diff --git a/src/exchangedb/test_exchangedb_by_j.c b/src/exchangedb/test_exchangedb_by_j.c index b2f6ddeb5..43f471671 100644 --- a/src/exchangedb/test_exchangedb_by_j.c +++ b/src/exchangedb/test_exchangedb_by_j.c @@ -33,7 +33,7 @@ static int result; */ #define FAILIF(cond) \ do { \ - if (! (cond)) {break;} \ + if (! (cond)) {break;} \ GNUNET_break (0); \ goto drop; \ } while (0) @@ -83,21 +83,14 @@ run (void *cls) } (void) plugin->drop_tables (plugin->cls); if (GNUNET_OK != - plugin->create_tables (plugin->cls)) + plugin->create_tables (plugin->cls, + true, + num_partitions)) { 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< 7; i++) { static unsigned int batches[] = {1, 1, 2, 4, 16, 64, 256}; @@ -114,28 +107,28 @@ run (void *cls) &value)); now = GNUNET_TIME_absolute_get (); ts = GNUNET_TIME_timestamp_get (); - for (unsigned int r=0;r<10;r++) + 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); + 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, @@ -201,4 +194,5 @@ main (int argc, return result; } + /* end of test_exchangedb_by_j.c */ -- cgit v1.2.3