mirror of
https://github.com/ElementsProject/lightning.git
synced 2025-02-23 15:00:34 +01:00
db: Add tracking of whether the current transaction is dirty
This commit is contained in:
parent
097af493dd
commit
09247d4f95
2 changed files with 17 additions and 0 deletions
13
wallet/db.c
13
wallet/db.c
|
@ -763,6 +763,11 @@ static void db_report_changes(struct db *db, const char *final, size_t min)
|
|||
assert(db->changes);
|
||||
assert(tal_count(db->changes) >= min);
|
||||
|
||||
/* Having changes implies that we have a dirty TX. The opposite is
|
||||
* currently not true, e.g., the postgres driver doesn't record
|
||||
* changes yet. */
|
||||
assert(!tal_count(db->changes) || db->dirty);
|
||||
|
||||
if (tal_count(db->changes) > min)
|
||||
plugin_hook_db_sync(db);
|
||||
db->changes = tal_free(db->changes);
|
||||
|
@ -785,6 +790,9 @@ void db_begin_transaction_(struct db *db, const char *location)
|
|||
if (db->in_transaction)
|
||||
db_fatal("Already in transaction from %s", db->in_transaction);
|
||||
|
||||
/* No writes yet. */
|
||||
db->dirty = false;
|
||||
|
||||
db_prepare_for_changes(db);
|
||||
ok = db->config->begin_tx_fn(db);
|
||||
if (!ok)
|
||||
|
@ -805,6 +813,7 @@ void db_commit_transaction(struct db *db)
|
|||
db_fatal("Failed to commit DB transaction: %s", db->error);
|
||||
|
||||
db->in_transaction = NULL;
|
||||
db->dirty = false;
|
||||
}
|
||||
|
||||
static struct db_config *db_config_find(const char *dsn)
|
||||
|
@ -1357,6 +1366,10 @@ void db_column_txid(struct db_stmt *stmt, int pos, struct bitcoin_txid *t)
|
|||
bool db_exec_prepared_v2(struct db_stmt *stmt TAKES)
|
||||
{
|
||||
bool ret = stmt->db->config->exec_fn(stmt);
|
||||
|
||||
/* If this was a write we need to bump the data_version upon commit. */
|
||||
stmt->db->dirty = stmt->db->dirty || !stmt->query->readonly;
|
||||
|
||||
stmt->executed = true;
|
||||
list_del_from(&stmt->db->pending_statements, &stmt->list);
|
||||
|
||||
|
|
|
@ -30,6 +30,10 @@ struct db {
|
|||
char *error;
|
||||
|
||||
struct log *log;
|
||||
|
||||
/* Were there any modifying statements in the current transaction?
|
||||
* Used to bump the data_version in the DB.*/
|
||||
bool dirty;
|
||||
};
|
||||
|
||||
struct db_query {
|
||||
|
|
Loading…
Add table
Reference in a new issue