You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudberry.apache.org by ch...@apache.org on 2025/10/31 15:05:56 UTC

(cloudberry) branch cbdb-postgres-merge updated: Fix tablespace without location

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 b79cc5443ba Fix tablespace without location
b79cc5443ba is described below

commit b79cc5443ba81a2d3bd895bda8ff528c4bf08761
Author: Jinbao Chen <ch...@gmail.com>
AuthorDate: Fri Oct 31 23:05:39 2025 +0800

    Fix tablespace without location
---
 src/backend/commands/tablespace.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/src/backend/commands/tablespace.c b/src/backend/commands/tablespace.c
index 1ad7c6a8f70..a8674513b86 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -328,7 +328,12 @@ CreateTableSpace(CreateTableSpaceStmt *stmt)
 	}
 
 	if (!location)
+	{
+		if (stmt->location == NULL)
+			stmt->location = "";
+
 		location = pstrdup(stmt->location);
+	}
 
 	if (stmt->filehandler)
 		fileHandler = pstrdup(stmt->filehandler);
@@ -843,8 +848,10 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
 	elog(DEBUG5, "creating tablespace directories for tablespaceoid %d on dbid %d",
 		tablespaceoid, GpIdentity.dbid);
 
+	in_place = strlen(location) == 0;
+
 	linkloc = psprintf("pg_tblspc/%u", tablespaceoid);
-	location_with_dbid_dir = psprintf("%s/%d", location, GpIdentity.dbid);
+	location_with_dbid_dir = psprintf("%s/%d", in_place ? linkloc : location, GpIdentity.dbid);
 	location_with_version_dir = psprintf("%s/%s", location_with_dbid_dir,
 										 GP_TABLESPACE_VERSION_DIRECTORY);
 	in_place = strlen(location) == 0;
@@ -884,11 +891,11 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
 					(errcode_for_file_access(),
 					 errmsg("could not stat directory \"%s\": %m",
 							location_with_version_dir)));
-		else if (MakePGDirectory(location_with_version_dir) < 0)
+		else if (pg_mkdir_p(location_with_version_dir, S_IRWXU) < 0)
 			ereport(ERROR,
 					(errcode_for_file_access(),
-						errmsg("could not stat directory \"%s\": %m", location_with_dbid_dir)));
-
+					 errmsg("could not create directory \"%s\": %m",
+							location_with_version_dir)));
 	}
 	else if (!S_ISDIR(st.st_mode))
 		ereport(ERROR,
@@ -910,7 +917,7 @@ create_tablespace_directories(const char *location, const Oid tablespaceoid)
 	/*
 	 * Create the symlink under PGDATA
 	 */
-	if (symlink(location_with_dbid_dir, linkloc) < 0)
+	if (!in_place && symlink(location_with_dbid_dir, linkloc) < 0)
 		ereport(ERROR,
 				(errcode_for_file_access(),
 				 errmsg("could not create symbolic link \"%s\": %m",


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cloudberry.apache.org
For additional commands, e-mail: commits-help@cloudberry.apache.org