From 6e1e4702a5f80db2895bbd9bbf16ce76da6395ea Mon Sep 17 00:00:00 2001 From: Bob Liu Date: Mon, 20 Nov 2023 11:13:09 +0800 Subject: [PATCH] adjust --- include/libs/nodes/nodes.h | 1 - source/dnode/mgmt/node_mgmt/src/dmEnv.c | 1 - source/libs/nodes/src/nodesCodeFuncs.c | 27 +++++++++++-------------- source/libs/nodes/src/nodesUtilFuncs.c | 1 - 4 files changed, 12 insertions(+), 18 deletions(-) diff --git a/include/libs/nodes/nodes.h b/include/libs/nodes/nodes.h index 136926a856..bcbfd245f8 100644 --- a/include/libs/nodes/nodes.h +++ b/include/libs/nodes/nodes.h @@ -101,7 +101,6 @@ typedef struct SNodeList { typedef struct SNodeAllocator SNodeAllocator; -void nodesInit(); int32_t nodesInitAllocatorSet(); void nodesDestroyAllocatorSet(); int32_t nodesCreateAllocator(int64_t queryId, int32_t chunkSize, int64_t* pAllocatorId); diff --git a/source/dnode/mgmt/node_mgmt/src/dmEnv.c b/source/dnode/mgmt/node_mgmt/src/dmEnv.c index c57043b8bb..acbb3554ce 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmEnv.c +++ b/source/dnode/mgmt/node_mgmt/src/dmEnv.c @@ -156,7 +156,6 @@ extern void s3End(); int32_t dmInit() { dInfo("start to init dnode env"); - nodesInit(); if (dmDiskInit() != 0) return -1; if (!dmCheckDataDirVersion()) return -1; if (!dmCheckDiskSpace()) return -1; diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 6771677aac..cf5bc528e3 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -46,7 +46,7 @@ typedef struct SBuiltinNodeDefinition { SBuiltinNodeDefinition funcNodes[QUERY_NODE_END] = {NULL}; static TdThreadOnce functionNodeInit = PTHREAD_ONCE_INIT; -static int32_t initNodeCode = -1; +volatile int32_t initNodeCode = -1; static void setFunc(const char* name, int32_t type, int32_t nodeSize, FExecNodeToJson toJsonFunc, FExecJsonToNode toNodeFunc, FExecDestoryNode destoryFunc) { @@ -59,19 +59,16 @@ static void setFunc(const char* name, int32_t type, int32_t nodeSize, FExecNodeT static void doInitNodeFuncArray(); -void nodesInit() { - taosThreadOnce(&functionNodeInit, doInitNodeFuncArray); -} - bool funcArrayCheck(int32_t type) { - if (type < 0 || QUERY_NODE_END < (type+1)) { - nodesError("funcArrayCheck unknown type = %d", type); + if (type < 0 || QUERY_NODE_END <= type) { + nodesError("funcArrayCheck out of range type = %d", type); return false; } if (initNodeCode != 0) { - nodesInit(); + taosThreadOnce(&functionNodeInit, doInitNodeFuncArray); } if (!funcNodes[type].name) { + nodesError("funcArrayCheck unsupported type = %d", type); return false; } return true; @@ -6494,7 +6491,7 @@ static int32_t jsonToInsertStmt(const SJson* pJson, void* pObj) { int32_t specificNodeToJson(const void* pObj, SJson* pJson) { ENodeType type = nodeType(pObj); if (!funcArrayCheck(type)) { - return TSDB_CODE_SUCCESS; + return TSDB_CODE_NOT_FOUND; } if (funcNodes[type].toJsonFunc) { @@ -6508,7 +6505,7 @@ int32_t specificNodeToJson(const void* pObj, SJson* pJson) { int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { ENodeType type = nodeType(pObj); if (!funcArrayCheck(type)) { - return TSDB_CODE_SUCCESS; + return TSDB_CODE_NOT_FOUND; } if (funcNodes[type].toNodeFunc) { @@ -7423,16 +7420,16 @@ void nodesDestroyNode(SNode* pNode) { return; } - int32_t index = nodeType(pNode); - if (!funcArrayCheck(index)) { + int32_t type = nodeType(pNode); + if (!funcArrayCheck(type)) { return; } - if (funcNodes[index].destoryFunc) { - funcNodes[index].destoryFunc(pNode); + if (funcNodes[type].destoryFunc) { + funcNodes[type].destoryFunc(pNode); nodesFree(pNode); return; } - nodesError("nodesDestroyNode unknown node type = %d", nodeType(pNode)); + nodesWarn("nodesDestroyNode unknown type = %d", type); nodesFree(pNode); return; } diff --git a/source/libs/nodes/src/nodesUtilFuncs.c b/source/libs/nodes/src/nodesUtilFuncs.c index 3a738dbbd2..2ea387792b 100644 --- a/source/libs/nodes/src/nodesUtilFuncs.c +++ b/source/libs/nodes/src/nodesUtilFuncs.c @@ -131,7 +131,6 @@ static void destroyNodeAllocator(void* p) { } int32_t nodesInitAllocatorSet() { - nodesInit(); if (g_allocatorReqRefPool >= 0) { nodesWarn("nodes already initialized"); return TSDB_CODE_SUCCESS;