From 9a022bca606879b13e734c944e080b31af5bc377 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Thu, 19 May 2022 23:54:44 +0800 Subject: [PATCH 01/11] feat: add case for update without multi-version --- source/dnode/vnode/src/tsdb/tsdbRead.c | 11 +- tests/script/tsim/insert/update0.sim | 155 +++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 3 deletions(-) create mode 100644 tests/script/tsim/insert/update0.sim diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index 90adba6f4d..6640090085 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2030,8 +2030,14 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf } #endif if (TD_SUPPORT_UPDATE(pCfg->update)) { + if (lastKeyAppend != key) { + lastKeyAppend = key; + if (lastKeyAppend != TSKEY_INITIAL_VAL) { + ++curRow; + } + } + // load data from file firstly numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, pos, pos); - lastKeyAppend = key; if (rv1 != TD_ROW_SVER(row1)) { rv1 = TD_ROW_SVER(row1); @@ -2041,7 +2047,7 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf } // still assign data into current row - mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols, + numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols, pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend); if (cur->win.skey == TSKEY_INITIAL_VAL) { @@ -2053,7 +2059,6 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf cur->mixBlock = true; moveToNextRowInMem(pCheckInfo); - ++curRow; pos += step; } else { diff --git a/tests/script/tsim/insert/update0.sim b/tests/script/tsim/insert/update0.sim new file mode 100644 index 0000000000..c34a08c79d --- /dev/null +++ b/tests/script/tsim/insert/update0.sim @@ -0,0 +1,155 @@ +system sh/stop_dnodes.sh +system sh/deploy.sh -n dnode1 -i 1 +system sh/exec.sh -n dnode1 -s start +sleep 50 +sql connect + +print =============== create database +sql create database d0 keep 365000d,365000d,365000d +sql use d0 + +print =============== create super table and register rsma +sql create table if not exists stb (ts timestamp, c1 int) tags (city binary(20),district binary(20)) rollup(min) file_factor 0.1 delay 2; + +sql show stables +if $rows != 1 then + return -1 +endi + +print =============== create child table +sql create table ct1 using stb tags("BeiJing", "ChaoYang") +sql create table ct2 using stb tags("BeiJing", "HaiDian") + +sql show tables +if $rows != 2 then + return -1 +endi + +print =============== step3-1 insert records into ct1 +sql insert into ct1 values('2022-05-03 16:59:00.010', 10); +sql insert into ct1 values('2022-05-03 16:59:00.011', 11); +sql insert into ct1 values('2022-05-03 16:59:00.016', 16); +sql insert into ct1 values('2022-05-03 16:59:00.016', 17); +sql insert into ct1 values('2022-05-03 16:59:00.020', 20); +sql insert into ct1 values('2022-05-03 16:59:00.016', 18); +sql insert into ct1 values('2022-05-03 16:59:00.021', 21); +sql insert into ct1 values('2022-05-03 16:59:00.022', 22); + +print =============== step3-1 query records from ct1 from memory +sql select * from ct1; +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 +print $data30 $data31 +print $data40 $data41 +print $data50 $data51 + +if $rows != 6 then + print rows $rows != 6 + return -1 +endi + +if $data01 != 10 then + print data01 $data01 != 10 + return -1 +endi + +if $data21 != 18 then + print data21 $data21 != 18 + return -1 +endi + +if $data51 != 22 then + print data51 $data51 != 22 + return -1 +endi + +print =============== step3-1 insert records into ct2 +sql insert into ct2 values('2022-03-02 16:59:00.010', 1),('2022-03-02 16:59:00.010',11),('2022-04-01 16:59:00.011',2),('2022-04-01 16:59:00.011',5),('2022-03-06 16:59:00.013',7); +sql insert into ct2 values('2022-03-02 16:59:00.010', 3),('2022-03-02 16:59:00.010',33),('2022-04-01 16:59:00.011',4),('2022-04-01 16:59:00.011',6),('2022-03-06 16:59:00.013',8); +sql insert into ct2 values('2022-03-02 16:59:00.010', 103),('2022-03-02 16:59:00.010',303),('2022-04-01 16:59:00.011',40),('2022-04-01 16:59:00.011',60),('2022-03-06 16:59:00.013',80); + +print =============== step3-1 query records from ct2 from memory +sql select * from ct2; +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 + +if $rows != 3 then + print rows $rows != 3 + return -1 +endi + +if $data01 != 103 then + print data01 $data01 != 103 + return -1 +endi + +if $data11 != 80 then + print data11 $data11 != 80 + return -1 +endi + +if $data21 != 40 then + print data21 $data21 != 40 + return -1 +endi + +#==================== reboot to trigger commit data to file +system sh/exec.sh -n dnode1 -s stop -x SIGINT +system sh/exec.sh -n dnode1 -s start + +print =============== step3-2 query records from ct1 from file +sql select * from ct1; +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 +print $data30 $data31 +print $data40 $data41 +print $data50 $data51 + +if $rows != 6 then + print rows $rows != 6 + return -1 +endi + +if $data01 != 10 then + print data01 $data01 != 10 + return -1 +endi + +if $data21 != 18 then + print data21 $data21 != 18 + return -1 +endi + +if $data51 != 22 then + print data51 $data51 != 22 + return -1 +endi + +print =============== step3-2 query records from ct2 from file +sql select * from ct2; +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 + +if $rows != 3 then + print rows $rows != 3 + return -1 +endi + +if $data01 != 103 then + print data01 $data01 != 103 + return -1 +endi + +if $data11 != 80 then + print data11 $data11 != 80 + return -1 +endi + +if $data21 != 40 then + print data21 $data21 != 40 + return -1 +endi \ No newline at end of file From 18eb037706ea039476905b77a64b1b3965c0407f Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 20 May 2022 11:47:08 +0800 Subject: [PATCH 02/11] fix: ref count --- source/dnode/mgmt/mgmt_vnode/src/vmWorker.c | 18 +++++++++--------- source/dnode/mgmt/node_mgmt/src/dmMonitor.c | 12 +++++++----- source/util/src/tqueue.c | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index eec6bb3fb4..c3f5a2cd93 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -308,22 +308,23 @@ int32_t vmPutNodeMsgToMgmtQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { int32_t vmPutNodeMsgToMonitorQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { SSingleWorker *pWorker = &pMgmt->monitorWorker; - dTrace("msg:%p, put into vnode-monitor worker, type:%s", pMsg, TMSG_INFO(pMsg->msgType)); taosWriteQitem(pWorker->queue, pMsg); return 0; } static int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc, EQueueType qtype) { - SMsgHead *pHead = pRpc->pCont; - + SMsgHead *pHead = pRpc->pCont; SVnodeObj *pVnode = vmAcquireVnode(pMgmt, pHead->vgId); if (pVnode == NULL) return -1; SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM); - int32_t code = 0; + int32_t code = -1; - if (pMsg != NULL) { + if (pMsg == NULL) { + rpcFreeCont(pRpc->pCont); + pRpc->pCont = NULL; + } else { memcpy(pMsg, pRpc, sizeof(SRpcMsg)); switch (qtype) { case WRITE_QUEUE: @@ -351,7 +352,6 @@ static int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc, EQueueType q taosWriteQitem(pVnode->pSyncQ, pMsg); break; default: - code = -1; terrno = TSDB_CODE_INVALID_PARA; break; } @@ -428,7 +428,7 @@ int32_t vmAllocQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { return -1; } - dDebug("vgId:%d, vnode queue is alloced", pVnode->vgId); + dDebug("vgId:%d, queue is alloced", pVnode->vgId); return 0; } @@ -445,7 +445,7 @@ void vmFreeQueue(SVnodeMgmt *pMgmt, SVnodeObj *pVnode) { pVnode->pQueryQ = NULL; pVnode->pFetchQ = NULL; pVnode->pMergeQ = NULL; - dDebug("vgId:%d, vnode queue is freed", pVnode->vgId); + dDebug("vgId:%d, queue is freed", pVnode->vgId); } int32_t vmStartWorker(SVnodeMgmt *pMgmt) { @@ -496,7 +496,7 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) { .param = pMgmt, }; if (tSingleWorkerInit(&pMgmt->monitorWorker, &mCfg) != 0) { - dError("failed to start mnode vnode-monitor worker since %s", terrstr()); + dError("failed to start vnode-monitor worker since %s", terrstr()); return -1; } diff --git a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c index 2497da13ec..0b74d865fd 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmMonitor.c +++ b/source/dnode/mgmt/node_mgmt/src/dmMonitor.c @@ -161,10 +161,12 @@ void dmGetVnodeLoads(SMonVloadInfo *pInfo) { void dmGetMnodeLoads(SMonMloadInfo *pInfo) { SDnode *pDnode = dmInstance(); SMgmtWrapper *pWrapper = &pDnode->wrappers[MNODE]; - if (tsMultiProcess) { - dmSendLocalRecv(pDnode, TDMT_MON_MM_LOAD, tDeserializeSMonMloadInfo, pInfo); - } else if (pWrapper->pMgmt != NULL) { - mmGetMnodeLoads(pWrapper->pMgmt, pInfo); + if (dmMarkWrapper(pWrapper) == 0) { + if (tsMultiProcess) { + dmSendLocalRecv(pDnode, TDMT_MON_MM_LOAD, tDeserializeSMonMloadInfo, pInfo); + } else if (pWrapper->pMgmt != NULL) { + mmGetMnodeLoads(pWrapper->pMgmt, pInfo); + } + dmReleaseWrapper(pWrapper); } - dmReleaseWrapper(pWrapper); } diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index 5e206f3e6e..6a10794ea1 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -162,7 +162,7 @@ void *taosAllocateQitem(int32_t size, EQItype itype) { uTrace("item:%p, node:%p is allocated", pNode->item, pNode); } - return (void *)pNode->item; + return pNode->item; } void taosFreeQitem(void *pItem) { From eddd5b390cb4eb313094a5992e26c457a4d39e15 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 20 May 2022 12:48:15 +0800 Subject: [PATCH 03/11] refactor: adjust vm worker --- source/dnode/mgmt/mgmt_vnode/src/vmWorker.c | 44 ++++++++------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index c3f5a2cd93..50e2256145 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -22,21 +22,19 @@ static inline void vmSendRsp(SRpcMsg *pMsg, int32_t code) { SRpcMsg rsp = { .code = code, - .info = pMsg->info, .pCont = pMsg->info.rsp, .contLen = pMsg->info.rspLen, + .info = pMsg->info, }; tmsgSendRsp(&rsp); } static void vmProcessMgmtMonitorQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { SVnodeMgmt *pMgmt = pInfo->ahandle; + int32_t code = -1; + dTrace("msg:%p, get from vnode queue, type:%s", pMsg, TMSG_INFO(pMsg->msgType)); - int32_t code = -1; - tmsg_t msgType = pMsg->msgType; - dTrace("msg:%p, get from vnode queue, type:%s", pMsg, TMSG_INFO(msgType)); - - switch (msgType) { + switch (pMsg->msgType) { case TDMT_MON_VM_INFO: code = vmProcessGetMonitorInfoReq(pMgmt, pMsg); break; @@ -54,7 +52,7 @@ static void vmProcessMgmtMonitorQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { dError("msg:%p, not processed in vnode queue", pMsg); } - if (msgType & 1u) { + if (IsReq(pMsg)) { if (code != 0 && terrno != 0) code = terrno; vmSendRsp(pMsg, code); } @@ -96,7 +94,6 @@ static void vmProcessFetchQueue(SQueueInfo *pInfo, SRpcMsg *pMsg) { static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SVnodeObj *pVnode = pInfo->ahandle; - SArray *pArray = taosArrayInit(numOfMsgs, sizeof(SRpcMsg *)); if (pArray == NULL) { dError("failed to process %d msgs in write-queue since %s", numOfMsgs, terrstr()); @@ -116,7 +113,7 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO for (int i = 0; i < taosArrayGetSize(pArray); i++) { SRpcMsg *pMsg = *(SRpcMsg **)taosArrayGet(pArray, i); - SRpcMsg rsp = {.info = pMsg->info, .pCont = NULL, .contLen = 0}; + SRpcMsg rsp = {.info = pMsg->info}; int32_t ret = syncPropose(vnodeGetSyncHandle(pVnode->pImpl), pMsg, false); if (ret == TAOS_SYNC_PROPOSE_NOT_LEADER) { @@ -130,7 +127,6 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO rsp.code = TSDB_CODE_SYN_INTERNAL_ERROR; tmsgSendRsp(&rsp); } else if (ret == TAOS_SYNC_PROPOSE_SUCCESS) { - // ok // send response in applyQ } else { assert(0); @@ -149,16 +145,13 @@ static void vmProcessWriteQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SVnodeObj *pVnode = pInfo->ahandle; - SRpcMsg *pMsg = NULL; - SRpcMsg rsp; for (int32_t i = 0; i < numOfMsgs; ++i) { + SRpcMsg *pMsg = NULL; taosGetQitem(qall, (void **)&pMsg); // init response rpc msg - rsp.code = 0; - rsp.pCont = NULL; - rsp.contLen = 0; + SRpcMsg rsp = {0}; // get original rpc msg assert(pMsg->msgType == TDMT_VND_SYNC_APPLY_MSG); @@ -177,7 +170,6 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO rpcFreeCont(originalRpcMsg.pCont); // if leader, send response - // if (pMsg->rpcMsg.handle != NULL && pMsg->rpcMsg.ahandle != NULL) { if (pMsg->info.handle != NULL) { rsp.info = pMsg->info; tmsgSendRsp(&rsp); @@ -190,21 +182,19 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SVnodeObj *pVnode = pInfo->ahandle; - SRpcMsg *pMsg = NULL; for (int32_t i = 0; i < numOfMsgs; ++i) { + SRpcMsg *pMsg = NULL; taosGetQitem(qall, (void **)&pMsg); - // todo - SRpcMsg *pRsp = NULL; - int32_t ret = vnodeProcessSyncReq(pVnode->pImpl, pMsg, &pRsp); - if (ret != 0) { - // if leader, send response + int32_t code = vnodeProcessSyncReq(pVnode->pImpl, pMsg, NULL); + if (code != 0) { if (pMsg->info.handle != NULL) { - SRpcMsg rsp = {0}; - rsp.code = terrno; - rsp.info = pMsg->info; - dTrace("msg:%p, process sync queue error since code:%s", pMsg, terrstr()); + SRpcMsg rsp = { + .code = (terrno < 0) ? terrno : code, + .info = pMsg->info, + }; + dTrace("msg:%p, failed to process sync queue since %s", pMsg, terrstr()); tmsgSendRsp(&rsp); } } @@ -216,9 +206,9 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf static void vmProcessMergeQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOfMsgs) { SVnodeObj *pVnode = pInfo->ahandle; - SRpcMsg *pMsg = NULL; for (int32_t i = 0; i < numOfMsgs; ++i) { + SRpcMsg *pMsg = NULL; taosGetQitem(qall, (void **)&pMsg); dTrace("msg:%p, get from vnode-merge queue", pMsg); From a67e46efc813b58a98c904163cef7af7c916ec89 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 20 May 2022 13:42:03 +0800 Subject: [PATCH 04/11] fix: invalid code --- source/dnode/mgmt/mgmt_vnode/src/vmWorker.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c index 50e2256145..9b60260cc1 100644 --- a/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c +++ b/source/dnode/mgmt/mgmt_vnode/src/vmWorker.c @@ -309,11 +309,12 @@ static int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc, EQueueType q if (pVnode == NULL) return -1; SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg), RPC_QITEM); - int32_t code = -1; + int32_t code = 0; if (pMsg == NULL) { rpcFreeCont(pRpc->pCont); pRpc->pCont = NULL; + code = -1; } else { memcpy(pMsg, pRpc, sizeof(SRpcMsg)); switch (qtype) { @@ -342,6 +343,7 @@ static int32_t vmPutRpcMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pRpc, EQueueType q taosWriteQitem(pVnode->pSyncQ, pMsg); break; default: + code = -1; terrno = TSDB_CODE_INVALID_PARA; break; } From 3b4551cc269005934fd483d0c7b630084b10bf7a Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 20 May 2022 07:07:51 +0000 Subject: [PATCH 05/11] fix: tdb concurrency --- source/libs/tdb/src/db/tdbPCache.c | 58 ++++++++++++++++++------------ source/libs/tdb/src/db/tdbPager.c | 13 ++++++- source/libs/tdb/src/inc/tdbInt.h | 14 ++++---- source/libs/tdb/test/tdbTest.cpp | 10 +++--- 4 files changed, 60 insertions(+), 35 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 22d7e8e5a4..5ba5d65815 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -14,6 +14,9 @@ */ #include "tdbInt.h" +#include +#include + struct SPCache { int szPage; int nPages; @@ -32,7 +35,6 @@ static inline uint32_t tdbPCachePageHash(const SPgid *pPgid) { uint32_t *t = (uint32_t *)((pPgid)->fileid); return (uint32_t)(t[0] + t[1] + t[2] + t[3] + t[4] + t[5] + (pPgid)->pgno); } -#define PAGE_IS_PINNED(pPage) ((pPage)->pLruNext == NULL) static int tdbPCacheOpenImpl(SPCache *pCache); static SPage *tdbPCacheFetchImpl(SPCache *pCache, const SPgid *pPgid, TXN *pTxn); @@ -80,16 +82,22 @@ int tdbPCacheClose(SPCache *pCache) { SPage *tdbPCacheFetch(SPCache *pCache, const SPgid *pPgid, TXN *pTxn) { SPage *pPage; + i32 nRef; tdbPCacheLock(pCache); pPage = tdbPCacheFetchImpl(pCache, pPgid, pTxn); if (pPage) { - tdbRefPage(pPage); + nRef = tdbRefPage(pPage); } + ASSERT(pPage); + tdbPCacheUnlock(pCache); + // printf("thread %" PRId64 " fetch page %d pgno %d pPage %p nRef %d\n", taosGetSelfPthreadId(), pPage->id, + // TDB_PAGE_PGNO(pPage), pPage, nRef); + return pPage; } @@ -98,30 +106,31 @@ void tdbPCacheRelease(SPCache *pCache, SPage *pPage, TXN *pTxn) { ASSERT(pTxn); + // nRef = tdbUnrefPage(pPage); + // ASSERT(nRef >= 0); + + tdbPCacheLock(pCache); nRef = tdbUnrefPage(pPage); - ASSERT(nRef >= 0); - if (nRef == 0) { - tdbPCacheLock(pCache); - // test the nRef again to make sure // it is safe th handle the page - nRef = tdbGetPageRef(pPage); - if (nRef == 0) { - if (pPage->isLocal) { - tdbPCacheUnpinPage(pCache, pPage); - } else { - if (TDB_TXN_IS_WRITE(pTxn)) { - // remove from hash - tdbPCacheRemovePageFromHash(pCache, pPage); - } - - tdbPageDestroy(pPage, pTxn->xFree, pTxn->xArg); + // nRef = tdbGetPageRef(pPage); + // if (nRef == 0) { + if (pPage->isLocal) { + tdbPCacheUnpinPage(pCache, pPage); + } else { + if (TDB_TXN_IS_WRITE(pTxn)) { + // remove from hash + tdbPCacheRemovePageFromHash(pCache, pPage); } - } - tdbPCacheUnlock(pCache); + tdbPageDestroy(pPage, pTxn->xFree, pTxn->xArg); + } + // } } + tdbPCacheUnlock(pCache); + // printf("thread %" PRId64 " relas page %d pgno %d pPage %p nRef %d\n", taosGetSelfPthreadId(), pPage->id, + // TDB_PAGE_PGNO(pPage), pPage, nRef); } int tdbPCacheGetPageSize(SPCache *pCache) { return pCache->szPage; } @@ -223,6 +232,7 @@ static void tdbPCachePinPage(SPCache *pCache, SPage *pPage) { pCache->nRecyclable--; + // printf("pin page %d pgno %d pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage); tdbTrace("pin page %d", pPage->id); } } @@ -243,6 +253,7 @@ static void tdbPCacheUnpinPage(SPCache *pCache, SPage *pPage) { pCache->nRecyclable++; + // printf("unpin page %d pgno %d pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage); tdbTrace("unpin page %d", pPage->id); } @@ -253,10 +264,12 @@ static void tdbPCacheRemovePageFromHash(SPCache *pCache, SPage *pPage) { h = tdbPCachePageHash(&(pPage->pgid)); for (ppPage = &(pCache->pgHash[h % pCache->nHash]); (*ppPage) && *ppPage != pPage; ppPage = &((*ppPage)->pHashNext)) ; - ASSERT(*ppPage == pPage); - *ppPage = pPage->pHashNext; - pCache->nPage--; + if (*ppPage) { + *ppPage = pPage->pHashNext; + pCache->nPage--; + // printf("rmv page %d to hash, pgno %d, pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage); + } tdbTrace("remove page %d to hash", pPage->id); } @@ -271,6 +284,7 @@ static void tdbPCacheAddPageToHash(SPCache *pCache, SPage *pPage) { pCache->nPage++; + // printf("add page %d to hash, pgno %d, pPage %p\n", pPage->id, TDB_PAGE_PGNO(pPage), pPage); tdbTrace("add page %d to hash", pPage->id); } diff --git a/source/libs/tdb/src/db/tdbPager.c b/source/libs/tdb/src/db/tdbPager.c index 4024cfe745..a74bb54883 100644 --- a/source/libs/tdb/src/db/tdbPager.c +++ b/source/libs/tdb/src/db/tdbPager.c @@ -265,6 +265,7 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa pgid.pgno = pgno; pPage = tdbPCacheFetch(pPager->pCache, &pgid, pTxn); if (pPage == NULL) { + ASSERT(0); return -1; } @@ -272,10 +273,14 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa if (!TDB_PAGE_INITIALIZED(pPage)) { ret = tdbPagerInitPage(pPager, pPage, initPage, arg, loadPage); if (ret < 0) { + ASSERT(0); return -1; } } + // printf("thread %" PRId64 " pager fetch page %d pgno %d ppage %p\n", taosGetSelfPthreadId(), pPage->id, + // TDB_PAGE_PGNO(pPage), pPage); + ASSERT(TDB_PAGE_INITIALIZED(pPage)); ASSERT(pPage->pPager == pPager); @@ -284,7 +289,11 @@ int tdbPagerFetchPage(SPager *pPager, SPgno *ppgno, SPage **ppPage, int (*initPa return 0; } -void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn) { tdbPCacheRelease(pPager->pCache, pPage, pTxn); } +void tdbPagerReturnPage(SPager *pPager, SPage *pPage, TXN *pTxn) { + tdbPCacheRelease(pPager->pCache, pPage, pTxn); + // printf("thread %" PRId64 " pager retun page %d pgno %d ppage %p\n", taosGetSelfPthreadId(), pPage->id, + // TDB_PAGE_PGNO(pPage), pPage); +} static int tdbPagerAllocFreePage(SPager *pPager, SPgno *ppgno) { // TODO: Allocate a page from the free list @@ -352,6 +361,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage ret = (*initPage)(pPage, arg, init); if (ret < 0) { + ASSERT(0); TDB_UNLOCK_PAGE(pPage); return -1; } @@ -370,6 +380,7 @@ static int tdbPagerInitPage(SPager *pPager, SPage *pPage, int (*initPage)(SPage } } } else { + ASSERT(0); return -1; } diff --git a/source/libs/tdb/src/inc/tdbInt.h b/source/libs/tdb/src/inc/tdbInt.h index 2c79f39bc0..9f0267da93 100644 --- a/source/libs/tdb/src/inc/tdbInt.h +++ b/source/libs/tdb/src/inc/tdbInt.h @@ -275,15 +275,15 @@ static inline i32 tdbUnrefPage(SPage *pPage) { #define P_LOCK_FAIL -1 static inline int tdbTryLockPage(tdb_spinlock_t *pLock) { - int ret; - if (tdbSpinlockTrylock(pLock) == 0) { - ret = P_LOCK_SUCC; - } else if (errno == EBUSY) { - ret = P_LOCK_BUSY; + int ret = tdbSpinlockTrylock(pLock); + if (ret == 0) { + return P_LOCK_SUCC; + } else if (ret == EBUSY) { + return P_LOCK_BUSY; } else { - ret = P_LOCK_FAIL; + ASSERT(0); + return P_LOCK_FAIL; } - return ret; } #define TDB_INIT_PAGE_LOCK(pPage) tdbSpinlockInit(&((pPage)->lock), 0) diff --git a/source/libs/tdb/test/tdbTest.cpp b/source/libs/tdb/test/tdbTest.cpp index 5a3b45cca5..6070052127 100644 --- a/source/libs/tdb/test/tdbTest.cpp +++ b/source/libs/tdb/test/tdbTest.cpp @@ -486,18 +486,18 @@ TEST(tdb_test, DISABLED_simple_upsert1) { tdbClose(pEnv); } -TEST(tdb_test, DISABLED_multi_thread_query) { +TEST(tdb_test, multi_thread_query) { int ret; TDB *pEnv; TTB *pDb; tdb_cmpr_fn_t compFunc; - int nData = 100000; + int nData = 1000000; TXN txn; taosRemoveDir("tdb"); // Open Env - ret = tdbOpen("tdb", 512, 1, &pEnv); + ret = tdbOpen("tdb", 4096, 10, &pEnv); GTEST_ASSERT_EQ(ret, 0); // Create a database @@ -507,7 +507,7 @@ TEST(tdb_test, DISABLED_multi_thread_query) { char key[64]; char val[64]; - int64_t poolLimit = 4096; // 1M pool limit + int64_t poolLimit = 4096 * 20; // 1M pool limit int64_t txnid = 0; SPoolMem *pPool; @@ -600,7 +600,7 @@ TEST(tdb_test, DISABLED_multi_thread_query) { GTEST_ASSERT_EQ(ret, 0); } -TEST(tdb_test, multi_thread1) { +TEST(tdb_test, DISABLED_multi_thread1) { #if 0 int ret; TDB *pDb; From 9025abe617c30ba71b2c553e0574f8bdb9303baa Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Fri, 20 May 2022 15:14:02 +0800 Subject: [PATCH 06/11] fix(os): disable win compile warning output --- cmake/cmake.define | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmake/cmake.define b/cmake/cmake.define index 4e27ff5f47..55412fd26f 100644 --- a/cmake/cmake.define +++ b/cmake/cmake.define @@ -46,11 +46,17 @@ ENDIF () IF (TD_WINDOWS) MESSAGE("${Yellow} set compiler flag for Windows! ${ColourReset}") - SET(COMMON_FLAGS "/W3 /D_WIN32") + SET(COMMON_FLAGS "/w /D_WIN32") SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO") # IF (MSVC AND (MSVC_VERSION GREATER_EQUAL 1900)) # SET(COMMON_FLAGS "${COMMON_FLAGS} /Wv:18") # ENDIF () + IF (CMAKE_DEPFILE_FLAGS_C) + SET(CMAKE_DEPFILE_FLAGS_C "") + ENDIF () + IF (CMAKE_DEPFILE_FLAGS_CXX) + SET(CMAKE_DEPFILE_FLAGS_CXX "") + ENDIF () SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COMMON_FLAGS}") SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COMMON_FLAGS}") From b563902bb494f7e62ecf8f8257502dc3e8f3f66c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Fri, 20 May 2022 07:40:21 +0000 Subject: [PATCH 07/11] make it compile --- source/libs/tdb/src/db/tdbPCache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/tdb/src/db/tdbPCache.c b/source/libs/tdb/src/db/tdbPCache.c index 5ba5d65815..cdae73bfb9 100644 --- a/source/libs/tdb/src/db/tdbPCache.c +++ b/source/libs/tdb/src/db/tdbPCache.c @@ -14,8 +14,8 @@ */ #include "tdbInt.h" -#include -#include +// #include +// #include struct SPCache { int szPage; From 28b7f9599ed10d5a119b2f35c285f6b3a38b72a7 Mon Sep 17 00:00:00 2001 From: afwerar <1296468573@qq.com> Date: Fri, 20 May 2022 16:20:15 +0800 Subject: [PATCH 08/11] fix(os): disable win compile tests --- cmake/cmake.options | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/cmake/cmake.options b/cmake/cmake.options index d83ab49fd5..c77b580c17 100644 --- a/cmake/cmake.options +++ b/cmake/cmake.options @@ -46,6 +46,18 @@ IF(${TD_WINDOWS}) ON ) + option( + BUILD_TEST + "If build unit tests using googletest" + OFF + ) +ELSE () + + option( + BUILD_TEST + "If build unit tests using googletest" + ON + ) ENDIF () option( @@ -54,12 +66,6 @@ option( OFF ) -option( - BUILD_TEST - "If build unit tests using googletest" - ON -) - option( BUILD_WITH_LEVELDB "If build with leveldb" From 5e819fbdb3c00a5704c1b84cf24c91c8fea4288d Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 20 May 2022 16:50:39 +0800 Subject: [PATCH 09/11] fix(query): assign the group id in the ssdatablock when generating grouped results. --- source/libs/executor/src/executorimpl.c | 32 ++++++++++++------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/source/libs/executor/src/executorimpl.c b/source/libs/executor/src/executorimpl.c index 37aeb367f5..750554e828 100644 --- a/source/libs/executor/src/executorimpl.c +++ b/source/libs/executor/src/executorimpl.c @@ -2062,15 +2062,7 @@ void setExecutionContext(int32_t numOfOutput, uint64_t groupId, SExecTaskInfo* p pAggInfo->groupId = groupId; } -/** - * For interval query of both super table and table, copy the data in ascending order, since the output results are - * ordered in SWindowResutl already. While handling the group by query for both table and super table, - * all group result are completed already. - * - * @param pQInfo - * @param result - */ -int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, +int32_t doCopyToSDataBlock(SExecTaskInfo* pTaskInfo, SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, SGroupResInfo* pGroupResInfo, int32_t* rowCellOffset, SqlFunctionCtx* pCtx, int32_t numOfExprs) { int32_t numOfRows = getNumOfTotalRes(pGroupResInfo); int32_t start = pGroupResInfo->index; @@ -2087,6 +2079,15 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock, SExprIn continue; } + if (pBlock->info.groupId == 0) { + pBlock->info.groupId = pPos->groupId; + } else { + // current value belongs to different group, it can't be packed into one datablock + if (pBlock->info.groupId != pPos->groupId) { + break; + } + } + if (pBlock->info.rows + pRow->numOfRows > pBlock->info.capacity) { break; } @@ -2100,9 +2101,8 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock, SExprIn if (pCtx[j].fpSet.finalize) { int32_t code = pCtx[j].fpSet.finalize(&pCtx[j], pBlock); if (TAOS_FAILED(code)) { - qError("%s build result data block error, code %s", GET_TASKID(taskInfo), tstrerror(code)); - taskInfo->code = code; - longjmp(taskInfo->env, code); + qError("%s build result data block error, code %s", GET_TASKID(pTaskInfo), tstrerror(code)); + longjmp(pTaskInfo->env, code); } } else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) { // do nothing, todo refactor @@ -2124,7 +2124,7 @@ int32_t doCopyToSDataBlock(SExecTaskInfo* taskInfo, SSDataBlock* pBlock, SExprIn } } - // qDebug("QInfo:0x%"PRIx64" copy data to query buf completed", GET_TASKID(pRuntimeEnv)); + qDebug("%s result generated, rows:%d, groupId:%"PRIu64, GET_TASKID(pTaskInfo), pBlock->info.rows, pBlock->info.groupId); blockDataUpdateTsWindow(pBlock); return 0; } @@ -2145,10 +2145,9 @@ void doBuildResultDatablock(SOperatorInfo* pOperator, SOptrBasicInfo* pbInfo, SG return; } + // clear the existed group id + pBlock->info.groupId = 0; doCopyToSDataBlock(pTaskInfo, pBlock, pExprInfo, pBuf, pGroupResInfo, rowCellOffset, pCtx, numOfExprs); - - // add condition (pBlock->info.rows >= 1) just to runtime happy - blockDataUpdateTsWindow(pBlock); } static void updateNumOfRowsInResultRows(SqlFunctionCtx* pCtx, int32_t numOfOutput, SResultRowInfo* pResultRowInfo, @@ -3656,7 +3655,6 @@ static SSDataBlock* getAggregateResult(SOperatorInfo* pOperator) { doSetOperatorCompleted(pOperator); } - doSetOperatorCompleted(pOperator); return (blockDataGetNumOfRows(pInfo->pRes) != 0) ? pInfo->pRes : NULL; } From fa84d0585bf5bb01a7d6d6f14f710dfe39d79827 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Fri, 20 May 2022 17:07:53 +0800 Subject: [PATCH 10/11] enh(query): enable remove the candidate table ids in the stream scanner. --- source/dnode/vnode/inc/vnode.h | 2 + source/dnode/vnode/src/tq/tqRead.c | 11 +++++ source/libs/executor/src/executor.c | 70 ++++++++++++++++------------- 3 files changed, 53 insertions(+), 30 deletions(-) diff --git a/source/dnode/vnode/inc/vnode.h b/source/dnode/vnode/inc/vnode.h index ecb022426b..b870c406ec 100644 --- a/source/dnode/vnode/inc/vnode.h +++ b/source/dnode/vnode/inc/vnode.h @@ -126,6 +126,8 @@ STqReadHandle *tqInitSubmitMsgScanner(SMeta *pMeta); void tqReadHandleSetColIdList(STqReadHandle *pReadHandle, SArray *pColIdList); int tqReadHandleSetTbUidList(STqReadHandle *pHandle, const SArray *tbUidList); int tqReadHandleAddTbUidList(STqReadHandle *pHandle, const SArray *tbUidList); +int tqReadHandleRemoveTbUidList(STqReadHandle* pHandle, const SArray* tbUidList); + int32_t tqReadHandleSetMsg(STqReadHandle *pHandle, SSubmitReq *pMsg, int64_t ver); bool tqNextDataBlock(STqReadHandle *pHandle); int32_t tqRetrieveDataBlock(SArray **ppCols, STqReadHandle *pHandle, uint64_t *pGroupId, uint64_t *pUid, diff --git a/source/dnode/vnode/src/tq/tqRead.c b/source/dnode/vnode/src/tq/tqRead.c index 8fbd1e24e1..6ab2b0d917 100644 --- a/source/dnode/vnode/src/tq/tqRead.c +++ b/source/dnode/vnode/src/tq/tqRead.c @@ -235,3 +235,14 @@ int tqReadHandleAddTbUidList(STqReadHandle* pHandle, const SArray* tbUidList) { return 0; } + +int tqReadHandleRemoveTbUidList(STqReadHandle* pHandle, const SArray* tbUidList) { + ASSERT(pHandle->tbIdHash != NULL); + + for(int32_t i = 0; i < taosArrayGetSize(tbUidList); i++) { + int64_t* pKey = (int64_t*) taosArrayGet(tbUidList, i); + taosHashRemove(pHandle->tbIdHash, pKey, sizeof(int64_t)); + } + + return 0; +} diff --git a/source/libs/executor/src/executor.c b/source/libs/executor/src/executor.c index fa840e1cd6..6d308d7221 100644 --- a/source/libs/executor/src/executor.c +++ b/source/libs/executor/src/executor.c @@ -125,6 +125,33 @@ qTaskInfo_t qCreateStreamExecTaskInfo(void* msg, void* streamReadHandle) { return pTaskInfo; } +static SArray* filterQualifiedChildTables(const SStreamBlockScanInfo* pScanInfo, const SArray* tableIdList) { + SArray* qa = taosArrayInit(4, sizeof(tb_uid_t)); + + // let's discard the tables those are not created according to the queried super table. + SMetaReader mr = {0}; + metaReaderInit(&mr, pScanInfo->readHandle.meta, 0); + for (int32_t i = 0; i < taosArrayGetSize(tableIdList); ++i) { + int64_t* id = (int64_t*)taosArrayGet(tableIdList, i); + + int32_t code = metaGetTableEntryByUid(&mr, *id); + if (code != TSDB_CODE_SUCCESS) { + qError("failed to get table meta, uid:%" PRIu64 " code:%s", *id, tstrerror(terrno)); + continue; + } + + ASSERT(mr.me.type == TSDB_CHILD_TABLE); + if (mr.me.ctbEntry.suid != pScanInfo->tableUid) { + continue; + } + + taosArrayPush(qa, id); + } + + metaReaderClear(&mr); + return qa; +} + int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) { SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo; @@ -134,41 +161,24 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo pInfo = pInfo->pDownstream[0]; } + int32_t code = 0; SStreamBlockScanInfo* pScanInfo = pInfo->info; - if (isAdd) { - SArray* qa = taosArrayInit(4, sizeof(tb_uid_t)); - - SMetaReader mr = {0}; - metaReaderInit(&mr, pScanInfo->readHandle.meta, 0); - for (int32_t i = 0; i < taosArrayGetSize(tableIdList); ++i) { - int64_t* id = (int64_t*)taosArrayGet(tableIdList, i); - - int32_t code = metaGetTableEntryByUid(&mr, *id); - if (code != TSDB_CODE_SUCCESS) { - qError("failed to get table meta, uid:%" PRIu64 " code:%s", *id, tstrerror(terrno)); - continue; - } - - ASSERT(mr.me.type == TSDB_CHILD_TABLE); - if (mr.me.ctbEntry.suid != pScanInfo->tableUid) { - continue; - } - - taosArrayPush(qa, id); - } - - metaReaderClear(&mr); + if (isAdd) { // add new table id + SArray* qa = filterQualifiedChildTables(pScanInfo, tableIdList); qDebug(" %d qualified child tables added into stream scanner", (int32_t)taosArrayGetSize(qa)); - int32_t code = tqReadHandleAddTbUidList(pScanInfo->streamBlockReader, qa); - if (code != TSDB_CODE_SUCCESS) { - return code; - } - } else { - assert(0); + code = tqReadHandleAddTbUidList(pScanInfo->streamBlockReader, qa); + taosArrayDestroy(qa); + + } else { // remove the table id in current list + SArray* qa = filterQualifiedChildTables(pScanInfo, tableIdList); + + qDebug(" %d remove child tables from the stream scanner", (int32_t)taosArrayGetSize(tableIdList)); + code = tqReadHandleAddTbUidList(pScanInfo->streamBlockReader, tableIdList); + taosArrayDestroy(qa); } - return TSDB_CODE_SUCCESS; + return code; } int32_t qGetQueriedTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, char* tableName, int32_t* sversion, int32_t* tversion) { From e9607a9e25c7dfdf906b6a8203360038aa3c6f14 Mon Sep 17 00:00:00 2001 From: Cary Xu Date: Fri, 20 May 2022 17:24:10 +0800 Subject: [PATCH 11/11] feat: add cases to merge dup data in file and mem --- source/dnode/vnode/src/tsdb/tsdbRead.c | 2 +- tests/script/tsim/insert/update0.sim | 83 ++++++++++++++++++++++++-- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/source/dnode/vnode/src/tsdb/tsdbRead.c b/source/dnode/vnode/src/tsdb/tsdbRead.c index b9ef72edc5..f0aa4d2ac6 100644 --- a/source/dnode/vnode/src/tsdb/tsdbRead.c +++ b/source/dnode/vnode/src/tsdb/tsdbRead.c @@ -2077,10 +2077,10 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf #endif if (TD_SUPPORT_UPDATE(pCfg->update)) { if (lastKeyAppend != key) { - lastKeyAppend = key; if (lastKeyAppend != TSKEY_INITIAL_VAL) { ++curRow; } + lastKeyAppend = key; } // load data from file firstly numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, pos, pos); diff --git a/tests/script/tsim/insert/update0.sim b/tests/script/tsim/insert/update0.sim index c34a08c79d..89eecaf860 100644 --- a/tests/script/tsim/insert/update0.sim +++ b/tests/script/tsim/insert/update0.sim @@ -35,7 +35,7 @@ sql insert into ct1 values('2022-05-03 16:59:00.016', 18); sql insert into ct1 values('2022-05-03 16:59:00.021', 21); sql insert into ct1 values('2022-05-03 16:59:00.022', 22); -print =============== step3-1 query records from ct1 from memory +print =============== step3-1 query records of ct1 from memory sql select * from ct1; print $data00 $data01 print $data10 $data11 @@ -69,7 +69,7 @@ sql insert into ct2 values('2022-03-02 16:59:00.010', 1),('2022-03-02 16:59:00.0 sql insert into ct2 values('2022-03-02 16:59:00.010', 3),('2022-03-02 16:59:00.010',33),('2022-04-01 16:59:00.011',4),('2022-04-01 16:59:00.011',6),('2022-03-06 16:59:00.013',8); sql insert into ct2 values('2022-03-02 16:59:00.010', 103),('2022-03-02 16:59:00.010',303),('2022-04-01 16:59:00.011',40),('2022-04-01 16:59:00.011',60),('2022-03-06 16:59:00.013',80); -print =============== step3-1 query records from ct2 from memory +print =============== step3-1 query records of ct2 from memory sql select * from ct2; print $data00 $data01 print $data10 $data11 @@ -99,7 +99,7 @@ endi system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s start -print =============== step3-2 query records from ct1 from file +print =============== step3-2 query records of ct1 from file sql select * from ct1; print $data00 $data01 print $data10 $data11 @@ -128,7 +128,7 @@ if $data51 != 22 then return -1 endi -print =============== step3-2 query records from ct2 from file +print =============== step3-2 query records of ct2 from file sql select * from ct2; print $data00 $data01 print $data10 $data11 @@ -152,4 +152,79 @@ endi if $data21 != 40 then print data21 $data21 != 40 return -1 +endi + +print =============== step3-3 query records of ct1 from memory and file(merge) +sql insert into ct1 values('2022-05-03 16:59:00.010', 100); +sql insert into ct1 values('2022-05-03 16:59:00.022', 200); +sql insert into ct1 values('2022-05-03 16:59:00.016', 160); + +sql select * from ct1; +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 +print $data30 $data31 +print $data40 $data41 +print $data50 $data51 + +if $rows != 6 then + print rows $rows != 6 + return -1 +endi + +if $data01 != 100 then + print data01 $data01 != 100 + return -1 +endi + +if $data21 != 160 then + print data21 $data21 != 160 + return -1 +endi + +if $data51 != 200 then + print data51 $data51 != 200 + return -1 +endi + +print =============== step3-3 query records of ct2 from memory and file(merge) +sql insert into ct2(ts) values('2022-04-02 16:59:00.016'); +sql insert into ct2 values('2022-03-06 16:59:00.013', NULL); +sql insert into ct2 values('2022-03-01 16:59:00.016', 10); +sql insert into ct2(ts) values('2022-04-01 16:59:00.011'); +sql select * from ct2; +print $data00 $data01 +print $data10 $data11 +print $data20 $data21 +print $data30 $data31 +print $data40 $data41 + +if $rows != 5 then + print rows $rows != 5 + return -1 +endi + +if $data01 != 10 then + print data01 $data01 != 10 + return -1 +endi + +if $data11 != 103 then + print data11 $data11 != 103 + return -1 +endi + +if $data21 != NULL then + print data21 $data21 != NULL + return -1 +endi + +if $data31 != 40 then + print data31 $data31 != 40 + return -1 +endi + +if $data41 != NULL then + print data41 $data41 != NULL + return -1 endi \ No newline at end of file