|
| 1 | +diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c |
| 2 | +index 3e53b3df6fb..f76bfc2a646 100644 |
| 3 | +--- a/src/backend/replication/basebackup.c |
| 4 | ++++ b/src/backend/replication/basebackup.c |
| 5 | +@@ -209,6 +209,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 | +@@ -224,6 +231,10 @@ static const struct exclude_list_item noChecksumFiles[] = { |
| 20 | + {"pg_filenode.map", false}, |
| 21 | + {"pg_internal.init", true}, |
| 22 | + {"PG_VERSION", false}, |
| 23 | ++ {"ptrack.map.mmap", false}, |
| 24 | ++ {"ptrack.map", false}, |
| 25 | ++ {"ptrack.map.tmp", false}, |
| 26 | ++ |
| 27 | + #ifdef EXEC_BACKEND |
| 28 | + {"config_exec_params", true}, |
| 29 | + #endif |
| 30 | +diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c |
| 31 | +index 4a0d23b11e3..d59009a4c8c 100644 |
| 32 | +--- a/src/backend/storage/file/copydir.c |
| 33 | ++++ b/src/backend/storage/file/copydir.c |
| 34 | +@@ -27,6 +27,8 @@ |
| 35 | + #include "miscadmin.h" |
| 36 | + #include "pgstat.h" |
| 37 | + |
| 38 | ++copydir_hook_type copydir_hook = NULL; |
| 39 | ++ |
| 40 | + /* |
| 41 | + * copydir: copy a directory |
| 42 | + * |
| 43 | +@@ -78,6 +80,9 @@ copydir(char *fromdir, char *todir, bool recurse) |
| 44 | + } |
| 45 | + FreeDir(xldir); |
| 46 | + |
| 47 | ++ if (copydir_hook) |
| 48 | ++ copydir_hook(todir); |
| 49 | ++ |
| 50 | + /* |
| 51 | + * Be paranoid here and fsync all files to ensure the copy is really done. |
| 52 | + * But if fsync is disabled, we're done. |
| 53 | +diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c |
| 54 | +index 200cc7f657a..d0dcb5c0287 100644 |
| 55 | +--- a/src/backend/storage/smgr/md.c |
| 56 | ++++ b/src/backend/storage/smgr/md.c |
| 57 | +@@ -39,6 +39,7 @@ |
| 58 | + #include "utils/memutils.h" |
| 59 | + #include "pg_trace.h" |
| 60 | + |
| 61 | ++ProcessSyncRequests_hook_type ProcessSyncRequests_hook = NULL; |
| 62 | + |
| 63 | + /* intervals for calling AbsorbFsyncRequests in mdsync and mdpostckpt */ |
| 64 | + #define FSYNCS_PER_ABSORB 10 |
| 65 | +@@ -114,6 +115,8 @@ typedef struct _MdfdVec |
| 66 | + |
| 67 | + static MemoryContext MdCxt; /* context for all MdfdVec objects */ |
| 68 | + |
| 69 | ++mdextend_hook_type mdextend_hook = NULL; |
| 70 | ++mdwrite_hook_type mdwrite_hook = NULL; |
| 71 | + |
| 72 | + /* |
| 73 | + * In some contexts (currently, standalone backends and the checkpointer) |
| 74 | +@@ -558,6 +561,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, |
| 75 | + register_dirty_segment(reln, forknum, v); |
| 76 | + |
| 77 | + Assert(_mdnblocks(reln, forknum, v) <= ((BlockNumber) RELSEG_SIZE)); |
| 78 | ++ |
| 79 | ++ if (mdextend_hook) |
| 80 | ++ mdextend_hook(reln->smgr_rnode, forknum, blocknum); |
| 81 | + } |
| 82 | + |
| 83 | + /* |
| 84 | +@@ -851,6 +857,9 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, |
| 85 | + |
| 86 | + if (!skipFsync && !SmgrIsTemp(reln)) |
| 87 | + register_dirty_segment(reln, forknum, v); |
| 88 | ++ |
| 89 | ++ if (mdwrite_hook) |
| 90 | ++ mdwrite_hook(reln->smgr_rnode, forknum, blocknum); |
| 91 | + } |
| 92 | + |
| 93 | + /* |
| 94 | +@@ -1329,6 +1338,9 @@ mdsync(void) |
| 95 | + CheckpointStats.ckpt_longest_sync = longest; |
| 96 | + CheckpointStats.ckpt_agg_sync_time = total_elapsed; |
| 97 | + |
| 98 | ++ if (ProcessSyncRequests_hook) |
| 99 | ++ ProcessSyncRequests_hook(); |
| 100 | ++ |
| 101 | + /* Flag successful completion of mdsync */ |
| 102 | + mdsync_in_progress = false; |
| 103 | + } |
| 104 | +diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c |
| 105 | +index 6fb403a5a8a..6e31ccb3e0f 100644 |
| 106 | +--- a/src/bin/pg_resetwal/pg_resetwal.c |
| 107 | ++++ b/src/bin/pg_resetwal/pg_resetwal.c |
| 108 | +@@ -84,6 +84,7 @@ static void RewriteControlFile(void); |
| 109 | + static void FindEndOfXLOG(void); |
| 110 | + static void KillExistingXLOG(void); |
| 111 | + static void KillExistingArchiveStatus(void); |
| 112 | ++static void KillExistingPtrack(void); |
| 113 | + static void WriteEmptyXLOG(void); |
| 114 | + static void usage(void); |
| 115 | + |
| 116 | +@@ -516,6 +517,7 @@ main(int argc, char *argv[]) |
| 117 | + RewriteControlFile(); |
| 118 | + KillExistingXLOG(); |
| 119 | + KillExistingArchiveStatus(); |
| 120 | ++ KillExistingPtrack(); |
| 121 | + WriteEmptyXLOG(); |
| 122 | + |
| 123 | + printf(_("Write-ahead log reset\n")); |
| 124 | +@@ -1201,6 +1203,57 @@ KillExistingArchiveStatus(void) |
| 125 | + } |
| 126 | + } |
| 127 | + |
| 128 | ++/* |
| 129 | ++ * Remove existing ptrack files |
| 130 | ++ */ |
| 131 | ++static void |
| 132 | ++KillExistingPtrack(void) |
| 133 | ++{ |
| 134 | ++#define PTRACKDIR "global" |
| 135 | ++ |
| 136 | ++ DIR *xldir; |
| 137 | ++ struct dirent *xlde; |
| 138 | ++ char path[MAXPGPATH + sizeof(PTRACKDIR)]; |
| 139 | ++ |
| 140 | ++ xldir = opendir(PTRACKDIR); |
| 141 | ++ if (xldir == NULL) |
| 142 | ++ { |
| 143 | ++ fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"), |
| 144 | ++ progname, PTRACKDIR, strerror(errno)); |
| 145 | ++ exit(1); |
| 146 | ++ } |
| 147 | ++ |
| 148 | ++ while (errno = 0, (xlde = readdir(xldir)) != NULL) |
| 149 | ++ { |
| 150 | ++ if (strcmp(xlde->d_name, "ptrack.map.mmap") == 0 || |
| 151 | ++ strcmp(xlde->d_name, "ptrack.map") == 0 || |
| 152 | ++ strcmp(xlde->d_name, "ptrack.map.tmp") == 0) |
| 153 | ++ { |
| 154 | ++ snprintf(path, sizeof(path), "%s/%s", PTRACKDIR, xlde->d_name); |
| 155 | ++ if (unlink(path) < 0) |
| 156 | ++ { |
| 157 | ++ fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"), |
| 158 | ++ progname, path, strerror(errno)); |
| 159 | ++ exit(1); |
| 160 | ++ } |
| 161 | ++ } |
| 162 | ++ } |
| 163 | ++ |
| 164 | ++ if (errno) |
| 165 | ++ { |
| 166 | ++ fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"), |
| 167 | ++ progname, PTRACKDIR, strerror(errno)); |
| 168 | ++ exit(1); |
| 169 | ++ } |
| 170 | ++ |
| 171 | ++ if (closedir(xldir)) |
| 172 | ++ { |
| 173 | ++ fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"), |
| 174 | ++ progname, PTRACKDIR, strerror(errno)); |
| 175 | ++ exit(1); |
| 176 | ++ } |
| 177 | ++} |
| 178 | ++ |
| 179 | + |
| 180 | + /* |
| 181 | + * Write an empty XLOG file, containing only the checkpoint record |
| 182 | +diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c |
| 183 | +index 197163d5544..fc846e78175 100644 |
| 184 | +--- a/src/bin/pg_rewind/filemap.c |
| 185 | ++++ b/src/bin/pg_rewind/filemap.c |
| 186 | +@@ -118,6 +118,10 @@ static const struct exclude_list_item excludeFiles[] = |
| 187 | + {"postmaster.pid", false}, |
| 188 | + {"postmaster.opts", false}, |
| 189 | + |
| 190 | ++ {"ptrack.map.mmap", false}, |
| 191 | ++ {"ptrack.map", false}, |
| 192 | ++ {"ptrack.map.tmp", false}, |
| 193 | ++ |
| 194 | + /* end of list */ |
| 195 | + {NULL, false} |
| 196 | + }; |
| 197 | +diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h |
| 198 | +index 80241455357..50dca7bf6f4 100644 |
| 199 | +--- a/src/include/miscadmin.h |
| 200 | ++++ b/src/include/miscadmin.h |
| 201 | +@@ -367,7 +367,7 @@ typedef enum ProcessingMode |
| 202 | + NormalProcessing /* normal processing */ |
| 203 | + } ProcessingMode; |
| 204 | + |
| 205 | +-extern ProcessingMode Mode; |
| 206 | ++extern PGDLLIMPORT ProcessingMode Mode; |
| 207 | + |
| 208 | + #define IsBootstrapProcessingMode() (Mode == BootstrapProcessing) |
| 209 | + #define IsInitProcessingMode() (Mode == InitProcessing) |
| 210 | +diff --git a/src/include/port/pg_crc32c.h b/src/include/port/pg_crc32c.h |
| 211 | +index 9a26295c8e8..dc72b27a10d 100644 |
| 212 | +--- a/src/include/port/pg_crc32c.h |
| 213 | ++++ b/src/include/port/pg_crc32c.h |
| 214 | +@@ -69,8 +69,11 @@ extern pg_crc32c pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t le |
| 215 | + #define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) |
| 216 | + |
| 217 | + extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void *data, size_t len); |
| 218 | +-extern pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len); |
| 219 | +- |
| 220 | ++extern |
| 221 | ++#ifndef FRONTEND |
| 222 | ++PGDLLIMPORT |
| 223 | ++#endif |
| 224 | ++pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len); |
| 225 | + #ifdef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK |
| 226 | + extern pg_crc32c pg_comp_crc32c_sse42(pg_crc32c crc, const void *data, size_t len); |
| 227 | + #endif |
| 228 | +diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h |
| 229 | +index 4fef3e21072..e55430879c3 100644 |
| 230 | +--- a/src/include/storage/copydir.h |
| 231 | ++++ b/src/include/storage/copydir.h |
| 232 | +@@ -13,6 +13,9 @@ |
| 233 | + #ifndef COPYDIR_H |
| 234 | + #define COPYDIR_H |
| 235 | + |
| 236 | ++typedef void (*copydir_hook_type) (const char *path); |
| 237 | ++extern PGDLLIMPORT copydir_hook_type copydir_hook; |
| 238 | ++ |
| 239 | + extern void copydir(char *fromdir, char *todir, bool recurse); |
| 240 | + extern void copy_file(char *fromfile, char *tofile); |
| 241 | + |
| 242 | +diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h |
| 243 | +index 0298ed1a2bc..24c684771d0 100644 |
| 244 | +--- a/src/include/storage/smgr.h |
| 245 | ++++ b/src/include/storage/smgr.h |
| 246 | +@@ -116,6 +116,17 @@ extern void AtEOXact_SMgr(void); |
| 247 | + /* internals: move me elsewhere -- ay 7/94 */ |
| 248 | + |
| 249 | + /* in md.c */ |
| 250 | ++ |
| 251 | ++typedef void (*mdextend_hook_type) (RelFileNodeBackend smgr_rnode, |
| 252 | ++ ForkNumber forknum, BlockNumber blocknum); |
| 253 | ++extern PGDLLIMPORT mdextend_hook_type mdextend_hook; |
| 254 | ++typedef void (*mdwrite_hook_type) (RelFileNodeBackend smgr_rnode, |
| 255 | ++ ForkNumber forknum, BlockNumber blocknum); |
| 256 | ++extern PGDLLIMPORT mdwrite_hook_type mdwrite_hook; |
| 257 | ++ |
| 258 | ++typedef void (*ProcessSyncRequests_hook_type) (void); |
| 259 | ++extern PGDLLIMPORT ProcessSyncRequests_hook_type ProcessSyncRequests_hook; |
| 260 | ++ |
| 261 | + extern void mdinit(void); |
| 262 | + extern void mdclose(SMgrRelation reln, ForkNumber forknum); |
| 263 | + extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo); |
0 commit comments