diff --git a/src/mtconnect/buffer/checkpoint.hpp b/src/mtconnect/buffer/checkpoint.hpp index 7e2e6c5e..3b20558a 100644 --- a/src/mtconnect/buffer/checkpoint.hpp +++ b/src/mtconnect/buffer/checkpoint.hpp @@ -174,9 +174,17 @@ namespace mtconnect::buffer { /// @param[in] diMap the map of data ids to data item pointers void updateDataItems(std::unordered_map &diMap) { - for (auto &o : m_observations) + auto iter = m_observations.begin(); + while( iter != m_observations.end() ) { - o.second->updateDataItem(diMap); + auto item = *iter; + if( item.second->isOrphan() ) { + iter = m_observations.erase(iter); + } + else { + item.second->updateDataItem(diMap); + iter++; + } } } diff --git a/src/mtconnect/buffer/circular_buffer.hpp b/src/mtconnect/buffer/circular_buffer.hpp index 2bb859a6..4d30aab4 100644 --- a/src/mtconnect/buffer/circular_buffer.hpp +++ b/src/mtconnect/buffer/circular_buffer.hpp @@ -27,6 +27,9 @@ #include "mtconnect/config.hpp" #include "mtconnect/observation/observation.hpp" #include "mtconnect/utilities.hpp" +#include "mtconnect/logging.hpp" +#include "mtconnect/entity/requirement.hpp" + namespace mtconnect::buffer { using SequenceNumber_t = uint64_t; @@ -84,9 +87,13 @@ namespace mtconnect::buffer { { for (auto &o : m_slidingBuffer) { - o->updateDataItem(diMap); + if( o->isOrphan() ) { + continue; + } + o->updateDataItem(diMap); } + // checkpoints will remove orphans from its observations m_first.updateDataItems(diMap); m_latest.updateDataItems(diMap);