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

Function fsync_pgdata

src/common/file_utils.c:63–120  ·  view source on GitHub ↗

* Issue fsync recursively on PGDATA and all its contents. * * We fsync regular files and directories wherever they are, but we follow * symlinks only for pg_wal (or pg_xlog) and immediately under pg_tblspc. * Other symlinks are presumed to point at files we're not responsible for * fsyncing, and might not have privileges to write at all. * * serverVersion indicates the version of the server

Source from the content-addressed store, hash-verified

61 * serverVersion indicates the version of the server to be fsync'd.
62 */
63void
64fsync_pgdata(const char *pg_data,
65 int serverVersion)
66{
67 bool xlog_is_symlink;
68 char pg_wal[MAXPGPATH];
69 char pg_tblspc[MAXPGPATH];
70
71 /* handle renaming of pg_xlog to pg_wal in post-10 clusters */
72 snprintf(pg_wal, MAXPGPATH, "%s/%s", pg_data,
73 serverVersion < MINIMUM_VERSION_FOR_PG_WAL ? "pg_xlog" : "pg_wal");
74 snprintf(pg_tblspc, MAXPGPATH, "%s/pg_tblspc", pg_data);
75
76 /*
77 * If pg_wal is a symlink, we'll need to recurse into it separately,
78 * because the first walkdir below will ignore it.
79 */
80 xlog_is_symlink = false;
81
82#ifndef WIN32
83 {
84 struct stat st;
85
86 if (lstat(pg_wal, &st) < 0)
87 pg_log_error("could not stat file \"%s\": %m", pg_wal);
88 else if (S_ISLNK(st.st_mode))
89 xlog_is_symlink = true;
90 }
91#else
92 if (pgwin32_is_junction(pg_wal))
93 xlog_is_symlink = true;
94#endif
95
96 /*
97 * If possible, hint to the kernel that we're soon going to fsync the data
98 * directory and its contents.
99 */
100#ifdef PG_FLUSH_DATA_WORKS
101 walkdir(pg_data, pre_sync_fname, false);
102 if (xlog_is_symlink)
103 walkdir(pg_wal, pre_sync_fname, false);
104 walkdir(pg_tblspc, pre_sync_fname, true);
105#endif
106
107 /*
108 * Now we do the fsync()s in the same order.
109 *
110 * The main call ignores symlinks, so in addition to specially processing
111 * pg_wal if it's a symlink, pg_tblspc has to be visited separately with
112 * process_symlinks = true. Note that if there are any plain directories
113 * in pg_tblspc, they'll get fsync'd twice. That's not an expected case
114 * so we don't worry about optimizing it.
115 */
116 walkdir(pg_data, fsync_fname, false);
117 if (xlog_is_symlink)
118 walkdir(pg_wal, fsync_fname, false);
119 walkdir(pg_tblspc, fsync_fname, true);
120}

Callers 4

sync_target_dirFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85
BaseBackupFunction · 0.85

Calls 2

pgwin32_is_junctionFunction · 0.85
walkdirFunction · 0.70

Tested by

no test coverage detected