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

Function db_data_version_incr

db/exec.c:104–119  ·  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

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

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
tal_freeFunction · 0.85
db_fatalFunction · 0.50

Tested by

no test coverage detected