Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
71983725
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看板
提交
71983725
编写于
4月 19, 2022
作者:
S
slzhou
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
befor debugging teardown
上级
eae11bf8
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
34 addition
and
20 deletion
+34
-20
source/libs/function/inc/tudf.h
source/libs/function/inc/tudf.h
+1
-1
source/libs/function/src/tudf.c
source/libs/function/src/tudf.c
+11
-7
source/libs/function/src/udfd.c
source/libs/function/src/udfd.c
+18
-12
source/libs/function/test/runUdf.c
source/libs/function/test/runUdf.c
+4
-0
未找到文件。
source/libs/function/inc/tudf.h
浏览文件 @
71983725
...
...
@@ -136,7 +136,7 @@ typedef int32_t (*TUdfTeardownFunc)();
//typedef int32_t addFixedLengthColumnData(SColumnData *columnData, int rowIndex, bool isNull, int32_t colBytes, char* data);
//typedef int32_t addVariableLengthColumnData(SColumnData *columnData, int rowIndex, bool isNull, int32_t dataLen, char * data);
typedef
int32_t
(
*
TUdfFreeUdfColumn
Data
Func
)(
SUdfColumn
*
columnData
);
typedef
int32_t
(
*
TUdfFreeUdfColumnFunc
)(
SUdfColumn
*
columnData
);
typedef
int32_t
(
*
TUdfScalarProcFunc
)(
SUdfDataBlock
block
,
SUdfColumn
*
resultCol
);
typedef
int32_t
(
*
TUdfAggInitFunc
)(
SUdfInterBuf
*
buf
);
...
...
source/libs/function/src/tudf.c
浏览文件 @
71983725
...
...
@@ -318,7 +318,7 @@ int32_t encodeUdfRequest(void** buf, const SUdfRequest* request) {
void
*
decodeUdfRequest
(
const
void
*
buf
,
SUdfRequest
*
request
)
{
request
->
msgLen
=
*
(
int32_t
*
)(
buf
);
POINTER_SHIFT
(
buf
,
sizeof
(
request
->
msgLen
));
buf
=
POINTER_SHIFT
(
buf
,
sizeof
(
request
->
msgLen
));
buf
=
taosDecodeFixedI64
(
buf
,
&
request
->
seqNum
);
buf
=
taosDecodeFixedI8
(
buf
,
&
request
->
type
);
...
...
@@ -429,7 +429,7 @@ int32_t encodeUdfResponse(void** buf, const SUdfResponse* rsp) {
void
*
decodeUdfResponse
(
const
void
*
buf
,
SUdfResponse
*
rsp
)
{
rsp
->
msgLen
=
*
(
int32_t
*
)(
buf
);
POINTER_SHIFT
(
buf
,
sizeof
(
rsp
->
msgLen
));
buf
=
POINTER_SHIFT
(
buf
,
sizeof
(
rsp
->
msgLen
));
buf
=
taosDecodeFixedI64
(
buf
,
&
rsp
->
seqNum
);
buf
=
taosDecodeFixedI8
(
buf
,
&
rsp
->
type
);
buf
=
taosDecodeFixedI32
(
buf
,
&
rsp
->
code
);
...
...
@@ -786,9 +786,10 @@ int32_t createUdfcUvTask(SClientUdfTask *task, int8_t uvTaskType, SClientUvTaskN
}
int32_t
bufLen
=
encodeUdfRequest
(
NULL
,
&
request
);
request
.
msgLen
=
bufLen
;
void
*
buf
=
taosMemoryMalloc
(
bufLen
);
void
*
bufBegin
=
taosMemoryMalloc
(
bufLen
);
void
*
buf
=
bufBegin
;
encodeUdfRequest
(
&
buf
,
&
request
);
uvTask
->
reqBuf
=
uv_buf_init
(
buf
,
bufLen
);
uvTask
->
reqBuf
=
uv_buf_init
(
buf
Begin
,
bufLen
);
uvTask
->
seqNum
=
request
.
seqNum
;
}
else
if
(
uvTaskType
==
UV_TASK_DISCONNECT
)
{
uvTask
->
pipe
=
task
->
session
->
udfSvcPipe
;
...
...
@@ -931,7 +932,7 @@ void onUdfdExit(uv_process_t *req, int64_t exit_status, int term_signal) {
gUdfcState
=
UDFC_STATE_RESTARTING
;
//TODO: asynchronous without blocking. how to do it
cleanUpUvTasks
();
startUdfd
();
//
startUdfd();
}
}
...
...
@@ -966,7 +967,7 @@ void constructUdfService(void *argsThread) {
uv_loop_init
(
&
gUdfdLoop
);
//TODO spawn error
startUdfd
();
//
startUdfd();
uv_async_init
(
&
gUdfdLoop
,
&
gUdfLoopTaskAync
,
udfClientAsyncCb
);
uv_async_init
(
&
gUdfdLoop
,
&
gUdfLoopStopAsync
,
udfStopAsyncCb
);
...
...
@@ -1009,7 +1010,8 @@ int32_t udfcRunUvTask(SClientUdfTask *task, int8_t uvTaskType) {
udfcGetUvTaskResponseResult
(
task
,
uvTask
);
if
(
uvTaskType
==
UV_TASK_CONNECT
)
{
task
->
session
->
udfSvcPipe
=
uvTask
->
pipe
;
}
taosMemoryFree
(
uvTask
);
}
taosMemoryFree
(
uvTask
);
uvTask
=
NULL
;
return
task
->
errCode
;
}
...
...
@@ -1050,6 +1052,8 @@ int32_t callUdf(UdfHandle handle, int8_t callType, SSDataBlock *input, SUdfInter
task
->
type
=
UDF_TASK_CALL
;
SUdfCallRequest
*
req
=
&
task
->
_call
.
req
;
req
->
udfHandle
=
task
->
session
->
severHandle
;
switch
(
callType
)
{
case
TSDB_UDF_CALL_AGG_INIT
:
{
req
->
initFirst
=
1
;
...
...
source/libs/function/src/udfd.c
浏览文件 @
71983725
...
...
@@ -49,7 +49,7 @@ typedef struct SUdf {
uv_lib_t
lib
;
TUdfScalarProcFunc
scalarProcFunc
;
TUdfFreeUdfColumn
DataFunc
freeUdfColumnData
;
TUdfFreeUdfColumn
Func
freeUdfColumn
;
}
SUdf
;
//TODO: low priority: change name onxxx to xxxCb, and udfc or udfd as prefix
...
...
@@ -72,18 +72,22 @@ void udfdProcessRequest(uv_work_t *req) {
SUdfSetupRequest
*
setup
=
&
request
.
setup
;
strcpy
(
udf
->
name
,
setup
->
udfName
);
//TODO: retrive udf info from mnode
char
*
path
=
"udf1.so"
;
char
*
path
=
"
lib
udf1.so"
;
int
err
=
uv_dlopen
(
path
,
&
udf
->
lib
);
if
(
err
!=
0
)
{
debugPrint
(
"can not load library %s. error: %s"
,
path
,
uv_strerror
(
err
));
//TODO set error
}
char
normalFuncName
[
32
]
=
{
0
};
char
normalFuncName
[
TSDB_FUNC_NAME_LEN
]
=
{
0
};
strcpy
(
normalFuncName
,
setup
->
udfName
);
//TODO error,
//TODO error,
multi-thread, same udf, lock it
//TODO find all functions normal, init, destroy, normal, merge, finalize
uv_dlsym
(
&
udf
->
lib
,
normalFuncName
,
(
void
**
)
(
&
udf
->
scalarProcFunc
));
char
freeFuncName
[
TSDB_FUNC_NAME_LEN
+
5
];
strncpy
(
freeFuncName
,
normalFuncName
,
strlen
(
normalFuncName
));
strcat
(
freeFuncName
,
"_free"
);
uv_dlsym
(
&
udf
->
lib
,
freeFuncName
,
(
void
**
)(
&
udf
->
freeUdfColumn
));
SUdfHandle
*
handle
=
taosMemoryMalloc
(
sizeof
(
SUdfHandle
));
handle
->
udf
=
udf
;
...
...
@@ -96,10 +100,11 @@ void udfdProcessRequest(uv_work_t *req) {
rsp
.
setupRsp
.
udfHandle
=
(
int64_t
)
(
handle
);
int32_t
len
=
encodeUdfResponse
(
NULL
,
&
rsp
);
rsp
.
msgLen
=
len
;
void
*
buf
=
taosMemoryMalloc
(
len
);
void
*
bufBegin
=
taosMemoryMalloc
(
len
);
void
*
buf
=
bufBegin
;
encodeUdfResponse
(
&
buf
,
&
rsp
);
uvUdf
->
output
=
uv_buf_init
(
buf
,
len
);
uvUdf
->
output
=
uv_buf_init
(
buf
Begin
,
len
);
taosMemoryFree
(
uvUdf
->
input
.
base
);
break
;
...
...
@@ -131,12 +136,13 @@ void udfdProcessRequest(uv_work_t *req) {
int32_t
len
=
encodeUdfResponse
(
NULL
,
rsp
);
rsp
->
msgLen
=
len
;
void
*
buf
=
taosMemoryMalloc
(
len
);
void
*
bufBegin
=
taosMemoryMalloc
(
len
);
void
*
buf
=
bufBegin
;
encodeUdfResponse
(
&
buf
,
rsp
);
uvUdf
->
output
=
uv_buf_init
(
buf
,
len
);
uvUdf
->
output
=
uv_buf_init
(
buf
Begin
,
len
);
//TODO: free
udf
->
freeUdfColumn
Data
(
&
output
);
udf
->
freeUdfColumn
(
&
output
);
taosMemoryFree
(
uvUdf
->
input
.
base
);
break
;
...
...
@@ -160,12 +166,12 @@ void udfdProcessRequest(uv_work_t *req) {
rsp
->
seqNum
=
request
.
seqNum
;
rsp
->
type
=
request
.
type
;
rsp
->
code
=
0
;
SUdfTeardownResponse
*
subRsp
=
&
response
.
teardownRsp
;
int32_t
len
=
encodeUdfResponse
(
NULL
,
rsp
);
void
*
buf
=
taosMemoryMalloc
(
len
);
rsp
->
msgLen
=
len
;
void
*
bufBegin
=
taosMemoryMalloc
(
len
);
void
*
buf
=
bufBegin
;
encodeUdfResponse
(
&
buf
,
rsp
);
uvUdf
->
output
=
uv_buf_init
(
buf
,
len
);
uvUdf
->
output
=
uv_buf_init
(
buf
Begin
,
len
);
taosMemoryFree
(
uvUdf
->
input
.
base
);
break
;
...
...
source/libs/function/test/runUdf.c
浏览文件 @
71983725
...
...
@@ -29,11 +29,15 @@ int main(int argc, char *argv[]) {
pBlock
->
pDataBlock
=
taosArrayInit
(
1
,
sizeof
(
SColumnInfoData
));
pBlock
->
info
.
numOfCols
=
1
;
pBlock
->
info
.
rows
=
4
;
char
data
[
16
]
=
{
0
};
char
bitmap
[
1
]
=
{
0
};
for
(
int32_t
i
=
0
;
i
<
pBlock
->
info
.
numOfCols
;
++
i
)
{
SColumnInfoData
colInfo
=
{
0
};
colInfo
.
info
.
type
=
TSDB_DATA_TYPE_INT
;
colInfo
.
info
.
bytes
=
sizeof
(
int32_t
);
colInfo
.
info
.
colId
=
1
;
colInfo
.
pData
=
data
;
colInfo
.
nullbitmap
=
bitmap
;
for
(
int32_t
j
=
0
;
j
<
pBlock
->
info
.
rows
;
++
j
)
{
colDataAppendInt32
(
&
colInfo
,
j
,
&
j
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录