gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-exchange] 03/08: convert another function for #5010


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] 03/08: convert another function for #5010
Date: Mon, 19 Jun 2017 00:18:20 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository exchange.

commit d2c7ef54a7eb906b40032969b5bc45c180003f4b
Author: Christian Grothoff <address@hidden>
AuthorDate: Sun Jun 18 15:13:13 2017 +0200

    convert another function for #5010
---
 src/exchange/taler-exchange-httpd_db.c             | 21 ++++++--
 src/exchangedb/perf_taler_exchangedb_interpreter.c |  6 +--
 src/exchangedb/plugin_exchangedb_postgres.c        | 58 +++++++++++-----------
 src/exchangedb/test_exchangedb.c                   |  2 +-
 src/include/taler_exchangedb_plugin.h              | 12 ++---
 5 files changed, 53 insertions(+), 46 deletions(-)

diff --git a/src/exchange/taler-exchange-httpd_db.c 
b/src/exchange/taler-exchange-httpd_db.c
index 71f82e9..abbb6c3 100644
--- a/src/exchange/taler-exchange-httpd_db.c
+++ b/src/exchange/taler-exchange-httpd_db.c
@@ -228,6 +228,8 @@ TEH_DB_execute_deposit (struct MHD_Connection *connection,
   struct TEH_KS_StateHandle *mks;
   struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki;
   int ret;
+  enum GNUNET_DB_QueryStatus qs;
+  unsigned int retries = 0;
 
   if (NULL == (session = TEH_plugin->get_session (TEH_plugin->cls)))
   {
@@ -235,6 +237,7 @@ TEH_DB_execute_deposit (struct MHD_Connection *connection,
     return TEH_RESPONSE_reply_internal_db_error (connection,
                                                 TALER_EC_DB_SETUP_FAILED);
   }
+ again:
   if (GNUNET_YES ==
       TEH_plugin->have_deposit (TEH_plugin->cls,
                                 session,
@@ -305,10 +308,10 @@ TEH_DB_execute_deposit (struct MHD_Connection *connection,
   }
   TEH_plugin->free_coin_transaction_list (TEH_plugin->cls,
                                           tl);
-  if (GNUNET_OK !=
-      TEH_plugin->insert_deposit (TEH_plugin->cls,
-                                  session,
-                                  deposit))
+  qs = TEH_plugin->insert_deposit (TEH_plugin->cls,
+                                  session,
+                                  deposit);
+  if (GNUNET_DB_STATUS_HARD_ERROR == qs)
   {
     TALER_LOG_WARNING ("Failed to store /deposit information in database\n");
     TEH_plugin->rollback (TEH_plugin->cls,
@@ -316,6 +319,16 @@ TEH_DB_execute_deposit (struct MHD_Connection *connection,
     return TEH_RESPONSE_reply_internal_db_error (connection,
                                                 
TALER_EC_DEPOSIT_STORE_DB_ERROR);
   }
+  if (GNUNET_DB_STATUS_SOFT_ERROR == qs)
+  {
+    retries++;
+    TEH_plugin->rollback (TEH_plugin->cls,
+                          session);
+    if (retries > 5)
+      return TEH_RESPONSE_reply_internal_db_error (connection,
+                                                  
TALER_EC_DEPOSIT_STORE_DB_ERROR);
+    goto again;
+  }
 
   COMMIT_TRANSACTION(session, connection);
   GNUNET_assert (GNUNET_SYSERR !=
diff --git a/src/exchangedb/perf_taler_exchangedb_interpreter.c 
b/src/exchangedb/perf_taler_exchangedb_interpreter.c
index 2e43075..e378fc9 100644
--- a/src/exchangedb/perf_taler_exchangedb_interpreter.c
+++ b/src/exchangedb/perf_taler_exchangedb_interpreter.c
@@ -1334,15 +1334,15 @@ interpret (struct 
PERF_TALER_EXCHANGEDB_interpreter_state *state)
       case PERF_TALER_EXCHANGEDB_CMD_INSERT_DEPOSIT:
         {
           int deposit_index;
-          int ret;
+          enum GNUNET_DB_QueryStatus qs;
           struct TALER_EXCHANGEDB_Deposit *deposit;
 
           deposit_index = 
state->cmd[state->i].details.insert_deposit.index_deposit;
           deposit = state->cmd[deposit_index].exposed.data.deposit;
-          ret = state->plugin->insert_deposit (state->plugin->cls,
+          qs = state->plugin->insert_deposit (state->plugin->cls,
                                                         state->session,
                                                         deposit);
-          GNUNET_assert (GNUNET_SYSERR != ret);
+          GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
           state->cmd[state->i].exposed.data.deposit = deposit;
         }
         break;
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index 37db30d..d56afed 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -3181,11 +3181,9 @@ get_known_coin (void *cls,
  * @param cls plugin closure
  * @param session the shared database session
  * @param coin_info the public coin info
- * @return #GNUNET_SYSERR upon error;
- *         #GNUNET_NO on transient error
- *         #GNUNET_OK upon success
+ * @return query result status
  */
-static int
+static enum GNUNET_DB_QueryStatus
 insert_known_coin (void *cls,
                    struct TALER_EXCHANGEDB_Session *session,
                    const struct TALER_CoinPublicInfo *coin_info)
@@ -3200,9 +3198,9 @@ insert_known_coin (void *cls,
 
   GNUNET_CRYPTO_rsa_public_key_hash (coin_info->denom_pub.rsa_public_key,
                                     &denom_pub_hash);
-  return execute_prepared_non_select (session,
-                                      "insert_known_coin",
-                                      params);
+  return GNUNET_PQ_eval_prepared_non_select (session->conn,
+                                            "insert_known_coin",
+                                            params);
 }
 
 
@@ -3212,16 +3210,15 @@ insert_known_coin (void *cls,
  * @param cls the `struct PostgresClosure` with the plugin-specific state
  * @param session connection to the database
  * @param deposit deposit information to store
- * @return #GNUNET_OK on success,
- *         #GNUNET_NO on transient error
- *         #GNUNET_SYSERR on error
+ * @return query result status
  */
-static int
+static enum GNUNET_DB_QueryStatus
 postgres_insert_deposit (void *cls,
                          struct TALER_EXCHANGEDB_Session *session,
                          const struct TALER_EXCHANGEDB_Deposit *deposit)
 {
   int ret;
+  enum GNUNET_DB_QueryStatus qs;
   struct GNUNET_PQ_QueryParam params[] = {
     GNUNET_PQ_query_param_auto_from_type (&deposit->coin.coin_pub),
     TALER_PQ_query_param_amount (&deposit->amount_with_fee),
@@ -3248,19 +3245,19 @@ postgres_insert_deposit (void *cls,
   }
   if (GNUNET_NO == ret)         /* if not, insert it */
   {
-    if (GNUNET_OK !=
-        (ret = insert_known_coin (cls,
-                                  session,
-                                  &deposit->coin)))
+    qs = insert_known_coin (cls,
+                           session,
+                           &deposit->coin);
+    if (0 > qs)
     {
-      GNUNET_break (GNUNET_NO == ret);
-      return ret;
+      GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
+      return qs;
     }
   }
 
-  return execute_prepared_non_select (session,
-                                      "insert_deposit",
-                                      params);
+  return GNUNET_PQ_eval_prepared_non_select (session->conn,
+                                            "insert_deposit",
+                                            params);
 }
 
 
@@ -3416,6 +3413,7 @@ postgres_create_refresh_session (void *cls,
     GNUNET_PQ_query_param_end
   };
   int ret;
+  enum GNUNET_DB_QueryStatus qs;
 
   /* check if the coin is already known */
   ret = get_known_coin (cls,
@@ -3429,12 +3427,12 @@ postgres_create_refresh_session (void *cls,
   }
   if (GNUNET_NO == ret)         /* if not, insert it */
   {
-    if (GNUNET_OK !=
-        (ret = insert_known_coin (cls,
-                                  session,
-                                  &refresh_session->melt.coin)))
+    qs = insert_known_coin (cls,
+                           session,
+                           &refresh_session->melt.coin);
+    if (0 > qs)
     {
-      GNUNET_break (GNUNET_NO == ret);
+      GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
       return GNUNET_SYSERR;
     }
   }
@@ -6155,12 +6153,12 @@ postgres_insert_payback_request (void *cls,
   }
   if (GNUNET_NO == ret)         /* if not, insert it */
   {
-    if (GNUNET_OK !=
-        (ret = insert_known_coin (cls,
-                                  session,
-                                  coin)))
+    qs = insert_known_coin (cls,
+                           session,
+                           coin);
+    if (0 > qs)
     {
-      GNUNET_break (GNUNET_NO == ret);
+      GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs);
       return ret;
     }
   }
diff --git a/src/exchangedb/test_exchangedb.c b/src/exchangedb/test_exchangedb.c
index 28e089c..319b4dc 100644
--- a/src/exchangedb/test_exchangedb.c
+++ b/src/exchangedb/test_exchangedb.c
@@ -1768,7 +1768,7 @@ run (void *cls)
   deposit.amount_with_fee = value;
   deposit.deposit_fee = fee_deposit;
   result = 8;
-  FAILIF (GNUNET_OK !=
+  FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT !=
           plugin->insert_deposit (plugin->cls,
                                   session,
                                   &deposit));
diff --git a/src/include/taler_exchangedb_plugin.h 
b/src/include/taler_exchangedb_plugin.h
index eed4321..b5eaeea 100644
--- a/src/include/taler_exchangedb_plugin.h
+++ b/src/include/taler_exchangedb_plugin.h
@@ -1309,11 +1309,9 @@ struct TALER_EXCHANGEDB_Plugin
    * @param cls the @e cls of this struct with the plugin-specific state
    * @param session connection to the database
    * @param deposit deposit information to store
-   * @return #GNUNET_OK on success,
-   *         #GNUNET_NO on transient error
-   *         #GNUNET_SYSERR on error
+   * @return query result status
    */
-  int
+  enum GNUNET_DB_QueryStatus
   (*insert_deposit) (void *cls,
                      struct TALER_EXCHANGEDB_Session *session,
                      const struct TALER_EXCHANGEDB_Deposit *deposit);
@@ -1375,11 +1373,9 @@ struct TALER_EXCHANGEDB_Plugin
    * @param cls the @e cls of this struct with the plugin-specific state
    * @param session connection to the database
    * @param deposit_rowid identifies the deposit row to modify
-   * @return #GNUNET_OK on success,
-   *         #GNUNET_NO on transient error
-   *         #GNUNET_SYSERR on error
+   * @return query result status
    */
-  int
+  enum GNUNET_DB_QueryStatus
   (*mark_deposit_done) (void *cls,
                         struct TALER_EXCHANGEDB_Session *session,
                         uint64_t rowid);

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]