Skip to content

Commit e662845

Browse files
cferreiragonzMiguelCompany
authored andcommitted
Avoid sending duplicated ACKs in DataSharing (#5986)
* Refs #23603: Avoid duplicate ACK in datasharing Signed-off-by: cferreiragonz <[email protected]> * Refs #23603: Doxygen Signed-off-by: cferreiragonz <[email protected]> * Refs #23603: Mock method Signed-off-by: cferreiragonz <[email protected]> --------- Signed-off-by: cferreiragonz <[email protected]> (cherry picked from commit 8421fb0)
1 parent f9e57f7 commit e662845

File tree

7 files changed

+30
-18
lines changed

7 files changed

+30
-18
lines changed

src/cpp/fastdds/subscriber/DataReaderImpl/ReadTakeCommand.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ struct ReadTakeCommand
147147
ReturnCode_t previous_return_value = return_value_;
148148
bool added = add_sample(*it, remove_change);
149149
history_.change_was_processed_nts(change, added);
150-
rtps::BaseReader::downcast(reader_)->end_sample_access_nts(change, wp, added);
151150

152151
// Check if the payload is dirty
153152
if (added && !check_datasharing_validity(change, data_values_.has_ownership()))
@@ -165,7 +164,11 @@ struct ReadTakeCommand
165164
added = false;
166165
}
167166

168-
if (remove_change || (added && take_samples))
167+
// Only send ACK if the change will not be removed to avoid sending the same ACK twice
168+
bool should_remove = remove_change || (added && take_samples);
169+
rtps::BaseReader::downcast(reader_)->end_sample_access_nts(change, wp, added, !should_remove);
170+
171+
if (should_remove)
169172
{
170173
// Remove from history
171174
history_.remove_change_sub(change, it);

src/cpp/rtps/reader/BaseReader.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,14 +221,16 @@ class BaseReader
221221
/**
222222
* @brief Called after the change has been deserialized.
223223
*
224-
* @param [in] change Pointer to the change being accessed.
225-
* @param [in] writer Writer proxy the @c change belongs to.
226-
* @param [in] mark_as_read Whether the @c change should be marked as read or not.
224+
* @param [in] change Pointer to the change being accessed.
225+
* @param [in] writer Writer proxy the @c change belongs to.
226+
* @param [in] mark_as_read Whether the @c change should be marked as read or not.
227+
* @param [in] should_send_ack Whether an ACKNACK should be sent to the writer or not.
227228
*/
228229
virtual void end_sample_access_nts(
229230
fastdds::rtps::CacheChange_t* change,
230231
fastdds::rtps::WriterProxy*& writer,
231-
bool mark_as_read) = 0;
232+
bool mark_as_read,
233+
bool should_send_ack = false) = 0;
232234

233235
/**
234236
* @brief A method to update the liveliness changed status of the reader

src/cpp/rtps/reader/StatefulReader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,8 @@ bool StatefulReader::begin_sample_access_nts(
14671467
void StatefulReader::end_sample_access_nts(
14681468
CacheChange_t* change,
14691469
WriterProxy*& writer,
1470-
bool mark_as_read)
1470+
bool mark_as_read,
1471+
bool should_send_ack)
14711472
{
14721473
assert(!writer || change->writerGUID == writer->guid());
14731474

@@ -1481,7 +1482,7 @@ void StatefulReader::end_sample_access_nts(
14811482
}
14821483
}
14831484

1484-
if (mark_as_read)
1485+
if (should_send_ack && mark_as_read)
14851486
{
14861487
send_ack_if_datasharing(this, history_, writer, change->sequenceNumber);
14871488
}

src/cpp/rtps/reader/StatefulReader.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,14 +295,16 @@ class StatefulReader : public fastdds::rtps::BaseReader
295295

296296
/**
297297
* Called after the change has been deserialized.
298-
* @param [in] change Pointer to the change being accessed.
299-
* @param [in] writer Writer proxy the @c change belongs to.
300-
* @param [in] mark_as_read Whether the @c change should be marked as read or not.
298+
* @param [in] change Pointer to the change being accessed.
299+
* @param [in] writer Writer proxy the @c change belongs to.
300+
* @param [in] mark_as_read Whether the @c change should be marked as read or not.
301+
* @param [in] should_send_ack Whether an ACKNACK should be sent to the writer or not.
301302
*/
302303
void end_sample_access_nts(
303304
CacheChange_t* change,
304305
WriterProxy*& writer,
305-
bool mark_as_read) override;
306+
bool mark_as_read,
307+
bool should_send_ack = false) override;
306308

307309
/**
308310
* @brief Fills the provided vector with the GUIDs of the matched writers.

src/cpp/rtps/reader/StatelessReader.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,8 @@ bool StatelessReader::begin_sample_access_nts(
513513
void StatelessReader::end_sample_access_nts(
514514
CacheChange_t* change,
515515
WriterProxy*& /*writer*/,
516-
bool mark_as_read)
516+
bool mark_as_read,
517+
bool /*should_send_ack*/)
517518
{
518519
// Mark change as read
519520
if (mark_as_read && !change->isRead)

src/cpp/rtps/reader/StatelessReader.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,14 +218,16 @@ class StatelessReader : public fastdds::rtps::BaseReader
218218

219219
/**
220220
* Called after the change has been deserialized.
221-
* @param [in] change Pointer to the change being accessed.
222-
* @param [in] writer Writer proxy the @c change belongs to.
223-
* @param [in] mark_as_read Whether the @c change should be marked as read or not.
221+
* @param [in] change Pointer to the change being accessed.
222+
* @param [in] writer Writer proxy the @c change belongs to.
223+
* @param [in] mark_as_read Whether the @c change should be marked as read or not.
224+
* @param [in] should_send_ack Whether an ACKNACK should be sent to the writer or not.
224225
*/
225226
void end_sample_access_nts(
226227
CacheChange_t* change,
227228
WriterProxy*& writer,
228-
bool mark_as_read) override;
229+
bool mark_as_read,
230+
bool should_send_ack = false) override;
229231

230232
/**
231233
* @brief Fills the provided vector with the GUIDs of the matched writers.

test/mock/rtps/RTPSReader/rtps/reader/BaseReader.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ class BaseReader : public fastdds::rtps::RTPSReader
154154
virtual void end_sample_access_nts(
155155
fastdds::rtps::CacheChange_t* /*change*/,
156156
fastdds::rtps::WriterProxy*& /*wp*/,
157-
bool /*mark_as_read*/)
157+
bool /*mark_as_read*/,
158+
bool /*should_send_ack*/ = false)
158159
{
159160
}
160161

0 commit comments

Comments
 (0)