Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ee2f3e7e
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看板
提交
ee2f3e7e
编写于
5月 17, 2022
作者:
S
slzhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: clear invalid udf func handle
上级
e73b1c48
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
86 addition
and
71 deletion
+86
-71
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+86
-71
未找到文件。
source/libs/function/src/tudf.c
浏览文件 @
ee2f3e7e
...
...
@@ -1314,6 +1314,90 @@ int32_t doSetupUdf(char udfName[], UdfcFuncHandle *funcHandle) {
return
err
;
}
int
compareUdfcFuncSub
(
const
void
*
elem1
,
const
void
*
elem2
)
{
SUdfcFuncStub
*
stub1
=
(
SUdfcFuncStub
*
)
elem1
;
SUdfcFuncStub
*
stub2
=
(
SUdfcFuncStub
*
)
elem2
;
return
strcmp
(
stub1
->
udfName
,
stub2
->
udfName
);
}
int32_t
acquireUdfFuncHandle
(
char
*
udfName
,
UdfcFuncHandle
*
pHandle
)
{
int32_t
code
=
0
;
uv_mutex_lock
(
&
gUdfdProxy
.
udfStubsMutex
);
SUdfcFuncStub
key
=
{
0
};
strcpy
(
key
.
udfName
,
udfName
);
int32_t
stubIndex
=
taosArraySearchIdx
(
gUdfdProxy
.
udfStubs
,
&
key
,
compareUdfcFuncSub
,
TD_EQ
);
if
(
stubIndex
!=
-
1
)
{
SUdfcFuncStub
*
foundStub
=
taosArrayGet
(
gUdfdProxy
.
udfStubs
,
stubIndex
);
UdfcFuncHandle
handle
=
foundStub
->
handle
;
if
(
handle
!=
NULL
&&
((
SUdfcUvSession
*
)
handle
)
->
udfUvPipe
!=
NULL
)
{
*
pHandle
=
foundStub
->
handle
;
++
foundStub
->
refCount
;
foundStub
->
lastRefTime
=
taosGetTimestampUs
();
uv_mutex_unlock
(
&
gUdfdProxy
.
udfStubsMutex
);
return
0
;
}
else
{
fnInfo
(
"invalid handle for %s, refCount: %d, last ref time: %"
PRId64
". remove it from cache"
,
udfName
,
foundStub
->
refCount
,
foundStub
->
lastRefTime
);
taosArrayRemove
(
gUdfdProxy
.
udfStubs
,
stubIndex
);
}
}
*
pHandle
=
NULL
;
code
=
doSetupUdf
(
udfName
,
pHandle
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
SUdfcFuncStub
stub
=
{
0
};
strcpy
(
stub
.
udfName
,
udfName
);
stub
.
handle
=
*
pHandle
;
++
stub
.
refCount
;
stub
.
lastRefTime
=
taosGetTimestampUs
();
taosArrayPush
(
gUdfdProxy
.
udfStubs
,
&
stub
);
taosArraySort
(
gUdfdProxy
.
udfStubs
,
compareUdfcFuncSub
);
}
else
{
*
pHandle
=
NULL
;
}
uv_mutex_unlock
(
&
gUdfdProxy
.
udfStubsMutex
);
return
code
;
}
void
releaseUdfFuncHandle
(
char
*
udfName
)
{
uv_mutex_lock
(
&
gUdfdProxy
.
udfStubsMutex
);
SUdfcFuncStub
key
=
{
0
};
strcpy
(
key
.
udfName
,
udfName
);
SUdfcFuncStub
*
foundStub
=
taosArraySearch
(
gUdfdProxy
.
udfStubs
,
&
key
,
compareUdfcFuncSub
,
TD_EQ
);
ASSERT
(
foundStub
);
--
foundStub
->
refCount
;
ASSERT
(
foundStub
->
refCount
>=
0
);
uv_mutex_unlock
(
&
gUdfdProxy
.
udfStubsMutex
);
}
int32_t
cleanUpUdfs
()
{
uv_mutex_lock
(
&
gUdfdProxy
.
udfStubsMutex
);
int32_t
i
=
0
;
SArray
*
udfStubs
=
taosArrayInit
(
16
,
sizeof
(
SUdfcFuncStub
));
while
(
i
<
taosArrayGetSize
(
gUdfdProxy
.
udfStubs
))
{
SUdfcFuncStub
*
stub
=
taosArrayGet
(
gUdfdProxy
.
udfStubs
,
i
);
if
(
stub
->
refCount
==
0
)
{
fnInfo
(
"tear down udf. udf name: %s, handle: %p"
,
stub
->
udfName
,
stub
->
handle
);
doTeardownUdf
(
stub
->
handle
);
}
else
{
fnInfo
(
"udf still in use. udf name: %s, ref count: %d, last ref time: %"
PRId64
", handle: %p"
,
stub
->
udfName
,
stub
->
refCount
,
stub
->
lastRefTime
,
stub
->
handle
);
UdfcFuncHandle
handle
=
stub
->
handle
;
if
(
handle
!=
NULL
&&
((
SUdfcUvSession
*
)
handle
)
->
udfUvPipe
!=
NULL
)
{
taosArrayPush
(
udfStubs
,
stub
);
}
else
{
fnInfo
(
"invalid handle for %s, refCount: %d, last ref time: %"
PRId64
". remove it from cache"
,
stub
->
udfName
,
stub
->
refCount
,
stub
->
lastRefTime
);
}
}
++
i
;
}
taosArrayDestroy
(
gUdfdProxy
.
udfStubs
);
gUdfdProxy
.
udfStubs
=
udfStubs
;
uv_mutex_unlock
(
&
gUdfdProxy
.
udfStubsMutex
);
return
0
;
}
int32_t
callUdf
(
UdfcFuncHandle
handle
,
int8_t
callType
,
SSDataBlock
*
input
,
SUdfInterBuf
*
state
,
SUdfInterBuf
*
state2
,
SSDataBlock
*
output
,
SUdfInterBuf
*
newState
)
{
fnTrace
(
"udfc call udf. callType: %d, funcHandle: %p"
,
callType
,
handle
);
...
...
@@ -1437,57 +1521,10 @@ int32_t doCallUdfScalarFunc(UdfcFuncHandle handle, SScalarParam *input, int32_t
return
err
;
}
int
compareUdfcFuncSub
(
const
void
*
elem1
,
const
void
*
elem2
)
{
SUdfcFuncStub
*
stub1
=
(
SUdfcFuncStub
*
)
elem1
;
SUdfcFuncStub
*
stub2
=
(
SUdfcFuncStub
*
)
elem2
;
return
strcmp
(
stub1
->
udfName
,
stub2
->
udfName
);
}
int32_t
accquireUdfFuncHandle
(
char
*
udfName
,
UdfcFuncHandle
*
pHandle
)
{
int32_t
code
=
0
;
uv_mutex_lock
(
&
gUdfdProxy
.
udfStubsMutex
);
SUdfcFuncStub
key
=
{
0
};
strcpy
(
key
.
udfName
,
udfName
);
SUdfcFuncStub
*
foundStub
=
taosArraySearch
(
gUdfdProxy
.
udfStubs
,
&
key
,
compareUdfcFuncSub
,
TD_EQ
);
if
(
foundStub
!=
NULL
)
{
uv_mutex_unlock
(
&
gUdfdProxy
.
udfStubsMutex
);
*
pHandle
=
foundStub
->
handle
;
++
foundStub
->
refCount
;
foundStub
->
lastRefTime
=
taosGetTimestampUs
();
return
0
;
}
*
pHandle
=
NULL
;
code
=
doSetupUdf
(
udfName
,
pHandle
);
if
(
code
==
TSDB_CODE_SUCCESS
)
{
SUdfcFuncStub
stub
=
{
0
};
strcpy
(
stub
.
udfName
,
udfName
);
stub
.
handle
=
*
pHandle
;
++
stub
.
refCount
;
stub
.
lastRefTime
=
taosGetTimestampUs
();
taosArrayPush
(
gUdfdProxy
.
udfStubs
,
&
stub
);
taosArraySort
(
gUdfdProxy
.
udfStubs
,
compareUdfcFuncSub
);
}
else
{
*
pHandle
=
NULL
;
}
uv_mutex_unlock
(
&
gUdfdProxy
.
udfStubsMutex
);
return
code
;
}
void
releaseUdfFuncHandle
(
char
*
udfName
)
{
uv_mutex_lock
(
&
gUdfdProxy
.
udfStubsMutex
);
SUdfcFuncStub
key
=
{
0
};
strcpy
(
key
.
udfName
,
udfName
);
SUdfcFuncStub
*
foundStub
=
taosArraySearch
(
gUdfdProxy
.
udfStubs
,
&
key
,
compareUdfcFuncSub
,
TD_EQ
);
ASSERT
(
foundStub
);
--
foundStub
->
refCount
;
ASSERT
(
foundStub
->
refCount
>=
0
);
uv_mutex_unlock
(
&
gUdfdProxy
.
udfStubsMutex
);
}
int32_t
callUdfScalarFunc
(
char
*
udfName
,
SScalarParam
*
input
,
int32_t
numOfCols
,
SScalarParam
*
output
)
{
UdfcFuncHandle
handle
=
NULL
;
int32_t
code
=
ac
c
quireUdfFuncHandle
(
udfName
,
&
handle
);
int32_t
code
=
acquireUdfFuncHandle
(
udfName
,
&
handle
);
if
(
code
!=
0
)
{
return
code
;
}
...
...
@@ -1549,7 +1586,7 @@ bool udfAggInit(struct SqlFunctionCtx *pCtx, struct SResultRowEntryInfo* pResult
}
UdfcFuncHandle
handle
;
int32_t
udfCode
=
0
;
if
((
udfCode
=
ac
c
quireUdfFuncHandle
((
char
*
)
pCtx
->
udfName
,
&
handle
))
!=
0
)
{
if
((
udfCode
=
acquireUdfFuncHandle
((
char
*
)
pCtx
->
udfName
,
&
handle
))
!=
0
)
{
fnError
(
"udfAggInit error. step doSetupUdf. udf code: %d"
,
udfCode
);
return
false
;
}
...
...
@@ -1662,25 +1699,3 @@ int32_t udfAggFinalize(struct SqlFunctionCtx *pCtx, SSDataBlock* pBlock) {
releaseUdfFuncHandle
(
pCtx
->
udfName
);
return
udfCallCode
==
0
?
numOfResults
:
udfCallCode
;
}
int32_t
cleanUpUdfs
()
{
uv_mutex_lock
(
&
gUdfdProxy
.
udfStubsMutex
);
int32_t
i
=
0
;
SArray
*
udfStubs
=
taosArrayInit
(
16
,
sizeof
(
SUdfcFuncStub
));
while
(
i
<
taosArrayGetSize
(
gUdfdProxy
.
udfStubs
))
{
SUdfcFuncStub
*
stub
=
taosArrayGet
(
gUdfdProxy
.
udfStubs
,
i
);
if
(
stub
->
refCount
==
0
)
{
fnInfo
(
"tear down udf. udf name: %s, handle: %p"
,
stub
->
udfName
,
stub
->
handle
);
doTeardownUdf
(
stub
->
handle
);
}
else
{
fnInfo
(
"udf still in use. udf name: %s, ref count: %d, last ref time: %"
PRId64
", handle: %p"
,
stub
->
udfName
,
stub
->
refCount
,
stub
->
lastRefTime
,
stub
->
handle
);
taosArrayPush
(
udfStubs
,
stub
);
}
++
i
;
}
taosArrayDestroy
(
gUdfdProxy
.
udfStubs
);
gUdfdProxy
.
udfStubs
=
udfStubs
;
uv_mutex_unlock
(
&
gUdfdProxy
.
udfStubsMutex
);
return
0
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录