1- commit a14ac459d71528c64df00c693e9c71ac70d3ba29
2- Author: anastasia <a.lubennikova@postgrespro.ru>
3- Date: Mon Oct 19 14:53:06 2020 +0300
4-
5- add ptrack 2.0
6-
71diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
8- index50ae1f16d0..721b926ad2 100644
2+ index5244823ff85..160889b4a04 100644
93--- a/src/backend/replication/basebackup.c
104+++ b/src/backend/replication/basebackup.c
11- @@ -233 ,6 +233 ,13 @@ static const struct exclude_list_item excludeFiles[] =
5+ @@ -197 ,6 +197 ,13 @@ static const struct exclude_list_item excludeFiles[] =
126 {"postmaster.pid", false},
137 {"postmaster.opts", false},
148
@@ -22,7 +16,7 @@ index 50ae1f16d0..721b926ad2 100644
2216 /* end of list */
2317 {NULL, false}
2418 };
25- @@ -248 ,6 +255 ,11 @@ static const struct exclude_list_item noChecksumFiles[] = {
19+ @@ -212 ,6 +219 ,11 @@ static const struct exclude_list_item noChecksumFiles[] = {
2620 {"pg_filenode.map", false},
2721 {"pg_internal.init", true},
2822 {"PG_VERSION", false},
@@ -35,7 +29,7 @@ index 50ae1f16d0..721b926ad2 100644
3529 {"config_exec_params", true},
3630 #endif
3731diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
38- index0cf598dd0c..c9c44a4ae7 100644
32+ index658fd95ba95..eee38eba176 100644
3933--- a/src/backend/storage/file/copydir.c
4034+++ b/src/backend/storage/file/copydir.c
4135@@ -27,6 +27,8 @@
@@ -58,7 +52,7 @@ index 0cf598dd0c..c9c44a4ae7 100644
5852 * Be paranoid here and fsync all files to ensure the copy is really done.
5953 * But if fsync is disabled, we're done.
6054diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
61- index0eacd461cd..c2ef404a1a 100644
55+ index43edaf5d873..bbaf7500944 100644
6256--- a/src/backend/storage/smgr/md.c
6357+++ b/src/backend/storage/smgr/md.c
6458@@ -87,6 +87,8 @@ typedef struct _MdfdVec
@@ -70,7 +64,7 @@ index 0eacd461cd..c2ef404a1a 100644
7064
7165 /* Populate a file tag describing an md.c segment file. */
7266 #define INIT_MD_FILETAG(a,xx_rnode,xx_forknum,xx_segno) \
73- @@ -435 ,6 +437 ,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
67+ @@ -467 ,6 +469 ,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
7468 register_dirty_segment(reln, forknum, v);
7569
7670 Assert(_mdnblocks(reln, forknum, v) <= ((BlockNumber) RELSEG_SIZE));
@@ -80,7 +74,7 @@ index 0eacd461cd..c2ef404a1a 100644
8074 }
8175
8276 /*
83- @@ -721 ,6 +726 ,9 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
77+ @@ -756 ,6 +761 ,9 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
8478
8579 if (!skipFsync && !SmgrIsTemp(reln))
8680 register_dirty_segment(reln, forknum, v);
@@ -91,10 +85,10 @@ index 0eacd461cd..c2ef404a1a 100644
9185
9286 /*
9387diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c
94- index3ded2cdd71..3a596a59f7 100644
88+ indexe1fb6310038..76d75680b31 100644
9589--- a/src/backend/storage/sync/sync.c
9690+++ b/src/backend/storage/sync/sync.c
97- @@ -75 ,6 +75 ,8 @@ static MemoryContext pendingOpsCxt; /* context for the above */
91+ @@ -81 ,6 +81 ,8 @@ static MemoryContext pendingOpsCxt; /* context for the above */
9892 static CycleCtr sync_cycle_ctr = 0;
9993 static CycleCtr checkpoint_cycle_ctr = 0;
10094
@@ -103,7 +97,7 @@ index 3ded2cdd71..3a596a59f7 100644
10397 /* Intervals for calling AbsorbSyncRequests */
10498 #define FSYNCS_PER_ABSORB10
10599 #define UNLINKS_PER_ABSORB10
106- @@ -420 ,6 +422 ,9 @@ ProcessSyncRequests(void)
100+ @@ -477 ,6 +479 ,9 @@ ProcessSyncRequests(void)
107101 CheckpointStats.ckpt_longest_sync = longest;
108102 CheckpointStats.ckpt_agg_sync_time = total_elapsed;
109103
@@ -113,23 +107,11 @@ index 3ded2cdd71..3a596a59f7 100644
113107 /* Flag successful completion of ProcessSyncRequests */
114108 sync_in_progress = false;
115109 }
116- diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c
117- index 1683629ee3..d2fc154576 100644
118- --- a/src/backend/utils/misc/guc.c
119- +++ b/src/backend/utils/misc/guc.c
120- @@ -620,7 +620,6 @@ static char *recovery_target_xid_string;
121- static char *recovery_target_name_string;
122- static char *recovery_target_lsn_string;
123-
124- -
125- /* should be static, but commands/variable.c needs to get at this */
126- char *role_string;
127-
128110diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c
129- indexffdc23945c..7ae95866ce 100644
111+ index21dfe1b6ee5..266ac1ef40a 100644
130112--- a/src/bin/pg_checksums/pg_checksums.c
131113+++ b/src/bin/pg_checksums/pg_checksums.c
132- @@ -114 ,6 +114 ,11 @@ static const struct exclude_list_item skip[] = {
114+ @@ -118 ,6 +118 ,11 @@ static const struct exclude_list_item skip[] = {
133115 {"pg_filenode.map", false},
134116 {"pg_internal.init", true},
135117 {"PG_VERSION", false},
@@ -142,27 +124,27 @@ index ffdc23945c..7ae95866ce 100644
142124 {"config_exec_params", true},
143125 #endif
144126diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
145- index233441837f..cf7bd073bf 100644
127+ indexd4772a29650..3318f64359d 100644
146128--- a/src/bin/pg_resetwal/pg_resetwal.c
147129+++ b/src/bin/pg_resetwal/pg_resetwal.c
148- @@ -84 ,6 +84 ,7 @@ static void RewriteControlFile(void);
130+ @@ -85 ,6 +85 ,7 @@ static void RewriteControlFile(void);
149131 static void FindEndOfXLOG(void);
150132 static void KillExistingXLOG(void);
151133 static void KillExistingArchiveStatus(void);
152134+ static void KillExistingPtrack(void);
153135 static void WriteEmptyXLOG(void);
154136 static void usage(void);
155137
156- @@ -513 ,6 +514 ,7 @@ main(int argc, char *argv[])
138+ @@ -488 ,6 +489 ,7 @@ main(int argc, char *argv[])
157139 RewriteControlFile();
158140 KillExistingXLOG();
159141 KillExistingArchiveStatus();
160142+ KillExistingPtrack();
161143 WriteEmptyXLOG();
162144
163145 printf(_("Write-ahead log reset\n"));
164- @@ -1102 ,6 +1104,53 @@ KillExistingArchiveStatus(void)
165- }
146+ @@ -1036 ,6 +1038,41 @@ KillExistingArchiveStatus(void)
147+ pg_fatal("could not close directory \"%s\": %m", ARCHSTATDIR);
166148 }
167149
168150+ /*
@@ -173,16 +155,13 @@ index 233441837f..cf7bd073bf 100644
173155+ {
174156+ #define PTRACKDIR "global"
175157+
176- + DIR *xldir;
158+ + DIR *xldir;
177159+ struct dirent *xlde;
178- + char path[MAXPGPATH + sizeof(PTRACKDIR)];
160+ + char path[MAXPGPATH + sizeof(PTRACKDIR)];
179161+
180162+ xldir = opendir(PTRACKDIR);
181163+ if (xldir == NULL)
182- + {
183- + pg_log_error("could not open directory \"%s\": %m", PTRACKDIR);
184- + exit(1);
185- + }
164+ + pg_fatal("could not open directory \"%s\": %m", PTRACKDIR);
186165+
187166+ while (errno = 0, (xlde = readdir(xldir)) != NULL)
188167+ {
@@ -192,34 +171,25 @@ index 233441837f..cf7bd073bf 100644
192171+ {
193172+ snprintf(path, sizeof(path), "%s/%s", PTRACKDIR, xlde->d_name);
194173+ if (unlink(path) < 0)
195- + {
196- + pg_log_error("could not delete file \"%s\": %m", path);
197- + exit(1);
198- + }
174+ + pg_fatal("could not delete file \"%s\": %m", path);
199175+ }
200176+ }
201177+
202178+ if (errno)
203- + {
204- + pg_log_error("could not read directory \"%s\": %m", PTRACKDIR);
205- + exit(1);
206- + }
179+ + pg_fatal("could not read directory \"%s\": %m", PTRACKDIR);
207180+
208181+ if (closedir(xldir))
209- + {
210- + pg_log_error("could not close directory \"%s\": %m", PTRACKDIR);
211- + exit(1);
212- + }
182+ + pg_fatal("could not close directory \"%s\": %m", PTRACKDIR);
213183+ }
214184+
215185
216186 /*
217187 * Write an empty XLOG file, containing only the checkpoint record
218188diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
219- indexfbb97b5cf1..6cd7f2ae3e 100644
189+ index62529310415..b496f54fb06 100644
220190--- a/src/bin/pg_rewind/filemap.c
221191+++ b/src/bin/pg_rewind/filemap.c
222- @@ -124 ,6 +124 ,10 @@ static const struct exclude_list_item excludeFiles[] =
192+ @@ -157 ,6 +157 ,10 @@ static const struct exclude_list_item excludeFiles[] =
223193 {"postmaster.pid", false},
224194 {"postmaster.opts", false},
225195
@@ -230,39 +200,21 @@ index fbb97b5cf1..6cd7f2ae3e 100644
230200 /* end of list */
231201 {NULL, false}
232202 };
233- diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
234- index 72e3352398..5c2e016501 100644
235- --- a/src/include/miscadmin.h
236- +++ b/src/include/miscadmin.h
237- @@ -388,7 +388,7 @@ typedef enum ProcessingMode
238- NormalProcessing/* normal processing */
239- } ProcessingMode;
240-
241- - extern ProcessingMode Mode;
242- + extern PGDLLIMPORT ProcessingMode Mode;
243-
244- #define IsBootstrapProcessingMode() (Mode == BootstrapProcessing)
245- #define IsInitProcessingMode()(Mode == InitProcessing)
246203diff --git a/src/include/port/pg_crc32c.h b/src/include/port/pg_crc32c.h
247- index3c6f906683..a7355f7ad1 100644
204+ indexd7668651ba8..33994a27f5f 100644
248205--- a/src/include/port/pg_crc32c.h
249206+++ b/src/include/port/pg_crc32c.h
250- @@ -69,8 +69,11 @@ extern pg_crc32c pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t le
207+ @@ -69,7 +69,7 @@ extern pg_crc32c pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t le
251208 #define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF)
252209
253210 extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void *data, size_t len);
254211- extern pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len);
255- -
256- + extern
257- + #ifndef FRONTEND
258- + PGDLLIMPORT
259- + #endif
260- + pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len);
212+ + extern PGDLLIMPORT pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len);
213+
261214 #ifdef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK
262215 extern pg_crc32c pg_comp_crc32c_sse42(pg_crc32c crc, const void *data, size_t len);
263- #endif
264216diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h
265- index5d28f59c1d..0d3f04d8af 100644
217+ index50a26edeb06..af1602f5154 100644
266218--- a/src/include/storage/copydir.h
267219+++ b/src/include/storage/copydir.h
268220@@ -13,6 +13,9 @@
@@ -276,7 +228,7 @@ index 5d28f59c1d..0d3f04d8af 100644
276228 extern void copy_file(char *fromfile, char *tofile);
277229
278230diff --git a/src/include/storage/md.h b/src/include/storage/md.h
279- index07fd1bb7d0..5294811bc8 100644
231+ indexffffa40db71..3ff98e0bf01 100644
280232--- a/src/include/storage/md.h
281233+++ b/src/include/storage/md.h
282234@@ -19,6 +19,13 @@
@@ -287,17 +239,17 @@ index 07fd1bb7d0..5294811bc8 100644
287239+ ForkNumber forknum, BlockNumber blocknum);
288240+ extern PGDLLIMPORT mdextend_hook_type mdextend_hook;
289241+ typedef void (*mdwrite_hook_type) (RelFileNodeBackend smgr_rnode,
290- + ForkNumber forknum, BlockNumber blocknum);
242+ + ForkNumber forknum, BlockNumber blocknum);
291243+ extern PGDLLIMPORT mdwrite_hook_type mdwrite_hook;
292244+
293245 /* md storage manager functionality */
294246 extern void mdinit(void);
295247 extern void mdopen(SMgrRelation reln);
296248diff --git a/src/include/storage/sync.h b/src/include/storage/sync.h
297- indexe16ab8e711..88da9686eb 100644
249+ index9737e1eb67c..914ad86328f 100644
298250--- a/src/include/storage/sync.h
299251+++ b/src/include/storage/sync.h
300- @@ -50 ,6 +50 ,9 @@ typedef struct FileTag
252+ @@ -55 ,6 +55 ,9 @@ typedef struct FileTag
301253 uint32segno;
302254 } FileTag;
303255