From: Sebastian Harl Date: Thu, 15 Nov 2012 12:42:29 +0000 (+0100) Subject: postgresql plugin: Simplified transaction handling a bit. X-Git-Tag: collectd-5.2.0~13^2~2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=aabd019de0a1bd837ec770bc53ef9433cb136c12;p=collectd.git postgresql plugin: Simplified transaction handling a bit. Don't set any next commit time after committing a transaction but only when starting a new transaction. This way, db->next_commit == 0 always means that we're outside of a transaction. Also, this removes the need to restart a transaction right away. Rather, the write callback will take care of that the next time it gets any data. --- diff --git a/src/postgresql.c b/src/postgresql.c index 9f4894ca..eeb036fe 100644 --- a/src/postgresql.c +++ b/src/postgresql.c @@ -203,7 +203,7 @@ static int c_psql_commit (c_psql_database_t *db) if (r != NULL) { if (PGRES_COMMAND_OK == PQresultStatus (r)) { - db->next_commit = cdtime () + db->commit_interval; + db->next_commit = 0; log_debug ("Successfully committed transaction."); status = 0; } @@ -913,8 +913,7 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl, /* this will abort any current transaction -> restart */ if (db->next_commit > 0) - if (c_psql_commit (db) == 0) - c_psql_begin (db); + c_psql_commit (db); pthread_mutex_unlock (&db->db_lock); return -1; @@ -924,8 +923,7 @@ static int c_psql_write (const data_set_t *ds, const value_list_t *vl, if ((db->next_commit > 0) && (cdtime () > db->next_commit)) - if (c_psql_commit (db) == 0) - c_psql_begin (db); + c_psql_commit (db); pthread_mutex_unlock (&db->db_lock); @@ -957,8 +955,7 @@ static int c_psql_flush (cdtime_t timeout, * interval as in that case all requested data has already been * committed */ if ((db->next_commit > 0) && (db->commit_interval > timeout)) - if (c_psql_commit (db) == 0) - c_psql_begin (db); + c_psql_commit (db); } return 0; } /* c_psql_flush */