Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3ff6a37

Browse files
committed
Fix remote archive-get and restore
1 parentadee1ef commit3ff6a37

File tree

4 files changed

+49
-44
lines changed

4 files changed

+49
-44
lines changed

‎src/backup.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,13 +1617,13 @@ wait_wal_lsn(XLogRecPtr lsn, bool is_start_lsn, bool wait_prev_segment)
16171617
{
16181618
if (!file_exists)
16191619
{
1620-
file_exists=fileExists(wal_segment_path,is_start_lsn ?FIO_DB_HOST :FIO_BACKUP_HOST);
1620+
file_exists=fileExists(wal_segment_path,FIO_BACKUP_HOST);
16211621

16221622
/* Try to find compressed WAL file */
16231623
if (!file_exists)
16241624
{
16251625
#ifdefHAVE_LIBZ
1626-
file_exists=fileExists(gz_wal_segment_path,is_start_lsn ?FIO_DB_HOST :FIO_BACKUP_HOST);
1626+
file_exists=fileExists(gz_wal_segment_path,FIO_BACKUP_HOST);
16271627
if (file_exists)
16281628
elog(LOG,"Found compressed WAL segment: %s",wal_segment_path);
16291629
#endif

‎src/data.c‎

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,29 +1263,16 @@ get_wal_file(const char *from_path, const char *to_path)
12631263
gzFilegz_in=NULL;
12641264
#endif
12651265

1266-
/* open file for read */
1267-
in=fopen(from_path,PG_BINARY_R);
1268-
if (in==NULL)
1266+
/* First check source file for existance */
1267+
if (fio_access(from_path,F_OK,FIO_BACKUP_HOST)!=0)
12691268
{
12701269
#ifdefHAVE_LIBZ
12711270
/*
12721271
* Maybe we need to decompress the file. Check it with .gz
12731272
* extension.
12741273
*/
12751274
snprintf(gz_from_path,sizeof(gz_from_path),"%s.gz",from_path);
1276-
gz_in=gzopen(gz_from_path,PG_BINARY_R);
1277-
if (gz_in==NULL)
1278-
{
1279-
if (errno==ENOENT)
1280-
{
1281-
/* There is no compressed file too, raise an error below */
1282-
}
1283-
/* Cannot open compressed file for some reason */
1284-
else
1285-
elog(ERROR,"Cannot open compressed WAL file \"%s\": %s",
1286-
gz_from_path,strerror(errno));
1287-
}
1288-
else
1275+
if (fio_access(gz_from_path,F_OK,FIO_BACKUP_HOST)==0)
12891276
{
12901277
/* Found compressed file */
12911278
is_decompress= true;
@@ -1294,9 +1281,28 @@ get_wal_file(const char *from_path, const char *to_path)
12941281
#endif
12951282
/* Didn't find compressed file */
12961283
if (!is_decompress)
1284+
elog(ERROR,"Source WAL file \"%s\" doesn't exist",
1285+
from_path);
1286+
}
1287+
1288+
/* open file for read */
1289+
if (!is_decompress)
1290+
{
1291+
in=fio_fopen(from_path,PG_BINARY_R,FIO_BACKUP_HOST);
1292+
if (in==NULL)
12971293
elog(ERROR,"Cannot open source WAL file \"%s\": %s",
1298-
from_path,strerror(errno));
1294+
from_path,strerror(errno));
1295+
}
1296+
#ifdefHAVE_LIBZ
1297+
else
1298+
{
1299+
gz_in=fio_gzopen(gz_from_path,PG_BINARY_R,Z_DEFAULT_COMPRESSION,
1300+
FIO_BACKUP_HOST);
1301+
if (gz_in==NULL)
1302+
elog(ERROR,"Cannot open compressed WAL file \"%s\": %s",
1303+
gz_from_path,strerror(errno));
12991304
}
1305+
#endif
13001306

13011307
/* open backup file for write */
13021308
snprintf(to_path_temp,sizeof(to_path_temp),"%s.partial",to_path);
@@ -1314,8 +1320,8 @@ get_wal_file(const char *from_path, const char *to_path)
13141320
#ifdefHAVE_LIBZ
13151321
if (is_decompress)
13161322
{
1317-
read_len=gzread(gz_in,buf,sizeof(buf));
1318-
if (read_len!=sizeof(buf)&& !gzeof(gz_in))
1323+
read_len=fio_gzread(gz_in,buf,sizeof(buf));
1324+
if (read_len!=sizeof(buf)&& !fio_gzeof(gz_in))
13191325
{
13201326
errno_temp=errno;
13211327
fio_unlink(to_path_temp,FIO_DB_HOST);
@@ -1326,7 +1332,7 @@ get_wal_file(const char *from_path, const char *to_path)
13261332
else
13271333
#endif
13281334
{
1329-
read_len=fread(buf,1,sizeof(buf),in);
1335+
read_len=fio_fread(in,buf,sizeof(buf));
13301336
if (ferror(in))
13311337
{
13321338
errno_temp=errno;
@@ -1351,13 +1357,13 @@ get_wal_file(const char *from_path, const char *to_path)
13511357
#ifdefHAVE_LIBZ
13521358
if (is_decompress)
13531359
{
1354-
if (gzeof(gz_in)||read_len==0)
1360+
if (fio_gzeof(gz_in)||read_len==0)
13551361
break;
13561362
}
13571363
else
13581364
#endif
13591365
{
1360-
if (feof(in)||read_len==0)
1366+
if (/*feof(in) || */read_len==0)
13611367
break;
13621368
}
13631369
}
@@ -1373,7 +1379,7 @@ get_wal_file(const char *from_path, const char *to_path)
13731379
#ifdefHAVE_LIBZ
13741380
if (is_decompress)
13751381
{
1376-
if (gzclose(gz_in)!=0)
1382+
if (fio_gzclose(gz_in)!=0)
13771383
{
13781384
errno_temp=errno;
13791385
fio_unlink(to_path_temp,FIO_DB_HOST);
@@ -1384,7 +1390,7 @@ get_wal_file(const char *from_path, const char *to_path)
13841390
else
13851391
#endif
13861392
{
1387-
if (fclose(in))
1393+
if (fio_fclose(in))
13881394
{
13891395
errno_temp=errno;
13901396
fio_unlink(to_path_temp,FIO_DB_HOST);

‎src/pg_probackup.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ main(int argc, char *argv[])
341341
canonicalize_path(backup_path);
342342

343343
MyLocation=IsSshProtocol()
344-
?backup_subcmd==ARCHIVE_PUSH_CMD
344+
?(backup_subcmd==ARCHIVE_PUSH_CMD||backup_subcmd==ARCHIVE_GET_CMD)
345345
?FIO_DB_HOST :FIO_BACKUP_HOST
346346
:FIO_LOCAL_HOST;
347347

‎src/restore.c‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -716,18 +716,18 @@ create_recovery_conf(time_t backup_id,
716716
elog(LOG,"creating recovery.conf");
717717

718718
snprintf(path,lengthof(path),"%s/recovery.conf",instance_config.pgdata);
719-
fp=fopen(path,"wt");
719+
fp=fio_fopen(path,"wt",FIO_DB_HOST);
720720
if (fp==NULL)
721721
elog(ERROR,"cannot open recovery.conf \"%s\": %s",path,
722722
strerror(errno));
723723

724-
fprintf(fp,"# recovery.conf generated by pg_probackup %s\n",
725-
PROGRAM_VERSION);
724+
fio_fprintf(fp,"# recovery.conf generated by pg_probackup %s\n",
725+
PROGRAM_VERSION);
726726

727727
if (need_restore_conf)
728728
{
729729

730-
fprintf(fp,"restore_command = '%s archive-get -B %s --instance %s "
730+
fio_fprintf(fp,"restore_command = '%s archive-get -B %s --instance %s "
731731
"--wal-file-path %%p --wal-file-name %%f'\n",
732732
PROGRAM_NAME,backup_path,instance_name);
733733

@@ -736,42 +736,41 @@ create_recovery_conf(time_t backup_id,
736736
* exclusive options is specified, so the order of calls is insignificant.
737737
*/
738738
if (rt->recovery_target_name)
739-
fprintf(fp,"recovery_target_name = '%s'\n",rt->recovery_target_name);
739+
fio_fprintf(fp,"recovery_target_name = '%s'\n",rt->recovery_target_name);
740740

741741
if (rt->time_specified)
742-
fprintf(fp,"recovery_target_time = '%s'\n",rt->target_time_string);
742+
fio_fprintf(fp,"recovery_target_time = '%s'\n",rt->target_time_string);
743743

744744
if (rt->xid_specified)
745-
fprintf(fp,"recovery_target_xid = '%s'\n",rt->target_xid_string);
745+
fio_fprintf(fp,"recovery_target_xid = '%s'\n",rt->target_xid_string);
746746

747747
if (rt->recovery_target_lsn)
748-
fprintf(fp,"recovery_target_lsn = '%s'\n",rt->target_lsn_string);
748+
fio_fprintf(fp,"recovery_target_lsn = '%s'\n",rt->target_lsn_string);
749749

750750
if (rt->recovery_target_immediate)
751-
fprintf(fp,"recovery_target = 'immediate'\n");
751+
fio_fprintf(fp,"recovery_target = 'immediate'\n");
752752

753753
if (rt->inclusive_specified)
754-
fprintf(fp,"recovery_target_inclusive = '%s'\n",
754+
fio_fprintf(fp,"recovery_target_inclusive = '%s'\n",
755755
rt->recovery_target_inclusive?"true":"false");
756756

757757
if (rt->recovery_target_tli)
758-
fprintf(fp,"recovery_target_timeline = '%u'\n",rt->recovery_target_tli);
758+
fio_fprintf(fp,"recovery_target_timeline = '%u'\n",rt->recovery_target_tli);
759759

760760
if (rt->recovery_target_action)
761-
fprintf(fp,"recovery_target_action = '%s'\n",rt->recovery_target_action);
761+
fio_fprintf(fp,"recovery_target_action = '%s'\n",rt->recovery_target_action);
762762
}
763763

764764
if (restore_as_replica)
765765
{
766-
fprintf(fp,"standby_mode = 'on'\n");
766+
fio_fprintf(fp,"standby_mode = 'on'\n");
767767

768768
if (backup->primary_conninfo)
769-
fprintf(fp,"primary_conninfo = '%s'\n",backup->primary_conninfo);
769+
fio_fprintf(fp,"primary_conninfo = '%s'\n",backup->primary_conninfo);
770770
}
771771

772-
if (fflush(fp)!=0||
773-
fsync(fileno(fp))!=0||
774-
fclose(fp))
772+
if (fio_fflush(fp)!=0||
773+
fio_fclose(fp))
775774
elog(ERROR,"cannot write recovery.conf \"%s\": %s",path,
776775
strerror(errno));
777776
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp