exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

update_shard_progress.c (2772B)


      1 /*
      2    This file is part of TALER
      3    Copyright (C) 2022, 2026 Taler Systems SA
      4 
      5    TALER is free software; you can redistribute it and/or modify it under the
      6    terms of the GNU General Public License as published by the Free Software
      7    Foundation; either version 3, or (at your option) any later version.
      8 
      9    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
     10    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
     11    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
     12 
     13    You should have received a copy of the GNU General Public License along with
     14    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
     15  */
     16 /**
     17  * @file exchangedb/update_shard_progress.c
     18  * @brief Implementation of the update_shard_progress function for Postgres
     19  * @author Christian Grothoff
     20  */
     21 #include "taler/taler_pq_lib.h"
     22 #include "exchange-database/update_shard_progress.h"
     23 #include "helper.h"
     24 
     25 
     26 enum GNUNET_DB_QueryStatus
     27 TALER_EXCHANGEDB_update_shard_progress (
     28   struct TALER_EXCHANGEDB_PostgresContext *pg,
     29   const char *job_name,
     30   uint64_t start_row,
     31   uint64_t end_row,
     32   uint64_t progress_row,
     33   struct GNUNET_TIME_Relative lease)
     34 {
     35   struct GNUNET_TIME_Absolute lease_until
     36     = GNUNET_TIME_relative_to_absolute (lease);
     37   struct GNUNET_PQ_QueryParam params[] = {
     38     GNUNET_PQ_query_param_string (job_name),
     39     GNUNET_PQ_query_param_uint64 (&start_row),
     40     GNUNET_PQ_query_param_uint64 (&end_row),
     41     GNUNET_PQ_query_param_uint64 (&progress_row),
     42     GNUNET_PQ_query_param_absolute_time (&lease_until),
     43     GNUNET_PQ_query_param_end
     44   };
     45 
     46   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
     47               "Shard %s (%llu,%llu] progressed to %llu\n",
     48               job_name,
     49               (unsigned long long) start_row,
     50               (unsigned long long) end_row,
     51               (unsigned long long) progress_row);
     52   /* GREATEST() keeps this monotonic: a worker that lost the shard to a second
     53      one and only notices later must not push the marker back. Both the
     54      'completed' flag and the lease renewal ride along on this one statement,
     55      so a caller never needs a second round-trip (let alone a second
     56      transaction) to say "and that was the last of it". */
     57   PREPARE (pg,
     58            "update_shard_progress",
     59            "UPDATE work_shards"
     60            "   SET progress_row=GREATEST(progress_row,$4)"
     61            "      ,completed=(GREATEST(progress_row,$4) >= end_row)"
     62            "      ,last_attempt=$5"
     63            " WHERE job_name=$1"
     64            "   AND start_row=$2"
     65            "   AND end_row=$3;");
     66   return GNUNET_PQ_eval_prepared_non_select (pg->conn,
     67                                              "update_shard_progress",
     68                                              params);
     69 }