forked from lix-project/lix
Merge pull request #8199 from tweag/fix-sqlite-busy-reporting
Fix unnecessary reporting of SQLite busy errors
This commit is contained in:
commit
7eac8838df
|
@ -239,14 +239,11 @@ SQLiteTxn::~SQLiteTxn()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleSQLiteBusy(const SQLiteBusy & e)
|
void handleSQLiteBusy(const SQLiteBusy & e, time_t & nextWarning)
|
||||||
{
|
{
|
||||||
static std::atomic<time_t> lastWarned{0};
|
|
||||||
|
|
||||||
time_t now = time(0);
|
time_t now = time(0);
|
||||||
|
if (now > nextWarning) {
|
||||||
if (now > lastWarned + 10) {
|
nextWarning = now + 10;
|
||||||
lastWarned = now;
|
|
||||||
logWarning({
|
logWarning({
|
||||||
.msg = hintfmt(e.what())
|
.msg = hintfmt(e.what())
|
||||||
});
|
});
|
||||||
|
|
|
@ -139,7 +139,7 @@ protected:
|
||||||
|
|
||||||
MakeError(SQLiteBusy, SQLiteError);
|
MakeError(SQLiteBusy, SQLiteError);
|
||||||
|
|
||||||
void handleSQLiteBusy(const SQLiteBusy & e);
|
void handleSQLiteBusy(const SQLiteBusy & e, time_t & nextWarning);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience function for retrying a SQLite transaction when the
|
* Convenience function for retrying a SQLite transaction when the
|
||||||
|
@ -148,11 +148,13 @@ void handleSQLiteBusy(const SQLiteBusy & e);
|
||||||
template<typename T, typename F>
|
template<typename T, typename F>
|
||||||
T retrySQLite(F && fun)
|
T retrySQLite(F && fun)
|
||||||
{
|
{
|
||||||
|
time_t nextWarning = time(0) + 1;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
return fun();
|
return fun();
|
||||||
} catch (SQLiteBusy & e) {
|
} catch (SQLiteBusy & e) {
|
||||||
handleSQLiteBusy(e);
|
handleSQLiteBusy(e, nextWarning);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue