提交 a91d1f96 编写于 作者: H Heikki Linnakangas

Replace uses of CopyRelPath with upstream relpath() function.

CopyRelPath() is essentially a copy of relpath(), but it returns the result
in a caller-supplied buffer instead of pallocing. That's redundant, and the
calls are not in performance-critical path, so let's just use relpath() and
get rid of CopyRelPath(). This reduces our diff footprint vs upstream. If
there were upstream changes to relpath(), we would surely forget to make
the same changes to CopyRelPath().
上级 64c84d07
......@@ -189,57 +189,6 @@ relpath(RelFileNode rnode)
return path;
}
void
CopyRelPath(char *target, int targetMaxLen, RelFileNode rnode)
{
int snprintfResult;
if (rnode.spcNode == GLOBALTABLESPACE_OID)
{
/* Shared system relations live in {datadir}/global */
Assert(rnode.dbNode == 0);
snprintfResult =
snprintf(target, targetMaxLen, "global/%u",
rnode.relNode);
}
else if (rnode.spcNode == DEFAULTTABLESPACE_OID)
{
/* The default tablespace is {datadir}/base */
snprintfResult =
snprintf(target, targetMaxLen, "base/%u/%u",
rnode.dbNode, rnode.relNode);
}
else
{
char *primary_path;
/* All other tablespaces are accessed via filespace locations */
GetFilespacePathForTablespace(
rnode.spcNode,
&primary_path);
/* Copy path into the passed in target location */
snprintfResult =
snprintf(target, targetMaxLen, "%s/%u/%u/%u",
primary_path, rnode.spcNode, rnode.dbNode, rnode.relNode);
/* Throw away the allocation we got from persistent layer */
pfree(primary_path);
}
if (snprintfResult < 0)
elog(ERROR, "CopyRelPath formatting error");
/*
* Magically truncating the result to fit in the target string is unacceptable here
* because it can result in the wrong file-system object being referenced.
*/
if (snprintfResult >= targetMaxLen)
elog(ERROR, "CopyRelPath formatting result length %d exceeded the maximum length %d",
snprintfResult,
targetMaxLen);
}
/*
* GetDatabasePath - construct path to a database dir
*
......
......@@ -411,9 +411,9 @@ static void copy_append_only_segment_file(
{
MIRRORED_LOCK_DECLARE;
char *basepath;
char srcFileName[MAXPGPATH];
char dstFileName[MAXPGPATH];
char extension[12];
File srcFile;
......@@ -446,18 +446,12 @@ static void copy_append_only_segment_file(
ItemPointerToString(persistentTid),
eof);
basepath = relpath(*srcRelFileNode);
if (segmentFileNum > 0)
{
sprintf(extension, ".%u", segmentFileNum);
}
snprintf(srcFileName, sizeof(srcFileName), "%s.%u", basepath, segmentFileNum);
else
extension[0] = '\0';
CopyRelPath(srcFileName, MAXPGPATH, *srcRelFileNode);
if (segmentFileNum > 0)
{
strcat(srcFileName, extension);
}
snprintf(srcFileName, sizeof(srcFileName), "%s", basepath);
pfree(basepath);
/*
* Open the files
......@@ -468,11 +462,12 @@ static void copy_append_only_segment_file(
(errcode_for_file_access(),
errmsg("could not open file \"%s\": %m", srcFileName)));
CopyRelPath(dstFileName, MAXPGPATH, *dstRelFileNode);
basepath = relpath(*dstRelFileNode);
if (segmentFileNum > 0)
{
strcat(dstFileName, extension);
}
snprintf(dstFileName, sizeof(dstFileName), "%s.%u", basepath, segmentFileNum);
else
snprintf(dstFileName, sizeof(dstFileName), "%s", basepath);
pfree(basepath);
MirroredAppendOnly_OpenReadWrite(
&mirroredDstOpen,
......
......@@ -9432,9 +9432,9 @@ copy_append_only_data(
{
MIRRORED_LOCK_DECLARE;
char *basepath;
char srcFileName[MAXPGPATH];
char dstFileName[MAXPGPATH];
char extension[12];
File srcFile;
......@@ -9454,34 +9454,28 @@ copy_append_only_data(
MirrorDataLossTrackingState originalMirrorDataLossTrackingState;
int64 originalMirrorDataLossTrackingSessionNum;
if (segmentFileNum > 0)
{
sprintf(extension, ".%u", segmentFileNum);
}
else
extension[0] = '\0';
CopyRelPath(srcFileName, MAXPGPATH, *oldRelFileNode);
if (segmentFileNum > 0)
{
strcat(srcFileName, extension);
}
/*
* Open the files
*/
basepath = relpath(*oldRelFileNode);
if (segmentFileNum > 0)
snprintf(srcFileName, sizeof(srcFileName), "%s.%u", basepath, segmentFileNum);
else
snprintf(srcFileName, sizeof(srcFileName), "%s", basepath);
pfree(basepath);
srcFile = PathNameOpenFile(srcFileName, O_RDONLY | PG_BINARY, 0);
if (srcFile < 0)
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open file \"%s\": %m", srcFileName)));
CopyRelPath(dstFileName, MAXPGPATH, *newRelFileNode);
basepath = relpath(*newRelFileNode);
if (segmentFileNum > 0)
{
strcat(dstFileName, extension);
}
snprintf(dstFileName, sizeof(srcFileName), "%s.%u", basepath, segmentFileNum);
else
snprintf(dstFileName, sizeof(srcFileName), "%s", basepath);
pfree(basepath);
MirroredAppendOnly_OpenReadWrite(
&mirroredDstOpen,
......
......@@ -20,7 +20,6 @@
extern char *relpath(RelFileNode rnode);
extern void CopyRelPath(char *target, int targetMaxLen, RelFileNode rnode);
extern char *GetDatabasePath(Oid dbNode, Oid spcNode);
extern void FormDatabasePath(char *databasePath, char *filespaceLocation, Oid tablespaceOid, Oid databaseOid);
extern void FormTablespacePath(char *tablespacePath, char *filespaceLocation, Oid tablespaceOid);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册