diff --git a/engine.c b/engine.c index 42fa65a..8f65557 100644 --- a/engine.c +++ b/engine.c @@ -31,7 +31,11 @@ #include "access/xlog.h" #include "catalog/pg_tablespace.h" #include "miscadmin.h" +#if PG_VERSION_NUM >= 150000 +#include "storage/checksum.h" +#else #include "port/pg_crc32c.h" +#endif #include "storage/copydir.h" #if PG_VERSION_NUM >= 120000 #include "storage/md.h" @@ -39,6 +43,10 @@ #endif #include "storage/reinit.h" #include "storage/smgr.h" +#if PG_VERSION_NUM >= 150000 +#include "storage/fd.h" +#include "access/xlogrecovery.h" +#endif #include "utils/array.h" #include "utils/builtins.h" #include "utils/pg_lsn.h" @@ -73,7 +81,11 @@ ptrack_file_exists(const char *path) static void ptrack_write_chunk(int fd, pg_crc32c *crc, char *chunk, size_t size) { +#if PG_VERSION_NUM >= 150000 + COMP_CRC32C_COMMON(*crc, (char *) chunk, size); +#else COMP_CRC32C(*crc, (char *) chunk, size); +#endif if (write(fd, chunk, size) != size) { @@ -193,7 +205,11 @@ ptrackMapReadFromFile(const char *ptrack_path) pg_crc32c *file_crc; INIT_CRC32C(crc); +#if PG_VERSION_NUM >= 150000 + COMP_CRC32C_COMMON(crc, (char *) ptrack_map, PtrackCrcOffset); +#else COMP_CRC32C(crc, (char *) ptrack_map, PtrackCrcOffset); +#endif FIN_CRC32C(crc); file_crc = (pg_crc32c *) ((char *) ptrack_map + PtrackCrcOffset); diff --git a/patches/master-ptrack-core.diff b/patches/master-ptrack-core.diff index 3491700..a756ca0 100644 --- a/patches/master-ptrack-core.diff +++ b/patches/master-ptrack-core.diff @@ -1,14 +1,14 @@ -commit a14ac459d71528c64df00c693e9c71ac70d3ba29 -Author: anastasia -Date: Mon Oct 19 14:53:06 2020 +0300 +commit 98d98792c0dbe589e8baee4c4100e0dc174ccacb +Author: Anton A. Melnikov +Date: Wed Apr 13 09:49:33 2022 +0300 - add ptrack 2.0 + Apply core patch on PG master diff --git a/src/backend/replication/basebackup.c b/src/backend/replication/basebackup.c -index 50ae1f16d0..721b926ad2 100644 +index 67489192a2..5e22017bd1 100644 --- a/src/backend/replication/basebackup.c +++ b/src/backend/replication/basebackup.c -@@ -233,6 +233,13 @@ static const struct exclude_list_item excludeFiles[] = +@@ -197,6 +197,13 @@ static const struct exclude_list_item excludeFiles[] = {"postmaster.pid", false}, {"postmaster.opts", false}, @@ -22,7 +22,7 @@ index 50ae1f16d0..721b926ad2 100644 /* end of list */ {NULL, false} }; -@@ -248,6 +255,11 @@ static const struct exclude_list_item noChecksumFiles[] = { +@@ -212,6 +219,11 @@ static const struct exclude_list_item noChecksumFiles[] = { {"pg_filenode.map", false}, {"pg_internal.init", true}, {"PG_VERSION", false}, @@ -35,7 +35,7 @@ index 50ae1f16d0..721b926ad2 100644 {"config_exec_params", true}, #endif diff --git a/src/backend/storage/file/copydir.c b/src/backend/storage/file/copydir.c -index 0cf598dd0c..c9c44a4ae7 100644 +index 658fd95ba9..eee38eba17 100644 --- a/src/backend/storage/file/copydir.c +++ b/src/backend/storage/file/copydir.c @@ -27,6 +27,8 @@ @@ -58,7 +58,7 @@ index 0cf598dd0c..c9c44a4ae7 100644 * 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 0eacd461cd..c2ef404a1a 100644 +index 286dd3f755..2c496b3a6d 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -87,6 +87,8 @@ typedef struct _MdfdVec @@ -70,7 +70,7 @@ index 0eacd461cd..c2ef404a1a 100644 /* Populate a file tag describing an md.c segment file. */ #define INIT_MD_FILETAG(a,xx_rnode,xx_forknum,xx_segno) \ -@@ -435,6 +437,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, +@@ -465,6 +467,9 @@ mdextend(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, register_dirty_segment(reln, forknum, v); Assert(_mdnblocks(reln, forknum, v) <= ((BlockNumber) RELSEG_SIZE)); @@ -80,7 +80,7 @@ index 0eacd461cd..c2ef404a1a 100644 } /* -@@ -721,6 +726,9 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, +@@ -757,6 +762,9 @@ mdwrite(SMgrRelation reln, ForkNumber forknum, BlockNumber blocknum, if (!skipFsync && !SmgrIsTemp(reln)) register_dirty_segment(reln, forknum, v); @@ -91,10 +91,10 @@ index 0eacd461cd..c2ef404a1a 100644 /* diff --git a/src/backend/storage/sync/sync.c b/src/backend/storage/sync/sync.c -index 3ded2cdd71..3a596a59f7 100644 +index c695d816fc..77e2ab1996 100644 --- a/src/backend/storage/sync/sync.c +++ b/src/backend/storage/sync/sync.c -@@ -75,6 +75,8 @@ static MemoryContext pendingOpsCxt; /* context for the above */ +@@ -81,6 +81,8 @@ static MemoryContext pendingOpsCxt; /* context for the above */ static CycleCtr sync_cycle_ctr = 0; static CycleCtr checkpoint_cycle_ctr = 0; @@ -103,7 +103,7 @@ index 3ded2cdd71..3a596a59f7 100644 /* Intervals for calling AbsorbSyncRequests */ #define FSYNCS_PER_ABSORB 10 #define UNLINKS_PER_ABSORB 10 -@@ -420,6 +422,9 @@ ProcessSyncRequests(void) +@@ -478,6 +480,9 @@ ProcessSyncRequests(void) CheckpointStats.ckpt_longest_sync = longest; CheckpointStats.ckpt_agg_sync_time = total_elapsed; @@ -113,23 +113,11 @@ index 3ded2cdd71..3a596a59f7 100644 /* Flag successful completion of ProcessSyncRequests */ sync_in_progress = false; } -diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c -index 1683629ee3..d2fc154576 100644 ---- a/src/backend/utils/misc/guc.c -+++ b/src/backend/utils/misc/guc.c -@@ -620,7 +620,6 @@ static char *recovery_target_xid_string; - static char *recovery_target_name_string; - static char *recovery_target_lsn_string; - -- - /* should be static, but commands/variable.c needs to get at this */ - char *role_string; - diff --git a/src/bin/pg_checksums/pg_checksums.c b/src/bin/pg_checksums/pg_checksums.c -index ffdc23945c..7ae95866ce 100644 +index 21dfe1b6ee..266ac1ef40 100644 --- a/src/bin/pg_checksums/pg_checksums.c +++ b/src/bin/pg_checksums/pg_checksums.c -@@ -114,6 +114,11 @@ static const struct exclude_list_item skip[] = { +@@ -118,6 +118,11 @@ static const struct exclude_list_item skip[] = { {"pg_filenode.map", false}, {"pg_internal.init", true}, {"PG_VERSION", false}, @@ -142,10 +130,10 @@ index ffdc23945c..7ae95866ce 100644 {"config_exec_params", true}, #endif diff --git a/src/bin/pg_resetwal/pg_resetwal.c b/src/bin/pg_resetwal/pg_resetwal.c -index 233441837f..cf7bd073bf 100644 +index d4772a2965..66456f7e44 100644 --- a/src/bin/pg_resetwal/pg_resetwal.c +++ b/src/bin/pg_resetwal/pg_resetwal.c -@@ -84,6 +84,7 @@ static void RewriteControlFile(void); +@@ -85,6 +85,7 @@ static void RewriteControlFile(void); static void FindEndOfXLOG(void); static void KillExistingXLOG(void); static void KillExistingArchiveStatus(void); @@ -153,7 +141,7 @@ index 233441837f..cf7bd073bf 100644 static void WriteEmptyXLOG(void); static void usage(void); -@@ -513,6 +514,7 @@ main(int argc, char *argv[]) +@@ -488,6 +489,7 @@ main(int argc, char *argv[]) RewriteControlFile(); KillExistingXLOG(); KillExistingArchiveStatus(); @@ -161,8 +149,8 @@ index 233441837f..cf7bd073bf 100644 WriteEmptyXLOG(); printf(_("Write-ahead log reset\n")); -@@ -1102,6 +1104,53 @@ KillExistingArchiveStatus(void) - } +@@ -1036,6 +1038,53 @@ KillExistingArchiveStatus(void) + pg_fatal("could not close directory \"%s\": %m", ARCHSTATDIR); } +/* @@ -216,10 +204,10 @@ index 233441837f..cf7bd073bf 100644 /* * 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 fbb97b5cf1..6cd7f2ae3e 100644 +index d61067f6b2..27ec23137d 100644 --- a/src/bin/pg_rewind/filemap.c +++ b/src/bin/pg_rewind/filemap.c -@@ -124,6 +124,10 @@ static const struct exclude_list_item excludeFiles[] = +@@ -157,6 +157,10 @@ static const struct exclude_list_item excludeFiles[] = {"postmaster.pid", false}, {"postmaster.opts", false}, @@ -230,39 +218,55 @@ index fbb97b5cf1..6cd7f2ae3e 100644 /* end of list */ {NULL, false} }; -diff --git a/src/include/miscadmin.h b/src/include/miscadmin.h -index 72e3352398..5c2e016501 100644 ---- a/src/include/miscadmin.h -+++ b/src/include/miscadmin.h -@@ -388,7 +388,7 @@ typedef enum ProcessingMode - NormalProcessing /* normal processing */ - } ProcessingMode; +diff --git a/src/include/storage/checksum.h b/src/include/storage/checksum.h +index 1904fabd5a..f9306a6d01 100644 +--- a/src/include/storage/checksum.h ++++ b/src/include/storage/checksum.h +@@ -14,6 +14,7 @@ + #define CHECKSUM_H --extern ProcessingMode Mode; -+extern PGDLLIMPORT ProcessingMode Mode; + #include "storage/block.h" ++#include "port/pg_crc32c.h" - #define IsBootstrapProcessingMode() (Mode == BootstrapProcessing) - #define IsInitProcessingMode() (Mode == InitProcessing) -diff --git a/src/include/port/pg_crc32c.h b/src/include/port/pg_crc32c.h -index 3c6f906683..a7355f7ad1 100644 ---- a/src/include/port/pg_crc32c.h -+++ b/src/include/port/pg_crc32c.h -@@ -69,8 +69,11 @@ extern pg_crc32c pg_comp_crc32c_armv8(pg_crc32c crc, const void *data, size_t le - #define FIN_CRC32C(crc) ((crc) ^= 0xFFFFFFFF) + /* + * 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); - extern pg_crc32c pg_comp_crc32c_sb8(pg_crc32c crc, const void *data, size_t len); --extern pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len); -- -+extern -+#ifndef FRONTEND -+PGDLLIMPORT ++#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 015f0f1f83..1c5a0ba351 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 -+pg_crc32c (*pg_comp_crc32c) (pg_crc32c crc, const void *data, size_t len); - #ifdef USE_SSE42_CRC32C_WITH_RUNTIME_CHECK - extern pg_crc32c pg_comp_crc32c_sse42(pg_crc32c crc, const void *data, size_t len); - #endif diff --git a/src/include/storage/copydir.h b/src/include/storage/copydir.h -index 5d28f59c1d..0d3f04d8af 100644 +index 50a26edeb0..af1602f515 100644 --- a/src/include/storage/copydir.h +++ b/src/include/storage/copydir.h @@ -13,6 +13,9 @@ @@ -276,7 +280,7 @@ index 5d28f59c1d..0d3f04d8af 100644 extern void copy_file(char *fromfile, char *tofile); diff --git a/src/include/storage/md.h b/src/include/storage/md.h -index 07fd1bb7d0..5294811bc8 100644 +index 6e46d8d96a..f0967ef484 100644 --- a/src/include/storage/md.h +++ b/src/include/storage/md.h @@ -19,6 +19,13 @@ @@ -294,10 +298,10 @@ index 07fd1bb7d0..5294811bc8 100644 extern void mdinit(void); extern void mdopen(SMgrRelation reln); diff --git a/src/include/storage/sync.h b/src/include/storage/sync.h -index e16ab8e711..88da9686eb 100644 +index 9737e1eb67..914ad86328 100644 --- a/src/include/storage/sync.h +++ b/src/include/storage/sync.h -@@ -50,6 +50,9 @@ typedef struct FileTag +@@ -55,6 +55,9 @@ typedef struct FileTag uint32 segno; } FileTag;