From bdafe035cb6db388cab2c32572450ab7731672e7 Mon Sep 17 00:00:00 2001 From: Andrew Pogrebnoy Date: Sun, 1 Dec 2024 16:44:47 +0200 Subject: [PATCH] Make pg_rewind read encrypted XLog --- src/bin/pg_rewind/Makefile | 13 +++++++++++++ src/bin/pg_rewind/meson.build | 4 +++- src/bin/pg_rewind/parsexlog.c | 8 ++++++++ src/bin/pg_rewind/pg_rewind.c | 11 +++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/bin/pg_rewind/Makefile b/src/bin/pg_rewind/Makefile index 12b138b2f2ce3..d81a6218b41eb 100644 --- a/src/bin/pg_rewind/Makefile +++ b/src/bin/pg_rewind/Makefile @@ -32,6 +32,19 @@ OBJS = \ EXTRA_CLEAN = xlogreader.c +ifeq ($(enable_percona_ext),yes) +# TODO: Ideally should be built in pg_tde as a static lib +include $(top_srcdir)/contrib/pg_tde/Makefile.tools + +TDE_OBJS2 = $(TDE_OBJS:%=$(top_srcdir)/contrib/pg_tde/%) + +OBJS += \ + $(top_srcdir)/src/fe_utils/simple_list.o \ + $(TDE_OBJS2) + +override CPPFLAGS := -I$(top_srcdir)/contrib/pg_tde/src/include -I$(top_srcdir)/contrib/pg_tde/src/libkmip/libkmip/include $(CPPFLAGS) +endif + all: pg_rewind pg_rewind: $(OBJS) | submake-libpq submake-libpgport diff --git a/src/bin/pg_rewind/meson.build b/src/bin/pg_rewind/meson.build index 200ebf84eb9e1..704f8cc615651 100644 --- a/src/bin/pg_rewind/meson.build +++ b/src/bin/pg_rewind/meson.build @@ -12,6 +12,7 @@ pg_rewind_sources = files( ) pg_rewind_sources += xlogreader_sources +pg_rewind_sources += tde_decrypt_sources if host_system == 'windows' pg_rewind_sources += rc_bin_gen.process(win32ver_rc, extra_args: [ @@ -21,9 +22,10 @@ endif pg_rewind = executable('pg_rewind', pg_rewind_sources, - dependencies: [frontend_code, libpq, lz4, zstd], + dependencies: [frontend_code, libpq, lz4, zstd, tde_deps], c_args: ['-DFRONTEND'], # needed for xlogreader et al kwargs: default_bin_args, + include_directories: [postgres_inc, tde_include], ) bin_targets += pg_rewind diff --git a/src/bin/pg_rewind/parsexlog.c b/src/bin/pg_rewind/parsexlog.c index 242326c97a70e..3507ef27b4193 100644 --- a/src/bin/pg_rewind/parsexlog.c +++ b/src/bin/pg_rewind/parsexlog.c @@ -24,6 +24,10 @@ #include "filemap.h" #include "pg_rewind.h" +#ifdef PERCONA_EXT +#include "access/pg_tde_xlog_encrypt_fe.h" +#endif + /* * RmgrNames is an array of the built-in resource manager names, to make error * messages a bit nicer. @@ -364,7 +368,11 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, } +#ifdef PERCONA_EXT + r = xlog_smgr->seg_read(xlogreadfd, readBuf, XLOG_BLCKSZ, 0); +#else r = read(xlogreadfd, readBuf, XLOG_BLCKSZ); +#endif if (r != XLOG_BLCKSZ) { if (r < 0) diff --git a/src/bin/pg_rewind/pg_rewind.c b/src/bin/pg_rewind/pg_rewind.c index 661095622e74b..4caf61cdd8c2f 100644 --- a/src/bin/pg_rewind/pg_rewind.c +++ b/src/bin/pg_rewind/pg_rewind.c @@ -32,6 +32,10 @@ #include "rewind_source.h" #include "storage/bufpage.h" +#ifdef PERCONA_EXT +#include "access/pg_tde_xlog_encrypt_fe.h" +#endif + static void usage(const char *progname); static void perform_rewind(filemap_t *filemap, rewind_source *source, @@ -364,6 +368,13 @@ main(int argc, char **argv) target_tli = Max(ControlFile_target.minRecoveryPointTLI, ControlFile_target.checkPointCopy.ThisTimeLineID); +#ifdef PERCONA_EXT + /* TDOD: tde_path setup should be moved to the pg_tde side */ + char tde_path[MAXPGPATH]; + snprintf(tde_path, sizeof(tde_path), "%s/%s", datadir_target, PG_TDE_DATA_DIR); + TDE_XLOG_INIT(tde_path); +#endif + /* * Find the common ancestor timeline between the clusters. *