Skip to content

Commit cf6ca26

Browse files
author
Michael Paquier
committed
Remove notion of Xlog ID/offset and use XLogRecPtr instead
This simplifies algorithm and APIs a bit, and removes a duplication function used to generate a file name...
1 parent 5bc7164 commit cf6ca26

File tree

2 files changed

+16
-31
lines changed

2 files changed

+16
-31
lines changed

pg_rman.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -318,19 +318,4 @@ extern void remove_not_digit(char *buf, size_t len, const char *str);
318318
/* in pgsql_src/pg_ctl.c */
319319
extern bool is_pg_running(void);
320320

321-
#define NextLogSeg(logId, logSeg) \
322-
do { \
323-
if ((logSeg) >= XLogSegmentsPerXLogId - 1) \
324-
{ \
325-
(logId)++; \
326-
(logSeg) = 0; \
327-
} \
328-
else \
329-
(logSeg)++; \
330-
} while (0)
331-
332-
#define MAXFNAMELEN 64
333-
#define XLogFileNameLong(fname, tli, log, seg) \
334-
snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli, log, seg)
335-
336321
#endif /* PG_RMAN_H */

restore.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ static pgRecoveryTarget *checkIfCreateRecoveryConf(const char *target_time,
2929
const char *target_inclusive);
3030
static parray * readTimeLineHistory(TimeLineID targetTLI);
3131
static bool satisfy_timeline(const parray *timelines, const pgBackup *backup);
32-
static bool satisfy_recovery_target(const pgBackup *backup, const pgRecoveryTarget *rt);
32+
static bool satisfy_recovery_target(const pgBackup *backup,
33+
const pgRecoveryTarget *rt);
3334
static TimeLineID get_current_timeline(void);
34-
static TimeLineID get_fullbackup_timeline(parray *backups, const pgRecoveryTarget *rt);
35+
static TimeLineID get_fullbackup_timeline(parray *backups,
36+
const pgRecoveryTarget *rt);
3537
static void print_backup_id(const pgBackup *backup);
36-
static void search_next_wal(const char *path, uint32 *needId, uint32 *needSeg, parray *timelines);
38+
static void search_next_wal(const char *path,
39+
XLogRecPtr *need_lsn,
40+
parray *timelines);
3741

3842
int
3943
do_restore(const char *target_time,
@@ -53,9 +57,8 @@ do_restore(const char *target_time,
5357
parray *files;
5458
parray *timelines;
5559
char timeline_dir[MAXPGPATH];
56-
uint32 needId = 0;
57-
uint32 needSeg = 0;
5860
pgRecoveryTarget *rt = NULL;
61+
XLogRecPtr need_lsn;
5962

6063
/* PGDATA and ARCLOG_PATH are always required */
6164
if (pgdata == NULL)
@@ -224,11 +227,7 @@ do_restore(const char *target_time,
224227
if (check)
225228
{
226229
pgBackup *backup = (pgBackup *) parray_get(backups, last_restored_index);
227-
uint32 xrecoff = (uint32) backup->start_lsn;
228-
uint32 xlogid = (uint32) (backup->start_lsn >> 32);
229-
230-
needId = xlogid;
231-
needSeg = xrecoff / XLogSegSize;
230+
need_lsn = backup->start_lsn;
232231
}
233232

234233
for (i = last_restored_index; i >= 0; i--)
@@ -253,7 +252,7 @@ do_restore(const char *target_time,
253252
char xlogpath[MAXPGPATH];
254253

255254
pgBackupGetPath(backup, xlogpath, lengthof(xlogpath), ARCLOG_DIR);
256-
search_next_wal(xlogpath, &needId, &needSeg, timelines);
255+
search_next_wal(xlogpath, &need_lsn, timelines);
257256
}
258257
}
259258

@@ -266,13 +265,13 @@ do_restore(const char *target_time,
266265
if (verbose)
267266
printf(_("searching archived WAL...\n"));
268267

269-
search_next_wal(arclog_path, &needId, &needSeg, timelines);
268+
search_next_wal(arclog_path, &need_lsn, timelines);
270269

271270
if (verbose)
272271
printf(_("searching online WAL...\n"));
273272

274273
join_path_components(xlogpath, pgdata, PG_XLOG_DIR);
275-
search_next_wal(xlogpath, &needId, &needSeg, timelines);
274+
search_next_wal(xlogpath, &need_lsn, timelines);
276275

277276
if (verbose)
278277
printf(_("all necessary files are found.\n"));
@@ -989,7 +988,7 @@ print_backup_id(const pgBackup *backup)
989988
}
990989

991990
static void
992-
search_next_wal(const char *path, uint32 *needId, uint32 *needSeg, parray *timelines)
991+
search_next_wal(const char *path, XLogRecPtr *need_lsn, parray *timelines)
993992
{
994993
int i;
995994
int j;
@@ -1006,7 +1005,7 @@ search_next_wal(const char *path, uint32 *needId, uint32 *needSeg, parray *timel
10061005
{
10071006
pgTimeLine *timeline = (pgTimeLine *) parray_get(timelines, i);
10081007

1009-
XLogFileNameLong(xlogfname, timeline->tli, *needId, *needSeg);
1008+
XLogFileName(xlogfname, timeline->tli, *need_lsn);
10101009
join_path_components(xlogpath, path, xlogfname);
10111010

10121011
if (stat(xlogpath, &st) == 0)
@@ -1035,7 +1034,8 @@ search_next_wal(const char *path, uint32 *needId, uint32 *needSeg, parray *timel
10351034
parray_remove(timelines, i + 1);
10361035
/* XXX: should we add a linebreak when we find a timeline? */
10371036

1038-
NextLogSeg(*needId, *needSeg);
1037+
/* Move to next xlog record */
1038+
(*need_lsn)++;
10391039
}
10401040
}
10411041

0 commit comments

Comments
 (0)