Skip to content

Commit 89624b9

Browse files
authored
Merge pull request #41 from postgrespro/merge-ce
Merge ce
2 parents 9a75c19 + 75838c0 commit 89624b9

12 files changed

+1244
-115
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ It is designed to allow false positives (i.e. block/page is marked in the `ptrac
1212

1313
Currently, `ptrack` codebase is split between small PostgreSQL core patch and extension. All public SQL API methods and main engine are placed in the `ptrack` extension, while the core patch contains only certain hooks and modifies binary utilities to ignore `ptrack.map.*` files.
1414

15-
This extension is compatible with PostgreSQL [11](patches/REL_11_STABLE-ptrack-core.diff), [12](patches/REL_12_STABLE-ptrack-core.diff), [13](patches/REL_13_STABLE-ptrack-core.diff), [14](patches/REL_14_STABLE-ptrack-core.diff), [15](patches/REL_15_STABLE-ptrack-core.diff).
15+
This extension is compatible with PostgreSQL [11](patches/REL_11_STABLE-ptrack-core.diff), [12](patches/REL_12_STABLE-ptrack-core.diff), [13](patches/REL_13_STABLE-ptrack-core.diff), [14](patches/REL_14_STABLE-ptrack-core.diff), [15](patches/REL_15_STABLE-ptrack-core.diff), [16](patches/REL_16_STABLE-ptrack-core.diff), [17](patches/REL_17_STABLE-ptrack-core.diff).
1616

1717
## Installation
1818

meson.build

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2025, Postgres Professional
2+
3+
# Does not support the PGXS infrastructure at this time. Please, compile as part
4+
# of the contrib source tree.
5+
6+
ptrack_sources = files(
7+
'datapagemap.c',
8+
'engine.c',
9+
'ptrack.c',
10+
)
11+
12+
if host_system == 'windows'
13+
ptrack_sources += rc_lib_gen.process(win32ver_rc, extra_args: [
14+
'--NAME', 'ptrack',
15+
'--FILEDESC', 'ptrack - block-level incremental backup engine for Postgres Pro.',])
16+
endif
17+
18+
ptrack = shared_module('ptrack',
19+
ptrack_sources,
20+
kwargs: contrib_mod_args,
21+
)
22+
contrib_targets += ptrack
23+
24+
install_data(
25+
'ptrack.control',
26+
'ptrack--2.0--2.1.sql',
27+
'ptrack--2.1--2.2.sql',
28+
'ptrack--2.1.sql',
29+
'ptrack--2.2--2.3.sql',
30+
'ptrack--2.3--2.4.sql',
31+
'ptrack--2.4--2.5.sql',
32+
kwargs: contrib_data_args,
33+
)
34+
35+
tests += {
36+
'name': 'ptrack',
37+
'sd': meson.current_source_dir(),
38+
'bd': meson.current_build_dir(),
39+
'tap': {
40+
'tests': [
41+
't/001_basic.pl',
42+
't/002_cfs_compatibility.pl',
43+
],
44+
},
45+
}

patches/REL_11_STABLE-ptrack-core.diff

Lines changed: 113 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c
2-
index 3e53b3df6fb..f76bfc2a646 100644
2+
index ba4b47443f..62baf8ab4f 100644
33
--- a/src/backend/replication/basebackup.c
44
+++ b/src/backend/replication/basebackup.c
55
@@ -209,6 +209,13 @@ static const struct exclude_list_item excludeFiles[] =
@@ -28,7 +28,7 @@ index 3e53b3df6fb..f76bfc2a646 100644
2828
{"config_exec_params", true},
2929
#endif
3030
diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c
31-
index 4a0d23b11e3..d59009a4c8c 100644
31+
index 4a0d23b11e..d59009a4c8 100644
3232
--- a/src/backend/storage/file/copydir.c
3333
+++ b/src/backend/storage/file/copydir.c
3434
@@ -27,6 +27,8 @@
@@ -51,7 +51,7 @@ index 4a0d23b11e3..d59009a4c8c 100644
5151
* Be paranoid here and fsync all files to ensure the copy is really done.
5252
* But if fsync is disabled, we're done.
5353
diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c
54-
index 200cc7f657a..d0dcb5c0287 100644
54+
index 5418452261..3332a3c717 100644
5555
--- a/src/backend/storage/smgr/md.c
5656
+++ b/src/backend/storage/smgr/md.c
5757
@@ -39,6 +39,7 @@
@@ -71,7 +71,7 @@ index 200cc7f657a..d0dcb5c0287 100644
7171

7272
/*
7373
* In some contexts (currently, standalone backends and the checkpointer)
74-
@@ -558,6 +561,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
74+
@@ -603,6 +606,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
7575
register_dirty_segment(reln, forknum, v);
7676

7777
Assert(_mdnblocks(reln, forknum, v) <= ((BlockNumber) RELSEG_SIZE));
@@ -81,7 +81,7 @@ index 200cc7f657a..d0dcb5c0287 100644
8181
}
8282

8383
/*
84-
@@ -851,6 +857,9 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
84+
@@ -896,6 +902,9 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum,
8585

8686
if (!skipFsync && !SmgrIsTemp(reln))
8787
register_dirty_segment(reln, forknum, v);
@@ -91,7 +91,7 @@ index 200cc7f657a..d0dcb5c0287 100644
9191
}
9292

9393
/*
94-
@@ -1329,6 +1338,9 @@ mdsync(void)
94+
@@ -1374,6 +1383,9 @@ mdsync(void)
9595
CheckpointStats.ckpt_longest_sync = longest;
9696
CheckpointStats.ckpt_agg_sync_time = total_elapsed;
9797

@@ -101,27 +101,124 @@ index 200cc7f657a..d0dcb5c0287 100644
101101
/* Flag successful completion of mdsync */
102102
mdsync_in_progress = false;
103103
}
104+
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
105+
index c7f3ee733d..837ee73217 100644
106+
--- a/src/backend/utils/init/miscinit.c
107+
+++ b/src/backend/utils/init/miscinit.c
108+
@@ -74,6 +74,11 @@ static Latch LocalLatchData;
109+
110+
bool IgnoreSystemIndexes = false;
111+
112+
+/* ----------------------------------------------------------------
113+
+ * Ptrack functions support
114+
+ * ----------------------------------------------------------------
115+
+ */
116+
+static void check_use_ptrack(const char *libraries);
117+
118+
/* ----------------------------------------------------------------
119+
* database path / name support stuff
120+
@@ -1601,6 +1606,8 @@ process_shared_preload_libraries(void)
121+
"shared_preload_libraries",
122+
false);
123+
process_shared_preload_libraries_in_progress = false;
124+
+
125+
+ check_use_ptrack(shared_preload_libraries_string);
126+
}
127+
128+
/*
129+
@@ -1631,3 +1638,71 @@ pg_bindtextdomain(const char *domain)
130+
}
131+
#endif
132+
}
133+
+
134+
+/*-------------------------------------------------------------------------
135+
+ * Ptrack functions support
136+
+ *-------------------------------------------------------------------------
137+
+ */
138+
+
139+
+/* Persistent copy of ptrack.map to restore after crash */
140+
+#define PTRACK_PATH "global/ptrack.map"
141+
+/* Used for atomical crash-safe update of ptrack.map */
142+
+#define PTRACK_PATH_TMP "global/ptrack.map.tmp"
143+
+
144+
+/*
145+
+ * Check that path is accessible by us and return true if it is
146+
+ * not a directory.
147+
+ */
148+
+static bool
149+
+ptrack_file_exists(const char *path)
150+
+{
151+
+ struct stat st;
152+
+
153+
+ Assert(path != NULL);
154+
+
155+
+ if (stat(path, &st) == 0)
156+
+ return S_ISDIR(st.st_mode) ? false : true;
157+
+ else if (!(errno == ENOENT || errno == ENOTDIR || errno == EACCES))
158+
+ ereport(ERROR,
159+
+ (errcode_for_file_access(),
160+
+ errmsg("could not access file \"%s\": %m", path)));
161+
+
162+
+ return false;
163+
+}
164+
+
165+
+/*
166+
+ * Delete ptrack files when ptrack is disabled.
167+
+ *
168+
+ * This is performed by postmaster at start,
169+
+ * so that there are no concurrent delete issues.
170+
+ */
171+
+static void
172+
+ptrackCleanFiles(void)
173+
+{
174+
+ char ptrack_path[MAXPGPATH];
175+
+ char ptrack_path_tmp[MAXPGPATH];
176+
+
177+
+ sprintf(ptrack_path, "%s/%s", DataDir, PTRACK_PATH);
178+
+ sprintf(ptrack_path_tmp, "%s/%s", DataDir, PTRACK_PATH_TMP);
179+
+
180+
+ elog(DEBUG1, "ptrack: clean map files");
181+
+
182+
+ if (ptrack_file_exists(ptrack_path_tmp))
183+
+ durable_unlink(ptrack_path_tmp, LOG);
184+
+
185+
+ if (ptrack_file_exists(ptrack_path))
186+
+ durable_unlink(ptrack_path, LOG);
187+
+}
188+
+
189+
+static void
190+
+check_use_ptrack(const char *libraries)
191+
+{
192+
+ /* We need to delete the ptrack.map file when ptrack was turned off */
193+
+ if (strstr(shared_preload_libraries_string, "ptrack") == NULL)
194+
+ {
195+
+ ptrackCleanFiles();
196+
+ }
197+
+}
198+
+
199+
+#undef PTRACK_PATH
200+
+#undef PTRACK_PATH_TMP
104201
diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c
105-
index 6fb403a5a8a..6e31ccb3e0f 100644
202+
index 611edf6ade..ec1c1212bd 100644
106203
--- a/src/bin/pg_resetwal/pg_resetwal.c
107204
+++ b/src/bin/pg_resetwal/pg_resetwal.c
108-
@@ -84,6 +84,7 @@ static void RewriteControlFile(void);
205+
@@ -85,6 +85,7 @@ static void RewriteControlFile(void);
109206
static void FindEndOfXLOG(void);
110207
static void KillExistingXLOG(void);
111208
static void KillExistingArchiveStatus(void);
112209
+static void KillExistingPtrack(void);
113210
static void WriteEmptyXLOG(void);
114211
static void usage(void);
115212

116-
@@ -516,6 +517,7 @@ main(int argc, char *argv[])
213+
@@ -525,6 +526,7 @@ main(int argc, char *argv[])
117214
RewriteControlFile();
118215
KillExistingXLOG();
119216
KillExistingArchiveStatus();
120217
+ KillExistingPtrack();
121218
WriteEmptyXLOG();
122219

123220
printf(_("Write-ahead log reset\n"));
124-
@@ -1201,6 +1203,57 @@ KillExistingArchiveStatus(void)
221+
@@ -1210,6 +1212,57 @@ KillExistingArchiveStatus(void)
125222
}
126223
}
127224

@@ -180,7 +277,7 @@ index 6fb403a5a8a..6e31ccb3e0f 100644
180277
/*
181278
* Write an empty XLOG file, containing only the checkpoint record
182279
diff --git a/src/bin/pg_rewind/filemap.c b/src/bin/pg_rewind/filemap.c
183-
index 197163d5544..fc846e78175 100644
280+
index 8ea7fafa27..997168fcac 100644
184281
--- a/src/bin/pg_rewind/filemap.c
185282
+++ b/src/bin/pg_rewind/filemap.c
186283
@@ -118,6 +118,10 @@ static const struct exclude_list_item excludeFiles[] =
@@ -195,10 +292,10 @@ index 197163d5544..fc846e78175 100644
195292
{NULL, false}
196293
};
197294
diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h
198-
index 80241455357..50dca7bf6f4 100644
295+
index 7c9f319b67..1e29827030 100644
199296
--- a/src/include/miscadmin.h
200297
+++ b/src/include/miscadmin.h
201-
@@ -367,7 +367,7 @@ typedef enum ProcessingMode
298+
@@ -379,7 +379,7 @@ typedef enum ProcessingMode
202299
NormalProcessing /* normal processing */
203300
} ProcessingMode;
204301

@@ -208,7 +305,7 @@ index 80241455357..50dca7bf6f4 100644
208305
#define IsBootstrapProcessingMode() (Mode == BootstrapProcessing)
209306
#define IsInitProcessingMode() (Mode == InitProcessing)
210307
diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h
211-
index 4fef3e21072..e55430879c3 100644
308+
index 4fef3e2107..e55430879c 100644
212309
--- a/src/include/storage/copydir.h
213310
+++ b/src/include/storage/copydir.h
214311
@@ -13,6 +13,9 @@
@@ -222,7 +319,7 @@ index 4fef3e21072..e55430879c3 100644
222319
extern void copy_file(char *fromfile, char *tofile);
223320

224321
diff --git a/src/include/storage/smgr.h b/src/include/storage/smgr.h
225-
index 0298ed1a2bc..24c684771d0 100644
322+
index 0298ed1a2b..24c684771d 100644
226323
--- a/src/include/storage/smgr.h
227324
+++ b/src/include/storage/smgr.h
228325
@@ -116,6 +116,17 @@ extern void AtEOXact_SMgr(void);
@@ -244,7 +341,7 @@ index 0298ed1a2bc..24c684771d0 100644
244341
extern void mdclose(SMgrRelation reln, ForkNumber forknum);
245342
extern void mdcreate(SMgrRelation reln, ForkNumber forknum, bool isRedo);
246343
diff --git a/src/tools/msvc/Mkvcbuild.pm b/src/tools/msvc/Mkvcbuild.pm
247-
index b52baa90988..74870c048db 100644
344+
index b52baa9098..74870c048d 100644
248345
--- a/src/tools/msvc/Mkvcbuild.pm
249346
+++ b/src/tools/msvc/Mkvcbuild.pm
250347
@@ -33,7 +33,7 @@ my @unlink_on_exit;

0 commit comments

Comments
 (0)