-
Notifications
You must be signed in to change notification settings - Fork 38
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
Don't load events when there's a gap between known events #300
Conversation
d2ac630
to
c10afdf
Compare
1a654bf
to
f6783af
Compare
f6783af
to
fa227b7
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.
Overall methodology looks great.
state/accumulator.go
Outdated
// filled in by other pollers. | ||
// | ||
// A: E1 persisted, E2 omitted and unknown, E3 unknown (missing previous) | ||
// B: E1 persisted, E2 omitted and known, E3 unknown (not missing previous) |
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.
Terminology is too confusing. Hard to grok what:
- omitted
- unknown
- missing previous
are all supposed to mean. The proxy has either seen the event or not, why do we have 3^2 states?
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.
There are two edge cases I have in mind here. Starting with the simpler of the two:
Case B. Suppose Alice's poller sees E1, E2, and E3 all in the same timeline. All is well; nothing is MissingPrevious. Then suppose Bob's poller sees E1 in a first sync, followed by a limited (gappy) sync beginning with E3. In this situation:
- The Accumulate logic doesn't know that E2 directly preceeds E3. (For all it knows, there could be an E2.5 between them.) Therefore it has to consider E3 as MissingPrevious.
- However the proxy already knows that E2 comes before E3. Therefore E3 should not be marked as MissingPrevious in the database. (This should be fine because the event upsert logic says ON CONFLICT DO NOTHING.)
Case A. Suppose that Alice's poller sees E1 and E2 in the same timeline. Neither is MissingPrevious. Suppose Bob's sees the same two responses as before: E1 in a first sync, followed by a limited (gappy) sync beginning with E3. This time:
- The Accumulate logic still doesn't know that E2 directly preceeds E3, and has to consider E3 as MissingPrevious.
- Nor does the proxy already knows that E2 comes before E3. Therefore E3 should be marked as MissingPrevious in the database.
A follow-up: if some future poller (for Chris, say) saw E2 and E3 adacent in a timeline it could upsert the row for E3 to mark it as not MissingPrevious. However I'm not sure that's worth the effort.
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.
a5c02b2 tries to explain this better.
Upgrade test is failing. After the upgrade:
which is sliding-sync/state/event_table.go Lines 114 to 132 in 4aa0667
That's a surprise to me because I thought CREATE TABLE IF NOT EXISTS would be a no-op if the table already exists! |
Oh this will be the COMMENT ON..., won't 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.
Let's give it a go.
sync2/client.go
Outdated
@@ -4,7 +4,7 @@ import ( | |||
"context" | |||
"encoding/json" | |||
"fmt" | |||
"github.com/matrix-org/sliding-sync/internal" | |||
"go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp" |
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 has this appeared?
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.
Some kind of merge faffing with #301 I think?
}, | ||
} | ||
|
||
for _, tc := range testcases { | ||
// We're using the notation (X, Y] for a half-open interval excluding X but including Y. |
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 personally prefer rust's notation of X..=Y
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.
X..=Y
includes X, but I want to exclude X here.
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 could be worse---the French style of this notation is ]X, Y]
(!)
state/event_table_test.go
Outdated
{ID: "G", MissingPrevious: true}, | ||
{ID: "H", MissingPrevious: true}, | ||
{ID: "G-gap", MissingPrevious: true}, | ||
{ID: "H-gap", MissingPrevious: true}, |
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 I'm just having a lot of mental block here because I see A B C D and instinctively think there is no gap. When you then put H-gap
I think "uhh before or after"? Can we +2 letters to hint at the gap maybe? E.g A B C F-gap?
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.
Hmm. I think rename these to e.g. chunkX-eventY
, so that gaps only appear when we change chunks.
I'm sympathetic, but let's not stress about it now.
Only EW failed, but it suceeded on the prior commit. The only change I made was in unit tests, so I assume this is some Cypressy flake. |
Fixes #283
Part of #294.
Is going to conflict with #296.
Recommend commitwise review. I was going to write an E2E test, but it's fiddley to get a gappy sync deterministically, so opted for an integration test.