Skip to content

Commit b13d1de

Browse files
committed
Refs #20866. Fix issue.
Signed-off-by: Miguel Company <[email protected]>
1 parent 029e69e commit b13d1de

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/cpp/fastdds/subscriber/history/DataReaderHistory.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -853,13 +853,39 @@ bool DataReaderHistory::update_instance_nts(
853853

854854
assert(vit != instances_.end());
855855
assert(false == change->isRead);
856+
auto previous_owner = vit->second->current_owner.first;
856857
++counters_.samples_unread;
857858
bool ret =
858859
vit->second->update_state(counters_, change->kind, change->writerGUID,
859860
change->reader_info.writer_ownership_strength);
860861
change->reader_info.disposed_generation_count = vit->second->disposed_generation_count;
861862
change->reader_info.no_writers_generation_count = vit->second->no_writers_generation_count;
862863

864+
auto current_owner = vit->second->current_owner.first;
865+
if (current_owner != previous_owner)
866+
{
867+
assert(vit->second->current_owner.first == change->writerGUID);
868+
869+
// Remove all changes from different owners after the change.
870+
DataReaderInstance::ChangeCollection& changes = vit->second->cache_changes;
871+
auto it = std::lower_bound(changes.begin(), changes.end(), change, rtps::history_order_cmp);
872+
assert(it != changes.end());
873+
assert(*it == change);
874+
++it;
875+
while (it != changes.end())
876+
{
877+
if ((*it)->writerGUID != current_owner)
878+
{
879+
// Remove from history
880+
remove_change_sub(*it, it);
881+
882+
// Current iterator will point to change next to the one removed. Avoid incrementing.
883+
continue;
884+
}
885+
++it;
886+
}
887+
}
888+
863889
return ret;
864890
}
865891

0 commit comments

Comments
 (0)