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

Drop replication slot on tenant delete #1965

Merged
merged 17 commits into from
Nov 12, 2024
Merged

Conversation

robacourt
Copy link
Contributor

Fixes #1924

Comment on lines -17 to +18
Electric.TenantSupervisor.start_link([])
{:ok, _} =
Electric.TenantSupervisor.start_link(electric_instance_id: ctx.electric_instance_id)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This silently failed before

@@ -67,20 +68,26 @@ defmodule Support.ComponentSetup do
]

:ok = Electric.TenantManager.store_tenant(tenant, tenant_opts)
Electric.TenantSupervisor.start_tenant(ctx)
Copy link
Contributor Author

@robacourt robacourt Nov 11, 2024

Choose a reason for hiding this comment

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

This silently fails so I've removed it. Typically it's run inside with_complete_stack that also the shape cache, shape log collector which then conflict with the ones created inside the tenant. I spent some time trying to fix this but was spending too much time on it so will leave that work for a separate PR.


defp drop_publication(state) do
publication_name = Keyword.fetch!(state.replication_opts, :publication_name)
Postgrex.query!(state.pool_pid, "DROP PUBLICATION #{publication_name}", [])
Copy link
Contributor Author

@robacourt robacourt Nov 11, 2024

Choose a reason for hiding this comment

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

This runs the query directly on the pool rather than using the Postgrex.ReplicationConnection :query return term like we do for creating the publication. This is because there isn't a way to switch from stream mode back into query mode without waiting for something to arrive in the stream. WAL Keep-alives will eventually come but this is rather slow. Running the query directly seemed a better option.

@@ -0,0 +1,14 @@
defmodule Electric.TenantTables do
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this module to Tenant.Tables one level down? Top level is already quite crowded

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link

netlify bot commented Nov 12, 2024

Deploy Preview for electric-next ready!

Name Link
🔨 Latest commit a4c209f
🔍 Latest deploy log https://app.netlify.com/sites/electric-next/deploys/673311c1b7589d00085023a1
😎 Deploy Preview https://deploy-preview-1965--electric-next.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@robacourt robacourt merged commit ae18f4a into main Nov 12, 2024
25 checks passed
@robacourt robacourt deleted the rob/remove-replication-slot branch November 12, 2024 10:19
robacourt added a commit that referenced this pull request Nov 19, 2024
Following on from #1965 this drops the replication slot as well as the
publication.
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.

DELETE database_id shall clean up replication slot
2 participants