Fix possible staled flann index (#1742)

* Fix possible staled flann index

* fixed compatible crc flann index after repair and reload

* Added tests

* test coverage

* testing another possible branch

* removed doxygen tag version not opulated yet

* updated codedev to ignore test code

* Disabled all mac intel ci flaky builds
This commit is contained in:
matlabbe
2026-08-07 20:48:41 -07:00
committed by GitHub
parent c5ecfef101
commit 47ce2b0c74
11 changed files with 488 additions and 33 deletions
+20 -4
View File
@@ -614,7 +614,12 @@ void Memory::loadDataFromDb(bool postInitClosingEvents)
UWARN("%s", msg.c_str());
if(postInitClosingEvents) UEventsManager::post(new RtabmapEventInit(msg));
_memoryChanged = true; // This will force rtabmap to save back the dictionary even if we don't process any new data
_vwd->update();
// Re-index from scratch instead of adding the words above to the
// index already built: the index would then contain them in a
// different order than the words loaded from the database, which
// makes the index saved on close (see saveFlannIndex()) rejected
// when it is deserialized on next load.
_vwd->rebuildIndex();
}
}
@@ -714,12 +719,21 @@ void Memory::close(bool databaseSaved, bool postInitClosingEvents, const std::st
UINFO("No changes added to database.");
if(_dbDriver)
{
if(!this->isReadOnly()) {
if(this->isReadOnly())
{
if(_memoryChanged || _linksChanged || databaseNameChanged)
{
UWARN("Memory has been modified (nodes=%s links=%s name=%s) but the database is read-only, changes are not saved to database.",
_memoryChanged?"true":"false", _linksChanged?"true":"false", databaseNameChanged?"true":"false");
}
}
else if(databaseSaved)
{
saveFlannIndex(postInitClosingEvents);
}
else if(_memoryChanged || _linksChanged || databaseNameChanged)
{
UWARN("Memory has been modified (nodes=%s links=%s name=%s) but the database is read-only, changes are not saved to database.",
UWARN("Memory has been modified (nodes=%s links=%s name=%s) but databaseSaved=false, changes are not saved to database.",
_memoryChanged?"true":"false", _linksChanged?"true":"false", databaseNameChanged?"true":"false");
}
if(postInitClosingEvents) UEventsManager::post(new RtabmapEventInit(uFormat("Closing database \"%s\"...", _dbDriver->getUrl().c_str())));
@@ -736,8 +750,10 @@ void Memory::close(bool databaseSaved, bool postInitClosingEvents, const std::st
{
UINFO("Saving memory...");
if(postInitClosingEvents) UEventsManager::post(new RtabmapEventInit("Saving memory..."));
if(!_memoryChanged && _dbDriver)
if(_dbDriver)
{
// Must be done before clear(), which clears the dictionary.
// saveFlannIndex() saves only if the dictionary has been modified.
saveFlannIndex(postInitClosingEvents);
}
this->clear();
+10 -4
View File
@@ -118,10 +118,7 @@ void VWDictionary::parseParameters(const ParametersMap & parameters)
if(!treeUpdated && byteToFloat!=_byteToFloat && _strategy == kNNFlannKdTree)
{
UINFO("KDTree: Binary to Float conversion approach has changed, re-initialize kd-tree.");
_dataTree = cv::Mat();
_notIndexedWords = uKeysSet(_visualWords);
_removedIndexedWords.clear();
this->update();
this->rebuildIndex();
}
if(incrementalDictionary)
@@ -296,6 +293,15 @@ bool VWDictionary::isModified() const
return _modified;
}
void VWDictionary::rebuildIndex()
{
UDEBUG("Re-indexing all %ld words...", _visualWords.size());
_dataTree = cv::Mat();
_notIndexedWords = uKeysSet(_visualWords);
_removedIndexedWords.clear();
this->update();
}
bool VWDictionary::setNNStrategy(NNStrategy strategy)
{
#if CV_MAJOR_VERSION < 3