-debugging batch reserves_in notification logic: success: pg_notify does not work, identifier vs. string

This commit is contained in:
Christian Grothoff 2023-02-05 21:59:41 +01:00
parent f079cff4ae
commit 6d3efbe900
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
6 changed files with 62 additions and 37 deletions

View File

@ -25,7 +25,7 @@ DECLARE
BEGIN BEGIN
PERFORM create_partitioned_table( PERFORM create_partitioned_table(
'CREATE TABLE %I' 'CREATE TABLE %I'
'(reserve_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY' '(reserve_in_serial_id BIGINT GENERATED BY DEFAULT AS IDENTITY'
',reserve_pub BYTEA PRIMARY KEY' ',reserve_pub BYTEA PRIMARY KEY'
',wire_reference INT8 NOT NULL' ',wire_reference INT8 NOT NULL'
',credit_val INT8 NOT NULL' ',credit_val INT8 NOT NULL'

View File

@ -21,7 +21,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch2_reserves_insert(
IN in_credit_val INT8, IN in_credit_val INT8,
IN in_credit_frac INT4, IN in_credit_frac INT4,
IN in_exchange_account_name VARCHAR, IN in_exchange_account_name VARCHAR,
IN in_exectution_date INT8, IN in_execution_date INT8,
IN in_wire_source_h_payto BYTEA, ---h_payto IN in_wire_source_h_payto BYTEA, ---h_payto
IN in_payto_uri VARCHAR, IN in_payto_uri VARCHAR,
IN in_reserve_expiration INT8, IN in_reserve_expiration INT8,
@ -32,7 +32,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch2_reserves_insert(
IN in2_credit_val INT8, IN in2_credit_val INT8,
IN in2_credit_frac INT4, IN in2_credit_frac INT4,
IN in2_exchange_account_name VARCHAR, IN in2_exchange_account_name VARCHAR,
IN in2_exectution_date INT8, IN in2_execution_date INT8,
IN in2_wire_source_h_payto BYTEA, ---h_payto IN in2_wire_source_h_payto BYTEA, ---h_payto
IN in2_payto_uri VARCHAR, IN in2_payto_uri VARCHAR,
IN in2_reserve_expiration INT8, IN in2_reserve_expiration INT8,
@ -116,6 +116,7 @@ BEGIN
END LOOP; END LOOP;
CLOSE curs_reserve_exist; CLOSE curs_reserve_exist;
-- FIXME: must be changed to EXECUTE FORMAT!
PERFORM pg_notify(in_notify, NULL); PERFORM pg_notify(in_notify, NULL);
PERFORM pg_notify(in2_notify, NULL); PERFORM pg_notify(in2_notify, NULL);
@ -136,14 +137,14 @@ BEGIN
,in_credit_frac ,in_credit_frac
,in_exchange_account_name ,in_exchange_account_name
,in_wire_source_h_payto ,in_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in2_reserve_pub (in2_reserve_pub
,in2_wire_ref ,in2_wire_ref
,in2_credit_val ,in2_credit_val
,in2_credit_frac ,in2_credit_frac
,in2_exchange_account_name ,in2_exchange_account_name
,in2_wire_source_h_payto ,in2_wire_source_h_payto
,in_expiration_date) ,in_execution_date)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
RETURNING reserve_pub) RETURNING reserve_pub)
SELECT * FROM reserve_in_exist; SELECT * FROM reserve_in_exist;
@ -181,4 +182,3 @@ BEGIN
CLOSE curs_transaction_exist; CLOSE curs_transaction_exist;
RETURN; RETURN;
END $$; END $$;

View File

@ -21,7 +21,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch4_reserves_insert(
IN in_credit_val INT8, IN in_credit_val INT8,
IN in_credit_frac INT4, IN in_credit_frac INT4,
IN in_exchange_account_name VARCHAR, IN in_exchange_account_name VARCHAR,
IN in_exectution_date INT8, IN in_execution_date INT8,
IN in_wire_source_h_payto BYTEA, ---h_payto IN in_wire_source_h_payto BYTEA, ---h_payto
IN in_payto_uri VARCHAR, IN in_payto_uri VARCHAR,
IN in_reserve_expiration INT8, IN in_reserve_expiration INT8,
@ -34,7 +34,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch4_reserves_insert(
IN in2_credit_val INT8, IN in2_credit_val INT8,
IN in2_credit_frac INT4, IN in2_credit_frac INT4,
IN in2_exchange_account_name VARCHAR, IN in2_exchange_account_name VARCHAR,
IN in2_exectution_date INT8, IN in2_execution_date INT8,
IN in2_wire_source_h_payto BYTEA, ---h_payto IN in2_wire_source_h_payto BYTEA, ---h_payto
IN in2_payto_uri VARCHAR, IN in2_payto_uri VARCHAR,
IN in2_reserve_expiration INT8, IN in2_reserve_expiration INT8,
@ -43,7 +43,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch4_reserves_insert(
IN in3_credit_val INT8, IN in3_credit_val INT8,
IN in3_credit_frac INT4, IN in3_credit_frac INT4,
IN in3_exchange_account_name VARCHAR, IN in3_exchange_account_name VARCHAR,
IN in3_exectution_date INT8, IN in3_execution_date INT8,
IN in3_wire_source_h_payto BYTEA, ---h_payto IN in3_wire_source_h_payto BYTEA, ---h_payto
IN in3_payto_uri VARCHAR, IN in3_payto_uri VARCHAR,
IN in3_reserve_expiration INT8, IN in3_reserve_expiration INT8,
@ -52,7 +52,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch4_reserves_insert(
IN in4_credit_val INT8, IN in4_credit_val INT8,
IN in4_credit_frac INT4, IN in4_credit_frac INT4,
IN in4_exchange_account_name VARCHAR, IN in4_exchange_account_name VARCHAR,
IN in4_exectution_date INT8, IN in4_execution_date INT8,
IN in4_wire_source_h_payto BYTEA, ---h_payto IN in4_wire_source_h_payto BYTEA, ---h_payto
IN in4_payto_uri VARCHAR, IN in4_payto_uri VARCHAR,
IN in4_reserve_expiration INT8, IN in4_reserve_expiration INT8,
@ -196,6 +196,7 @@ BEGIN
CLOSE curs_reserve_exist; CLOSE curs_reserve_exist;
-- FIXME: must be changed to EXECUTE FORMAT!
PERFORM pg_notify(in_notify, NULL); PERFORM pg_notify(in_notify, NULL);
PERFORM pg_notify(in2_notify, NULL); PERFORM pg_notify(in2_notify, NULL);
PERFORM pg_notify(in3_notify, NULL); PERFORM pg_notify(in3_notify, NULL);
@ -219,28 +220,28 @@ BEGIN
,in_credit_frac ,in_credit_frac
,in_exchange_account_name ,in_exchange_account_name
,in_wire_source_h_payto ,in_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in2_reserve_pub (in2_reserve_pub
,in2_wire_ref ,in2_wire_ref
,in2_credit_val ,in2_credit_val
,in2_credit_frac ,in2_credit_frac
,in2_exchange_account_name ,in2_exchange_account_name
,in2_wire_source_h_payto ,in2_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in3_reserve_pub (in3_reserve_pub
,in3_wire_ref ,in3_wire_ref
,in3_credit_val ,in3_credit_val
,in3_credit_frac ,in3_credit_frac
,in3_exchange_account_name ,in3_exchange_account_name
,in3_wire_source_h_payto ,in3_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in4_reserve_pub (in4_reserve_pub
,in4_wire_ref ,in4_wire_ref
,in4_credit_val ,in4_credit_val
,in4_credit_frac ,in4_credit_frac
,in4_exchange_account_name ,in4_exchange_account_name
,in4_wire_source_h_payto ,in4_wire_source_h_payto
,in_expiration_date) ,in_execution_date)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
RETURNING reserve_pub) RETURNING reserve_pub)
SELECT * FROM reserve_in_changes; SELECT * FROM reserve_in_changes;

View File

@ -21,7 +21,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch8_reserves_insert(
IN in_credit_val INT8, IN in_credit_val INT8,
IN in_credit_frac INT4, IN in_credit_frac INT4,
IN in_exchange_account_name VARCHAR, IN in_exchange_account_name VARCHAR,
IN in_exectution_date INT8, IN in_execution_date INT8,
IN in_wire_source_h_payto BYTEA, ---h_payto IN in_wire_source_h_payto BYTEA, ---h_payto
IN in_payto_uri VARCHAR, IN in_payto_uri VARCHAR,
IN in_reserve_expiration INT8, IN in_reserve_expiration INT8,
@ -38,7 +38,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch8_reserves_insert(
IN in2_credit_val INT8, IN in2_credit_val INT8,
IN in2_credit_frac INT4, IN in2_credit_frac INT4,
IN in2_exchange_account_name VARCHAR, IN in2_exchange_account_name VARCHAR,
IN in2_exectution_date INT8, IN in2_execution_date INT8,
IN in2_wire_source_h_payto BYTEA, ---h_payto IN in2_wire_source_h_payto BYTEA, ---h_payto
IN in2_payto_uri VARCHAR, IN in2_payto_uri VARCHAR,
IN in2_reserve_expiration INT8, IN in2_reserve_expiration INT8,
@ -47,7 +47,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch8_reserves_insert(
IN in3_credit_val INT8, IN in3_credit_val INT8,
IN in3_credit_frac INT4, IN in3_credit_frac INT4,
IN in3_exchange_account_name VARCHAR, IN in3_exchange_account_name VARCHAR,
IN in3_exectution_date INT8, IN in3_execution_date INT8,
IN in3_wire_source_h_payto BYTEA, ---h_payto IN in3_wire_source_h_payto BYTEA, ---h_payto
IN in3_payto_uri VARCHAR, IN in3_payto_uri VARCHAR,
IN in3_reserve_expiration INT8, IN in3_reserve_expiration INT8,
@ -56,7 +56,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch8_reserves_insert(
IN in4_credit_val INT8, IN in4_credit_val INT8,
IN in4_credit_frac INT4, IN in4_credit_frac INT4,
IN in4_exchange_account_name VARCHAR, IN in4_exchange_account_name VARCHAR,
IN in4_exectution_date INT8, IN in4_execution_date INT8,
IN in4_wire_source_h_payto BYTEA, ---h_payto IN in4_wire_source_h_payto BYTEA, ---h_payto
IN in4_payto_uri VARCHAR, IN in4_payto_uri VARCHAR,
IN in4_reserve_expiration INT8, IN in4_reserve_expiration INT8,
@ -65,7 +65,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch8_reserves_insert(
IN in5_credit_val INT8, IN in5_credit_val INT8,
IN in5_credit_frac INT4, IN in5_credit_frac INT4,
IN in5_exchange_account_name VARCHAR, IN in5_exchange_account_name VARCHAR,
IN in5_exectution_date INT8, IN in5_execution_date INT8,
IN in5_wire_source_h_payto BYTEA, ---h_payto IN in5_wire_source_h_payto BYTEA, ---h_payto
IN in5_payto_uri VARCHAR, IN in5_payto_uri VARCHAR,
IN in5_reserve_expiration INT8, IN in5_reserve_expiration INT8,
@ -74,7 +74,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch8_reserves_insert(
IN in6_credit_val INT8, IN in6_credit_val INT8,
IN in6_credit_frac INT4, IN in6_credit_frac INT4,
IN in6_exchange_account_name VARCHAR, IN in6_exchange_account_name VARCHAR,
IN in6_exectution_date INT8, IN in6_execution_date INT8,
IN in6_wire_source_h_payto BYTEA, ---h_payto IN in6_wire_source_h_payto BYTEA, ---h_payto
IN in6_payto_uri VARCHAR, IN in6_payto_uri VARCHAR,
IN in6_reserve_expiration INT8, IN in6_reserve_expiration INT8,
@ -83,7 +83,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch8_reserves_insert(
IN in7_credit_val INT8, IN in7_credit_val INT8,
IN in7_credit_frac INT4, IN in7_credit_frac INT4,
IN in7_exchange_account_name VARCHAR, IN in7_exchange_account_name VARCHAR,
IN in7_exectution_date INT8, IN in7_execution_date INT8,
IN in7_wire_source_h_payto BYTEA, ---h_payto IN in7_wire_source_h_payto BYTEA, ---h_payto
IN in7_payto_uri VARCHAR, IN in7_payto_uri VARCHAR,
IN in7_reserve_expiration INT8, IN in7_reserve_expiration INT8,
@ -92,7 +92,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch8_reserves_insert(
IN in8_credit_val INT8, IN in8_credit_val INT8,
IN in8_credit_frac INT4, IN in8_credit_frac INT4,
IN in8_exchange_account_name VARCHAR, IN in8_exchange_account_name VARCHAR,
IN in8_exectution_date INT8, IN in8_execution_date INT8,
IN in8_wire_source_h_payto BYTEA, ---h_payto IN in8_wire_source_h_payto BYTEA, ---h_payto
IN in8_payto_uri VARCHAR, IN in8_payto_uri VARCHAR,
IN in8_reserve_expiration INT8, IN in8_reserve_expiration INT8,
@ -369,6 +369,7 @@ BEGIN
CLOSE curs_reserve_existed; CLOSE curs_reserve_existed;
-- FIXME: must be changed to EXECUTE FORMAT!
PERFORM pg_notify(in_notify, NULL); PERFORM pg_notify(in_notify, NULL);
PERFORM pg_notify(in2_notify, NULL); PERFORM pg_notify(in2_notify, NULL);
PERFORM pg_notify(in3_notify, NULL); PERFORM pg_notify(in3_notify, NULL);
@ -395,56 +396,56 @@ BEGIN
,in_credit_frac ,in_credit_frac
,in_exchange_account_name ,in_exchange_account_name
,in_wire_source_h_payto ,in_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in2_reserve_pub (in2_reserve_pub
,in2_wire_ref ,in2_wire_ref
,in2_credit_val ,in2_credit_val
,in2_credit_frac ,in2_credit_frac
,in2_exchange_account_name ,in2_exchange_account_name
,in2_wire_source_h_payto ,in2_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in3_reserve_pub (in3_reserve_pub
,in3_wire_ref ,in3_wire_ref
,in3_credit_val ,in3_credit_val
,in3_credit_frac ,in3_credit_frac
,in3_exchange_account_name ,in3_exchange_account_name
,in3_wire_source_h_payto ,in3_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in4_reserve_pub (in4_reserve_pub
,in4_wire_ref ,in4_wire_ref
,in4_credit_val ,in4_credit_val
,in4_credit_frac ,in4_credit_frac
,in4_exchange_account_name ,in4_exchange_account_name
,in4_wire_source_h_payto ,in4_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in5_reserve_pub (in5_reserve_pub
,in5_wire_ref ,in5_wire_ref
,in5_credit_val ,in5_credit_val
,in5_credit_frac ,in5_credit_frac
,in5_exchange_account_name ,in5_exchange_account_name
,in5_wire_source_h_payto ,in5_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in6_reserve_pub (in6_reserve_pub
,in6_wire_ref ,in6_wire_ref
,in6_credit_val ,in6_credit_val
,in6_credit_frac ,in6_credit_frac
,in6_exchange_account_name ,in6_exchange_account_name
,in6_wire_source_h_payto ,in6_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in7_reserve_pub (in7_reserve_pub
,in7_wire_ref ,in7_wire_ref
,in7_credit_val ,in7_credit_val
,in7_credit_frac ,in7_credit_frac
,in7_exchange_account_name ,in7_exchange_account_name
,in7_wire_source_h_payto ,in7_wire_source_h_payto
,in_expiration_date), ,in_execution_date),
(in8_reserve_pub (in8_reserve_pub
,in8_wire_ref ,in8_wire_ref
,in8_credit_val ,in8_credit_val
,in8_credit_frac ,in8_credit_frac
,in8_exchange_account_name ,in8_exchange_account_name
,in8_wire_source_h_payto ,in8_wire_source_h_payto
,in_expiration_date) ,in_execution_date)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
RETURNING reserve_pub) RETURNING reserve_pub)
SELECT * FROM reserve_in_changes; SELECT * FROM reserve_in_changes;

View File

@ -22,7 +22,7 @@ CREATE OR REPLACE FUNCTION exchange_do_batch_reserves_in_insert(
IN in_credit_val INT8, IN in_credit_val INT8,
IN in_credit_frac INT4, IN in_credit_frac INT4,
IN in_exchange_account_name VARCHAR, IN in_exchange_account_name VARCHAR,
IN in_exectution_date INT8, IN in_execution_date INT8,
IN in_wire_source_h_payto BYTEA, ---h_payto IN in_wire_source_h_payto BYTEA, ---h_payto
IN in_payto_uri VARCHAR, IN in_payto_uri VARCHAR,
IN in_reserve_expiration INT8, IN in_reserve_expiration INT8,
@ -39,10 +39,11 @@ DECLARE
DECLARE DECLARE
curs_trans refcursor; curs_trans refcursor;
BEGIN BEGIN
ruuid= 0; ruuid = 0;
out_reserve_found = TRUE; out_reserve_found = TRUE;
transaction_duplicate= TRUE; transaction_duplicate = TRUE;
--SIMPLE INSERT ON CONFLICT DO NOTHING
--SIMPLE INSERT ON CONFLICT DO NOTHING
INSERT INTO wire_targets INSERT INTO wire_targets
(wire_target_h_payto (wire_target_h_payto
,payto_uri) ,payto_uri)
@ -97,7 +98,7 @@ transaction_duplicate= TRUE;
,in_credit_frac ,in_credit_frac
,in_exchange_account_name ,in_exchange_account_name
,in_wire_source_h_payto ,in_wire_source_h_payto
,in_expiration_date) ,in_execution_date)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING
RETURNING reserve_pub) RETURNING reserve_pub)
SELECT * FROM reserve_transaction; SELECT * FROM reserve_transaction;
@ -108,7 +109,9 @@ transaction_duplicate= TRUE;
THEN THEN
-- HAPPY PATH THERE IS NO DUPLICATE TRANS -- HAPPY PATH THERE IS NO DUPLICATE TRANS
transaction_duplicate = FALSE; transaction_duplicate = FALSE;
PERFORM pg_notify(in_notify, NULL); EXECUTE FORMAT (
'NOTIFY %s'
,in_notify);
END IF; END IF;
END IF; END IF;
CLOSE curs_trans; CLOSE curs_trans;

View File

@ -54,6 +54,25 @@ compute_notify_on_reserve (const struct TALER_ReservePublicKeyP *reserve_pub)
} }
static void
notify_on_reserve (struct PostgresClosure *pg,
const struct TALER_ReservePublicKeyP *reserve_pub)
{
struct TALER_ReserveEventP rep = {
.header.size = htons (sizeof (rep)),
.header.type = htons (TALER_DBEVENT_EXCHANGE_RESERVE_INCOMING),
.reserve_pub = *reserve_pub
};
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"Notifying on reserve!\n");
TEH_PG_event_notify (pg,
&rep.header,
NULL,
0);
}
static enum GNUNET_DB_QueryStatus static enum GNUNET_DB_QueryStatus
insert1 (struct PostgresClosure *pg, insert1 (struct PostgresClosure *pg,
const struct TALER_EXCHANGEDB_ReserveInInfo reserves[1], const struct TALER_EXCHANGEDB_ReserveInInfo reserves[1],
@ -689,6 +708,7 @@ TEH_PG_reserves_in_insert (void *cls,
{ {
unsigned int bs = GNUNET_MIN (batch_size, unsigned int bs = GNUNET_MIN (batch_size,
reserves_length - i); reserves_length - i);
bs = 1; // FIXME-JOSEPH: for now, until pg_notify is gone!
if (bs >= 8) if (bs >= 8)
{ {
qs1 = insert8 (pg, qs1 = insert8 (pg,