Skip to content

Commit

Permalink
pghoard: rename prefetched WAL in pghoard_postgres_command_go
Browse files Browse the repository at this point in the history
  • Loading branch information
egor-voynov-aiven committed Mar 26, 2024
1 parent d62770c commit abd4650
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions golang/pghoard_postgres_command_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func run() (int, error) {
retry_seconds := *riPtr
for {
attempt += 1
rc, err := restore_command(url, *outputPtr)
rc, err := restore_command(url, *outputPtr, *xlogPtr)
if rc != EXIT_RESTORE_FAIL {
return rc, err
}
Expand All @@ -100,7 +100,7 @@ func archive_command(url string) (int, error) {
return EXIT_ABORT, errors.New("archive_command not yet implemented")
}

func restore_command(url string, output string) (int, error) {
func restore_command(url string, output string, xlog string) (int, error) {
var output_path string
var req *http.Request
var err error
Expand All @@ -120,6 +120,16 @@ func restore_command(url string, output string) (int, error) {
}
output_path = path.Join(cwd, output)
}
// if file "<xlog>.pghoard.prefetch" exists, just move it to destination
xlogPrefetchPath := path.Join(path.Dir(output_path), xlog+".pghoard.prefetch")
_, err = os.Stat(xlogPrefetchPath)
if err == nil {
err := os.Rename(xlogPrefetchPath, output_path)
if err != nil {
return EXIT_ABORT, err
}
return EXIT_OK, nil
}
req, err = http.NewRequest("GET", url, nil)
req.Header.Set("x-pghoard-target-path", output_path)
}
Expand Down

0 comments on commit abd4650

Please sign in to comment.