-
Notifications
You must be signed in to change notification settings - Fork 91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(spooler): Fix datetime comparison #4025
Conversation
// Unfortunately we have to do this because SQLite `DELETE` with `RETURNING` doesn't | ||
// 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())) |
There was a problem hiding this comment.
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.
assert!(envelope_store | ||
.insert_many(envelopes.iter().map(|e| e.as_ref().try_into().unwrap())) | ||
.await | ||
.is_ok()); | ||
|
||
// 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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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).
This PR uses
UnixTimestamp
instead ofDateTime
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