diff options
author | Christian Grothoff <christian@grothoff.org> | 2021-08-01 11:55:11 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2021-08-01 11:56:52 +0200 |
commit | 76cf111084c13d5dc2d4ba686ecbbdeb8ff1ade9 (patch) | |
tree | d4fc196e98d9d0b10563e939d626ace7c03fcb34 | |
parent | 42d323d4344c748e1e793a606646c932d998cb47 (diff) |
-implement lock expiratin (#6937)
m--------- | contrib/merchant-backoffice | 0 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-orders.c | 6 | ||||
-rw-r--r-- | src/backend/taler-merchant-httpd_private-post-products-ID-lock.c | 2 | ||||
-rw-r--r-- | src/backenddb/plugin_merchantdb_postgres.c | 60 | ||||
-rw-r--r-- | src/include/taler_merchantdb_plugin.h | 11 |
5 files changed, 76 insertions, 3 deletions
diff --git a/contrib/merchant-backoffice b/contrib/merchant-backoffice -Subproject 4320467db1392e5f48a4acd079f7e2a253cf998 +Subproject fe987187e178816d42ed12178d430c8771cb5a7 diff --git a/src/backend/taler-merchant-httpd_private-post-orders.c b/src/backend/taler-merchant-httpd_private-post-orders.c index 22e6327f..c3923995 100644 --- a/src/backend/taler-merchant-httpd_private-post-orders.c +++ b/src/backend/taler-merchant-httpd_private-post-orders.c @@ -1331,9 +1331,11 @@ TMH_private_post_orders (const struct TMH_RequestHandler *rh, : MHD_NO; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, - "Refund delay is %llu\n", - (unsigned long long) refund_delay.rel_value_us); + "Refund delay is %s\n", + GNUNET_STRINGS_relative_time_to_string (refund_delay, + GNUNET_NO)); + TMH_db->expire_locks (TMH_db->cls); if (create_token) { GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_NONCE, diff --git a/src/backend/taler-merchant-httpd_private-post-products-ID-lock.c b/src/backend/taler-merchant-httpd_private-post-products-ID-lock.c index 7fc7b0ac..9983b520 100644 --- a/src/backend/taler-merchant-httpd_private-post-products-ID-lock.c +++ b/src/backend/taler-merchant-httpd_private-post-products-ID-lock.c @@ -24,6 +24,7 @@ */ #include "platform.h" #include "taler-merchant-httpd_private-post-products-ID-lock.h" +#include "taler-merchant-httpd_helper.h" #include <taler/taler_json_lib.h> @@ -64,6 +65,7 @@ TMH_private_post_products_ID_lock (const struct TMH_RequestHandler *rh, } TMH_uuid_from_string (uuids, &uuid); + TMH_db->expire_locks (TMH_db->cls); qs = TMH_db->lock_product (TMH_db->cls, mi->settings.id, product_id, diff --git a/src/backenddb/plugin_merchantdb_postgres.c b/src/backenddb/plugin_merchantdb_postgres.c index 46e5e376..b882b24b 100644 --- a/src/backenddb/plugin_merchantdb_postgres.c +++ b/src/backenddb/plugin_merchantdb_postgres.c @@ -1,6 +1,6 @@ /* This file is part of TALER - (C) 2014--2020 Taler Systems SA + (C) 2014--2021 Taler Systems SA TALER is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software @@ -1220,6 +1220,51 @@ postgres_lock_product (void *cls, /** + * Release all expired product locks, including + * those from expired offers -- across all + * instances. + * + * @param cls closure + * @return database result code, #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if nothing was unlocked + */ +static void +postgres_expire_locks (void *cls) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_TIME_Absolute now; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_absolute_time (&now), + GNUNET_PQ_query_param_end + }; + enum GNUNET_DB_QueryStatus qs1; + enum GNUNET_DB_QueryStatus qs2; + + check_connection (pg); + now = GNUNET_TIME_absolute_get (); + qs1 = GNUNET_PQ_eval_prepared_non_select (pg->conn, + "unlock_products", + params); + if (qs1 < 0) + { + GNUNET_break (0); + return; + } + qs2 = GNUNET_PQ_eval_prepared_non_select (pg->conn, + "unlock_orders", + params); + if (qs2 < 0) + { + GNUNET_break (0); + return; + } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Released %d+%d locks\n", + qs1, + qs2); +} + + +/** * Delete information about an order. Note that the transaction must * enforce that the order is not awaiting payment anymore. * @@ -6586,6 +6631,18 @@ postgres_connect (void *cls) " FROM merchant_order_locks" " WHERE product_serial=ps.product_serial)", 5), + + /* for postgres_expire_locks() */ + GNUNET_PQ_make_prepare ("unlock_products", + "DELETE FROM merchant_inventory_locks" + " WHERE expiration < $1", + 1), + /* for postgres_expire_locks() */ + GNUNET_PQ_make_prepare ("unlock_orders", + "DELETE FROM merchant_orders" + " WHERE pay_deadline < $1", + 1), + /* for postgres_delete_order() */ GNUNET_PQ_make_prepare ("delete_order", "DELETE" @@ -8832,6 +8889,7 @@ libtaler_plugin_merchantdb_postgres_init (void *cls) plugin->insert_product = &postgres_insert_product; plugin->update_product = &postgres_update_product; plugin->lock_product = &postgres_lock_product; + plugin->expire_locks = &postgres_expire_locks; plugin->delete_order = &postgres_delete_order; plugin->lookup_order = &postgres_lookup_order; plugin->lookup_order_summary = &postgres_lookup_order_summary; diff --git a/src/include/taler_merchantdb_plugin.h b/src/include/taler_merchantdb_plugin.h index 91c33f60..f8ac0eaf 100644 --- a/src/include/taler_merchantdb_plugin.h +++ b/src/include/taler_merchantdb_plugin.h @@ -1011,6 +1011,17 @@ struct TALER_MERCHANTDB_Plugin /** + * Release all expired product locks, including + * those from expired offers -- across all + * instances. + * + * @param cls closure + */ + void + (*expire_locks)(void *cls); + + + /** * Delete information about an order. Note that the transaction must * enforce that the order is not awaiting payment anymore. * |