Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b725c9e1
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1193
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
b725c9e1
编写于
4月 09, 2023
作者:
S
slzhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enhance: change udf func body dir to tsDataDir/.udf
上级
dc86bf96
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
45 addition
and
13 deletion
+45
-13
source/libs/function/src/udfd.c
source/libs/function/src/udfd.c
+45
-13
未找到文件。
source/libs/function/src/udfd.c
浏览文件 @
b725c9e1
...
@@ -229,6 +229,7 @@ typedef struct SUdfdContext {
...
@@ -229,6 +229,7 @@ typedef struct SUdfdContext {
SArray
*
residentFuncs
;
SArray
*
residentFuncs
;
char
udfDataDir
[
PATH_MAX
];
bool
printVersion
;
bool
printVersion
;
}
SUdfdContext
;
}
SUdfdContext
;
...
@@ -390,12 +391,13 @@ int32_t udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) {
...
@@ -390,12 +391,13 @@ int32_t udfdInitializePythonPlugin(SUdfScriptPlugin *plugin) {
}
}
if
(
plugin
->
openFunc
)
{
if
(
plugin
->
openFunc
)
{
int16_t
lenPythonPath
=
strlen
(
tsUdfdLdLibPath
)
+
strlen
(
tsDataDir
)
+
1
+
1
;
// tsDataDir:tsUdfdLdLibPath
int16_t
lenPythonPath
=
char
*
pythonPath
=
taosMemoryMalloc
(
lenPythonPath
);
strlen
(
tsUdfdLdLibPath
)
+
strlen
(
global
.
udfDataDir
)
+
1
+
1
;
// global.udfDataDir:tsUdfdLdLibPath
char
*
pythonPath
=
taosMemoryMalloc
(
lenPythonPath
);
#ifdef WINDOWS
#ifdef WINDOWS
snprintf
(
pythonPath
,
lenPythonPath
,
"%s;%s"
,
ts
DataDir
,
tsUdfdLdLibPath
);
snprintf
(
pythonPath
,
lenPythonPath
,
"%s;%s"
,
global
.
udf
DataDir
,
tsUdfdLdLibPath
);
#else
#else
snprintf
(
pythonPath
,
lenPythonPath
,
"%s:%s"
,
ts
DataDir
,
tsUdfdLdLibPath
);
snprintf
(
pythonPath
,
lenPythonPath
,
"%s:%s"
,
global
.
udf
DataDir
,
tsUdfdLdLibPath
);
#endif
#endif
SScriptUdfEnvItem
items
[]
=
{{
"PYTHONPATH"
,
pythonPath
},
{
"LOGDIR"
,
tsLogDir
}};
SScriptUdfEnvItem
items
[]
=
{{
"PYTHONPATH"
,
pythonPath
},
{
"LOGDIR"
,
tsLogDir
}};
err
=
plugin
->
openFunc
(
items
,
2
);
err
=
plugin
->
openFunc
(
items
,
2
);
...
@@ -567,7 +569,7 @@ int32_t udfdInitUdf(char *udfName, SUdf *udf) {
...
@@ -567,7 +569,7 @@ int32_t udfdInitUdf(char *udfName, SUdf *udf) {
SUdf
*
udfdNewUdf
(
const
char
*
udfName
)
{
SUdf
*
udfdNewUdf
(
const
char
*
udfName
)
{
SUdf
*
udfNew
=
taosMemoryCalloc
(
1
,
sizeof
(
SUdf
));
SUdf
*
udfNew
=
taosMemoryCalloc
(
1
,
sizeof
(
SUdf
));
udfNew
->
refCount
=
1
;
udfNew
->
refCount
=
1
;
udfNew
->
lastFetchTime
=
taosGetTimestamp
U
s
();
udfNew
->
lastFetchTime
=
taosGetTimestamp
M
s
();
strncpy
(
udfNew
->
name
,
udfName
,
TSDB_FUNC_NAME_LEN
);
strncpy
(
udfNew
->
name
,
udfName
,
TSDB_FUNC_NAME_LEN
);
udfNew
->
state
=
UDF_STATE_INIT
;
udfNew
->
state
=
UDF_STATE_INIT
;
...
@@ -592,15 +594,19 @@ SUdf *udfdGetOrCreateUdf(const char *udfName) {
...
@@ -592,15 +594,19 @@ SUdf *udfdGetOrCreateUdf(const char *udfName) {
int64_t
currTime
=
taosGetTimestampSec
();
int64_t
currTime
=
taosGetTimestampSec
();
bool
expired
=
false
;
bool
expired
=
false
;
if
(
pUdfHash
)
{
if
(
pUdfHash
)
{
expired
=
currTime
-
(
*
pUdfHash
)
->
lastFetchTime
>
10
*
1000
*
1000
;
// 10s
expired
=
currTime
-
(
*
pUdfHash
)
->
lastFetchTime
>
10
*
1000
;
// 10s
if
(
!
expired
)
{
if
(
!
expired
)
{
++
(
*
pUdfHash
)
->
refCount
;
++
(
*
pUdfHash
)
->
refCount
;
SUdf
*
udf
=
*
pUdfHash
;
SUdf
*
udf
=
*
pUdfHash
;
uv_mutex_unlock
(
&
global
.
udfsMutex
);
uv_mutex_unlock
(
&
global
.
udfsMutex
);
fnInfo
(
"udfd reuse existing udf. udf %s udf version %d, udf created time %"
PRIx64
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
return
udf
;
return
udf
;
}
else
{
}
else
{
(
*
pUdfHash
)
->
expired
=
true
;
(
*
pUdfHash
)
->
expired
=
true
;
taosHashRemove
(
global
.
udfsHash
,
udfName
,
strlen
(
udfName
));
taosHashRemove
(
global
.
udfsHash
,
udfName
,
strlen
(
udfName
));
fnInfo
(
"udfd expired, check for new version. existing udf %s udf version %d, udf created time %"
PRIx64
,
(
*
pUdfHash
)
->
name
,
(
*
pUdfHash
)
->
version
,
(
*
pUdfHash
)
->
createdTime
);
}
}
}
}
...
@@ -814,21 +820,22 @@ void udfdProcessTeardownRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
...
@@ -814,21 +820,22 @@ void udfdProcessTeardownRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
void
udfdGetFuncBodyPath
(
const
SUdf
*
udf
,
char
*
path
)
{
void
udfdGetFuncBodyPath
(
const
SUdf
*
udf
,
char
*
path
)
{
if
(
udf
->
scriptType
==
TSDB_FUNC_SCRIPT_BIN_LIB
)
{
if
(
udf
->
scriptType
==
TSDB_FUNC_SCRIPT_BIN_LIB
)
{
#ifdef WINDOWS
#ifdef WINDOWS
snprintf
(
path
,
PATH_MAX
,
"%s%s_%d_%"
PRIx64
".dll"
,
ts
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
snprintf
(
path
,
PATH_MAX
,
"%s%s_%d_%"
PRIx64
".dll"
,
global
.
udf
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
#else
#else
snprintf
(
path
,
PATH_MAX
,
"%s/lib%s_%d_%"
PRIx64
".so"
,
tsDataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
snprintf
(
path
,
PATH_MAX
,
"%s/lib%s_%d_%"
PRIx64
".so"
,
global
.
udfDataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
#endif
#endif
}
else
if
(
udf
->
scriptType
==
TSDB_FUNC_SCRIPT_PYTHON
)
{
}
else
if
(
udf
->
scriptType
==
TSDB_FUNC_SCRIPT_PYTHON
)
{
#ifdef WINDOWS
#ifdef WINDOWS
snprintf
(
path
,
PATH_MAX
,
"%s%s_%d_%"
PRIx64
".py"
,
ts
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
snprintf
(
path
,
PATH_MAX
,
"%s%s_%d_%"
PRIx64
".py"
,
global
.
udf
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
#else
#else
snprintf
(
path
,
PATH_MAX
,
"%s/%s_%d_%"
PRIx64
".py"
,
ts
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
snprintf
(
path
,
PATH_MAX
,
"%s/%s_%d_%"
PRIx64
".py"
,
global
.
udf
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
#endif
#endif
}
else
{
}
else
{
#ifdef WINDOWS
#ifdef WINDOWS
snprintf
(
path
,
PATH_MAX
,
"%s%s_%d_%"
PRIx64
,
ts
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
snprintf
(
path
,
PATH_MAX
,
"%s%s_%d_%"
PRIx64
,
global
.
udf
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
#else
#else
snprintf
(
path
,
PATH_MAX
,
"%s/lib%s_%d_%"
PRIx64
,
ts
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
snprintf
(
path
,
PATH_MAX
,
"%s/lib%s_%d_%"
PRIx64
,
global
.
udf
DataDir
,
udf
->
name
,
udf
->
version
,
udf
->
createdTime
);
#endif
#endif
}
}
}
}
...
@@ -845,6 +852,7 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) {
...
@@ -845,6 +852,7 @@ int32_t udfdSaveFuncBodyToFile(SFuncInfo *pFuncInfo, SUdf *udf) {
bool
fileExist
=
!
(
taosStatFile
(
path
,
NULL
,
NULL
)
<
0
);
bool
fileExist
=
!
(
taosStatFile
(
path
,
NULL
,
NULL
)
<
0
);
if
(
fileExist
)
{
if
(
fileExist
)
{
strncpy
(
udf
->
path
,
path
,
PATH_MAX
);
strncpy
(
udf
->
path
,
path
,
PATH_MAX
);
fnInfo
(
"udfd func body file. reuse existing file %s"
,
path
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
...
@@ -1429,6 +1437,24 @@ int32_t udfdCleanup() {
...
@@ -1429,6 +1437,24 @@ int32_t udfdCleanup() {
return
0
;
return
0
;
}
}
int32_t
udfdCreateUdfSourceDir
()
{
snprintf
(
global
.
udfDataDir
,
PATH_MAX
,
"%s/.udf"
,
tsDataDir
);
int32_t
code
=
taosMkDir
(
global
.
udfDataDir
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
snprintf
(
global
.
udfDataDir
,
PATH_MAX
,
"%s/.udf"
,
tsTempDir
);
code
=
taosMkDir
(
global
.
udfDataDir
);
}
fnInfo
(
"udfd create udf source directory %s. result: %s"
,
global
.
udfDataDir
,
tstrerror
(
code
));
return
code
;
}
int32_t
udfdDestroyUdfSourceDir
()
{
fnInfo
(
"destory udf source directory %s"
,
global
.
udfDataDir
);
taosRemoveDir
(
global
.
udfDataDir
);
return
0
;
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
!
taosCheckSystemIsLittleEnd
())
{
if
(
!
taosCheckSystemIsLittleEnd
())
{
printf
(
"failed to start since on non-little-end machines
\n
"
);
printf
(
"failed to start since on non-little-end machines
\n
"
);
...
@@ -1457,10 +1483,15 @@ int main(int argc, char *argv[]) {
...
@@ -1457,10 +1483,15 @@ int main(int argc, char *argv[]) {
initEpSetFromCfg
(
tsFirst
,
tsSecond
,
&
global
.
mgmtEp
);
initEpSetFromCfg
(
tsFirst
,
tsSecond
,
&
global
.
mgmtEp
);
if
(
udfdOpenClientRpc
()
!=
0
)
{
if
(
udfdOpenClientRpc
()
!=
0
)
{
fnError
(
"open rpc connection to mnode fail
ure
"
);
fnError
(
"open rpc connection to mnode fail
ed
"
);
return
-
3
;
return
-
3
;
}
}
if
(
udfdCreateUdfSourceDir
()
!=
0
)
{
fnError
(
"create udf source directory failed"
);
return
-
4
;
}
if
(
udfdUvInit
()
!=
0
)
{
if
(
udfdUvInit
()
!=
0
)
{
fnError
(
"uv init failure"
);
fnError
(
"uv init failure"
);
return
-
5
;
return
-
5
;
...
@@ -1474,6 +1505,7 @@ int main(int argc, char *argv[]) {
...
@@ -1474,6 +1505,7 @@ int main(int argc, char *argv[]) {
udfdRun
();
udfdRun
();
removeListeningPipe
();
removeListeningPipe
();
udfdDestroyUdfSourceDir
();
udfdCloseClientRpc
();
udfdCloseClientRpc
();
udfdDeinitResidentFuncs
();
udfdDeinitResidentFuncs
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录