From: James Turner Date: Tue, 27 Nov 2012 17:34:52 +0000 (+0000) Subject: Handle DB-locked errors. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c8996d86b8367dfbb30a03fc12a8bd2b647f5985;p=flightgear.git Handle DB-locked errors. When multiple processes (right now, multiple copies of fgfs, but potentially other users in the future) access the navcache, it can cause SQLite to return a 'locked' error, so the request should be re-tried. Add code to do this. --- diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index e6eb1827b..0e5d3e940 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -334,15 +334,32 @@ public: return stepSelect(stmt); } + const int MAX_RETRIES = 10; + bool stepSelect(sqlite3_stmt_ptr stmt) { - int result = sqlite3_step(stmt); - if (result == SQLITE_ROW) { - return true; // at least one result row - } + int retries = 0; + int result; + while (retries < MAX_RETRIES) { + result = sqlite3_step(stmt); + if (result == SQLITE_ROW) { + return true; // at least one result row + } + + if (result == SQLITE_DONE) { + return false; // no result rows + } + + if (result != SQLITE_LOCKED) { + break; + } + + ++retries; + } // of retry loop for DB locked - if (result == SQLITE_DONE) { - return false; // no result rows + if (retries >= MAX_RETRIES) { + SG_LOG(SG_NAVCACHE, SG_ALERT, "exceeded maximum number of SQLITE_LOCKED retries"); + return false; } string errMsg;