From 8284d8b8e0f8b820a79e48db37c08bdabed21051 Mon Sep 17 00:00:00 2001 From: slzhou Date: Mon, 16 May 2022 13:27:04 +0800 Subject: [PATCH] fix: accquire rpc client in the same way as dmInitClient --- source/libs/function/src/udfd.c | 40 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/source/libs/function/src/udfd.c b/source/libs/function/src/udfd.c index 34681dc6cd..5f9787b329 100644 --- a/source/libs/function/src/udfd.c +++ b/source/libs/function/src/udfd.c @@ -570,27 +570,41 @@ int32_t udfdFillUdfInfoFromMNode(void *clientRpc, char *udfName, SUdf *udf) { return 0; } +static bool udfdRpcRfp(int32_t code) { + if (code == TSDB_CODE_RPC_REDIRECT) { + return true; + } else { + return false; + } +} + +#define INTERNAL_USER "_dnd" +#define INTERNAL_CKEY "_key" +#define INTERNAL_SECRET "_pwd" + int32_t udfdOpenClientRpc() { - char *pass = "taosdata"; - char *user = "root"; - char secretEncrypt[TSDB_PASSWORD_LEN + 1] = {0}; - taosEncryptPass_c((uint8_t *)pass, strlen(pass), secretEncrypt); SRpcInit rpcInit = {0}; - rpcInit.label = (char *)"UDFD"; + rpcInit.label = "UDFD"; rpcInit.numOfThreads = 1; - rpcInit.cfp = udfdProcessRpcRsp; + rpcInit.cfp = (RpcCfp)udfdProcessRpcRsp; rpcInit.sessions = 1024; rpcInit.connType = TAOS_CONN_CLIENT; - rpcInit.idleTime = 30 * 1000; - rpcInit.parent = &global; - - rpcInit.user = (char *)user; - rpcInit.ckey = (char *)"key"; - rpcInit.secret = (char *)secretEncrypt; + rpcInit.idleTime = tsShellActivityTimer * 1000; + rpcInit.user = INTERNAL_USER; + rpcInit.ckey = INTERNAL_CKEY; rpcInit.spi = 1; + rpcInit.parent = &global; + rpcInit.rfp = udfdRpcRfp; + + char pass[TSDB_PASSWORD_LEN + 1] = {0}; + taosEncryptPass_c((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass); + rpcInit.secret = pass; global.clientRpc = rpcOpen(&rpcInit); - + if (global.clientRpc == NULL) { + fnError("failed to init dnode rpc client"); + return -1; + } return 0; }