-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathREL_11_STABLE-ptrack-core.diff
More file actions
355 lines (328 loc) · 10.5 KB
/
REL_11_STABLE-ptrack-core.diff
File metadata and controls
355 lines (328 loc) · 10.5 KB
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
index ba4b47443f..62baf8ab4f 100644
--- a/src/backend/replication/basebackup.c
+++ b/src/backend/replication/basebackup.c
@@ -209,6 +209,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}
};
@@ -224,6 +231,10 @@ 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 4a0d23b11e..d59009a4c8 100644
--- a/src/backend/storage/file/copydir.c
+++ b/src/backend/storage/file/copydir.c
@@ -27,6 +27,8 @@
#include "miscadmin.h"
#include "pgstat.h"
+copydir_hook_type copydir_hook = NULL;
+
/*
* copydir: copy a directory
*
@@ -78,6 +80,9 @@ copydir(char *fromdir, 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 5418452261..3332a3c717 100644
--- a/src/backend/storage/smgr/md.c
+++ b/src/backend/storage/smgr/md.c
@@ -39,6 +39,7 @@
#include "utils/memutils.h"
#include "pg_trace.h"
+ProcessSyncRequests_hook_type ProcessSyncRequests_hook = NULL;
/* intervals for calling AbsorbFsyncRequests in mdsync and mdpostckpt */
#define FSYNCS_PER_ABSORB 10
@@ -114,6 +115,8 @@ typedef struct _MdfdVec
static MemoryContext MdCxt; /* context for all MdfdVec objects */
+mdextend_hook_type mdextend_hook = NULL;
+mdwrite_hook_type mdwrite_hook = NULL;
/*
* In some contexts (currently, standalone backends and the checkpointer)
@@ -603,6 +606,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_rnode, forknum, blocknum);
}
/*
@@ -896,6 +902,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_rnode, forknum, blocknum);
}
/*
@@ -1374,6 +1383,9 @@ mdsync(void)
CheckpointStats.ckpt_longest_sync = longest;
CheckpointStats.ckpt_agg_sync_time = total_elapsed;
+ if (ProcessSyncRequests_hook)
+ ProcessSyncRequests_hook();
+
/* Flag successful completion of mdsync */
mdsync_in_progress = false;
}
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index c7f3ee733d..837ee73217 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -74,6 +74,11 @@ static Latch LocalLatchData;
bool IgnoreSystemIndexes = false;
+/* ----------------------------------------------------------------
+ * Ptrack functions support
+ * ----------------------------------------------------------------
+ */
+static void check_use_ptrack(const char *libraries);
/* ----------------------------------------------------------------
* database path / name support stuff
@@ -1601,6 +1606,8 @@ process_shared_preload_libraries(void)
"shared_preload_libraries",
false);
process_shared_preload_libraries_in_progress = false;
+
+ check_use_ptrack(shared_preload_libraries_string);
}
/*
@@ -1631,3 +1638,71 @@ pg_bindtextdomain(const char *domain)
}
#endif
}
+
+/*-------------------------------------------------------------------------
+ * Ptrack functions support
+ *-------------------------------------------------------------------------
+ */
+
+/* Persistent copy of ptrack.map to restore after crash */
+#define PTRACK_PATH "global/ptrack.map"
+/* Used for atomical crash-safe update of ptrack.map */
+#define PTRACK_PATH_TMP "global/ptrack.map.tmp"
+
+/*
+ * Check that path is accessible by us and return true if it is
+ * not a directory.
+ */
+static bool
+ptrack_file_exists(const char *path)
+{
+ struct stat st;
+
+ Assert(path != NULL);
+
+ if (stat(path, &st) == 0)
+ return S_ISDIR(st.st_mode) ? false : true;
+ else if (!(errno == ENOENT || errno == ENOTDIR || errno == EACCES))
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not access file \"%s\": %m", path)));
+
+ return false;
+}
+
+/*
+ * Delete ptrack files when ptrack is disabled.
+ *
+ * This is performed by postmaster at start,
+ * so that there are no concurrent delete issues.
+ */
+static void
+ptrackCleanFiles(void)
+{
+ char ptrack_path[MAXPGPATH];
+ char ptrack_path_tmp[MAXPGPATH];
+
+ sprintf(ptrack_path, "%s/%s", DataDir, PTRACK_PATH);
+ sprintf(ptrack_path_tmp, "%s/%s", DataDir, PTRACK_PATH_TMP);
+
+ elog(DEBUG1, "ptrack: clean map files");
+
+ if (ptrack_file_exists(ptrack_path_tmp))
+ durable_unlink(ptrack_path_tmp, LOG);
+
+ if (ptrack_file_exists(ptrack_path))
+ durable_unlink(ptrack_path, LOG);
+}
+
+static void
+check_use_ptrack(const char *libraries)
+{
+ /* We need to delete the ptrack.map file when ptrack was turned off */
+ if (strstr(shared_preload_libraries_string, "ptrack") == NULL)
+ {
+ ptrackCleanFiles();
+ }
+}
+
+#undef PTRACK_PATH
+#undef PTRACK_PATH_TMP
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
index 611edf6ade..ec1c1212bd 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);
@@ -525,6 +526,7 @@ main(int argc, char *argv[])
RewriteControlFile();
KillExistingXLOG();
KillExistingArchiveStatus();
+ KillExistingPtrack();
WriteEmptyXLOG();
printf(_("Write-ahead log reset\n"));
@@ -1210,6 +1212,57 @@ KillExistingArchiveStatus(void)
}
}
+/*
+ * 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)
+ {
+ fprintf(stderr, _("%s: could not open directory \"%s\": %s\n"),
+ progname, PTRACKDIR, strerror(errno));
+ exit(1);
+ }
+
+ 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)
+ {
+ fprintf(stderr, _("%s: could not delete file \"%s\": %s\n"),
+ progname, path, strerror(errno));
+ exit(1);
+ }
+ }
+ }
+
+ if (errno)
+ {
+ fprintf(stderr, _("%s: could not read directory \"%s\": %s\n"),
+ progname, PTRACKDIR, strerror(errno));
+ exit(1);
+ }
+
+ if (closedir(xldir))
+ {
+ fprintf(stderr, _("%s: could not close directory \"%s\": %s\n"),
+ progname, PTRACKDIR, strerror(errno));
+ exit(1);
+ }
+}
+
/*
* 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 8ea7fafa27..997168fcac 100644
--- a/src/bin/pg_rewind/filemap.c
+++ b/src/bin/pg_rewind/filemap.c
@@ -118,6 +118,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/miscadmin.h b/src/include/miscadmin.h
index 7c9f319b67..1e29827030 100644
--- a/src/include/miscadmin.h
+++ b/src/include/miscadmin.h
@@ -379,7 +379,7 @@ typedef enum ProcessingMode
NormalProcessing /* normal processing */
} ProcessingMode;
-extern ProcessingMode Mode;
+extern PGDLLIMPORT ProcessingMode Mode;
#define IsBootstrapProcessingMode() (Mode == BootstrapProcessing)
#define IsInitProcessingMode() (Mode == InitProcessing)
diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h
index 4fef3e2107..e55430879c 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(char *fromdir, char *todir, bool recurse);
extern void copy_file(char *fromfile, char *tofile);
diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h
index 0298ed1a2b..24c684771d 100644
--- a/src/include/storage/smgr.h
+++ b/src/include/storage/smgr.h
@@ -116,6 +116,17 @@ extern void AtEOXact_SMgr(void);
/* internals: move me elsewhere -- ay 7/94 */
/* in md.c */
+
+typedef void (*mdextend_hook_type) (RelFileNodeBackend smgr_rnode,
+ ForkNumber forknum, BlockNumber blocknum);
+extern PGDLLIMPORT mdextend_hook_type mdextend_hook;
+typedef void (*mdwrite_hook_type) (RelFileNodeBackend smgr_rnode,
+ ForkNumber forknum, BlockNumber blocknum);
+extern PGDLLIMPORT mdwrite_hook_type mdwrite_hook;
+
+typedef void (*ProcessSyncRequests_hook_type) (void);
+extern PGDLLIMPORT ProcessSyncRequests_hook_type ProcessSyncRequests_hook;
+
extern void mdinit(void);
extern void mdclose(SMgrRelation reln, ForkNumber forknum);
extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
index b52baa9098..74870c048d 100644
--- a/src/tools/msvc/Mkvcbuild.pm
+++ b/src/tools/msvc/Mkvcbuild.pm
@@ -33,7 +33,7 @@ my @unlink_on_exit;
# Set of variables for modules in contrib/ and src/test/modules/
my $contrib_defines = { 'refint' => 'REFINT_VERBOSE' };
my @contrib_uselibpq = ('dblink', 'oid2name', 'postgres_fdw', 'vacuumlo');
-my @contrib_uselibpgport = ('oid2name', 'pg_standby', 'vacuumlo');
+my @contrib_uselibpgport = ('oid2name', 'pg_standby', 'vacuumlo', 'ptrack');
my @contrib_uselibpgcommon = ('oid2name', 'pg_standby', 'vacuumlo');
my $contrib_extralibs = undef;
my $contrib_extraincludes = { 'dblink' => ['src/backend'] };