Skip to content

Commit 5a6bd01

Browse files
committed
[refactoring] move fio_location argument in first place in fio_ functions (part 1)
1 parent f22c5fc commit 5a6bd01

File tree

17 files changed

+196
-183
lines changed

17 files changed

+196
-183
lines changed

src/archive.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ push_file(WALSegno *xlogfile, const char *archive_status_dir,
364364
elog(VERBOSE, "Rename \"%s\" to \"%s\"", wal_file_ready, wal_file_done);
365365

366366
/* do not error out, if rename failed */
367-
if (fio_rename(wal_file_ready, wal_file_done, FIO_DB_HOST) < 0)
367+
if (fio_rename(FIO_DB_HOST, wal_file_ready, wal_file_done) < 0)
368368
elog(WARNING, "Cannot rename ready file \"%s\" to \"%s\": %s",
369369
wal_file_ready, wal_file_done, strerror(errno));
370370
}
@@ -418,7 +418,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
418418
snprintf(to_fullpath_part, sizeof(to_fullpath_part), "%s.part", to_fullpath);
419419

420420
/* Grab lock by creating temp file in exclusive mode */
421-
out = fio_open(to_fullpath_part, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, FIO_BACKUP_HOST);
421+
out = fio_open(FIO_BACKUP_HOST, to_fullpath_part, O_RDWR | O_CREAT | O_EXCL | PG_BINARY);
422422
if (out < 0)
423423
{
424424
if (errno != EEXIST)
@@ -444,12 +444,12 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
444444

445445
while (partial_try_count < archive_timeout)
446446
{
447-
if (fio_stat(to_fullpath_part, &st, false, FIO_BACKUP_HOST) < 0)
447+
if (fio_stat(FIO_BACKUP_HOST, to_fullpath_part, &st, false) < 0)
448448
{
449449
if (errno == ENOENT)
450450
{
451451
//part file is gone, lets try to grab it
452-
out = fio_open(to_fullpath_part, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, FIO_BACKUP_HOST);
452+
out = fio_open(FIO_BACKUP_HOST, to_fullpath_part, O_RDWR | O_CREAT | O_EXCL | PG_BINARY);
453453
if (out < 0)
454454
{
455455
if (errno != EEXIST)
@@ -497,10 +497,10 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
497497

498498
/* Partial segment is considered stale, so reuse it */
499499
elog(LOG, "Reusing stale temp WAL file \"%s\"", to_fullpath_part);
500-
if (fio_remove(to_fullpath_part, false, FIO_BACKUP_HOST) != 0)
500+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_part, false) != 0)
501501
elog(ERROR, "Cannot remove stale temp WAL file \"%s\": %s", to_fullpath_part, strerror(errno));
502502

503-
out = fio_open(to_fullpath_part, O_RDWR | O_CREAT | O_EXCL | PG_BINARY, FIO_BACKUP_HOST);
503+
out = fio_open(FIO_BACKUP_HOST, to_fullpath_part, O_RDWR | O_CREAT | O_EXCL | PG_BINARY);
504504
if (out < 0)
505505
elog(ERROR, "Cannot open temp WAL file \"%s\": %s", to_fullpath_part, strerror(errno));
506506
}
@@ -513,8 +513,8 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
513513
pg_crc32 crc32_src;
514514
pg_crc32 crc32_dst;
515515

516-
crc32_src = fio_get_crc32(from_fullpath, FIO_DB_HOST, false);
517-
crc32_dst = fio_get_crc32(to_fullpath, FIO_BACKUP_HOST, false);
516+
crc32_src = fio_get_crc32(FIO_DB_HOST, from_fullpath, false);
517+
crc32_dst = fio_get_crc32(FIO_BACKUP_HOST, to_fullpath, false);
518518

519519
if (crc32_src == crc32_dst)
520520
{
@@ -523,7 +523,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
523523
/* cleanup */
524524
fclose(in);
525525
fio_close(out);
526-
if (fio_remove(to_fullpath_part, false, FIO_BACKUP_HOST) != 0)
526+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_part, false) != 0)
527527
elog(WARNING, "Cannot remove temp WAL file \"%s\": %s", to_fullpath_part, strerror(errno));
528528
return 1;
529529
}
@@ -537,7 +537,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
537537
/* Overwriting is forbidden,
538538
* so we must unlink partial file and exit with error.
539539
*/
540-
if (fio_remove(to_fullpath_part, false, FIO_BACKUP_HOST) != 0)
540+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_part, false) != 0)
541541
elog(WARNING, "Cannot remove temp WAL file \"%s\": %s", to_fullpath_part, strerror(errno));
542542
elog(ERROR, "WAL file already exists in archive with "
543543
"different checksum: \"%s\"", to_fullpath);
@@ -556,7 +556,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
556556
if (ferror(in))
557557
{
558558
int save_errno = errno;
559-
if (fio_remove(to_fullpath_part, false, FIO_BACKUP_HOST) != 0)
559+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_part, false) != 0)
560560
elog(WARNING, "Cannot remove temp WAL file \"%s\": %s", to_fullpath_part, strerror(errno));
561561
elog(ERROR, "Cannot read source file \"%s\": %s",
562562
from_fullpath, strerror(save_errno));
@@ -565,7 +565,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
565565
if (read_len > 0 && fio_write_async(out, buf, read_len) != read_len)
566566
{
567567
int save_errno = errno;
568-
if (fio_remove(to_fullpath_part, false, FIO_BACKUP_HOST) != 0)
568+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_part, false) != 0)
569569
elog(WARNING, "Cannot cleanup temp WAL file \"%s\": %s", to_fullpath_part, strerror(errno));
570570
elog(ERROR, "Cannot write to destination temp file \"%s\": %s",
571571
to_fullpath_part, strerror(save_errno));
@@ -581,7 +581,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
581581
/* Writing is asynchronous in case of push in remote mode, so check agent status */
582582
if (fio_check_error_fd(out, &errmsg))
583583
{
584-
if (fio_remove(to_fullpath_part, false, FIO_BACKUP_HOST) != 0)
584+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_part, false) != 0)
585585
elog(WARNING, "Cannot cleanup temp WAL file \"%s\": %s", to_fullpath_part, strerror(errno));
586586
elog(ERROR, "Cannot write to the remote file \"%s\": %s",
587587
to_fullpath_part, errmsg);
@@ -591,7 +591,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
591591
if (fio_close(out) != 0)
592592
{
593593
int save_errno = errno;
594-
if (fio_remove(to_fullpath_part, false, FIO_BACKUP_HOST) != 0)
594+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_part, false) != 0)
595595
elog(WARNING, "Cannot cleanup temp WAL file \"%s\": %s", to_fullpath_part, strerror(errno));
596596
elog(ERROR, "Cannot close temp WAL file \"%s\": %s",
597597
to_fullpath_part, strerror(save_errno));
@@ -600,7 +600,7 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
600600
/* sync temp file to disk */
601601
if (!no_sync)
602602
{
603-
if (fio_sync(to_fullpath_part, FIO_BACKUP_HOST) != 0)
603+
if (fio_sync(FIO_BACKUP_HOST, to_fullpath_part) != 0)
604604
elog(ERROR, "Failed to sync file \"%s\": %s",
605605
to_fullpath_part, strerror(errno));
606606
}
@@ -610,10 +610,10 @@ push_file_internal_uncompressed(const char *wal_file_name, const char *pg_xlog_d
610610
//copy_file_attributes(from_path, FIO_DB_HOST, to_path_temp, FIO_BACKUP_HOST, true);
611611

612612
/* Rename temp file to destination file */
613-
if (fio_rename(to_fullpath_part, to_fullpath, FIO_BACKUP_HOST) < 0)
613+
if (fio_rename(FIO_BACKUP_HOST, to_fullpath_part, to_fullpath) < 0)
614614
{
615615
int save_errno = errno;
616-
if (fio_remove(to_fullpath_part, false, FIO_BACKUP_HOST) != 0)
616+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_part, false) != 0)
617617
elog(WARNING, "Cannot cleanup temp WAL file \"%s\": %s", to_fullpath_part, strerror(errno));
618618
elog(ERROR, "Cannot rename file \"%s\" to \"%s\": %s",
619619
to_fullpath_part, to_fullpath, strerror(save_errno));
@@ -675,7 +675,7 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
675675
setvbuf(in, NULL, _IONBF, BUFSIZ);
676676

677677
/* Grab lock by creating temp file in exclusive mode */
678-
out = fio_gzopen(to_fullpath_gz_part, PG_BINARY_W, compress_level, FIO_BACKUP_HOST);
678+
out = fio_gzopen(FIO_BACKUP_HOST, to_fullpath_gz_part, PG_BINARY_W, compress_level);
679679
if (out == NULL)
680680
{
681681
if (errno != EEXIST)
@@ -701,12 +701,12 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
701701

702702
while (partial_try_count < archive_timeout)
703703
{
704-
if (fio_stat(to_fullpath_gz_part, &st, false, FIO_BACKUP_HOST) < 0)
704+
if (fio_stat(FIO_BACKUP_HOST, to_fullpath_gz_part, &st, false) < 0)
705705
{
706706
if (errno == ENOENT)
707707
{
708708
//part file is gone, lets try to grab it
709-
out = fio_gzopen(to_fullpath_gz_part, PG_BINARY_W, compress_level, FIO_BACKUP_HOST);
709+
out = fio_gzopen(FIO_BACKUP_HOST, to_fullpath_gz_part, PG_BINARY_W, compress_level);
710710
if (out == NULL)
711711
{
712712
if (errno != EEXIST)
@@ -755,10 +755,10 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
755755

756756
/* Partial segment is considered stale, so reuse it */
757757
elog(LOG, "Reusing stale temp WAL file \"%s\"", to_fullpath_gz_part);
758-
if (fio_remove(to_fullpath_gz_part, false, FIO_BACKUP_HOST) != 0)
758+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_gz_part, false) != 0)
759759
elog(ERROR, "Cannot remove stale compressed temp WAL file \"%s\": %s", to_fullpath_gz_part, strerror(errno));
760760

761-
out = fio_gzopen(to_fullpath_gz_part, PG_BINARY_W, compress_level, FIO_BACKUP_HOST);
761+
out = fio_gzopen(FIO_BACKUP_HOST, to_fullpath_gz_part, PG_BINARY_W, compress_level);
762762
if (out == NULL)
763763
elog(ERROR, "Cannot open temp WAL file \"%s\": %s",
764764
to_fullpath_gz_part, strerror(errno));
@@ -774,8 +774,8 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
774774
pg_crc32 crc32_dst;
775775

776776
/* TODO: what if one of them goes missing? */
777-
crc32_src = fio_get_crc32(from_fullpath, FIO_DB_HOST, false);
778-
crc32_dst = fio_get_crc32(to_fullpath_gz, FIO_BACKUP_HOST, true);
777+
crc32_src = fio_get_crc32(FIO_DB_HOST, from_fullpath, false);
778+
crc32_dst = fio_get_crc32(FIO_BACKUP_HOST, to_fullpath_gz, true);
779779

780780
if (crc32_src == crc32_dst)
781781
{
@@ -784,7 +784,7 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
784784
/* cleanup */
785785
fclose(in);
786786
fio_gzclose(out);
787-
if (fio_remove(to_fullpath_gz_part, false, FIO_BACKUP_HOST) != 0)
787+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_gz_part, false) != 0)
788788
elog(WARNING, "Cannot remove compressed temp WAL file \"%s\": %s", to_fullpath_gz_part, strerror(errno));
789789
return 1;
790790
}
@@ -798,7 +798,7 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
798798
/* Overwriting is forbidden,
799799
* so we must unlink partial file and exit with error.
800800
*/
801-
if (fio_remove(to_fullpath_gz_part, false, FIO_BACKUP_HOST) != 0)
801+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_gz_part, false) != 0)
802802
elog(WARNING, "Cannot remove compressed temp WAL file \"%s\": %s", to_fullpath_gz_part, strerror(errno));
803803
elog(ERROR, "WAL file already exists in archive with "
804804
"different checksum: \"%s\"", to_fullpath_gz);
@@ -817,7 +817,7 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
817817
if (ferror(in))
818818
{
819819
int save_errno = errno;
820-
if (fio_remove(to_fullpath_gz_part, false, FIO_BACKUP_HOST) != 0)
820+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_gz_part, false) != 0)
821821
elog(WARNING, "Cannot remove compressed temp WAL file \"%s\": %s", to_fullpath_gz_part, strerror(errno));
822822
elog(ERROR, "Cannot read from source file \"%s\": %s",
823823
from_fullpath, strerror(save_errno));
@@ -826,7 +826,7 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
826826
if (read_len > 0 && fio_gzwrite(out, buf, read_len) != read_len)
827827
{
828828
int save_errno = errno;
829-
if (fio_remove(to_fullpath_gz_part, false, FIO_BACKUP_HOST) != 0)
829+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_gz_part, false) != 0)
830830
elog(WARNING, "Cannot cleanup compressed temp WAL file \"%s\": %s", to_fullpath_gz_part, strerror(errno));
831831
elog(ERROR, "Cannot write to compressed temp WAL file \"%s\": %s",
832832
to_fullpath_gz_part, get_gz_error(out, save_errno));
@@ -842,7 +842,7 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
842842
/* Writing is asynchronous in case of push in remote mode, so check agent status */
843843
if (fio_check_error_fd_gz(out, &errmsg))
844844
{
845-
if (fio_remove(to_fullpath_gz_part, false, FIO_BACKUP_HOST) != 0)
845+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_gz_part, false) != 0)
846846
elog(WARNING, "Cannot cleanup remote compressed temp WAL file \"%s\": %s", to_fullpath_gz_part, strerror(errno));
847847
elog(ERROR, "Cannot write to the remote compressed file \"%s\": %s",
848848
to_fullpath_gz_part, errmsg);
@@ -852,7 +852,7 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
852852
if (fio_gzclose(out) != 0)
853853
{
854854
int save_errno = errno;
855-
if (fio_remove(to_fullpath_gz_part, false, FIO_BACKUP_HOST) != 0)
855+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_gz_part, false) != 0)
856856
elog(WARNING, "Cannot cleanup compressed temp WAL file \"%s\": %s", to_fullpath_gz_part, strerror(errno));
857857
elog(ERROR, "Cannot close compressed temp WAL file \"%s\": %s",
858858
to_fullpath_gz_part, strerror(save_errno));
@@ -861,7 +861,7 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
861861
/* sync temp file to disk */
862862
if (!no_sync)
863863
{
864-
if (fio_sync(to_fullpath_gz_part, FIO_BACKUP_HOST) != 0)
864+
if (fio_sync(FIO_BACKUP_HOST, to_fullpath_gz_part) != 0)
865865
elog(ERROR, "Failed to sync file \"%s\": %s",
866866
to_fullpath_gz_part, strerror(errno));
867867
}
@@ -872,10 +872,10 @@ push_file_internal_gz(const char *wal_file_name, const char *pg_xlog_dir,
872872
//copy_file_attributes(from_path, FIO_DB_HOST, to_path_temp, FIO_BACKUP_HOST, true);
873873

874874
/* Rename temp file to destination file */
875-
if (fio_rename(to_fullpath_gz_part, to_fullpath_gz, FIO_BACKUP_HOST) < 0)
875+
if (fio_rename(FIO_BACKUP_HOST, to_fullpath_gz_part, to_fullpath_gz) < 0)
876876
{
877877
int save_errno = errno;
878-
if (fio_remove(to_fullpath_gz_part, false, FIO_BACKUP_HOST) != 0)
878+
if (fio_remove(FIO_BACKUP_HOST, to_fullpath_gz_part, false) != 0)
879879
elog(WARNING, "Cannot cleanup compressed temp WAL file \"%s\": %s", to_fullpath_gz_part, strerror(errno));
880880
elog(ERROR, "Cannot rename file \"%s\" to \"%s\": %s",
881881
to_fullpath_gz_part, to_fullpath_gz, strerror(save_errno));
@@ -913,15 +913,15 @@ get_gz_error(gzFile gzf, int errnum)
913913
//{
914914
// struct stat st;
915915
//
916-
// if (fio_stat(from_path, &st, true, from_location) == -1)
916+
// if (fio_stat(from_location, from_path, &st, true) == -1)
917917
// {
918918
// if (unlink_on_error)
919919
// fio_unlink(to_path, to_location);
920920
// elog(ERROR, "Cannot stat file \"%s\": %s",
921921
// from_path, strerror(errno));
922922
// }
923923
//
924-
// if (fio_chmod(to_path, st.st_mode, to_location) == -1)
924+
// if (fio_chmod(to_location, to_path, st.st_mode) == -1)
925925
// {
926926
// if (unlink_on_error)
927927
// fio_unlink(to_path, to_location);

src/backup.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* backup.c: backup DB cluster, archived WAL
44
*
55
* Portions Copyright (c) 2009-2013, NIPPON TELEGRAPH AND TELEPHONE CORPORATION
6-
* Portions Copyright (c) 2015-2019, Postgres Professional
6+
* Portions Copyright (c) 2015-2022, Postgres Professional
77
*
88
*-------------------------------------------------------------------------
99
*/
@@ -242,7 +242,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
242242
if (current.backup_mode == BACKUP_MODE_DIFF_PAGE || !current.stream)
243243
{
244244
/* Check that archive_dir can be reached */
245-
if (fio_access(instanceState->instance_wal_subdir_path, F_OK, FIO_BACKUP_HOST) != 0)
245+
if (fio_access(FIO_BACKUP_HOST, instanceState->instance_wal_subdir_path, F_OK) != 0)
246246
elog(ERROR, "WAL archive directory is not accessible \"%s\": %s",
247247
instanceState->instance_wal_subdir_path, strerror(errno));
248248

@@ -260,7 +260,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
260260
char stream_xlog_path[MAXPGPATH];
261261

262262
join_path_components(stream_xlog_path, current.database_dir, PG_XLOG_DIR);
263-
fio_mkdir(stream_xlog_path, DIR_PERMISSION, FIO_BACKUP_HOST);
263+
fio_mkdir(FIO_BACKUP_HOST, stream_xlog_path, DIR_PERMISSION);
264264

265265
start_WAL_streaming(backup_conn, stream_xlog_path, &instance_config.conn_opt,
266266
current.start_lsn, current.tli, true);
@@ -413,7 +413,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
413413
join_path_components(dirpath, current.database_dir, file->rel_path);
414414

415415
elog(VERBOSE, "Create directory '%s'", dirpath);
416-
fio_mkdir(dirpath, DIR_PERMISSION, FIO_BACKUP_HOST);
416+
fio_mkdir(FIO_BACKUP_HOST, dirpath, DIR_PERMISSION);
417417
}
418418

419419
}
@@ -528,7 +528,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
528528
{
529529
cleanup_header_map(&(current.hdr_map));
530530

531-
if (fio_sync(current.hdr_map.path, FIO_BACKUP_HOST) != 0)
531+
if (fio_sync(FIO_BACKUP_HOST, current.hdr_map.path) != 0)
532532
elog(ERROR, "Cannot sync file \"%s\": %s", current.hdr_map.path, strerror(errno));
533533
}
534534

@@ -587,7 +587,7 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
587587
join_path_components(to_fullpath, external_dst, file->rel_path);
588588
}
589589

590-
if (fio_sync(to_fullpath, FIO_BACKUP_HOST) != 0)
590+
if (fio_sync(FIO_BACKUP_HOST, to_fullpath) != 0)
591591
elog(ERROR, "Cannot sync file \"%s\": %s", to_fullpath, strerror(errno));
592592
}
593593

@@ -1788,7 +1788,7 @@ pg_stop_backup_write_file_helper(const char *path, const char *filename, const c
17881788
char full_filename[MAXPGPATH];
17891789

17901790
join_path_components(full_filename, path, filename);
1791-
fp = fio_fopen(full_filename, PG_BINARY_W, FIO_BACKUP_HOST);
1791+
fp = fio_fopen(FIO_BACKUP_HOST, full_filename, PG_BINARY_W);
17921792
if (fp == NULL)
17931793
elog(ERROR, "can't open %s file \"%s\": %s",
17941794
error_msg_filename, full_filename, strerror(errno));

0 commit comments

Comments
 (0)