Skip to content

[Feature]: Add replica.token option #3944

Closed

Description

@gbartolini

Is there an existing issue already for this feature request/idea?

  • I have searched for an existing issue, and could not find anything. I believe this is a new feature request to be evaluated.

What problem is this feature going to solve? Why should it be added?

We do not have a way to ensure that a former replica cluster is promoted as a primary without any data loss.

Describe the solution you'd like

We should introduce a new option called replica.token that is evaluated by a replica cluster when it transitions from replica to primary mode. The token format is the one described in #3790, and contains some fundamental information, including:

  • Database system identifier
  • Latest checkpoint's TimeLineID
  • Latest checkpoint's REDO location
  • Latest checkpoint's REDO WAL file
  • Time of latest checkpoint

Consider this simplified scenario with pg2 being a replica cluster of pg1.

pg1 looks like this:

kind: Cluster
metadata:
  name: pg1
spec:
   # ...
  replica:
    primary: pg1
    source: pg2
    enabled: auto

and pg2:

kind: Cluster
metadata:
  name: pg2
spec:
   # ...
  replica:
    primary: pg1
    source: pg1
    enabled: auto

We change the pg1 cluster, informing it that the new distributed primary is pg2:

  # pg1 cluster
  replica:
    primary: pg2
    source: pg2

This operation cleanly shuts down pg1 and adds shutdownCheckpointToken to its status.

We grab the token and modify pg2 as follows:

  # pg2 cluster
  replica:
    primary: pg2
    source: pg1
    token: <SHUTDOWN_CHECKPOINT_TOKEN_FROM_PG1>

The operator detects that the primary in pg2 has changed, and that there's a token. We extract the information from the token and verify that we are on the same timeline and not ahead of the LSN. If so, we set on the designated primary:

  • recovery_target_action to promote (we need to double check this during implementation)
  • recovery_target_timeline to the one in the token
  • recovery_target_lsn to the one in the token

We need to decide what to do in case somebody changes the token field and it is not compatible with the current timeline.

The token field represents the last time the current cluster was requested to be promoted.

The patch should also include a command for the plugin to facilitate this operation. We should also consider expanding the information we have in the token, if it helps us improve the resiliency of the operation.

Describe alternatives you've considered

We have thought about using a table in the database to control this, but discarded as we prefer to use configuration.

Additional context

This ticket depends on the following issues:

Backport?

No

Are you willing to actively contribute to this feature?

Yes

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added
    triage
    on Feb 26, 2024
  2. self-assigned this
    on Feb 26, 2024
  3. added
    enhancement 🪄
    and removed
    triage
    on Feb 26, 2024
  4. added this to the 1.23.0 milestone on Apr 5, 2024
  5. modified the milestones: 1.23.0, 1.24.0 on Apr 15, 2024
  6. added a commit that references this issue on Jun 19, 2024
    f2b876e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement 🪄

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions