Repository navigation
Description
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_actiontopromote(we need to double check this during implementation)recovery_target_timelineto the one in the tokenrecovery_target_lsnto 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:
- [Feature]: Add
shutdownCheckpointTokenin the status after fencing/hibernating #3790 - [Feature]: Enable replica mode on an existing cluster #3796
- [Feature]: Introduce
replica.primaryandreplica.enabled = auto#3942
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
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
feat: introduce controlled switchover of a replica cluster (cloudnati…