Skip to content

Commit af80680

Browse files
committed
Merge branch 'REL_2_6-PBCKP-314' into REL_2_6
2 parents ef9ac65 + d6815e0 commit af80680

File tree

12 files changed

+197
-66
lines changed

12 files changed

+197
-66
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ borrowed.mk: $(firstword $(MAKEFILE_LIST))
9595
$(file >$@,# This file is autogenerated. Do not edit!)
9696
$(foreach borrowed_file, $(BORROWED_H_SRC) $(BORROWED_C_SRC), \
9797
$(file >>$@,$(addprefix $(BORROW_DIR)/, $(notdir $(borrowed_file))): | $(CURDIR)/$(BORROW_DIR)/ $(realpath $(top_srcdir)/$(borrowed_file))) \
98-
$(file >>$@,$(shell echo " "'$$(LN_S) $(realpath $(top_srcdir)/$(borrowed_file)) $$@')) \
98+
$(file >>$@,$(shell echo " "'$$(LN_S) -f $(realpath $(top_srcdir)/$(borrowed_file)) $$@')) \
9999
)
100100
include borrowed.mk
101101

src/backup.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
111111
time_t start_time, end_time;
112112
char pretty_time[20];
113113
char pretty_bytes[20];
114+
err_i err = $noerr();
115+
114116

115117
elog(INFO, "Database backup start");
116118
if(current.external_dir_str)
@@ -252,7 +254,12 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
252254
char stream_xlog_path[MAXPGPATH];
253255

254256
join_path_components(stream_xlog_path, current.database_dir, PG_XLOG_DIR);
255-
fio_mkdir(FIO_BACKUP_HOST, stream_xlog_path, DIR_PERMISSION, false);
257+
err = $i(pioMakeDir, current.backup_location, .path = stream_xlog_path,
258+
.mode = DIR_PERMISSION, .strict = false);
259+
if ($haserr(err))
260+
{
261+
elog(ERROR, "Can not create WAL directory: %s", $errmsg(err));
262+
}
256263

257264
start_WAL_streaming(backup_conn, stream_xlog_path, &instance_config.conn_opt,
258265
current.start_lsn, current.tli, true);
@@ -400,7 +407,13 @@ do_backup_pg(InstanceState *instanceState, PGconn *backup_conn,
400407
join_path_components(dirpath, current.database_dir, file->rel_path);
401408

402409
elog(LOG, "Create directory '%s'", dirpath);
403-
fio_mkdir(FIO_BACKUP_HOST, dirpath, DIR_PERMISSION, false);
410+
err = $i(pioMakeDir, current.backup_location, .path = dirpath,
411+
.mode = DIR_PERMISSION, .strict = false);
412+
if ($haserr(err))
413+
{
414+
elog(ERROR, "Can not create instance backup directory: %s",
415+
$errmsg(err));
416+
}
404417
}
405418

406419
}

src/catalog.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ static pgBackup* get_closest_backup(timelineInfo *tlinfo);
2222
static pgBackup* get_oldest_backup(timelineInfo *tlinfo);
2323
static const char *backupModes[] = {"", "PAGE", "PTRACK", "DELTA", "FULL"};
2424
static pgBackup *readBackupControlFile(const char *path);
25-
static int create_backup_dir(pgBackup *backup, const char *backup_instance_path);
25+
static err_i create_backup_dir(pgBackup *backup, const char *backup_instance_path);
2626

2727
static bool backup_lock_exit_hook_registered = false;
2828
static parray *locks = NULL;
@@ -1461,9 +1461,11 @@ pgBackupInitDir(pgBackup *backup, const char *backup_instance_path)
14611461
int i;
14621462
char temp[MAXPGPATH];
14631463
parray *subdirs;
1464+
err_i err = $noerr();
14641465

14651466
/* Try to create backup directory at first */
1466-
if (create_backup_dir(backup, backup_instance_path) != 0)
1467+
err = create_backup_dir(backup, backup_instance_path);
1468+
if ($haserr(err))
14671469
{
14681470
/* Clear backup_id as indication of error */
14691471
backup->backup_id = INVALID_BACKUP_ID;
@@ -1499,7 +1501,12 @@ pgBackupInitDir(pgBackup *backup, const char *backup_instance_path)
14991501
for (i = 0; i < parray_num(subdirs); i++)
15001502
{
15011503
join_path_components(temp, backup->root_dir, parray_get(subdirs, i));
1502-
fio_mkdir(FIO_BACKUP_HOST, temp, DIR_PERMISSION, false);
1504+
err = $i(pioMakeDir, backup->backup_location, .path = temp,
1505+
.mode = DIR_PERMISSION, .strict = false);
1506+
if ($haserr(err))
1507+
{
1508+
elog(ERROR, "Can not create backup directory: %s", $errmsg(err));
1509+
}
15031510
}
15041511

15051512
free_dir_list(subdirs);
@@ -1512,22 +1519,25 @@ pgBackupInitDir(pgBackup *backup, const char *backup_instance_path)
15121519
* 0 - ok
15131520
* -1 - error (warning message already emitted)
15141521
*/
1515-
int
1522+
static err_i
15161523
create_backup_dir(pgBackup *backup, const char *backup_instance_path)
15171524
{
1518-
int rc;
15191525
char path[MAXPGPATH];
1526+
err_i err;
15201527

15211528
join_path_components(path, backup_instance_path, base36enc(backup->backup_id));
15221529

15231530
/* TODO: add wrapper for remote mode */
1524-
rc = fio_mkdir(FIO_BACKUP_HOST, path, DIR_PERMISSION, true);
1525-
1526-
if (rc == 0)
1531+
err = $i(pioMakeDir, backup->backup_location, .path = path,
1532+
.mode = DIR_PERMISSION, .strict = true);
1533+
if (!$haserr(err))
1534+
{
15271535
backup->root_dir = pgut_strdup(path);
1528-
else
1529-
elog(WARNING, "Cannot create directory \"%s\": %s", path, strerror(errno));
1530-
return rc;
1536+
} else {
1537+
elog(ERROR, "Can not create backup directory: %s", $errmsg(err));
1538+
}
1539+
1540+
return err;
15311541
}
15321542

15331543
/*
@@ -2969,6 +2979,9 @@ pgBackupInit(pgBackup *backup)
29692979
backup->files = NULL;
29702980
backup->note = NULL;
29712981
backup->content_crc = 0;
2982+
2983+
backup->backup_location = pioDriveForLocation(FIO_BACKUP_HOST);
2984+
backup->database_location = pioDriveForLocation(FIO_DB_HOST);
29722985
}
29732986

29742987
/* free pgBackup object */
@@ -2977,6 +2990,10 @@ pgBackupFree(void *backup)
29772990
{
29782991
pgBackup *b = (pgBackup *) backup;
29792992

2993+
/* Both point to global static vars */
2994+
b->backup_location.self = NULL;
2995+
b->database_location.self = NULL;
2996+
29802997
pg_free(b->primary_conninfo);
29812998
pg_free(b->external_dir_str);
29822999
pg_free(b->root_dir);

src/catchup.c

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ int
613613
do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads, bool sync_dest_files,
614614
parray *exclude_absolute_paths_list, parray *exclude_relative_paths_list)
615615
{
616+
pioDrive_i local_location = pioDriveForLocation(FIO_LOCAL_HOST);
616617
PGconn *source_conn = NULL;
617618
PGNodeInfo source_node_info;
618619
bool backup_logs = false;
@@ -632,6 +633,8 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
632633
ssize_t transfered_datafiles_bytes = 0;
633634
ssize_t transfered_walfiles_bytes = 0;
634635
char pretty_source_bytes[20];
636+
err_i err = $noerr();
637+
635638

636639
source_conn = catchup_init_state(&source_node_info, source_pgdata, dest_pgdata);
637640
catchup_preflight_checks(&source_node_info, source_conn, source_pgdata, dest_pgdata);
@@ -704,7 +707,12 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
704707
join_path_components(dest_xlog_path, dest_pgdata, PG_XLOG_DIR);
705708
if (!dry_run)
706709
{
707-
fio_mkdir(FIO_LOCAL_HOST, dest_xlog_path, DIR_PERMISSION, false);
710+
err = $i(pioMakeDir, local_location, .path = dest_xlog_path,
711+
.mode = DIR_PERMISSION, .strict = false);
712+
if($haserr(err))
713+
{
714+
elog(ERROR, "Can not create WAL directory: %s", $errmsg(err));
715+
}
708716
start_WAL_streaming(source_conn, dest_xlog_path, &instance_config.conn_opt,
709717
current.start_lsn, current.tli, false);
710718
}
@@ -820,7 +828,14 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
820828

821829
elog(LOG, "Create directory '%s'", dirpath);
822830
if (!dry_run)
823-
fio_mkdir(FIO_LOCAL_HOST, dirpath, DIR_PERMISSION, false);
831+
{
832+
err = $i(pioMakeDir, local_location, .path = dirpath,
833+
.mode = DIR_PERMISSION, .strict = false);
834+
if ($haserr(err))
835+
{
836+
elog(ERROR, "Can not create directory: %s", $errmsg(err));
837+
}
838+
}
824839
}
825840
else
826841
{
@@ -854,9 +869,13 @@ do_catchup(const char *source_pgdata, const char *dest_pgdata, int num_threads,
854869
if (!dry_run)
855870
{
856871
/* create tablespace directory */
857-
if (fio_mkdir(FIO_LOCAL_HOST, linked_path, file->mode, false) != 0)
858-
elog(ERROR, "Could not create tablespace directory \"%s\": %s",
859-
linked_path, strerror(errno));
872+
err = $i(pioMakeDir, local_location, .path = linked_path,
873+
.mode = file->mode, .strict = false);
874+
if ($haserr(err))
875+
{
876+
elog(ERROR, "Could not create tablespace directory \"%s\": \"%s\"",
877+
linked_path, $errmsg(err));
878+
}
860879

861880
/* create link to linked_path */
862881
if (fio_symlink(FIO_LOCAL_HOST, linked_path, to_path, true) < 0)

src/dir.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,13 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba
847847
bool extract_tablespaces, bool incremental, fio_location location,
848848
const char* waldir_path)
849849
{
850+
pioDrive_i drive = pioDriveForLocation(location);
850851
int i;
851852
parray *links = NULL;
852853
mode_t pg_tablespace_mode = DIR_PERMISSION;
853854
char to_path[MAXPGPATH];
855+
err_i err = $noerr();
856+
854857

855858
if (waldir_path && !dir_is_empty(waldir_path, location))
856859
{
@@ -932,7 +935,13 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba
932935
waldir_path, to_path);
933936

934937
/* create tablespace directory from waldir_path*/
935-
fio_mkdir(location, waldir_path, pg_tablespace_mode, false);
938+
err = $i(pioMakeDir, drive, .path = waldir_path,
939+
.mode = pg_tablespace_mode, .strict = false);
940+
if ($haserr(err))
941+
{
942+
elog(ERROR, "Can not create tablespace directory: %s",
943+
$errmsg(err));
944+
}
936945

937946
/* create link to linked_path */
938947
if (fio_symlink(location, waldir_path, to_path, incremental) < 0)
@@ -974,7 +983,13 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba
974983
linked_path, to_path);
975984

976985
/* create tablespace directory */
977-
fio_mkdir(location, linked_path, pg_tablespace_mode, false);
986+
err = $i(pioMakeDir, drive, .path = linked_path,
987+
.mode = pg_tablespace_mode, .strict = false);
988+
if ($haserr(err))
989+
{
990+
elog(ERROR, "Can not create tablespace directory: %s",
991+
$errmsg(err));
992+
}
978993

979994
/* create link to linked_path */
980995
if (fio_symlink(location, linked_path, to_path, incremental) < 0)
@@ -991,8 +1006,13 @@ create_data_directories(parray *dest_files, const char *data_dir, const char *ba
9911006

9921007
join_path_components(to_path, data_dir, dir->rel_path);
9931008

994-
// TODO check exit code
995-
fio_mkdir(location, to_path, dir->mode, false);
1009+
err = $i(pioMakeDir, drive, .path = to_path, .mode = dir->mode,
1010+
.strict = false);
1011+
if ($haserr(err))
1012+
{
1013+
elog(ERROR, "Can not create tablespace directory: %s",
1014+
$errmsg(err));
1015+
}
9961016
}
9971017

9981018
if (extract_tablespaces)

src/init.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
int
1919
do_init(CatalogState *catalogState)
2020
{
21+
pioDrive_i backup_location = pioDriveForLocation(FIO_BACKUP_HOST);
2122
int results;
23+
err_i err;
2224

2325
results = pg_check_dir(catalogState->catalog_path);
2426

@@ -32,13 +34,31 @@ do_init(CatalogState *catalogState)
3234
}
3335

3436
/* create backup catalog root directory */
35-
fio_mkdir(FIO_BACKUP_HOST, catalogState->catalog_path, DIR_PERMISSION, false);
37+
err = $i(pioMakeDir, backup_location, .path = catalogState->catalog_path,
38+
.mode = DIR_PERMISSION, .strict = false);
39+
if ($haserr(err))
40+
{
41+
elog(ERROR, "Can not create backup catalog root directory: %s",
42+
$errmsg(err));
43+
}
3644

3745
/* create backup catalog data directory */
38-
fio_mkdir(FIO_BACKUP_HOST, catalogState->backup_subdir_path, DIR_PERMISSION, false);
46+
err = $i(pioMakeDir, backup_location, .path = catalogState->backup_subdir_path,
47+
.mode = DIR_PERMISSION, .strict = false);
48+
if ($haserr(err))
49+
{
50+
elog(ERROR, "Can not create backup catalog data directory: %s",
51+
$errmsg(err));
52+
}
3953

4054
/* create backup catalog wal directory */
41-
fio_mkdir(FIO_BACKUP_HOST, catalogState->wal_subdir_path, DIR_PERMISSION, false);
55+
err = $i(pioMakeDir, backup_location, .path = catalogState->wal_subdir_path,
56+
.mode = DIR_PERMISSION, .strict = false);
57+
if ($haserr(err))
58+
{
59+
elog(ERROR, "Can not create backup catalog WAL directory: %s",
60+
$errmsg(err));
61+
}
4262

4363
elog(INFO, "Backup catalog '%s' successfully inited", catalogState->catalog_path);
4464
return 0;
@@ -47,8 +67,10 @@ do_init(CatalogState *catalogState)
4767
int
4868
do_add_instance(InstanceState *instanceState, InstanceConfig *instance)
4969
{
70+
pioDrive_i backup_location = pioDriveForLocation(FIO_BACKUP_HOST);
5071
struct stat st;
5172
CatalogState *catalogState = instanceState->catalog_state;
73+
err_i err;
5274

5375
/* PGDATA is always required */
5476
if (instance->pgdata == NULL)
@@ -85,8 +107,19 @@ do_add_instance(InstanceState *instanceState, InstanceConfig *instance)
85107
instanceState->instance_name, instanceState->instance_wal_subdir_path);
86108

87109
/* Create directory for data files of this specific instance */
88-
fio_mkdir(FIO_BACKUP_HOST, instanceState->instance_backup_subdir_path, DIR_PERMISSION, false);
89-
fio_mkdir(FIO_BACKUP_HOST, instanceState->instance_wal_subdir_path, DIR_PERMISSION, false);
110+
err = $i(pioMakeDir, backup_location, .path = instanceState->instance_backup_subdir_path,
111+
.mode = DIR_PERMISSION, .strict = false);
112+
if ($haserr(err))
113+
{
114+
elog(ERROR, "Can not create instance backup directory: %s",
115+
$errmsg(err));
116+
}
117+
err = $i(pioMakeDir, backup_location, .path = instanceState->instance_wal_subdir_path,
118+
.mode = DIR_PERMISSION, .strict = false);
119+
if ($haserr(err))
120+
{
121+
elog(ERROR, "Can not create instance WAL directory: %s", $errmsg(err));
122+
}
90123

91124
/*
92125
* Write initial configuration file.

src/merge.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,8 @@ merge_chain(InstanceState *instanceState,
461461
/* in-place merge flags */
462462
bool compression_match = false;
463463
bool program_version_match = false;
464+
err_i err = $noerr();
465+
464466
/* It's redundant to check block checksumms during merge */
465467
skip_block_validation = true;
466468

@@ -645,7 +647,13 @@ merge_chain(InstanceState *instanceState,
645647
makeExternalDirPathByNum(new_container, full_external_prefix,
646648
file->external_dir_num);
647649
join_path_components(dirpath, new_container, file->rel_path);
648-
fio_mkdir(FIO_BACKUP_HOST, dirpath, DIR_PERMISSION, false);
650+
err = $i(pioMakeDir, dest_backup->backup_location, .path = dirpath,
651+
.mode = DIR_PERMISSION, .strict = false);
652+
if ($haserr(err))
653+
{
654+
elog(ERROR, "Can not create backup external directory: %s",
655+
$errmsg(err));
656+
}
649657
}
650658

651659
pg_atomic_init_flag(&file->lock);

src/pg_probackup.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ main(int argc, char *argv[])
294294

295295
ft_init_log(elog_ft_log);
296296
fobj_init();
297+
FOBJ_FUNC_ARP();
297298
init_pio_objects();
298299

299300
PROGRAM_NAME_FULL = argv[0];

src/pg_probackup.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,9 @@ struct pgBackup
488488

489489
/* map used for access to page headers */
490490
HeaderMap hdr_map;
491+
492+
pioDrive_i database_location; /* Where to backup from/restore to */
493+
pioDrive_i backup_location; /* Where to save to/read from */
491494
};
492495

493496
/* Recovery target for restore and validate subcommands */

0 commit comments

Comments
 (0)