-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathmaster-ptrack-core.diff
295 lines (271 loc) · 8.94 KB
/
master-ptrack-core.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
diff --git a/src/backend/backup/basebackup.c b/src/backend/backup/basebackup.c
index 3fb9451643..3d528fd007 100644
--- a/src/backend/backup/basebackup.c
+++ b/src/backend/backup/basebackup.c
@@ -199,6 +199,13 @@ static const struct exclude_list_item excludeFiles[] =
{"postmaster.pid", false},
{"postmaster.opts", false},
+ /*
+ * Skip all transient ptrack files, but do copy ptrack.map, since it may
+ * be successfully used immediately after backup. TODO: check, test?
+ */
+ {"ptrack.map.mmap", false},
+ {"ptrack.map.tmp", false},
+
/* end of list */
{NULL, false}
};
@@ -214,6 +221,11 @@ static const struct exclude_list_item noChecksumFiles[] = {
{"pg_filenode.map", false},
{"pg_internal.init", true},
{"PG_VERSION", false},
+
+ {"ptrack.map.mmap", false},
+ {"ptrack.map", false},
+ {"ptrack.map.tmp", false},
+
#ifdef EXEC_BACKEND
{"config_exec_params", true},
#endif
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
index e04bc3941a..996b5de616 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -27,6 +27,8 @@
#include "storage/copydir.h"
#include "storage/fd.h"
+copydir_hook_type copydir_hook = NULL;
+
/*
* copydir: copy a directory
*
@@ -75,6 +77,9 @@ copydir(const char *fromdir, const char *todir, bool recurse)
}
FreeDir(xldir);
+ if (copydir_hook)
+ copydir_hook(todir);
+
/*
* Be paranoid here and fsync all files to ensure the copy is really done.
* But if fsync is disabled, we're done.
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
index 352958e1fe..9dc6bf29f4 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -87,6 +87,8 @@ typedef struct _MdfdVec
static MemoryContext MdCxt; /* context for all MdfdVec objects */
+mdextend_hook_type mdextend_hook = NULL;
+mdwrite_hook_type mdwrite_hook = NULL;
/* Populate a file tag describing an md.c segment file. */
#define INIT_MD_FILETAG(a,xx_rlocator,xx_forknum,xx_segno) \
@@ -498,6 +500,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
register_dirty_segment(reln, forknum, v);
Assert(_mdnblocks(reln, forknum, v) <= ((BlockNumber) RELSEG_SIZE));
+
+ if (mdextend_hook)
+ mdextend_hook(reln->smgr_rlocator, forknum, blocknum);
}
/*
@@ -787,6 +792,9 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
if (!skipFsync && !SmgrIsTemp(reln))
register_dirty_segment(reln, forknum, v);
+
+ if (mdwrite_hook)
+ mdwrite_hook(reln->smgr_rlocator, forknum, blocknum);
}
/*
diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
index 768d1dbfc4..17cbc6bb2a 100644
--- a/src/backend/storage/sync/sync.c
+++ b/src/backend/storage/sync/sync.c
@@ -81,6 +81,8 @@ static MemoryContext pendingOpsCxt; /* context for the above */
static CycleCtr sync_cycle_ctr = 0;
static CycleCtr checkpoint_cycle_ctr = 0;
+ProcessSyncRequests_hook_type ProcessSyncRequests_hook = NULL;
+
/* Intervals for calling AbsorbSyncRequests */
#define FSYNCS_PER_ABSORB 10
#define UNLINKS_PER_ABSORB 10
@@ -477,6 +479,9 @@ ProcessSyncRequests(void)
CheckpointStats.ckpt_longest_sync = longest;
CheckpointStats.ckpt_agg_sync_time = total_elapsed;
+ if (ProcessSyncRequests_hook)
+ ProcessSyncRequests_hook();
+
/* Flag successful completion of ProcessSyncRequests */
sync_in_progress = false;
}
diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
index aa21007497..96fe58ee3e 100644
--- a/src/bin/pg_checksums/pg_checksums.c
+++ b/src/bin/pg_checksums/pg_checksums.c
@@ -118,6 +118,11 @@ static const struct exclude_list_item skip[] = {
{"pg_filenode.map", false},
{"pg_internal.init", true},
{"PG_VERSION", false},
+
+ {"ptrack.map.mmap", false},
+ {"ptrack.map", false},
+ {"ptrack.map.tmp", false},
+
#ifdef EXEC_BACKEND
{"config_exec_params", true},
#endif
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index e7ef2b8bd0..ca7f8cdbc2 100644
--- a/src/bin/pg_resetwal/pg_resetwal.c
+++ b/src/bin/pg_resetwal/pg_resetwal.c
@@ -85,6 +85,7 @@ static void RewriteControlFile(void);
static void FindEndOfXLOG(void);
static void KillExistingXLOG(void);
static void KillExistingArchiveStatus(void);
+static void KillExistingPtrack(void);
static void WriteEmptyXLOG(void);
static void usage(void);
@@ -488,6 +489,7 @@ main(int argc, char *argv[])
RewriteControlFile();
KillExistingXLOG();
KillExistingArchiveStatus();
+ KillExistingPtrack();
WriteEmptyXLOG();
printf(_("Write-ahead log reset\n"));
@@ -1029,6 +1031,41 @@ KillExistingArchiveStatus(void)
pg_fatal("could not close directory \"%s\": %m", ARCHSTATDIR);
}
+/*
+ * Remove existing ptrack files
+ */
+static void
+KillExistingPtrack(void)
+{
+#define PTRACKDIR "global"
+
+ DIR *xldir;
+ struct dirent *xlde;
+ char path[MAXPGPATH + sizeof(PTRACKDIR)];
+
+ xldir = opendir(PTRACKDIR);
+ if (xldir == NULL)
+ pg_fatal("could not open directory \"%s\": %m", PTRACKDIR);
+
+ while (errno = 0, (xlde = readdir(xldir)) != NULL)
+ {
+ if (strcmp(xlde->d_name, "ptrack.map.mmap") == 0 ||
+ strcmp(xlde->d_name, "ptrack.map") == 0 ||
+ strcmp(xlde->d_name, "ptrack.map.tmp") == 0)
+ {
+ snprintf(path, sizeof(path), "%s/%s", PTRACKDIR, xlde->d_name);
+ if (unlink(path) < 0)
+ pg_fatal("could not delete file \"%s\": %m", path);
+ }
+ }
+
+ if (errno)
+ pg_fatal("could not read directory \"%s\": %m", PTRACKDIR);
+
+ if (closedir(xldir))
+ pg_fatal("could not close directory \"%s\": %m", PTRACKDIR);
+}
+
/*
* Write an empty XLOG file, containing only the checkpoint record
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
index bd5c598e20..a568156c5f 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -157,6 +157,10 @@ static const struct exclude_list_item excludeFiles[] =
{"postmaster.pid", false},
{"postmaster.opts", false},
+ {"ptrack.map.mmap", false},
+ {"ptrack.map", false},
+ {"ptrack.map.tmp", false},
+
/* end of list */
{NULL, false}
};
diff --git a/src/include/storage/checksum.h b/src/include/storage/checksum.h
index 4afd25a0af..c2afee20b5 100644
--- a/src/include/storage/checksum.h
+++ b/src/include/storage/checksum.h
@@ -14,6 +14,7 @@
#define CHECKSUM_H
#include "storage/block.h"
+#include "port/pg_crc32c.h"
/*
* Compute the checksum for a Postgres page. The page must be aligned on a
@@ -21,4 +22,18 @@
*/
extern uint16 pg_checksum_page(char *page, BlockNumber blkno);
+#ifdef WIN32
+/*
+ * Wrapper function for COMP_CRC32C macro. Was added to avoid
+ * FRONTEND macro use for pg_comp_crc32c pointer in windows build.
+ */
+extern void
+comp_crc32c(pg_crc32c *crc, const void *data, size_t len);
+
+#define COMP_CRC32C_COMMON(crc, data, len) \
+ comp_crc32c(&(crc), data, len)
+#else
+#define COMP_CRC32C_COMMON COMP_CRC32C
+#endif /* WIN32 */
+
#endif /* CHECKSUM_H */
diff --git a/src/include/storage/checksum_impl.h b/src/include/storage/checksum_impl.h
index 7b157161a2..a69425f6cc 100644
--- a/src/include/storage/checksum_impl.h
+++ b/src/include/storage/checksum_impl.h
@@ -213,3 +213,11 @@ pg_checksum_page(char *page, BlockNumber blkno)
*/
return (uint16) ((checksum % 65535) + 1);
}
+
+#ifdef WIN32
+void
+comp_crc32c(pg_crc32c *crc, const void *data, size_t len)
+{
+ COMP_CRC32C(*crc, data, len);
+}
+#endif
diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h
index a8be5b21e0..020874f96c 100644
--- a/src/include/storage/copydir.h
+++ b/src/include/storage/copydir.h
@@ -13,6 +13,9 @@
#ifndef COPYDIR_H
#define COPYDIR_H
+typedef void (*copydir_hook_type) (const char *path);
+extern PGDLLIMPORT copydir_hook_type copydir_hook;
+
extern void copydir(const char *fromdir, const char *todir, bool recurse);
extern void copy_file(const char *fromfile, const char *tofile);
diff --git a/src/include/storage/md.h b/src/include/storage/md.h
index 8f32af9ef3..f8b427ceca 100644
--- a/src/include/storage/md.h
+++ b/src/include/storage/md.h
@@ -19,6 +19,13 @@
#include "storage/smgr.h"
#include "storage/sync.h"
+typedef void (*mdextend_hook_type) (RelFileLocatorBackend smgr_rlocator,
+ ForkNumber forknum, BlockNumber blocknum);
+extern PGDLLIMPORT mdextend_hook_type mdextend_hook;
+typedef void (*mdwrite_hook_type) (RelFileLocatorBackend smgr_rlocator,
+ ForkNumber forknum, BlockNumber blocknum);
+extern PGDLLIMPORT mdwrite_hook_type mdwrite_hook;
+
/* md storage manager functionality */
extern void mdinit(void);
extern void mdopen(SMgrRelation reln);
diff --git a/src/include/storage/sync.h b/src/include/storage/sync.h
index cfbcfa6797..2a432440db 100644
--- a/src/include/storage/sync.h
+++ b/src/include/storage/sync.h
@@ -55,6 +55,9 @@ typedef struct FileTag
uint32 segno;
} FileTag;
+typedef void (*ProcessSyncRequests_hook_type) (void);
+extern PGDLLIMPORT ProcessSyncRequests_hook_type ProcessSyncRequests_hook;
+
extern void InitSync(void);
extern void SyncPreCheckpoint(void);
extern void SyncPostCheckpoint(void);