1
0
Fork 0

Tweak Natural-earth loading to reduce DB contention

Reduce ‘SQLITE BUSY’ issues with multiple running copies of FG
This commit is contained in:
James Turner 2021-02-05 11:14:34 +00:00
parent b915d02f55
commit 0cc465d39f
2 changed files with 10 additions and 3 deletions

View file

@ -218,14 +218,18 @@ private:
return;
flightgear::PolyLineList::const_iterator begin = m_parsedLines.begin() + m_lineInsertCount;
unsigned int numToAdd = std::min<unsigned int>(1000U, static_cast<unsigned int>(m_parsedLines.size()) - m_lineInsertCount);
// add lines in batches of 100; this is a tradeoff to ensure we don't lock
// the database for too long. (Which triggers SQLITE_BUSY)
const int lineInsertBatchSize = 100U;
unsigned int numToAdd = std::min<unsigned int>(100U, static_cast<unsigned int>(m_parsedLines.size()) - m_lineInsertCount);
flightgear::PolyLineList::const_iterator end = begin + numToAdd;
flightgear::PolyLine::bulkAddToSpatialIndex(begin, end);
if (end == m_parsedLines.end()) {
deleteLater(); // commit suicide
} else {
m_lineInsertCount += 1000;
m_lineInsertCount += lineInsertBatchSize;
QTimer::singleShot(50, this, SLOT(onFinished()));
}
}

View file

@ -458,6 +458,8 @@ public:
{
int retries = 0;
int result;
int retryMSec = 10;
while (retries < MAX_RETRIES) {
result = sqlite3_step(stmt);
if (result == SQLITE_ROW) {
@ -473,7 +475,8 @@ public:
}
SG_LOG(SG_NAVCACHE, SG_ALERT, "NavCache contention on select, will retry:" << retries);
SGTimeStamp::sleepForMSec(++retries * 10);
SGTimeStamp::sleepForMSec(retryMSec);
retryMSec *= 2; // double the back-off time, each time
} // of retry loop for DB locked
if (retries >= MAX_RETRIES) {