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.
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;
}
/* 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;
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);
* 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 */