Skip to content

Commit ee3ce85

Browse files
committed
PGPRO-427: Merge with master
2 parents 56ce573 + 4c3a86f commit ee3ce85

31 files changed

+768
-469
lines changed

gen_probackup_project.pl

Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
# -*-perl-*- hey - emacs - this is a perl file
2+
BEGIN{
3+
use Cwd;
4+
use File::Basename;
5+
6+
my $pgsrc="";
7+
if (@ARGV==1)
8+
{
9+
$pgsrc = shift @ARGV;
10+
if($pgsrc == "--help"){
11+
print STDERR "Usage $0 pg-source-dir \n";
12+
print STDERR "Like this: \n";
13+
print STDERR "$0 C:/PgProject/postgresql.10dev/postgrespro \n";
14+
print STDERR "May be need input this before: \n";
15+
print STDERR "CALL \"C:\\Program Files (x86)\\Microsoft Visual Studio 12.0\\VC\\vcvarsall\" amd64\n";
16+
exit 1;
17+
}
18+
}
19+
else
20+
{
21+
use Cwd qw(abs_path);
22+
my $path = dirname(abs_path($0));
23+
chdir($path);
24+
chdir("../..");
25+
$pgsrc = cwd();
26+
}
27+
28+
chdir("$pgsrc/src/tools/msvc");
29+
push(@INC, "$pgsrc/src/tools/msvc");
30+
chdir("../../..") if (-d "../msvc" && -d "../../../src");
31+
32+
}
33+
34+
use Win32;
35+
use Carp;
36+
use strict;
37+
use warnings;
38+
39+
40+
use Project;
41+
use Solution;
42+
use File::Copy;
43+
use Config;
44+
use VSObjectFactory;
45+
use List::Util qw(first);
46+
47+
use Exporter;
48+
our (@ISA, @EXPORT_OK);
49+
@ISA = qw(Exporter);
50+
@EXPORT_OK = qw(Mkvcbuild);
51+
52+
my $solution;
53+
my $libpgport;
54+
my $libpgcommon;
55+
my $libpgfeutils;
56+
my $postgres;
57+
my $libpq;
58+
my @unlink_on_exit;
59+
60+
61+
use lib "src/tools/msvc";
62+
63+
use Mkvcbuild;
64+
65+
# if (-e "src/tools/msvc/buildenv.pl")
66+
# {
67+
# do "src/tools/msvc/buildenv.pl";
68+
# }
69+
# elsif (-e "./buildenv.pl")
70+
# {
71+
# do "./buildenv.pl";
72+
# }
73+
74+
# set up the project
75+
our $config;
76+
do "config_default.pl";
77+
do "config.pl" if (-f "src/tools/msvc/config.pl");
78+
79+
# my $vcver = Mkvcbuild::mkvcbuild($config);
80+
my $vcver = build_pgprobackup($config);
81+
82+
# check what sort of build we are doing
83+
84+
my $bconf = $ENV{CONFIG} || "Release";
85+
my $msbflags = $ENV{MSBFLAGS} || "";
86+
my $buildwhat = $ARGV[1] || "";
87+
if (uc($ARGV[0]) eq 'DEBUG')
88+
{
89+
$bconf = "Debug";
90+
}
91+
elsif (uc($ARGV[0]) ne "RELEASE")
92+
{
93+
$buildwhat = $ARGV[0] || "";
94+
}
95+
96+
# ... and do it
97+
system("msbuild pg_probackup.vcxproj /verbosity:normal $msbflags /p:Configuration=$bconf" );
98+
99+
100+
# report status
101+
102+
my $status = $? >> 8;
103+
104+
exit $status;
105+
106+
107+
108+
sub build_pgprobackup
109+
{
110+
our $config = shift;
111+
112+
chdir('../../..') if (-d '../msvc' && -d '../../../src');
113+
die 'Must run from root or msvc directory'
114+
unless (-d 'src/tools/msvc' && -d 'src');
115+
116+
# my $vsVersion = DetermineVisualStudioVersion();
117+
my $vsVersion = '12.00';
118+
119+
$solution = CreateSolution($vsVersion, $config);
120+
121+
$libpq = $solution->AddProject('libpq', 'dll', 'interfaces',
122+
'src/interfaces/libpq');
123+
$libpgfeutils = $solution->AddProject('libpgfeutils', 'lib', 'misc');
124+
$libpgcommon = $solution->AddProject('libpgcommon', 'lib', 'misc');
125+
$libpgport = $solution->AddProject('libpgport', 'lib', 'misc');
126+
127+
#vvs test
128+
my $probackup =
129+
$solution->AddProject('pg_probackup', 'exe', 'pg_probackup'); #, 'contrib/pg_probackup'
130+
$probackup->AddFiles(
131+
'contrib/pg_probackup/src',
132+
'archive.c',
133+
'backup.c',
134+
'catalog.c',
135+
'configure.c',
136+
'data.c',
137+
'delete.c',
138+
'dir.c',
139+
'fetch.c',
140+
'help.c',
141+
'init.c',
142+
'parsexlog.c',
143+
'pg_probackup.c',
144+
'restore.c',
145+
'show.c',
146+
'status.c',
147+
'util.c',
148+
'validate.c'
149+
);
150+
$probackup->AddFiles(
151+
'contrib/pg_probackup/src/utils',
152+
'json.c',
153+
'logger.c',
154+
'parray.c',
155+
'pgut.c',
156+
'thread.c'
157+
);
158+
$probackup->AddFile('src/backend/access/transam/xlogreader.c');
159+
$probackup->AddFiles(
160+
'src/bin/pg_basebackup',
161+
'receivelog.c',
162+
'streamutil.c'
163+
);
164+
165+
if (-e 'src/bin/pg_basebackup/walmethods.c')
166+
{
167+
$probackup->AddFile('src/bin/pg_basebackup/walmethods.c');
168+
}
169+
170+
$probackup->AddFile('src/bin/pg_rewind/datapagemap.c');
171+
172+
$probackup->AddFile('src/interfaces/libpq/pthread-win32.c');
173+
174+
$probackup->AddIncludeDir('src/bin/pg_basebackup');
175+
$probackup->AddIncludeDir('src/bin/pg_rewind');
176+
$probackup->AddIncludeDir('src/interfaces/libpq');
177+
$probackup->AddIncludeDir('src');
178+
$probackup->AddIncludeDir('src/port');
179+
180+
$probackup->AddIncludeDir('contrib/pg_probackup');
181+
$probackup->AddIncludeDir('contrib/pg_probackup/src');
182+
$probackup->AddIncludeDir('contrib/pg_probackup/src/utils');
183+
184+
$probackup->AddReference($libpq, $libpgfeutils, $libpgcommon, $libpgport);
185+
$probackup->AddLibrary('ws2_32.lib');
186+
187+
$probackup->Save();
188+
return $solution->{vcver};
189+
190+
}

src/backup.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ remote_copy_file(PGconn *conn, pgFile* file)
329329
{
330330
write_buffer_size = Min(row_length, sizeof(buf));
331331
memcpy(buf, copybuf, write_buffer_size);
332-
COMP_CRC32C(file->crc, &buf, write_buffer_size);
332+
COMP_CRC32C(file->crc, buf, write_buffer_size);
333333

334334
/* TODO calc checksum*/
335335
if (fwrite(buf, 1, write_buffer_size, out) != write_buffer_size)
@@ -732,7 +732,7 @@ do_backup_instance(void)
732732
else
733733
pthread_create(&threads[i], NULL, remote_backup_files, arg);
734734
}
735-
735+
736736
/* Wait threads */
737737
for (i = 0; i < num_threads; i++)
738738
{
@@ -854,7 +854,7 @@ do_backup(time_t start_time)
854854
elog(WARNING, "This PostgreSQL instance was initialized without data block checksums. "
855855
"pg_probackup have no way to detect data block corruption without them. "
856856
"Reinitialize PGDATA with option '--data-checksums'.");
857-
857+
858858
StrNCpy(current.server_version, server_version_str,
859859
sizeof(current.server_version));
860860
current.stream = stream_wal;
@@ -1030,7 +1030,7 @@ check_system_identifiers(void)
10301030

10311031
system_id_pgdata = get_system_identifier(pgdata);
10321032
system_id_conn = get_remote_system_identifier(backup_conn);
1033-
1033+
10341034
if (system_id_conn != system_identifier)
10351035
elog(ERROR, "Backup data directory was initialized for system id %ld, but connected instance system id is %ld",
10361036
system_identifier, system_id_conn);
@@ -1053,13 +1053,13 @@ confirm_block_size(const char *name, int blcksz)
10531053
res = pgut_execute(backup_conn, "SELECT pg_catalog.current_setting($1)", 1, &name);
10541054
if (PQntuples(res) != 1 || PQnfields(res) != 1)
10551055
elog(ERROR, "cannot get %s: %s", name, PQerrorMessage(backup_conn));
1056-
1056+
10571057
block_size = strtol(PQgetvalue(res, 0, 0), &endp, 10);
10581058
if ((endp && *endp) || block_size != blcksz)
10591059
elog(ERROR,
10601060
"%s(%d) is not compatible(%d expected)",
10611061
name, block_size, blcksz);
1062-
1062+
10631063
PQclear(res);
10641064
}
10651065

@@ -1846,7 +1846,7 @@ pg_stop_backup(pgBackup *backup)
18461846
elog(ERROR,
18471847
"result of txid_snapshot_xmax() is invalid: %s",
18481848
PQgetvalue(res, 0, 0));
1849-
if (!parse_time(PQgetvalue(res, 0, 1), &recovery_time))
1849+
if (!parse_time(PQgetvalue(res, 0, 1), &recovery_time, true))
18501850
elog(ERROR,
18511851
"result of current_timestamp is invalid: %s",
18521852
PQgetvalue(res, 0, 1));
@@ -2034,7 +2034,7 @@ backup_files(void *arg)
20342034
pgFile *file = (pgFile *) parray_get(arguments->files_list, i);
20352035

20362036
elog(VERBOSE, "Copying file: \"%s\" ", file->path);
2037-
if (!pg_atomic_test_set_flag(&file->lock))
2037+
if (!pg_atomic_test_set_flag(&file->lock))
20382038
continue;
20392039

20402040
/* check for interrupt */
@@ -2402,12 +2402,12 @@ make_pagemap_from_ptrack(parray *files)
24022402

24032403
if (file->is_datafile)
24042404
{
2405-
if (file->tblspcOid == tblspcOid_with_ptrack_init
2406-
&& file->dbOid == dbOid_with_ptrack_init)
2405+
if (file->tblspcOid == tblspcOid_with_ptrack_init &&
2406+
file->dbOid == dbOid_with_ptrack_init)
24072407
{
24082408
/* ignore ptrack if ptrack_init exists */
24092409
elog(VERBOSE, "Ignoring ptrack because of ptrack_init for file: %s", file->path);
2410-
file->pagemap.bitmapsize = PageBitmapIsAbsent;
2410+
file->pagemap_isabsent = true;
24112411
continue;
24122412
}
24132413

@@ -2460,7 +2460,7 @@ make_pagemap_from_ptrack(parray *files)
24602460
* - target relation was deleted.
24612461
*/
24622462
elog(VERBOSE, "Ptrack is missing for file: %s", file->path);
2463-
file->pagemap.bitmapsize = PageBitmapIsAbsent;
2463+
file->pagemap_isabsent = true;
24642464
}
24652465
}
24662466
}

src/catalog.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,14 @@ IsDir(const char *dirpath, const char *entry)
250250
parray *
251251
catalog_get_backup_list(time_t requested_backup_id)
252252
{
253-
DIR *date_dir = NULL;
254-
struct dirent *date_ent = NULL;
253+
DIR *data_dir = NULL;
254+
struct dirent *data_ent = NULL;
255255
parray *backups = NULL;
256256
pgBackup *backup = NULL;
257257

258258
/* open backup instance backups directory */
259-
date_dir = opendir(backup_instance_path);
260-
if (date_dir == NULL)
259+
data_dir = opendir(backup_instance_path);
260+
if (data_dir == NULL)
261261
{
262262
elog(WARNING, "cannot open directory \"%s\": %s", backup_instance_path,
263263
strerror(errno));
@@ -266,21 +266,21 @@ catalog_get_backup_list(time_t requested_backup_id)
266266

267267
/* scan the directory and list backups */
268268
backups = parray_new();
269-
for (; (date_ent = readdir(date_dir)) != NULL; errno = 0)
269+
for (; (data_ent = readdir(data_dir)) != NULL; errno = 0)
270270
{
271271
char backup_conf_path[MAXPGPATH];
272-
char date_path[MAXPGPATH];
272+
char data_path[MAXPGPATH];
273273

274274
/* skip not-directory entries and hidden entries */
275-
if (!IsDir(backup_instance_path, date_ent->d_name)
276-
|| date_ent->d_name[0] == '.')
275+
if (!IsDir(backup_instance_path, data_ent->d_name)
276+
|| data_ent->d_name[0] == '.')
277277
continue;
278278

279279
/* open subdirectory of specific backup */
280-
join_path_components(date_path, backup_instance_path, date_ent->d_name);
280+
join_path_components(data_path, backup_instance_path, data_ent->d_name);
281281

282282
/* read backup information from BACKUP_CONTROL_FILE */
283-
snprintf(backup_conf_path, MAXPGPATH, "%s/%s", date_path, BACKUP_CONTROL_FILE);
283+
snprintf(backup_conf_path, MAXPGPATH, "%s/%s", data_path, BACKUP_CONTROL_FILE);
284284
backup = readBackupControlFile(backup_conf_path);
285285

286286
/* ignore corrupted backups */
@@ -298,8 +298,8 @@ catalog_get_backup_list(time_t requested_backup_id)
298298

299299
if (errno && errno != ENOENT)
300300
{
301-
elog(WARNING, "cannot read date directory \"%s\": %s",
302-
date_ent->d_name, strerror(errno));
301+
elog(WARNING, "cannot read data directory \"%s\": %s",
302+
data_ent->d_name, strerror(errno));
303303
goto err_proc;
304304
}
305305
}
@@ -310,16 +310,16 @@ catalog_get_backup_list(time_t requested_backup_id)
310310
goto err_proc;
311311
}
312312

313-
closedir(date_dir);
314-
date_dir = NULL;
313+
closedir(data_dir);
314+
data_dir = NULL;
315315

316316
parray_qsort(backups, pgBackupCompareIdDesc);
317317

318318
return backups;
319319

320320
err_proc:
321-
if (date_dir)
322-
closedir(date_dir);
321+
if (data_dir)
322+
closedir(data_dir);
323323
if (backup)
324324
pgBackupFree(backup);
325325
if (backups)

0 commit comments

Comments
 (0)