Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
32523d72
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
32523d72
编写于
4月 08, 2023
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: add created time to file name and keep file reuse
上级
26f1e91d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
61 addition
and
34 deletion
+61
-34
include/common/tmsg.h
include/common/tmsg.h
+6
-1
include/libs/function/taosudf.h
include/libs/function/taosudf.h
+1
-0
source/common/src/tmsg.c
source/common/src/tmsg.c
+13
-11
source/dnode/mnode/impl/src/mndFunc.c
source/dnode/mnode/impl/src/mndFunc.c
+6
-4
source/libs/catalog/test/catalogTests.cpp
source/libs/catalog/test/catalogTests.cpp
+3
-3
source/libs/function/src/udfd.c
source/libs/function/src/udfd.c
+31
-14
source/libs/qcom/src/querymsg.c
source/libs/qcom/src/querymsg.c
+1
-1
未找到文件。
include/common/tmsg.h
浏览文件 @
32523d72
...
...
@@ -1093,10 +1093,15 @@ typedef struct {
char
*
pCode
;
}
SFuncInfo
;
typedef
struct
{
int32_t
funcVersion
;
int64_t
funcCreatedTime
;
}
SFuncExtraInfo
;
typedef
struct
{
int32_t
numOfFuncs
;
SArray
*
pFuncInfos
;
SArray
*
pFunc
Version
s
;
SArray
*
pFunc
ExtraInfo
s
;
}
SRetrieveFuncRsp
;
int32_t
tSerializeSRetrieveFuncRsp
(
void
*
buf
,
int32_t
bufLen
,
SRetrieveFuncRsp
*
pRsp
);
...
...
include/libs/function/taosudf.h
浏览文件 @
32523d72
...
...
@@ -277,6 +277,7 @@ typedef enum EUdfFuncType { UDF_FUNC_TYPE_SCALAR = 1, UDF_FUNC_TYPE_AGG = 2 } EU
typedef
struct
SScriptUdfInfo
{
const
char
*
name
;
int32_t
version
;
int64_t
createdTime
;
EUdfFuncType
funcType
;
int8_t
scriptType
;
...
...
source/common/src/tmsg.c
浏览文件 @
32523d72
...
...
@@ -1865,10 +1865,11 @@ int32_t tSerializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp *
}
}
if
(
pRsp
->
numOfFuncs
!=
(
int32_t
)
taosArrayGetSize
(
pRsp
->
pFunc
Version
s
))
return
-
1
;
if
(
pRsp
->
numOfFuncs
!=
(
int32_t
)
taosArrayGetSize
(
pRsp
->
pFunc
ExtraInfo
s
))
return
-
1
;
for
(
int32_t
i
=
0
;
i
<
pRsp
->
numOfFuncs
;
++
i
)
{
int32_t
version
=
*
(
int32_t
*
)
taosArrayGet
(
pRsp
->
pFuncVersions
,
i
);
if
(
tEncodeI32
(
&
encoder
,
version
)
<
0
)
return
-
1
;
SFuncExtraInfo
*
extraInfo
=
taosArrayGet
(
pRsp
->
pFuncExtraInfos
,
i
);
if
(
tEncodeI32
(
&
encoder
,
extraInfo
->
funcVersion
)
<
0
)
return
-
1
;
if
(
tEncodeI64
(
&
encoder
,
extraInfo
->
funcCreatedTime
)
<
0
)
return
-
1
;
}
tEndEncode
(
&
encoder
);
...
...
@@ -1919,18 +1920,19 @@ int32_t tDeserializeSRetrieveFuncRsp(void *buf, int32_t bufLen, SRetrieveFuncRsp
taosArrayPush
(
pRsp
->
pFuncInfos
,
&
fInfo
);
}
pRsp
->
pFunc
Versions
=
taosArrayInit
(
pRsp
->
numOfFuncs
,
sizeof
(
int32_t
));
if
(
pRsp
->
pFunc
Version
s
==
NULL
)
return
-
1
;
pRsp
->
pFunc
ExtraInfos
=
taosArrayInit
(
pRsp
->
numOfFuncs
,
sizeof
(
SFuncExtraInfo
));
if
(
pRsp
->
pFunc
ExtraInfo
s
==
NULL
)
return
-
1
;
if
(
tDecodeIsEnd
(
&
decoder
))
{
for
(
int32_t
i
=
0
;
i
<
pRsp
->
numOfFuncs
;
++
i
)
{
int32_t
version
=
0
;
taosArrayPush
(
pRsp
->
pFunc
Versions
,
&
version
);
SFuncExtraInfo
extraInfo
=
{
0
}
;
taosArrayPush
(
pRsp
->
pFunc
ExtraInfos
,
&
extraInfo
);
}
}
else
{
for
(
int32_t
i
=
0
;
i
<
pRsp
->
numOfFuncs
;
++
i
)
{
int32_t
version
=
0
;
if
(
tDecodeI32
(
&
decoder
,
&
version
)
<
0
)
return
-
1
;
taosArrayPush
(
pRsp
->
pFuncVersions
,
&
version
);
SFuncExtraInfo
extraInfo
=
{
0
};
if
(
tDecodeI32
(
&
decoder
,
&
extraInfo
.
funcVersion
)
<
0
)
return
-
1
;
if
(
tDecodeI64
(
&
decoder
,
&
extraInfo
.
funcCreatedTime
)
<
0
)
return
-
1
;
taosArrayPush
(
pRsp
->
pFuncExtraInfos
,
&
extraInfo
);
}
}
tEndDecode
(
&
decoder
);
...
...
@@ -1955,7 +1957,7 @@ void tFreeSRetrieveFuncRsp(SRetrieveFuncRsp *pRsp) {
tFreeSFuncInfo
(
pInfo
);
}
taosArrayDestroy
(
pRsp
->
pFuncInfos
);
taosArrayDestroy
(
pRsp
->
pFunc
Version
s
);
taosArrayDestroy
(
pRsp
->
pFunc
ExtraInfo
s
);
}
int32_t
tSerializeSTableCfgReq
(
void
*
buf
,
int32_t
bufLen
,
STableCfgReq
*
pReq
)
{
...
...
source/dnode/mnode/impl/src/mndFunc.c
浏览文件 @
32523d72
...
...
@@ -428,8 +428,8 @@ static int32_t mndProcessRetrieveFuncReq(SRpcMsg *pReq) {
goto
RETRIEVE_FUNC_OVER
;
}
retrieveRsp
.
pFunc
Versions
=
taosArrayInit
(
retrieveReq
.
numOfFuncs
,
sizeof
(
int32_t
));
if
(
retrieveRsp
.
pFunc
Version
s
==
NULL
)
{
retrieveRsp
.
pFunc
ExtraInfos
=
taosArrayInit
(
retrieveReq
.
numOfFuncs
,
sizeof
(
SFuncExtraInfo
));
if
(
retrieveRsp
.
pFunc
ExtraInfo
s
==
NULL
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
RETRIEVE_FUNC_OVER
;
}
...
...
@@ -472,8 +472,10 @@ static int32_t mndProcessRetrieveFuncReq(SRpcMsg *pReq) {
}
}
taosArrayPush
(
retrieveRsp
.
pFuncInfos
,
&
funcInfo
);
taosArrayPush
(
retrieveRsp
.
pFuncVersions
,
&
pFunc
->
funcVersion
);
SFuncExtraInfo
extraInfo
=
{
0
};
extraInfo
.
funcVersion
=
pFunc
->
funcVersion
;
extraInfo
.
funcCreatedTime
=
pFunc
->
createdTime
;
taosArrayPush
(
retrieveRsp
.
pFuncExtraInfos
,
&
pFunc
->
funcVersion
);
mndReleaseFunc
(
pMnode
,
pFunc
);
}
...
...
source/libs/catalog/test/catalogTests.cpp
浏览文件 @
32523d72
...
...
@@ -672,14 +672,14 @@ void ctgTestRspUdfInfo(void *shandle, SEpSet *pEpSet, SRpcMsg *pMsg, SRpcMsg *pR
SRetrieveFuncRsp
funcRsp
=
{
0
};
funcRsp
.
numOfFuncs
=
1
;
funcRsp
.
pFuncInfos
=
taosArrayInit
(
1
,
sizeof
(
SFuncInfo
));
funcRsp
.
pFunc
Versions
=
taosArrayInit
(
1
,
sizeof
(
int32_t
));
funcRsp
.
pFunc
ExtraInfos
=
taosArrayInit
(
1
,
sizeof
(
SFuncExtraInfo
));
SFuncInfo
funcInfo
=
{
0
};
strcpy
(
funcInfo
.
name
,
"func1"
);
funcInfo
.
funcType
=
ctgTestFuncType
;
(
void
)
taosArrayPush
(
funcRsp
.
pFuncInfos
,
&
funcInfo
);
int32_t
version
=
0
;
(
void
)
taosArrayPush
(
funcRsp
.
pFunc
Versions
,
&
version
);
SFuncExtraInfo
extraInfo
=
{.
funcVersion
=
1
,
.
funcCreatedTime
=
taosGetTimestampMs
()}
;
(
void
)
taosArrayPush
(
funcRsp
.
pFunc
ExtraInfos
,
&
extraInfo
);
int32_t
rspLen
=
tSerializeSRetrieveFuncRsp
(
NULL
,
0
,
&
funcRsp
);
void
*
pReq
=
rpcMallocCont
(
rspLen
);
...
...
source/libs/function/src/udfd.c
浏览文件 @
32523d72
...
...
@@ -53,9 +53,9 @@ int32_t udfdCPluginOpen(SScriptUdfEnvItem *items, int numItems) { return 0; }
int32_t
udfdCPluginClose
()
{
return
0
;
}
const
char
*
udfdCPluginUdfInitLoadInitDestoryFuncs
(
SUdfCPluginCtx
*
udfCtx
,
const
char
*
udfName
)
{
char
initFuncName
[
TSDB_FUNC_NAME_LEN
+
5
]
=
{
0
};
char
*
initSuffix
=
"_init"
;
const
char
*
udfdCPluginUdfInitLoadInitDestoryFuncs
(
SUdfCPluginCtx
*
udfCtx
,
const
char
*
udfName
)
{
char
initFuncName
[
TSDB_FUNC_NAME_LEN
+
5
]
=
{
0
};
char
*
initSuffix
=
"_init"
;
strcpy
(
initFuncName
,
udfName
);
strncat
(
initFuncName
,
initSuffix
,
strlen
(
initSuffix
));
uv_dlsym
(
&
udfCtx
->
lib
,
initFuncName
,
(
void
**
)(
&
udfCtx
->
initFunc
));
...
...
@@ -100,7 +100,7 @@ int32_t udfdCPluginUdfInit(SScriptUdfInfo *udf, void **pUdfCtx) {
fnError
(
"can not load library %s. error: %s"
,
udf
->
path
,
uv_strerror
(
err
));
return
TSDB_CODE_UDF_LOAD_UDF_FAILURE
;
}
const
char
*
udfName
=
udf
->
name
;
const
char
*
udfName
=
udf
->
name
;
udfdCPluginUdfInitLoadInitDestoryFuncs
(
udfCtx
,
udfName
);
...
...
@@ -260,6 +260,7 @@ typedef enum { UDF_STATE_INIT = 0, UDF_STATE_LOADING, UDF_STATE_READY } EUdfStat
typedef
struct
SUdf
{
char
name
[
TSDB_FUNC_NAME_LEN
+
1
];
int32_t
version
;
int64_t
createdTime
;
int8_t
funcType
;
int8_t
scriptType
;
...
...
@@ -518,6 +519,7 @@ void convertUdf2UdfInfo(SUdf *udf, SScriptUdfInfo *udfInfo) {
}
udfInfo
->
name
=
udf
->
name
;
udfInfo
->
version
=
udf
->
version
;
udfInfo
->
createdTime
=
udf
->
createdTime
;
udfInfo
->
outputLen
=
udf
->
outputLen
;
udfInfo
->
outputType
=
udf
->
outputType
;
udfInfo
->
path
=
udf
->
path
;
...
...
@@ -527,9 +529,9 @@ void convertUdf2UdfInfo(SUdf *udf, SScriptUdfInfo *udfInfo) {
int32_t
udfdRenameUdfFile
(
SUdf
*
udf
)
{
char
newPath
[
PATH_MAX
];
if
(
udf
->
scriptType
==
TSDB_FUNC_SCRIPT_BIN_LIB
)
{
snprintf
(
newPath
,
PATH_MAX
,
"%s/lib%s_%d_%"
PRIx64
".so"
,
tsDataDir
,
udf
->
name
,
udf
->
version
,
udf
->
lastFetch
Time
);
snprintf
(
newPath
,
PATH_MAX
,
"%s/lib%s_%d_%"
PRIx64
".so"
,
tsDataDir
,
udf
->
name
,
udf
->
version
,
udf
->
created
Time
);
}
else
if
(
udf
->
scriptType
==
TSDB_FUNC_SCRIPT_PYTHON
)
{
snprintf
(
newPath
,
PATH_MAX
,
"%s/%s_%d_%"
PRIx64
".py"
,
tsDataDir
,
udf
->
name
,
udf
->
version
,
udf
->
lastFetch
Time
);
snprintf
(
newPath
,
PATH_MAX
,
"%s/%s_%d_%"
PRIx64
".py"
,
tsDataDir
,
udf
->
name
,
udf
->
version
,
udf
->
created
Time
);
}
else
{
return
TSDB_CODE_UDF_SCRIPT_NOT_SUPPORTED
;
}
...
...
@@ -606,7 +608,7 @@ SUdf *udfdGetOrCreateUdf(const char *udfName) {
int64_t
currTime
=
taosGetTimestampSec
();
bool
expired
=
false
;
if
(
pUdfHash
)
{
expired
=
currTime
-
(
*
pUdfHash
)
->
lastFetchTime
>
10
*
1000
*
1000
;
// 10s
expired
=
currTime
-
(
*
pUdfHash
)
->
lastFetchTime
>
10
*
1000
*
1000
;
// 10s
if
(
!
expired
)
{
++
(
*
pUdfHash
)
->
refCount
;
SUdf
*
udf
=
*
pUdfHash
;
...
...
@@ -618,7 +620,7 @@ SUdf *udfdGetOrCreateUdf(const char *udfName) {
}
}
SUdf
*
udf
=
udfdNewUdf
(
udfName
);
SUdf
*
udf
=
udfdNewUdf
(
udfName
);
SUdf
**
pUdf
=
&
udf
;
taosHashPut
(
global
.
udfsHash
,
udfName
,
strlen
(
udfName
),
pUdf
,
POINTER_BYTES
);
...
...
@@ -805,7 +807,6 @@ void udfdProcessTeardownRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
uv_mutex_destroy
(
&
udf
->
lock
);
code
=
udf
->
scriptPlugin
->
udfDestroyFunc
(
udf
->
scriptUdfCtx
);
fnDebug
(
"udfd destroy function returns %d"
,
code
);
taosRemoveFile
(
udf
->
path
);
taosMemoryFree
(
udf
);
}
taosMemoryFree
(
handle
);
...
...
@@ -835,22 +836,36 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) {
char
path
[
PATH_MAX
]
=
{
0
};
#ifdef WINDOWS
snprintf
(
path
,
sizeof
(
path
),
"%s%s_%d_%"
PRIx64
,
tsDataDir
,
pFuncInfo
->
name
,
udf
->
version
,
udf
->
lastFetch
Time
);
snprintf
(
path
,
sizeof
(
path
),
"%s%s_%d_%"
PRIx64
,
tsDataDir
,
pFuncInfo
->
name
,
udf
->
version
,
udf
->
created
Time
);
#else
snprintf
(
path
,
sizeof
(
path
),
"%s/%s_%d_%"
PRIx64
,
tsDataDir
,
pFuncInfo
->
name
,
udf
->
version
,
udf
->
lastFetch
Time
);
snprintf
(
path
,
sizeof
(
path
),
"%s/%s_%d_%"
PRIx64
,
tsDataDir
,
pFuncInfo
->
name
,
udf
->
version
,
udf
->
created
Time
);
#endif
bool
fileExist
=
!
(
taosStatFile
(
path
,
NULL
,
NULL
)
<
0
);
if
(
fileExist
)
{
// TODO: error processing
TdFilePtr
file
=
taosOpenFile
(
path
,
TD_FILE_READ
);
int64_t
size
=
0
;
taosFStatFile
(
file
,
&
size
,
NULL
);
taosCloseFile
(
file
);
if
(
size
==
pFuncInfo
->
codeSize
)
{
strncpy
(
udf
->
path
,
path
,
PATH_MAX
);
return
TSDB_CODE_SUCCESS
;
}
}
TdFilePtr
file
=
taosOpenFile
(
path
,
TD_FILE_CREATE
|
TD_FILE_WRITE
|
TD_FILE_READ
|
TD_FILE_TRUNC
);
if
(
file
==
NULL
)
{
fnError
(
"udfd write udf shared library: %s failed, error: %d %s"
,
path
,
errno
,
strerror
(
errno
));
return
TSDB_CODE_FILE_CORRUPTED
;
}
int64_t
count
=
taosWriteFile
(
file
,
pFuncInfo
->
pCode
,
pFuncInfo
->
codeSize
);
if
(
count
!=
pFuncInfo
->
codeSize
)
{
fnError
(
"udfd write udf shared library failed"
);
return
TSDB_CODE_FILE_CORRUPTED
;
}
taosCloseFile
(
&
file
);
strncpy
(
udf
->
path
,
path
,
PATH_MAX
);
return
TSDB_CODE_SUCCESS
;
}
...
...
@@ -901,15 +916,17 @@ void udfdProcessRpcRsp(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) {
udf
->
outputType
=
pFuncInfo
->
outputType
;
udf
->
outputLen
=
pFuncInfo
->
outputLen
;
udf
->
bufSize
=
pFuncInfo
->
bufSize
;
udf
->
version
=
*
(
int32_t
*
)
taosArrayGet
(
retrieveRsp
.
pFuncVersion
s
,
0
);
SFuncExtraInfo
*
pFuncExtraInfo
=
(
SFuncExtraInfo
*
)
taosArrayGet
(
retrieveRsp
.
pFuncExtraInfo
s
,
0
);
udf
->
version
=
pFuncExtraInfo
->
funcVersion
;
udf
->
createdTime
=
pFuncExtraInfo
->
funcCreatedTime
;
msgInfo
->
code
=
udfdSaveFuncBodyToFile
(
pFuncInfo
,
udf
);
if
(
msgInfo
->
code
!=
0
)
{
udf
->
lastFetchTime
=
0
;
}
tFreeSFuncInfo
(
pFuncInfo
);
taosArrayDestroy
(
retrieveRsp
.
pFuncInfos
);
taosArrayDestroy
(
retrieveRsp
.
pFunc
Version
s
);
taosArrayDestroy
(
retrieveRsp
.
pFunc
ExtraInfo
s
);
}
_return:
...
...
source/libs/qcom/src/querymsg.c
浏览文件 @
32523d72
...
...
@@ -587,7 +587,7 @@ int32_t queryProcessRetrieveFuncRsp(void *output, char *msg, int32_t msgSize) {
memcpy
(
output
,
funcInfo
,
sizeof
(
*
funcInfo
));
taosArrayDestroy
(
out
.
pFuncInfos
);
taosArrayDestroy
(
out
.
pFunc
Version
s
);
taosArrayDestroy
(
out
.
pFunc
ExtraInfo
s
);
return
TSDB_CODE_SUCCESS
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录