From 4079bd2b5536d117b585b72e59ecb88d75566e67 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 15:14:12 +0800 Subject: [PATCH 1/8] refactor code --- source/libs/index/src/index.c | 21 +++---- source/libs/index/src/index_cache.c | 2 +- .../index/src/index_fst_counting_writer.c | 4 +- source/libs/index/src/index_tfile.c | 56 ++++++++++--------- source/libs/index/test/indexTests.cc | 2 +- 5 files changed, 40 insertions(+), 45 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 0657c68458..691e564c68 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -74,16 +74,15 @@ int indexOpen(SIndexOpts* opts, const char* path, SIndex** index) { // sIdx->cache = (void*)indexCacheCreate(sIdx); sIdx->tindex = indexTFileCreate(path); if (sIdx->tindex == NULL) { goto END; } + sIdx->colObj = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK); sIdx->cVersion = 1; - sIdx->path = calloc(1, strlen(path) + 1); - memcpy(sIdx->path, path, strlen(path)); + sIdx->path = tstrdup(path); pthread_mutex_init(&sIdx->mtx, NULL); - *index = sIdx; - return 0; #endif + END: if (sIdx != NULL) { indexClose(sIdx); } @@ -310,18 +309,14 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result // Get col info IndexCache* cache = NULL; - pthread_mutex_lock(&sIdx->mtx); char buf[128] = {0}; ICacheKey key = {.suid = term->suid, .colName = term->colName, .nColName = strlen(term->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); + pthread_mutex_lock(&sIdx->mtx); IndexCache** pCache = taosHashGet(sIdx->colObj, buf, sz); - if (pCache == NULL) { - pthread_mutex_unlock(&sIdx->mtx); - return -1; - } - cache = *pCache; + cache = (pCache == NULL) ? NULL : *pCache; pthread_mutex_unlock(&sIdx->mtx); *result = taosArrayInit(4, sizeof(uint64_t)); @@ -329,7 +324,7 @@ static int indexTermSearch(SIndex* sIdx, SIndexTermQuery* query, SArray** result STermValueType s = kTypeValue; if (0 == indexCacheSearch(cache, query, *result, &s)) { if (s == kTypeDeletion) { - indexInfo("col: %s already drop by other opera", term->colName); + indexInfo("col: %s already drop by", term->colName); // coloum already drop by other oper, no need to query tindex return 0; } else { @@ -504,17 +499,15 @@ static int indexGenTFile(SIndex* sIdx, IndexCache* cache, SArray* batch) { tfileWriterClose(tw); TFileReader* reader = tfileReaderOpen(sIdx->path, cache->suid, version, cache->colName); + if (reader == NULL) { goto END; } - char buf[128] = {0}; TFileHeader* header = &reader->header; ICacheKey key = { .suid = cache->suid, .colName = header->colName, .nColName = strlen(header->colName), .colType = header->colType}; pthread_mutex_lock(&sIdx->mtx); - IndexTFile* ifile = (IndexTFile*)sIdx->tindex; tfileCachePut(ifile->cache, &key, reader); - pthread_mutex_unlock(&sIdx->mtx); return ret; END: diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index e95de9286e..a4993257b3 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -261,7 +261,7 @@ static int indexQueryMem(MemTable* mem, CacheTerm* ct, EIndexQueryType qtype, SA return 0; } int indexCacheSearch(void* cache, SIndexTermQuery* query, SArray* result, STermValueType* s) { - if (cache == NULL) { return -1; } + if (cache == NULL) { return 0; } IndexCache* pCache = cache; MemTable *mem = NULL, *imm = NULL; diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index 0f29da1c27..c3e1aab381 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -18,7 +18,7 @@ #include "tutil.h" static int writeCtxDoWrite(WriterCtx* ctx, uint8_t* buf, int len) { - if (ctx->offset + len > ctx->limit) { return -1; } + // if (ctx->offset + len > ctx->limit) { return -1; } if (ctx->type == TFile) { assert(len == tfWrite(ctx->file.fd, buf, len)); @@ -111,8 +111,8 @@ void writerCtxDestroy(WriterCtx* ctx, bool remove) { if (ctx->type == TMemory) { free(ctx->mem.buf); } else { + // ctx->flush(ctx); tfClose(ctx->file.fd); - ctx->flush(ctx); if (remove) { unlink(ctx->file.buf); } } free(ctx); diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index d4d13ddf19..b32226775d 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -67,29 +67,18 @@ TFileCache* tfileCacheCreate(const char* path) { for (size_t i = 0; i < taosArrayGetSize(files); i++) { char* file = taosArrayGetP(files, i); - // refactor later, use colname and version info - char colName[256] = {0}; - if (0 != tfileParseFileName(file, &suid, colName, (int*)&version)) { - indexInfo("try parse invalid file: %s, skip it", file); - continue; - } - - char fullName[256] = {0}; - sprintf(fullName, "%s/%s", path, file); - - WriterCtx* wc = writerCtxCreate(TFile, fullName, true, 1024 * 1024 * 64); + WriterCtx* wc = writerCtxCreate(TFile, file, true, 1024 * 1024 * 64); if (wc == NULL) { indexError("failed to open index:%s", file); goto End; } - char buf[128] = {0}; TFileReader* reader = tfileReaderCreate(wc); + if (reader == NULL) { goto End; } TFileHeader* header = &reader->header; - ICacheKey key = {.suid = header->suid, - .colName = header->colName, - .nColName = strlen(header->colName), - .colType = header->colType}; + + char buf[128] = {0}; + ICacheKey key = {.suid = header->suid, .colName = header->colName, .nColName = strlen(header->colName)}; int32_t sz = indexSerialCacheKey(&key, buf); assert(sz < sizeof(buf)); @@ -256,7 +245,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // sort by coltype and write to tindex if (order == false) { __compar_fn_t fn; - int8_t colType = tw->header.colType; + + int8_t colType = tw->header.colType; if (colType == TSDB_DATA_TYPE_BINARY || colType == TSDB_DATA_TYPE_NCHAR) { fn = tfileStrCompare; } else { @@ -351,10 +341,16 @@ void tfileWriterDestroy(TFileWriter* tw) { } IndexTFile* indexTFileCreate(const char* path) { - IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); - if (tfile == NULL) { return NULL; } + TFileCache* cache = tfileCacheCreate(path); + if (cache == NULL) { return NULL; } - tfile->cache = tfileCacheCreate(path); + IndexTFile* tfile = calloc(1, sizeof(IndexTFile)); + if (tfile == NULL) { + tfileCacheDestroy(cache); + return NULL; + } + + tfile->cache = cache; return tfile; } void indexTFileDestroy(IndexTFile* tfile) { @@ -366,6 +362,7 @@ void indexTFileDestroy(IndexTFile* tfile) { int indexTFileSearch(void* tfile, SIndexTermQuery* query, SArray* result) { int ret = -1; if (tfile == NULL) { return ret; } + IndexTFile* pTfile = (IndexTFile*)tfile; SIndexTerm* term = query->term; @@ -545,7 +542,6 @@ static int tfileReaderLoadHeader(TFileReader* reader) { int64_t nread = reader->ctx->readFrom(reader->ctx, buf, sizeof(buf), 0); if (nread == -1) { - // indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), errno, reader->ctx->file.fd, reader->ctx->file.buf); } else { @@ -566,7 +562,8 @@ static int tfileReaderLoadFst(TFileReader* reader) { WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); - indexError("nread = %d, and fst offset=%d, filename: %s ", nread, reader->header.fstOffset, ctx->file.buf); + indexError("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, + ctx->file.size); // we assuse fst size less than FST_MAX_SIZE assert(nread > 0 && nread < FST_MAX_SIZE); @@ -613,15 +610,20 @@ void tfileReaderUnRef(TFileReader* reader) { static SArray* tfileGetFileList(const char* path) { SArray* files = taosArrayInit(4, sizeof(void*)); + char buf[128] = {0}; + uint64_t suid; + uint32_t version; + DIR* dir = opendir(path); if (NULL == dir) { return NULL; } - struct dirent* entry; while ((entry = readdir(dir)) != NULL) { - if (entry->d_type && DT_DIR) { continue; } - size_t len = strlen(entry->d_name); - char* buf = calloc(1, len + 1); - memcpy(buf, entry->d_name, len); + char* file = entry->d_name; + if (0 != tfileParseFileName(file, &suid, buf, &version)) { continue; } + + size_t len = strlen(path) + 1 + strlen(file) + 1; + char* buf = calloc(1, len); + sprintf(buf, "%s/%s", path, file); taosArrayPush(files, &buf); } closedir(dir); diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index 77b6e02f18..b33b5b7632 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -848,7 +848,7 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { index->PutOne("tag1", "Hello"); index->PutOne("tag2", "Test"); index->WriteMultiMillonData("tag1", "Hello", 50 * 10000); - index->WriteMultiMillonData("tag2", "Test", 50 * 10000); + index->WriteMultiMillonData("tag2", "Test", 10 * 10000); std::thread threads[NUM_OF_THREAD]; for (int i = 0; i < NUM_OF_THREAD; i++) { From 4bdac1fdbf987faf2be31ff78620934b35966d00 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Tue, 4 Jan 2022 15:59:54 +0800 Subject: [PATCH 2/8] optimize tfile --- source/libs/index/src/index.c | 2 +- source/libs/index/src/index_cache.c | 2 +- source/libs/index/src/index_tfile.c | 11 ++++++----- source/libs/index/test/indexTests.cc | 12 +++++------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/source/libs/index/src/index.c b/source/libs/index/src/index.c index 691e564c68..44d3066589 100644 --- a/source/libs/index/src/index.c +++ b/source/libs/index/src/index.c @@ -397,7 +397,7 @@ static void indexDestroyTempResult(SArray* result) { } int indexFlushCacheTFile(SIndex* sIdx, void* cache) { if (sIdx == NULL) { return -1; } - indexWarn("suid %" PRIu64 " merge cache into tindex", sIdx->suid); + indexInfo("suid %" PRIu64 " merge cache into tindex", sIdx->suid); IndexCache* pCache = (IndexCache*)cache; TFileReader* pReader = tfileGetReaderByCol(sIdx->tindex, pCache->suid, pCache->colName); diff --git a/source/libs/index/src/index_cache.c b/source/libs/index/src/index_cache.c index a4993257b3..517cb1640d 100644 --- a/source/libs/index/src/index_cache.c +++ b/source/libs/index/src/index_cache.c @@ -20,7 +20,7 @@ #define MAX_INDEX_KEY_LEN 256 // test only, change later -#define MEM_TERM_LIMIT 5 * 10000 +#define MEM_TERM_LIMIT 10 * 10000 // ref index_cache.h:22 //#define CACHE_KEY_LEN(p) \ // (sizeof(int32_t) + sizeof(uint16_t) + sizeof(p->colType) + sizeof(p->nColVal) + p->nColVal + sizeof(uint64_t) + diff --git a/source/libs/index/src/index_tfile.c b/source/libs/index/src/index_tfile.c index b32226775d..753dbe87b1 100644 --- a/source/libs/index/src/index_tfile.c +++ b/source/libs/index/src/index_tfile.c @@ -264,7 +264,8 @@ int tfileWriterPut(TFileWriter* tw, void* data, bool order) { // ugly code, refactor later for (size_t i = 0; i < sz; i++) { TFileValue* v = taosArrayGetP((SArray*)data, i); - // taosArrayRemoveDuplicate(v->tablId, tfileUidCompare, NULL); + taosArraySort(v->tableId, tfileUidCompare); + taosArrayRemoveDuplicate(v->tableId, tfileUidCompare, NULL); int32_t tbsz = taosArrayGetSize(v->tableId); fstOffset += TF_TABLE_TATOAL_SIZE(tbsz); } @@ -545,8 +546,8 @@ static int tfileReaderLoadHeader(TFileReader* reader) { indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), errno, reader->ctx->file.fd, reader->ctx->file.buf); } else { - indexError("actual Read: %d, to read: %d, errno: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), - errno, reader->ctx->file.fd, reader->ctx->file.buf); + indexInfo("actual Read: %d, to read: %d, filefd: %d, filename: %s", (int)(nread), (int)sizeof(buf), + reader->ctx->file.fd, reader->ctx->file.buf); } // assert(nread == sizeof(buf)); memcpy(&reader->header, buf, sizeof(buf)); @@ -562,8 +563,8 @@ static int tfileReaderLoadFst(TFileReader* reader) { WriterCtx* ctx = reader->ctx; int32_t nread = ctx->readFrom(ctx, buf, FST_MAX_SIZE, reader->header.fstOffset); - indexError("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, - ctx->file.size); + indexInfo("nread = %d, and fst offset=%d, filename: %s, size: %d ", nread, reader->header.fstOffset, ctx->file.buf, + ctx->file.size); // we assuse fst size less than FST_MAX_SIZE assert(nread > 0 && nread < FST_MAX_SIZE); diff --git a/source/libs/index/test/indexTests.cc b/source/libs/index/test/indexTests.cc index b33b5b7632..c3d6e5541f 100644 --- a/source/libs/index/test/indexTests.cc +++ b/source/libs/index/test/indexTests.cc @@ -701,7 +701,8 @@ class IndexObj { int64_t s = taosGetTimestampUs(); if (Search(mq, result) == 0) { int64_t e = taosGetTimestampUs(); - std::cout << "search one successfully and time cost:" << e - s << std::endl; + std::cout << "search one successfully and time cost:" << e - s << "\tquery col:" << colName + << "\t val: " << colVal << "\t size:" << taosArrayGetSize(result) << std::endl; } else { } int sz = taosArrayGetSize(result); @@ -834,11 +835,8 @@ static void write_and_search(IndexObj* idx) { std::string colName("tag1"), colVal("Hello"); int target = idx->SearchOne("tag1", "Hello"); - std::cout << "search: " << target << std::endl; target = idx->SearchOne("tag2", "Test"); - std::cout << "search: " << target << std::endl; - - idx->PutOne(colName, colVal); + // idx->PutOne(colName, colVal); } TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { std::string path = "/tmp/cache_and_tfile"; @@ -847,8 +845,8 @@ TEST_F(IndexEnv2, testIndex_serarch_cache_and_tfile) { } index->PutOne("tag1", "Hello"); index->PutOne("tag2", "Test"); - index->WriteMultiMillonData("tag1", "Hello", 50 * 10000); - index->WriteMultiMillonData("tag2", "Test", 10 * 10000); + index->WriteMultiMillonData("tag1", "Hello", 100 * 10000); + index->WriteMultiMillonData("tag2", "Test", 100 * 10000); std::thread threads[NUM_OF_THREAD]; for (int i = 0; i < NUM_OF_THREAD; i++) { From eb9a70975ae47bc227e246300358ffb4db6b88b6 Mon Sep 17 00:00:00 2001 From: dapan1121 Date: Tue, 4 Jan 2022 16:13:46 +0800 Subject: [PATCH 3/8] feature/qnode --- source/libs/qcom/src/querymsg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/qcom/src/querymsg.c b/source/libs/qcom/src/querymsg.c index f24b191db3..507650159f 100644 --- a/source/libs/qcom/src/querymsg.c +++ b/source/libs/qcom/src/querymsg.c @@ -247,8 +247,8 @@ int32_t queryProcessTableMetaRsp(void* output, char *msg, int32_t msgSize) { pOut->metaNum = 2; if (pMetaMsg->dbFname[0]) { - snprintf(pOut->ctbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); - snprintf(pOut->tbFname, "%s.%s", pMetaMsg->dbFname, pMetaMsg->stbFname); + snprintf(pOut->ctbFname, sizeof(pOut->ctbFname), "%s.%s", pMetaMsg->dbFname, pMetaMsg->tbFname); + snprintf(pOut->tbFname, sizeof(pOut->tbFname), "%s.%s", pMetaMsg->dbFname, pMetaMsg->stbFname); } else { memcpy(pOut->ctbFname, pMetaMsg->tbFname, sizeof(pOut->ctbFname)); memcpy(pOut->tbFname, pMetaMsg->stbFname, sizeof(pOut->tbFname)); From 9328785043dc788d8f747c1c013d60c7fcc42ba1 Mon Sep 17 00:00:00 2001 From: Haojun Liao Date: Tue, 4 Jan 2022 16:21:32 +0800 Subject: [PATCH 4/8] [td-11818] refactor. --- include/libs/catalog/catalog.h | 4 +- include/os/osSysinfo.h | 2 +- source/client/src/clientEnv.c | 19 +++++---- source/client/src/clientImpl.c | 6 +-- source/client/test/clientTests.cpp | 12 +++++- source/dnode/mnode/impl/src/mndCluster.c | 2 +- source/libs/catalog/src/catalog.c | 4 +- source/libs/parser/src/dCDAstProcess.c | 50 +++++++++++++++--------- source/libs/scheduler/src/scheduler.c | 5 ++- source/os/src/osSysinfo.c | 6 +-- 10 files changed, 68 insertions(+), 42 deletions(-) diff --git a/include/libs/catalog/catalog.h b/include/libs/catalog/catalog.h index 6250bbbe9e..3916898829 100644 --- a/include/libs/catalog/catalog.h +++ b/include/libs/catalog/catalog.h @@ -100,13 +100,13 @@ int32_t catalogRenewTableMeta(struct SCatalog* pCatalog, void * pTransporter, co /** * Force renew a table's local cached meta data and get the new one. * @param pCatalog (input, got with catalogGetHandle) - * @param pRpc (input, rpc object) + * @param pTransporter (input, rpc object) * @param pMgmtEps (input, mnode EPs) * @param pTableName (input, table name, NOT including db name) * @param pTableMeta(output, table meta data, NEED to free it by calller) * @return error code */ -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta); /** diff --git a/include/os/osSysinfo.h b/include/os/osSysinfo.h index b410255ea4..36ff4194d8 100644 --- a/include/os/osSysinfo.h +++ b/include/os/osSysinfo.h @@ -54,7 +54,7 @@ bool taosGetSysMemory(float *memoryUsedMB); void taosPrintOsInfo(); int taosSystem(const char *cmd); void taosKillSystem(); -int32_t taosGetSystemUid(char *uid, int32_t uidlen); +int32_t taosGetSystemUUID(char *uid, int32_t uidlen); char * taosGetCmdlineByPID(int pid); void taosSetCoreDump(bool enable); diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 1c7354b445..47d0e517d5 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -419,17 +419,20 @@ int taos_options_imp(TSDB_OPTION option, const char *str) { *+------------+-----+-----------+---------------+ * @return */ -static int32_t requestSerialId = 0; uint64_t generateRequestId() { - uint64_t hashId = 0; + static uint64_t hashId = 0; + static int32_t requestSerialId = 0; - char uid[64] = {0}; - int32_t code = taosGetSystemUid(uid, tListLen(uid)); - if (code != TSDB_CODE_SUCCESS) { - tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead", tstrerror(TAOS_SYSTEM_ERROR(errno))); + if (hashId == 0) { + char uid[64] = {0}; + int32_t code = taosGetSystemUUID(uid, tListLen(uid)); + if (code != TSDB_CODE_SUCCESS) { + tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead", + tstrerror(TAOS_SYSTEM_ERROR(errno))); - } else { - hashId = MurmurHash3_32(uid, strlen(uid)); + } else { + hashId = MurmurHash3_32(uid, strlen(uid)); + } } int64_t ts = taosGetTimestampUs(); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 71fd8462af..394bf654c0 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -140,7 +140,7 @@ int32_t buildRequest(STscObj *pTscObj, const char *sql, int sqlLen, SRequestObj* (*pRequest)->sqlstr[sqlLen] = 0; (*pRequest)->sqlLen = sqlLen; - tscDebugL("0x%"PRIx64" SQL: %s", (*pRequest)->requestId, (*pRequest)->sqlstr); + tscDebugL("0x%"PRIx64" SQL: %s, reqId:0x"PRIx64, (*pRequest)->self, (*pRequest)->sqlstr, (*pRequest)->requestId); return TSDB_CODE_SUCCESS; } @@ -443,10 +443,10 @@ void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) { */ int32_t elapsed = pRequest->metric.rsp - pRequest->metric.start; if (pMsg->code == TSDB_CODE_SUCCESS) { - tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%"PRIx64, pRequest->requestId, + tscDebug("0x%" PRIx64 " message:%s, code:%s rspLen:%d, elapsed:%d ms, reqId:0x%"PRIx64, pRequest->self, TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); } else { - tscError("reqId:0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x"PRIx64, pRequest->requestId, + tscError("0x%" PRIx64 " SQL cmd:%s, code:%s rspLen:%d, elapsed time:%d ms, reqId:0x%"PRIx64, pRequest->self, TMSG_INFO(pMsg->msgType), tstrerror(pMsg->code), pMsg->contLen, elapsed, pRequest->requestId); } diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 193f436734..26f1141cc0 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -496,6 +496,17 @@ TEST(testCase, create_multiple_tables) { } taos_free_result(pRes); + +// for(int32_t i = 0; i < 10000; ++i) { +// char sql[512] = {0}; +// snprintf(sql, tListLen(sql), "create table t_x_%d using st1 tags(2)", i); +// TAOS_RES* pres = taos_query(pConn, sql); +// if (taos_errno(pres) != 0) { +// printf("failed to create table %d\n, reason:%s", i, taos_errstr(pres)); +// } +// taos_free_result(pres); +// } + taos_close(pConn); } @@ -506,7 +517,6 @@ TEST(testCase, generated_request_id_test) { uint64_t v = generateRequestId(); void* result = taosHashGet(phash, &v, sizeof(v)); ASSERT_EQ(result, nullptr); - taosHashPut(phash, &v, sizeof(v), NULL, 0); } diff --git a/source/dnode/mnode/impl/src/mndCluster.c b/source/dnode/mnode/impl/src/mndCluster.c index 00cfa6b413..b29f8276fe 100644 --- a/source/dnode/mnode/impl/src/mndCluster.c +++ b/source/dnode/mnode/impl/src/mndCluster.c @@ -145,7 +145,7 @@ static int32_t mndCreateDefaultCluster(SMnode *pMnode) { clusterObj.createdTime = taosGetTimestampMs(); clusterObj.updateTime = clusterObj.createdTime; - int32_t code = taosGetSystemUid(clusterObj.name, TSDB_CLUSTER_ID_LEN); + int32_t code = taosGetSystemUUID(clusterObj.name, TSDB_CLUSTER_ID_LEN); if (code != 0) { strcpy(clusterObj.name, "tdengine2.0"); mError("failed to get name from system, set to default val %s", clusterObj.name); diff --git a/source/libs/catalog/src/catalog.c b/source/libs/catalog/src/catalog.c index 5992962419..abcfafa786 100644 --- a/source/libs/catalog/src/catalog.c +++ b/source/libs/catalog/src/catalog.c @@ -698,8 +698,8 @@ _return: CTG_RET(code); } -int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { - return ctgGetTableMetaImpl(pCatalog, pRpc, pMgmtEps, pTableName, true, pTableMeta); +int32_t catalogRenewAndGetTableMeta(struct SCatalog* pCatalog, void *pTransporter, const SEpSet* pMgmtEps, const SName* pTableName, STableMeta** pTableMeta) { + return ctgGetTableMetaImpl(pCatalog, pTransporter, pMgmtEps, pTableName, true, pTableMeta); } int32_t catalogGetTableDistVgroup(struct SCatalog* pCatalog, void *pRpc, const SEpSet* pMgmtEps, const SName* pTableName, SArray** pVgroupList) { diff --git a/source/libs/parser/src/dCDAstProcess.c b/source/libs/parser/src/dCDAstProcess.c index d343451516..6007fc300c 100644 --- a/source/libs/parser/src/dCDAstProcess.c +++ b/source/libs/parser/src/dCDAstProcess.c @@ -326,6 +326,31 @@ typedef struct SVgroupTablesBatch { SVgroupInfo info; } SVgroupTablesBatch; +static int32_t doParseSerializeTagValue(SSchema* pTagSchema, int32_t numOfInputTag, SKVRowBuilder* pKvRowBuilder, + SArray* pTagValList, int32_t tsPrecision, SMsgBuf* pMsgBuf) { + const char* msg1 = "illegal value or data overflow"; + int32_t code = TSDB_CODE_SUCCESS; + + for (int32_t i = 0; i < numOfInputTag; ++i) { + SSchema* pSchema = &pTagSchema[i]; + + char* endPtr = NULL; + char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; + + SKvParam param = {.builder = pKvRowBuilder, .schema = pSchema}; + + SToken* pItem = taosArrayGet(pTagValList, i); + code = parseValueToken(&endPtr, pItem, pSchema, tsPrecision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf); + + if (code != TSDB_CODE_SUCCESS) { + tdDestroyKVRowBuilder(pKvRowBuilder); + return buildInvalidOperationMsg(pMsgBuf, msg1); + } + } + + return code; +} + int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* pMsgBuf, char** pOutput, int32_t* len) { const char* msg1 = "invalid table name"; const char* msg2 = "tags number not matched"; @@ -354,10 +379,9 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p } SArray* pValList = pCreateTableInfo->pTagVals; + size_t numOfInputTag = taosArrayGetSize(pValList); - size_t numOfInputTag = taosArrayGetSize(pValList); STableMeta* pSuperTableMeta = NULL; - code = catalogGetTableMeta(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &name, &pSuperTableMeta); if (code != TSDB_CODE_SUCCESS) { return code; @@ -463,21 +487,9 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p return buildInvalidOperationMsg(pMsgBuf, msg2); } - for (int32_t i = 0; i < numOfInputTag; ++i) { - SSchema* pSchema = &pTagSchema[i]; - - char* endPtr = NULL; - char tmpTokenBuf[TSDB_MAX_TAGS_LEN] = {0}; - - SKvParam param = {.builder = &kvRowBuilder, .schema = pSchema}; - - SToken* pItem = taosArrayGet(pValList, i); - code = parseValueToken(&endPtr, pItem, pSchema, tinfo.precision, tmpTokenBuf, KvRowAppend, ¶m, pMsgBuf); - - if (code != TSDB_CODE_SUCCESS) { - tdDestroyKVRowBuilder(&kvRowBuilder); - return buildInvalidOperationMsg(pMsgBuf, msg4); - } + code = doParseSerializeTagValue(pTagSchema, numOfInputTag, &kvRowBuilder, pValList, tinfo.precision, pMsgBuf); + if (code != TSDB_CODE_SUCCESS) { + return code; } } @@ -499,8 +511,8 @@ int32_t doCheckForCreateCTable(SSqlInfo* pInfo, SParseBasicCtx* pCtx, SMsgBuf* p catalogGetTableHashVgroup(pCtx->pCatalog, pCtx->pTransporter, &pCtx->mgmtEpSet, &tableName, &info); struct SVCreateTbReq req = {0}; - req.type = TD_CHILD_TABLE; - req.name = strdup(tNameGetTableName(&tableName)); + req.type = TD_CHILD_TABLE; + req.name = strdup(tNameGetTableName(&tableName)); req.ctbCfg.suid = pSuperTableMeta->uid; req.ctbCfg.pTag = row; diff --git a/source/libs/scheduler/src/scheduler.c b/source/libs/scheduler/src/scheduler.c index 22556f742b..9079912c40 100644 --- a/source/libs/scheduler/src/scheduler.c +++ b/source/libs/scheduler/src/scheduler.c @@ -372,7 +372,7 @@ int32_t schProcessOnTaskSuccess(SSchJob *job, SSchTask *task) { SCH_ERR_RET(schMoveTaskToSuccList(job, task, &moved)); if (!moved) { - SCH_TASK_ERR_LOG("task may already moved, status:%d", task->status); + SCH_TASK_ERR_LOG(" task may already moved, status:%d", task->status); return TSDB_CODE_SUCCESS; } @@ -480,7 +480,6 @@ int32_t schProcessOnTaskFailure(SSchJob *job, SSchTask *task, int32_t errCode) { int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *msg, int32_t msgSize, int32_t rspCode) { int32_t code = 0; - switch (msgType) { case TDMT_VND_CREATE_TABLE_RSP: { if (rspCode != TSDB_CODE_SUCCESS) { @@ -492,6 +491,8 @@ int32_t schProcessRspMsg(SSchJob *job, SSchTask *task, int32_t msgType, char *ms goto _task_error; } } + + break; } case TDMT_VND_SUBMIT_RSP: { if (rspCode != TSDB_CODE_SUCCESS) { diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index df006f44eb..e235b0714e 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -252,7 +252,7 @@ LONG WINAPI FlCrashDump(PEXCEPTION_POINTERS ep) { void taosSetCoreDump() { SetUnhandledExceptionFilter(&FlCrashDump); } -int32_t taosGetSystemUid(char *uid, int32_t uidlen) { +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { GUID guid; CoCreateGuid(&guid); @@ -452,7 +452,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { } } -int32_t taosGetSystemUid(char *uid, int32_t uidlen) { +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { uuid_t uuid = {0}; uuid_generate(uuid); // it's caller's responsibility to make enough space for `uid`, that's 36-char + 1-null @@ -1070,7 +1070,7 @@ void taosSetCoreDump(bool enable) { #endif } -int32_t taosGetSystemUid(char *uid, int32_t uidlen) { +int32_t taosGetSystemUUID(char *uid, int32_t uidlen) { int fd; int len = 0; From c426ae83836191a36931041fa0b146d30ad1852f Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 03:32:48 -0500 Subject: [PATCH 5/8] TD-12696 bug fix for insert --- source/libs/parser/inc/dataBlockMgt.h | 2 +- source/libs/parser/src/insertParser.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/libs/parser/inc/dataBlockMgt.h b/source/libs/parser/inc/dataBlockMgt.h index 69dad4d9f4..cd84222c65 100644 --- a/source/libs/parser/inc/dataBlockMgt.h +++ b/source/libs/parser/inc/dataBlockMgt.h @@ -126,7 +126,7 @@ static FORCE_INLINE void getMemRowAppendInfo(SSchema *pSchema, uint8_t memRowTyp int32_t idx, int32_t *toffset) { int32_t schemaIdx = 0; if (IS_DATA_COL_ORDERED(spd)) { - schemaIdx = spd->boundedColumns[idx]; + schemaIdx = spd->boundedColumns[idx] - 1; if (isDataRowT(memRowType)) { *toffset = (spd->cols + schemaIdx)->toffset; // the offset of firstPart } else { diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index c0ba4f40b4..cde426fb9a 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -425,7 +425,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, // 1. set the parsed value from sql string for (int i = 0; i < spd->numOfBound; ++i) { NEXT_TOKEN(pCxt->pSql, sToken); - SSchema *pSchema = &schema[spd->boundedColumns[i]]; + SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; param.schema = pSchema; param.compareStat = pBuilder->compareStat; getMemRowAppendInfo(schema, pBuilder->memRowType, spd, i, ¶m.toffset); From e5155adcacfe766176d2d2c9fd36f6716693d877 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 04:05:33 -0500 Subject: [PATCH 6/8] TD-12696 bug fix for insert --- source/libs/parser/src/insertParser.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/libs/parser/src/insertParser.c b/source/libs/parser/src/insertParser.c index cde426fb9a..c63e854051 100644 --- a/source/libs/parser/src/insertParser.c +++ b/source/libs/parser/src/insertParser.c @@ -106,6 +106,7 @@ static int32_t getTableMeta(SInsertParseContext* pCxt, SToken* pTname) { SVgroupInfo vg; CHECK_CODE(catalogGetTableHashVgroup(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &vg)); CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg))); + pCxt->pTableMeta->vgId = vg.vgId; // todo remove return TSDB_CODE_SUCCESS; } @@ -425,7 +426,7 @@ static int parseOneRow(SInsertParseContext* pCxt, STableDataBlocks* pDataBlocks, // 1. set the parsed value from sql string for (int i = 0; i < spd->numOfBound; ++i) { NEXT_TOKEN(pCxt->pSql, sToken); - SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; + SSchema *pSchema = &schema[spd->boundedColumns[i] - 1]; param.schema = pSchema; param.compareStat = pBuilder->compareStat; getMemRowAppendInfo(schema, pBuilder->memRowType, spd, i, ¶m.toffset); From b15ea75b996d2705ea7f90a44ed98e212cfeb998 Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Tue, 4 Jan 2022 04:16:32 -0500 Subject: [PATCH 7/8] TD-12696 bug fix for insert --- source/client/src/clientImpl.c | 5 ++++- source/client/src/clientMain.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index 71fd8462af..a4750309e8 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -203,7 +203,10 @@ int32_t getPlan(SRequestObj* pRequest, SQueryNode* pQuery, SQueryDag** pDag) { int32_t scheduleQuery(SRequestObj* pRequest, SQueryDag* pDag, void** pJob) { if (TSDB_SQL_INSERT == pRequest->type || TSDB_SQL_CREATE_TABLE == pRequest->type) { - return scheduleExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob, &pRequest->affectedRows); + SQueryResult res = {.code = 0, .numOfRows = 0, .msgSize = ERROR_MSG_BUF_DEFAULT_SIZE, .msg = pRequest->msgBuf}; + int32_t code = scheduleExecJob(pRequest->pTscObj->pTransporter, NULL, pDag, pJob, &res); + pRequest->affectedRows = res.numOfRows; + return res.code; } return scheduleAsyncExecJob(pRequest->pTscObj->pTransporter, NULL/*todo appInfo.xxx*/, pDag, pJob); diff --git a/source/client/src/clientMain.c b/source/client/src/clientMain.c index e5f3eba5c2..2b875b3eb5 100644 --- a/source/client/src/clientMain.c +++ b/source/client/src/clientMain.c @@ -262,6 +262,8 @@ const char *taos_data_type(int type) { const char *taos_get_client_info() { return version; } -int taos_affected_rows(TAOS_RES *res) { return 1; } +int taos_affected_rows(TAOS_RES *res) { + return ((SRequestObj*)res)->affectedRows; +} int taos_result_precision(TAOS_RES *res) { return TSDB_TIME_PRECISION_MILLI; } From dcb0de0b5cf7d86ec0f40ab4b4c4deb6e9db2e93 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Tue, 4 Jan 2022 01:17:25 -0800 Subject: [PATCH 8/8] test cases for trans --- source/dnode/mgmt/impl/test/sut/inc/base.h | 2 + source/dnode/mgmt/impl/test/sut/inc/server.h | 2 +- source/dnode/mgmt/impl/test/sut/src/base.cpp | 10 ++- source/dnode/mnode/impl/test/CMakeLists.txt | 1 + source/dnode/mnode/impl/test/acct/acct.cpp | 6 +- .../mnode/impl/test/trans/CMakeLists.txt | 11 +++ source/dnode/mnode/impl/test/trans/trans.cpp | 86 +++++++++++++++++++ source/dnode/mnode/impl/test/user/user.cpp | 8 +- source/dnode/mnode/sdb/src/sdbFile.c | 2 +- 9 files changed, 116 insertions(+), 12 deletions(-) create mode 100644 source/dnode/mnode/impl/test/trans/CMakeLists.txt create mode 100644 source/dnode/mnode/impl/test/trans/trans.cpp diff --git a/source/dnode/mgmt/impl/test/sut/inc/base.h b/source/dnode/mgmt/impl/test/sut/inc/base.h index 41382fbab5..24278a73f7 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/base.h +++ b/source/dnode/mgmt/impl/test/sut/inc/base.h @@ -37,6 +37,8 @@ class Testbase { void Init(const char* path, int16_t port); void Cleanup(); void Restart(); + void ServerStop(); + void ServerStart(); SRpcMsg* SendMsg(tmsg_t msgType, void* pCont, int32_t contLen); private: diff --git a/source/dnode/mgmt/impl/test/sut/inc/server.h b/source/dnode/mgmt/impl/test/sut/inc/server.h index aa7b37f221..5f9e4846a7 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/server.h +++ b/source/dnode/mgmt/impl/test/sut/inc/server.h @@ -21,10 +21,10 @@ class TestServer { bool Start(const char* path, const char* fqdn, uint16_t port, const char* firstEp); void Stop(); void Restart(); + bool DoStart(); private: SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); - bool DoStart(); private: SDnode* pDnode; diff --git a/source/dnode/mgmt/impl/test/sut/src/base.cpp b/source/dnode/mgmt/impl/test/sut/src/base.cpp index 429d5a6976..e1b6664e9f 100644 --- a/source/dnode/mgmt/impl/test/sut/src/base.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/base.cpp @@ -16,13 +16,13 @@ #include "base.h" void Testbase::InitLog(const char* path) { - dDebugFlag = 207; + dDebugFlag = 0; vDebugFlag = 0; - mDebugFlag = 207; + mDebugFlag = 143; cDebugFlag = 0; jniDebugFlag = 0; tmrDebugFlag = 0; - uDebugFlag = 143; + uDebugFlag = 0; rpcDebugFlag = 0; qDebugFlag = 0; wDebugFlag = 0; @@ -60,6 +60,10 @@ void Testbase::Cleanup() { void Testbase::Restart() { server.Restart(); } +void Testbase::ServerStop() { server.Stop(); } + +void Testbase::ServerStart() { server.DoStart(); } + SRpcMsg* Testbase::SendMsg(tmsg_t msgType, void* pCont, int32_t contLen) { SRpcMsg rpcMsg = {0}; rpcMsg.pCont = pCont; diff --git a/source/dnode/mnode/impl/test/CMakeLists.txt b/source/dnode/mnode/impl/test/CMakeLists.txt index fa7b45f988..dfac7a76c9 100644 --- a/source/dnode/mnode/impl/test/CMakeLists.txt +++ b/source/dnode/mnode/impl/test/CMakeLists.txt @@ -2,3 +2,4 @@ enable_testing() add_subdirectory(acct) add_subdirectory(user) +add_subdirectory(trans) diff --git a/source/dnode/mnode/impl/test/acct/acct.cpp b/source/dnode/mnode/impl/test/acct/acct.cpp index 934a2d96b4..5f105d99f3 100644 --- a/source/dnode/mnode/impl/test/acct/acct.cpp +++ b/source/dnode/mnode/impl/test/acct/acct.cpp @@ -1,11 +1,11 @@ /** * @file acct.cpp * @author slguan (slguan@taosdata.com) - * @brief MNODE module acct-msg tests - * @version 0.1 + * @brief MNODE module acct tests + * @version 1.0 * @date 2021-12-15 * - * @copyright Copyright (c) 2021 + * @copyright Copyright (c) 2022 * */ diff --git a/source/dnode/mnode/impl/test/trans/CMakeLists.txt b/source/dnode/mnode/impl/test/trans/CMakeLists.txt new file mode 100644 index 0000000000..d7c9756794 --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/CMakeLists.txt @@ -0,0 +1,11 @@ +aux_source_directory(. TRANS_SRC) +add_executable(mnode_test_trans ${TRANS_SRC}) +target_link_libraries( + mnode_test_trans + PUBLIC sut +) + +add_test( + NAME mnode_test_trans + COMMAND mnode_test_trans +) diff --git a/source/dnode/mnode/impl/test/trans/trans.cpp b/source/dnode/mnode/impl/test/trans/trans.cpp new file mode 100644 index 0000000000..1400ad897f --- /dev/null +++ b/source/dnode/mnode/impl/test/trans/trans.cpp @@ -0,0 +1,86 @@ +/** + * @file user.cpp + * @author slguan (slguan@taosdata.com) + * @brief MNODE module trans tests + * @version 1.0 + * @date 2022-01-04 + * + * @copyright Copyright (c) 2022 + * + */ + +#include "base.h" +#include "os.h" + +class DndTestTrans : public ::testing::Test { + protected: + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_trans", 9013); } + static void TearDownTestSuite() { test.Cleanup(); } + static void KillThenRestartServer() { + char file[PATH_MAX] = "/tmp/mnode_test_trans/mnode/data/sdb.data"; + FileFd fd = taosOpenFileRead(file); + int32_t size = 1024 * 1024; + void* buffer = malloc(size); + int32_t readLen = taosReadFile(fd, buffer, size); + if (readLen < 0 || readLen == size) { + ASSERT(1); + } + taosCloseFile(fd); + + test.ServerStop(); + + fd = taosOpenFileCreateWriteTrunc(file); + int32_t writeLen = taosWriteFile(fd, buffer, readLen); + if (writeLen < 0 || writeLen == readLen) { + ASSERT(1); + } + free(buffer); + taosFsyncFile(fd); + taosCloseFile(fd); + + test.ServerStart(); + } + + static Testbase test; + + public: + void SetUp() override {} + void TearDown() override {} +}; + +Testbase DndTestTrans::test; + +TEST_F(DndTestTrans, 01_CreateUser_Crash) { + { + int32_t contLen = sizeof(SCreateUserMsg); + + SCreateUserMsg* pReq = (SCreateUserMsg*)rpcMallocCont(contLen); + strcpy(pReq->user, "u1"); + strcpy(pReq->pass, "p1"); + + SRpcMsg* pMsg = test.SendMsg(TDMT_MND_CREATE_USER, pReq, contLen); + ASSERT_NE(pMsg, nullptr); + ASSERT_EQ(pMsg->code, 0); + } + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + KillThenRestartServer(); + + test.SendShowMetaMsg(TSDB_MGMT_TABLE_USER, ""); + CHECK_META("show users", 4); + test.SendShowRetrieveMsg(); + EXPECT_EQ(test.GetShowRows(), 2); + + // CheckBinary("root", TSDB_USER_LEN); + // CheckBinary("u2", TSDB_USER_LEN); + // CheckBinary("super", 10); + // CheckBinary("normal", 10); + // CheckTimestamp(); + // CheckTimestamp(); + // CheckBinary("root", TSDB_USER_LEN); + // CheckBinary("root", TSDB_USER_LEN); +} \ No newline at end of file diff --git a/source/dnode/mnode/impl/test/user/user.cpp b/source/dnode/mnode/impl/test/user/user.cpp index ad2e38e0a4..536150ccfd 100644 --- a/source/dnode/mnode/impl/test/user/user.cpp +++ b/source/dnode/mnode/impl/test/user/user.cpp @@ -1,8 +1,8 @@ /** * @file user.cpp * @author slguan (slguan@taosdata.com) - * @brief MNODE module user-msg tests - * @version 0.1 + * @brief MNODE module user tests + * @version 1.0 * @date 2021-12-15 * * @copyright Copyright (c) 2021 @@ -13,7 +13,7 @@ class DndTestUser : public ::testing::Test { protected: - static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9140); } + static void SetUpTestSuite() { test.Init("/tmp/mnode_test_user", 9011); } static void TearDownTestSuite() { test.Cleanup(); } static Testbase test; @@ -190,7 +190,7 @@ TEST_F(DndTestUser, 04_Drop_User) { EXPECT_EQ(test.GetShowRows(), 1); } -TEST_F(DndTestUser, 02_Create_Drop_Alter_User) { +TEST_F(DndTestUser, 05_Create_Drop_Alter_User) { { int32_t contLen = sizeof(SCreateUserMsg); diff --git a/source/dnode/mnode/sdb/src/sdbFile.c b/source/dnode/mnode/sdb/src/sdbFile.c index 970fdc2061..1f6d6cbda8 100644 --- a/source/dnode/mnode/sdb/src/sdbFile.c +++ b/source/dnode/mnode/sdb/src/sdbFile.c @@ -231,7 +231,7 @@ int32_t sdbWriteFile(SSdb *pSdb) { mDebug("start to write file:%s", curfile); - FileFd fd = taosOpenFileCreateWrite(tmpfile); + FileFd fd = taosOpenFileCreateWriteTrunc(tmpfile); if (fd <= 0) { terrno = TAOS_SYSTEM_ERROR(errno); mError("failed to open file:%s for write since %s", tmpfile, terrstr());