address #5010 for wirewatch

This commit is contained in:
Christian Grothoff 2017-06-23 14:37:53 +02:00
parent ff8633910d
commit 6acb0271d6
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
4 changed files with 54 additions and 68 deletions

View File

@ -223,7 +223,7 @@ history_cb (void *cls,
const struct TALER_WIRE_TransferDetails *details) const struct TALER_WIRE_TransferDetails *details)
{ {
struct TALER_EXCHANGEDB_Session *session = cls; struct TALER_EXCHANGEDB_Session *session = cls;
int ret; enum GNUNET_DB_QueryStatus qs;
if (TALER_BANK_DIRECTION_NONE == dir) if (TALER_BANK_DIRECTION_NONE == dir)
{ {
@ -231,9 +231,9 @@ history_cb (void *cls,
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
"End of list. Committing progress!\n"); "End of list. Committing progress!\n");
ret = db_plugin->commit (db_plugin->cls, qs = db_plugin->commit (db_plugin->cls,
session); session);
if (GNUNET_OK == ret) if (0 <= qs)
{ {
GNUNET_free_non_null (start_off); GNUNET_free_non_null (start_off);
start_off = last_row_off; start_off = last_row_off;
@ -258,7 +258,7 @@ history_cb (void *cls,
"Adding wire transfer over %s with subject `%s'\n", "Adding wire transfer over %s with subject `%s'\n",
TALER_amount2s (&details->amount), TALER_amount2s (&details->amount),
TALER_B2S (&details->reserve_pub)); TALER_B2S (&details->reserve_pub));
ret = db_plugin->reserves_in_insert (db_plugin->cls, qs = db_plugin->reserves_in_insert (db_plugin->cls,
session, session,
&details->reserve_pub, &details->reserve_pub,
&details->amount, &details->amount,
@ -266,9 +266,16 @@ history_cb (void *cls,
details->account_details, details->account_details,
row_off, row_off,
row_off_size); row_off_size);
if (GNUNET_OK != ret) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{ {
GNUNET_break (0); GNUNET_break (0);
db_plugin->rollback (db_plugin->cls,
session);
GNUNET_SCHEDULER_shutdown ();
return GNUNET_SYSERR;
}
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
{
db_plugin->rollback (db_plugin->cls, db_plugin->rollback (db_plugin->cls,
session); session);
/* try again */ /* try again */
@ -298,7 +305,7 @@ static void
find_transfers (void *cls) find_transfers (void *cls)
{ {
struct TALER_EXCHANGEDB_Session *session; struct TALER_EXCHANGEDB_Session *session;
int ret; enum GNUNET_DB_QueryStatus qs;
task = NULL; task = NULL;
GNUNET_log (GNUNET_ERROR_TYPE_INFO, GNUNET_log (GNUNET_ERROR_TYPE_INFO,
@ -322,11 +329,11 @@ find_transfers (void *cls)
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
} }
ret = db_plugin->get_latest_reserve_in_reference (db_plugin->cls, qs = db_plugin->get_latest_reserve_in_reference (db_plugin->cls,
session, session,
&start_off, &start_off,
&start_off_size); &start_off_size);
if (GNUNET_SYSERR == ret) if (GNUNET_DB_STATUS_HARD_ERROR == qs)
{ {
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to obtain starting point for montoring from database!\n"); "Failed to obtain starting point for montoring from database!\n");
@ -334,6 +341,15 @@ find_transfers (void *cls)
GNUNET_SCHEDULER_shutdown (); GNUNET_SCHEDULER_shutdown ();
return; return;
} }
if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
{
/* try again */
db_plugin->rollback (db_plugin->cls,
session);
task = GNUNET_SCHEDULER_add_now (&find_transfers,
NULL);
return;
}
delay = GNUNET_YES; delay = GNUNET_YES;
hh = wire_plugin->get_history (wire_plugin->cls, hh = wire_plugin->get_history (wire_plugin->cls,
TALER_BANK_DIRECTION_CREDIT, TALER_BANK_DIRECTION_CREDIT,

View File

@ -2092,36 +2092,17 @@ postgres_reserves_in_insert (void *cls,
* @param session the database session handle * @param session the database session handle
* @param[out] wire_reference set to unique reference identifying the wire transfer (binary blob) * @param[out] wire_reference set to unique reference identifying the wire transfer (binary blob)
* @param[out] wire_reference_size set to number of bytes in @a wire_reference * @param[out] wire_reference_size set to number of bytes in @a wire_reference
* @return #GNUNET_OK upon success; #GNUNET_NO if we never got any incoming transfers * @return transaction status code
* #GNUNET_SYSERR upon failures (DB error)
*/ */
static int static enum GNUNET_DB_QueryStatus
postgres_get_latest_reserve_in_reference (void *cls, postgres_get_latest_reserve_in_reference (void *cls,
struct TALER_EXCHANGEDB_Session *session, struct TALER_EXCHANGEDB_Session *session,
void **wire_reference, void **wire_reference,
size_t *wire_reference_size) size_t *wire_reference_size)
{ {
PGresult *result;
struct GNUNET_PQ_QueryParam params[] = { struct GNUNET_PQ_QueryParam params[] = {
GNUNET_PQ_query_param_end GNUNET_PQ_query_param_end
}; };
int ret;
ret = GNUNET_SYSERR;
result = GNUNET_PQ_exec_prepared (session->conn,
"reserves_in_get_latest_wire_reference",
params);
if (PGRES_TUPLES_OK != PQresultStatus (result))
{
QUERY_ERR (result, session->conn);
goto cleanup;
}
if (0 == PQntuples (result))
{
ret = GNUNET_NO;
goto cleanup;
}
{
struct GNUNET_PQ_ResultSpec rs[] = { struct GNUNET_PQ_ResultSpec rs[] = {
GNUNET_PQ_result_spec_variable_size ("wire_reference", GNUNET_PQ_result_spec_variable_size ("wire_reference",
wire_reference, wire_reference,
@ -2129,19 +2110,10 @@ postgres_get_latest_reserve_in_reference (void *cls,
GNUNET_PQ_result_spec_end GNUNET_PQ_result_spec_end
}; };
if (GNUNET_OK != return GNUNET_PQ_eval_prepared_singleton_select (session->conn,
GNUNET_PQ_extract_result (result, "reserves_in_get_latest_wire_reference",
rs, params,
0)) rs);
{
GNUNET_break (0);
goto cleanup;
}
}
ret = GNUNET_OK;
cleanup:
PQclear (result);
return ret;
} }

View File

@ -1518,7 +1518,7 @@ run (void *cls)
result = 4; result = 4;
sndr = json_loads ("{ \"account\":\"1\" }", 0, NULL); sndr = json_loads ("{ \"account\":\"1\" }", 0, NULL);
GNUNET_assert (NULL != sndr); GNUNET_assert (NULL != sndr);
FAILIF (GNUNET_NO != FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS !=
plugin->get_latest_reserve_in_reference (plugin->cls, plugin->get_latest_reserve_in_reference (plugin->cls,
session, session,
&rr, &rr,
@ -1532,7 +1532,7 @@ run (void *cls)
sndr, sndr,
"TEST", "TEST",
4)); 4));
FAILIF (GNUNET_OK != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls, plugin->get_latest_reserve_in_reference (plugin->cls,
session, session,
&rr, &rr,
@ -1555,12 +1555,12 @@ run (void *cls)
sndr, sndr,
"TEST2", "TEST2",
5)); 5));
FAILIF (GNUNET_OK != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls, plugin->get_latest_reserve_in_reference (plugin->cls,
session, session,
&rr, &rr,
&rr_size)); &rr_size));
FAILIF (GNUNET_OK != FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
plugin->get_latest_reserve_in_reference (plugin->cls, plugin->get_latest_reserve_in_reference (plugin->cls,
session, session,
&rr, &rr,

View File

@ -1107,8 +1107,7 @@ struct TALER_EXCHANGEDB_Plugin
* *
* @param cls the @e cls of this struct with the plugin-specific state * @param cls the @e cls of this struct with the plugin-specific state
* @param session connection to use * @param session connection to use
* @return #GNUNET_OK on success, #GNUNET_NO if the transaction * @return transaction status
* can be retried, #GNUNET_SYSERR on hard failures
*/ */
enum GNUNET_DB_QueryStatus enum GNUNET_DB_QueryStatus
(*commit) (void *cls, (*commit) (void *cls,
@ -1210,10 +1209,9 @@ struct TALER_EXCHANGEDB_Plugin
* @param db the database connection handle * @param db the database connection handle
* @param[out] wire_reference set to unique reference identifying the wire transfer (binary blob) * @param[out] wire_reference set to unique reference identifying the wire transfer (binary blob)
* @param[out] wire_reference_size set to number of bytes in @a wire_reference * @param[out] wire_reference_size set to number of bytes in @a wire_reference
* @return #GNUNET_OK upon success; #GNUNET_NO if we never got any incoming transfers * @return transaction status code
* #GNUNET_SYSERR upon failures (DB error)
*/ */
int enum GNUNET_DB_QueryStatus
(*get_latest_reserve_in_reference)(void *cls, (*get_latest_reserve_in_reference)(void *cls,
struct TALER_EXCHANGEDB_Session *db, struct TALER_EXCHANGEDB_Session *db,
void **wire_reference, void **wire_reference,