Geo [LR]: rake tasks to create and drop the logical replication subscription
Geo with logical replication (LR) needs a way to create and drop the LR subscription on the secondary as a first-class rake task. Today only the publication side is covered in product code, and every consumer of the subscription lifecycle has reimplemented the same raw SQL independently.
Why
ee/lib/tasks/gitlab/geo/logical_replication.rake ships gitlab:geo:logical_replication:publication:create, publication:delete, publication:set_tables, and subscription:refresh, but there is no subscription:create or subscription:drop anywhere in the codebase.
Because of that gap, the subscription lifecycle lives as vendored raw psql in three separate places:
- The Dedicated instrumentor seed job creates it (
common/jsonnet/geo-logical-replication-seed-subscribe.shin https://gitlab.com/gitlab-com/gl-infra/gitlab-dedicated/instrumentor/-/merge_requests/7958), withcopy_data = trueand teardown on failed runs. - The instrumentor cutover tool drops it (
bin/geo-logical-replication-cutover), in its abort, promote, and revert subcommands. - The local test environment https://gitlab.com/dbalexandre/geo-caproni-lr documents the same manual SQL in its promotion guide.
The teardown ordering is subtle and every consumer has to get it right on its own: ALTER SUBSCRIPTION ... DISABLE, then ALTER SUBSCRIPTION ... SET (slot_name = NONE) so DROP never hangs on the publisher connection, then DROP SUBSCRIPTION, then drop the detached replication slot on the publisher. Forgetting the publisher slot causes unbounded WAL retention on the publisher.
Promotion (!250118 (merged)) aborts with ActiveSubscriptionError while a subscription exists, even one that is merely disabled. Dropping the subscription is a mandatory pre-promotion step, and today there is no product-side implementation of it.
How
Extend the existing gitlab:geo:logical_replication:subscription namespace, reusing the Tasks::Gitlab::Geo::LogicalReplication helpers and the GEO_SUBSCRIPTION env var convention already used by subscription:refresh.
subscription:create: takes connection parameters via env vars, uses a publication name that defaults togeo_publication, setscopy_data = trueby default, and is guarded to run only on a Geo secondary.subscription:drop: idempotent (no-op if the subscription does not exist), uses the safe teardown ordering (DISABLE, SET slot_name = NONE, DROP), then attemptspg_drop_replication_sloton the publisher. If the publisher is unreachable, it prints the manual command instead of failing, mirroring the warning path already used by the instrumentor cutover tool.
What
- Add
gitlab:geo:logical_replication:subscription:create - Add
gitlab:geo:logical_replication:subscription:dropwith safe teardown ordering, idempotency, and publisher slot handling - Specs for both tasks, including re-run/no-op paths
- Document both tasks alongside the existing publication tasks
- Open a follow-up on the Dedicated side for instrumentor to call these instead of its vendored SQL
Exit criteria
- Both tasks exist and are idempotent.
- A promotion can be prepared with
subscription:dropalone, satisfying the MR 250118 pre-promotion requirement. - Instrumentor and geo-caproni-lr can delete their vendored subscription SQL.
Related: