Skip to content
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

chore(electric): Load and clear client reconnection info per client #1188

Merged
merged 10 commits into from May 6, 2024

Conversation

alco
Copy link
Member

@alco alco commented Apr 23, 2024

This is a follow-up to #1116, specifically addressing Ilia's request.

Client reconnection info is now reloaded from the database at client connection time. This way we can ensure consistency between the data cached in ETS and data stored in the database.

@alco alco force-pushed the alco/vax-1804-scope-client-reconnection-info branch 2 times, most recently from 0ed48fe to 4169713 Compare April 23, 2024 21:28
@alco alco changed the title Alco/vax 1804 scope client reconnection info chore(electric): Load and clear client reconnection info per client Apr 23, 2024
@alco alco requested a review from icehaunter April 23, 2024 21:40
@alco alco marked this pull request as ready for review April 23, 2024 21:51
@alco alco force-pushed the alco/vax-1804-scope-client-reconnection-info branch from e3973a7 to e83d160 Compare April 24, 2024 11:29
Copy link
Contributor

@icehaunter icehaunter left a comment

Choose a reason for hiding this comment

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

I like the approach, thanks for addressing these concerns! I do have two discussion points that I think warrant solving before merge

@alco alco force-pushed the alco/vax-1804-scope-client-reconnection-info branch 2 times, most recently from e87a7c2 to 2c31b6d Compare April 30, 2024 09:03
Copy link
Contributor

@icehaunter icehaunter left a comment

Choose a reason for hiding this comment

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

LGTM with one nitpick to remove a piece of code


# Make sure we don't have any leftover cached info for this client in case its local data
# was cleared without the server knowing about it.
ClientReconnectionInfo.clear_all_data!(state.origin, state.client_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to add this here, given :perform_initial_sync_and_subscribe handler will call ClientReconnectionInfo.store_initial_checkpoint!/4 that will clear all this data atomically anyway?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's a fair point. I added this call because it looked like a logical thing to do for this module if you don't take into account that ClientReconnectionInfo.store_initial_checkpoint!() calls it internally.

I know that one is required to know what happens in all three modules--WebsocketServer, Protocol, ClientReconnectionInfo--in order to be able to make sense of the data flow for any given client, but I would still argue that having this call here does more good than harm since it's handling an edge case. At some point some implementation detail may change elsewhere that could affect the part of logic defined here, in Protocol. Better be prepared for that than sorry.

with {:ok, state} <- restore_subscriptions(subscription_ids, state) do
restore_graph(lsn, observed_txn_data, state)
end
end

defp restore_subscriptions(subscription_ids, %State{} = state) do
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpicky question: what's with function reordering here? Makes it harder to compare diffs

Copy link
Member Author

Choose a reason for hiding this comment

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

I simply moved this function definition up because it is called first in restore_client_state(), and restore_graph() is called after it.

@alco alco force-pushed the alco/vax-1804-scope-client-reconnection-info branch from f269173 to 77c5cd3 Compare May 6, 2024 07:59
@alco alco merged commit f60ff0a into main May 6, 2024
7 checks passed
@alco alco deleted the alco/vax-1804-scope-client-reconnection-info branch May 6, 2024 09:35
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.

None yet

2 participants