-
Notifications
You must be signed in to change notification settings - Fork 14
PTEUDO-1543: Handle schema drops on restore failure, avoid special extensions #319
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
Conversation
leandrorichardtoledo
commented
Sep 26, 2024
- Ticket: PTEUDO-1543;
# Conflicts: # pkg/databaseclaim/databaseclaim.go
@@ -1165,7 +1165,7 @@ func (r *DatabaseClaimReconciler) manageUserAndExtensions(reqInfo *requestInfo, | |||
if err != nil { | |||
return err | |||
} | |||
if roleCreated { | |||
if roleCreated && operationalMode != M_MigrateExistingToNewDB && operationalMode != M_MigrationInProgress { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻
pkg/pgctl/pgrestore.go
Outdated
result.Error = &ResultError{Err: exitError, ExitCode: exitError.ExitCode(), CmdOutput: result.Output} | ||
|
||
// Attempt to drop schemas after restore failure. | ||
fmt.Println("restore failed, dropping all schemas") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is needed, can you pass in a logger to output the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the DropSchemas to return structured output of the stdout/stderr of the cli calls happening here. You could modify Exec() a little bit and re-use it for DropSchemas
pkg/pgctl/pgrestore.go
Outdated
@@ -76,3 +107,25 @@ func (x *Restore) SetOptions(o []string) { | |||
func (x *Restore) GetOptions() []string { | |||
return x.Options | |||
} | |||
|
|||
// DropSchemas drops all schemas except the system ones. | |||
func (x *Restore) DropSchemas() error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The pattern of the other methods is to return a Result. Maybe that's a better option so stdout/stderr of the command can be handled more strictly.
func (x *Restore) DropSchemas() error { | |
func (x *Restore) DropSchemas() Result { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed
pkg/pgctl/pgrestore.go
Outdated
cmd := exec.Command(PSQL, x.DsnUri, "-c", dropSchemaSQL) | ||
cmd.Stderr = os.Stderr | ||
cmd.Stdout = os.Stdout | ||
|
||
if err := cmd.Run(); err != nil { | ||
return fmt.Errorf("error dropping schemas: %w", err) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's handle these with loggers rather than sending directly to stdout/stderr. You could copy what's done in (x *Dump) Exec
or send back (string, error)
cmd := exec.Command(PSQL, x.DsnUri, "-c", dropSchemaSQL) | |
cmd.Stderr = os.Stderr | |
cmd.Stdout = os.Stdout | |
if err := cmd.Run(); err != nil { | |
return fmt.Errorf("error dropping schemas: %w", err) | |
} | |
var result Result | |
cmd := exec.Command(PSQL, x.DsnUri, "-c", dropSchemaSQL) | |
stderrIn, _ := cmd.StderrPipe() | |
go func() { | |
result.Output = streamExecOutput(stderrIn, opts) | |
}() | |
cmd.Start() | |
err := cmd.Wait() | |
... |
pkg/pgctl/pgrestore.go
Outdated
if dropErr != nil { | ||
result.Error = &ResultError{ | ||
Err: dropErr, | ||
CmdOutput: fmt.Sprintf("restore error: %v\ndrop schemas error: %v", exitError, dropErr), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error is already in Err field, no reason to duplicate it. You've also lost the stdout/stderr text. It should be passing hat back or just have DropSchemas() return a Result{} object