From 00d346d51d459d10fa6ca7aa9768ed5012a743df Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 18 May 2022 08:30:39 +0000 Subject: [PATCH 01/32] more --- include/common/tdataformat.h | 2 +- source/common/src/tdataformat.c | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index e13705d403..d9220c461d 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -62,7 +62,7 @@ int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow); int32_t tTagNew(STagVal *pTagVals, int16_t nTag, STag **ppTag); void tTagFree(STag *pTag); void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, int32_t *nData); -int32_t tEncodeTag(SEncoder *pEncoder, STag *pTag); +int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag); int32_t tDecodeTag(SDecoder *pDecoder, const STag **ppTag); // STRUCT ================= diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 8aa8ed2f14..4bc01cba70 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -597,17 +597,12 @@ void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, int32_t *nD } } -int32_t tEncodeTag(SEncoder *pEncoder, STag *pTag) { - // return tEncodeBinary(pEncoder, (uint8_t *)pTag, pTag->len); - ASSERT(0); - return 0; +int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag) { + return tEncodeBinary(pEncoder, (const uint8_t *)pTag, pTag->len); } int32_t tDecodeTag(SDecoder *pDecoder, const STag **ppTag) { - // uint32_t n; - // return tDecodeBinary(pDecoder, (const uint8_t **)ppTag, &n); - ASSERT(0); - return 0; + return tDecodeBinary(pDecoder, (const uint8_t **)ppTag, NULL); } #if 1 // =================================================================================================================== From 70042a918c01210061999569d0fd76af76b20fe6 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 18 May 2022 09:17:38 +0000 Subject: [PATCH 02/32] more data format --- include/common/tdataformat.h | 3 ++- source/common/src/tdataformat.c | 47 ++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index d9220c461d..29e9695e3e 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -61,7 +61,8 @@ int32_t tTSRowBuilderGetRow(STSRowBuilder *pBuilder, const STSRow2 **ppRow); // STag int32_t tTagNew(STagVal *pTagVals, int16_t nTag, STag **ppTag); void tTagFree(STag *pTag); -void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, int32_t *nData); +int32_t tTagSet(STag *pTag, SSchema *pSchema, int32_t nCols, int iCol, uint8_t *pData, uint32_t nData, STag **ppTag); +void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, uint32_t *nData); int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag); int32_t tDecodeTag(SDecoder *pDecoder, const STag **ppTag); diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 4bc01cba70..f4b8f00e3b 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -581,7 +581,52 @@ void tTagFree(STag *pTag) { if (pTag) taosMemoryFree(pTag); } -void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, int32_t *nData) { +int32_t tTagSet(STag *pTag, SSchema *pSchema, int32_t nCols, int iCol, uint8_t *pData, uint32_t nData, STag **ppTag) { + STagVal *pTagVals; + int16_t nTags = 0; + SSchema *pColumn; + uint8_t *p; + uint32_t n; + + pTagVals = (STagVal *)taosMemoryMalloc(sizeof(*pTagVals) * nCols); + if (pTagVals == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + for (int32_t i = 0; i < nCols; i++) { + pColumn = &pSchema[i]; + + if (i == iCol) { + p = pData; + n = nData; + } else { + tTagGet(pTag, pColumn->colId, pColumn->type, &p, &n); + } + + if (p == NULL) continue; + + ASSERT(IS_VAR_DATA_TYPE(pColumn->type) || n == pColumn->bytes); + + pTagVals[nTags].cid = pColumn->colId; + pTagVals[nTags].type = pColumn->type; + pTagVals[nTags].nData = n; + pTagVals[nTags].pData = p; + + nTags++; + } + + // create new tag + if (tTagNew(pTagVals, nTags, ppTag) < 0) { + taosMemoryFree(pTagVals); + return -1; + } + + taosMemoryFree(pTagVals); + return 0; +} + +void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, uint32_t *nData) { STagIdx *pTagIdx = bsearch(&((STagIdx){.cid = cid}), pTag->idx, pTag->nTag, sizeof(STagIdx), tTagIdxCmprFn); if (pTagIdx == NULL) { *ppData = NULL; From 067af9d0bea04fad5bdbe00260dcabe2b2ce408c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 24 May 2022 06:50:47 +0000 Subject: [PATCH 03/32] feat: vnode snapshot 1 --- include/common/tdataformat.h | 2 +- include/util/taoserror.h | 1 + source/common/src/tdataformat.c | 6 +- source/dnode/vnode/CMakeLists.txt | 3 + source/dnode/vnode/inc/vnode.h | 12 +-- source/dnode/vnode/src/inc/vnodeInt.h | 26 ++++-- source/dnode/vnode/src/meta/metaSnapshot.c | 35 ++++++++ source/dnode/vnode/src/tsdb/tsdbSnapshot.c | 35 ++++++++ source/dnode/vnode/src/vnd/vnodeSnapshot.c | 97 ++++++++++++++++++++++ source/util/src/terror.c | 1 + 10 files changed, 199 insertions(+), 19 deletions(-) create mode 100644 source/dnode/vnode/src/meta/metaSnapshot.c create mode 100644 source/dnode/vnode/src/tsdb/tsdbSnapshot.c create mode 100644 source/dnode/vnode/src/vnd/vnodeSnapshot.c diff --git a/include/common/tdataformat.h b/include/common/tdataformat.h index bbe7d22cfb..ef931ed3b1 100644 --- a/include/common/tdataformat.h +++ b/include/common/tdataformat.h @@ -64,7 +64,7 @@ void tTagFree(STag *pTag); int32_t tTagSet(STag *pTag, SSchema *pSchema, int32_t nCols, int iCol, uint8_t *pData, uint32_t nData, STag **ppTag); void tTagGet(STag *pTag, int16_t cid, int8_t type, uint8_t **ppData, uint32_t *nData); int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag); -int32_t tDecodeTag(SDecoder *pDecoder, const STag **ppTag); +int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag); // STRUCT ================= struct STColumn { diff --git a/include/util/taoserror.h b/include/util/taoserror.h index e318978339..0ba1d0c0f2 100644 --- a/include/util/taoserror.h +++ b/include/util/taoserror.h @@ -313,6 +313,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_VND_INVALID_TABLE_ACTION TAOS_DEF_ERROR_CODE(0, 0x0519) #define TSDB_CODE_VND_COL_ALREADY_EXISTS TAOS_DEF_ERROR_CODE(0, 0x051a) #define TSDB_CODE_VND_TABLE_COL_NOT_EXISTS TAOS_DEF_ERROR_CODE(0, 0x051b) +#define TSDB_CODE_VND_READ_END TAOS_DEF_ERROR_CODE(0, 0x051c) // tsdb #define TSDB_CODE_TDB_INVALID_TABLE_ID TAOS_DEF_ERROR_CODE(0, 0x0600) diff --git a/source/common/src/tdataformat.c b/source/common/src/tdataformat.c index 65c044a29b..e8d7e3ac09 100644 --- a/source/common/src/tdataformat.c +++ b/source/common/src/tdataformat.c @@ -646,9 +646,7 @@ int32_t tEncodeTag(SEncoder *pEncoder, const STag *pTag) { return tEncodeBinary(pEncoder, (const uint8_t *)pTag, pTag->len); } -int32_t tDecodeTag(SDecoder *pDecoder, const STag **ppTag) { - return tDecodeBinary(pDecoder, (const uint8_t **)ppTag, NULL); -} +int32_t tDecodeTag(SDecoder *pDecoder, STag **ppTag) { return tDecodeBinary(pDecoder, (uint8_t **)ppTag, NULL); } #if 1 // =================================================================================================================== static void dataColSetNEleNull(SDataCol *pCol, int nEle); @@ -1127,7 +1125,7 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) { kvRowSetNCols(row, pBuilder->nCols); kvRowSetLen(row, tlen); - if(pBuilder->nCols > 0){ + if (pBuilder->nCols > 0) { memcpy(kvRowColIdx(row), pBuilder->pColIdx, sizeof(SColIdx) * pBuilder->nCols); memcpy(kvRowValues(row), pBuilder->buf, pBuilder->size); } diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index 4141485d28..cb73f5462b 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -13,6 +13,7 @@ target_sources( "src/vnd/vnodeModule.c" "src/vnd/vnodeSvr.c" "src/vnd/vnodeSync.c" + "src/vnd/vnodeSnapshot.c" # meta "src/meta/metaOpen.c" @@ -22,6 +23,7 @@ target_sources( "src/meta/metaQuery.c" "src/meta/metaCommit.c" "src/meta/metaEntry.c" + "src/meta/metaSnapshot.c" # sma "src/sma/sma.c" @@ -44,6 +46,7 @@ target_sources( "src/tsdb/tsdbReadImpl.c" # "src/tsdb/tsdbSma.c" "src/tsdb/tsdbWrite.c" + "src/tsdb/tsdbSnapshot.c" # tq "src/tq/tq.c" diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 9e33973c05..1b8fe71fb8 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -39,9 +39,10 @@ extern "C" { #endif // vnode -typedef struct SVnode SVnode; -typedef struct STsdbCfg STsdbCfg; // todo: remove -typedef struct SVnodeCfg SVnodeCfg; +typedef struct SVnode SVnode; +typedef struct STsdbCfg STsdbCfg; // todo: remove +typedef struct SVnodeCfg SVnodeCfg; +typedef struct SVSnapshotReader SVSnapshotReader; extern const SVnodeCfg vnodeCfgDefault; @@ -59,13 +60,14 @@ int32_t vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg); int32_t vnodeProcessFetchMsg(SVnode *pVnode, SRpcMsg *pMsg, SQueueInfo *pInfo); int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad); int32_t vnodeValidateTableHash(SVnode *pVnode, char *tableFName); - int32_t vnodeStart(SVnode *pVnode); void vnodeStop(SVnode *pVnode); - int64_t vnodeGetSyncHandle(SVnode *pVnode); void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot); void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId); +int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int64_t sver, int64_t ever); +int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader); +int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, void **ppData, uint32_t *nData); // meta typedef struct SMeta SMeta; // todo: remove diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 24b3f458b1..380b1fc518 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -47,15 +47,17 @@ extern "C" { #endif -typedef struct SVnodeInfo SVnodeInfo; -typedef struct SMeta SMeta; -typedef struct SSma SSma; -typedef struct STsdb STsdb; -typedef struct STQ STQ; -typedef struct SVState SVState; -typedef struct SVBufPool SVBufPool; -typedef struct SQWorker SQHandle; -typedef struct STsdbKeepCfg STsdbKeepCfg; +typedef struct SVnodeInfo SVnodeInfo; +typedef struct SMeta SMeta; +typedef struct SSma SSma; +typedef struct STsdb STsdb; +typedef struct STQ STQ; +typedef struct SVState SVState; +typedef struct SVBufPool SVBufPool; +typedef struct SQWorker SQHandle; +typedef struct STsdbKeepCfg STsdbKeepCfg; +typedef struct SMetaSnapshotReader SMetaSnapshotReader; +typedef struct STsdbSnapshotReader STsdbSnapshotReader; #define VNODE_META_DIR "meta" #define VNODE_TSDB_DIR "tsdb" @@ -95,6 +97,9 @@ STSma* metaGetSmaInfoByIndex(SMeta* pMeta, int64_t indexUid); STSmaWrapper* metaGetSmaInfoByTable(SMeta* pMeta, tb_uid_t uid, bool deepCopy); SArray* metaGetSmaIdsByTable(SMeta* pMeta, tb_uid_t uid); SArray* metaGetSmaTbUids(SMeta* pMeta); +int32_t metaSnapshotReaderOpen(SMeta* pMeta, SMetaSnapshotReader** ppReader, int64_t sver, int64_t ever); +int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader); +int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nData); int32_t metaCreateTSma(SMeta* pMeta, int64_t version, SSmaCfg* pCfg); int32_t metaDropTSma(SMeta* pMeta, int64_t indexUid); @@ -112,6 +117,9 @@ tsdbReaderT* tsdbQueryTables(SVnode* pVnode, SQueryTableDataCond* pCond, STableG tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId, void* pMemRef); int32_t tsdbGetTableGroupFromIdListT(STsdb* tsdb, SArray* pTableIdList, STableGroupInfo* pGroupInfo); +int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever); +int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader); +int32_t tsdbSnapshotRead(STsdbSnapshotReader* pReader, void** ppData, uint32_t* nData); // tq STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal); diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c new file mode 100644 index 0000000000..9a9d8dd641 --- /dev/null +++ b/source/dnode/vnode/src/meta/metaSnapshot.c @@ -0,0 +1,35 @@ +/* + * 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 "meta.h" + +struct SMetaSnapshotReader { + // TODO +}; + +int32_t metaSnapshotReaderOpen(SMeta* pMeta, SMetaSnapshotReader** ppReader, int64_t sver, int64_t ever) { + // TODO + return 0; +} + +int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader) { + // TODO + return 0; +} + +int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nData) { + // TODO + return 0; +} \ No newline at end of file diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c new file mode 100644 index 0000000000..f40cab600f --- /dev/null +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -0,0 +1,35 @@ +/* + * 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 "tsdb.h" + +struct STsdbSnapshotReader { + // TODO +}; + +int32_t tsdbSnapshotReaderOpen(STsdb* pTsdb, STsdbSnapshotReader** ppReader, int64_t sver, int64_t ever) { + // TODO + return 0; +} + +int32_t tsdbSnapshotReaderClose(STsdbSnapshotReader* pReader) { + // TODO + return 0; +} + +int32_t tsdbSnapshotRead(STsdbSnapshotReader* pReader, void** ppData, uint32_t* nData) { + // TODO + return 0; +} diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c new file mode 100644 index 0000000000..67d9c120db --- /dev/null +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -0,0 +1,97 @@ +/* + * 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" + +struct SVSnapshotReader { + SVnode *pVnode; + int64_t sver; + int64_t ever; + int8_t isMetaEnd; + int8_t isTsdbEnd; + SMetaSnapshotReader *pMetaReader; + STsdbSnapshotReader *pTsdbReader; +}; + +int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int64_t sver, int64_t ever) { + SVSnapshotReader *pReader = NULL; + + pReader = (SVSnapshotReader *)taosMemoryCalloc(1, sizeof(*pReader)); + if (pReader == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pReader->pVnode = pVnode; + pReader->sver = sver; + pReader->ever = ever; + pReader->isMetaEnd = 0; + pReader->isTsdbEnd = 0; + + if (metaSnapshotReaderOpen(pVnode->pMeta, &pReader->pMetaReader, sver, ever) < 0) { + taosMemoryFree(pReader); + goto _err; + } + + if (tsdbSnapshotReaderOpen(pVnode->pTsdb, &pReader->pTsdbReader, sver, ever) < 0) { + metaSnapshotReaderClose(pReader->pMetaReader); + taosMemoryFree(pReader); + goto _err; + } + +_exit: + *ppReader = pReader; + return 0; + +_err: + *ppReader = NULL; + return -1; +} + +int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader) { + if (pReader) { + tsdbSnapshotReaderClose(pReader->pTsdbReader); + metaSnapshotReaderClose(pReader->pMetaReader); + taosMemoryFree(pReader); + } + return 0; +} + +int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, void **ppData, uint32_t *nData) { + int32_t code = 0; + + if (!pReader->isMetaEnd) { + code = metaSnapshotRead(pReader->pMetaReader, ppData, nData); + if (code) { + if (code == TSDB_CODE_VND_READ_END) { + pReader->isMetaEnd = 1; + } else { + return code; + } + } else { + return code; + } + } + + if (!pReader->isTsdbEnd) { + code = tsdbSnapshotRead(pReader->pTsdbReader, ppData, nData); + if (code) { + } else { + return code; + } + } + + code = TSDB_CODE_VND_READ_END; + return code; +} \ No newline at end of file diff --git a/source/util/src/terror.c b/source/util/src/terror.c index 7c4f0fa2dd..0b37a71c60 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -311,6 +311,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_VND_TABLE_NOT_EXIST, "Table does not exists TAOS_DEFINE_ERROR(TSDB_CODE_VND_INVALID_TABLE_ACTION, "Invalid table action") TAOS_DEFINE_ERROR(TSDB_CODE_VND_COL_ALREADY_EXISTS, "Table column already exists") TAOS_DEFINE_ERROR(TSDB_CODE_VND_TABLE_COL_NOT_EXISTS, "Table column not exists") +TAOS_DEFINE_ERROR(TSDB_CODE_VND_READ_END, "Read end") // tsdb From c81ff9cbab82c807ea7db07b1fc6d05f67a40974 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 24 May 2022 09:12:14 +0000 Subject: [PATCH 04/32] vnode snapshot 2 --- source/dnode/vnode/CMakeLists.txt | 1 + source/dnode/vnode/src/inc/vnodeInt.h | 6 +- source/dnode/vnode/src/meta/metaSnapshot.c | 72 +++++++++++++++++++--- source/dnode/vnode/src/vnd/vnodeUtil.c | 45 ++++++++++++++ 4 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 source/dnode/vnode/src/vnd/vnodeUtil.c diff --git a/source/dnode/vnode/CMakeLists.txt b/source/dnode/vnode/CMakeLists.txt index cb73f5462b..d988f97188 100644 --- a/source/dnode/vnode/CMakeLists.txt +++ b/source/dnode/vnode/CMakeLists.txt @@ -14,6 +14,7 @@ target_sources( "src/vnd/vnodeSvr.c" "src/vnd/vnodeSync.c" "src/vnd/vnodeSnapshot.c" + "src/vnd/vnodeUtil.c" # meta "src/meta/metaOpen.c" diff --git a/source/dnode/vnode/src/inc/vnodeInt.h b/source/dnode/vnode/src/inc/vnodeInt.h index 380b1fc518..faf0ddcd4a 100644 --- a/source/dnode/vnode/src/inc/vnodeInt.h +++ b/source/dnode/vnode/src/inc/vnodeInt.h @@ -69,8 +69,10 @@ typedef struct STsdbSnapshotReader STsdbSnapshotReader; #define VNODE_RSMA2_DIR "rsma2" // vnd.h -void* vnodeBufPoolMalloc(SVBufPool* pPool, int size); -void vnodeBufPoolFree(SVBufPool* pPool, void* p); +void* vnodeBufPoolMalloc(SVBufPool* pPool, int size); +void vnodeBufPoolFree(SVBufPool* pPool, void* p); +int32_t vnodeRealloc(void** pp, int32_t size); +void vnodeFree(void* p); // meta typedef struct SMCtbCursor SMCtbCursor; diff --git a/source/dnode/vnode/src/meta/metaSnapshot.c b/source/dnode/vnode/src/meta/metaSnapshot.c index 9a9d8dd641..5757039d55 100644 --- a/source/dnode/vnode/src/meta/metaSnapshot.c +++ b/source/dnode/vnode/src/meta/metaSnapshot.c @@ -16,20 +16,78 @@ #include "meta.h" struct SMetaSnapshotReader { - // TODO + SMeta* pMeta; + TBC* pTbc; + int64_t sver; + int64_t ever; }; int32_t metaSnapshotReaderOpen(SMeta* pMeta, SMetaSnapshotReader** ppReader, int64_t sver, int64_t ever) { - // TODO - return 0; + int32_t code = 0; + int32_t c = 0; + SMetaSnapshotReader* pMetaReader = NULL; + + pMetaReader = (SMetaSnapshotReader*)taosMemoryCalloc(1, sizeof(*pMetaReader)); + if (pMetaReader == NULL) { + code = TSDB_CODE_OUT_OF_MEMORY; + goto _err; + } + pMetaReader->pMeta = pMeta; + pMetaReader->sver = sver; + pMetaReader->ever = ever; + code = tdbTbcOpen(pMeta->pTbDb, &pMetaReader->pTbc, NULL); + if (code) { + goto _err; + } + + code = tdbTbcMoveTo(pMetaReader->pTbc, &(STbDbKey){.version = sver, .uid = INT64_MIN}, sizeof(STbDbKey), &c); + if (code) { + goto _err; + } + + *ppReader = pMetaReader; + return code; + +_err: + *ppReader = NULL; + return code; } int32_t metaSnapshotReaderClose(SMetaSnapshotReader* pReader) { - // TODO + if (pReader) { + tdbTbcClose(pReader->pTbc); + taosMemoryFree(pReader); + } return 0; } -int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nData) { - // TODO - return 0; +int32_t metaSnapshotRead(SMetaSnapshotReader* pReader, void** ppData, uint32_t* nDatap) { + const void* pKey = NULL; + const void* pData = NULL; + int32_t nKey = 0; + int32_t nData = 0; + int32_t code = 0; + + for (;;) { + code = tdbTbcGet(pReader->pTbc, &pKey, &nKey, &pData, &nData); + if (code || ((STbDbKey*)pData)->version > pReader->ever) { + return TSDB_CODE_VND_READ_END; + } + + if (((STbDbKey*)pData)->version < pReader->sver) { + continue; + } + + break; + } + + // copy the data + if (vnodeRealloc(ppData, nData) < 0) { + code = TSDB_CODE_OUT_OF_MEMORY; + return code; + } + + memcpy(*ppData, pData, nData); + *nDatap = nData; + return code; } \ No newline at end of file diff --git a/source/dnode/vnode/src/vnd/vnodeUtil.c b/source/dnode/vnode/src/vnd/vnodeUtil.c new file mode 100644 index 0000000000..cd942099bc --- /dev/null +++ b/source/dnode/vnode/src/vnd/vnodeUtil.c @@ -0,0 +1,45 @@ +/* + * 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 "vnd.h" + +int32_t vnodeRealloc(void** pp, int32_t size) { + uint8_t* p = NULL; + int32_t csize = 0; + + if (*pp) { + p = (uint8_t*)(*pp) - sizeof(int32_t); + csize = *(int32_t*)p; + } + + if (csize >= size) { + return 0; + } + + p = (uint8_t*)taosMemoryRealloc(p, size); + if (p == NULL) { + return TSDB_CODE_OUT_OF_MEMORY; + } + *(int32_t*)p = size; + *pp = p + sizeof(int32_t); + + return 0; +} + +void vnodeFree(void* p) { + if (p) { + taosMemoryFree(((uint8_t*)p) - sizeof(int32_t)); + } +} \ No newline at end of file From 9fbbb25aea2f79bf2d2c05775dad400616c47ae2 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Tue, 24 May 2022 09:21:14 +0000 Subject: [PATCH 05/32] feat: vnode snapshot --- source/dnode/vnode/inc/vnode.h | 2 +- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index 1b8fe71fb8..6026245174 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -67,7 +67,7 @@ void vnodeGetSnapshot(SVnode *pVnode, SSnapshot *pSnapshot); void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId); int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int64_t sver, int64_t ever); int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader); -int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, void **ppData, uint32_t *nData); +int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32_t *nData); // meta typedef struct SMeta SMeta; // todo: remove diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 67d9c120db..5e451e4142 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -23,6 +23,8 @@ struct SVSnapshotReader { int8_t isTsdbEnd; SMetaSnapshotReader *pMetaReader; STsdbSnapshotReader *pTsdbReader; + void *pData; + int32_t nData; }; int32_t vnodeSnapshotReaderOpen(SVnode *pVnode, SVSnapshotReader **ppReader, int64_t sver, int64_t ever) { @@ -61,6 +63,7 @@ _err: int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader) { if (pReader) { + vnodeFree(pReader->pData); tsdbSnapshotReaderClose(pReader->pTsdbReader); metaSnapshotReaderClose(pReader->pMetaReader); taosMemoryFree(pReader); @@ -68,11 +71,11 @@ int32_t vnodeSnapshotReaderClose(SVSnapshotReader *pReader) { return 0; } -int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, void **ppData, uint32_t *nData) { +int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32_t *nData) { int32_t code = 0; if (!pReader->isMetaEnd) { - code = metaSnapshotRead(pReader->pMetaReader, ppData, nData); + code = metaSnapshotRead(pReader->pMetaReader, &pReader->pData, &pReader->pData); if (code) { if (code == TSDB_CODE_VND_READ_END) { pReader->isMetaEnd = 1; @@ -80,14 +83,23 @@ int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, void **ppData, uint32_t *nD return code; } } else { + *ppData = pReader->pData; + *nData = pReader->nData; return code; } } if (!pReader->isTsdbEnd) { - code = tsdbSnapshotRead(pReader->pTsdbReader, ppData, nData); + code = tsdbSnapshotRead(pReader->pTsdbReader, &pReader->pData, pReader->nData); if (code) { + if (code == TSDB_CODE_VND_READ_END) { + pReader->isTsdbEnd = 1; + } else { + return code; + } } else { + *ppData = pReader->pData; + *nData = pReader->nData; return code; } } From 0a5412f33d7ae055c251584d38a027d6b1e82be2 Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Tue, 24 May 2022 21:00:14 +0800 Subject: [PATCH 06/32] refactor: modify FpSnapshotRead, FpSnapshotApply --- include/libs/sync/sync.h | 13 +++++++++++-- source/dnode/mnode/impl/src/mndSync.c | 6 +++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 5ffcbb7a09..4ac4922e80 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -98,8 +98,17 @@ typedef struct SSyncFSM { void (*FpRestoreFinishCb)(struct SSyncFSM* pFsm); int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot); - void* (*FpSnapshotRead)(struct SSyncFSM* pFsm, const SSnapshot* snapshot, void* iter, char** ppBuf, int32_t* len); - int32_t (*FpSnapshotApply)(struct SSyncFSM* pFsm, const SSnapshot* snapshot, char* pBuf, int32_t len); + + // if (*ppIter == NULL) + // *ppIter = new iter; + // else + // *ppIter.next(); + // + // if success, return 0. else return error code + int32_t (*FpSnapshotRead)(struct SSyncFSM* pFsm, const SSnapshot* pSnapshot, void** ppIter, char** ppBuf, int32_t* len); + + // apply data into fsm + int32_t (*FpSnapshotApply)(struct SSyncFSM* pFsm, const SSnapshot* pSnapshot, char* pBuf, int32_t len); void (*FpReConfigCb)(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta); diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 2b4b472c35..0ddb542b38 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -55,7 +55,7 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) { pMnode->syncMgmt.restored = true; } -void* mndSnapshotRead(struct SSyncFSM* pFsm, const SSnapshot* snapshot, void* iter, char** ppBuf, int32_t* len) { +int32_t mndSnapshotRead(struct SSyncFSM* pFsm, const SSnapshot* pSnapshot, void** ppIter, char** ppBuf, int32_t* len) { /* SMnode *pMnode = pFsm->data; SSdbIter *pIter; @@ -68,10 +68,10 @@ void* mndSnapshotRead(struct SSyncFSM* pFsm, const SSnapshot* snapshot, void* it return pIter; */ - return NULL; + return 0; } -int32_t mndSnapshotApply(struct SSyncFSM* pFsm, const SSnapshot* snapshot, char* pBuf, int32_t len) { +int32_t mndSnapshotApply(struct SSyncFSM* pFsm, const SSnapshot* pSnapshot, char* pBuf, int32_t len) { SMnode *pMnode = pFsm->data; sdbWrite(pMnode->pSdb, (SSdbRaw*)pBuf); return 0; From 9beb5ebee381029f4ff74d9da868ee2f907085ba Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 24 May 2022 23:10:21 +0800 Subject: [PATCH 07/32] refactor: let all operations of mnode into the sync log --- source/dnode/mnode/impl/inc/mndInt.h | 1 + source/dnode/mnode/impl/src/mndDnode.c | 29 +++++++++++++++++++++++++- source/dnode/mnode/impl/src/mndMnode.c | 26 +++++++++++++++++++++++ source/dnode/mnode/impl/src/mndTrans.c | 2 +- source/dnode/mnode/impl/src/mndUser.c | 26 +++++++++++++++++++++++ source/dnode/mnode/impl/src/mnode.c | 24 +++++++++++++-------- 6 files changed, 97 insertions(+), 11 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index a258a369d3..489e1aec5c 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -93,6 +93,7 @@ typedef struct SMnode { int32_t selfId; int64_t clusterId; TdThread thread; + bool deploy; bool stopped; int8_t replica; int8_t selfIndex; diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 0cac7fd86b..1f6dc03dc3 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -90,13 +90,40 @@ static int32_t mndCreateDefaultDnode(SMnode *pMnode) { dnodeObj.updateTime = dnodeObj.createdTime; dnodeObj.port = pMnode->replicas[0].port; memcpy(&dnodeObj.fqdn, pMnode->replicas[0].fqdn, TSDB_FQDN_LEN); + snprintf(dnodeObj.ep, TSDB_EP_LEN, "%s:%u", dnodeObj.fqdn, dnodeObj.port); SSdbRaw *pRaw = mndDnodeActionEncode(&dnodeObj); if (pRaw == NULL) return -1; if (sdbSetRawStatus(pRaw, SDB_STATUS_READY) != 0) return -1; mDebug("dnode:%d, will be created while deploy sdb, raw:%p", dnodeObj.id, pRaw); + +#if 0 return sdbWrite(pMnode->pSdb, pRaw); +#else + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_DNODE, NULL); + if (pTrans == NULL) { + mError("dnode:%s, failed to create since %s", dnodeObj.ep, terrstr()); + return -1; + } + mDebug("trans:%d, used to create dnode:%s", pTrans->id, dnodeObj.ep); + + if (mndTransAppendCommitlog(pTrans, pRaw) != 0) { + mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + + mndTransDrop(pTrans); + return 0; +#endif } static SSdbRaw *mndDnodeActionEncode(SDnodeObj *pDnode) { @@ -701,7 +728,7 @@ static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB colDataAppend(pColInfo, numOfRows, (const char *)&pDnode->id, false); char buf[tListLen(pDnode->ep) + VARSTR_HEADER_SIZE] = {0}; - STR_WITH_MAXSIZE_TO_VARSTR(buf, pDnode->ep, pShow->pMeta->pSchemas[cols].bytes); + STR_WITH_MAXSIZE_TO_VARSTR(buf, pDnode->ep, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, buf, false); diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 0bb89a1d91..414b0466bb 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -110,7 +110,33 @@ static int32_t mndCreateDefaultMnode(SMnode *pMnode) { sdbSetRawStatus(pRaw, SDB_STATUS_READY); mDebug("mnode:%d, will be created while deploy sdb, raw:%p", mnodeObj.id, pRaw); + +#if 0 return sdbWrite(pMnode->pSdb, pRaw); +#else + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_DNODE, NULL); + if (pTrans == NULL) { + mError("mnode:%d, failed to create since %s", mnodeObj.id, terrstr()); + return -1; + } + mDebug("trans:%d, used to create mnode:%d", pTrans->id, mnodeObj.id); + + if (mndTransAppendCommitlog(pTrans, pRaw) != 0) { + mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + + mndTransDrop(pTrans); + return 0; +#endif } static SSdbRaw *mndMnodeActionEncode(SMnodeObj *pObj) { diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index c6fcc7903f..31fb12a0a2 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -563,7 +563,7 @@ STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnType type, const S pTrans->policy = policy; pTrans->type = type; pTrans->createdTime = taosGetTimestampMs(); - pTrans->rpcInfo = pReq->info; + if (pReq != NULL) pTrans->rpcInfo = pReq->info; pTrans->redoLogs = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(void *)); pTrans->undoLogs = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(void *)); pTrans->commitLogs = taosArrayInit(TRANS_ARRAY_SIZE, sizeof(void *)); diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 5f2147a5fe..cc6364c457 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -78,7 +78,33 @@ static int32_t mndCreateDefaultUser(SMnode *pMnode, char *acct, char *user, char sdbSetRawStatus(pRaw, SDB_STATUS_READY); mDebug("user:%s, will be created while deploy sdb, raw:%p", userObj.user, pRaw); + +#if 0 return sdbWrite(pMnode->pSdb, pRaw); +#else + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_USER, NULL); + if (pTrans == NULL) { + mError("user:%s, failed to create since %s", userObj.user, terrstr()); + return -1; + } + mDebug("trans:%d, used to create user:%s", pTrans->id, userObj.user); + + if (mndTransAppendCommitlog(pTrans, pRaw) != 0) { + mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + + mndTransDrop(pTrans); + return 0; +#endif } static int32_t mndCreateDefaultUsers(SMnode *pMnode) { diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 572844d8d4..4f1b99959f 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -153,8 +153,14 @@ static int32_t mndInitSdb(SMnode *pMnode) { return 0; } -static int32_t mndDeploySdb(SMnode *pMnode) { return sdbDeploy(pMnode->pSdb); } -static int32_t mndReadSdb(SMnode *pMnode) { return sdbReadFile(pMnode->pSdb); } +static int32_t mndOpenSdb(SMnode *pMnode) { + if (!pMnode->deploy) { + return sdbReadFile(pMnode->pSdb); + } else { + // return sdbDeploy(pMnode->pSdb);; + return 0; + } +} static void mndCleanupSdb(SMnode *pMnode) { if (pMnode->pSdb) { @@ -176,7 +182,7 @@ static int32_t mndAllocStep(SMnode *pMnode, char *name, MndInitFp initFp, MndCle return 0; } -static int32_t mndInitSteps(SMnode *pMnode, bool deploy) { +static int32_t mndInitSteps(SMnode *pMnode) { if (mndAllocStep(pMnode, "mnode-sdb", mndInitSdb, mndCleanupSdb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-trans", mndInitTrans, mndCleanupTrans) != 0) return -1; if (mndAllocStep(pMnode, "mnode-cluster", mndInitCluster, mndCleanupCluster) != 0) return -1; @@ -201,11 +207,7 @@ static int32_t mndInitSteps(SMnode *pMnode, bool deploy) { if (mndAllocStep(pMnode, "mnode-perfs", mndInitPerfs, mndCleanupPerfs) != 0) return -1; if (mndAllocStep(pMnode, "mnode-db", mndInitDb, mndCleanupDb) != 0) return -1; if (mndAllocStep(pMnode, "mnode-func", mndInitFunc, mndCleanupFunc) != 0) return -1; - if (deploy) { - if (mndAllocStep(pMnode, "mnode-sdb-deploy", mndDeploySdb, NULL) != 0) return -1; - } else { - if (mndAllocStep(pMnode, "mnode-sdb-read", mndReadSdb, NULL) != 0) return -1; - } + if (mndAllocStep(pMnode, "mnode-sdb", mndOpenSdb, NULL) != 0) return -1; if (mndAllocStep(pMnode, "mnode-profile", mndInitProfile, mndCleanupProfile) != 0) return -1; if (mndAllocStep(pMnode, "mnode-show", mndInitShow, mndCleanupShow) != 0) return -1; if (mndAllocStep(pMnode, "mnode-query", mndInitQuery, mndCleanupQuery) != 0) return -1; @@ -280,6 +282,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { (void)taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); mndSetOptions(pMnode, pOption); + pMnode->deploy = pOption->deploy; pMnode->pSteps = taosArrayInit(24, sizeof(SMnodeStep)); if (pMnode->pSteps == NULL) { taosMemoryFree(pMnode); @@ -297,7 +300,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { return NULL; } - code = mndInitSteps(pMnode, pOption->deploy); + code = mndInitSteps(pMnode); if (code != 0) { code = terrno; mError("failed to open mnode since %s", terrstr()); @@ -332,6 +335,9 @@ void mndClose(SMnode *pMnode) { int32_t mndStart(SMnode *pMnode) { mndSyncStart(pMnode); + if (pMnode->deploy && sdbDeploy(pMnode->pSdb) != 0) { + return -1; + } return mndInitTimer(pMnode); } From 3ac134adbe129c9d4ce8301a3155fb78d6b6ac90 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 24 May 2022 23:10:51 +0800 Subject: [PATCH 08/32] enh: free cursor if it is not a null pointer. --- include/common/tmsg.h | 3 +-- source/libs/executor/src/scanoperator.c | 3 ++- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 32cb739535..88fa385f9c 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -660,8 +660,7 @@ typedef struct { int32_t tz; // query client timezone char intervalUnit; char slidingUnit; - char - offsetUnit; // TODO Remove it, the offset is the number of precision tickle, and it must be a immutable duration. + char offsetUnit; int8_t precision; int64_t interval; int64_t sliding; diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index f77b80c533..2215d0035d 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -1031,8 +1031,9 @@ static void destroySysScanOperator(void* param, int32_t numOfOutput) { blockDataDestroy(pInfo->pRes); const char* name = tNameGetTableName(&pInfo->name); - if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0) { + if (strncasecmp(name, TSDB_INS_TABLE_USER_TABLES, TSDB_TABLE_FNAME_LEN) == 0 || pInfo->pCur != NULL) { metaCloseTbCursor(pInfo->pCur); + pInfo->pCur = NULL; } taosArrayDestroy(pInfo->scanCols); From bf8bbfbfbb03cfed83a2ffc25acae6f6f4ee6d00 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 25 May 2022 10:30:02 +0800 Subject: [PATCH 09/32] refactor: mnode sync --- source/common/src/systable.c | 1 - source/dnode/mnode/impl/src/mndMnode.c | 5 +---- source/dnode/mnode/impl/src/mndSync.c | 6 ++++-- source/dnode/mnode/impl/src/mndTrans.c | 4 ++-- source/dnode/mnode/impl/src/mnode.c | 8 ++++---- source/os/src/osSocket.c | 6 +++--- 6 files changed, 14 insertions(+), 16 deletions(-) diff --git a/source/common/src/systable.c b/source/common/src/systable.c index 9fe7645e2b..5e1405e0c6 100644 --- a/source/common/src/systable.c +++ b/source/common/src/systable.c @@ -36,7 +36,6 @@ static const SSysDbTableSchema mnodesSchema[] = { {.name = "id", .bytes = 4, .type = TSDB_DATA_TYPE_INT}, {.name = "endpoint", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, {.name = "role", .bytes = 12 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_VARCHAR}, - {.name = "role_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, {.name = "create_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP}, }; diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 414b0466bb..ede021faee 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -652,16 +652,13 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, b1, false); - const char *roles = syncStr(pObj->role); + const char *roles = syncStr(syncGetMyRole(pMnode->syncMgmt.sync)); char *b2 = taosMemoryCalloc(1, 12 + VARSTR_HEADER_SIZE); STR_WITH_MAXSIZE_TO_VARSTR(b2, roles, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)b2, false); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); - colDataAppend(pColInfo, numOfRows, (const char *)&pObj->roleTime, false); - pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, (const char *)&pObj->createdTime, false); diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 3ac7c3713f..231cecf58e 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -49,8 +49,10 @@ int32_t mndSyncGetSnapshot(struct SSyncFSM *pFsm, SSnapshot *pSnapshot) { void mndRestoreFinish(struct SSyncFSM *pFsm) { SMnode *pMnode = pFsm->data; - mndTransPullup(pMnode); - pMnode->syncMgmt.restored = true; + if (!pMnode->deploy) { + mndTransPullup(pMnode); + pMnode->syncMgmt.restored = true; + } } void *mndSnapshotRead(struct SSyncFSM *pFsm, const SSnapshot *snapshot, void *iter, char **ppBuf, int32_t *len) { diff --git a/source/dnode/mnode/impl/src/mndTrans.c b/source/dnode/mnode/impl/src/mndTrans.c index 31fb12a0a2..444c4bb619 100644 --- a/source/dnode/mnode/impl/src/mndTrans.c +++ b/source/dnode/mnode/impl/src/mndTrans.c @@ -1080,7 +1080,7 @@ static bool mndTransPerformRedoLogStage(SMnode *pMnode, STrans *pTrans) { } static bool mndTransPerformRedoActionStage(SMnode *pMnode, STrans *pTrans) { - if (!mndIsMaster(pMnode)) return false; + if (!pMnode->deploy && !mndIsMaster(pMnode)) return false; bool continueExec = true; int32_t code = mndTransExecuteRedoActions(pMnode, pTrans); @@ -1171,7 +1171,7 @@ static bool mndTransPerformUndoLogStage(SMnode *pMnode, STrans *pTrans) { } static bool mndTransPerformUndoActionStage(SMnode *pMnode, STrans *pTrans) { - if (!mndIsMaster(pMnode)) return false; + if (!pMnode->deploy && !mndIsMaster(pMnode)) return false; bool continueExec = true; int32_t code = mndTransExecuteUndoActions(pMnode, pTrans); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 4f1b99959f..9d2a2fd2e8 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -335,8 +335,9 @@ void mndClose(SMnode *pMnode) { int32_t mndStart(SMnode *pMnode) { mndSyncStart(pMnode); - if (pMnode->deploy && sdbDeploy(pMnode->pSdb) != 0) { - return -1; + if (pMnode->deploy) { + if (sdbDeploy(pMnode->pSdb) != 0) return -1; + pMnode->syncMgmt.restored = true; } return mndInitTimer(pMnode); } @@ -414,8 +415,7 @@ int32_t mndProcessMsg(SRpcMsg *pMsg) { mTrace("msg:%p, will be processed, type:%s app:%p", pMsg, TMSG_INFO(pMsg->msgType), ahandle); if (IsReq(pMsg)) { - if (!mndIsMaster(pMnode) && pMsg->msgType != TDMT_MND_TRANS_TIMER && pMsg->msgType != TDMT_MND_MQ_TIMER && - pMsg->msgType != TDMT_MND_TELEM_TIMER) { + if (!mndIsMaster(pMnode)) { terrno = TSDB_CODE_APP_NOT_READY; mDebug("msg:%p, failed to process since %s, app:%p", pMsg, terrstr(), ahandle); return -1; diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index 572e2db6fd..35a953fc5c 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -913,12 +913,12 @@ uint32_t taosGetIpv4FromFqdn(const char *fqdn) { } else { #ifdef EAI_SYSTEM if (ret == EAI_SYSTEM) { - printf("failed to get the ip address, fqdn:%s, errno:%d, since:%s", fqdn, errno, strerror(errno)); + // printf("failed to get the ip address, fqdn:%s, errno:%d, since:%s", fqdn, errno, strerror(errno)); } else { - printf("failed to get the ip address, fqdn:%s, ret:%d, since:%s", fqdn, ret, gai_strerror(ret)); + // printf("failed to get the ip address, fqdn:%s, ret:%d, since:%s", fqdn, ret, gai_strerror(ret)); } #else - printf("failed to get the ip address, fqdn:%s, ret:%d, since:%s", fqdn, ret, gai_strerror(ret)); + // printf("failed to get the ip address, fqdn:%s, ret:%d, since:%s", fqdn, ret, gai_strerror(ret)); #endif return 0xFFFFFFFF; } From 3c80623ca55f4e139cfb0c6629199978b717d652 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 25 May 2022 10:50:26 +0800 Subject: [PATCH 10/32] fix: several use cases after trans tweak --- tests/script/tsim/dnode/basic1.sim | 6 ++---- tests/script/tsim/trans/create_db.sim | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/script/tsim/dnode/basic1.sim b/tests/script/tsim/dnode/basic1.sim index d49dba60f3..d5c791e902 100644 --- a/tests/script/tsim/dnode/basic1.sim +++ b/tests/script/tsim/dnode/basic1.sim @@ -7,6 +7,7 @@ sql connect print =============== show dnodes sql show dnodes; +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] if $rows != 1 then return -1 endi @@ -15,12 +16,9 @@ if $data00 != 1 then return -1 endi -# check 'vnodes' feild ? -#if $data02 != 0 then -# return -1 -#endi sql show mnodes; +print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] if $rows != 1 then return -1 endi diff --git a/tests/script/tsim/trans/create_db.sim b/tests/script/tsim/trans/create_db.sim index 0db5add88a..65dd72184c 100644 --- a/tests/script/tsim/trans/create_db.sim +++ b/tests/script/tsim/trans/create_db.sim @@ -64,7 +64,7 @@ if $rows != 1 then return -1 endi -if $data[0][0] != 2 then +if $data[0][0] != 5 then return -1 endi @@ -114,7 +114,7 @@ if $rows != 1 then return -1 endi -if $data[0][0] != 4 then +if $data[0][0] != 7 then return -1 endi @@ -137,7 +137,7 @@ endi sql_error create database d2 vgroups 2; print =============== kill transaction -sql kill transaction 4; +sql kill transaction 7; sleep 2000 sql show transactions From 229cb7b7d95551c769fa9be4fcb96effce56253f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 25 May 2022 12:13:36 +0800 Subject: [PATCH 11/32] refactor: sdb header --- source/dnode/mnode/sdb/CMakeLists.txt | 3 +- .../sdb => source/dnode/mnode/sdb/inc}/sdb.h | 98 ++++++++++++------- source/dnode/mnode/sdb/src/sdb.c | 2 +- source/dnode/mnode/sdb/src/sdbFile.c | 2 +- source/dnode/mnode/sdb/src/sdbHash.c | 2 +- source/dnode/mnode/sdb/src/sdbRaw.c | 2 +- source/dnode/mnode/sdb/src/sdbRow.c | 2 +- tests/script/jenkins/basic.txt | 3 +- tests/test/c/sdbDump.c | 2 +- 9 files changed, 72 insertions(+), 44 deletions(-) rename {include/dnode/mnode/sdb => source/dnode/mnode/sdb/inc}/sdb.h (89%) diff --git a/source/dnode/mnode/sdb/CMakeLists.txt b/source/dnode/mnode/sdb/CMakeLists.txt index e2ebed7a78..2001a70da2 100644 --- a/source/dnode/mnode/sdb/CMakeLists.txt +++ b/source/dnode/mnode/sdb/CMakeLists.txt @@ -2,8 +2,7 @@ aux_source_directory(src MNODE_SRC) add_library(sdb STATIC ${MNODE_SRC}) target_include_directories( sdb - PUBLIC "${TD_SOURCE_DIR}/include/dnode/mnode/sdb" - PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc" + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc" ) target_link_libraries( sdb os common util wal diff --git a/include/dnode/mnode/sdb/sdb.h b/source/dnode/mnode/sdb/inc/sdb.h similarity index 89% rename from include/dnode/mnode/sdb/sdb.h rename to source/dnode/mnode/sdb/inc/sdb.h index a9e2f5a71a..3d9148360a 100644 --- a/include/dnode/mnode/sdb/sdb.h +++ b/source/dnode/mnode/sdb/inc/sdb.h @@ -27,6 +27,15 @@ extern "C" { #endif +// clang-format off +#define mFatal(...) { if (mDebugFlag & DEBUG_FATAL) { taosPrintLog("MND FATAL ", DEBUG_FATAL, 255, __VA_ARGS__); }} +#define mError(...) { if (mDebugFlag & DEBUG_ERROR) { taosPrintLog("MND ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); }} +#define mWarn(...) { if (mDebugFlag & DEBUG_WARN) { taosPrintLog("MND WARN ", DEBUG_WARN, 255, __VA_ARGS__); }} +#define mInfo(...) { if (mDebugFlag & DEBUG_INFO) { taosPrintLog("MND ", DEBUG_INFO, 255, __VA_ARGS__); }} +#define mDebug(...) { if (mDebugFlag & DEBUG_DEBUG) { taosPrintLog("MND ", DEBUG_DEBUG, mDebugFlag, __VA_ARGS__); }} +#define mTrace(...) { if (mDebugFlag & DEBUG_TRACE) { taosPrintLog("MND ", DEBUG_TRACE, mDebugFlag, __VA_ARGS__); }} +// clang-format on + #define SDB_GET_VAL(pData, dataPos, val, pos, func, type) \ { \ if (func(pRaw, dataPos, val) != 0) { \ @@ -65,7 +74,7 @@ extern "C" { #define SDB_SET_INT64(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt64, int64_t) #define SDB_SET_INT32(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt32, int32_t) #define SDB_SET_INT16(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt16, int16_t) -#define SDB_SET_INT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt8, int8_t) +#define SDB_SET_INT8(pRaw, dataPos, val, pos) SDB_SET_VAL(pRaw, dataPos, val, pos, sdbSetRawInt8, int8_t) #define SDB_SET_BINARY(pRaw, dataPos, val, valLen, pos) \ { \ @@ -89,8 +98,16 @@ extern "C" { } typedef struct SMnode SMnode; +typedef struct SSdb SSdb; typedef struct SSdbRaw SSdbRaw; typedef struct SSdbRow SSdbRow; +typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj); +typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj); +typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj, bool callFunc); +typedef int32_t (*SdbDeployFp)(SMnode *pMnode); +typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw); +typedef SSdbRaw *(*SdbEncodeFp)(void *pObj); +typedef bool (*sdbTraverseFp)(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3); typedef enum { SDB_KEY_BINARY = 1, @@ -130,14 +147,47 @@ typedef enum { SDB_MAX = 20 } ESdbType; -typedef struct SSdb SSdb; -typedef int32_t (*SdbInsertFp)(SSdb *pSdb, void *pObj); -typedef int32_t (*SdbUpdateFp)(SSdb *pSdb, void *pSrcObj, void *pDstObj); -typedef int32_t (*SdbDeleteFp)(SSdb *pSdb, void *pObj, bool callFunc); -typedef int32_t (*SdbDeployFp)(SMnode *pMnode); -typedef SSdbRow *(*SdbDecodeFp)(SSdbRaw *pRaw); -typedef SSdbRaw *(*SdbEncodeFp)(void *pObj); -typedef bool (*sdbTraverseFp)(SMnode *pMnode, void *pObj, void *p1, void *p2, void *p3); +typedef struct SSdbRaw { + int8_t type; + int8_t status; + int8_t sver; + int8_t reserved; + int32_t dataLen; + char pData[]; +} SSdbRaw; + +typedef struct SSdbRow { + ESdbType type; + ESdbStatus status; + int32_t refCount; + char pObj[]; +} SSdbRow; + +typedef struct SSdb { + SMnode *pMnode; + char *currDir; + char *syncDir; + char *tmpDir; + int64_t lastCommitVer; + int64_t curVer; + int64_t curTerm; + int64_t tableVer[SDB_MAX]; + int64_t maxId[SDB_MAX]; + EKeyType keyTypes[SDB_MAX]; + SHashObj *hashObjs[SDB_MAX]; + TdThreadRwlock locks[SDB_MAX]; + SdbInsertFp insertFps[SDB_MAX]; + SdbUpdateFp updateFps[SDB_MAX]; + SdbDeleteFp deleteFps[SDB_MAX]; + SdbDeployFp deployFps[SDB_MAX]; + SdbEncodeFp encodeFps[SDB_MAX]; + SdbDecodeFp decodeFps[SDB_MAX]; +} SSdb; + +typedef struct SSdbIter { + TdFilePtr file; + int64_t readlen; +} SSdbIter; typedef struct { ESdbType sdbType; @@ -328,36 +378,14 @@ int32_t sdbGetRawTotalSize(SSdbRaw *pRaw); SSdbRow *sdbAllocRow(int32_t objSize); void *sdbGetRowObj(SSdbRow *pRow); - -typedef struct SSdb { - SMnode *pMnode; - char *currDir; - char *syncDir; - char *tmpDir; - int64_t lastCommitVer; - int64_t curVer; - int64_t curTerm; - int64_t tableVer[SDB_MAX]; - int64_t maxId[SDB_MAX]; - EKeyType keyTypes[SDB_MAX]; - SHashObj *hashObjs[SDB_MAX]; - TdThreadRwlock locks[SDB_MAX]; - SdbInsertFp insertFps[SDB_MAX]; - SdbUpdateFp updateFps[SDB_MAX]; - SdbDeleteFp deleteFps[SDB_MAX]; - SdbDeployFp deployFps[SDB_MAX]; - SdbEncodeFp encodeFps[SDB_MAX]; - SdbDecodeFp decodeFps[SDB_MAX]; -} SSdb; - -typedef struct SSdbIter { - TdFilePtr file; - int64_t readlen; -} SSdbIter; +void sdbFreeRow(SSdb *pSdb, SSdbRow *pRow, bool callFunc); SSdbIter *sdbIterInit(SSdb *pSdb); SSdbIter *sdbIterRead(SSdb *pSdb, SSdbIter *iter, char **ppBuf, int32_t *len); +const char *sdbTableName(ESdbType type); +void sdbPrintOper(SSdb *pSdb, SSdbRow *pRow, const char *oper); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/sdb/src/sdb.c b/source/dnode/mnode/sdb/src/sdb.c index 7b90d8acb5..d289e30d7b 100644 --- a/source/dnode/mnode/sdb/src/sdb.c +++ b/source/dnode/mnode/sdb/src/sdb.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "sdbInt.h" +#include "sdb.h" static int32_t sdbCreateDir(SSdb *pSdb); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index eac7f4af5d..25cda19956 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "sdbInt.h" +#include "sdb.h" #include "tchecksum.h" #include "wal.h" diff --git a/source/dnode/mnode/sdb/src/sdbHash.c b/source/dnode/mnode/sdb/src/sdbHash.c index a25c7a5233..abf35b71a9 100644 --- a/source/dnode/mnode/sdb/src/sdbHash.c +++ b/source/dnode/mnode/sdb/src/sdbHash.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "sdbInt.h" +#include "sdb.h" static void sdbCheckRow(SSdb *pSdb, SSdbRow *pRow); diff --git a/source/dnode/mnode/sdb/src/sdbRaw.c b/source/dnode/mnode/sdb/src/sdbRaw.c index fd2f20c242..ba3b00c12d 100644 --- a/source/dnode/mnode/sdb/src/sdbRaw.c +++ b/source/dnode/mnode/sdb/src/sdbRaw.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "sdbInt.h" +#include "sdb.h" SSdbRaw *sdbAllocRaw(ESdbType type, int8_t sver, int32_t dataLen) { SSdbRaw *pRaw = taosMemoryCalloc(1, dataLen + sizeof(SSdbRaw)); diff --git a/source/dnode/mnode/sdb/src/sdbRow.c b/source/dnode/mnode/sdb/src/sdbRow.c index 43f70cb245..e57a6b028b 100644 --- a/source/dnode/mnode/sdb/src/sdbRow.c +++ b/source/dnode/mnode/sdb/src/sdbRow.c @@ -14,7 +14,7 @@ */ #define _DEFAULT_SOURCE -#include "sdbInt.h" +#include "sdb.h" SSdbRow *sdbAllocRow(int32_t objSize) { SSdbRow *pRow = taosMemoryCalloc(1, objSize + sizeof(SSdbRow)); diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 7aaf1e1eca..7f32407b29 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -94,7 +94,8 @@ ./test.sh -f tsim/stable/values.sim ./test.sh -f tsim/stable/vnode3.sim ./test.sh -f tsim/stable/column_add.sim -./test.sh -f tsim/stable/column_drop.sim +#./test.sh -f tsim/stable/column_drop.sim +#./test.sh -f tsim/stable/column_modify.sim # --- for multi process mode diff --git a/tests/test/c/sdbDump.c b/tests/test/c/sdbDump.c index 1d3eba7cde..2a19ae778f 100644 --- a/tests/test/c/sdbDump.c +++ b/tests/test/c/sdbDump.c @@ -16,7 +16,7 @@ #define _DEFAULT_SOURCE #include "dmMgmt.h" #include "mndInt.h" -#include "sdbInt.h" +#include "sdb.h" #include "tconfig.h" #include "tjson.h" From 7ee2e5a37fc5f1e4f249e3c4995b4bbe23c7baf9 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 25 May 2022 12:54:49 +0800 Subject: [PATCH 12/32] refactor: let all operations of mnode into the sync log --- source/dnode/mnode/impl/inc/mndDef.h | 49 +++++++++-------- source/dnode/mnode/impl/src/mndAcct.c | 70 +++++++++++++++++------- source/dnode/mnode/impl/src/mndCluster.c | 26 +++++++++ tests/script/tsim/mnode/basic2.sim | 44 +++------------ tests/script/tsim/trans/create_db.sim | 6 +- 5 files changed, 114 insertions(+), 81 deletions(-) diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 81f4c5ed1e..432b95059d 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -67,30 +67,33 @@ typedef enum { typedef enum { TRN_TYPE_BASIC_SCOPE = 1000, - TRN_TYPE_CREATE_USER = 1001, - TRN_TYPE_ALTER_USER = 1002, - TRN_TYPE_DROP_USER = 1003, - TRN_TYPE_CREATE_FUNC = 1004, - TRN_TYPE_DROP_FUNC = 1005, + TRN_TYPE_CREATE_ACCT = 1001, + TRN_TYPE_CREATE_CLUSTER = 1002, + TRN_TYPE_CREATE_USER = 1003, + TRN_TYPE_ALTER_USER = 1004, + TRN_TYPE_DROP_USER = 1005, + TRN_TYPE_CREATE_FUNC = 1006, + TRN_TYPE_DROP_FUNC = 1007, - TRN_TYPE_CREATE_SNODE = 1006, - TRN_TYPE_DROP_SNODE = 1007, - TRN_TYPE_CREATE_QNODE = 1008, - TRN_TYPE_DROP_QNODE = 1009, - TRN_TYPE_CREATE_BNODE = 1010, - TRN_TYPE_DROP_BNODE = 1011, - TRN_TYPE_CREATE_MNODE = 1012, - TRN_TYPE_DROP_MNODE = 1013, - TRN_TYPE_CREATE_TOPIC = 1014, - TRN_TYPE_DROP_TOPIC = 1015, - TRN_TYPE_SUBSCRIBE = 1016, - TRN_TYPE_REBALANCE = 1017, - TRN_TYPE_COMMIT_OFFSET = 1018, - TRN_TYPE_CREATE_STREAM = 1019, - TRN_TYPE_DROP_STREAM = 1020, - TRN_TYPE_ALTER_STREAM = 1021, - TRN_TYPE_CONSUMER_LOST = 1022, - TRN_TYPE_CONSUMER_RECOVER = 1023, + TRN_TYPE_CREATE_SNODE = 1010, + TRN_TYPE_DROP_SNODE = 1011, + TRN_TYPE_CREATE_QNODE = 1012, + TRN_TYPE_DROP_QNODE = 10013, + TRN_TYPE_CREATE_BNODE = 1014, + TRN_TYPE_DROP_BNODE = 1015, + TRN_TYPE_CREATE_MNODE = 1016, + TRN_TYPE_DROP_MNODE = 1017, + + TRN_TYPE_CREATE_TOPIC = 1020, + TRN_TYPE_DROP_TOPIC = 1021, + TRN_TYPE_SUBSCRIBE = 1022, + TRN_TYPE_REBALANCE = 1023, + TRN_TYPE_COMMIT_OFFSET = 1024, + TRN_TYPE_CREATE_STREAM = 1025, + TRN_TYPE_DROP_STREAM = 1026, + TRN_TYPE_ALTER_STREAM = 1027, + TRN_TYPE_CONSUMER_LOST = 1028, + TRN_TYPE_CONSUMER_RECOVER = 1029, TRN_TYPE_BASIC_SCOPE_END, TRN_TYPE_GLOBAL_SCOPE = 2000, diff --git a/source/dnode/mnode/impl/src/mndAcct.c b/source/dnode/mnode/impl/src/mndAcct.c index 52b9ac62e6..a4fde4b706 100644 --- a/source/dnode/mnode/impl/src/mndAcct.c +++ b/source/dnode/mnode/impl/src/mndAcct.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "mndAcct.h" #include "mndShow.h" +#include "mndTrans.h" #define ACCT_VER_NUMBER 1 #define ACCT_RESERVE_SIZE 128 @@ -31,14 +32,16 @@ static int32_t mndProcessAlterAcctReq(SRpcMsg *pReq); static int32_t mndProcessDropAcctReq(SRpcMsg *pReq); int32_t mndInitAcct(SMnode *pMnode) { - SSdbTable table = {.sdbType = SDB_ACCT, - .keyType = SDB_KEY_BINARY, - .deployFp = mndCreateDefaultAcct, - .encodeFp = (SdbEncodeFp)mndAcctActionEncode, - .decodeFp = (SdbDecodeFp)mndAcctActionDecode, - .insertFp = (SdbInsertFp)mndAcctActionInsert, - .updateFp = (SdbUpdateFp)mndAcctActionUpdate, - .deleteFp = (SdbDeleteFp)mndAcctActionDelete}; + SSdbTable table = { + .sdbType = SDB_ACCT, + .keyType = SDB_KEY_BINARY, + .deployFp = mndCreateDefaultAcct, + .encodeFp = (SdbEncodeFp)mndAcctActionEncode, + .decodeFp = (SdbDecodeFp)mndAcctActionDecode, + .insertFp = (SdbInsertFp)mndAcctActionInsert, + .updateFp = (SdbUpdateFp)mndAcctActionUpdate, + .deleteFp = (SdbDeleteFp)mndAcctActionDelete, + }; mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ACCT, mndProcessCreateAcctReq); mndSetMsgHandle(pMnode, TDMT_MND_ALTER_ACCT, mndProcessAlterAcctReq); @@ -56,25 +59,52 @@ static int32_t mndCreateDefaultAcct(SMnode *pMnode) { acctObj.updateTime = acctObj.createdTime; acctObj.acctId = 1; acctObj.status = 0; - acctObj.cfg = (SAcctCfg){.maxUsers = INT32_MAX, - .maxDbs = INT32_MAX, - .maxStbs = INT32_MAX, - .maxTbs = INT32_MAX, - .maxTimeSeries = INT32_MAX, - .maxStreams = INT32_MAX, - .maxFuncs = INT32_MAX, - .maxConsumers = INT32_MAX, - .maxConns = INT32_MAX, - .maxTopics = INT32_MAX, - .maxStorage = INT64_MAX, - .accessState = TSDB_VN_ALL_ACCCESS}; + acctObj.cfg = (SAcctCfg){ + .maxUsers = INT32_MAX, + .maxDbs = INT32_MAX, + .maxStbs = INT32_MAX, + .maxTbs = INT32_MAX, + .maxTimeSeries = INT32_MAX, + .maxStreams = INT32_MAX, + .maxFuncs = INT32_MAX, + .maxConsumers = INT32_MAX, + .maxConns = INT32_MAX, + .maxTopics = INT32_MAX, + .maxStorage = INT64_MAX, + .accessState = TSDB_VN_ALL_ACCCESS, + }; SSdbRaw *pRaw = mndAcctActionEncode(&acctObj); if (pRaw == NULL) return -1; sdbSetRawStatus(pRaw, SDB_STATUS_READY); mDebug("acct:%s, will be created while deploy sdb, raw:%p", acctObj.acct, pRaw); +#if 0 return sdbWrite(pMnode->pSdb, pRaw); +#else + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_ACCT, NULL); + if (pTrans == NULL) { + mError("acct:%s, failed to create since %s", acctObj.acct, terrstr()); + return -1; + } + mDebug("trans:%d, used to create acct:%s", pTrans->id, acctObj.acct); + + if (mndTransAppendCommitlog(pTrans, pRaw) != 0) { + mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + + mndTransDrop(pTrans); + return 0; +#endif } static SSdbRaw *mndAcctActionEncode(SAcctObj *pAcct) { diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index f6f6813b97..6266f22f39 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -16,6 +16,7 @@ #define _DEFAULT_SOURCE #include "mndCluster.h" #include "mndShow.h" +#include "mndTrans.h" #define CLUSTER_VER_NUMBE 1 #define CLUSTER_RESERVE_SIZE 64 @@ -177,7 +178,32 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { sdbSetRawStatus(pRaw, SDB_STATUS_READY); mDebug("cluster:%" PRId64 ", will be created while deploy sdb, raw:%p", clusterObj.id, pRaw); +#if 0 return sdbWrite(pMnode->pSdb, pRaw); +#else + STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_TYPE_CREATE_CLUSTER, NULL); + if (pTrans == NULL) { + mError("cluster:%" PRId64 ", failed to create since %s", clusterObj.id, terrstr()); + return -1; + } + mDebug("trans:%d, used to create cluster:%" PRId64, pTrans->id, clusterObj.id); + + if (mndTransAppendCommitlog(pTrans, pRaw) != 0) { + mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + sdbSetRawStatus(pRaw, SDB_STATUS_READY); + + if (mndTransPrepare(pMnode, pTrans) != 0) { + mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr()); + mndTransDrop(pTrans); + return -1; + } + + mndTransDrop(pTrans); + return 0; +#endif } static int32_t mndRetrieveClusters(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) { diff --git a/tests/script/tsim/mnode/basic2.sim b/tests/script/tsim/mnode/basic2.sim index 53dea6821e..c24d7fc6f7 100644 --- a/tests/script/tsim/mnode/basic2.sim +++ b/tests/script/tsim/mnode/basic2.sim @@ -6,15 +6,6 @@ system sh/exec.sh -n dnode2 -s start sql connect print =============== show dnodes -sql show dnodes; -if $rows != 1 then - return -1 -endi - -if $data00 != 1 then - return -1 -endi - sql show mnodes; if $rows != 1 then return -1 @@ -30,35 +21,11 @@ endi print =============== create dnodes sql create dnode $hostname port 7200 +sql create dnode $hostname port 7300 sleep 2000 sql show dnodes; -if $rows != 2 then - return -1 -endi - -if $data00 != 1 then - return -1 -endi - -if $data10 != 2 then - return -1 -endi - -print $data02 -if $data02 != 0 then - return -1 -endi - -if $data12 != 0 then - return -1 -endi - -if $data04 != ready then - return -1 -endi - -if $data14 != ready then +if $rows != 3 then return -1 endi @@ -82,3 +49,10 @@ if $rows != 2 then return -1 endi +return +sql create mnode on dnode 3 +sql show mnodes +if $rows != 3 then + return -1 +endi + diff --git a/tests/script/tsim/trans/create_db.sim b/tests/script/tsim/trans/create_db.sim index 65dd72184c..ae6b7eab16 100644 --- a/tests/script/tsim/trans/create_db.sim +++ b/tests/script/tsim/trans/create_db.sim @@ -64,7 +64,7 @@ if $rows != 1 then return -1 endi -if $data[0][0] != 5 then +if $data[0][0] != 7 then return -1 endi @@ -114,7 +114,7 @@ if $rows != 1 then return -1 endi -if $data[0][0] != 7 then +if $data[0][0] != 9 then return -1 endi @@ -137,7 +137,7 @@ endi sql_error create database d2 vgroups 2; print =============== kill transaction -sql kill transaction 7; +sql kill transaction 9; sleep 2000 sql show transactions From 81d0798f5f801043ebb489f487b4761b119c5dad Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 25 May 2022 14:27:59 +0800 Subject: [PATCH 13/32] refactor: update config when there's one locally --- source/libs/sync/src/syncMain.c | 20 ++++++++++++++++++-- source/libs/sync/test/syncTest.cpp | 10 +++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index 4aca68fa64..d128ed48b4 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -349,7 +349,9 @@ int32_t syncPropose(int64_t rid, const SRpcMsg* pMsg, bool isWeak) { } // open/close -------------- -SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { +SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { + SSyncInfo* pSyncInfo = (SSyncInfo*)pOldSyncInfo; + SSyncNode* pSyncNode = (SSyncNode*)taosMemoryMalloc(sizeof(SSyncNode)); assert(pSyncNode != NULL); memset(pSyncNode, 0, sizeof(SSyncNode)); @@ -361,11 +363,25 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) { sError("failed to create dir:%s since %s", pSyncInfo->path, terrstr()); return NULL; } + } + snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s/raft_config.json", pSyncInfo->path); + if (!taosCheckExistFile(pSyncNode->configPath)) { // create raft config file - snprintf(pSyncNode->configPath, sizeof(pSyncNode->configPath), "%s/raft_config.json", pSyncInfo->path); ret = syncCfgCreateFile((SSyncCfg*)&(pSyncInfo->syncCfg), pSyncNode->configPath); assert(ret == 0); + + } else { + // update syncCfg by raft_config.json + pSyncNode->pRaftCfg = raftCfgOpen(pSyncNode->configPath); + assert(pSyncNode->pRaftCfg != NULL); + pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg; + + char *seralized = raftCfg2Str(pSyncNode->pRaftCfg); + sInfo("syncNodeOpen update config :%s", seralized); + taosMemoryFree(seralized); + + raftCfgClose(pSyncNode->pRaftCfg); } // init by SSyncInfo diff --git a/source/libs/sync/test/syncTest.cpp b/source/libs/sync/test/syncTest.cpp index 76024e061e..5d205d8efe 100644 --- a/source/libs/sync/test/syncTest.cpp +++ b/source/libs/sync/test/syncTest.cpp @@ -49,7 +49,7 @@ void test4() { logTest((char*)__FUNCTION__); } -int main() { +int main(int argc, char **argv) { // taosInitLog("tmp/syncTest.log", 100); tsAsyncLog = 0; @@ -58,6 +58,14 @@ int main() { test3(); test4(); + if (argc == 2) { + bool bTaosDirExist = taosDirExist(argv[1]); + printf("%s bTaosDirExist:%d \n", argv[1], bTaosDirExist); + + bool bTaosCheckExistFile = taosCheckExistFile(argv[1]); + printf("%s bTaosCheckExistFile:%d \n", argv[1], bTaosCheckExistFile); + } + // taosCloseLog(); return 0; } From aa7a1a77505f338abd61eed9809e108a4946d50b Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 25 May 2022 06:38:13 +0000 Subject: [PATCH 14/32] make compile --- source/dnode/vnode/src/vnd/vnodeSnapshot.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/dnode/vnode/src/vnd/vnodeSnapshot.c b/source/dnode/vnode/src/vnd/vnodeSnapshot.c index 5e451e4142..baa8422307 100644 --- a/source/dnode/vnode/src/vnd/vnodeSnapshot.c +++ b/source/dnode/vnode/src/vnd/vnodeSnapshot.c @@ -75,7 +75,7 @@ int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32 int32_t code = 0; if (!pReader->isMetaEnd) { - code = metaSnapshotRead(pReader->pMetaReader, &pReader->pData, &pReader->pData); + code = metaSnapshotRead(pReader->pMetaReader, &pReader->pData, &pReader->nData); if (code) { if (code == TSDB_CODE_VND_READ_END) { pReader->isMetaEnd = 1; @@ -90,7 +90,7 @@ int32_t vnodeSnapshotRead(SVSnapshotReader *pReader, const void **ppData, uint32 } if (!pReader->isTsdbEnd) { - code = tsdbSnapshotRead(pReader->pTsdbReader, &pReader->pData, pReader->nData); + code = tsdbSnapshotRead(pReader->pTsdbReader, &pReader->pData, &pReader->nData); if (code) { if (code == TSDB_CODE_VND_READ_END) { pReader->isTsdbEnd = 1; From 104a20757957d077412180b528453b2dd64e7c8d Mon Sep 17 00:00:00 2001 From: Minghao Li Date: Wed, 25 May 2022 14:43:45 +0800 Subject: [PATCH 15/32] FpReConfigCb --- include/libs/sync/sync.h | 9 +++++---- source/dnode/mnode/impl/src/mndSync.c | 1 + source/libs/sync/src/syncAppendEntries.c | 10 ++++++++++ source/libs/sync/src/syncCommit.c | 10 ++++++++++ source/libs/sync/src/syncMain.c | 2 +- source/libs/sync/test/syncTest.cpp | 2 +- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 4ac4922e80..b14b7667d2 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -99,14 +99,15 @@ typedef struct SSyncFSM { void (*FpRestoreFinishCb)(struct SSyncFSM* pFsm); int32_t (*FpGetSnapshot)(struct SSyncFSM* pFsm, SSnapshot* pSnapshot); - // if (*ppIter == NULL) + // if (*ppIter == NULL) // *ppIter = new iter; - // else + // else // *ppIter.next(); // // if success, return 0. else return error code - int32_t (*FpSnapshotRead)(struct SSyncFSM* pFsm, const SSnapshot* pSnapshot, void** ppIter, char** ppBuf, int32_t* len); - + int32_t (*FpSnapshotRead)(struct SSyncFSM* pFsm, const SSnapshot* pSnapshot, void** ppIter, char** ppBuf, + int32_t* len); + // apply data into fsm int32_t (*FpSnapshotApply)(struct SSyncFSM* pFsm, const SSnapshot* pSnapshot, char* pBuf, int32_t len); diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index f127991c46..50425761ba 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -74,6 +74,7 @@ int32_t mndSnapshotApply(struct SSyncFSM* pFsm, const SSnapshot* pSnapshot, char } void mndReConfig(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) { + mInfo("mndReConfig cbMeta.code:%d, cbMeta.currentTerm:%ld, cbMeta.term:%ld, cbMeta.index:%ld", cbMeta.code, cbMeta.currentTerm, cbMeta.term, cbMeta.index); if (cbMeta.code == 0) { // config change success } else { diff --git a/source/libs/sync/src/syncAppendEntries.c b/source/libs/sync/src/syncAppendEntries.c index 0411628c5c..c9e16c53c8 100644 --- a/source/libs/sync/src/syncAppendEntries.c +++ b/source/libs/sync/src/syncAppendEntries.c @@ -357,6 +357,16 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) { } else { syncNodeBecomeFollower(ths); } + + // maybe newSyncCfg.myIndex is updated in syncNodeUpdateConfig + if (ths->pFsm->FpReConfigCb != NULL) { + SReConfigCbMeta cbMeta = {0}; + cbMeta.code = 0; + cbMeta.currentTerm = ths->pRaftStore->currentTerm; + cbMeta.index = pEntry->index; + cbMeta.term = pEntry->term; + ths->pFsm->FpReConfigCb(ths->pFsm, newSyncCfg, cbMeta); + } } // restore finish diff --git a/source/libs/sync/src/syncCommit.c b/source/libs/sync/src/syncCommit.c index 36713ceed5..a3d480956e 100644 --- a/source/libs/sync/src/syncCommit.c +++ b/source/libs/sync/src/syncCommit.c @@ -134,6 +134,16 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) { } else { syncNodeBecomeFollower(pSyncNode); } + + // maybe newSyncCfg.myIndex is updated in syncNodeUpdateConfig + if (pSyncNode->pFsm->FpReConfigCb != NULL) { + SReConfigCbMeta cbMeta = {0}; + cbMeta.code = 0; + cbMeta.currentTerm = pSyncNode->pRaftStore->currentTerm; + cbMeta.index = pEntry->index; + cbMeta.term = pEntry->term; + pSyncNode->pFsm->FpReConfigCb(pSyncNode->pFsm, newSyncCfg, cbMeta); + } } // restore finish diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index d128ed48b4..e4b6fc215f 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -377,7 +377,7 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pOldSyncInfo) { assert(pSyncNode->pRaftCfg != NULL); pSyncInfo->syncCfg = pSyncNode->pRaftCfg->cfg; - char *seralized = raftCfg2Str(pSyncNode->pRaftCfg); + char* seralized = raftCfg2Str(pSyncNode->pRaftCfg); sInfo("syncNodeOpen update config :%s", seralized); taosMemoryFree(seralized); diff --git a/source/libs/sync/test/syncTest.cpp b/source/libs/sync/test/syncTest.cpp index 5d205d8efe..ffe8b81571 100644 --- a/source/libs/sync/test/syncTest.cpp +++ b/source/libs/sync/test/syncTest.cpp @@ -49,7 +49,7 @@ void test4() { logTest((char*)__FUNCTION__); } -int main(int argc, char **argv) { +int main(int argc, char** argv) { // taosInitLog("tmp/syncTest.log", 100); tsAsyncLog = 0; From 3a36979576a35119029f57ac40a5d642fb8942ef Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 25 May 2022 14:49:08 +0800 Subject: [PATCH 16/32] refactor: let all operations of mnode into the sync log --- include/util/tlog.h | 1 + source/dnode/mnode/impl/src/mndMnode.c | 8 +++- source/dnode/mnode/impl/src/mnode.c | 5 ++- source/libs/monitor/src/monMain.c | 3 +- tests/script/jenkins/basic.txt | 2 +- tests/script/tsim/mnode/basic2.sim | 60 ++++++++++++++++++++++++-- 6 files changed, 70 insertions(+), 9 deletions(-) diff --git a/include/util/tlog.h b/include/util/tlog.h index be31aa8115..47ac01aacf 100644 --- a/include/util/tlog.h +++ b/include/util/tlog.h @@ -88,6 +88,7 @@ void taosPrintLongString(const char *flags, ELogLevel level, int32_t dflag, cons #define uInfo(...) { if (uDebugFlag & DEBUG_INFO) { taosPrintLog("UTL ", DEBUG_INFO, tsLogEmbedded ? 255 : uDebugFlag, __VA_ARGS__); }} #define uDebug(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLog("UTL ", DEBUG_DEBUG, uDebugFlag, __VA_ARGS__); }} #define uTrace(...) { if (uDebugFlag & DEBUG_TRACE) { taosPrintLog("UTL ", DEBUG_TRACE, uDebugFlag, __VA_ARGS__); }} +#define uDebugL(...) { if (uDebugFlag & DEBUG_DEBUG) { taosPrintLongString("UTL ", DEBUG_DEBUG, uDebugFlag, __VA_ARGS__); }} #define pError(...) { taosPrintLog("APP ERROR ", DEBUG_ERROR, 255, __VA_ARGS__); } #define pPrint(...) { taosPrintLog("APP ", DEBUG_INFO, 255, __VA_ARGS__); } diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index ede021faee..14d33414fa 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -652,8 +652,12 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, b1, false); - const char *roles = syncStr(syncGetMyRole(pMnode->syncMgmt.sync)); - char *b2 = taosMemoryCalloc(1, 12 + VARSTR_HEADER_SIZE); + // const char *roles = syncStr(syncGetMyRole(pMnode->syncMgmt.sync)); + const char *roles = syncStr(TAOS_SYNC_STATE_FOLLOWER); + if (pObj->id == pMnode->selfId) { + roles = syncStr(TAOS_SYNC_STATE_LEADER); + } + char *b2 = taosMemoryCalloc(1, 12 + VARSTR_HEADER_SIZE); STR_WITH_MAXSIZE_TO_VARSTR(b2, roles, pShow->pMeta->pSchemas[cols].bytes); pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 9d2a2fd2e8..5cc19f8bee 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -519,11 +519,12 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr SMonMnodeDesc desc = {0}; desc.mnode_id = pObj->id; tstrncpy(desc.mnode_ep, pObj->pDnode->ep, sizeof(desc.mnode_ep)); - tstrncpy(desc.role, syncStr(pObj->role), sizeof(desc.role)); + tstrncpy(desc.role, syncStr(TAOS_SYNC_STATE_LEADER), sizeof(desc.role)); + // tstrncpy(desc.role, syncStr(pObj->role), sizeof(desc.role)); taosArrayPush(pClusterInfo->mnodes, &desc); sdbRelease(pSdb, pObj); - if (pObj->role == TAOS_SYNC_STATE_LEADER) { + if (pObj->id == pMnode->selfId) { pClusterInfo->first_ep_dnode_id = pObj->id; tstrncpy(pClusterInfo->first_ep, pObj->pDnode->ep, sizeof(pClusterInfo->first_ep)); pClusterInfo->master_uptime = (ms - pObj->roleTime) / (86400000.0f); diff --git a/source/libs/monitor/src/monMain.c b/source/libs/monitor/src/monMain.c index 3ece089a28..bf857ad718 100644 --- a/source/libs/monitor/src/monMain.c +++ b/source/libs/monitor/src/monMain.c @@ -530,7 +530,8 @@ void monSendReport() { monGenLogJson(pMonitor); char *pCont = tjsonToString(pMonitor->pJson); - if (pCont != NULL) { + // uDebugL("report cont:%s\n", pCont); + if (pCont != NULL) { EHttpCompFlag flag = tsMonitor.cfg.comp ? HTTP_GZIP : HTTP_FLAT; if (taosSendHttpReport(tsMonitor.cfg.server, tsMonitor.cfg.port, pCont, strlen(pCont), flag) != 0) { uError("failed to send monitor msg"); diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 1cc8b97f6f..02372bfcc6 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -56,7 +56,7 @@ # ---- mnode #./test.sh -f tsim/mnode/basic1.sim -./test.sh -f tsim/mnode/basic2.sim +#./test.sh -f tsim/mnode/basic2.sim # ---- show ./test.sh -f tsim/show/basic.sim diff --git a/tests/script/tsim/mnode/basic2.sim b/tests/script/tsim/mnode/basic2.sim index c24d7fc6f7..f293718285 100644 --- a/tests/script/tsim/mnode/basic2.sim +++ b/tests/script/tsim/mnode/basic2.sim @@ -45,14 +45,68 @@ endi print =============== create mnode 2 sql create mnode on dnode 2 sql show mnodes +print $data(1)[0] $data(1)[1] $data(1)[2] +print $data(2)[0] $data(2)[1] $data(2)[2] + +if $rows != 2 then + return -1 +endi +if $data(1)[0] != 1 then + return -1 +endi +if $data(1)[2] != LEADER then + return -1 +endi +if $data(2)[0] != 2 then + return -1 +endi +if $data(2)[2] != FOLLOWER then + return -1 +endi + +print =============== create user +sql create user user1 PASS 'user1' +sql show users if $rows != 2 then return -1 endi -return -sql create mnode on dnode 3 +#sql create database db +#sql show databases +#if $rows != 3 then +# return -1 +#endi + +system sh/exec.sh -n dnode1 -s stop +system sh/exec.sh -n dnode2 -s stop +sleep 100 +system sh/exec.sh -n dnode1 -s start +system sh/exec.sh -n dnode2 -s start + +sql connect + sql show mnodes -if $rows != 3 then +if $rows != 2 then + return -1 +endi +if $data(1)[0] != 1 then + return -1 +endi +if $data(1)[2] != LEADER then return -1 endi +sql show users +if $rows != 2 then + return -1 +endi + +#sql show databases +#if $rows != 3 then +# return -1 +#endi + +return + +system sh/exec.sh -n dnode1 -s stop +system sh/exec.sh -n dnode2 -s stop \ No newline at end of file From 823d47672d0c545e1965e55c2b0bb7f29fe068c5 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 25 May 2022 14:50:20 +0800 Subject: [PATCH 17/32] enh: asan option --- cmake/cmake.define | 4 ++-- source/util/src/thash.c | 4 ++-- tests/script/jenkins/basic.txt | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/cmake/cmake.define b/cmake/cmake.define index 0ae4f56f71..a8bab17aba 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -71,8 +71,8 @@ ELSE () ENDIF () IF (${SANITIZER} MATCHES "true") - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -g3") - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=null -fno-sanitize=alignment -g3") + SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment -g3") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wno-literal-suffix -Werror=return-type -fPIC -gdwarf-2 -fsanitize=address -fsanitize=undefined -fsanitize-recover=all -fsanitize=float-divide-by-zero -fsanitize=float-cast-overflow -fno-sanitize=shift-base -fno-sanitize=alignment -g3") MESSAGE(STATUS "Will compile with Address Sanitizer!") ELSE () SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror -Werror=return-type -fPIC -gdwarf-2 -g3") diff --git a/source/util/src/thash.c b/source/util/src/thash.c index 551c3b67c8..f564ae45b6 100644 --- a/source/util/src/thash.c +++ b/source/util/src/thash.c @@ -708,7 +708,7 @@ SHashNode *doCreateHashNode(const void *key, size_t keyLen, const void *pData, s pNewNode->removed = 0; pNewNode->next = NULL; - memcpy(GET_HASH_NODE_DATA(pNewNode), pData, dsize); + if (pData) memcpy(GET_HASH_NODE_DATA(pNewNode), pData, dsize); memcpy(GET_HASH_NODE_KEY(pNewNode), key, keyLen); return pNewNode; @@ -774,7 +774,7 @@ static void *taosHashReleaseNode(SHashObj *pHashObj, void *p, int *slot) { ASSERT(prevNode->next != prevNode); } else { pe->next = pOld->next; - SHashNode* x = pe->next; + SHashNode *x = pe->next; if (x != NULL) { ASSERT(x->next != x); } diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index f9c6cbf42a..a30b470256 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -67,6 +67,7 @@ # ---- stream ./test.sh -f tsim/stream/basic0.sim ./test.sh -f tsim/stream/basic1.sim +./test.sh -f tsim/stream/basic2.sim ./test.sh -f tsim/stream/session0.sim ./test.sh -f tsim/stream/session1.sim From 74f2746677df861c6090088c84eae7258eca159e Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 25 May 2022 07:14:36 +0000 Subject: [PATCH 18/32] drop super table --- source/dnode/vnode/src/meta/metaTable.c | 101 +++++++++++++----------- 1 file changed, 54 insertions(+), 47 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index a792343380..208d6f9fca 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -71,64 +71,71 @@ _err: } int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) { - TBC *pNameIdxc = NULL; - TBC *pUidIdxc = NULL; - TBC *pCtbIdxc = NULL; - SCtbIdxKey *pCtbIdxKey; - const void *pKey = NULL; - int nKey; - const void *pData = NULL; - int nData; - int c, ret; + void *pKey = NULL; + int nKey = 0; + void *pData = NULL; + int nData = 0; + int c = 0; + int rc = 0; - // prepare uid idx cursor - tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn); - ret = tdbTbcMoveTo(pUidIdxc, &pReq->suid, sizeof(tb_uid_t), &c); - if (ret < 0 || c != 0) { - terrno = TSDB_CODE_VND_TB_NOT_EXIST; - tdbTbcClose(pUidIdxc); - goto _err; + // check if super table exists + rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData); + if (rc < 0 || *(tb_uid_t *)pData != pReq->suid) { + terrno = TSDB_CODE_VND_TABLE_NOT_EXIST; + return -1; } - // prepare name idx cursor - tdbTbcOpen(pMeta->pNameIdx, &pNameIdxc, &pMeta->txn); - ret = tdbTbcMoveTo(pNameIdxc, pReq->name, strlen(pReq->name) + 1, &c); - if (ret < 0 || c != 0) { - ASSERT(0); - } + // drop all child tables + TBC *pCtbIdxc = NULL; + SArray *pArray = taosArrayInit(8, sizeof(tb_uid_t)); - tdbTbcDelete(pUidIdxc); - tdbTbcDelete(pNameIdxc); - tdbTbcClose(pUidIdxc); - tdbTbcClose(pNameIdxc); - - // loop to drop each child table tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn); - ret = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = pReq->suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); - if (ret < 0 || (c < 0 && tdbTbcMoveToNext(pCtbIdxc) < 0)) { + rc = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = pReq->suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c); + if (rc < 0) { tdbTbcClose(pCtbIdxc); - goto _exit; + metaWLock(pMeta); + goto _drop_super_table; } for (;;) { - tdbTbcGet(pCtbIdxc, &pKey, &nKey, NULL, NULL); - pCtbIdxKey = (SCtbIdxKey *)pKey; + rc = tdbTbcNext(pCtbIdxc, &pKey, &nKey, NULL, NULL); + if (rc < 0) break; - if (pCtbIdxKey->suid > pReq->suid) break; + if (((SCtbIdxKey *)pKey)->suid < pReq->suid) { + continue; + } else if (((SCtbIdxKey *)pKey)->suid > pReq->suid) { + break; + } - // drop the child table (TODO) - - if (tdbTbcMoveToNext(pCtbIdxc) < 0) break; + taosArrayPush(pArray, &(((SCtbIdxKey *)pKey)->uid)); } + tdbTbcClose(pCtbIdxc); + + metaWLock(pMeta); + + for (int32_t iChild = 0; iChild < taosArrayGetSize(pArray); iChild++) { + tb_uid_t uid = *(tb_uid_t *)taosArrayGet(pArray, iChild); + metaDropTableByUid(pMeta, uid); + } + + taosArrayDestroy(pArray); + + // drop super table +_drop_super_table: + tdbTbGet(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), &pData, &nData); + tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = *(int64_t *)pData, .uid = pReq->suid}, sizeof(STbDbKey), + &pMeta->txn); + tdbTbDelete(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pMeta->txn); + tdbTbDelete(pMeta->pUidIdx, &pReq->suid, sizeof(tb_uid_t), &pMeta->txn); + + metaULock(pMeta); + _exit: + tdbFree(pKey); + tdbFree(pData); metaDebug("vgId:%d super table %s uid:%" PRId64 " is dropped", TD_VID(pMeta->pVnode), pReq->name, pReq->suid); return 0; - -_err: - metaError("vgId:%d failed to drop super table %s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name, - pReq->suid, tstrerror(terrno)); - return -1; } int metaAlterSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { @@ -608,14 +615,14 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA // TODO : need to update tag index } ctbEntry.version = version; - if(pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON){ + if (pTagSchema->nCols == 1 && pTagSchema->pSchema[0].type == TSDB_DATA_TYPE_JSON) { ctbEntry.ctbEntry.pTags = taosMemoryMalloc(pAlterTbReq->nTagVal); - if(ctbEntry.ctbEntry.pTags == NULL){ + if (ctbEntry.ctbEntry.pTags == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; goto _err; } - memcpy((void*)ctbEntry.ctbEntry.pTags, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal); - }else{ + memcpy((void *)ctbEntry.ctbEntry.pTags, pAlterTbReq->pTagVal, pAlterTbReq->nTagVal); + } else { SKVRowBuilder kvrb = {0}; const SKVRow pOldTag = (const SKVRow)ctbEntry.ctbEntry.pTags; SKVRow pNewTag = NULL; @@ -649,7 +656,7 @@ static int metaUpdateTableTagVal(SMeta *pMeta, int64_t version, SVAlterTbReq *pA tDecoderClear(&dc1); tDecoderClear(&dc2); - if (ctbEntry.ctbEntry.pTags) taosMemoryFree((void*)ctbEntry.ctbEntry.pTags); + if (ctbEntry.ctbEntry.pTags) taosMemoryFree((void *)ctbEntry.ctbEntry.pTags); if (ctbEntry.pBuf) taosMemoryFree(ctbEntry.pBuf); if (stbEntry.pBuf) tdbFree(stbEntry.pBuf); tdbTbcClose(pTbDbc); From 84f6898fcd5863767a7694d268f7d729e9c27b3e Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 25 May 2022 15:22:34 +0800 Subject: [PATCH 19/32] enh(query): add detailed sort exec information in analysis of operator. --- include/common/tcommon.h | 10 ++++ include/common/tdatablock.h | 2 +- source/common/src/tdatablock.c | 10 +--- source/libs/command/src/explain.c | 47 ++++++++++++++---- source/libs/executor/inc/executorimpl.h | 10 ++-- source/libs/executor/inc/tsort.h | 8 ++++ source/libs/executor/src/scanoperator.c | 2 +- source/libs/executor/src/sortoperator.c | 63 ++++++++++++++++++++----- source/libs/executor/src/tsort.c | 45 +++++++++++++----- source/util/src/tpagedbuf.c | 15 ++++-- 10 files changed, 158 insertions(+), 54 deletions(-) diff --git a/include/common/tcommon.h b/include/common/tcommon.h index 9e3ad42a82..0ff13963c0 100644 --- a/include/common/tcommon.h +++ b/include/common/tcommon.h @@ -219,6 +219,16 @@ typedef struct { #define GET_FORWARD_DIRECTION_FACTOR(ord) (((ord) == TSDB_ORDER_ASC) ? QUERY_ASC_FORWARD_STEP : QUERY_DESC_FORWARD_STEP) +#define SORT_QSORT_T 0x1 +#define SORT_SPILLED_MERGE_SORT_T 0x2 +typedef struct SSortExecInfo { + int32_t sortMethod; + int32_t sortBuffer; + int32_t loops; // loop count + int32_t writeBytes; // write io bytes + int32_t readBytes; // read io bytes +} SSortExecInfo; + #ifdef __cplusplus } #endif diff --git a/include/common/tdatablock.h b/include/common/tdatablock.h index db8644ecfe..e8fe47a462 100644 --- a/include/common/tdatablock.h +++ b/include/common/tdatablock.h @@ -198,7 +198,7 @@ void colDataTrim(SColumnInfoData* pColumnInfoData); size_t blockDataGetNumOfCols(const SSDataBlock* pBlock); size_t blockDataGetNumOfRows(const SSDataBlock* pBlock); -int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pIndexMap); +int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc); int32_t blockDataSplitRows(SSDataBlock* pBlock, bool hasVarCol, int32_t startIndex, int32_t* stopIndex, int32_t pageSize); int32_t blockDataToBuf(char* buf, const SSDataBlock* pBlock); diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 51bcd05ea1..816fdab3d2 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -361,19 +361,13 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex) return 0; } -// if pIndexMap = NULL, merger one column by on column -int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc, SArray* pIndexMap) { +int32_t blockDataMerge(SSDataBlock* pDest, const SSDataBlock* pSrc) { assert(pSrc != NULL && pDest != NULL); int32_t capacity = pDest->info.capacity; for (int32_t i = 0; i < pDest->info.numOfCols; ++i) { - int32_t mapIndex = i; - // if (pIndexMap) { - // mapIndex = *(int32_t*)taosArrayGet(pIndexMap, i); - // } - SColumnInfoData* pCol2 = taosArrayGet(pDest->pDataBlock, i); - SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, mapIndex); + SColumnInfoData* pCol1 = taosArrayGet(pSrc->pDataBlock, i); capacity = pDest->info.capacity; colDataMergeCol(pCol2, pDest->info.rows, &capacity, pCol1, pSrc->info.rows); diff --git a/source/libs/command/src/explain.c b/source/libs/command/src/explain.c index 1acc9368c8..26a0f3bf6c 100644 --- a/source/libs/command/src/explain.c +++ b/source/libs/command/src/explain.c @@ -16,6 +16,7 @@ #include "commandInt.h" #include "plannodes.h" #include "query.h" +#include "tcommon.h" int32_t qExplainGenerateResNode(SPhysiNode *pNode, SExplainGroup *group, SExplainResNode **pRes); int32_t qExplainAppendGroupResRows(void *pCtx, int32_t groupId, int32_t level); @@ -637,13 +638,48 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); } - EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, pSortNode->pSortKeys->length); + + SDataBlockDescNode* pDescNode = pSortNode->node.pOutputDataBlockDesc; + EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, nodesGetOutputNumFromSlotList(pDescNode->pSlots)); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); - EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pSortNode->node.pOutputDataBlockDesc->totalRowSize); + EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pDescNode->totalRowSize); EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + if (EXPLAIN_MODE_ANALYZE == ctx->mode) { + // sort key + EXPLAIN_ROW_NEW(level, "Sort Key: "); + if (pResNode->pExecInfo) { + for (int32_t i = 0; i < LIST_LENGTH(pSortNode->pSortKeys); ++i) { + SOrderByExprNode *ptn = nodesListGetNode(pSortNode->pSortKeys, i); + EXPLAIN_ROW_APPEND("%s ", nodesGetNameFromColumnNode(ptn->pExpr)); + } + } + + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + + // sort method + EXPLAIN_ROW_NEW(level, "Sort Method: "); + + int32_t nodeNum = taosArrayGetSize(pResNode->pExecInfo); + SExplainExecInfo *execInfo = taosArrayGet(pResNode->pExecInfo, 0); + SSortExecInfo * pExecInfo = (SSortExecInfo *)execInfo->verboseInfo; + EXPLAIN_ROW_APPEND("%s", pExecInfo->sortMethod == SORT_QSORT_T ? "quicksort" : "merge sort"); + if (pExecInfo->sortBuffer > 1024 * 1024) { + EXPLAIN_ROW_APPEND(" Buffers:%.2f Mb", pExecInfo->sortBuffer / (1024 * 1024.0)); + } else if (pExecInfo->sortBuffer > 1024) { + EXPLAIN_ROW_APPEND(" Buffers:%.2f Kb", pExecInfo->sortBuffer / (1024.0)); + } else { + EXPLAIN_ROW_APPEND(" Buffers:%d b", pExecInfo->sortBuffer); + } + + EXPLAIN_ROW_APPEND(" loops:%d", pExecInfo->loops); + EXPLAIN_ROW_END(); + QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); + } + if (verbose) { EXPLAIN_ROW_NEW(level + 1, EXPLAIN_OUTPUT_FORMAT); EXPLAIN_ROW_APPEND(EXPLAIN_COLUMNS_FORMAT, @@ -792,13 +828,8 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i QRY_ERR_RET(qExplainBufAppendExecInfo(pResNode->pExecInfo, tbuf, &tlen)); EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); } -// EXPLAIN_ROW_APPEND(EXPLAIN_FUNCTIONS_FORMAT, pPartNode->length); -// EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pPartNode->node.pOutputDataBlockDesc->totalRowSize); -// if (pPartNode->pGroupKeys) { -// EXPLAIN_ROW_APPEND(EXPLAIN_BLANK_FORMAT); -// EXPLAIN_ROW_APPEND(EXPLAIN_GROUPS_FORMAT, pPartNode->pGroupKeys->length); -// } + EXPLAIN_ROW_APPEND(EXPLAIN_RIGHT_PARENTHESIS_FORMAT); EXPLAIN_ROW_END(); QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level)); diff --git a/source/libs/executor/inc/executorimpl.h b/source/libs/executor/inc/executorimpl.h index 8ac320b9aa..2dfbaaa4aa 100644 --- a/source/libs/executor/inc/executorimpl.h +++ b/source/libs/executor/inc/executorimpl.h @@ -588,18 +588,14 @@ typedef struct SSortedMergeOperatorInfo { typedef struct SSortOperatorInfo { SOptrBasicInfo binfo; - uint32_t sortBufSize; // max buffer size for in-memory sort + uint32_t sortBufSize; // max buffer size for in-memory sort SArray* pSortInfo; SSortHandle* pSortHandle; SArray* pColMatchInfo; // for index map from table scan output int32_t bufPageSize; - // TODO extact struct - int64_t startTs; // sort start time - uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included. - uint64_t totalSize; // total load bytes from remote - uint64_t totalRows; // total number of rows - uint64_t totalElapsed; // total elapsed time + int64_t startTs; // sort start time + uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included. } SSortOperatorInfo; typedef struct STagFilterOperatorInfo { diff --git a/source/libs/executor/inc/tsort.h b/source/libs/executor/inc/tsort.h index d74628a72f..c8b1b3ee51 100644 --- a/source/libs/executor/inc/tsort.h +++ b/source/libs/executor/inc/tsort.h @@ -137,6 +137,14 @@ void* tsortGetValue(STupleHandle* pVHandle, int32_t colId); */ SSDataBlock* tsortGetSortedDataBlock(const SSortHandle* pSortHandle); +/** + * return the sort execution information. + * + * @param pHandle + * @return + */ +SSortExecInfo tsortGetSortExecInfo(SSortHandle* pHandle); + #ifdef __cplusplus } #endif diff --git a/source/libs/executor/src/scanoperator.c b/source/libs/executor/src/scanoperator.c index 2215d0035d..ccd4b7c4cf 100644 --- a/source/libs/executor/src/scanoperator.c +++ b/source/libs/executor/src/scanoperator.c @@ -790,7 +790,7 @@ static SSDataBlock* getDataFromCatch(SStreamBlockScanInfo* pInfo) { SSDataBlock* pDB = createOneDataBlock(pInfo->pRes, false); blockDataFromBuf(pDB, buf); SSDataBlock* pSub = blockDataExtractBlock(pDB, pos->rowId, 1); - blockDataMerge(pInfo->pRes, pSub, NULL); + blockDataMerge(pInfo->pRes, pSub); blockDataDestroy(pDB); blockDataDestroy(pSub); } diff --git a/source/libs/executor/src/sortoperator.c b/source/libs/executor/src/sortoperator.c index 990dc0f200..8f5fa88070 100644 --- a/source/libs/executor/src/sortoperator.c +++ b/source/libs/executor/src/sortoperator.c @@ -2,6 +2,9 @@ #include "executorimpl.h" static SSDataBlock* doSort(SOperatorInfo* pOperator); +static int32_t doOpenSortOperator(SOperatorInfo* pOperator); +static int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len); + static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput); SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExprInfo* pExprInfo, int32_t numOfCols, @@ -35,7 +38,7 @@ SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pR pOperator->pTaskInfo = pTaskInfo; pOperator->fpSet = - createOperatorFpSet(operatorDummyOpenFn, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, NULL); + createOperatorFpSet(doOpenSortOperator, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, getExplainExecInfo); int32_t code = appendDownstream(pOperator, &downstream, 1); return pOperator; @@ -121,20 +124,17 @@ void applyScalarFunction(SSDataBlock* pBlock, void* param) { } } -SSDataBlock* doSort(SOperatorInfo* pOperator) { - if (pOperator->status == OP_EXEC_DONE) { - return NULL; - } - - SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; +int32_t doOpenSortOperator(SOperatorInfo* pOperator) { SSortOperatorInfo* pInfo = pOperator->info; + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; - if (pOperator->status == OP_RES_TO_RETURN) { - return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo); + if (OPTR_IS_OPENED(pOperator)) { + return TSDB_CODE_SUCCESS; } -// pInfo->binfo.pRes is not equalled to the input datablock. -// int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize; + pInfo->startTs = taosGetTimestampUs(); + + // pInfo->binfo.pRes is not equalled to the input datablock. pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->pColMatchInfo, SORT_SINGLESOURCE_SORT, -1, -1, NULL, pTaskInfo->id.str); @@ -146,12 +146,39 @@ SSDataBlock* doSort(SOperatorInfo* pOperator) { int32_t code = tsortOpen(pInfo->pSortHandle); taosMemoryFreeClear(ps); + if (code != TSDB_CODE_SUCCESS) { longjmp(pTaskInfo->env, terrno); } + pOperator->cost.openCost = (taosGetTimestampUs() - pInfo->startTs)/1000.0; pOperator->status = OP_RES_TO_RETURN; - return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo); + + OPTR_SET_OPENED(pOperator); + return TSDB_CODE_SUCCESS; +} + +SSDataBlock* doSort(SOperatorInfo* pOperator) { + if (pOperator->status == OP_EXEC_DONE) { + return NULL; + } + + SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo; + SSortOperatorInfo* pInfo = pOperator->info; + + int32_t code = pOperator->fpSet._openFn(pOperator); + if (code != TSDB_CODE_SUCCESS) { + longjmp(pTaskInfo->env, code); + } + + SSDataBlock* pBlock = getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity, pInfo->pColMatchInfo); + + if (pBlock != NULL) { + pOperator->resultInfo.totalRows += pBlock->info.rows; + } else { + doSetOperatorCompleted(pOperator); + } + return pBlock; } void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) { @@ -161,3 +188,15 @@ void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) { taosArrayDestroy(pInfo->pSortInfo); taosArrayDestroy(pInfo->pColMatchInfo); } + +int32_t getExplainExecInfo(SOperatorInfo* pOptr, void** pOptrExplain, uint32_t* len) { + ASSERT(pOptr != NULL); + SSortExecInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortExecInfo)); + + SSortOperatorInfo *pOperatorInfo = (SSortOperatorInfo*)pOptr->info; + + *pInfo = tsortGetSortExecInfo(pOperatorInfo->pSortHandle); + *pOptrExplain = pInfo; + *len = sizeof(SSortExecInfo); + return TSDB_CODE_SUCCESS; +} diff --git a/source/libs/executor/src/tsort.c b/source/libs/executor/src/tsort.c index c826cb68bf..7581836d59 100644 --- a/source/libs/executor/src/tsort.c +++ b/source/libs/executor/src/tsort.c @@ -31,20 +31,16 @@ struct STupleHandle { struct SSortHandle { int32_t type; - int32_t pageSize; int32_t numOfPages; SDiskbasedBuf *pBuf; SArray *pSortInfo; - SArray *pIndexMap; SArray *pOrderedSource; - _sort_fetch_block_fn_t fetchfp; - _sort_merge_compar_fn_t comparFn; - SMultiwayMergeTreeInfo *pMergeTree; - int64_t startTs; + int32_t loops; uint64_t sortElapsed; + int64_t startTs; uint64_t totalElapsed; int32_t sourceId; @@ -53,13 +49,15 @@ struct SSortHandle { int32_t numOfCompletedSources; bool opened; const char *idStr; - bool inMemSort; bool needAdjust; STupleHandle tupleHandle; - void *param; void (*beforeFp)(SSDataBlock* pBlock, void* param); + + _sort_fetch_block_fn_t fetchfp; + _sort_merge_compar_fn_t comparFn; + SMultiwayMergeTreeInfo *pMergeTree; }; static int32_t msortComparFn(const void *pLeft, const void *pRight, void *param); @@ -80,7 +78,7 @@ SSortHandle* tsortCreateSortHandle(SArray* pSortInfo, SArray* pIndexMap, int32_t pSortHandle->pageSize = pageSize; pSortHandle->numOfPages = numOfPages; pSortHandle->pSortInfo = pSortInfo; - pSortHandle->pIndexMap = pIndexMap; + pSortHandle->loops = 0; if (pBlock != NULL) { pSortHandle->pDataBlock = createOneDataBlock(pBlock, false); @@ -415,6 +413,9 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { int32_t numOfRows = blockDataGetCapacityInRow(pHandle->pDataBlock, pHandle->pageSize); blockDataEnsureCapacity(pHandle->pDataBlock, numOfRows); + // the initial pass + sortPass + final mergePass + pHandle->loops = sortPass + 2; + size_t numOfSorted = taosArrayGetSize(pHandle->pOrderedSource); for(int32_t t = 0; t < sortPass; ++t) { int64_t st = taosGetTimestampUs(); @@ -502,12 +503,13 @@ static int32_t doInternalMergeSort(SSortHandle* pHandle) { return 0; } -static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { +static int32_t createInitialSources(SSortHandle* pHandle) { size_t sortBufSize = pHandle->numOfPages * pHandle->pageSize; if (pHandle->type == SORT_SINGLESOURCE_SORT) { SSortSource* source = taosArrayGetP(pHandle->pOrderedSource, 0); taosArrayClear(pHandle->pOrderedSource); + while (1) { SSDataBlock* pBlock = pHandle->fetchfp(source->param); if (pBlock == NULL) { @@ -524,6 +526,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { } else { pHandle->pageSize = 4096; } + // todo!! pHandle->numOfPages = 1024; sortBufSize = pHandle->numOfPages * pHandle->pageSize; @@ -535,7 +538,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { } // todo relocate the columns - int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock, pHandle->pIndexMap); + int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock); if (code != 0) { return code; } @@ -569,6 +572,7 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) { pHandle->cmpParam.numOfSources = 1; pHandle->inMemSort = true; + pHandle->loops = 1; pHandle->tupleHandle.rowIndex = -1; pHandle->tupleHandle.pBlock = pHandle->pDataBlock; return 0; @@ -592,7 +596,7 @@ int32_t tsortOpen(SSortHandle* pHandle) { pHandle->opened = true; - int32_t code = createInitialSortedMultiSources(pHandle); + int32_t code = createInitialSources(pHandle); if (code != TSDB_CODE_SUCCESS) { return code; } @@ -692,3 +696,20 @@ void* tsortGetValue(STupleHandle* pVHandle, int32_t colIndex) { SColumnInfoData* pColInfo = TARRAY_GET_ELEM(pVHandle->pBlock->pDataBlock, colIndex); return colDataGetData(pColInfo, pVHandle->rowIndex); } + +SSortExecInfo tsortGetSortExecInfo(SSortHandle* pHandle) { + SSortExecInfo info = {0}; + + info.sortBuffer = pHandle->pageSize * pHandle->numOfPages; + info.sortMethod = pHandle->inMemSort? SORT_QSORT_T:SORT_SPILLED_MERGE_SORT_T; + info.loops = pHandle->loops; + + if (pHandle->pBuf != NULL) { + SDiskbasedBufStatis st = getDBufStatis(pHandle->pBuf); + info.writeBytes = st.flushBytes; + info.readBytes = st.loadBytes; + } + + return info; +} + diff --git a/source/util/src/tpagedbuf.c b/source/util/src/tpagedbuf.c index 00f1233707..101ac78e18 100644 --- a/source/util/src/tpagedbuf.c +++ b/source/util/src/tpagedbuf.c @@ -549,11 +549,16 @@ void destroyDiskbasedBuf(SDiskbasedBuf* pBuf) { // print the statistics information { SDiskbasedBufStatis* ps = &pBuf->statis; - uDebug( - "Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f " - "Kb\n", - ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, - ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages)); + if (ps->loadPages == 0) { + uDebug( + "Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages)", + ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, ps->loadPages); + } else { + uDebug( + "Get/Release pages:%d/%d, flushToDisk:%.2f Kb (%d Pages), loadFromDisk:%.2f Kb (%d Pages), avgPageSize:%.2f Kb", + ps->getPages, ps->releasePages, ps->flushBytes / 1024.0f, ps->flushPages, ps->loadBytes / 1024.0f, + ps->loadPages, ps->loadBytes / (1024.0 * ps->loadPages)); + } } taosRemoveFile(pBuf->path); From d5d0bd2b191279873228f814bcbc2307430dd217 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 25 May 2022 15:36:57 +0800 Subject: [PATCH 20/32] fix(query): add check for invalid tablename. --- source/libs/parser/src/parInsert.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/libs/parser/src/parInsert.c b/source/libs/parser/src/parInsert.c index 239bd21abc..8b3ee20545 100644 --- a/source/libs/parser/src/parInsert.c +++ b/source/libs/parser/src/parInsert.c @@ -189,6 +189,7 @@ static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, con const char* msg1 = "name too long"; const char* msg2 = "invalid database name"; const char* msg3 = "db is not specified"; + const char* msg4 = "invalid table name"; int32_t code = TSDB_CODE_SUCCESS; char* p = strnchr(pTableName->z, TS_PATH_DELIMITER[0], pTableName->n, true); @@ -207,6 +208,10 @@ static int32_t createSName(SName* pName, SToken* pTableName, int32_t acctId, con } int32_t tbLen = pTableName->n - dbLen - 1; + if (tbLen <= 0) { + return buildInvalidOperationMsg(pMsgBuf, msg4); + } + char tbname[TSDB_TABLE_FNAME_LEN] = {0}; strncpy(tbname, p + 1, tbLen); /*tbLen = */ strdequote(tbname); From d1a4e2d232c35264621503b9905be1f19ebd7469 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 25 May 2022 08:03:05 +0000 Subject: [PATCH 21/32] feat: drop stable --- source/dnode/vnode/src/meta/metaTable.c | 154 ++++++++---------------- 1 file changed, 48 insertions(+), 106 deletions(-) diff --git a/source/dnode/vnode/src/meta/metaTable.c b/source/dnode/vnode/src/meta/metaTable.c index 208d6f9fca..462d461a8a 100644 --- a/source/dnode/vnode/src/meta/metaTable.c +++ b/source/dnode/vnode/src/meta/metaTable.c @@ -23,6 +23,7 @@ static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME); static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME); static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry); +static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type); int metaCreateSTable(SMeta *pMeta, int64_t version, SVCreateStbReq *pReq) { SMetaEntry me = {0}; @@ -116,7 +117,7 @@ int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) { for (int32_t iChild = 0; iChild < taosArrayGetSize(pArray); iChild++) { tb_uid_t uid = *(tb_uid_t *)taosArrayGet(pArray, iChild); - metaDropTableByUid(pMeta, uid); + metaDropTableByUid(pMeta, uid, NULL); } taosArrayDestroy(pArray); @@ -263,122 +264,63 @@ _err: } int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq, SArray *tbUids) { - TBC *pTbDbc = NULL; - TBC *pUidIdxc = NULL; - TBC *pNameIdxc = NULL; - const void *pData; - int nData; - tb_uid_t uid; - int64_t tver; - SMetaEntry me = {0}; - SDecoder coder = {0}; - int8_t type; - int64_t ctime; - tb_uid_t suid; - int c = 0, ret; + void *pData = NULL; + int nData = 0; + int rc = 0; + tb_uid_t uid; + int type; - // search & delete the name idx - tdbTbcOpen(pMeta->pNameIdx, &pNameIdxc, &pMeta->txn); - ret = tdbTbcMoveTo(pNameIdxc, pReq->name, strlen(pReq->name) + 1, &c); - if (ret < 0 || !tdbTbcIsValid(pNameIdxc) || c) { - tdbTbcClose(pNameIdxc); + rc = tdbTbGet(pMeta->pNameIdx, pReq->name, strlen(pReq->name) + 1, &pData, &nData); + if (rc < 0) { terrno = TSDB_CODE_VND_TABLE_NOT_EXIST; return -1; } - - ret = tdbTbcGet(pNameIdxc, NULL, NULL, &pData, &nData); - if (ret < 0) { - ASSERT(0); - return -1; - } - uid = *(tb_uid_t *)pData; - tdbTbcDelete(pNameIdxc); - tdbTbcClose(pNameIdxc); + metaWLock(pMeta); + metaDropTableByUid(pMeta, uid, &type); + metaULock(pMeta); - // search & delete uid idx - tdbTbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn); - ret = tdbTbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c); - if (ret < 0 || c != 0) { - ASSERT(0); - return -1; + if (type == TSDB_CHILD_TABLE && tbUids) { + taosArrayPush(tbUids, &uid); } - ret = tdbTbcGet(pUidIdxc, NULL, NULL, &pData, &nData); - if (ret < 0) { - ASSERT(0); - return -1; + tdbFree(pData); + return 0; +} + +static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) { + void *pData = NULL; + int nData = 0; + int rc = 0; + int64_t version; + SMetaEntry e = {0}; + SDecoder dc = {0}; + + rc = tdbTbGet(pMeta->pUidIdx, &uid, sizeof(uid), &pData, &nData); + version = *(int64_t *)pData; + + tdbTbGet(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pData, &nData); + + tDecoderInit(&dc, pData, nData); + metaDecodeEntry(&dc, &e); + + if (type) *type = e.type; + + tdbTbDelete(pMeta->pTbDb, &(STbDbKey){.version = version, .uid = uid}, sizeof(STbDbKey), &pMeta->txn); + tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn); + tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn); + if (e.type == TSDB_CHILD_TABLE) { + tdbTbDelete(pMeta->pCtbIdx, &(SCtbIdxKey){.suid = e.ctbEntry.suid, .uid = uid}, sizeof(SCtbIdxKey), &pMeta->txn); + } else if (e.type == TSDB_NORMAL_TABLE) { + // drop schema.db (todo) + // drop ttl.idx (todo) + } else if (e.type == TSDB_SUPER_TABLE) { + // drop schema.db (todo) } - tver = *(int64_t *)pData; - tdbTbcDelete(pUidIdxc); - tdbTbcClose(pUidIdxc); - - // search and get meta entry - tdbTbcOpen(pMeta->pTbDb, &pTbDbc, &pMeta->txn); - ret = tdbTbcMoveTo(pTbDbc, &(STbDbKey){.uid = uid, .version = tver}, sizeof(STbDbKey), &c); - if (ret < 0 || c != 0) { - ASSERT(0); - return -1; - } - - ret = tdbTbcGet(pTbDbc, NULL, NULL, &pData, &nData); - if (ret < 0) { - ASSERT(0); - return -1; - } - - // decode entry - void *pDataCopy = taosMemoryMalloc(nData); // remove the copy (todo) - memcpy(pDataCopy, pData, nData); - tDecoderInit(&coder, pDataCopy, nData); - ret = metaDecodeEntry(&coder, &me); - if (ret < 0) { - ASSERT(0); - return -1; - } - - type = me.type; - if (type == TSDB_CHILD_TABLE) { - ctime = me.ctbEntry.ctime; - suid = me.ctbEntry.suid; - taosArrayPush(tbUids, &me.uid); - } else if (type == TSDB_NORMAL_TABLE) { - ctime = me.ntbEntry.ctime; - suid = 0; - } else { - ASSERT(0); - } - - taosMemoryFree(pDataCopy); - tDecoderClear(&coder); - tdbTbcClose(pTbDbc); - - if (type == TSDB_CHILD_TABLE) { - // remove the pCtbIdx - TBC *pCtbIdxc = NULL; - tdbTbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn); - - ret = tdbTbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = uid}, sizeof(SCtbIdxKey), &c); - if (ret < 0 || c != 0) { - ASSERT(0); - return -1; - } - - tdbTbcDelete(pCtbIdxc); - tdbTbcClose(pCtbIdxc); - - // remove tags from pTagIdx (todo) - } else if (type == TSDB_NORMAL_TABLE) { - // remove from pSkmDb - } else { - ASSERT(0); - } - - // remove from ttl (todo) - if (ctime > 0) { - } + tDecoderClear(&dc); + tdbFree(pData); return 0; } From b638d0ef8c582160a9a39fa48152ed67e24592ee Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 25 May 2022 16:41:38 +0800 Subject: [PATCH 22/32] refactor: let mnode report sync state --- include/common/tmsg.h | 1 + include/dnode/mnode/mnode.h | 1 + source/common/src/tmsg.c | 5 +++ source/dnode/mgmt/mgmt_dnode/src/dmHandle.c | 3 +- source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 9 ++++-- source/dnode/mgmt/node_util/inc/dmUtil.h | 4 +-- source/dnode/mnode/impl/inc/mndDef.h | 5 ++- source/dnode/mnode/impl/inc/mndInt.h | 3 +- source/dnode/mnode/impl/inc/mndMnode.h | 1 - source/dnode/mnode/impl/src/mndDnode.c | 27 +++++++++++----- source/dnode/mnode/impl/src/mndMnode.c | 35 +++++---------------- source/dnode/mnode/impl/src/mndSync.c | 5 ++- source/dnode/mnode/impl/src/mnode.c | 18 +++++------ 13 files changed, 58 insertions(+), 59 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 32cb739535..de26af48ee 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -950,6 +950,7 @@ typedef struct { int32_t numOfCores; int32_t numOfSupportVnodes; char dnodeEp[TSDB_EP_LEN]; + SMnodeLoad mload; SClusterCfg clusterCfg; SArray* pVloads; // array of SVnodeLoad } SStatusReq; diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 69260d720c..bc14dc3210 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -29,6 +29,7 @@ extern "C" { typedef struct SMnode SMnode; typedef struct { + int32_t dnodeId; bool standby; bool deploy; int8_t replica; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 7f886b078a..93a592f120 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -891,6 +891,9 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tEncodeI64(&encoder, pload->pointsWritten) < 0) return -1; } + // mnode loads + if (tEncodeI32(&encoder, pReq->mload.syncState) < 0) return -1; + tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -946,6 +949,8 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { } } + if (tDecodeI32(&decoder, &pReq->mload.syncState) < 0) return -1; + tEndDecode(&decoder); tDecoderClear(&decoder); return 0; diff --git a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c index f7337f482f..bb2c069eaa 100644 --- a/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c +++ b/source/dnode/mgmt/mgmt_dnode/src/dmHandle.c @@ -75,8 +75,9 @@ void dmSendStatusReq(SDnodeMgmt *pMgmt) { (*pMgmt->getVnodeLoadsFp)(&vinfo); req.pVloads = vinfo.pVloads; - SMonMloadInfo minfo = {0}; + SMonMloadInfo minfo = {0}; (*pMgmt->getMnodeLoadsFp)(&minfo); + req.mload = minfo.load; int32_t contLen = tSerializeSStatusReq(NULL, 0, &req); void *pHead = rpcMallocCont(contLen); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 875be9768c..964c2d42b7 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -42,6 +42,8 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInpu pOption->standby = false; pOption->deploy = true; pOption->msgCb = pMgmt->msgCb; + pOption->dnodeId = pMgmt->pData->dnodeId; + pOption->replica = 1; pOption->selfIndex = 0; @@ -52,9 +54,10 @@ static void mmBuildOptionForDeploy(SMnodeMgmt *pMgmt, const SMgmtInputOpt *pInpu } static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { - pOption->msgCb = pMgmt->msgCb; pOption->deploy = false; pOption->standby = false; + pOption->msgCb = pMgmt->msgCb; + pOption->dnodeId = pMgmt->pData->dnodeId; if (pMgmt->replica > 0) { pOption->standby = true; @@ -71,9 +74,11 @@ static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { } static int32_t mmBuildOptionForAlter(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCreateMnodeReq *pCreate) { - pOption->msgCb = pMgmt->msgCb; pOption->standby = false; pOption->deploy = false; + pOption->msgCb = pMgmt->msgCb; + pOption->dnodeId = pMgmt->pData->dnodeId; + pOption->replica = pCreate->replica; pOption->selfIndex = -1; diff --git a/source/dnode/mgmt/node_util/inc/dmUtil.h b/source/dnode/mgmt/node_util/inc/dmUtil.h index 4946669678..0d921c2e8b 100644 --- a/source/dnode/mgmt/node_util/inc/dmUtil.h +++ b/source/dnode/mgmt/node_util/inc/dmUtil.h @@ -90,8 +90,8 @@ typedef enum { typedef int32_t (*ProcessCreateNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg); typedef int32_t (*ProcessDropNodeFp)(EDndNodeType ntype, SRpcMsg *pMsg); typedef void (*SendMonitorReportFp)(); -typedef void (*GetVnodeLoadsFp)(); -typedef void (*GetMnodeLoadsFp)(); +typedef void (*GetVnodeLoadsFp)(SMonVloadInfo *pInfo); +typedef void (*GetMnodeLoadsFp)(SMonMloadInfo *pInfo); typedef struct { int32_t dnodeId; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 432b95059d..26cfaa62ff 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -199,9 +199,8 @@ typedef struct { int32_t id; int64_t createdTime; int64_t updateTime; - ESyncState role; - int32_t roleTerm; - int64_t roleTime; + ESyncState state; + int64_t stateStartTime; SDnodeObj* pDnode; } SMnodeObj; diff --git a/source/dnode/mnode/impl/inc/mndInt.h b/source/dnode/mnode/impl/inc/mndInt.h index 489e1aec5c..189ea82bfc 100644 --- a/source/dnode/mnode/impl/inc/mndInt.h +++ b/source/dnode/mnode/impl/inc/mndInt.h @@ -78,7 +78,6 @@ typedef struct { SWal *pWal; sem_t syncSem; int64_t sync; - ESyncState state; bool standby; bool restored; int32_t errCode; @@ -90,7 +89,7 @@ typedef struct { } SGrantInfo; typedef struct SMnode { - int32_t selfId; + int32_t selfDnodeId; int64_t clusterId; TdThread thread; bool deploy; diff --git a/source/dnode/mnode/impl/inc/mndMnode.h b/source/dnode/mnode/impl/inc/mndMnode.h index a5cdfa1061..fd62b3ce75 100644 --- a/source/dnode/mnode/impl/inc/mndMnode.h +++ b/source/dnode/mnode/impl/inc/mndMnode.h @@ -28,7 +28,6 @@ SMnodeObj *mndAcquireMnode(SMnode *pMnode, int32_t mnodeId); void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj); bool mndIsMnode(SMnode *pMnode, int32_t dnodeId); void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet); -void mndUpdateMnodeRole(SMnode *pMnode); #ifdef __cplusplus } diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 1f6dc03dc3..047562ec02 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -58,14 +58,16 @@ static int32_t mndRetrieveDnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB static void mndCancelGetNextDnode(SMnode *pMnode, void *pIter); int32_t mndInitDnode(SMnode *pMnode) { - SSdbTable table = {.sdbType = SDB_DNODE, - .keyType = SDB_KEY_INT32, - .deployFp = (SdbDeployFp)mndCreateDefaultDnode, - .encodeFp = (SdbEncodeFp)mndDnodeActionEncode, - .decodeFp = (SdbDecodeFp)mndDnodeActionDecode, - .insertFp = (SdbInsertFp)mndDnodeActionInsert, - .updateFp = (SdbUpdateFp)mndDnodeActionUpdate, - .deleteFp = (SdbDeleteFp)mndDnodeActionDelete}; + SSdbTable table = { + .sdbType = SDB_DNODE, + .keyType = SDB_KEY_INT32, + .deployFp = (SdbDeployFp)mndCreateDefaultDnode, + .encodeFp = (SdbEncodeFp)mndDnodeActionEncode, + .decodeFp = (SdbDecodeFp)mndDnodeActionDecode, + .insertFp = (SdbInsertFp)mndDnodeActionInsert, + .updateFp = (SdbUpdateFp)mndDnodeActionUpdate, + .deleteFp = (SdbDeleteFp)mndDnodeActionDelete, + }; mndSetMsgHandle(pMnode, TDMT_MND_CREATE_DNODE, mndProcessCreateDnodeReq); mndSetMsgHandle(pMnode, TDMT_MND_DROP_DNODE, mndProcessDropDnodeReq); @@ -377,6 +379,15 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { mndReleaseVgroup(pMnode, pVgroup); } + SMnodeObj *pObj = mndAcquireMnode(pMnode, pDnode->id); + if (pObj != NULL) { + if (pObj->state != statusReq.mload.syncState) { + pObj->state = statusReq.mload.syncState; + pObj->stateStartTime = taosGetTimestampMs(); + } + mndReleaseMnode(pMnode, pObj); + } + int64_t curMs = taosGetTimestampMs(); bool online = mndIsDnodeOnline(pMnode, pDnode, curMs); bool dnodeChanged = (statusReq.dnodeVer != sdbGetTableVer(pMnode->pSdb, SDB_DNODE)); diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 14d33414fa..93284a95c5 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -77,28 +77,6 @@ void mndReleaseMnode(SMnode *pMnode, SMnodeObj *pObj) { sdbRelease(pMnode->pSdb, pObj); } -void mndUpdateMnodeRole(SMnode *pMnode) { - SSdb *pSdb = pMnode->pSdb; - void *pIter = NULL; - while (1) { - SMnodeObj *pObj = NULL; - pIter = sdbFetch(pSdb, SDB_MNODE, pIter, (void **)&pObj); - if (pIter == NULL) break; - - ESyncState lastRole = pObj->role; - if (pObj->id == 1) { - pObj->role = TAOS_SYNC_STATE_LEADER; - } else { - pObj->role = TAOS_SYNC_STATE_CANDIDATE; - } - if (pObj->role != lastRole) { - pObj->roleTime = taosGetTimestampMs(); - } - - sdbRelease(pSdb, pObj); - } -} - static int32_t mndCreateDefaultMnode(SMnode *pMnode) { SMnodeObj mnodeObj = {0}; mnodeObj.id = 1; @@ -209,7 +187,7 @@ static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj) { return -1; } - pObj->role = TAOS_SYNC_STATE_FOLLOWER; + pObj->state = TAOS_SYNC_STATE_ERROR; return 0; } @@ -253,7 +231,7 @@ void mndGetMnodeEpSet(SMnode *pMnode, SEpSet *pEpSet) { if (pObj->pDnode == NULL) { mError("mnode:%d, no corresponding dnode exists", pObj->id); } else { - if (pObj->role == TAOS_SYNC_STATE_LEADER) { + if (pObj->state == TAOS_SYNC_STATE_LEADER) { pEpSet->inUse = pEpSet->numOfEps; } addEpIntoEpSet(pEpSet, pObj->pDnode->fqdn, pObj->pDnode->port); @@ -581,7 +559,7 @@ static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq) { goto _OVER; } - if (pMnode->selfId == dropReq.dnodeId) { + if (pMnode->selfDnodeId == dropReq.dnodeId) { terrno = TSDB_CODE_MND_CANT_DROP_MASTER; goto _OVER; } @@ -652,10 +630,11 @@ static int32_t mndRetrieveMnodes(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pB pColInfo = taosArrayGet(pBlock->pDataBlock, cols++); colDataAppend(pColInfo, numOfRows, b1, false); - // const char *roles = syncStr(syncGetMyRole(pMnode->syncMgmt.sync)); - const char *roles = syncStr(TAOS_SYNC_STATE_FOLLOWER); - if (pObj->id == pMnode->selfId) { + const char *roles = NULL; + if (pObj->id == pMnode->selfDnodeId) { roles = syncStr(TAOS_SYNC_STATE_LEADER); + } else { + roles = syncStr(pObj->state); } char *b2 = taosMemoryCalloc(1, 12 + VARSTR_HEADER_SIZE); STR_WITH_MAXSIZE_TO_VARSTR(b2, roles, pShow->pMeta->pSchemas[cols].bytes); diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 231cecf58e..f6b07fd880 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -196,9 +196,8 @@ void mndSyncStop(SMnode *pMnode) {} bool mndIsMaster(SMnode *pMnode) { SSyncMgmt *pMgmt = &pMnode->syncMgmt; - pMgmt->state = syncGetMyRole(pMgmt->sync); - - return (pMgmt->state == TAOS_SYNC_STATE_LEADER) && (pMnode->syncMgmt.restored); + ESyncState state = syncGetMyRole(pMgmt->sync); + return (state == TAOS_SYNC_STATE_LEADER) && (pMnode->syncMgmt.restored); } int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 5cc19f8bee..4e4f69e01d 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -264,7 +264,7 @@ static void mndSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { pMnode->selfIndex = pOption->selfIndex; memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); pMnode->msgCb = pOption->msgCb; - pMnode->selfId = pOption->replicas[pOption->selfIndex].id; + pMnode->selfDnodeId = pOption->dnodeId; pMnode->syncMgmt.standby = pOption->standby; } @@ -318,7 +318,6 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) { return NULL; } - mndUpdateMnodeRole(pMnode); mDebug("mnode open successfully "); return pMnode; } @@ -519,16 +518,17 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr SMonMnodeDesc desc = {0}; desc.mnode_id = pObj->id; tstrncpy(desc.mnode_ep, pObj->pDnode->ep, sizeof(desc.mnode_ep)); - tstrncpy(desc.role, syncStr(TAOS_SYNC_STATE_LEADER), sizeof(desc.role)); - // tstrncpy(desc.role, syncStr(pObj->role), sizeof(desc.role)); - taosArrayPush(pClusterInfo->mnodes, &desc); - sdbRelease(pSdb, pObj); - if (pObj->id == pMnode->selfId) { + if (pObj->id == pMnode->selfDnodeId) { pClusterInfo->first_ep_dnode_id = pObj->id; tstrncpy(pClusterInfo->first_ep, pObj->pDnode->ep, sizeof(pClusterInfo->first_ep)); - pClusterInfo->master_uptime = (ms - pObj->roleTime) / (86400000.0f); + pClusterInfo->master_uptime = (ms - pObj->stateStartTime) / (86400000.0f); + tstrncpy(desc.role, syncStr(TAOS_SYNC_STATE_LEADER), sizeof(desc.role)); + } else { + tstrncpy(desc.role, syncStr(pObj->state), sizeof(desc.role)); } + taosArrayPush(pClusterInfo->mnodes, &desc); + sdbRelease(pSdb, pObj); } // vgroup info @@ -581,6 +581,6 @@ int32_t mndGetMonitorInfo(SMnode *pMnode, SMonClusterInfo *pClusterInfo, SMonVgr } int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad) { - pLoad->syncState = pMnode->syncMgmt.state; + pLoad->syncState = syncGetMyRole(pMnode->syncMgmt.sync); return 0; } From 08a9cabc9cbaf57e70e7a90710f376f7fda032aa Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 25 May 2022 16:47:51 +0800 Subject: [PATCH 23/32] refactor: let all operations of mnode into the sync log --- source/dnode/mgmt/mgmt_mnode/inc/mmInt.h | 1 - 1 file changed, 1 deletion(-) diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h index 030d4b309e..854c06a0c4 100644 --- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h @@ -36,7 +36,6 @@ typedef struct SMnodeMgmt { SSingleWorker monitorWorker; SReplica replicas[TSDB_MAX_REPLICA]; int8_t replica; - int8_t selfIndex; bool stopped; int32_t refCount; TdThreadRwlock lock; From 8011ea777ff6eac86cbaf080ea5d841298da7937 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Wed, 25 May 2022 09:16:16 +0000 Subject: [PATCH 24/32] make compile --- source/dnode/vnode/src/tsdb/tsdbSnapshot.c | 1 + 1 file changed, 1 insertion(+) diff --git a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c index f40cab600f..79989a5560 100644 --- a/source/dnode/vnode/src/tsdb/tsdbSnapshot.c +++ b/source/dnode/vnode/src/tsdb/tsdbSnapshot.c @@ -16,6 +16,7 @@ #include "tsdb.h" struct STsdbSnapshotReader { + STsdb* pTsdb; // TODO }; From a9c54ae70155a6fc3ac5e7b1bc9ee7a1e4c63b45 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 25 May 2022 15:54:49 +0800 Subject: [PATCH 25/32] enh(tmq): support restart --- source/dnode/vnode/src/tq/tq.c | 123 ++++++++++++++++++++------------- 1 file changed, 75 insertions(+), 48 deletions(-) diff --git a/source/dnode/vnode/src/tq/tq.c b/source/dnode/vnode/src/tq/tq.c index 979db9169e..0e8835357a 100644 --- a/source/dnode/vnode/src/tq/tq.c +++ b/source/dnode/vnode/src/tq/tq.c @@ -51,6 +51,47 @@ int tqExecKeyCompare(const void* pKey1, int32_t kLen1, const void* pKey2, int32_ return strcmp(pKey1, pKey2); } +int32_t tqStoreExec(STQ* pTq, const char* key, const STqExec* pExec) { + int32_t code; + int32_t vlen; + tEncodeSize(tEncodeSTqExec, pExec, vlen, code); + ASSERT(code == 0); + + void* buf = taosMemoryCalloc(1, vlen); + if (buf == NULL) { + ASSERT(0); + } + + SEncoder encoder; + tEncoderInit(&encoder, buf, vlen); + + if (tEncodeSTqExec(&encoder, pExec) < 0) { + ASSERT(0); + } + + TXN txn; + + if (tdbTxnOpen(&txn, 0, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED) < 0) { + ASSERT(0); + } + + if (tdbBegin(pTq->pMetaStore, &txn) < 0) { + ASSERT(0); + } + + if (tdbTbUpsert(pTq->pExecStore, key, (int)strlen(key), buf, vlen, &txn) < 0) { + ASSERT(0); + } + + if (tdbCommit(pTq->pMetaStore, &txn) < 0) { + ASSERT(0); + } + + tEncoderClear(&encoder); + taosMemoryFree(buf); + return 0; +} + STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal) { STQ* pTq = taosMemoryMalloc(sizeof(STQ)); if (pTq == NULL) { @@ -96,8 +137,31 @@ STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal) { int vLen; tdbTbcMoveToFirst(pCur); + SDecoder decoder; while (tdbTbcNext(pCur, &pKey, &kLen, &pVal, &vLen) == 0) { - // create, put into execsj + STqExec exec; + tDecoderInit(&decoder, (uint8_t*)pVal, vLen); + tDecodeSTqExec(&decoder, &exec); + exec.pWalReader = walOpenReadHandle(pTq->pVnode->pWal); + if (exec.subType == TOPIC_SUB_TYPE__TABLE) { + for (int32_t i = 0; i < 5; i++) { + exec.pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta); + + SReadHandle handle = { + .reader = exec.pExecReader[i], + .meta = pTq->pVnode->pMeta, + .pMsgCb = &pTq->pVnode->msgCb, + }; + exec.task[i] = qCreateStreamExecTaskInfo(exec.qmsg, &handle); + ASSERT(exec.task[i]); + } + } else { + for (int32_t i = 0; i < 5; i++) { + exec.pExecReader[i] = tqInitSubmitMsgScanner(pTq->pVnode->pMeta); + } + exec.pDropTbUid = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK); + } + taosHashPut(pTq->execs, pKey, kLen, &exec, sizeof(STqExec)); } if (tdbTxnClose(&txn) < 0) { @@ -604,7 +668,9 @@ int32_t tqProcessVgDeleteReq(STQ* pTq, char* msg, int32_t msgLen) { ASSERT(0); } - tdbTbDelete(pTq->pExecStore, pReq->subKey, (int)strlen(pReq->subKey), &txn); + if (tdbTbDelete(pTq->pExecStore, pReq->subKey, (int)strlen(pReq->subKey), &txn) < 0) { + /*ASSERT(0);*/ + } if (tdbCommit(pTq->pMetaStore, &txn) < 0) { ASSERT(0); @@ -659,60 +725,21 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) { } taosHashPut(pTq->execs, req.subKey, strlen(req.subKey), pExec, sizeof(STqExec)); - int32_t code; - int32_t vlen; - tEncodeSize(tEncodeSTqExec, pExec, vlen, code); - ASSERT(code == 0); - - void* buf = taosMemoryCalloc(1, vlen); - if (buf == NULL) { - ASSERT(0); + if (tqStoreExec(pTq, req.subKey, pExec) < 0) { + // TODO } - - SEncoder encoder; - tEncoderInit(&encoder, buf, vlen); - - if (tEncodeSTqExec(&encoder, pExec) < 0) { - ASSERT(0); - } - - TXN txn; - - if (tdbTxnOpen(&txn, 0, tdbDefaultMalloc, tdbDefaultFree, NULL, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED) < 0) { - ASSERT(0); - } - - if (tdbBegin(pTq->pMetaStore, &txn) < 0) { - ASSERT(0); - } - - if (tdbTbUpsert(pTq->pExecStore, req.subKey, (int)strlen(req.subKey), buf, vlen, &txn) < 0) { - ASSERT(0); - } - - if (tdbCommit(pTq->pMetaStore, &txn) < 0) { - ASSERT(0); - } - - tEncoderClear(&encoder); - taosMemoryFree(buf); - return 0; } else { - /*if (req.newConsumerId != -1) {*/ - /*taosWLockLatch(&pExec->lock);*/ - ASSERT(pExec->consumerId == req.oldConsumerId); + /*ASSERT(pExec->consumerId == req.oldConsumerId);*/ // TODO handle qmsg and exec modification atomic_store_32(&pExec->epoch, -1); atomic_store_64(&pExec->consumerId, req.newConsumerId); atomic_add_fetch_32(&pExec->epoch, 1); - /*taosWUnLockLatch(&pExec->lock);*/ + + if (tqStoreExec(pTq, req.subKey, pExec) < 0) { + // TODO + } return 0; - /*} else {*/ - // TODO - /*taosHashRemove(pTq->tqMetaNew, req.subKey, strlen(req.subKey));*/ - /*return 0;*/ - /*}*/ } } From 1100ec3fb3f6c51c6230a03f9cd8b3d4be882e2d Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 25 May 2022 17:44:43 +0800 Subject: [PATCH 26/32] refacor: alter mnode --- include/dnode/mnode/mnode.h | 9 ---- source/dnode/mgmt/mgmt_mnode/inc/mmInt.h | 1 - source/dnode/mgmt/mgmt_mnode/src/mmHandle.c | 16 ------- source/dnode/mgmt/mgmt_mnode/src/mmInt.c | 40 ---------------- source/dnode/mgmt/mgmt_mnode/src/mmWorker.c | 3 -- source/dnode/mnode/impl/src/mndMnode.c | 51 +++++++++++++++++++++ source/dnode/mnode/impl/src/mndSync.c | 30 +++--------- tests/script/tsim/mnode/basic2.sim | 2 +- 8 files changed, 59 insertions(+), 93 deletions(-) diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index bc14dc3210..ddd6f1c05f 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -55,15 +55,6 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption); */ void mndClose(SMnode *pMnode); -/** - * @brief Close a mnode. - * - * @param pMnode The mnode object to close. - * @param pOption Options of the mnode. - * @return int32_t 0 for success, -1 for failure. - */ -int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption); - /** * @brief Start mnode * diff --git a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h index 854c06a0c4..bd034fe7d6 100644 --- a/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h +++ b/source/dnode/mgmt/mgmt_mnode/inc/mmInt.h @@ -46,7 +46,6 @@ int32_t mmReadFile(SMnodeMgmt *pMgmt, bool *pDeployed); int32_t mmWriteFile(SMnodeMgmt *pMgmt, SDCreateMnodeReq *pMsg, bool deployed); // mmInt.c -int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pMsg); int32_t mmAcquire(SMnodeMgmt *pMgmt); void mmRelease(SMnodeMgmt *pMgmt); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c index a894a4962d..90d7b88859 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmHandle.c @@ -124,22 +124,6 @@ int32_t mmProcessDropReq(const SMgmtInputOpt *pInput, SRpcMsg *pMsg) { return 0; } -int32_t mmProcessAlterReq(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) { - SDAlterMnodeReq alterReq = {0}; - if (tDeserializeSDCreateMnodeReq(pMsg->pCont, pMsg->contLen, &alterReq) != 0) { - terrno = TSDB_CODE_INVALID_MSG; - return -1; - } - - if (pMgmt->pData->dnodeId != 0 && alterReq.dnodeId != pMgmt->pData->dnodeId) { - terrno = TSDB_CODE_INVALID_OPTION; - dError("failed to alter mnode since %s, input:%d cur:%d", terrstr(), alterReq.dnodeId, pMgmt->pData->dnodeId); - return -1; - } else { - return mmAlter(pMgmt, &alterReq); - } -} - SArray *mmGetMsgHandles() { int32_t code = -1; SArray *pArray = taosArrayInit(64, sizeof(SMgmtHandle)); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c index 964c2d42b7..1b973f3045 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmInt.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmInt.c @@ -73,46 +73,6 @@ static void mmBuildOptionForOpen(SMnodeMgmt *pMgmt, SMnodeOpt *pOption) { } } -static int32_t mmBuildOptionForAlter(SMnodeMgmt *pMgmt, SMnodeOpt *pOption, SDCreateMnodeReq *pCreate) { - pOption->standby = false; - pOption->deploy = false; - pOption->msgCb = pMgmt->msgCb; - pOption->dnodeId = pMgmt->pData->dnodeId; - - pOption->replica = pCreate->replica; - pOption->selfIndex = -1; - - for (int32_t i = 0; i < pCreate->replica; ++i) { - SReplica *pReplica = &pOption->replicas[i]; - pReplica->id = pCreate->replicas[i].id; - pReplica->port = pCreate->replicas[i].port; - memcpy(pReplica->fqdn, pCreate->replicas[i].fqdn, TSDB_FQDN_LEN); - if (pReplica->id == pMgmt->pData->dnodeId) { - pOption->selfIndex = i; - } - } - - if (pOption->selfIndex == -1) { - dError("failed to build mnode options since %s", terrstr()); - return -1; - } - - return 0; -} - -int32_t mmAlter(SMnodeMgmt *pMgmt, SDAlterMnodeReq *pMsg) { - SMnodeOpt option = {0}; - if (mmBuildOptionForAlter(pMgmt, &option, pMsg) != 0) { - return -1; - } - - if (mndAlter(pMgmt->pMnode, &option) != 0) { - return -1; - } - - return 0; -} - static void mmClose(SMnodeMgmt *pMgmt) { if (pMgmt->pMnode != NULL) { mmStopWorker(pMgmt); diff --git a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c index 71cc2d2693..85120102bc 100644 --- a/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c +++ b/source/dnode/mgmt/mgmt_mnode/src/mmWorker.c @@ -32,9 +32,6 @@ static void mmProcessQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { dTrace("msg:%p, get from mnode queue", pMsg); switch (pMsg->msgType) { - case TDMT_DND_ALTER_MNODE: - code = mmProcessAlterReq(pMgmt, pMsg); - break; case TDMT_MON_MM_INFO: code = mmProcessGetMonitorInfoReq(pMgmt, pMsg); break; diff --git a/source/dnode/mnode/impl/src/mndMnode.c b/source/dnode/mnode/impl/src/mndMnode.c index 93284a95c5..a47221ea39 100644 --- a/source/dnode/mnode/impl/src/mndMnode.c +++ b/source/dnode/mnode/impl/src/mndMnode.c @@ -31,6 +31,7 @@ static int32_t mndMnodeActionInsert(SSdb *pSdb, SMnodeObj *pObj); static int32_t mndMnodeActionDelete(SSdb *pSdb, SMnodeObj *pObj); static int32_t mndMnodeActionUpdate(SSdb *pSdb, SMnodeObj *pOld, SMnodeObj *pNew); static int32_t mndProcessCreateMnodeReq(SRpcMsg *pReq); +static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq); static int32_t mndProcessDropMnodeReq(SRpcMsg *pReq); static int32_t mndProcessCreateMnodeRsp(SRpcMsg *pRsp); static int32_t mndProcessAlterMnodeRsp(SRpcMsg *pRsp); @@ -51,6 +52,7 @@ int32_t mndInitMnode(SMnode *pMnode) { }; mndSetMsgHandle(pMnode, TDMT_MND_CREATE_MNODE, mndProcessCreateMnodeReq); + mndSetMsgHandle(pMnode, TDMT_DND_ALTER_MNODE, mndProcessAlterMnodeReq); mndSetMsgHandle(pMnode, TDMT_MND_DROP_MNODE, mndProcessDropMnodeReq); mndSetMsgHandle(pMnode, TDMT_DND_CREATE_MNODE_RSP, mndProcessCreateMnodeRsp); mndSetMsgHandle(pMnode, TDMT_DND_ALTER_MNODE_RSP, mndProcessAlterMnodeRsp); @@ -658,3 +660,52 @@ static void mndCancelGetNextMnode(SMnode *pMnode, void *pIter) { SSdb *pSdb = pMnode->pSdb; sdbCancelFetch(pSdb, pIter); } + +static int32_t mndProcessAlterMnodeReq(SRpcMsg *pReq) { + SMnode *pMnode = pReq->info.node; + SDAlterMnodeReq alterReq = {0}; + + if (tDeserializeSDCreateMnodeReq(pReq->pCont, pReq->contLen, &alterReq) != 0) { + terrno = TSDB_CODE_INVALID_MSG; + return -1; + } + + if (alterReq.dnodeId != pMnode->selfDnodeId) { + terrno = TSDB_CODE_INVALID_OPTION; + mError("failed to alter mnode since %s, input:%d cur:%d", terrstr(), alterReq.dnodeId, pMnode->selfDnodeId); + return -1; + } + + SSyncCfg cfg = {.replicaNum = alterReq.replica, .myIndex = -1}; + for (int32_t i = 0; i < alterReq.replica; ++i) { + SNodeInfo *pNode = &cfg.nodeInfo[i]; + tstrncpy(pNode->nodeFqdn, alterReq.replicas[i].fqdn, sizeof(pNode->nodeFqdn)); + pNode->nodePort = alterReq.replicas[i].port; + if (alterReq.replicas[i].id == pMnode->selfDnodeId) cfg.myIndex = i; + } + + if (cfg.myIndex == -1) { + mError("failed to alter mnode since myindex is -1"); + return -1; + } else { + mInfo("start to alter mnode sync, replica:%d myindex:%d", cfg.replicaNum, cfg.myIndex); + for (int32_t i = 0; i < alterReq.replica; ++i) { + SNodeInfo *pNode = &cfg.nodeInfo[i]; + mInfo("index:%d, fqdn:%s port:%d", i, pNode->nodeFqdn, pNode->nodePort); + } + } + + SSyncMgmt *pMgmt = &pMnode->syncMgmt; + pMgmt->standby = 0; + int32_t code = syncReconfig(pMgmt->sync, &cfg); + if (code != 0) { + mError("failed to alter mnode sync since %s", terrstr()); + return code; + } else { + pMgmt->errCode = 0; + tsem_wait(&pMgmt->syncSem); + mInfo("alter mnode sync result:%s", tstrerror(pMgmt->errCode)); + terrno = pMgmt->errCode; + return pMgmt->errCode; + } +} diff --git a/source/dnode/mnode/impl/src/mndSync.c b/source/dnode/mnode/impl/src/mndSync.c index 47f11b652e..ca25133c96 100644 --- a/source/dnode/mnode/impl/src/mndSync.c +++ b/source/dnode/mnode/impl/src/mndSync.c @@ -74,14 +74,13 @@ int32_t mndSnapshotApply(struct SSyncFSM* pFsm, const SSnapshot* pSnapshot, char sdbWrite(pMnode->pSdb, (SSdbRaw*)pBuf); return 0; } - -void mndReConfig(struct SSyncFSM* pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) { - mInfo("mndReConfig cbMeta.code:%d, cbMeta.currentTerm:%ld, cbMeta.term:%ld, cbMeta.index:%ld", cbMeta.code, cbMeta.currentTerm, cbMeta.term, cbMeta.index); - if (cbMeta.code == 0) { - // config change success - } else { - // config change failed - } + +void mndReConfig(struct SSyncFSM *pFsm, SSyncCfg newCfg, SReConfigCbMeta cbMeta) { + mInfo("mndReConfig cbMeta.code:%d, cbMeta.currentTerm:%" PRId64 ", cbMeta.term:%" PRId64 ", cbMeta.index:%" PRId64, + cbMeta.code, cbMeta.currentTerm, cbMeta.term, cbMeta.index); + SMnode *pMnode = pFsm->data; + pMnode->syncMgmt.errCode = cbMeta.code; + tsem_post(&pMnode->syncMgmt.syncSem); } SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) { @@ -207,18 +206,3 @@ bool mndIsMaster(SMnode *pMnode) { ESyncState state = syncGetMyRole(pMgmt->sync); return (state == TAOS_SYNC_STATE_LEADER) && (pMnode->syncMgmt.restored); } - -int32_t mndAlter(SMnode *pMnode, const SMnodeOpt *pOption) { - SSyncCfg cfg = {.replicaNum = pOption->replica, .myIndex = pOption->selfIndex}; - mInfo("start to alter mnode sync, replica:%d myindex:%d standby:%d", cfg.replicaNum, cfg.myIndex, pOption->standby); - for (int32_t i = 0; i < pOption->replica; ++i) { - SNodeInfo *pNode = &cfg.nodeInfo[i]; - tstrncpy(pNode->nodeFqdn, pOption->replicas[i].fqdn, sizeof(pNode->nodeFqdn)); - pNode->nodePort = pOption->replicas[i].port; - mInfo("index:%d, fqdn:%s port:%d", i, pNode->nodeFqdn, pNode->nodePort); - } - - SSyncMgmt *pMgmt = &pMnode->syncMgmt; - pMgmt->standby = pOption->standby; - return syncReconfig(pMgmt->sync, &cfg); -} \ No newline at end of file diff --git a/tests/script/tsim/mnode/basic2.sim b/tests/script/tsim/mnode/basic2.sim index f293718285..f1a3a8c251 100644 --- a/tests/script/tsim/mnode/basic2.sim +++ b/tests/script/tsim/mnode/basic2.sim @@ -60,7 +60,7 @@ endi if $data(2)[0] != 2 then return -1 endi -if $data(2)[2] != FOLLOWER then +if $data(2)[2] == LEADER then return -1 endi From 356c9e90569dbc395bc53f8787f60906b19bad94 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Wed, 25 May 2022 17:55:34 +0800 Subject: [PATCH 27/32] fix(query): set correct expression number in project operator. --- source/libs/executor/src/executorimpl.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index e16b60e58b..232333ffb7 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -1748,8 +1748,7 @@ void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t SResultRow* pRow = doSetResultOutBufByKey(pSup->pResultBuf, pResultRowInfo, (char*)&tid, sizeof(tid), true, groupId, pTaskInfo, false, pSup); - ASSERT(pDataBlock->info.numOfCols == numOfExprs); - for (int32_t i = 0; i < pDataBlock->info.numOfCols; ++i) { + for (int32_t i = 0; i < numOfExprs; ++i) { struct SResultRowEntryInfo* pEntry = getResultCell(pRow, i, rowCellInfoOffset); cleanupResultRowEntry(pEntry); @@ -1757,7 +1756,7 @@ void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t pCtx[i].scanFlag = stage; } - initCtxOutputBuffer(pCtx, pDataBlock->info.numOfCols); + initCtxOutputBuffer(pCtx, numOfExprs); } void updateOutputBuf(SOptrBasicInfo* pBInfo, int32_t* bufCapacity, int32_t numOfInputRows) { From 84cf8ff273bd9ab74b3ec8711c0e163648342b98 Mon Sep 17 00:00:00 2001 From: jiajingbin Date: Wed, 25 May 2022 18:00:58 +0800 Subject: [PATCH 28/32] test: add debug cases --- tests/pytest/stream/test1.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/pytest/stream/test1.py diff --git a/tests/pytest/stream/test1.py b/tests/pytest/stream/test1.py new file mode 100644 index 0000000000..d3439a7bdb --- /dev/null +++ b/tests/pytest/stream/test1.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- + +import sys +from util.log import * +from util.cases import * +from util.sql import * +class TDTestCase: + def init(self, conn, logSql): + tdLog.debug("start to execute %s" % __file__) + tdSql.init(conn.cursor(), logSql) + + def run(self): + tdSql.prepare() + tdSql.execute('drop database if exists slmfvojuxt;') + tdSql.execute('create database if not exists slmfvojuxt vgroups 1;') + tdSql.execute('use slmfvojuxt;') + tdSql.execute('create table if not exists downsampling_stb (ts timestamp, c1 int, c2 double, c3 varchar(100), c4 bool) tags (t1 int, t2 double, t3 varchar(100), t4 bool);') + tdSql.execute('create table ownsampling_ct1 using downsampling_stb tags(10, 10.1, "beijing", True);') + tdSql.execute('create table if not exists scalar_stb (ts timestamp, c1 int, c2 double, c3 binary(20)) tags (t1 int);') + tdSql.execute('create table scalar_ct1 using scalar_stb tags(10);') + tdSql.execute('create stream downsampling_stream into output_downsampling_stb as select _wstartts AS start, min(c1), max(c2), sum(c1) from downsampling_stb interval(10m);') + tdSql.execute('create stream scalar_stream into output_scalar_stb as select ts, abs(c1) a1 , abs(c2) a2 from scalar_stb;') + tdSql.execute('insert into scalar_ct1 values (1653471881952, 100, 100.1, "beijing");') + tdSql.execute('insert into scalar_ct1 values (1653471881952+1s, -50, -50.1, "tianjin");') + def stop(self): + tdSql.close() + tdLog.success("%s successfully executed" % __file__) + + +tdCases.addWindows(__file__, TDTestCase()) +tdCases.addLinux(__file__, TDTestCase()) From ae9c03e7f51043a85f1ba21f49edf054f5957382 Mon Sep 17 00:00:00 2001 From: 54liuyao <54liuyao@163.com> Date: Wed, 25 May 2022 14:41:18 +0800 Subject: [PATCH 29/32] ci(stream): close session test --- tests/script/jenkins/basic.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/script/jenkins/basic.txt b/tests/script/jenkins/basic.txt index 03744768c9..a8f96cccf1 100644 --- a/tests/script/jenkins/basic.txt +++ b/tests/script/jenkins/basic.txt @@ -68,8 +68,8 @@ ./test.sh -f tsim/stream/basic0.sim ./test.sh -f tsim/stream/basic1.sim ./test.sh -f tsim/stream/basic2.sim -./test.sh -f tsim/stream/session0.sim -./test.sh -f tsim/stream/session1.sim +# ./test.sh -f tsim/stream/session0.sim +# ./test.sh -f tsim/stream/session1.sim # ---- transaction ./test.sh -f tsim/trans/lossdata1.sim From 79e97271ca0997853beaeca251a6a2c3140b0bd5 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 25 May 2022 18:43:25 +0800 Subject: [PATCH 30/32] fix(stream): memory error --- include/libs/stream/tstream.h | 2 +- source/libs/stream/src/tstream.c | 7 +- tests/pytest/stream/cqSupportBefore1970.py | 93 --------- tests/pytest/stream/history.py | 67 ------- tests/pytest/stream/metric_1.py | 104 ---------- tests/pytest/stream/metric_n.py | 123 ------------ tests/pytest/stream/new.py | 79 -------- tests/pytest/stream/parser.py | 182 ------------------ .../pytest/stream/showStreamExecTimeisNull.py | 98 ---------- tests/pytest/stream/stream1.py | 142 -------------- tests/pytest/stream/stream2.py | 164 ---------------- tests/pytest/stream/stream3.py | 108 ----------- tests/pytest/stream/sys.py | 62 ------ tests/pytest/stream/table_1.py | 89 --------- tests/pytest/stream/table_n.py | 143 -------------- 15 files changed, 5 insertions(+), 1458 deletions(-) delete mode 100644 tests/pytest/stream/cqSupportBefore1970.py delete mode 100644 tests/pytest/stream/history.py delete mode 100644 tests/pytest/stream/metric_1.py delete mode 100644 tests/pytest/stream/metric_n.py delete mode 100644 tests/pytest/stream/new.py delete mode 100644 tests/pytest/stream/parser.py delete mode 100644 tests/pytest/stream/showStreamExecTimeisNull.py delete mode 100644 tests/pytest/stream/stream1.py delete mode 100644 tests/pytest/stream/stream2.py delete mode 100644 tests/pytest/stream/stream3.py delete mode 100644 tests/pytest/stream/sys.py delete mode 100644 tests/pytest/stream/table_1.py delete mode 100644 tests/pytest/stream/table_n.py diff --git a/include/libs/stream/tstream.h b/include/libs/stream/tstream.h index d18f609d54..55e8cf0050 100644 --- a/include/libs/stream/tstream.h +++ b/include/libs/stream/tstream.h @@ -107,7 +107,7 @@ static FORCE_INLINE void streamDataSubmitRefDec(SStreamDataSubmit* pDataSubmit) if (ref == 0) { taosMemoryFree(pDataSubmit->data); taosMemoryFree(pDataSubmit->dataRef); - // taosFreeQitem(pDataSubmit); + taosFreeQitem(pDataSubmit); } } diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index 0acec0e4e6..dd7e38a458 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -166,6 +166,7 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) streamDataSubmitRefDec((SStreamDataSubmit*)data); } else { taosArrayDestroyEx(((SStreamDataBlock*)data)->blocks, (FDelete)tDeleteSSDataBlock); + taosFreeQitem(data); } return 0; } @@ -186,7 +187,7 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) { streamTaskExecImpl(pTask, data, pRes); - taosFreeQitem(data); + /*taosFreeQitem(data);*/ if (taosArrayGetSize(pRes) != 0) { SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); @@ -206,7 +207,7 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) { streamTaskExecImpl(pTask, data, pRes); - taosFreeQitem(data); + /*taosFreeQitem(data);*/ if (taosArrayGetSize(pRes) != 0) { SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); @@ -228,7 +229,7 @@ int32_t streamExec(SStreamTask* pTask, SMsgCb* pMsgCb) { streamTaskExecImpl(pTask, data, pRes); - taosFreeQitem(data); + /*taosFreeQitem(data);*/ if (taosArrayGetSize(pRes) != 0) { SStreamDataBlock* resQ = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM); diff --git a/tests/pytest/stream/cqSupportBefore1970.py b/tests/pytest/stream/cqSupportBefore1970.py deleted file mode 100644 index 01ba5234fc..0000000000 --- a/tests/pytest/stream/cqSupportBefore1970.py +++ /dev/null @@ -1,93 +0,0 @@ -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug(f"start to execute {__file__}") - tdSql.init(conn.cursor(), logSql) - - def insertnow(self): - - # timestamp list: - # 0 -> "1970-01-01 08:00:00" | -28800000 -> "1970-01-01 00:00:00" | -946800000000 -> "1940-01-01 00:00:00" - # -631180800000 -> "1950-01-01 00:00:00" - - tsp1 = 0 - tsp2 = -28800000 - tsp3 = -946800000000 - tsp4 = "1969-01-01 00:00:00.000" - - tdSql.execute("insert into tcq1 values (now-11d, 5)") - tdSql.execute(f"insert into tcq1 values ({tsp1}, 4)") - tdSql.execute(f"insert into tcq1 values ({tsp2}, 3)") - tdSql.execute(f"insert into tcq1 values ('{tsp4}', 2)") - tdSql.execute(f"insert into tcq1 values ({tsp3}, 1)") - - def waitedQuery(self, sql, expectRows, timeout): - tdLog.info(f"sql: {sql}, try to retrieve {expectRows} rows in {timeout} seconds") - try: - for i in range(timeout): - tdSql.cursor.execute(sql) - self.queryResult = tdSql.cursor.fetchall() - self.queryRows = len(self.queryResult) - self.queryCols = len(tdSql.cursor.description) - # tdLog.info("sql: %s, try to retrieve %d rows,get %d rows" % (sql, expectRows, self.queryRows)) - if self.queryRows >= expectRows: - return (self.queryRows, i) - time.sleep(1) - except Exception as e: - caller = inspect.getframeinfo(inspect.stack()[1][0]) - tdLog.notice(f"{caller.filename}({caller.lineno}) failed: sql:{sql}, {repr(e)}") - raise Exception(repr(e)) - return (self.queryRows, timeout) - - def cq(self): - tdSql.execute( - "create table cq1 as select avg(c1) from tcq1 where ts > -946800000000 interval(10d) sliding(1d)" - ) - self.waitedQuery("select * from cq1", 1, 120) - - def querycq(self): - tdSql.query("select * from cq1") - tdSql.checkData(0, 1, 1.0) - tdSql.checkData(10, 1, 2.0) - - def run(self): - tdSql.execute("drop database if exists dbcq") - tdSql.execute("create database if not exists dbcq keep 36500") - tdSql.execute("use dbcq") - - tdSql.execute("create table stbcq (ts timestamp, c1 int ) TAGS(t1 int)") - tdSql.execute("create table tcq1 using stbcq tags(1)") - - self.insertnow() - self.cq() - self.querycq() - - # after wal and sync, check again - tdSql.query("show dnodes") - index = tdSql.getData(0, 0) - tdDnodes.stop(index) - tdDnodes.start(index) - - self.querycq() - - def stop(self): - tdSql.close() - tdLog.success(f"{__file__} successfully executed") - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/pytest/stream/history.py b/tests/pytest/stream/history.py deleted file mode 100644 index cb8a4d5986..0000000000 --- a/tests/pytest/stream/history.py +++ /dev/null @@ -1,67 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def run(self): - tdSql.prepare() - - tdSql.execute("create table cars(ts timestamp, s int) tags(id int)") - tdSql.execute("create table car0 using cars tags(0)") - tdSql.execute("create table car1 using cars tags(1)") - tdSql.execute("create table car2 using cars tags(2)") - tdSql.execute("create table car3 using cars tags(3)") - tdSql.execute("create table car4 using cars tags(4)") - - tdSql.execute("insert into car0 values('2019-01-01 00:00:00.103', 1)") - tdSql.execute("insert into car1 values('2019-01-01 00:00:00.234', 1)") - tdSql.execute("insert into car0 values('2019-01-01 00:00:01.012', 1)") - tdSql.execute("insert into car0 values('2019-01-01 00:00:02.003', 1)") - tdSql.execute("insert into car2 values('2019-01-01 00:00:02.328', 1)") - tdSql.execute("insert into car0 values('2019-01-01 00:00:03.139', 1)") - tdSql.execute("insert into car0 values('2019-01-01 00:00:04.348', 1)") - tdSql.execute("insert into car0 values('2019-01-01 00:00:05.783', 1)") - tdSql.execute("insert into car1 values('2019-01-01 00:00:01.893', 1)") - tdSql.execute("insert into car1 values('2019-01-01 00:00:02.712', 1)") - tdSql.execute("insert into car1 values('2019-01-01 00:00:03.982', 1)") - tdSql.execute("insert into car3 values('2019-01-01 00:00:01.389', 1)") - tdSql.execute("insert into car4 values('2019-01-01 00:00:01.829', 1)") - - tdSql.error("create table strm as select count(*) from cars") - - tdSql.execute("create table strm as select count(*) from cars interval(4s)") - tdSql.waitedQuery("select * from strm", 2, 100) - tdSql.checkData(0, 1, 11) - tdSql.checkData(1, 1, 2) - - - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/stream/metric_1.py b/tests/pytest/stream/metric_1.py deleted file mode 100644 index b4cccac69c..0000000000 --- a/tests/pytest/stream/metric_1.py +++ /dev/null @@ -1,104 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def createFuncStream(self, expr, suffix, value): - tbname = "strm_" + suffix - tdLog.info("create stream table %s" % tbname) - tdSql.query("select %s from stb interval(1d)" % expr) - tdSql.checkData(0, 1, value) - tdSql.execute("create table %s as select %s from stb interval(1d)" % (tbname, expr)) - - def checkStreamData(self, suffix, value): - sql = "select * from strm_" + suffix - tdSql.waitedQuery(sql, 1, 120) - tdSql.checkData(0, 1, value) - - def run(self): - tbNum = 10 - rowNum = 20 - - tdSql.prepare() - - tdLog.info("===== preparing data =====") - tdSql.execute( - "create table stb(ts timestamp, tbcol int, tbcol2 float) tags(tgcol int)") - for i in range(tbNum): - tdSql.execute("create table tb%d using stb tags(%d)" % (i, i)) - for j in range(rowNum): - tdSql.execute( - "insert into tb%d values (now - %dm, %d, %d)" % - (i, 1440 - j, j, j)) - time.sleep(0.1) - - self.createFuncStream("count(*)", "c1", 200) - self.createFuncStream("count(tbcol)", "c2", 200) - self.createFuncStream("count(tbcol2)", "c3", 200) - self.createFuncStream("avg(tbcol)", "av", 9.5) - self.createFuncStream("sum(tbcol)", "su", 1900) - self.createFuncStream("min(tbcol)", "mi", 0) - self.createFuncStream("max(tbcol)", "ma", 19) - self.createFuncStream("first(tbcol)", "fi", 0) - self.createFuncStream("last(tbcol)", "la", 19) - #tdSql.query("select stddev(tbcol) from stb interval(1d)") - #tdSql.query("select leastsquares(tbcol, 1, 1) from stb interval(1d)") - tdSql.query("select top(tbcol, 1) from stb interval(1d)") - tdSql.query("select bottom(tbcol, 1) from stb interval(1d)") - #tdSql.query("select percentile(tbcol, 1) from stb interval(1d)") - #tdSql.query("select diff(tbcol) from stb interval(1d)") - - tdSql.query("select count(tbcol) from stb where ts < now + 4m interval(1d)") - tdSql.checkData(0, 1, 200) - #tdSql.execute("create table strm_wh as select count(tbcol) from stb where ts < now + 4m interval(1d)") - - self.createFuncStream("count(tbcol)", "as", 200) - - tdSql.query("select count(tbcol) from stb interval(1d) group by tgcol") - tdSql.checkData(0, 1, 20) - - tdSql.query("select count(tbcol) from stb where ts < now + 4m interval(1d) group by tgcol") - tdSql.checkData(0, 1, 20) - - self.checkStreamData("c1", 200) - self.checkStreamData("c2", 200) - self.checkStreamData("c3", 200) - self.checkStreamData("av", 9.5) - self.checkStreamData("su", 1900) - self.checkStreamData("mi", 0) - self.checkStreamData("ma", 19) - self.checkStreamData("fi", 0) - self.checkStreamData("la", 19) - #self.checkStreamData("wh", 200) - self.checkStreamData("as", 200) - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) - - diff --git a/tests/pytest/stream/metric_n.py b/tests/pytest/stream/metric_n.py deleted file mode 100644 index d223fe81fc..0000000000 --- a/tests/pytest/stream/metric_n.py +++ /dev/null @@ -1,123 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def run(self): - tbNum = 10 - rowNum = 20 - totalNum = tbNum * rowNum - - tdSql.prepare() - - tdLog.info("===== preparing data =====") - tdSql.execute( - "create table stb(ts timestamp, tbcol int, tbcol2 float) tags(tgcol int)") - for i in range(tbNum): - tdSql.execute("create table tb%d using stb tags(%d)" % (i, i)) - for j in range(rowNum): - tdSql.execute( - "insert into tb%d values (now - %dm, %d, %d)" % - (i, 1440 - j, j, j)) - time.sleep(0.1) - - tdLog.info("===== step 1 =====") - tdSql.query("select count(*), count(tbcol), count(tbcol2) from stb interval(1d)") - tdSql.checkData(0, 1, totalNum) - tdSql.checkData(0, 2, totalNum) - tdSql.checkData(0, 3, totalNum) - - tdLog.info("===== step 2 =====") - tdSql.execute("create table strm_c3 as select count(*), count(tbcol), count(tbcol2) from stb interval(1d)") - - tdLog.info("===== step 3 =====") - tdSql.execute("create table strm_c32 as select count(*), count(tbcol) as c1, count(tbcol2) as c2, count(tbcol) as c3, count(tbcol) as c4, count(tbcol) as c5, count(tbcol) as c6, count(tbcol) as c7, count(tbcol) as c8, count(tbcol) as c9, count(tbcol) as c10, count(tbcol) as c11, count(tbcol) as c12, count(tbcol) as c13, count(tbcol) as c14, count(tbcol) as c15, count(tbcol) as c16, count(tbcol) as c17, count(tbcol) as c18, count(tbcol) as c19, count(tbcol) as c20, count(tbcol) as c21, count(tbcol) as c22, count(tbcol) as c23, count(tbcol) as c24, count(tbcol) as c25, count(tbcol) as c26, count(tbcol) as c27, count(tbcol) as c28, count(tbcol) as c29, count(tbcol) as c30 from stb interval(1d)") - - tdLog.info("===== step 4 =====") - tdSql.query("select count(*), count(tbcol) as c1, count(tbcol2) as c2, count(tbcol) as c3, count(tbcol) as c4, count(tbcol) as c5, count(tbcol) as c6, count(tbcol) as c7, count(tbcol) as c8, count(tbcol) as c9, count(tbcol) as c10, count(tbcol) as c11, count(tbcol) as c12, count(tbcol) as c13, count(tbcol) as c14, count(tbcol) as c15, count(tbcol) as c16, count(tbcol) as c17, count(tbcol) as c18, count(tbcol) as c19, count(tbcol) as c20, count(tbcol) as c21, count(tbcol) as c22, count(tbcol) as c23, count(tbcol) as c24, count(tbcol) as c25, count(tbcol) as c26, count(tbcol) as c27, count(tbcol) as c28, count(tbcol) as c29, count(tbcol) as c30 from stb interval(1d)") - tdSql.checkData(0, 1, totalNum) - tdSql.checkData(0, 2, totalNum) - tdSql.checkData(0, 3, totalNum) - - tdLog.info("===== step 5 =====") - tdSql.execute("create table strm_c31 as select count(*), count(tbcol) as c1, count(tbcol2) as c2, count(tbcol) as c3, count(tbcol) as c4, count(tbcol) as c5, count(tbcol) as c6, count(tbcol) as c7, count(tbcol) as c8, count(tbcol) as c9, count(tbcol) as c10, count(tbcol) as c11, count(tbcol) as c12, count(tbcol) as c13, count(tbcol) as c14, count(tbcol) as c15, count(tbcol) as c16, count(tbcol) as c17, count(tbcol) as c18, count(tbcol) as c19, count(tbcol) as c20, count(tbcol) as c21, count(tbcol) as c22, count(tbcol) as c23, count(tbcol) as c24, count(tbcol) as c25, count(tbcol) as c26, count(tbcol) as c27, count(tbcol) as c28, count(tbcol) as c29, count(tbcol) as c30 from stb interval(1d)") - - tdLog.info("===== step 6 =====") - tdSql.query("select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from stb interval(1d)") - tdSql.checkData(0, 1, 9.5) - tdSql.checkData(0, 2, 1900) - tdSql.checkData(0, 3, 0) - tdSql.checkData(0, 4, 19) - tdSql.checkData(0, 5, 0) - tdSql.checkData(0, 6, 19) - tdSql.execute("create table strm_avg as select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from stb interval(1d)") - - tdLog.info("===== step 7 =====") - tdSql.query("select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol), count(tbcol) from stb where ts < now + 4m interval(1d)") - tdSql.checkData(0, 1, 9.5) - tdSql.checkData(0, 2, 1900) - tdSql.checkData(0, 3, 0) - tdSql.checkData(0, 4, 19) - tdSql.checkData(0, 5, 0) - tdSql.checkData(0, 6, 19) - tdSql.checkData(0, 7, totalNum) - - tdLog.info("===== step 8 =====") - tdSql.query("select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol), count(tbcol) from stb where ts < now + 4m interval(1d)") - tdSql.checkData(0, 1, 9.5) - tdSql.checkData(0, 2, 1900) - tdSql.checkData(0, 3, 0) - tdSql.checkData(0, 4, 19) - tdSql.checkData(0, 5, 0) - tdSql.checkData(0, 6, 19) - tdSql.checkData(0, 7, totalNum) - - tdLog.info("===== step 9 =====") - tdSql.waitedQuery("select * from strm_c3", 1, 120) - tdSql.checkData(0, 1, totalNum) - tdSql.checkData(0, 2, totalNum) - tdSql.checkData(0, 3, totalNum) - - tdLog.info("===== step 10 =====") - tdSql.waitedQuery("select * from strm_c31", 1, 30) - for i in range(1, 10): - tdSql.checkData(0, i, totalNum) - - tdLog.info("===== step 11 =====") - tdSql.waitedQuery("select * from strm_avg", 1, 20) - tdSql.checkData(0, 1, 9.5) - tdSql.checkData(0, 2, 1900) - tdSql.checkData(0, 3, 0) - tdSql.checkData(0, 4, 19) - tdSql.checkData(0, 5, 0) - tdSql.checkData(0, 6, 19) - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/stream/new.py b/tests/pytest/stream/new.py deleted file mode 100644 index 4a0e47c01a..0000000000 --- a/tests/pytest/stream/new.py +++ /dev/null @@ -1,79 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def run(self): - rowNum = 200 - tdSql.prepare() - - tdLog.info("=============== step1") - tdSql.execute("create table mt(ts timestamp, tbcol int, tbcol2 float) TAGS(tgcol int)") - for i in range(5): - tdSql.execute("create table tb%d using mt tags(%d)" % (i, i)) - for j in range(rowNum): - tdSql.execute("insert into tb%d values(now + %ds, %d, %d)" % (i, j, j, j)) - time.sleep(0.1) - - tdLog.info("=============== step2") - tdSql.query("select count(*), count(tbcol), count(tbcol2) from mt interval(10s)") - tdSql.execute("create table st as select count(*), count(tbcol), count(tbcol2) from mt interval(10s)") - - tdLog.info("=============== step3") - start = time.time() - tdSql.waitedQuery("select * from st", 1, 180) - delay = int(time.time() - start) + 80 - v = tdSql.getData(0, 3) - if v >= 51: - tdLog.exit("value is %d, which is larger than 51" % v) - - tdLog.info("=============== step4") - for i in range(5, 10): - tdSql.execute("create table tb%d using mt tags(%d)" % (i, i)) - for j in range(rowNum): - tdSql.execute("insert into tb%d values(now + %ds, %d, %d)" % (i, j, j, j)) - - tdLog.info("=============== step5") - maxValue = 0 - for i in range(delay): - time.sleep(1) - tdSql.query("select * from st order by ts desc") - v = tdSql.getData(0, 3) - if v > maxValue: - maxValue = v - if v > 51: - break - - if maxValue <= 51: - tdLog.exit("value is %d, which is smaller than 51" % maxValue) - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) - - diff --git a/tests/pytest/stream/parser.py b/tests/pytest/stream/parser.py deleted file mode 100644 index 3b231d2b39..0000000000 --- a/tests/pytest/stream/parser.py +++ /dev/null @@ -1,182 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - ''' - def bug2222(self): - tdSql.prepare() - tdSql.execute("create table superreal(ts timestamp, addr binary(5), val float) tags (deviceNo binary(20))") - tdSql.execute("create table real_001 using superreal tags('001')") - tdSql.execute("create table tj_001 as select sum(val) from real_001 interval(1m)") - - t = datetime.datetime.now() - for i in range(60): - ts = t.strftime("%Y-%m-%d %H:%M") - t += datetime.timedelta(minutes=1) - sql = "insert into real_001 values('%s:0%d', '1', %d)" % (ts, 0, i) - for j in range(4): - sql += ",('%s:0%d', '%d', %d)" % (ts, j + 1, j + 1, i) - tdSql.execute(sql) - time.sleep(60 + random.random() * 60 - 30) - ''' - - def tbase300(self): - tdLog.debug("begin tbase300") - - tdSql.prepare() - tdSql.execute("create table mt(ts timestamp, c1 int, c2 int) tags(t1 int)") - tdSql.execute("create table tb1 using mt tags(1)"); - tdSql.execute("create table tb2 using mt tags(2)"); - tdSql.execute("create table strm as select count(*), avg(c1), sum(c2), max(c1), min(c2),first(c1), last(c2) from mt interval(4s) sliding(2s)") - #tdSql.execute("create table strm as select count(*), avg(c1), sum(c2), max(c1), min(c2), first(c1) from mt interval(4s) sliding(2s)") - tdLog.sleep(10) - tdSql.execute("insert into tb2 values(now, 1, 1)"); - tdSql.execute("insert into tb1 values(now, 1, 1)"); - tdLog.sleep(4) - tdSql.query("select * from mt") - tdSql.query("select * from strm") - tdSql.execute("drop table tb1") - - tdSql.waitedQuery("select * from strm", 1, 100) - if tdSql.queryRows < 1 or tdSql.queryRows > 2: - tdLog.exit("rows should be 1 or 2") - - tdSql.execute("drop table tb2") - tdSql.execute("drop table mt") - tdSql.execute("drop table strm") - - def tbase304(self): - tdLog.debug("begin tbase304") - # we cannot reset query cache in server side, as a workaround, - # set super table name to mt304, need to change back to mt later - tdSql.execute("create table mt304 (ts timestamp, c1 int) tags(t1 int, t2 int)") - tdSql.execute("create table tb1 using mt304 tags(1, 1)") - tdSql.execute("create table tb2 using mt304 tags(1, -1)") - time.sleep(0.1) - tdSql.execute("create table strm as select count(*), avg(c1) from mt304 where t2 >= 0 interval(4s) sliding(2s)") - tdSql.execute("insert into tb1 values (now,1)") - tdSql.execute("insert into tb2 values (now,2)") - - tdSql.waitedQuery("select * from strm", 1, 100) - if tdSql.queryRows < 1 or tdSql.queryRows > 2: - tdLog.exit("rows should be 1 or 2") - - tdSql.checkData(0, 1, 1) - tdSql.checkData(0, 2, 1.000000000) - tdSql.execute("alter table mt304 drop tag t2") - tdSql.execute("insert into tb2 values (now,2)") - tdSql.execute("insert into tb1 values (now,1)") - tdSql.query("select * from strm") - tdSql.execute("alter table mt304 add tag t2 int") - tdLog.sleep(1) - tdSql.query("select * from strm") - - def wildcardFilterOnTags(self): - tdLog.debug("begin wildcardFilterOnTag") - tdSql.prepare() - tdSql.execute("create table stb (ts timestamp, c1 int, c2 binary(10)) tags(t1 binary(10))") - tdSql.execute("create table tb1 using stb tags('a1')") - tdSql.execute("create table tb2 using stb tags('b2')") - tdSql.execute("create table tb3 using stb tags('a3')") - tdSql.execute("create table strm as select count(*), avg(c1), first(c2) from stb where t1 like 'a%' interval(4s) sliding(2s)") - tdSql.query("describe strm") - tdSql.checkRows(4) - - tdLog.sleep(1) - tdSql.execute("insert into tb1 values (now, 0, 'tb1')") - tdLog.sleep(4) - tdSql.execute("insert into tb2 values (now, 2, 'tb2')") - tdLog.sleep(4) - tdSql.execute("insert into tb3 values (now, 0, 'tb3')") - - tdSql.waitedQuery("select * from strm", 4, 60) - tdSql.checkRows(4) - tdSql.checkData(0, 2, 0.000000000) - if tdSql.getData(0, 3) == 'tb2': - tdLog.exit("unexpected value of data03") - if tdSql.getData(1, 3) == 'tb2': - tdLog.exit("unexpected value of data13") - if tdSql.getData(2, 3) == 'tb2': - tdLog.exit("unexpected value of data23") - if tdSql.getData(3, 3) == 'tb2': - tdLog.exit("unexpected value of data33") - - tdLog.info("add table tb4 to see if stream still works correctly") - # The vnode client needs to refresh metadata cache to allow strm calculate tb4's data. - # But the current refreshing frequency is every 10 min - # commented out the case below to save running time - tdSql.execute("create table tb4 using stb tags('a4')") - tdSql.execute("insert into tb4 values(now, 4, 'tb4')") - tdSql.waitedQuery("select * from strm order by ts desc", 6, 60) - tdSql.checkRows(6) - tdSql.checkData(0, 2, 4) - tdSql.checkData(0, 3, "tb4") - - tdLog.info("change tag values to see if stream still works correctly") - tdSql.execute("alter table tb4 set tag t1='b4'") - tdLog.sleep(3) - tdSql.execute("insert into tb1 values (now, 1, 'tb1_a1')") - tdLog.sleep(4) - tdSql.execute("insert into tb4 values (now, -4, 'tb4_b4')") - tdSql.waitedQuery("select * from strm order by ts desc", 8, 100) - tdSql.checkRows(8) - tdSql.checkData(0, 2, 1) - tdSql.checkData(0, 3, "tb1_a1") - - def datatypes(self): - tdLog.debug("begin data types") - tdSql.prepare() - tdSql.execute("create table stb3 (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 binary(15), c6 nchar(15), c7 bool) tags(t1 int, t2 binary(15))") - tdSql.execute("create table tb0 using stb3 tags(0, 'tb0')") - tdSql.execute("create table tb1 using stb3 tags(1, 'tb1')") - tdSql.execute("create table tb2 using stb3 tags(2, 'tb2')") - tdSql.execute("create table tb3 using stb3 tags(3, 'tb3')") - tdSql.execute("create table tb4 using stb3 tags(4, 'tb4')") - - tdSql.execute("create table strm0 as select count(ts), count(c1), max(c2), min(c4), first(c5), last(c6) from stb3 where ts < now + 30s interval(4s) sliding(2s)") - #tdSql.execute("create table strm0 as select count(ts), count(c1), max(c2), min(c4), first(c5) from stb where ts < now + 30s interval(4s) sliding(2s)") - tdLog.sleep(1) - tdSql.execute("insert into tb0 values (now, 0, 0, 0, 0, 'binary0', '涛思0', true) tb1 values (now, 1, 1, 1, 1, 'binary1', '涛思1', false) tb2 values (now, 2, 2, 2, 2, 'binary2', '涛思2', true) tb3 values (now, 3, 3, 3, 3, 'binary3', '涛思3', false) tb4 values (now, 4, 4, 4, 4, 'binary4', '涛思4', true) ") - - tdSql.waitedQuery("select * from strm0 order by ts desc", 2, 120) - tdSql.checkRows(2) - - tdSql.execute("insert into tb0 values (now, 10, 10, 10, 10, 'binary0', '涛思0', true) tb1 values (now, 11, 11, 11, 11, 'binary1', '涛思1', false) tb2 values (now, 12, 12, 12, 12, 'binary2', '涛思2', true) tb3 values (now, 13, 13, 13, 13, 'binary3', '涛思3', false) tb4 values (now, 14, 14, 14, 14, 'binary4', '涛思4', true) ") - tdSql.waitedQuery("select * from strm0 order by ts desc", 4, 120) - tdSql.checkRows(4) - - def run(self): - self.tbase300() - self.tbase304() - self.wildcardFilterOnTags() - self.datatypes() - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/stream/showStreamExecTimeisNull.py b/tests/pytest/stream/showStreamExecTimeisNull.py deleted file mode 100644 index 8a2a09cec6..0000000000 --- a/tests/pytest/stream/showStreamExecTimeisNull.py +++ /dev/null @@ -1,98 +0,0 @@ -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -from util.log import * -from util.cases import * -from util.sql import * -from util.dnodes import * - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug(f"start to execute {__file__}") - tdSql.init(conn.cursor(), logSql) - - def insertnow(self): - - # timestamp list: - # 0 -> "1970-01-01 08:00:00" | -28800000 -> "1970-01-01 00:00:00" | -946800000000 -> "1940-01-01 00:00:00" - # -631180800000 -> "1950-01-01 00:00:00" - - tsp1 = 0 - tsp2 = -28800000 - tsp3 = -946800000000 - tsp4 = "1969-01-01 00:00:00.000" - - tdSql.execute("insert into tcq1 values (now-11d, 5)") - tdSql.execute(f"insert into tcq1 values ({tsp1}, 4)") - tdSql.execute(f"insert into tcq1 values ({tsp2}, 3)") - tdSql.execute(f"insert into tcq1 values ('{tsp4}', 2)") - tdSql.execute(f"insert into tcq1 values ({tsp3}, 1)") - - def waitedQuery(self, sql, expectRows, timeout): - tdLog.info(f"sql: {sql}, try to retrieve {expectRows} rows in {timeout} seconds") - try: - for i in range(timeout): - tdSql.cursor.execute(sql) - self.queryResult = tdSql.cursor.fetchall() - self.queryRows = len(self.queryResult) - self.queryCols = len(tdSql.cursor.description) - # tdLog.info("sql: %s, try to retrieve %d rows,get %d rows" % (sql, expectRows, self.queryRows)) - if self.queryRows >= expectRows: - return (self.queryRows, i) - time.sleep(1) - except Exception as e: - caller = inspect.getframeinfo(inspect.stack()[1][0]) - tdLog.notice(f"{caller.filename}({caller.lineno}) failed: sql:{sql}, {repr(e)}") - raise Exception(repr(e)) - return (self.queryRows, timeout) - - def showstream(self): - tdSql.execute( - "create table cq1 as select avg(c1) from tcq1 interval(10d) sliding(1d)" - ) - sql = "show streams" - timeout = 30 - exception = "ValueError('year -292275055 is out of range')" - try: - for i in range(timeout): - tdSql.cursor.execute(sql) - self.queryResult = tdSql.cursor.fetchall() - self.queryRows = len(self.queryResult) - self.queryCols = len(tdSql.cursor.description) - # tdLog.info("sql: %s, try to retrieve %d rows,get %d rows" % (sql, expectRows, self.queryRows)) - if self.queryRows >= 1: - tdSql.query(sql) - tdSql.checkData(0, 5, None) - return (self.queryRows, i) - time.sleep(1) - except Exception as e: - tdLog.exit(f"sql: {sql} except raise {exception}, actually raise {repr(e)} ") - # else: - # tdLog.exit(f"sql: {sql} except raise {exception}, actually not") - - def run(self): - tdSql.execute("drop database if exists dbcq") - tdSql.execute("create database if not exists dbcq keep 36500") - tdSql.execute("use dbcq") - - tdSql.execute("create table stbcq (ts timestamp, c1 int ) TAGS(t1 int)") - tdSql.execute("create table tcq1 using stbcq tags(1)") - - self.insertnow() - self.showstream() - - - def stop(self): - tdSql.close() - tdLog.success(f"{__file__} successfully executed") - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) \ No newline at end of file diff --git a/tests/pytest/stream/stream1.py b/tests/pytest/stream/stream1.py deleted file mode 100644 index c657379441..0000000000 --- a/tests/pytest/stream/stream1.py +++ /dev/null @@ -1,142 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def run(self): - tbNum = 10 - rowNum = 20 - - tdSql.prepare() - - tdLog.info("===== step1 =====") - tdSql.execute( - "create table stb0(ts timestamp, col1 int, col2 float) tags(tgcol int)") - for i in range(tbNum): - tdSql.execute("create table tb%d using stb0 tags(%d)" % (i, i)) - for j in range(rowNum): - tdSql.execute( - "insert into tb%d values (now - %dm, %d, %d)" % - (i, 1440 - j, j, j)) - time.sleep(0.1) - - tdLog.info("===== step2 =====") - tdSql.query( - "select count(*), count(col1), count(col2) from tb0 interval(1d)") - tdSql.checkData(0, 1, rowNum) - tdSql.checkData(0, 2, rowNum) - tdSql.checkData(0, 3, rowNum) - tdSql.query("show tables") - tdSql.checkRows(tbNum) - tdSql.execute( - "create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") - tdSql.query("show tables") - tdSql.checkRows(tbNum + 1) - - tdLog.info("===== step3 =====") - tdSql.waitedQuery("select * from s0", 1, 120) - try: - tdSql.checkData(0, 1, rowNum) - tdSql.checkData(0, 2, rowNum) - tdSql.checkData(0, 3, rowNum) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step4 =====") - tdSql.execute("drop table s0") - tdSql.query("show tables") - tdSql.checkRows(tbNum) - - tdLog.info("===== step5 =====") - tdSql.error("select * from s0") - - tdLog.info("===== step6 =====") - time.sleep(0.1) - tdSql.execute( - "create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") - tdSql.query("show tables") - tdSql.checkRows(tbNum + 1) - - tdLog.info("===== step7 =====") - tdSql.waitedQuery("select * from s0", 1, 120) - try: - tdSql.checkData(0, 1, rowNum) - tdSql.checkData(0, 2, rowNum) - tdSql.checkData(0, 3, rowNum) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step8 =====") - tdSql.query( - "select count(*), count(col1), count(col2) from stb0 interval(1d)") - tdSql.checkData(0, 1, rowNum * tbNum) - tdSql.checkData(0, 2, rowNum * tbNum) - tdSql.checkData(0, 3, rowNum * tbNum) - tdSql.query("show tables") - tdSql.checkRows(tbNum + 1) - - tdSql.execute( - "create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") - tdSql.query("show tables") - tdSql.checkRows(tbNum + 2) - - tdLog.info("===== step9 =====") - tdSql.waitedQuery("select * from s1", 1, 120) - try: - tdSql.checkData(0, 1, rowNum * tbNum) - tdSql.checkData(0, 2, rowNum * tbNum) - tdSql.checkData(0, 3, rowNum * tbNum) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step10 =====") - tdSql.execute("drop table s1") - tdSql.query("show tables") - tdSql.checkRows(tbNum + 1) - - tdLog.info("===== step11 =====") - tdSql.error("select * from s1") - - tdLog.info("===== step12 =====") - tdSql.execute( - "create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") - tdSql.query("show tables") - tdSql.checkRows(tbNum + 2) - - tdLog.info("===== step13 =====") - tdSql.waitedQuery("select * from s1", 1, 120) - try: - tdSql.checkData(0, 1, rowNum * tbNum) - tdSql.checkData(0, 2, rowNum * tbNum) - tdSql.checkData(0, 3, rowNum * tbNum) - except Exception as e: - tdLog.info(repr(e)) - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/stream/stream2.py b/tests/pytest/stream/stream2.py deleted file mode 100644 index 9b4eb8725c..0000000000 --- a/tests/pytest/stream/stream2.py +++ /dev/null @@ -1,164 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def run(self): - tbNum = 10 - rowNum = 20 - totalNum = tbNum * rowNum - - tdSql.prepare() - - tdLog.info("===== step1 =====") - tdSql.execute( - "create table stb0(ts timestamp, col1 int, col2 float) tags(tgcol int)") - for i in range(tbNum): - tdSql.execute("create table tb%d using stb0 tags(%d)" % (i, i)) - for j in range(rowNum): - tdSql.execute( - "insert into tb%d values (now - %dm, %d, %d)" % - (i, 1440 - j, j, j)) - time.sleep(0.1) - - tdLog.info("===== step2 =====") - tdSql.query("select count(col1) from tb0 interval(1d)") - tdSql.checkData(0, 1, rowNum) - tdSql.query("show tables") - tdSql.checkRows(tbNum) - tdSql.execute( - "create table s0 as select count(col1) from tb0 interval(1d)") - tdSql.query("show tables") - tdSql.checkRows(tbNum + 1) - - tdLog.info("===== step3 =====") - tdSql.waitedQuery("select * from s0", 1, 120) - try: - tdSql.checkData(0, 1, rowNum) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step4 =====") - tdSql.execute("drop table s0") - tdSql.query("show tables") - try: - tdSql.checkRows(tbNum) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step5 =====") - tdSql.error("select * from s0") - - tdLog.info("===== step6 =====") - tdSql.execute( - "create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") - tdSql.query("show tables") - try: - tdSql.checkRows(tbNum + 1) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step7 =====") - tdSql.waitedQuery("select * from s0", 1, 120) - try: - tdSql.checkData(0, 1, rowNum) - tdSql.checkData(0, 2, rowNum) - tdSql.checkData(0, 3, rowNum) - except Exception as e: - tdLog.info(repr(e)) - - - time.sleep(5) - tdSql.query("show streams") - tdSql.checkRows(1) - tdSql.checkData(0, 2, 's0') - - tdLog.info("===== step8 =====") - tdSql.query( - "select count(*), count(col1), count(col2) from stb0 interval(1d)") - try: - tdSql.checkData(0, 1, totalNum) - tdSql.checkData(0, 2, totalNum) - tdSql.checkData(0, 3, totalNum) - except Exception as e: - tdLog.info(repr(e)) - tdSql.query("show tables") - tdSql.checkRows(tbNum + 1) - tdSql.execute( - "create table s1 as select count(*), count(col1), count(col2) from stb0 interval(1d)") - tdSql.query("show tables") - tdSql.checkRows(tbNum + 2) - - tdLog.info("===== step9 =====") - tdSql.waitedQuery("select * from s1", 1, 120) - try: - tdSql.checkData(0, 1, totalNum) - tdSql.checkData(0, 2, totalNum) - tdSql.checkData(0, 3, totalNum) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step10 =====") - tdSql.execute("drop table s1") - tdSql.query("show tables") - try: - tdSql.checkRows(tbNum + 1) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step11 =====") - tdSql.error("select * from s1") - - tdLog.info("===== step12 =====") - tdSql.execute( - "create table s1 as select count(col1) from stb0 interval(1d)") - tdSql.query("show tables") - try: - tdSql.checkRows(tbNum + 2) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step13 =====") - tdSql.waitedQuery("select * from s1", 1, 120) - try: - tdSql.checkData(0, 1, totalNum) - #tdSql.checkData(0, 2, None) - #tdSql.checkData(0, 3, None) - except Exception as e: - tdLog.info(repr(e)) - - time.sleep(5) - tdSql.query("show streams") - tdSql.checkRows(2) - tdSql.checkData(0, 2, 's1') - tdSql.checkData(1, 2, 's0') - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/stream/stream3.py b/tests/pytest/stream/stream3.py deleted file mode 100644 index 9a5c6c9aec..0000000000 --- a/tests/pytest/stream/stream3.py +++ /dev/null @@ -1,108 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def run(self): - ts = 1500000000000 - tbNum = 10 - rowNum = 20 - - tdSql.prepare() - - tdLog.info("===== step1 =====") - tdSql.execute( - "create table stb0(ts timestamp, col1 binary(20), col2 nchar(20)) tags(tgcol int)") - for i in range(tbNum): - tdSql.execute("create table tb%d using stb0 tags(%d)" % (i, i)) - for j in range(rowNum): - tdSql.execute( - "insert into tb%d values (%d, 'binary%d', 'nchar%d')" % - (i, ts + 60000 * j, j, j)) - tdSql.execute("insert into tb0 values(%d, null, null)" % (ts + 10000000)) - time.sleep(0.1) - - tdLog.info("===== step2 =====") - tdSql.query( - "select count(*), count(col1), count(col2) from stb0 interval(1d)") - tdSql.checkData(0, 1, rowNum * tbNum + 1) - tdSql.checkData(0, 2, rowNum * tbNum) - tdSql.checkData(0, 3, rowNum * tbNum) - - tdSql.query("show tables") - tdSql.checkRows(tbNum) - tdSql.execute( - "create table s0 as select count(*), count(col1), count(col2) from stb0 interval(1d)") - tdSql.query("show tables") - tdSql.checkRows(tbNum + 1) - - tdLog.info("===== step3 =====") - tdSql.waitedQuery("select * from s0", 1, 120) - try: - tdSql.checkData(0, 1, rowNum * tbNum + 1) - tdSql.checkData(0, 2, rowNum * tbNum) - tdSql.checkData(0, 3, rowNum * tbNum) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step4 =====") - tdSql.execute("drop table s0") - tdSql.query("show tables") - tdSql.checkRows(tbNum) - - tdLog.info("===== step5 =====") - tdSql.error("select * from s0") - - tdLog.info("===== step6 =====") - time.sleep(0.1) - tdSql.execute( - "create table s0 as select count(*), count(col1), count(col2) from tb0 interval(1d)") - tdSql.query("show tables") - tdSql.checkRows(tbNum + 1) - - tdLog.info("===== step7 =====") - tdSql.waitedQuery("select * from s0", 1, 120) - try: - tdSql.checkData(0, 1, rowNum + 1) - tdSql.checkData(0, 2, rowNum) - tdSql.checkData(0, 3, rowNum) - except Exception as e: - tdLog.info(repr(e)) - - tdLog.info("===== step8 =====") - tdSql.query( - "select count(*), count(col1), count(col2) from stb0 interval(1d)") - tdSql.checkData(0, 1, rowNum * tbNum + 1) - tdSql.checkData(0, 2, rowNum * tbNum) - tdSql.checkData(0, 3, rowNum * tbNum) - tdSql.query("show tables") - tdSql.checkRows(tbNum + 1) - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/stream/sys.py b/tests/pytest/stream/sys.py deleted file mode 100644 index c9a3fccfe6..0000000000 --- a/tests/pytest/stream/sys.py +++ /dev/null @@ -1,62 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# migrated from 'stream_on_sys.sim' -# -*- coding: utf-8 -*- -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - updatecfgDict = {'monitor': 1} - - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - - def run(self): - time.sleep(5) - tdSql.execute("use log") - - tdSql.execute("create table cpustrm as select count(*), avg(cpu_taosd), max(cpu_taosd), min(cpu_taosd), avg(cpu_system), max(cpu_cores), min(cpu_cores), last(cpu_cores) from log.dn1 interval(4s)") - tdSql.execute("create table memstrm as select count(*), avg(mem_taosd), max(mem_taosd), min(mem_taosd), avg(mem_system), first(mem_total), last(mem_total) from log.dn1 interval(4s)") - tdSql.execute("create table diskstrm as select count(*), avg(disk_used), last(disk_used), avg(disk_total), first(disk_total) from log.dn1 interval(4s)") - tdSql.execute("create table bandstrm as select count(*), avg(band_speed), last(band_speed) from log.dn1 interval(4s)") - tdSql.execute("create table reqstrm as select count(*), avg(req_http), last(req_http), avg(req_select), last(req_select), avg(req_insert), last(req_insert) from log.dn1 interval(4s)") - tdSql.execute("create table iostrm as select count(*), avg(io_read), last(io_read), avg(io_write), last(io_write) from log.dn1 interval(4s)") - - sqls = [ - "select * from cpustrm", - "select * from memstrm", - "select * from diskstrm", - "select * from bandstrm", - "select * from reqstrm", - "select * from iostrm", - ] - for sql in sqls: - (rows, _) = tdSql.waitedQuery(sql, 1, 240) - if rows < 1: - tdLog.exit("failed: sql:%s, expect at least one row" % sql) - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) - diff --git a/tests/pytest/stream/table_1.py b/tests/pytest/stream/table_1.py deleted file mode 100644 index b205491fad..0000000000 --- a/tests/pytest/stream/table_1.py +++ /dev/null @@ -1,89 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def createFuncStream(self, expr, suffix, value): - tbname = "strm_" + suffix - tdLog.info("create stream table %s" % tbname) - tdSql.query("select %s from tb1 interval(1d)" % expr) - tdSql.checkData(0, 1, value) - tdSql.execute("create table %s as select %s from tb1 interval(1d)" % (tbname, expr)) - - def checkStreamData(self, suffix, value): - sql = "select * from strm_" + suffix - tdSql.waitedQuery(sql, 1, 120) - tdSql.checkData(0, 1, value) - - def run(self): - tbNum = 10 - rowNum = 20 - - tdSql.prepare() - - tdLog.info("===== step1 =====") - tdSql.execute( - "create table stb(ts timestamp, tbcol int, tbcol2 float) tags(tgcol int)") - for i in range(tbNum): - tdSql.execute("create table tb%d using stb tags(%d)" % (i, i)) - for j in range(rowNum): - tdSql.execute( - "insert into tb%d values (now - %dm, %d, %d)" % - (i, 1440 - j, j, j)) - time.sleep(1) - - self.createFuncStream("count(*)", "c1", rowNum) - self.createFuncStream("count(tbcol)", "c2", rowNum) - self.createFuncStream("count(tbcol2)", "c3", rowNum) - self.createFuncStream("avg(tbcol)", "av", 9.5) - self.createFuncStream("sum(tbcol)", "su", 190) - self.createFuncStream("min(tbcol)", "mi", 0) - self.createFuncStream("max(tbcol)", "ma", 19) - self.createFuncStream("first(tbcol)", "fi", 0) - self.createFuncStream("last(tbcol)", "la", 19) - self.createFuncStream("stddev(tbcol)", "st", 5.766281297335398) - self.createFuncStream("percentile(tbcol, 1)", "pe", 0.19) - self.createFuncStream("count(tbcol)", "as", rowNum) - - self.checkStreamData("c1", rowNum) - self.checkStreamData("c2", rowNum) - self.checkStreamData("c3", rowNum) - self.checkStreamData("av", 9.5) - self.checkStreamData("su", 190) - self.checkStreamData("mi", 0) - self.checkStreamData("ma", 19) - self.checkStreamData("fi", 0) - self.checkStreamData("la", 19) - self.checkStreamData("st", 5.766281297335398) - self.checkStreamData("pe", 0.19) - self.checkStreamData("as", rowNum) - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) diff --git a/tests/pytest/stream/table_n.py b/tests/pytest/stream/table_n.py deleted file mode 100644 index 371af76977..0000000000 --- a/tests/pytest/stream/table_n.py +++ /dev/null @@ -1,143 +0,0 @@ -################################################################### -# Copyright (c) 2016 by TAOS Technologies, Inc. -# All rights reserved. -# -# This file is proprietary and confidential to TAOS Technologies. -# No part of this file may be reproduced, stored, transmitted, -# disclosed or used in any form or by any means other than as -# expressly provided by the written permission from Jianhui Tao -# -################################################################### - -# -*- coding: utf-8 -*- - -import sys -import time -import taos -from util.log import tdLog -from util.cases import tdCases -from util.sql import tdSql - - -class TDTestCase: - def init(self, conn, logSql): - tdLog.debug("start to execute %s" % __file__) - tdSql.init(conn.cursor(), logSql) - - def run(self): - tbNum = 10 - rowNum = 20 - - tdSql.prepare() - - tdLog.info("===== preparing data =====") - tdSql.execute( - "create table stb(ts timestamp, tbcol int, tbcol2 float) tags(tgcol int)") - for i in range(tbNum): - tdSql.execute("create table tb%d using stb tags(%d)" % (i, i)) - for j in range(rowNum): - tdSql.execute( - "insert into tb%d values (now - %dm, %d, %d)" % - (i, 1440 - j, j, j)) - time.sleep(0.1) - - tdLog.info("===== step 1 =====") - tdSql.query("select count(*), count(tbcol), count(tbcol2) from tb1 interval(1d)") - tdSql.checkData(0, 1, rowNum) - tdSql.checkData(0, 2, rowNum) - tdSql.checkData(0, 3, rowNum) - - tdLog.info("===== step 2 =====") - tdSql.execute("create table strm_c3 as select count(*), count(tbcol), count(tbcol2) from tb1 interval(1d)") - - tdLog.info("===== step 3 =====") - tdSql.execute("create table strm_c32 as select count(*), count(tbcol) as c1, count(tbcol2) as c2, count(tbcol) as c3, count(tbcol) as c4, count(tbcol) as c5, count(tbcol) as c6, count(tbcol) as c7, count(tbcol) as c8, count(tbcol) as c9, count(tbcol) as c10, count(tbcol) as c11, count(tbcol) as c12, count(tbcol) as c13, count(tbcol) as c14, count(tbcol) as c15, count(tbcol) as c16, count(tbcol) as c17, count(tbcol) as c18, count(tbcol) as c19, count(tbcol) as c20, count(tbcol) as c21, count(tbcol) as c22, count(tbcol) as c23, count(tbcol) as c24, count(tbcol) as c25, count(tbcol) as c26, count(tbcol) as c27, count(tbcol) as c28, count(tbcol) as c29, count(tbcol) as c30 from tb1 interval(1d)") - - tdLog.info("===== step 4 =====") - tdSql.query("select count(*), count(tbcol) as c1, count(tbcol2) as c2, count(tbcol) as c3, count(tbcol) as c4, count(tbcol) as c5, count(tbcol) as c6, count(tbcol) as c7, count(tbcol) as c8, count(tbcol) as c9, count(tbcol) as c10, count(tbcol) as c11, count(tbcol) as c12, count(tbcol) as c13, count(tbcol) as c14, count(tbcol) as c15, count(tbcol) as c16, count(tbcol) as c17, count(tbcol) as c18, count(tbcol) as c19, count(tbcol) as c20, count(tbcol) as c21, count(tbcol) as c22, count(tbcol) as c23, count(tbcol) as c24, count(tbcol) as c25, count(tbcol) as c26, count(tbcol) as c27, count(tbcol) as c28, count(tbcol) as c29, count(tbcol) as c30 from tb1 interval(1d)") - tdSql.checkData(0, 1, rowNum) - tdSql.checkData(0, 2, rowNum) - tdSql.checkData(0, 3, rowNum) - - tdLog.info("===== step 5 =====") - tdSql.execute("create table strm_c31 as select count(*), count(tbcol) as c1, count(tbcol2) as c2, count(tbcol) as c3, count(tbcol) as c4, count(tbcol) as c5, count(tbcol) as c6, count(tbcol) as c7, count(tbcol) as c8, count(tbcol) as c9, count(tbcol) as c10, count(tbcol) as c11, count(tbcol) as c12, count(tbcol) as c13, count(tbcol) as c14, count(tbcol) as c15, count(tbcol) as c16, count(tbcol) as c17, count(tbcol) as c18, count(tbcol) as c19, count(tbcol) as c20, count(tbcol) as c21, count(tbcol) as c22, count(tbcol) as c23, count(tbcol) as c24, count(tbcol) as c25, count(tbcol) as c26, count(tbcol) as c27, count(tbcol) as c28, count(tbcol) as c29, count(tbcol) as c30 from tb1 interval(1d)") - - tdLog.info("===== step 6 =====") - tdSql.query("select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from tb1 interval(1d)") - tdSql.checkData(0, 1, 9.5) - tdSql.checkData(0, 2, 190) - tdSql.checkData(0, 3, 0) - tdSql.checkData(0, 4, 19) - tdSql.checkData(0, 5, 0) - tdSql.checkData(0, 6, 19) - tdSql.execute("create table strm_avg as select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol) from tb1 interval(1d)") - - tdLog.info("===== step 7 =====") - tdSql.query("select stddev(tbcol), leastsquares(tbcol, 1, 1), percentile(tbcol, 1) from tb1 interval(1d)") - tdSql.checkData(0, 1, 5.766281297335398) - tdSql.checkData(0, 3, 0.19) - tdSql.execute("create table strm_ot as select stddev(tbcol), leastsquares(tbcol, 1, 1), percentile(tbcol, 1) from tb1 interval(1d)") - - tdLog.info("===== step 8 =====") - tdSql.query("select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol), stddev(tbcol), percentile(tbcol, 1), count(tbcol), leastsquares(tbcol, 1, 1) from tb1 interval(1d)") - tdSql.checkData(0, 1, 9.5) - tdSql.checkData(0, 2, 190) - tdSql.checkData(0, 3, 0) - tdSql.checkData(0, 4, 19) - tdSql.checkData(0, 5, 0) - tdSql.checkData(0, 6, 19) - tdSql.checkData(0, 7, 5.766281297335398) - tdSql.checkData(0, 8, 0.19) - tdSql.checkData(0, 9, rowNum) - tdSql.execute("create table strm_to as select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol), stddev(tbcol), percentile(tbcol, 1), count(tbcol), leastsquares(tbcol, 1, 1) from tb1 interval(1d)") - - tdLog.info("===== step 9 =====") - tdSql.query("select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol), stddev(tbcol), percentile(tbcol, 1), count(tbcol), leastsquares(tbcol, 1, 1) from tb1 where ts < now + 4m interval(1d)") - tdSql.checkData(0, 9, rowNum) - tdSql.execute("create table strm_wh as select avg(tbcol), sum(tbcol), min(tbcol), max(tbcol), first(tbcol), last(tbcol), stddev(tbcol), percentile(tbcol, 1), count(tbcol), leastsquares(tbcol, 1, 1) from tb1 where ts < now + 4m interval(1d)") - - tdLog.info("===== step 10 =====") - tdSql.waitedQuery("select * from strm_c3", 1, 120) - tdSql.checkData(0, 1, rowNum) - tdSql.checkData(0, 2, rowNum) - tdSql.checkData(0, 3, rowNum) - - tdLog.info("===== step 11 =====") - tdSql.waitedQuery("select * from strm_c31", 1, 30) - for i in range(1, 10): - tdSql.checkData(0, i, rowNum) - - tdLog.info("===== step 12 =====") - tdSql.waitedQuery("select * from strm_avg", 1, 20) - tdSql.checkData(0, 1, 9.5) - tdSql.checkData(0, 2, 190) - tdSql.checkData(0, 3, 0) - tdSql.checkData(0, 4, 19) - tdSql.checkData(0, 5, 0) - tdSql.checkData(0, 6, 19) - - tdLog.info("===== step 13 =====") - tdSql.waitedQuery("select * from strm_ot", 1, 20) - tdSql.checkData(0, 1, 5.766281297335398) - tdSql.checkData(0, 3, 0.19) - - tdLog.info("===== step 14 =====") - tdSql.waitedQuery("select * from strm_to", 1, 20) - tdSql.checkData(0, 1, 9.5) - tdSql.checkData(0, 2, 190) - tdSql.checkData(0, 3, 0) - tdSql.checkData(0, 4, 19) - tdSql.checkData(0, 5, 0) - tdSql.checkData(0, 6, 19) - tdSql.checkData(0, 7, 5.766281297335398) - tdSql.checkData(0, 8, 0.19) - tdSql.checkData(0, 9, rowNum) - - - def stop(self): - tdSql.close() - tdLog.success("%s successfully executed" % __file__) - - -tdCases.addWindows(__file__, TDTestCase()) -tdCases.addLinux(__file__, TDTestCase()) From 86c9446a84deb49668ce7968b3acb78dfba97f13 Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 25 May 2022 19:37:52 +0800 Subject: [PATCH 31/32] fix(stream): handle null data --- source/common/src/tdatablock.c | 18 +++++++++++------- source/libs/stream/src/tstream.c | 4 +++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/source/common/src/tdatablock.c b/source/common/src/tdatablock.c index 816fdab3d2..733693f584 100644 --- a/source/common/src/tdatablock.c +++ b/source/common/src/tdatablock.c @@ -350,7 +350,7 @@ int32_t blockDataUpdateTsWindow(SSDataBlock* pDataBlock, int32_t tsColumnIndex) return -1; } - int32_t index = (tsColumnIndex == -1)? 0:tsColumnIndex; + int32_t index = (tsColumnIndex == -1) ? 0 : tsColumnIndex; SColumnInfoData* pColInfoData = taosArrayGet(pDataBlock->pDataBlock, index); if (pColInfoData->info.type != TSDB_DATA_TYPE_TIMESTAMP) { return 0; @@ -599,8 +599,8 @@ int32_t blockDataFromBuf(SSDataBlock* pBlock, const char* buf) { } int32_t blockDataFromBuf1(SSDataBlock* pBlock, const char* buf, size_t capacity) { - pBlock->info.rows = *(int32_t*) buf; - pBlock->info.groupId = *(uint64_t*) (buf + sizeof(int32_t)); + pBlock->info.rows = *(int32_t*)buf; + pBlock->info.groupId = *(uint64_t*)(buf + sizeof(int32_t)); int32_t numOfCols = pBlock->info.numOfCols; const char* pStart = buf + sizeof(uint32_t) + sizeof(uint64_t); @@ -669,7 +669,7 @@ size_t blockDataGetSerialMetaSize(const SSDataBlock* pBlock) { return sizeof(int32_t) + sizeof(uint64_t) + pBlock->info.numOfCols * sizeof(int32_t); } -double blockDataGetSerialRowSize(const SSDataBlock* pBlock) { +double blockDataGetSerialRowSize(const SSDataBlock* pBlock) { ASSERT(pBlock != NULL); double rowSize = 0; @@ -1232,7 +1232,7 @@ size_t blockDataGetCapacityInRow(const SSDataBlock* pBlock, size_t pageSize) { // the true value must be less than the value of nRows int32_t additional = 0; - for(int32_t i = 0; i < pBlock->info.numOfCols; ++i) { + for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) { SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, i); if (IS_VAR_DATA_TYPE(pCol->info.type)) { additional += nRows * sizeof(int32_t); @@ -1728,8 +1728,12 @@ SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema, boo for (int32_t k = 0; k < pTSchema->numOfCols; k++) { const STColumn* pColumn = &pTSchema->columns[k]; SColumnInfoData* pColData = taosArrayGet(pDataBlock->pDataBlock, k); - void* data = colDataGetData(pColData, j); - tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k); + if (colDataIsNull_s(pColData, j)) { + tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NONE, NULL, false, pColumn->offset, k); + } else { + void* data = colDataGetData(pColData, j); + tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k); + } } int32_t rowLen = TD_ROW_LEN(rowData); rowData = POINTER_SHIFT(rowData, rowLen); diff --git a/source/libs/stream/src/tstream.c b/source/libs/stream/src/tstream.c index dd7e38a458..933b37825f 100644 --- a/source/libs/stream/src/tstream.c +++ b/source/libs/stream/src/tstream.c @@ -158,7 +158,9 @@ static int32_t streamTaskExecImpl(SStreamTask* pTask, void* data, SArray* pRes) ASSERT(false); } if (output == NULL) break; - taosArrayPush(pRes, output); + // TODO: do we need free memory? + SSDataBlock* outputCopy = createOneDataBlock(output, true); + taosArrayPush(pRes, outputCopy); } // destroy From 18241f7170b3bd9a0d31f2da918a81920117b1ee Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Wed, 25 May 2022 20:24:47 +0800 Subject: [PATCH 32/32] chore: remove out-of-date example --- examples/c/stream.c | 178 -------------------------------------------- 1 file changed, 178 deletions(-) delete mode 100644 examples/c/stream.c diff --git a/examples/c/stream.c b/examples/c/stream.c deleted file mode 100644 index 41365813ae..0000000000 --- a/examples/c/stream.c +++ /dev/null @@ -1,178 +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 -#include -#include -#include -#include -#include "../../../include/client/taos.h" // include TDengine header file - -typedef struct { - char server_ip[64]; - char db_name[64]; - char tbl_name[64]; -} param; - -int g_thread_exit_flag = 0; -void* insert_rows(void *sarg); - -void streamCallBack(void *param, TAOS_RES *res, TAOS_ROW row) -{ - // in this simple demo, it just print out the result - char temp[128]; - - TAOS_FIELD *fields = taos_fetch_fields(res); - int numFields = taos_num_fields(res); - - taos_print_row(temp, row, fields, numFields); - - printf("\n%s\n", temp); -} - -int main(int argc, char *argv[]) -{ - TAOS *taos; - char db_name[64]; - char tbl_name[64]; - char sql[1024] = { 0 }; - - if (argc != 4) { - printf("usage: %s server-ip dbname tblname\n", argv[0]); - exit(0); - } - - strcpy(db_name, argv[2]); - strcpy(tbl_name, argv[3]); - - // create pthread to insert into row per second for stream calc - param *t_param = (param *)malloc(sizeof(param)); - if (NULL == t_param) - { - printf("failed to malloc\n"); - exit(1); - } - memset(t_param, 0, sizeof(param)); - strcpy(t_param->server_ip, argv[1]); - strcpy(t_param->db_name, db_name); - strcpy(t_param->tbl_name, tbl_name); - - pthread_t pid; - pthread_create(&pid, NULL, (void * (*)(void *))insert_rows, t_param); - - sleep(3); // waiting for database is created. - // open connection to database - taos = taos_connect(argv[1], "root", "taosdata", db_name, 0); - if (taos == NULL) { - printf("failed to connet to server:%s\n", argv[1]); - free(t_param); - exit(1); - } - - // starting stream calc, - printf("please input stream SQL:[e.g., select count(*) from tblname interval(5s) sliding(2s);]\n"); - fgets(sql, sizeof(sql), stdin); - if (sql[0] == 0) { - printf("input NULL stream SQL, so exit!\n"); - free(t_param); - exit(1); - } - - // param is set to NULL in this demo, it shall be set to the pointer to app context - TAOS_STREAM *pStream = taos_open_stream(taos, sql, streamCallBack, 0, NULL, NULL); - if (NULL == pStream) { - printf("failed to create stream\n"); - free(t_param); - exit(1); - } - - printf("presss any key to exit\n"); - getchar(); - - taos_close_stream(pStream); - - g_thread_exit_flag = 1; - pthread_join(pid, NULL); - - taos_close(taos); - free(t_param); - - return 0; -} - - -void* insert_rows(void *sarg) -{ - TAOS *taos; - char command[1024] = { 0 }; - param *winfo = (param * )sarg; - - if (NULL == winfo){ - printf("para is null!\n"); - exit(1); - } - - taos = taos_connect(winfo->server_ip, "root", "taosdata", NULL, 0); - if (taos == NULL) { - printf("failed to connet to server:%s\n", winfo->server_ip); - exit(1); - } - - // drop database - sprintf(command, "drop database %s;", winfo->db_name); - if (taos_query(taos, command) != 0) { - printf("failed to drop database, reason:%s\n", taos_errstr(taos)); - exit(1); - } - - // create database - sprintf(command, "create database %s;", winfo->db_name); - if (taos_query(taos, command) != 0) { - printf("failed to create database, reason:%s\n", taos_errstr(taos)); - exit(1); - } - - // use database - sprintf(command, "use %s;", winfo->db_name); - if (taos_query(taos, command) != 0) { - printf("failed to use database, reason:%s\n", taos_errstr(taos)); - exit(1); - } - - // create table - sprintf(command, "create table %s (ts timestamp, speed int);", winfo->tbl_name); - if (taos_query(taos, command) != 0) { - printf("failed to create table, reason:%s\n", taos_errstr(taos)); - exit(1); - } - - // insert data - int64_t begin = (int64_t)time(NULL); - int index = 0; - while (1) { - if (g_thread_exit_flag) break; - - index++; - sprintf(command, "insert into %s values (%ld, %d)", winfo->tbl_name, (begin + index) * 1000, index); - if (taos_query(taos, command)) { - printf("failed to insert row [%s], reason:%s\n", command, taos_errstr(taos)); - } - sleep(1); - } - - taos_close(taos); - return 0; -} -