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

*: set recovery_target_action to promote when using recovery target settings #545

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/keeper/cmd/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,10 +396,10 @@ func (p *PostgresKeeper) createRecoveryParameters(standbySettings *cluster.Stand
if recoveryTargetSettings.RecoveryTargetXid != "" {
parameters["recovery_target_xid"] = recoveryTargetSettings.RecoveryTargetXid
}

if recoveryTargetSettings.RecoveryTargetTimeline != "" {
parameters["recovery_target_timeline"] = recoveryTargetSettings.RecoveryTargetTimeline
}
parameters["recovery_target_action"] = "promote"
}

return parameters
Expand Down
3 changes: 3 additions & 0 deletions internal/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,9 @@ func (os *ClusterSpec) Validate() error {
if s.PITRConfig.DataRestoreCommand == "" {
return fmt.Errorf("pitrConfig.DataRestoreCommand undefined")
}
if s.PITRConfig.RecoveryTargetSettings != nil && *s.Role == ClusterRoleStandby {
return fmt.Errorf("cannot define pitrConfig.RecoveryTargetSettings when required cluster role is standby")
}
default:
return fmt.Errorf("unknown initMode: %q", *s.InitMode)

Expand Down
20 changes: 20 additions & 0 deletions tests/integration/pitr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ import (
func TestPITR(t *testing.T) {
t.Parallel()

testPITR(t, false)
}

func TestPITRRecoveryTarget(t *testing.T) {
t.Parallel()

testPITR(t, true)
}

func testPITR(t *testing.T, recoveryTarget bool) {
dir, err := ioutil.TempDir("", "stolon")
if err != nil {
t.Fatalf("unexpected err: %v", err)
Expand Down Expand Up @@ -109,6 +119,9 @@ func TestPITR(t *testing.T) {
t.Fatalf("unexpected err: %v", err)
}

// save current time used to define recovery_target_time
now := time.Now()

// ioutil.Tempfile already creates files with 0600 permissions
pgpass, err := ioutil.TempFile("", "pgpass")
if err != nil {
Expand Down Expand Up @@ -155,6 +168,13 @@ func TestPITR(t *testing.T) {
"max_prepared_transactions": "100",
}),
}

if recoveryTarget {
initialClusterSpec.PITRConfig.RecoveryTargetSettings = &cluster.RecoveryTargetSettings{
RecoveryTargetTime: now.Format(time.RFC3339),
}
}

initialClusterSpecFile, err = writeClusterSpec(dir, initialClusterSpec)
if err != nil {
t.Fatalf("unexpected err: %v", err)
Expand Down