提交 e0445e06 编写于 作者: S slzhou

fix: taos_connect in gpd_init method and taos_close in gpd_destroy method

上级 d156bff7
......@@ -29,8 +29,6 @@
#include "trpc.h"
// clang-foramt on
SArray* udfdResidentFuncs = NULL;
typedef struct SUdfdContext {
uv_loop_t * loop;
uv_pipe_t ctrlPipe;
......@@ -43,6 +41,8 @@ typedef struct SUdfdContext {
uv_mutex_t udfsMutex;
SHashObj * udfsHash;
SArray* residentFuncs;
bool printVersion;
} SUdfdContext;
......@@ -204,8 +204,8 @@ void udfdProcessSetupRequest(SUvUdfWork *uvUdf, SUdfRequest *request) {
udf->initFunc();
}
udf->resident = false;
for (int32_t i = 0; i < taosArrayGetSize(udfdResidentFuncs); ++i) {
char* funcName = taosArrayGet(udfdResidentFuncs, i);
for (int32_t i = 0; i < taosArrayGetSize(global.residentFuncs); ++i) {
char* funcName = taosArrayGet(global.residentFuncs, i);
if (strcmp(setup->udfName, funcName) == 0) {
udf->resident = true;
break;
......@@ -930,8 +930,6 @@ static int32_t udfdRun() {
uv_run(global.loop, UV_RUN_DEFAULT);
uv_loop_close(global.loop);
uv_mutex_destroy(&global.udfsMutex);
taosHashCleanup(global.udfsHash);
return 0;
}
......@@ -953,17 +951,17 @@ void udfdConnectMnodeThreadFunc(void *args) {
}
int32_t udfdInitResidentFuncs() {
udfdResidentFuncs = taosArrayInit(2, TSDB_FUNC_NAME_LEN);
global.residentFuncs = taosArrayInit(2, TSDB_FUNC_NAME_LEN);
char gpd[TSDB_FUNC_NAME_LEN] = "gpd";
taosArrayPush(udfdResidentFuncs, gpd);
taosArrayPush(global.residentFuncs, gpd);
char gpdBatch[TSDB_FUNC_NAME_LEN] = "gpdbatch";
taosArrayPush(udfdResidentFuncs, gpdBatch);
taosArrayPush(global.residentFuncs, gpdBatch);
return TSDB_CODE_SUCCESS;
}
int32_t udfdDeinitResidentFuncs() {
for (int32_t i = 0; i < taosArrayGetSize(udfdResidentFuncs); ++i) {
char* funcName = taosArrayGet(udfdResidentFuncs, i);
for (int32_t i = 0; i < taosArrayGetSize(global.residentFuncs); ++i) {
char* funcName = taosArrayGet(global.residentFuncs, i);
SUdf** udfInHash = taosHashGet(global.udfsHash, funcName, strlen(funcName));
if (udfInHash) {
taosHashRemove(global.udfsHash, funcName, strlen(funcName));
......@@ -975,9 +973,16 @@ int32_t udfdDeinitResidentFuncs() {
taosMemoryFree(udf);
}
}
taosArrayDestroy(global.residentFuncs);
return TSDB_CODE_SUCCESS;
}
int32_t udfdCleanup() {
uv_mutex_destroy(&global.udfsMutex);
taosHashCleanup(global.udfsHash);
return 0;
}
int main(int argc, char *argv[]) {
if (!taosCheckSystemIsLittleEnd()) {
printf("failed to start since on non-little-end machines\n");
......@@ -1026,5 +1031,6 @@ int main(int argc, char *argv[]) {
udfdCloseClientRpc();
udfdDeinitResidentFuncs();
udfdCleanup();
return 0;
}
......@@ -9,12 +9,16 @@
#endif
#include "taosudf.h"
TAOS* taos = NULL;
DLL_EXPORT int32_t gpd_init() {
taos = taos_connect("localhost", "root", "taosdata", "", 7100);
return 0;
}
DLL_EXPORT int32_t gpd_destroy() {
taos_close(taos);
taos_cleanup();
return 0;
}
......@@ -40,11 +44,6 @@ DLL_EXPORT int32_t gpd(SUdfDataBlock* block, SUdfColumn *resultCol) {
udfColDataSet(resultCol, i, (char *)&luckyNum, false);
}
}
taos_init();
TAOS* taos = taos_connect("localhost", "root", "taosdata", "", 7100);
if (taos == NULL) {
char* errstr = "can not connect";
}
TAOS_RES* res = taos_query(taos, "create database if not exists gpd");
if (taos_errno(res) != 0) {
char* errstr = taos_errstr(res);
......@@ -64,8 +63,6 @@ DLL_EXPORT int32_t gpd(SUdfDataBlock* block, SUdfColumn *resultCol) {
char* errstr = taos_errstr(res);
}
taos_close(taos);
taos_cleanup();
//to simulate actual processing delay by udf
#ifdef LINUX
usleep(1 * 1000); // usleep takes sleep time in us (1 millionth of a second)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册