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 f51f513b7d1 Make correct path for internal tablespace
f51f513b7d1 is described below
commit f51f513b7d160bd5c10fa7c1d6988118c0bd598f
Author: Jinbao Chen <[email protected]>
AuthorDate: Sun Dec 21 02:35:27 2025 +0800
Make correct path for internal tablespace
---
src/backend/commands/tablespace.c | 39 ++++++++++++++++++++++++++++++++++++---
src/common/relpath.c | 4 ++--
2 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/src/backend/commands/tablespace.c
b/src/backend/commands/tablespace.c
index 8224b67f135..c9fbea7b895 100644
--- a/src/backend/commands/tablespace.c
+++ b/src/backend/commands/tablespace.c
@@ -848,13 +848,21 @@ create_tablespace_directories(const char *location, const
Oid tablespaceoid)
elog(DEBUG5, "creating tablespace directories for tablespaceoid %d on
dbid %d",
tablespaceoid, GpIdentity.dbid);
+ linkloc = psprintf("pg_tblspc/%u", tablespaceoid);
+
+ /*
+ * If we're asked to make an 'in place' tablespace, create the directory
+ * directly where the symlink would normally go. This is a
developer-only
+ * option for now, to facilitate regression testing.
+ */
in_place = strlen(location) == 0;
+ if (in_place)
+ location_with_dbid_dir = psprintf("%s", linkloc);
+ else
+ location_with_dbid_dir = psprintf("%s/%d", location,
GpIdentity.dbid);
- linkloc = psprintf("pg_tblspc/%u", tablespaceoid);
- 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;
/*
* Attempt to coerce target directory to safe permissions. If this
fails,
@@ -877,6 +885,31 @@ create_tablespace_directories(const char *location, const
Oid tablespaceoid)
location)));
}
+ /*
+ * In GPDB each segment has a directory with its unique dbid under the
+ * tablespace path. Unlike the location_with_version_dir, do not error
out
+ * if it already exists.
+ */
+ if (!in_place && stat(location_with_dbid_dir, &st) < 0)
+ {
+ if (errno == ENOENT)
+ {
+ if (mkdir(location_with_dbid_dir, S_IRWXU) < 0)
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could
not create directory \"%s\": %m", location_with_dbid_dir)));
+ }
+ else
+ ereport(ERROR,
+ (errcode_for_file_access(),
+ errmsg("could not stat
directory \"%s\": %m", location_with_dbid_dir)));
+
+ }
+ else
+ ereport(DEBUG1,
+ (errmsg("directory \"%s\" already exists in
tablespace",
+ location_with_dbid_dir)));
+
/*
* The creation of the version directory prevents more than one
tablespace
* in a single location. This imitates TablespaceCreateDbspace(), but
it
diff --git a/src/common/relpath.c b/src/common/relpath.c
index a4d9691e0d4..f1937dc39b6 100644
--- a/src/common/relpath.c
+++ b/src/common/relpath.c
@@ -124,8 +124,8 @@ GetDatabasePath(Oid dbOid, Oid spcOid)
else
{
/* All other tablespaces are accessed via symlinks */
- return psprintf("pg_tblspc/%u/%d/%s/%u",
- spcOid, GpIdentity.dbid,
GP_TABLESPACE_VERSION_DIRECTORY, dbOid);
+ return psprintf("pg_tblspc/%u/%s/%u",
+ spcOid,
GP_TABLESPACE_VERSION_DIRECTORY, dbOid);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]