Skip to content

Conversation

@iambriccardo
Copy link
Contributor

@iambriccardo iambriccardo commented Sep 11, 2024

This PR uses UnixTimestamp instead of DateTime to compare timestamps when sorting data from disk.

This fixes an issue that raised the following panic (https://doc.rust-lang.org/src/core/slice/sort/shared/smallsort.rs.html#862) which caused the envelope buffer service to crash and stop handling envelopes.

ref: rust-lang/rust#129561

@iambriccardo iambriccardo marked this pull request as ready for review September 11, 2024 13:12
@iambriccardo iambriccardo requested a review from a team as a code owner September 11, 2024 13:12
@iambriccardo iambriccardo changed the title riccardo/fix/sorting fix(spooler): Fix datetime comparison Sep 11, 2024
// return deleted rows in a specific order.
extracted_envelopes.sort_by_key(|a| a.received_at());
extracted_envelopes.sort_by_key(|a| {
Reverse(UnixTimestamp::from_datetime(a.received_at()).unwrap_or(UnixTimestamp::now()))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot to return the dates in reverse sorted order to honor the API. This is now fixed, the envelopes are returning in descending timestamp order.


// We check that if we load more than the limit, we still get back at most 10.
// We check that if we load 5, we get the newest 5.
let extracted_envelopes = envelope_store
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and improved this test.

// Since the store returns the envelopes sorted in descending order, we want to put them
// in reverse into the vector in the buffer, because we want to pop the last element always,
// which has to be the newest (aka with the biggest timestamp).
envelopes.reverse();
Copy link
Member

Choose a reason for hiding this comment

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

Why do we reverse twice, once here and once in delete_many?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's explained in the comment above, I wanted to return descending values from the store but when concatenating in the buffer, we pop from the bottom (which we assume has the newest timestamp).

@iambriccardo iambriccardo merged commit bb90d30 into master Sep 12, 2024
@iambriccardo iambriccardo deleted the riccardo/fix/sorting branch September 12, 2024 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants