Skip to content

Commit 4e2a192

Browse files
committed
Re-encrypt WAL segments when copying data to the new timeline
We use TLI to calculate encryption IV, therefore, data in segments has to be re-encrypted when copied to the new timeline. For PG-1412
1 parent 10ad9d8 commit 4e2a192

File tree

1 file changed

+5
-2
lines changed
  • src/backend/access/transam

1 file changed

+5
-2
lines changed

src/backend/access/transam/xlog.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3423,6 +3423,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
34233423
int srcfd;
34243424
int fd;
34253425
int nbytes;
3426+
off_t offset = 0;
34263427

34273428
/*
34283429
* Open the source file
@@ -3471,7 +3472,8 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
34713472
if (nread > sizeof(buffer))
34723473
nread = sizeof(buffer);
34733474
pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_READ);
3474-
r = read(srcfd, buffer.data, nread);
3475+
r = xlog_smgr->seg_read(srcfd, buffer.data, nread, offset,
3476+
srcTLI, srcsegno, wal_segment_size);
34753477
if (r != nread)
34763478
{
34773479
if (r < 0)
@@ -3489,7 +3491,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
34893491
}
34903492
errno = 0;
34913493
pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_WRITE);
3492-
if ((int) write(fd, buffer.data, sizeof(buffer)) != (int) sizeof(buffer))
3494+
if ((int) xlog_smgr->seg_write(fd, buffer.data, sizeof(buffer), offset, destTLI, destsegno) != (int) sizeof(buffer))
34933495
{
34943496
int save_errno = errno;
34953497

@@ -3505,6 +3507,7 @@ XLogFileCopy(TimeLineID destTLI, XLogSegNo destsegno,
35053507
errmsg("could not write to file \"%s\": %m", tmppath)));
35063508
}
35073509
pgstat_report_wait_end();
3510+
offset += sizeof(buffer);
35083511
}
35093512

35103513
pgstat_report_wait_start(WAIT_EVENT_WAL_COPY_SYNC);

0 commit comments

Comments
 (0)