Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions src/backup.c
Original file line number Diff line number Diff line change
Expand Up @@ -506,12 +506,12 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
/* copy pg_control at very end */
if (backup_isok)
{
char from_fullpath[MAXPGPATH];
char to_fullpath[MAXPGPATH];

elog(progress ? INFO : LOG, "Progress: Backup file \"%s\"",
src_pg_control_file->rel_path);

char from_fullpath[MAXPGPATH];
char to_fullpath[MAXPGPATH];
join_path_components(from_fullpath, instance_config.pgdata, src_pg_control_file->rel_path);
join_path_components(to_fullpath, current.database_dir, src_pg_control_file->rel_path);

Expand Down
102 changes: 51 additions & 51 deletions src/catalog.c
Original file line number Diff line number Diff line change
Expand Up @@ -1755,27 +1755,27 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)

for (i = 0; i < parray_num(timelineinfos); i++)
{
timelineInfo *tlinfo = parray_get(timelineinfos, i);
timelineInfo *tlInfo = parray_get(timelineinfos, i);
for (j = 0; j < parray_num(backups); j++)
{
pgBackup *backup = parray_get(backups, j);
if (tlinfo->tli == backup->tli)
if (tlInfo->tli == backup->tli)
{
if (tlinfo->backups == NULL)
tlinfo->backups = parray_new();
if (tlInfo->backups == NULL)
tlInfo->backups = parray_new();

parray_append(tlinfo->backups, backup);
parray_append(tlInfo->backups, backup);
}
}
}

/* determine oldest backup and closest backup for every timeline */
for (i = 0; i < parray_num(timelineinfos); i++)
{
timelineInfo *tlinfo = parray_get(timelineinfos, i);
timelineInfo *tlInfo = parray_get(timelineinfos, i);

tlinfo->oldest_backup = get_oldest_backup(tlinfo);
tlinfo->closest_backup = get_closest_backup(tlinfo);
tlInfo->oldest_backup = get_oldest_backup(tlInfo);
tlInfo->closest_backup = get_closest_backup(tlInfo);
}

/* determine which WAL segments must be kept because of wal retention */
Expand Down Expand Up @@ -1845,18 +1845,18 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
for (i = 0; i < parray_num(timelineinfos); i++)
{
int count = 0;
timelineInfo *tlinfo = parray_get(timelineinfos, i);
timelineInfo *tlInfo = parray_get(timelineinfos, i);

/*
* Iterate backward on backups belonging to this timeline to find
* anchor_backup. NOTE Here we rely on the fact that backups list
* is ordered by start_lsn DESC.
*/
if (tlinfo->backups)
if (tlInfo->backups)
{
for (j = 0; j < parray_num(tlinfo->backups); j++)
for (j = 0; j < parray_num(tlInfo->backups); j++)
{
pgBackup *backup = parray_get(tlinfo->backups, j);
pgBackup *backup = parray_get(tlInfo->backups, j);

/* sanity */
if (XLogRecPtrIsInvalid(backup->start_lsn) ||
Expand Down Expand Up @@ -1886,12 +1886,12 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
if (count == instance->wal_depth)
{
elog(LOG, "On timeline %i WAL is protected from purge at %X/%X",
tlinfo->tli,
tlInfo->tli,
(uint32) (backup->start_lsn >> 32),
(uint32) (backup->start_lsn));

tlinfo->anchor_lsn = backup->start_lsn;
tlinfo->anchor_tli = backup->tli;
tlInfo->anchor_lsn = backup->start_lsn;
tlInfo->anchor_tli = backup->tli;
break;
}
}
Expand All @@ -1916,7 +1916,7 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
* If closest_backup is not available, then general WAL purge rules
* are applied.
*/
if (XLogRecPtrIsInvalid(tlinfo->anchor_lsn))
if (XLogRecPtrIsInvalid(tlInfo->anchor_lsn))
{
/*
* Failed to find anchor_lsn in our own timeline.
Expand All @@ -1942,7 +1942,7 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
xlogInterval *interval = NULL;
TimeLineID tli = 0;
/* check if tli has closest_backup */
if (!tlinfo->closest_backup)
if (!tlInfo->closest_backup)
/* timeline has no closest_backup, wal retention cannot be
* applied to this timeline.
* Timeline will be purged up to oldest_backup if any or
Expand All @@ -1952,47 +1952,47 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
continue;

/* sanity for closest_backup */
if (XLogRecPtrIsInvalid(tlinfo->closest_backup->start_lsn) ||
tlinfo->closest_backup->tli <= 0)
if (XLogRecPtrIsInvalid(tlInfo->closest_backup->start_lsn) ||
tlInfo->closest_backup->tli <= 0)
continue;

/*
* Set anchor_lsn and anchor_tli to protect whole timeline from purge
* In the example above: tli3.
*/
tlinfo->anchor_lsn = tlinfo->closest_backup->start_lsn;
tlinfo->anchor_tli = tlinfo->closest_backup->tli;
tlInfo->anchor_lsn = tlInfo->closest_backup->start_lsn;
tlInfo->anchor_tli = tlInfo->closest_backup->tli;

/* closest backup may be located not in parent timeline */
closest_backup = tlinfo->closest_backup;
closest_backup = tlInfo->closest_backup;

tli = tlinfo->tli;
tli = tlInfo->tli;

/*
* Iterate over parent timeline chain and
* look for timeline where closest_backup belong
*/
while (tlinfo->parent_link)
while (tlInfo->parent_link)
{
/* In case of intermediate timeline save to keep_segments
* begin_segno and switchpoint segment.
* In case of final timelines save to keep_segments
* closest_backup start_lsn segment and switchpoint segment.
*/
XLogRecPtr switchpoint = tlinfo->switchpoint;
XLogRecPtr switchpoint = tlInfo->switchpoint;

tlinfo = tlinfo->parent_link;
tlInfo = tlInfo->parent_link;

if (tlinfo->keep_segments == NULL)
tlinfo->keep_segments = parray_new();
if (tlInfo->keep_segments == NULL)
tlInfo->keep_segments = parray_new();

/* in any case, switchpoint segment must be added to interval */
interval = palloc(sizeof(xlogInterval));
GetXLogSegNo(switchpoint, interval->end_segno, instance->xlog_seg_size);

/* Save [S1`, S2] to keep_segments */
if (tlinfo->tli != closest_backup->tli)
interval->begin_segno = tlinfo->begin_segno;
if (tlInfo->tli != closest_backup->tli)
interval->begin_segno = tlInfo->begin_segno;
/* Save [B1, S1] to keep_segments */
else
GetXLogSegNo(closest_backup->start_lsn, interval->begin_segno, instance->xlog_seg_size);
Expand All @@ -2002,27 +2002,27 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
* covered by other larger interval.
*/

GetXLogFileName(begin_segno_str, tlinfo->tli, interval->begin_segno, instance->xlog_seg_size);
GetXLogFileName(end_segno_str, tlinfo->tli, interval->end_segno, instance->xlog_seg_size);
GetXLogFileName(begin_segno_str, tlInfo->tli, interval->begin_segno, instance->xlog_seg_size);
GetXLogFileName(end_segno_str, tlInfo->tli, interval->end_segno, instance->xlog_seg_size);

elog(LOG, "Timeline %i to stay reachable from timeline %i "
"protect from purge WAL interval between "
"%s and %s on timeline %i",
tli, closest_backup->tli, begin_segno_str,
end_segno_str, tlinfo->tli);
end_segno_str, tlInfo->tli);

parray_append(tlinfo->keep_segments, interval);
parray_append(tlInfo->keep_segments, interval);
continue;
}
continue;
}

/* Iterate over backups left */
for (j = count; j < parray_num(tlinfo->backups); j++)
for (j = count; j < parray_num(tlInfo->backups); j++)
{
XLogSegNo segno = 0;
xlogInterval *interval = NULL;
pgBackup *backup = parray_get(tlinfo->backups, j);
pgBackup *backup = parray_get(tlInfo->backups, j);

/*
* We must calculate keep_segments intervals for ARCHIVE backups
Expand All @@ -2039,7 +2039,7 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
continue;

/* no point in clogging keep_segments by backups protected by anchor_lsn */
if (backup->start_lsn >= tlinfo->anchor_lsn)
if (backup->start_lsn >= tlInfo->anchor_lsn)
continue;

/* append interval to keep_segments */
Expand All @@ -2057,19 +2057,19 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
else
interval->end_segno = segno;

GetXLogFileName(begin_segno_str, tlinfo->tli, interval->begin_segno, instance->xlog_seg_size);
GetXLogFileName(end_segno_str, tlinfo->tli, interval->end_segno, instance->xlog_seg_size);
GetXLogFileName(begin_segno_str, tlInfo->tli, interval->begin_segno, instance->xlog_seg_size);
GetXLogFileName(end_segno_str, tlInfo->tli, interval->end_segno, instance->xlog_seg_size);

elog(LOG, "Archive backup %s to stay consistent "
"protect from purge WAL interval "
"between %s and %s on timeline %i",
backup_id_of(backup),
begin_segno_str, end_segno_str, backup->tli);

if (tlinfo->keep_segments == NULL)
tlinfo->keep_segments = parray_new();
if (tlInfo->keep_segments == NULL)
tlInfo->keep_segments = parray_new();

parray_append(tlinfo->keep_segments, interval);
parray_append(tlInfo->keep_segments, interval);
}
}

Expand All @@ -2081,27 +2081,27 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
for (i = 0; i < parray_num(timelineinfos); i++)
{
XLogSegNo anchor_segno = 0;
timelineInfo *tlinfo = parray_get(timelineinfos, i);
timelineInfo *tlInfo = parray_get(timelineinfos, i);

/*
* At this point invalid anchor_lsn can be only in one case:
* timeline is going to be purged by regular WAL purge rules.
*/
if (XLogRecPtrIsInvalid(tlinfo->anchor_lsn))
if (XLogRecPtrIsInvalid(tlInfo->anchor_lsn))
continue;

/*
* anchor_lsn is located in another timeline, it means that the timeline
* will be protected from purge entirely.
*/
if (tlinfo->anchor_tli > 0 && tlinfo->anchor_tli != tlinfo->tli)
if (tlInfo->anchor_tli > 0 && tlInfo->anchor_tli != tlInfo->tli)
continue;

GetXLogSegNo(tlinfo->anchor_lsn, anchor_segno, instance->xlog_seg_size);
GetXLogSegNo(tlInfo->anchor_lsn, anchor_segno, instance->xlog_seg_size);

for (j = 0; j < parray_num(tlinfo->xlog_filelist); j++)
for (j = 0; j < parray_num(tlInfo->xlog_filelist); j++)
{
xlogFile *wal_file = (xlogFile *) parray_get(tlinfo->xlog_filelist, j);
xlogFile *wal_file = (xlogFile *) parray_get(tlInfo->xlog_filelist, j);

if (wal_file->segno >= anchor_segno)
{
Expand All @@ -2110,13 +2110,13 @@ catalog_get_timelines(InstanceState *instanceState, InstanceConfig *instance)
}

/* no keep segments */
if (!tlinfo->keep_segments)
if (!tlInfo->keep_segments)
continue;

/* Protect segments belonging to one of the keep invervals */
for (k = 0; k < parray_num(tlinfo->keep_segments); k++)
for (k = 0; k < parray_num(tlInfo->keep_segments); k++)
{
xlogInterval *keep_segments = (xlogInterval *) parray_get(tlinfo->keep_segments, k);
xlogInterval *keep_segments = (xlogInterval *) parray_get(tlInfo->keep_segments, k);

if ((wal_file->segno >= keep_segments->begin_segno) &&
wal_file->segno <= keep_segments->end_segno)
Expand Down
10 changes: 5 additions & 5 deletions src/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ parse_tli_history_buffer(char *history, TimeLineID tli)
if (curLineLen > 0)
{
char *ptr;
TimeLineID tli;
TimeLineID currTLI;
uint32 switchpoint_hi;
uint32 switchpoint_lo;
int nfields;
Expand All @@ -605,7 +605,7 @@ parse_tli_history_buffer(char *history, TimeLineID tli)
if (*ptr == '\0' || *ptr == '#')
continue;

nfields = sscanf(tempStr, "%u\t%X/%X", &tli, &switchpoint_hi, &switchpoint_lo);
nfields = sscanf(tempStr, "%u\t%X/%X", &currTLI, &switchpoint_hi, &switchpoint_lo);

if (nfields < 1)
{
Expand All @@ -615,11 +615,11 @@ parse_tli_history_buffer(char *history, TimeLineID tli)
if (nfields != 3)
elog(ERROR, "Syntax error in timeline history: \"%s\". Expected a transaction log switchpoint location.", tempStr);

if (last_timeline && tli <= last_timeline->tli)
if (last_timeline && currTLI <= last_timeline->tli)
elog(ERROR, "Timeline IDs must be in increasing sequence: \"%s\"", tempStr);

entry = pgut_new(TimeLineHistoryEntry);
entry->tli = tli;
entry->tli = currTLI;
entry->end = ((uint64) switchpoint_hi << 32) | switchpoint_lo;

last_timeline = entry;
Expand All @@ -628,7 +628,7 @@ parse_tli_history_buffer(char *history, TimeLineID tli)
result = parray_new();
parray_append(result, entry);
elog(VERBOSE, "parse_tli_history_buffer() found entry: tli = %X, end = %X/%X",
tli, switchpoint_hi, switchpoint_lo);
currTLI, switchpoint_hi, switchpoint_lo);

/* we ignore the remainder of each line */
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1684,7 +1684,7 @@ fio_gzread(gzFile f, void *buf, unsigned size)
{
gz->strm.next_in = gz->buf;
}
rc = fio_read(gz->fd, gz->strm.next_in + gz->strm.avail_in,
rc = fio_read(gz->fd, (void *) (gz->strm.next_in + gz->strm.avail_in),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a good idea to discard const qualifier because external library, probably, can cache some values because expected constant value.

gz->buf + ZLIB_BUFFER_SIZE - gz->strm.next_in - gz->strm.avail_in);
if (rc > 0)
{
Expand Down Expand Up @@ -2499,21 +2499,21 @@ fio_send_pages_impl(int out, char* buf)
int
fio_send_file_gz(const char *from_fullpath, FILE* out, char **errormsg)
{
fio_header hdr;
fio_header header;
int exit_code = SEND_OK;
char *in_buf = pgut_malloc(CHUNK_SIZE); /* buffer for compressed data */
char *out_buf = pgut_malloc(OUT_BUF_SIZE); /* 1MB buffer for decompressed data */
size_t path_len = strlen(from_fullpath) + 1;
/* decompressor */
z_stream *strm = NULL;

hdr.cop = FIO_SEND_FILE;
hdr.size = path_len;
header.cop = FIO_SEND_FILE;
header.size = path_len;

// elog(VERBOSE, "Thread [%d]: Attempting to open remote compressed WAL file '%s'",
// thread_num, from_fullpath);

IO_CHECK(fio_write_all(fio_stdout, &hdr, sizeof(hdr)), sizeof(hdr));
IO_CHECK(fio_write_all(fio_stdout, &header, sizeof(header)), sizeof(header));
IO_CHECK(fio_write_all(fio_stdout, from_fullpath, path_len), path_len);

for (;;)
Expand Down