Skip to content

fix: Reconcile on SubscriptionManager init#1931

Merged
edgurgel merged 1 commit into
mainfrom
fix/subscription-manager-reconciliation
Jun 16, 2026
Merged

fix: Reconcile on SubscriptionManager init#1931
edgurgel merged 1 commit into
mainfrom
fix/subscription-manager-reconciliation

Conversation

@edgurgel

@edgurgel edgurgel commented Jun 2, 2026

Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

Instead of always deleting the subscriptions table when SubscriptionManager starts we:

  • Cold start cleans up the DB
  • Warm restarts now re-adopt ETS and re-monitor subscribers

Orphan processes are not a problem because ReplicationPoller simply broadcasts if it can't find the pid/node related to the subscription row. See

case collect_subscription_nodes(subscribers_nodes_table, change.subscription_ids) do
{:ok, nodes} ->
for {node, subscription_ids} <- nodes do
TenantBroadcaster.pubsub_direct_broadcast(
node,
tenant_id,
topic,
# Send only the subscription IDs relevant to this node
{change.type, payload, MapSet.new(subscription_ids)},
MessageDispatcher,
:postgres_changes
)
end
{:error, :node_not_found} ->
TenantBroadcaster.pubsub_broadcast(
tenant_id,
topic,
{change.type, payload, change.subscription_ids},
MessageDispatcher,
:postgres_changes
)
end

One option that I decided to not implement was to do a "delete from subscription NOT IN $alive_sub_ids" as this can be problematic depending on the size of the table and it's not a huge issue to have orphan rows there momentarily. It's also more complicated.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage is 91.533%fix/subscription-manager-reconciliation into main. No base build found for main.

@edgurgel
edgurgel force-pushed the fix/subscription-manager-reconciliation branch from 9e73b55 to bf522a5 Compare June 16, 2026 04:57
Instead of always deleting the subscriptions table when
SubscriptionManager starts we:

* warm restarts now re-adopt ETS and re-monitor subscribers
* cold start cleans up the DB

Orphan processes are not a problem because ReplicationPoller simply
broadcasts if it can't find the pid related to the subscription row
@edgurgel
edgurgel force-pushed the fix/subscription-manager-reconciliation branch from bf522a5 to 67dc693 Compare June 16, 2026 04:58
@edgurgel
edgurgel merged commit 6275961 into main Jun 16, 2026
45 of 46 checks passed
@edgurgel
edgurgel deleted the fix/subscription-manager-reconciliation branch June 16, 2026 22:49
@realtime-release-bot

Copy link
Copy Markdown

🎉 This PR is included in version 2.107.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants