Skip to content

Build and test pg_rewind with encrypted WAL #97

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/backend/access/transam/xlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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;

Expand All @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/bin/pg_rewind/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 10 additions & 1 deletion src/bin/pg_rewind/parsexlog.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
17 changes: 17 additions & 0 deletions src/bin/pg_rewind/pg_rewind.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*
Expand Down
16 changes: 16 additions & 0 deletions src/bin/pg_rewind/t/RewindTest.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading