From 28c3ae47de7428b4f7019db9158390f8d14ca93d Mon Sep 17 00:00:00 2001 From: Joseph Date: Fri, 6 Jan 2023 11:15:32 -0500 Subject: [PATCH] try batch1 with cursor --- .../exchange_do_batch_reserves_in_insert.sql | 20 ++++++++++++------- src/exchangedb/pg_batch2_reserves_in_insert.c | 2 +- src/exchangedb/test_exchangedb_by_j.c | 2 +- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/exchangedb/exchange_do_batch_reserves_in_insert.sql b/src/exchangedb/exchange_do_batch_reserves_in_insert.sql index d1cc35d3e..c95f75c3c 100644 --- a/src/exchangedb/exchange_do_batch_reserves_in_insert.sql +++ b/src/exchangedb/exchange_do_batch_reserves_in_insert.sql @@ -36,6 +36,8 @@ DECLARE curs refcursor; DECLARE i RECORD; +DECLARE + curs_trans refcursor; BEGIN ruuid= 0; out_reserve_found = TRUE; @@ -79,6 +81,8 @@ transaction_duplicate= TRUE; CLOSE curs; PERFORM pg_notify(in_notify, NULL); + OPEN curs_trans FOR + WITH reserve_transaction AS( INSERT INTO reserves_in (reserve_pub ,wire_reference @@ -95,16 +99,18 @@ transaction_duplicate= TRUE; ,in_exchange_account_name ,in_wire_source_h_payto ,in_expiration_date) - ON CONFLICT DO NOTHING; + ON CONFLICT DO NOTHING + RETURNING reserve_pub) + SELECT * FROM reserve_transaction; + FETCH FROM curs_trans INTO i; IF FOUND THEN + IF i.reserve_pub = in_reserve_pub + THEN -- HAPPY PATH THERE IS NO DUPLICATE TRANS - transaction_duplicate = FALSE; - ELSE - -- Unhappy... - RAISE EXCEPTION 'Reserve did not exist, but INSERT into reserves_in gave conflict'; - transaction_duplicate = TRUE; --- ROLLBACK; + transaction_duplicate = FALSE; + END IF; END IF; + CLOSE curs_trans; RETURN; END $$; diff --git a/src/exchangedb/pg_batch2_reserves_in_insert.c b/src/exchangedb/pg_batch2_reserves_in_insert.c index e0208f094..1ef9045da 100644 --- a/src/exchangedb/pg_batch2_reserves_in_insert.c +++ b/src/exchangedb/pg_batch2_reserves_in_insert.c @@ -817,7 +817,7 @@ TEH_PG_batch2_reserves_in_insert (void *cls, } need_update |= conflicts[i]; t_duplicate |= transaction_duplicate[i]; - // fprintf(stdout, "reserve uuid : %ld c :%d t:%d\n", reserve_uuid[i], conflicts[i], transaction_duplicate[i]); + // fprintf(stdout, "reserve uuid : %ld c :%d t:%d\n", reserve_uuid[i], conflicts[i], transaction_duplicate[i]); i += 1; break; case 0: diff --git a/src/exchangedb/test_exchangedb_by_j.c b/src/exchangedb/test_exchangedb_by_j.c index 533871cca..9769d964b 100644 --- a/src/exchangedb/test_exchangedb_by_j.c +++ b/src/exchangedb/test_exchangedb_by_j.c @@ -107,7 +107,7 @@ run (void *cls) const char *sndr = "payto://x-taler-bank/localhost:8080/1"; struct TALER_Amount value; unsigned int batch_size = batches[i]; - unsigned int iterations = 10000;//1024*10; + unsigned int iterations = 16;//1024*10; struct TALER_ReservePublicKeyP reserve_pubs[iterations]; struct GNUNET_TIME_Absolute now; struct GNUNET_TIME_Timestamp ts;