From 8336bbcf27a42f10718e37b595f537729dff2ab8 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 21 Jun 2020 04:11:08 +0000 Subject: [PATCH 1/2] fix commit assert error --- src/tsdb/src/tsdbMemTable.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index e928cdc385..2989daad49 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -222,11 +222,12 @@ int tsdbAsyncCommit(STsdbRepo *pRepo) { terrno = TAOS_SYSTEM_ERROR(errno); return -1; } + pRepo->commit = 0; } ASSERT(pRepo->commit == 0); - if (pRepo->appH.notifyStatus) pRepo->appH.notifyStatus(pRepo->appH.appH, TSDB_STATUS_COMMIT_START); if (pRepo->mem != NULL) { + if (pRepo->appH.notifyStatus) pRepo->appH.notifyStatus(pRepo->appH.appH, TSDB_STATUS_COMMIT_START); if (tsdbLockRepo(pRepo) < 0) return -1; pRepo->imem = pRepo->mem; pRepo->mem = NULL; @@ -468,9 +469,6 @@ _err: static void tsdbEndCommit(STsdbRepo *pRepo) { ASSERT(pRepo->commit == 1); - tsdbLockRepo(pRepo); - pRepo->commit = 0; - tsdbUnlockRepo(pRepo); if (pRepo->appH.notifyStatus) pRepo->appH.notifyStatus(pRepo->appH.appH, TSDB_STATUS_COMMIT_OVER); } From 0e1c6aafb39607247b7f618670fc48b064e54c4c Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Sun, 21 Jun 2020 10:41:12 +0000 Subject: [PATCH 2/2] fix coverity scan problems --- src/tsdb/src/tsdbBuffer.c | 1 + src/tsdb/src/tsdbFile.c | 4 +++- src/tsdb/src/tsdbMain.c | 7 ++++--- src/tsdb/src/tsdbMemTable.c | 4 +--- src/tsdb/src/tsdbMeta.c | 3 ++- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/tsdb/src/tsdbBuffer.c b/src/tsdb/src/tsdbBuffer.c index 686fc4bbec..16f06c82bb 100644 --- a/src/tsdb/src/tsdbBuffer.c +++ b/src/tsdb/src/tsdbBuffer.c @@ -124,6 +124,7 @@ SListNode *tsdbAllocBufBlockFromPool(STsdbRepo *pRepo) { } SListNode * pNode = tdListPopHead(pBufPool->bufBlockList); + ASSERT(pNode != NULL); STsdbBufBlock *pBufBlock = NULL; tdListNodeGetData(pBufPool->bufBlockList, pNode, (void *)(&pBufBlock)); diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index ffac8da944..8ebb62f341 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -358,7 +358,9 @@ void tsdbRemoveFileGroup(STsdbRepo *pRepo, SFileGroup *pFGroup) { ASSERT(pFileH->nFGroups >= 0); for (int type = TSDB_FILE_TYPE_HEAD; type < TSDB_FILE_TYPE_MAX; type++) { - remove(fileGroup.files[type].fname); + if (remove(fileGroup.files[type].fname) < 0) { + tsdbError("vgId:%d failed to remove file %s", REPO_ID(pRepo), fileGroup.files[type].fname); + } tsdbDestroyFile(&fileGroup.files[type]); } } diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index 80e5e8ea0d..ac334e8ed1 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -237,12 +237,13 @@ uint32_t tsdbGetFileInfo(TSDB_REPO_T *repo, char *name, uint32_t *index, uint32_ } SFile *pFile = &pFGroup->files[(*index) % 3]; - strcpy(fname, pFile->fname); + fname = strdup(pFile->fname); } } if (stat(fname, &fState) < 0) { tfree(sdup); + tfree(fname); return 0; } @@ -566,7 +567,7 @@ static int32_t tsdbSaveConfig(char *rootDir, STsdbCfg *pCfg) { _err: tfree(fname); - if (fd > 0) close(fd); + if (fd >= 0) close(fd); return -1; } @@ -609,7 +610,7 @@ static int tsdbLoadConfig(char *rootDir, STsdbCfg *pCfg) { _err: tfree(fname); - if (fd > 0) close(fd); + if (fd >= 0) close(fd); return -1; } diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 2989daad49..b1de90bc29 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -524,8 +524,6 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe goto _err; } - free(dataDir); - // Open files for write/read if (tsdbSetAndOpenHelperFile(pHelper, pGroup) < 0) { tsdbError("vgId:%d failed to set helper file since %s", REPO_ID(pRepo), tstrerror(terrno)); @@ -599,7 +597,7 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe return 0; _err: - // ASSERT(false); + tfree(dataDir); tsdbCloseHelperFile(pHelper, 1); return -1; } diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index beb8f33052..83392462ab 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -147,6 +147,7 @@ int tsdbDropTable(TSDB_REPO_T *repo, STableId tableId) { tsdbInsertTableAct(pRepo, TSDB_DROP_META, buf, tTable); tsdbRemoveTableFromMeta(pRepo, tTable, false, true); } + tSkipListDestroyIter(pIter); } tsdbRemoveTableFromMeta(pRepo, pTable, true, true); @@ -270,7 +271,6 @@ STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) { _err: tdDestroyTSchemaBuilder(&schemaBuilder); tsdbClearTableCfg(pCfg); - tfree(pCfg); return NULL; } @@ -309,6 +309,7 @@ int tsdbUpdateTagValue(TSDB_REPO_T *repo, SUpdateTableTagValMsg *pMsg) { int32_t code = tsdbUpdateTable(pRepo, super, pTableCfg); if (code != TSDB_CODE_SUCCESS) { + tsdbClearTableCfg(pTableCfg); return code; } tsdbClearTableCfg(pTableCfg);