From: James Turner Date: Sat, 24 Nov 2012 12:14:56 +0000 (+0000) Subject: Fix some groundnet cache issues. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=ec2975bac32dfcc368ebb8082c4c865b15086ff0;p=flightgear.git Fix some groundnet cache issues. 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. --- diff --git a/src/Airports/dynamicloader.cxx b/src/Airports/dynamicloader.cxx index bf3eeed70..bf9335ae3 100644 --- a/src/Airports/dynamicloader.cxx +++ b/src/Airports/dynamicloader.cxx @@ -66,7 +66,7 @@ void FGAirportDynamicsXMLLoader::endXML () for (it = _parkingPushbacks.begin(); it != _parkingPushbacks.end(); ++it) { std::map::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; } diff --git a/src/Airports/xmlloader.cxx b/src/Airports/xmlloader.cxx index 901d1235f..7a45e806b 100644 --- a/src/Airports/xmlloader.cxx +++ b/src/Airports/xmlloader.cxx @@ -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; } diff --git a/src/Navaids/NavDataCache.cxx b/src/Navaids/NavDataCache.cxx index 3c44fc95c..91ddb76ea 100644 --- a/src/Navaids/NavDataCache.cxx +++ b/src/Navaids/NavDataCache.cxx @@ -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 diff --git a/src/Navaids/NavDataCache.hxx b/src/Navaids/NavDataCache.hxx index 069ffa907..71e3d5853 100644 --- a/src/Navaids/NavDataCache.hxx +++ b/src/Navaids/NavDataCache.hxx @@ -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,