-
Notifications
You must be signed in to change notification settings - Fork 269
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
feat(event cache): avoid storing useless prev-batch tokens #4427
Conversation
…ad no prev-batch token
…icated, after sync
…icated, after back-pagination
Stealing the review to @stefanceriu because <3. |
…decryption` more stable When starting to back-paginate, in this test, we: - either have a previous-batch token, that points to the first event *before* the message was sent, - or have no previous-batch token, because we stopped sync before receiving the first sync result. Because of the behavior introduced in 944a922, we don't restart back-paginating from the end, if we've reached the start. Now, if we are in the case described by the first bullet item, then we may backpaginate until the start of the room, and stop then, because we've back-paginated all events. And so we'll never see the message sent by Alice after we stopped sync'ing. One solution to get to the desired state is to clear the internal state of the room event cache, thus deleting the previous-batch token, thus causing the situation described in the second bullet item. This achieves what we want, that is, back-paginating from the end of the timeline.
baa3623
to
47193f1
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4427 +/- ##
=======================================
Coverage 85.42% 85.42%
=======================================
Files 283 283
Lines 31490 31518 +28
=======================================
+ Hits 26899 26923 +24
- Misses 4591 4595 +4 ☔ View full report in Codecov by Sentry. |
Fwiw, there's actually a small issue with back-paginations: if we're not storing a previous-batch token, we should also not replace the gap with the events returned by back-pagination. Consider the following timeline, that exists as such on the server, where the numbers represent event ids: [0, 1, 2, 3, 4, 5]. Let's take the notation that Conceptually, a token for back-pagination may be present in the timeline everywhere there's a timeline gap, so we can a mixed representation of a timeline like [ We start sliding sync:
I think the solution is to not do anything when all the events are known. After all, they are at their right location in the linked chunk, and as such, they shouldn't move anymore. I'll need to think a bit more about this, to make sure this is the right solution. |
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'm not sure to understand if more work is required, but so far, it looks good. I'm approving the PR :-).
Thank you for taking care of the tests.
pub fn deduplicated_all_new_events(&self) -> bool { | ||
self.num_new_unique > 0 && self.num_new_unique == self.num_duplicated | ||
} |
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.
Can't you simply test self.num_duplicated > 0
?
Actually, I don't understand the code here. The code, the doc, and the method name don't seem to do the same thing. Can you revisit this a bit please?
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.
Can't you simply test self.num_duplicated > 0?
No, what we're trying to know is:
- there was at least 1 new event
- AND all the new events we saw have been deduplicated
Which means we don't have any work to do (i.e. not update the current chunks, based on the assumption they were correctly positioned), and we should stop storing the previous-batch tokens (since we already knew about the events, if we needed a previous-batch token, we should have stored it already).
The code, the doc, and the method name don't seem to do the same thing. Can you revisit this a bit please?
Yep, I will expand upon this comment, and likely revisit the approach: the last commit that fixes the ordering issue observed in #4427 (comment) makes it a bit unwieldy now, and maybe we can spare the existence of AddEventReport
entirely.
Thanks!
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 rewritten the last commit and put a super large comment, hopefully it helps. Let me know if it doesn't, post-merge, and we can rephrase it 🙏
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 like you've removed AddEventReport
, it seems cleaner this way. I may have prefer a Option<T>
instead of (bool, T)
, but it's a personal taste (I believe it matches std
a bit better, but that's a detail, I'll try to submit a PR to not forget that and being able to discuss it).
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.
HHmm, it conflicts with other API which already returns an Option
. It would end up with Result<Option<Option<Positon>>, Error>
for example, which is a bit ugly… Let's say we are good here.
…'t cause meaningful changes See comment on top of `deduplicated_all_new_events`.
c11b4ce
to
b986f96
Compare
We have a problem right now, with the event cache storage: as soon as you receive a previous-batch token, either from the sync or from a previous back-pagination, we consider that we may have more events to retrieve in the past. Later, after running back-paginations, we may realize those events are duplicated. But since a back-pagination will return another previous-batch token, until we hit the start of the timeline, then we're getting stuck in back-pagination mode, until we've reached the start of the timeline again.
That's bad, because it makes the event cache store basically useless: every time you restore a session, you may receive a previous-batch token from sync (even more so with sliding sync, which will give one previous-batch token when timeline_limit=1, then another one when the timeline limit expands to 20). And so you back-paginate back until the start of the history.
This series of commits fixes that, by introducing two new rules:
With these two rules, we're not storing useless previous-batch tokens anymore, and we'll back-paginate at most one, for a given room. Interestingly, this might uncover some bugs related to back-pagination orderings, so we'll desperately want #4408 <3
Part of #3280.