From b017d2a4c8480cd2df03a6e78309e4074a979419 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 15 Apr 2022 15:04:17 +0800 Subject: [PATCH 01/13] refactor: adjust logs and code style --- source/common/src/tglobal.c | 2 +- source/util/src/tconfig.c | 6 +++--- tools/shell/src/shellMain.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 9226e9aa37..49f4afc12b 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -238,7 +238,7 @@ static int32_t taosLoadCfg(SConfig *pCfg, const char *inputCfgDir, const char *e if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgDir) != 0) { if (cfgLoad(pCfg, CFG_STYPE_CFG_FILE, cfgFile) != 0) { - uError("failed to load from config file:%s since %s", cfgFile, terrstr()); + uInfo("cfg file:%s not read since %s", cfgFile, terrstr()); return 0; } } diff --git a/source/util/src/tconfig.c b/source/util/src/tconfig.c index 74d7c15e78..06a6b8317d 100644 --- a/source/util/src/tconfig.c +++ b/source/util/src/tconfig.c @@ -591,12 +591,12 @@ void cfgDumpCfg(SConfig *pCfg, bool tsc, bool dump) { } int32_t cfgLoadFromEnvVar(SConfig *pConfig) { - uInfo("load from env variables not implemented yet"); + uDebug("load from env variables not implemented yet"); return 0; } int32_t cfgLoadFromEnvFile(SConfig *pConfig, const char *filepath) { - uInfo("load from env file not implemented yet"); + uDebug("load from env file not implemented yet"); return 0; } @@ -655,6 +655,6 @@ int32_t cfgLoadFromCfgFile(SConfig *pConfig, const char *filepath) { } int32_t cfgLoadFromApollUrl(SConfig *pConfig, const char *url) { - uInfo("load from apoll url not implemented yet"); + uDebug("load from apoll url not implemented yet"); return 0; } diff --git a/tools/shell/src/shellMain.c b/tools/shell/src/shellMain.c index 70563c79e6..8ca8142eca 100644 --- a/tools/shell/src/shellMain.c +++ b/tools/shell/src/shellMain.c @@ -45,7 +45,7 @@ static tsem_t cancelSem; static struct argp_option options[] = { {"host", 'h', "HOST", 0, "TDengine server FQDN to connect. The default host is localhost."}, - {"password", 'p', 0, 0, "The password to use when connecting to the server."}, + {"password", 'p', 0, 0, "The password to use when connecting to the server."}, {"port", 'P', "PORT", 0, "The TCP/IP port number to use for the connection."}, {"user", 'u', "USER", 0, "The user name to use when connecting to the server."}, {"auth", 'A', "Auth", 0, "The auth string to use when connecting to the server."}, From 9fae3397100d8f8cd2632f52ea56829a6e9b85fc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 16 Apr 2022 16:35:24 +0800 Subject: [PATCH 02/13] enh: add tag index filter impl --- source/libs/executor/src/indexoperator.c | 154 +++++++++++++++++++++-- 1 file changed, 144 insertions(+), 10 deletions(-) diff --git a/source/libs/executor/src/indexoperator.c b/source/libs/executor/src/indexoperator.c index b5b9cdb740..84098bba2e 100644 --- a/source/libs/executor/src/indexoperator.c +++ b/source/libs/executor/src/indexoperator.c @@ -22,35 +22,170 @@ typedef struct SIFCtx { SHashObj *pRes; /* element is SScalarParam */ } SIFCtx; +#define SIF_ERR_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + return _code; \ + } \ + } while (0) +#define SIF_RET(c) \ + do { \ + int32_t _code = c; \ + if (_code != TSDB_CODE_SUCCESS) { \ + terrno = _code; \ + } \ + return _code; \ + } while (0) +#define SIF_ERR_JRET(c) \ + do { \ + code = c; \ + if (code != TSDB_CODE_SUCCESS) { \ + terrno = code; \ + goto _return; \ + } \ + } while (0) + typedef struct SIFParam { SArray * result; SHashObj *pFilter; } SIFParam; + +typedef int32_t (*sif_func_t)(SNode *left, SNode *rigth, SIFParam *output); // construct tag filter operator later -static void destroyTagFilterOperatorInfo(void *param) { - STagFilterOperatorInfo *pInfo = (STagFilterOperatorInfo *)param; -} +static void destroyTagFilterOperatorInfo(void *param) { STagFilterOperatorInfo *pInfo = (STagFilterOperatorInfo *)param; } static void sifFreeParam(SIFParam *param) { if (param == NULL) return; taosArrayDestroy(param->result); } -int32_t sifInitOperParams(SIFParam *params, SOperatorNode *node, SIFCtx *ctx) { - int32_t code = 0; - return code; +static int32_t sifGetOperParamNum(EOperatorType ty) { + if (OP_TYPE_IS_NULL == ty || OP_TYPE_IS_NOT_NULL == ty || OP_TYPE_IS_TRUE == ty || OP_TYPE_IS_NOT_TRUE == ty || OP_TYPE_IS_FALSE == ty || + OP_TYPE_IS_NOT_FALSE == ty || OP_TYPE_IS_UNKNOWN == ty || OP_TYPE_IS_NOT_UNKNOWN == ty || OP_TYPE_MINUS == ty) { + return 1; + } + return 2; } +static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) { + switch (nodeType(node)) { + case QUERY_NODE_VALUE: { + SValueNode *vn = (SValueNode *)node; + + break; + } + case QUERY_NODE_COLUMN: { + SColumnNode *cn = (SColumnNode *)node; + + break; + } + case QUERY_NODE_NODE_LIST: { + SNodeListNode *nl = (SNodeListNode *)node; + if (LIST_LENGTH(nl->pNodeList) <= 0) { + qError("invalid length for node:%p, length: %d", node, LIST_LENGTH(nl->pNodeList)); + SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + + if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) { + taosHashCleanup(param->pFilter); + qError("taosHashPut nodeList failed, size:%d", (int32_t)sizeof(*param)); + SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + break; + } + case QUERY_NODE_FUNCTION: + case QUERY_NODE_OPERATOR: + case QUERY_NODE_LOGIC_CONDITION: { + SIFParam *res = (SIFParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES); + if (NULL == res) { + qError("no result for node, type:%d, node:%p", nodeType(node), node); + SIF_ERR_RET(TSDB_CODE_QRY_APP_ERROR); + } + *param = *res; + break; + } + default: + break; + } + return TSDB_CODE_SUCCESS; +} + +static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx *ctx) { + int32_t code = 0; + int32_t nParam = sifGetOperParamNum(node->opType); + if (NULL == node->pLeft || (nParam == 2 && NULL == node->pRight)) { + qError("invalid operation node, left: %p, rigth: %p", node->pLeft, node->pRight); + SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT); + } + SIFParam *paramList = taosMemoryCalloc(nParam, sizeof(SIFParam)); + if (NULL == paramList) { + SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SIF_ERR_JRET(sifInitParam(node->pLeft, ¶mList[0], ctx)); + if (nParam > 1) { + SIF_ERR_JRET(sifInitParam(node->pRight, ¶mList[0], ctx)); + } + *params = paramList; + SIF_RET(TSDB_CODE_SUCCESS); +_return: + taosMemoryFree(paramList); + SIF_RET(code); +} +// int32_t sifInitOperParams(SIFParam *params, SOperatorNode *node, SIFCtx *ctx) { +// int32_t code = 0; +// return code; +//} static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *output) { qError("index-filter not support buildin function"); + return TSDB_CODE_QRY_INVALID_INPUT; +} + +static int32_t sifLessThanFunc(SNode *left, SNode *rigth, SIFParam *output) { + // impl later return TSDB_CODE_SUCCESS; } +static int32_t sifDefaultFunc(SNode *left, SNode *rigth, SIFParam *output) { + // add more except + return TSDB_CODE_QRY_INVALID_INPUT; +} + +static sif_func_t sifGetOperFn(int32_t funcId) { + // impl later + switch (funcId) { + case OP_TYPE_LOWER_THAN: + return sifLessThanFunc; + default: + return sifDefaultFunc; + } + return sifDefaultFunc; +} static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) { + int32_t code = 0; SIFParam *params = NULL; + SIF_ERR_RET(sifInitOperParams(¶ms, node, ctx)); - return TSDB_CODE_SUCCESS; + int32_t nParam = sifGetOperParamNum(node->opType); + if (nParam <= 1) { + SIF_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); + } + sif_func_t operFn = sifGetOperFn(node->opType); + + return operFn(node->pLeft, node->pRight, output); +_return: + taosMemoryFree(params); + SIF_RET(code); } -static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *output) { return TSDB_CODE_SUCCESS; } +static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *output) { + if (NULL == node->pParameterList || node->pParameterList->length <= 0) { + qError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0); + return TSDB_CODE_QRY_INVALID_INPUT; + } + // impl later + return TSDB_CODE_SUCCESS; +} static EDealRes sifWalkFunction(SNode *pNode, void *context) { // impl later @@ -104,8 +239,7 @@ static EDealRes sifWalkOper(SNode *pNode, void *context) { } EDealRes sifCalcWalker(SNode *node, void *context) { - if (QUERY_NODE_VALUE == nodeType(node) || QUERY_NODE_NODE_LIST == nodeType(node) || - QUERY_NODE_COLUMN == nodeType(node)) { + if (QUERY_NODE_VALUE == nodeType(node) || QUERY_NODE_NODE_LIST == nodeType(node) || QUERY_NODE_COLUMN == nodeType(node)) { return DEAL_RES_CONTINUE; } SIFCtx *ctx = (SIFCtx *)context; From fe367b5ef49ec0f16d37d5c760f657f9a088966b Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 16 Apr 2022 17:56:06 +0800 Subject: [PATCH 03/13] enh: add tag index filter impl --- source/libs/executor/src/indexoperator.c | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/source/libs/executor/src/indexoperator.c b/source/libs/executor/src/indexoperator.c index 84098bba2e..edffe24ac4 100644 --- a/source/libs/executor/src/indexoperator.c +++ b/source/libs/executor/src/indexoperator.c @@ -146,6 +146,52 @@ static int32_t sifLessThanFunc(SNode *left, SNode *rigth, SIFParam *output) { // impl later return TSDB_CODE_SUCCESS; } +static int32_t sifLessEqualFunc(SNode *left, SNode *rigth, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} +static int32_t sifGreaterThanFunc(SNode *left, SNode *rigth, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} +static int32_t sifGreaterEqualFunc(SNode *left, SNode *rigth, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} + +static int32_t sifEqualFunc(SNode *left, SNode *rigth, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} +static int32_t sifNotEqualFunc(SNode *left, SNode *rigth, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} +static int32_t sifInFunc(SNode *left, SNode *rigth, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} +static int32_t sifNotInFunc(SNode *left, SNode *right, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} +static int32_t sifLikeFunc(SNode *left, SNode *right, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} +static int32_t sifNotLikeFunc(SNode *left, SNode *right, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} + +static int32_t sifMatchFunc(SNode *left, SNode *rigth, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} +static int32_t sifNotMatchFunc(SNode *left, SNode *rigth, SIFParam *output) { + // impl later + return TSDB_CODE_SUCCESS; +} static int32_t sifDefaultFunc(SNode *left, SNode *rigth, SIFParam *output) { // add more except return TSDB_CODE_QRY_INVALID_INPUT; @@ -154,8 +200,30 @@ static int32_t sifDefaultFunc(SNode *left, SNode *rigth, SIFParam *output) { static sif_func_t sifGetOperFn(int32_t funcId) { // impl later switch (funcId) { + case OP_TYPE_GREATER_THAN: + return sifGreaterThanFunc; + case OP_TYPE_GREATER_EQUAL: + return sifGreaterEqualFunc; case OP_TYPE_LOWER_THAN: return sifLessThanFunc; + case OP_TYPE_LOWER_EQUAL: + return sifLessEqualFunc; + case OP_TYPE_EQUAL: + return sifEqualFunc; + case OP_TYPE_NOT_EQUAL: + return sifNotEqualFunc; + case OP_TYPE_IN: + return sifInFunc; + case OP_TYPE_NOT_IN: + return sifNotInFunc; + case OP_TYPE_LIKE: + return sifLikeFunc; + case OP_TYPE_NOT_LIKE: + return sifNotLikeFunc; + case OP_TYPE_MATCH: + return sifMatchFunc; + case OP_TYPE_NMATCH: + return sifNotMatchFunc; default: return sifDefaultFunc; } From f090d78c67075a315c7bfe4783357f3101b250f7 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sat, 16 Apr 2022 11:22:49 +0000 Subject: [PATCH 04/13] refact vnode meta --- source/dnode/vnode/CMakeLists.txt | 5 +- source/dnode/vnode/src/inc/meta.h | 46 ++++------ source/dnode/vnode/src/inc/vnd.h | 12 +-- source/dnode/vnode/src/meta/metaMain.c | 111 ------------------------ source/dnode/vnode/src/meta/metaOpen.c | 66 ++++++++++++++ source/dnode/vnode/src/meta/metaTbUid.c | 30 ------- source/dnode/vnode/src/vnd/vnodeCfg.c | 7 -- source/dnode/vnode/src/vnd/vnodeOpen.c | 11 +-- 8 files changed, 94 insertions(+), 194 deletions(-) delete mode 100644 source/dnode/vnode/src/meta/metaMain.c create mode 100644 source/dnode/vnode/src/meta/metaOpen.c delete mode 100644 source/dnode/vnode/src/meta/metaTbUid.c diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index c0e458219c..5a6fdd1b40 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -18,12 +18,11 @@ target_sources( "src/vnd/vnodeSvr.c" # meta - # "src/meta/metaBDBImpl.c" + "src/meta/metaOpen.c" "src/meta/metaIdx.c" - "src/meta/metaMain.c" "src/meta/metaTable.c" - "src/meta/metaTbUid.c" "src/meta/metaTDBImpl.c" + # "src/meta/metaBDBImpl.c" # tsdb "src/tsdb/tsdbTDBImpl.c" diff --git a/source/dnode/vnode/src/inc/meta.h b/source/dnode/vnode/src/inc/meta.h index f30696c9ac..fb875a46e0 100644 --- a/source/dnode/vnode/src/inc/meta.h +++ b/source/dnode/vnode/src/inc/meta.h @@ -20,7 +20,6 @@ extern "C" { #endif -typedef struct SMetaCache SMetaCache; typedef struct SMetaIdx SMetaIdx; typedef struct SMetaDB SMetaDB; typedef struct SMCtbCursor SMCtbCursor; @@ -36,13 +35,22 @@ typedef struct SMSmaCursor SMSmaCursor; #define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("META ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0) // clang-format on +// metaOpen ================== +int metaOpen(SVnode* pVnode, SMeta** ppMeta); +int metaClose(SMeta* pMeta); + +// metaIdx ================== +int metaOpenIdx(SMeta* pMeta); +void metaCloseIdx(SMeta* pMeta); +int metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions); +int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid); + +static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64(); } + #define META_SUPER_TABLE TD_SUPER_TABLE #define META_CHILD_TABLE TD_CHILD_TABLE #define META_NORMAL_TABLE TD_NORMAL_TABLE -SMeta* metaOpen(const char* path, SMemAllocatorFactory* pMAF); -void metaClose(SMeta* pMeta); -void metaRemove(const char* path); int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg); int metaDropTable(SMeta* pMeta, tb_uid_t uid); int metaCommit(SMeta* pMeta); @@ -71,37 +79,15 @@ int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid); int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg); int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid); -// SMetaCache -int metaOpenCache(SMeta* pMeta); -void metaCloseCache(SMeta* pMeta); - // SMetaIdx -int metaOpenIdx(SMeta* pMeta); -void metaCloseIdx(SMeta* pMeta); -int metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions); -int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid); -// STbUidGnrt -typedef struct STbUidGenerator { - tb_uid_t nextUid; -} STbUidGenerator; - -// STableUidGenerator -int metaOpenUidGnrt(SMeta* pMeta); -void metaCloseUidGnrt(SMeta* pMeta); - -// tb_uid_t -#define IVLD_TB_UID 0 tb_uid_t metaGenerateUid(SMeta* pMeta); struct SMeta { - char* path; - SVnode* pVnode; - SMetaDB* pDB; - SMetaIdx* pIdx; - SMetaCache* pCache; - STbUidGenerator uidGnrt; - SMemAllocatorFactory* pmaf; + char* path; + SVnode* pVnode; + SMetaDB* pDB; + SMetaIdx* pIdx; }; #ifdef __cplusplus diff --git a/source/dnode/vnode/src/inc/vnd.h b/source/dnode/vnode/src/inc/vnd.h index cb40900e81..6be6c07e30 100644 --- a/source/dnode/vnode/src/inc/vnd.h +++ b/source/dnode/vnode/src/inc/vnd.h @@ -44,6 +44,11 @@ int vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg); int vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg); int vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo); int vnodeLoadInfo(const char* dir, SVnodeInfo* pInfo); +int vnodeBegin(SVnode* pVnode, int option); +int vnodeSyncCommit(SVnode* pVnode); +int vnodeAsyncCommit(SVnode* pVnode); + +#define vnodeShouldCommit vnodeBufPoolIsFull #if 1 // SVBufPool @@ -84,13 +89,8 @@ bool vmaIsFull(SVMemAllocator* pVMA); // vnodeCfg.h extern const SVnodeCfg vnodeCfgDefault; -int vnodeCheckCfg(const SVnodeCfg*); -void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc); +int vnodeCheckCfg(const SVnodeCfg*); -// For commit -#define vnodeShouldCommit vnodeBufPoolIsFull -int vnodeSyncCommit(SVnode* pVnode); -int vnodeAsyncCommit(SVnode* pVnode); #endif #ifdef __cplusplus diff --git a/source/dnode/vnode/src/meta/metaMain.c b/source/dnode/vnode/src/meta/metaMain.c deleted file mode 100644 index 879a7e8a6f..0000000000 --- a/source/dnode/vnode/src/meta/metaMain.c +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "tcoding.h" - -#include "vnodeInt.h" - -static SMeta *metaNew(const char *path, SMemAllocatorFactory *pMAF); -static void metaFree(SMeta *pMeta); -static int metaOpenImpl(SMeta *pMeta); -static void metaCloseImpl(SMeta *pMeta); - -SMeta *metaOpen(const char *path, SMemAllocatorFactory *pMAF) { - SMeta *pMeta = NULL; - - // Allocate handle - pMeta = metaNew(path, pMAF); - if (pMeta == NULL) { - // TODO: handle error - return NULL; - } - - // Create META path (TODO) - taosMkDir(path); - - // Open meta - if (metaOpenImpl(pMeta) < 0) { - metaFree(pMeta); - return NULL; - } - - return pMeta; -} - -void metaClose(SMeta *pMeta) { - if (pMeta) { - metaCloseImpl(pMeta); - metaFree(pMeta); - } -} - -void metaRemove(const char *path) { taosRemoveDir(path); } - -/* ------------------------ STATIC METHODS ------------------------ */ -static SMeta *metaNew(const char *path, SMemAllocatorFactory *pMAF) { - SMeta *pMeta; - size_t psize = strlen(path); - - pMeta = (SMeta *)taosMemoryCalloc(1, sizeof(*pMeta)); - if (pMeta == NULL) { - return NULL; - } - - pMeta->path = strdup(path); - if (pMeta->path == NULL) { - metaFree(pMeta); - return NULL; - } - - return pMeta; -}; - -static void metaFree(SMeta *pMeta) { - if (pMeta) { - taosMemoryFreeClear(pMeta->path); - taosMemoryFree(pMeta); - } -} - -static int metaOpenImpl(SMeta *pMeta) { - // Open meta db - if (metaOpenDB(pMeta) < 0) { - // TODO: handle error - metaCloseImpl(pMeta); - return -1; - } - - // Open meta index - if (metaOpenIdx(pMeta) < 0) { - // TODO: handle error - metaCloseImpl(pMeta); - return -1; - } - - // Open meta table uid generator - if (metaOpenUidGnrt(pMeta) < 0) { - // TODO: handle error - metaCloseImpl(pMeta); - return -1; - } - - return 0; -} - -static void metaCloseImpl(SMeta *pMeta) { - metaCloseUidGnrt(pMeta); - metaCloseIdx(pMeta); - metaCloseDB(pMeta); -} \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaOpen.c b/source/dnode/vnode/src/meta/metaOpen.c new file mode 100644 index 0000000000..4419420e59 --- /dev/null +++ b/source/dnode/vnode/src/meta/metaOpen.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#include "vnodeInt.h" + +int metaOpen(SVnode *pVnode, SMeta **ppMeta) { + SMeta *pMeta = NULL; + int slen; + + *ppMeta = NULL; + + // create handle + slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(VNODE_META_DIR) + 3; + if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + slen)) == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + pMeta->path = (char *)&pMeta[1]; + sprintf(pMeta->path, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP, + VNODE_META_DIR); + pMeta->pVnode = pVnode; + + // create path if not created yet + taosMkDir(pMeta->path); + + // open meta + if (metaOpenDB(pMeta) < 0) { + goto _err; + } + + if (metaOpenIdx(pMeta) < 0) { + goto _err; + } + + *ppMeta = pMeta; + return 0; + +_err: + if (pMeta->pIdx) metaCloseIdx(pMeta); + if (pMeta->pDB) metaCloseDB(pMeta); + taosMemoryFree(pMeta); + return -1; +} + +int metaClose(SMeta *pMeta) { + if (pMeta) { + metaCloseIdx(pMeta); + metaCloseDB(pMeta); + taosMemoryFree(pMeta); + } + + return 0; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/meta/metaTbUid.c b/source/dnode/vnode/src/meta/metaTbUid.c deleted file mode 100644 index 27a2ecfb19..0000000000 --- a/source/dnode/vnode/src/meta/metaTbUid.c +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#include "vnodeInt.h" - -int metaOpenUidGnrt(SMeta *pMeta) { - // Init a generator - pMeta->uidGnrt.nextUid = IVLD_TB_UID; - return 0; -} - -void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */ -} - -tb_uid_t metaGenerateUid(SMeta *pMeta) { - // Generate a new table UID - return tGenIdPI64(); -} diff --git a/source/dnode/vnode/src/vnd/vnodeCfg.c b/source/dnode/vnode/src/vnd/vnodeCfg.c index 34b983c20c..a5596dc998 100644 --- a/source/dnode/vnode/src/vnd/vnodeCfg.c +++ b/source/dnode/vnode/src/vnd/vnodeCfg.c @@ -23,11 +23,6 @@ int vnodeCheckCfg(const SVnodeCfg *pCfg) { return 0; } -#if 1 //====================================================================== -void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) { - memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeCfg)); -} - int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) { uint32_t hashValue = 0; @@ -47,5 +42,3 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) { return TSDB_CODE_SUCCESS; } - -#endif \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeOpen.c b/source/dnode/vnode/src/vnd/vnodeOpen.c index d0433b7764..5d4b07ec18 100644 --- a/source/dnode/vnode/src/vnd/vnodeOpen.c +++ b/source/dnode/vnode/src/vnd/vnodeOpen.c @@ -65,14 +65,15 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { } // create handle - pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode)); + pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode) + strlen(path) + 1); if (pVnode == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; vError("vgId: %d failed to open vnode since %s", info.config.vgId, tstrerror(terrno)); return NULL; } - pVnode->path = strdup(dir); + pVnode->path = (char *)&pVnode[1]; + strcpy(pVnode->path, path); pVnode->config = info.config; pVnode->state.committed = info.state.committed; pVnode->state.processed = pVnode->state.applied = pVnode->state.committed; @@ -88,9 +89,7 @@ SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) { } // open meta - sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_META_DIR); - pVnode->pMeta = metaOpen(tdir, vBufPoolGetMAF(pVnode)); - if (pVnode->pMeta == NULL) { + if (metaOpen(pVnode, &pVnode->pMeta) < 0) { vError("vgId: %d failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno)); goto _err; } @@ -141,7 +140,6 @@ _err: if (pVnode->pTsdb) tsdbClose(pVnode->pTsdb); if (pVnode->pMeta) metaClose(pVnode->pMeta); tsem_destroy(&(pVnode->canCommit)); - taosMemoryFreeClear(pVnode->path); taosMemoryFree(pVnode); return NULL; } @@ -159,7 +157,6 @@ void vnodeClose(SVnode *pVnode) { vnodeCloseBufPool(pVnode); // destroy handle tsem_destroy(&(pVnode->canCommit)); - taosMemoryFreeClear(pVnode->path); taosMemoryFree(pVnode); } } From 25837faf28cf17599afae04e7eccc422cd51aee5 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sat, 16 Apr 2022 20:35:18 +0800 Subject: [PATCH 05/13] enh: add multi filter merge --- source/libs/executor/src/indexoperator.c | 52 ++++++++++++++++++++---- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/source/libs/executor/src/indexoperator.c b/source/libs/executor/src/indexoperator.c index edffe24ac4..34b04c04de 100644 --- a/source/libs/executor/src/indexoperator.c +++ b/source/libs/executor/src/indexoperator.c @@ -125,18 +125,37 @@ static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx SIF_ERR_JRET(sifInitParam(node->pLeft, ¶mList[0], ctx)); if (nParam > 1) { - SIF_ERR_JRET(sifInitParam(node->pRight, ¶mList[0], ctx)); + SIF_ERR_JRET(sifInitParam(node->pRight, ¶mList[1], ctx)); } *params = paramList; - SIF_RET(TSDB_CODE_SUCCESS); + return TSDB_CODE_SUCCESS; _return: taosMemoryFree(paramList); SIF_RET(code); } -// int32_t sifInitOperParams(SIFParam *params, SOperatorNode *node, SIFCtx *ctx) { -// int32_t code = 0; -// return code; -//} +static int32_t sifInitParamList(SIFParam **params, SNodeList *nodeList, SIFCtx *ctx) { + int32_t code = 0; + SIFParam *tParams = taosMemoryCalloc(nodeList->length, sizeof(SIFParam)); + if (tParams == NULL) { + qError("failed to calloc, nodeList: %p", nodeList); + SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY); + } + + SListCell *cell = nodeList->pHead; + for (int32_t i = 0; i < nodeList->length; i++) { + if (NULL == cell || NULL == cell->pNode) { + SIF_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT); + } + SIF_ERR_JRET(sifInitParam(cell->pNode, &tParams[i], ctx)); + cell = cell->pNext; + } + *params = tParams; + return TSDB_CODE_SUCCESS; + +_return: + taosMemoryFree(tParams); + SIF_RET(code); +} static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *output) { qError("index-filter not support buildin function"); return TSDB_CODE_QRY_INVALID_INPUT; @@ -251,12 +270,27 @@ static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *ou qError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0); return TSDB_CODE_QRY_INVALID_INPUT; } - // impl later - return TSDB_CODE_SUCCESS; + + int32_t code; + SIFParam *params = NULL; + SIF_ERR_RET(sifInitParamList(¶ms, node->pParameterList, ctx)); + + for (int32_t m = 0; m < node->pParameterList->length; m++) { + // add impl later + if (node->condType == LOGIC_COND_TYPE_AND) { + taosArrayAddAll(output->result, params[m].result); + } else if (node->condType == LOGIC_COND_TYPE_OR) { + taosArrayAddAll(output->result, params[m].result); + } else if (node->condType == LOGIC_COND_TYPE_NOT) { + taosArrayAddAll(output->result, params[m].result); + } + } +_return: + taosMemoryFree(params); + SIF_RET(code); } static EDealRes sifWalkFunction(SNode *pNode, void *context) { - // impl later SFunctionNode *node = (SFunctionNode *)pNode; SIFParam output = {0}; From dea51ba36418814928b6ef5c27b5db2462e5b61a Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Sat, 16 Apr 2022 20:46:51 +0800 Subject: [PATCH 06/13] fix(build): use static taos lib. --- example/CMakeLists.txt | 6 +- packaging/make_install.sh | 919 ++++++++++++--------- source/client/CMakeLists.txt | 21 +- source/client/test/CMakeLists.txt | 4 +- source/dnode/mgmt/interface/CMakeLists.txt | 2 +- source/libs/catalog/test/CMakeLists.txt | 2 +- source/libs/executor/test/CMakeLists.txt | 2 +- source/libs/scheduler/test/CMakeLists.txt | 2 +- tests/test/c/CMakeLists.txt | 6 +- tests/tsim/CMakeLists.txt | 2 +- tools/shell/CMakeLists.txt | 2 +- 11 files changed, 553 insertions(+), 415 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 54bb83d244..fe5f8cf7ed 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -18,15 +18,15 @@ target_sources(demoapi ) target_link_libraries(tmq - taos + taos_static ) target_link_libraries(tstream - taos + taos_static ) target_link_libraries(demoapi - taos + taos_static ) target_include_directories(tmq diff --git a/packaging/make_install.sh b/packaging/make_install.sh index e9d719eefc..f70f176a40 100755 --- a/packaging/make_install.sh +++ b/packaging/make_install.sh @@ -4,7 +4,7 @@ # is required to use systemd to manage services at boot set -e -# set -x +#set -x # -----------------------Variables definition source_dir=$1 @@ -13,40 +13,52 @@ osType=$3 verNumber=$4 if [ "$osType" != "Darwin" ]; then - script_dir=$(dirname $(readlink -f "$0")) + script_dir=$(dirname $(readlink -f "$0")) else - script_dir=${source_dir}/packaging/tools + script_dir=${source_dir}/packaging/tools fi # Dynamic directory +clientName="taos" +serverName="taosd" +logDir="/var/log/taos" +dataDir="/var/lib/taos" +configDir="/etc/taos" +configFile="taos.cfg" +installDir="/usr/local/taos" +productName="TDengine" +emailName="taosdata.com" +uninstallScript="rmtaos" if [ "$osType" != "Darwin" ]; then - data_dir="/var/lib/taos" - log_dir="/var/log/taos" + data_dir=${dataDir} + log_dir=${logDir} - cfg_install_dir="/etc/taos" + cfg_install_dir=${configDir} - bin_link_dir="/usr/bin" - lib_link_dir="/usr/lib" - lib64_link_dir="/usr/lib64" - inc_link_dir="/usr/include" + bin_link_dir="/usr/bin" + lib_link_dir="/usr/lib" + lib64_link_dir="/usr/lib64" + inc_link_dir="/usr/include" - install_main_dir="/usr/local/taos" + install_main_dir=${installDir} - bin_dir="/usr/local/taos/bin" + bin_dir="${installDir}/bin" else - data_dir="/usr/local/var/lib/taos" - log_dir="/usr/local/var/log/taos" + data_dir="/usr/local${dataDir}" + log_dir="/usr/local${logDir}" - cfg_install_dir="/usr/local/etc/taos" + cfg_install_dir="/usr/local${configDir}" - bin_link_dir="/usr/local/bin" - lib_link_dir="/usr/local/lib" - inc_link_dir="/usr/local/include" + bin_link_dir="/usr/local/bin" + lib_link_dir="/usr/local/lib" + inc_link_dir="/usr/local/include" - install_main_dir="/usr/local/Cellar/tdengine/${verNumber}" + install_main_dir="/usr/local/Cellar/tdengine/${verNumber}" + install_main_2_dir="/usr/local/Cellar/tdengine@${verNumber}/${verNumber}" - bin_dir="/usr/local/Cellar/tdengine/${verNumber}/bin" + bin_dir="/usr/local/Cellar/tdengine/${verNumber}/bin" + bin_2_dir="/usr/local/Cellar/tdengine@${verNumber}/${verNumber}/bin" fi service_config_dir="/etc/systemd/system" @@ -60,479 +72,586 @@ NC='\033[0m' csudo="" -if [ "$osType" != "Darwin" ]; then - if command -v sudo > /dev/null; then - csudo="sudo" - fi - initd_mod=0 - service_mod=2 - if pidof systemd &> /dev/null; then - service_mod=0 - elif $(which service &> /dev/null); then - service_mod=1 - service_config_dir="/etc/init.d" - if $(which chkconfig &> /dev/null); then - initd_mod=1 - elif $(which insserv &> /dev/null); then - initd_mod=2 - elif $(which update-rc.d &> /dev/null); then - initd_mod=3 - else - service_mod=2 - fi - else - service_mod=2 - fi +service_mod=2 +os_type=0 - # get the operating system type for using the corresponding init file - # ubuntu/debian(deb), centos/fedora(rpm), others: opensuse, redhat, ..., no verification - #osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) - osinfo=$(cat /etc/os-release | grep "NAME" | cut -d '"' -f2) - #echo "osinfo: ${osinfo}" - os_type=0 - if echo $osinfo | grep -qwi "ubuntu" ; then - echo "this is ubuntu system" - os_type=1 - elif echo $osinfo | grep -qwi "debian" ; then - echo "this is debian system" - os_type=1 - elif echo $osinfo | grep -qwi "Kylin" ; then - echo "this is Kylin system" - os_type=1 - elif echo $osinfo | grep -qwi "centos" ; then - echo "this is centos system" - os_type=2 - elif echo $osinfo | grep -qwi "fedora" ; then - echo "this is fedora system" - os_type=2 +if [ "$osType" != "Darwin" ]; then + if command -v sudo >/dev/null; then + csudo="sudo " + fi + initd_mod=0 + if pidof systemd &>/dev/null; then + service_mod=0 + elif $(which service &>/dev/null); then + service_mod=1 + service_config_dir="/etc/init.d" + if $(which chkconfig &>/dev/null); then + initd_mod=1 + elif $(which insserv &>/dev/null); then + initd_mod=2 + elif $(which update-rc.d &>/dev/null); then + initd_mod=3 else - echo "${osinfo}: This is an officially unverified linux system, If there are any problems with the installation and operation, " - echo "please feel free to contact taosdata.com for support." - os_type=1 + service_mod=2 fi + else + service_mod=2 + fi + + # get the operating system type for using the corresponding init file + # ubuntu/debian(deb), centos/fedora(rpm), others: opensuse, redhat, ..., no verification + #osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release) + osinfo=$(cat /etc/os-release | grep "NAME" | cut -d '"' -f2) + #echo "osinfo: ${osinfo}" + if echo $osinfo | grep -qwi "ubuntu"; then + echo "this is ubuntu system" + os_type=1 + elif echo $osinfo | grep -qwi "debian"; then + echo "this is debian system" + os_type=1 + elif echo $osinfo | grep -qwi "Kylin"; then + echo "this is Kylin system" + os_type=1 + elif echo $osinfo | grep -qwi "centos"; then + echo "this is centos system" + os_type=2 + elif echo $osinfo | grep -qwi "fedora"; then + echo "this is fedora system" + os_type=2 + else + echo "${osinfo}: This is an officially unverified linux system, If there are any problems with the installation and operation, " + echo "please feel free to contact ${emailName} for support." + os_type=1 + fi fi +function kill_taosadapter() { + pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}') + if [ -n "$pid" ]; then + ${csudo}kill -9 $pid || : + fi +} + function kill_taosd() { - pid=$(ps -ef | grep "taosd" | grep -v "grep" | awk '{print $2}') - if [ -n "$pid" ]; then - ${csudo} kill -9 $pid || : - fi + ps -ef | grep ${serverName} + pid=$(ps -ef | grep -w ${serverName} | grep -v "grep" | awk '{print $2}') + if [ -n "$pid" ]; then + ${csudo}kill -9 $pid || : + fi } function install_main_path() { - #create install main dir and all sub dir - ${csudo} rm -rf ${install_main_dir} || : - ${csudo} mkdir -p ${install_main_dir} - ${csudo} mkdir -p ${install_main_dir}/cfg - ${csudo} mkdir -p ${install_main_dir}/bin - ${csudo} mkdir -p ${install_main_dir}/connector - ${csudo} mkdir -p ${install_main_dir}/driver - ${csudo} mkdir -p ${install_main_dir}/examples - ${csudo} mkdir -p ${install_main_dir}/include - if [ "$osType" != "Darwin" ]; then - ${csudo} mkdir -p ${install_main_dir}/init.d - fi + #create install main dir and all sub dir + if [ "$osType" != "Darwin" ]; then + ${csudo}rm -rf ${install_main_dir} || : + ${csudo}mkdir -p ${install_main_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin + # ${csudo}mkdir -p ${install_main_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include + # ${csudo}mkdir -p ${install_main_dir}/init.d + else + ${csudo}rm -rf ${install_main_dir} || ${csudo}rm -rf ${install_main_2_dir} || : + ${csudo}mkdir -p ${install_main_dir} || ${csudo}mkdir -p ${install_main_2_dir} + ${csudo}mkdir -p ${install_main_dir}/cfg || ${csudo}mkdir -p ${install_main_2_dir}/cfg + ${csudo}mkdir -p ${install_main_dir}/bin || ${csudo}mkdir -p ${install_main_2_dir}/bin + # ${csudo}mkdir -p ${install_main_dir}/connector || ${csudo}mkdir -p ${install_main_2_dir}/connector + ${csudo}mkdir -p ${install_main_dir}/driver || ${csudo}mkdir -p ${install_main_2_dir}/driver + ${csudo}mkdir -p ${install_main_dir}/examples || ${csudo}mkdir -p ${install_main_2_dir}/examples + ${csudo}mkdir -p ${install_main_dir}/include || ${csudo}mkdir -p ${install_main_2_dir}/include + fi } function install_bin() { - # Remove links - ${csudo} rm -f ${bin_link_dir}/taos || : - ${csudo} rm -f ${bin_link_dir}/taosd || : - ${csudo} rm -f ${bin_link_dir}/taosdemo || : - ${csudo} rm -f ${bin_link_dir}/taosdump || : + # Remove links + ${csudo}rm -f ${bin_link_dir}/${clientName} || : + ${csudo}rm -f ${bin_link_dir}/${serverName} || : + ${csudo}rm -f ${bin_link_dir}/taosadapter || : + ${csudo}rm -f ${bin_link_dir}/taosdemo || : + ${csudo}rm -f ${bin_link_dir}/taosdump || : - if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${bin_link_dir}/perfMonitor || : - ${csudo} rm -f ${bin_link_dir}/set_core || : - ${csudo} rm -f ${bin_link_dir}/rmtaos || : - fi - - ${csudo} cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin || : - ${csudo} cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || : + if [ "$osType" != "Darwin" ]; then + ${csudo}rm -f ${bin_link_dir}/perfMonitor || : + ${csudo}rm -f ${bin_link_dir}/set_core || : + ${csudo}rm -f ${bin_link_dir}/run_taosd_and_taosadapter.sh || : + ${csudo}rm -f ${bin_link_dir}/${uninstallScript} || : - if [ "$osType" != "Darwin" ]; then - ${csudo} cp -r ${script_dir}/remove.sh ${install_main_dir}/bin || : - ${csudo} cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin || : - ${csudo} cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin || : - else - ${csudo} cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin || : - fi - ${csudo} chmod 0555 ${install_main_dir}/bin/* || : + ${csudo}cp -r ${binary_dir}/build/bin/${clientName} ${install_main_dir}/bin || : + [ -f ${binary_dir}/build/bin/taosBenchmark ] && ${csudo}cp -r ${binary_dir}/build/bin/taosBenchmark ${install_main_dir}/bin || : + [ -f ${install_main_dir}/bin/taosBenchmark ] && ${csudo}ln -sf ${install_main_dir}/bin/taosBenchmark ${install_main_dir}/bin/taosdemo || : + [ -f ${binary_dir}/build/bin/taosdump ] && ${csudo}cp -r ${binary_dir}/build/bin/taosdump ${install_main_dir}/bin || : + [ -f ${binary_dir}/build/bin/taosadapter ] && ${csudo}cp -r ${binary_dir}/build/bin/taosadapter ${install_main_dir}/bin || : + ${csudo}cp -r ${binary_dir}/build/bin/${serverName} ${install_main_dir}/bin || : + ${csudo}cp -r ${binary_dir}/build/bin/tarbitrator ${install_main_dir}/bin || : + ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || : + ${csudo}cp -r ${script_dir}/remove.sh ${install_main_dir}/bin || : + ${csudo}cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin || : + ${csudo}cp -r ${script_dir}/run_taosd_and_taosadapter.sh ${install_main_dir}/bin || : + ${csudo}cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin || : + + ${csudo}chmod 0555 ${install_main_dir}/bin/* #Make link - [ -x ${install_main_dir}/bin/taos ] && ${csudo} ln -s ${install_main_dir}/bin/taos ${bin_link_dir}/taos || : - [ -x ${install_main_dir}/bin/taosd ] && ${csudo} ln -s ${install_main_dir}/bin/taosd ${bin_link_dir}/taosd || : - [ -x ${install_main_dir}/bin/taosdump ] && ${csudo} ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || : - [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo} ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : + [ -x ${install_main_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || : + [ -x ${install_main_dir}/bin/${serverName} ] && ${csudo}ln -s ${install_main_dir}/bin/${serverName} ${bin_link_dir}/${serverName} || : + [ -x ${install_main_dir}/bin/taosadapter ] && ${csudo}ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || : + [ -x ${install_main_dir}/bin/taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || : + [ -x ${install_main_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : + [ -x ${install_main_dir}/bin/perfMonitor ] && ${csudo}ln -s ${install_main_dir}/bin/perfMonitor ${bin_link_dir}/perfMonitor || : + [ -x ${install_main_dir}/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : + [ -x ${install_main_dir}/run_taosd_and_taosadapter.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd_and_taosadapter.sh ${bin_link_dir}/run_taosd_and_taosadapter.sh || : + [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/${uninstallScript} || : + else - if [ "$osType" != "Darwin" ]; then - [ -x ${install_main_dir}/bin/perfMonitor ] && ${csudo} ln -s ${install_main_dir}/bin/perfMonitor ${bin_link_dir}/perfMonitor || : - [ -x ${install_main_dir}/set_core.sh ] && ${csudo} ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || : - fi - - if [ "$osType" != "Darwin" ]; then - [ -x ${install_main_dir}/bin/remove.sh ] && ${csudo} ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/rmtaos || : - fi + ${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin || ${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_2_dir}/bin || : + ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_2_dir} || : + ${csudo}cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/remove_client.sh ${install_main_2_dir}/bin || : + ${csudo}chmod 0555 ${install_main_dir}/bin/* || ${csudo}chmod 0555 ${install_main_2_dir}/bin/* + #Make link + [ -x ${install_main_dir}/bin/${clientName} ] || [ -x ${install_main_2_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || ${csudo}ln -s ${install_main_2_dir}/bin/${clientName} || : + [ -x ${install_main_dir}/bin/${serverName} ] || [ -x ${install_main_2_dir}/bin/${serverName} ] && ${csudo}ln -s ${install_main_dir}/bin/${serverName} ${bin_link_dir}/${serverName} || ${csudo}ln -s ${install_main_2_dir}/bin/${serverName} || : + [ -x ${install_main_dir}/bin/taosadapter ] || [ -x ${install_main_2_dir}/bin/taosadapter ] && ${csudo}ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || ${csudo}ln -s ${install_main_2_dir}/bin/taosadapter || : + [ -x ${install_main_dir}/bin/taosdump ] || [ -x ${install_main_2_dir}/bin/taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || ln -s ${install_main_2_dir}/bin/taosdump ${bin_link_dir}/taosdump || : + [ -x ${install_main_dir}/bin/taosdemo ] || [ -x ${install_main_2_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || ln -s ${install_main_2_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || : + fi } function install_jemalloc() { - if [ "$osType" != "Darwin" ]; then - /usr/bin/install -c -d /usr/local/bin + if [ "$osType" != "Darwin" ]; then + /usr/bin/install -c -d /usr/local/bin - if [ -f ${binary_dir}/build/bin/jemalloc-config ]; then - /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc-config /usr/local/bin - fi - if [ -f ${binary_dir}/build/bin/jemalloc.sh ]; then - /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc.sh /usr/local/bin - fi - if [ -f ${binary_dir}/build/bin/jeprof ]; then - /usr/bin/install -c -m 755 ${binary_dir}/build/bin/jeprof /usr/local/bin - fi - if [ -f ${binary_dir}/build/include/jemalloc/jemalloc.h ]; then - /usr/bin/install -c -d /usr/local/include/jemalloc - /usr/bin/install -c -m 644 ${binary_dir}/build/include/jemalloc/jemalloc.h /usr/local/include/jemalloc - fi - if [ -f ${binary_dir}/build/lib/libjemalloc.so.2 ]; then - /usr/bin/install -c -d /usr/local/lib - /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.so.2 /usr/local/lib - ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so - /usr/bin/install -c -d /usr/local/lib - if [ -f ${binary_dir}/build/lib/libjemalloc.a ]; then - /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.a /usr/local/lib - fi - if [ -f ${binary_dir}/build/lib/libjemalloc_pic.a ]; then - /usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib - fi - if [ -f ${binary_dir}/build/lib/pkgconfig/jemalloc.pc ]; then - /usr/bin/install -c -d /usr/local/lib/pkgconfig - /usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc /usr/local/lib/pkgconfig - fi - fi - if [ -f ${binary_dir}/build/share/doc/jemalloc/jemalloc.html ]; then - /usr/bin/install -c -d /usr/local/share/doc/jemalloc - /usr/bin/install -c -m 644 ${binary_dir}/build/share/doc/jemalloc/jemalloc.html /usr/local/share/doc/jemalloc - fi - if [ -f ${binary_dir}/build/share/man/man3/jemalloc.3 ]; then - /usr/bin/install -c -d /usr/local/share/man/man3 - /usr/bin/install -c -m 644 ${binary_dir}/build/share/man/man3/jemalloc.3 /usr/local/share/man/man3 - fi - - if [ -d /etc/ld.so.conf.d ]; then - echo "/usr/local/lib" | ${csudo} tee /etc/ld.so.conf.d/jemalloc.conf - ${csudo} ldconfig - else - echo "/etc/ld.so.conf.d not found!" - fi + if [ -f "${binary_dir}/build/bin/jemalloc-config" ]; then + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc-config /usr/local/bin fi + if [ -f "${binary_dir}/build/bin/jemalloc.sh" ]; then + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc.sh /usr/local/bin + fi + if [ -f "${binary_dir}/build/bin/jeprof" ]; then + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jeprof /usr/local/bin + fi + if [ -f "${binary_dir}/build/include/jemalloc/jemalloc.h" ]; then + ${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/include/jemalloc/jemalloc.h \ + /usr/local/include/jemalloc + fi + if [ -f "${binary_dir}/build/lib/libjemalloc.so.2" ]; then + ${csudo}/usr/bin/install -c -d /usr/local/lib + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.so.2 /usr/local/lib + ${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so + ${csudo}/usr/bin/install -c -d /usr/local/lib + [ -f ${binary_dir}/build/lib/libjemalloc.a ] && + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.a /usr/local/lib + [ -f ${binary_dir}/build/lib/libjemalloc_pic.a ] && + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib + if [ -f "${binary_dir}/build/lib/pkgconfig/jemalloc.pc" ]; then + ${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig + ${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc \ + /usr/local/lib/pkgconfig + fi + if [ -d /etc/ld.so.conf.d ]; then + echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf >/dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf" + ${csudo}ldconfig + else + echo "/etc/ld.so.conf.d not found!" + fi + fi + if [ -f "${binary_dir}/build/share/doc/jemalloc/jemalloc.html" ]; then + ${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc + ${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/share/doc/jemalloc/jemalloc.html \ + /usr/local/share/doc/jemalloc + fi + if [ -f "${binary_dir}/build/share/man/man3/jemalloc.3" ]; then + ${csudo}/usr/bin/install -c -d /usr/local/share/man/man3 + ${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/share/man/man3/jemalloc.3 \ + /usr/local/share/man/man3 + fi + fi +} + +function install_avro() { + if [ "$osType" != "Darwin" ]; then + if [ -f "${binary_dir}/build/$1/libavro.so.23.0.0" ] && [ -d /usr/local/$1 ]; then + ${csudo}/usr/bin/install -c -d /usr/local/$1 + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.so.23.0.0 /usr/local/$1 + ${csudo}ln -sf libavro.so.23.0.0 /usr/local/$1/libavro.so.23 + ${csudo}ln -sf libavro.so.23 /usr/local/$1/libavro.so + ${csudo}/usr/bin/install -c -d /usr/local/$1 + [ -f ${binary_dir}/build/$1/libavro.a ] && + ${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.a /usr/local/$1 + + if [ -d /etc/ld.so.conf.d ]; then + echo "/usr/local/$1" | ${csudo}tee /etc/ld.so.conf.d/libavro.conf >/dev/null || echo -e "failed to write /etc/ld.so.conf.d/libavro.conf" + ${csudo}ldconfig + else + echo "/etc/ld.so.conf.d not found!" + fi + fi + fi } function install_lib() { - # Remove links - ${csudo} rm -f ${lib_link_dir}/libtaos.* || : - if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${lib64_link_dir}/libtaos.* || : + # Remove links + ${csudo}rm -f ${lib_link_dir}/libtaos.* || : + if [ "$osType" != "Darwin" ]; then + ${csudo}rm -f ${lib64_link_dir}/libtaos.* || : + fi + + if [ "$osType" != "Darwin" ]; then + ${csudo}cp ${binary_dir}/build/lib/libtaos.so.${verNumber} \ + ${install_main_dir}/driver && + ${csudo}chmod 777 ${install_main_dir}/driver/* + + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 + ${csudo}ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + + if [ -d "${lib64_link_dir}" ]; then + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 + ${csudo}ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so fi + else + ${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \ + ${install_main_dir}/driver || + ${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \ + ${install_main_2_dir}/driver && + ${csudo}chmod 777 ${install_main_dir}/driver/* || + ${csudo}chmod 777 ${install_main_2_dir}/driver/* - if [ "$osType" != "Darwin" ]; then - ${csudo} cp ${binary_dir}/build/lib/libtaos.so ${install_main_dir}/driver/libtaos.so.${verNumber} && ${csudo} chmod 777 ${install_main_dir}/driver/* - ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1 - ${csudo} ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.* \ + ${install_main_dir}/driver/libtaos.1.dylib || + ${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.* \ + ${install_main_2_dir}/driver/libtaos.1.dylib || : - if [ -d "${lib64_link_dir}" ]; then - ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1 - ${csudo} ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so - fi - else - ${csudo} cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib ${install_main_dir}/driver && ${csudo} chmod 777 ${install_main_dir}/driver/* + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.1.dylib \ + ${install_main_dir}/driver/libtaos.dylib || + ${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.1.dylib \ + ${install_main_2_dir}/driver/libtaos.dylib || : - ${csudo} ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.1.dylib - ${csudo} ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib - fi - - install_jemalloc + ${csudo}ln -sf ${install_main_dir}/driver/libtaos.${verNumber}.dylib \ + ${lib_link_dir}/libtaos.1.dylib || + ${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.${verNumber}.dylib \ + ${lib_link_dir}/libtaos.1.dylib || : - if [ "$osType" != "Darwin" ]; then - ${csudo} ldconfig - fi + ${csudo}ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib || : + fi + + install_jemalloc + install_avro lib + install_avro lib64 + + if [ "$osType" != "Darwin" ]; then + ${csudo}ldconfig + fi } function install_header() { - if [ "$osType" != "Darwin" ]; then - ${csudo} rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taoserror.h || : - fi - ${csudo} cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/util/taoserror.h ${install_main_dir}/include && ${csudo} chmod 644 ${install_main_dir}/include/* - if [ "$osType" != "Darwin" ]; then - ${csudo} ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h - ${csudo} ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h - fi + if [ "$osType" != "Darwin" ]; then + ${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || : + ${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h \ + ${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/* + ${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h + ${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h + ${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h + else + ${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h \ + ${install_main_dir}/include || + ${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h \ + ${install_main_2_dir}/include && + ${csudo}chmod 644 ${install_main_dir}/include/* || + ${csudo}chmod 644 ${install_main_2_dir}/include/* + fi } function install_config() { - #${csudo} rm -f ${install_main_dir}/cfg/taos.cfg || : + if [ ! -f ${cfg_install_dir}/${configFile} ]; then + ${csudo}mkdir -p ${cfg_install_dir} + [ -f ${script_dir}/../cfg/${configFile} ] && + ${csudo}cp ${script_dir}/../cfg/${configFile} ${cfg_install_dir} || : + ${csudo}chmod 644 ${cfg_install_dir}/${configFile} + ${csudo}cp -f ${script_dir}/../cfg/${configFile} \ + ${cfg_install_dir}/${configFile}.${verNumber} || : + ${csudo}ln -s ${cfg_install_dir}/${configFile} \ + ${install_main_dir}/cfg/${configFile} + else + ${csudo}cp -f ${script_dir}/../cfg/${configFile} \ + ${cfg_install_dir}/${configFile}.${verNumber} || : + fi +} - if [ ! -f ${cfg_install_dir}/taos.cfg ]; then - ${csudo} mkdir -p ${cfg_install_dir} - [ -f ${script_dir}/../cfg/taos.cfg ] && - ${csudo} cp ${script_dir}/../cfg/taos.cfg ${cfg_install_dir} || : - ${csudo} chmod 644 ${cfg_install_dir}/* - fi - - ${csudo} cp -f ${script_dir}/../cfg/taos.cfg ${install_main_dir}/cfg/taos.cfg.org || : - - if [ "$osType" != "Darwin" ]; then ${csudo} ln -s ${cfg_install_dir}/taos.cfg ${install_main_dir}/cfg +function install_taosadapter_config() { + if [ ! -f "${cfg_install_dir}/taosadapter.toml" ]; then + ${csudo}mkdir -p ${cfg_install_dir} || : + [ -f ${binary_dir}/test/cfg/taosadapter.toml ] && + ${csudo}cp ${binary_dir}/test/cfg/taosadapter.toml ${cfg_install_dir} || : + [ -f ${cfg_install_dir}/taosadapter.toml ] && + ${csudo}chmod 644 ${cfg_install_dir}/taosadapter.toml || : + [ -f ${binary_dir}/test/cfg/taosadapter.toml ] && + ${csudo}cp -f ${binary_dir}/test/cfg/taosadapter.toml \ + ${cfg_install_dir}/taosadapter.toml.${verNumber} || : + [ -f ${cfg_install_dir}/taosadapter.toml ] && + ${csudo}ln -s ${cfg_install_dir}/taosadapter.toml \ + ${install_main_dir}/cfg/taosadapter.toml || : + else + if [ -f "${binary_dir}/test/cfg/taosadapter.toml" ]; then + ${csudo}cp -f ${binary_dir}/test/cfg/taosadapter.toml \ + ${cfg_install_dir}/taosadapter.toml.${verNumber} || : fi + fi } function install_log() { - ${csudo} rm -rf ${log_dir} || : - ${csudo} mkdir -p ${log_dir} && ${csudo} chmod 777 ${log_dir} - ${csudo} ln -s ${log_dir} ${install_main_dir}/log + ${csudo}rm -rf ${log_dir} || : + ${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir} + if [ "$osType" != "Darwin" ]; then + ${csudo}ln -s ${log_dir} ${install_main_dir}/log + else + ${csudo}ln -s ${log_dir} ${install_main_dir}/log || ${csudo}ln -s ${log_dir} ${install_main_2_dir}/log + fi } function install_data() { - ${csudo} mkdir -p ${data_dir} - ${csudo} ln -s ${data_dir} ${install_main_dir}/data + ${csudo}mkdir -p ${data_dir} + if [ "$osType" != "Darwin" ]; then + ${csudo}ln -s ${data_dir} ${install_main_dir}/data + else + ${csudo}ln -s ${data_dir} ${install_main_dir}/data || ${csudo}ln -s ${data_dir} ${install_main_2_dir}/data + fi } function install_connector() { - if [ -d "${source_dir}/src/connector/grafanaplugin/dist" ]; then - ${csudo} cp -rf ${source_dir}/src/connector/grafanaplugin/dist ${install_main_dir}/connector/grafanaplugin - else - echo "WARNING: grafanaplugin bundled dir not found, please check if want to use it!" - fi - if find ${source_dir}/src/connector/go -mindepth 1 -maxdepth 1 | read; then - ${csudo} cp -r ${source_dir}/src/connector/go ${install_main_dir}/connector - else - echo "WARNING: go connector not found, please check if want to use it!" - fi - ${csudo} cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || : - ${csudo} cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &> /dev/null && ${csudo} chmod 777 ${install_main_dir}/connector/*.jar || echo &> /dev/null + if find ${source_dir}/src/connector/go -mindepth 1 -maxdepth 1 | read; then + ${csudo}cp -r ${source_dir}/src/connector/go ${install_main_dir}/connector || : + else + echo "WARNING: go connector not found, please check if want to use it!" + fi + if [ "$osType" != "Darwin" ]; then + ${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || : + ${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &>/dev/null && ${csudo}chmod 777 ${install_main_dir}/connector/*.jar || echo &>/dev/null || : + else + ${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || ${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_2_dir}/connector || : + ${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &>/dev/null && ${csudo}chmod 777 ${install_main_dir}/connector/*.jar || echo &>/dev/null || : + ${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_2_dir}/connector &>/dev/null && ${csudo}chmod 777 ${install_main_2_dir}/connector/*.jar || echo &>/dev/null || : + fi } function install_examples() { - ${csudo} cp -rf ${source_dir}/tests/examples/* ${install_main_dir}/examples || : + if [ "$osType" != "Darwin" ]; then + ${csudo}cp -rf ${source_dir}/examples/* ${install_main_dir}/examples || : + else + ${csudo}cp -rf ${source_dir}/examples/* ${install_main_dir}/examples || ${csudo}cp -rf ${source_dir}/examples/* ${install_main_2_dir}/examples || : + fi } function clean_service_on_sysvinit() { - #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} sed -i "\|${restart_config_str}|d" /etc/inittab || : + if pidof ${serverName} &>/dev/null; then + ${csudo}service ${serverName} stop || : + fi - if pidof taosd &> /dev/null; then - ${csudo} service taosd stop || : - fi + if ((${initd_mod} == 1)); then + ${csudo}chkconfig --del ${serverName} || : + elif ((${initd_mod} == 2)); then + ${csudo}insserv -r ${serverName} || : + elif ((${initd_mod} == 3)); then + ${csudo}update-rc.d -f ${serverName} remove || : + fi - if ((${initd_mod}==1)); then - ${csudo} chkconfig --del taosd || : - elif ((${initd_mod}==2)); then - ${csudo} insserv -r taosd || : - elif ((${initd_mod}==3)); then - ${csudo} update-rc.d -f taosd remove || : - fi + ${csudo}rm -f ${service_config_dir}/${serverName} || : - ${csudo} rm -f ${service_config_dir}/taosd || : - - if $(which init &> /dev/null); then - ${csudo} init q || : - fi + if $(which init &>/dev/null); then + ${csudo}init q || : + fi } function install_service_on_sysvinit() { - clean_service_on_sysvinit + clean_service_on_sysvinit - sleep 1 + sleep 1 - # Install taosd service - if ((${os_type}==1)); then - ${csudo} cp -f ${script_dir}/../deb/taosd ${install_main_dir}/init.d || : - ${csudo} cp ${script_dir}/../deb/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd || : - elif ((${os_type}==2)); then - ${csudo} cp -f ${script_dir}/../rpm/taosd ${install_main_dir}/init.d || : - ${csudo} cp ${script_dir}/../rpm/taosd ${service_config_dir} && ${csudo} chmod a+x ${service_config_dir}/taosd || : - fi + if ((${os_type} == 1)); then + # ${csudo}cp -f ${script_dir}/../deb/${serverName} ${install_main_dir}/init.d + ${csudo}cp ${script_dir}/../deb/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName} || : + elif ((${os_type} == 2)); then + # ${csudo}cp -f ${script_dir}/../rpm/${serverName} ${install_main_dir}/init.d + ${csudo}cp ${script_dir}/../rpm/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName} || : + fi - #restart_config_str="taos:2345:respawn:${service_config_dir}/taosd start" - #${csudo} grep -q -F "$restart_config_str" /etc/inittab || ${csudo} bash -c "echo '${restart_config_str}' >> /etc/inittab" - - if ((${initd_mod}==1)); then - ${csudo} chkconfig --add taosd || : - ${csudo} chkconfig --level 2345 taosd on || : - elif ((${initd_mod}==2)); then - ${csudo} insserv taosd || : - ${csudo} insserv -d taosd || : - elif ((${initd_mod}==3)); then - ${csudo} update-rc.d taosd defaults || : - fi + if ((${initd_mod} == 1)); then + ${csudo}chkconfig --add ${serverName} || : + ${csudo}chkconfig --level 2345 ${serverName} on || : + elif ((${initd_mod} == 2)); then + ${csudo}insserv ${serverName} || : + ${csudo}insserv -d ${serverName} || : + elif ((${initd_mod} == 3)); then + ${csudo}update-rc.d ${serverName} defaults || : + fi } function clean_service_on_systemd() { - taosd_service_config="${service_config_dir}/taosd.service" + taosd_service_config="${service_config_dir}/${serverName}.service" - if systemctl is-active --quiet taosd; then - echo "TDengine is running, stopping it..." - ${csudo} systemctl stop taosd &> /dev/null || echo &> /dev/null - fi - ${csudo} systemctl disable taosd &> /dev/null || echo &> /dev/null + if systemctl is-active --quiet ${serverName}; then + echo "${productName} is running, stopping it..." + ${csudo}systemctl stop ${serverName} &>/dev/null || echo &>/dev/null + fi + ${csudo}systemctl disable ${serverName} &>/dev/null || echo &>/dev/null - ${csudo} rm -f ${taosd_service_config} + ${csudo}rm -f ${taosd_service_config} } -# taos:2345:respawn:/etc/init.d/taosd start - function install_service_on_systemd() { - clean_service_on_systemd + clean_service_on_systemd - taosd_service_config="${service_config_dir}/taosd.service" + taosd_service_config="${service_config_dir}/${serverName}.service" - ${csudo} bash -c "echo '[Unit]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Description=TDengine server service' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'After=network-online.target' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Wants=network-online.target' >> ${taosd_service_config}" - ${csudo} bash -c "echo >> ${taosd_service_config}" - ${csudo} bash -c "echo '[Service]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Type=simple' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'ExecStart=/usr/bin/taosd' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'ExecStartPre=/usr/local/taos/bin/startPre.sh' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'Restart=always' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" - ${csudo} bash -c "echo >> ${taosd_service_config}" - ${csudo} bash -c "echo '[Install]' >> ${taosd_service_config}" - ${csudo} bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" - ${csudo} systemctl enable taosd + ${csudo}bash -c "echo '[Unit]' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Description=${productName} server service' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'After=network-online.target' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Wants=network-online.target' >> ${taosd_service_config}" + ${csudo}bash -c "echo >> ${taosd_service_config}" + ${csudo}bash -c "echo '[Service]' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Type=simple' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'ExecStart=/usr/bin/${serverName}' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'ExecStartPre=${installDir}/bin/startPre.sh' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'Restart=always' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}" + ${csudo}bash -c "echo >> ${taosd_service_config}" + ${csudo}bash -c "echo '[Install]' >> ${taosd_service_config}" + ${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}" + ${csudo}systemctl enable ${serverName} +} + +function install_taosadapter_service() { + if ((${service_mod} == 0)); then + [ -f ${binary_dir}/test/cfg/taosadapter.service ] && + ${csudo}cp ${binary_dir}/test/cfg/taosadapter.service \ + ${service_config_dir}/ || : + ${csudo}systemctl daemon-reload + fi } function install_service() { - if ((${service_mod}==0)); then - install_service_on_systemd - elif ((${service_mod}==1)); then - install_service_on_sysvinit - else - # must manual stop taosd - kill_taosd - fi + if ((${service_mod} == 0)); then + install_service_on_systemd + elif ((${service_mod} == 1)); then + install_service_on_sysvinit + else + kill_taosd + fi } function update_TDengine() { - echo -e "${GREEN}Start to update TDengine...${NC}" - # Stop the service if running + echo -e "${GREEN}Start to update ${productName}...${NC}" + # Stop the service if running - if [ "$osType" != "Darwin" ]; then - if pidof taosd &> /dev/null; then - if ((${service_mod}==0)); then - ${csudo} systemctl stop taosd || : - elif ((${service_mod}==1)); then - ${csudo} service taosd stop || : - else - kill_taosd - fi - sleep 1 - fi - fi - - install_main_path - - install_log - install_header - install_lib - install_connector - install_examples - install_bin - - if [ "$osType" != "Darwin" ]; then - install_service - fi - - install_config - - if [ "$osType" != "Darwin" ]; then - echo - echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" - echo - - echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" - if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" - elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" - else - echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" - fi - - echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" - echo - echo -e "\033[44;32;1mTDengine is updated successfully!${NC}" + if pidof ${serverName} &>/dev/null; then + if ((${service_mod} == 0)); then + ${csudo}systemctl stop ${serverName} || : + elif ((${service_mod} == 1)); then + ${csudo}service ${serverName} stop || : else - echo - echo -e "\033[44;32;1mTDengine Client is updated successfully!${NC}" - echo - - echo -e "${GREEN_DARK}To access TDengine Client ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" - echo - echo -e "\033[44;32;1mTDengine Client is updated successfully!${NC}" + kill_taosadapter + kill_taosd fi + sleep 1 + fi + + install_main_path + + install_log + install_header + install_lib + # install_connector + install_examples + install_bin + + install_service + install_taosadapter_service + + install_config + install_taosadapter_config + + echo + echo -e "\033[44;32;1m${productName} is updated successfully!${NC}" + echo + + echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${configDir}/${configFile}" + echo -e "${GREEN_DARK}To configure Taos Adapter (if has) ${NC}: edit ${configDir}/taosadapter.toml" + if ((${service_mod} == 0)); then + echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}" + elif ((${service_mod} == 1)); then + echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}" + else + echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}" + echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${serverName}${NC}" + fi + + echo -e "${GREEN_DARK}To access ${productName} ${NC}: use ${GREEN_UNDERLINE}${clientName}${NC} in shell${NC}" + echo + echo -e "\033[44;32;1m${productName} is updated successfully!${NC}" } function install_TDengine() { - # Start to install - if [ "$osType" != "Darwin" ]; then - echo -e "${GREEN}Start to install TDEngine...${NC}" - else - echo -e "${GREEN}Start to install TDEngine Client ...${NC}" - fi - - install_main_path + # Start to install + echo -e "${GREEN}Start to install ${productName}...${NC}" - install_data - install_log - install_header - install_lib - install_connector - install_examples - install_bin - - if [ "$osType" != "Darwin" ]; then - install_service - fi - - install_config + install_main_path - if [ "$osType" != "Darwin" ]; then - # Ask if to start the service - echo - echo -e "\033[44;32;1mTDengine is installed successfully!${NC}" - echo - echo -e "${GREEN_DARK}To configure TDengine ${NC}: edit /etc/taos/taos.cfg" - if ((${service_mod}==0)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} systemctl start taosd${NC}" - elif ((${service_mod}==1)); then - echo -e "${GREEN_DARK}To start TDengine ${NC}: ${csudo} service taosd start${NC}" - else - echo -e "${GREEN_DARK}To start TDengine ${NC}: ./taosd${NC}" - fi + install_data + install_log + install_header + install_lib + # install_connector + install_examples + install_bin - echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" - echo - echo -e "\033[44;32;1mTDengine is installed successfully!${NC}" - else - echo -e "${GREEN_DARK}To access TDengine ${NC}: use ${GREEN_UNDERLINE}taos${NC} in shell${NC}" - echo - echo -e "\033[44;32;1mTDengine Client is installed successfully!${NC}" - fi + install_service + install_taosadapter_service + + install_config + install_taosadapter_config + + # Ask if to start the service + echo + echo -e "\033[44;32;1m${productName} is installed successfully!${NC}" + echo + echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${configDir}/${configFile}" + echo -e "${GREEN_DARK}To configure taosadapter (if has) ${NC}: edit ${configDir}/taosadapter.toml" + if ((${service_mod} == 0)); then + echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}" + elif ((${service_mod} == 1)); then + echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}" + else + echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}" + echo -e "${GREEN_DARK}To start ${productName} ${NC}: ./${serverName}${NC}" + fi + + echo -e "${GREEN_DARK}To access ${productName} ${NC}: use ${GREEN_UNDERLINE}${clientName}${NC} in shell${NC}" + echo + echo -e "\033[44;32;1m${productName} is installed successfully!${NC}" } ## ==============================Main program starts from here============================ echo source directory: $1 echo binary directory: $2 -echo $bin_dir -if [ -x ${bin_dir}/taos ]; then +if [ "$osType" != "Darwin" ]; then + if [ -x ${bin_dir}/${clientName} ]; then update_TDengine -else + else install_TDengine + fi +else + if [ -x ${bin_dir}/${clientName} ] || [ -x ${bin_2_dir}/${clientName} ]; then + update_TDengine + else + install_TDengine + fi fi diff --git a/source/client/CMakeLists.txt b/source/client/CMakeLists.txt index bbceaa8fed..3ff671d536 100644 --- a/source/client/CMakeLists.txt +++ b/source/client/CMakeLists.txt @@ -1,5 +1,5 @@ aux_source_directory(src CLIENT_SRC) -add_library(taos ${CLIENT_SRC}) +add_library(taos SHARED ${CLIENT_SRC}) target_include_directories( taos PUBLIC "${TD_SOURCE_DIR}/include/client" @@ -11,6 +11,25 @@ target_link_libraries( PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom ) +set_target_properties( + taos + PROPERTIES + VERSION ${TD_VER_NUMBER} + SOVERSION ${TD_VER_NUMBER} +) + +add_library(taos_static STATIC ${CLIENT_SRC}) +target_include_directories( + taos_static + PUBLIC "${TD_SOURCE_DIR}/include/client" + PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" +) +target_link_libraries( + taos_static + INTERFACE api + PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom +) + if(${BUILD_TEST}) ADD_SUBDIRECTORY(test) endif(${BUILD_TEST}) \ No newline at end of file diff --git a/source/client/test/CMakeLists.txt b/source/client/test/CMakeLists.txt index 73e11caa95..9df6b260f6 100644 --- a/source/client/test/CMakeLists.txt +++ b/source/client/test/CMakeLists.txt @@ -8,13 +8,13 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(clientTest clientTests.cpp) TARGET_LINK_LIBRARIES( clientTest - PUBLIC os util common transport parser catalog scheduler function gtest taos qcom + PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom ) ADD_EXECUTABLE(tmqTest tmqTest.cpp) TARGET_LINK_LIBRARIES( tmqTest - PUBLIC os util common transport parser catalog scheduler function gtest taos qcom + PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom ) TARGET_INCLUDE_DIRECTORIES( diff --git a/source/dnode/mgmt/interface/CMakeLists.txt b/source/dnode/mgmt/interface/CMakeLists.txt index 69cb6e040f..a99fc2703d 100644 --- a/source/dnode/mgmt/interface/CMakeLists.txt +++ b/source/dnode/mgmt/interface/CMakeLists.txt @@ -6,5 +6,5 @@ target_include_directories( PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( - dnode_interface cjson mnode vnode qnode snode bnode wal sync taos tfs monitor + dnode_interface cjson mnode vnode qnode snode bnode wal sync taos_static tfs monitor ) \ No newline at end of file diff --git a/source/libs/catalog/test/CMakeLists.txt b/source/libs/catalog/test/CMakeLists.txt index 3ffb420b4b..d74eef7855 100644 --- a/source/libs/catalog/test/CMakeLists.txt +++ b/source/libs/catalog/test/CMakeLists.txt @@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(catalogTest ${SOURCE_LIST}) TARGET_LINK_LIBRARIES( catalogTest - PUBLIC os util common catalog transport gtest qcom taos + PUBLIC os util common catalog transport gtest qcom taos_static ) TARGET_INCLUDE_DIRECTORIES( diff --git a/source/libs/executor/test/CMakeLists.txt b/source/libs/executor/test/CMakeLists.txt index b07ff89d90..b1f379585b 100644 --- a/source/libs/executor/test/CMakeLists.txt +++ b/source/libs/executor/test/CMakeLists.txt @@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(executorTest ${SOURCE_LIST}) TARGET_LINK_LIBRARIES( executorTest - PRIVATE os util common transport gtest taos qcom executor function planner scalar nodes + PRIVATE os util common transport gtest taos_static qcom executor function planner scalar nodes ) TARGET_INCLUDE_DIRECTORIES( diff --git a/source/libs/scheduler/test/CMakeLists.txt b/source/libs/scheduler/test/CMakeLists.txt index 4018f73ee2..0b0aafebb9 100644 --- a/source/libs/scheduler/test/CMakeLists.txt +++ b/source/libs/scheduler/test/CMakeLists.txt @@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST) ADD_EXECUTABLE(schedulerTest ${SOURCE_LIST}) TARGET_LINK_LIBRARIES( schedulerTest - PUBLIC os util common catalog transport gtest qcom taos planner scheduler + PUBLIC os util common catalog transport gtest qcom taos_static planner scheduler ) TARGET_INCLUDE_DIRECTORIES( diff --git a/tests/test/c/CMakeLists.txt b/tests/test/c/CMakeLists.txt index 804894a69d..41e9382379 100644 --- a/tests/test/c/CMakeLists.txt +++ b/tests/test/c/CMakeLists.txt @@ -3,21 +3,21 @@ add_executable(tmq_demo tmqDemo.c) add_executable(tmq_sim tmqSim.c) target_link_libraries( create_table - PUBLIC taos + PUBLIC taos_static PUBLIC util PUBLIC common PUBLIC os ) target_link_libraries( tmq_demo - PUBLIC taos + PUBLIC taos_static PUBLIC util PUBLIC common PUBLIC os ) target_link_libraries( tmq_sim - PUBLIC taos + PUBLIC taos_static PUBLIC util PUBLIC common PUBLIC os diff --git a/tests/tsim/CMakeLists.txt b/tests/tsim/CMakeLists.txt index 81737809d9..c2cf7ac3c5 100644 --- a/tests/tsim/CMakeLists.txt +++ b/tests/tsim/CMakeLists.txt @@ -2,7 +2,7 @@ aux_source_directory(src TSIM_SRC) add_executable(tsim ${TSIM_SRC}) target_link_libraries( tsim - PUBLIC taos + PUBLIC taos_static PUBLIC util PUBLIC common PUBLIC os diff --git a/tools/shell/CMakeLists.txt b/tools/shell/CMakeLists.txt index 284693795e..3b22b30852 100644 --- a/tools/shell/CMakeLists.txt +++ b/tools/shell/CMakeLists.txt @@ -3,7 +3,7 @@ aux_source_directory(src SHELL_SRC) add_executable(shell ${SHELL_SRC}) target_link_libraries( shell - PUBLIC taos + PUBLIC taos_static PRIVATE os common transport util ) target_include_directories( From 884bf3775f13308182cd59598a099fa430e4fbc3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 18 Apr 2022 10:21:25 +0800 Subject: [PATCH 07/13] fix: definite lost in tcache.c found by valgrind --- source/util/src/tcache.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/util/src/tcache.c b/source/util/src/tcache.c index c4e85a425e..a69f11f285 100644 --- a/source/util/src/tcache.c +++ b/source/util/src/tcache.c @@ -910,6 +910,8 @@ void taosCacheRefresh(SCacheObj *pCacheObj, __cache_trav_fn_t fp, void *param1) void taosStopCacheRefreshWorker(void) { stopRefreshWorker = true; + taosThreadJoin(cacheRefreshWorker, NULL); + taosArrayDestroy(pCacheArrayList); } size_t taosCacheGetNumOfObj(const SCacheObj* pCacheObj) { From 0d262b874745a409800856e976b719b40fe8fdce Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 18 Apr 2022 10:22:08 +0800 Subject: [PATCH 08/13] fix: definite lost in tlog.c found by valgrind --- include/os/osMemory.h | 12 +-- source/client/src/clientMain.c | 2 +- source/util/src/tlog.c | 163 +++++++++++++++++---------------- 3 files changed, 92 insertions(+), 85 deletions(-) diff --git a/include/os/osMemory.h b/include/os/osMemory.h index 4efe69e204..92d9319d5c 100644 --- a/include/os/osMemory.h +++ b/include/os/osMemory.h @@ -36,12 +36,12 @@ void *taosMemoryStrDup(void *ptr); void taosMemoryFree(void *ptr); int32_t taosMemorySize(void *ptr); -#define taosMemoryFreeClear(ptr) \ - do { \ - if (ptr) { \ - taosMemoryFree((void*)ptr); \ - (ptr) = NULL; \ - } \ +#define taosMemoryFreeClear(ptr) \ + do { \ + if (ptr) { \ + taosMemoryFree((void *)ptr); \ + (ptr) = NULL; \ + } \ } while (0) #ifdef __cplusplus diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index 73ac059276..2e6cd4ce17 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -69,9 +69,9 @@ void taos_cleanup(void) { rpcCleanup(); catalogDestroy(); schedulerDestroy(); - taosCloseLog(); tscInfo("all local resources released"); + taosCloseLog(); } setConfRet taos_set_config(const char *config) { diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index b37b1b2f69..3dce260b10 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -38,27 +38,26 @@ #define LOG_BUF_MUTEX(x) ((x)->buffMutex) typedef struct { - char *buffer; - int32_t buffStart; - int32_t buffEnd; - int32_t buffSize; - int32_t minBuffSize; - TdFilePtr pFile; - int32_t stop; - TdThread asyncThread; + char *buffer; + int32_t buffStart; + int32_t buffEnd; + int32_t buffSize; + int32_t minBuffSize; + TdFilePtr pFile; + int32_t stop; + TdThread asyncThread; TdThreadMutex buffMutex; - tsem_t buffNotEmpty; } SLogBuff; typedef struct { - int32_t fileNum; - int32_t maxLines; - int32_t lines; - int32_t flag; - int32_t openInProgress; - pid_t pid; - char logName[LOG_FILE_NAME_LEN]; - SLogBuff *logHandle; + int32_t fileNum; + int32_t maxLines; + int32_t lines; + int32_t flag; + int32_t openInProgress; + pid_t pid; + char logName[LOG_FILE_NAME_LEN]; + SLogBuff *logHandle; TdThreadMutex logMutex; } SLogObj; @@ -100,7 +99,7 @@ int64_t dbgBigWN = 0; int64_t dbgWSize = 0; static void *taosAsyncOutputLog(void *param); -static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t msgLen); +static int32_t taosPushLogBuffer(SLogBuff *pLogBuf, const char *msg, int32_t msgLen); static SLogBuff *taosLogBuffNew(int32_t bufSize); static void taosCloseLogByFd(TdFilePtr pFile); static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum); @@ -136,16 +135,24 @@ static void taosStopLog() { } } +static void taosLogBuffDestroy() { + taosThreadMutexDestroy(&tsLogObj.logHandle->buffMutex); + taosCloseFile(&tsLogObj.logHandle->pFile); + taosMemoryFreeClear(tsLogObj.logHandle->buffer); + memset(&tsLogObj.logHandle->buffer, 0, sizeof(tsLogObj.logHandle->buffer)); + taosThreadMutexDestroy(&tsLogObj.logMutex); + taosMemoryFreeClear(tsLogObj.logHandle); + memset(&tsLogObj.logHandle, 0, sizeof(tsLogObj.logHandle)); + tsLogObj.logHandle = NULL; +} + void taosCloseLog() { taosStopLog(); if (taosCheckPthreadValid(tsLogObj.logHandle->asyncThread)) { taosThreadJoin(tsLogObj.logHandle->asyncThread, NULL); } tsLogInited = 0; - // In case that other threads still use log resources causing invalid write in valgrind - // we comment two lines below. - // taosLogBuffDestroy(tsLogObj.logHandle); - // taosCloseLog(); + taosLogBuffDestroy(tsLogObj.logHandle); } static bool taosLockLogFile(TdFilePtr pFile) { @@ -231,7 +238,7 @@ static int32_t taosOpenNewLogFile() { tsLogObj.openInProgress = 1; uInfo("open new log file ......"); - TdThread thread; + TdThread thread; TdThreadAttr attr; taosThreadAttrInit(&attr); taosThreadAttrSetDetachState(&attr, PTHREAD_CREATE_DETACHED); @@ -506,45 +513,45 @@ static void taosCloseLogByFd(TdFilePtr pFile) { } static SLogBuff *taosLogBuffNew(int32_t bufSize) { - SLogBuff *tLogBuff = NULL; + SLogBuff *pLogBuf = NULL; - tLogBuff = taosMemoryCalloc(1, sizeof(SLogBuff)); - if (tLogBuff == NULL) return NULL; + pLogBuf = taosMemoryCalloc(1, sizeof(SLogBuff)); + if (pLogBuf == NULL) return NULL; - LOG_BUF_BUFFER(tLogBuff) = taosMemoryMalloc(bufSize); - if (LOG_BUF_BUFFER(tLogBuff) == NULL) goto _err; + LOG_BUF_BUFFER(pLogBuf) = taosMemoryMalloc(bufSize); + if (LOG_BUF_BUFFER(pLogBuf) == NULL) goto _err; - LOG_BUF_START(tLogBuff) = LOG_BUF_END(tLogBuff) = 0; - LOG_BUF_SIZE(tLogBuff) = bufSize; - tLogBuff->minBuffSize = bufSize / 10; - tLogBuff->stop = 0; + LOG_BUF_START(pLogBuf) = LOG_BUF_END(pLogBuf) = 0; + LOG_BUF_SIZE(pLogBuf) = bufSize; + pLogBuf->minBuffSize = bufSize / 10; + pLogBuf->stop = 0; - if (taosThreadMutexInit(&LOG_BUF_MUTEX(tLogBuff), NULL) < 0) goto _err; - // tsem_init(&(tLogBuff->buffNotEmpty), 0, 0); + if (taosThreadMutexInit(&LOG_BUF_MUTEX(pLogBuf), NULL) < 0) goto _err; + // tsem_init(&(pLogBuf->buffNotEmpty), 0, 0); - return tLogBuff; + return pLogBuf; _err: - taosMemoryFreeClear(LOG_BUF_BUFFER(tLogBuff)); - taosMemoryFreeClear(tLogBuff); + taosMemoryFreeClear(LOG_BUF_BUFFER(pLogBuf)); + taosMemoryFreeClear(pLogBuf); return NULL; } -static void taosCopyLogBuffer(SLogBuff *tLogBuff, int32_t start, int32_t end, const char *msg, int32_t msgLen) { +static void taosCopyLogBuffer(SLogBuff *pLogBuf, int32_t start, int32_t end, const char *msg, int32_t msgLen) { if (start > end) { - memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, msgLen); + memcpy(LOG_BUF_BUFFER(pLogBuf) + end, msg, msgLen); } else { - if (LOG_BUF_SIZE(tLogBuff) - end < msgLen) { - memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, LOG_BUF_SIZE(tLogBuff) - end); - memcpy(LOG_BUF_BUFFER(tLogBuff), msg + LOG_BUF_SIZE(tLogBuff) - end, msgLen - LOG_BUF_SIZE(tLogBuff) + end); + if (LOG_BUF_SIZE(pLogBuf) - end < msgLen) { + memcpy(LOG_BUF_BUFFER(pLogBuf) + end, msg, LOG_BUF_SIZE(pLogBuf) - end); + memcpy(LOG_BUF_BUFFER(pLogBuf), msg + LOG_BUF_SIZE(pLogBuf) - end, msgLen - LOG_BUF_SIZE(pLogBuf) + end); } else { - memcpy(LOG_BUF_BUFFER(tLogBuff) + end, msg, msgLen); + memcpy(LOG_BUF_BUFFER(pLogBuf) + end, msg, msgLen); } } - LOG_BUF_END(tLogBuff) = (LOG_BUF_END(tLogBuff) + msgLen) % LOG_BUF_SIZE(tLogBuff); + LOG_BUF_END(pLogBuf) = (LOG_BUF_END(pLogBuf) + msgLen) % LOG_BUF_SIZE(pLogBuf); } -static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t msgLen) { +static int32_t taosPushLogBuffer(SLogBuff *pLogBuf, const char *msg, int32_t msgLen) { int32_t start = 0; int32_t end = 0; int32_t remainSize = 0; @@ -552,13 +559,13 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms char tmpBuf[40] = {0}; int32_t tmpBufLen = 0; - if (tLogBuff == NULL || tLogBuff->stop) return -1; + if (pLogBuf == NULL || pLogBuf->stop) return -1; - taosThreadMutexLock(&LOG_BUF_MUTEX(tLogBuff)); - start = LOG_BUF_START(tLogBuff); - end = LOG_BUF_END(tLogBuff); + taosThreadMutexLock(&LOG_BUF_MUTEX(pLogBuf)); + start = LOG_BUF_START(pLogBuf); + end = LOG_BUF_END(pLogBuf); - remainSize = (start > end) ? (start - end - 1) : (start + LOG_BUF_SIZE(tLogBuff) - end - 1); + remainSize = (start > end) ? (start - end - 1) : (start + LOG_BUF_SIZE(pLogBuf) - end - 1); if (lostLine > 0) { sprintf(tmpBuf, "...Lost %" PRId64 " lines here...\n", lostLine); @@ -568,47 +575,47 @@ static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, const char *msg, int32_t ms if (remainSize <= msgLen || ((lostLine > 0) && (remainSize <= (msgLen + tmpBufLen)))) { lostLine++; tsAsyncLogLostLines++; - taosThreadMutexUnlock(&LOG_BUF_MUTEX(tLogBuff)); + taosThreadMutexUnlock(&LOG_BUF_MUTEX(pLogBuf)); return -1; } if (lostLine > 0) { - taosCopyLogBuffer(tLogBuff, start, end, tmpBuf, tmpBufLen); + taosCopyLogBuffer(pLogBuf, start, end, tmpBuf, tmpBufLen); lostLine = 0; } - taosCopyLogBuffer(tLogBuff, LOG_BUF_START(tLogBuff), LOG_BUF_END(tLogBuff), msg, msgLen); + taosCopyLogBuffer(pLogBuf, LOG_BUF_START(pLogBuf), LOG_BUF_END(pLogBuf), msg, msgLen); // int32_t w = atomic_sub_fetch_32(&waitLock, 1); /* - if (w <= 0 || ((remainSize - msgLen - tmpBufLen) < (LOG_BUF_SIZE(tLogBuff) * 4 /5))) { - tsem_post(&(tLogBuff->buffNotEmpty)); + if (w <= 0 || ((remainSize - msgLen - tmpBufLen) < (LOG_BUF_SIZE(pLogBuf) * 4 /5))) { + tsem_post(&(pLogBuf->buffNotEmpty)); dbgPostN++; } else { dbgNoPostN++; } */ - taosThreadMutexUnlock(&LOG_BUF_MUTEX(tLogBuff)); + taosThreadMutexUnlock(&LOG_BUF_MUTEX(pLogBuf)); return 0; } -static int32_t taosGetLogRemainSize(SLogBuff *tLogBuff, int32_t start, int32_t end) { +static int32_t taosGetLogRemainSize(SLogBuff *pLogBuf, int32_t start, int32_t end) { int32_t rSize = end - start; - return rSize >= 0 ? rSize : LOG_BUF_SIZE(tLogBuff) + rSize; + return rSize >= 0 ? rSize : LOG_BUF_SIZE(pLogBuf) + rSize; } -static void taosWriteLog(SLogBuff *tLogBuff) { +static void taosWriteLog(SLogBuff *pLogBuf) { static int32_t lastDuration = 0; int32_t remainChecked = 0; int32_t start, end, pollSize; do { if (remainChecked == 0) { - start = LOG_BUF_START(tLogBuff); - end = LOG_BUF_END(tLogBuff); + start = LOG_BUF_START(pLogBuf); + end = LOG_BUF_END(pLogBuf); if (start == end) { dbgEmptyW++; @@ -616,8 +623,8 @@ static void taosWriteLog(SLogBuff *tLogBuff) { return; } - pollSize = taosGetLogRemainSize(tLogBuff, start, end); - if (pollSize < tLogBuff->minBuffSize) { + pollSize = taosGetLogRemainSize(pLogBuf, start, end); + if (pollSize < pLogBuf->minBuffSize) { lastDuration += tsWriteInterval; if (lastDuration < LOG_MAX_WAIT_MSEC) { break; @@ -628,38 +635,38 @@ static void taosWriteLog(SLogBuff *tLogBuff) { } if (start < end) { - taosWriteFile(tLogBuff->pFile, LOG_BUF_BUFFER(tLogBuff) + start, pollSize); + taosWriteFile(pLogBuf->pFile, LOG_BUF_BUFFER(pLogBuf) + start, pollSize); } else { - int32_t tsize = LOG_BUF_SIZE(tLogBuff) - start; - taosWriteFile(tLogBuff->pFile, LOG_BUF_BUFFER(tLogBuff) + start, tsize); + int32_t tsize = LOG_BUF_SIZE(pLogBuf) - start; + taosWriteFile(pLogBuf->pFile, LOG_BUF_BUFFER(pLogBuf) + start, tsize); - taosWriteFile(tLogBuff->pFile, LOG_BUF_BUFFER(tLogBuff), end); + taosWriteFile(pLogBuf->pFile, LOG_BUF_BUFFER(pLogBuf), end); } dbgWN++; dbgWSize += pollSize; - if (pollSize < tLogBuff->minBuffSize) { + if (pollSize < pLogBuf->minBuffSize) { dbgSmallWN++; if (tsWriteInterval < LOG_MAX_INTERVAL) { tsWriteInterval += LOG_INTERVAL_STEP; } - } else if (pollSize > LOG_BUF_SIZE(tLogBuff) / 3) { + } else if (pollSize > LOG_BUF_SIZE(pLogBuf) / 3) { dbgBigWN++; tsWriteInterval = LOG_MIN_INTERVAL; - } else if (pollSize > LOG_BUF_SIZE(tLogBuff) / 4) { + } else if (pollSize > LOG_BUF_SIZE(pLogBuf) / 4) { if (tsWriteInterval > LOG_MIN_INTERVAL) { tsWriteInterval -= LOG_INTERVAL_STEP; } } - LOG_BUF_START(tLogBuff) = (LOG_BUF_START(tLogBuff) + pollSize) % LOG_BUF_SIZE(tLogBuff); + LOG_BUF_START(pLogBuf) = (LOG_BUF_START(pLogBuf) + pollSize) % LOG_BUF_SIZE(pLogBuf); - start = LOG_BUF_START(tLogBuff); - end = LOG_BUF_END(tLogBuff); + start = LOG_BUF_START(pLogBuf); + end = LOG_BUF_END(pLogBuf); - pollSize = taosGetLogRemainSize(tLogBuff, start, end); - if (pollSize < tLogBuff->minBuffSize) { + pollSize = taosGetLogRemainSize(pLogBuf, start, end); + if (pollSize < pLogBuf->minBuffSize) { break; } @@ -670,16 +677,16 @@ static void taosWriteLog(SLogBuff *tLogBuff) { } static void *taosAsyncOutputLog(void *param) { - SLogBuff *tLogBuff = (SLogBuff *)param; + SLogBuff *pLogBuf = (SLogBuff *)param; setThreadName("log"); while (1) { taosMsleep(tsWriteInterval); // Polling the buffer - taosWriteLog(tLogBuff); + taosWriteLog(pLogBuf); - if (tLogBuff->stop) break; + if (pLogBuf->stop) break; } return NULL; From b4ceaa0f0d40fafcbd76c866b52a27d0f9c2cd0c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 18 Apr 2022 10:22:31 +0800 Subject: [PATCH 09/13] fix: definite lost in tfs found by valgrind --- source/dnode/mgmt/mgmt_vnode/src/vmInt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c index bf33e85b95..a212d7edf4 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmInt.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmInt.c @@ -262,6 +262,7 @@ static void vmCleanup(SMgmtWrapper *pWrapper) { vmCloseVnodes(pMgmt); vmStopWorker(pMgmt); vnodeCleanup(); + tfsClose(pMgmt->pTfs); // walCleanUp(); taosMemoryFree(pMgmt); pWrapper->pMgmt = NULL; From 9ba91dbafa1431573a18d775bc85054f6aa8255f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 18 Apr 2022 10:44:00 +0800 Subject: [PATCH 10/13] test: invalid synatx in tsim --- tests/script/tsim/parser/fourArithmetic-basic.sim | 1 - tests/script/tsim/query/charScalarFunction.sim | 1 - tests/script/tsim/query/scalarFunction.sim | 1 - tests/script/tsim/query/session.sim | 1 - tests/script/tsim/tmq/basic1.sim | 1 - tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim | 1 - tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim | 1 - tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim | 1 - tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim | 1 - tests/script/tsim/tmq/mainConsumerInMultiTopic.sim | 1 - tests/script/tsim/tmq/mainConsumerInOneTopic.sim | 1 - tests/script/tsim/tmq/multiTopic.sim | 1 - tests/script/tsim/tmq/oneTopic.sim | 1 - tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim | 1 - 14 files changed, 14 deletions(-) diff --git a/tests/script/tsim/parser/fourArithmetic-basic.sim b/tests/script/tsim/parser/fourArithmetic-basic.sim index eee294dc80..dde451279d 100644 --- a/tests/script/tsim/parser/fourArithmetic-basic.sim +++ b/tests/script/tsim/parser/fourArithmetic-basic.sim @@ -1,7 +1,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/query/charScalarFunction.sim b/tests/script/tsim/query/charScalarFunction.sim index 18ee93f610..f1575d7293 100644 --- a/tests/script/tsim/query/charScalarFunction.sim +++ b/tests/script/tsim/query/charScalarFunction.sim @@ -2,7 +2,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/query/scalarFunction.sim b/tests/script/tsim/query/scalarFunction.sim index be75e1a21c..80d2dafa84 100644 --- a/tests/script/tsim/query/scalarFunction.sim +++ b/tests/script/tsim/query/scalarFunction.sim @@ -2,7 +2,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/query/session.sim b/tests/script/tsim/query/session.sim index 28f021e4ed..6f4010c3f3 100644 --- a/tests/script/tsim/query/session.sim +++ b/tests/script/tsim/query/session.sim @@ -2,7 +2,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/basic1.sim b/tests/script/tsim/tmq/basic1.sim index 84927c83a0..f7bd273624 100644 --- a/tests/script/tsim/tmq/basic1.sim +++ b/tests/script/tsim/tmq/basic1.sim @@ -11,7 +11,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim b/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim index 4fd4e60648..cf53cc7bcd 100644 --- a/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim +++ b/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrCtb.sim @@ -14,7 +14,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim b/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim index 3f199836f4..fe37ffffcb 100644 --- a/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim +++ b/tests/script/tsim/tmq/main2Con1Cgrp1TopicFrStb.sim @@ -14,7 +14,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim b/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim index 818a87a5a1..76f3c93e27 100644 --- a/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim +++ b/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrCtb.sim @@ -14,7 +14,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim b/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim index 1789a6bef3..86e0b32980 100644 --- a/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim +++ b/tests/script/tsim/tmq/main2Con1Cgrp2TopicFrStb.sim @@ -14,7 +14,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim b/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim index e0c463df65..d846632da4 100644 --- a/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim +++ b/tests/script/tsim/tmq/mainConsumerInMultiTopic.sim @@ -14,7 +14,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/mainConsumerInOneTopic.sim b/tests/script/tsim/tmq/mainConsumerInOneTopic.sim index 985237e34b..f6fccee5e5 100644 --- a/tests/script/tsim/tmq/mainConsumerInOneTopic.sim +++ b/tests/script/tsim/tmq/mainConsumerInOneTopic.sim @@ -14,7 +14,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/multiTopic.sim b/tests/script/tsim/tmq/multiTopic.sim index 4ad2df38f8..3795e82e86 100644 --- a/tests/script/tsim/tmq/multiTopic.sim +++ b/tests/script/tsim/tmq/multiTopic.sim @@ -14,7 +14,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/oneTopic.sim b/tests/script/tsim/tmq/oneTopic.sim index dbe6dbcb27..d4353f60c9 100644 --- a/tests/script/tsim/tmq/oneTopic.sim +++ b/tests/script/tsim/tmq/oneTopic.sim @@ -14,7 +14,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 diff --git a/tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim b/tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim index 2bad16fbaa..01bf91fd9f 100644 --- a/tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim +++ b/tests/script/tsim/tmq/overlapTopic2Con1Cgrp.sim @@ -14,7 +14,6 @@ system sh/stop_dnodes.sh system sh/deploy.sh -n dnode1 -i 1 -system sh/cfg.sh -n dnode1 system sh/exec.sh -n dnode1 -s start $loop_cnt = 0 From f56c354c00a33909817c5c786b652da8f68e872a Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 18 Apr 2022 10:58:40 +0800 Subject: [PATCH 11/13] fix: startup is slow in valgrind mode --- tests/tsim/src/simExe.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 5a18084fff..a4db0eff13 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -18,7 +18,7 @@ void simLogSql(char *sql, bool useSharp) { static TdFilePtr pFile = NULL; - char filename[256]; + char filename[256]; sprintf(filename, "%s/sim.sql", simScriptDir); if (pFile == NULL) { // fp = fopen(filename, "w"); @@ -305,7 +305,8 @@ bool simExecuteRunBackCmd(SScript *script, char *option) { return true; } -void simReplaceStr(char *buf, char *src, char *dst) { +bool simReplaceStr(char *buf, char *src, char *dst) { + bool replaced = false; char *begin = strstr(buf, src); if (begin != NULL) { int32_t srcLen = (int32_t)strlen(src); @@ -320,13 +321,16 @@ void simReplaceStr(char *buf, char *src, char *dst) { } memcpy(begin, dst, dstLen); + replaced = true; } simInfo("system cmd is %s", buf); + return replaced; } bool simExecuteSystemCmd(SScript *script, char *option) { char buf[4096] = {0}; + bool replaced = false; #ifndef WINDOWS sprintf(buf, "cd %s; ", simScriptDir); @@ -341,7 +345,7 @@ bool simExecuteSystemCmd(SScript *script, char *option) { } if (useValgrind) { - simReplaceStr(buf, "exec.sh", "exec.sh -v"); + replaced = simReplaceStr(buf, "exec.sh", "exec.sh -v"); } simLogSql(buf, true); @@ -359,6 +363,11 @@ bool simExecuteSystemCmd(SScript *script, char *option) { sprintf(script->system_exit_code, "%d", code); script->linePos++; + if (replaced && strstr(buf, "start") != NULL) { + simInfo("====> startup is slow in valgrind mode, so sleep 5 seconds after exec.sh -s start"); + taosMsleep(5000); + } + return true; } @@ -774,7 +783,7 @@ bool simExecuteSqlSlowCmd(SScript *script, char *rest) { bool simExecuteRestfulCmd(SScript *script, char *rest) { TdFilePtr pFile = NULL; - char filename[256]; + char filename[256]; sprintf(filename, "%s/tmp.sql", simScriptDir); // fp = fopen(filename, "w"); pFile = taosOpenFile(filename, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM); From 9de53b0019f6e50e494892bbd126eea057175162 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Mon, 18 Apr 2022 11:25:39 +0800 Subject: [PATCH 12/13] fix valgrind memleak --- source/libs/qworker/src/qworker.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/libs/qworker/src/qworker.c b/source/libs/qworker/src/qworker.c index a9a360e03e..f97d7ffae0 100644 --- a/source/libs/qworker/src/qworker.c +++ b/source/libs/qworker/src/qworker.c @@ -1470,6 +1470,9 @@ void qWorkerDestroy(void **qWorkerMgmt) { //TODO FREE ALL + taosHashCleanup(mgmt->ctxHash); + taosHashCleanup(mgmt->schHash); + taosMemoryFreeClear(*qWorkerMgmt); } From 649a9ac230fa725c9d340a0b3f34994cd413440c Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 18 Apr 2022 11:42:39 +0800 Subject: [PATCH 13/13] fix: memory overwrite while process nchar in sim script --- tests/tsim/inc/simInt.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tsim/inc/simInt.h b/tests/tsim/inc/simInt.h index c8b13736c7..24119b1433 100644 --- a/tests/tsim/inc/simInt.h +++ b/tests/tsim/inc/simInt.h @@ -33,7 +33,7 @@ #define MAX_BACKGROUND_SCRIPT_NUM 10 #define MAX_FILE_NAME_LEN 256 #define MAX_ERROR_LEN 1024 -#define MAX_QUERY_VALUE_LEN 40 +#define MAX_QUERY_VALUE_LEN 10240 #define MAX_QUERY_COL_NUM 20 #define MAX_QUERY_ROW_NUM 20 #define MAX_SYSTEM_RESULT_LEN 2048