Skip to content

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

Merged
merged 4 commits into from
Sep 27, 2024

Conversation

leandrorichardtoledo
Copy link
Contributor

# 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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

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")
Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed

Copy link
Contributor

@drewwells drewwells left a 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

@@ -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 {
Copy link
Contributor

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.

Suggested change
func (x *Restore) DropSchemas() error {
func (x *Restore) DropSchemas() Result {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

Comment on lines 123 to 129
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)
}
Copy link
Contributor

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)

Suggested change
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()
...

if dropErr != nil {
result.Error = &ResultError{
Err: dropErr,
CmdOutput: fmt.Sprintf("restore error: %v\ndrop schemas error: %v", exitError, dropErr),
Copy link
Contributor

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

@leandrorichardtoledo leandrorichardtoledo merged commit 6d4741f into main Sep 27, 2024
3 checks passed
@leandrorichardtoledo leandrorichardtoledo deleted the PTEUDO-1543 branch September 27, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants