aboutsummaryrefslogtreecommitdiff
path: root/src/libstore
diff options
context:
space:
mode:
authorBen Radford <benradf@users.noreply.github.com>2023-04-11 16:03:37 +0100
committerBen Radford <benradf@users.noreply.github.com>2023-04-11 16:14:16 +0100
commitde3df3009bf003f327d35e246d5904d93273e2e9 (patch)
tree75e7f17f5dda6717470d845ee750c680c23c4519 /src/libstore
parentda322ebda62470acbf5373374c4cee8236705c2f (diff)
Move warning timing logic into handleSQLiteBusy.
Diffstat (limited to 'src/libstore')
-rw-r--r--src/libstore/sqlite.cc6
-rw-r--r--src/libstore/sqlite.hh13
2 files changed, 6 insertions, 13 deletions
diff --git a/src/libstore/sqlite.cc b/src/libstore/sqlite.cc
index c57e58fe0..df334c23c 100644
--- a/src/libstore/sqlite.cc
+++ b/src/libstore/sqlite.cc
@@ -239,9 +239,11 @@ SQLiteTxn::~SQLiteTxn()
}
}
-void handleSQLiteBusy(const SQLiteBusy & e, bool shouldWarn)
+void handleSQLiteBusy(const SQLiteBusy & e, time_t & nextWarning)
{
- if (shouldWarn) {
+ time_t now = time(0);
+ if (now > nextWarning) {
+ nextWarning = now + 10;
logWarning({
.msg = hintfmt(e.what())
});
diff --git a/src/libstore/sqlite.hh b/src/libstore/sqlite.hh
index e2c9e28f8..6e14852cb 100644
--- a/src/libstore/sqlite.hh
+++ b/src/libstore/sqlite.hh
@@ -139,7 +139,7 @@ protected:
MakeError(SQLiteBusy, SQLiteError);
-void handleSQLiteBusy(const SQLiteBusy & e, bool shouldWarn);
+void handleSQLiteBusy(const SQLiteBusy & e, time_t & nextWarning);
/**
* Convenience function for retrying a SQLite transaction when the
@@ -153,17 +153,8 @@ T retrySQLite(F && fun)
while (true) {
try {
return fun();
-
} catch (SQLiteBusy & e) {
- time_t now = time(0);
- bool shouldWarn = false;
-
- if (now > nextWarning) {
- nextWarning = now + 10;
- shouldWarn = true;
- }
-
- handleSQLiteBusy(e, shouldWarn);
+ handleSQLiteBusy(e, nextWarning);
}
}
}