From a13f90a15ee910c0ada316366e197de11bc6cc62 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 14 Apr 2022 00:00:50 +0200 Subject: add wirewatch shutdown shard cleanup logic --- src/exchangedb/plugin_exchangedb_postgres.c | 40 +++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/exchangedb/plugin_exchangedb_postgres.c') diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c index 9d3171c2..ff2dcbf4 100644 --- a/src/exchangedb/plugin_exchangedb_postgres.c +++ b/src/exchangedb/plugin_exchangedb_postgres.c @@ -3354,6 +3354,15 @@ prepare_statements (struct PostgresClosure *pg) " ORDER BY end_row DESC" " LIMIT 1;", 1), + /* Used in #postgres_abort_shard() */ + GNUNET_PQ_make_prepare ( + "abort_shard", + "UPDATE work_shards" + " SET last_attempt=0" + " WHERE job_name = $1 " + " AND start_row = $2 " + " AND end_row = $3;", + 3), /* Used in #postgres_begin_shard() */ GNUNET_PQ_make_prepare ( "claim_next_shard", @@ -12586,6 +12595,35 @@ commit: } +/** + * Function called to abort work on a shard. + * + * @param cls the @e cls of this struct with the plugin-specific state + * @param job_name name of the operation to abort a word shard for + * @param start_row inclusive start row of the shard + * @param end_row exclusive end row of the shard + * @return transaction status code + */ +static enum GNUNET_DB_QueryStatus +postgres_abort_shard (void *cls, + const char *job_name, + uint64_t start_row, + uint64_t end_row) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (job_name), + GNUNET_PQ_query_param_uint64 (&start_row), + GNUNET_PQ_query_param_uint64 (&end_row), + GNUNET_PQ_query_param_end + }; + + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "abort_shard", + params); +} + + /** * Function called to persist that work on a shard was completed. * @@ -13889,6 +13927,8 @@ libtaler_plugin_exchangedb_postgres_init (void *cls) = &postgres_insert_records_by_table; plugin->begin_shard = &postgres_begin_shard; + plugin->abort_shard + = &postgres_abort_shard; plugin->complete_shard = &postgres_complete_shard; plugin->begin_revolving_shard -- cgit v1.2.3