eliminate dead macros

This commit is contained in:
Christian Grothoff 2017-07-04 23:28:03 +02:00
parent d77c4160ec
commit f9950799fc
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
2 changed files with 33 additions and 67 deletions

View File

@ -30,72 +30,6 @@
#define LOG(kind,...) GNUNET_log_from (kind, "taler-auditordb-postgres", __VA_ARGS__)
/**
* 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).
*/

View File

@ -1477,6 +1477,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;