Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
e8b467d9
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
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看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
e8b467d9
编写于
5月 14, 2022
作者:
S
shenglian-zhou
提交者:
GitHub
5月 14, 2022
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12476 from taosdata/feature/udf
feat: fix session error that is caused by udfd restart
上级
8f5fc4a0
cef0f74c
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
48 addition
and
54 deletion
+48
-54
include/util/taoserror.h
include/util/taoserror.h
+1
-0
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+32
-9
source/libs/scalar/inc/sclInt.h
source/libs/scalar/inc/sclInt.h
+0
-2
source/libs/scalar/src/scalar.c
source/libs/scalar/src/scalar.c
+14
-42
source/util/src/terror.c
source/util/src/terror.c
+1
-1
未找到文件。
include/util/taoserror.h
浏览文件 @
e8b467d9
...
...
@@ -657,6 +657,7 @@ int32_t* taosGetErrno();
#define TSDB_CODE_UDF_LOAD_UDF_FAILURE TAOS_DEF_ERROR_CODE(0, 0x2905)
#define TSDB_CODE_UDF_INVALID_STATE TAOS_DEF_ERROR_CODE(0, 0x2906)
#define TSDB_CODE_UDF_INVALID_INPUT TAOS_DEF_ERROR_CODE(0, 0x2907)
#define TSDB_CODE_UDF_NO_FUNC_HANDLE TAOS_DEF_ERROR_CODE(0, 0x2908)
#define TSDB_CODE_SML_INVALID_PROTOCOL_TYPE TAOS_DEF_ERROR_CODE(0, 0x3000)
#define TSDB_CODE_SML_INVALID_PRECISION_TYPE TAOS_DEF_ERROR_CODE(0, 0x3001)
...
...
source/libs/function/src/tudf.c
浏览文件 @
e8b467d9
...
...
@@ -1072,6 +1072,8 @@ int32_t udfcQueueUvTask(SClientUvTaskNode *uvTask) {
int32_t
udfcStartUvTask
(
SClientUvTaskNode
*
uvTask
)
{
fnTrace
(
"event loop start uv task. task: %d, %p"
,
uvTask
->
type
,
uvTask
);
int32_t
code
=
0
;
switch
(
uvTask
->
type
)
{
case
UV_TASK_CONNECT
:
{
uv_pipe_t
*
pipe
=
taosMemoryMalloc
(
sizeof
(
uv_pipe_t
));
...
...
@@ -1091,22 +1093,34 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) {
uv_connect_t
*
connReq
=
taosMemoryMalloc
(
sizeof
(
uv_connect_t
));
connReq
->
data
=
uvTask
;
uv_pipe_connect
(
connReq
,
pipe
,
uvTask
->
udfc
->
udfdPipeName
,
onUdfcPipeConnect
);
code
=
0
;
break
;
}
case
UV_TASK_REQ_RSP
:
{
uv_pipe_t
*
pipe
=
uvTask
->
pipe
;
if
(
pipe
==
NULL
)
{
code
=
TSDB_CODE_UDF_PIPE_NO_PIPE
;
}
else
{
uv_write_t
*
write
=
taosMemoryMalloc
(
sizeof
(
uv_write_t
));
write
->
data
=
uvTask
;
int
err
=
uv_write
(
write
,
(
uv_stream_t
*
)
pipe
,
&
uvTask
->
reqBuf
,
1
,
onUdfcPipetWrite
);
if
(
err
!=
0
)
{
fnError
(
"udfc event loop start req/rsp task uv_write failed. code: %s"
,
uv_strerror
(
err
));
}
code
=
err
;
}
break
;
}
case
UV_TASK_DISCONNECT
:
{
SClientUvConn
*
conn
=
uvTask
->
pipe
->
data
;
uv_pipe_t
*
pipe
=
uvTask
->
pipe
;
if
(
pipe
==
NULL
)
{
code
=
TSDB_CODE_UDF_PIPE_NO_PIPE
;
}
else
{
SClientUvConn
*
conn
=
pipe
->
data
;
QUEUE_INSERT_TAIL
(
&
conn
->
taskQueue
,
&
uvTask
->
connTaskQueue
);
uv_close
((
uv_handle_t
*
)
uvTask
->
pipe
,
onUdfcPipeClose
);
uv_close
((
uv_handle_t
*
)
uvTask
->
pipe
,
onUdfcPipeClose
);
code
=
0
;
}
break
;
}
default:
{
...
...
@@ -1115,7 +1129,7 @@ int32_t udfcStartUvTask(SClientUvTaskNode *uvTask) {
}
}
return
0
;
return
code
;
}
void
udfClientAsyncCb
(
uv_async_t
*
async
)
{
...
...
@@ -1133,6 +1147,9 @@ void udfClientAsyncCb(uv_async_t *async) {
int32_t
code
=
udfcStartUvTask
(
task
);
if
(
code
==
0
)
{
QUEUE_INSERT_TAIL
(
&
udfc
->
uvProcTaskQueue
,
&
task
->
procTaskQueue
);
}
else
{
task
->
errCode
=
code
;
uv_sem_post
(
&
task
->
taskSem
);
}
}
...
...
@@ -1483,6 +1500,9 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
SUdfAggRes
*
udfRes
=
(
SUdfAggRes
*
)
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
SClientUdfUvSession
*
session
=
udfRes
->
session
;
if
(
session
==
NULL
)
{
return
TSDB_CODE_UDF_NO_FUNC_HANDLE
;
}
udfRes
->
finalResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
);
udfRes
->
interResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
)
+
session
->
outputLen
;
...
...
@@ -1535,6 +1555,9 @@ int32_t udfAggProcess(struct SqlFunctionCtx *pCtx) {
int32_t
udfAggFinalize
(
struct
SqlFunctionCtx
*
pCtx
,
SSDataBlock
*
pBlock
)
{
SUdfAggRes
*
udfRes
=
(
SUdfAggRes
*
)
GET_ROWCELL_INTERBUF
(
GET_RES_INFO
(
pCtx
));
SClientUdfUvSession
*
session
=
udfRes
->
session
;
if
(
session
==
NULL
)
{
return
TSDB_CODE_UDF_NO_FUNC_HANDLE
;
}
udfRes
->
finalResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
);
udfRes
->
interResBuf
=
(
char
*
)
udfRes
+
sizeof
(
SUdfAggRes
)
+
session
->
outputLen
;
...
...
source/libs/scalar/inc/sclInt.h
浏览文件 @
e8b467d9
...
...
@@ -27,13 +27,11 @@ typedef struct SScalarCtx {
SArray
*
pBlockList
;
/* element is SSDataBlock* */
SHashObj
*
pRes
;
/* element is SScalarParam */
void
*
param
;
// additional parameter (meta actually) for acquire value such as tbname/tags values
SHashObj
*
udf2Handle
;
}
SScalarCtx
;
#define SCL_DATA_TYPE_DUMMY_HASH 9000
#define SCL_DEFAULT_OP_NUM 10
#define SCL_DEFAULT_UDF_NUM 8
#define SCL_IS_CONST_NODE(_node) ((NULL == (_node)) || (QUERY_NODE_VALUE == (_node)->type) || (QUERY_NODE_NODE_LIST == (_node)->type))
#define SCL_IS_CONST_CALC(_ctx) (NULL == (_ctx)->pBlockList)
...
...
source/libs/scalar/src/scalar.c
浏览文件 @
e8b467d9
...
...
@@ -154,18 +154,6 @@ void sclFreeRes(SHashObj *res) {
taosHashCleanup
(
res
);
}
void
sclFreeUdfHandles
(
SHashObj
*
udf2handle
)
{
void
*
pIter
=
taosHashIterate
(
udf2handle
,
NULL
);
while
(
pIter
)
{
UdfcFuncHandle
*
handle
=
(
UdfcFuncHandle
*
)
pIter
;
if
(
handle
)
{
teardownUdf
(
*
handle
);
}
pIter
=
taosHashIterate
(
udf2handle
,
pIter
);
}
taosHashCleanup
(
udf2handle
);
}
void
sclFreeParam
(
SScalarParam
*
param
)
{
if
(
param
->
columnData
!=
NULL
)
{
colDataDestroy
(
param
->
columnData
);
...
...
@@ -375,28 +363,22 @@ int32_t sclExecFunction(SFunctionNode *node, SScalarCtx *ctx, SScalarParam *outp
if
(
fmIsUserDefinedFunc
(
node
->
funcId
))
{
UdfcFuncHandle
udfHandle
=
NULL
;
char
*
udfName
=
node
->
functionName
;
if
(
ctx
->
udf2Handle
)
{
UdfcFuncHandle
*
pHandle
=
taosHashGet
(
ctx
->
udf2Handle
,
udfName
,
strlen
(
udfName
));
if
(
pHandle
)
{
udfHandle
=
*
pHandle
;
}
}
if
(
udfHandle
==
NULL
)
{
code
=
setupUdf
(
udfName
,
&
udfHandle
);
code
=
setupUdf
(
node
->
functionName
,
&
udfHandle
);
if
(
code
!=
0
)
{
sclError
(
"fmExecFunction error. setupUdf. function name: %s, code:%d"
,
udf
Name
,
code
);
sclError
(
"fmExecFunction error. setupUdf. function name: %s, code:%d"
,
node
->
function
Name
,
code
);
goto
_return
;
}
if
(
ctx
->
udf2Handle
)
{
taosHashPut
(
ctx
->
udf2Handle
,
udfName
,
strlen
(
udfName
),
&
udfHandle
,
sizeof
(
UdfcFuncHandle
));
}
}
code
=
callUdfScalarFunc
(
udfHandle
,
params
,
paramNum
,
output
);
if
(
code
!=
0
)
{
sclError
(
"fmExecFunction error. callUdfScalarFunc. function name: %s, udf code:%d"
,
node
->
functionName
,
code
);
goto
_return
;
}
code
=
teardownUdf
(
udfHandle
);
if
(
code
!=
0
)
{
sclError
(
"fmExecFunction error. callUdfScalarFunc. function name: %s, udf code:%d"
,
node
->
functionName
,
code
);
goto
_return
;
}
}
else
{
SScalarFuncExecFuncs
ffpSet
=
{
0
};
code
=
fmGetScalarFuncExecFuncs
(
node
->
funcId
,
&
ffpSet
);
...
...
@@ -910,20 +892,15 @@ int32_t scalarCalculateConstants(SNode *pNode, SNode **pRes) {
SScalarCtx
ctx
=
{
0
};
ctx
.
pRes
=
taosHashInit
(
SCL_DEFAULT_OP_NUM
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
ctx
.
pRes
)
{
sclError
(
"taosHashInit result map failed, num:%d"
,
SCL_DEFAULT_OP_NUM
);
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
ctx
.
udf2Handle
=
taosHashInit
(
SCL_DEFAULT_UDF_NUM
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
if
(
NULL
==
ctx
.
udf2Handle
)
{
sclError
(
"taosHashInit udf to handle map failed, num:%d"
,
SCL_DEFAULT_OP_NUM
);
sclError
(
"taosHashInit failed, num:%d"
,
SCL_DEFAULT_OP_NUM
);
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
nodesRewriteExprPostOrder
(
&
pNode
,
sclConstantsRewriter
,
(
void
*
)
&
ctx
);
SCL_ERR_JRET
(
ctx
.
code
);
*
pRes
=
pNode
;
_return:
sclFreeUdfHandles
(
ctx
.
udf2Handle
);
sclFreeRes
(
ctx
.
pRes
);
return
code
;
}
...
...
@@ -939,14 +916,10 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
// TODO: OPT performance
ctx
.
pRes
=
taosHashInit
(
SCL_DEFAULT_OP_NUM
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
false
,
HASH_NO_LOCK
);
if
(
NULL
==
ctx
.
pRes
)
{
sclError
(
"taosHashInit result map failed, num:%d"
,
SCL_DEFAULT_OP_NUM
);
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
ctx
.
udf2Handle
=
taosHashInit
(
SCL_DEFAULT_UDF_NUM
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
);
if
(
NULL
==
ctx
.
udf2Handle
)
{
sclError
(
"taosHashInit udf to handle map failed, num:%d"
,
SCL_DEFAULT_OP_NUM
);
sclError
(
"taosHashInit failed, num:%d"
,
SCL_DEFAULT_OP_NUM
);
SCL_ERR_RET
(
TSDB_CODE_QRY_OUT_OF_MEMORY
);
}
nodesWalkExprPostOrder
(
pNode
,
sclCalcWalker
,
(
void
*
)
&
ctx
);
SCL_ERR_JRET
(
ctx
.
code
);
...
...
@@ -964,7 +937,6 @@ int32_t scalarCalculate(SNode *pNode, SArray *pBlockList, SScalarParam *pDst) {
_return:
//nodesDestroyNode(pNode);
sclFreeUdfHandles
(
ctx
.
udf2Handle
);
sclFreeRes
(
ctx
.
pRes
);
return
code
;
}
source/util/src/terror.c
浏览文件 @
e8b467d9
...
...
@@ -463,7 +463,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_UDF_PIPE_NO_PIPE, "udf no pipe")
TAOS_DEFINE_ERROR
(
TSDB_CODE_UDF_LOAD_UDF_FAILURE
,
"udf load failure"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_UDF_INVALID_STATE
,
"udf invalid state"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_UDF_INVALID_INPUT
,
"udf invalid function input"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_UDF_NO_FUNC_HANDLE
,
"udf no function handle"
)
//schemaless
TAOS_DEFINE_ERROR
(
TSDB_CODE_SML_INVALID_PROTOCOL_TYPE
,
"Invalid line protocol type"
)
TAOS_DEFINE_ERROR
(
TSDB_CODE_SML_INVALID_PRECISION_TYPE
,
"Invalid timestamp precision type"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录