diff --git a/src/balance/src/balance.c b/src/balance/src/balance.c index 7aed8c05ca..db5dd6a520 100644 --- a/src/balance/src/balance.c +++ b/src/balance/src/balance.c @@ -14,10 +14,10 @@ */ #define _DEFAULT_SOURCE +#include "os.h" #include "tutil.h" #include "tbalance.h" #include "tsync.h" -#include "ttime.h" #include "ttimer.h" #include "tglobal.h" #include "tdataformat.h" diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index 549a0e8d0d..eee255f55b 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -18,7 +18,6 @@ #include "tlog.h" #include "tscUtil.h" #include "tsclient.h" -#include "ttime.h" #include "com_taosdata_jdbc_TSDBJNIConnector.h" diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index 17f6c97ea1..c4f768f6ac 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -27,7 +27,6 @@ #include "tscSubquery.h" #include "tscompression.h" #include "tsqlfunction.h" -#include "ttime.h" #include "tutil.h" #define GET_INPUT_CHAR(x) (((char *)((x)->aInputElemBuf)) + ((x)->startOffset) * ((x)->inputBytes)) @@ -2108,7 +2107,7 @@ static void copyTopBotRes(SQLFunctionCtx *pCtx, int32_t type) { } } - tfree(pData); + taosTFree(pData); } /* diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 7f336daa91..a8f287d499 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -326,7 +326,7 @@ static void tscProcessServerVer(SSqlObj *pSql) { STR_WITH_SIZE_TO_VARSTR(vx, v, t); tscSetLocalQueryResult(pSql, vx, pExpr->aliasName, pExpr->resType, pExpr->resBytes); - tfree(vx); + taosTFree(vx); } static void tscProcessClientVer(SSqlObj *pSql) { @@ -342,7 +342,7 @@ static void tscProcessClientVer(SSqlObj *pSql) { STR_WITH_SIZE_TO_VARSTR(v, version, t); tscSetLocalQueryResult(pSql, v, pExpr->aliasName, pExpr->resType, pExpr->resBytes); - tfree(v); + taosTFree(v); } static void tscProcessServStatus(SSqlObj *pSql) { diff --git a/src/client/src/tscLocalMerge.c b/src/client/src/tscLocalMerge.c index bf76b8cbe8..394b725781 100644 --- a/src/client/src/tscLocalMerge.c +++ b/src/client/src/tscLocalMerge.c @@ -230,7 +230,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd if (ds == NULL) { tscError("%p failed to create merge structure", pSql); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; - tfree(pReducer); + taosTFree(pReducer); return; } @@ -257,7 +257,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd if (ds->filePage.num == 0) { // no data in this flush, the index does not increase tscDebug("%p flush data is empty, ignore %d flush record", pSql, idx); - tfree(ds); + taosTFree(ds); continue; } @@ -267,7 +267,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd // no data actually, no need to merge result. if (idx == 0) { - tfree(pReducer); + taosTFree(pReducer); return; } @@ -275,7 +275,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd SCompareParam *param = malloc(sizeof(SCompareParam)); if (param == NULL) { - tfree(pReducer); + taosTFree(pReducer); return; } param->pLocalData = pReducer->pLocalDataSrc; @@ -288,8 +288,8 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pRes->code = tLoserTreeCreate(&pReducer->pLoserTree, pReducer->numOfBuffer, param, treeComparator); if (pReducer->pLoserTree == NULL || pRes->code != 0) { - tfree(param); - tfree(pReducer); + taosTFree(param); + taosTFree(pReducer); return; } @@ -332,14 +332,14 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd if (pReducer->pTempBuffer == NULL || pReducer->discardData == NULL || pReducer->pResultBuf == NULL || /*pReducer->pBufForInterpo == NULL || */pReducer->pFinalRes == NULL || pReducer->prevRowOfInput == NULL) { - tfree(pReducer->pTempBuffer); - tfree(pReducer->discardData); - tfree(pReducer->pResultBuf); - tfree(pReducer->pFinalRes); - tfree(pReducer->prevRowOfInput); - tfree(pReducer->pLoserTree); - tfree(param); - tfree(pReducer); + taosTFree(pReducer->pTempBuffer); + taosTFree(pReducer->discardData); + taosTFree(pReducer->pResultBuf); + taosTFree(pReducer->pFinalRes); + taosTFree(pReducer->prevRowOfInput); + taosTFree(pReducer->pLoserTree); + taosTFree(param); + taosTFree(pReducer); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return; } @@ -516,38 +516,38 @@ void tscDestroyLocalReducer(SSqlObj *pSql) { tVariantDestroy(&pCtx->tag); if (pCtx->tagInfo.pTagCtxList != NULL) { - tfree(pCtx->tagInfo.pTagCtxList); + taosTFree(pCtx->tagInfo.pTagCtxList); } } - tfree(pLocalReducer->pCtx); + taosTFree(pLocalReducer->pCtx); } - tfree(pLocalReducer->prevRowOfInput); + taosTFree(pLocalReducer->prevRowOfInput); - tfree(pLocalReducer->pTempBuffer); - tfree(pLocalReducer->pResultBuf); + taosTFree(pLocalReducer->pTempBuffer); + taosTFree(pLocalReducer->pResultBuf); if (pLocalReducer->pResInfo != NULL) { for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { - tfree(pLocalReducer->pResInfo[i].interResultBuf); + taosTFree(pLocalReducer->pResInfo[i].interResultBuf); } - tfree(pLocalReducer->pResInfo); + taosTFree(pLocalReducer->pResInfo); } if (pLocalReducer->pLoserTree) { - tfree(pLocalReducer->pLoserTree->param); - tfree(pLocalReducer->pLoserTree); + taosTFree(pLocalReducer->pLoserTree->param); + taosTFree(pLocalReducer->pLoserTree); } - tfree(pLocalReducer->pFinalRes); - tfree(pLocalReducer->discardData); + taosTFree(pLocalReducer->pFinalRes); + taosTFree(pLocalReducer->discardData); tscLocalReducerEnvDestroy(pLocalReducer->pExtMemBuffer, pLocalReducer->pDesc, pLocalReducer->resColModel, pLocalReducer->numOfVnode); for (int32_t i = 0; i < pLocalReducer->numOfBuffer; ++i) { - tfree(pLocalReducer->pLocalDataSrc[i]); + taosTFree(pLocalReducer->pLocalDataSrc[i]); } pLocalReducer->numOfBuffer = 0; @@ -593,7 +593,7 @@ static int32_t createOrderDescriptor(tOrderDescriptor **pOrderDesc, SSqlCmd *pCm } *pOrderDesc = tOrderDesCreate(orderIdx, numOfGroupByCols, pModel, pQueryInfo->order.order); - tfree(orderIdx); + taosTFree(orderIdx); if (*pOrderDesc == NULL) { return TSDB_CODE_TSC_OUT_OF_MEMORY; @@ -705,7 +705,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr if (createOrderDescriptor(pOrderDesc, pCmd, pModel) != TSDB_CODE_SUCCESS) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; - tfree(pSchema); + taosTFree(pSchema); return pRes->code; } @@ -746,7 +746,7 @@ int32_t tscLocalReducerEnvCreate(SSqlObj *pSql, tExtMemBuffer ***pMemBuffer, tOr } *pFinalModel = createColumnModel(pSchema, size, capacity); - tfree(pSchema); + taosTFree(pSchema); return TSDB_CODE_SUCCESS; } @@ -765,7 +765,7 @@ void tscLocalReducerEnvDestroy(tExtMemBuffer **pMemBuffer, tOrderDescriptor *pDe pMemBuffer[i] = destoryExtMemBuffer(pMemBuffer[i]); } - tfree(pMemBuffer); + taosTFree(pMemBuffer); } /** @@ -1036,10 +1036,10 @@ static void doFillResult(SSqlObj *pSql, SLocalReducer *pLocalReducer, bool doneO pFinalDataPage->num = 0; for (int32_t i = 0; i < pQueryInfo->fieldsInfo.numOfOutput; ++i) { - tfree(pResPages[i]); + taosTFree(pResPages[i]); } - tfree(pResPages); + taosTFree(pResPages); } static void savePreviousRow(SLocalReducer *pLocalReducer, tFilePage *tmpBuffer) { diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index ae2370cd56..2f245ee513 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -30,7 +30,6 @@ #include "tscLog.h" #include "tscSubquery.h" #include "tstoken.h" -#include "ttime.h" #include "tdataformat.h" @@ -1388,7 +1387,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { assert(taos_errno(pSql) == code); taos_free_result(pSql); - tfree(pSupporter); + taosTFree(pSupporter); fclose(fp); pParentSql->res.code = code; @@ -1453,7 +1452,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { } } - tfree(tokenBuf); + taosTFree(tokenBuf); free(line); if (count > 0) { @@ -1466,7 +1465,7 @@ static void parseFileSendDataBlock(void *param, TAOS_RES *tres, int code) { } else { taos_free_result(pSql); - tfree(pSupporter); + taosTFree(pSupporter); fclose(fp); pParentSql->fp = pParentSql->fetchFp; @@ -1496,7 +1495,7 @@ void tscProcessMultiVnodesImportFromFile(SSqlObj *pSql) { pSql->res.code = TAOS_SYSTEM_ERROR(errno); tscError("%p failed to open file %s to load data from file, code:%s", pSql, pCmd->payload, tstrerror(pSql->res.code)); - tfree(pSupporter) + taosTFree(pSupporter) tscQueueAsyncRes(pSql); return; diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 0cf69dfd46..3ddfc1c341 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -613,7 +613,7 @@ int taos_stmt_execute(TAOS_STMT* stmt) { if (sql == NULL) { ret = TSDB_CODE_TSC_OUT_OF_MEMORY; } else { - tfree(pStmt->pSql->sqlstr); + taosTFree(pStmt->pSql->sqlstr); pStmt->pSql->sqlstr = sql; SSqlObj* pSql = taos_query((TAOS*)pStmt->taos, pStmt->pSql->sqlstr); ret = taos_errno(pSql); diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 602b4654df..363243b1d7 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -16,7 +16,6 @@ #include "os.h" #include "tscLog.h" #include "tsclient.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" #include "taosmsg.h" diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 44236face0..4e0c238ac0 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -29,7 +29,6 @@ #include "tsclient.h" #include "tstoken.h" #include "tstrbuild.h" -#include "ttime.h" #include "ttokendef.h" #define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0" @@ -737,7 +736,7 @@ int32_t tscSetTableFullName(STableMetaInfo* pTableMetaInfo, SSQLToken* pzTableNa assert(pTableMetaInfo->pTableMeta == NULL); } - tfree(oldName); + taosTFree(oldName); return TSDB_CODE_SUCCESS; } @@ -3648,7 +3647,7 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t ret = setObjFullName(idBuf, account, &dbToken, &t, &xlen); if (ret != TSDB_CODE_SUCCESS) { taosStringBuilderDestroy(&sb1); - tfree(segments); + taosTFree(segments); invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg); return ret; @@ -3661,7 +3660,7 @@ static int32_t setTableCondForSTableQuery(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, pQueryInfo->tagCond.tbnameCond.cond = strdup(str); taosStringBuilderDestroy(&sb1); - tfree(segments); + taosTFree(segments); return TSDB_CODE_SUCCESS; } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 521280af87..3fd0aa79a6 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -23,7 +23,6 @@ #include "tscUtil.h" #include "tschemautil.h" #include "tsclient.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" #include "tlockfree.h" @@ -196,7 +195,7 @@ void tscProcessActivityTimer(void *handle, void *tmrId) { pSql->cmd.command = TSDB_SQL_HB; if (TSDB_CODE_SUCCESS != tscAllocPayload(&(pSql->cmd), TSDB_DEFAULT_PAYLOAD_SIZE)) { - tfree(pSql); + taosTFree(pSql); return; } @@ -1538,7 +1537,7 @@ int tscBuildTableMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { pCmd->payloadLen = pMsg - (char*)pInfoMsg; pCmd->msgType = TSDB_MSG_TYPE_CM_TABLE_META; - tfree(tmpData); + taosTFree(tmpData); assert(msgLen + minMsgSize() <= pCmd->allocSize); return TSDB_CODE_SUCCESS; @@ -1572,7 +1571,7 @@ int tscBuildMultiMeterMetaMsg(SSqlObj *pSql, SSqlInfo *pInfo) { memcpy(pInfoMsg->tableIds, tmpData, pCmd->payloadLen); } - tfree(tmpData); + taosTFree(tmpData); pCmd->payloadLen += sizeof(SMgmtHead) + sizeof(SCMMultiTableInfoMsg); pCmd->msgType = TSDB_MSG_TYPE_CM_TABLES_META; @@ -1962,7 +1961,7 @@ int tscProcessShowRsp(SSqlObj *pSql) { pCmd->numOfCols = pQueryInfo->fieldsInfo.numOfOutput; tscFieldInfoUpdateOffset(pQueryInfo); - tfree(pTableMeta); + taosTFree(pTableMeta); return 0; } diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index ff050dbbbf..10720874e2 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -474,7 +474,7 @@ int taos_fetch_block(TAOS_RES *res, TAOS_ROW *rows) { pRes->rspType = 0; pSql->numOfSubs = 0; - tfree(pSql->pSubs); + taosTFree(pSql->pSubs); assert(pSql->fp == NULL); @@ -753,7 +753,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { if (sqlLen > tsMaxSQLStringLen) { tscError("%p sql too long", pSql); pRes->code = TSDB_CODE_TSC_INVALID_SQL; - tfree(pSql); + taosTFree(pSql); return pRes->code; } @@ -762,7 +762,7 @@ int taos_validate_sql(TAOS *taos, const char *sql) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); tscDebug("%p Valid SQL result:%d, %s pObj:%p", pSql, pRes->code, taos_errstr(taos), pObj); - tfree(pSql); + taosTFree(pSql); return pRes->code; } @@ -896,7 +896,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { if (tblListLen > MAX_TABLE_NAME_LENGTH) { tscError("%p tableNameList too long, length:%d, maximum allowed:%d", pSql, tblListLen, MAX_TABLE_NAME_LENGTH); pRes->code = TSDB_CODE_TSC_INVALID_SQL; - tfree(pSql); + taosTFree(pSql); return pRes->code; } @@ -904,7 +904,7 @@ int taos_load_table_info(TAOS *taos, const char *tableNameList) { if (str == NULL) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscError("%p failed to malloc sql string buffer", pSql); - tfree(pSql); + taosTFree(pSql); return pRes->code; } diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index b07627c87b..20b5e86090 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -21,7 +21,6 @@ #include "tsched.h" #include "tcache.h" #include "tsclient.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" @@ -156,7 +155,7 @@ static void tscProcessStreamQueryCallback(void *param, TAOS_RES *tres, int numOf STableMetaInfo* pTableMetaInfo = tscGetTableMetaInfoFromCmd(&pStream->pSql->cmd, 0, 0); taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), true); - tfree(pTableMetaInfo->vgroupList); + taosTFree(pTableMetaInfo->vgroupList); tscSetRetryTimer(pStream, pStream->pSql, retryDelay); return; @@ -260,9 +259,9 @@ static void tscProcessStreamRetrieveResult(void *param, TAOS_RES *res, int numOf taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), false); tscFreeSqlResult(pSql); - tfree(pSql->pSubs); + taosTFree(pSql->pSubs); pSql->numOfSubs = 0; - tfree(pTableMetaInfo->vgroupList); + taosTFree(pTableMetaInfo->vgroupList); tscSetNextLaunchTimer(pStream, pSql); } } @@ -592,6 +591,6 @@ void taos_close_stream(TAOS_STREAM *handle) { tscFreeSqlObj(pSql); pStream->pSql = NULL; - tfree(pStream); + taosTFree(pStream); } } diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index 6e572d94d1..9569987de0 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -18,7 +18,6 @@ #include "trpc.h" #include "tsclient.h" #include "tsocket.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" #include "tscLog.h" diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index 79c45daa20..fed790b9af 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -215,7 +215,7 @@ static void tscDestroyJoinSupporter(SJoinSupporter* pSupporter) { pSupporter->f = NULL; } - tfree(pSupporter->pIdTagList); + taosTFree(pSupporter->pIdTagList); tscTagCondRelease(&pSupporter->tagCond); free(pSupporter); } @@ -407,7 +407,7 @@ void freeJoinSubqueryObj(SSqlObj* pSql) { } } - tfree(pState); + taosTFree(pState); pSql->numOfSubs = 0; } @@ -1317,12 +1317,12 @@ static void doCleanupSubqueries(SSqlObj *pSql, int32_t numOfSubs, SSubqueryState SRetrieveSupport* pSupport = pSub->param; - tfree(pSupport->localBuffer); + taosTFree(pSupport->localBuffer); pthread_mutex_unlock(&pSupport->queryMutex); pthread_mutex_destroy(&pSupport->queryMutex); - tfree(pSupport); + taosTFree(pSupport); tscFreeSqlObj(pSub); } @@ -1358,7 +1358,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { if (ret != 0) { pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; tscQueueAsyncRes(pSql); - tfree(pMemoryBuf); + taosTFree(pMemoryBuf); return ret; } @@ -1386,7 +1386,7 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { trs->localBuffer = (tFilePage *)calloc(1, nBufferSize + sizeof(tFilePage)); if (trs->localBuffer == NULL) { tscError("%p failed to malloc buffer for local buffer, orderOfSub:%d, reason:%s", pSql, i, strerror(errno)); - tfree(trs); + taosTFree(trs); break; } @@ -1404,8 +1404,8 @@ int32_t tscHandleMasterSTableQuery(SSqlObj *pSql) { SSqlObj *pNew = tscCreateSqlObjForSubquery(pSql, trs, NULL); if (pNew == NULL) { tscError("%p failed to malloc buffer for subObj, orderOfSub:%d, reason:%s", pSql, i, strerror(errno)); - tfree(trs->localBuffer); - tfree(trs); + taosTFree(trs->localBuffer); + taosTFree(trs); break; } @@ -1450,12 +1450,12 @@ static void tscFreeSubSqlObj(SRetrieveSupport *trsupport, SSqlObj *pSql) { taos_free_result(pSql); - tfree(trsupport->localBuffer); + taosTFree(trsupport->localBuffer); pthread_mutex_unlock(&trsupport->queryMutex); pthread_mutex_destroy(&trsupport->queryMutex); - tfree(trsupport); + taosTFree(trsupport); } static void tscRetrieveFromDnodeCallBack(void *param, TAOS_RES *tres, int numOfRows); @@ -1572,7 +1572,7 @@ void tscHandleSubqueryError(SRetrieveSupport *trsupport, SSqlObj *pSql, int numO tscLocalReducerEnvDestroy(trsupport->pExtMemBuffer, trsupport->pOrderDescriptor, trsupport->pFinalColModel, pState->numOfTotal); - tfree(trsupport->pState); + taosTFree(trsupport->pState); tscFreeSubSqlObj(trsupport, pSql); // in case of second stage join subquery, invoke its callback function instead of regular QueueAsyncRes @@ -1651,7 +1651,7 @@ static void tscAllDataRetrievedFromDnode(SRetrieveSupport *trsupport, SSqlObj* p pParentSql->res.row = 0; // only free once - tfree(trsupport->pState); + taosTFree(trsupport->pState); tscFreeSubSqlObj(trsupport, pSql); // set the command flag must be after the semaphore been correctly set. @@ -1855,7 +1855,7 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows) } taos_free_result(tres); - tfree(pSupporter); + taosTFree(pSupporter); if (atomic_sub_fetch_32(&pState->numOfRemain, 1) > 0) { return; @@ -1864,7 +1864,7 @@ static void multiVnodeInsertFinalize(void* param, TAOS_RES* tres, int numOfRows) tscDebug("%p Async insertion completed, total inserted:%" PRId64, pParentObj, pParentObj->res.numOfRows); // release data block data - tfree(pState); + taosTFree(pState); // restore user defined fp pParentObj->fp = pParentObj->fetchFp; @@ -1968,11 +1968,11 @@ int32_t tscHandleMultivnodeInsert(SSqlObj *pSql) { _error: for(int32_t j = 0; j < numOfSub; ++j) { - tfree(pSql->pSubs[j]->param); + taosTFree(pSql->pSubs[j]->param); taos_free_result(pSql->pSubs[j]); } - tfree(pState); + taosTFree(pState); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -2143,7 +2143,7 @@ void **doSetResultRowData(SSqlObj *pSql, bool finalResult) { assert(pRes->row >= 0 && pRes->row <= pRes->numOfRows); if (pRes->row >= pRes->numOfRows) { // all the results has returned to invoker - tfree(pRes->tsrow); + taosTFree(pRes->tsrow); return pRes->tsrow; } diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 42356108b1..a252beec33 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -18,7 +18,6 @@ #include "tcache.h" #include "trpc.h" #include "tsystem.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" #include "tsched.h" diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 73d6f0e592..9e0ff8a9bf 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -245,7 +245,7 @@ void tscClearInterpInfo(SQueryInfo* pQueryInfo) { } pQueryInfo->fillType = TSDB_FILL_NONE; - tfree(pQueryInfo->fillVal); + taosTFree(pQueryInfo->fillVal); } int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) { @@ -259,9 +259,9 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) { // not enough memory if (pRes->tsrow == NULL || (pRes->buffer == NULL && pRes->numOfCols > 0)) { - tfree(pRes->tsrow); - tfree(pRes->buffer); - tfree(pRes->length); + taosTFree(pRes->tsrow); + taosTFree(pRes->buffer); + taosTFree(pRes->length); pRes->code = TSDB_CODE_TSC_OUT_OF_MEMORY; return pRes->code; @@ -274,23 +274,23 @@ int32_t tscCreateResPointerInfo(SSqlRes* pRes, SQueryInfo* pQueryInfo) { void tscDestroyResPointerInfo(SSqlRes* pRes) { if (pRes->buffer != NULL) { // free all buffers containing the multibyte string for (int i = 0; i < pRes->numOfCols; i++) { - tfree(pRes->buffer[i]); + taosTFree(pRes->buffer[i]); } pRes->numOfCols = 0; } - tfree(pRes->pRsp); - tfree(pRes->tsrow); - tfree(pRes->length); + taosTFree(pRes->pRsp); + taosTFree(pRes->tsrow); + taosTFree(pRes->length); - tfree(pRes->pGroupRec); - tfree(pRes->pColumnIndex); - tfree(pRes->buffer); + taosTFree(pRes->pGroupRec); + taosTFree(pRes->pColumnIndex); + taosTFree(pRes->buffer); if (pRes->pArithSup != NULL) { - tfree(pRes->pArithSup->data); - tfree(pRes->pArithSup); + taosTFree(pRes->pArithSup->data); + taosTFree(pRes->pArithSup); } pRes->data = NULL; // pRes->data points to the buffer of pRsp, no need to free @@ -307,11 +307,11 @@ static void tscFreeQueryInfo(SSqlCmd* pCmd) { freeQueryInfoImpl(pQueryInfo); clearAllTableMetaInfo(pQueryInfo, (const char*)addr, false); - tfree(pQueryInfo); + taosTFree(pQueryInfo); } pCmd->numOfClause = 0; - tfree(pCmd->pQueryInfo); + taosTFree(pCmd->pQueryInfo); } void tscResetSqlCmdObj(SSqlCmd* pCmd) { @@ -357,13 +357,13 @@ void tscPartiallyFreeSqlObj(SSqlObj* pSql) { // pSql->sqlstr will be used by tscBuildQueryStreamDesc if (pObj->signature == pObj) { //pthread_mutex_lock(&pObj->mutex); - tfree(pSql->sqlstr); + taosTFree(pSql->sqlstr); //pthread_mutex_unlock(&pObj->mutex); } tscFreeSqlResult(pSql); - tfree(pSql->pSubs); + taosTFree(pSql->pSubs); pSql->numOfSubs = 0; tscResetSqlCmdObj(pCmd); @@ -383,10 +383,10 @@ void tscFreeSqlObj(SSqlObj* pSql) { SSqlCmd* pCmd = &pSql->cmd; memset(pCmd->payload, 0, (size_t)pCmd->allocSize); - tfree(pCmd->payload); + taosTFree(pCmd->payload); pCmd->allocSize = 0; - tfree(pSql->sqlstr); + taosTFree(pSql->sqlstr); sem_destroy(&pSql->rspSem); free(pSql); } @@ -396,12 +396,12 @@ void tscDestroyDataBlock(STableDataBlocks* pDataBlock) { return; } - tfree(pDataBlock->pData); - tfree(pDataBlock->params); + taosTFree(pDataBlock->pData); + taosTFree(pDataBlock->params); // free the refcount for metermeta taosCacheRelease(tscCacheHandle, (void**)&(pDataBlock->pTableMeta), false); - tfree(pDataBlock); + taosTFree(pDataBlock); } SParamInfo* tscAddParamToDataBlock(STableDataBlocks* pDataBlock, char type, uint8_t timePrec, short bytes, @@ -679,7 +679,7 @@ int32_t tscMergeTableDataBlocks(SSqlObj* pSql, SArray* pTableDataBlockList) { taosHashCleanup(pVnodeDataBlockHashList); tscDestroyBlockArrayList(pVnodeDataBlockList); - tfree(dataBuf->pData); + taosTFree(dataBuf->pData); return TSDB_CODE_TSC_OUT_OF_MEMORY; } @@ -735,7 +735,7 @@ void tscCloseTscObj(STscObj* pObj) { } tscDebug("%p DB connection is closed, dnodeConn:%p", pObj, pObj->pDnodeConn); - tfree(pObj); + taosTFree(pObj); } bool tscIsInsertData(char* sqlstr) { @@ -916,7 +916,7 @@ void tscFieldInfoClear(SFieldInfo* pFieldInfo) { if (pInfo->pArithExprInfo != NULL) { tExprTreeDestroy(&pInfo->pArithExprInfo->pExpr, NULL); - tfree(pInfo->pArithExprInfo); + taosTFree(pInfo->pArithExprInfo); } } @@ -1029,7 +1029,7 @@ void* sqlExprDestroy(SSqlExpr* pExpr) { tVariantDestroy(&pExpr->param[i]); } - tfree(pExpr); + taosTFree(pExpr); return NULL; } @@ -1116,11 +1116,11 @@ SColumn* tscColumnListInsert(SArray* pColumnList, SColumnIndex* pColIndex) { static void destroyFilterInfo(SColumnFilterInfo* pFilterInfo, int32_t numOfFilters) { for(int32_t i = 0; i < numOfFilters; ++i) { if (pFilterInfo[i].filterstr) { - tfree(pFilterInfo[i].pz); + taosTFree(pFilterInfo[i].pz); } } - tfree(pFilterInfo); + taosTFree(pFilterInfo); } SColumn* tscColumnClone(const SColumn* src) { @@ -1351,7 +1351,7 @@ void tscTagCondRelease(STagCond* pTagCond) { size_t s = taosArrayGetSize(pTagCond->pCond); for (int32_t i = 0; i < s; ++i) { SCond* p = taosArrayGet(pTagCond->pCond, i); - tfree(p->cond); + taosTFree(p->cond); } taosArrayDestroy(pTagCond->pCond); @@ -1546,7 +1546,7 @@ static void freeQueryInfoImpl(SQueryInfo* pQueryInfo) { pQueryInfo->tsBuf = tsBufDestroy(pQueryInfo->tsBuf); - tfree(pQueryInfo->fillVal); + taosTFree(pQueryInfo->fillVal); } void tscClearSubqueryInfo(SSqlCmd* pCmd) { @@ -1566,7 +1566,7 @@ void clearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool rem free(pTableMetaInfo); } - tfree(pQueryInfo->pTableMetaInfo); + taosTFree(pQueryInfo->pTableMetaInfo); } STableMetaInfo* tscAddTableMetaInfo(SQueryInfo* pQueryInfo, const char* name, STableMeta* pTableMeta, @@ -1613,7 +1613,7 @@ void tscClearTableMetaInfo(STableMetaInfo* pTableMetaInfo, bool removeFromCache) } taosCacheRelease(tscCacheHandle, (void**)&(pTableMetaInfo->pTableMeta), removeFromCache); - tfree(pTableMetaInfo->vgroupList); + taosTFree(pTableMetaInfo->vgroupList); tscColumnListDestroy(pTableMetaInfo->tagColList); pTableMetaInfo->tagColList = NULL; @@ -2084,7 +2084,7 @@ void tscTryQueryNextClause(SSqlObj* pSql, __async_cb_func_t fp) { pRes->numOfTotal = num; - tfree(pSql->pSubs); + taosTFree(pSql->pSubs); pSql->numOfSubs = 0; pSql->fp = fp; diff --git a/src/client/tests/timeParseTest.cpp b/src/client/tests/timeParseTest.cpp index b37be0485b..bee01b5cec 100644 --- a/src/client/tests/timeParseTest.cpp +++ b/src/client/tests/timeParseTest.cpp @@ -1,10 +1,10 @@ +#include "os.h" #include #include #include #include "taos.h" #include "tstoken.h" -#include "ttime.h" #include "tutil.h" int main(int argc, char** argv) { diff --git a/src/common/inc/tdataformat.h b/src/common/inc/tdataformat.h index 68875341ba..6c6e5e35d8 100644 --- a/src/common/inc/tdataformat.h +++ b/src/common/inc/tdataformat.h @@ -80,7 +80,7 @@ typedef struct { #define schemaFLen(s) ((s)->flen) #define schemaVLen(s) ((s)->vlen) #define schemaColAt(s, i) ((s)->columns + i) -#define tdFreeSchema(s) tfree((s)) +#define tdFreeSchema(s) taosTFree((s)) STSchema *tdDupSchema(STSchema *pSchema); int tdEncodeSchema(void **buf, STSchema *pSchema); @@ -284,7 +284,7 @@ typedef struct { #define kvRowCpy(dst, r) memcpy((dst), (r), kvRowLen(r)) #define kvRowColVal(r, colIdx) POINTER_SHIFT(kvRowValues(r), (colIdx)->offset) #define kvRowColIdxAt(r, i) (kvRowColIdx(r) + (i)) -#define kvRowFree(r) tfree(r) +#define kvRowFree(r) taosTFree(r) #define kvRowEnd(r) POINTER_SHIFT(r, kvRowLen(r)) SKVRow tdKVRowDup(SKVRow row); diff --git a/src/common/src/tdataformat.c b/src/common/src/tdataformat.c index adfce5580e..a185a9de7b 100644 --- a/src/common/src/tdataformat.c +++ b/src/common/src/tdataformat.c @@ -93,7 +93,7 @@ int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, int32_t version) { void tdDestroyTSchemaBuilder(STSchemaBuilder *pBuilder) { if (pBuilder) { - tfree(pBuilder->columns); + taosTFree(pBuilder->columns); } } @@ -361,8 +361,8 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) { void tdFreeDataCols(SDataCols *pCols) { if (pCols) { - tfree(pCols->buf); - tfree(pCols->cols); + taosTFree(pCols->buf); + taosTFree(pCols->cols); free(pCols); } } @@ -685,8 +685,8 @@ int tdInitKVRowBuilder(SKVRowBuilder *pBuilder) { } void tdDestroyKVRowBuilder(SKVRowBuilder *pBuilder) { - tfree(pBuilder->pColIdx); - tfree(pBuilder->buf); + taosTFree(pBuilder->pColIdx); + taosTFree(pBuilder->buf); } void tdResetKVRowBuilder(SKVRowBuilder *pBuilder) { diff --git a/src/common/src/tvariant.c b/src/common/src/tvariant.c index 1b64a7aefa..2906b3f0ac 100644 --- a/src/common/src/tvariant.c +++ b/src/common/src/tvariant.c @@ -128,7 +128,7 @@ void tVariantDestroy(tVariant *pVar) { if (pVar == NULL) return; if (pVar->nType == TSDB_DATA_TYPE_BINARY || pVar->nType == TSDB_DATA_TYPE_NCHAR) { - tfree(pVar->pz); + taosTFree(pVar->pz); pVar->nLen = 0; } diff --git a/src/cq/src/cqMain.c b/src/cq/src/cqMain.c index e0f30166c4..758d620e57 100644 --- a/src/cq/src/cqMain.c +++ b/src/cq/src/cqMain.c @@ -114,7 +114,7 @@ void cqClose(void *handle) { SCqObj *pTemp = pObj; pObj = pObj->next; tdFreeSchema(pTemp->pSchema); - tfree(pTemp->sqlStr); + taosTFree(pTemp->sqlStr); free(pTemp); } diff --git a/src/dnode/src/dnodeMPeer.c b/src/dnode/src/dnodeMPeer.c index 85230c7da9..82ed7dd179 100644 --- a/src/dnode/src/dnodeMPeer.c +++ b/src/dnode/src/dnodeMPeer.c @@ -75,7 +75,7 @@ void dnodeCleanupMnodePeer() { } taosCloseQset(tsMPeerQset); - tfree(tsMPeerPool.peerWorker); + taosTFree(tsMPeerPool.peerWorker); dInfo("dnode mpeer is closed"); } diff --git a/src/dnode/src/dnodeMWrite.c b/src/dnode/src/dnodeMWrite.c index b53c66e00c..0a305b5598 100644 --- a/src/dnode/src/dnodeMWrite.c +++ b/src/dnode/src/dnodeMWrite.c @@ -77,7 +77,7 @@ void dnodeCleanupMnodeWrite() { } taosCloseQset(tsMWriteQset); - tfree(tsMWritePool.writeWorker); + taosTFree(tsMWritePool.writeWorker); dInfo("dnode mwrite is closed"); } diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index ec35475d73..745ffb3b84 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -18,13 +18,11 @@ #include "cJSON.h" #include "taoserror.h" #include "taosmsg.h" -#include "ttime.h" #include "ttimer.h" #include "tsdb.h" #include "twal.h" #include "tqueue.h" #include "tsync.h" -#include "ttime.h" #include "ttimer.h" #include "tbalance.h" #include "tglobal.h" diff --git a/src/kit/shell/src/shellDarwin.c b/src/kit/shell/src/shellDarwin.c index 1a75a2aa85..3cb324abe9 100644 --- a/src/kit/shell/src/shellDarwin.c +++ b/src/kit/shell/src/shellDarwin.c @@ -229,8 +229,8 @@ void shellReadCommand(TAOS *con, char *command) { printf("\n"); if (isReadyGo(&cmd)) { sprintf(command, "%s%s", cmd.buffer, cmd.command); - tfree(cmd.buffer); - tfree(cmd.command); + taosTFree(cmd.buffer); + taosTFree(cmd.command); return; } else { updateBuffer(&cmd); diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 616a3bfd7f..5d877ba6f0 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -21,7 +21,6 @@ #include "os.h" #include "shell.h" #include "shellCommand.h" -#include "ttime.h" #include "tutil.h" #include "taosdef.h" #include "taoserror.h" @@ -176,7 +175,7 @@ int32_t shellRunCommand(TAOS* con, char* command) { history.hist[(history.hend + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE] == NULL || strcmp(command, history.hist[(history.hend + MAX_HISTORY_SIZE - 1) % MAX_HISTORY_SIZE]) != 0) { if (history.hist[history.hend] != NULL) { - tfree(history.hist[history.hend]); + taosTFree(history.hist[history.hend]); } history.hist[history.hend] = strdup(command); @@ -770,7 +769,7 @@ void write_history() { for (int i = history.hstart; i != history.hend;) { if (history.hist[i] != NULL) { fprintf(f, "%s\n", history.hist[i]); - tfree(history.hist[i]); + taosTFree(history.hist[i]); } i = (i + 1) % MAX_HISTORY_SIZE; } diff --git a/src/kit/shell/src/shellImport.c b/src/kit/shell/src/shellImport.c index afd2d85dae..ee0a90757b 100644 --- a/src/kit/shell/src/shellImport.c +++ b/src/kit/shell/src/shellImport.c @@ -21,7 +21,6 @@ #include "shell.h" #include "shellCommand.h" #include "tglobal.h" -#include "ttime.h" #include "tutil.h" static char **shellSQLFiles = NULL; diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index 94f3901dd8..963afe346d 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -201,8 +201,8 @@ void shellReadCommand(TAOS *con, char *command) { printf("\n"); if (isReadyGo(&cmd)) { sprintf(command, "%s%s", cmd.buffer, cmd.command); - tfree(cmd.buffer); - tfree(cmd.command); + taosTFree(cmd.buffer); + taosTFree(cmd.command); return; } else { updateBuffer(&cmd); @@ -320,7 +320,7 @@ void *shellLoopQuery(void *arg) { reset_terminal_mode(); } while (shellRunCommand(con, command) == 0); - tfree(command); + taosTFree(command); exitShell(); pthread_cleanup_pop(1); diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 7ae209bbdf..ee98c711e0 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -448,8 +448,8 @@ int main(int argc, char *argv[]) { void taosFreeDbInfos() { if (dbInfos == NULL) return; - for (int i = 0; i < 128; i++) tfree(dbInfos[i]); - tfree(dbInfos); + for (int i = 0; i < 128; i++) taosTFree(dbInfos[i]); + taosTFree(dbInfos); } // check table is normal table or super table @@ -606,11 +606,11 @@ int32_t taosSaveTableOfMetricToTempFile(TAOS *taosCon, char* metric, struct argu if (numOfTable >= arguments->table_batch) { numOfTable = 0; - tclose(fd); + taosClose(fd); fd = -1; } } - tclose(fd); + taosClose(fd); fd = -1; taos_free_result(result); @@ -780,14 +780,14 @@ int taosDumpOut(struct arguments *arguments) { if (retCode < 0) { if (-1 != normalTblFd){ - tclose(normalTblFd); + taosClose(normalTblFd); } goto _clean_tmp_file; } } if (-1 != normalTblFd){ - tclose(normalTblFd); + taosClose(normalTblFd); } // start multi threads to dumpout @@ -806,7 +806,7 @@ int taosDumpOut(struct arguments *arguments) { fclose(fp); taos_close(taos); taos_free_result(result); - tfree(command); + taosTFree(command); taosFreeDbInfos(); fprintf(stderr, "dump out rows: %" PRId64 "\n", totalDumpOutRows); return 0; @@ -815,7 +815,7 @@ _exit_failure: fclose(fp); taos_close(taos); taos_free_result(result); - tfree(command); + taosTFree(command); taosFreeDbInfos(); fprintf(stderr, "dump out rows: %" PRId64 "\n", totalDumpOutRows); return -1; @@ -1076,7 +1076,7 @@ void* taosDumpOutWorkThreadFp(void *arg) } taos_free_result(tmpResult); - tclose(fd); + taosClose(fd); fclose(fp); return NULL; @@ -1206,7 +1206,7 @@ int32_t taosDumpCreateSuperTableClause(TAOS* taosCon, char* dbName, FILE *fp) (void)taosDumpStable(tableRecord.name, fp, taosCon); } - tclose(fd); + taosClose(fd); remove(".stables.tmp"); free(tmpCommand); @@ -1288,11 +1288,11 @@ int taosDumpDb(SDbInfo *dbInfo, struct arguments *arguments, FILE *fp, TAOS *tao if (numOfTable >= arguments->table_batch) { numOfTable = 0; - tclose(fd); + taosClose(fd); fd = -1; } } - tclose(fd); + taosClose(fd); fd = -1; taos_free_result(tmpResult); @@ -1760,13 +1760,13 @@ void taosLoadFileCharset(FILE *fp, char *fcharset) { } strcpy(fcharset, line + 2); - tfree(line); + taosTFree(line); return; _exit_no_charset: fseek(fp, 0, SEEK_SET); *fcharset = '\0'; - tfree(line); + taosTFree(line); return; } @@ -1860,9 +1860,9 @@ static void taosMallocSQLFiles() static void taosFreeSQLFiles() { for (int i = 0; i < tsSqlFileNum; i++) { - tfree(tsDumpInSqlFiles[i]); + taosTFree(tsDumpInSqlFiles[i]); } - tfree(tsDumpInSqlFiles); + taosTFree(tsDumpInSqlFiles); } static void taosGetDirectoryFileList(char *inputDir) @@ -2063,17 +2063,17 @@ int taosDumpInOneFile_old(TAOS * taos, FILE* fp, char* fcharset, char* encod } if (cd != ((iconv_t)(-1))) iconv_close(cd); - tfree(line); - tfree(command); - tfree(lcommand); + taosTFree(line); + taosTFree(command); + taosTFree(lcommand); taos_close(taos); fclose(fp); return 0; _dumpin_exit_failure: if (cd != ((iconv_t)(-1))) iconv_close(cd); - tfree(command); - tfree(lcommand); + taosTFree(command); + taosTFree(lcommand); taos_close(taos); fclose(fp); return -1; @@ -2120,8 +2120,8 @@ int taosDumpInOneFile(TAOS * taos, FILE* fp, char* fcharset, char* encode, c cmd_len = 0; } - tfree(cmd); - tfree(line); + taosTFree(cmd); + taosTFree(line); fclose(fp); return 0; } diff --git a/src/kit/taosmigrate/taosmigrateVnodeCfg.c b/src/kit/taosmigrate/taosmigrateVnodeCfg.c index e80e687f02..472671c22c 100644 --- a/src/kit/taosmigrate/taosmigrateVnodeCfg.c +++ b/src/kit/taosmigrate/taosmigrateVnodeCfg.c @@ -289,7 +289,7 @@ static int32_t readVnodeCfg(SVnodeObj *pVnode, char* cfgFile) //} PARSE_OVER: - tfree(content); + taosTFree(content); cJSON_Delete(root); if (fp) fclose(fp); return ret; diff --git a/src/mnode/src/mnodeAcct.c b/src/mnode/src/mnodeAcct.c index c40a696ede..5244bc3e85 100644 --- a/src/mnode/src/mnodeAcct.c +++ b/src/mnode/src/mnodeAcct.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taoserror.h" -#include "ttime.h" #include "dnode.h" #include "mnodeDef.h" #include "mnodeInt.h" @@ -34,7 +33,7 @@ static int32_t mnodeCreateRootAcct(); static int32_t mnodeAcctActionDestroy(SSdbOper *pOper) { SAcctObj *pAcct = pOper->pObj; pthread_mutex_destroy(&pAcct->mutex); - tfree(pOper->pObj); + taosTFree(pOper->pObj); return TSDB_CODE_SUCCESS; } diff --git a/src/mnode/src/mnodeCluster.c b/src/mnode/src/mnodeCluster.c index 41727712b5..5231b7bcd3 100644 --- a/src/mnode/src/mnodeCluster.c +++ b/src/mnode/src/mnodeCluster.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taoserror.h" -#include "ttime.h" #include "dnode.h" #include "mnodeDef.h" #include "mnodeInt.h" @@ -34,7 +33,7 @@ static int32_t mnodeGetClusterMeta(STableMetaMsg *pMeta, SShowObj *pShow, void * static int32_t mnodeRetrieveClusters(SShowObj *pShow, char *data, int32_t rows, void *pConn); static int32_t mnodeClusterActionDestroy(SSdbOper *pOper) { - tfree(pOper->pObj); + taosTFree(pOper->pObj); return TSDB_CODE_SUCCESS; } diff --git a/src/mnode/src/mnodeDb.c b/src/mnode/src/mnodeDb.c index 82ac0868d1..c7e3085e69 100644 --- a/src/mnode/src/mnodeDb.c +++ b/src/mnode/src/mnodeDb.c @@ -19,7 +19,6 @@ #include "tutil.h" #include "tgrant.h" #include "tglobal.h" -#include "ttime.h" #include "tname.h" #include "tbalance.h" #include "tdataformat.h" @@ -53,8 +52,8 @@ static int32_t mnodeProcessDropDbMsg(SMnodeMsg *pMsg); static void mnodeDestroyDb(SDbObj *pDb) { pthread_mutex_destroy(&pDb->mutex); - tfree(pDb->vgList); - tfree(pDb); + taosTFree(pDb->vgList); + taosTFree(pDb); } static int32_t mnodeDbActionDestroy(SSdbOper *pOper) { @@ -386,7 +385,7 @@ static int32_t mnodeCreateDb(SAcctObj *pAcct, SCMCreateDbMsg *pCreate, void *pMs code = mnodeCheckDbCfg(&pDb->cfg); if (code != TSDB_CODE_SUCCESS) { - tfree(pDb); + taosTFree(pDb); return code; } diff --git a/src/mnode/src/mnodeDnode.c b/src/mnode/src/mnodeDnode.c index be15abe354..06c343a903 100644 --- a/src/mnode/src/mnodeDnode.c +++ b/src/mnode/src/mnodeDnode.c @@ -19,7 +19,6 @@ #include "tbalance.h" #include "tglobal.h" #include "tconfig.h" -#include "ttime.h" #include "tutil.h" #include "tsocket.h" #include "tbalance.h" @@ -62,7 +61,7 @@ static int32_t mnodeRetrieveDnodes(SShowObj *pShow, char *data, int32_t rows, vo static char* mnodeGetDnodeAlternativeRoleStr(int32_t alternativeRole); static int32_t mnodeDnodeActionDestroy(SSdbOper *pOper) { - tfree(pOper->pObj); + taosTFree(pOper->pObj); return TSDB_CODE_SUCCESS; } @@ -504,7 +503,7 @@ static int32_t mnodeCreateDnode(char *ep, SMnodeMsg *pMsg) { int32_t code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { int dnodeId = pDnode->dnodeId; - tfree(pDnode); + taosTFree(pDnode); mError("failed to create dnode:%d, reason:%s", dnodeId, tstrerror(code)); } else { mLInfo("dnode:%d is created", pDnode->dnodeId); diff --git a/src/mnode/src/mnodeMnode.c b/src/mnode/src/mnodeMnode.c index 5f82a9afad..c762403525 100644 --- a/src/mnode/src/mnodeMnode.c +++ b/src/mnode/src/mnodeMnode.c @@ -21,7 +21,6 @@ #include "tsync.h" #include "tbalance.h" #include "tutil.h" -#include "ttime.h" #include "tsocket.h" #include "tdataformat.h" #include "mnodeDef.h" @@ -57,7 +56,7 @@ static int32_t mnodeRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, vo #endif static int32_t mnodeMnodeActionDestroy(SSdbOper *pOper) { - tfree(pOper->pObj); + taosTFree(pOper->pObj); return TSDB_CODE_SUCCESS; } @@ -279,7 +278,7 @@ int32_t mnodeAddMnode(int32_t dnodeId) { int32_t code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { - tfree(pMnode); + taosTFree(pMnode); } mnodeUpdateMnodeEpSet(); diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index ff4ddf1b2a..353dd59671 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -18,7 +18,6 @@ #include "taosmsg.h" #include "taoserror.h" #include "tutil.h" -#include "ttime.h" #include "tcache.h" #include "tglobal.h" #include "tdataformat.h" @@ -133,8 +132,8 @@ SConnObj *mnodeAccquireConn(int32_t connId, char *user, uint32_t ip, uint16_t po static void mnodeFreeConn(void *data) { SConnObj *pConn = data; - tfree(pConn->pQueries); - tfree(pConn->pStreams); + taosTFree(pConn->pQueries); + taosTFree(pConn->pStreams); mDebug("connId:%d, is destroyed", pConn->connId); } diff --git a/src/mnode/src/mnodeSdb.c b/src/mnode/src/mnodeSdb.c index f3f6e33431..a4c2c60aa3 100644 --- a/src/mnode/src/mnodeSdb.c +++ b/src/mnode/src/mnodeSdb.c @@ -934,7 +934,7 @@ void sdbCleanupWriteWorker() { } sdbFreeWritequeue(); - tfree(tsSdbPool.writeWorker); + taosTFree(tsSdbPool.writeWorker); mInfo("sdb write is closed"); } diff --git a/src/mnode/src/mnodeShow.c b/src/mnode/src/mnodeShow.c index 733bd43c74..995bfbe840 100644 --- a/src/mnode/src/mnodeShow.c +++ b/src/mnode/src/mnodeShow.c @@ -403,7 +403,7 @@ static void mnodeFreeShowObj(void *data) { sdbFreeIter(pShow->pIter); mDebug("%p, show is destroyed, data:%p index:%d", pShow, data, pShow->index); - tfree(pShow); + taosTFree(pShow); } static void mnodeReleaseShowObj(SShowObj *pShow, bool forceRemove) { diff --git a/src/mnode/src/mnodeTable.c b/src/mnode/src/mnodeTable.c index 009633b43b..1c39ef3294 100644 --- a/src/mnode/src/mnodeTable.c +++ b/src/mnode/src/mnodeTable.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taosmsg.h" -#include "ttime.h" #include "tutil.h" #include "taoserror.h" #include "taosmsg.h" @@ -90,10 +89,10 @@ static void mnodeProcessAlterTableRsp(SRpcMsg *rpcMsg); static int32_t mnodeFindSuperTableColumnIndex(SSuperTableObj *pStable, char *colName); static void mnodeDestroyChildTable(SChildTableObj *pTable) { - tfree(pTable->info.tableId); - tfree(pTable->schema); - tfree(pTable->sql); - tfree(pTable); + taosTFree(pTable->info.tableId); + taosTFree(pTable->schema); + taosTFree(pTable->sql); + taosTFree(pTable); } static int32_t mnodeChildTableActionDestroy(SSdbOper *pOper) { @@ -411,9 +410,9 @@ static void mnodeDestroySuperTable(SSuperTableObj *pStable) { taosHashCleanup(pStable->vgHash); pStable->vgHash = NULL; } - tfree(pStable->info.tableId); - tfree(pStable->schema); - tfree(pStable); + taosTFree(pStable->info.tableId); + taosTFree(pStable->schema); + taosTFree(pStable); } static int32_t mnodeSuperTableActionDestroy(SSdbOper *pOper) { diff --git a/src/mnode/src/mnodeUser.c b/src/mnode/src/mnodeUser.c index a875cff4a2..765661ac71 100644 --- a/src/mnode/src/mnodeUser.c +++ b/src/mnode/src/mnodeUser.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" #include "trpc.h" -#include "ttime.h" #include "tutil.h" #include "tglobal.h" #include "tgrant.h" @@ -43,7 +42,7 @@ static int32_t mnodeProcessDropUserMsg(SMnodeMsg *pMsg); static int32_t mnodeProcessAuthMsg(SMnodeMsg *pMsg); static int32_t mnodeUserActionDestroy(SSdbOper *pOper) { - tfree(pOper->pObj); + taosTFree(pOper->pObj); return TSDB_CODE_SUCCESS; } @@ -239,7 +238,7 @@ int32_t mnodeCreateUser(SAcctObj *pAcct, char *name, char *pass, void *pMsg) { code = sdbInsertRow(&oper); if (code != TSDB_CODE_SUCCESS && code != TSDB_CODE_MND_ACTION_IN_PROGRESS) { mError("user:%s, failed to create by %s, reason:%s", pUser->user, mnodeGetUserFromMsg(pMsg), tstrerror(code)); - tfree(pUser); + taosTFree(pUser); } else { mLInfo("user:%s, is created by %s", pUser->user, mnodeGetUserFromMsg(pMsg)); } diff --git a/src/mnode/src/mnodeVgroup.c b/src/mnode/src/mnodeVgroup.c index 91aa3fdec2..e46da1d892 100644 --- a/src/mnode/src/mnodeVgroup.c +++ b/src/mnode/src/mnodeVgroup.c @@ -20,7 +20,6 @@ #include "tsocket.h" #include "tidpool.h" #include "tsync.h" -#include "ttime.h" #include "tbalance.h" #include "tglobal.h" #include "tdataformat.h" @@ -70,7 +69,7 @@ static void mnodeDestroyVgroup(SVgObj *pVgroup) { pVgroup->idPool = NULL; } - tfree(pVgroup); + taosTFree(pVgroup); } static int32_t mnodeVgroupActionDestroy(SSdbOper *pOper) { diff --git a/src/os/inc/os.h b/src/os/inc/os.h index 896f3afc7a..70f8487baa 100644 --- a/src/os/inc/os.h +++ b/src/os/inc/os.h @@ -44,7 +44,23 @@ extern "C" { #include "osWindows32.h" #endif -#include "osSpec.h" +#include "osAtomic.h" +#include "osDef.h" +#include "osDir.h" +#include "osFile.h" +#include "osLz4.h" +#include "osMath.h" +#include "osMemory.h" +#include "osPthread.h" +#include "osRand.h" +#include "osSemphone.h" +#include "osSocket.h" +#include "osString.h" +#include "osSysinfo.h" +#include "osTime.h" +#include "osTimer.h" + +void osInit(); #ifdef __cplusplus } diff --git a/src/os/inc/osAtomic.h b/src/os/inc/osAtomic.h new file mode 100644 index 0000000000..803c351400 --- /dev/null +++ b/src/os/inc/osAtomic.h @@ -0,0 +1,113 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_ATOMIC_H +#define TDENGINE_OS_ATOMIC_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef TAOS_OS_FUNC_ATOMIC + #define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) + #define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) + #define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) + #define atomic_load_64(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) + #define atomic_load_ptr(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) + + #define atomic_store_8(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_store_16(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_store_32(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_store_64(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_store_ptr(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_exchange_8(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_exchange_16(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_exchange_32(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_val_compare_exchange_8 __sync_val_compare_and_swap + #define atomic_val_compare_exchange_16 __sync_val_compare_and_swap + #define atomic_val_compare_exchange_32 __sync_val_compare_and_swap + #define atomic_val_compare_exchange_64 __sync_val_compare_and_swap + #define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap + + #define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) + + #define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) + #define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osDef.h b/src/os/inc/osDef.h new file mode 100644 index 0000000000..81c70a58fd --- /dev/null +++ b/src/os/inc/osDef.h @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_DEF_H +#define TDENGINE_OS_DEF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef STDERR_FILENO +#define STDERR_FILENO (2) +#endif + +#define FD_VALID(x) ((x) > STDERR_FILENO) +#define FD_INITIALIZER ((int32_t)-1) + +#define WCHAR wchar_t + +#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b))) +#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2)) + +#ifndef NDEBUG +#define ASSERT(x) assert(x) +#else +#define ASSERT(x) +#endif + +#ifdef UNUSED +#undefine UNUSED +#endif +#define UNUSED(x) ((void)(x)) + +#ifdef UNUSED_FUNC +#undefine UNUSED_FUNC +#endif + +#ifdef UNUSED_PARAM +#undef UNUSED_PARAM +#endif + +#if defined(__GNUC__) +#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused)) +#define UNUSED_FUNC __attribute__((unused)) +#else +#define UNUSED_PARAM(x) x +#define UNUSED_FUNC +#endif + +#ifdef tListLen +#undefine tListLen +#endif +#define tListLen(x) (sizeof(x) / sizeof((x)[0])) + +#if defined(__GNUC__) +#define FORCE_INLINE inline __attribute__((always_inline)) +#else +#define FORCE_INLINE +#endif + +#define DEFAULT_UNICODE_ENCODEC "UCS-4LE" + +#define DEFAULT_COMP(x, y) \ + do { \ + if ((x) == (y)) { \ + return 0; \ + } else { \ + return (x) < (y) ? -1 : 1; \ + } \ + } while (0) + +#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1))) + +// align to 8bytes +#define ALIGN8(n) ALIGN_NUM(n, 8) + +#undef threadlocal +#ifdef _ISOC11_SOURCE + #define threadlocal _Thread_local +#elif defined(__APPLE__) + #define threadlocal +#elif defined(__GNUC__) && !defined(threadlocal) + #define threadlocal __thread +#else + #define threadlocal +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osDir.h b/src/os/inc/osDir.h new file mode 100644 index 0000000000..73e4b216e6 --- /dev/null +++ b/src/os/inc/osDir.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_DIR_H +#define TDENGINE_OS_DIR_H + +#ifdef __cplusplus +extern "C" { +#endif + +// TAOS_OS_FUNC_DIR +void taosRemoveDir(char *rootDir); +int taosMkDir(const char *pathname, mode_t mode); +void taosMvDir(char* destDir, char *srcDir); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osFile.h b/src/os/inc/osFile.h new file mode 100644 index 0000000000..4f4d9e8aed --- /dev/null +++ b/src/os/inc/osFile.h @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_FILE_H +#define TDENGINE_OS_FILE_H + +#ifdef __cplusplus +extern "C" { +#endif + +ssize_t taosTReadImp(int fd, void *buf, size_t count); +ssize_t taosTWriteImp(int fd, void *buf, size_t count); + +// TAOS_OS_FUNC_FILE_TSENDIFLE +ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size); +int taosFSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count); + +#define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) +#define taosFSendFile(outfile, infile, offset, count) taosTSendFileImp(fileno(outfile), fileno(infile), offset, size) + +#ifndef TAOS_RANDOM_FILE_FAIL + #define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count) + #define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count) + #define taosLSeek(fd, offset, whence) lseek(fd, offset, whence) +#else + void taosSetRandomFileFailFactor(int factor); + void taosSetRandomFileFailOutput(const char *path); + ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); + ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); + off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line); + #define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__) + #define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__) + #define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__) +#endif + +// TAOS_OS_FUNC_FILE_GETTMPFILEPATH +void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath); + +int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osLz4.h b/src/os/inc/osLz4.h new file mode 100644 index 0000000000..a944892c48 --- /dev/null +++ b/src/os/inc/osLz4.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_LZ4_H +#define TDENGINE_OS_LZ4_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef TAOS_OS_FUNC_LZ4 + #define BUILDIN_CLZL(val) __builtin_clzl(val) + #define BUILDIN_CTZL(val) __builtin_ctzl(val) + #define BUILDIN_CLZ(val) __builtin_clz(val) + #define BUILDIN_CTZ(val) __builtin_ctz(val) +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osMath.h b/src/os/inc/osMath.h new file mode 100644 index 0000000000..168f6607f0 --- /dev/null +++ b/src/os/inc/osMath.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_MATH_H +#define TDENGINE_OS_MATH_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define POW2(x) ((x) * (x)) + +#ifndef TAOS_OS_FUNC_MATH + #define SWAP(a, b, c) \ + do { \ + typeof(a) __tmp = (a); \ + (a) = (b); \ + (b) = __tmp; \ + } while (0) + + #define MAX(a, b) \ + ({ \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + (__a > __b) ? __a : __b; \ + }) + + #define MIN(a, b) \ + ({ \ + typeof(a) __a = (a); \ + typeof(b) __b = (b); \ + (__a < __b) ? __a : __b; \ + }) +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osMemory.h b/src/os/inc/osMemory.h new file mode 100644 index 0000000000..eb2ff02f77 --- /dev/null +++ b/src/os/inc/osMemory.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_MEMORY_H +#define TDENGINE_OS_MEMORY_H + +#include "osString.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + TAOS_ALLOC_MODE_DEFAULT = 0, + TAOS_ALLOC_MODE_RANDOM_FAIL = 1, + TAOS_ALLOC_MODE_DETECT_LEAK = 2 +} ETaosMemoryAllocMode; + +void taosSetAllocMode(int mode, const char *path, bool autoDump); +void taosDumpMemoryLeak(); + +void * taosTMalloc(size_t size); +void * taosTCalloc(size_t nmemb, size_t size); +void * taosTRealloc(void *ptr, size_t size); +void taosTZfree(void *ptr); +size_t taosTSizeof(void *ptr); +void taosTMemset(void *ptr, int c); + +#define taosTFree(x) \ + do { \ + if (x) { \ + free((void *)(x)); \ + x = 0; \ + } \ + } while (0); + +#ifndef TAOS_MEM_CHECK + #define taosMalloc(size) malloc(size) + #define taosCalloc(num, size) calloc(num, size) + #define taosRealloc(ptr, size) realloc(ptr, size) + #define taosFree(ptr) free(ptr) + #define taosStrdup(str) taosStrdupImp(str) + #define taosStrndup(str, size) taosStrndupImp(str, size) + #define taosGetline(lineptr, n, stream) taosGetlineImp(lineptr, n, stream) +#else + void * taos_malloc(size_t size, const char *file, uint32_t line); + void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line); + void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line); + void taos_free(void *ptr, const char *file, uint32_t line); + char * taos_strdup(const char *str, const char *file, uint32_t line); + char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line); + ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line); + #define taosMalloc(size) taos_malloc(size, __FILE__, __LINE__) + #define taosCalloc(num, size) taos_calloc(num, size, __FILE__, __LINE__) + #define taosRealloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__) + #define taosFree(ptr) taos_free(ptr, __FILE__, __LINE__) + #define taosStrdup(str) taos_strdup(str, __FILE__, __LINE__) + #define taosStrndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) + #define taosGetline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osPthread.h b/src/os/inc/osPthread.h new file mode 100644 index 0000000000..add5c9042d --- /dev/null +++ b/src/os/inc/osPthread.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_PTHREAD_H +#define TDENGINE_OS_PTHREAD_H + +#ifdef __cplusplus +extern "C" { +#endif + +// TAOS_OS_FUNC_PTHREAD +bool taosCheckPthreadValid(pthread_t thread); +int64_t taosGetPthreadId(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osRand.h b/src/os/inc/osRand.h new file mode 100644 index 0000000000..310340d420 --- /dev/null +++ b/src/os/inc/osRand.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_RAND_H +#define TDENGINE_OS_RAND_H + +#ifdef __cplusplus +extern "C" { +#endif + +// TAOS_OS_FUNC_RAND +uint32_t taosRand(void); +void taosRandStr(char* str, int32_t size); +uint32_t trand(void); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osSemphone.h b/src/os/inc/osSemphone.h new file mode 100644 index 0000000000..138a6f97ee --- /dev/null +++ b/src/os/inc/osSemphone.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_SEMPHONE_H +#define TDENGINE_OS_SEMPHONE_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef TAOS_OS_FUNC_SEMPHONE + #define tsem_t sem_t + #define tsem_init sem_init + #define tsem_wait sem_wait + #define tsem_post sem_post + #define tsem_destroy sem_destroy +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osSocket.h b/src/os/inc/osSocket.h new file mode 100644 index 0000000000..f013ae4a3a --- /dev/null +++ b/src/os/inc/osSocket.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_SOCKET_H +#define TDENGINE_OS_SOCKET_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags) +#define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen) +#define taosReadSocket(fd, buf, len) read(fd, buf, len) +#define taosWriteSocket(fd, buf, len) write(fd, buf, len) +#define taosCloseSocket(x) \ + { \ + if (FD_VALID(x)) { \ + close(x); \ + x = FD_INITIALIZER; \ + } \ + } + +#define taosClose(x) taosCloseSocket(x) + +#ifdef TAOS_RANDOM_NETWORK_FAIL + ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags); + ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); + ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count); + ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count); + #undef taosSend + #undef taosSendto + #undef taosReadSocket + #undef taosWriteSocket + #define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags) + #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen) + #define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len) + #define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len) +#endif + +// TAOS_OS_FUNC_SOCKET +int taosSetNonblocking(int sock, int on); +void taosBlockSIGPIPE(); + +// TAOS_OS_FUNC_SOCKET_SETSOCKETOPT +int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osSpec.h b/src/os/inc/osSpec.h deleted file mode 100644 index f0223c3ac5..0000000000 --- a/src/os/inc/osSpec.h +++ /dev/null @@ -1,400 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef TDENGINE_OS_SPEC_H -#define TDENGINE_OS_SPEC_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define tclose(x) taosCloseSocket(x) -#define tfree(x) \ - do { \ - if (x) { \ - free((void *)(x)); \ - x = 0; \ - } \ - } while (0); - -#define tstrncpy(dst, src, size) \ - do { \ - strncpy((dst), (src), (size)); \ - (dst)[(size)-1] = 0; \ - } while (0); - -#ifndef STDERR_FILENO -#define STDERR_FILENO (2) -#endif - -#define FD_VALID(x) ((x) > STDERR_FILENO) -#define FD_INITIALIZER ((int32_t)-1) - -#define WCHAR wchar_t - -#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b))) -#define POINTER_DISTANCE(p1, p2) ((char *)(p1) - (char *)(p2)) - -#ifndef NDEBUG -#define ASSERT(x) assert(x) -#else -#define ASSERT(x) -#endif - -#ifdef UNUSED -#undefine UNUSED -#endif -#define UNUSED(x) ((void)(x)) - -#ifdef UNUSED_FUNC -#undefine UNUSED_FUNC -#endif - -#ifdef UNUSED_PARAM -#undef UNUSED_PARAM -#endif - -#if defined(__GNUC__) -#define UNUSED_PARAM(x) _UNUSED##x __attribute__((unused)) -#define UNUSED_FUNC __attribute__((unused)) -#else -#define UNUSED_PARAM(x) x -#define UNUSED_FUNC -#endif - -#ifdef tListLen -#undefine tListLen -#endif -#define tListLen(x) (sizeof(x) / sizeof((x)[0])) - -#if defined(__GNUC__) -#define FORCE_INLINE inline __attribute__((always_inline)) -#else -#define FORCE_INLINE -#endif - -#define DEFAULT_UNICODE_ENCODEC "UCS-4LE" - -#define DEFAULT_COMP(x, y) \ - do { \ - if ((x) == (y)) { \ - return 0; \ - } else { \ - return (x) < (y) ? -1 : 1; \ - } \ - } while (0) - -#define ALIGN_NUM(n, align) (((n) + ((align)-1)) & (~((align)-1))) - -// align to 8bytes -#define ALIGN8(n) ALIGN_NUM(n, 8) - -#define POW2(x) ((x) * (x)) - -#ifndef TAOS_OS_FUNC_MATH - #define SWAP(a, b, c) \ - do { \ - typeof(a) __tmp = (a); \ - (a) = (b); \ - (b) = __tmp; \ - } while (0) - - #define MAX(a, b) \ - ({ \ - typeof(a) __a = (a); \ - typeof(b) __b = (b); \ - (__a > __b) ? __a : __b; \ - }) - - #define MIN(a, b) \ - ({ \ - typeof(a) __a = (a); \ - typeof(b) __b = (b); \ - (__a < __b) ? __a : __b; \ - }) -#endif - -#ifndef TAOS_OS_DEF_TIME - #define MILLISECOND_PER_SECOND ((int64_t)1000L) -#endif -#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60) -#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60) -#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24) -#define MILLISECOND_PER_WEEK (MILLISECOND_PER_DAY * 7) -#define MILLISECOND_PER_MONTH (MILLISECOND_PER_DAY * 30) -#define MILLISECOND_PER_YEAR (MILLISECOND_PER_DAY * 365) - -#ifndef TAOS_OS_FUNC_SEMPHONE - #define tsem_t sem_t - #define tsem_init sem_init - #define tsem_wait sem_wait - #define tsem_post sem_post - #define tsem_destroy sem_destroy -#endif - -#ifndef TAOS_OS_FUNC_ATOMIC - #define atomic_load_8(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) - #define atomic_load_16(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) - #define atomic_load_32(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) - #define atomic_load_64(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) - #define atomic_load_ptr(ptr) __atomic_load_n((ptr), __ATOMIC_SEQ_CST) - - #define atomic_store_8(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_store_16(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_store_32(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_store_64(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_store_ptr(ptr, val) __atomic_store_n((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_exchange_8(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_exchange_16(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_exchange_32(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_exchange_64(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_exchange_ptr(ptr, val) __atomic_exchange_n((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_val_compare_exchange_8 __sync_val_compare_and_swap - #define atomic_val_compare_exchange_16 __sync_val_compare_and_swap - #define atomic_val_compare_exchange_32 __sync_val_compare_and_swap - #define atomic_val_compare_exchange_64 __sync_val_compare_and_swap - #define atomic_val_compare_exchange_ptr __sync_val_compare_and_swap - - #define atomic_add_fetch_8(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_add_fetch_16(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_add_fetch_32(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_add_fetch_64(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_add_fetch_ptr(ptr, val) __atomic_add_fetch((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_fetch_add_8(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_add_16(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_add_32(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_add_64(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_add_ptr(ptr, val) __atomic_fetch_add((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_sub_fetch_8(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_sub_fetch_16(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_sub_fetch_32(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_sub_fetch_64(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_sub_fetch_ptr(ptr, val) __atomic_sub_fetch((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_fetch_sub_8(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_sub_16(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_sub_32(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_sub_64(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_sub_ptr(ptr, val) __atomic_fetch_sub((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_and_fetch_8(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_and_fetch_16(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_and_fetch_32(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_and_fetch_64(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_and_fetch_ptr(ptr, val) __atomic_and_fetch((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_fetch_and_8(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_and_16(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_and_32(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_and_64(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_and_ptr(ptr, val) __atomic_fetch_and((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_or_fetch_8(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_or_fetch_16(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_or_fetch_32(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_or_fetch_64(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_or_fetch_ptr(ptr, val) __atomic_or_fetch((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_fetch_or_8(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_or_16(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_or_32(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_or_64(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_or_ptr(ptr, val) __atomic_fetch_or((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_xor_fetch_8(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_xor_fetch_16(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_xor_fetch_32(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_xor_fetch_64(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_xor_fetch_ptr(ptr, val) __atomic_xor_fetch((ptr), (val), __ATOMIC_SEQ_CST) - - #define atomic_fetch_xor_8(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_xor_16(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_xor_32(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_xor_64(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) - #define atomic_fetch_xor_ptr(ptr, val) __atomic_fetch_xor((ptr), (val), __ATOMIC_SEQ_CST) -#endif - -ssize_t taosTReadImp(int fd, void *buf, size_t count); -ssize_t taosTWriteImp(int fd, void *buf, size_t count); -// TAOS_OS_FUNC_FILEOP -ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size); -int taosFSendFileImp(FILE* out_file, FILE* in_file, int64_t* offset, int32_t count); -#ifndef TAOS_OS_FUNC_FILEOP - #define taosTSendFile(dfd, sfd, offset, size) taosTSendFileImp(dfd, sfd, offset, size) - #define taosFSendFile(outfile, infile, offset, count) taosTSendFileImp(fileno(outfile), fileno(infile), offset, size) -#endif - -#ifndef TAOS_OS_FUNC_NETWORK - #define taosSend(sockfd, buf, len, flags) send(sockfd, buf, len, flags) - #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, buf, len, flags, dest_addr, addrlen) - #define taosReadSocket(fd, buf, len) read(fd, buf, len) - #define taosWriteSocket(fd, buf, len) write(fd, buf, len) - #define taosCloseSocket(x) \ - { \ - if (FD_VALID(x)) { \ - close(x); \ - x = FD_INITIALIZER; \ - } \ - } -#endif - -#ifndef TAOS_OS_FUNC_LZ4 - #define BUILDIN_CLZL(val) __builtin_clzl(val) - #define BUILDIN_CTZL(val) __builtin_ctzl(val) - #define BUILDIN_CLZ(val) __builtin_clz(val) - #define BUILDIN_CTZ(val) __builtin_ctz(val) -#endif - -#ifndef TAOS_OS_FUNC_WCHAR - #define twcslen wcslen -#endif - -#undef threadlocal -#ifdef _ISOC11_SOURCE - #define threadlocal _Thread_local -#elif defined(__APPLE__) - #define threadlocal -#elif defined(__GNUC__) && !defined(threadlocal) - #define threadlocal __thread -#else - #define threadlocal -#endif - -void osInit(); - -// TAOS_OS_FUNC_PTHREAD -bool taosCheckPthreadValid(pthread_t thread); -int64_t taosGetPthreadId(); - -// TAOS_OS_FUNC_SOCKET -int taosSetNonblocking(int sock, int on); -void taosBlockSIGPIPE(); - -// TAOS_OS_FUNC_SOCKET_SETSOCKETOPT -int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen); - -// TAOS_OS_FUNC_SYSINFO -void taosGetSystemInfo(); -bool taosGetProcIO(float *readKB, float *writeKB); -bool taosGetBandSpeed(float *bandSpeedKb); -bool taosGetDisk(); -bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) ; -bool taosGetProcMemory(float *memoryUsedMB) ; -bool taosGetSysMemory(float *memoryUsedMB); -void taosPrintOsInfo(); -int taosSystem(const char * cmd) ; -void taosKillSystem(); - -// TAOS_OS_FUNC_CORE -void taosSetCoreDump(); - -// TAOS_OS_FUNC_UTIL -int64_t tsosStr2int64(char *str); - -// TAOS_OS_FUNC_TIMER -void taosMsleep(int mseconds); -int taosInitTimer(void (*callback)(int), int ms); -void taosUninitTimer(); - -// TAOS_OS_FUNC_RAND -uint32_t taosRand(void); -void taosRandStr(char* str, int32_t size); -uint32_t trand(void); - -// TAOS_OS_FUNC_FILE -void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath); -int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstPath); - -// USE_LIBICONV -int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); -bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, size_t *len); -int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes); -bool taosValidateEncodec(const char *encodec); -char * taosCharsetReplace(char *charsetstr); - -// TAOS_OS_FUNC_MALLOC -#define TAOS_ALLOC_MODE_DEFAULT 0 -#define TAOS_ALLOC_MODE_RANDOM_FAIL 1 -#define TAOS_ALLOC_MODE_DETECT_LEAK 2 -void taosSetAllocMode(int mode, const char *path, bool autoDump); -void taosDumpMemoryLeak(); -void * tmalloc(size_t size); -void * tcalloc(size_t nmemb, size_t size); -size_t tsizeof(void *ptr); -void tmemset(void *ptr, int c); -void * trealloc(void *ptr, size_t size); -void tzfree(void *ptr); - -// TAOS_OS_FUNC_DIR -void taosRemoveDir(char *rootDir); -int taosMkDir(const char *pathname, mode_t mode); -void taosMvDir(char* destDir, char *srcDir); - -#ifdef TAOS_RANDOM_FILE_FAIL - void taosSetRandomFileFailFactor(int factor); - void taosSetRandomFileFailOutput(const char *path); - ssize_t taosReadFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); - ssize_t taosWriteFileRandomFail(int fd, void *buf, size_t count, const char *file, uint32_t line); - off_t taosLSeekRandomFail(int fd, off_t offset, int whence, const char *file, uint32_t line); - #define taosTRead(fd, buf, count) taosReadFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosTWrite(fd, buf, count) taosWriteFileRandomFail(fd, buf, count, __FILE__, __LINE__) - #define taosLSeek(fd, offset, whence) taosLSeekRandomFail(fd, offset, whence, __FILE__, __LINE__) -#else - #define taosTRead(fd, buf, count) taosTReadImp(fd, buf, count) - #define taosTWrite(fd, buf, count) taosTWriteImp(fd, buf, count) - #define taosLSeek(fd, offset, whence) lseek(fd, offset, whence) -#endif - -#ifdef TAOS_RANDOM_NETWORK_FAIL - ssize_t taosSendRandomFail(int sockfd, const void *buf, size_t len, int flags); - ssize_t taosSendToRandomFail(int sockfd, const void *buf, size_t len, int flags, const struct sockaddr *dest_addr, socklen_t addrlen); - ssize_t taosReadSocketRandomFail(int fd, void *buf, size_t count); - ssize_t taosWriteSocketRandomFail(int fd, const void *buf, size_t count); - #undef taosSend - #undef taosSendto - #undef taosReadSocket - #undef taosWriteSocket - #define taosSend(sockfd, buf, len, flags) taosSendRandomFail(sockfd, buf, len, flags) - #define taosSendto(sockfd, buf, len, flags, dest_addr, addrlen) taosSendToRandomFail(sockfd, buf, len, flags, dest_addr, addrlen) - #define taosReadSocket(fd, buf, len) taosReadSocketRandomFail(fd, buf, len) - #define taosWriteSocket(fd, buf, len) taosWriteSocketRandomFail(fd, buf, len) -#endif - -#ifdef TAOS_MEM_CHECK - void * taos_malloc(size_t size, const char *file, uint32_t line); - void * taos_calloc(size_t num, size_t size, const char *file, uint32_t line); - void * taos_realloc(void *ptr, size_t size, const char *file, uint32_t line); - void taos_free(void *ptr, const char *file, uint32_t line); - char * taos_strdup(const char *str, const char *file, uint32_t line); - char * taos_strndup(const char *str, size_t size, const char *file, uint32_t line); - ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char *file, uint32_t line); - #define malloc(size) taos_malloc(size, __FILE__, __LINE__) - #define calloc(num, size) taos_calloc(num, size, __FILE__, __LINE__) - #define realloc(ptr, size) taos_realloc(ptr, size, __FILE__, __LINE__) - #define free(ptr) taos_free(ptr, __FILE__, __LINE__) - #define strdup(str) taos_strdup(str, __FILE__, __LINE__) - #define strndup(str, size) taos_strndup(str, size, __FILE__, __LINE__) - #define getline(lineptr, n, stream) taos_getline(lineptr, n, stream, __FILE__, __LINE__) -#endif // TAOS_MEM_CHECK - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/os/inc/osString.h b/src/os/inc/osString.h new file mode 100644 index 0000000000..c91aef6d18 --- /dev/null +++ b/src/os/inc/osString.h @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_STRING_H +#define TDENGINE_OS_STRING_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef TAOS_OS_FUNC_STRING_STRDUP + #define taosStrdupImp(str) strdup(str) + #define taosStrndupImp(str, size) strndup(str, size) +#endif + +#ifndef TAOS_OS_FUNC_STRING_GETLINE + #define taosGetlineImp(lineptr, n, stream) getline(lineptr, n , stream) +#endif + +#ifndef TAOS_OS_FUNC_WCHAR + #define twcslen wcslen +#endif + +#define tstrncpy(dst, src, size) \ + do { \ + strncpy((dst), (src), (size)); \ + (dst)[(size)-1] = 0; \ + } while (0); + +// TAOS_OS_FUNC_UTIL +int64_t tsosStr2int64(char *str); + +// USE_LIBICONV +int32_t taosUcs4ToMbs(void *ucs4, int32_t ucs4_max_len, char *mbs); +bool taosMbsToUcs4(char *mbs, size_t mbs_len, char *ucs4, int32_t ucs4_max_len, size_t *len); +int tasoUcs4Compare(void *f1_ucs4, void *f2_ucs4, int bytes); +bool taosValidateEncodec(const char *encodec); +char * taosCharsetReplace(char *charsetstr); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/inc/osSysinfo.h b/src/os/inc/osSysinfo.h new file mode 100644 index 0000000000..ac91e73ab3 --- /dev/null +++ b/src/os/inc/osSysinfo.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_SYSINFO_H +#define TDENGINE_OS_SYSINFO_H + +#ifdef __cplusplus +extern "C" { +#endif + +// TAOS_OS_FUNC_SYSINFO +void taosGetSystemInfo(); +bool taosGetProcIO(float *readKB, float *writeKB); +bool taosGetBandSpeed(float *bandSpeedKb); +bool taosGetDisk(); +bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) ; +bool taosGetProcMemory(float *memoryUsedMB) ; +bool taosGetSysMemory(float *memoryUsedMB); +void taosPrintOsInfo(); +int taosSystem(const char * cmd) ; +void taosKillSystem(); + +// TAOS_OS_FUNC_CORE +void taosSetCoreDump(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/util/inc/ttime.h b/src/os/inc/osTime.h similarity index 79% rename from src/util/inc/ttime.h rename to src/os/inc/osTime.h index 25d1bdb23e..e2d3e081a1 100644 --- a/src/util/inc/ttime.h +++ b/src/os/inc/osTime.h @@ -13,8 +13,8 @@ * along with this program. If not, see . */ -#ifndef TDENGINE_TTIME_H -#define TDENGINE_TTIME_H +#ifndef TDENGINE_OS_TIME_H +#define TDENGINE_OS_TIME_H #ifdef __cplusplus extern "C" { @@ -23,6 +23,16 @@ extern "C" { #include "os.h" #include "taosdef.h" +#ifndef TAOS_OS_DEF_TIME + #define MILLISECOND_PER_SECOND ((int64_t)1000L) +#endif +#define MILLISECOND_PER_MINUTE (MILLISECOND_PER_SECOND * 60) +#define MILLISECOND_PER_HOUR (MILLISECOND_PER_MINUTE * 60) +#define MILLISECOND_PER_DAY (MILLISECOND_PER_HOUR * 24) +#define MILLISECOND_PER_WEEK (MILLISECOND_PER_DAY * 7) +#define MILLISECOND_PER_MONTH (MILLISECOND_PER_DAY * 30) +#define MILLISECOND_PER_YEAR (MILLISECOND_PER_DAY * 365) + //@return timestamp in second int32_t taosGetTimestampSec(); diff --git a/src/os/inc/osTimer.h b/src/os/inc/osTimer.h new file mode 100644 index 0000000000..d6deae2a6d --- /dev/null +++ b/src/os/inc/osTimer.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2019 TAOS Data, Inc. + * + * This program is free software: you can use, redistribute, and/or modify + * it under the terms of the GNU Affero General Public License, version 3 + * or later ("AGPL"), as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +#ifndef TDENGINE_OS_TIMER_H +#define TDENGINE_OS_TIMER_H + +#ifdef __cplusplus +extern "C" { +#endif + +// TAOS_OS_FUNC_TIMER +void taosMsleep(int mseconds); +int taosInitTimer(void (*callback)(int), int ms); +void taosUninitTimer(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/os/src/detail/osDir.c b/src/os/src/detail/osDir.c index b2a91d803a..c8d63f621e 100644 --- a/src/os/src/detail/osDir.c +++ b/src/os/src/detail/osDir.c @@ -17,6 +17,7 @@ #include "os.h" #include "tglobal.h" #include "tulog.h" +#include "osSysinfo.h" #ifndef TAOS_OS_FUNC_DIR diff --git a/src/os/src/detail/osFile.c b/src/os/src/detail/osFile.c index 7b5d5fbfcc..1cd7445658 100644 --- a/src/os/src/detail/osFile.c +++ b/src/os/src/detail/osFile.c @@ -15,28 +15,26 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "ttime.h" - -#ifndef TAOS_OS_FUNC_FILE +#include "osRand.h" +#ifndef TAOS_OS_FUNC_FILE_GETTMPFILEPATH void taosGetTmpfilePath(const char *fileNamePrefix, char *dstPath) { - const char* tdengineTmpFileNamePrefix = "tdengine-"; - - char tmpPath[PATH_MAX]; + const char *tdengineTmpFileNamePrefix = "tdengine-"; + + char tmpPath[PATH_MAX]; char *tmpDir = "/tmp/"; - + strcpy(tmpPath, tmpDir); strcat(tmpPath, tdengineTmpFileNamePrefix); if (strlen(tmpPath) + strlen(fileNamePrefix) + strlen("-%d-%s") < PATH_MAX) { strcat(tmpPath, fileNamePrefix); strcat(tmpPath, "-%d-%s"); } - + char rand[8] = {0}; taosRandStr(rand, tListLen(rand) - 1); snprintf(dstPath, PATH_MAX, tmpPath, getpid(), rand); } - #endif // rename file name @@ -66,3 +64,75 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP return rename(fullPath, *dstPath); } + +ssize_t taosTReadImp(int fd, void *buf, size_t count) { + size_t leftbytes = count; + ssize_t readbytes; + char * tbuf = (char *)buf; + + while (leftbytes > 0) { + readbytes = read(fd, (void *)tbuf, leftbytes); + if (readbytes < 0) { + if (errno == EINTR) { + continue; + } else { + return -1; + } + } else if (readbytes == 0) { + return (ssize_t)(count - leftbytes); + } + + leftbytes -= readbytes; + tbuf += readbytes; + } + + return (ssize_t)count; +} + +ssize_t taosTWriteImp(int fd, void *buf, size_t n) { + size_t nleft = n; + ssize_t nwritten = 0; + char * tbuf = (char *)buf; + + while (nleft > 0) { + nwritten = write(fd, (void *)tbuf, nleft); + if (nwritten < 0) { + if (errno == EINTR) { + continue; + } + return -1; + } + nleft -= nwritten; + tbuf += nwritten; + } + + return n; +} + +#ifndef TAOS_OS_FUNC_FILE_TSENDIFLE +ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) { + size_t leftbytes = size; + ssize_t sentbytes; + + while (leftbytes > 0) { + /* + * TODO : Think to check if file is larger than 1GB + */ + // if (leftbytes > 1000000000) leftbytes = 1000000000; + sentbytes = sendfile(dfd, sfd, offset, leftbytes); + if (sentbytes == -1) { + if (errno == EINTR) { + continue; + } else { + return -1; + } + } else if (sentbytes == 0) { + return (ssize_t)(size - leftbytes); + } + + leftbytes -= sentbytes; + } + + return size; +} +#endif \ No newline at end of file diff --git a/src/os/src/detail/osFileOp.c b/src/os/src/detail/osFileOp.c deleted file mode 100644 index b6928049b6..0000000000 --- a/src/os/src/detail/osFileOp.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" - -ssize_t taosTReadImp(int fd, void *buf, size_t count) { - size_t leftbytes = count; - ssize_t readbytes; - char * tbuf = (char *)buf; - - while (leftbytes > 0) { - readbytes = read(fd, (void *)tbuf, leftbytes); - if (readbytes < 0) { - if (errno == EINTR) { - continue; - } else { - return -1; - } - } else if (readbytes == 0) { - return (ssize_t)(count - leftbytes); - } - - leftbytes -= readbytes; - tbuf += readbytes; - } - - return (ssize_t)count; -} - -ssize_t taosTWriteImp(int fd, void *buf, size_t n) { - size_t nleft = n; - ssize_t nwritten = 0; - char *tbuf = (char *)buf; - - while (nleft > 0) { - nwritten = write(fd, (void *)tbuf, nleft); - if (nwritten < 0) { - if (errno == EINTR) { - continue; - } - return -1; - } - nleft -= nwritten; - tbuf += nwritten; - } - - return n; -} - -#ifndef TAOS_OS_FUNC_FILEOP - -ssize_t taosTSendFileImp(int dfd, int sfd, off_t *offset, size_t size) { - size_t leftbytes = size; - ssize_t sentbytes; - - while (leftbytes > 0) { - /* - * TODO : Think to check if file is larger than 1GB - */ - //if (leftbytes > 1000000000) leftbytes = 1000000000; - sentbytes = sendfile(dfd, sfd, offset, leftbytes); - if (sentbytes == -1) { - if (errno == EINTR) { - continue; - } - else { - return -1; - } - } else if (sentbytes == 0) { - return (ssize_t)(size - leftbytes); - } - - leftbytes -= sentbytes; - } - - return size; -} - -#endif \ No newline at end of file diff --git a/src/os/src/detail/osMalloc.c b/src/os/src/detail/osMalloc.c deleted file mode 100644 index 66377827da..0000000000 --- a/src/os/src/detail/osMalloc.c +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" - -#ifndef TAOS_OS_FUNC_MALLOC - -void *tmalloc(size_t size) { - if (size <= 0) return NULL; - - void *ret = malloc(size + sizeof(size_t)); - if (ret == NULL) return NULL; - - *(size_t *)ret = size; - - return (void *)((char *)ret + sizeof(size_t)); -} - -void *tcalloc(size_t nmemb, size_t size) { - size_t tsize = nmemb * size; - void * ret = tmalloc(tsize); - if (ret == NULL) return NULL; - - tmemset(ret, 0); - return ret; -} - -size_t tsizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; } - -void tmemset(void *ptr, int c) { memset(ptr, c, tsizeof(ptr)); } - -void * trealloc(void *ptr, size_t size) { - if (ptr == NULL) return tmalloc(size); - - if (size <= tsizeof(ptr)) return ptr; - - void * tptr = (void *)((char *)ptr - sizeof(size_t)); - size_t tsize = size + sizeof(size_t); - tptr = realloc(tptr, tsize); - if (tptr == NULL) return NULL; - - *(size_t *)tptr = size; - - return (void *)((char *)tptr + sizeof(size_t)); -} - -void tzfree(void *ptr) { - if (ptr) { - free((void *)((char *)ptr - sizeof(size_t))); - } -} - -#endif \ No newline at end of file diff --git a/src/os/src/detail/osMem.c b/src/os/src/detail/osMemory.c similarity index 87% rename from src/os/src/detail/osMem.c rename to src/os/src/detail/osMemory.c index 93943c6543..3bbe806369 100644 --- a/src/os/src/detail/osMem.c +++ b/src/os/src/detail/osMemory.c @@ -19,7 +19,7 @@ #ifdef TAOS_MEM_CHECK -static int allocMode = TAOS_ALLOC_MODE_DEFAULT; +static ETaosMemoryAllocMode allocMode = TAOS_ALLOC_MODE_DEFAULT; static FILE* fpAllocLog = NULL; //////////////////////////////////////////////////////////////////////////////// @@ -62,7 +62,7 @@ static void* realloc_random(void* ptr, size_t size, const char* file, uint32_t l static char* strdup_random(const char* str, const char* file, uint32_t line) { size_t len = strlen(str); - return random_alloc_fail(len + 1, file, line) ? NULL : strdup(str); + return random_alloc_fail(len + 1, file, line) ? NULL : taosStrdupImp(str); } static char* strndup_random(const char* str, size_t size, const char* file, uint32_t line) { @@ -70,11 +70,11 @@ static char* strndup_random(const char* str, size_t size, const char* file, uint if (len > size) { len = size; } - return random_alloc_fail(len + 1, file, line) ? NULL : strndup(str, len); + return random_alloc_fail(len + 1, file, line) ? NULL : taosStrndupImp(str, len); } static ssize_t getline_random(char **lineptr, size_t *n, FILE *stream, const char* file, uint32_t line) { - return random_alloc_fail(*n, file, line) ? -1 : getline(lineptr, n, stream); + return random_alloc_fail(*n, file, line) ? -1 : taosGetlineImp(lineptr, n, stream); } //////////////////////////////////////////////////////////////////////////////// @@ -242,7 +242,7 @@ static char* strndup_detect_leak(const char* str, size_t size, const char* file, static ssize_t getline_detect_leak(char **lineptr, size_t *n, FILE *stream, const char* file, uint32_t line) { char* buf = NULL; size_t bufSize = 0; - ssize_t size = getline(&buf, &bufSize, stream); + ssize_t size = taosGetlineImp(&buf, &bufSize, stream); if (size != -1) { if (*n < size + 1) { void* p = realloc_detect_leak(*lineptr, size + 1, file, line); @@ -372,7 +372,7 @@ void taos_free(void* ptr, const char* file, uint32_t line) { char* taos_strdup(const char* str, const char* file, uint32_t line) { switch (allocMode) { case TAOS_ALLOC_MODE_DEFAULT: - return strdup(str); + return taosStrdupImp(str); case TAOS_ALLOC_MODE_RANDOM_FAIL: return strdup_random(str, file, line); @@ -380,13 +380,13 @@ char* taos_strdup(const char* str, const char* file, uint32_t line) { case TAOS_ALLOC_MODE_DETECT_LEAK: return strdup_detect_leak(str, file, line); } - return strdup(str); + return taosStrdupImp(str); } char* taos_strndup(const char* str, size_t size, const char* file, uint32_t line) { switch (allocMode) { case TAOS_ALLOC_MODE_DEFAULT: - return strndup(str, size); + return taosStrndupImp(str, size); case TAOS_ALLOC_MODE_RANDOM_FAIL: return strndup_random(str, size, file, line); @@ -394,13 +394,13 @@ char* taos_strndup(const char* str, size_t size, const char* file, uint32_t line case TAOS_ALLOC_MODE_DETECT_LEAK: return strndup_detect_leak(str, size, file, line); } - return strndup(str, size); + return taosStrndupImp(str, size); } ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char* file, uint32_t line) { switch (allocMode) { case TAOS_ALLOC_MODE_DEFAULT: - return getline(lineptr, n, stream); + return taosGetlineImp(lineptr, n, stream); case TAOS_ALLOC_MODE_RANDOM_FAIL: return getline_random(lineptr, n, stream, file, line); @@ -408,7 +408,7 @@ ssize_t taos_getline(char **lineptr, size_t *n, FILE *stream, const char* file, case TAOS_ALLOC_MODE_DETECT_LEAK: return getline_detect_leak(lineptr, n, stream, file, line); } - return getline(lineptr, n, stream); + return taosGetlineImp(lineptr, n, stream); } static void close_alloc_log() { @@ -472,3 +472,48 @@ void taosDumpMemoryLeak() { } #endif // TAOS_MEM_CHECK + +void *taosTMalloc(size_t size) { + if (size <= 0) return NULL; + + void *ret = malloc(size + sizeof(size_t)); + if (ret == NULL) return NULL; + + *(size_t *)ret = size; + + return (void *)((char *)ret + sizeof(size_t)); +} + +void *taosTCalloc(size_t nmemb, size_t size) { + size_t tsize = nmemb * size; + void * ret = taosTMalloc(tsize); + if (ret == NULL) return NULL; + + taosTMemset(ret, 0); + return ret; +} + +size_t taosTSizeof(void *ptr) { return (ptr) ? (*(size_t *)((char *)ptr - sizeof(size_t))) : 0; } + +void taosTMemset(void *ptr, int c) { memset(ptr, c, taosTSizeof(ptr)); } + +void * taosTRealloc(void *ptr, size_t size) { + if (ptr == NULL) return taosTMalloc(size); + + if (size <= taosTSizeof(ptr)) return ptr; + + void * tptr = (void *)((char *)ptr - sizeof(size_t)); + size_t tsize = size + sizeof(size_t); + tptr = realloc(tptr, tsize); + if (tptr == NULL) return NULL; + + *(size_t *)tptr = size; + + return (void *)((char *)tptr + sizeof(size_t)); +} + +void taosTZfree(void *ptr) { + if (ptr) { + free((void *)((char *)ptr - sizeof(size_t))); + } +} \ No newline at end of file diff --git a/src/os/src/detail/osSysinfo.c b/src/os/src/detail/osSysinfo.c index 89813d9864..f753566134 100644 --- a/src/os/src/detail/osSysinfo.c +++ b/src/os/src/detail/osSysinfo.c @@ -63,7 +63,7 @@ bool taosGetProcMemory(float *memoryUsedMB) { size_t len; char * line = NULL; while (!feof(fp)) { - tfree(line); + taosTFree(line); len = 0; getline(&line, &len, fp); if (line == NULL) { @@ -85,7 +85,7 @@ bool taosGetProcMemory(float *memoryUsedMB) { sscanf(line, "%s %" PRId64, tmp, &memKB); *memoryUsedMB = (float)((double)memKB / 1024); - tfree(line); + taosTFree(line); fclose(fp); return true; } @@ -109,7 +109,7 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { char cpu[10] = {0}; sscanf(line, "%s %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, cpu, &cpuInfo->user, &cpuInfo->nice, &cpuInfo->system, &cpuInfo->idle); - tfree(line); + taosTFree(line); fclose(fp); return true; } @@ -138,7 +138,7 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { } } - tfree(line); + taosTFree(line); fclose(fp); return true; } @@ -378,7 +378,7 @@ static bool taosGetCardInfo(int64_t *bytes) { *bytes += (rbytes + tbytes); } - tfree(line); + taosTFree(line); fclose(fp); return true; @@ -433,7 +433,7 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { int readIndex = 0; while (!feof(fp)) { - tfree(line); + taosTFree(line); len = 0; getline(&line, &len, fp); if (line == NULL) { @@ -451,7 +451,7 @@ static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { if (readIndex >= 2) break; } - tfree(line); + taosTFree(line); fclose(fp); if (readIndex < 2) { diff --git a/src/util/src/ttime.c b/src/os/src/detail/osTime.c similarity index 99% rename from src/util/src/ttime.c rename to src/os/src/detail/osTime.c index 018c0d640b..28c13165fa 100644 --- a/src/util/src/ttime.c +++ b/src/os/src/detail/osTime.c @@ -22,7 +22,6 @@ #include #include "taosdef.h" -#include "ttime.h" #include "tutil.h" /* * mktime64 - Converts date to seconds. diff --git a/src/plugins/http/src/httpContext.c b/src/plugins/http/src/httpContext.c index f46d3fb427..ad72ac8823 100644 --- a/src/plugins/http/src/httpContext.c +++ b/src/plugins/http/src/httpContext.c @@ -18,7 +18,6 @@ #include "taosmsg.h" #include "tsocket.h" #include "tutil.h" -#include "ttime.h" #include "ttimer.h" #include "tglobal.h" #include "tcache.h" @@ -39,7 +38,7 @@ static void httpRemoveContextFromEpoll(HttpContext *pContext) { static void httpDestroyContext(void *data) { HttpContext *pContext = *(HttpContext **)data; - if (pContext->fd > 0) tclose(pContext->fd); + if (pContext->fd > 0) taosClose(pContext->fd); HttpThread *pThread = pContext->pThread; httpRemoveContextFromEpoll(pContext); @@ -55,7 +54,7 @@ static void httpDestroyContext(void *data) { httpFreeJsonBuf(pContext); httpFreeMultiCmds(pContext); - tfree(pContext); + taosTFree(pContext); } bool httpInitContexts() { diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index ec3d2c0d44..5c910a3311 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -18,7 +18,6 @@ #include "taosmsg.h" #include "tsocket.h" #include "tutil.h" -#include "ttime.h" #include "ttimer.h" #include "tglobal.h" #include "httpInt.h" @@ -203,7 +202,7 @@ static void httpProcessHttpData(void *param) { if (pContext == NULL) { httpError("context:%p, is already released, close connect", events[i].data.ptr); //epoll_ctl(pThread->pollFd, EPOLL_CTL_DEL, events[i].data.fd, NULL); - //tclose(events[i].data.fd); + //taosClose(events[i].data.fd); continue; } @@ -331,7 +330,7 @@ static void *httpAcceptHttpConnection(void *arg) { if (epoll_ctl(pThread->pollFd, EPOLL_CTL_ADD, connFd, &event) < 0) { httpError("context:%p, fd:%d, ip:%s, thread:%s, failed to add http fd for epoll, error:%s", pContext, connFd, pContext->ipstr, pThread->label, strerror(errno)); - tclose(pContext->fd); + taosClose(pContext->fd); httpReleaseContext(pContext); continue; } diff --git a/src/plugins/http/src/httpSession.c b/src/plugins/http/src/httpSession.c index 256b0c9549..fce85df45e 100644 --- a/src/plugins/http/src/httpSession.c +++ b/src/plugins/http/src/httpSession.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taos.h" -#include "ttime.h" #include "tglobal.h" #include "tcache.h" #include "httpInt.h" diff --git a/src/plugins/http/src/httpSystem.c b/src/plugins/http/src/httpSystem.c index 3a0998f2e8..38bd8624b2 100644 --- a/src/plugins/http/src/httpSystem.c +++ b/src/plugins/http/src/httpSystem.c @@ -99,7 +99,7 @@ void httpCleanUpSystem() { httpCleanupContexts(); httpCleanUpSessions(); pthread_mutex_destroy(&tsHttpServer.serverMutex); - tfree(tsHttpServer.pThreads); + taosTFree(tsHttpServer.pThreads); tsHttpServer.pThreads = NULL; tsHttpServer.status = HTTP_SERVER_CLOSED; diff --git a/src/plugins/monitor/src/monitorMain.c b/src/plugins/monitor/src/monitorMain.c index 0cc28bb82c..b31fc368af 100644 --- a/src/plugins/monitor/src/monitorMain.c +++ b/src/plugins/monitor/src/monitorMain.c @@ -18,7 +18,6 @@ #include "taosdef.h" #include "taoserror.h" #include "tlog.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" #include "tsystem.h" diff --git a/src/query/src/qExecutor.c b/src/query/src/qExecutor.c index 6efc8a827e..1277e7bfbb 100644 --- a/src/query/src/qExecutor.c +++ b/src/query/src/qExecutor.c @@ -28,7 +28,6 @@ #include "queryLog.h" #include "tlosertree.h" #include "tscompression.h" -#include "ttime.h" /** * check if the primary column is load by default, otherwise, the program will @@ -930,7 +929,7 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * STimeWindow win = getActiveTimeWindow(pWindowResInfo, ts, pQuery); if (setWindowOutputBufByKey(pRuntimeEnv, pWindowResInfo, pDataBlockInfo->tid, &win, masterScan, &hasTimeWindow) != TSDB_CODE_SUCCESS) { - tfree(sasArray); + taosTFree(sasArray); return; } @@ -993,10 +992,10 @@ static void blockwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis * continue; } - tfree(sasArray[i].data); + taosTFree(sasArray[i].data); } - tfree(sasArray); + taosTFree(sasArray); } static int32_t setGroupResultOutputBuf(SQueryRuntimeEnv *pRuntimeEnv, char *pData, int16_t type, int16_t bytes) { @@ -1301,7 +1300,7 @@ static void rowwiseApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SDataStatis *pS continue; } - tfree(sasArray[i].data); + taosTFree(sasArray[i].data); } free(sasArray); @@ -1468,7 +1467,7 @@ static void setCtxTagColumnInfo(SQueryRuntimeEnv *pRuntimeEnv, SQLFunctionCtx *p p->tagInfo.numOfTagCols = num; p->tagInfo.tagsLen = tagLen; } else { - tfree(pTagCtx); + taosTFree(pTagCtx); } } } @@ -1576,8 +1575,8 @@ static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, int16_t order return TSDB_CODE_SUCCESS; _clean: - tfree(pRuntimeEnv->resultInfo); - tfree(pRuntimeEnv->pCtx); + taosTFree(pRuntimeEnv->resultInfo); + taosTFree(pRuntimeEnv->pCtx); return TSDB_CODE_QRY_OUT_OF_MEMORY; } @@ -1602,11 +1601,11 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { } tVariantDestroy(&pCtx->tag); - tfree(pCtx->tagInfo.pTagCtxList); + taosTFree(pCtx->tagInfo.pTagCtxList); } - tfree(pRuntimeEnv->resultInfo); - tfree(pRuntimeEnv->pCtx); + taosTFree(pRuntimeEnv->resultInfo); + taosTFree(pRuntimeEnv->pCtx); } pRuntimeEnv->pFillInfo = taosDestoryFillInfo(pRuntimeEnv->pFillInfo); @@ -2739,8 +2738,8 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { STableQueryInfo **pTableList = malloc(POINTER_BYTES * size); if (pTableList == NULL || posList == NULL) { - tfree(posList); - tfree(pTableList); + taosTFree(posList); + taosTFree(pTableList); qError("QInfo:%p failed alloc memory", pQInfo); longjmp(pRuntimeEnv->env, TSDB_CODE_QRY_OUT_OF_MEMORY); @@ -2759,8 +2758,8 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { } if (numOfTables == 0) { - tfree(posList); - tfree(pTableList); + taosTFree(posList); + taosTFree(pTableList); assert(pQInfo->numOfGroupResultPages == 0); return 0; @@ -2843,10 +2842,10 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { if (flushFromResultBuf(pQInfo) != TSDB_CODE_SUCCESS) { qError("QInfo:%p failed to flush data into temp file, abort query", pQInfo); - tfree(pTree); - tfree(pTableList); - tfree(posList); - tfree(pResultInfo); + taosTFree(pTree); + taosTFree(pTableList); + taosTFree(posList); + taosTFree(pResultInfo); return -1; } @@ -2860,14 +2859,14 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray *pGroup) { qDebug("QInfo:%p result merge completed for group:%d, elapsed time:%" PRId64 " ms", pQInfo, pQInfo->groupIndex, endt - startt); - tfree(pTableList); - tfree(posList); - tfree(pTree); + taosTFree(pTableList); + taosTFree(posList); + taosTFree(pTree); pQInfo->offset = 0; - tfree(pResultInfo); - tfree(buf); + taosTFree(pResultInfo); + taosTFree(buf); return pQInfo->numOfGroupResultPages; } @@ -5454,13 +5453,13 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, return TSDB_CODE_SUCCESS; _cleanup: - tfree(*pExpr); + taosTFree(*pExpr); taosArrayDestroy(*pTableIdList); *pTableIdList = NULL; - tfree(*tbnameCond); - tfree(*groupbyCols); - tfree(*tagCols); - tfree(*tagCond); + taosTFree(*tbnameCond); + taosTFree(*groupbyCols); + taosTFree(*tagCols); + taosTFree(*tagCond); return code; } @@ -5511,7 +5510,7 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * code = buildAirthmeticExprFromMsg(&pExprs[i], pQueryMsg); if (code != TSDB_CODE_SUCCESS) { - tfree(pExprs); + taosTFree(pExprs); return code; } @@ -5540,7 +5539,7 @@ static int32_t createQFunctionExprFromMsg(SQueryTableMsg *pQueryMsg, SExprInfo * int32_t param = pExprs[i].base.arg[0].argValue.i64; if (getResultDataInfo(type, bytes, pExprs[i].base.functionId, param, &pExprs[i].type, &pExprs[i].bytes, &pExprs[i].interBytes, 0, isSuperTable) != TSDB_CODE_SUCCESS) { - tfree(pExprs); + taosTFree(pExprs); return TSDB_CODE_QRY_INVALID_MSG; } @@ -5905,14 +5904,14 @@ _cleanup_query: taosArrayDestroy(pGroupbyExpr->columnInfo); free(pGroupbyExpr); } - tfree(pTagCols); + taosTFree(pTagCols); for (int32_t i = 0; i < numOfOutput; ++i) { SExprInfo* pExprInfo = &pExprs[i]; if (pExprInfo->pExpr != NULL) { tExprTreeDestroy(&pExprInfo->pExpr, NULL); } } - tfree(pExprs); + taosTFree(pExprs); _cleanup: freeQInfo(pQInfo); @@ -5997,7 +5996,7 @@ static void freeQInfo(SQInfo *pQInfo) { qDebug("QInfo:%p start to free QInfo", pQInfo); for (int32_t col = 0; col < pQuery->numOfOutput; ++col) { - tfree(pQuery->sdata[col]); + taosTFree(pQuery->sdata[col]); } teardownQueryRuntimeEnv(&pQInfo->runtimeEnv); @@ -6005,7 +6004,7 @@ static void freeQInfo(SQInfo *pQInfo) { for (int32_t i = 0; i < pQuery->numOfFilterCols; ++i) { SSingleColumnFilterInfo *pColFilter = &pQuery->pFilterInfo[i]; if (pColFilter->numOfFilters > 0) { - tfree(pColFilter->pFilters); + taosTFree(pColFilter->pFilters); } } @@ -6018,11 +6017,11 @@ static void freeQInfo(SQInfo *pQInfo) { } } - tfree(pQuery->pSelectExpr); + taosTFree(pQuery->pSelectExpr); } if (pQuery->fillVal != NULL) { - tfree(pQuery->fillVal); + taosTFree(pQuery->fillVal); } // todo refactor, extract method to destroytableDataInfo @@ -6041,7 +6040,7 @@ static void freeQInfo(SQInfo *pQInfo) { } } - tfree(pQInfo->pBuf); + taosTFree(pQInfo->pBuf); taosArrayDestroy(pQInfo->tableqinfoGroupInfo.pGroupList); taosHashCleanup(pQInfo->tableqinfoGroupInfo.map); tsdbDestroyTableGroup(&pQInfo->tableGroupInfo); @@ -6049,27 +6048,27 @@ static void freeQInfo(SQInfo *pQInfo) { if (pQuery->pGroupbyExpr != NULL) { taosArrayDestroy(pQuery->pGroupbyExpr->columnInfo); - tfree(pQuery->pGroupbyExpr); + taosTFree(pQuery->pGroupbyExpr); } - tfree(pQuery->tagColList); - tfree(pQuery->pFilterInfo); + taosTFree(pQuery->tagColList); + taosTFree(pQuery->pFilterInfo); if (pQuery->colList != NULL) { for (int32_t i = 0; i < pQuery->numOfCols; i++) { SColumnInfo* column = pQuery->colList + i; freeColumnFilterInfo(column->filters, column->numOfFilters); } - tfree(pQuery->colList); + taosTFree(pQuery->colList); } - tfree(pQuery->sdata); - tfree(pQuery); + taosTFree(pQuery->sdata); + taosTFree(pQuery); pQInfo->signature = 0; qDebug("QInfo:%p QInfo is freed", pQInfo); - tfree(pQInfo); + taosTFree(pQInfo); } static size_t getResultSize(SQInfo *pQInfo, int64_t *numOfRows) { @@ -6692,7 +6691,7 @@ void qCleanupQueryMgmt(void* pQMgmt) { taosCacheCleanup(pqinfoPool); pthread_mutex_destroy(&pQueryMgmt->lock); - tfree(pQueryMgmt); + taosTFree(pQueryMgmt); qDebug("vgId:%d queryMgmt cleanup completed", vgId); } diff --git a/src/query/src/qExtbuffer.c b/src/query/src/qExtbuffer.c index 6f1c51a19e..21b5361acb 100644 --- a/src/query/src/qExtbuffer.c +++ b/src/query/src/qExtbuffer.c @@ -65,7 +65,7 @@ void* destoryExtMemBuffer(tExtMemBuffer *pMemBuffer) { // release flush out info link SExtFileInfo *pFileMeta = &pMemBuffer->fileMeta; if (pFileMeta->flushoutData.nAllocSize != 0 && pFileMeta->flushoutData.pFlushoutInfo != NULL) { - tfree(pFileMeta->flushoutData.pFlushoutInfo); + taosTFree(pFileMeta->flushoutData.pFlushoutInfo); } // release all in-memory buffer pages @@ -73,7 +73,7 @@ void* destoryExtMemBuffer(tExtMemBuffer *pMemBuffer) { while (pFilePages != NULL) { tFilePagesItem *pTmp = pFilePages; pFilePages = pFilePages->pNext; - tfree(pTmp); + taosTFree(pTmp); } // close temp file @@ -88,8 +88,8 @@ void* destoryExtMemBuffer(tExtMemBuffer *pMemBuffer) { destroyColumnModel(pMemBuffer->pColumnModel); - tfree(pMemBuffer->path); - tfree(pMemBuffer); + taosTFree(pMemBuffer->path); + taosTFree(pMemBuffer); return NULL; } @@ -276,7 +276,7 @@ int32_t tExtMemBufferFlush(tExtMemBuffer *pMemBuffer) { tFilePagesItem *ptmp = first; first = first->pNext; - tfree(ptmp); // release all data in memory buffer + taosTFree(ptmp); // release all data in memory buffer } fflush(pMemBuffer->file); // flush to disk @@ -301,7 +301,7 @@ void tExtMemBufferClear(tExtMemBuffer *pMemBuffer) { while (first != NULL) { tFilePagesItem *ptmp = first; first = first->pNext; - tfree(ptmp); + taosTFree(ptmp); } pMemBuffer->fileMeta.numOfElemsInFile = 0; @@ -788,7 +788,7 @@ void destroyColumnModel(SColumnModel *pModel) { return; } - tfree(pModel); + taosTFree(pModel); } static void printBinaryData(char *data, int32_t len) { @@ -1073,5 +1073,5 @@ void tOrderDescDestroy(tOrderDescriptor *pDesc) { } destroyColumnModel(pDesc->pColumnModel); - tfree(pDesc); + taosTFree(pDesc); } diff --git a/src/query/src/qFill.c b/src/query/src/qFill.c index 9dec2598bc..e65d793dc9 100644 --- a/src/query/src/qFill.c +++ b/src/query/src/qFill.c @@ -74,18 +74,18 @@ void* taosDestoryFillInfo(SFillInfo* pFillInfo) { return NULL; } - tfree(pFillInfo->prevValues); - tfree(pFillInfo->nextValues); - tfree(pFillInfo->pTags); + taosTFree(pFillInfo->prevValues); + taosTFree(pFillInfo->nextValues); + taosTFree(pFillInfo->pTags); for(int32_t i = 0; i < pFillInfo->numOfCols; ++i) { - tfree(pFillInfo->pData[i]); + taosTFree(pFillInfo->pData[i]); } - tfree(pFillInfo->pData); - tfree(pFillInfo->pFillCol); + taosTFree(pFillInfo->pData); + taosTFree(pFillInfo->pFillCol); - tfree(pFillInfo); + taosTFree(pFillInfo); return NULL; } @@ -454,7 +454,7 @@ int32_t generateDataBlockImpl(SFillInfo* pFillInfo, tFilePage** data, int32_t nu pFillInfo->numOfRows = 0; /* the raw data block is exhausted, next value does not exists */ - tfree(*nextValues); + taosTFree(*nextValues); } pFillInfo->numOfTotal += pFillInfo->numOfCurrent; diff --git a/src/query/src/qParserImpl.c b/src/query/src/qParserImpl.c index 7cf995193b..f556e2dd53 100644 --- a/src/query/src/qParserImpl.c +++ b/src/query/src/qParserImpl.c @@ -22,7 +22,6 @@ #include "tglobal.h" #include "tstoken.h" #include "tstrbuild.h" -#include "ttime.h" #include "ttokendef.h" #include "tutil.h" @@ -609,7 +608,7 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) { doDestroyQuerySql(pQuerySql); } - tfree(pClause->pClause); + taosTFree(pClause->pClause); } SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SSQLToken *pStableName, @@ -679,12 +678,12 @@ void SQLInfoDestroy(SSqlInfo *pInfo) { tFieldListDestroy(pCreateTableInfo->colInfo.pTagColumns); tVariantListDestroy(pCreateTableInfo->usingInfo.pTagVals); - tfree(pInfo->pCreateTableInfo); + taosTFree(pInfo->pCreateTableInfo); } else if (pInfo->type == TSDB_SQL_ALTER_TABLE) { tVariantListDestroy(pInfo->pAlterInfo->varList); tFieldListDestroy(pInfo->pAlterInfo->pAddColumns); - tfree(pInfo->pAlterInfo); + taosTFree(pInfo->pAlterInfo); } else { if (pInfo->pDCLInfo != NULL && pInfo->pDCLInfo->nAlloc > 0) { free(pInfo->pDCLInfo->a); @@ -694,7 +693,7 @@ void SQLInfoDestroy(SSqlInfo *pInfo) { tVariantListDestroy(pInfo->pDCLInfo->dbOpt.keep); } - tfree(pInfo->pDCLInfo); + taosTFree(pInfo->pDCLInfo); } } diff --git a/src/query/src/qPercentile.c b/src/query/src/qPercentile.c index 85e45e46b3..7f5fa08cf1 100644 --- a/src/query/src/qPercentile.c +++ b/src/query/src/qPercentile.c @@ -70,7 +70,7 @@ static tFilePage *loadIntoBucketFromDisk(tMemBucket *pMemBucket, int32_t segIdx, printf("id: %d count: %" PRIu64 "\n", j, buffer->num); } } - tfree(pPage); + taosTFree(pPage); assert(buffer->num == pMemBuffer->fileMeta.numOfElemsInFile); } @@ -284,7 +284,7 @@ tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nE }; default: { uError("MemBucket:%p,not support data type %d,failed", pBucket, pBucket->dataType); - tfree(pBucket); + taosTFree(pBucket); return NULL; } } @@ -292,14 +292,14 @@ tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nE int32_t numOfCols = pDesc->pColumnModel->numOfCols; if (numOfCols != 1) { uError("MemBucket:%p,only consecutive data is allowed,invalid numOfCols:%d", pBucket, numOfCols); - tfree(pBucket); + taosTFree(pBucket); return NULL; } SSchema* pSchema = getColumnModelSchema(pDesc->pColumnModel, 0); if (pSchema->type != dataType) { uError("MemBucket:%p,data type is not consistent,%d in schema, %d in param", pBucket, pSchema->type, dataType); - tfree(pBucket); + taosTFree(pBucket); return NULL; } @@ -329,7 +329,7 @@ void tMemBucketDestroy(tMemBucket *pBucket) { if (pBucket->pSegs) { for (int32_t i = 0; i < pBucket->numOfSegs; ++i) { tMemBucketSegment *pSeg = &(pBucket->pSegs[i]); - tfree(pSeg->pBoundingEntries); + taosTFree(pSeg->pBoundingEntries); if (pSeg->pBuffer == NULL || pSeg->numOfSlots == 0) { continue; @@ -340,12 +340,12 @@ void tMemBucketDestroy(tMemBucket *pBucket) { pSeg->pBuffer[j] = destoryExtMemBuffer(pSeg->pBuffer[j]); } } - tfree(pSeg->pBuffer); + taosTFree(pSeg->pBuffer); } } - tfree(pBucket->pSegs); - tfree(pBucket); + taosTFree(pBucket->pSegs); + taosTFree(pBucket); } /* @@ -789,7 +789,7 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) } } double val = (1 - fraction) * td + fraction * nd; - tfree(buffer); + taosTFree(buffer); return val; } else { // incur a second round bucket split @@ -891,8 +891,8 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) if (unlink(pMemBuffer->path) != 0) { uError("MemBucket:%p, remove tmp file %s failed", pMemBucket, pMemBuffer->path); } - tfree(pMemBuffer); - tfree(pPage); + taosTFree(pMemBuffer); + taosTFree(pPage); return getPercentileImpl(pMemBucket, count - num, fraction); } diff --git a/src/query/src/qResultbuf.c b/src/query/src/qResultbuf.c index 363b590d80..b73a7cc887 100644 --- a/src/query/src/qResultbuf.c +++ b/src/query/src/qResultbuf.c @@ -258,7 +258,7 @@ static char* evicOneDataPage(SDiskbasedResultBuf* pResultBuf) { assert(d->pn == pn); d->pn = NULL; - tfree(pn); + taosTFree(pn); bufPage = flushPageToDisk(pResultBuf, d); } @@ -406,7 +406,7 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) { } unlink(pResultBuf->path); - tfree(pResultBuf->path); + taosTFree(pResultBuf->path); SHashMutableIterator* iter = taosHashCreateIter(pResultBuf->groupSet); while(taosHashIterNext(iter)) { @@ -414,8 +414,8 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) { size_t n = taosArrayGetSize(*p); for(int32_t i = 0; i < n; ++i) { SPageInfo* pi = taosArrayGetP(*p, i); - tfree(pi->pData); - tfree(pi); + taosTFree(pi->pData); + taosTFree(pi); } taosArrayDestroy(*p); @@ -428,8 +428,8 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) { taosHashCleanup(pResultBuf->groupSet); taosHashCleanup(pResultBuf->all); - tfree(pResultBuf->assistBuf); - tfree(pResultBuf); + taosTFree(pResultBuf->assistBuf); + taosTFree(pResultBuf); } SPageInfo* getLastPageInfo(SIDList pList) { diff --git a/src/query/src/qTsbuf.c b/src/query/src/qTsbuf.c index 8ab45cc1a9..fe39fe4e4a 100644 --- a/src/query/src/qTsbuf.c +++ b/src/query/src/qTsbuf.c @@ -142,11 +142,11 @@ void* tsBufDestroy(STSBuf* pTSBuf) { return NULL; } - tfree(pTSBuf->assistBuf); - tfree(pTSBuf->tsData.rawBuf); + taosTFree(pTSBuf->assistBuf); + taosTFree(pTSBuf->tsData.rawBuf); - tfree(pTSBuf->pData); - tfree(pTSBuf->block.payload); + taosTFree(pTSBuf->pData); + taosTFree(pTSBuf->block.payload); fclose(pTSBuf->f); diff --git a/src/query/src/qUtil.c b/src/query/src/qUtil.c index c9143b3a53..7175262270 100644 --- a/src/query/src/qUtil.c +++ b/src/query/src/qUtil.c @@ -14,11 +14,8 @@ */ #include "os.h" - #include "hash.h" #include "taosmsg.h" -#include "ttime.h" - #include "qExecutor.h" #include "qUtil.h" @@ -89,7 +86,7 @@ void cleanupTimeWindowInfo(SWindowResInfo *pWindowResInfo) { } taosHashCleanup(pWindowResInfo->hashList); - tfree(pWindowResInfo->pResult); + taosTFree(pWindowResInfo->pResult); } void resetTimeWindowInfo(SQueryRuntimeEnv *pRuntimeEnv, SWindowResInfo *pWindowResInfo) { diff --git a/src/query/tests/tsBufTest.cpp b/src/query/tests/tsBufTest.cpp index e9827518e1..28b1d9cefe 100644 --- a/src/query/tests/tsBufTest.cpp +++ b/src/query/tests/tsBufTest.cpp @@ -1,13 +1,12 @@ +#include "os.h" #include #include #include #include "taos.h" #include "tsdb.h" - #include "qTsbuf.h" #include "tstoken.h" -#include "ttime.h" #include "tutil.h" namespace { diff --git a/src/query/tests/unitTest.cpp b/src/query/tests/unitTest.cpp index 60c73b4fad..b59e0783a2 100644 --- a/src/query/tests/unitTest.cpp +++ b/src/query/tests/unitTest.cpp @@ -1,3 +1,4 @@ +#include "os.h" #include #include #include @@ -6,7 +7,6 @@ #include "tsdb.h" #include "../../client/inc/tscUtil.h" -#include "ttime.h" #include "tutil.h" #include "tvariant.h" #include "ttokendef.h" diff --git a/src/rpc/src/rpcCache.c b/src/rpc/src/rpcCache.c index 6f89969305..3f76b202c9 100644 --- a/src/rpc/src/rpcCache.c +++ b/src/rpc/src/rpcCache.c @@ -16,7 +16,6 @@ #include "os.h" #include "tglobal.h" #include "tmempool.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" #include "rpcLog.h" @@ -102,9 +101,9 @@ void rpcCloseConnCache(void *handle) { if (pCache->connHashMemPool) taosMemPoolCleanUp(pCache->connHashMemPool); - tfree(pCache->connHashList); - tfree(pCache->count); - tfree(pCache->lockedBy); + taosTFree(pCache->connHashList); + taosTFree(pCache->count); + taosTFree(pCache->lockedBy); pthread_mutex_unlock(&pCache->mutex); diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index 7425558535..be609c4ee8 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -17,7 +17,6 @@ #include "tidpool.h" #include "tmd5.h" #include "tmempool.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" #include "lz4.h" @@ -1563,10 +1562,10 @@ static void rpcDecRef(SRpcInfo *pRpc) taosTmrCleanUp(pRpc->tmrCtrl); taosIdPoolCleanUp(pRpc->idPool); - tfree(pRpc->connList); + taosTFree(pRpc->connList); pthread_mutex_destroy(&pRpc->mutex); tDebug("%s rpc resources are released", pRpc->label); - tfree(pRpc); + taosTFree(pRpc); } } diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 5cb45a6d26..7fa05af9b0 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -213,8 +213,8 @@ void taosCleanUpTcpServer(void *handle) { tDebug("%s TCP server is cleaned up", pServerObj->label); - tfree(pServerObj->pThreadObj); - tfree(pServerObj); + taosTFree(pServerObj->pThreadObj); + taosTFree(pServerObj); } static void *taosAcceptTcpConnection(void *arg) { @@ -324,7 +324,7 @@ void taosCleanUpTcpClient(void *chandle) { taosStopTcpThread(pThreadObj); tDebug ("%s TCP client is cleaned up", pThreadObj->label); - tfree(pThreadObj); + taosTFree(pThreadObj); } void *taosOpenTcpClientConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port) { @@ -518,7 +518,7 @@ static SFdObj *taosMallocFdObj(SThreadObj *pThreadObj, int fd) { event.events = EPOLLIN | EPOLLRDHUP; event.data.ptr = pFdObj; if (epoll_ctl(pThreadObj->pollFd, EPOLL_CTL_ADD, fd, &event) < 0) { - tfree(pFdObj); + taosTFree(pFdObj); terrno = TAOS_SYSTEM_ERROR(errno); return NULL; } @@ -571,5 +571,5 @@ static void taosFreeFdObj(SFdObj *pFdObj) { tDebug("%s %p TCP connection is closed, FD:%p numOfFds:%d", pThreadObj->label, pFdObj->thandle, pFdObj, pThreadObj->numOfFds); - tfree(pFdObj); + taosTFree(pFdObj); } diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index bdaae4c597..f75375e2fe 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -145,7 +145,7 @@ void taosStopUdpConnection(void *handle) { for (int i = 0; i < pSet->threads; ++i) { pConn = pSet->udpConn + i; if (pConn->thread) pthread_join(pConn->thread, NULL); - tfree(pConn->buffer); + taosTFree(pConn->buffer); // tTrace("%s UDP thread is closed, index:%d", pConn->label, i); } @@ -164,7 +164,7 @@ void taosCleanUpUdpConnection(void *handle) { } tDebug("%s UDP is cleaned up", pSet->label); - tfree(pSet); + taosTFree(pSet); } void *taosOpenUdpConnection(void *shandle, void *thandle, uint32_t ip, uint16_t port) { diff --git a/src/sync/src/syncMain.c b/src/sync/src/syncMain.c index 5195e70364..2cc026484b 100644 --- a/src/sync/src/syncMain.c +++ b/src/sync/src/syncMain.c @@ -20,7 +20,6 @@ #include "tlog.h" #include "tutil.h" #include "ttimer.h" -#include "ttime.h" #include "tsocket.h" #include "tglobal.h" #include "taoserror.h" @@ -438,9 +437,9 @@ static void syncDecNodeRef(SSyncNode *pNode) { if (atomic_sub_fetch_8(&pNode->refCount, 1) == 0) { pthread_mutex_destroy(&pNode->mutex); - tfree(pNode->pRecv); - tfree(pNode->pSyncFwds); - tfree(pNode); + taosTFree(pNode->pRecv); + taosTFree(pNode->pSyncFwds); + taosTFree(pNode); if (atomic_sub_fetch_32(&tsNodeNum, 1) == 0) { if (tsTcpPool) taosCloseTcpThreadPool(tsTcpPool); @@ -466,8 +465,8 @@ int syncDecPeerRef(SSyncPeer *pPeer) syncDecNodeRef(pPeer->pSyncNode); sDebug("%s, resource is freed", pPeer->id); - tfree(pPeer->watchFd); - tfree(pPeer); + taosTFree(pPeer->watchFd); + taosTFree(pPeer); return 0; } @@ -477,7 +476,7 @@ int syncDecPeerRef(SSyncPeer *pPeer) static void syncClosePeerConn(SSyncPeer *pPeer) { taosTmrStopA(&pPeer->timer); - tclose(pPeer->syncFd); + taosClose(pPeer->syncFd); if (pPeer->peerFd >=0) { pPeer->peerFd = -1; taosFreeTcpConn(pPeer->pConn); @@ -756,7 +755,7 @@ static void syncProcessSyncRequest(char *msg, SSyncPeer *pPeer) if (nodeRole != TAOS_SYNC_ROLE_MASTER) { sError("%s, I am not master anymore", pPeer->id); - tclose(pPeer->syncFd); + taosClose(pPeer->syncFd); return; } @@ -1053,7 +1052,7 @@ static void syncCreateRestoreDataThread(SSyncPeer *pPeer) if (ret < 0) { sError("%s, failed to create sync thread", pPeer->id); - tclose(pPeer->syncFd); + taosClose(pPeer->syncFd); syncDecPeerRef(pPeer); } else { sInfo("%s, sync connection is up", pPeer->id); diff --git a/src/sync/src/syncRestore.c b/src/sync/src/syncRestore.c index 07d99b916e..505882b209 100644 --- a/src/sync/src/syncRestore.c +++ b/src/sync/src/syncRestore.c @@ -225,10 +225,10 @@ int syncSaveIntoBuffer(SSyncPeer *pPeer, SWalHead *pHead) static void syncCloseRecvBuffer(SSyncNode *pNode) { if (pNode->pRecv) { - tfree(pNode->pRecv->buffer); + taosTFree(pNode->pRecv->buffer); } - tfree(pNode->pRecv); + taosTFree(pNode->pRecv); } static int syncOpenRecvBuffer(SSyncNode *pNode) @@ -319,7 +319,7 @@ void *syncRestoreData(void *param) (*pNode->notifyRole)(pNode->ahandle, nodeRole); nodeSStatus = TAOS_SYNC_STATUS_INIT; - tclose(pPeer->syncFd) + taosClose(pPeer->syncFd) syncCloseRecvBuffer(pNode); __sync_fetch_and_sub(&tsSyncNum, 1); syncDecPeerRef(pPeer); diff --git a/src/sync/src/syncRetrieve.c b/src/sync/src/syncRetrieve.c index 8aa7d101e7..f881b680f5 100644 --- a/src/sync/src/syncRetrieve.c +++ b/src/sync/src/syncRetrieve.c @@ -190,7 +190,7 @@ static int syncReadOneWalRecord(int sfd, SWalHead *pHead, uint32_t *pEvent) static int syncMonitorLastWal(SSyncPeer *pPeer, char *name) { pPeer->watchNum = 0; - tclose(pPeer->notifyFd); + taosClose(pPeer->notifyFd); pPeer->notifyFd = inotify_init1(IN_NONBLOCK); if (pPeer->notifyFd < 0) { sError("%s, failed to init inotify(%s)", pPeer->id, strerror(errno)); @@ -271,7 +271,7 @@ static int syncRetrieveLastWal(SSyncPeer *pPeer, char *name, uint64_t fversion, } free(pHead); - tclose(sfd); + taosClose(sfd); if (code == 0) return bytes; return -1; @@ -352,7 +352,7 @@ static int syncProcessLastWal(SSyncPeer *pPeer, char *wname, uint32_t index) sDebug("%s, last wal is closed, try new one", pPeer->id); } - tclose(pPeer->notifyFd); + taosClose(pPeer->notifyFd); return code; } @@ -486,8 +486,8 @@ void *syncRetrieveData(void *param) } pPeer->fileChanged = 0; - tclose(pPeer->notifyFd); - tclose(pPeer->syncFd); + taosClose(pPeer->notifyFd); + taosClose(pPeer->syncFd); syncDecPeerRef(pPeer); return NULL; diff --git a/src/sync/src/taosTcpPool.c b/src/sync/src/taosTcpPool.c index fa94caeed7..88c2c53be4 100644 --- a/src/sync/src/taosTcpPool.c +++ b/src/sync/src/taosTcpPool.c @@ -102,7 +102,7 @@ void taosCloseTcpThreadPool(void *param) if (pThread) taosStopPoolThread(pThread); } - tfree(pPool->pThread); + taosTFree(pPool->pThread); free(pPool); uDebug("%p TCP pool is closed", pPool); } @@ -166,7 +166,7 @@ static void taosProcessBrokenLink(SConnObj *pConn) { pThread->numOfFds--; epoll_ctl(pThread->pollFd, EPOLL_CTL_DEL, pConn->fd, NULL); uDebug("%p fd:%d is removed from epoll thread, num:%d", pThread, pConn->fd, pThread->numOfFds); - tclose(pConn->fd); + taosClose(pConn->fd); free(pConn); } @@ -255,7 +255,7 @@ static void *taosAcceptPeerTcpConnection(void *argv) { (*pInfo->processIncomingConn)(connFd, clientAddr.sin_addr.s_addr); } - tclose(pPool->acceptFd); + taosClose(pPool->acceptFd); return NULL; } @@ -320,6 +320,6 @@ static void taosStopPoolThread(SThreadObj* pThread) { } pthread_join(thread, NULL); - tclose(fd); + taosClose(fd); } diff --git a/src/sync/src/tarbitrator.c b/src/sync/src/tarbitrator.c index c308c2a454..3c6db88a9c 100644 --- a/src/sync/src/tarbitrator.c +++ b/src/sync/src/tarbitrator.c @@ -19,7 +19,6 @@ #include "tlog.h" #include "tutil.h" #include "ttimer.h" -#include "ttime.h" #include "tsocket.h" #include "tglobal.h" #include "taoserror.h" @@ -133,7 +132,7 @@ static void arbProcessIncommingConnection(int connFd, uint32_t sourceIp) snprintf(pNode->id, sizeof(pNode->id), "vgId:%d peer:%s:%d", firstPkt.sourceId, firstPkt.fqdn, firstPkt.port); if (firstPkt.syncHead.vgId) { sDebug("%s, vgId in head is not zero, close the connection", pNode->id); - tfree(pNode); + taosTFree(pNode); taosCloseSocket(connFd); return; } @@ -149,7 +148,7 @@ static void arbProcessBrokenLink(void *param) { SNodeConn *pNode = param; sDebug("%s, TCP link is broken(%s), close connection", pNode->id, strerror(errno)); - tfree(pNode); + taosTFree(pNode); } static int arbProcessPeerMsg(void *param, void *buffer) diff --git a/src/tsdb/src/tsdbBuffer.c b/src/tsdb/src/tsdbBuffer.c index dcc9d4ca1b..2e097c6ff7 100644 --- a/src/tsdb/src/tsdbBuffer.c +++ b/src/tsdb/src/tsdbBuffer.c @@ -157,4 +157,4 @@ _err: return NULL; } -static void tsdbFreeBufBlock(STsdbBufBlock *pBufBlock) { tfree(pBufBlock); } \ No newline at end of file +static void tsdbFreeBufBlock(STsdbBufBlock *pBufBlock) { taosTFree(pBufBlock); } \ No newline at end of file diff --git a/src/tsdb/src/tsdbFile.c b/src/tsdb/src/tsdbFile.c index 6e7b39830e..299802f9b4 100644 --- a/src/tsdb/src/tsdbFile.c +++ b/src/tsdb/src/tsdbFile.c @@ -19,7 +19,6 @@ #include "tchecksum.h" #include "tsdbMain.h" #include "tutil.h" -#include "ttime.h" #ifdef TSDB_IDX const char *tsdbFileSuffix[] = {".idx", ".head", ".data", ".last", "", ".i", ".h", ".l"}; @@ -65,7 +64,7 @@ _err: void tsdbFreeFileH(STsdbFileH *pFileH) { if (pFileH) { pthread_rwlock_destroy(&pFileH->fhlock); - tfree(pFileH->pFGroup); + taosTFree(pFileH->pFGroup); free(pFileH); } } @@ -116,14 +115,14 @@ int tsdbOpenFileH(STsdbRepo *pRepo) { qsort((void *)(pFileH->pFGroup), pFileH->nFGroups, sizeof(SFileGroup), compFGroup); } - tfree(tDataDir); + taosTFree(tDataDir); closedir(dir); return 0; _err: for (int type = 0; type < TSDB_FILE_TYPE_MAX; type++) tsdbDestroyFile(&fileGroup.files[type]); - tfree(tDataDir); + taosTFree(tDataDir); if (dir != NULL) closedir(dir); tsdbCloseFileH(pRepo); return -1; diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index b04b0be9ba..e23228cc0e 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -23,7 +23,6 @@ #include "tchecksum.h" #include "tscompression.h" #include "tsdb.h" -#include "ttime.h" #include "tulog.h" @@ -214,7 +213,7 @@ uint32_t tsdbGetFileInfo(TSDB_REPO_T *repo, char *name, uint32_t *index, uint32_ char *sdup = strdup(pRepo->rootDir); char *prefix = dirname(sdup); int prefixLen = strlen(prefix); - tfree(sdup); + taosTFree(sdup); if (name[0] == 0) { // get the file from index or after, but not larger than eindex int fid = (*index) / TSDB_FILE_TYPE_MAX; @@ -262,14 +261,14 @@ uint32_t tsdbGetFileInfo(TSDB_REPO_T *repo, char *name, uint32_t *index, uint32_ } if (stat(fname, &fState) < 0) { - tfree(fname); + taosTFree(fname); return 0; } *size = fState.st_size; // magic = *size; - tfree(fname); + taosTFree(fname); return magic; } @@ -565,7 +564,7 @@ static int32_t tsdbSaveConfig(char *rootDir, STsdbCfg *pCfg) { return 0; _err: - tfree(fname); + taosTFree(fname); if (fd >= 0) close(fd); return -1; } @@ -602,13 +601,13 @@ static int tsdbLoadConfig(char *rootDir, STsdbCfg *pCfg) { tsdbDecodeCfg(buf, pCfg); - tfree(fname); + taosTFree(fname); close(fd); return 0; _err: - tfree(fname); + taosTFree(fname); if (fd >= 0) close(fd); return -1; } @@ -681,7 +680,7 @@ static void tsdbFreeRepo(STsdbRepo *pRepo) { tsdbFreeMeta(pRepo->tsdbMeta); // tsdbFreeMemTable(pRepo->mem); // tsdbFreeMemTable(pRepo->imem); - tfree(pRepo->rootDir); + taosTFree(pRepo->rootDir); pthread_mutex_destroy(&pRepo->mutex); free(pRepo); } diff --git a/src/tsdb/src/tsdbMemTable.c b/src/tsdb/src/tsdbMemTable.c index 506f3c11c1..803b07515c 100644 --- a/src/tsdb/src/tsdbMemTable.c +++ b/src/tsdb/src/tsdbMemTable.c @@ -398,7 +398,7 @@ static void tsdbFreeMemTable(SMemTable* pMemTable) { tdListFree(pMemTable->bufBlockList); tdListFree(pMemTable->actList); - tfree(pMemTable->tData); + taosTFree(pMemTable->tData); free(pMemTable); } } @@ -647,7 +647,7 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe goto _err; } - tfree(dataDir); + taosTFree(dataDir); tsdbCloseHelperFile(pHelper, 0); pthread_rwlock_wrlock(&(pFileH->fhlock)); @@ -662,7 +662,7 @@ static int tsdbCommitToFile(STsdbRepo *pRepo, int fid, SCommitIter *iters, SRWHe return 0; _err: - tfree(dataDir); + taosTFree(dataDir); tsdbCloseHelperFile(pHelper, 1); return -1; } @@ -737,7 +737,7 @@ static int tsdbAdjustMemMaxTables(SMemTable *pMemTable, int maxTables) { pMemTable->tData = pTableData; taosWUnLockLatch(&(pMemTable->latch)); - tfree(tData); + taosTFree(tData); return 0; } \ No newline at end of file diff --git a/src/tsdb/src/tsdbMeta.c b/src/tsdb/src/tsdbMeta.c index d389a96fee..8db6a4a32a 100644 --- a/src/tsdb/src/tsdbMeta.c +++ b/src/tsdb/src/tsdbMeta.c @@ -185,7 +185,7 @@ int tsdbDropTable(TSDB_REPO_T *repo, STableId tableId) { return 0; _err: - tfree(tbname); + taosTFree(tbname); return -1; } @@ -453,7 +453,7 @@ void tsdbFreeMeta(STsdbMeta *pMeta) { if (pMeta) { taosHashCleanup(pMeta->uidMap); tdListFree(pMeta->superList); - tfree(pMeta->tables); + taosTFree(pMeta->tables); pthread_rwlock_destroy(&pMeta->rwLock); free(pMeta); } @@ -477,11 +477,11 @@ int tsdbOpenMeta(STsdbRepo *pRepo) { } tsdbDebug("vgId:%d open TSDB meta succeed", REPO_ID(pRepo)); - tfree(fname); + taosTFree(fname); return 0; _err: - tfree(fname); + taosTFree(fname); return -1; } @@ -745,7 +745,7 @@ static void tsdbFreeTable(STable *pTable) { if (pTable->name != NULL) tsdbTrace("table %s tid %d uid %" PRIu64 " is freed", TABLE_CHAR_NAME(pTable), TABLE_TID(pTable), TABLE_UID(pTable)); - tfree(TABLE_NAME(pTable)); + taosTFree(TABLE_NAME(pTable)); if (TABLE_TYPE(pTable) != TSDB_CHILD_TABLE) { for (int i = 0; i < TSDB_MAX_TABLE_SCHEMAS; i++) { tdFreeSchema(pTable->schema[i]); @@ -759,7 +759,7 @@ static void tsdbFreeTable(STable *pTable) { kvRowFree(pTable->tagVal); tSkipListDestroy(pTable->pIndex); - tfree(pTable->sql); + taosTFree(pTable->sql); free(pTable); } } @@ -1065,9 +1065,9 @@ void tsdbClearTableCfg(STableCfg *config) { if (config->schema) tdFreeSchema(config->schema); if (config->tagSchema) tdFreeSchema(config->tagSchema); if (config->tagValues) kvRowFree(config->tagValues); - tfree(config->name); - tfree(config->sname); - tfree(config->sql); + taosTFree(config->name); + taosTFree(config->sname); + taosTFree(config->sql); free(config); } } @@ -1291,7 +1291,7 @@ static int tsdbAdjustMetaTables(STsdbRepo *pRepo, int tid) { STable **tTables = pMeta->tables; pMeta->tables = tables; - tfree(tTables); + taosTFree(tTables); tsdbDebug("vgId:%d tsdb meta maxTables is adjusted as %d", REPO_ID(pRepo), maxTables); return 0; diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index 8d3908666e..9a96ec62e2 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -72,8 +72,8 @@ int tsdbInitWriteHelper(SRWHelper *pHelper, STsdbRepo *pRepo) { void tsdbDestroyHelper(SRWHelper *pHelper) { if (pHelper) { - tzfree(pHelper->pBuffer); - tzfree(pHelper->compBuffer); + taosTZfree(pHelper->pBuffer); + taosTZfree(pHelper->compBuffer); tsdbDestroyHelperFile(pHelper); tsdbDestroyHelperTable(pHelper); tsdbDestroyHelperBlock(pHelper); @@ -444,8 +444,8 @@ int tsdbWriteCompInfo(SRWHelper *pHelper) { pFile = helperNewIdxF(pHelper); #endif - if (tsizeof(pHelper->pWIdx) < pFile->info.len + sizeof(SCompIdx) + 12) { - pHelper->pWIdx = trealloc(pHelper->pWIdx, tsizeof(pHelper->pWIdx) == 0 ? 1024 : tsizeof(pHelper->pWIdx) * 2); + if (taosTSizeof(pHelper->pWIdx) < pFile->info.len + sizeof(SCompIdx) + 12) { + pHelper->pWIdx = taosTRealloc(pHelper->pWIdx, taosTSizeof(pHelper->pWIdx) == 0 ? 1024 : taosTSizeof(pHelper->pWIdx) * 2); if (pHelper->pWIdx == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; @@ -470,8 +470,8 @@ int tsdbWriteCompIdx(SRWHelper *pHelper) { #endif pFile->info.len += sizeof(TSCKSUM); - if (tsizeof(pHelper->pWIdx) < pFile->info.len) { - pHelper->pWIdx = trealloc(pHelper->pWIdx, pFile->info.len); + if (taosTSizeof(pHelper->pWIdx) < pFile->info.len) { + pHelper->pWIdx = taosTRealloc(pHelper->pWIdx, pFile->info.len); if (pHelper->pWIdx == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; @@ -512,7 +512,7 @@ int tsdbLoadCompIdx(SRWHelper *pHelper, void *target) { if (!helperHasState(pHelper, TSDB_HELPER_IDX_LOAD)) { // If not load from file, just load it in object if (pFile->info.len > 0) { - if ((pHelper->pBuffer = trealloc(pHelper->pBuffer, pFile->info.len)) == NULL) { + if ((pHelper->pBuffer = taosTRealloc(pHelper->pBuffer, pFile->info.len)) == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; } @@ -541,11 +541,11 @@ int tsdbLoadCompIdx(SRWHelper *pHelper, void *target) { pHelper->idxH.numOfIdx = 0; void *ptr = pHelper->pBuffer; while (POINTER_DISTANCE(ptr, pHelper->pBuffer) < (pFile->info.len - sizeof(TSCKSUM))) { - size_t tlen = tsizeof(pHelper->idxH.pIdxArray); + size_t tlen = taosTSizeof(pHelper->idxH.pIdxArray); pHelper->idxH.numOfIdx++; if (tlen < pHelper->idxH.numOfIdx * sizeof(SCompIdx)) { - pHelper->idxH.pIdxArray = (SCompIdx *)trealloc(pHelper->idxH.pIdxArray, (tlen == 0) ? 1024 : tlen * 2); + pHelper->idxH.pIdxArray = (SCompIdx *)taosTRealloc(pHelper->idxH.pIdxArray, (tlen == 0) ? 1024 : tlen * 2); if (pHelper->idxH.pIdxArray == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; @@ -593,7 +593,7 @@ int tsdbLoadCompInfo(SRWHelper *pHelper, void *target) { return -1; } - pHelper->pCompInfo = trealloc((void *)pHelper->pCompInfo, pIdx->len); + pHelper->pCompInfo = taosTRealloc((void *)pHelper->pCompInfo, pIdx->len); if (taosTRead(fd, (void *)(pHelper->pCompInfo), pIdx->len) < pIdx->len) { tsdbError("vgId:%d failed to read %d bytes from file %s since %s", REPO_ID(pHelper->pRepo), pIdx->len, helperHeadF(pHelper)->fname, strerror(errno)); @@ -629,7 +629,7 @@ int tsdbLoadCompData(SRWHelper *pHelper, SCompBlock *pCompBlock, void *target) { } size_t tsize = TSDB_GET_COMPCOL_LEN(pCompBlock->numOfCols); - pHelper->pCompData = trealloc((void *)pHelper->pCompData, tsize); + pHelper->pCompData = taosTRealloc((void *)pHelper->pCompData, tsize); if (pHelper->pCompData == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; @@ -807,7 +807,7 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa if (pCfg->compression) { if (pCfg->compression == TWO_STAGE_COMP) { - pHelper->compBuffer = trealloc(pHelper->compBuffer, tlen + COMP_OVERFLOW_BYTES); + pHelper->compBuffer = taosTRealloc(pHelper->compBuffer, tlen + COMP_OVERFLOW_BYTES); if (pHelper->compBuffer == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; @@ -815,8 +815,8 @@ static int tsdbWriteBlockToFile(SRWHelper *pHelper, SFile *pFile, SDataCols *pDa } flen = (*(tDataTypeDesc[pDataCol->type].compFunc))((char *)pDataCol->pData, tlen, rowsToWrite, tptr, - tsizeof(pHelper->pBuffer) - lsize, pCfg->compression, - pHelper->compBuffer, tsizeof(pHelper->compBuffer)); + taosTSizeof(pHelper->pBuffer) - lsize, pCfg->compression, + pHelper->compBuffer, taosTSizeof(pHelper->compBuffer)); } else { flen = tlen; memcpy(tptr, pDataCol->pData, flen); @@ -895,9 +895,9 @@ static int compareKeyBlock(const void *arg1, const void *arg2) { } static int tsdbAdjustInfoSizeIfNeeded(SRWHelper *pHelper, size_t esize) { - if (tsizeof((void *)pHelper->pCompInfo) <= esize) { + if (taosTSizeof((void *)pHelper->pCompInfo) <= esize) { size_t tsize = esize + sizeof(SCompBlock) * 16; - pHelper->pCompInfo = (SCompInfo *)trealloc(pHelper->pCompInfo, tsize); + pHelper->pCompInfo = (SCompInfo *)taosTRealloc(pHelper->pCompInfo, tsize); if (pHelper->pCompInfo == NULL) return -1; } @@ -923,8 +923,8 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int // Memmove if needed int tsize = pIdx->len - (sizeof(SCompInfo) + sizeof(SCompBlock) * blkIdx); if (tsize > 0) { - ASSERT(sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1) < tsizeof(pHelper->pCompInfo)); - ASSERT(sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1) + tsize <= tsizeof(pHelper->pCompInfo)); + ASSERT(sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1) < taosTSizeof(pHelper->pCompInfo)); + ASSERT(sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1) + tsize <= taosTSizeof(pHelper->pCompInfo)); memmove(POINTER_SHIFT(pHelper->pCompInfo, sizeof(SCompInfo) + sizeof(SCompBlock) * (blkIdx + 1)), POINTER_SHIFT(pHelper->pCompInfo, sizeof(SCompInfo) + sizeof(SCompBlock) * blkIdx), tsize); } @@ -932,7 +932,7 @@ static int tsdbInsertSuperBlock(SRWHelper *pHelper, SCompBlock *pCompBlock, int pIdx->numOfBlocks++; pIdx->len += sizeof(SCompBlock); - ASSERT(pIdx->len <= tsizeof(pHelper->pCompInfo)); + ASSERT(pIdx->len <= taosTSizeof(pHelper->pCompInfo)); pIdx->maxKey = blockAtIdx(pHelper, pIdx->numOfBlocks - 1)->keyLast; pIdx->hasLast = blockAtIdx(pHelper, pIdx->numOfBlocks - 1)->last; @@ -1094,8 +1094,8 @@ static int tsdbInitHelperFile(SRWHelper *pHelper) { static void tsdbDestroyHelperFile(SRWHelper *pHelper) { tsdbCloseHelperFile(pHelper, false); tsdbResetHelperFileImpl(pHelper); - tzfree(pHelper->idxH.pIdxArray); - tzfree(pHelper->pWIdx); + taosTZfree(pHelper->idxH.pIdxArray); + taosTZfree(pHelper->pWIdx); } // ---------- Operations on Helper Table part @@ -1112,7 +1112,7 @@ static void tsdbResetHelperTable(SRWHelper *pHelper) { static void tsdbInitHelperTable(SRWHelper *pHelper) { tsdbResetHelperTableImpl(pHelper); } -static void tsdbDestroyHelperTable(SRWHelper *pHelper) { tzfree((void *)pHelper->pCompInfo); } +static void tsdbDestroyHelperTable(SRWHelper *pHelper) { taosTZfree((void *)pHelper->pCompInfo); } // ---------- Operations on Helper Block part static void tsdbResetHelperBlockImpl(SRWHelper *pHelper) { @@ -1142,7 +1142,7 @@ static int tsdbInitHelperBlock(SRWHelper *pHelper) { } static void tsdbDestroyHelperBlock(SRWHelper *pHelper) { - tzfree(pHelper->pCompData); + taosTZfree(pHelper->pCompData); tdFreeDataCols(pHelper->pDataCols[0]); tdFreeDataCols(pHelper->pDataCols[1]); } @@ -1167,7 +1167,7 @@ static int tsdbInitHelper(SRWHelper *pHelper, STsdbRepo *pRepo, tsdb_rw_helper_t // TODO: pMeta->maxRowBytes and pMeta->maxCols may change here causing invalid write pHelper->pBuffer = - tmalloc(sizeof(SCompData) + (sizeof(SCompCol) + sizeof(TSCKSUM) + COMP_OVERFLOW_BYTES) * pMeta->maxCols + + taosTMalloc(sizeof(SCompData) + (sizeof(SCompCol) + sizeof(TSCKSUM) + COMP_OVERFLOW_BYTES) * pMeta->maxCols + pMeta->maxRowBytes * pCfg->maxRowsPerFileBlock + sizeof(TSCKSUM)); if (pHelper->pBuffer == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; @@ -1212,13 +1212,13 @@ static int tsdbLoadColData(SRWHelper *pHelper, SFile *pFile, SCompBlock *pCompBl SDataCol *pDataCol) { ASSERT(pDataCol->colId == pCompCol->colId); int tsize = pDataCol->bytes * pCompBlock->numOfRows + COMP_OVERFLOW_BYTES; - pHelper->pBuffer = trealloc(pHelper->pBuffer, pCompCol->len); + pHelper->pBuffer = taosTRealloc(pHelper->pBuffer, pCompCol->len); if (pHelper->pBuffer == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; } - pHelper->compBuffer = trealloc(pHelper->compBuffer, tsize); + pHelper->compBuffer = taosTRealloc(pHelper->compBuffer, tsize); if (pHelper->compBuffer == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; return -1; @@ -1240,7 +1240,7 @@ static int tsdbLoadColData(SRWHelper *pHelper, SFile *pFile, SCompBlock *pCompBl if (tsdbCheckAndDecodeColumnData(pDataCol, pHelper->pBuffer, pCompCol->len, pCompBlock->algorithm, pCompBlock->numOfRows, pHelper->pRepo->config.maxRowsPerFileBlock, - pHelper->compBuffer, tsizeof(pHelper->compBuffer)) < 0) { + pHelper->compBuffer, taosTSizeof(pHelper->compBuffer)) < 0) { tsdbError("vgId:%d file %s is broken at column %d offset %" PRId64, REPO_ID(pHelper->pRepo), pFile->fname, pCompCol->colId, offset); return -1; @@ -1331,7 +1331,7 @@ static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDa SFile *pFile = (pCompBlock->last) ? helperLastF(pHelper) : helperDataF(pHelper); - pHelper->pBuffer = trealloc(pHelper->pBuffer, pCompBlock->len); + pHelper->pBuffer = taosTRealloc(pHelper->pBuffer, pCompBlock->len); if (pHelper->pBuffer == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; @@ -1395,7 +1395,7 @@ static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDa if (pDataCol->type == TSDB_DATA_TYPE_BINARY || pDataCol->type == TSDB_DATA_TYPE_NCHAR) { zsize += (sizeof(VarDataLenT) * pCompBlock->numOfRows); } - pHelper->compBuffer = trealloc(pHelper->compBuffer, zsize); + pHelper->compBuffer = taosTRealloc(pHelper->compBuffer, zsize); if (pHelper->compBuffer == NULL) { terrno = TSDB_CODE_TDB_OUT_OF_MEMORY; goto _err; @@ -1403,7 +1403,7 @@ static int tsdbLoadBlockDataImpl(SRWHelper *pHelper, SCompBlock *pCompBlock, SDa } if (tsdbCheckAndDecodeColumnData(pDataCol, (char *)pCompData + tsize + toffset, tlen, pCompBlock->algorithm, pCompBlock->numOfRows, pDataCols->maxPoints, pHelper->compBuffer, - tsizeof(pHelper->compBuffer)) < 0) { + taosTSizeof(pHelper->compBuffer)) < 0) { tsdbError("vgId:%d file %s is broken at column %d block offset %" PRId64 " column offset %d", REPO_ID(pHelper->pRepo), pFile->fname, tcolId, (int64_t)pCompBlock->offset, toffset); goto _err; diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 0e3a657fde..c3aeed519c 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -17,7 +17,6 @@ #include "tulog.h" #include "talgo.h" #include "tutil.h" -#include "ttime.h" #include "tcompare.h" #include "exception.h" @@ -1291,15 +1290,15 @@ int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order) { } static void cleanBlockOrderSupporter(SBlockOrderSupporter* pSupporter, int32_t numOfTables) { - tfree(pSupporter->numOfBlocksPerTable); - tfree(pSupporter->blockIndexArray); + taosTFree(pSupporter->numOfBlocksPerTable); + taosTFree(pSupporter->blockIndexArray); for (int32_t i = 0; i < numOfTables; ++i) { STableBlockInfo* pBlockInfo = pSupporter->pDataBlockInfo[i]; - tfree(pBlockInfo); + taosTFree(pBlockInfo); } - tfree(pSupporter->pDataBlockInfo); + taosTFree(pSupporter->pDataBlockInfo); } static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* param) { @@ -1770,11 +1769,11 @@ void changeQueryHandleForLastrowQuery(TsdbQueryHandleT pqHandle) { tSkipListDestroyIter(pTableCheckInfo->iter); if (pTableCheckInfo->pDataCols != NULL) { - tfree(pTableCheckInfo->pDataCols->buf); + taosTFree(pTableCheckInfo->pDataCols->buf); } - tfree(pTableCheckInfo->pDataCols); - tfree(pTableCheckInfo->pCompInfo); + taosTFree(pTableCheckInfo->pDataCols); + taosTFree(pTableCheckInfo->pCompInfo); } STableCheckInfo info = *(STableCheckInfo*) taosArrayGet(pQueryHandle->pTableCheckInfo, index); @@ -2033,7 +2032,7 @@ static void destroyHelper(void* param) { tQueryInfo* pInfo = (tQueryInfo*)param; if (pInfo->optr != TSDB_RELATION_IN) { - tfree(pInfo->q); + taosTFree(pInfo->q); } // tVariantDestroy(&(pInfo->q)); @@ -2185,7 +2184,7 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC taosqsort(pTableList->pData, size, POINTER_BYTES, pSupp, tableGroupComparFn); createTableGroupImpl(pTableGroup, pTableList, size, pSupp, tableGroupComparFn); - tfree(pSupp); + taosTFree(pSupp); } return pTableGroup; @@ -2431,11 +2430,11 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) { destroyTableMemIterator(pTableCheckInfo); if (pTableCheckInfo->pDataCols != NULL) { - tfree(pTableCheckInfo->pDataCols->buf); + taosTFree(pTableCheckInfo->pDataCols->buf); } - tfree(pTableCheckInfo->pDataCols); - tfree(pTableCheckInfo->pCompInfo); + taosTFree(pTableCheckInfo->pDataCols); + taosTFree(pTableCheckInfo->pCompInfo); } taosArrayDestroy(pQueryHandle->pTableCheckInfo); } @@ -2444,14 +2443,14 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) { size_t cols = taosArrayGetSize(pQueryHandle->pColumns); for (int32_t i = 0; i < cols; ++i) { SColumnInfoData* pColInfo = taosArrayGet(pQueryHandle->pColumns, i); - tfree(pColInfo->pData); + taosTFree(pColInfo->pData); } taosArrayDestroy(pQueryHandle->pColumns); } taosArrayDestroy(pQueryHandle->defaultLoadColumn); - tfree(pQueryHandle->pDataBlockInfo); - tfree(pQueryHandle->statis); + taosTFree(pQueryHandle->pDataBlockInfo); + taosTFree(pQueryHandle->statis); // todo check error tsdbUnTakeMemSnapShot(pQueryHandle->pTsdb, pQueryHandle->mem, pQueryHandle->imem); @@ -2462,7 +2461,7 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) { tsdbDebug("%p :io-cost summary: statis-info:%"PRId64"us, datablock:%" PRId64"us, check data:%"PRId64"us, %p", pQueryHandle, pCost->statisInfoLoadTime, pCost->blockLoadTime, pCost->checkForNextTime, pQueryHandle->qinfo); - tfree(pQueryHandle); + taosTFree(pQueryHandle); } void tsdbDestroyTableGroup(STableGroupInfo *pGroupList) { diff --git a/src/tsdb/tests/tsdbTests.cpp b/src/tsdb/tests/tsdbTests.cpp index 5e678a8ee5..e504109cec 100644 --- a/src/tsdb/tests/tsdbTests.cpp +++ b/src/tsdb/tests/tsdbTests.cpp @@ -80,7 +80,7 @@ static int insertData(SInsertInfo *pInfo) { pMsg->numOfBlocks = htonl(pMsg->numOfBlocks); if (tsdbInsertData(pInfo->pRepo, pMsg, NULL) < 0) { - tfree(pMsg); + taosTFree(pMsg); return -1; } } @@ -88,7 +88,7 @@ static int insertData(SInsertInfo *pInfo) { double etime = getCurTime(); printf("Spent %f seconds to write %d records\n", etime - stime, pInfo->totalRows); - tfree(pMsg); + taosTFree(pMsg); return 0; } diff --git a/src/util/src/hash.c b/src/util/src/hash.c index 695529d02f..88f02aff7e 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -303,7 +303,7 @@ void taosHashRemove(SHashObj *pHashObj, const void *key, size_t keyLen) { pNode->next = NULL; pNode->prev = NULL; - tfree(pNode); + taosTFree(pNode); __unlock(pHashObj->lock); } @@ -335,7 +335,7 @@ void taosHashCleanup(SHashObj *pHashObj) { __unlock(pHashObj->lock); __lock_destroy(pHashObj->lock); - tfree(pHashObj->lock); + taosTFree(pHashObj->lock); memset(pHashObj, 0, sizeof(SHashObj)); free(pHashObj); } diff --git a/src/util/src/talgo.c b/src/util/src/talgo.c index 3a594faeb9..6879461953 100644 --- a/src/util/src/talgo.c +++ b/src/util/src/talgo.c @@ -153,7 +153,7 @@ static void tqsortImpl(void *src, int32_t start, int32_t end, size_t size, const void taosqsort(void *src, size_t numOfElem, size_t size, const void* param, __ext_compar_fn_t comparFn) { char *buf = calloc(1, size); // prepare the swap buffer tqsortImpl(src, 0, numOfElem - 1, size, param, comparFn, buf); - tfree(buf); + taosTFree(buf); } void * taosbsearch(const void *key, const void *base, size_t nmemb, size_t size, __compar_fn_t compar, int flags) { diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index dc9128d4a9..4a30a66871 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "os.h" #include "tulog.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" #include "tcache.h" @@ -634,7 +633,7 @@ void doCleanupDataCache(SCacheObj *pCacheObj) { taosTrashCanEmpty(pCacheObj, true); __cache_lock_destroy(pCacheObj); - tfree(pCacheObj->name); + taosTFree(pCacheObj->name); memset(pCacheObj, 0, sizeof(SCacheObj)); free(pCacheObj); } diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c index 59bc09e877..9fc9386b42 100644 --- a/src/util/src/tconfig.c +++ b/src/util/src/tconfig.c @@ -297,7 +297,7 @@ void taosReadGlobalLogCfg() { taosReadLogOption(option, value); } - tfree(line); + taosTFree(line); fclose(fp); } @@ -349,7 +349,7 @@ bool taosReadGlobalCfg() { fclose(fp); - tfree(line); + taosTFree(line); return true; } diff --git a/src/util/src/tdes.c b/src/util/src/tdes.c index c76938d3aa..871ae15a8a 100644 --- a/src/util/src/tdes.c +++ b/src/util/src/tdes.c @@ -1,8 +1,5 @@ -#include -#include -#include -#include -#include + +#include "os.h" #include "tkey.h" #define ENCRYPTION_MODE 1 diff --git a/src/util/src/tkvstore.c b/src/util/src/tkvstore.c index d7bf9d7857..2cea295c82 100644 --- a/src/util/src/tkvstore.c +++ b/src/util/src/tkvstore.c @@ -434,9 +434,9 @@ _err: static void tdFreeKVStore(SKVStore *pStore) { if (pStore) { - tfree(pStore->fname); - tfree(pStore->fsnap); - tfree(pStore->fnew); + taosTFree(pStore->fname); + taosTFree(pStore->fsnap); + taosTFree(pStore->fnew); taosHashCleanup(pStore->map); free(pStore); } @@ -575,11 +575,11 @@ static int tdRestoreKVStore(SKVStore *pStore) { if (pStore->aFunc) (*pStore->aFunc)(pStore->appH); taosHashDestroyIter(pIter); - tfree(buf); + taosTFree(buf); return 0; _err: taosHashDestroyIter(pIter); - tfree(buf); + taosTFree(buf); return -1; } diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 96ae417297..6bba8885b1 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -210,10 +210,10 @@ static bool taosCheckFileIsOpen(char *logFileName) { if (taosLockFile(fd)) { taosUnLockFile(fd); - tclose(fd); + taosClose(fd); return false; } else { - tclose(fd); + taosClose(fd); return true; } } @@ -457,7 +457,7 @@ void taosCloseLog() { static void taosCloseLogByFd(int32_t fd) { if (fd >= 0) { taosUnLockFile(fd); - tclose(fd); + taosClose(fd); } } @@ -482,8 +482,8 @@ static SLogBuff *taosLogBuffNew(int32_t bufSize) { return tLogBuff; _err: - tfree(LOG_BUF_BUFFER(tLogBuff)); - tfree(tLogBuff); + taosTFree(LOG_BUF_BUFFER(tLogBuff)); + taosTFree(tLogBuff); return NULL; } @@ -492,7 +492,7 @@ static void taosLogBuffDestroy(SLogBuff *tLogBuff) { tsem_destroy(&(tLogBuff->buffNotEmpty)); pthread_mutex_destroy(&(tLogBuff->buffMutex)); free(tLogBuff->buffer); - tfree(tLogBuff); + taosTFree(tLogBuff); } #endif diff --git a/src/util/src/tmempool.c b/src/util/src/tmempool.c index f5329800f3..4a899ebb48 100644 --- a/src/util/src/tmempool.c +++ b/src/util/src/tmempool.c @@ -56,9 +56,9 @@ mpool_h taosMemPoolInit(int numOfBlock, int blockSize) { if (pool_p->pool == NULL || pool_p->freeList == NULL) { uError("failed to allocate memory\n"); - tfree(pool_p->freeList); - tfree(pool_p->pool); - tfree(pool_p); + taosTFree(pool_p->freeList); + taosTFree(pool_p->pool); + taosTFree(pool_p); return NULL; } diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index aacc4a5487..14029fbd81 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -162,7 +162,7 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint8_t keyLen, ui pSkipList->level = 1; if (!initForwardBackwardPtr(pSkipList)) { - tfree(pSkipList); + taosTFree(pSkipList); return NULL; } @@ -170,8 +170,8 @@ SSkipList *tSkipListCreate(uint8_t maxLevel, uint8_t keyType, uint8_t keyLen, ui pSkipList->lock = calloc(1, sizeof(pthread_rwlock_t)); if (pthread_rwlock_init(pSkipList->lock, NULL) != 0) { - tfree(pSkipList->pHead); - tfree(pSkipList); + taosTFree(pSkipList->pHead); + taosTFree(pSkipList); return NULL; } @@ -201,7 +201,7 @@ void *tSkipListDestroy(SSkipList *pSkipList) { while (pNode != pSkipList->pTail) { SSkipListNode *pTemp = pNode; pNode = SL_GET_FORWARD_POINTER(pNode, 0); - tfree(pTemp); + taosTFree(pTemp); } } @@ -209,11 +209,11 @@ void *tSkipListDestroy(SSkipList *pSkipList) { pthread_rwlock_unlock(pSkipList->lock); pthread_rwlock_destroy(pSkipList->lock); - tfree(pSkipList->lock); + taosTFree(pSkipList->lock); } - tfree(pSkipList->pHead); - tfree(pSkipList); + taosTFree(pSkipList->pHead); + taosTFree(pSkipList); return NULL; } @@ -470,7 +470,7 @@ uint32_t tSkipListRemove(SSkipList *pSkipList, SSkipListKey key) { } if (pSkipList->keyInfo.freeNode) { - tfree(p); + taosTFree(p); } ++count; @@ -509,7 +509,7 @@ void tSkipListRemoveNode(SSkipList *pSkipList, SSkipListNode *pNode) { } if (pSkipList->keyInfo.freeNode) { - tfree(pNode); + taosTFree(pNode); } atomic_sub_fetch_32(&pSkipList->size, 1); @@ -592,7 +592,7 @@ void* tSkipListDestroyIter(SSkipListIterator* iter) { return NULL; } - tfree(iter); + taosTFree(iter); return NULL; } diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index 5cdc6ff918..b2982d353f 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -16,7 +16,6 @@ #include "os.h" #include "tlog.h" #include "tsched.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index eaa60d739b..f4b6ae629d 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -16,7 +16,6 @@ #include "os.h" #include "tcrc32c.h" #include "tglobal.h" -#include "ttime.h" #include "taosdef.h" #include "tutil.h" #include "tulog.h" diff --git a/src/util/tests/cacheTest.cpp b/src/util/tests/cacheTest.cpp index 9100b7e7f6..e0debd53f4 100644 --- a/src/util/tests/cacheTest.cpp +++ b/src/util/tests/cacheTest.cpp @@ -1,3 +1,4 @@ +#include "os.h" #include #include #include @@ -10,7 +11,6 @@ #include "tutil.h" #include "tcache.h" #include "ttimer.h" -#include "ttime.h" namespace { int32_t tsMaxMgmtConnections = 10000; diff --git a/src/util/tests/hashTest.cpp b/src/util/tests/hashTest.cpp index 93a1989741..6ffce61e61 100644 --- a/src/util/tests/hashTest.cpp +++ b/src/util/tests/hashTest.cpp @@ -1,11 +1,11 @@ +#include "os.h" #include #include #include #include #include "hash.h" -#include "taos.h" -#include "ttime.h" +#include "taos.h"" namespace { // the simple test code for basic operations diff --git a/src/util/tests/skiplistTest.cpp b/src/util/tests/skiplistTest.cpp index 70445a3d65..77174f69fd 100644 --- a/src/util/tests/skiplistTest.cpp +++ b/src/util/tests/skiplistTest.cpp @@ -3,9 +3,9 @@ #include #include +#include "os.h" #include "taosmsg.h" #include "tskiplist.h" -#include "ttime.h" #include "tutil.h" namespace { @@ -59,7 +59,7 @@ void doubleSkipListTest() { } if (size > 0) { - tfree(pNodes); + taosTFree(pNodes); } } @@ -196,7 +196,7 @@ void stringKeySkiplistTest() { tSkipListRemoveNode(pSkipList, pres[0]); if (num > 0) { - tfree(pres); + taosTFree(pres); } } @@ -276,7 +276,7 @@ void skiplistPerformanceTest() { assert(tSkipListGetSize(pSkipList) == size); tSkipListDestroy(pSkipList); - tfree(total); + taosTFree(total); } // todo not support duplicated key yet @@ -357,7 +357,7 @@ TEST(testCase, skiplist_test) { printf("-----%lf\n", pNodes[i]->key.dKey); } printf("the range query result size is: %d\n", size); - tfree(pNodes); + taosTFree(pNodes); SSkipListKey *pKeys = malloc(sizeof(SSkipListKey) * 20); for (int32_t i = 0; i < 8; i += 2) { @@ -371,7 +371,7 @@ TEST(testCase, skiplist_test) { for (int32_t i = 0; i < r; ++i) { // printf("%lf ", pNodes[i]->key.dKey); } - tfree(pNodes); + taosTFree(pNodes); free(pKeys);*/ } diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 8a56a2c500..6abd255dc4 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -25,7 +25,6 @@ #include "tglobal.h" #include "trpc.h" #include "tsdb.h" -#include "ttime.h" #include "ttimer.h" #include "tutil.h" #include "vnode.h" @@ -348,7 +347,7 @@ void vnodeRelease(void *pVnodeRaw) { dnodeFreeVnodeRqueue(pVnode->rqueue); pVnode->rqueue = NULL; - tfree(pVnode->rootDir); + taosTFree(pVnode->rootDir); if (pVnode->dropped) { char rootDir[TSDB_FILENAME_LEN] = {0}; @@ -870,7 +869,7 @@ static int32_t vnodeReadCfg(SVnodeObj *pVnode) { } PARSE_OVER: - tfree(content); + taosTFree(content); cJSON_Delete(root); if (fp) fclose(fp); return terrno; @@ -945,7 +944,7 @@ static int32_t vnodeReadVersion(SVnodeObj *pVnode) { vInfo("vgId:%d, read vnode version successfully, version:%" PRId64, pVnode->vgId, pVnode->version); PARSE_OVER: - tfree(content); + taosTFree(content); cJSON_Delete(root); if(fp) fclose(fp); return terrno; diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index bf3b0f63ea..a8f88c7be9 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -128,7 +128,7 @@ void walClose(void *handle) { if (handle == NULL) return; SWal *pWal = handle; - tclose(pWal->fd); + taosClose(pWal->fd); if (pWal->timer) taosTmrStopA(&pWal->timer); if (pWal->keep == 0) { diff --git a/tests/test/c/createTablePerformance.c b/tests/test/c/createTablePerformance.c index 69022bdecf..eae104291a 100644 --- a/tests/test/c/createTablePerformance.c +++ b/tests/test/c/createTablePerformance.c @@ -18,7 +18,6 @@ #include "taoserror.h" #include "taos.h" #include "tulog.h" -#include "ttime.h" #include "tutil.h" #include "tglobal.h" #include "hash.h" diff --git a/tests/test/c/hashPerformance.c b/tests/test/c/hashPerformance.c index fa3612d6e8..db3be0e950 100644 --- a/tests/test/c/hashPerformance.c +++ b/tests/test/c/hashPerformance.c @@ -17,7 +17,6 @@ #include "os.h" #include "taos.h" #include "tulog.h" -#include "ttime.h" #include "tutil.h" #include "hash.h" diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 3469180607..fdec38b4c7 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -20,6 +20,7 @@ #include "tglobal.h" #include "tutil.h" #include "cJSON.h" +#undef TAOS_MEM_CHECK void simLogSql(char *sql, bool useSharp) { static FILE *fp = NULL; diff --git a/tests/tsim/src/simParse.c b/tests/tsim/src/simParse.c index 9fea1f115b..2528fde9f5 100644 --- a/tests/tsim/src/simParse.c +++ b/tests/tsim/src/simParse.c @@ -57,12 +57,11 @@ * */ +#include "os.h" #include "sim.h" -#include -#include -#include #include "simParse.h" #include "tutil.h" +#undef TAOS_MEM_CHECK static SCommand *cmdHashList[MAX_NUM_CMD]; static SCmdLine cmdLine[MAX_CMD_LINES]; diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index b50c853ea8..17df7f306a 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -20,6 +20,7 @@ #include "ttimer.h" #include "tutil.h" #include "tsocket.h" +#undef TAOS_MEM_CHECK SScript *simScriptList[MAX_MAIN_SCRIPT_NUM]; SCommand simCmdList[SIM_CMD_END]; @@ -94,9 +95,9 @@ void simFreeScript(SScript *script) { } taos_close(script->taos); - tfree(script->lines); - tfree(script->optionBuffer); - tfree(script); + taosTFree(script->lines); + taosTFree(script->optionBuffer); + taosTFree(script); } SScript *simProcessCallOver(SScript *script) {