Skip to content

Commit 1bc0f9b

Browse files
author
Michael Paquier
committed
Support pg_rman for PG_VERSION_NUM >= 9.3
In Postgres 9.3, XLogRecPtr has been changed to a unique uint64, making the old structure based on two uint32 obsolete. Note that this makes pg_rman incompatible with PG <= 9.2.
1 parent 44e8da5 commit 1bc0f9b

File tree

6 files changed

+66
-48
lines changed

6 files changed

+66
-48
lines changed

backup.c

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
206206
*/
207207
lsn = &prev_backup->start_lsn;
208208
elog(LOG, _("backup only the page that there was of the update from LSN(%X/%08X).\n"),
209-
lsn->xlogid, lsn->xrecoff);
209+
(uint32) (*lsn >> 32), (uint32) *lsn);
210210
}
211211
}
212212

@@ -265,7 +265,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
265265
* and append TABLESPACE to the list backup from non-snapshot.
266266
* TABLESPACE name and oid is obtained by inquiring of the database.
267267
*/
268-
268+
269269
reconnect();
270270
tblspc_res = execute("SELECT spcname, oid FROM pg_tablespace WHERE "
271271
"spcname NOT IN ('pg_default', 'pg_global') ORDER BY spcname ASC", 0, NULL);
@@ -446,7 +446,7 @@ do_backup_database(parray *backup_list, pgBackupOption bkupopt)
446446
/* create file list */
447447
create_file_list(files, pgdata, NULL, false);
448448
}
449-
449+
450450
/* print summary of size of backup mode files */
451451
for (i = 0; i < parray_num(files); i++)
452452
{
@@ -518,7 +518,7 @@ do_backup_arclog(parray *backup_list)
518518
current.read_arclog_bytes = 0;
519519

520520
/* switch xlog if database is not backed up */
521-
if (current.stop_lsn.xrecoff == 0)
521+
if ((uint32) current.stop_lsn == 0)
522522
pg_switch_xlog(&current);
523523

524524
/*
@@ -771,10 +771,8 @@ do_backup(pgBackupOption bkupopt)
771771
/* initialize backup result */
772772
current.status = BACKUP_STATUS_RUNNING;
773773
current.tli = 0; /* get from result of pg_start_backup() */
774-
current.start_lsn.xlogid = 0;
775-
current.start_lsn.xrecoff = 0;
776-
current.stop_lsn.xlogid = 0;
777-
current.stop_lsn.xrecoff = 0;
774+
current.start_lsn = 0;
775+
current.stop_lsn = 0;
778776
current.start_time = time(NULL);
779777
current.end_time = (time_t) 0;
780778
current.total_data_bytes = BYTES_INVALID;
@@ -816,7 +814,7 @@ do_backup(pgBackupOption bkupopt)
816814
/* backup serverlog */
817815
files_srvlog = do_backup_srvlog(backup_list);
818816
pgut_atexit_pop(backup_cleanup, NULL);
819-
817+
820818
/* update backup status to DONE */
821819
current.end_time = time(NULL);
822820
current.status = BACKUP_STATUS_DONE;
@@ -1052,8 +1050,10 @@ wait_for_archive(pgBackup *backup, const char *sql)
10521050
if (backup != NULL)
10531051
{
10541052
get_lsn(res, &backup->tli, &backup->stop_lsn);
1055-
elog(LOG, _("%s(): tli=%X lsn=%X/%08X"), __FUNCTION__, backup->tli,
1056-
backup->stop_lsn.xlogid, backup->stop_lsn.xrecoff);
1053+
elog(LOG, _("%s(): tli=%X lsn=%X/%08X"),
1054+
__FUNCTION__, backup->tli,
1055+
(uint32) (backup->stop_lsn >> 32),
1056+
(uint32) backup->stop_lsn);
10571057
}
10581058

10591059
/* get filename from the result of pg_xlogfile_name_offset() */
@@ -1114,6 +1114,8 @@ static void
11141114
get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn)
11151115
{
11161116
uint32 off_upper;
1117+
uint32 xlogid;
1118+
uint32 xrecoff;
11171119

11181120
if (res == NULL || PQntuples(res) != 1 || PQnfields(res) != 2)
11191121
elog(ERROR_PG_COMMAND,
@@ -1122,8 +1124,8 @@ get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn)
11221124

11231125
/* get TimeLineID, LSN from result of pg_stop_backup() */
11241126
if (sscanf(PQgetvalue(res, 0, 0), "%08X%08X%08X",
1125-
timeline, &lsn->xlogid, &off_upper) != 3 ||
1126-
sscanf(PQgetvalue(res, 0, 1), "%u", &lsn->xrecoff) != 1)
1127+
timeline, &xlogid, &off_upper) != 3 ||
1128+
sscanf(PQgetvalue(res, 0, 1), "%u", &xrecoff) != 1)
11271129
{
11281130
elog(ERROR_PG_COMMAND,
11291131
_("result of pg_xlogfile_name_offset() is invalid: %s"),
@@ -1132,7 +1134,10 @@ get_lsn(PGresult *res, TimeLineID *timeline, XLogRecPtr *lsn)
11321134

11331135
elog(LOG, "%s():%s %s",
11341136
__FUNCTION__, PQgetvalue(res, 0, 0), PQgetvalue(res, 0, 1));
1135-
lsn->xrecoff += off_upper << 24;
1137+
xrecoff += off_upper << 24;
1138+
1139+
/* Set LSN correctly */
1140+
*lsn = (XLogRecPtr) (xlogid << 32) | xrecoff;
11361141
}
11371142

11381143
/*

catalog.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -352,10 +352,12 @@ pgBackupWriteResultSection(FILE *out, pgBackup *backup)
352352

353353
fprintf(out, "# result\n");
354354
fprintf(out, "TIMELINEID=%d\n", backup->tli);
355-
fprintf(out, "START_LSN=%x/%08x\n", backup->start_lsn.xlogid,
356-
backup->start_lsn.xrecoff);
357-
fprintf(out, "STOP_LSN=%x/%08x\n", backup->stop_lsn.xlogid,
358-
backup->stop_lsn.xrecoff);
355+
fprintf(out, "START_LSN=%x/%08x\n",
356+
(uint32) (backup->start_lsn >> 32),
357+
(uint32) backup->start_lsn);
358+
fprintf(out, "STOP_LSN=%x/%08x\n",
359+
(uint32) (backup->stop_lsn >> 32),
360+
(uint32) backup->stop_lsn);
359361

360362
time2iso(timestamp, lengthof(timestamp), backup->start_time);
361363
fprintf(out, "START_TIME='%s'\n", timestamp);
@@ -491,19 +493,23 @@ catalog_read_ini(const char *path)
491493

492494
if (start_lsn)
493495
{
494-
XLogRecPtr lsn;
495-
if (sscanf(start_lsn, "%X/%X", &lsn.xlogid, &lsn.xrecoff) == 2)
496-
backup->start_lsn = lsn;
496+
uint32 xlogid;
497+
uint32 xrecoff;
498+
499+
if (sscanf(start_lsn, "%X/%X", &xlogid, &xrecoff) == 2)
500+
backup->start_lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff;
497501
else
498502
elog(WARNING, _("invalid START_LSN \"%s\""), start_lsn);
499503
free(start_lsn);
500504
}
501505

502506
if (stop_lsn)
503507
{
504-
XLogRecPtr lsn;
505-
if (sscanf(stop_lsn, "%X/%X", &lsn.xlogid, &lsn.xrecoff) == 2)
506-
backup->stop_lsn = lsn;
508+
uint32 xlogid;
509+
uint32 xrecoff;
510+
511+
if (sscanf(stop_lsn, "%X/%X", &xlogid, &xrecoff) == 2)
512+
backup->stop_lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff;
507513
else
508514
elog(WARNING, _("invalid STOP_LSN \"%s\""), stop_lsn);
509515
free(stop_lsn);
@@ -609,10 +615,8 @@ catalog_init_config(pgBackup *backup)
609615
backup->compress_data = false;
610616
backup->status = BACKUP_STATUS_INVALID;
611617
backup->tli = 0;
612-
backup->start_lsn.xlogid = 0;
613-
backup->start_lsn.xrecoff = 0;
614-
backup->stop_lsn.xlogid = 0;
615-
backup->stop_lsn.xrecoff = 0;
618+
backup->start_lsn = 0;
619+
backup->stop_lsn = 0;
616620
backup->start_time = (time_t) 0;
617621
backup->end_time = (time_t) 0;
618622
backup->recovery_xid = 0;

data.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ parse_page(const DataPage *page, int server_version,
265265
return true;
266266
}
267267
}
268-
268+
269269
*offset = *length = 0;
270270
return false;
271271
}
@@ -382,7 +382,7 @@ backup_data_file(const char *from_root, const char *to_root,
382382
file->read_size += read_len;
383383

384384
/* if the page has not been modified since last backup, skip it */
385-
if (lsn && !XLogRecPtrIsInvalid(page_lsn) && XLByteLT(page_lsn, *lsn))
385+
if (lsn && !XLogRecPtrIsInvalid(page_lsn) && page_lsn < *lsn)
386386
continue;
387387

388388
upper_offset = header.hole_offset + header.hole_length;

dir.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ dir_list_file(parray *files, const char *root, const char *exclude[], bool omit_
238238
black_list = parray_new();
239239
black_list_file = fopen(path, "r");
240240
if (black_list_file == NULL)
241-
elog(ERROR_SYSTEM, _("can't open black_list: %s"),
241+
elog(ERROR_SYSTEM, _("can't open black_list: %s"),
242242
strerror(errno));
243243
while (fgets(buf, lengthof(buf), black_list_file) != NULL)
244244
{
@@ -296,11 +296,9 @@ dir_list_file_internal(parray *files, const char *root, const char *exclude[],
296296
if (linked[0] != '/')
297297
{
298298
char dname[MAXPGPATH];
299-
char *dnamep;
300299
char absolute[MAXPGPATH];
301300

302301
strncpy(dname, file->path, lengthof(dname));
303-
dnamep = dirname(dname);
304302
join_path_components(absolute, dname, linked);
305303
file = pgFileNew(absolute, omit_symlink);
306304
}

restore.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,11 @@ do_restore(const char *target_time,
224224
if (check)
225225
{
226226
pgBackup *backup = (pgBackup *) parray_get(backups, last_restored_index);
227-
/* XLByteToSeg(xlrp, logId, logSeg) */
228-
needId = backup->start_lsn.xlogid;
229-
needSeg = backup->start_lsn.xrecoff / XLogSegSize;
227+
uint32 xrecoff = (uint32) backup->start_lsn;
228+
uint32 xlogid = (uint32) (backup->start_lsn >> 32);
229+
230+
needId = xlogid;
231+
needSeg = xrecoff / XLogSegSize;
230232
}
231233

232234
for (i = last_restored_index; i >= 0; i--)
@@ -296,7 +298,7 @@ do_restore(const char *target_time,
296298
elog(INFO, _("restore complete. Recovery starts automatically when the PostgreSQL server is started."));
297299

298300
return 0;
299-
}
301+
}
300302

301303
/*
302304
* Validate and restore backup.
@@ -780,8 +782,7 @@ readTimeLineHistory(TimeLineID targetTLI)
780782

781783
timeline = pgut_new(pgTimeLine);
782784
timeline->tli = 0;
783-
timeline->end.xlogid = 0;
784-
timeline->end.xrecoff = 0;
785+
timeline->end = 0;
785786

786787
/* expect a numeric timeline ID as first field of line */
787788
timeline->tli = (TimeLineID) strtoul(ptr, &endptr, 0);
@@ -824,8 +825,8 @@ readTimeLineHistory(TimeLineID targetTLI)
824825
/* append target timeline */
825826
timeline = pgut_new(pgTimeLine);
826827
timeline->tli = targetTLI;
827-
timeline->end.xlogid = (uint32) -1; /* lsn in target timelie is valid */
828-
timeline->end.xrecoff = (uint32) -1; /* lsn target timelie is valid */
828+
/* lsn in target timeline is valid */
829+
timeline->end = (uint32) (-1UL << 32) | -1UL;
829830
parray_insert(result, 0, timeline);
830831

831832
/* dump timeline branches for debug */
@@ -836,7 +837,9 @@ readTimeLineHistory(TimeLineID targetTLI)
836837
{
837838
pgTimeLine *timeline = parray_get(result, i);
838839
elog(LOG, "%s() result[%d]: %08X/%08X/%08X", __FUNCTION__, i,
839-
timeline->tli, timeline->end.xlogid, timeline->end.xrecoff);
840+
timeline->tli,
841+
(uint32) (timeline->end >> 32),
842+
(uint32) timeline->end);
840843
}
841844
}
842845

@@ -873,7 +876,7 @@ satisfy_timeline(const parray *timelines, const pgBackup *backup)
873876
{
874877
pgTimeLine *timeline = (pgTimeLine *) parray_get(timelines, i);
875878
if (backup->tli == timeline->tli &&
876-
XLByteLT(backup->stop_lsn, timeline->end))
879+
backup->stop_lsn < timeline->end)
877880
return true;
878881
}
879882
return false;
@@ -977,8 +980,10 @@ print_backup_id(const pgBackup *backup)
977980
{
978981
char timestamp[100];
979982
time2iso(timestamp, lengthof(timestamp), backup->start_time);
980-
printf(_(" %s (%X/%08X)\n"), timestamp, backup->stop_lsn.xlogid,
981-
backup->stop_lsn.xrecoff);
983+
printf(_(" %s (%X/%08X)\n"),
984+
timestamp,
985+
(uint32) (backup->stop_lsn >> 32),
986+
(uint32) backup->stop_lsn);
982987
}
983988

984989
static void

xlog.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,17 @@ bool
113113
xlog_logfname2lsn(const char *logfname, XLogRecPtr *lsn)
114114
{
115115
uint32 tli;
116+
uint32 xlogid;
117+
uint32 xrecoff;
116118

117119
if (sscanf(logfname, "%08X%08X%08X",
118-
&tli, &lsn->xlogid, &lsn->xrecoff) != 3)
120+
&tli, &xlogid, &xrecoff) != 3)
119121
return false;
120122

121-
lsn->xrecoff *= XLogSegSize;
123+
xrecoff *= XLogSegSize;
124+
125+
/* Finish calculation of LSN */
126+
*lsn = (XLogRecPtr) ((uint64) xlogid << 32) | xrecoff;
122127
return true;
123128
}
124129

@@ -129,5 +134,6 @@ void
129134
xlog_fname(char *fname, size_t len, TimeLineID tli, XLogRecPtr *lsn)
130135
{
131136
snprintf(fname, len, "%08X%08X%08X", tli,
132-
lsn->xlogid, lsn->xrecoff / XLogSegSize);
137+
(uint32) (*lsn / XLogSegSize),
138+
(uint32) (*lsn % XLogSegSize));
133139
}

0 commit comments

Comments
 (0)