MCPcopy Create free account
hub / github.com/ElementsProject/lightning / db_data_version_incr

Function db_data_version_incr

db/exec.c:105–120  ·  view source on GitHub ↗

By making the update conditional on the current value we expect we * are implementing an optimistic lock: if the update results in * changes on the DB we know that the data_version did not change * under our feet and no other transaction ran in the meantime. * * Notice that this update effectively locks the row, so that other * operations attempting to change this outside the transaction wil

Source from the content-addressed store, hash-verified

103 * until our transaction is committed.
104 */
105static void db_data_version_incr(struct db *db)
106{
107 struct db_stmt *stmt = db_prepare_v2(
108 db, SQL("UPDATE vars "
109 "SET intval = intval + 1 "
110 "WHERE name = 'data_version'"
111 " AND intval = ?"));
112 db_bind_int(stmt, db->data_version);
113 db_exec_prepared_v2(stmt);
114 if (db_count_changes(stmt) != 1)
115 db_fatal(stmt->db, "Optimistic lock on the database failed. There"
116 " may be a concurrent access to the database."
117 " Aborting since concurrent access is unsafe.");
118 tal_free(stmt);
119 db->data_version++;
120}
121
122void db_begin_transaction_(struct db *db, const char *location)
123{

Callers 1

db_commit_transactionFunction · 0.85

Calls 5

db_bind_intFunction · 0.85
db_exec_prepared_v2Function · 0.85
db_count_changesFunction · 0.85
db_fatalFunction · 0.85
tal_freeFunction · 0.85

Tested by

no test coverage detected