kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 5b3cee342889a871f93f3bcd45d4996ba0318c2c
parent 43234cd36eaeb002648d292503ba58350aa78009
Author: Joris Vink <joris@coders.se>
Date:   Sat, 28 Jul 2018 22:28:19 +0200

Use a synchronous query to issue a ROLLBACK.

Diffstat:
src/pgsql.c | 49+++++++++----------------------------------------
1 file changed, 9 insertions(+), 40 deletions(-)

diff --git a/src/pgsql.c b/src/pgsql.c @@ -52,7 +52,6 @@ static void pgsql_conn_release(struct kore_pgsql *); static void pgsql_conn_cleanup(struct pgsql_conn *); static void pgsql_read_result(struct kore_pgsql *); static void pgsql_schedule(struct kore_pgsql *); -static void pgsql_rollback_state(struct kore_pgsql *, void *); static struct pgsql_conn *pgsql_conn_create(struct kore_pgsql *, struct pgsql_db *); @@ -372,7 +371,6 @@ kore_pgsql_continue(struct kore_pgsql *pgsql) void kore_pgsql_cleanup(struct kore_pgsql *pgsql) { - kore_debug("kore_pgsql_cleanup(%p)", pgsql); pgsql_queue_remove(pgsql); if (pgsql->result != NULL) @@ -436,7 +434,7 @@ pgsql_conn_next(struct kore_pgsql *pgsql, struct pgsql_db *db) { PGTransactionStatusType state; struct pgsql_conn *conn; - struct kore_pgsql *rollback; + struct kore_pgsql rollback; rescan: conn = NULL; @@ -454,21 +452,16 @@ rescan: conn->flags &= ~PGSQL_CONN_FREE; TAILQ_REMOVE(&pgsql_conn_free, conn, list); - rollback = kore_malloc(sizeof(*rollback)); - kore_pgsql_init(rollback); - kore_pgsql_bind_callback(rollback, - pgsql_rollback_state, NULL); - rollback->flags |= KORE_PGSQL_ASYNC; + kore_pgsql_init(&rollback); + rollback.conn = conn; + rollback.flags = KORE_PGSQL_SYNC; - rollback->conn = conn; - rollback->conn->job = kore_pool_get(&pgsql_job_pool); - rollback->conn->job->pgsql = rollback; - - if (!kore_pgsql_query(rollback, "ROLLBACK")) { - kore_pgsql_logerror(rollback); - kore_pgsql_cleanup(rollback); - kore_free(rollback); + if (!kore_pgsql_query(&rollback, "ROLLBACK")) { + kore_pgsql_logerror(&rollback); + kore_pgsql_cleanup(&rollback); pgsql_conn_cleanup(conn); + } else { + kore_pgsql_cleanup(&rollback); } goto rescan; @@ -611,8 +604,6 @@ pgsql_conn_create(struct kore_pgsql *pgsql, struct pgsql_db *db) conn->name = kore_strdup(db->name); TAILQ_INSERT_TAIL(&pgsql_conn_free, conn, list); - kore_debug("pgsql_conn_create(): %p", conn); - conn->db = PQconnectdb(db->conn_string); if (conn->db == NULL || (PQstatus(conn->db) != CONNECTION_OK)) { pgsql_set_error(pgsql, PQerrorMessage(conn->db)); @@ -667,7 +658,6 @@ pgsql_conn_cleanup(struct pgsql_conn *conn) struct kore_pgsql *pgsql; struct pgsql_db *pgsqldb; - kore_debug("pgsql_conn_cleanup(): %p", conn); if (conn->flags & PGSQL_CONN_FREE) TAILQ_REMOVE(&pgsql_conn_free, conn, list); @@ -760,24 +750,3 @@ pgsql_cancel(struct kore_pgsql *pgsql) PQfreeCancel(cancel); } } - -static void -pgsql_rollback_state(struct kore_pgsql *pgsql, void *arg) -{ - struct pgsql_conn *conn; - - switch (pgsql->state) { - case KORE_PGSQL_STATE_ERROR: - conn = pgsql->conn; - kore_pgsql_logerror(pgsql); - kore_pgsql_cleanup(pgsql); - pgsql_conn_cleanup(conn); - break; - case KORE_PGSQL_STATE_COMPLETE: - kore_pgsql_cleanup(pgsql); - break; - default: - kore_pgsql_continue(pgsql); - break; - } -}