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, 3 Aug 2018 08:42:42 +0000 (14:12 +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 9776858f0321e6b2908a23b3cc88db5ec1aff428..ee9e3686b78c9e160eecc89139c08ad306638c2d 100644 (file)
@@ -907,14 +907,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
@@ -932,8 +935,7 @@ sendTablespace(char *path, bool sizeonly)
                return 0;
        }
 
-       size = _tarWriteHeader(TABLESPACE_VERSION_DIRECTORY, NULL, &statbuf,
-                                                  sizeonly);
+       size = _tarWriteHeader(subdirbuf, NULL, &statbuf, sizeonly);
 
        /* Send all the files in the tablespace version directory */
        size += sendDir(pathbuf, strlen(path), sizeonly, NIL, true);