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

maxyang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudberry.git


The following commit(s) were added to refs/heads/main by this push:
     new e601fb6a1d Change directory table directory's file path from 
relfilenode to relid.
e601fb6a1d is described below

commit e601fb6a1d3fdf28bad259a851f778f161f02a5e
Author: zhangwenchao <[email protected]>
AuthorDate: Fri Jun 6 14:14:30 2025 +0800

    Change directory table directory's file path from relfilenode to relid.
    
    At first, we use relfilenode to construct the directory table's
    directory path. However, relfilenode may be different between QD and
    QE, this will cause the directory table's file paths are different which
    will be confused in using. As a result, we will use relid that is same
    between QD and QE to construct the directory table's file path in this
    commit.
    
    Authored-by: Zhang Wenchao [email protected]
---
 src/backend/commands/dirtablecmds.c | 11 +----------
 src/backend/storage/file/ufile.c    | 12 ++++++------
 src/include/storage/ufile.h         |  4 ++--
 3 files changed, 9 insertions(+), 18 deletions(-)

diff --git a/src/backend/commands/dirtablecmds.c 
b/src/backend/commands/dirtablecmds.c
index 6f3bd94285..7f34d46943 100644
--- a/src/backend/commands/dirtablecmds.c
+++ b/src/backend/commands/dirtablecmds.c
@@ -136,21 +136,12 @@ CreateDirectoryTable(CreateDirectoryTableStmt *stmt, Oid 
relId)
        }
        else
        {
-               Form_pg_class pg_class_tuple = NULL;
-               HeapTuple       class_tuple = NULL;
                RelFileNode relFileNode = {0};
 
-               class_tuple = SearchSysCache1(RELOID, ObjectIdGetDatum(relId));
-               if (!HeapTupleIsValid(class_tuple))
-                       elog(ERROR, "cache lookup failed for relation %u", 
relId);
-               pg_class_tuple = (Form_pg_class) GETSTRUCT(class_tuple);
-
                relFileNode.spcNode = spcId;
                relFileNode.dbNode = MyDatabaseId;
-               relFileNode.relNode = pg_class_tuple->relfilenode;
 
-               dirTablePath = UFileFormatPathName(&relFileNode);
-               ReleaseSysCache(class_tuple);
+               dirTablePath = UFileFormatPathName(relId, &relFileNode);
        }
 
        /*
diff --git a/src/backend/storage/file/ufile.c b/src/backend/storage/file/ufile.c
index 0c1ba28b99..0938a1bd83 100644
--- a/src/backend/storage/file/ufile.c
+++ b/src/backend/storage/file/ufile.c
@@ -59,7 +59,7 @@ static int localFileRead(UFile *file, char *buffer, int 
amount);
 static int localFileWrite(UFile *file, char *buffer, int amount);
 static off_t localFileSize(UFile *file);
 static void localFileUnlink(Oid spcId, const char *fileName);
-static char *localFormatPathName(RelFileNode *relFileNode);
+static char *localFormatPathName(Oid relid, RelFileNode *relFileNode);
 static bool localEnsurePath(Oid spcId, const char *PathName);
 static bool localFileExists(Oid spcId, const char *fileName);
 static const char *localFileName(UFile *file);
@@ -307,15 +307,15 @@ localFileUnlink(Oid spcId, const char *fileName)
 }
 
 static char *
-localFormatPathName(RelFileNode *relFileNode)
+localFormatPathName(Oid relid, RelFileNode *relFileNode)
 {
        if (relFileNode->spcNode == DEFAULTTABLESPACE_OID)
                return psprintf("base/%u/%u_dirtable",
-                                               relFileNode->dbNode, 
relFileNode->relNode);
+                                               relFileNode->dbNode, relid);
        else
                return psprintf("pg_tblspc/%u/%s/%u/%u_dirtable",
                                                relFileNode->spcNode, 
GP_TABLESPACE_VERSION_DIRECTORY,
-                                               relFileNode->dbNode, 
relFileNode->relNode);
+                                               relFileNode->dbNode, relid);
 }
 
 bool
@@ -440,13 +440,13 @@ UFileUnlink(Oid spcId, const char *fileName)
 }
 
 char *
-UFileFormatPathName(RelFileNode *relFileNode)
+UFileFormatPathName(Oid relid, RelFileNode *relFileNode)
 {
        FileAm *fileAm;
 
        fileAm = GetTablespaceFileHandler(relFileNode->spcNode);
 
-       return fileAm->formatPathName(relFileNode);
+       return fileAm->formatPathName(relid, relFileNode);
 }
 
 bool
diff --git a/src/include/storage/ufile.h b/src/include/storage/ufile.h
index e34d66350c..7e66196c04 100644
--- a/src/include/storage/ufile.h
+++ b/src/include/storage/ufile.h
@@ -44,7 +44,7 @@ typedef struct FileAm
        int (*write) (struct UFile *file, char *buffer, int amount);
        int64_t (*size) (struct UFile *file);
        void (*unlink) (Oid spcId, const char *fileName);
-       char* (*formatPathName) (RelFileNode *relFileNode);
+       char* (*formatPathName) (Oid relid, RelFileNode *relFileNode);
        bool (*ensurePath) (Oid spcId, const char *pathName);
        bool (*exists) (Oid spcId, const char *fileName);
        const char *(*name) (struct UFile *file);
@@ -72,7 +72,7 @@ extern off_t UFileSize(UFile *file);
 extern const char *UFileName(UFile *file);
 
 extern void UFileUnlink(Oid spcId, const char *fileName);
-extern char* UFileFormatPathName(RelFileNode *relFileNode);
+extern char* UFileFormatPathName(Oid relid, RelFileNode *relFileNode);
 extern bool UFileEnsurePath(Oid spcId, const char *pathName);
 extern bool UFileExists(Oid spcId, const char *fileName);
 


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

Reply via email to