summaryrefslogtreecommitdiff
path: root/src/backenddb/plugin_merchantdb_postgres.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backenddb/plugin_merchantdb_postgres.c')
-rw-r--r--src/backenddb/plugin_merchantdb_postgres.c60
1 files changed, 59 insertions, 1 deletions
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;