-
Notifications
You must be signed in to change notification settings - Fork 260
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
Add an enqueue time to the send queue system #4385
base: main
Are you sure you want to change the base?
Add an enqueue time to the send queue system #4385
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4385 +/- ##
==========================================
+ Coverage 85.41% 85.44% +0.03%
==========================================
Files 283 283
Lines 31559 31659 +100
==========================================
+ Hits 26955 27052 +97
- Misses 4604 4607 +3 ☔ View full report in Codecov by Sentry. |
e0b7108
to
b1ef4ca
Compare
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.
Looks like this is on the right path! It would be nice to expose the value in the local echoes themselves then, and test this all works fine.
0208b4e
to
f06e529
Compare
@bnjbvr thank you for the review. Made your suggested corrections (one pending question), and then in a second commit I have attempted to expose this timestamp through the api layer. It was more involved than I thought, but I think there was only one spot where I wasn't quite sure which timestamp to use (related to retry of a media message I believe, I left a comment). Right now I have the storage layer assigning the timestamp and returning it to be used by the SendHandle system. If you think it would be cleaner to pass in a timestamp I am open to changing this. If you think this API shape is reasonable, I will work to add some tests (or extend the existing tests) to exercise it. |
f06e529
to
0530eb0
Compare
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.
Looks like this is going in the right direction 👍 I haven't reviewed in depth, but left a few high-level comments in places. Let's go ahead and add some tests 💪
crates/matrix-sdk-sqlite/migrations/state_store/010_send_queue_enqueue_time.sql
Outdated
Show resolved
Hide resolved
crates/matrix-sdk-sqlite/migrations/state_store/010_send_queue_enqueue_time.sql
Outdated
Show resolved
Hide resolved
7f01da5
to
6d799dd
Compare
c3726a0
to
df7fc6e
Compare
@bnjbvr I had to mark the |
df7fc6e
to
12d9609
Compare
Rebased to resolve merge conflicts and flattened the commits. |
12d9609
to
9ac86a1
Compare
9ac86a1
to
d47e45a
Compare
Unclear to me what the current build break is related to in this PR. |
Yep, it's an unrelated intermittent failure, nothing to do with your PR. I'll take another look today 👍 |
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.
Looks like we're getting super close to land this. Sorry to ask a bit for more changes, I spotted a few ways to make this even cleaner.
(I will be on holidays starting today for a few weeks, so there might be a bit of delay before the next round of review. Happy end of the year, and thanks for bearing with us :))
@@ -1033,6 +1033,7 @@ impl<'a, 'o> TimelineEventHandler<'a, 'o> { | |||
send_state: EventSendState::NotSentYet, | |||
transaction_id: txn_id.to_owned(), | |||
send_handle: send_handle.clone(), | |||
created_at: send_handle.clone().and_then(|h| h.created_at), |
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.
Probably the cloning is not required here:
created_at: send_handle.clone().and_then(|h| h.created_at), | |
created_at: send_handle.created_at, |
(or created_at.clone()
, if borrowck complains)
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.
So send_handle is an Option so I can't access created_at directly. And if I try to map and clone, it seems to dislike the Option being mapped (since self.ctx_flow is a reference). I think the clone is needed?
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 think the field is Copy
so it should work with send_handle.as_ref().and_then(|h| h.created_at)
.
@@ -131,6 +132,9 @@ pub struct QueuedRequest { | |||
/// The bigger the value, the higher the priority at which this request | |||
/// should be handled. | |||
pub priority: usize, | |||
|
|||
/// The time that the request was original attempted. | |||
pub created_at: Option<MilliSecondsSinceUnixEpoch>, |
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.
Could this be non-optional, since this is not serialized we could always provide a value here? There might be places where we upgrade a DependentQueuedRequest
with no created_at
(because they were created before this change is introduced) to a QueuedRequest
, but it seems fine to use Milliseconds::now()
in those cases, maybe?
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.
Yeah, so if we are okay with injecting Milliseconds::now when it fails to parse coming out of the DB (either due to a previous migration or due to ... cosmic rays, then I think we can safely make this non optional.
IMO that's totally fine to do as you explained, just wasn't sure about injecting false data.
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've updated it to use a ::now in most places and make it required everywhere except when it is exposed in the FFI (because SendHandle might not be present for the Local items)
let created_at = MilliSecondsSinceUnixEpoch::now(); | ||
let transaction_id = self.inner.queue.push(content.clone().into(), created_at).await?; |
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.
The PR mixes two ways of feeding the created_at
:
- sometimes it's created at the
RoomSendQueue
level, and passed as a parameter to aQueueStorage
function, - sometimes it's the
QueueStorage
that will callnow()
and pass it directly to the underlying store functions.
We should make this a bit more uniform; I think I prefer the latter where the QueueStorage
internally sets it. It's nicer, because it implies having fewer parameters to the QueueStorage
external functions too.
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.
So the original version had it being injected directly in the send_queue to minimize the API changes.
But this meant though that the timestamp would have to be returned to be used in constructing a SendHandle
, which we did not like. Sometimes the SendHandles come from the persisted store, but sometimes they are constructed directly by people calling the send_queue method.
Let me know which way you prefer. Personally I think the current method is cleaner, and also makes it easier to write tests against.
crates/matrix-sdk/src/send_queue.rs
Outdated
|
||
/// The time that this send handle was first created | ||
pub created_at: Option<MilliSecondsSinceUnixEpoch>, |
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 see that the only place where this is read is in the timeline code, correct? As a last high-level comment: I think this could be moved to the LocalEchoContent::Event
variant, even — we might not care about a reaction's created_at
(or do we? if so, we could move it to the LocalEcho
struct more generally).
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.
So the issue is that it needs to be exposed in the LocalEventTimelineItem
in crates/matrix-sdk-ui/src/timeline/event_handler.rs
which doesn't appear to have access to LocalEchos. Thats why I put it in the SendHandle.
(If you rebase on top of main it should be fixed now.) |
d47e45a
to
b5e4b99
Compare
Co-authored-by: Benjamin Bouvier <[email protected]> Signed-off-by: Daniel Salinas <[email protected]>
71b057d
to
1e6bfa3
Compare
8d4a9e7
to
f3a1334
Compare
Add a new created_at to the send_queue_events and dependent_send_queue_events stored records. This will allow clients to understand how stale a pending message might be in the event that the queue encounters and error and becomes wedged.
This change is exposed through the FFI on the
EventTimelineItem
struct as a new optional field namedlocal_created_at
. It will beNone
for any Remote event, andSome
for Local events (except for those that were enqueued before the migrations were run).Signed-off-by: Daniel Salinas