batch test for reserves-in-insert
This commit is contained in:
parent
b9ccfbd66b
commit
dbfd4e252a
@ -25,6 +25,7 @@
|
|||||||
#include "pg_batch_reserves_in_insert.h"
|
#include "pg_batch_reserves_in_insert.h"
|
||||||
#include "pg_helper.h"
|
#include "pg_helper.h"
|
||||||
#include "pg_start.h"
|
#include "pg_start.h"
|
||||||
|
#include "pg_rollback.h"
|
||||||
#include "pg_start_read_committed.h"
|
#include "pg_start_read_committed.h"
|
||||||
#include "pg_commit.h"
|
#include "pg_commit.h"
|
||||||
#include "pg_reserves_get.h"
|
#include "pg_reserves_get.h"
|
||||||
@ -97,7 +98,6 @@ TEH_PG_batch_reserves_in_insert (void *cls,
|
|||||||
{
|
{
|
||||||
struct GNUNET_PQ_QueryParam params[] = {
|
struct GNUNET_PQ_QueryParam params[] = {
|
||||||
GNUNET_PQ_query_param_auto_from_type (&reserves->reserve_pub), /*$1*/
|
GNUNET_PQ_query_param_auto_from_type (&reserves->reserve_pub), /*$1*/
|
||||||
TALER_PQ_query_param_amount (&reserves->balance), /*$2+3*/
|
|
||||||
GNUNET_PQ_query_param_timestamp (&expiry), /*$4*/
|
GNUNET_PQ_query_param_timestamp (&expiry), /*$4*/
|
||||||
GNUNET_PQ_query_param_timestamp (&gc), /*$5*/
|
GNUNET_PQ_query_param_timestamp (&gc), /*$5*/
|
||||||
GNUNET_PQ_query_param_uint64 (&reserves->wire_reference), /*6*/
|
GNUNET_PQ_query_param_uint64 (&reserves->wire_reference), /*6*/
|
||||||
@ -121,6 +121,7 @@ TEH_PG_batch_reserves_in_insert (void *cls,
|
|||||||
GNUNET_PQ_result_spec_end
|
GNUNET_PQ_result_spec_end
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
|
||||||
"Reserve does not exist; creating a new one\n");
|
"Reserve does not exist; creating a new one\n");
|
||||||
/* Note: query uses 'on conflict do nothing' */
|
/* Note: query uses 'on conflict do nothing' */
|
||||||
@ -129,21 +130,23 @@ TEH_PG_batch_reserves_in_insert (void *cls,
|
|||||||
"SELECT "
|
"SELECT "
|
||||||
"out_reserve_found AS conflicted"
|
"out_reserve_found AS conflicted"
|
||||||
",transaction_duplicate"
|
",transaction_duplicate"
|
||||||
",ruuid"
|
",ruuid AS reserve_uuid"
|
||||||
" FROM batch_reserves_in"
|
" FROM batch_reserves_in"
|
||||||
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12);");
|
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11);");
|
||||||
|
|
||||||
qs1 = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
|
qs1 = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
|
||||||
"reserve_create",
|
"reserve_create",
|
||||||
params,
|
params,
|
||||||
rs);
|
rs);
|
||||||
|
|
||||||
|
|
||||||
if (qs1 < 0)
|
if (qs1 < 0)
|
||||||
return qs1;
|
return qs1;
|
||||||
}
|
}
|
||||||
|
if ((int)conflicted == 0 && (int)transaction_duplicate == 1)
|
||||||
|
TEH_PG_rollback(pg);
|
||||||
notify_on_reserve (pg,
|
notify_on_reserve (pg,
|
||||||
&reserves->reserve_pub);
|
&reserves->reserve_pub);
|
||||||
|
|
||||||
|
|
||||||
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
|
return GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
|
||||||
}
|
}
|
||||||
|
@ -2522,15 +2522,13 @@ END $$;
|
|||||||
|
|
||||||
CREATE OR REPLACE FUNCTION batch_reserves_in(
|
CREATE OR REPLACE FUNCTION batch_reserves_in(
|
||||||
IN in_reserve_pub BYTEA,
|
IN in_reserve_pub BYTEA,
|
||||||
IN in_current_balance_val INT8,
|
|
||||||
IN in_current_balance_frac INT4,
|
|
||||||
IN in_expiration_date INT8,
|
IN in_expiration_date INT8,
|
||||||
IN in_gc_date INT8,
|
IN in_gc_date INT8,
|
||||||
IN in_wire_ref INT8,
|
IN in_wire_ref INT8,
|
||||||
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 INT4,
|
IN in_exectution_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,
|
||||||
@ -2545,15 +2543,6 @@ DECLARE
|
|||||||
my_amount_frac INT4;
|
my_amount_frac INT4;
|
||||||
BEGIN
|
BEGIN
|
||||||
|
|
||||||
SELECT
|
|
||||||
current_balance_val
|
|
||||||
,current_balance_frac
|
|
||||||
INTO
|
|
||||||
my_amount_val
|
|
||||||
,my_amount_frac
|
|
||||||
FROM reserves
|
|
||||||
WHERE reserves.reserve_pub = in_reserve_pub;
|
|
||||||
|
|
||||||
INSERT INTO reserves
|
INSERT INTO reserves
|
||||||
(reserve_pub
|
(reserve_pub
|
||||||
,current_balance_val
|
,current_balance_val
|
||||||
@ -2562,18 +2551,19 @@ BEGIN
|
|||||||
,gc_date)
|
,gc_date)
|
||||||
VALUES
|
VALUES
|
||||||
(in_reserve_pub
|
(in_reserve_pub
|
||||||
,in_current_balance_val
|
,in_credit_val
|
||||||
,in_current_balance_frac
|
,in_credit_frac
|
||||||
,in_expiration_date
|
,in_expiration_date
|
||||||
,in_gc_date)
|
,in_gc_date)
|
||||||
ON CONFLICT DO NOTHING
|
ON CONFLICT DO NOTHING
|
||||||
RETURNING reserves.reserve_uuid INTO ruuid;
|
RETURNING reserve_uuid INTO ruuid;
|
||||||
|
|
||||||
--IF THE INSERT WAS NOT SUCCESSFUL, REMEMBER IT
|
IF FOUND
|
||||||
IF NOT FOUND
|
|
||||||
THEN
|
THEN
|
||||||
|
-- We made a change, so the reserve did not previously exist.
|
||||||
out_reserve_found = FALSE;
|
out_reserve_found = FALSE;
|
||||||
ELSE
|
ELSE
|
||||||
|
-- We made no change, which means the reserve existed.
|
||||||
out_reserve_found = TRUE;
|
out_reserve_found = TRUE;
|
||||||
END IF;
|
END IF;
|
||||||
|
|
||||||
@ -2597,42 +2587,52 @@ BEGIN
|
|||||||
VALUES
|
VALUES
|
||||||
(in_reserve_pub
|
(in_reserve_pub
|
||||||
,in_wire_ref
|
,in_wire_ref
|
||||||
,in_current_balance_val
|
,in_credit_val
|
||||||
,in_credit_frac
|
,in_credit_frac
|
||||||
,in_exchange_account_section
|
,in_exchange_account_name
|
||||||
,in_wire_source_h_payto
|
,in_wire_source_h_payto
|
||||||
,in_execution_date);
|
,in_expiration_date);
|
||||||
|
|
||||||
--IF THE INSERTION WAS A SUCCESS IT MEANS NO DUPLICATED TRANSACTION
|
--IF THE INSERTION WAS A SUCCESS IT MEANS NO DUPLICATED TRANSACTION
|
||||||
IF FOUND
|
IF FOUND
|
||||||
THEN
|
THEN
|
||||||
transaction_duplicate = FALSE;
|
transaction_duplicate = FALSE;
|
||||||
IF out_reserve_found = TRUE
|
IF out_reserve_found
|
||||||
THEN
|
THEN
|
||||||
UPDATE reserves
|
UPDATE reserves
|
||||||
SET
|
SET
|
||||||
in_current_balance_frac=in_current_balance_frac+my_amount_frac
|
current_balance_frac = current_balance_frac+in_credit_frac
|
||||||
- CASE
|
- CASE
|
||||||
WHEN in_current_balance_frac + my_amount_frac >= 100000000
|
WHEN current_balance_frac + in_credit_frac >= 100000000
|
||||||
THEN 100000000
|
THEN 100000000
|
||||||
ELSE 0
|
ELSE 1
|
||||||
END
|
END
|
||||||
,in_current_balance_val=in_current_balance_val+my_amount_val
|
,current_balance_val = current_balance_val+in_credit_val
|
||||||
+ CASE
|
+ CASE
|
||||||
WHEN in_current_balance_frac + my_amount_frac >= 100000000
|
WHEN current_balance_frac + in_credit_frac >= 100000000
|
||||||
THEN 1
|
THEN 1
|
||||||
ELSE 0
|
ELSE 0
|
||||||
END
|
END
|
||||||
,expiration_date=GREATEST(in_expiration_date,in_reserve_expiration)
|
,expiration_date=GREATEST(expiration_date,in_expiration_date)
|
||||||
,gc_date=GREATEST(in_gc_date,in_reserve_expiration)
|
,gc_date=GREATEST(gc_date,in_expiration_date)
|
||||||
WHERE reserves.reserve_pub=in_reserve_pub;
|
WHERE reserves.reserve_pub=in_reserve_pub;
|
||||||
|
out_reserve_found = TRUE;
|
||||||
RETURN;
|
RETURN;
|
||||||
ELSE
|
ELSE
|
||||||
|
out_reserve_found=FALSE;
|
||||||
RETURN;
|
RETURN;
|
||||||
END IF;
|
END IF;
|
||||||
|
out_reserve_found = TRUE;
|
||||||
ELSE
|
ELSE
|
||||||
transaction_duplicate = TRUE;
|
transaction_duplicate = TRUE;
|
||||||
RETURN;
|
IF out_reserve_found
|
||||||
|
THEN
|
||||||
|
out_reserve_found = TRUE;
|
||||||
|
RETURN;
|
||||||
|
ELSE
|
||||||
|
out_reserve_found = FALSE;
|
||||||
|
RETURN;
|
||||||
|
END IF;
|
||||||
END IF;
|
END IF;
|
||||||
END $$;
|
END $$;
|
||||||
|
|
||||||
|
@ -98,9 +98,9 @@ run (void *cls)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i< 8; i++)
|
for (unsigned int i = 0; i< 7; i++)
|
||||||
{
|
{
|
||||||
static unsigned int batches[] = {1, 1, 0, 2, 4, 16, 64, 256};
|
static unsigned int batches[] = {1, 1, 2, 4, 16, 64, 256};
|
||||||
const char *sndr = "payto://x-taler-bank/localhost:8080/1";
|
const char *sndr = "payto://x-taler-bank/localhost:8080/1";
|
||||||
struct TALER_Amount value;
|
struct TALER_Amount value;
|
||||||
unsigned int batch_size = batches[i];
|
unsigned int batch_size = batches[i];
|
||||||
@ -124,6 +124,7 @@ run (void *cls)
|
|||||||
reserves[k].execution_time = ts;
|
reserves[k].execution_time = ts;
|
||||||
reserves[k].sender_account_details = sndr;
|
reserves[k].sender_account_details = sndr;
|
||||||
reserves[k].exchange_account_name = "name";
|
reserves[k].exchange_account_name = "name";
|
||||||
|
reserves[k].wire_reference = k;
|
||||||
|
|
||||||
}
|
}
|
||||||
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
|
FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
|
||||||
|
Loading…
Reference in New Issue
Block a user