Skip to content

Commit

Permalink
Bring back nil check
Browse files Browse the repository at this point in the history
  • Loading branch information
bandetto committed Jun 21, 2024
1 parent d2e7ad0 commit 285e237
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions helper/restore_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ func (r *RestoreReader) endPluginProcess() {

// Reap plugin process and log plugin stderr. This should be called on every
// reader that used a plugin as to not leave any zombies behind.
func (r *RestoreReader) finalizePlugin() {
if r.pluginCmd != nil {
func finalizeReaderPlugin(r *RestoreReader) {
if r != nil && r.pluginCmd != nil {
log(fmt.Sprintf("Finalizing plugin process (%d)", r.pluginCmd.Process.Pid))
r.logPluginStderr()
r.endPluginProcess()
Expand Down Expand Up @@ -195,7 +195,7 @@ func doRestoreAgent() error {
logError(fmt.Sprintf("Error encountered getting restore data reader for single data file: %v", err))
return err
}
defer readers[contentToRestore].finalizePlugin()
defer finalizeReaderPlugin(readers[contentToRestore])
log(fmt.Sprintf("Using reader type: %s", readers[contentToRestore].readerType))

contentToRestore += *destSize
Expand Down Expand Up @@ -269,7 +269,7 @@ func doRestoreAgent() error {
logError(fmt.Sprintf("Error encountered getting restore data reader: %v", err))
return err
}
defer readers[contentToRestore].finalizePlugin()
defer finalizeReaderPlugin(readers[contentToRestore])
}
}

Expand Down Expand Up @@ -331,11 +331,11 @@ func doRestoreAgent() error {
if *singleDataFile && !(*isResizeRestore && contentToRestore >= *origSize) {
log(fmt.Sprintf("Oid %d: Data Reader - Start Byte: %d; End Byte: %d; Last Byte: %d", oid, start[contentToRestore], end[contentToRestore], lastByte[contentToRestore]))
err = readers[contentToRestore].positionReader(start[contentToRestore]-lastByte[contentToRestore], oid)
defer finalizeReaderPlugin(readers[contentToRestore])
if err != nil {
logError(fmt.Sprintf("Oid %d: Error reading from pipe: %v", oid, err))
return err
}
defer readers[contentToRestore].finalizePlugin()
}

log(fmt.Sprintf("Oid %d: Start table restore", oid))
Expand Down Expand Up @@ -371,10 +371,9 @@ func doRestoreAgent() error {
log(fmt.Sprintf("Oid %d: Copied %d bytes into the pipe", oid, bytesRead))

// SDF reads the pipe by chunks in several iterations but Wait()
// call will close the stdout immediately. For that case, Let defer
// do the work instead.
// call will close the pipe immediately. Let defer do the work.
if !*singleDataFile {
readers[contentToRestore].finalizePlugin()
finalizeReaderPlugin(readers[contentToRestore])
}

log(fmt.Sprintf("Closing pipe for oid %d: %s", oid, currentPipe))
Expand Down

0 comments on commit 285e237

Please sign in to comment.