From 0df2028f96f5977739d4659bf253e0c6d9468326 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Sun, 19 Aug 2018 16:01:57 +0200 Subject: make transactions smaller to try to reduce rollbacks --- src/exchangedb/perf_taler_exchangedb_interpreter.c | 12 +++++-- src/exchangedb/plugin_exchangedb_postgres.c | 39 +++++++++++++--------- src/exchangedb/test_exchangedb.c | 12 +++++++ 3 files changed, 46 insertions(+), 17 deletions(-) (limited to 'src/exchangedb') diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c b/src/exchangedb/perf_taler_exchangedb_interpreter.c index 43891e55f..2d0ec396c 100644 --- a/src/exchangedb/perf_taler_exchangedb_interpreter.c +++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c @@ -1205,6 +1205,10 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state) deposit_index = state->cmd[state->i].details.insert_deposit.index_deposit; deposit = state->cmd[deposit_index].exposed.data.deposit; + qs = state->plugin->ensure_coin_known (state->plugin->cls, + state->session, + &deposit->coin); + GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs); qs = state->plugin->insert_deposit (state->plugin->cls, state->session, deposit); @@ -1434,7 +1438,11 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state) &refresh_session.amount_with_fee)); refresh_session.noreveal_index = 1; GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == - state->plugin->insert_melt (state->session, + state->plugin->ensure_coin_known (state->plugin->cls, + state->session, + &refresh_session.coin)); + GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == + state->plugin->insert_melt (state->plugin->cls, state->session, &refresh_session)); state->cmd[state->i].exposed.data.rc = refresh_session.rc; @@ -1449,7 +1457,7 @@ interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state) hash_index = state->cmd[state->i].details.get_refresh_session.index_hash; rc = &state->cmd[hash_index].exposed.data.rc; - state->plugin->get_melt (state->session, + state->plugin->get_melt (state->plugin->cls, state->session, rc, &refresh); diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 724bf28a5..d3efb9314 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -3197,15 +3197,16 @@ insert_known_coin (void *cls, * @return database transaction status, non-negative on success */ static enum GNUNET_DB_QueryStatus -ensure_coin_known (struct PostgresClosure *cls, - struct TALER_EXCHANGEDB_Session *session, - const struct TALER_CoinPublicInfo *coin) +postgres_ensure_coin_known (void *cls, + struct TALER_EXCHANGEDB_Session *session, + const struct TALER_CoinPublicInfo *coin) { + struct PostgresClosure *pc = cls; enum GNUNET_DB_QueryStatus qs; struct TALER_CoinPublicInfo known_coin; /* check if the coin is already known */ - qs = get_known_coin (cls, + qs = get_known_coin (pc, session, &coin->coin_pub, &known_coin); @@ -3222,7 +3223,7 @@ ensure_coin_known (struct PostgresClosure *cls, } GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs); /* if not known, insert it */ - qs = insert_known_coin (cls, + qs = insert_known_coin (pc, session, coin); if (0 >= qs) @@ -3249,7 +3250,6 @@ postgres_insert_deposit (void *cls, struct TALER_EXCHANGEDB_Session *session, const struct TALER_EXCHANGEDB_Deposit *deposit) { - enum GNUNET_DB_QueryStatus qs; struct GNUNET_PQ_QueryParam params[] = { GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub), TALER_PQ_query_param_amount (&deposit->amount_with_fee), @@ -3264,10 +3264,14 @@ postgres_insert_deposit (void *cls, GNUNET_PQ_query_param_end }; - if (0 > (qs = ensure_coin_known (cls, - session, - &deposit->coin))) +#if 0 + enum GNUNET_DB_QueryStatus qs; + + if (0 > (qs = postgres_ensure_coin_known (cls, + session, + &deposit->coin))) return qs; +#endif GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Inserting deposit to be executed at %s (%llu/%llu)\n", GNUNET_STRINGS_absolute_time_to_string (deposit->wire_deadline), @@ -3501,12 +3505,14 @@ postgres_insert_melt (void *cls, GNUNET_PQ_query_param_uint32 (&refresh_session->noreveal_index), GNUNET_PQ_query_param_end }; +#if 0 enum GNUNET_DB_QueryStatus qs; - if (0 > (qs = ensure_coin_known (cls, - session, - &refresh_session->coin))) + if (0 > (qs = postgres_ensure_coin_known (cls, + session, + &refresh_session->coin))) return qs; +#endif return GNUNET_PQ_eval_prepared_non_select (session->conn, "insert_melt", params); @@ -6371,11 +6377,13 @@ postgres_insert_payback_request (void *cls, }; enum GNUNET_DB_QueryStatus qs; +#if 0 /* check if the coin is already known */ - if (0 > (qs = ensure_coin_known (cls, - session, - coin))) + if (0 > (qs = postgres_ensure_coin_known (cls, + session, + coin))) return qs; +#endif /* now store actual payback information */ qs = GNUNET_PQ_eval_prepared_non_select (session->conn, "payback_insert", @@ -6993,6 +7001,7 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) plugin->insert_withdraw_info = &postgres_insert_withdraw_info; plugin->get_reserve_history = &postgres_get_reserve_history; plugin->free_reserve_history = &common_free_reserve_history; + plugin->ensure_coin_known = &postgres_ensure_coin_known; plugin->have_deposit = &postgres_have_deposit; plugin->mark_deposit_tiny = &postgres_mark_deposit_tiny; plugin->test_deposit_done = &postgres_test_deposit_done; diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c index 16467d578..8666f1a5d 100644 --- a/src/exchangedb/test_exchangedb.c +++ b/src/exchangedb/test_exchangedb.c @@ -590,6 +590,10 @@ test_melting (struct TALER_EXCHANGEDB_Session *session) session, &refresh_session.rc, &ret_refresh_session)); + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->ensure_coin_known (plugin->cls, + session, + &refresh_session.coin)); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->insert_melt (plugin->cls, session, @@ -1775,6 +1779,10 @@ run (void *cls) deposit.coin.denom_sig = cbc.sig; deadline = GNUNET_TIME_absolute_get (); (void) GNUNET_TIME_round_abs (&deadline); + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->ensure_coin_known (plugin->cls, + session, + &deposit.coin)); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->insert_payback_request (plugin->cls, session, @@ -1922,6 +1930,10 @@ run (void *cls) deposit.refund_deadline = deadline; deposit.wire_deadline = deadline; result = 8; + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->ensure_coin_known (plugin->cls, + session, + &deposit.coin)); FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != plugin->insert_deposit (plugin->cls, session, -- cgit v1.2.3