corrections applied to batch_test

This commit is contained in:
Joseph 2023-01-04 07:31:08 -05:00
parent 31fefec5dd
commit 6457ee56df
No known key found for this signature in database
GPG Key ID: E709789D3076B5CC
11 changed files with 407 additions and 325 deletions

View File

@ -295,16 +295,16 @@ check_PROGRAMS = \
bench-db-postgres\ bench-db-postgres\
perf-exchangedb-reserves-in-insert-postgres\ perf-exchangedb-reserves-in-insert-postgres\
test-exchangedb-by-j-postgres\ test-exchangedb-by-j-postgres\
test-exchangedb-batch-reserves-in-insert-postgres test-exchangedb-batch-reserves-in-insert-postgres\
test-exchangedb-populate-table-postgres
AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH; AM_TESTS_ENVIRONMENT=export TALER_PREFIX=$${TALER_PREFIX:-@libdir@};export PATH=$${TALER_PREFIX:-@prefix@}/bin:$$PATH;
TESTS = \ TESTS = \
test-exchangedb-postgres\ test-exchangedb-postgres\
test-exchangedb-by-j-postgres\ test-exchangedb-by-j-postgres\
perf-exchangedb-reserves-in-insert-postgres\ perf-exchangedb-reserves-in-insert-postgres\
test-exchangedb-batch-reserves-in-insert-postgres test-exchangedb-batch-reserves-in-insert-postgres\
test-exchangedb-populate-table-postgres
test_exchangedb_postgres_SOURCES = \ test_exchangedb_postgres_SOURCES = \
test_exchangedb.c test_exchangedb.c
test_exchangedb_postgres_LDADD = \ test_exchangedb_postgres_LDADD = \
@ -376,7 +376,27 @@ bench_db_postgres_LDADD = \
-lgnunetutil \ -lgnunetutil \
$(XLIB) $(XLIB)
test_exchangedb_populate_table_postgres_SOURCES = \
test_exchangedb_populate_table.c
test_exchangedb_populate_table_postgres_LDADD = \
libtalerexchangedb.la \
$(top_builddir)/src/json/libtalerjson.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/pq/libtalerpq.la \
-ljansson \
-lgnunetjson \
-lgnunetutil \
$(XLIB)
bench_db_postgres_SOURCES = \
bench_db.c
bench_db_postgres_LDADD = \
libtalerexchangedb.la \
$(top_builddir)/src/util/libtalerutil.la \
$(top_builddir)/src/pq/libtalerpq.la \
-lgnunetpq \
-lgnunetutil \
$(XLIB)
EXTRA_test_exchangedb_postgres_DEPENDENCIES = \ EXTRA_test_exchangedb_postgres_DEPENDENCIES = \
libtaler_plugin_exchangedb_postgres.la libtaler_plugin_exchangedb_postgres.la

View File

@ -54,8 +54,8 @@ DECLARE
r RECORD; r RECORD;
BEGIN BEGIN
--SIMPLE INSERT ON CONFLICT DO NOTHING --SIMPLE INSERT ON CONFLICT DO NOTHING
transaction_duplicate=FALSE; transaction_duplicate=TRUE;
transaction_duplicate2=FALSE; transaction_duplicate2=TRUE;
out_reserve_found = TRUE; out_reserve_found = TRUE;
out_reserve_found2 = TRUE; out_reserve_found2 = TRUE;
ruuid=0; ruuid=0;
@ -148,7 +148,7 @@ BEGIN
,in_exchange_account_name ,in_exchange_account_name
,in_wire_source_h_payto ,in_wire_source_h_payto
,in_expiration_date), ,in_expiration_date),
(in2_reserve_pub (in3_reserve_pub
,in2_wire_ref ,in2_wire_ref
,in2_credit_val ,in2_credit_val
,in2_credit_frac ,in2_credit_frac
@ -163,26 +163,32 @@ BEGIN
THEN THEN
IF in_reserve_pub = r.reserve_pub IF in_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate = TRUE; transaction_duplicate = FALSE;
END IF; END IF;
IF in2_reserve_pub = i.reserve_pub IF in2_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate = TRUE; transaction_duplicate2 = FALSE;
END IF; END IF;
FETCH FROM curs_transaction_exist INTO r; FETCH FROM curs_transaction_exist INTO r;
IF FOUND IF FOUND
THEN THEN
IF in_reserve_pub = r.reserve_pub IF in_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate = TRUE; transaction_duplicate = FALSE;
END IF; END IF;
IF in2_reserve_pub = i.reserve_pub IF in2_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate = TRUE; transaction_duplicate2 = FALSE;
END IF; END IF;
END IF; END IF;
END IF; END IF;
/* IF transaction_duplicate
OR transaction_duplicate2
THEN
CLOSE curs_transaction_exist;
ROLLBACK;
RETURN;
END IF;*/
CLOSE curs_transaction_exist; CLOSE curs_transaction_exist;
RETURN; RETURN;
END $$; END $$;

View File

@ -81,10 +81,10 @@ DECLARE
BEGIN BEGIN
--INITIALIZATION --INITIALIZATION
transaction_duplicate=FALSE; transaction_duplicate=TRUE;
transaction_duplicate2=FALSE; transaction_duplicate2=TRUE;
transaction_duplicate3=FALSE; transaction_duplicate3=TRUE;
transaction_duplicate4=FALSE; transaction_duplicate4=TRUE;
out_reserve_found = TRUE; out_reserve_found = TRUE;
out_reserve_found2 = TRUE; out_reserve_found2 = TRUE;
out_reserve_found3 = TRUE; out_reserve_found3 = TRUE;
@ -232,25 +232,34 @@ BEGIN
THEN THEN
IF in_reserve_pub = i.reserve_pub IF in_reserve_pub = i.reserve_pub
THEN THEN
transaction_duplicate = TRUE; transaction_duplicate = FALSE;
END IF; END IF;
IF in2_reserve_pub = i.reserve_pub IF in2_reserve_pub = i.reserve_pub
THEN THEN
transaction_duplicate2 = TRUE; transaction_duplicate2 = FALSE;
END IF; END IF;
IF in3_reserve_pub = i.reserve_pub IF in3_reserve_pub = i.reserve_pub
THEN THEN
transaction_duplicate3 = TRUE; transaction_duplicate3 = FALSE;
END IF; END IF;
IF in4_reserve_pub = i.reserve_pub IF in4_reserve_pub = i.reserve_pub
THEN THEN
transaction_duplicate4 = TRUE; transaction_duplicate4 = FALSE;
END IF; END IF;
END IF; END IF;
k=k+1; k=k+1;
END LOOP; END LOOP;
CLOSE curs_transaction_exist; /* IF transaction_duplicate
OR transaction_duplicate2
OR transaction_duplicate3
OR transaction_duplicate4
THEN
RAISE EXCEPTION 'Reserve did not exist, but INSERT into reserves_in gave conflict';
CLOSE curs_transaction_exist;
RETURN;
END IF;*/
CLOSE curs_transaction_exist;
RETURN; RETURN;
END $$; END $$;

View File

@ -136,14 +136,14 @@ DECLARE
BEGIN BEGIN
--INITIALIZATION --INITIALIZATION
transaction_duplicate=FALSE; transaction_duplicate=TRUE;
transaction_duplicate2=FALSE; transaction_duplicate2=TRUE;
transaction_duplicate3=FALSE; transaction_duplicate3=TRUE;
transaction_duplicate4=FALSE; transaction_duplicate4=TRUE;
transaction_duplicate5=FALSE; transaction_duplicate5=TRUE;
transaction_duplicate6=FALSE; transaction_duplicate6=TRUE;
transaction_duplicate7=FALSE; transaction_duplicate7=TRUE;
transaction_duplicate8=FALSE; transaction_duplicate8=TRUE;
out_reserve_found = TRUE; out_reserve_found = TRUE;
out_reserve_found2 = TRUE; out_reserve_found2 = TRUE;
out_reserve_found3 = TRUE; out_reserve_found3 = TRUE;
@ -388,41 +388,52 @@ BEGIN
THEN THEN
IF in_reserve_pub = r.reserve_pub IF in_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate = TRUE; transaction_duplicate = FALSE;
END IF; END IF;
IF in2_reserve_pub = r.reserve_pub IF in2_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate2 = TRUE; transaction_duplicate2 = FALSE;
END IF; END IF;
IF in3_reserve_pub = r.reserve_pub IF in3_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate3 = TRUE; transaction_duplicate3 = FALSE;
END IF; END IF;
IF in4_reserve_pub = r.reserve_pub IF in4_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate4 = TRUE; transaction_duplicate4 = FALSE;
END IF; END IF;
IF in5_reserve_pub = r.reserve_pub IF in5_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate5 = TRUE; transaction_duplicate5 = FALSE;
END IF; END IF;
IF in6_reserve_pub = r.reserve_pub IF in6_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate6 = TRUE; transaction_duplicate6 = FALSE;
END IF; END IF;
IF in7_reserve_pub = r.reserve_pub IF in7_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate7 = TRUE; transaction_duplicate7 = FALSE;
END IF; END IF;
IF in8_reserve_pub = r.reserve_pub IF in8_reserve_pub = r.reserve_pub
THEN THEN
transaction_duplicate8 = TRUE; transaction_duplicate8 = FALSE;
END IF; END IF;
END IF; END IF;
k=k+1; k=k+1;
END LOOP; END LOOP;
/* IF transaction_duplicate
OR transaction_duplicate2
OR transaction_duplicate3
OR transaction_duplicate4
OR transaction_duplicate5
OR transaction_duplicate6
OR transaction_duplicate7
OR transaction_duplicate8
THEN
CLOSE curs_transaction_existed;
ROLLBACK;
RETURN;
END IF;*/
CLOSE curs_transaction_existed; CLOSE curs_transaction_existed;
RETURN; RETURN;
END $$; END $$;

View File

@ -36,7 +36,7 @@ AS $$
BEGIN BEGIN
ruuid= 0; ruuid= 0;
out_reserve_found = TRUE; out_reserve_found = TRUE;
transaction_duplicate= FALSE; 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
@ -66,7 +66,7 @@ transaction_duplicate= FALSE;
out_reserve_found = FALSE; out_reserve_found = FALSE;
ELSE ELSE
-- We made no change, which means the reserve existed. -- We made no change, which means the reserve existed.
out_reserve_found = TRUE; /*RESERVE EXISTED BUT WE DO NOT HAVE ANY INFORMATION ABOUT TRANSACTION, RETURN*/ out_reserve_found = TRUE;
RETURN; RETURN;
END IF; END IF;
PERFORM pg_notify(in_notify, NULL); PERFORM pg_notify(in_notify, NULL);
@ -89,11 +89,14 @@ transaction_duplicate= FALSE;
ON CONFLICT DO NOTHING; ON CONFLICT DO NOTHING;
IF FOUND IF FOUND
THEN THEN
transaction_duplicate = FALSE; /*HAPPY PATH THERE IS NO DUPLICATE TRANS AND NEW RESERVE*/ -- HAPPY PATH THERE IS NO DUPLICATE TRANS
transaction_duplicate = FALSE;
RETURN; RETURN;
ELSE ELSE
-- Unhappy...
RAISE EXCEPTION 'Reserve did not exist, but INSERT into reserves_in gave conflict';
transaction_duplicate = TRUE; transaction_duplicate = TRUE;
/*HAPPY PATH IF THERE IS A DUPLICATE TRANS WE JUST NEED TO ROLLBACK COMPLAIN*/ ROLLBACK;
RETURN; RETURN;
END IF; END IF;
RETURN; RETURN;

View File

@ -14,25 +14,19 @@
-- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
-- --
CREATE OR REPLACE PROCEDURE exchange_do_batch_reserves_update( CREATE OR REPLACE FUNCTION exchange_do_batch_reserves_update(
IN in_reserve_pub BYTEA, IN in_reserve_pub BYTEA,
IN in_expiration_date INT8, IN in_expiration_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_reserve_found BOOLEAN,
IN in_wire_source_h_payto BYTEA, IN in_wire_source_h_payto BYTEA,
IN in_notify text) IN in_notify text,
OUT out_duplicate BOOLEAN)
LANGUAGE plpgsql LANGUAGE plpgsql
AS $$ AS $$
DECLARE
i RECORD;
DECLARE
curs refcursor;
BEGIN BEGIN
OPEN curs FOR
WITH reserves_update AS (
INSERT INTO reserves_in INSERT INTO reserves_in
(reserve_pub (reserve_pub
,wire_reference ,wire_reference
@ -49,15 +43,11 @@ BEGIN
,in_exchange_account_name ,in_exchange_account_name
,in_wire_source_h_payto ,in_wire_source_h_payto
,in_expiration_date) ,in_expiration_date)
ON CONFLICT DO NOTHING ON CONFLICT DO NOTHING;
RETURNING reserve_pub, credit_val, credit_frac) IF FOUND
SELECT * FROM reserves_in;
FETCH FROM curs INTO i;
IF FOUND --IF THE INSERTION WAS A SUCCESS IT MEANS NO DUPLICATED TRANSACTION
THEN
IF in_reserve_found
THEN THEN
--IF THE INSERTION WAS A SUCCESS IT MEANS NO DUPLICATED TRANSACTION
out_duplicate = FALSE;
UPDATE reserves UPDATE reserves
SET SET
current_balance_frac = current_balance_frac+in_credit_frac current_balance_frac = current_balance_frac+in_credit_frac
@ -75,20 +65,9 @@ BEGIN
,expiration_date=GREATEST(expiration_date,in_expiration_date) ,expiration_date=GREATEST(expiration_date,in_expiration_date)
,gc_date=GREATEST(gc_date,in_expiration_date) ,gc_date=GREATEST(gc_date,in_expiration_date)
WHERE reserve_pub=in_reserve_pub; WHERE reserve_pub=in_reserve_pub;
END IF;
PERFORM pg_notify(in_notify, NULL); PERFORM pg_notify(in_notify, NULL);
ELSE ELSE
CLOSE curs; out_duplicate = TRUE;
IF NOT in_reserve_found
THEN
ROLLBACK;
END IF; END IF;
PERFORM pg_notify(in_notify, NULL); RETURN;
/* UPDATE reserves_in
SET credit_frac = credit_frac - in_credit_frac
AND credit_val = credit_val + in_credit_val
WHERE reserve_pub = in_reserve_pub;*/
END IF;
END $$; END $$;

View File

@ -62,7 +62,8 @@ insert1(struct PostgresClosure *pg,
struct GNUNET_TIME_Timestamp reserve_expiration, struct GNUNET_TIME_Timestamp reserve_expiration,
bool *transaction_duplicate, bool *transaction_duplicate,
bool *conflict, bool *conflict,
uint64_t *reserve_uuid) uint64_t *reserve_uuid,
enum GNUNET_DB_QueryStatus results[1])
{ {
enum GNUNET_DB_QueryStatus qs2; enum GNUNET_DB_QueryStatus qs2;
PREPARE (pg, PREPARE (pg,
@ -107,22 +108,23 @@ insert1(struct PostgresClosure *pg,
"batch1_reserve_create", "batch1_reserve_create",
params, params,
rs); rs);
if (qs2 < 0) if (qs2 < 0)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to create reserves (%d)\n", "Failed to create reserves (%d)\n",
qs2); qs2);
results[0] = qs2;
return qs2; return qs2;
} }
GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs2); GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs2);
if ((conflict[0]) && transaction_duplicate[0])
if (conflict[0] && transaction_duplicate[0])
{ {
GNUNET_break (0); GNUNET_break (0);
TEH_PG_rollback (pg); TEH_PG_rollback (pg);
results[0] = GNUNET_DB_STATUS_HARD_ERROR;
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
results[0] = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
return qs2; return qs2;
} }
@ -138,7 +140,8 @@ insert2 (struct PostgresClosure *pg,
struct GNUNET_TIME_Timestamp reserve_expiration, struct GNUNET_TIME_Timestamp reserve_expiration,
bool *transaction_duplicate, bool *transaction_duplicate,
bool *conflict, bool *conflict,
uint64_t *reserve_uuid) uint64_t *reserve_uuid,
enum GNUNET_DB_QueryStatus results[1])
{ {
enum GNUNET_DB_QueryStatus qs1; enum GNUNET_DB_QueryStatus qs1;
PREPARE (pg, PREPARE (pg,
@ -154,7 +157,7 @@ insert2 (struct PostgresClosure *pg,
" ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22);"); " ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18,$19,$20,$21,$22);");
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
// THIS is wrong, not 22 args!
GNUNET_PQ_query_param_auto_from_type (reserves[0].reserve_pub), GNUNET_PQ_query_param_auto_from_type (reserves[0].reserve_pub),
GNUNET_PQ_query_param_timestamp (&expiry), GNUNET_PQ_query_param_timestamp (&expiry),
GNUNET_PQ_query_param_timestamp (&gc), GNUNET_PQ_query_param_timestamp (&gc),
@ -209,6 +212,7 @@ insert2 (struct PostgresClosure *pg,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to create reserves (%d)\n", "Failed to create reserves (%d)\n",
qs1); qs1);
results[0]=qs1;
return qs1; return qs1;
} }
@ -224,8 +228,10 @@ insert2 (struct PostgresClosure *pg,
{ {
GNUNET_break (0); GNUNET_break (0);
TEH_PG_rollback (pg); TEH_PG_rollback (pg);
results[0] = GNUNET_DB_STATUS_HARD_ERROR;
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
results[0] = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
return qs1; return qs1;
} }
@ -240,7 +246,8 @@ insert4 (struct PostgresClosure *pg,
struct GNUNET_TIME_Timestamp reserve_expiration, struct GNUNET_TIME_Timestamp reserve_expiration,
bool *transaction_duplicate, bool *transaction_duplicate,
bool *conflict, bool *conflict,
uint64_t *reserve_uuid) uint64_t *reserve_uuid,
enum GNUNET_DB_QueryStatus results[1])
{ {
enum GNUNET_DB_QueryStatus qs3; enum GNUNET_DB_QueryStatus qs3;
PREPARE (pg, PREPARE (pg,
@ -353,13 +360,11 @@ insert4 (struct PostgresClosure *pg,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to create reserves4 (%d)\n", "Failed to create reserves4 (%d)\n",
qs3); qs3);
results[0] = qs3;
return qs3; return qs3;
} }
GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs3); GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs3);
/* results[i] = (transaction_duplicate)
? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
: GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;*/
if ( if (
((conflict[0]) && (transaction_duplicate[0])) ((conflict[0]) && (transaction_duplicate[0]))
@ -370,8 +375,10 @@ insert4 (struct PostgresClosure *pg,
{ {
GNUNET_break (0); GNUNET_break (0);
TEH_PG_rollback (pg); TEH_PG_rollback (pg);
results[0] = GNUNET_DB_STATUS_HARD_ERROR;
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
results[0] = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
return qs3; return qs3;
} }
@ -386,7 +393,8 @@ insert8 (struct PostgresClosure *pg,
struct GNUNET_TIME_Timestamp reserve_expiration, struct GNUNET_TIME_Timestamp reserve_expiration,
bool *transaction_duplicate, bool *transaction_duplicate,
bool *conflict, bool *conflict,
uint64_t *reserve_uuid) uint64_t *reserve_uuid,
enum GNUNET_DB_QueryStatus results[1])
{ {
enum GNUNET_DB_QueryStatus qs3; enum GNUNET_DB_QueryStatus qs3;
PREPARE (pg, PREPARE (pg,
@ -583,6 +591,7 @@ insert8 (struct PostgresClosure *pg,
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to create reserves8 (%d)\n", "Failed to create reserves8 (%d)\n",
qs3); qs3);
results[0]=qs3;
return qs3; return qs3;
} }
@ -604,8 +613,10 @@ insert8 (struct PostgresClosure *pg,
{ {
GNUNET_break (0); GNUNET_break (0);
TEH_PG_rollback (pg); TEH_PG_rollback (pg);
results[0]=GNUNET_DB_STATUS_HARD_ERROR;
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
results[0] = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
return qs3; return qs3;
} }
@ -627,6 +638,7 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
uint64_t reserve_uuid[reserves_length]; uint64_t reserve_uuid[reserves_length];
bool transaction_duplicate[reserves_length]; bool transaction_duplicate[reserves_length];
bool need_update = false; bool need_update = false;
bool t_duplicate=false;
struct GNUNET_TIME_Timestamp reserve_expiration struct GNUNET_TIME_Timestamp reserve_expiration
= GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time); = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time);
bool conflicts[reserves_length]; bool conflicts[reserves_length];
@ -689,7 +701,8 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
reserve_expiration, reserve_expiration,
&transaction_duplicate[i], &transaction_duplicate[i],
&conflicts[i], &conflicts[i],
&reserve_uuid[i]); &reserve_uuid[i],
&results[i]);
if (qs1<0) if (qs1<0)
{ {
@ -707,6 +720,14 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
need_update |= conflicts[i+5]; need_update |= conflicts[i+5];
need_update |= conflicts[i+6]; need_update |= conflicts[i+6];
need_update |= conflicts[i+7]; need_update |= conflicts[i+7];
t_duplicate |= transaction_duplicate[i];
t_duplicate |= transaction_duplicate[i+1];
t_duplicate |= transaction_duplicate[i+2];
t_duplicate |= transaction_duplicate[i+3];
t_duplicate |= transaction_duplicate[i+4];
t_duplicate |= transaction_duplicate[i+5];
t_duplicate |= transaction_duplicate[i+6];
t_duplicate |= transaction_duplicate[i+7];
i+=8; i+=8;
continue; continue;
} }
@ -725,7 +746,8 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
reserve_expiration, reserve_expiration,
&transaction_duplicate[i], &transaction_duplicate[i],
&conflicts[i], &conflicts[i],
&reserve_uuid[i]); &reserve_uuid[i],
&results[i]);
if (qs4<0) if (qs4<0)
{ {
@ -738,8 +760,10 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
need_update |= conflicts[i+1]; need_update |= conflicts[i+1];
need_update |= conflicts[i+2]; need_update |= conflicts[i+2];
need_update |= conflicts[i+3]; need_update |= conflicts[i+3];
// fprintf(stdout, "%ld %ld %ld %ld\n", reserve_uuid[i], reserve_uuid[i+1], reserve_uuid[i+2], reserve_uuid[i+3]); t_duplicate |= transaction_duplicate[i];
//fprintf(stdout, "%d %d %d %d\n", transaction_duplicate[i], transaction_duplicate[i+1], transaction_duplicate[i+2], transaction_duplicate[i+3]); t_duplicate |= transaction_duplicate[i+1];
t_duplicate |= transaction_duplicate[i+2];
t_duplicate |= transaction_duplicate[i+3];
i += 4; i += 4;
break; break;
case 3: case 3:
@ -753,17 +777,21 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
reserve_expiration, reserve_expiration,
&transaction_duplicate[i], &transaction_duplicate[i],
&conflicts[i], &conflicts[i],
&reserve_uuid[i]); &reserve_uuid[i],
&results[i]);
if (qs5<0) if (qs5<0)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to update reserves (%d)\n", "Failed to update reserves 2 (%d)\n",
qs5); qs5);
return qs5; return qs5;
} }
need_update |= conflicts[i]; need_update |= conflicts[i];
need_update |= conflicts[i+1]; need_update |= conflicts[i+1];
// fprintf(stdout, "%ld %ld\n", reserve_uuid[i], reserve_uuid[i+1]); t_duplicate |= transaction_duplicate[i];
t_duplicate |= transaction_duplicate[i+1];
//fprintf(stdout, "%ld %ld c:%d t:%d\n", reserve_uuid[i], reserve_uuid[i+1], conflicts[i], transaction_duplicate[i]);
i += 2; i += 2;
break; break;
case 1: case 1:
@ -776,14 +804,19 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
reserve_expiration, reserve_expiration,
&transaction_duplicate[i], &transaction_duplicate[i],
&conflicts[i], &conflicts[i],
&reserve_uuid[i]); &reserve_uuid[i],
&results[i]);
if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs2) if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs2)
{ {
GNUNET_break (0); GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
need_update |= conflicts[i]; need_update |= conflicts[i];
t_duplicate |= transaction_duplicate[i];
// fprintf(stdout, "%ld c:%d t:%d\n", reserve_uuid[i], conflicts[i], transaction_duplicate[i]);
i += 1; i += 1;
break; break;
case 0: case 0:
GNUNET_assert (0); GNUNET_assert (0);
@ -807,6 +840,8 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
{ {
goto exit; goto exit;
} }
if (t_duplicate)
goto exit;
// begin serializable // begin serializable
{ {
if (GNUNET_OK != if (GNUNET_OK !=
@ -819,42 +854,52 @@ TEH_PG_batch2_reserves_in_insert (void *cls,
} }
enum GNUNET_DB_QueryStatus qs3; enum GNUNET_DB_QueryStatus qs3;
PREPARE (pg,
"reserves_update",
"SELECT"
" out_duplicate AS duplicate "
"FROM exchange_do_batch_reserves_update"
" ($1,$2,$3,$4,$5,$6,$7,$8);");
for (unsigned int i = 0; i<reserves_length; i++) for (unsigned int i = 0; i<reserves_length; i++)
{ {
if (! conflicts[i]) if (! conflicts[i])
continue; continue;
// fprintf(stdout, "%d\n", conflicts[i]); // fprintf(stdout, "%d\n", conflicts[i]);
{ {
// const struct TALER_EXCHANGEDB_ReserveInInfo *reserve = &reserves[i]; bool duplicate;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserves[i].reserve_pub), GNUNET_PQ_query_param_auto_from_type (reserves[i].reserve_pub),
GNUNET_PQ_query_param_timestamp (&expiry), GNUNET_PQ_query_param_timestamp (&expiry),
GNUNET_PQ_query_param_uint64 (&reserves[i].wire_reference), GNUNET_PQ_query_param_uint64 (&reserves[i].wire_reference),
TALER_PQ_query_param_amount (reserves[i].balance), TALER_PQ_query_param_amount (reserves[i].balance),
GNUNET_PQ_query_param_string (reserves[i].exchange_account_name), GNUNET_PQ_query_param_string (reserves[i].exchange_account_name),
GNUNET_PQ_query_param_bool (conflicts[i]),
GNUNET_PQ_query_param_auto_from_type (&h_payto), GNUNET_PQ_query_param_auto_from_type (&h_payto),
GNUNET_PQ_query_param_string (notify_s[i]), GNUNET_PQ_query_param_string (notify_s[i]),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
PREPARE (pg, struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_bool ("duplicate",
&duplicate),
GNUNET_PQ_result_spec_end
};
qs3 = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"reserves_update", "reserves_update",
"CALL exchange_do_batch_reserves_update" params,
" ($1,$2,$3,$4,$5,$6,$7,$8,$9);"); rs);
qs3 = GNUNET_PQ_eval_prepared_non_select (pg->conn,
"reserves_update",
params);
if (qs3<0) if (qs3<0)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to update (%d)\n", "Failed to update (%d)\n",
qs3); qs3);
results[i] = qs3;
return qs3; return qs3;
} }
results[i] = duplicate
? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
: GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
} }
} }
{ {
enum GNUNET_DB_QueryStatus cs; enum GNUNET_DB_QueryStatus cs;

View File

@ -16,7 +16,7 @@
/** /**
* @file exchangedb/pg_batch2_reserves_in_insert.h * @file exchangedb/pg_batch2_reserves_in_insert.h
* @brief implementation of the batch2_reserves_in_insert function for Postgres * @brief implementation of the batch2_reserves_in_insert function for Postgres
* @author Christian Grothoff * @author Joseph XU
*/ */
#ifndef PG_BATCH2_RESERVES_IN_INSERT_H #ifndef PG_BATCH2_RESERVES_IN_INSERT_H
#define PG_BATCH2_RESERVES_IN_INSERT_H #define PG_BATCH2_RESERVES_IN_INSERT_H

View File

@ -66,9 +66,6 @@ TEH_PG_batch_reserves_in_insert (
struct GNUNET_TIME_Timestamp gc; struct GNUNET_TIME_Timestamp gc;
struct TALER_PaytoHashP h_payto; struct TALER_PaytoHashP h_payto;
uint64_t reserve_uuid; uint64_t reserve_uuid;
bool conflicted;
bool transaction_duplicate;
bool need_update = false;
struct GNUNET_TIME_Timestamp reserve_expiration struct GNUNET_TIME_Timestamp reserve_expiration
= GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time); = GNUNET_TIME_relative_to_timestamp (pg->idle_reserve_expiration_time);
bool conflicts[reserves_length]; bool conflicts[reserves_length];
@ -100,8 +97,6 @@ TEH_PG_batch_reserves_in_insert (
GNUNET_STRINGS_relative_time_to_string ( GNUNET_STRINGS_relative_time_to_string (
pg->idle_reserve_expiration_time, pg->idle_reserve_expiration_time,
GNUNET_NO)); GNUNET_NO));
{
if (GNUNET_OK != if (GNUNET_OK !=
TEH_PG_start_read_committed (pg, TEH_PG_start_read_committed (pg,
"READ_COMMITED")) "READ_COMMITED"))
@ -109,7 +104,6 @@ TEH_PG_batch_reserves_in_insert (
GNUNET_break (0); GNUNET_break (0);
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
}
/* Optimistically assume this is a new reserve, create balance for the first /* Optimistically assume this is a new reserve, create balance for the first
time; we do this before adding the actual transaction to "reserves_in", 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 as for a new reserve it can't be a duplicate 'add' operation, and as
@ -119,9 +113,12 @@ TEH_PG_batch_reserves_in_insert (
const struct TALER_EXCHANGEDB_ReserveInInfo *reserve = &reserves[i]; const struct TALER_EXCHANGEDB_ReserveInInfo *reserve = &reserves[i];
notify_s[i] = compute_notify_on_reserve (reserve->reserve_pub); notify_s[i] = compute_notify_on_reserve (reserve->reserve_pub);
} }
bool need_update = false;
for (unsigned int i = 0; i<reserves_length; i++) for (unsigned int i = 0; i<reserves_length; i++)
{ {
bool conflicted;
bool transaction_duplicate;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserves[i].reserve_pub), GNUNET_PQ_query_param_auto_from_type (reserves[i].reserve_pub),
GNUNET_PQ_query_param_timestamp (&expiry), GNUNET_PQ_query_param_timestamp (&expiry),
@ -136,7 +133,6 @@ TEH_PG_batch_reserves_in_insert (
GNUNET_PQ_query_param_string (notify_s[i]), GNUNET_PQ_query_param_string (notify_s[i]),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_bool ("conflicted", GNUNET_PQ_result_spec_bool ("conflicted",
&conflicted), &conflicted),
@ -149,30 +145,30 @@ TEH_PG_batch_reserves_in_insert (
TALER_payto_hash (reserves[i].sender_account_details, TALER_payto_hash (reserves[i].sender_account_details,
&h_payto); &h_payto);
/* Note: query uses 'on conflict do nothing' */ /* Note: query uses 'on conflict do nothing' */
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)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to create reserves (%d)\n", "Failed to create reserves (%d)\n",
qs1); qs1);
results[i] = qs1;
return qs1; return qs1;
} }
GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs1); GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != qs1);
conflicts[i] = conflicted; conflicts[i] = conflicted;
// fprintf(stdout, "%d", conflicts[i]); // fprintf(stdout, "%d", conflicts[i]);
if (conflicts[i] && transaction_duplicate) if (conflicts[i] && transaction_duplicate)
{ {
GNUNET_break (0); GNUNET_break (0);
results[i] = GNUNET_DB_STATUS_HARD_ERROR;
TEH_PG_rollback (pg); TEH_PG_rollback (pg);
return GNUNET_DB_STATUS_HARD_ERROR; return GNUNET_DB_STATUS_HARD_ERROR;
} }
results[i] = GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
need_update |= conflicted; need_update |= conflicted;
} }
// commit // commit
@ -183,7 +179,6 @@ TEH_PG_batch_reserves_in_insert (
if (cs < 0) if (cs < 0)
return cs; return cs;
} }
if (! need_update) if (! need_update)
goto exit; goto exit;
// begin serializable // begin serializable
@ -200,35 +195,46 @@ TEH_PG_batch_reserves_in_insert (
enum GNUNET_DB_QueryStatus qs2; enum GNUNET_DB_QueryStatus qs2;
PREPARE (pg, PREPARE (pg,
"reserves_in_add_transaction", "reserves_in_add_transaction",
"SELECT exchange_do_batch_reserves_update" "SELECT"
" ($1,$2,$3,$4,$5,$6,$7,$8,$9);"); " out_duplicate AS duplicate"
" FROM exchange_do_batch_reserves_update"
" ($1,$2,$3,$4,$5,$6,$7,$8);");
for (unsigned int i = 0; i<reserves_length; i++) for (unsigned int i = 0; i<reserves_length; i++)
{ {
if (! conflicts[i]) if (! conflicts[i])
continue; continue;
{ {
bool duplicate;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_auto_from_type (reserves[i].reserve_pub), GNUNET_PQ_query_param_auto_from_type (reserves[i].reserve_pub),
GNUNET_PQ_query_param_timestamp (&expiry), GNUNET_PQ_query_param_timestamp (&expiry),
GNUNET_PQ_query_param_uint64 (&reserves[i].wire_reference), GNUNET_PQ_query_param_uint64 (&reserves[i].wire_reference),
TALER_PQ_query_param_amount (reserves[i].balance), TALER_PQ_query_param_amount (reserves[i].balance),
GNUNET_PQ_query_param_string (reserves[i].exchange_account_name), GNUNET_PQ_query_param_string (reserves[i].exchange_account_name),
GNUNET_PQ_query_param_bool (conflicted),
GNUNET_PQ_query_param_auto_from_type (&h_payto), GNUNET_PQ_query_param_auto_from_type (&h_payto),
GNUNET_PQ_query_param_string (notify_s[i]), GNUNET_PQ_query_param_string (notify_s[i]),
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
struct GNUNET_PQ_ResultSpec rs[] = {
qs2 = GNUNET_PQ_eval_prepared_non_select (pg->conn, GNUNET_PQ_result_spec_bool ("duplicate",
&duplicate),
GNUNET_PQ_result_spec_end
};
qs2 = GNUNET_PQ_eval_prepared_singleton_select (pg->conn,
"reserves_in_add_transaction", "reserves_in_add_transaction",
params); params,
if (qs2<0) rs);
if (qs2 < 0)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_WARNING, GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
"Failed to update reserves (%d)\n", "Failed to update reserves (%d)\n",
qs2); qs2);
results[i] = qs2;
return qs2; return qs2;
} }
results[i] = duplicate
? GNUNET_DB_STATUS_SUCCESS_NO_RESULTS
: GNUNET_DB_STATUS_SUCCESS_ONE_RESULT;
} }
} }
{ {
@ -238,7 +244,6 @@ TEH_PG_batch_reserves_in_insert (
if (cs < 0) if (cs < 0)
return cs; return cs;
} }
exit: exit:
for (unsigned int i = 0; i<reserves_length; i++) for (unsigned int i = 0; i<reserves_length; i++)
GNUNET_free (notify_s[i]); GNUNET_free (notify_s[i]);

View File

@ -107,7 +107,7 @@ run (void *cls)
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];
unsigned int iterations = 16;//1024*10; unsigned int iterations = 200;//1024*10;
struct TALER_ReservePublicKeyP reserve_pubs[iterations]; struct TALER_ReservePublicKeyP reserve_pubs[iterations];
struct GNUNET_TIME_Absolute now; struct GNUNET_TIME_Absolute now;
struct GNUNET_TIME_Timestamp ts; struct GNUNET_TIME_Timestamp ts;

View File

@ -62,7 +62,7 @@ static int result;
* Number of newly minted coins to use in the test. * Number of newly minted coins to use in the test.
*/ */
#define MELT_NEW_COINS 5 #define MELT_NEW_COINS 5
#define i 0
#define NUMBER_DEPOSIT 10 #define NUMBER_DEPOSIT 10
/** /**
* How big do we make the RSA keys? * How big do we make the RSA keys?
@ -353,25 +353,36 @@ run (void *cls)
&alg_values, &alg_values,
&bks); &bks);
cbc.reserve_pub = reserve_pub;
cbc.amount_with_fee = value;
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (CURRENCY,
&cbc.withdraw_fee));
/* for (unsigned int i=0; i< NUMBER_DEPOSIT; i++)
{*/
fprintf(stdout, "%d\n", i);
struct TALER_CoinSpendPublicKeyP coin_pub;
RND_BLK (&coin_pub);
{ {
struct TALER_PlanchetDetail pd; struct TALER_PlanchetDetail pd;
struct TALER_CoinSpendPublicKeyP coin_pub;
struct TALER_AgeCommitmentHash age_hash; struct TALER_AgeCommitmentHash age_hash;
struct TALER_AgeCommitmentHash *p_ah[2] = { struct TALER_AgeCommitmentHash *p_ah[2] = {
NULL, NULL,
&age_hash &age_hash
}; };
RND_BLK (&age_hash); RND_BLK (&age_hash);
for (size_t i = 0; i < sizeof(p_ah) / sizeof(p_ah[0]); i++)
for (size_t k = 0; k < sizeof(p_ah) / sizeof(p_ah[0]); k++)
{ {
fprintf(stdout, "OPEN\n"); fprintf(stdout, "OPEN\n");
RND_BLK (&coin_pub);
GNUNET_assert (GNUNET_OK == GNUNET_assert (GNUNET_OK ==
TALER_denom_blind (&dkp->pub, TALER_denom_blind (&dkp->pub,
&bks, &bks,
p_ah[i], p_ah[k],
&coin_pub, &coin_pub,
&alg_values, &alg_values,
&c_hash, &c_hash,
@ -380,7 +391,7 @@ run (void *cls)
TALER_coin_ev_hash (&pd.blinded_planchet, TALER_coin_ev_hash (&pd.blinded_planchet,
&cbc.denom_pub_hash, &cbc.denom_pub_hash,
&cbc.h_coin_envelope)); &cbc.h_coin_envelope));
if (i != 0) if (k != 0)
TALER_blinded_denom_sig_free (&cbc.sig); TALER_blinded_denom_sig_free (&cbc.sig);
GNUNET_assert ( GNUNET_assert (
GNUNET_OK == GNUNET_OK ==
@ -393,14 +404,7 @@ run (void *cls)
} }
} }
cbc.reserve_pub = reserve_pub;
cbc.amount_with_fee = value;
GNUNET_assert (GNUNET_OK ==
TALER_amount_set_zero (CURRENCY,
&cbc.withdraw_fee));
for (unsigned int i=0; i< NUMBER_DEPOSIT; i++)
{
fprintf(stdout, "%d\n", i);
depos[i].deposit_fee = fees.deposit; depos[i].deposit_fee = fees.deposit;
RND_BLK (&depos[i].coin.coin_pub); RND_BLK (&depos[i].coin.coin_pub);
@ -521,7 +525,7 @@ run (void *cls)
TALER_payto_hash (payto_uri2, TALER_payto_hash (payto_uri2,
&wire_target_h_payto); &wire_target_h_payto);
GNUNET_free (payto_uri2); GNUNET_free (payto_uri2);
} // }
/* { /* {
RND_BLK (&ref.details.merchant_pub); RND_BLK (&ref.details.merchant_pub);
RND_BLK(&ref.details.merchant_sig); RND_BLK(&ref.details.merchant_sig);
@ -544,8 +548,8 @@ drop:
cleanup: cleanup:
if (NULL != dkp) if (NULL != dkp)
destroy_denom_key_pair (dkp); destroy_denom_key_pair (dkp);
for (unsigned int i=0; i<NUMBER_DEPOSIT; i++){ // for (unsigned int i=0; i<NUMBER_DEPOSIT; i++){
TALER_denom_sig_free (&depos[i].coin.denom_sig);} TALER_denom_sig_free (&depos[i].coin.denom_sig);//}
TALER_denom_sig_free (&ref.coin.denom_sig); TALER_denom_sig_free (&ref.coin.denom_sig);
TALER_blinded_denom_sig_free (&cbc.sig); TALER_blinded_denom_sig_free (&cbc.sig);