Use correct path for tablspaces while creating a basebackup
authorPavan Deolasee <[email protected]>
Fri, 3 Aug 2018 08:39:12 +0000 (14:09 +0530)
committerPavan Deolasee <[email protected]>
Fri, 10 Aug 2018 05:38:13 +0000 (11:08 +0530)
In XL, we embed the nodename in the tablespace subdir name to ensure that
non-conflicting paths are created when multiple coordinators/datanodes are
running on the same server. The code to handle tablespace mapping in basebackup
was missing this support.

Per report and patch by Wanglin.

src/backend/replication/basebackup.c

index b7d732a7d8f1db9fce2c0a2814fc10e6f7f12117..142952a95c3e03efbf69ba343aaa905fad803f87 100644 (file)
@@ -833,14 +833,17 @@ sendTablespace(char *path, bool sizeonly)
 {
        int64           size;
        char            pathbuf[MAXPGPATH];
+       char            subdirbuf[MAXPGPATH];
        struct stat statbuf;
 
        /*
         * 'path' points to the tablespace location, but we only want to include
         * the version directory in it that belongs to us.
         */
-       snprintf(pathbuf, sizeof(pathbuf), "%s/%s", path,
-                        TABLESPACE_VERSION_DIRECTORY);
+       snprintf(subdirbuf, sizeof(subdirbuf), "%s_%s",
+                       TABLESPACE_VERSION_DIRECTORY, PGXCNodeName);
+       snprintf(pathbuf, sizeof(pathbuf), "%s/%s_%s", path,
+                       TABLESPACE_VERSION_DIRECTORY, PGXCNodeName);
 
        /*
         * Store a directory entry in the tar file so we get the permissions
@@ -858,7 +861,7 @@ sendTablespace(char *path, bool sizeonly)
                return 0;
        }
        if (!sizeonly)
-               _tarWriteHeader(TABLESPACE_VERSION_DIRECTORY, NULL, &statbuf);
+               _tarWriteHeader(subdirbuf, NULL, &statbuf);
        size = 512;                                     /* Size of the header just added */
 
        /* Send all the files in the tablespace version directory */