summaryrefslogtreecommitdiff
path: root/src/exchangedb/plugin_exchangedb_postgres.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2017-07-04 23:28:03 +0200
committerChristian Grothoff <christian@grothoff.org>2017-07-04 23:28:03 +0200
commitf9950799fc21c6847d13f93aaec2cd6a555d546a (patch)
tree02816ec563bf39fb4e719fb284a1b05ed09f7161 /src/exchangedb/plugin_exchangedb_postgres.c
parentd77c4160ecf7b1d33d49ba47e3236f5dcc14ecc8 (diff)
downloadexchange-f9950799fc21c6847d13f93aaec2cd6a555d546a.tar.gz
exchange-f9950799fc21c6847d13f93aaec2cd6a555d546a.tar.bz2
exchange-f9950799fc21c6847d13f93aaec2cd6a555d546a.zip
eliminate dead macros
Diffstat (limited to 'src/exchangedb/plugin_exchangedb_postgres.c')
-rw-r--r--src/exchangedb/plugin_exchangedb_postgres.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/exchangedb/plugin_exchangedb_postgres.c b/src/exchangedb/plugin_exchangedb_postgres.c
index b6241c8f3..de3c783ea 100644
--- a/src/exchangedb/plugin_exchangedb_postgres.c
+++ b/src/exchangedb/plugin_exchangedb_postgres.c
@@ -1478,6 +1478,33 @@ db_conn_destroy (void *cls)
/**
+ * Reset the thread-local database-handle. Disconnects from the DB.
+ * Needed after the database server restarts as we need to properly
+ * reconnect.
+ *
+ * @param cls the `struct PostgresClosure` with the plugin-specific state
+ * @return the database connection, or NULL on error
+ */
+static void
+postgres_reset_session (void *cls)
+{
+ struct PostgresClosure *pc = cls;
+ struct TALER_EXCHANGEDB_Session *session;
+
+ if (NULL != (session = pthread_getspecific (pc->db_conn_threadlocal)))
+ return;
+ if (0 != pthread_setspecific (pc->db_conn_threadlocal,
+ NULL))
+ {
+ GNUNET_break (0);
+ return;
+ }
+ PQfinish (session->conn);
+ GNUNET_free (session);
+}
+
+
+/**
* Get the thread-local database-handle.
* Connect to the db if the connection does not exist yet.
*
@@ -1492,7 +1519,12 @@ 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))
+ postgres_reset_session (pc);
+ else
+ return session;
+ }
db_conn = GNUNET_PQ_connect (pc->connection_cfg_str);
if (NULL == db_conn)
return NULL;