MCPcopy Create free account
hub / github.com/apache/cloudberry / RestoreArchivedFile

Function RestoreArchivedFile

src/fe_utils/archive.c:38–124  ·  view source on GitHub ↗

* RestoreArchivedFile * * Attempt to retrieve the specified file from off-line archival storage. * If successful, return a file descriptor of the restored file, else * return -1. * * For fixed-size files, the caller may pass the expected size as an * additional crosscheck on successful recovery. If the file size is not * known, set expectedSize = 0. */

Source from the content-addressed store, hash-verified

36 * known, set expectedSize = 0.
37 */
38int
39RestoreArchivedFile(const char *path, const char *xlogfname,
40 off_t expectedSize, const char *restoreCommand)
41{
42 char xlogpath[MAXPGPATH];
43 char *xlogRestoreCmd;
44 int rc;
45 struct stat stat_buf;
46
47 snprintf(xlogpath, MAXPGPATH, "%s/" XLOGDIR "/%s", path, xlogfname);
48
49 xlogRestoreCmd = BuildRestoreCommand(restoreCommand, xlogpath,
50 xlogfname, NULL);
51 if (xlogRestoreCmd == NULL)
52 {
53 pg_log_fatal("cannot use restore_command with %%r placeholder");
54 exit(1);
55 }
56
57 /*
58 * Execute restore_command, which should copy the missing file from
59 * archival storage.
60 */
61 rc = system(xlogRestoreCmd);
62 pfree(xlogRestoreCmd);
63
64 if (rc == 0)
65 {
66 /*
67 * Command apparently succeeded, but let's make sure the file is
68 * really there now and has the correct size.
69 */
70 if (stat(xlogpath, &stat_buf) == 0)
71 {
72 if (expectedSize > 0 && stat_buf.st_size != expectedSize)
73 {
74 pg_log_fatal("unexpected file size for \"%s\": %lld instead of %lld",
75 xlogfname, (long long int) stat_buf.st_size,
76 (long long int) expectedSize);
77 exit(1);
78 }
79 else
80 {
81 int xlogfd = open(xlogpath, O_RDONLY | PG_BINARY, 0);
82
83 if (xlogfd < 0)
84 {
85 pg_log_fatal("could not open file \"%s\" restored from archive: %m",
86 xlogpath);
87 exit(1);
88 }
89 else
90 return xlogfd;
91 }
92 }
93 else
94 {
95 if (errno != ENOENT)

Callers

nothing calls this directly

Calls 5

BuildRestoreCommandFunction · 0.85
wait_result_to_strFunction · 0.85
statClass · 0.70
pfreeFunction · 0.50

Tested by

no test coverage detected