Move the only function defined in util.c/util.h to where it's used.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 9 Jan 2015 09:08:23 +0000 (11:08 +0200)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Fri, 16 Jan 2015 11:37:07 +0000 (13:37 +0200)
contrib/pg_rewind/Makefile
contrib/pg_rewind/copy_fetch.c
contrib/pg_rewind/datapagemap.c
contrib/pg_rewind/filemap.c
contrib/pg_rewind/pg_rewind.h
contrib/pg_rewind/util.c [deleted file]
contrib/pg_rewind/util.h [deleted file]

index 48a36929b2c7682d57cb7cc6e9ba16cbafdebc2d..0c8b218015714bcb4ced24df8f3196540522bea1 100644 (file)
@@ -7,7 +7,7 @@ PGFILEDESC = "pg_rewind - repurpose an old master server as standby"
 PGAPPICON = win32
 
 PROGRAM = pg_rewind
-OBJS   = pg_rewind.o parsexlog.o xlogreader.o util.o datapagemap.o timeline.o \
+OBJS   = pg_rewind.o parsexlog.o xlogreader.o datapagemap.o timeline.o \
        fetch.o copy_fetch.o libpq_fetch.o filemap.o $(WIN32RES)
 
 PG_CPPFLAGS = -I$(libpq_srcdir)
index 6b0ccc196befa7a8e651ffecd30a873e21fe16e3..4695d0ecac1e87bf0729db4d2b4b611d27ac9c66 100644 (file)
@@ -22,7 +22,6 @@
 #include "fetch.h"
 #include "filemap.h"
 #include "datapagemap.h"
-#include "util.h"
 
 static void recurse_dir(const char *datadir, const char *path,
                        process_file_callback_t callback);
index 235a881a1e57c70c6a91e1ffa24c4444e7411b20..6d76b3ad7d463e980bfd93520c2790b49b28202b 100644 (file)
@@ -13,7 +13,6 @@
 #include "postgres_fe.h"
 
 #include "datapagemap.h"
-#include "util.h"
 
 struct datapagemap_iterator
 {
index 5fac54b3fc3a953ea06ae87f80929f65ff4422a7..41d3c9ef925ea1f582059ab7c75f76bbdbf85c24 100644 (file)
@@ -16,7 +16,6 @@
 
 #include "datapagemap.h"
 #include "filemap.h"
-#include "util.h"
 #include "pg_rewind.h"
 #include "catalog/pg_tablespace.h"
 #include "storage/fd.h"
@@ -24,6 +23,8 @@
 filemap_t *filemap = NULL;
 
 static bool isRelDataFile(const char *path);
+static char *datasegpath(RelFileNode rnode, ForkNumber forknum,
+                       BlockNumber segno);
 static int path_cmp(const void *a, const void *b);
 static int final_filemap_cmp(const void *a, const void *b);
 static void filemap_list_to_array(void);
@@ -497,9 +498,7 @@ static bool
 isRelDataFile(const char *path)
 {
        char            buf[20 + 1];
-       Oid                     spcNode;
-       Oid                     dbNode;
-       Oid                     relNode;
+       RelFileNode     rnode;
        unsigned int segNo;
        int                     nmatch;
        bool            matched;
@@ -520,33 +519,34 @@ isRelDataFile(const char *path)
         * And the relation data files themselves have a filename like:
         *
         * <oid>.<segment number>
-        *
         */
-       spcNode = InvalidOid;
-       dbNode = InvalidOid;
-       relNode = InvalidOid;
+       rnode.spcNode = InvalidOid;
+       rnode.dbNode = InvalidOid;
+       rnode.relNode = InvalidOid;
        segNo = 0;
        matched = false;
 
-       nmatch = sscanf(path, "global/%u.%u", &relNode, &segNo);
+       nmatch = sscanf(path, "global/%u.%u", &rnode.relNode, &segNo);
        if (nmatch == 1 || nmatch == 2)
        {
-               spcNode = GLOBALTABLESPACE_OID;
-               dbNode = 0;
+               rnode.spcNode = GLOBALTABLESPACE_OID;
+               rnode.dbNode = 0;
                matched = true;
        }
        else
        {
-               nmatch = sscanf(path, "base/%u/%u.%u", &dbNode, &relNode, &segNo);
+               nmatch = sscanf(path, "base/%u/%u.%u",
+                                               &rnode.dbNode, &rnode.relNode, &segNo);
                if (nmatch == 2 || nmatch == 3)
                {
-                       spcNode = DEFAULTTABLESPACE_OID;
+                       rnode.spcNode = DEFAULTTABLESPACE_OID;
                        matched = true;
                }
                else
                {
                        nmatch = sscanf(path, "pg_tblspc/%u/PG_%20s/%u/%u.%u",
-                                                       &spcNode, buf, &dbNode, &relNode, &segNo);
+                                                       &rnode.spcNode, buf, &rnode.dbNode, &rnode.relNode,
+                                                       &segNo);
                        if (nmatch == 4 || nmatch == 5)
                                matched = true;
                }
@@ -562,26 +562,37 @@ isRelDataFile(const char *path)
         */
        if (matched)
        {
-               char *check_path;
-               char *check_path_with_seg;
-
-               check_path = GetRelationPath(dbNode, spcNode, relNode, InvalidBackendId,
-                                                                        MAIN_FORKNUM);
-               if (segNo != 0)
-               {
-                       check_path_with_seg = psprintf("%s.%u", check_path, segNo);
-                       pfree(check_path);
-               }
-               else
-                       check_path_with_seg = check_path;
+               char *check_path = datasegpath(rnode, MAIN_FORKNUM, segNo);
 
-               if (strcmp(check_path_with_seg, path) != 0)
+               if (strcmp(check_path, path) != 0)
                        matched = false;
+
+               pfree(check_path);
        }
 
        return matched;
 }
 
+/*
+ * A helper function to create the path of a relation file and segment.
+ *
+ * The returned path is palloc'd
+ */
+static char *
+datasegpath(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
+{
+       char *path = relpathperm(rnode, forknum);
+
+       if (segno > 0)
+       {
+               char *segpath = psprintf("%s.%u", path, segno);
+               pfree(path);
+               return segpath;
+       }
+       else
+               return path;
+}
+
 static int
 path_cmp(const void *a, const void *b)
 {
index d092902632108276918ee49ab258156c64913bc4..5a6dbce05386a9dea80ae02fd77c96e2f6790a46 100644 (file)
@@ -14,7 +14,6 @@
 #include "c.h"
 
 #include "datapagemap.h"
-#include "util.h"
 
 #include "access/timeline.h"
 #include "storage/block.h"
diff --git a/contrib/pg_rewind/util.c b/contrib/pg_rewind/util.c
deleted file mode 100644 (file)
index bb03319..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * util.c
- *             Misc utility functions
- *
- * Copyright (c) 2013-2015, PostgreSQL Global Development Group
- *
- *-------------------------------------------------------------------------
- */
-#include "postgres_fe.h"
-
-#include "common/relpath.h"
-#include "catalog/catalog.h"
-#include "catalog/pg_tablespace.h"
-
-#include "pg_rewind.h"
-
-char *
-datasegpath(RelFileNode rnode, ForkNumber forknum, BlockNumber segno)
-{
-       char *path = relpathperm(rnode, forknum);
-
-       if (segno > 0)
-       {
-               char *segpath = pg_malloc(strlen(path) + 13);
-               sprintf(segpath, "%s.%u", path, segno);
-               pg_free(path);
-               return segpath;
-       }
-       else
-               return path;
-}
diff --git a/contrib/pg_rewind/util.h b/contrib/pg_rewind/util.h
deleted file mode 100644 (file)
index e3d69f8..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*-------------------------------------------------------------------------
- *
- * util.h
- *             Prototypes for functions in util.c
- *
- * Copyright (c) 2013-2015, PostgreSQL Global Development Group
- *-------------------------------------------------------------------------
- */
-#ifndef UTIL_H
-#define UTIL_H
-
-extern char *datasegpath(RelFileNode rnode, ForkNumber forknum,
-           BlockNumber segno);
-
-#endif   /* UTIL_H */