Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
fe718f60
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
fe718f60
编写于
4月 12, 2023
作者:
S
shenglian zhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: add expired udfc func stub to track the expired
上级
33143e90
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
45 addition
and
9 deletion
+45
-9
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+45
-9
未找到文件。
source/libs/function/src/tudf.c
浏览文件 @
fe718f60
...
...
@@ -363,6 +363,7 @@ typedef struct SUdfcProxy {
uv_mutex_t
udfStubsMutex
;
SArray
*
udfStubs
;
// SUdfcFuncStub
SArray
*
expiredUdfStubs
;
//SUdfcFuncStub
uv_mutex_t
udfcUvMutex
;
int8_t
initialized
;
...
...
@@ -983,15 +984,22 @@ int32_t acquireUdfFuncHandle(char *udfName, UdfcFuncHandle *pHandle) {
SUdfcFuncStub
*
foundStub
=
taosArrayGet
(
gUdfcProxy
.
udfStubs
,
stubIndex
);
UdfcFuncHandle
handle
=
foundStub
->
handle
;
int64_t
currUs
=
taosGetTimestampUs
();
if
(
handle
!=
NULL
&&
((
SUdfcUvSession
*
)
handle
)
->
udfUvPipe
!=
NULL
&&
(
currUs
-
foundStub
->
createTime
)
<
10
*
1000
*
1000
)
{
*
pHandle
=
foundStub
->
handle
;
++
foundStub
->
refCount
;
uv_mutex_unlock
(
&
gUdfcProxy
.
udfStubsMutex
);
return
0
;
bool
expired
=
(
currUs
-
foundStub
->
createTime
)
>=
10
*
1000
*
1000
;
if
(
!
expired
)
{
if
(
handle
!=
NULL
&&
((
SUdfcUvSession
*
)
handle
)
->
udfUvPipe
!=
NULL
)
{
*
pHandle
=
foundStub
->
handle
;
++
foundStub
->
refCount
;
uv_mutex_unlock
(
&
gUdfcProxy
.
udfStubsMutex
);
return
0
;
}
else
{
fnInfo
(
"invalid handle for %s, refCount: %d, create time: %"
PRId64
". remove it from cache"
,
udfName
,
foundStub
->
refCount
,
foundStub
->
createTime
);
taosArrayRemove
(
gUdfcProxy
.
udfStubs
,
stubIndex
);
}
}
else
{
fnInfo
(
"invalid handle for %s, refCount: %d, create time: %"
PRId64
". remove it from cache"
,
udfName
,
foundStub
->
refCount
,
foundStub
->
createTime
);
taosArrayRemove
(
gUdfcProxy
.
udfStubs
,
stubIndex
);
taosArrayPush
(
gUdfcProxy
.
expiredUdfStubs
,
foundStub
);
taosArraySort
(
gUdfcProxy
.
expiredUdfStubs
,
compareUdfcFuncSub
);
}
}
*
pHandle
=
NULL
;
...
...
@@ -1017,13 +1025,17 @@ void releaseUdfFuncHandle(char *udfName) {
SUdfcFuncStub
key
=
{
0
};
strncpy
(
key
.
udfName
,
udfName
,
TSDB_FUNC_NAME_LEN
);
SUdfcFuncStub
*
foundStub
=
taosArraySearch
(
gUdfcProxy
.
udfStubs
,
&
key
,
compareUdfcFuncSub
,
TD_EQ
);
if
(
!
foundStub
)
{
SUdfcFuncStub
*
expiredStub
=
taosArraySearch
(
gUdfcProxy
.
expiredUdfStubs
,
&
key
,
compareUdfcFuncSub
,
TD_EQ
);
if
(
!
foundStub
&&
!
expiredStub
)
{
uv_mutex_unlock
(
&
gUdfcProxy
.
udfStubsMutex
);
return
;
}
if
(
foundStub
->
refCount
>
0
)
{
if
(
foundStub
!=
NULL
&&
foundStub
->
refCount
>
0
)
{
--
foundStub
->
refCount
;
}
if
(
expiredStub
!=
NULL
&&
expiredStub
->
refCount
>
0
)
{
--
expiredStub
->
refCount
;
}
uv_mutex_unlock
(
&
gUdfcProxy
.
udfStubsMutex
);
}
...
...
@@ -1060,6 +1072,28 @@ int32_t cleanUpUdfs() {
}
taosArrayDestroy
(
gUdfcProxy
.
udfStubs
);
gUdfcProxy
.
udfStubs
=
udfStubs
;
SArray
*
expiredUdfStubs
=
taosArrayInit
(
16
,
sizeof
(
SUdfcFuncStub
));
while
(
i
<
taosArrayGetSize
(
gUdfcProxy
.
expiredUdfStubs
))
{
SUdfcFuncStub
*
stub
=
taosArrayGet
(
gUdfcProxy
.
expiredUdfStubs
,
i
);
if
(
stub
->
refCount
==
0
)
{
fnInfo
(
"tear down udf. expired. udf name: %s, handle: %p, ref count: %d"
,
stub
->
udfName
,
stub
->
handle
,
stub
->
refCount
);
doTeardownUdf
(
stub
->
handle
);
}
else
{
fnInfo
(
"udf still in use. expired. udf name: %s, ref count: %d, create time: %"
PRId64
", handle: %p"
,
stub
->
udfName
,
stub
->
refCount
,
stub
->
createTime
,
stub
->
handle
);
UdfcFuncHandle
handle
=
stub
->
handle
;
if
(
handle
!=
NULL
&&
((
SUdfcUvSession
*
)
handle
)
->
udfUvPipe
!=
NULL
)
{
taosArrayPush
(
expiredUdfStubs
,
stub
);
}
else
{
fnInfo
(
"udf invalid handle for %s, expired. refCount: %d, create time: %"
PRId64
". remove it from cache"
,
stub
->
udfName
,
stub
->
refCount
,
stub
->
createTime
);
}
}
++
i
;
}
taosArrayDestroy
(
gUdfcProxy
.
udfStubs
);
gUdfcProxy
.
expiredUdfStubs
=
expiredUdfStubs
;
uv_mutex_unlock
(
&
gUdfcProxy
.
udfStubsMutex
);
return
0
;
}
...
...
@@ -1663,6 +1697,7 @@ int32_t udfcOpen() {
uv_barrier_wait
(
&
proxy
->
initBarrier
);
uv_mutex_init
(
&
proxy
->
udfStubsMutex
);
proxy
->
udfStubs
=
taosArrayInit
(
8
,
sizeof
(
SUdfcFuncStub
));
proxy
->
expiredUdfStubs
=
taosArrayInit
(
8
,
sizeof
(
SUdfcFuncStub
));
uv_mutex_init
(
&
proxy
->
udfcUvMutex
);
fnInfo
(
"udfc initialized"
)
return
0
;
}
...
...
@@ -1679,6 +1714,7 @@ int32_t udfcClose() {
uv_thread_join
(
&
udfc
->
loopThread
);
uv_mutex_destroy
(
&
udfc
->
taskQueueMutex
);
uv_barrier_destroy
(
&
udfc
->
initBarrier
);
taosArrayDestroy
(
udfc
->
expiredUdfStubs
);
taosArrayDestroy
(
udfc
->
udfStubs
);
uv_mutex_destroy
(
&
udfc
->
udfStubsMutex
);
uv_mutex_destroy
(
&
udfc
->
udfcUvMutex
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录