Skip to content

Commit 59715f2

Browse files
committed
Merge branch 'release_2_4' into issue_205
2 parents 70b9e15 + 0f58b2d commit 59715f2

File tree

9 files changed

+255
-281
lines changed

9 files changed

+255
-281
lines changed

doc/pgprobackup.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4055,10 +4055,10 @@ pg_probackup archive-push -B <replaceable>backup_dir</replaceable> --instance <r
40554055
corruption.
40564056
</para>
40574057
<para>
4058-
To speed up archiving, you can specify the <option>-j</option> option
4059-
to run <command>archive-push</command> on multiple threads.
4060-
If you provide the <option>--batch-size</option> option, WAL files
4061-
will be copied in batches of the specified size.
4058+
To speed up archiving, you can specify the <option>--batch-size</option> option
4059+
to copy WAL segments in batches of the specified size.
4060+
If <option>--batch-size</option> option is used, then you can also specify
4061+
the <option>-j</option> option to copy the batch of WAL segments on multiple threads.
40624062
</para>
40634063
<para>
40644064
WAL segments copied to the archive are synced to disk unless
@@ -4096,10 +4096,10 @@ pg_probackup archive-get -B <replaceable>backup_dir</replaceable> --instance <re
40964096
</para>
40974097

40984098
<para>
4099-
To speed up recovery, you can specify the <option>-j</option> option
4100-
to run <command>archive-get</command> on multiple threads.
4101-
If you provide the <option>--batch-size</option> option, WAL segments
4102-
will be copied in batches of the specified size.
4099+
To speed up recovery, you can specify the <option>--batch-size</option> option
4100+
to copy WAL segments in batches of the specified size.
4101+
If <option>--batch-size</option> option is used, then you can also specify
4102+
the <option>-j</option> option to copy the batch of WAL segments on multiple threads.
41034103
</para>
41044104

41054105
<para>

src/archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ do_archive_get(InstanceConfig *instance, const char *prefetch_dir_arg,
11091109
{
11101110
/* discard prefetch */
11111111
// n_fetched = 0;
1112-
rmtree(prefetch_dir, false);
1112+
pgut_rmtree(prefetch_dir, false, false);
11131113
}
11141114
}
11151115
else

src/backup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ do_backup_instance(PGconn *backup_conn, PGNodeInfo *nodeInfo, bool no_sync, bool
191191
{
192192
/* try to setup multi-timeline backup chain */
193193
elog(WARNING, "Valid backup on current timeline %u is not found, "
194-
"try to look up on previous timelines",
194+
"trying to look up on previous timelines",
195195
current.tli);
196196

197197
tli_list = catalog_get_timelines(&instance_config);

src/delete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ do_delete_instance(void)
985985
parray_free(backup_list);
986986

987987
/* Delete all wal files. */
988-
rmtree(arclog_path, false);
988+
pgut_rmtree(arclog_path, false, true);
989989

990990
/* Delete backup instance config file */
991991
join_path_components(instance_config_path, backup_instance_path, BACKUP_CATALOG_CONF_FILE);

src/pg_probackup.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,8 @@ extern int fio_send_file(const char *from_fullpath, const char *to_fullpath, FIL
10381038
extern void fio_list_dir(parray *files, const char *root, bool exclude, bool follow_symlink,
10391039
bool add_root, bool backup_logs, int external_dir_num);
10401040

1041+
extern bool pgut_rmtree(const char *path, bool rmtopdir, bool strict);
1042+
10411043
/* return codes for fio_send_pages() and fio_send_file() */
10421044
#define SEND_OK (0)
10431045
#define FILE_MISSING (-1)

src/utils/pgut.c

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ static void on_interrupt(void);
4343
static void on_cleanup(void);
4444
static pqsigfunc oldhandler = NULL;
4545

46+
static char ** pgut_pgfnames(const char *path, bool strict);
47+
static void pgut_pgfnames_cleanup(char **filenames);
48+
4649
void discard_response(PGconn *conn);
4750

4851
void
@@ -1062,3 +1065,140 @@ discard_response(PGconn *conn)
10621065
PQclear(res);
10631066
} while (res);
10641067
}
1068+
1069+
/*
1070+
* pgfnames
1071+
*
1072+
* return a list of the names of objects in the argument directory. Caller
1073+
* must call pgfnames_cleanup later to free the memory allocated by this
1074+
* function.
1075+
*/
1076+
char **
1077+
pgut_pgfnames(const char *path, bool strict)
1078+
{
1079+
DIR *dir;
1080+
struct dirent *file;
1081+
char **filenames;
1082+
int numnames = 0;
1083+
int fnsize = 200; /* enough for many small dbs */
1084+
1085+
dir = opendir(path);
1086+
if (dir == NULL)
1087+
{
1088+
elog(strict ? ERROR : WARNING, "could not open directory \"%s\": %m", path);
1089+
return NULL;
1090+
}
1091+
1092+
filenames = (char **) palloc(fnsize * sizeof(char *));
1093+
1094+
while (errno = 0, (file = readdir(dir)) != NULL)
1095+
{
1096+
if (strcmp(file->d_name, ".") != 0 && strcmp(file->d_name, "..") != 0)
1097+
{
1098+
if (numnames + 1 >= fnsize)
1099+
{
1100+
fnsize *= 2;
1101+
filenames = (char **) repalloc(filenames,
1102+
fnsize * sizeof(char *));
1103+
}
1104+
filenames[numnames++] = pstrdup(file->d_name);
1105+
}
1106+
}
1107+
1108+
if (errno)
1109+
{
1110+
elog(strict ? ERROR : WARNING, "could not read directory \"%s\": %m", path);
1111+
return NULL;
1112+
}
1113+
1114+
filenames[numnames] = NULL;
1115+
1116+
if (closedir(dir))
1117+
{
1118+
elog(strict ? ERROR : WARNING, "could not close directory \"%s\": %m", path);
1119+
return NULL;
1120+
}
1121+
1122+
return filenames;
1123+
}
1124+
1125+
/*
1126+
* pgfnames_cleanup
1127+
*
1128+
* deallocate memory used for filenames
1129+
*/
1130+
void
1131+
pgut_pgfnames_cleanup(char **filenames)
1132+
{
1133+
char **fn;
1134+
1135+
for (fn = filenames; *fn; fn++)
1136+
pfree(*fn);
1137+
1138+
pfree(filenames);
1139+
}
1140+
1141+
/* Shamelessly stolen from commom/rmtree.c */
1142+
bool
1143+
pgut_rmtree(const char *path, bool rmtopdir, bool strict)
1144+
{
1145+
bool result = true;
1146+
char pathbuf[MAXPGPATH];
1147+
char **filenames;
1148+
char **filename;
1149+
struct stat statbuf;
1150+
1151+
/*
1152+
* we copy all the names out of the directory before we start modifying
1153+
* it.
1154+
*/
1155+
filenames = pgut_pgfnames(path, strict);
1156+
1157+
if (filenames == NULL)
1158+
return false;
1159+
1160+
/* now we have the names we can start removing things */
1161+
for (filename = filenames; *filename; filename++)
1162+
{
1163+
snprintf(pathbuf, MAXPGPATH, "%s/%s", path, *filename);
1164+
1165+
if (lstat(pathbuf, &statbuf) != 0)
1166+
{
1167+
elog(strict ? ERROR : WARNING, "could not stat file or directory \"%s\": %m", pathbuf);
1168+
result = false;
1169+
break;
1170+
}
1171+
1172+
if (S_ISDIR(statbuf.st_mode))
1173+
{
1174+
/* call ourselves recursively for a directory */
1175+
if (!pgut_rmtree(pathbuf, true, strict))
1176+
{
1177+
result = false;
1178+
break;
1179+
}
1180+
}
1181+
else
1182+
{
1183+
if (unlink(pathbuf) != 0)
1184+
{
1185+
elog(strict ? ERROR : WARNING, "could not remove file or directory \"%s\": %m", pathbuf);
1186+
result = false;
1187+
break;
1188+
}
1189+
}
1190+
}
1191+
1192+
if (rmtopdir)
1193+
{
1194+
if (rmdir(path) != 0)
1195+
{
1196+
elog(strict ? ERROR : WARNING, "could not remove file or directory \"%s\": %m", path);
1197+
result = false;
1198+
}
1199+
}
1200+
1201+
pgut_pgfnames_cleanup(filenames);
1202+
1203+
return result;
1204+
}

0 commit comments

Comments
 (0)