]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/NavDataCache.cxx
Handle DB-locked errors.
[flightgear.git] / src / Navaids / NavDataCache.cxx
index 91ddb76ea0d1da4fc82d2aefde63f80606c556dc..0e5d3e9407c150e3c9947bab2fb5445745a3ade9 100644 (file)
@@ -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;
@@ -1271,16 +1288,23 @@ bool NavDataCache::isCachedFileModified(const SGPath& path) const
   sqlite_bind_temp_stdstring(d->statCacheCheck, 1, path.str());
   if (d->execSelect(d->statCacheCheck)) {
     time_t modtime = sqlite3_column_int64(d->statCacheCheck, 0);
-    bool modified = (modtime != path.modTime());
-    if (modified)
+    time_t delta = std::labs(modtime - path.modTime());
+    if (delta != 0)
     {
       SG_LOG(SG_NAVCACHE, SG_DEBUG, "NavCache: rebuild required for " << path << ". Timestamps: " << modtime << " != " << path.modTime());
+      if (delta < 30)
+      {
+          // File system time stamp has slightly changed. It's unlikely that the user has managed to change a file, start fgfs,
+          // and then changed file again within x seconds - so it's suspicious...
+          SG_LOG(SG_NAVCACHE, SG_ALERT, "NavCache: suspicious file timestamp change. Please report this to FlightGear. "
+                  << "Delta: " << delta << ", Timestamps: " << modtime << ", " << path.modTime() << ", path: " << path);
+      }
     }
     else
     {
       SG_LOG(SG_NAVCACHE, SG_DEBUG, "NavCache: no rebuild required for " << path);
     }
-    return (modtime != path.modTime());
+    return (delta != 0);
   } else {
     SG_LOG(SG_NAVCACHE, SG_DEBUG, "NavCache: initial build required for " << path);
     return true;