[#23974] Fix DataReader history enforcement to respect max_samples_per_instance #6228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes a bug where
DataReaderwas incorrectly usinghistory.depthinstead ofmax_samples_per_instancewhendepth > max_samples_per_instance.Current Behavior (Bug)
When a DataReader is configured with:
history.depth = 10max_samples_per_instance = 5The QoS validation correctly warns:
However, the DataReader was actually storing 10 samples (using
depth) instead of 5 (usingmax_samples_per_instance), making the warning misleading.Root Cause
The bug existed in three locations:
max_samples_per_instancewas being overwritten withmax_samples, destroying the user's QoS settinginstance_changes.size() < depthinstead ofinstance_changes.size() < min(depth, max_samples_per_instance)Changes
min(history.depth, max_samples_per_instance)as the effective limitDataWriterHistory::to_history_attributesfor consistency in memory allocationImpact
This fix ensures the DataReader behavior matches the documented QoS warning message. Applications relying on
max_samples_per_instanceto limit memory usage will now work correctly.@Mergifyio backport 3.4.x 3.3.x 3.2.x 2.14.x
Contributor Checklist
versions.mdfile (if applicable).Reviewer Checklist