diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 78255a45d5432fffe3ea0d2daf87d94dff041e42..c8bd2c60769ca80eec1d6ac1f2fd390719e367bf 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -618,7 +618,7 @@ typedef struct { } SMDVnodeDesc; typedef struct { - char db[TSDB_DB_NAME_LEN]; + char db[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; SMDVnodeCfg cfg; SMDVnodeDesc nodes[TSDB_MAX_REPLICA]; } SMDCreateVnodeMsg; diff --git a/src/mnode/inc/mnodeDef.h b/src/mnode/inc/mnodeDef.h index ae1ba98a0f4a15d37824de71e5db81c73effa89c..46d2675705e5b7dc0ee53ba8db8f62a9ad5046df 100644 --- a/src/mnode/inc/mnodeDef.h +++ b/src/mnode/inc/mnodeDef.h @@ -132,7 +132,7 @@ typedef struct SVgObj { int64_t createdTime; int32_t lbDnodeId; int32_t lbTime; - char dbName[TSDB_DB_NAME_LEN]; + char dbName[TSDB_ACCT_LEN + TSDB_DB_NAME_LEN]; int8_t inUse; int8_t accessState; int8_t reserved0[5]; diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index e1d255ee76ee9140ee5a9a071582d73fa67b272d..761dce6720c1f43a14ff1c4d01ec3e844ae039ac 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -367,6 +367,7 @@ void sdbCleanUp() { tsSdbObj.status = SDB_STATUS_CLOSING; sdbCleanupWriteWorker(); + sdbDebug("sdb will be closed, version:%" PRId64, tsSdbObj.version); if (tsSdbObj.sync) { syncStop(tsSdbObj.sync); diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index 6f5216dfa3754a3bf3bd4724e179facc7ea161c8..06ef2cb452fb063f642b12c6b3c7c5cf44d1b673 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -281,6 +281,7 @@ static int32_t mnodeProcessHeartBeatMsg(SMnodeMsg *pMsg) { static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { SCMConnectMsg *pConnectMsg = pMsg->rpcMsg.pCont; + SCMConnectRsp *pConnectRsp = NULL; int32_t code = TSDB_CODE_SUCCESS; SRpcConnInfo connInfo; @@ -309,7 +310,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { mnodeDecDbRef(pDb); } - SCMConnectRsp *pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp)); + pConnectRsp = rpcMallocCont(sizeof(SCMConnectRsp)); if (pConnectRsp == NULL) { code = TSDB_CODE_MND_OUT_OF_MEMORY; goto connect_over; @@ -332,7 +333,7 @@ static int32_t mnodeProcessConnectMsg(SMnodeMsg *pMsg) { connect_over: if (code != TSDB_CODE_SUCCESS) { - rpcFreeCont(pConnectRsp); + if (pConnectRsp) rpcFreeCont(pConnectRsp); mLError("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code)); } else { mLInfo("user:%s login from %s, result:%s", connInfo.user, taosIpStr(connInfo.clientIp), tstrerror(code)); diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 2d9892cf017f0674d6a944af12641633d84f1b68..65900a60dbe8413b1e04602d8729484d43c4993a 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -457,10 +457,9 @@ static int32_t mnodeSuperTableActionUpdate(SSdbOper *pOper) { free(pNew); free(oldTableId); free(oldSchema); - - mnodeDecTableRef(pTable); } + mnodeDecTableRef(pTable); return TSDB_CODE_SUCCESS; } @@ -2374,6 +2373,17 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows strcat(prefix, TS_PATH_DELIMITER); int32_t prefixLen = strlen(prefix); + char* pattern = NULL; + if (pShow->payloadLen > 0) { + pattern = (char*)malloc(pShow->payloadLen + 1); + if (pattern == NULL) { + terrno = TSDB_CODE_QRY_OUT_OF_MEMORY; + return 0; + } + memcpy(pattern, pShow->payload, pShow->payloadLen); + pattern[pShow->payloadLen] = 0; + } + while (numOfRows < rows) { pShow->pIter = mnodeGetNextChildTable(pShow->pIter, &pTable); if (pTable == NULL) break; @@ -2389,7 +2399,7 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows // pattern compare for table name mnodeExtractTableName(pTable->info.tableId, tableName); - if (pShow->payloadLen > 0 && patternMatch(pShow->payload, tableName, sizeof(tableName) - 1, &info) != TSDB_PATTERN_MATCH) { + if (pattern != NULL && patternMatch(pattern, tableName, sizeof(tableName) - 1, &info) != TSDB_PATTERN_MATCH) { mnodeDecTableRef(pTable); continue; } @@ -2433,6 +2443,7 @@ static int32_t mnodeRetrieveShowTables(SShowObj *pShow, char *data, int32_t rows mnodeVacuumResult(data, NUM_OF_COLUMNS, numOfRows, rows, pShow); mnodeDecDbRef(pDb); + free(pattern); return numOfRows; } diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 36fa306c9f5180e1a7fac51424740ab5b6b30cd0..b314bfc8d03689842e33bdbbe9f5197a3bd9f6ca 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -358,7 +358,7 @@ int32_t mnodeCreateVgroup(SMnodeMsg *pMsg, SDbObj *pDb) { if (pMsg == NULL) return TSDB_CODE_MND_APP_ERROR; SVgObj *pVgroup = (SVgObj *)calloc(1, sizeof(SVgObj)); - tstrncpy(pVgroup->dbName, pDb->name, TSDB_DB_NAME_LEN); + tstrncpy(pVgroup->dbName, pDb->name, TSDB_ACCT_LEN + TSDB_DB_NAME_LEN); pVgroup->numOfVnodes = pDb->cfg.replications; pVgroup->createdTime = taosGetTimestampMs(); pVgroup->accessState = TSDB_VN_ALL_ACCCESS; diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 94fefa16f32994f19ed8902e78e5c63c59912edb..ff9cff54bfda4e4e23a7516f9f6083a370929b89 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -6009,7 +6009,7 @@ void qDestroyQueryInfo(qinfo_t qHandle, void (*fp)(void*), void* param) { return; } - int16_t ref = T_REF_DEC(pQInfo); + int32_t ref = T_REF_DEC(pQInfo); qDebug("QInfo:%p dec refCount, value:%d", pQInfo, ref); if (ref == 0) { diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 12db79182e51c03b3f1f83033a51f37f75548457..d3b9081a36b5ddc2e16a23d5e4eb7e75e19ae1c3 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -111,7 +111,7 @@ int tsdbInsertRowToMem(STsdbRepo *pRepo, SDataRow row, STable *pTable) { ASSERT(pTableData->numOfRows == tSkipListGetSize(pTableData->pData)); } - tsdbDebug("vgId:%d a row is inserted to table %s tid %d uid %" PRIu64 " key %" PRIu64, REPO_ID(pRepo), + tsdbTrace("vgId:%d a row is inserted to table %s tid %d uid %" PRIu64 " key %" PRIu64, REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable), key); return 0; diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index b769a87beb0c23fa4cb2a3fc6c335999dea5dc5e..13b676ee1dc27be6a8f6c2f76fc5b8cd942d6089 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -550,13 +550,13 @@ int tsdbUnlockRepoMeta(STsdbRepo *pRepo) { } void tsdbRefTable(STable *pTable) { - int16_t ref = T_REF_INC(pTable); + int32_t ref = T_REF_INC(pTable); UNUSED(ref); // tsdbDebug("ref table %"PRIu64", tid:%d, refCount:%d", TABLE_UID(pTable), TABLE_TID(pTable), ref); } void tsdbUnRefTable(STable *pTable) { - int16_t ref = T_REF_DEC(pTable); + int32_t ref = T_REF_DEC(pTable); tsdbDebug("unref table uid:%"PRIu64", tid:%d, refCount:%d", TABLE_UID(pTable), TABLE_TID(pTable), ref); if (ref == 0) { @@ -596,7 +596,7 @@ static int tsdbRestoreTable(void *pHandle, void *cont, int contLen) { return -1; } - tsdbDebug("vgId:%d table %s tid %d uid %" PRIu64 " is restored from file", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), + tsdbTrace("vgId:%d table %s tid %d uid %" PRIu64 " is restored from file", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable)); return 0; } @@ -797,7 +797,7 @@ static int tsdbAddTableToMeta(STsdbRepo *pRepo, STable *pTable, bool addIdx) { pTable->cqhandle = (*pRepo->appH.cqCreateFunc)(pRepo->appH.cqH, TABLE_UID(pTable), TABLE_TID(pTable), pTable->sql, tsdbGetTableSchema(pTable)); } - tsdbDebug("vgId:%d table %s tid %d uid %" PRIu64 " is added to meta", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), + tsdbTrace("vgId:%d table %s tid %d uid %" PRIu64 " is added to meta", REPO_ID(pRepo), TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable)); return 0; @@ -1252,4 +1252,4 @@ static int tsdbRmTableFromMeta(STsdbRepo *pRepo, STable *pTable) { } return 0; -} \ No newline at end of file +} diff --git a/src/util/inc/tref.h b/src/util/inc/tref.h index fa2517e19a16942fd874cab1fff00262c1b90722..0503325326ab90837de9c1990de44db45548b946 100644 --- a/src/util/inc/tref.h +++ b/src/util/inc/tref.h @@ -22,7 +22,7 @@ typedef void (*_ref_fn_t)(const void* pObj); #define T_REF_DECLARE() \ struct { \ - int16_t val; \ + int32_t val; \ } _ref; #define T_REF_REGISTER_FUNC(s, e) \ @@ -31,7 +31,7 @@ typedef void (*_ref_fn_t)(const void* pObj); _ref_fn_t end; \ } _ref_func = {.begin = (s), .end = (e)}; -#define T_REF_INC(x) (atomic_add_fetch_16(&((x)->_ref.val), 1)) +#define T_REF_INC(x) (atomic_add_fetch_32(&((x)->_ref.val), 1)) #define T_REF_INC_WITH_CB(x, p) \ do { \ @@ -41,11 +41,11 @@ typedef void (*_ref_fn_t)(const void* pObj); } \ } while (0) -#define T_REF_DEC(x) (atomic_sub_fetch_16(&((x)->_ref.val), 1)) +#define T_REF_DEC(x) (atomic_sub_fetch_32(&((x)->_ref.val), 1)) #define T_REF_DEC_WITH_CB(x, p) \ do { \ - int32_t v = atomic_sub_fetch_16(&((x)->_ref.val), 1); \ + int32_t v = atomic_sub_fetch_32(&((x)->_ref.val), 1); \ if (v == 0 && (p)->_ref_func.end != NULL) { \ (p)->_ref_func.end((x)); \ } \ diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 2dd641731c7f2cff5cf49c6bf4d7ce1b5865dd6d..2e57ad83aee0a59246bbe6ec25012daecbe916d4 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -415,7 +415,7 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { } *data = NULL; - int16_t ref = T_REF_DEC(pNode); + int32_t ref = T_REF_DEC(pNode); uDebug("%p data released, refcnt:%d", pNode, ref); if (_remove) { diff --git a/src/util/src/tqueue.c b/src/util/src/tqueue.c index b499f340606b1e718f412423fb86b50b78716a5c..f4f79049682253664711ed1981b13faee149404d 100644 --- a/src/util/src/tqueue.c +++ b/src/util/src/tqueue.c @@ -100,7 +100,7 @@ void *taosAllocateQitem(int size) { void taosFreeQitem(void *param) { if (param == NULL) return; - uDebug("item:%p is freed", param); + uTrace("item:%p is freed", param); char *temp = (char *)param; temp -= sizeof(STaosQnode); free(temp); @@ -124,7 +124,7 @@ int taosWriteQitem(taos_queue param, int type, void *item) { queue->numOfItems++; if (queue->qset) atomic_add_fetch_32(&queue->qset->numOfItems, 1); - uDebug("item:%p is put into queue:%p, type:%d items:%d", item, queue, type, queue->numOfItems); + uTrace("item:%p is put into queue:%p, type:%d items:%d", item, queue, type, queue->numOfItems); pthread_mutex_unlock(&queue->mutex); @@ -206,7 +206,7 @@ int taosGetQitem(taos_qall param, int *type, void **pitem) { *pitem = pNode->item; *type = pNode->type; num = 1; - uDebug("item:%p is fetched, type:%d", *pitem, *type); + uTrace("item:%p is fetched, type:%d", *pitem, *type); } return num; @@ -344,7 +344,7 @@ int taosReadQitemFromQset(taos_qset param, int *type, void **pitem, void **phand queue->numOfItems--; atomic_sub_fetch_32(&qset->numOfItems, 1); code = 1; - uDebug("item:%p is read out from queue:%p, type:%d items:%d", *pitem, queue, *type, queue->numOfItems); + uTrace("item:%p is read out from queue:%p, type:%d items:%d", *pitem, queue, *type, queue->numOfItems); } pthread_mutex_unlock(&queue->mutex); diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index f43d10a7a3cc39d456f6c01e21deb219cb89a708..171557acb61b78b3ac8ac7dff7531a21a654daf6 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -94,7 +94,7 @@ static int32_t vnodeProcessSubmitMsg(SVnodeObj *pVnode, void *pCont, SRspRet *pR // save insert result into item - vDebug("vgId:%d, submit msg is processed", pVnode->vgId); + vTrace("vgId:%d, submit msg is processed", pVnode->vgId); pRet->len = sizeof(SShellSubmitRspMsg); pRet->rsp = rpcMallocCont(pRet->len); diff --git a/tests/pytest/query/queryMetaData.py b/tests/pytest/query/queryMetaData.py index 7e30cfc4bfb1508ad87fcf793e6d1447364904d5..65114a62634bb21da42451204341ae6fa2b2c7d5 100755 --- a/tests/pytest/query/queryMetaData.py +++ b/tests/pytest/query/queryMetaData.py @@ -13,16 +13,20 @@ import sys import taos +import threading import time from datetime import datetime - -class QueryMetaData: - def __init__(self): +class MetadataQuery: + def initConnection(self): + self.tables = 10000 + self.records = 10 + self.numOfTherads = 10 + self.ts = 1537146000000 self.host = "127.0.0.1" self.user = "root" self.password = "taosdata" - self.config = "/etc/taos" + self.config = "/etc/taos" def connectDB(self): self.conn = taos.connect( @@ -30,31 +34,88 @@ class QueryMetaData: self.user, self.password, self.config) - self.cursor = self.conn.cursor() + return self.conn.cursor() + + def createStable(self): + print("================= Create stable meters =================") + cursor = self.connectDB() + cursor.execute("drop database if exists test") + cursor.execute("create database test") + cursor.execute("use test") + cursor.execute('''create table if not exists meters (ts timestamp, speed int) tags( + tgcol1 tinyint, tgcol2 smallint, tgcol3 int, tgcol4 bigint, tgcol5 float, tgcol6 double, tgcol7 bool, tgcol8 binary(20), tgcol9 nchar(20), + tgcol10 tinyint, tgcol11 smallint, tgcol12 int, tgcol13 bigint, tgcol14 float, tgcol15 double, tgcol16 bool, tgcol17 binary(20), tgcol18 nchar(20), + tgcol19 tinyint, tgcol20 smallint, tgcol21 int, tgcol22 bigint, tgcol23 float, tgcol24 double, tgcol25 bool, tgcol26 binary(20), tgcol27 nchar(20), + tgcol28 tinyint, tgcol29 smallint, tgcol30 int, tgcol31 bigint, tgcol32 float, tgcol33 double, tgcol34 bool, tgcol35 binary(20), tgcol36 nchar(20), + tgcol37 tinyint, tgcol38 smallint, tgcol39 int, tgcol40 bigint, tgcol41 float, tgcol42 double, tgcol43 bool, tgcol44 binary(20), tgcol45 nchar(20), + tgcol46 tinyint, tgcol47 smallint, tgcol48 int, tgcol49 bigint, tgcol50 float, tgcol51 double, tgcol52 bool, tgcol53 binary(20), tgcol54 nchar(20))''') + cursor.close() + self.conn.close() + + def queryData(self, q): + print("================= query tag data =================") + cursor = self.connectDB() + cursor.execute("use test") - def queryData(self): - print("===============query tag data===============") - self.cursor.execute("use test") startTime = datetime.now() - self.cursor.execute("select areaid from meters") - data = self.cursor.fetchall() + cursor.execute(q) + cursor.fetchall() endTime = datetime.now() - - print(endTime - startTime) - - start = datetime.now() - self.cursor.execute("select areaid, loc from meters") - data2 = self.cursor.fetchall() - end = datetime.now() - - print(end - start) + print("Query time for the above query is %d seconds" % (endTime - startTime).seconds) - def closeConn(self): - self.cursor.close() + cursor.close() self.conn.close() + + def createTablesAndInsertData(self, threadID): + cursor = self.connectDB() + cursor.execute("use test") + base = threadID * self.tables + for i in range(self.tables): + cursor.execute('''create table t%d using meters tags( + %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', + %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', + %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', + %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', + %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d', + %d, %d, %d, %d, %f, %f, %d, 'taosdata%d', '涛思数据%d')''' + % (base + i + 1, + (base + i) % 100, (base + i) % 10000, (base + i) % 1000000, (base + i) % 100000000, (base + i) % 100 * 1.1, (base + i) % 100 * 2.3, (base + i) % 2, (base + i) % 100, (base + i) % 100, + (base + i) % 100, (base + i) % 10000, (base + i) % 1000000, (base + i) % 100000000, (base + i) % 100 * 1.1, (base + i) % 100 * 2.3, (base + i) % 2, (base + i) % 100, (base + i) % 100, + (base + i) % 100, (base + i) % 10000, (base + i) % 1000000, (base + i) % 100000000, (base + i) % 100 * 1.1, (base + i) % 100 * 2.3, (base + i) % 2, (base + i) % 100, (base + i) % 100, + (base + i) % 100, (base + i) % 10000, (base + i) % 1000000, (base + i) % 100000000, (base + i) % 100 * 1.1, (base + i) % 100 * 2.3, (base + i) % 2, (base + i) % 100, (base + i) % 100, + (base + i) % 100, (base + i) % 10000, (base + i) % 1000000, (base + i) % 100000000, (base + i) % 100 * 1.1, (base + i) % 100 * 2.3, (base + i) % 2, (base + i) % 100, (base + i) % 100, + (base + i) % 100, (base + i) % 10000, (base + i) % 1000000, (base + i) % 100000000, (base + i) % 100 * 1.1, (base + i) % 100 * 2.3, (base + i) % 2, (base + i) % 100, (base + i) % 100 )) + for j in range(self.records): + cursor.execute("insert into t%d values(%d, %d)" % (base + i + 1, self.ts + j, j)) + cursor.close() + self.conn.close() + + +if __name__ == '__main__': + + t = MetadataQuery() + t.initConnection() + t.createStable() + + print("================= Create %d tables and insert %d records into each table =================" % (t.tables, t.records)) + startTime = datetime.now() + for i in range(t.numOfTherads): + thread = threading.Thread(target=t.createTablesAndInsertData, args=(i,)) + thread.start() + thread.join() + endTime = datetime.now() + diff = (endTime - startTime).seconds + + print("spend %d seconds to create %d tables and insert %d records into each table" % (diff, t.tables, t.records)); + + # tgcol28, tgcol29, tgcol30, tgcol31, tgcol32, tgcol33, tgcol34, tgcol35, tgcol36, + # tgcol37, tgcol38, tgcol39, tgcol40, tgcol41, tgcol42, tgcol43, tgcol44, tgcol45, + # tgcol46, tgcol47, tgcol48, tgcol49, tgcol50, tgcol51, tgcol52, tgcol53, tgcol54 + # tgcol19, tgcol20, tgcol21, tgcol22, tgcol23, tgcol24, tgcol25, tgcol26, tgcol27, + query = '''select tgcol1, tgcol2, tgcol3, tgcol4, tgcol5, tgcol6, tgcol7, tgcol8, tgcol9, + tgcol10, tgcol11, tgcol12, tgcol13, tgcol14, tgcol15, tgcol16, tgcol17, tgcol18, + from meters where tgcol1 > 10 AND tgcol1 < 100 and tgcol2 > 100 and tgcol2 < 1000 or tgcol3 > 10000 or tgcol7 = true + or tgcol8 like '%2' and tgcol10 < 10''' -test = QueryMetaData() -test.connectDB() -test.queryData() -test.closeConn() + t.queryData(query) diff --git a/tests/script/regressionSuite.sim b/tests/script/regressionSuite.sim index c671cf47c63b9fa866dfa29dfa569321113f1488..f4ffb5ea9e6655319e5fa9d0a7b0e31133497405 100644 --- a/tests/script/regressionSuite.sim +++ b/tests/script/regressionSuite.sim @@ -142,6 +142,8 @@ run general/stable/dnode3.sim run general/stable/metrics.sim run general/stable/values.sim run general/stable/vnode3.sim +run general/stable/refcount.sim +run general/stable/show.sim run general/table/autocreate.sim run general/table/basic1.sim run general/table/basic2.sim