Convenience macros for retrying a SQLite transaction

This commit is contained in:
Eelco Dolstra 2013-10-16 14:46:35 +02:00
parent bce14d0f61
commit 4bd5282573

View file

@ -75,6 +75,11 @@ static void throwSQLiteError(sqlite3 * db, const format & f)
} }
/* Convenience macros for retrying a SQLite transaction. */
#define retry_sqlite while (1) { try {
#define end_retry_sqlite break; } catch (SQLiteBusy & e) { } }
SQLite::~SQLite() SQLite::~SQLite()
{ {
try { try {
@ -1219,8 +1224,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
* expense of some speed of the path registering operation. */ * expense of some speed of the path registering operation. */
if (settings.syncBeforeRegistering) sync(); if (settings.syncBeforeRegistering) sync();
while (1) { retry_sqlite {
try {
SQLiteTxn txn(db); SQLiteTxn txn(db);
PathSet paths; PathSet paths;
@ -1246,12 +1250,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
topoSortPaths(*this, paths); topoSortPaths(*this, paths);
txn.commit(); txn.commit();
break; } end_retry_sqlite;
} catch (SQLiteBusy & e) {
/* Retry; the `txn' destructor will roll back the current
transaction. */
}
}
} }
@ -1642,8 +1641,7 @@ void LocalStore::invalidatePathChecked(const Path & path)
{ {
assertStorePath(path); assertStorePath(path);
while (1) { retry_sqlite {
try {
SQLiteTxn txn(db); SQLiteTxn txn(db);
if (isValidPath(path)) { if (isValidPath(path)) {
@ -1656,9 +1654,7 @@ void LocalStore::invalidatePathChecked(const Path & path)
} }
txn.commit(); txn.commit();
break; } end_retry_sqlite;
} catch (SQLiteBusy & e) { };
}
} }