author | Sebastian Harl <sh@tokkee.org> | |
Tue, 5 Mar 2013 01:11:13 +0000 (02:11 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 5 Mar 2013 01:11:13 +0000 (02:11 +0100) |
src/backend/puppet-storeconfigs.c | patch | blob | history | |
src/include/utils/dbi.h | patch | blob | history | |
src/utils/dbi.c | patch | blob | history |
index 1129a5a1f352f40d6894df6827a1e87b2226d3de..f03380871a1de9dc38c733cea763f592f7624c2f 100644 (file)
return -1;
client = SDB_OBJ_WRAPPER(user_data)->data;
+ if (sdb_dbi_client_check_conn(client)) {
+ fprintf(stderr, "puppet storeconfigs backend: "
+ "Connection to storeconfigs DB failed.\n");
+ return -1;
+ }
+
if (sdb_dbi_exec_query(client, "SELECT name, updated_at FROM hosts;",
sdb_puppet_stcfg_get_hosts, NULL, /* #columns = */ 2,
/* col types = */ SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
index 77d004296d333acaefc7460677a246765e182423..c2490410de8b5a38cd66b8c89db85f0e1b9bd1df 100644 (file)
--- a/src/include/utils/dbi.h
+++ b/src/include/utils/dbi.h
int
sdb_dbi_client_connect(sdb_dbi_client_t *client);
+/*
+ * sdb_dbi_client_check_conn:
+ * Check the database-connection and try to reconnect if that fails.
+ *
+ * Returns:
+ * - 0 on success (the connection is connected after the call)
+ * - a negative value else (failed to reconnect)
+ */
+int
+sdb_dbi_client_check_conn(sdb_dbi_client_t *client);
+
/*
* sdb_dbi_exec_query:
* Execute an SQL query on the database. The specified 'callback' will be
diff --git a/src/utils/dbi.c b/src/utils/dbi.c
index ee2280ce939e6bb9f61cdde27ba3cfa5415d5028..380a841321a1c6507f0c6f07a7f322e2d3e8ba6b 100644 (file)
--- a/src/utils/dbi.c
+++ b/src/utils/dbi.c
return 0;
} /* sdb_dbi_client_connect */
+int
+sdb_dbi_client_check_conn(sdb_dbi_client_t *client)
+{
+ if (! client)
+ return -1;
+
+ if (! client->conn)
+ return sdb_dbi_client_connect(client);
+
+ if (dbi_conn_ping(client->conn))
+ return 0;
+ return sdb_dbi_client_connect(client);
+} /* sdb_dbi_client_check_conn */
+
int
sdb_dbi_exec_query(sdb_dbi_client_t *client, const char *query,
sdb_dbi_data_cb callback, sdb_object_t *user_data, int n, ...)
int status;
- if ((! client) || (! query))
+ if ((! client) || (! client->conn) || (! query))
return -1;
res = dbi_conn_query(client->conn, query);