diff options
author | Ben Radford <benradf@users.noreply.github.com> | 2023-04-11 10:22:07 +0100 |
---|---|---|
committer | Ben Radford <benradf@users.noreply.github.com> | 2023-04-11 11:15:34 +0100 |
commit | 7c56e842133afe14812270c34cda3dc0a3da8aa6 (patch) | |
tree | 6d8892879f18699c773eb45b025c0f1e09c7a0bb /src/libstore/sqlite.hh | |
parent | 7f5ca6192d091090bc71ab7bf96dd4acf0f1d376 (diff) |
Warn after a second of being busy instead of immediately.
Getting the occasional SQLITE_BUSY is expected when the database is being
accessed concurrently. The retry will likely succeed so it is pointless to warn
immediately. Instead we track how long each retrySQLite block has been running,
and only begin warning after a second has elapsed (and then every 10 seconds
subsequently).
Diffstat (limited to 'src/libstore/sqlite.hh')
-rw-r--r-- | src/libstore/sqlite.hh | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/libstore/sqlite.hh b/src/libstore/sqlite.hh index b735838ec..e2c9e28f8 100644 --- a/src/libstore/sqlite.hh +++ b/src/libstore/sqlite.hh @@ -139,7 +139,7 @@ protected: MakeError(SQLiteBusy, SQLiteError); -void handleSQLiteBusy(const SQLiteBusy & e); +void handleSQLiteBusy(const SQLiteBusy & e, bool shouldWarn); /** * Convenience function for retrying a SQLite transaction when the @@ -148,11 +148,22 @@ void handleSQLiteBusy(const SQLiteBusy & e); template<typename T, typename F> T retrySQLite(F && fun) { + time_t nextWarning = time(0) + 1; + while (true) { try { return fun(); + } catch (SQLiteBusy & e) { - handleSQLiteBusy(e); + time_t now = time(0); + bool shouldWarn = false; + + if (now > nextWarning) { + nextWarning = now + 10; + shouldWarn = true; + } + + handleSQLiteBusy(e, shouldWarn); } } } |