Convenience macros for retrying a SQLite transaction
This commit is contained in:
parent
bce14d0f61
commit
4bd5282573
1 changed files with 42 additions and 46 deletions
|
@ -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()
|
||||
{
|
||||
try {
|
||||
|
@ -1219,8 +1224,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
|
|||
* expense of some speed of the path registering operation. */
|
||||
if (settings.syncBeforeRegistering) sync();
|
||||
|
||||
while (1) {
|
||||
try {
|
||||
retry_sqlite {
|
||||
SQLiteTxn txn(db);
|
||||
PathSet paths;
|
||||
|
||||
|
@ -1246,12 +1250,7 @@ void LocalStore::registerValidPaths(const ValidPathInfos & infos)
|
|||
topoSortPaths(*this, paths);
|
||||
|
||||
txn.commit();
|
||||
break;
|
||||
} catch (SQLiteBusy & e) {
|
||||
/* Retry; the `txn' destructor will roll back the current
|
||||
transaction. */
|
||||
}
|
||||
}
|
||||
} end_retry_sqlite;
|
||||
}
|
||||
|
||||
|
||||
|
@ -1642,8 +1641,7 @@ void LocalStore::invalidatePathChecked(const Path & path)
|
|||
{
|
||||
assertStorePath(path);
|
||||
|
||||
while (1) {
|
||||
try {
|
||||
retry_sqlite {
|
||||
SQLiteTxn txn(db);
|
||||
|
||||
if (isValidPath(path)) {
|
||||
|
@ -1656,9 +1654,7 @@ void LocalStore::invalidatePathChecked(const Path & path)
|
|||
}
|
||||
|
||||
txn.commit();
|
||||
break;
|
||||
} catch (SQLiteBusy & e) { };
|
||||
}
|
||||
} end_retry_sqlite;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue