diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index 631deea344da7..ba1f3cc1bd0d4 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -3423,6 +3423,8 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno, int srcfd; int fd; int nbytes; + off_t read_pos = 0; + off_t write_pos = 0; /* * Open the source file @@ -3471,7 +3473,8 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno, if (nread > sizeof(buffer)) nread = sizeof(buffer); pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_READ); - r = read(srcfd, buffer.data, nread); + r = xlog_smgr->seg_read(srcfd, buffer.data, nread, read_pos, + srcTLI, srcsegno, wal_segment_size); if (r != nread) { if (r < 0) @@ -3486,10 +3489,11 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno, path, r, (Size) nread))); } pgstat_report_wait_end(); + read_pos += nread; } errno = 0; pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_WRITE); - if ((int) write(fd, buffer.data, sizeof(buffer)) != (int) sizeof(buffer)) + if ((int) xlog_smgr->seg_write(fd, buffer.data, sizeof(buffer), write_pos, destTLI, destsegno) != (int) sizeof(buffer)) { int save_errno = errno; @@ -3505,6 +3509,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno, errmsg("could not write to file \"%s\": %m", tmppath))); } pgstat_report_wait_end(); + write_pos += sizeof(buffer); } pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_SYNC); diff --git a/src/bin/pg_rewind/meson.build b/src/bin/pg_rewind/meson.build index 200ebf84eb9e1..8614f75381c8f 100644 --- a/src/bin/pg_rewind/meson.build +++ b/src/bin/pg_rewind/meson.build @@ -19,11 +19,22 @@ if host_system == 'windows' '--FILEDESC', 'pg_rewind - synchronize a data directory with another one forked from']) endif + +link_w = [] +include_dirs = [postgres_inc] + +if percona_ext == true + link_w = [pg_tde_frontend] + include_dirs = [postgres_inc, pg_tde_inc] +endif + pg_rewind = executable('pg_rewind', pg_rewind_sources, dependencies: [frontend_code, libpq, lz4, zstd], c_args: ['-DFRONTEND'], # needed for xlogreader et al kwargs: default_bin_args, + include_directories: include_dirs, + link_with: link_w ) bin_targets += pg_rewind diff --git a/src/bin/pg_rewind/parsexlog.c b/src/bin/pg_rewind/parsexlog.c index 242326c97a70e..f5664ebad97a0 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.h" +#endif + /* * RmgrNames is an array of the built-in resource manager names, to make error * messages a bit nicer. @@ -363,8 +367,13 @@ SimpleXLogPageRead(XLogReaderState *xlogreader, XLogRecPtr targetPagePtr, return -1; } - +#ifdef PERCONA_EXT + r = xlog_smgr->seg_read(xlogreadfd, readBuf, XLOG_BLCKSZ, 0, + targetHistory[private->tliIndex].tli, + xlogreadsegno, WalSegSz); +#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 53eb49abdeaf6..099241d9036ff 100644 --- a/src/bin/pg_rewind/pg_rewind.c +++ b/src/bin/pg_rewind/pg_rewind.c @@ -32,6 +32,13 @@ #include "rewind_source.h" #include "storage/bufpage.h" +#ifdef PERCONA_EXT +#include "pg_tde.h" +#include "access/pg_tde_fe_init.h" +#include "access/pg_tde_xlog_encrypt.h" +#include "catalog/tde_global_space.h" +#endif + static void usage(const char *progname); static void perform_rewind(filemap_t *filemap, rewind_source *source, @@ -364,6 +371,16 @@ 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); + pg_tde_fe_init(tde_path); + TDEXLogSmgrInit(); + } + #endif + /* * Find the common ancestor timeline between the clusters. * diff --git a/src/bin/pg_rewind/t/RewindTest.pm b/src/bin/pg_rewind/t/RewindTest.pm index 0bf59db997359..1cc178a21af2e 100644 --- a/src/bin/pg_rewind/t/RewindTest.pm +++ b/src/bin/pg_rewind/t/RewindTest.pm @@ -132,7 +132,23 @@ sub setup_cluster 'postgresql.conf', qq( wal_keep_size = 320MB allow_in_place_tablespaces = on + +shared_preload_libraries = 'pg_tde' )); + + $node_primary->start; + + $node_primary->safe_psql('postgres', "CREATE EXTENSION IF NOT EXISTS pg_tde;"); + $node_primary->safe_psql('postgres', "SELECT pg_tde_add_global_key_provider_file('file-keyring-wal','/tmp/pg_tde_test_keyring-wal.per');");; + $node_primary->safe_psql('postgres', "SELECT pg_tde_set_server_principal_key('global-db-principal-key', 'file-keyring-wal');"); + + $node_primary->append_conf( + 'postgresql.conf', q{ + pg_tde.wal_encrypt = on + }); + + $node_primary->stop; + return; }