|
| 1 | +diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c |
| 2 | +index 45be21131c5..134e677f9d1 100644 |
| 3 | +--- a/src/backend/backup/basebackup.c |
| 4 | ++++ b/src/backend/backup/basebackup.c |
| 5 | +@@ -199,6 +199,13 @@ static const struct exclude_list_item excludeFiles[] = |
| 6 | + {"postmaster.pid", false}, |
| 7 | + {"postmaster.opts", false}, |
| 8 | + |
| 9 | ++ /* |
| 10 | ++ * Skip all transient ptrack files, but do copy ptrack.map, since it may |
| 11 | ++ * be successfully used immediately after backup. TODO: check, test? |
| 12 | ++ */ |
| 13 | ++ {"ptrack.map.mmap", false}, |
| 14 | ++ {"ptrack.map.tmp", false}, |
| 15 | ++ |
| 16 | + /* end of list */ |
| 17 | + {NULL, false} |
| 18 | + }; |
| 19 | +@@ -214,6 +221,11 @@ static const struct exclude_list_item noChecksumFiles[] = { |
| 20 | + {"pg_filenode.map", false}, |
| 21 | + {"pg_internal.init", true}, |
| 22 | + {"PG_VERSION", false}, |
| 23 | ++ |
| 24 | ++ {"ptrack.map.mmap", false}, |
| 25 | ++ {"ptrack.map", false}, |
| 26 | ++ {"ptrack.map.tmp", false}, |
| 27 | ++ |
| 28 | + #ifdef EXEC_BACKEND |
| 29 | + {"config_exec_params", true}, |
| 30 | + #endif |
| 31 | +diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c |
| 32 | +index e04bc3941ae..996b5de6169 100644 |
| 33 | +--- a/src/backend/storage/file/copydir.c |
| 34 | ++++ b/src/backend/storage/file/copydir.c |
| 35 | +@@ -27,6 +27,8 @@ |
| 36 | + #include "storage/copydir.h" |
| 37 | + #include "storage/fd.h" |
| 38 | + |
| 39 | ++copydir_hook_type copydir_hook = NULL; |
| 40 | ++ |
| 41 | + /* |
| 42 | + * copydir: copy a directory |
| 43 | + * |
| 44 | +@@ -75,6 +77,9 @@ copydir(const char *fromdir, const char *todir, bool recurse) |
| 45 | + } |
| 46 | + FreeDir(xldir); |
| 47 | + |
| 48 | ++ if (copydir_hook) |
| 49 | ++ copydir_hook(todir); |
| 50 | ++ |
| 51 | + /* |
| 52 | + * Be paranoid here and fsync all files to ensure the copy is really done. |
| 53 | + * But if fsync is disabled, we're done. |
| 54 | +diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c |
| 55 | +index fdecbad1709..f849d00161e 100644 |
| 56 | +--- a/src/backend/storage/smgr/md.c |
| 57 | ++++ b/src/backend/storage/smgr/md.c |
| 58 | +@@ -87,6 +87,8 @@ typedef struct _MdfdVec |
| 59 | + |
| 60 | + static MemoryContext MdCxt; /* context for all MdfdVec objects */ |
| 61 | + |
| 62 | ++mdextend_hook_type mdextend_hook = NULL; |
| 63 | ++mdwrite_hook_type mdwrite_hook = NULL; |
| 64 | + |
| 65 | + /* Populate a file tag describing an md.c segment file. */ |
| 66 | + #define INIT_MD_FILETAG(a,xx_rlocator,xx_forknum,xx_segno) \ |
| 67 | +@@ -515,6 +517,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, |
| 68 | + register_dirty_segment(reln, forknum, v); |
| 69 | + |
| 70 | + Assert(_mdnblocks(reln, forknum, v) <= ((BlockNumber) RELSEG_SIZE)); |
| 71 | ++ |
| 72 | ++ if (mdextend_hook) |
| 73 | ++ mdextend_hook(reln->smgr_rlocator, forknum, blocknum); |
| 74 | + } |
| 75 | + |
| 76 | + /* |
| 77 | +@@ -622,6 +627,12 @@ mdzeroextend(SMgrRelation reln, ForkNumber forknum, |
| 78 | + |
| 79 | + remblocks -= numblocks; |
| 80 | + curblocknum += numblocks; |
| 81 | ++ |
| 82 | ++ if (mdextend_hook) |
| 83 | ++ { |
| 84 | ++ for (; blocknum < curblocknum; blocknum++) |
| 85 | ++ mdextend_hook(reln->smgr_rlocator, forknum, blocknum); |
| 86 | ++ } |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | +@@ -867,6 +878,9 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, |
| 91 | + |
| 92 | + if (!skipFsync && !SmgrIsTemp(reln)) |
| 93 | + register_dirty_segment(reln, forknum, v); |
| 94 | ++ |
| 95 | ++ if (mdwrite_hook) |
| 96 | ++ mdwrite_hook(reln->smgr_rlocator, forknum, blocknum); |
| 97 | + } |
| 98 | + |
| 99 | + /* |
| 100 | +diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c |
| 101 | +index 04fcb06056d..22bf179f560 100644 |
| 102 | +--- a/src/backend/storage/sync/sync.c |
| 103 | ++++ b/src/backend/storage/sync/sync.c |
| 104 | +@@ -79,6 +79,8 @@ static MemoryContext pendingOpsCxt; /* context for the above */ |
| 105 | + static CycleCtr sync_cycle_ctr = 0; |
| 106 | + static CycleCtr checkpoint_cycle_ctr = 0; |
| 107 | + |
| 108 | ++ProcessSyncRequests_hook_type ProcessSyncRequests_hook = NULL; |
| 109 | ++ |
| 110 | + /* Intervals for calling AbsorbSyncRequests */ |
| 111 | + #define FSYNCS_PER_ABSORB 10 |
| 112 | + #define UNLINKS_PER_ABSORB 10 |
| 113 | +@@ -475,6 +477,9 @@ ProcessSyncRequests(void) |
| 114 | + CheckpointStats.ckpt_longest_sync = longest; |
| 115 | + CheckpointStats.ckpt_agg_sync_time = total_elapsed; |
| 116 | + |
| 117 | ++ if (ProcessSyncRequests_hook) |
| 118 | ++ ProcessSyncRequests_hook(); |
| 119 | ++ |
| 120 | + /* Flag successful completion of ProcessSyncRequests */ |
| 121 | + sync_in_progress = false; |
| 122 | + } |
| 123 | +diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c |
| 124 | +index 19eb67e4854..008a7acc9f0 100644 |
| 125 | +--- a/src/bin/pg_checksums/pg_checksums.c |
| 126 | ++++ b/src/bin/pg_checksums/pg_checksums.c |
| 127 | +@@ -118,6 +118,11 @@ static const struct exclude_list_item skip[] = { |
| 128 | + {"pg_filenode.map", false}, |
| 129 | + {"pg_internal.init", true}, |
| 130 | + {"PG_VERSION", false}, |
| 131 | ++ |
| 132 | ++ {"ptrack.map.mmap", false}, |
| 133 | ++ {"ptrack.map", false}, |
| 134 | ++ {"ptrack.map.tmp", false}, |
| 135 | ++ |
| 136 | + #ifdef EXEC_BACKEND |
| 137 | + {"config_exec_params", true}, |
| 138 | + #endif |
| 139 | +diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c |
| 140 | +index e7ef2b8bd0c..ca7f8cdbc2f 100644 |
| 141 | +--- a/src/bin/pg_resetwal/pg_resetwal.c |
| 142 | ++++ b/src/bin/pg_resetwal/pg_resetwal.c |
| 143 | +@@ -85,6 +85,7 @@ static void RewriteControlFile(void); |
| 144 | + static void FindEndOfXLOG(void); |
| 145 | + static void KillExistingXLOG(void); |
| 146 | + static void KillExistingArchiveStatus(void); |
| 147 | ++static void KillExistingPtrack(void); |
| 148 | + static void WriteEmptyXLOG(void); |
| 149 | + static void usage(void); |
| 150 | + |
| 151 | +@@ -488,6 +489,7 @@ main(int argc, char *argv[]) |
| 152 | + RewriteControlFile(); |
| 153 | + KillExistingXLOG(); |
| 154 | + KillExistingArchiveStatus(); |
| 155 | ++ KillExistingPtrack(); |
| 156 | + WriteEmptyXLOG(); |
| 157 | + |
| 158 | + printf(_("Write-ahead log reset\n")); |
| 159 | +@@ -1029,6 +1031,41 @@ KillExistingArchiveStatus(void) |
| 160 | + pg_fatal("could not close directory \"%s\": %m", ARCHSTATDIR); |
| 161 | + } |
| 162 | + |
| 163 | ++/* |
| 164 | ++ * Remove existing ptrack files |
| 165 | ++ */ |
| 166 | ++static void |
| 167 | ++KillExistingPtrack(void) |
| 168 | ++{ |
| 169 | ++#define PTRACKDIR "global" |
| 170 | ++ |
| 171 | ++ DIR *xldir; |
| 172 | ++ struct dirent *xlde; |
| 173 | ++ char path[MAXPGPATH + sizeof(PTRACKDIR)]; |
| 174 | ++ |
| 175 | ++ xldir = opendir(PTRACKDIR); |
| 176 | ++ if (xldir == NULL) |
| 177 | ++ pg_fatal("could not open directory \"%s\": %m", PTRACKDIR); |
| 178 | ++ |
| 179 | ++ while (errno = 0, (xlde = readdir(xldir)) != NULL) |
| 180 | ++ { |
| 181 | ++ if (strcmp(xlde->d_name, "ptrack.map.mmap") == 0 || |
| 182 | ++ strcmp(xlde->d_name, "ptrack.map") == 0 || |
| 183 | ++ strcmp(xlde->d_name, "ptrack.map.tmp") == 0) |
| 184 | ++ { |
| 185 | ++ snprintf(path, sizeof(path), "%s/%s", PTRACKDIR, xlde->d_name); |
| 186 | ++ if (unlink(path) < 0) |
| 187 | ++ pg_fatal("could not delete file \"%s\": %m", path); |
| 188 | ++ } |
| 189 | ++ } |
| 190 | ++ |
| 191 | ++ if (errno) |
| 192 | ++ pg_fatal("could not read directory \"%s\": %m", PTRACKDIR); |
| 193 | ++ |
| 194 | ++ if (closedir(xldir)) |
| 195 | ++ pg_fatal("could not close directory \"%s\": %m", PTRACKDIR); |
| 196 | ++} |
| 197 | ++ |
| 198 | + |
| 199 | + /* |
| 200 | + * Write an empty XLOG file, containing only the checkpoint record |
| 201 | +diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c |
| 202 | +index bd5c598e200..a568156c5fb 100644 |
| 203 | +--- a/src/bin/pg_rewind/filemap.c |
| 204 | ++++ b/src/bin/pg_rewind/filemap.c |
| 205 | +@@ -157,6 +157,10 @@ static const struct exclude_list_item excludeFiles[] = |
| 206 | + {"postmaster.pid", false}, |
| 207 | + {"postmaster.opts", false}, |
| 208 | + |
| 209 | ++ {"ptrack.map.mmap", false}, |
| 210 | ++ {"ptrack.map", false}, |
| 211 | ++ {"ptrack.map.tmp", false}, |
| 212 | ++ |
| 213 | + /* end of list */ |
| 214 | + {NULL, false} |
| 215 | + }; |
| 216 | +diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h |
| 217 | +index a8be5b21e0b..020874f96cd 100644 |
| 218 | +--- a/src/include/storage/copydir.h |
| 219 | ++++ b/src/include/storage/copydir.h |
| 220 | +@@ -13,6 +13,9 @@ |
| 221 | + #ifndef COPYDIR_H |
| 222 | + #define COPYDIR_H |
| 223 | + |
| 224 | ++typedef void (*copydir_hook_type) (const char *path); |
| 225 | ++extern PGDLLIMPORT copydir_hook_type copydir_hook; |
| 226 | ++ |
| 227 | + extern void copydir(const char *fromdir, const char *todir, bool recurse); |
| 228 | + extern void copy_file(const char *fromfile, const char *tofile); |
| 229 | + |
| 230 | +diff --git a/src/include/storage/md.h b/src/include/storage/md.h |
| 231 | +index 941879ee6a8..24738aeecd0 100644 |
| 232 | +--- a/src/include/storage/md.h |
| 233 | ++++ b/src/include/storage/md.h |
| 234 | +@@ -19,6 +19,13 @@ |
| 235 | + #include "storage/smgr.h" |
| 236 | + #include "storage/sync.h" |
| 237 | + |
| 238 | ++typedef void (*mdextend_hook_type) (RelFileLocatorBackend smgr_rlocator, |
| 239 | ++ ForkNumber forknum, BlockNumber blocknum); |
| 240 | ++extern PGDLLIMPORT mdextend_hook_type mdextend_hook; |
| 241 | ++typedef void (*mdwrite_hook_type) (RelFileLocatorBackend smgr_rlocator, |
| 242 | ++ ForkNumber forknum, BlockNumber blocknum); |
| 243 | ++extern PGDLLIMPORT mdwrite_hook_type mdwrite_hook; |
| 244 | ++ |
| 245 | + /* md storage manager functionality */ |
| 246 | + extern void mdinit(void); |
| 247 | + extern void mdopen(SMgrRelation reln); |
| 248 | +diff --git a/src/include/storage/sync.h b/src/include/storage/sync.h |
| 249 | +index cfbcfa6797d..2a432440db9 100644 |
| 250 | +--- a/src/include/storage/sync.h |
| 251 | ++++ b/src/include/storage/sync.h |
| 252 | +@@ -55,6 +55,9 @@ typedef struct FileTag |
| 253 | + uint32 segno; |
| 254 | + } FileTag; |
| 255 | + |
| 256 | ++typedef void (*ProcessSyncRequests_hook_type) (void); |
| 257 | ++extern PGDLLIMPORT ProcessSyncRequests_hook_type ProcessSyncRequests_hook; |
| 258 | ++ |
| 259 | + extern void InitSync(void); |
| 260 | + extern void SyncPreCheckpoint(void); |
| 261 | + extern void SyncPostCheckpoint(void); |
0 commit comments