db: Track the data_version in the database

This increments the `data_version` upon committing dirty transactions, reads
the last data_version upon startup, and tracks the number in memory in
parallel to the DB (see next commit for rationale).

Changelog-Changed: JSON-RPC: Added a `data_version` field to the `db_write` hook which returns a numeric transaction counter.
This commit is contained in:
Christian Decker
2019-12-18 19:45:24 +01:00
committed by neil saitug
parent 4a4184be70
commit 2c11c54dd2
6 changed files with 43 additions and 0 deletions

View File

@@ -63,6 +63,7 @@ static struct db *create_test_db(void)
dsn = tal_fmt(NULL, "sqlite3://%s", filename);
db = db_open(NULL, dsn);
db->data_version = 0;
tal_free(dsn);
return db;
}
@@ -107,6 +108,10 @@ static bool test_primitives(void)
CHECK_MSG(db_err, "Failing SQL command");
tal_free(stmt);
db_err = tal_free(db_err);
/* We didn't migrate the DB, so don't have the vars table. Pretend we
* didn't change anything so we don't bump the data_version. */
db->dirty = false;
db_commit_transaction(db);
CHECK(!db->in_transaction);
tal_free(db);