gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [taler-exchange] branch master updated (d77c416 -> 5d6dfde)


From: gnunet
Subject: [GNUnet-SVN] [taler-exchange] branch master updated (d77c416 -> 5d6dfde)
Date: Tue, 04 Jul 2017 23:42:18 +0200

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

grothoff pushed a change to branch master
in repository exchange.

    from d77c416  implement logic to check protocol version compatibility 
(#5035)
     new f995079  eliminate dead macros
     new 5d6dfde  fix #4955 in auditordb, clean up fix in exchangedb

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/auditordb/plugin_auditordb_postgres.c   | 89 +++++++----------------------
 src/exchangedb/plugin_exchangedb_postgres.c | 24 +++++++-
 2 files changed, 43 insertions(+), 70 deletions(-)

diff --git a/src/auditordb/plugin_auditordb_postgres.c 
b/src/auditordb/plugin_auditordb_postgres.c
index e02e69a..4862cf2 100644
--- a/src/auditordb/plugin_auditordb_postgres.c
+++ b/src/auditordb/plugin_auditordb_postgres.c
@@ -31,72 +31,6 @@
 
 
 /**
- * Log a query error.
- *
- * @param result PQ result object of the query that failed
- */
-#define QUERY_ERR(result)                          \
-  LOG (GNUNET_ERROR_TYPE_ERROR, "Query failed at %s:%u: %s (%s)\n", __FILE__, 
__LINE__, PQresultErrorMessage (result), PQresStatus (PQresultStatus (result)))
-
-
-/**
- * Log a really unexpected PQ error.
- *
- * @param result PQ result object of the PQ operation that failed
- */
-#define BREAK_DB_ERR(result) do { \
-    GNUNET_break (0); \
-    LOG (GNUNET_ERROR_TYPE_ERROR, "Database failure: %s (%s)\n", 
PQresultErrorMessage (result), PQresStatus (PQresultStatus (result))); \
-  } while (0)
-
-
-/**
- * Shorthand for exit jumps.  Logs the current line number
- * and jumps to the "EXITIF_exit" label.
- *
- * @param cond condition that must be TRUE to exit with an error
- */
-#define EXITIF(cond)                                              \
-  do {                                                            \
-    if (cond) { GNUNET_break (0); goto EXITIF_exit; }             \
-  } while (0)
-
-
-/**
- * Execute an SQL statement and log errors on failure. Must be
- * run in a function that has an "SQLEXEC_fail" label to jump
- * to in case the SQL statement failed.
- *
- * @param conn database connection
- * @param sql SQL statement to run
- */
-#define SQLEXEC_(conn, sql)                                             \
-  do {                                                                  \
-    PGresult *result = PQexec (conn, sql);                              \
-    if (PGRES_COMMAND_OK != PQresultStatus (result))                    \
-    {                                                                   \
-      BREAK_DB_ERR (result);                                            \
-      PQclear (result);                                                 \
-      goto SQLEXEC_fail;                                                \
-    }                                                                   \
-    PQclear (result);                                                   \
-  } while (0)
-
-
-/**
- * Run an SQL statement, ignoring errors and clearing the result.
- *
- * @param conn database connection
- * @param sql SQL statement to run
- */
-#define SQLEXEC_IGNORE_ERROR_(conn, sql)                                \
-  do {                                                                  \
-    PGresult *result = PQexec (conn, sql);                              \
-    PQclear (result);                                                   \
-  } while (0)
-
-
-/**
  * Handle for a database session (per-thread, for transactions).
  */
 struct TALER_AUDITORDB_Session
@@ -887,8 +821,11 @@ static void
 db_conn_destroy (void *cls)
 {
   struct TALER_AUDITORDB_Session *session = cls;
-  PGconn *db_conn = session->conn;
+  PGconn *db_conn;
 
+  if (NULL == session)
+    return;
+  db_conn = session->conn;
   if (NULL != db_conn)
     PQfinish (db_conn);
   GNUNET_free (session);
@@ -910,7 +847,23 @@ postgres_get_session (void *cls)
   struct TALER_AUDITORDB_Session *session;
 
   if (NULL != (session = pthread_getspecific (pc->db_conn_threadlocal)))
-    return session;
+  {
+    if (CONNECTION_BAD == PQstatus (session->conn))
+    {
+      /**
+       * Reset the thread-local database-handle.  Disconnects from the
+       * DB.  Needed after the database server restarts as we need to
+       * properly reconnect. */
+      GNUNET_assert (0 == pthread_setspecific (pc->db_conn_threadlocal,
+                                             NULL));
+      PQfinish (session->conn);
+      GNUNET_free (session);
+    }
+    else
+    {
+      return session;
+    }
+  }
   db_conn = connect_to_postgres (pc);
   if (NULL == db_conn)
     return NULL;
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c 
b/src/exchangedb/plugin_exchangedb_postgres.c
index b6241c8..8b3fe7f 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -1469,8 +1469,11 @@ static void
 db_conn_destroy (void *cls)
 {
   struct TALER_EXCHANGEDB_Session *session = cls;
-  PGconn *db_conn = session->conn;
+  PGconn *db_conn;
 
+  if (NULL == session)
+    return;
+  db_conn = session->conn;
   if (NULL != db_conn)
     PQfinish (db_conn);
   GNUNET_free (session);
@@ -1492,7 +1495,24 @@ postgres_get_session (void *cls)
   struct TALER_EXCHANGEDB_Session *session;
 
   if (NULL != (session = pthread_getspecific (pc->db_conn_threadlocal)))
-    return session;
+  {
+    if (CONNECTION_BAD == PQstatus (session->conn))
+    {
+      /**
+       * Reset the thread-local database-handle.  Disconnects from the
+       * DB.  Needed after the database server restarts as we need to
+       * properly reconnect. */
+      GNUNET_assert (0 ==
+                    pthread_setspecific (pc->db_conn_threadlocal,
+                                         NULL));
+      PQfinish (session->conn);
+      GNUNET_free (session);
+    }
+    else
+    {
+      return session;
+    }
+  }
   db_conn = GNUNET_PQ_connect (pc->connection_cfg_str);
   if (NULL == db_conn)
     return NULL;

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



reply via email to

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