]> git.mxchange.org Git - flightgear.git/commitdiff
Fix some groundnet cache issues.
authorJames Turner <zakalawe@mac.com>
Sat, 24 Nov 2012 12:14:56 +0000 (12:14 +0000)
committerJames Turner <zakalawe@mac.com>
Sat, 24 Nov 2012 12:14:56 +0000 (12:14 +0000)
ThorstenB identified some cases where mod-times changing could lead to corrupted ground-cache data in the DB - handle both of these. What's still unclear is why the mod-times changes; hopefully the additional debug info will reveal this.

src/Airports/dynamicloader.cxx
src/Airports/xmlloader.cxx
src/Navaids/NavDataCache.cxx
src/Navaids/NavDataCache.hxx

index bf3eeed70a1fd47ee5cb412acc2c416c5a154b72..bf9335ae3d36b1f6d00174ea7d556707996c6a92 100644 (file)
@@ -66,7 +66,7 @@ void  FGAirportDynamicsXMLLoader::endXML ()
   for (it = _parkingPushbacks.begin(); it != _parkingPushbacks.end(); ++it) {
     std::map<int, PositionedID>::iterator j = _idMap.find(it->second);
     if (j == _idMap.end()) {
-      SG_LOG(SG_GENERAL, SG_WARN, "bad groundnet, no node for index:" << it->first);
+      SG_LOG(SG_NAVAID, SG_WARN, "bad groundnet, no node for index:" << it->first);
       continue;
     }
     
@@ -74,7 +74,7 @@ void  FGAirportDynamicsXMLLoader::endXML ()
   }
   
   BOOST_FOREACH(PositionedID id, _unreferencedNodes) {
-    SG_LOG(SG_GENERAL, SG_WARN, "unreferenced groundnet node:" << id);
+    SG_LOG(SG_NAVAID, SG_WARN, "unreferenced groundnet node:" << id);
   }
   
 }
@@ -167,7 +167,7 @@ void FGAirportDynamicsXMLLoader::startNode(const XMLAttributes &atts)
        }
   
   if (_idMap.find(index) != _idMap.end()) {
-    SG_LOG(SG_GENERAL, SG_WARN, "duplicate ground-net index:" << index);
+    SG_LOG(SG_NAVAID, SG_WARN, "duplicate ground-net index:" << index);
   }
   
   SGGeod pos(SGGeod::fromDeg(processPosition(lon), processPosition(lat)));
@@ -195,7 +195,7 @@ void FGAirportDynamicsXMLLoader::startArc(const XMLAttributes &atts)
   
   IntPair e(begin, end);
   if (_arcSet.find(e) != _arcSet.end()) {
-    SG_LOG(SG_GENERAL, SG_WARN, _dynamics->parent()->ident() << " ground-net: skipping duplicate edge:" << begin << "->" << end);
+    SG_LOG(SG_NAVAID, SG_WARN, _dynamics->parent()->ident() << " ground-net: skipping duplicate edge:" << begin << "->" << end);
     return;
   }
   
index 901d1235f19d34fe566946c6c55862be94b574dc..7a45e806b6477a5fbd1b7ddbd3446a01f3345393 100644 (file)
@@ -52,12 +52,15 @@ void XMLLoader::load(FGAirportDynamics* d)
     return;
   }
   
-  SG_LOG(SG_GENERAL, SG_INFO, "reading groundnet data from " << path);
+  SG_LOG(SG_NAVAID, SG_INFO, "reading groundnet data from " << path);
   SGTimeStamp t;
   try {
     cache->beginTransaction();
     t.stamp();
     {
+      // drop all current data
+      cache->dropGroundnetFor(d->parent()->guid());
+      
       FGAirportDynamicsXMLLoader visitor(d);
       readXML(path.str(), visitor);
     } // ensure visitor is destroyed so its destructor runs
@@ -67,7 +70,7 @@ void XMLLoader::load(FGAirportDynamics* d)
     cache->abortTransaction();
   }
 
-  SG_LOG(SG_GENERAL, SG_INFO, "parsing XML took " << t.elapsedMSec());
+  SG_LOG(SG_NAVAID, SG_INFO, "parsing groundnet XML took " << t.elapsedMSec());
 }
 
 void XMLLoader::load(FGRunwayPreference* p) {
@@ -109,7 +112,7 @@ bool XMLLoader::loadAirportXMLDataIntoVisitor(const string& aICAO,
 {
   SGPath path;
   if (!findAirportData(aICAO, aFileName, path)) {
-    SG_LOG(SG_GENERAL, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
+    SG_LOG(SG_NAVAID, SG_DEBUG, "loadAirportXMLDataIntoVisitor: failed to find data for " << aICAO << "/" << aFileName);
     return false;
   }
 
index 3c44fc95c3ae3f283aa1c46899295c24e1057788..91ddb76ea0d1da4fc82d2aefde63f80606c556dc 100644 (file)
@@ -1131,6 +1131,10 @@ void NavDataCache::doRebuild()
     d->runSQL("DELETE FROM octree");
     d->runSQL("DELETE FROM airway");
     d->runSQL("DELETE FROM airway_edge");
+    d->runSQL("DELETE FROM taxi_node");
+    d->runSQL("DELETE FROM parking");
+    d->runSQL("DELETE FROM groundnet_edge");
+    d->runSQL("DELETE FROM stat_cache");
     
   // initialise the root octree node
     d->runSQL("INSERT INTO octree (rowid, children) VALUES (1, 0)");
@@ -1991,5 +1995,28 @@ PositionedIDVec NavDataCache::findAirportParking(PositionedID airport, const std
   return d->selectIds(d->findAirportParking);
 }
 
+void NavDataCache::dropGroundnetFor(PositionedID aAirport)
+{
+  sqlite3_stmt_ptr q = d->prepare("DELETE FROM parking WHERE rowid IN (SELECT rowid FROM positioned WHERE type=?1 AND airport=?2)");
+  sqlite3_bind_int(q, 1, FGPositioned::PARKING);
+  sqlite3_bind_int64(q, 2, aAirport);
+  d->execUpdate(q);
+  
+  q = d->prepare("DELETE FROM taxi_node WHERE rowid IN (SELECT rowid FROM positioned WHERE type=?1 AND airport=?2)");
+  sqlite3_bind_int(q, 1, FGPositioned::TAXI_NODE);
+  sqlite3_bind_int64(q, 2, aAirport);
+  d->execUpdate(q);
+  
+  q = d->prepare("DELETE FROM positioned WHERE (type=?1 OR type=?2) AND airport=?3");
+  sqlite3_bind_int(q, 1, FGPositioned::TAXI_NODE);
+  sqlite3_bind_int(q, 2, FGPositioned::PARKING);
+  sqlite3_bind_int64(q, 3, aAirport);
+  d->execUpdate(q);
+  
+  q = d->prepare("DELETE FROM groundnet_edge WHERE airport=?1");
+  sqlite3_bind_int64(q, 1, aAirport);
+  d->execUpdate(q);
+}
+  
 } // of namespace flightgear
 
index 069ffa9074f794ff3d6cd483b2a76ebe358a2c7b..71e3d5853af2202aae35c9a5e5ae29ebf8b0bbd9 100644 (file)
@@ -123,6 +123,8 @@ public:
   
   PositionedID createUserWaypoint(const std::string& ident, const SGGeod& aPos);
   
+  void dropGroundnetFor(PositionedID aAirport);
+  
   PositionedID insertParking(const std::string& name, const SGGeod& aPos,
                              PositionedID aAirport,
                              double aHeading, int aRadius, const std::string& aAircraftType,