Skip to content

Commit 8863b79

Browse files
author
itagaki.takahiro
committed
Adjust to be able to build on 8.3 or older versions.
git-svn-id: http://pg-rman.googlecode.com/svn/trunk@22 182aca00-e38e-11de-a668-6fd11605f5ce
1 parent f0d7a12 commit 8863b79

File tree

9 files changed

+105
-48
lines changed

9 files changed

+105
-48
lines changed

backup.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ static bool in_backup = false; /* TODO: more robust logic */
2727
* Backup routines
2828
*/
2929
static void backup_cleanup(bool fatal, void *userdata);
30-
static void delete_old_files(const char *root, parray *files, int keep_files, int keep_days, bool is_arclog);
30+
static void delete_old_files(const char *root, parray *files, int keep_files,
31+
int keep_days, int server_version, bool is_arclog);
3132
static void backup_files(const char *from_root, const char *to_root,
3233
parray *files, parray *prev_files, XLogRecPtr *lsn, bool compress_data);
3334
static parray *do_backup_database(parray *backup_list, bool smooth_checkpoint);
@@ -432,11 +433,12 @@ do_backup(bool smooth_checkpoint,
432433
int keep_data_generations,
433434
int keep_data_days)
434435
{
435-
int ret;
436436
parray *backup_list;
437437
parray *files_database;
438438
parray *files_arclog;
439439
parray *files_srvlog;
440+
int server_version;
441+
int ret;
440442

441443
/* PGDATA and BACKUP_MODE are always required */
442444
if (pgdata == NULL)
@@ -462,7 +464,7 @@ do_backup(bool smooth_checkpoint,
462464
#endif
463465

464466
/* confirm data block size and xlog block size are compatible */
465-
(void) get_server_version();
467+
server_version = get_server_version();
466468

467469
/* setup cleanup callback function */
468470
in_backup = true;
@@ -546,10 +548,10 @@ do_backup(bool smooth_checkpoint,
546548
*/
547549
if (HAVE_ARCLOG(&current))
548550
delete_old_files(arclog_path, files_arclog, keep_arclog_files,
549-
keep_arclog_days, true);
551+
keep_arclog_days, server_version, true);
550552
if (current.with_serverlog)
551553
delete_old_files(srvlog_path, files_srvlog, keep_srvlog_files,
552-
keep_srvlog_days, false);
554+
keep_srvlog_days, server_version, false);
553555

554556
/* Delete old backup files after all backup operation. */
555557
pgBackupDelete(keep_data_generations, keep_data_days);
@@ -603,14 +605,17 @@ get_server_version(void)
603605

604606
/* confirm server version */
605607
server_version = PQserverVersion(connection);
606-
if (server_version < 80000)
608+
if (server_version < 80200)
607609
elog(ERROR_PG_INCOMPATIBLE,
608-
_("server version is %d, but must be 8.0 or higher."),
609-
server_version);
610+
_("server version is %d.%d.%d, but must be 8.2 or higher."),
611+
server_version / 10000,
612+
(server_version / 100) % 100,
613+
server_version % 100);
610614

611615
/* confirm block_size (BLCKSZ) and wal_block_size (XLOG_BLCKSZ) */
612616
confirm_block_size("block_size", BLCKSZ);
613-
confirm_block_size("wal_block_size", XLOG_BLCKSZ);
617+
if (server_version >= 80400)
618+
confirm_block_size("wal_block_size", XLOG_BLCKSZ);
614619

615620
if (my_conn)
616621
disconnect();
@@ -625,9 +630,7 @@ confirm_block_size(const char *name, int blcksz)
625630
char *endp;
626631
int block_size;
627632

628-
res = execute(
629-
"SELECT setting from pg_settings where name = $1",
630-
1, &name);
633+
res = execute("SELECT current_setting($1)", 1, &name);
631634
if (PQntuples(res) != 1 || PQnfields(res) != 1)
632635
elog(ERROR_PG_COMMAND, _("can't get %s: %s"),
633636
name, PQerrorMessage(connection));
@@ -955,7 +958,12 @@ backup_files(const char *from_root, const char *to_root, parray *files,
955958
* of newer files exist.
956959
*/
957960
static void
958-
delete_old_files(const char *root, parray *files, int keep_files, int keep_days, bool is_arclog)
961+
delete_old_files(const char *root,
962+
parray *files,
963+
int keep_files,
964+
int keep_days,
965+
int server_version,
966+
bool is_arclog)
959967
{
960968
int i;
961969
int j;
@@ -996,7 +1004,7 @@ delete_old_files(const char *root, parray *files, int keep_files, int keep_days,
9961004

9971005
elog(LOG, "%s() %s", __FUNCTION__, file->path);
9981006
/* Delete complete WAL only. */
999-
if (is_arclog && !xlog_is_complete_wal(file))
1007+
if (is_arclog && !xlog_is_complete_wal(file, server_version))
10001008
{
10011009
elog(LOG, "%s() not complete WAL", __FUNCTION__);
10021010
continue;

catalog.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ catalog_get_last_srvlog_backup(parray *backup_list)
311311
/* create backup directory in $BACKUP_PATH */
312312
int
313313
pgBackupCreateDir(pgBackup *backup)
314-
{
314+
{
315315
int i;
316316
char path[MAXPGPATH];
317317
char *subdirs[] = { DATABASE_DIR, ARCLOG_DIR, SRVLOG_DIR, NULL };

data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ backup_data_file(const char *from_root, const char *to_root,
432432
{
433433
/*
434434
* If the odd size page is the 1st page, fallback to simple copy because
435-
* the file is not a datafile.
435+
* the file is not a datafile.
436436
* Otherwise treat the page as a datapage with no hole.
437437
*/
438438
if (blknum == 0)

delete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ pgBackupDeleteFiles(pgBackup *backup)
177177

178178
/*
179179
* update STATUS to BACKUP_STATUS_DELETING in preparation for the case which
180-
* the error occurs before deleting all backup files.
180+
* the error occurs before deleting all backup files.
181181
*/
182182
if (!check)
183183
{

parray.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ parray_expand(parray *array, size_t newsize)
5656

5757
array->alloced = newsize;
5858
array->data = p;
59-
60-
return;
6159
}
6260

6361
void

pg_rman.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "utils/pg_crc.h"
2020
#include "parray.h"
2121

22+
#if PG_VERSION_NUM < 80200
23+
#define XLOG_BLCKSZ BLCKSZ
24+
#endif
25+
2226
/* Directory/File names */
2327
#define DATABASE_DIR "database"
2428
#define ARCLOG_DIR "arclog"
@@ -52,7 +56,7 @@ typedef struct pgFile
5256
time_t mtime; /* time of last modification */
5357
mode_t mode; /* protection (file type and permission) */
5458
size_t size; /* size of the file */
55-
size_t read_size; /* size of the portion read (if only some pages are
59+
size_t read_size; /* size of the portion read (if only some pages are
5660
backed up partially, it's different from size) */
5761
size_t write_size; /* size of the backed-up file. BYTES_INVALID means
5862
that the file existed but was not backed up
@@ -241,7 +245,7 @@ extern int pgFileCompareMtime(const void *f1, const void *f2);
241245
extern int pgFileCompareMtimeDesc(const void *f1, const void *f2);
242246

243247
/* in xlog.c */
244-
extern bool xlog_is_complete_wal(const pgFile *file);
248+
extern bool xlog_is_complete_wal(const pgFile *file, int server_version);
245249
extern bool xlog_logfname2lsn(const char *logfname, XLogRecPtr *lsn);
246250
extern void xlog_fname(char *fname, size_t len, TimeLineID tli, XLogRecPtr *lsn);
247251

pgut/pgut-port.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ typedef struct REPARSE_DATA
5656
ssize_t
5757
readlink(const char *path, char *target, size_t size)
5858
{
59-
HANDLE handle;
59+
HANDLE handle;
6060
DWORD attr;
6161
REPARSE_DATA data;
6262
DWORD datasize;
@@ -68,12 +68,12 @@ readlink(const char *path, char *target, size_t size)
6868
if (attr == INVALID_FILE_ATTRIBUTES)
6969
{
7070
_dosmaperr(GetLastError());
71-
return -1;
72-
}
71+
return -1;
72+
}
7373
if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) == 0)
7474
{
7575
errno = EINVAL; /* not a symlink */
76-
return -1;
76+
return -1;
7777
}
7878

7979
handle = CreateFileA(path, 0,
@@ -83,9 +83,9 @@ readlink(const char *path, char *target, size_t size)
8383
if (handle == INVALID_HANDLE_VALUE)
8484
{
8585
_dosmaperr(GetLastError());
86-
return -1;
86+
return -1;
8787
}
88-
88+
8989
wpath = NULL;
9090
if (DeviceIoControl(handle, FSCTL_GET_REPARSE_POINT, NULL, 0,
9191
&data, sizeof(data), &datasize, NULL))

restore.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616

1717
#include "catalog/pg_control.h"
1818

19-
#if PG_VERSION_NUM < 80200
20-
#define XLOG_BLCKSZ BLCKSZ
21-
#endif
22-
2319
static void backup_online_files(bool re_recovery);
2420
static void restore_online_files(void);
2521
static void restore_database(pgBackup *backup);

xlog.c

Lines changed: 68 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,49 +21,100 @@ typedef struct MemoryContextData *MemoryContext;
2121

2222
#include "access/xlog_internal.h"
2323

24+
#define XLOG_PAGE_MAGIC_v80 0xD05C /* 8.0 */
25+
#define XLOG_PAGE_MAGIC_v81 0xD05D /* 8.1 */
26+
#define XLOG_PAGE_MAGIC_v82 0xD05E /* 8.2 */
27+
#define XLOG_PAGE_MAGIC_v83 0xD062 /* 8.3 */
28+
#define XLOG_PAGE_MAGIC_v84 0xD063 /* 8.4 */
29+
#define XLOG_PAGE_MAGIC_v85 0xD063 /* 8.5 */
30+
31+
typedef struct XLogLongPageHeaderData_v81
32+
{
33+
XLogPageHeaderData std;
34+
uint64 xlp_sysid;
35+
uint32 xlp_seg_size;
36+
} XLogLongPageHeaderData_v81, *XLogLongPageHeader_v81;
37+
38+
typedef struct XLogLongPageHeaderData_v82
39+
{
40+
XLogPageHeaderData std; /* standard header fields */
41+
uint64 xlp_sysid; /* system identifier from pg_control */
42+
uint32 xlp_seg_size; /* just as a cross-check */
43+
uint32 xlp_xlog_blcksz; /* just as a cross-check */
44+
} XLogLongPageHeaderData_v82, *XLogLongPageHeader_v82;
45+
46+
typedef union XLogPage
47+
{
48+
XLogPageHeaderData header;
49+
XLogLongPageHeaderData_v81 long_v81; /* 8.1 - 8.2 */
50+
XLogLongPageHeaderData_v82 long_v82; /* 8.3 - */
51+
char data[XLOG_BLCKSZ];
52+
} XLogPage;
53+
2454
/*
2555
* Return whether the file is a WAL segment or not.
2656
* based on ValidXLOGHeader() in src/backend/access/transam/xlog.c.
2757
*/
2858
bool
29-
xlog_is_complete_wal(const pgFile *file)
59+
xlog_is_complete_wal(const pgFile *file, int server_version)
3060
{
31-
FILE *fp;
32-
char page[XLOG_BLCKSZ];
33-
XLogPageHeader header = (XLogPageHeader) page;
34-
XLogLongPageHeader lheader = (XLogLongPageHeader) page;
61+
FILE *fp;
62+
XLogPage page;
63+
uint16 xlog_page_magic;
3564

3665
fp = fopen(file->path, "r");
3766
if (!fp)
3867
return false;
39-
if (fread(page, 1, sizeof(page), fp) != XLOG_BLCKSZ)
68+
if (fread(&page, 1, sizeof(page), fp) != XLOG_BLCKSZ)
4069
{
4170
fclose(fp);
4271
return false;
4372
}
4473
fclose(fp);
4574

75+
/* xlog_page_magic from server version */
76+
if (server_version < 80100)
77+
xlog_page_magic = XLOG_PAGE_MAGIC_v80;
78+
else if (server_version < 80200)
79+
xlog_page_magic = XLOG_PAGE_MAGIC_v81;
80+
else if (server_version < 80300)
81+
xlog_page_magic = XLOG_PAGE_MAGIC_v82;
82+
else if (server_version < 80400)
83+
xlog_page_magic = XLOG_PAGE_MAGIC_v83;
84+
else if (server_version < 80500)
85+
xlog_page_magic = XLOG_PAGE_MAGIC_v84;
86+
else
87+
xlog_page_magic = XLOG_PAGE_MAGIC_v85;
88+
4689
/* check header */
47-
if (header->xlp_magic != XLOG_PAGE_MAGIC)
90+
if (page.header.xlp_magic != xlog_page_magic)
4891
return false;
49-
if ((header->xlp_info & ~XLP_ALL_FLAGS) != 0)
92+
if ((page.header.xlp_info & ~XLP_ALL_FLAGS) != 0)
5093
return false;
51-
52-
if (header->xlp_info & XLP_LONG_HEADER)
94+
if (page.header.xlp_info & XLP_LONG_HEADER)
5395
{
54-
if (lheader->xlp_seg_size != XLogSegSize)
96+
if (page.long_v81.xlp_seg_size != XLogSegSize)
5597
return false;
5698

5799
/* compressed WAL (with lesslog) has 0 in lheader->xlp_xlog_blcksz. */
58-
if (lheader->xlp_xlog_blcksz != XLOG_BLCKSZ &&
59-
lheader->xlp_xlog_blcksz != 0)
100+
if (server_version >= 80300)
101+
{
102+
if (page.long_v82.xlp_xlog_blcksz == XLOG_BLCKSZ)
103+
{
104+
/* check size (actual file size, not backup file size) */
105+
if (file->size != XLogSegSize)
106+
return false;
107+
}
108+
else
109+
{
110+
if (page.long_v82.xlp_xlog_blcksz != 0)
111+
return false;
112+
}
113+
}
114+
else if (file->size != XLogSegSize)
60115
return false;
61116
}
62117

63-
/* check size (actual file size, not backup file size) */
64-
if (lheader->xlp_xlog_blcksz == XLOG_BLCKSZ && file->size != XLogSegSize)
65-
return false;
66-
67118
return true;
68119
}
69120

0 commit comments

Comments
 (0)