8000 Fix pg_rewind to handle relation data files in tablespaces properly. · itsmadness55/postgres@7aba4f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7aba4f2

Browse files
committed
Fix pg_rewind to handle relation data files in tablespaces properly.
pg_rewind checks whether each file is a relation data file, from its path. Previously this check logic had the bug which made pg_rewind fail to recognize any relation data files in tablespaces. Which also caused an assertion failure in pg_rewind. Back-patch to 9.5 where pg_rewind was added. Author: Takayuki Tsunakawa Reviewed-by: Michael Paquier Discussion: https://postgr.es/m/0A3221C70F24FB45833433255569204D1F8D6C7A@G01JPEXMBYT05
1 parent e2108f5 commit 7aba4f2

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/bin/pg_rewind/filemap.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "pg_rewind.h"
2121

2222
#include "common/string.h"
23+
#include "catalog/catalog.h"
2324
#include "catalog/pg_tablespace.h"
2425
#include "storage/fd.h"
2526

@@ -555,7 +556,6 @@ print_filemap(void)
555556
static bool
556557
isRelDataFile(const char *path)
557558
{
558-
char buf[20 + 1];
559559
RelFileNode rnode;
560560
unsigned int segNo;
561561
int nmatch;
@@ -570,7 +570,7 @@ isRelDataFile(const char *path)
570570
* base/<db oid>/
571571
* regular relations, default tablespace
572572
*
573-
* pg_tblspc/<tblspc oid>/PG_9.4_201403261/
573+
* pg_tblspc/<tblspc oid>/<tblspc version>/
574574
* within a non-default tablespace (the name of the directory
575575
* depends on version)
576576
*
@@ -604,21 +604,19 @@ isRelDataFile(const char *path)
604604
}
605605
else
606606
{
607-
nmatch = sscanf(path, "pg_tblspc/%u/PG_%20s/%u/%u.%u",
608-
&rnode.spcNode, buf, &rnode.dbNode, &rnode.relNode,
607+
nmatch = sscanf(path, "pg_tblspc/%u/" TABLESPACE_VERSION_DIRECTORY "/%u/%u.%u",
608+
&rnode.spcNode, &rnode.dbNode, &rnode.relNode,
609609
&segNo);
610-
if (nmatch == 4 || nmatch == 5)
610+
if (nmatch == 3 || nmatch == 4)
611611
matched = true;
612612
}
613613
}
614614

615615
/*
616616
* The sscanf tests above can match files that have extra characters at
617-
* the end, and the last check can also match a path belonging to a
618-
* different version (different TABLESPACE_VERSION_DIRECTORY). To make
619-
* eliminate such cases, cross-check that GetRelationPath creates the
620-
* exact same filename, when passed the RelFileNode information we
621-
* extracted from the filename.
617+
* the end. To eliminate such cases, cross-check that GetRelationPath
618+
* creates the exact same filename, when passed the RelFileNode information
619+
* we extracted from the filename.
622620
*/
623621
if (matched)
624622
{

0 commit comments

Comments
 (0)
0