Skip to content

Fix Gridstore has_pointer to account for delete pending operation#7638

Merged
timvisee merged 1 commit intodevfrom
fix-gridstore-has-pointer
Dec 1, 2025
Merged

Fix Gridstore has_pointer to account for delete pending operation#7638
timvisee merged 1 commit intodevfrom
fix-gridstore-has-pointer

Conversation

@agourlay
Copy link
Copy Markdown
Member

@agourlay agourlay commented Nov 28, 2025

This PR fixes a bug in Gridstore's has_pointer operation.

The bug manifests itself by an incorrect result from the put_value operation.

The contract for the returned boolean is

    /// Put a value in the storage.
    ///
    /// Returns true if the value existed previously and was updated, false if it was newly inserted.
    pub fn put_value(
        &mut self,
        point_offset: PointOffset,
        value: &V,
        hw_counter: HwMetricRefCounter,
    ) -> Result<bool> {

The value returned was incorrect in case of a delete operation present in the pending operation.

Luckily for us, no call site for put_value seems to rely on this returned information 😌

@agourlay agourlay changed the title Fix Gridstore has pointer lookup to account for nature of pending ope… Fix Gridstore has_pointer to account for delete pending operation Dec 1, 2025

pub fn has_pointer(&self, point_offset: PointOffset) -> bool {
self.pending_updates.contains_key(&point_offset) || self.get(point_offset).is_some()
self.get(point_offset).is_some()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pending_updates.contains_key is not correct, the pending operation might be a delete

the get method implements this check properly internally

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

The key thing is that self.get(point_offset) always represents the latest data. And so pending_updates must be ignored here as it's purely for persisting storage separately.

Put(PointOffset, Payload),
Delete(PointOffset),
Update(PointOffset, Payload),
Get(PointOffset),
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discovered the bug while improving our randomized test :)

@agourlay agourlay marked this pull request as ready for review December 1, 2025 09:19
@agourlay agourlay requested review from coszio and timvisee December 1, 2025 09:19
@qdrant qdrant deleted a comment from coderabbitai Bot Dec 1, 2025
Copy link
Copy Markdown
Member

@timvisee timvisee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updated tests 🙏

@timvisee timvisee merged commit eba78a6 into dev Dec 1, 2025
15 checks passed
@timvisee timvisee deleted the fix-gridstore-has-pointer branch December 1, 2025 09:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants