Skip to content

Commit 23924fe

Browse files
committed
Fix handling of missing files when using pg_rewind with online source
When working with an online source cluster, pg_rewind gets a list of all the files in the source data directory using a WITH RECURSIVE query, returning a NULL result for a file's metadata if it gets removed between the moment it is listed in a directory and the moment its metadata is obtained with pg_stat_file() (say a recycled WAL segment). The query result was processed in such a way that for each tuple we checked only that the first file's metadata was NULL. This could have two consequences, both resulting in a failure of the rewind: - If the first tuple referred to a removed file, all files from the source would be ignored. - Any file actually missing would not be considered as such. While on it, rework slightly the code so as no values are saved if we know that a file is going to be skipped. Issue introduced by b36805f, so backpatch down to 9.5. Author: Justin Pryzby, Michael Paquier Reviewed-by: Daniel Gustafsson, Masahiko Sawada Discussion: https://postgr.es/m/20200713061010.GC23581@telsasoft.com Backpatch-through: 9.5
1 parent 4e02f88 commit 23924fe

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/bin/pg_rewind/libpq_fetch.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,13 +220,13 @@ libpqProcessFileList(void)
220220
/* Read result to local variables */
221221
for (i = 0; i < PQntuples(res); i++)
222222
{
223-
char *path = PQgetvalue(res, i, 0);
224-
int64 filesize = atol(PQgetvalue(res, i, 1));
225-
bool isdir = (strcmp(PQgetvalue(res, i, 2), "t") == 0);
226-
char *link_target = PQgetvalue(res, i, 3);
223+
char *path;
224+
int64 filesize;
225+
bool isdir;
226+
char *link_target;
227227
file_type_t type;
228228

229-
if (PQgetisnull(res, 0, 1))
229+
if (PQgetisnull(res, i, 1))
230230
{
231231
/*
232232
* The file was removed from the server while the query was
@@ -235,6 +235,11 @@ libpqProcessFileList(void)
235235
continue;
236236
}
237237

238+
path = PQgetvalue(res, i, 0);
239+
filesize = atol(PQgetvalue(res, i, 1));
240+
isdir = (strcmp(PQgetvalue(res, i, 2), "t") == 0);
241+
link_target = PQgetvalue(res, i, 3);
242+
238243
if (link_target[0])
239244
type = FILE_TYPE_SYMLINK;
240245
else if (isdir)

0 commit comments

Comments
 (0)