fix #4955 in auditordb, clean up fix in exchangedb
This commit is contained in:
parent
f9950799fc
commit
5d6dfde044
@ -821,8 +821,11 @@ static void
|
|||||||
db_conn_destroy (void *cls)
|
db_conn_destroy (void *cls)
|
||||||
{
|
{
|
||||||
struct TALER_AUDITORDB_Session *session = 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)
|
if (NULL != db_conn)
|
||||||
PQfinish (db_conn);
|
PQfinish (db_conn);
|
||||||
GNUNET_free (session);
|
GNUNET_free (session);
|
||||||
@ -844,7 +847,23 @@ postgres_get_session (void *cls)
|
|||||||
struct TALER_AUDITORDB_Session *session;
|
struct TALER_AUDITORDB_Session *session;
|
||||||
|
|
||||||
if (NULL != (session = pthread_getspecific (pc->db_conn_threadlocal)))
|
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);
|
db_conn = connect_to_postgres (pc);
|
||||||
if (NULL == db_conn)
|
if (NULL == db_conn)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1469,41 +1469,17 @@ static void
|
|||||||
db_conn_destroy (void *cls)
|
db_conn_destroy (void *cls)
|
||||||
{
|
{
|
||||||
struct TALER_EXCHANGEDB_Session *session = 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)
|
if (NULL != db_conn)
|
||||||
PQfinish (db_conn);
|
PQfinish (db_conn);
|
||||||
GNUNET_free (session);
|
GNUNET_free (session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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.
|
* Get the thread-local database-handle.
|
||||||
* Connect to the db if the connection does not exist yet.
|
* Connect to the db if the connection does not exist yet.
|
||||||
@ -1521,9 +1497,21 @@ postgres_get_session (void *cls)
|
|||||||
if (NULL != (session = pthread_getspecific (pc->db_conn_threadlocal)))
|
if (NULL != (session = pthread_getspecific (pc->db_conn_threadlocal)))
|
||||||
{
|
{
|
||||||
if (CONNECTION_BAD == PQstatus (session->conn))
|
if (CONNECTION_BAD == PQstatus (session->conn))
|
||||||
postgres_reset_session (pc);
|
{
|
||||||
|
/**
|
||||||
|
* 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
|
else
|
||||||
|
{
|
||||||
return session;
|
return session;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
db_conn = GNUNET_PQ_connect (pc->connection_cfg_str);
|
db_conn = GNUNET_PQ_connect (pc->connection_cfg_str);
|
||||||
if (NULL == db_conn)
|
if (NULL == db_conn)
|
||||||
|
Loading…
Reference in New Issue
Block a user