This is an automated email from the ASF dual-hosted git repository.

chenjinbao1989 pushed a commit to branch cbdb-postgres-merge
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/cbdb-postgres-merge by this 
push:
     new f22d1cf25d0 Remove the dbid on the return of BASHBACKUP
f22d1cf25d0 is described below

commit f22d1cf25d018a437e445796cad5b53476e121a9
Author: Jinbao Chen <[email protected]>
AuthorDate: Thu Feb 5 09:41:12 2026 +0800

    Remove the dbid on the return of BASHBACKUP
---
 src/backend/backup/basebackup_copy.c  | 31 +++++++++++++++++++++++++++++--
 src/bin/pg_basebackup/pg_basebackup.c | 21 ++++++++++++++++++---
 2 files changed, 47 insertions(+), 5 deletions(-)

diff --git a/src/backend/backup/basebackup_copy.c 
b/src/backend/backup/basebackup_copy.c
index 1db80cde1b2..9eac60257f9 100644
--- a/src/backend/backup/basebackup_copy.c
+++ b/src/backend/backup/basebackup_copy.c
@@ -167,12 +167,24 @@ bbsink_copystream_begin_archive(bbsink *sink, const char 
*archive_name)
        bbsink_state *state = sink->bbs_state;
        tablespaceinfo *ti;
        StringInfoData buf;
+       char *link_path_to_be_sent;
 
        ti = list_nth(state->tablespaces, state->tablespace_num);
        pq_beginmessage(&buf, 'd'); /* CopyData */
        pq_sendbyte(&buf, 'n');         /* New archive */
        pq_sendstring(&buf, archive_name);
-       pq_sendstring(&buf, ti->path == NULL ? "" : ti->path);
+       if(ti->rpath == NULL && ti->path)
+       {
+               /* Lop off the dbid before sending the link target. */
+               char *link_path_without_dbid = pstrdup(ti->path);
+               char *file_sep_before_dbid_in_link_path =
+                               strrchr(link_path_without_dbid, '/');
+               *file_sep_before_dbid_in_link_path = '\0';
+               link_path_to_be_sent = link_path_without_dbid;
+       }
+       else
+               link_path_to_be_sent = ti->path;
+       pq_sendstring(&buf, ti->path == NULL ? "" : link_path_to_be_sent);
        pq_endmessage(&buf);
 }
 
@@ -407,8 +419,23 @@ SendTablespaceList(List *tablespaces)
                }
                else
                {
+                       char            *link_path_to_be_sent;
+
                        values[0] = ObjectIdGetDatum(strtoul(ti->oid, NULL, 
10));
-                       values[1] = CStringGetTextDatum(ti->path);
+
+                       if(ti->rpath == NULL && ti->path)
+                       {
+                               /* Lop off the dbid before sending the link 
target. */
+                               char *link_path_without_dbid = 
pstrdup(ti->path);
+                               char *file_sep_before_dbid_in_link_path =
+                                               strrchr(link_path_without_dbid, 
'/');
+                               *file_sep_before_dbid_in_link_path = '\0';
+                               link_path_to_be_sent = link_path_without_dbid;
+                       }
+                       else
+                               link_path_to_be_sent = ti->path;
+
+                       values[1] = CStringGetTextDatum(link_path_to_be_sent);
                }
                if (ti->size >= 0)
                        values[2] = Int64GetDatum(ti->size / 1024);
diff --git a/src/bin/pg_basebackup/pg_basebackup.c 
b/src/bin/pg_basebackup/pg_basebackup.c
index d6ed714c506..47ee928a758 100644
--- a/src/bin/pg_basebackup/pg_basebackup.c
+++ b/src/bin/pg_basebackup/pg_basebackup.c
@@ -1156,9 +1156,23 @@ CreateBackupStreamer(char *archive_name, char 
*spclocation,
                if (spclocation == NULL)
                        directory = basedir;
                else if (!is_absolute_path(spclocation))
-                       directory = psprintf("%s/%s", basedir, spclocation);
+               {
+                       if (target_gp_dbid < 1)
+                       {
+                               pg_log_error("cannot restore user-defined 
tablespaces without the --target-gp-dbid option");
+                               exit(1);
+                       }
+                       directory = psprintf("%s/%s/%d", basedir, spclocation, 
target_gp_dbid);
+               }
                else
-                       directory = get_tablespace_mapping(spclocation);
+               {
+                       if (target_gp_dbid < 1)
+                       {
+                               pg_log_error("cannot restore user-defined 
tablespaces without the --target-gp-dbid option");
+                               exit(1);
+                       }
+                       directory = psprintf("%s/%d", spclocation, 
target_gp_dbid);
+               }
                streamer = bbstreamer_extractor_new(directory,
                                                                                
        get_tablespace_mapping,
                                                                                
        progress_update_filename);
@@ -2066,11 +2080,12 @@ BaseBackup(char *compression_algorithm, char 
*compression_detail,
                 * won't be storing anything into these directories and thus 
should
                 * not create them.
                 */
+//             sleep(30);
                if (backup_target == NULL && format == 'p' && !PQgetisnull(res, 
i, 1))
                {
                        char path_with_subdir[MAXPGPATH];
                        char       *path = PQgetvalue(res, i, 1);
-
+                       
                        if (is_absolute_path(path))
                                path = unconstify(char *, 
get_tablespace_mapping(path));
                        else


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to