Skip to content

Commit ced83f7

Browse files
author
Michael Paquier
committed
Fix WAL segment file generation
Name file of WAL segment was generated using the API of xlog_internal.h called XlogFileName, based on XLogSegNo and not XLogRecPtr as the previous code assumed. This leaded to backup incorrect, actually too many WAL files in the archive code path because the analysis was based on a name completely fucked up. This commit fixes at the same time an issue in search_next_wal where the function could loop for a too long amount of time, eating much CPU when looking for the next WAL file. Regression tests are passing cleanly with this patch.
1 parent 78d92ff commit ced83f7

File tree

4 files changed

+11
-11
lines changed

4 files changed

+11
-11
lines changed

backup.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ do_backup_arclog(parray *backup_list)
433433
char prev_file_txt[MAXPGPATH];
434434
pgBackup *prev_backup;
435435
int64 arclog_write_bytes = 0;
436-
char last_wal[MAXPGPATH];
436+
char last_wal[MAXFNAMELEN];
437437

438438
Assert(current.backup_mode == BACKUP_MODE_ARCHIVE ||
439439
current.backup_mode == BACKUP_MODE_INCREMENTAL ||
@@ -485,7 +485,7 @@ do_backup_arclog(parray *backup_list)
485485
dir_list_file(files, arclog_path, NULL, true, false);
486486

487487
/* remove WALs archived after pg_stop_backup()/pg_switch_xlog() */
488-
xlog_fname(last_wal, lengthof(last_wal), current.tli, &current.stop_lsn);
488+
xlog_fname(last_wal, current.tli, current.stop_lsn);
489489
for (i = 0; i < parray_num(files); i++)
490490
{
491491
pgFile *file = (pgFile *) parray_get(files, i);
@@ -1023,7 +1023,7 @@ wait_for_archive(pgBackup *backup, const char *sql)
10231023
}
10241024

10251025
/* As well as WAL file name */
1026-
XLogFileName(file_name, tli, lsn);
1026+
xlog_fname(file_name, tli, lsn);
10271027

10281028
snprintf(ready_path, lengthof(ready_path),
10291029
"%s/pg_xlog/archive_status/%s.ready", pgdata,

pg_rman.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ extern int pgFileCompareMtimeDesc(const void *f1, const void *f2);
307307

308308
/* in xlog.c */
309309
extern bool xlog_is_complete_wal(const pgFile *file);
310-
extern void xlog_fname(char *fname, size_t len, TimeLineID tli, XLogRecPtr *lsn);
310+
extern void xlog_fname(char *fname, TimeLineID tli, XLogRecPtr lsn);
311311

312312
/* in data.c */
313313
extern bool backup_data_file(const char *from_root, const char *to_root,

restore.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ search_next_wal(const char *path, XLogRecPtr *need_lsn, parray *timelines)
992992
{
993993
pgTimeLine *timeline = (pgTimeLine *) parray_get(timelines, i);
994994

995-
XLogFileName(xlogfname, timeline->tli, *need_lsn);
995+
xlog_fname(xlogfname, timeline->tli, *need_lsn);
996996
join_path_components(xlogpath, path, xlogfname);
997997

998998
if (stat(xlogpath, &st) == 0)
@@ -1021,8 +1021,8 @@ search_next_wal(const char *path, XLogRecPtr *need_lsn, parray *timelines)
10211021
parray_remove(timelines, i + 1);
10221022
/* XXX: should we add a linebreak when we find a timeline? */
10231023

1024-
/* Move to next xlog record */
1025-
(*need_lsn)++;
1024+
/* Move to next xlog segment */
1025+
*need_lsn += XLogSegSize;
10261026
}
10271027
}
10281028

xlog.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@ xlog_is_complete_wal(const pgFile *file)
7373
* based on XLogFileName() in xlog_internal.h
7474
*/
7575
void
76-
xlog_fname(char *fname, size_t len, TimeLineID tli, XLogRecPtr *lsn)
76+
xlog_fname(char *fname, TimeLineID tli, XLogRecPtr lsn)
7777
{
78-
snprintf(fname, len, "%08X%08X%08X", tli,
79-
(uint32) (*lsn / XLogSegSize),
80-
(uint32) (*lsn % XLogSegSize));
78+
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,
79+
(uint32) (lsn >> 32),
80+
(uint32) (lsn / XLogSegSize));
8181
}

0 commit comments

Comments
 (0)