diff --git a/src/client/inc/tscLog.h b/src/client/inc/tscLog.h new file mode 100644 index 0000000000..e82b824123 --- /dev/null +++ b/src/client/inc/tscLog.h @@ -0,0 +1,50 @@ +/* + * 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_TSC_LOG_H +#define TDENGINE_TSC_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tlog.h" + +extern int32_t cdebugFlag; + +#define tscError(...) \ + if (cdebugFlag & DEBUG_ERROR) { \ + taosPrintLog("ERROR TSC ", 255, __VA_ARGS__); \ + } +#define tscWarn(...) \ + if (cdebugFlag & DEBUG_WARN) { \ + taosPrintLog("WARN TSC ", cdebugFlag, __VA_ARGS__); \ + } +#define tscTrace(...) \ + if (cdebugFlag & DEBUG_TRACE) { \ + taosPrintLog("TSC ", cdebugFlag, __VA_ARGS__); \ + } +#define tscPrint(...) \ + { taosPrintLog("TSC ", 255, __VA_ARGS__); } +#define tscDump(...) \ + if (cdebugFlag & DEBUG_TRACE) { \ + taosPrintLongString("TSC ", cdebugFlag, __VA_ARGS__); \ + } + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index bedaab1b2f..f225d546f3 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -29,8 +29,7 @@ extern "C" { #include "taosdef.h" #include "taosmsg.h" #include "tarray.h" -#include "tglobalcfg.h" -#include "tlog.h" +#include "tglobal.h" #include "trpc.h" #include "tsqlfunction.h" #include "tutil.h" diff --git a/src/client/src/TSDBJNIConnector.c b/src/client/src/TSDBJNIConnector.c index dfaedc7c14..29dec66ee8 100644 --- a/src/client/src/TSDBJNIConnector.c +++ b/src/client/src/TSDBJNIConnector.c @@ -16,12 +16,27 @@ #include "com_taosdata_jdbc_TSDBJNIConnector.h" #include "os.h" #include "taos.h" -#include "tlog.h" #include "tscSubquery.h" #include "tscUtil.h" #include "tsclient.h" +#include "tlog.h" #include "ttime.h" +#define jniError(...) \ + if (jnidebugFlag & DEBUG_ERROR) { \ + taosPrintLog("ERROR JNI ", jnidebugFlag, __VA_ARGS__); \ + } +#define jniWarn(...) \ + if (jnidebugFlag & DEBUG_WARN) { \ + taosPrintLog("WARN JNI ", jnidebugFlag, __VA_ARGS__); \ + } +#define jniTrace(...) \ + if (jnidebugFlag & DEBUG_TRACE) { \ + taosPrintLog("JNI ", jnidebugFlag, __VA_ARGS__); \ + } +#define jniPrint(...) \ + { taosPrintLog("JNI ", 255, __VA_ARGS__); } + int __init = 0; JavaVM *g_vm = NULL; diff --git a/src/client/src/tscAsync.c b/src/client/src/tscAsync.c index 8eabbcb62a..ee38fec475 100644 --- a/src/client/src/tscAsync.c +++ b/src/client/src/tscAsync.c @@ -14,9 +14,8 @@ */ #include "os.h" - -#include "tlog.h" #include "trpc.h" +#include "tscLog.h" #include "tscProfile.h" #include "tscSecondaryMerge.h" #include "tscUtil.h" diff --git a/src/client/src/tscFunctionImpl.c b/src/client/src/tscFunctionImpl.c index a5a0bf4a78..9a8bec4597 100644 --- a/src/client/src/tscFunctionImpl.c +++ b/src/client/src/tscFunctionImpl.c @@ -23,7 +23,7 @@ #include "qtsbuf.h" #include "taosdef.h" #include "taosmsg.h" -#include "tlog.h" +#include "tscLog.h" #include "tscSubquery.h" #include "tscompression.h" #include "tsqlfunction.h" @@ -155,7 +155,7 @@ typedef struct SRateInfo { int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionId, int32_t param, int16_t *type, int16_t *bytes, int16_t *intermediateResBytes, int16_t extLength, bool isSuperTable) { if (!isValidDataType(dataType, dataBytes)) { - pError("Illegal data type %d or data type length %d", dataType, dataBytes); + tscError("Illegal data type %d or data type length %d", dataType, dataBytes); return TSDB_CODE_INVALID_SQL; } @@ -381,7 +381,7 @@ static void function_finalizer(SQLFunctionCtx *pCtx) { SResultInfo *pResInfo = GET_RES_INFO(pCtx); if (pResInfo->hasResult != DATA_SET_FLAG) { - pTrace("no result generated, result is set to NULL"); + tscTrace("no result generated, result is set to NULL"); setNull(pCtx->aOutputBuf, pCtx->outputType, pCtx->outputBytes); } @@ -964,7 +964,7 @@ static void minMax_function(SQLFunctionCtx *pCtx, char *pOutput, int32_t isMin, } else if (pCtx->inputType == TSDB_DATA_TYPE_INT) { int32_t *data = (int32_t *)pOutput; #if defined(_DEBUG_VIEW) - pTrace("max value updated according to pre-cal:%d", *data); + tscTrace("max value updated according to pre-cal:%d", *data); #endif if ((*data < val) ^ isMin) { @@ -1024,7 +1024,7 @@ static void minMax_function(SQLFunctionCtx *pCtx, char *pOutput, int32_t isMin, *notNullElems += 1; } #if defined(_DEBUG_VIEW) - pTrace("max value updated:%d", *retVal); + tscTrace("max value updated:%d", *retVal); #endif } else if (pCtx->inputType == TSDB_DATA_TYPE_BIGINT) { TYPED_LOOPCHECK_N(int64_t, pOutput, p, pCtx, pCtx->inputType, isMin, *notNullElems); @@ -1063,7 +1063,7 @@ static bool min_func_setup(SQLFunctionCtx *pCtx) { *((int8_t *)pCtx->aOutputBuf) = INT8_MAX; break; default: - pError("illegal data type:%d in min/max query", pCtx->inputType); + tscError("illegal data type:%d in min/max query", pCtx->inputType); } return true; @@ -1096,7 +1096,7 @@ static bool max_func_setup(SQLFunctionCtx *pCtx) { *((int8_t *)pCtx->aOutputBuf) = INT8_MIN; break; default: - pError("illegal data type:%d in min/max query", pCtx->inputType); + tscError("illegal data type:%d in min/max query", pCtx->inputType); } return true; @@ -1367,7 +1367,7 @@ static void stddev_function(SQLFunctionCtx *pCtx) { break; } default: - pError("stddev function not support data type:%d", pCtx->inputType); + tscError("stddev function not support data type:%d", pCtx->inputType); } // TODO get the correct data @@ -1417,7 +1417,7 @@ static void stddev_function_f(SQLFunctionCtx *pCtx, int32_t index) { break; } default: - pError("stddev function not support data type:%d", pCtx->inputType); + tscError("stddev function not support data type:%d", pCtx->inputType); } SET_VAL(pCtx, 1, 1); @@ -1710,7 +1710,7 @@ static void last_data_assign_impl(SQLFunctionCtx *pCtx, char *pData, int32_t ind if (pInfo->hasResult != DATA_SET_FLAG || pInfo->ts < timestamp[index]) { #if defined(_DEBUG_VIEW) - pTrace("assign index:%d, ts:%" PRId64 ", val:%d, ", index, timestamp[index], *(int32_t *)pData); + tscTrace("assign index:%d, ts:%" PRId64 ", val:%d, ", index, timestamp[index], *(int32_t *)pData); #endif memcpy(pCtx->aOutputBuf, pData, pCtx->inputBytes); @@ -2097,7 +2097,7 @@ static void copyTopBotRes(SQLFunctionCtx *pCtx, int32_t type) { break; } default: { - pError("top/bottom function not support data type:%d", pCtx->inputType); + tscError("top/bottom function not support data type:%d", pCtx->inputType); return; } } @@ -2860,7 +2860,7 @@ static void leastsquares_function_f(SQLFunctionCtx *pCtx, int32_t index) { break; } default: - pError("error data type in leastsquare function:%d", pCtx->inputType); + tscError("error data type in leastsquare function:%d", pCtx->inputType); }; SET_VAL(pCtx, 1, 1); @@ -3207,7 +3207,7 @@ static void diff_function(SQLFunctionCtx *pCtx) { break; }; default: - pError("error input type"); + tscError("error input type"); } // initial value is not set yet @@ -3285,7 +3285,7 @@ static void diff_function_f(SQLFunctionCtx *pCtx, int32_t index) { break; }; default: - pError("error input type"); + tscError("error input type"); } if (GET_RES_INFO(pCtx)->numOfRes > 0) { @@ -4283,7 +4283,7 @@ static double do_calc_rate(const SRateInfo* pRateInfo) { double resultVal = ((double)diff) / duration; - pTrace("do_calc_rate() isIRate:%d firstKey:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " lastValue:%" PRId64 " CorrectionValue:%" PRId64 " resultVal:%f", + tscTrace("do_calc_rate() isIRate:%d firstKey:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " lastValue:%" PRId64 " CorrectionValue:%" PRId64 " resultVal:%f", pRateInfo->isIRate, pRateInfo->firstKey, pRateInfo->lastKey, pRateInfo->firstValue, pRateInfo->lastValue, pRateInfo->CorrectionValue, resultVal); return resultVal; @@ -4319,12 +4319,12 @@ static void rate_function(SQLFunctionCtx *pCtx) { SRateInfo *pRateInfo = (SRateInfo *)pResInfo->interResultBuf; TSKEY *primaryKey = pCtx->ptsList; - pTrace("%p rate_function() size:%d, hasNull:%d", pCtx, pCtx->size, pCtx->hasNull); + tscTrace("%p rate_function() size:%d, hasNull:%d", pCtx, pCtx->size, pCtx->hasNull); for (int32_t i = 0; i < pCtx->size; ++i) { char *pData = GET_INPUT_CHAR_INDEX(pCtx, i); if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { - pTrace("%p rate_function() index of null data:%d", pCtx, i); + tscTrace("%p rate_function() index of null data:%d", pCtx, i); continue; } @@ -4352,19 +4352,19 @@ static void rate_function(SQLFunctionCtx *pCtx) { pRateInfo->firstValue = v; pRateInfo->firstKey = primaryKey[i]; - pTrace("firstValue:%" PRId64 " firstKey:%" PRId64, pRateInfo->firstValue, pRateInfo->firstKey); + tscTrace("firstValue:%" PRId64 " firstKey:%" PRId64, pRateInfo->firstValue, pRateInfo->firstKey); } if (INT64_MIN == pRateInfo->lastValue) { pRateInfo->lastValue = v; } else if (v < pRateInfo->lastValue) { pRateInfo->CorrectionValue += pRateInfo->lastValue; - pTrace("CorrectionValue:%" PRId64, pRateInfo->CorrectionValue); + tscTrace("CorrectionValue:%" PRId64, pRateInfo->CorrectionValue); } pRateInfo->lastValue = v; pRateInfo->lastKey = primaryKey[i]; - pTrace("lastValue:%" PRId64 " lastKey:%" PRId64, pRateInfo->lastValue, pRateInfo->lastKey); + tscTrace("lastValue:%" PRId64 " lastKey:%" PRId64, pRateInfo->lastValue, pRateInfo->lastKey); } if (!pCtx->hasNull) { @@ -4427,7 +4427,7 @@ static void rate_function_f(SQLFunctionCtx *pCtx, int32_t index) { pRateInfo->lastValue = v; pRateInfo->lastKey = primaryKey[index]; - pTrace("====%p rate_function_f() index:%d lastValue:%" PRId64 " lastKey:%" PRId64 " CorrectionValue:%" PRId64, pCtx, index, pRateInfo->lastValue, pRateInfo->lastKey, pRateInfo->CorrectionValue); + tscTrace("====%p rate_function_f() index:%d lastValue:%" PRId64 " lastKey:%" PRId64 " CorrectionValue:%" PRId64, pCtx, index, pRateInfo->lastValue, pRateInfo->lastKey, pRateInfo->CorrectionValue); SET_VAL(pCtx, 1, 1); @@ -4447,7 +4447,7 @@ static void rate_func_merge(SQLFunctionCtx *pCtx) { SResultInfo *pResInfo = GET_RES_INFO(pCtx); assert(pResInfo->superTableQ); - pTrace("rate_func_merge() size:%d", pCtx->size); + tscTrace("rate_func_merge() size:%d", pCtx->size); //SRateInfo *pRateInfo = (SRateInfo *)pResInfo->interResultBuf; SRateInfo *pBuf = (SRateInfo *)pCtx->aOutputBuf; @@ -4464,7 +4464,7 @@ static void rate_func_merge(SQLFunctionCtx *pCtx) { numOfNotNull++; memcpy(pBuf, pInput, sizeof(SRateInfo)); - pTrace("%p rate_func_merge() isIRate:%d firstKey:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " lastValue:%" PRId64 " CorrectionValue:%" PRId64, + tscTrace("%p rate_func_merge() isIRate:%d firstKey:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " lastValue:%" PRId64 " CorrectionValue:%" PRId64, pCtx, pInput->isIRate, pInput->firstKey, pInput->lastKey, pInput->firstValue, pInput->lastValue, pInput->CorrectionValue); } @@ -4487,7 +4487,7 @@ static void rate_func_copy(SQLFunctionCtx *pCtx) { pResInfo->hasResult = ((SRateInfo*)pCtx->aInputElemBuf)->hasResult; SRateInfo* pRateInfo = (SRateInfo*)pCtx->aInputElemBuf; - pTrace("%p rate_func_second_merge() firstKey:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " lastValue:%" PRId64 " CorrectionValue:%" PRId64 " hasResult:%d", + tscTrace("%p rate_func_second_merge() firstKey:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " lastValue:%" PRId64 " CorrectionValue:%" PRId64 " hasResult:%d", pCtx, pRateInfo->firstKey, pRateInfo->lastKey, pRateInfo->firstValue, pRateInfo->lastValue, pRateInfo->CorrectionValue, pRateInfo->hasResult); } @@ -4497,7 +4497,7 @@ static void rate_finalizer(SQLFunctionCtx *pCtx) { SResultInfo *pResInfo = GET_RES_INFO(pCtx); SRateInfo *pRateInfo = (SRateInfo *)pResInfo->interResultBuf; - pTrace("%p isIRate:%d firstKey:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " lastValue:%" PRId64 " CorrectionValue:%" PRId64 " hasResult:%d", + tscTrace("%p isIRate:%d firstKey:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " lastValue:%" PRId64 " CorrectionValue:%" PRId64 " hasResult:%d", pCtx, pRateInfo->isIRate, pRateInfo->firstKey, pRateInfo->lastKey, pRateInfo->firstValue, pRateInfo->lastValue, pRateInfo->CorrectionValue, pRateInfo->hasResult); if (pRateInfo->hasResult != DATA_SET_FLAG) { @@ -4507,7 +4507,7 @@ static void rate_finalizer(SQLFunctionCtx *pCtx) { *(double*)pCtx->aOutputBuf = do_calc_rate(pRateInfo); - pTrace("rate_finalizer() output result:%f", *(double *)pCtx->aOutputBuf); + tscTrace("rate_finalizer() output result:%f", *(double *)pCtx->aOutputBuf); // cannot set the numOfIteratedElems again since it is set during previous iteration pResInfo->numOfRes = 1; @@ -4524,7 +4524,7 @@ static void irate_function(SQLFunctionCtx *pCtx) { SRateInfo *pRateInfo = (SRateInfo *)pResInfo->interResultBuf; TSKEY *primaryKey = pCtx->ptsList; - pTrace("%p irate_function() size:%d, hasNull:%d", pCtx, pCtx->size, pCtx->hasNull); + tscTrace("%p irate_function() size:%d, hasNull:%d", pCtx, pCtx->size, pCtx->hasNull); if (pCtx->size < 1) { return; @@ -4533,7 +4533,7 @@ static void irate_function(SQLFunctionCtx *pCtx) { for (int32_t i = pCtx->size - 1; i >= 0; --i) { char *pData = GET_INPUT_CHAR_INDEX(pCtx, i); if (pCtx->hasNull && isNull(pData, pCtx->inputType)) { - pTrace("%p irate_function() index of null data:%d", pCtx, i); + tscTrace("%p irate_function() index of null data:%d", pCtx, i); continue; } @@ -4562,7 +4562,7 @@ static void irate_function(SQLFunctionCtx *pCtx) { pRateInfo->lastValue = v; pRateInfo->lastKey = primaryKey[i]; - pTrace("%p irate_function() lastValue:%" PRId64 " lastKey:%" PRId64, pCtx, pRateInfo->lastValue, pRateInfo->lastKey); + tscTrace("%p irate_function() lastValue:%" PRId64 " lastKey:%" PRId64, pCtx, pRateInfo->lastValue, pRateInfo->lastKey); continue; } @@ -4570,7 +4570,7 @@ static void irate_function(SQLFunctionCtx *pCtx) { pRateInfo->firstValue = v; pRateInfo->firstKey = primaryKey[i]; - pTrace("%p irate_function() firstValue:%" PRId64 " firstKey:%" PRId64, pCtx, pRateInfo->firstValue, pRateInfo->firstKey); + tscTrace("%p irate_function() firstValue:%" PRId64 " firstKey:%" PRId64, pCtx, pRateInfo->firstValue, pRateInfo->firstKey); break; } } @@ -4623,7 +4623,7 @@ static void irate_function_f(SQLFunctionCtx *pCtx, int32_t index) { pRateInfo->lastValue = v; pRateInfo->lastKey = primaryKey[index]; - pTrace("====%p irate_function_f() index:%d lastValue:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " firstKey:%" PRId64, pCtx, index, pRateInfo->lastValue, pRateInfo->lastKey, pRateInfo->firstValue , pRateInfo->firstKey); + tscTrace("====%p irate_function_f() index:%d lastValue:%" PRId64 " lastKey:%" PRId64 " firstValue:%" PRId64 " firstKey:%" PRId64, pCtx, index, pRateInfo->lastValue, pRateInfo->lastKey, pRateInfo->firstValue , pRateInfo->firstKey); SET_VAL(pCtx, 1, 1); @@ -4647,7 +4647,7 @@ static void do_sumrate_merge(SQLFunctionCtx *pCtx) { for (int32_t i = 0; i < pCtx->size; ++i, input += pCtx->inputBytes) { SRateInfo *pInput = (SRateInfo *)input; - pTrace("%p do_sumrate_merge() hasResult:%d input num:%" PRId64 " input sum:%f total num:%" PRId64 " total sum:%f", pCtx, pInput->hasResult, pInput->num, pInput->sum, pRateInfo->num, pRateInfo->sum); + tscTrace("%p do_sumrate_merge() hasResult:%d input num:%" PRId64 " input sum:%f total num:%" PRId64 " total sum:%f", pCtx, pInput->hasResult, pInput->num, pInput->sum, pRateInfo->num, pRateInfo->sum); if (pInput->hasResult != DATA_SET_FLAG) { continue; @@ -4670,12 +4670,12 @@ static void do_sumrate_merge(SQLFunctionCtx *pCtx) { } static void sumrate_func_merge(SQLFunctionCtx *pCtx) { - pTrace("%p sumrate_func_merge() process ...", pCtx); + tscTrace("%p sumrate_func_merge() process ...", pCtx); do_sumrate_merge(pCtx); } static void sumrate_func_second_merge(SQLFunctionCtx *pCtx) { - pTrace("%p sumrate_func_second_merge() process ...", pCtx); + tscTrace("%p sumrate_func_second_merge() process ...", pCtx); do_sumrate_merge(pCtx); } @@ -4683,7 +4683,7 @@ static void sumrate_finalizer(SQLFunctionCtx *pCtx) { SResultInfo *pResInfo = GET_RES_INFO(pCtx); SRateInfo *pRateInfo = (SRateInfo *)pResInfo->interResultBuf; - pTrace("%p sumrate_finalizer() superTableQ:%d num:%" PRId64 " sum:%f hasResult:%d", pCtx, pResInfo->superTableQ, pRateInfo->num, pRateInfo->sum, pRateInfo->hasResult); + tscTrace("%p sumrate_finalizer() superTableQ:%d num:%" PRId64 " sum:%f hasResult:%d", pCtx, pResInfo->superTableQ, pRateInfo->num, pRateInfo->sum, pRateInfo->hasResult); if (pRateInfo->hasResult != DATA_SET_FLAG) { setNull(pCtx->aOutputBuf, TSDB_DATA_TYPE_DOUBLE, sizeof(double)); diff --git a/src/client/src/tscLocal.c b/src/client/src/tscLocal.c index 41d5febab5..7987c529bc 100644 --- a/src/client/src/tscLocal.c +++ b/src/client/src/tscLocal.c @@ -20,11 +20,11 @@ #include "tscUtil.h" #include "tsclient.h" #include "taosdef.h" - +#include "tscLog.h" #include "qextbuffer.h" #include "tscSecondaryMerge.h" #include "tschemautil.h" -#include "name.h" +#include "tname.h" static void tscSetLocalQueryResult(SSqlObj *pSql, const char *val, const char *columnName, size_t valueLength); @@ -477,7 +477,7 @@ int tscProcessLocalCmd(SSqlObj *pSql) { SSqlCmd *pCmd = &pSql->cmd; if (pCmd->command == TSDB_SQL_CFG_LOCAL) { - pSql->res.code = (uint8_t)tsCfgDynamicOptions(pCmd->payload); + pSql->res.code = (uint8_t)taosCfgDynamicOptions(pCmd->payload); } else if (pCmd->command == TSDB_SQL_DESCRIBE_TABLE) { pSql->res.code = (uint8_t)tscProcessDescribeTable(pSql); } else if (pCmd->command == TSDB_SQL_RETRIEVE_TAGS) { diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index be9a8418e9..2c203e4307 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -27,12 +27,12 @@ #include "ttokendef.h" #include "taosdef.h" -#include "tlog.h" +#include "tscLog.h" #include "tscSubquery.h" #include "tstoken.h" #include "ttime.h" -#include "dataformat.h" +#include "tdataformat.h" enum { TSDB_USE_SERVER_TS = 0, diff --git a/src/client/src/tscPrepare.c b/src/client/src/tscPrepare.c index 5c6127ae01..0602fe522f 100644 --- a/src/client/src/tscPrepare.c +++ b/src/client/src/tscPrepare.c @@ -19,7 +19,7 @@ #include "ttimer.h" #include "taosmsg.h" #include "tstrbuild.h" - +#include "tscLog.h" int tsParseInsertSql(SSqlObj *pSql); int taos_query_imp(STscObj* pObj, SSqlObj* pSql); diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 739ae7848e..e5c3a3b7f6 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "tlog.h" +#include "tscLog.h" #include "tsclient.h" #include "ttime.h" #include "ttimer.h" diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index c541a35d12..e2191c73c2 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -23,13 +23,12 @@ #include "tstoken.h" #include "tstrbuild.h" #include "ttime.h" - +#include "tscLog.h" #include "tscUtil.h" #include "tschemautil.h" #include "tsclient.h" #include "ttokendef.h" - -#include "name.h" +#include "tname.h" #include "tcompare.h" #define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0" diff --git a/src/client/src/tscSecondaryMerge.c b/src/client/src/tscSecondaryMerge.c index 25d3470e61..af186c84af 100644 --- a/src/client/src/tscSecondaryMerge.c +++ b/src/client/src/tscSecondaryMerge.c @@ -20,6 +20,7 @@ #include "tschemautil.h" #include "tsclient.h" #include "tutil.h" +#include "tscLog.h" typedef struct SCompareParam { SLocalDataSource **pLocalData; @@ -190,7 +191,7 @@ void tscCreateLocalReducer(tExtMemBuffer **pMemBuffer, int32_t numOfBuffer, tOrd pReducer->numOfVnode = numOfBuffer; pReducer->pDesc = pDesc; - pTrace("%p the number of merged leaves is: %d", pSqlObjAddr, pReducer->numOfBuffer); + tscTrace("%p the number of merged leaves is: %d", pSqlObjAddr, pReducer->numOfBuffer); int32_t idx = 0; for (int32_t i = 0; i < numOfBuffer; ++i) { diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index f5835e1fdd..ad5f9cd0af 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -26,6 +26,7 @@ #include "ttime.h" #include "ttimer.h" #include "tutil.h" +#include "tscLog.h" #define TSC_MGMT_VNODE 999 diff --git a/src/client/src/tscSql.c b/src/client/src/tscSql.c index 515ae90db3..4f02a96eec 100644 --- a/src/client/src/tscSql.c +++ b/src/client/src/tscSql.c @@ -17,9 +17,9 @@ #include "os.h" #include "qast.h" #include "tcache.h" -#include "tlog.h" #include "tnote.h" #include "trpc.h" +#include "tscLog.h" #include "tscProfile.h" #include "tscSecondaryMerge.h" #include "tscSubquery.h" diff --git a/src/client/src/tscStream.c b/src/client/src/tscStream.c index aabaa9330a..9323a4b0c4 100644 --- a/src/client/src/tscStream.c +++ b/src/client/src/tscStream.c @@ -16,7 +16,7 @@ #include #include "os.h" #include "taosmsg.h" -#include "tlog.h" +#include "tscLog.h" #include "tscUtil.h" #include "tsched.h" #include "tsclient.h" diff --git a/src/client/src/tscSub.c b/src/client/src/tscSub.c index aeeec328b4..d938bb0576 100644 --- a/src/client/src/tscSub.c +++ b/src/client/src/tscSub.c @@ -17,13 +17,13 @@ #include "shash.h" #include "taos.h" -#include "tlog.h" #include "trpc.h" #include "tsclient.h" #include "tsocket.h" #include "ttime.h" #include "ttimer.h" #include "tutil.h" +#include "tscLog.h" #include "tscUtil.h" #include "tcache.h" #include "tscProfile.h" diff --git a/src/client/src/tscSubquery.c b/src/client/src/tscSubquery.c index cf95332583..e647772226 100644 --- a/src/client/src/tscSubquery.c +++ b/src/client/src/tscSubquery.c @@ -17,6 +17,7 @@ #include "os.h" #include "qtsbuf.h" #include "tsclient.h" +#include "tscLog.h" typedef struct SInsertSupporter { SSubqueryState* pState; diff --git a/src/client/src/tscSystem.c b/src/client/src/tscSystem.c index 46f04b60c8..a24ca4d045 100644 --- a/src/client/src/tscSystem.c +++ b/src/client/src/tscSystem.c @@ -16,7 +16,6 @@ #include "os.h" #include "taosmsg.h" #include "tcache.h" -#include "tlog.h" #include "trpc.h" #include "taosdef.h" #include "tsocket.h" @@ -25,7 +24,12 @@ #include "ttimer.h" #include "tutil.h" #include "tsched.h" +#include "tscLog.h" #include "tsclient.h" +#include "tglobal.h" +#include "tconfig.h" +#include "ttimezone.h" +#include "tlocale.h" // global, not configurable void * pVnodeConn; @@ -116,7 +120,8 @@ void taos_init_imp() { strcpy(tsLocalIp, "0.0.0.0"); // Read global configuration. - tsReadGlobalLogConfig(); + taosInitGlobalCfg(); + taosReadGlobalLogCfg(); // For log directory if (stat(logDir, &dirstat) < 0) mkdir(logDir, 0755); @@ -126,8 +131,9 @@ void taos_init_imp() { printf("failed to open log file in directory:%s\n", logDir); } - tsReadGlobalConfig(); - tsPrintGlobalConfig(); + taosReadGlobalCfg(); + taosCheckGlobalCfg(); + taosPrintGlobalCfg(); tscTrace("starting to initialize TAOS client ..."); tscTrace("Local IP address is:%s", tsLocalIp); @@ -195,7 +201,7 @@ void taos_cleanup() { tscQhandle = NULL; } - taosCloseLogger(); + taosCloseLog(); if (pVnodeConn != NULL) { rpcClose(pVnodeConn); @@ -207,24 +213,20 @@ void taos_cleanup() { pTscMgmtConn = NULL; } - if (tsGlobalConfig != NULL) { - tfree(tsGlobalConfig); - } - taosTmrCleanUp(tscTmr); } static int taos_options_imp(TSDB_OPTION option, const char *pStr) { - SGlobalConfig *cfg = NULL; + SGlobalCfg *cfg = NULL; switch (option) { case TSDB_OPTION_CONFIGDIR: - cfg = tsGetConfigOption("configDir"); + cfg = taosGetConfigOption("configDir"); assert(cfg != NULL); - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { strncpy(configDir, pStr, TSDB_FILENAME_LEN); - cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION; + cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; tscPrint("set config file directory:%s", pStr); } else { tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr, @@ -233,14 +235,14 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { break; case TSDB_OPTION_SHELL_ACTIVITY_TIMER: - cfg = tsGetConfigOption("shellActivityTimer"); + cfg = taosGetConfigOption("shellActivityTimer"); assert(cfg != NULL); - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { tsShellActivityTimer = atoi(pStr); if (tsShellActivityTimer < 1) tsShellActivityTimer = 1; if (tsShellActivityTimer > 3600) tsShellActivityTimer = 3600; - cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION; + cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; tscPrint("set shellActivityTimer:%d", tsShellActivityTimer); } else { tscWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, pStr, @@ -249,7 +251,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { break; case TSDB_OPTION_LOCALE: { // set locale - cfg = tsGetConfigOption("locale"); + cfg = taosGetConfigOption("locale"); assert(cfg != NULL); size_t len = strlen(pStr); @@ -258,7 +260,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { return -1; } - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { char sep = '.'; if (strlen(tsLocale) == 0) { // locale does not set yet @@ -271,7 +273,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { if (locale != NULL) { tscPrint("locale set, prev locale:%s, new locale:%s", tsLocale, locale); - cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION; + cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; } else { // set the user-specified localed failed, use default LC_CTYPE as current locale locale = setlocale(LC_CTYPE, tsLocale); tscPrint("failed to set locale:%s, current locale:%s", pStr, tsLocale); @@ -293,7 +295,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { } strncpy(tsCharset, charset, tListLen(tsCharset)); - cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION; + cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; } else { tscPrint("charset:%s is not valid in locale, charset remains:%s", charset, tsCharset); @@ -312,7 +314,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { case TSDB_OPTION_CHARSET: { /* set charset will override the value of charset, assigned during system locale changed */ - cfg = tsGetConfigOption("charset"); + cfg = taosGetConfigOption("charset"); assert(cfg != NULL); size_t len = strlen(pStr); @@ -321,7 +323,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { return -1; } - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { if (taosValidateEncodec(pStr)) { if (strlen(tsCharset) == 0) { tscPrint("charset is set:%s", pStr); @@ -330,7 +332,7 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { } strncpy(tsCharset, pStr, tListLen(tsCharset)); - cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION; + cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; } else { tscPrint("charset:%s not valid", pStr); } @@ -343,13 +345,13 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { } case TSDB_OPTION_TIMEZONE: - cfg = tsGetConfigOption("timezone"); + cfg = taosGetConfigOption("timezone"); assert(cfg != NULL); - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { strcpy(tsTimezone, pStr); tsSetTimeZone(); - cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION; + cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; tscTrace("timezone set:%s, input:%s by taos_options", tsTimezone, pStr); } else { tscWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, pStr, @@ -358,17 +360,17 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) { break; case TSDB_OPTION_SOCKET_TYPE: - cfg = tsGetConfigOption("sockettype"); + cfg = taosGetConfigOption("sockettype"); assert(cfg != NULL); - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_OPTION) { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_OPTION) { // if (strcasecmp(pStr, TAOS_SOCKET_TYPE_NAME_UDP) != 0 && strcasecmp(pStr, TAOS_SOCKET_TYPE_NAME_TCP) != 0) { // tscError("only 'tcp' or 'udp' allowed for configuring the socket type"); // return -1; // } strncpy(tsSocketType, pStr, tListLen(tsSocketType)); - cfg->cfgStatus = TSDB_CFG_CSTATUS_OPTION; + cfg->cfgStatus = TAOS_CFG_CSTATUS_OPTION; tscPrint("socket type is set:%s", tsSocketType); } break; diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index f714611539..3650ea1f30 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -28,6 +28,7 @@ #include "tsclient.h" #include "ttimer.h" #include "ttokendef.h" +#include "tscLog.h" /* * the detailed information regarding metric meta key is: diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 6a5415a066..57a32f3d69 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -8,4 +8,5 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(src SRC) ADD_LIBRARY(common ${SRC}) + TARGET_LINK_LIBRARIES(common tutil) ENDIF () diff --git a/src/common/inc/dataformat.h b/src/common/inc/tdataformat.h similarity index 100% rename from src/common/inc/dataformat.h rename to src/common/inc/tdataformat.h diff --git a/src/util/inc/tglobalcfg.h b/src/common/inc/tglobal.h similarity index 60% rename from src/util/inc/tglobalcfg.h rename to src/common/inc/tglobal.h index 664eb16373..507843cb2f 100644 --- a/src/util/inc/tglobalcfg.h +++ b/src/common/inc/tglobal.h @@ -13,19 +13,21 @@ * along with this program. If not, see . */ -#ifndef TDENGINE_TGLOBALCFG_H -#define TDENGINE_TGLOBALCFG_H +#ifndef TDENGINE_COMMON_GLOBAL_H +#define TDENGINE_COMMON_GLOBAL_H #ifdef __cplusplus extern "C" { #endif -#include -#include -#include "taosdef.h" - -extern int (*startMonitor)(); -extern void (*stopMonitor)(); +extern char configDir[]; +extern char tsVnodeDir[]; +extern char tsDnodeDir[]; +extern char tsMnodeDir[]; +extern char dataDir[]; +extern char logDir[]; +extern char scriptDir[]; +extern char osName[]; // system info extern int64_t tsPageSize; @@ -42,6 +44,7 @@ extern float tsAvailDataDirGB; extern float tsMinimalLogDirGB; extern float tsMinimalTmpDirGB; extern float tsMinimalDataDirGB; +extern int32_t tsEnableCoreFile; extern int32_t tsTotalMemoryMB; extern int32_t tsVersion; @@ -49,14 +52,6 @@ extern int tscEmbedded; extern int64_t tsMsPerDay[2]; -extern char configDir[]; -extern char tsVnodeDir[]; -extern char tsDnodeDir[]; -extern char tsMnodeDir[]; -extern char dataDir[]; -extern char logDir[]; -extern char scriptDir[]; -extern char osName[]; extern char tsMasterIp[]; extern char tsSecondIp[]; @@ -64,9 +59,6 @@ extern uint16_t tsMnodeDnodePort; extern uint16_t tsMnodeShellPort; extern uint16_t tsDnodeShellPort; extern uint16_t tsDnodeMnodePort; -extern uint16_t tsVnodeVnodePort; -extern uint16_t tsMgmtMgmtPort; -extern uint16_t tsMgmtSyncPort; extern int tsStatusInterval; extern int tsShellActivityTimer; @@ -150,32 +142,30 @@ extern int tsTelegrafUseFieldNum; extern int tsTscEnableRecordSql; extern int tsAnyIp; -extern int tsIsCluster; extern char tsMonitorDbName[]; extern char tsInternalPass[]; extern int tsMonitorInterval; extern int tsNumOfLogLines; -extern uint32_t ddebugFlag; -extern uint32_t mdebugFlag; -extern uint32_t cdebugFlag; -extern uint32_t jnidebugFlag; -extern uint32_t tmrDebugFlag; -extern uint32_t sdbDebugFlag; -extern uint32_t httpDebugFlag; -extern uint32_t monitorDebugFlag; -extern uint32_t uDebugFlag; -extern uint32_t rpcDebugFlag; -extern uint32_t debugFlag; -extern uint32_t odbcdebugFlag; -extern uint32_t qdebugFlag; +extern int32_t ddebugFlag; +extern int32_t mdebugFlag; +extern int32_t cdebugFlag; +extern int32_t jnidebugFlag; +extern int32_t tmrDebugFlag; +extern int32_t sdbDebugFlag; +extern int32_t httpDebugFlag; +extern int32_t monitorDebugFlag; +extern int32_t uDebugFlag; +extern int32_t rpcDebugFlag; +extern int32_t debugFlag; +extern int32_t odbcdebugFlag; +extern int32_t qdebugFlag; extern uint32_t taosMaxTmrCtrl; extern int tsRpcTimer; extern int tsRpcMaxTime; -extern int tsRpcMaxUdpSize; extern int tsUdpDelay; extern char version[]; extern char compatible_version[]; @@ -187,80 +177,15 @@ extern char tsTimezone[64]; extern char tsLocale[64]; extern char tsCharset[64]; // default encode string -// -void tsReadGlobalLogConfig(); -bool tsReadGlobalConfig(); -int tsCfgDynamicOptions(char *msg); -void tsPrintGlobalConfig(); -void tsPrintGlobalConfigSpec(); -void tsSetAllDebugFlag(); -void tsSetTimeZone(); -void tsSetLocale(); -void tsInitGlobalConfig(); -void tsExpandFilePath(char* option_name, char* input_value); - -#define TSDB_CFG_CTYPE_B_CONFIG 1U // can be configured from file -#define TSDB_CFG_CTYPE_B_SHOW 2U // can displayed by "show configs" commands -#define TSDB_CFG_CTYPE_B_LOG 4U // is a log type configuration -#define TSDB_CFG_CTYPE_B_CLIENT 8U // can be displayed in the client log -#define TSDB_CFG_CTYPE_B_OPTION 16U // can be configured by taos_options function -#define TSDB_CFG_CTYPE_B_NOT_PRINT 32U // such as password -#define TSDB_CFG_CTYPE_B_LITE 64U // is a lite type configuration -#define TSDB_CFG_CTYPE_B_CLUSTER 128U // is a cluster type configuration - -#define TSDB_CFG_CSTATUS_NONE 0 // not configured -#define TSDB_CFG_CSTATUS_DEFAULT 1 // use system default value -#define TSDB_CFG_CSTATUS_FILE 2 // configured from file -#define TSDB_CFG_CSTATUS_OPTION 3 // configured by taos_options function -#define TSDB_CFG_CSTATUS_ARG 4 // configured by program argument - -enum { - TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_VTYPE_INT, - TSDB_CFG_VTYPE_UINT, - TSDB_CFG_VTYPE_FLOAT, - TSDB_CFG_VTYPE_STRING, - TSDB_CFG_VTYPE_IPSTR, - TSDB_CFG_VTYPE_DIRECTORY, -}; - -enum { - TSDB_CFG_UTYPE_NONE, - TSDB_CFG_UTYPE_PERCENT, - TSDB_CFG_UTYPE_GB, - TSDB_CFG_UTYPE_MB, - TSDB_CFG_UTYPE_Mb, - TSDB_CFG_UTYPE_BYTE, - TSDB_CFG_UTYPE_SECOND, - TSDB_CFG_UTYPE_MS -}; - -typedef struct { - char * option; - void * ptr; - float minValue; - float maxValue; - int8_t cfgType; - int8_t cfgStatus; - int8_t unitType; - int8_t valType; - uint32_t ptrLength; -} SGlobalConfig; - -extern SGlobalConfig *tsGlobalConfig; -extern int tsGlobalConfigNum; -extern char * tsCfgStatusStr[]; -SGlobalConfig *tsGetConfigOption(const char *option); - -#define TSDB_CFG_MAX_NUM 110 -#define TSDB_CFG_PRINT_LEN 23 -#define TSDB_CFG_OPTION_LEN 24 -#define TSDB_CFG_VALUE_LEN 41 - #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) +void taosInitGlobalCfg(); +bool taosCheckGlobalCfg(); +void taosSetAllDebugFlag(); +bool taosCfgDynamicOptions(char *msg); + #ifdef __cplusplus } #endif -#endif // TDENGINE_TGLOBALCFG_H +#endif diff --git a/src/common/inc/tlocale.h b/src/common/inc/tlocale.h new file mode 100644 index 0000000000..91ae386622 --- /dev/null +++ b/src/common/inc/tlocale.h @@ -0,0 +1,29 @@ +/* + * 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_COMMON_LOCALE_H +#define TDENGINE_COMMON_LOCALE_H + +#ifdef __cplusplus +extern "C" { +#endif + +void tsSetLocale(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/common/inc/name.h b/src/common/inc/tname.h similarity index 100% rename from src/common/inc/name.h rename to src/common/inc/tname.h diff --git a/src/util/inc/tsystem.h b/src/common/inc/tsystem.h similarity index 91% rename from src/util/inc/tsystem.h rename to src/common/inc/tsystem.h index 3ffa231296..93d305e49c 100644 --- a/src/util/inc/tsystem.h +++ b/src/common/inc/tsystem.h @@ -20,22 +20,16 @@ extern "C" { #endif -#include -#include - -extern char dataDir[]; - bool taosGetSysMemory(float *memoryUsedMB); - bool taosGetProcMemory(float *memoryUsedMB); - bool taosGetDisk(); - bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage); - bool taosGetBandSpeed(float *bandSpeedKb); - bool taosGetProcIO(float *readKB, float *writeKB); +void taosGetSystemInfo(); +void taosPrintOsInfo(); +void taosKillSystem(); +void taosSetCoreDump(); #ifdef __cplusplus } diff --git a/src/common/inc/ttimezone.h b/src/common/inc/ttimezone.h new file mode 100644 index 0000000000..0ae983dba0 --- /dev/null +++ b/src/common/inc/ttimezone.h @@ -0,0 +1,29 @@ +/* + * 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_COMMON_TIMEZONE_H +#define TDENGINE_COMMON_TIMEZONE_H + +#ifdef __cplusplus +extern "C" { +#endif + +void tsSetTimeZone(); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/common/inc/tulog.h b/src/common/inc/tulog.h new file mode 100644 index 0000000000..34b6ba7ae8 --- /dev/null +++ b/src/common/inc/tulog.h @@ -0,0 +1,51 @@ +/* + * 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_COMMON_ULOG_H +#define TDENGINE_COMMON_ULOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tlog.h" + +extern int32_t uDebugFlag; +extern int32_t tscEmbedded; + +#define uError(...) \ + if (uDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("ERROR UTL ", uDebugFlag, __VA_ARGS__); \ + } +#define uWarn(...) \ + if (uDebugFlag & DEBUG_WARN) { \ + taosPrintLog("WARN UTL ", uDebugFlag, __VA_ARGS__); \ + } +#define uTrace(...) \ + if (uDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("UTL ", uDebugFlag, __VA_ARGS__); \ + } +#define uDump(x, y) \ + if (uDebugFlag & DEBUG_DUMP) { \ + taosDumpData(x, y); \ + } +#define uPrint(...) \ + { taosPrintLog("UTL ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); } + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/common/src/dataformat.c b/src/common/src/tdataformat.c similarity index 99% rename from src/common/src/dataformat.c rename to src/common/src/tdataformat.c index fb20892452..aff6d7f773 100644 --- a/src/common/src/dataformat.c +++ b/src/common/src/tdataformat.c @@ -12,7 +12,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "dataformat.h" +#include "tdataformat.h" #include "tutil.h" static int tdFLenFromSchema(STSchema *pSchema); diff --git a/src/common/src/tglobal.c b/src/common/src/tglobal.c new file mode 100644 index 0000000000..2965117d2d --- /dev/null +++ b/src/common/src/tglobal.c @@ -0,0 +1,1364 @@ +/* + * 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" +#include "taosdef.h" +#include "taoserror.h" +#include "tulog.h" +#include "tconfig.h" +#include "tglobal.h" +#include "monitor.h" +#include "tsocket.h" +#include "tutil.h" +#include "tlocale.h" +#include "ttimezone.h" + +char configDir[TSDB_FILENAME_LEN] = "/etc/taos"; +char tsVnodeDir[TSDB_FILENAME_LEN] = {0}; +char tsDnodeDir[TSDB_FILENAME_LEN] = {0}; +char tsMnodeDir[TSDB_FILENAME_LEN] = {0}; +char dataDir[TSDB_FILENAME_LEN] = "/var/lib/taos"; +char scriptDir[TSDB_FILENAME_LEN] = "/etc/taos"; +char osName[10] = "Linux"; + +// system info, not configurable +int64_t tsPageSize; +int64_t tsOpenMax; +int64_t tsStreamMax; +int32_t tsNumOfCores = 1; +int32_t tsAlternativeRole = 0; +float tsTotalTmpDirGB = 0; +float tsTotalDataDirGB = 0; +float tsAvailTmpDirGB = 0; +float tsAvailDataDirGB = 0; +float tsMinimalTmpDirGB = 0.1; +float tsMinimalDataDirGB = 0.5; +int32_t tsTotalMemoryMB = 0; +int32_t tsVersion = 0; +int32_t tsEnableCoreFile = 0; + +// global, not configurable +int32_t tscEmbedded = 0; + +/* + * minmum scale for whole system, millisecond by default + * for TSDB_TIME_PRECISION_MILLI: 86400000L + * TSDB_TIME_PRECISION_MICRO: 86400000000L + */ +int64_t tsMsPerDay[] = {86400000L, 86400000000L}; + +char tsMasterIp[TSDB_IPv4ADDR_LEN] = {0}; +char tsSecondIp[TSDB_IPv4ADDR_LEN] = {0}; +uint16_t tsMnodeShellPort = 6030; // udp[6030-6034] tcp[6030] +uint16_t tsDnodeShellPort = 6035; // udp[6035-6039] tcp[6035] +uint16_t tsMnodeDnodePort = 6040; // udp/tcp +uint16_t tsDnodeMnodePort = 6041; // udp/tcp + +int32_t tsStatusInterval = 1; // second +int32_t tsShellActivityTimer = 3; // second +int32_t tsVnodePeerHBTimer = 1; // second +int32_t tsMgmtPeerHBTimer = 1; // second +int32_t tsMeterMetaKeepTimer = 7200; // second +int32_t tsMetricMetaKeepTimer = 600; // second +int tsRpcTimer = 300; +int tsRpcMaxTime = 600; // seconds; + +float tsNumOfThreadsPerCore = 1.0; +float tsRatioOfQueryThreads = 0.5; +char tsPublicIp[TSDB_IPv4ADDR_LEN] = {0}; +char tsPrivateIp[TSDB_IPv4ADDR_LEN] = {0}; +int16_t tsNumOfVnodesPerCore = 8; +int16_t tsNumOfTotalVnodes = TSDB_INVALID_VNODE_NUM; +int16_t tsCheckHeaderFile = 0; + +#ifdef _TD_ARM_32_ +int32_t tsSessionsPerVnode = 100; +#else +int32_t tsSessionsPerVnode = 1000; +#endif + +int32_t tsCacheBlockSize = 16384; // 256 columns +int32_t tsAverageCacheBlocks = TSDB_DEFAULT_AVG_BLOCKS; +/** + * Change the meaning of affected rows: + * 0: affected rows not include those duplicate records + * 1: affected rows include those duplicate records + */ +int16_t tsAffectedRowsMod = 0; + +int32_t tsRowsInFileBlock = 4096; +float tsFileBlockMinPercent = 0.05; + +int16_t tsNumOfBlocksPerMeter = 100; +int16_t tsCommitTime = 3600; // seconds +int16_t tsCommitLog = 1; +int16_t tsCompression = TSDB_MAX_COMPRESSION_LEVEL; +int16_t tsDaysPerFile = 10; +int32_t tsDaysToKeep = 3650; +int32_t tsReplications = TSDB_REPLICA_MIN_NUM; + +int32_t tsNumOfMPeers = 3; +int32_t tsMaxShellConns = 2000; +int32_t tsMaxTables = 100000; + +char tsLocalIp[TSDB_IPv4ADDR_LEN] = {0}; +char tsDefaultDB[TSDB_DB_NAME_LEN] = {0}; +char tsDefaultUser[64] = "root"; +char tsDefaultPass[64] = "taosdata"; +int32_t tsMaxMeterConnections = 10000; +int32_t tsMaxMgmtConnections = 2000; +int32_t tsMaxVnodeConnections = 10000; + +int32_t tsBalanceMonitorInterval = 2; // seconds +int32_t tsBalanceStartInterval = 300; // seconds +int32_t tsBalancePolicy = 0; // 1-use sys.montor +int32_t tsOfflineThreshold = 864000; // seconds 10days +int32_t tsMgmtEqualVnodeNum = 4; + +int32_t tsEnableHttpModule = 1; +int32_t tsEnableMonitorModule = 0; +int32_t tsRestRowLimit = 10240; +int32_t tsMaxSQLStringLen = TSDB_MAX_SQL_LEN; + +int32_t mdebugFlag = 135; +int32_t sdbDebugFlag = 135; +int32_t ddebugFlag = 131; +int32_t cdebugFlag = 131; +int32_t jnidebugFlag = 131; +int32_t odbcdebugFlag = 131; +int32_t httpDebugFlag = 131; +int32_t monitorDebugFlag = 131; +int32_t qdebugFlag = 131; +int32_t rpcDebugFlag = 131; +int32_t uDebugFlag = 131; +int32_t debugFlag = 131; +int tsNumOfLogLines = 10000000; + +// the maximum number of results for projection query on super table that are returned from +// one virtual node, to order according to timestamp +int32_t tsMaxNumOfOrderedResults = 100000; + +/* + * denote if the server needs to compress response message at the application layer to client, including query rsp, + * metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server. + * + * 0: all data are compressed + * -1: all data are not compressed + * other values: if the message payload size is greater than the tsCompressMsgSize, the message will be compressed. + */ +int32_t tsCompressMsgSize = -1; + +// use UDP by default[option: udp, tcp] +char tsSocketType[4] = "udp"; + +// time precision, millisecond by default +int32_t tsTimePrecision = TSDB_TIME_PRECISION_MILLI; + +// 10 ms for sliding time, the value will changed in case of time precision changed +int32_t tsMinSlidingTime = 10; + +// 10 ms for interval time range, changed accordingly +int32_t tsMinIntervalTime = 10; + +// 20sec, the maximum value of stream computing delay, changed accordingly +int32_t tsMaxStreamComputDelay = 20000; + +// 10sec, the first stream computing delay time after system launched successfully, changed accordingly +int32_t tsStreamCompStartDelay = 10000; + +// the stream computing delay time after executing failed, change accordingly +int32_t tsStreamCompRetryDelay = 10; + +// The delayed computing ration. 10% of the whole computing time window by default. +float tsStreamComputDelayRatio = 0.1; + +int32_t tsProjectExecInterval = 10000; // every 10sec, the projection will be executed once +int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance + +char tsHttpIp[TSDB_IPv4ADDR_LEN] = "0.0.0.0"; +uint16_t tsHttpPort = 6020; // only tcp, range tcp[6020] +// uint16_t tsNginxPort = 6060; //only tcp, range tcp[6060] +int32_t tsHttpCacheSessions = 100; +int32_t tsHttpSessionExpire = 36000; +int32_t tsHttpMaxThreads = 2; +int32_t tsHttpEnableCompress = 0; +int32_t tsHttpEnableRecordSql = 0; +int32_t tsTelegrafUseFieldNum = 0; + +int32_t tsTscEnableRecordSql = 0; +int32_t tsAnyIp = 1; +uint32_t tsPublicIpInt = 0; + +char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log"; +char tsInternalPass[] = "secretkey"; +int32_t tsMonitorInterval = 30; // seconds + +char tsTimezone[64] = {0}; +char tsLocale[TSDB_LOCALE_LEN] = {0}; +char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string + +static pthread_once_t tsInitGlobalCfgOnce = PTHREAD_ONCE_INIT; + +void taosSetAllDebugFlag() { + for (int32_t i = 0; i < tsGlobalConfigNum; ++i) { + SGlobalCfg *cfg = &tsGlobalConfig[i]; + if ((cfg->cfgType & TSDB_CFG_CTYPE_B_LOG) && cfg->cfgType == TAOS_CFG_VTYPE_INT32) { + *((int32_t*)cfg->ptr) = debugFlag; + } + } + uPrint("all debug flag are set to %d", debugFlag); +} + +bool taosCfgDynamicOptions(char *msg) { + char *option, *value; + int32_t olen, vlen; + int32_t vint = 0; + + paGetToken(msg, &option, &olen); + if (olen == 0) return TSDB_CODE_INVALID_MSG_CONTENT; + + paGetToken(option + olen + 1, &value, &vlen); + if (vlen == 0) + vint = 135; + else { + vint = atoi(value); + } + + uPrint("change dynamic option: %s, value: %d", option, vint); + + for (int32_t i = 0; i < tsGlobalConfigNum; ++i) { + SGlobalCfg *cfg = tsGlobalConfig + i; + if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue; + if (cfg->valType != TAOS_CFG_VTYPE_INT32) continue; + if (strncasecmp(option, cfg->option, olen) != 0) continue; + *((int32_t *)cfg->ptr) = vint; + + if (strncasecmp(cfg->option, "monitor", olen) == 0) { + // if (0 == vint) { + // monitorStartSystem(); + // } else { + // monitorStopSystem(); + // } + return true; + } + + if (strncasecmp(cfg->option, "debugFlag", olen) == 0) { + taosSetAllDebugFlag(); + } + + return true; + } + + if (strncasecmp(option, "resetlog", 8) == 0) { + taosResetLog(); + taosPrintGlobalCfg(); + return true; + } + + if (strncasecmp(option, "resetQueryCache", 15) == 0) { + uError("reset query cache can't be executed, for monitor not initialized"); + } + + return false; +} + +static void doInitGlobalConfig() { + SGlobalCfg cfg = {0}; + + // ip address + cfg.option = "masterIp"; + cfg.ptr = tsMasterIp; + cfg.valType = TAOS_CFG_VTYPE_IPSTR; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_IPv4ADDR_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "secondIp"; + cfg.ptr = tsSecondIp; + cfg.valType = TAOS_CFG_VTYPE_IPSTR; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_IPv4ADDR_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "publicIp"; + cfg.ptr = tsPublicIp; + cfg.valType = TAOS_CFG_VTYPE_IPSTR; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_IPv4ADDR_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "privateIp"; + cfg.ptr = tsPrivateIp; + cfg.valType = TAOS_CFG_VTYPE_IPSTR; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_IPv4ADDR_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "localIp"; + cfg.ptr = tsLocalIp; + cfg.valType = TAOS_CFG_VTYPE_IPSTR; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_IPv4ADDR_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "httpIp"; + cfg.ptr = tsHttpIp; + cfg.valType = TAOS_CFG_VTYPE_IPSTR; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_IPv4ADDR_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // port + cfg.option = "mnodeShellPort"; + cfg.ptr = &tsMnodeShellPort; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 1; + cfg.maxValue = 65535; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "dnodeShellPort"; + cfg.ptr = &tsDnodeShellPort; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 1; + cfg.maxValue = 65535; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "mnodeDnodePort"; + cfg.ptr = &tsMnodeDnodePort; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 65535; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "dnodeMnodePort"; + cfg.ptr = &tsDnodeMnodePort; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 65535; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // cfg.option = "syncPort"; + // cfg.ptr = &syncPort; + // cfg.valType = TAOS_CFG_VTYPE_INT16; + // cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + // cfg.minValue = 1; + // cfg.maxValue = 65535; + // cfg.ptrLength = 0; + // cfg.unitType = TAOS_CFG_UTYPE_NONE; + // taosInitConfigOption(cfg); + + cfg.option = "httpPort"; + cfg.ptr = &tsHttpPort; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 65535; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // directory + cfg.option = "configDir"; + cfg.ptr = configDir; + cfg.valType = TAOS_CFG_VTYPE_DIRECTORY; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_FILENAME_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "logDir"; + cfg.ptr = logDir; + cfg.valType = TAOS_CFG_VTYPE_DIRECTORY; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_LOG; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_FILENAME_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "scriptDir"; + cfg.ptr = scriptDir; + cfg.valType = TAOS_CFG_VTYPE_DIRECTORY; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_FILENAME_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "dataDir"; + cfg.ptr = dataDir; + cfg.valType = TAOS_CFG_VTYPE_DIRECTORY; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_FILENAME_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // dnode configs + cfg.option = "numOfThreadsPerCore"; + cfg.ptr = &tsNumOfThreadsPerCore; + cfg.valType = TAOS_CFG_VTYPE_FLOAT; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 10; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "ratioOfQueryThreads"; + cfg.ptr = &tsRatioOfQueryThreads; + cfg.valType = TAOS_CFG_VTYPE_FLOAT; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0.1; + cfg.maxValue = 0.9; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "numOfVnodesPerCore"; + cfg.ptr = &tsNumOfVnodesPerCore; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 64; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "numOfTotalVnodes"; + cfg.ptr = &tsNumOfTotalVnodes; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = TSDB_MAX_VNODES; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "numOfMPeers"; + cfg.ptr = &tsNumOfMPeers; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 3; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "balanceInterval"; + cfg.ptr = &tsBalanceStartInterval; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 30000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // 0-any; 1-mgmt; 2-dnode + cfg.option = "alternativeRole"; + cfg.ptr = &tsAlternativeRole; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 2; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "affectedRowsMod"; + cfg.ptr = &tsAffectedRowsMod; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // timer + cfg.option = "maxTmrCtrl"; + cfg.ptr = &taosMaxTmrCtrl; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 8; + cfg.maxValue = 2048; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "monitorInterval"; + cfg.ptr = &tsMonitorInterval; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 1; + cfg.maxValue = 600; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_SECOND; + taosInitConfigOption(cfg); + + cfg.option = "offlineThreshold"; + cfg.ptr = &tsOfflineThreshold; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 5; + cfg.maxValue = 7200000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_SECOND; + taosInitConfigOption(cfg); + + cfg.option = "rpcTimer"; + cfg.ptr = &tsRpcTimer; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 100; + cfg.maxValue = 3000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_MS; + taosInitConfigOption(cfg); + + cfg.option = "rpcMaxTime"; + cfg.ptr = &tsRpcMaxTime; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 100; + cfg.maxValue = 7200; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_SECOND; + taosInitConfigOption(cfg); + + cfg.option = "ctime"; + cfg.ptr = &tsCommitTime; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 30; + cfg.maxValue = 40960; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_SECOND; + taosInitConfigOption(cfg); + + cfg.option = "statusInterval"; + cfg.ptr = &tsStatusInterval; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 10; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_SECOND; + taosInitConfigOption(cfg); + + cfg.option = "shellActivityTimer"; + cfg.ptr = &tsShellActivityTimer; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 1; + cfg.maxValue = 120; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_SECOND; + taosInitConfigOption(cfg); + + cfg.option = "meterMetaKeepTimer"; + cfg.ptr = &tsMeterMetaKeepTimer; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 1; + cfg.maxValue = 8640000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_SECOND; + taosInitConfigOption(cfg); + + cfg.option = "metricMetaKeepTimer"; + cfg.ptr = &tsMetricMetaKeepTimer; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 1; + cfg.maxValue = 8640000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_SECOND; + taosInitConfigOption(cfg); + + cfg.option = "minSlidingTime"; + cfg.ptr = &tsMinSlidingTime; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 10; + cfg.maxValue = 1000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_MS; + taosInitConfigOption(cfg); + + cfg.option = "minIntervalTime"; + cfg.ptr = &tsMinIntervalTime; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 10; + cfg.maxValue = 1000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_MS; + taosInitConfigOption(cfg); + + cfg.option = "maxStreamCompDelay"; + cfg.ptr = &tsMaxStreamComputDelay; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 10; + cfg.maxValue = 1000000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_MS; + taosInitConfigOption(cfg); + + cfg.option = "maxFirstStreamCompDelay"; + cfg.ptr = &tsStreamCompStartDelay; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1000; + cfg.maxValue = 1000000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_MS; + taosInitConfigOption(cfg); + + cfg.option = "retryStreamCompDelay"; + cfg.ptr = &tsStreamCompRetryDelay; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 10; + cfg.maxValue = 1000000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_MS; + + taosInitConfigOption(cfg); + cfg.option = "streamCompDelayRatio"; + cfg.ptr = &tsStreamComputDelayRatio; + cfg.valType = TAOS_CFG_VTYPE_FLOAT; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0.1; + cfg.maxValue = 0.9; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // database configs + cfg.option = "clog"; + cfg.ptr = &tsCommitLog; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 2; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "comp"; + cfg.ptr = &tsCompression; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 2; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "days"; + cfg.ptr = &tsDaysPerFile; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 365; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "keep"; + cfg.ptr = &tsDaysToKeep; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 365000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "replica"; + cfg.ptr = &tsReplications; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 1; + cfg.maxValue = 3; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "tables"; + cfg.ptr = &tsSessionsPerVnode; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = TSDB_MIN_TABLES_PER_VNODE; + cfg.maxValue = TSDB_MAX_TABLES_PER_VNODE; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "cache"; + cfg.ptr = &tsCacheBlockSize; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 100; + cfg.maxValue = 1048576; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_BYTE; + taosInitConfigOption(cfg); + + cfg.option = "rows"; + cfg.ptr = &tsRowsInFileBlock; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 200; + cfg.maxValue = 1048576; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "fileBlockMinPercent"; + cfg.ptr = &tsFileBlockMinPercent; + cfg.valType = TAOS_CFG_VTYPE_FLOAT; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 1.0; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "ablocks"; + cfg.ptr = &tsAverageCacheBlocks; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = TSDB_MIN_AVG_BLOCKS; + cfg.maxValue = TSDB_MAX_AVG_BLOCKS; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "tblocks"; + cfg.ptr = &tsNumOfBlocksPerMeter; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 32; + cfg.maxValue = 4096; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // login configs + cfg.option = "defaultDB"; + cfg.ptr = tsDefaultDB; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_DB_NAME_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "defaultUser"; + cfg.ptr = tsDefaultUser; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_USER_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "defaultPass"; + cfg.ptr = tsDefaultPass; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_NOT_PRINT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_PASSWORD_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // socket type; udp by default + cfg.option = "sockettype"; + cfg.ptr = tsSocketType; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = 3; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "compressMsgSize"; + cfg.ptr = &tsCompressMsgSize; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = -1; + cfg.maxValue = 10000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "maxSQLLength"; + cfg.ptr = &tsMaxSQLStringLen; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = TSDB_MAX_SQL_LEN; + cfg.maxValue = TSDB_MAX_ALLOWED_SQL_LEN; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_BYTE; + taosInitConfigOption(cfg); + + cfg.option = "maxNumOfOrderedRes"; + cfg.ptr = &tsMaxNumOfOrderedResults; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = TSDB_MAX_SQL_LEN; + cfg.maxValue = TSDB_MAX_ALLOWED_SQL_LEN; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // locale & charset + cfg.option = "timezone"; + cfg.ptr = tsTimezone; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = tListLen(tsTimezone); + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "locale"; + cfg.ptr = tsLocale; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = tListLen(tsLocale); + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "charset"; + cfg.ptr = tsCharset; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = tListLen(tsCharset); + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // connect configs + cfg.option = "maxShellConns"; + cfg.ptr = &tsMaxShellConns; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 10; + cfg.maxValue = 50000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "maxMeterConnections"; + cfg.ptr = &tsMaxMeterConnections; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 10; + cfg.maxValue = 50000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "maxMgmtConnections"; + cfg.ptr = &tsMaxMgmtConnections; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 10; + cfg.maxValue = 50000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "maxVnodeConnections"; + cfg.ptr = &tsMaxVnodeConnections; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 10; + cfg.maxValue = 50000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "minimalLogDirGB"; + cfg.ptr = &tsMinimalLogDirGB; + cfg.valType = TAOS_CFG_VTYPE_FLOAT; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0.001; + cfg.maxValue = 10000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_GB; + taosInitConfigOption(cfg); + + cfg.option = "minimalTmpDirGB"; + cfg.ptr = &tsMinimalTmpDirGB; + cfg.valType = TAOS_CFG_VTYPE_FLOAT; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0.001; + cfg.maxValue = 10000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_GB; + taosInitConfigOption(cfg); + + cfg.option = "minimalDataDirGB"; + cfg.ptr = &tsMinimalDataDirGB; + cfg.valType = TAOS_CFG_VTYPE_FLOAT; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0.001; + cfg.maxValue = 10000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_GB; + taosInitConfigOption(cfg); + + // module configs + cfg.option = "mgmtEqualVnodeNum"; + cfg.ptr = &tsMgmtEqualVnodeNum; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 1000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "http"; + cfg.ptr = &tsEnableHttpModule; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 1; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "monitor"; + cfg.ptr = &tsEnableMonitorModule; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 1; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "monitorDbName"; + cfg.ptr = tsMonitorDbName; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = TSDB_DB_NAME_LEN; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // http configs + cfg.option = "httpCacheSessions"; + cfg.ptr = &tsHttpCacheSessions; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 1; + cfg.maxValue = 100000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "httpEnableRecordSql"; + cfg.ptr = &tsHttpEnableRecordSql; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "telegrafUseFieldNum"; + cfg.ptr = &tsTelegrafUseFieldNum; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 1; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "httpMaxThreads"; + cfg.ptr = &tsHttpMaxThreads; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 1; + cfg.maxValue = 1000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "restfulRowLimit"; + cfg.ptr = &tsRestRowLimit; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 1; + cfg.maxValue = 10000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "httpEnableCompress"; + cfg.ptr = &tsHttpEnableCompress; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 1; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // debug flag + cfg.option = "numOfLogLines"; + cfg.ptr = &tsNumOfLogLines; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 10000; + cfg.maxValue = 2000000000; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "asyncLog"; + cfg.ptr = &tsAsyncLog; + cfg.valType = TAOS_CFG_VTYPE_INT16; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "debugFlag"; + cfg.ptr = &debugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "mDebugFlag"; + cfg.ptr = &mdebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "dDebugFlag"; + cfg.ptr = &ddebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "sdbDebugFlag"; + cfg.ptr = &sdbDebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "rpcDebugFlag"; + cfg.ptr = &rpcDebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "tmrDebugFlag"; + cfg.ptr = &tmrDebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "cDebugFlag"; + cfg.ptr = &cdebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "jniDebugFlag"; + cfg.ptr = &jnidebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "odbcDebugFlag"; + cfg.ptr = &odbcdebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "uDebugFlag"; + cfg.ptr = &uDebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "httpDebugFlag"; + cfg.ptr = &httpDebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "monitorDebugFlag"; + cfg.ptr = &monitorDebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "qDebugFlag"; + cfg.ptr = &qdebugFlag; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 255; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "tscEnableRecordSql"; + cfg.ptr = &tsTscEnableRecordSql; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "enableCoreFile"; + cfg.ptr = &tsEnableCoreFile; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "anyIp"; + cfg.ptr = &tsAnyIp; + cfg.valType = TAOS_CFG_VTYPE_INT32; + cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; + cfg.minValue = 0; + cfg.maxValue = 1; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + // version info + cfg.option = "gitinfo"; + cfg.ptr = gitinfo; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "gitinfoOfInternal"; + cfg.ptr = gitinfoOfInternal; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "buildinfo"; + cfg.ptr = buildinfo; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); + + cfg.option = "version"; + cfg.ptr = version; + cfg.valType = TAOS_CFG_VTYPE_STRING; + cfg.cfgType = TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT; + cfg.minValue = 0; + cfg.maxValue = 0; + cfg.ptrLength = 0; + cfg.unitType = TAOS_CFG_UTYPE_NONE; + taosInitConfigOption(cfg); +} + +void taosInitGlobalCfg() { + pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig); +} + +bool taosCheckGlobalCfg() { + if (tsPrivateIp[0] == 0) { + taosGetPrivateIp(tsPrivateIp); + } + + if (tsPublicIp[0] == 0) { + strcpy(tsPublicIp, tsPrivateIp); + } + tsPublicIpInt = inet_addr(tsPublicIp); + + if (tsLocalIp[0] == 0) { + strcpy(tsLocalIp, tsPrivateIp); + } + + if (tsMasterIp[0] == 0) { + strcpy(tsMasterIp, tsPrivateIp); + } + + if (tsSecondIp[0] == 0) { + strcpy(tsSecondIp, tsMasterIp); + } + + taosGetSystemInfo(); + + tsSetLocale(); + + SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); + if (cfg_timezone && cfg_timezone->cfgStatus == TAOS_CFG_CSTATUS_FILE) { + tsSetTimeZone(); + } + + if (tsNumOfCores <= 0) { + tsNumOfCores = 1; + } + + if (tsNumOfTotalVnodes == TSDB_INVALID_VNODE_NUM) { + tsNumOfTotalVnodes = tsNumOfCores * tsNumOfVnodesPerCore; + tsNumOfTotalVnodes = tsNumOfTotalVnodes > TSDB_MAX_VNODES ? TSDB_MAX_VNODES : tsNumOfTotalVnodes; + tsNumOfTotalVnodes = tsNumOfTotalVnodes < TSDB_MIN_VNODES ? TSDB_MIN_VNODES : tsNumOfTotalVnodes; + } + + if (strlen(tsPrivateIp) == 0) { + uError("privateIp is null"); + return false; + } + + if (tscEmbedded) { + strcpy(tsLocalIp, tsPrivateIp); + } + + // todo refactor + tsVersion = 0; + for (int i = 0; i < 10; i++) { + if (version[i] >= '0' && version[i] <= '9') { + tsVersion = tsVersion * 10 + (version[i] - '0'); + } else if (version[i] == 0) { + break; + } + } + + tsVersion = 10 * tsVersion; + + return true; +} diff --git a/src/common/src/tlocale.c b/src/common/src/tlocale.c new file mode 100644 index 0000000000..35a68218f1 --- /dev/null +++ b/src/common/src/tlocale.c @@ -0,0 +1,53 @@ +/* + * 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" +#include "tulog.h" +#include "tglobal.h" +#include "tconfig.h" +#include "tutil.h" + +/** + * In some Linux systems, setLocale(LC_CTYPE, "") may return NULL, in which case the launch of + * both the TDengine Server and the Client may be interrupted. + * + * In case that the setLocale failed to be executed, the right charset needs to be set. + */ +void tsSetLocale() { + char msgLocale[] = "Invalid locale:%s, please set the valid locale in config file\n"; + char msgCharset[] = "Invalid charset:%s, please set the valid charset in config file\n"; + char msgCharset1[] = "failed to get charset, please set the valid charset in config file\n"; + + char *locale = setlocale(LC_CTYPE, tsLocale); + + // default locale or user specified locale is not valid, abort launch + if (locale == NULL) { + printf(msgLocale, tsLocale); + uPrint(msgLocale, tsLocale); + } + + if (strlen(tsCharset) == 0) { + printf("%s\n", msgCharset1); + uPrint(msgCharset1); + exit(-1); + } + + if (!taosValidateEncodec(tsCharset)) { + printf(msgCharset, tsCharset); + uPrint(msgCharset, tsCharset); + exit(-1); + } +} \ No newline at end of file diff --git a/src/common/src/name.c b/src/common/src/tname.c similarity index 98% rename from src/common/src/name.c rename to src/common/src/tname.c index a605b98a14..822d612243 100644 --- a/src/common/src/name.c +++ b/src/common/src/tname.c @@ -1,7 +1,7 @@ #include "os.h" #include "tutil.h" -#include "name.h" +#include "tname.h" #include "tstoken.h" #include "ttokendef.h" diff --git a/src/common/src/ttimezone.c b/src/common/src/ttimezone.c new file mode 100644 index 0000000000..0e8e1316b3 --- /dev/null +++ b/src/common/src/ttimezone.c @@ -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 . + */ + +#define _DEFAULT_SOURCE +#include "os.h" +#include "tulog.h" +#include "tglobal.h" +#include "tconfig.h" +#include "tutil.h" + +void tsSetTimeZone() { + SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); + uPrint("timezone is set to %s by %s", tsTimezone, tsCfgStatusStr[cfg_timezone->cfgStatus]); + +#ifdef WINDOWS + char winStr[TSDB_LOCALE_LEN * 2]; + sprintf(winStr, "TZ=%s", tsTimezone); + putenv(winStr); +#else + setenv("TZ", tsTimezone, 1); +#endif + tzset(); + + /* + * get CURRENT time zone. + * system current time zone is affected by daylight saving time(DST) + * + * e.g., the local time zone of London in DST is GMT+01:00, + * otherwise is GMT+00:00 + */ +#ifdef _MSC_VER +#if _MSC_VER >= 1900 + // see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019 + int64_t timezone = _timezone; + int32_t daylight = _daylight; + char **tzname = _tzname; +#endif +#endif + + int32_t tz = (-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR; + tz += daylight; + + /* + * format: + * (CST, +0800) + * (BST, +0100) + */ + sprintf(tsTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); + + uPrint("timezone format changed to %s", tsTimezone); +} diff --git a/src/dnode/inc/dnodeLog.h b/src/dnode/inc/dnodeLog.h new file mode 100644 index 0000000000..380e93dd7b --- /dev/null +++ b/src/dnode/inc/dnodeLog.h @@ -0,0 +1,50 @@ +/* + * 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_DNODE_LOG_H +#define TDENGINE_DNODE_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tlog.h" + +extern int32_t ddebugFlag; + +#define dError(...) \ + if (ddebugFlag & DEBUG_ERROR) { \ + taosPrintLog("ERROR DND ", 255, __VA_ARGS__); \ + } +#define dWarn(...) \ + if (ddebugFlag & DEBUG_WARN) { \ + taosPrintLog("WARN DND ", ddebugFlag, __VA_ARGS__); \ + } +#define dTrace(...) \ + if (ddebugFlag & DEBUG_TRACE) { \ + taosPrintLog("DND ", ddebugFlag, __VA_ARGS__); \ + } +#define dPrint(...) \ + { taosPrintLog("DND ", 255, __VA_ARGS__); } + +#define dLError(...) taosLogError(__VA_ARGS__) dError(__VA_ARGS__) +#define dLWarn(...) taosLogWarn(__VA_ARGS__) dWarn(__VA_ARGS__) +#define dLPrint(...) taosLogPrint(__VA_ARGS__) dPrint(__VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/dnode/src/dnodeMClient.c b/src/dnode/src/dnodeMClient.c index 38be318c25..fcf1f477b2 100644 --- a/src/dnode/src/dnodeMClient.c +++ b/src/dnode/src/dnodeMClient.c @@ -17,16 +17,17 @@ #include "os.h" #include "cJSON.h" #include "taosmsg.h" -#include "tlog.h" #include "trpc.h" #include "tutil.h" #include "tsync.h" #include "ttime.h" #include "ttimer.h" #include "tbalance.h" +#include "tglobal.h" #include "vnode.h" #include "mnode.h" #include "dnode.h" +#include "dnodeLog.h" #include "dnodeMClient.h" #include "dnodeModule.h" #include "dnodeMgmt.h" diff --git a/src/dnode/src/dnodeMain.c b/src/dnode/src/dnodeMain.c index a4e7b55995..b8ac9d1d4a 100644 --- a/src/dnode/src/dnodeMain.c +++ b/src/dnode/src/dnodeMain.c @@ -15,11 +15,13 @@ #define _DEFAULT_SOURCE #include "os.h" -#include "tglobalcfg.h" -#include "tlog.h" +#include "tglobal.h" #include "trpc.h" #include "tutil.h" +#include "tconfig.h" +#include "tglobal.h" #include "dnode.h" +#include "dnodeLog.h" #include "dnodeMClient.h" #include "dnodeMgmt.h" #include "dnodeMnode.h" @@ -50,7 +52,11 @@ int32_t main(int32_t argc, char *argv[]) { exit(EXIT_FAILURE); } } else if (strcmp(argv[i], "-V") == 0) { - char *versionStr = tsIsCluster ? "enterprise" : "community"; +#ifdef _SYNC + char *versionStr = "enterprise"; +#else + char *versionStr = "community"; +#endif printf("%s version: %s compatible_version: %s\n", versionStr, version, compatible_version); printf("gitinfo: %s\n", gitinfo); printf("gitinfoI: %s\n", gitinfoOfInternal); @@ -109,11 +115,11 @@ int32_t main(int32_t argc, char *argv[]) { static void signal_handler(int32_t signum, siginfo_t *sigInfo, void *context) { if (signum == SIGUSR1) { - tsCfgDynamicOptions("debugFlag 135"); + taosCfgDynamicOptions("debugFlag 135"); return; } if (signum == SIGUSR2) { - tsCfgDynamicOptions("resetlog"); + taosCfgDynamicOptions("resetlog"); return; } syslog(LOG_INFO, "Shut down signal is %d", signum); @@ -132,7 +138,8 @@ static int32_t dnodeInitSystem() { dnodeSetRunStatus(TSDB_DNODE_RUN_STATUS_INITIALIZE); tscEmbedded = 1; taosResolveCRC(); - tsReadGlobalLogConfig(); + taosInitGlobalCfg(); + taosReadGlobalLogCfg(); taosSetCoreDump(); signal(SIGPIPE, SIG_IGN); @@ -147,12 +154,12 @@ static int32_t dnodeInitSystem() { printf("failed to init log file\n"); } - if (!tsReadGlobalConfig()) { - tsPrintGlobalConfig(); + if (!taosReadGlobalCfg() || !taosCheckGlobalCfg()) { + taosPrintGlobalCfg(); dError("TDengine read global config failed"); return -1; } - tsPrintGlobalConfig(); + taosPrintGlobalCfg(); dPrint("Server IP address is:%s", tsPrivateIp); dPrint("starting to initialize TDengine ..."); @@ -185,7 +192,7 @@ static void dnodeCleanUpSystem() { dnodeCleanupRead(); dnodeCleanUpModules(); dnodeCleanupStorage(); - taosCloseLogger(); + taosCloseLog(); } } diff --git a/src/dnode/src/dnodeMgmt.c b/src/dnode/src/dnodeMgmt.c index 8f62e3adc0..7054cb8cd0 100644 --- a/src/dnode/src/dnodeMgmt.c +++ b/src/dnode/src/dnodeMgmt.c @@ -18,11 +18,12 @@ #include "ihash.h" #include "taoserror.h" #include "taosmsg.h" -#include "tlog.h" #include "trpc.h" #include "tsdb.h" #include "twal.h" #include "vnode.h" +#include "tglobal.h" +#include "dnodeLog.h" #include "dnodeMClient.h" #include "dnodeMgmt.h" #include "dnodeRead.h" @@ -180,5 +181,5 @@ static int32_t dnodeProcessAlterStreamMsg(SRpcMsg *pMsg) { static int32_t dnodeProcessConfigDnodeMsg(SRpcMsg *pMsg) { SMDCfgDnodeMsg *pCfg = (SMDCfgDnodeMsg *)pMsg->pCont; - return tsCfgDynamicOptions(pCfg->config); + return taosCfgDynamicOptions(pCfg->config); } diff --git a/src/dnode/src/dnodeMnode.c b/src/dnode/src/dnodeMnode.c index c19a63c0e7..0c16e0ca84 100644 --- a/src/dnode/src/dnodeMnode.c +++ b/src/dnode/src/dnodeMnode.c @@ -15,9 +15,10 @@ #include "os.h" #include "taosmsg.h" -#include "tlog.h" +#include "tglobal.h" #include "trpc.h" #include "dnode.h" +#include "dnodeLog.h" #include "dnodeMgmt.h" #include "dnodeWrite.h" diff --git a/src/dnode/src/dnodeModule.c b/src/dnode/src/dnodeModule.c index 57ef655078..815ecb089b 100644 --- a/src/dnode/src/dnodeModule.c +++ b/src/dnode/src/dnodeModule.c @@ -16,11 +16,11 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taosdef.h" -#include "tlog.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "mnode.h" #include "http.h" #include "monitor.h" +#include "dnodeLog.h" #include "dnodeModule.h" typedef struct { diff --git a/src/dnode/src/dnodeRead.c b/src/dnode/src/dnodeRead.c index 252eb0b3b6..e52b59d20a 100644 --- a/src/dnode/src/dnodeRead.c +++ b/src/dnode/src/dnodeRead.c @@ -17,10 +17,11 @@ #include "os.h" #include "taoserror.h" #include "taosmsg.h" -#include "tlog.h" #include "tqueue.h" #include "trpc.h" #include "twal.h" +#include "tglobal.h" +#include "dnodeLog.h" #include "dnodeMgmt.h" #include "dnodeRead.h" #include "vnode.h" diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 3681ef22c4..b1fe0594bc 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -18,9 +18,10 @@ #include "taoserror.h" #include "taosdef.h" #include "taosmsg.h" -#include "tlog.h" #include "trpc.h" +#include "tglobal.h" #include "dnode.h" +#include "dnodeLog.h" #include "dnodeRead.h" #include "dnodeWrite.h" #include "dnodeShell.h" diff --git a/src/dnode/src/dnodeWrite.c b/src/dnode/src/dnodeWrite.c index ee61d9c8b3..39757c690f 100644 --- a/src/dnode/src/dnodeWrite.c +++ b/src/dnode/src/dnodeWrite.c @@ -17,15 +17,16 @@ #include "os.h" #include "taosmsg.h" #include "taoserror.h" -#include "tlog.h" #include "tqueue.h" #include "trpc.h" #include "tsdb.h" #include "twal.h" -#include "dataformat.h" +#include "tglobal.h" +#include "vnode.h" +#include "tdataformat.h" +#include "dnodeLog.h" #include "dnodeWrite.h" #include "dnodeMgmt.h" -#include "vnode.h" typedef struct { taos_qall qall; diff --git a/src/inc/tsdb.h b/src/inc/tsdb.h index a31f4561ab..cd64f8e854 100644 --- a/src/inc/tsdb.h +++ b/src/inc/tsdb.h @@ -19,8 +19,8 @@ #include #include -#include "dataformat.h" -#include "name.h" +#include "tdataformat.h" +#include "tname.h" #include "taosdef.h" #include "taosmsg.h" #include "tarray.h" diff --git a/src/kit/shell/CMakeLists.txt b/src/kit/shell/CMakeLists.txt index 73bee20c73..9854a44c3b 100644 --- a/src/kit/shell/CMakeLists.txt +++ b/src/kit/shell/CMakeLists.txt @@ -5,6 +5,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/kit/shell/inc/shell.h b/src/kit/shell/inc/shell.h index fcc5e0a87c..7abe8a5776 100644 --- a/src/kit/shell/inc/shell.h +++ b/src/kit/shell/inc/shell.h @@ -18,7 +18,6 @@ #include "stdbool.h" #include "taos.h" -#include "tlog.h" #include "taosdef.h" #include "stdbool.h" diff --git a/src/kit/shell/src/shellEngine.c b/src/kit/shell/src/shellEngine.c index 69d0aa6a40..c85ed47023 100644 --- a/src/kit/shell/src/shellEngine.c +++ b/src/kit/shell/src/shellEngine.c @@ -23,7 +23,7 @@ #include "tutil.h" #include "taosdef.h" #include "taoserror.h" - +#include "tglobal.h" #include /**************** Global variables ****************/ diff --git a/src/kit/shell/src/shellImport.c b/src/kit/shell/src/shellImport.c index 143a27a371..256b251075 100644 --- a/src/kit/shell/src/shellImport.c +++ b/src/kit/shell/src/shellImport.c @@ -19,6 +19,7 @@ #include "os.h" #include "shell.h" #include "shellCommand.h" +#include "tglobal.h" #include "ttime.h" #include "tutil.h" diff --git a/src/kit/shell/src/shellLinux.c b/src/kit/shell/src/shellLinux.c index 15cee042e9..d3453cda36 100644 --- a/src/kit/shell/src/shellLinux.c +++ b/src/kit/shell/src/shellLinux.c @@ -14,12 +14,12 @@ */ #define __USE_XOPEN - #include "os.h" - +#include "tglobal.h" #include "shell.h" #include "shellCommand.h" #include "tkey.h" +#include "tulog.h" #define OPT_ABORT 1 /* �Cabort */ @@ -292,7 +292,7 @@ void *shellLoopQuery(void *arg) { char *command = malloc(MAX_COMMAND_SIZE); if (command == NULL){ - tscError("failed to malloc command"); + uError("failed to malloc command"); return NULL; } diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 0740045b4f..4b613aefdc 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -30,7 +30,7 @@ #include "taos.h" #include "taosmsg.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "tsclient.h" #include "taosdef.h" #include "tutil.h" diff --git a/src/mnode/inc/mgmtLog.h b/src/mnode/inc/mgmtLog.h index 401b8ac32c..fb4bb39828 100644 --- a/src/mnode/inc/mgmtLog.h +++ b/src/mnode/inc/mgmtLog.h @@ -22,44 +22,47 @@ extern "C" { #include "tlog.h" +extern int32_t mdebugFlag; +extern int32_t sdbDebugFlag; + // mnode log function #define mError(...) \ if (mdebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR MND ", 255, __VA_ARGS__); \ + taosPrintLog("ERROR MND ", 255, __VA_ARGS__); \ } #define mWarn(...) \ if (mdebugFlag & DEBUG_WARN) { \ - tprintf("WARN MND ", mdebugFlag, __VA_ARGS__); \ + taosPrintLog("WARN MND ", mdebugFlag, __VA_ARGS__); \ } #define mTrace(...) \ if (mdebugFlag & DEBUG_TRACE) { \ - tprintf("MND ", mdebugFlag, __VA_ARGS__); \ + taosPrintLog("MND ", mdebugFlag, __VA_ARGS__); \ } #define mPrint(...) \ - { tprintf("MND ", 255, __VA_ARGS__); } + { taosPrintLog("MND ", 255, __VA_ARGS__); } -#define mLError(...) taosLogError(__VA_ARGS__) mError(__VA_ARGS__) -#define mLWarn(...) taosLogWarn(__VA_ARGS__) mWarn(__VA_ARGS__) -#define mLPrint(...) taosLogPrint(__VA_ARGS__) mPrint(__VA_ARGS__) +#define mLError(...) mError(__VA_ARGS__) +#define mLWarn(...) mWarn(__VA_ARGS__) +#define mLPrint(...) mPrint(__VA_ARGS__) #define sdbError(...) \ if (sdbDebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR MND-SDB ", 255, __VA_ARGS__); \ + taosPrintLog("ERROR MND-SDB ", 255, __VA_ARGS__); \ } #define sdbWarn(...) \ if (sdbDebugFlag & DEBUG_WARN) { \ - tprintf("WARN MND-SDB ", sdbDebugFlag, __VA_ARGS__); \ + taosPrintLog("WARN MND-SDB ", sdbDebugFlag, __VA_ARGS__); \ } #define sdbTrace(...) \ if (sdbDebugFlag & DEBUG_TRACE) { \ - tprintf("MND-SDB ", sdbDebugFlag, __VA_ARGS__); \ + taosPrintLog("MND-SDB ", sdbDebugFlag, __VA_ARGS__); \ } #define sdbPrint(...) \ - { tprintf("MND-SDB ", 255, __VA_ARGS__); } + { taosPrintLog("MND-SDB ", 255, __VA_ARGS__); } -#define sdbLError(...) taosLogError(__VA_ARGS__) sdbError(__VA_ARGS__) -#define sdbLWarn(...) taosLogWarn(__VA_ARGS__) sdbWarn(__VA_ARGS__) -#define sdbLPrint(...) taosLogPrint(__VA_ARGS__) sdbPrint(__VA_ARGS__) +#define sdbLError(...) sdbError(__VA_ARGS__) +#define sdbLWarn(...) sdbWarn(__VA_ARGS__) +#define sdbLPrint(...) sdbPrint(__VA_ARGS__) #ifdef __cplusplus } diff --git a/src/mnode/src/mgmtDClient.c b/src/mnode/src/mgmtDClient.c index 177934ccfd..f547128f00 100644 --- a/src/mnode/src/mgmtDClient.c +++ b/src/mnode/src/mgmtDClient.c @@ -19,7 +19,7 @@ #include "tsched.h" #include "tsystem.h" #include "tutil.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "dnode.h" #include "tgrant.h" #include "mgmtDef.h" diff --git a/src/mnode/src/mgmtDServer.c b/src/mnode/src/mgmtDServer.c index 7d5b872f4a..80a87813d9 100644 --- a/src/mnode/src/mgmtDServer.c +++ b/src/mnode/src/mgmtDServer.c @@ -22,7 +22,7 @@ #include "tutil.h" #include "tgrant.h" #include "tbalance.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "dnode.h" #include "mgmtDef.h" #include "mgmtLog.h" diff --git a/src/mnode/src/mgmtDb.c b/src/mnode/src/mgmtDb.c index 90aaa03e9a..805546e15e 100644 --- a/src/mnode/src/mgmtDb.c +++ b/src/mnode/src/mgmtDb.c @@ -18,9 +18,9 @@ #include "taoserror.h" #include "tutil.h" #include "tgrant.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "ttime.h" -#include "name.h" +#include "tname.h" #include "mgmtDef.h" #include "mgmtLog.h" #include "mgmtAcct.h" diff --git a/src/mnode/src/mgmtDnode.c b/src/mnode/src/mgmtDnode.c index baec309424..d8164e48da 100644 --- a/src/mnode/src/mgmtDnode.c +++ b/src/mnode/src/mgmtDnode.c @@ -17,7 +17,8 @@ #include "os.h" #include "tgrant.h" #include "tbalance.h" -#include "tglobalcfg.h" +#include "tglobal.h" +#include "tconfig.h" #include "ttime.h" #include "tutil.h" #include "tsocket.h" @@ -728,7 +729,7 @@ int32_t mgmtRetrieveModules(SShowObj *pShow, char *data, int32_t rows, void *pCo return numOfRows; } -static bool mgmtCheckConfigShow(SGlobalConfig *cfg) { +static bool mgmtCheckConfigShow(SGlobalCfg *cfg) { if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_SHOW)) return false; return true; @@ -764,7 +765,7 @@ static int32_t mgmtGetConfigMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC pShow->numOfRows = 0; for (int32_t i = tsGlobalConfigNum - 1; i >= 0; --i) { - SGlobalConfig *cfg = tsGlobalConfig + i; + SGlobalCfg *cfg = tsGlobalConfig + i; if (!mgmtCheckConfigShow(cfg)) continue; pShow->numOfRows++; } @@ -780,7 +781,7 @@ static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, vo int32_t numOfRows = 0; for (int32_t i = tsGlobalConfigNum - 1; i >= 0 && numOfRows < rows; --i) { - SGlobalConfig *cfg = tsGlobalConfig + i; + SGlobalCfg *cfg = tsGlobalConfig + i; if (!mgmtCheckConfigShow(cfg)) continue; char *pWrite; @@ -792,25 +793,21 @@ static int32_t mgmtRetrieveConfigs(SShowObj *pShow, char *data, int32_t rows, vo pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; switch (cfg->valType) { - case TSDB_CFG_VTYPE_SHORT: + case TAOS_CFG_VTYPE_INT16: snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%d", *((int16_t *)cfg->ptr)); numOfRows++; break; - case TSDB_CFG_VTYPE_INT: + case TAOS_CFG_VTYPE_INT32: snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%d", *((int32_t *)cfg->ptr)); numOfRows++; break; - case TSDB_CFG_VTYPE_UINT: - snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%d", *((uint32_t *)cfg->ptr)); - numOfRows++; - break; - case TSDB_CFG_VTYPE_FLOAT: + case TAOS_CFG_VTYPE_FLOAT: snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%f", *((float *)cfg->ptr)); numOfRows++; break; - case TSDB_CFG_VTYPE_STRING: - case TSDB_CFG_VTYPE_IPSTR: - case TSDB_CFG_VTYPE_DIRECTORY: + case TAOS_CFG_VTYPE_STRING: + case TAOS_CFG_VTYPE_IPSTR: + case TAOS_CFG_VTYPE_DIRECTORY: snprintf(pWrite, TSDB_CFG_VALUE_LEN, "%s", (char *)cfg->ptr); numOfRows++; break; diff --git a/src/mnode/src/mgmtMain.c b/src/mnode/src/mgmtMain.c index 1d2f62a593..ac41e9c120 100644 --- a/src/mnode/src/mgmtMain.c +++ b/src/mnode/src/mgmtMain.c @@ -20,6 +20,7 @@ #include "tbalance.h" #include "tgrant.h" #include "ttimer.h" +#include "tglobal.h" #include "dnode.h" #include "mgmtDef.h" #include "mgmtLog.h" diff --git a/src/mnode/src/mgmtSdb.c b/src/mnode/src/mgmtSdb.c index 3344b2b759..c58dd4c923 100644 --- a/src/mnode/src/mgmtSdb.c +++ b/src/mnode/src/mgmtSdb.c @@ -16,13 +16,13 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taoserror.h" -#include "tlog.h" #include "trpc.h" #include "tutil.h" #include "tbalance.h" #include "tqueue.h" #include "twal.h" #include "tsync.h" +#include "tglobal.h" #include "hashint.h" #include "hashstr.h" #include "dnode.h" diff --git a/src/mnode/src/mgmtShell.c b/src/mnode/src/mgmtShell.c index 04f771081b..522968895e 100644 --- a/src/mnode/src/mgmtShell.c +++ b/src/mnode/src/mgmtShell.c @@ -17,18 +17,18 @@ #include "os.h" #include "taosmsg.h" #include "taoserror.h" -#include "tlog.h" #include "trpc.h" #include "tsched.h" #include "tutil.h" #include "ttimer.h" +#include "tgrant.h" +#include "tglobal.h" #include "dnode.h" #include "mgmtDef.h" #include "mgmtLog.h" #include "mgmtAcct.h" #include "mgmtDb.h" #include "mgmtDnode.h" -#include "tgrant.h" #include "mgmtMnode.h" #include "mgmtProfile.h" #include "mgmtSdb.h" diff --git a/src/mnode/src/mgmtTable.c b/src/mnode/src/mgmtTable.c index 383b347410..20d8459943 100644 --- a/src/mnode/src/mgmtTable.c +++ b/src/mnode/src/mgmtTable.c @@ -21,8 +21,9 @@ #include "taoserror.h" #include "taosmsg.h" #include "tscompression.h" -#include "name.h" +#include "tname.h" #include "tidpool.h" +#include "tglobal.h" #include "mgmtDef.h" #include "mgmtLog.h" #include "mgmtAcct.h" diff --git a/src/mnode/src/mgmtUser.c b/src/mnode/src/mgmtUser.c index dc4c3d6bea..fb65d61a35 100644 --- a/src/mnode/src/mgmtUser.c +++ b/src/mnode/src/mgmtUser.c @@ -18,6 +18,7 @@ #include "trpc.h" #include "ttime.h" #include "tutil.h" +#include "tglobal.h" #include "dnode.h" #include "mgmtDef.h" #include "mgmtLog.h" diff --git a/src/mnode/src/mgmtVgroup.c b/src/mnode/src/mgmtVgroup.c index 87d8ddb2b4..eca052ba34 100644 --- a/src/mnode/src/mgmtVgroup.c +++ b/src/mnode/src/mgmtVgroup.c @@ -16,13 +16,13 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taoserror.h" -#include "tlog.h" #include "tutil.h" #include "tsocket.h" #include "tidpool.h" #include "tsync.h" #include "ttime.h" #include "tbalance.h" +#include "tglobal.h" #include "mgmtDef.h" #include "mgmtLog.h" #include "mgmtDb.h" diff --git a/src/os/darwin/inc/os.h b/src/os/darwin/inc/os.h index 1aececeec9..1c719933a4 100644 --- a/src/os/darwin/inc/os.h +++ b/src/os/darwin/inc/os.h @@ -69,6 +69,8 @@ extern "C" { #include #include #include +#include +#include #define htobe64 htonll @@ -197,6 +199,8 @@ int tsem_wait(dispatch_semaphore_t *sem); int tsem_post(dispatch_semaphore_t *sem); int tsem_destroy(dispatch_semaphore_t *sem); +void osInit(); + ssize_t twrite(int fd, void *buf, size_t n); char *taosCharsetReplace(char *charsetstr); @@ -211,11 +215,11 @@ int taosSetNonblocking(int sock, int on); int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen); -void tsPrintOsInfo(); +void taosPrintOsInfo(); char *taosCharsetReplace(char *charsetstr); -void tsPrintOsInfo(); +void taosPrintOsInfo(); void taosGetSystemInfo(); diff --git a/src/os/darwin/src/darwinEnv.c b/src/os/darwin/src/darwinEnv.c new file mode 100644 index 0000000000..d9152e673d --- /dev/null +++ b/src/os/darwin/src/darwinEnv.c @@ -0,0 +1,30 @@ +/* + * 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" +#include "tglobal.h" +#include "tulog.h" + +void osInit() { + strcpy(configDir, "/etc/taos"); + strcpy(tsVnodeDir, ""); + strcpy(tsDnodeDir, ""); + strcpy(tsMnodeDir, ""); + strcpy(dataDir, "/var/lib/taos"); + strcpy(logDir, "~/TDengineLog"); + strcpy(scriptDir, "/etc/taos"); + strcpy(osName, "Darwin"); +} diff --git a/src/os/darwin/src/tdarwin.c b/src/os/darwin/src/darwinPlatform.c similarity index 84% rename from src/os/darwin/src/tdarwin.c rename to src/os/darwin/src/darwinPlatform.c index a8dfdb1e3f..5ee7889af4 100644 --- a/src/os/darwin/src/tdarwin.c +++ b/src/os/darwin/src/darwinPlatform.c @@ -13,32 +13,12 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "tglobalcfg.h" -#include "tlog.h" +#define _DEFAULT_SOURCE +#include "os.h" +#include "tglobal.h" #include "taosdef.h" #include "tutil.h" - -char configDir[TSDB_FILENAME_LEN] = "/etc/taos"; -char tsVnodeDir[TSDB_FILENAME_LEN] = "/var/lib/taos"; -char dataDir[TSDB_FILENAME_LEN] = "/var/lib/taos"; -char logDir[TSDB_FILENAME_LEN] = "~/TDengineLog"; -char scriptDir[TSDB_FILENAME_LEN] = "/etc/taos"; -char osName[] = "Darwin"; +#include "tulog.h" int64_t str2int64(char *str) { char *endptr = NULL; @@ -131,7 +111,7 @@ int taosGetPrivateIp(char *const ip) { return 0; } else { if (hasLoCard) { - pPrint("no net card was found, use lo:127.0.0.1 as default"); + uPrint("no net card was found, use lo:127.0.0.1 as default"); strcpy(ip, "127.0.0.1"); return 0; } @@ -142,7 +122,7 @@ int taosGetPrivateIp(char *const ip) { int taosSetNonblocking(int sock, int on) { int flags = 0; if ((flags = fcntl(sock, F_GETFL, 0)) < 0) { - pError("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno)); + uError("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno)); return 1; } @@ -152,7 +132,7 @@ int taosSetNonblocking(int sock, int on) { flags &= ~O_NONBLOCK; if ((flags = fcntl(sock, F_SETFL, flags)) < 0) { - pError("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno)); + uError("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno)); return 1; } @@ -181,7 +161,7 @@ int taosOpenUDClientSocket(char *ip, uint16_t port) { sockFd = socket(AF_UNIX, SOCK_STREAM, 0); if (sockFd < 0) { - pError("failed to open the UD socket:%s, reason:%s", name, strerror(errno)); + uError("failed to open the UD socket:%s, reason:%s", name, strerror(errno)); return -1; } @@ -192,7 +172,7 @@ int taosOpenUDClientSocket(char *ip, uint16_t port) { ret = connect(sockFd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); if (ret != 0) { - pError("failed to connect UD socket, name:%d, reason: %s", name, strerror(errno)); + uError("failed to connect UD socket, name:%d, reason: %s", name, strerror(errno)); sockFd = -1; } @@ -204,7 +184,7 @@ int taosOpenUDServerSocket(char *ip, uint16_t port) { int sockFd; char name[128]; - pTrace("open ud socket:%s", name); + uTrace("open ud socket:%s", name); sprintf(name, "%s.%hu", ip, port); bzero((char *)&serverAdd, sizeof(serverAdd)); @@ -213,19 +193,19 @@ int taosOpenUDServerSocket(char *ip, uint16_t port) { unlink(name); if ((sockFd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - pError("failed to open UD socket:%s, reason:%s", name, strerror(errno)); + uError("failed to open UD socket:%s, reason:%s", name, strerror(errno)); return -1; } /* bind socket to server address */ if (bind(sockFd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)) < 0) { - pError("bind socket:%s failed, reason:%s", name, strerror(errno)); + uError("bind socket:%s failed, reason:%s", name, strerror(errno)); tclose(sockFd); return -1; } if (listen(sockFd, 10) < 0) { - pError("listen socket:%s failed, reason:%s", name, strerror(errno)); + uError("listen socket:%s failed, reason:%s", name, strerror(errno)); return -1; } @@ -250,8 +230,8 @@ void taosUninitTimer() { void taosGetSystemTimezone() { // get and set default timezone - SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone"); - if (cfg_timezone && cfg_timezone->cfgStatus < TSDB_CFG_CSTATUS_DEFAULT) { + SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); + if (cfg_timezone && cfg_timezone->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { char *tz = getenv("TZ"); if (tz == NULL || strlen(tz) == 0) { strcpy(tsTimezone, "not configured"); @@ -259,33 +239,33 @@ void taosGetSystemTimezone() { else { strcpy(tsTimezone, tz); } - cfg_timezone->cfgStatus = TSDB_CFG_CSTATUS_DEFAULT; - pPrint("timezone not configured, use default"); + cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uPrint("timezone not configured, use default"); } } void taosGetSystemLocale() { // get and set default locale - SGlobalConfig *cfg_locale = tsGetConfigOption("locale"); - if (cfg_locale && cfg_locale->cfgStatus < TSDB_CFG_CSTATUS_DEFAULT) { + SGlobalCfg *cfg_locale = taosGetConfigOption("locale"); + if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { char *locale = setlocale(LC_CTYPE, "chs"); if (locale != NULL) { strncpy(tsLocale, locale, sizeof(tsLocale) / sizeof(tsLocale[0])); - cfg_locale->cfgStatus = TSDB_CFG_CSTATUS_DEFAULT; - pPrint("locale not configured, set to default:%s", tsLocale); + cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uPrint("locale not configured, set to default:%s", tsLocale); } } - SGlobalConfig *cfg_charset = tsGetConfigOption("charset"); - if (cfg_charset && cfg_charset->cfgStatus < TSDB_CFG_CSTATUS_DEFAULT) { + SGlobalCfg *cfg_charset = taosGetConfigOption("charset"); + if (cfg_charset && cfg_charset->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { strcpy(tsCharset, "cp936"); - cfg_charset->cfgStatus = TSDB_CFG_CSTATUS_DEFAULT; - pPrint("charset not configured, set to default:%s", tsCharset); + cfg_charset->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uPrint("charset not configured, set to default:%s", tsCharset); } } -void tsPrintOsInfo() {} +void taosPrintOsInfo() {} void taosKillSystem() { tError("function taosKillSystem, exit!"); diff --git a/src/os/linux/CMakeLists.txt b/src/os/linux/CMakeLists.txt index d5a736ce2e..83d717f905 100644 --- a/src/os/linux/CMakeLists.txt +++ b/src/os/linux/CMakeLists.txt @@ -5,7 +5,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) - INCLUDE_DIRECTORIES(${TD_ENTERPRISE_DIR}/src/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(src SRC) diff --git a/src/os/linux/inc/os.h b/src/os/linux/inc/os.h index ee75e1a079..27a8363050 100644 --- a/src/os/linux/inc/os.h +++ b/src/os/linux/inc/os.h @@ -25,6 +25,9 @@ extern "C" { #ifndef _ALPINE #include + #include +#else + #include #endif #include @@ -76,6 +79,9 @@ extern "C" { #include #include #include +#include +#include +#include #define taosCloseSocket(x) \ { \ @@ -201,6 +207,8 @@ extern "C" { #define tsem_post sem_post #define tsem_destroy sem_destroy +void osInit(); + ssize_t tsendfile(int dfd, int sfd, off_t *offset, size_t size); ssize_t twrite(int fd, void *buf, size_t n); @@ -217,7 +225,7 @@ int taosSetNonblocking(int sock, int on); int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optlen); -void tsPrintOsInfo(); +void taosPrintOsInfo(); char *taosCharsetReplace(char *charsetstr); diff --git a/src/os/linux/src/linuxEnv.c b/src/os/linux/src/linuxEnv.c new file mode 100644 index 0000000000..bc1a309c9e --- /dev/null +++ b/src/os/linux/src/linuxEnv.c @@ -0,0 +1,30 @@ +/* + * 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" +#include "tglobal.h" +#include "tulog.h" + +void osInit() { + strcpy(configDir, "/etc/taos"); + strcpy(tsVnodeDir, ""); + strcpy(tsDnodeDir, ""); + strcpy(tsMnodeDir, ""); + strcpy(dataDir, "/var/lib/taos"); + strcpy(logDir, "/var/log/taos"); + strcpy(scriptDir, "/etc/taos"); + strcpy(osName, "Linux"); +} \ No newline at end of file diff --git a/src/os/linux/src/tlinux.c b/src/os/linux/src/linuxPlatform.c similarity index 84% rename from src/os/linux/src/tlinux.c rename to src/os/linux/src/linuxPlatform.c index 88d69816ab..d9d56a2239 100644 --- a/src/os/linux/src/tlinux.c +++ b/src/os/linux/src/linuxPlatform.c @@ -13,35 +13,13 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "tglobalcfg.h" -#include "tlog.h" +#define _DEFAULT_SOURCE +#include "os.h" #include "taosdef.h" -#include "tutil.h" +#include "tglobal.h" #include "ttimer.h" - -char configDir[TSDB_FILENAME_LEN] = "/etc/taos"; -char tsVnodeDir[TSDB_FILENAME_LEN] = {0}; -char tsDnodeDir[TSDB_FILENAME_LEN] = {0}; -char tsMnodeDir[TSDB_FILENAME_LEN] = {0}; -char dataDir[TSDB_FILENAME_LEN] = "/var/lib/taos"; -char logDir[TSDB_FILENAME_LEN] = "/var/log/taos"; -char scriptDir[TSDB_FILENAME_LEN] = "/etc/taos"; -char osName[] = "Linux"; +#include "tulog.h" +#include "tutil.h" int64_t str2int64(char *str) { char *endptr = NULL; @@ -134,7 +112,7 @@ int taosGetPrivateIp(char *const ip) { return 0; } else { if (hasLoCard) { - pPrint("no net card was found, use lo:127.0.0.1 as default"); + uPrint("no net card was found, use lo:127.0.0.1 as default"); strcpy(ip, "127.0.0.1"); return 0; } @@ -145,7 +123,7 @@ int taosGetPrivateIp(char *const ip) { int taosSetNonblocking(int sock, int on) { int flags = 0; if ((flags = fcntl(sock, F_GETFL, 0)) < 0) { - pError("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno)); + uError("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno)); return 1; } @@ -155,7 +133,7 @@ int taosSetNonblocking(int sock, int on) { flags &= ~O_NONBLOCK; if ((flags = fcntl(sock, F_SETFL, flags)) < 0) { - pError("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno)); + uError("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno)); return 1; } @@ -176,7 +154,7 @@ int taosOpenUDClientSocket(char *ip, uint16_t port) { sockFd = socket(AF_UNIX, SOCK_STREAM, 0); if (sockFd < 0) { - pError("failed to open the UD socket:%s, reason:%s", name, strerror(errno)); + uError("failed to open the UD socket:%s, reason:%s", name, strerror(errno)); return -1; } @@ -187,7 +165,7 @@ int taosOpenUDClientSocket(char *ip, uint16_t port) { ret = connect(sockFd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); if (ret != 0) { - pError("failed to connect UD socket, name:%d, reason: %s", name, strerror(errno)); + uError("failed to connect UD socket, name:%d, reason: %s", name, strerror(errno)); sockFd = -1; } @@ -199,7 +177,7 @@ int taosOpenUDServerSocket(char *ip, uint16_t port) { int sockFd; char name[128]; - pTrace("open ud socket:%s", name); + uTrace("open ud socket:%s", name); sprintf(name, "%s.%hu", ip, port); bzero((char *)&serverAdd, sizeof(serverAdd)); @@ -208,19 +186,19 @@ int taosOpenUDServerSocket(char *ip, uint16_t port) { unlink(name); if ((sockFd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - pError("failed to open UD socket:%s, reason:%s", name, strerror(errno)); + uError("failed to open UD socket:%s, reason:%s", name, strerror(errno)); return -1; } /* bind socket to server address */ if (bind(sockFd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)) < 0) { - pError("bind socket:%s failed, reason:%s", name, strerror(errno)); + uError("bind socket:%s failed, reason:%s", name, strerror(errno)); tclose(sockFd); return -1; } if (listen(sockFd, 10) < 0) { - pError("listen socket:%s failed, reason:%s", name, strerror(errno)); + uError("listen socket:%s failed, reason:%s", name, strerror(errno)); return -1; } @@ -254,7 +232,7 @@ void *taosProcessAlarmSignal(void *tharg) { sevent.sigev_signo = SIGALRM; if (timer_create(CLOCK_REALTIME, &sevent, &timerId) == -1) { - tmrError("Failed to create timer"); + uError("Failed to create timer"); } pthread_cleanup_push(taosDeleteTimer, &timerId); @@ -266,14 +244,14 @@ void *taosProcessAlarmSignal(void *tharg) { ts.it_interval.tv_nsec = 1000000 * MSECONDS_PER_TICK; if (timer_settime(timerId, 0, &ts, NULL)) { - tmrError("Failed to init timer"); + uError("Failed to init timer"); return NULL; } int signo; while (1) { if (sigwait(&sigset, &signo)) { - tmrError("Failed to wait signal: number %d", signo); + uError("Failed to wait signal: number %d", signo); continue; } /* printf("Signal handling: number %d ......\n", signo); */ @@ -294,7 +272,7 @@ int taosInitTimer(void (*callback)(int), int ms) { int code = pthread_create(&timerThread, &tattr, taosProcessAlarmSignal, callback); pthread_attr_destroy(&tattr); if (code != 0) { - tmrError("failed to create timer thread"); + uError("failed to create timer thread"); return -1; } return 0; @@ -379,12 +357,12 @@ ssize_t twrite(int fd, void *buf, size_t n) { bool taosSkipSocketCheck() { struct utsname buf; if (uname(&buf)) { - pPrint("can't fetch os info"); + uPrint("can't fetch os info"); return false; } if (strstr(buf.release, "Microsoft") != 0) { - pPrint("using WSLv1"); + uPrint("using WSLv1"); return true; } @@ -397,6 +375,6 @@ void taosBlockSIGPIPE() { sigaddset(&signal_mask, SIGPIPE); int rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); if (rc != 0) { - pError("failed to block SIGPIPE"); + uError("failed to block SIGPIPE"); } } diff --git a/src/os/linux/src/tsystem.c b/src/os/linux/src/linuxSysPara.c similarity index 80% rename from src/os/linux/src/tsystem.c rename to src/os/linux/src/linuxSysPara.c index ea7b64980f..54e24c28e5 100644 --- a/src/os/linux/src/tsystem.c +++ b/src/os/linux/src/linuxSysPara.c @@ -12,38 +12,16 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef _ALPINE -#include -#else -#include -#endif - -#include "tglobalcfg.h" -#include "tlog.h" -#include "tsystem.h" +#define _DEFAULT_SOURCE +#include "os.h" +#include "tconfig.h" +#include "tglobal.h" +#include "tulog.h" #include "tutil.h" +#include "tsystem.h" #define PROCESS_ITEM 12 -extern char dataDir[TSDB_FILENAME_LEN]; typedef struct { uint64_t user; @@ -76,7 +54,7 @@ bool taosGetSysMemory(float *memoryUsedMB) { bool taosGetProcMemory(float *memoryUsedMB) { FILE *fp = fopen(tsProcMemFile, "r"); if (fp == NULL) { - pError("open file:%s failed", tsProcMemFile); + uError("open file:%s failed", tsProcMemFile); return false; } @@ -95,7 +73,7 @@ bool taosGetProcMemory(float *memoryUsedMB) { } if (line == NULL) { - pError("read file:%s failed", tsProcMemFile); + uError("read file:%s failed", tsProcMemFile); fclose(fp); return false; } @@ -110,10 +88,10 @@ bool taosGetProcMemory(float *memoryUsedMB) { return true; } -bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { +static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { FILE *fp = fopen(tsSysCpuFile, "r"); if (fp == NULL) { - pError("open file:%s failed", tsSysCpuFile); + uError("open file:%s failed", tsSysCpuFile); return false; } @@ -121,7 +99,7 @@ bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { char * line = NULL; getline(&line, &len, fp); if (line == NULL) { - pError("read file:%s failed", tsSysCpuFile); + uError("read file:%s failed", tsSysCpuFile); fclose(fp); return false; } @@ -134,10 +112,10 @@ bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { return true; } -bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { +static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { FILE *fp = fopen(tsProcCpuFile, "r"); if (fp == NULL) { - pError("open file:%s failed", tsProcCpuFile); + uError("open file:%s failed", tsProcCpuFile); return false; } @@ -145,7 +123,7 @@ bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { char * line = NULL; getline(&line, &len, fp); if (line == NULL) { - pError("read file:%s failed", tsProcCpuFile); + uError("read file:%s failed", tsProcCpuFile); fclose(fp); return false; } @@ -163,10 +141,10 @@ bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { return true; } -void taosGetSystemTimezone() { - SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone"); +static void taosGetSystemTimezone() { + SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); if (cfg_timezone == NULL) return; - if (cfg_timezone->cfgStatus >= TSDB_CFG_CSTATUS_DEFAULT) { + if (cfg_timezone->cfgStatus >= TAOS_CFG_CSTATUS_DEFAULT) { return; } @@ -218,8 +196,8 @@ void taosGetSystemTimezone() { */ sprintf(tsTimezone, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); - cfg_timezone->cfgStatus = TSDB_CFG_CSTATUS_DEFAULT; - pPrint("timezone not configured, set to system default:%s", tsTimezone); + // cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uPrint("timezone not configured, set to system default:%s", tsTimezone); } /* @@ -239,24 +217,24 @@ void taosGetSystemTimezone() { * CP936, CP437 for English charset. * */ -void taosGetSystemLocale() { // get and set default locale +static void taosGetSystemLocale() { // get and set default locale char sep = '.'; char *locale = NULL; - SGlobalConfig *cfg_locale = tsGetConfigOption("locale"); - if (cfg_locale && cfg_locale->cfgStatus < TSDB_CFG_CSTATUS_DEFAULT) { + SGlobalCfg *cfg_locale = taosGetConfigOption("locale"); + if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { locale = setlocale(LC_CTYPE, ""); if (locale == NULL) { - pError("can't get locale from system"); + uError("can't get locale from system"); } else { strncpy(tsLocale, locale, tListLen(tsLocale)); - pPrint("locale not configured, set to system default:%s", tsLocale); + uPrint("locale not configured, set to system default:%s", tsLocale); } } /* if user does not specify the charset, extract it from locale */ - SGlobalConfig *cfg_charset = tsGetConfigOption("charset"); - if (cfg_charset && cfg_charset->cfgStatus < TSDB_CFG_CSTATUS_DEFAULT) { + SGlobalCfg *cfg_charset = taosGetConfigOption("charset"); + if (cfg_charset && cfg_charset->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { char *str = strrchr(tsLocale, sep); if (str != NULL) { str++; @@ -265,7 +243,7 @@ void taosGetSystemLocale() { // get and set default locale strncpy(tsCharset, revisedCharset, tListLen(tsCharset)); free(revisedCharset); - pPrint("charset not configured, set to system default:%s", tsCharset); + uPrint("charset not configured, set to system default:%s", tsCharset); } } } @@ -345,7 +323,7 @@ bool taosGetDisk() { return true; } -bool taosGetCardName(char *ip, char *name) { +static bool taosGetCardName(char *ip, char *name) { struct ifaddrs *ifaddr, *ifa; int family, s; char host[NI_MAXHOST]; @@ -381,11 +359,11 @@ bool taosGetCardName(char *ip, char *name) { return ret; } -bool taosGetCardInfo(int64_t *bytes) { +static bool taosGetCardInfo(int64_t *bytes) { static char tsPublicCard[1000] = {0}; if (tsPublicCard[0] == 0) { if (!taosGetCardName(tsPrivateIp, tsPublicCard)) { - pError("can't get card name from ip:%s", tsPrivateIp); + uError("can't get card name from ip:%s", tsPrivateIp); return false; } int cardNameLen = (int)strlen(tsPublicCard); @@ -395,12 +373,12 @@ bool taosGetCardInfo(int64_t *bytes) { break; } } - // pTrace("card name of public ip:%s is %s", tsPublicIp, tsPublicCard); + // uTrace("card name of public ip:%s is %s", tsPublicIp, tsPublicCard); } FILE *fp = fopen(tsSysNetFile, "r"); if (fp == NULL) { - pError("open file:%s failed", tsSysNetFile); + uError("open file:%s failed", tsSysNetFile); return false; } @@ -430,7 +408,7 @@ bool taosGetCardInfo(int64_t *bytes) { fclose(fp); return true; } else { - pWarn("can't get card:%s info from device:%s", tsPublicCard, tsSysNetFile); + uWarn("can't get card:%s info from device:%s", tsPublicCard, tsSysNetFile); *bytes = 0; fclose(fp); return false; @@ -462,7 +440,7 @@ bool taosGetBandSpeed(float *bandSpeedKb) { double totalBytes = (double)(curBytes - lastBytes) / 1024 * 8; // Kb *bandSpeedKb = (float)(totalBytes / (double)(curTime - lastTime)); - // pPrint("bandwidth lastBytes:%ld, lastTime:%ld, curBytes:%ld, curTime:%ld, + // uPrint("bandwidth lastBytes:%ld, lastTime:%ld, curBytes:%ld, curTime:%ld, // speed:%f", lastBytes, lastTime, curBytes, curTime, *bandSpeed); lastTime = curTime; @@ -471,10 +449,10 @@ bool taosGetBandSpeed(float *bandSpeedKb) { return true; } -bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { +static bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { FILE *fp = fopen(tsProcIOFile, "r"); if (fp == NULL) { - pError("open file:%s failed", tsProcIOFile); + uError("open file:%s failed", tsProcIOFile); return false; } @@ -506,7 +484,7 @@ bool taosReadProcIO(int64_t *readbyte, int64_t *writebyte) { fclose(fp); if (readIndex < 2) { - pError("read file:%s failed", tsProcIOFile); + uError("read file:%s failed", tsProcIOFile); return false; } @@ -567,34 +545,33 @@ void taosGetSystemInfo() { taosGetSystemLocale(); } -void tsPrintOsInfo() { - pPrint(" os pageSize: %" PRId64 "(KB)", tsPageSize); - pPrint(" os openMax: %" PRId64, tsOpenMax); - pPrint(" os streamMax: %" PRId64, tsStreamMax); - pPrint(" os numOfCores: %d", tsNumOfCores); - pPrint(" os totalDisk: %f(GB)", tsTotalDataDirGB); - pPrint(" os totalMemory: %d(MB)", tsTotalMemoryMB); +void taosPrintOsInfo() { + uPrint(" os pageSize: %" PRId64 "(KB)", tsPageSize); + uPrint(" os openMax: %" PRId64, tsOpenMax); + uPrint(" os streamMax: %" PRId64, tsStreamMax); + uPrint(" os numOfCores: %d", tsNumOfCores); + uPrint(" os totalDisk: %f(GB)", tsTotalDataDirGB); + uPrint(" os totalMemory: %d(MB)", tsTotalMemoryMB); struct utsname buf; if (uname(&buf)) { - pPrint(" can't fetch os info"); + uPrint(" can't fetch os info"); return; } - pPrint(" os sysname: %s", buf.sysname); - pPrint(" os nodename: %s", buf.nodename); - pPrint(" os release: %s", buf.release); - pPrint(" os version: %s", buf.version); - pPrint(" os machine: %s", buf.machine); - pPrint("=================================="); + uPrint(" os sysname: %s", buf.sysname); + uPrint(" os nodename: %s", buf.nodename); + uPrint(" os release: %s", buf.release); + uPrint(" os version: %s", buf.version); + uPrint(" os machine: %s", buf.machine); + uPrint("=================================="); } void taosKillSystem() { // SIGINT - pPrint("taosd will shut down soon"); + uPrint("taosd will shut down soon"); kill(tsProcId, 2); } -extern int tsEnableCoreFile; int _sysctl(struct __sysctl_args *args ); void taosSetCoreDump() { if (0 == tsEnableCoreFile) { @@ -605,11 +582,11 @@ void taosSetCoreDump() { struct rlimit rlim; struct rlimit rlim_new; if (getrlimit(RLIMIT_CORE, &rlim) == 0) { - pPrint("the old unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max); + uPrint("the old unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max); rlim_new.rlim_cur = RLIM_INFINITY; rlim_new.rlim_max = RLIM_INFINITY; if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) { - pPrint("set unlimited fail, error: %s", strerror(errno)); + uPrint("set unlimited fail, error: %s", strerror(errno)); rlim_new.rlim_cur = rlim.rlim_max; rlim_new.rlim_max = rlim.rlim_max; (void)setrlimit(RLIMIT_CORE, &rlim_new); @@ -617,7 +594,7 @@ void taosSetCoreDump() { } if (getrlimit(RLIMIT_CORE, &rlim) == 0) { - pPrint("the new unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max); + uPrint("the new unlimited para: rlim_cur=%d, rlim_max=%d", rlim.rlim_cur, rlim.rlim_max); } #ifndef _TD_ARM_ @@ -641,10 +618,10 @@ void taosSetCoreDump() { old_len = sizeof(old_usespid); if (syscall(SYS__sysctl, &args) == -1) { - pPrint("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno)); + uPrint("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno)); } - pPrint("The old core_uses_pid[%d]: %d", old_len, old_usespid); + uPrint("The old core_uses_pid[%d]: %d", old_len, old_usespid); old_usespid = 0; @@ -658,10 +635,10 @@ void taosSetCoreDump() { old_len = sizeof(old_usespid); if (syscall(SYS__sysctl, &args) == -1) { - pPrint("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno)); + uPrint("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno)); } - pPrint("The new core_uses_pid[%d]: %d", old_len, old_usespid); + uPrint("The new core_uses_pid[%d]: %d", old_len, old_usespid); #endif #if 0 @@ -671,7 +648,7 @@ void taosSetCoreDump() { if (opendir(coredump_dir) == NULL) { status = mkdir(coredump_dir, S_IRWXU | S_IRWXG | S_IRWXO); if (status) { - pPrint("mkdir fail, error: %s\n", strerror(errno)); + uPrint("mkdir fail, error: %s\n", strerror(errno)); } } @@ -695,10 +672,10 @@ void taosSetCoreDump() { old_len = sizeof(old_corefile); if (syscall(SYS__sysctl, &args) == -1) { - pPrint("_sysctl(kern_core_pattern) set fail: %s", strerror(errno)); + uPrint("_sysctl(kern_core_pattern) set fail: %s", strerror(errno)); } - pPrint("The old kern_core_pattern: %*s\n", old_len, old_corefile); + uPrint("The old kern_core_pattern: %*s\n", old_len, old_corefile); memset(&args, 0, sizeof(struct __sysctl_args)); @@ -710,10 +687,10 @@ void taosSetCoreDump() { old_len = sizeof(old_corefile); if (syscall(SYS__sysctl, &args) == -1) { - pPrint("_sysctl(kern_core_pattern) get fail: %s", strerror(errno)); + uPrint("_sysctl(kern_core_pattern) get fail: %s", strerror(errno)); } - pPrint("The new kern_core_pattern: %*s\n", old_len, old_corefile); + uPrint("The new kern_core_pattern: %*s\n", old_len, old_corefile); #endif } diff --git a/src/os/windows/inc/os.h b/src/os/windows/inc/os.h index 3f957e8abd..a1901aa6e7 100644 --- a/src/os/windows/inc/os.h +++ b/src/os/windows/inc/os.h @@ -41,8 +41,8 @@ #include #include "winsock2.h" #include - #include +#include #ifdef __cplusplus extern "C" { @@ -337,6 +337,8 @@ __int64 interlocked_xor_fetch_64(__int64 volatile* ptr, __int64 val); #define tsem_post sem_post #define tsem_destroy sem_destroy +void osInit(); + int getline(char **lineptr, size_t *n, FILE *stream); int taosWinSetTimer(int ms, void(*callback)(int)); @@ -359,7 +361,7 @@ int taosSetSockOpt(int socketfd, int level, int optname, void *optval, int optle char *taosCharsetReplace(char *charsetstr); -void tsPrintOsInfo(); +void taosPrintOsInfo(); void taosGetSystemInfo(); diff --git a/src/os/windows/src/twindows.c b/src/os/windows/src/twindows.c index 83c6017b39..76b354f784 100644 --- a/src/os/windows/src/twindows.c +++ b/src/os/windows/src/twindows.c @@ -13,31 +13,13 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include -#include - +#define _DEFAULT_SOURCE #include "os.h" -#include "tlog.h" #include "taosdef.h" -#include "tglobalcfg.h" - -#include -#include -#include - -char configDir[TSDB_FILENAME_LEN] = "C:/TDengine/cfg"; -char tsVnodeDir[TSDB_FILENAME_LEN] = "C:/TDengine/data"; -char logDir[TSDB_FILENAME_LEN] = "C:/TDengine/log"; -char dataDir[TSDB_FILENAME_LEN] = "C:/TDengine/data"; -char scriptDir[TSDB_FILENAME_LEN] = "C:/TDengine/script"; -char osName[] = "Windows"; +#include "tglobal.h" +#include "ttimer.h" +#include "tulog.h" +#include "tutil.h" bool taosCheckPthreadValid(pthread_t thread) { return thread.p != NULL; @@ -220,12 +202,12 @@ __int64 interlocked_fetch_xor_64(__int64 volatile* ptr, __int64 val) { #endif -void tsPrintOsInfo() {} +void taosPrintOsInfo() {} void taosGetSystemTimezone() { // get and set default timezone - SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone"); - if (cfg_timezone && cfg_timezone->cfgStatus < TSDB_CFG_CSTATUS_DEFAULT) { + SGlobalCfg *cfg_timezone = taosGetConfigOption("timezone"); + if (cfg_timezone && cfg_timezone->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { char *tz = getenv("TZ"); if (tz == NULL || strlen(tz) == 0) { strcpy(tsTimezone, "not configured"); @@ -233,28 +215,28 @@ void taosGetSystemTimezone() { else { strcpy(tsTimezone, tz); } - cfg_timezone->cfgStatus = TSDB_CFG_CSTATUS_DEFAULT; - pPrint("timezone not configured, use default"); + cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uPrint("timezone not configured, use default"); } } void taosGetSystemLocale() { // get and set default locale - SGlobalConfig *cfg_locale = tsGetConfigOption("locale"); - if (cfg_locale && cfg_locale->cfgStatus < TSDB_CFG_CSTATUS_DEFAULT) { + SGlobalCfg *cfg_locale = taosGetConfigOption("locale"); + if (cfg_locale && cfg_locale->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { char *locale = setlocale(LC_CTYPE, "chs"); if (locale != NULL) { strncpy(tsLocale, locale, sizeof(tsLocale) / sizeof(tsLocale[0])); - cfg_locale->cfgStatus = TSDB_CFG_CSTATUS_DEFAULT; - pPrint("locale not configured, set to default:%s", tsLocale); + cfg_locale->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uPrint("locale not configured, set to default:%s", tsLocale); } } - SGlobalConfig *cfg_charset = tsGetConfigOption("charset"); - if (cfg_charset && cfg_charset->cfgStatus < TSDB_CFG_CSTATUS_DEFAULT) { + SGlobalCfg *cfg_charset = taosGetConfigOption("charset"); + if (cfg_charset && cfg_charset->cfgStatus < TAOS_CFG_CSTATUS_DEFAULT) { strcpy(tsCharset, "cp936"); - cfg_charset->cfgStatus = TSDB_CFG_CSTATUS_DEFAULT; - pPrint("charset not configured, set to default:%s", tsCharset); + cfg_charset->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; + uPrint("charset not configured, set to default:%s", tsCharset); } } diff --git a/src/os/windows/src/twinenv.c b/src/os/windows/src/twinenv.c new file mode 100644 index 0000000000..2b18acdaab --- /dev/null +++ b/src/os/windows/src/twinenv.c @@ -0,0 +1,30 @@ +/* + * 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" +#include "tglobal.h" +#include "tulog.h" + +void osInit() { + strcpy(configDir, "C:/TDengine/cfg"); + strcpy(tsVnodeDir, "C:/TDengine/data"); + strcpy(tsDnodeDir, ""); + strcpy(tsMnodeDir, ""); + strcpy(dataDir, "C:/TDengine/data"); + strcpy(logDir, "C:/TDengine/log"); + strcpy(scriptDir, "C:/TDengine/script"); + strcpy(osName, "Windows"); +} \ No newline at end of file diff --git a/src/os/windows/src/twintcpclient.c b/src/os/windows/src/twintcpclient.c index 9f40dae434..4736042aba 100644 --- a/src/os/windows/src/twintcpclient.c +++ b/src/os/windows/src/twintcpclient.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tlog.h" +#include "tulog.h" void *taosInitTcpClient(char *ip, uint16_t port, char *label, int num, void *fp, void *shandle) { tError("InitTcpClient not support in windows"); diff --git a/src/os/windows/src/twintcpserver.c b/src/os/windows/src/twintcpserver.c index d5e25693d0..10c0348bef 100644 --- a/src/os/windows/src/twintcpserver.c +++ b/src/os/windows/src/twintcpserver.c @@ -13,7 +13,7 @@ * along with this program. If not, see . */ -#include "tlog.h" +#include "tulog.h" void taosCloseTcpServerConnection(void *chandle) { tError("CloseTcpServerConnection not support in windows"); diff --git a/src/plugins/http/CMakeLists.txt b/src/plugins/http/CMakeLists.txt index 40dee94117..27bcae943c 100644 --- a/src/plugins/http/CMakeLists.txt +++ b/src/plugins/http/CMakeLists.txt @@ -6,6 +6,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/zlib-1.2.11/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc) diff --git a/src/plugins/http/inc/httpHandle.h b/src/plugins/http/inc/httpHandle.h index ad5a28e10e..a62dabc800 100644 --- a/src/plugins/http/inc/httpHandle.h +++ b/src/plugins/http/inc/httpHandle.h @@ -23,7 +23,6 @@ #include "taosdef.h" #include "tutil.h" #include "zlib.h" -#include "tlog.h" #include "http.h" #include "httpJson.h" @@ -313,27 +312,4 @@ const char* httpContextStateStr(HttpContextState state); bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState); void httpRemoveContextFromEpoll(HttpThread *pThread, HttpContext *pContext); -#define httpError(...) \ - if (httpDebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR HTP ", 255, __VA_ARGS__); \ - } -#define httpWarn(...) \ - if (httpDebugFlag & DEBUG_WARN) { \ - tprintf("WARN HTP ", httpDebugFlag, __VA_ARGS__); \ - } -#define httpTrace(...) \ - if (httpDebugFlag & DEBUG_TRACE) { \ - tprintf("HTP ", httpDebugFlag, __VA_ARGS__); \ - } -#define httpDump(...) \ - if (httpDebugFlag & DEBUG_TRACE) { \ - taosPrintLongString("HTP ", httpDebugFlag, __VA_ARGS__); \ - } -#define httpPrint(...) \ - { tprintf("HTP ", 255, __VA_ARGS__); } - -#define httpLError(...) taosLogError(__VA_ARGS__) httpError(__VA_ARGS__) -#define httpLWarn(...) taosLogWarn(__VA_ARGS__) httpWarn(__VA_ARGS__) -#define httpLPrint(...) taosLogPrint(__VA_ARGS__) httpPrint(__VA_ARGS__) - #endif diff --git a/src/plugins/http/inc/httpLog.h b/src/plugins/http/inc/httpLog.h new file mode 100644 index 0000000000..1723c30ab9 --- /dev/null +++ b/src/plugins/http/inc/httpLog.h @@ -0,0 +1,47 @@ +/* + * 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_HTTP_LOG_H +#define TDENGINE_HTTP_LOG_H + +#include "tlog.h" + +extern int32_t httpDebugFlag; + +#define httpError(...) \ + if (httpDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("ERROR HTP ", 255, __VA_ARGS__); \ + } +#define httpWarn(...) \ + if (httpDebugFlag & DEBUG_WARN) { \ + taosPrintLog("WARN HTP ", httpDebugFlag, __VA_ARGS__); \ + } +#define httpTrace(...) \ + if (httpDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("HTP ", httpDebugFlag, __VA_ARGS__); \ + } +#define httpDump(...) \ + if (httpDebugFlag & DEBUG_TRACE) { \ + taosPrintLongString("HTP ", httpDebugFlag, __VA_ARGS__); \ + } +#define httpPrint(...) \ + { taosPrintLog("HTP ", 255, __VA_ARGS__); } + +#define httpLError(...) taosLogError(__VA_ARGS__) httpError(__VA_ARGS__) +#define httpLWarn(...) taosLogWarn(__VA_ARGS__) httpWarn(__VA_ARGS__) +#define httpLPrint(...) taosLogPrint(__VA_ARGS__) httpPrint(__VA_ARGS__) + + +#endif diff --git a/src/plugins/http/src/gcHandle.c b/src/plugins/http/src/gcHandle.c index f60aca5c7a..4980c9c804 100644 --- a/src/plugins/http/src/gcHandle.c +++ b/src/plugins/http/src/gcHandle.c @@ -17,7 +17,7 @@ #include "cJSON.h" #include "gcJson.h" #include "taosdef.h" -#include "tlog.h" +#include "httpLog.h" static HttpDecodeMethod gcDecodeMethod = {"grafana", gcProcessRequest}; static HttpEncodeMethod gcHeartBeatMethod = {NULL, gcSendHeartBeatResp, NULL, NULL, NULL, NULL, NULL, NULL}; diff --git a/src/plugins/http/src/httpAuth.c b/src/plugins/http/src/httpAuth.c index 4503accc0a..adbf980f97 100644 --- a/src/plugins/http/src/httpAuth.c +++ b/src/plugins/http/src/httpAuth.c @@ -13,14 +13,10 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include +#include "os.h" #include "tutil.h" - #include "http.h" +#include "httpLog.h" #include "httpHandle.h" #include "tkey.h" #define KEY_DES_4 4971256377704625728L diff --git a/src/plugins/http/src/httpHandle.c b/src/plugins/http/src/httpHandle.c index 3701be7543..529714c8e6 100644 --- a/src/plugins/http/src/httpHandle.c +++ b/src/plugins/http/src/httpHandle.c @@ -24,10 +24,10 @@ #include "httpResp.h" #include "shash.h" #include "taos.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "tsocket.h" #include "ttimer.h" -#include "tlog.h" +#include "httpLog.h" void httpToLowerUrl(char* url) { /*ignore case */ diff --git a/src/plugins/http/src/httpJson.c b/src/plugins/http/src/httpJson.c index 926db9d440..fa74f857b3 100644 --- a/src/plugins/http/src/httpJson.c +++ b/src/plugins/http/src/httpJson.c @@ -25,7 +25,7 @@ #include "httpJson.h" #include "httpResp.h" #include "taosmsg.h" -#include "tlog.h" +#include "httpLog.h" #include "taoserror.h" #define MAX_NUM_STR_SZ 25 diff --git a/src/plugins/http/src/httpResp.c b/src/plugins/http/src/httpResp.c index 39f208a9dd..c0a5c6d7ea 100644 --- a/src/plugins/http/src/httpResp.c +++ b/src/plugins/http/src/httpResp.c @@ -19,7 +19,7 @@ #include "httpCode.h" #include "httpJson.h" #include "taosmsg.h" -#include "tlog.h" +#include "httpLog.h" #include "taoserror.h" const char *httpKeepAliveStr[] = {"", "Connection: Keep-Alive\r\n", "Connection: Close\r\n"}; diff --git a/src/plugins/http/src/httpServer.c b/src/plugins/http/src/httpServer.c index 5c321beffb..f564863652 100644 --- a/src/plugins/http/src/httpServer.c +++ b/src/plugins/http/src/httpServer.c @@ -14,16 +14,14 @@ */ #include "os.h" - #include "taosmsg.h" -#include "tlog.h" -#include "tlog.h" #include "tsocket.h" #include "tutil.h" #include "ttime.h" #include "ttimer.h" - +#include "tglobal.h" #include "http.h" +#include "httpLog.h" #include "httpCode.h" #include "httpHandle.h" #include "httpResp.h" diff --git a/src/plugins/http/src/httpSession.c b/src/plugins/http/src/httpSession.c index c6be951418..39b2ff7d24 100644 --- a/src/plugins/http/src/httpSession.c +++ b/src/plugins/http/src/httpSession.c @@ -26,7 +26,7 @@ #include "taos.h" #include "ttime.h" #include "ttimer.h" -#include "tlog.h" +#include "httpLog.h" void httpAccessSession(HttpContext *pContext) { HttpServer *server = pContext->pThread->pServer; diff --git a/src/plugins/http/src/httpSql.c b/src/plugins/http/src/httpSql.c index 4696e80dc7..017605093e 100644 --- a/src/plugins/http/src/httpSql.c +++ b/src/plugins/http/src/httpSql.c @@ -13,11 +13,7 @@ * along with this program. If not, see . */ -#include -#include -#include -#include - +#include "os.h" #include "http.h" #include "httpCode.h" #include "httpHandle.h" @@ -25,6 +21,7 @@ #include "taos.h" #include "tsclient.h" #include "tnote.h" +#include "httpLog.h" void *taos_connect_a(char *ip, char *user, char *pass, char *db, uint16_t port, void (*fp)(void *, TAOS_RES *, int), void *param, void **taos); diff --git a/src/plugins/http/src/httpSystem.c b/src/plugins/http/src/httpSystem.c index 52910cb1db..9afd5838c8 100644 --- a/src/plugins/http/src/httpSystem.c +++ b/src/plugins/http/src/httpSystem.c @@ -20,9 +20,10 @@ #include "httpCode.h" #include "httpHandle.h" #include "httpResp.h" +#include "httpLog.h" #include "shash.h" #include "taos.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "tsocket.h" #include "ttimer.h" #include "gcHandle.h" diff --git a/src/plugins/http/src/httpUtil.c b/src/plugins/http/src/httpUtil.c index 8b4fdeb553..c8d4737c41 100644 --- a/src/plugins/http/src/httpUtil.c +++ b/src/plugins/http/src/httpUtil.c @@ -13,20 +13,15 @@ * along with this program. If not, see . */ -#include -#include -#include -#include +#include "os.h" #include "tmd5.h" - #include "http.h" #include "httpCode.h" #include "httpHandle.h" #include "httpResp.h" - #include "shash.h" #include "taos.h" -#include "tlog.h" +#include "httpLog.h" bool httpCheckUsedbSql(char *sql) { if (strstr(sql, "use ") != NULL) { diff --git a/src/plugins/http/src/restHandle.c b/src/plugins/http/src/restHandle.c index 78c08ab866..79d6fe5662 100644 --- a/src/plugins/http/src/restHandle.c +++ b/src/plugins/http/src/restHandle.c @@ -15,7 +15,7 @@ #include "restHandle.h" #include "restJson.h" -#include "tlog.h" +#include "httpLog.h" static HttpDecodeMethod restDecodeMethod = {"rest", restProcessRequest}; static HttpDecodeMethod restDecodeMethod2 = {"restful", restProcessRequest}; diff --git a/src/plugins/http/src/restJson.c b/src/plugins/http/src/restJson.c index 107449bab3..0489bcdbe0 100644 --- a/src/plugins/http/src/restJson.c +++ b/src/plugins/http/src/restJson.c @@ -13,12 +13,9 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include "tlog.h" +#include "os.h" +#include "tglobal.h" +#include "httpLog.h" #include "httpJson.h" #include "restHandle.h" #include "restJson.h" diff --git a/src/plugins/http/src/tgHandle.c b/src/plugins/http/src/tgHandle.c index 2be39743bd..5ea5f832d5 100644 --- a/src/plugins/http/src/tgHandle.c +++ b/src/plugins/http/src/tgHandle.c @@ -13,12 +13,14 @@ * along with this program. If not, see . */ +#include "os.h" #include "tgHandle.h" #include "shash.h" #include "taosmsg.h" #include "tgJson.h" #include "taosdef.h" -#include "tlog.h" +#include "httpLog.h" +#include "tglobal.h" /* * taos.telegraf.cfg formats like diff --git a/src/plugins/http/src/tgJson.c b/src/plugins/http/src/tgJson.c index 6dfd2c8e9a..f19e00fb98 100644 --- a/src/plugins/http/src/tgJson.c +++ b/src/plugins/http/src/tgJson.c @@ -13,16 +13,13 @@ * along with this program. If not, see . */ -#include -#include -#include - +#include "os.h" #include "httpJson.h" #include "httpResp.h" #include "taosmsg.h" #include "tgHandle.h" #include "tgJson.h" -#include "tlog.h" +#include "httpLog.h" void tgInitQueryJson(HttpContext *pContext) { JsonBuf *jsonBuf = httpMallocJsonBuf(pContext); diff --git a/src/plugins/monitor/CMakeLists.txt b/src/plugins/monitor/CMakeLists.txt index c409f28b20..0ea5507501 100644 --- a/src/plugins/monitor/CMakeLists.txt +++ b/src/plugins/monitor/CMakeLists.txt @@ -6,6 +6,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/query/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(./src SRC) diff --git a/src/plugins/monitor/inc/monitorSystem.h b/src/plugins/monitor/inc/monitorSystem.h index 6fd5709475..dc49071b16 100644 --- a/src/plugins/monitor/inc/monitorSystem.h +++ b/src/plugins/monitor/inc/monitorSystem.h @@ -27,6 +27,13 @@ int32_t monitorInitSystem(); int32_t monitorStartSystem(); void monitorStopSystem(); void monitorCleanUpSystem(); +void monitorSaveAcctLog(char *acctId, int64_t currentPointsPerSecond, int64_t maxPointsPerSecond, + int64_t totalTimeSeries, int64_t maxTimeSeries, int64_t totalStorage, int64_t maxStorage, + int64_t totalQueryTime, int64_t maxQueryTime, int64_t totalInbound, int64_t maxInbound, + int64_t totalOutbound, int64_t maxOutbound, int64_t totalDbs, int64_t maxDbs, + int64_t totalUsers, int64_t maxUsers, int64_t totalStreams, int64_t maxStreams, + int64_t totalConns, int64_t maxConns, int8_t accessState); +void monitorSaveLog(int level, const char *const format, ...); #ifdef __cplusplus } diff --git a/src/plugins/monitor/src/monitorSystem.c b/src/plugins/monitor/src/monitorSystem.c index a547d13545..1811733790 100644 --- a/src/plugins/monitor/src/monitorSystem.c +++ b/src/plugins/monitor/src/monitorSystem.c @@ -28,22 +28,22 @@ #define monitorError(...) \ if (monitorDebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR MON ", 255, __VA_ARGS__); \ + taosPrintLog("ERROR MON ", 255, __VA_ARGS__); \ } #define monitorWarn(...) \ if (monitorDebugFlag & DEBUG_WARN) { \ - tprintf("WARN MON ", monitorDebugFlag, __VA_ARGS__); \ + taosPrintLog("WARN MON ", monitorDebugFlag, __VA_ARGS__); \ } #define monitorTrace(...) \ if (monitorDebugFlag & DEBUG_TRACE) { \ - tprintf("MON ", monitorDebugFlag, __VA_ARGS__); \ + taosPrintLog("MON ", monitorDebugFlag, __VA_ARGS__); \ } #define monitorPrint(...) \ - { tprintf("MON ", 255, __VA_ARGS__); } + { taosPrintLog("MON ", 255, __VA_ARGS__); } -#define monitorLError(...) taosLogError(__VA_ARGS__) monitorError(__VA_ARGS__) -#define monitorLWarn(...) taosLogWarn(__VA_ARGS__) monitorWarn(__VA_ARGS__) -#define monitorLPrint(...) taosLogPrint(__VA_ARGS__) monitorPrint(__VA_ARGS__) +#define monitorLError(...) monitorError(__VA_ARGS__) +#define monitorLWarn(...) monitorWarn(__VA_ARGS__) +#define monitorLPrint(...) monitorPrint(__VA_ARGS__) #define SQL_LENGTH 1024 #define LOG_LEN_STR 80 @@ -108,9 +108,6 @@ int monitorInitSystem() { monitor = (MonitorConn *)malloc(sizeof(MonitorConn)); memset(monitor, 0, sizeof(MonitorConn)); taosTmrReset(monitorCheckDiskUsage, CHECK_INTERVAL, NULL, tscTmr, &monitor->diskTimer); - - startMonitor = monitorStartSystem; - stopMonitor = monitorStopSystem; return 0; } @@ -234,10 +231,6 @@ void monitorInitDatabaseCb(void *param, TAOS_RES *result, int code) { if (-code == TSDB_CODE_TABLE_ALREADY_EXIST || -code == TSDB_CODE_DB_ALREADY_EXIST || code >= 0) { monitorTrace("monitor:%p, sql success, code:%d, %s", monitor->conn, code, monitor->sql); if (monitor->cmdIndex == MONITOR_CMD_CREATE_TB_LOG) { - //TODO - //taosLogFp = monitorSaveLog; - taosLogSqlFp = monitorExecuteSQL; - taosLogAcctFp = monitorSaveAcctLog; monitorLPrint("dnode:%s is started", tsPrivateIp); } monitor->cmdIndex++; @@ -256,7 +249,7 @@ void monitorStopSystem() { monitorLPrint("dnode:%s monitor module is stopped", tsPrivateIp); monitor->state = MONITOR_STATE_STOPPED; - taosLogFp = NULL; + // taosLogFp = NULL; if (monitor->initTimer != NULL) { taosTmrStopA(&(monitor->initTimer)); } @@ -404,6 +397,8 @@ void monitorSaveAcctLog(char *acctId, int64_t currentPointsPerSecond, int64_t ma int64_t totalOutbound, int64_t maxOutbound, int64_t totalDbs, int64_t maxDbs, int64_t totalUsers, int64_t maxUsers, int64_t totalStreams, int64_t maxStreams, int64_t totalConns, int64_t maxConns, int8_t accessState) { + if (monitor->state != MONITOR_STATE_INITIALIZED) return; + char sql[1024] = {0}; sprintf(sql, "insert into %s.acct_%s using %s.acct tags('%s') values(now" diff --git a/src/query/CMakeLists.txt b/src/query/CMakeLists.txt index 01be5e643b..620fd217de 100644 --- a/src/query/CMakeLists.txt +++ b/src/query/CMakeLists.txt @@ -6,6 +6,7 @@ INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/tsdb/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(inc) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) diff --git a/src/query/inc/qextbuffer.h b/src/query/inc/qextbuffer.h index f34deda6c1..a73948fe3b 100644 --- a/src/query/inc/qextbuffer.h +++ b/src/query/inc/qextbuffer.h @@ -25,7 +25,7 @@ extern "C" { #include "tarray.h" #include "tutil.h" -#include "dataformat.h" +#include "tdataformat.h" #include "talgo.h" #define DEFAULT_PAGE_SIZE 16384 // 16k larger than the SHistoInfo diff --git a/src/query/inc/queryLog.h b/src/query/inc/queryLog.h new file mode 100644 index 0000000000..929e079d1e --- /dev/null +++ b/src/query/inc/queryLog.h @@ -0,0 +1,45 @@ +/* + * 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_RPC_LOG_H +#define TDENGINE_RPC_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tlog.h" + +extern int32_t qdebugFlag; + +#define qTrace(...) \ + if (qdebugFlag & DEBUG_TRACE) { \ + taosPrintLog("DND QRY ", qdebugFlag, __VA_ARGS__); \ + } + +#define qError(...) \ + if (qdebugFlag & DEBUG_ERROR) { \ + taosPrintLog("ERROR RPC ", qdebugFlag, __VA_ARGS__); \ + } +#define qWarn(...) \ + if (qdebugFlag & DEBUG_WARN) { \ + taosPrintLog("WARN RPC ", qdebugFlag, __VA_ARGS__); \ + } + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_RPC_CACHE_H diff --git a/src/query/inc/tsqlfunction.h b/src/query/inc/tsqlfunction.h index 90ae7df36a..3cfcf83268 100644 --- a/src/query/inc/tsqlfunction.h +++ b/src/query/inc/tsqlfunction.h @@ -22,7 +22,7 @@ extern "C" { #include "os.h" -#include "../../common/inc/name.h" +#include "../../common/inc/tname.h" #include "taosdef.h" #include "trpc.h" #include "tvariant.h" diff --git a/src/query/src/qast.c b/src/query/src/qast.c index 8855caee56..14f340b3d3 100644 --- a/src/query/src/qast.c +++ b/src/query/src/qast.c @@ -14,7 +14,7 @@ */ #include "os.h" - +#include "tulog.h" #include "tutil.h" #include "tbuffer.h" #include "qast.h" @@ -23,14 +23,13 @@ #include "qsyntaxtreefunction.h" #include "taosdef.h" #include "taosmsg.h" -#include "tlog.h" #include "tsqlfunction.h" #include "tstoken.h" #include "ttokendef.h" - -#include "../../client/inc/tschemautil.h" +#include "tschemautil.h" #include "tarray.h" #include "tskiplist.h" +#include "queryLog.h" /* * @@ -267,7 +266,7 @@ static tExprNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *st // get the operator of expr uint8_t optr = getBinaryExprOptr(&t0); if (optr == 0) { - pError("not support binary operator:%d", t0.type); + uError("not support binary operator:%d", t0.type); tExprNodeDestroy(pLeft, NULL); return NULL; } @@ -319,7 +318,7 @@ static tExprNode *createSyntaxTree(SSchema *pSchema, int32_t numOfCols, char *st } else { uint8_t localOptr = getBinaryExprOptr(&t0); if (localOptr == 0) { - pError("not support binary operator:%d", t0.type); + uError("not support binary operator:%d", t0.type); free(pExpr); return NULL; } diff --git a/src/query/src/qextbuffer.c b/src/query/src/qextbuffer.c index 754970993b..2b403eb921 100644 --- a/src/query/src/qextbuffer.c +++ b/src/query/src/qextbuffer.c @@ -12,15 +12,16 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -#include "qextbuffer.h" #include "os.h" +#include "tulog.h" +#include "qextbuffer.h" #include "taos.h" #include "taosdef.h" #include "taosmsg.h" -#include "tlog.h" #include "tsqlfunction.h" #include "ttime.h" #include "tutil.h" +#include "queryLog.h" #define COLMODEL_GET_VAL(data, schema, allrow, rowId, colId) \ (data + (schema)->pFields[colId].offset * (allrow) + (rowId) * (schema)->pFields[colId].field.bytes) @@ -41,7 +42,7 @@ tExtMemBuffer* createExtMemBuffer(int32_t inMemSize, int32_t elemSize, SColumnMo getTmpfilePath("extbuf", name); pMemBuffer->path = strdup(name); - pTrace("create tmp file:%s", pMemBuffer->path); + uTrace("create tmp file:%s", pMemBuffer->path); SExtFileInfo *pFMeta = &pMemBuffer->fileMeta; @@ -79,10 +80,10 @@ void* destoryExtMemBuffer(tExtMemBuffer *pMemBuffer) { // close temp file if (pMemBuffer->file != 0) { if (fclose(pMemBuffer->file) != 0) { - pError("failed to close file:%s, reason:%s", pMemBuffer->path, strerror(errno)); + uError("failed to close file:%s, reason:%s", pMemBuffer->path, strerror(errno)); } - pTrace("remove temp file:%s for external buffer", pMemBuffer->path); + uTrace("remove temp file:%s for external buffer", pMemBuffer->path); unlink(pMemBuffer->path); } @@ -103,7 +104,7 @@ static bool allocFlushoutInfoEntries(SExtFileInfo *pFileMeta) { tFlushoutInfo *tmp = (tFlushoutInfo *)realloc(pFileMeta->flushoutData.pFlushoutInfo, sizeof(tFlushoutInfo) * pFileMeta->flushoutData.nAllocSize); if (tmp == NULL) { - pError("out of memory!\n"); + uError("out of memory!\n"); return false; } diff --git a/src/query/src/qparserImpl.c b/src/query/src/qparserImpl.c index f5763cfb45..28b30f6549 100644 --- a/src/query/src/qparserImpl.c +++ b/src/query/src/qparserImpl.c @@ -17,14 +17,14 @@ #include "qsqlparser.h" #include "taosdef.h" #include "taosmsg.h" -#include "tglobalcfg.h" -#include "tlog.h" +#include "tglobal.h" #include "tstoken.h" #include "ttime.h" #include "ttokendef.h" #include "tutil.h" #include "qsqltype.h" #include "tstrbuild.h" +#include "queryLog.h" int32_t tSQLParse(SSqlInfo *pSQLInfo, const char *pStr) { void *pParser = ParseAlloc(malloc); diff --git a/src/query/src/qpercentile.c b/src/query/src/qpercentile.c index 7283a9fd3f..2561bdf284 100644 --- a/src/query/src/qpercentile.c +++ b/src/query/src/qpercentile.c @@ -14,11 +14,11 @@ */ #include "os.h" - +#include "tulog.h" #include "qpercentile.h" #include "taosdef.h" #include "taosmsg.h" -#include "tlog.h" +#include "queryLog.h" tExtMemBuffer *releaseBucketsExceptFor(tMemBucket *pMemBucket, int16_t segIdx, int16_t slotIdx) { tExtMemBuffer *pBuffer = NULL; @@ -233,7 +233,7 @@ void tBucketDoubleHash(tMemBucket *pBucket, void *value, int16_t *segIdx, int16_ } if (*segIdx < 0 || *segIdx > 16 || *slotIdx < 0 || *slotIdx > 64) { - pError("error in hash process. segment is: %d, slot id is: %d\n", *segIdx, *slotIdx); + uError("error in hash process. segment is: %d, slot id is: %d\n", *segIdx, *slotIdx); } } } @@ -283,7 +283,7 @@ tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nE break; }; default: { - pError("MemBucket:%p,not support data type %d,failed", *pBucket, pBucket->dataType); + uError("MemBucket:%p,not support data type %d,failed", *pBucket, pBucket->dataType); tfree(pBucket); return NULL; } @@ -291,20 +291,20 @@ tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nE int32_t numOfCols = pDesc->pColumnModel->numOfCols; if (numOfCols != 1) { - pError("MemBucket:%p,only consecutive data is allowed,invalid numOfCols:%d", pBucket, numOfCols); + uError("MemBucket:%p,only consecutive data is allowed,invalid numOfCols:%d", pBucket, numOfCols); tfree(pBucket); return NULL; } SSchema* pSchema = getColumnModelSchema(pDesc->pColumnModel, 0); if (pSchema->type != dataType) { - pError("MemBucket:%p,data type is not consistent,%d in schema, %d in param", pBucket, pSchema->type, dataType); + uError("MemBucket:%p,data type is not consistent,%d in schema, %d in param", pBucket, pSchema->type, dataType); tfree(pBucket); return NULL; } if (pBucket->numOfTotalPages < pBucket->nTotalSlots) { - pWarn("MemBucket:%p,total buffer pages %d are not enough for all slots", pBucket, pBucket->numOfTotalPages); + uWarn("MemBucket:%p,total buffer pages %d are not enough for all slots", pBucket, pBucket->numOfTotalPages); } pBucket->pSegs = (tMemBucketSegment *)malloc(pBucket->numOfSegs * sizeof(tMemBucketSegment)); @@ -315,7 +315,7 @@ tMemBucket *tMemBucketCreate(int32_t totalSlots, int32_t nBufferSize, int16_t nE pBucket->pSegs[i].pBoundingEntries = NULL; } - pTrace("MemBucket:%p,created,buffer size:%d,elem size:%d", pBucket, pBucket->numOfTotalPages * DEFAULT_PAGE_SIZE, + uTrace("MemBucket:%p,created,buffer size:%d,elem size:%d", pBucket, pBucket->numOfTotalPages * DEFAULT_PAGE_SIZE, pBucket->nElemSize); return pBucket; @@ -545,11 +545,11 @@ void tMemBucketPut(tMemBucket *pBucket, void *data, int32_t numOfRows) { // ensure available memory pages to allocate int16_t cseg = 0, cslot = 0; if (pBucket->numOfAvailPages == 0) { - pTrace("MemBucket:%p,max avail size:%d, no avail memory pages,", pBucket, pBucket->numOfTotalPages); + uTrace("MemBucket:%p,max avail size:%d, no avail memory pages,", pBucket, pBucket->numOfTotalPages); tBucketGetMaxMemSlot(pBucket, &cseg, &cslot); if (cseg == -1 || cslot == -1) { - pError("MemBucket:%p,failed to find appropriated avail buffer", pBucket); + uError("MemBucket:%p,failed to find appropriated avail buffer", pBucket); return; } @@ -560,10 +560,10 @@ void tMemBucketPut(tMemBucket *pBucket, void *data, int32_t numOfRows) { UNUSED(avail); tExtMemBufferFlush(pBucket->pSegs[cseg].pBuffer[cslot]); - pTrace("MemBucket:%p,seg:%d,slot:%d flushed to disk,new avail pages:%d", pBucket, cseg, cslot, + uTrace("MemBucket:%p,seg:%d,slot:%d flushed to disk,new avail pages:%d", pBucket, cseg, cslot, pBucket->numOfAvailPages); } else { - pTrace("MemBucket:%p,failed to choose slot to flush to disk seg:%d,slot:%d", pBucket, cseg, cslot); + uTrace("MemBucket:%p,failed to choose slot to flush to disk seg:%d,slot:%d", pBucket, cseg, cslot); } } int16_t consumedPgs = pSeg->pBuffer[slotIdx]->numOfInMemPages; @@ -835,10 +835,10 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) return finalResult; } - pTrace("MemBucket:%p,start second round bucketing", pMemBucket); + uTrace("MemBucket:%p,start second round bucketing", pMemBucket); if (pSeg->pBuffer[j]->numOfElemsInBuffer != 0) { - pTrace("MemBucket:%p,flush %d pages to disk, clear status", pMemBucket, pSeg->pBuffer[j]->numOfInMemPages); + uTrace("MemBucket:%p,flush %d pages to disk, clear status", pMemBucket, pSeg->pBuffer[j]->numOfInMemPages); pMemBucket->numOfAvailPages += pSeg->pBuffer[j]->numOfInMemPages; tExtMemBufferFlush(pSeg->pBuffer[j]); @@ -886,7 +886,7 @@ double getPercentileImpl(tMemBucket *pMemBucket, int32_t count, double fraction) fclose(pMemBuffer->file); if (unlink(pMemBuffer->path) != 0) { - pError("MemBucket:%p, remove tmp file %s failed", pMemBucket, pMemBuffer->path); + uError("MemBucket:%p, remove tmp file %s failed", pMemBucket, pMemBuffer->path); } tfree(pMemBuffer); tfree(pPage); diff --git a/src/query/src/qresultBuf.c b/src/query/src/qresultBuf.c index 07fd5f11e3..7cdbfbd0ef 100644 --- a/src/query/src/qresultBuf.c +++ b/src/query/src/qresultBuf.c @@ -2,8 +2,8 @@ #include "hash.h" #include "qextbuffer.h" #include "taoserror.h" -#include "tlog.h" #include "tsqlfunction.h" +#include "queryLog.h" #define DEFAULT_INTERN_BUF_SIZE 16384L @@ -29,23 +29,23 @@ int32_t createDiskbasedResultBuffer(SDiskbasedResultBuf** pResultBuf, int32_t si memset(path, 0, tListLen(path)); if (!FD_VALID(pResBuf->fd)) { - pError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); + qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); return TSDB_CODE_CLI_NO_DISKSPACE; } int32_t ret = ftruncate(pResBuf->fd, pResBuf->numOfPages * DEFAULT_INTERN_BUF_SIZE); if (ret != TSDB_CODE_SUCCESS) { - pError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); + qError("failed to create tmp file: %s on disk. %s", pResBuf->path, strerror(errno)); return TSDB_CODE_CLI_NO_DISKSPACE; } pResBuf->pBuf = mmap(NULL, pResBuf->totalBufSize, PROT_READ | PROT_WRITE, MAP_SHARED, pResBuf->fd, 0); if (pResBuf->pBuf == MAP_FAILED) { - pError("QInfo:%p failed to map temp file: %s. %s", pResBuf->path, strerror(errno)); + qError("QInfo:%p failed to map temp file: %s. %s", pResBuf->path, strerror(errno)); return TSDB_CODE_CLI_OUT_OF_MEMORY; // todo change error code } - pTrace("create tmp file for output result, %s, " PRId64 "bytes", pResBuf->path, pResBuf->totalBufSize); + qTrace("create tmp file for output result, %s, " PRId64 "bytes", pResBuf->path, pResBuf->totalBufSize); *pResultBuf = pResBuf; return TSDB_CODE_SUCCESS; } @@ -198,7 +198,7 @@ void destroyResultBuf(SDiskbasedResultBuf* pResultBuf) { close(pResultBuf->fd); } - pTrace("disk-based output buffer closed, %" PRId64 " bytes, file:%s", pResultBuf->totalBufSize, pResultBuf->path); + qTrace("disk-based output buffer closed, %" PRId64 " bytes, file:%s", pResultBuf->totalBufSize, pResultBuf->path); munmap(pResultBuf->pBuf, pResultBuf->totalBufSize); unlink(pResultBuf->path); diff --git a/src/query/src/queryExecutor.c b/src/query/src/queryExecutor.c index 32f7a58d60..fcb073ef4d 100644 --- a/src/query/src/queryExecutor.c +++ b/src/query/src/queryExecutor.c @@ -17,18 +17,16 @@ #include "hash.h" #include "hashfunc.h" #include "taosmsg.h" -#include "tlog.h" #include "tlosertree.h" #include "tscompression.h" #include "ttime.h" - #include "qast.h" - #include "qresultBuf.h" #include "queryExecutor.h" #include "queryUtil.h" #include "query.h" #include "tsdbMain.h" //todo use TableId instead of STable object +#include "queryLog.h" #define DEFAULT_INTERN_BUF_SIZE 16384L @@ -180,7 +178,7 @@ bool getNeighborPoints(SQInfo *pQInfo, void *pMeterObj, SPointInterpoSupporter * * reset the status and load the data block that contains the qualified point */ if (Q_STATUS_EQUAL(pQuery->over, QUERY_NO_DATA_TO_CHECK)) { - dTrace("QInfo:%p no previous data block, start fileId:%d, slot:%d, pos:%d, qrange:%" PRId64 "-%" PRId64 + qTrace("QInfo:%p no previous data block, start fileId:%d, slot:%d, pos:%d, qrange:%" PRId64 "-%" PRId64 ", out of range", GET_QINFO_ADDR(pQuery), pRuntimeEnv->startPos.fileId, pRuntimeEnv->startPos.slot, pRuntimeEnv->startPos.pos, pQuery->skey, pQuery->ekey); @@ -1391,11 +1389,11 @@ void setExecParams(SQuery *pQuery, SQLFunctionCtx *pCtx, void *inputData, TSKEY // int64_t e = tsList[size - 1]; // if (IS_DATA_BLOCK_LOADED(blockStatus)) { -// dTrace("QInfo:%p query ts:%lld-%lld, offset:%d, rows:%d, bstatus:%d, +// qTrace("QInfo:%p query ts:%lld-%lld, offset:%d, rows:%d, bstatus:%d, // functId:%d", GET_QINFO_ADDR(pQuery), // s, e, startOffset, size, blockStatus, functionId); // } else { -// dTrace("QInfo:%p block not loaded, bstatus:%d", +// qTrace("QInfo:%p block not loaded, bstatus:%d", // GET_QINFO_ADDR(pQuery), blockStatus); // } #endif @@ -1439,7 +1437,7 @@ static void setWindowResultInfo(SResultInfo *pResultInfo, SQuery *pQuery, bool i } static int32_t setupQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv, SColumnModel *pTagsSchema, int16_t order) { - dTrace("QInfo:%p setup runtime env", GET_QINFO_ADDR(pRuntimeEnv)); + qTrace("QInfo:%p setup runtime env", GET_QINFO_ADDR(pRuntimeEnv)); SQuery *pQuery = pRuntimeEnv->pQuery; pRuntimeEnv->resultInfo = calloc(pQuery->numOfOutputCols, sizeof(SResultInfo)); @@ -1521,7 +1519,7 @@ static void teardownQueryRuntimeEnv(SQueryRuntimeEnv *pRuntimeEnv) { SQuery *pQuery = pRuntimeEnv->pQuery; - dTrace("QInfo:%p teardown runtime env", GET_QINFO_ADDR(pQuery)); + qTrace("QInfo:%p teardown runtime env", GET_QINFO_ADDR(pQuery)); cleanupTimeWindowInfo(&pRuntimeEnv->windowResInfo, pQuery->numOfOutputCols); if (pRuntimeEnv->pCtx != NULL) { @@ -1851,7 +1849,7 @@ bool vnodeParametersSafetyCheck(SQuery *pQuery) { // load data column information is incorrect for (int32_t i = 0; i < pQuery->numOfCols - 1; ++i) { if (pQuery->colList[i].info.colId == pQuery->colList[i + 1].info.colId) { - dError("QInfo:%p invalid data load column for query", GET_QINFO_ADDR(pQuery)); + qError("QInfo:%p invalid data load column for query", GET_QINFO_ADDR(pQuery)); return false; } } @@ -1889,7 +1887,7 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) { // todo handle the case the the order irrelevant query type mixed up with order critical query type // descending order query for last_row query if (isFirstLastRowQuery(pQuery)) { - dTrace("QInfo:%p scan order changed for last_row query, old:%d, new:%d", GET_QINFO_ADDR(pQuery), + qTrace("QInfo:%p scan order changed for last_row query, old:%d, new:%d", GET_QINFO_ADDR(pQuery), pQuery->order.order, TSDB_ORDER_DESC); pQuery->order.order = TSDB_ORDER_DESC; @@ -1905,7 +1903,7 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) { if (isPointInterpoQuery(pQuery) && pQuery->intervalTime == 0) { if (!QUERY_IS_ASC_QUERY(pQuery)) { - dTrace(msg, GET_QINFO_ADDR(pQuery), "interp", pQuery->order.order, TSDB_ORDER_ASC, pQuery->window.skey, + qTrace(msg, GET_QINFO_ADDR(pQuery), "interp", pQuery->order.order, TSDB_ORDER_ASC, pQuery->window.skey, pQuery->window.ekey, pQuery->window.ekey, pQuery->window.skey); SWAP(pQuery->window.skey, pQuery->window.ekey, TSKEY); } @@ -1917,7 +1915,7 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) { if (pQuery->intervalTime == 0) { if (onlyFirstQuery(pQuery)) { if (!QUERY_IS_ASC_QUERY(pQuery)) { - dTrace(msg, GET_QINFO_ADDR(pQuery), "only-first", pQuery->order.order, TSDB_ORDER_ASC, pQuery->window.skey, + qTrace(msg, GET_QINFO_ADDR(pQuery), "only-first", pQuery->order.order, TSDB_ORDER_ASC, pQuery->window.skey, pQuery->window.ekey, pQuery->window.ekey, pQuery->window.skey); SWAP(pQuery->window.skey, pQuery->window.ekey, TSKEY); @@ -1926,7 +1924,7 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) { pQuery->order.order = TSDB_ORDER_ASC; } else if (onlyLastQuery(pQuery)) { if (QUERY_IS_ASC_QUERY(pQuery)) { - dTrace(msg, GET_QINFO_ADDR(pQuery), "only-last", pQuery->order.order, TSDB_ORDER_DESC, pQuery->window.skey, + qTrace(msg, GET_QINFO_ADDR(pQuery), "only-last", pQuery->order.order, TSDB_ORDER_DESC, pQuery->window.skey, pQuery->window.ekey, pQuery->window.ekey, pQuery->window.skey); SWAP(pQuery->window.skey, pQuery->window.ekey, TSKEY); @@ -1939,7 +1937,7 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) { if (metricQuery) { if (onlyFirstQuery(pQuery)) { if (!QUERY_IS_ASC_QUERY(pQuery)) { - dTrace(msg, GET_QINFO_ADDR(pQuery), "only-first stable", pQuery->order.order, TSDB_ORDER_ASC, + qTrace(msg, GET_QINFO_ADDR(pQuery), "only-first stable", pQuery->order.order, TSDB_ORDER_ASC, pQuery->window.skey, pQuery->window.ekey, pQuery->window.ekey, pQuery->window.skey); SWAP(pQuery->window.skey, pQuery->window.ekey, TSKEY); @@ -1948,7 +1946,7 @@ static void changeExecuteScanOrder(SQuery *pQuery, bool metricQuery) { pQuery->order.order = TSDB_ORDER_ASC; } else if (onlyLastQuery(pQuery)) { if (QUERY_IS_ASC_QUERY(pQuery)) { - dTrace(msg, GET_QINFO_ADDR(pQuery), "only-last stable", pQuery->order.order, TSDB_ORDER_DESC, + qTrace(msg, GET_QINFO_ADDR(pQuery), "only-last stable", pQuery->order.order, TSDB_ORDER_DESC, pQuery->window.skey, pQuery->window.ekey, pQuery->window.ekey, pQuery->window.skey); SWAP(pQuery->window.skey, pQuery->window.ekey, TSKEY); @@ -2229,7 +2227,7 @@ char *getPosInResultPage(SQueryRuntimeEnv *pRuntimeEnv, int32_t columnIndex, SWi int32_t UNUSED_FUNC vnodeSTableQueryPrepare(SQInfo *pQInfo, SQuery *pQuery, void *param) { if ((QUERY_IS_ASC_QUERY(pQuery) && (pQuery->window.skey > pQuery->window.ekey)) || (!QUERY_IS_ASC_QUERY(pQuery) && (pQuery->window.ekey > pQuery->window.skey))) { - dTrace("QInfo:%p no result in time range %" PRId64 "-%" PRId64 ", order %d", pQInfo, pQuery->window.skey, + qTrace("QInfo:%p no result in time range %" PRId64 "-%" PRId64 ", order %d", pQInfo, pQuery->window.skey, pQuery->window.ekey, pQuery->order.order); sem_post(&pQInfo->dataReady); @@ -2338,7 +2336,7 @@ void vnodeDecMeterRefcnt(SQInfo *pQInfo) { #if 0 if (pQInfo == NULL || pQInfo->groupInfo.numOfTables == 1) { atomic_fetch_sub_32(&pQInfo->pObj->numOfQueries, 1); - dTrace("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pQInfo->pObj->vnode, + qTrace("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pQInfo->pObj->vnode, pQInfo->pObj->sid, pQInfo->pObj->meterId, pQInfo->pObj->numOfQueries); } else { int32_t num = 0; @@ -2347,7 +2345,7 @@ void vnodeDecMeterRefcnt(SQInfo *pQInfo) { atomic_fetch_sub_32(&(pMeter->numOfQueries), 1); if (pMeter->numOfQueries > 0) { - dTrace("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pMeter->vnode, pMeter->sid, + qTrace("QInfo:%p vid:%d sid:%d meterId:%s, query is over, numOfQueries:%d", pQInfo, pMeter->vnode, pMeter->sid, pMeter->meterId, pMeter->numOfQueries); num++; } @@ -2358,7 +2356,7 @@ void vnodeDecMeterRefcnt(SQInfo *pQInfo) { * we do not output corresponding information */ num = pQInfo->groupInfo.numOfTables - num; - dTrace("QInfo:%p metric query is over, dec query ref for %d meters, numOfQueries on %d meters are 0", pQInfo, + qTrace("QInfo:%p metric query is over, dec query ref for %d meters, numOfQueries on %d meters are 0", pQInfo, pQInfo->groupInfo.numOfTables, num); } #endif @@ -2489,7 +2487,7 @@ SArray *loadDataBlockOnDemand(SQueryRuntimeEnv *pRuntimeEnv, SDataBlockInfo *pBl */ if (!needToLoadDataBlock(pQuery, *pStatis, pRuntimeEnv->pCtx, pBlockInfo->rows)) { #if defined(_DEBUG_VIEW) - dTrace("QInfo:%p fileId:%d, slot:%d, block discarded by per-filter", GET_QINFO_ADDR(pQuery), pQuery->fileId, + qTrace("QInfo:%p fileId:%d, slot:%d, block discarded by per-filter", GET_QINFO_ADDR(pQuery), pQuery->fileId, pQuery->slot); #endif // return DISK_DATA_DISCARDED; @@ -2566,7 +2564,7 @@ int32_t binarySearchForKey(char *pValue, int num, TSKEY key, int order) { static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { SQuery *pQuery = pRuntimeEnv->pQuery; - dTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", lastkey:%" PRId64 ", order:%d", + qTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", lastkey:%" PRId64 ", order:%d", GET_QINFO_ADDR(pRuntimeEnv), pQuery->window.skey, pQuery->window.ekey, pQuery->lastKey, pQuery->order.order); TsdbQueryHandleT pQueryHandle = pRuntimeEnv->scanFlag == MASTER_SCAN? pRuntimeEnv->pQueryHandle:pRuntimeEnv->pSecQueryHandle; @@ -2629,7 +2627,7 @@ static int64_t doScanAllDataBlocks(SQueryRuntimeEnv *pRuntimeEnv) { int32_t numOfRes = tableApplyFunctionsOnBlock(pRuntimeEnv, &blockInfo, pStatis, binarySearchForKey, &pRuntimeEnv->windowResInfo, pDataBlock); - dTrace("QInfo:%p check data block, brange:%" PRId64 "-%" PRId64 ", rows:%d, res:%d", + qTrace("QInfo:%p check data block, brange:%" PRId64 "-%" PRId64 ", rows:%d, res:%d", GET_QINFO_ADDR(pRuntimeEnv), blockInfo.window.skey, blockInfo.window.ekey, blockInfo.rows, numOfRes); // save last access position @@ -2924,10 +2922,10 @@ int32_t mergeIntoGroupResult(SQInfo *pQInfo) { } assert(pQInfo->numOfGroupResultPages == 0); - dTrace("QInfo:%p no result in group %d, continue", pQInfo, pQInfo->subgroupIdx - 1); + qTrace("QInfo:%p no result in group %d, continue", pQInfo, pQInfo->subgroupIdx - 1); } - dTrace("QInfo:%p merge res data into group, index:%d, total group:%d, elapsed time:%lldms", + qTrace("QInfo:%p merge res data into group, index:%d, total group:%d, elapsed time:%lldms", pQInfo, pQInfo->subgroupIdx - 1, numOfGroups, taosGetTimestampMs() - st); return TSDB_CODE_SUCCESS; @@ -3108,7 +3106,7 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray* pGroup) { if (buffer[0]->numOfElems != 0) { // there are data in buffer if (flushFromResultBuf(pQInfo) != TSDB_CODE_SUCCESS) { - dError("QInfo:%p failed to flush data into temp file, abort query", pQInfo); + qError("QInfo:%p failed to flush data into temp file, abort query", pQInfo); tfree(pTree); tfree(pTableList); @@ -3125,7 +3123,7 @@ int32_t mergeIntoGroupResultImpl(SQInfo *pQInfo, SArray* pGroup) { displayInterResult(pQuery->sdata, pQuery, pQuery->sdata[0]->len); #endif - dTrace("QInfo:%p result merge completed, elapsed time:%" PRId64 " ms", GET_QINFO_ADDR(pQuery), endt - startt); + qTrace("QInfo:%p result merge completed, elapsed time:%" PRId64 " ms", GET_QINFO_ADDR(pQuery), endt - startt); tfree(pTree); tfree(pTableList); tfree(posList); @@ -3433,7 +3431,7 @@ static void doSingleMeterSupplementScan(SQueryRuntimeEnv *pRuntimeEnv) { return; } - dTrace("QInfo:%p start to supp scan", GET_QINFO_ADDR(pQuery)); + qTrace("QInfo:%p start to supp scan", GET_QINFO_ADDR(pQuery)); SET_SUPPLEMENT_SCAN_FLAG(pRuntimeEnv); // close necessary function execution during supplementary scan @@ -3873,7 +3871,7 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SWindowResult *result, int32_t orde int32_t startIdx = 0; int32_t step = -1; - dTrace("QInfo:%p start to copy data from windowResInfo to query buf", GET_QINFO_ADDR(pQuery)); + qTrace("QInfo:%p start to copy data from windowResInfo to query buf", GET_QINFO_ADDR(pQuery)); int32_t totalSubset = getNumOfSubset(pQInfo); if (orderType == TSDB_ORDER_ASC) { @@ -3922,7 +3920,7 @@ static int32_t doCopyToSData(SQInfo *pQInfo, SWindowResult *result, int32_t orde } } - dTrace("QInfo:%p copy data to query buf completed", pQInfo); + qTrace("QInfo:%p copy data to query buf completed", pQInfo); #ifdef _DEBUG_VIEW displayInterResult(pQuery->sdata, pQuery, numOfResult); @@ -4130,23 +4128,23 @@ void vnodePrintQueryStatistics(SQInfo *pQInfo) { pSummary->tmpBufferInDisk = getResBufSize(pRuntimeEnv->pResultBuf); } - dTrace("QInfo:%p statis: comp blocks:%d, size:%d Bytes, elapsed time:%.2f ms", pQInfo, pSummary->readCompInfo, + qTrace("QInfo:%p statis: comp blocks:%d, size:%d Bytes, elapsed time:%.2f ms", pQInfo, pSummary->readCompInfo, pSummary->totalCompInfoSize, pSummary->loadCompInfoUs / 1000.0); - dTrace("QInfo:%p statis: field info: %d, size:%d Bytes, avg size:%.2f Bytes, elapsed time:%.2f ms", pQInfo, + qTrace("QInfo:%p statis: field info: %d, size:%d Bytes, avg size:%.2f Bytes, elapsed time:%.2f ms", pQInfo, pSummary->readField, pSummary->totalFieldSize, (double)pSummary->totalFieldSize / pSummary->readField, pSummary->loadFieldUs / 1000.0); - dTrace( + qTrace( "QInfo:%p statis: file blocks:%d, size:%d Bytes, elapsed time:%.2f ms, skipped:%d, in-memory gen null:%d Bytes", pQInfo, pSummary->readDiskBlocks, pSummary->totalBlockSize, pSummary->loadBlocksUs / 1000.0, pSummary->skippedFileBlocks, pSummary->totalGenData); - dTrace("QInfo:%p statis: cache blocks:%d", pQInfo, pSummary->blocksInCache, 0); - dTrace("QInfo:%p statis: temp file:%d Bytes", pQInfo, pSummary->tmpBufferInDisk); + qTrace("QInfo:%p statis: cache blocks:%d", pQInfo, pSummary->blocksInCache, 0); + qTrace("QInfo:%p statis: temp file:%d Bytes", pQInfo, pSummary->tmpBufferInDisk); - dTrace("QInfo:%p statis: file:%d, table:%d", pQInfo, pSummary->numOfFiles, pSummary->numOfTables); - dTrace("QInfo:%p statis: seek ops:%d", pQInfo, pSummary->numOfSeek); + qTrace("QInfo:%p statis: file:%d, table:%d", pQInfo, pSummary->numOfFiles, pSummary->numOfTables); + qTrace("QInfo:%p statis: seek ops:%d", pQInfo, pSummary->numOfSeek); double total = pSummary->fileTimeUs + pSummary->cacheTimeUs; double io = pSummary->loadCompInfoUs + pSummary->loadBlocksUs + pSummary->loadFieldUs; @@ -4154,7 +4152,7 @@ void vnodePrintQueryStatistics(SQInfo *pQInfo) { // todo add the intermediate result save cost!! double computing = total - io; - dTrace( + qTrace( "QInfo:%p statis: total elapsed time:%.2f ms, file:%.2f ms(%.2f%), cache:%.2f ms(%.2f%). io:%.2f ms(%.2f%)," "comput:%.2fms(%.2f%)", pQInfo, total / 1000.0, pSummary->fileTimeUs / 1000.0, pSummary->fileTimeUs * 100 / total, @@ -4398,7 +4396,7 @@ static bool multiTableMultioutputHelper(SQInfo *pQInfo, int32_t index) { setTagVal(pRuntimeEnv, pTable->tableId, pQInfo->tsdb); - dTrace("QInfo:%p query on (%d): uid:%" PRIu64 ", tid:%d, qrange:%" PRId64 "-%" PRId64, pQInfo, index, + qTrace("QInfo:%p query on (%d): uid:%" PRIu64 ", tid:%d, qrange:%" PRId64 "-%" PRId64, pQInfo, index, pTable->tableId.uid, pInfo->pTableQInfo->lastKey, pInfo->pTableQInfo->win.ekey); STsdbQueryCond cond = { @@ -4509,7 +4507,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) { size_t numOfTable = taosArrayGetSize(group); if (isFirstLastRowQuery(pQuery)) { - dTrace("QInfo:%p last_row query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pTableIdList->numOfSubSet, + qTrace("QInfo:%p last_row query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pTableIdList->numOfSubSet, pQInfo->subgroupIdx); TSKEY key = -1; @@ -4530,7 +4528,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) { // int64_t num = doCheckMetersInGroup(pQInfo, index, start); // assert(num >= 0); } else { - dTrace("QInfo:%p interp query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pTableIdList->numOfSubSet, + qTrace("QInfo:%p interp query on vid:%d, numOfGroups:%d, current group:%d", pQInfo, vid, pTableIdList->numOfSubSet, pQInfo->subgroupIdx); for (int32_t k = start; k <= end; ++k) { @@ -4705,7 +4703,7 @@ static void sequentialTableProcess(SQInfo *pQInfo) { pQuery->rec.total += pQuery->rec.rows; - dTrace( "QInfo %p, numOfTables:%d, index:%d, numOfGroups:%d, %d points returned, total:%d totalReturn:%d," + qTrace( "QInfo %p, numOfTables:%d, index:%d, numOfGroups:%d, %d points returned, total:%d totalReturn:%d," " offset:%" PRId64, pQInfo, pQInfo->groupInfo.numOfTables, pQInfo->tableIndex, numOfGroups, pQuery->rec.rows, pQuery->rec.total, pQuery->limit.offset); } @@ -4829,11 +4827,11 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { // vnodePrintQueryStatistics(pSupporter); } - dTrace("QInfo:%p current:%lld, total:%lld", pQInfo, pQuery->rec.rows, pQuery->rec.total); + qTrace("QInfo:%p current:%lld, total:%lld", pQInfo, pQuery->rec.rows, pQuery->rec.total); return; } - dTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", order:%d, forward scan start", pQInfo, pQuery->window.skey, + qTrace("QInfo:%p query start, qrange:%" PRId64 "-%" PRId64 ", order:%d, forward scan start", pQInfo, pQuery->window.skey, pQuery->window.ekey, pQuery->order.order); // create the query support structures @@ -4841,12 +4839,12 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { // do check all qualified data blocks int64_t el = queryOnDataBlocks(pQInfo); - dTrace("QInfo:%p forward scan completed, elapsed time: %lldms, reversed scan start, order:%d", pQInfo, el, + qTrace("QInfo:%p forward scan completed, elapsed time: %lldms, reversed scan start, order:%d", pQInfo, el, pQuery->order.order ^ 1u); // query error occurred or query is killed, abort current execution if (pQInfo->code != TSDB_CODE_SUCCESS || isQueryKilled(pQInfo)) { - dTrace("QInfo:%p query killed or error occurred, code:%d, abort", pQInfo, pQInfo->code); + qTrace("QInfo:%p query killed or error occurred, code:%d, abort", pQInfo, pQInfo->code); return; } @@ -4857,17 +4855,17 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { doSaveContext(pQInfo); el = queryOnDataBlocks(pQInfo); - dTrace("QInfo:%p reversed scan completed, elapsed time: %lldms", pQInfo, el); + qTrace("QInfo:%p reversed scan completed, elapsed time: %lldms", pQInfo, el); doRestoreContext(pQInfo); } else { - dTrace("QInfo:%p no need to do reversed scan, query completed", pQInfo); + qTrace("QInfo:%p no need to do reversed scan, query completed", pQInfo); } setQueryStatus(pQuery, QUERY_COMPLETED); if (pQInfo->code != TSDB_CODE_SUCCESS || isQueryKilled(pQInfo)) { - dTrace("QInfo:%p query killed or error occurred, code:%d, abort", pQInfo, pQInfo->code); + qTrace("QInfo:%p query killed or error occurred, code:%d, abort", pQInfo, pQInfo->code); return; } @@ -4886,7 +4884,7 @@ static void multiTableQueryProcess(SQInfo *pQInfo) { } // handle the limitation of output buffer - dTrace("QInfo:%p points returned:%d, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total + pQuery->rec.rows); + qTrace("QInfo:%p points returned:%d, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total + pQuery->rec.rows); } /* @@ -4948,7 +4946,7 @@ static void tableMultiOutputProcess(SQInfo *pQInfo) { break; } - dTrace("QInfo:%p vid:%d sid:%d id:%s, skip current result, offset:%" PRId64 ", next qrange:%" PRId64 "-%" PRId64, + qTrace("QInfo:%p vid:%d sid:%d id:%s, skip current result, offset:%" PRId64 ", next qrange:%" PRId64 "-%" PRId64, pQInfo, pQuery->limit.offset, pQuery->lastKey); resetCtxOutputBuf(pRuntimeEnv); @@ -4956,11 +4954,11 @@ static void tableMultiOutputProcess(SQInfo *pQInfo) { doRevisedResultsByLimit(pQInfo); if (Q_STATUS_EQUAL(pQuery->status, QUERY_RESBUF_FULL)) { - dTrace("QInfo:%p query paused due to output limitation, next qrange:%" PRId64 "-%" PRId64, + qTrace("QInfo:%p query paused due to output limitation, next qrange:%" PRId64 "-%" PRId64, pQInfo, pQuery->lastKey, pQuery->window.ekey); } -// dTrace("QInfo:%p vid:%d sid:%d id:%s, %d points returned, totalRead:%d totalReturn:%d", pQInfo, pMeterObj->vnode, +// qTrace("QInfo:%p vid:%d sid:%d id:%s, %d points returned, totalRead:%d totalReturn:%d", pQInfo, pMeterObj->vnode, // pMeterObj->sid, pMeterObj->meterId, pQuery->size, pQInfo->size, pQInfo->pointsReturned); if (!isTSCompQuery(pQuery)) { @@ -5033,7 +5031,7 @@ static void tableIntervalProcess(SQInfo *pQInfo) { pQuery->rec.rows = vnodeQueryResultInterpolate( pQInfo, (tFilePage **)pQuery->sdata, (tFilePage **)pInterpoBuf, pQuery->rec.rows, &numOfInterpo); - dTrace("QInfo: %p interpo completed, final:%d", pQInfo, pQuery->rec.rows); + qTrace("QInfo: %p interpo completed, final:%d", pQInfo, pQuery->rec.rows); if (pQuery->rec.rows > 0 || Q_STATUS_EQUAL(pQuery->status, QUERY_COMPLETED)) { doRevisedResultsByLimit(pQInfo); break; @@ -5072,7 +5070,7 @@ static void tableQueryImpl(SQInfo* pQInfo) { doRevisedResultsByLimit(pQInfo); pQInfo->pointsInterpo += numOfInterpo; - dTrace("QInfo:%p current:%d returned, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total); + qTrace("QInfo:%p current:%d returned, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total); sem_post(&pQInfo->dataReady); return; } @@ -5094,14 +5092,14 @@ static void tableQueryImpl(SQInfo* pQInfo) { clearFirstNTimeWindow(pRuntimeEnv, pQInfo->subgroupIdx); if (pQuery->rec.rows > 0) { - dTrace("QInfo:%p %d rows returned from group results, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total); + qTrace("QInfo:%p %d rows returned from group results, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total); sem_post(&pQInfo->dataReady); return; } } } - dTrace("QInfo:%p query over, %d rows are returned", pQInfo, pQuery->rec.total); + qTrace("QInfo:%p query over, %d rows are returned", pQInfo, pQuery->rec.total); // vnodePrintQueryStatistics(pSupporter); sem_post(&pQInfo->dataReady); return; @@ -5127,10 +5125,10 @@ static void tableQueryImpl(SQInfo* pQInfo) { /* check if query is killed or not */ if (isQueryKilled(pQInfo)) { - dTrace("QInfo:%p query is killed", pQInfo); + qTrace("QInfo:%p query is killed", pQInfo); } else { // STableId* pTableId = taosArrayGet(pQInfo->groupInfo, 0); -// dTrace("QInfo:%p uid:%" PRIu64 " tid:%d, query completed, %" PRId64 " rows returned, numOfTotal:%" PRId64 " rows", +// qTrace("QInfo:%p uid:%" PRIu64 " tid:%d, query completed, %" PRId64 " rows returned, numOfTotal:%" PRId64 " rows", // pQInfo, pTableId->uid, pTableId->tid, pQuery->rec.rows, pQuery->rec.total + pQuery->rec.rows); } @@ -5158,7 +5156,7 @@ static void stableQueryImpl(SQInfo* pQInfo) { // taosInterpoSetStartInfo(&pQInfo->runtimeEnv.interpoInfo, pQuery->size, pQInfo->query.interpoType); if (pQuery->rec.rows == 0) { - dTrace("QInfo:%p over, %d tables queried, %d points are returned", pQInfo, pQInfo->groupInfo.numOfTables, pQuery->rec.total); + qTrace("QInfo:%p over, %d tables queried, %d points are returned", pQInfo, pQInfo->groupInfo.numOfTables, pQuery->rec.total); // vnodePrintQueryStatistics(pSupporter); } @@ -5186,27 +5184,27 @@ bool vnodeValidateExprColumnInfo(SQueryTableMsg *pQueryMsg, SSqlFuncExprMsg *pEx static int32_t validateQueryMsg(SQueryTableMsg *pQueryMsg) { if (pQueryMsg->intervalTime < 0) { - dError("qmsg:%p illegal value of aggTimeInterval %" PRId64 "", pQueryMsg, pQueryMsg->intervalTime); + qError("qmsg:%p illegal value of aggTimeInterval %" PRId64 "", pQueryMsg, pQueryMsg->intervalTime); return -1; } if (pQueryMsg->numOfCols <= 0 || pQueryMsg->numOfCols > TSDB_MAX_COLUMNS) { - dError("qmsg:%p illegal value of numOfCols %d", pQueryMsg, pQueryMsg->numOfCols); + qError("qmsg:%p illegal value of numOfCols %d", pQueryMsg, pQueryMsg->numOfCols); return -1; } if (pQueryMsg->numOfTables <= 0) { - dError("qmsg:%p illegal value of numOfTables %d", pQueryMsg, pQueryMsg->numOfTables); + qError("qmsg:%p illegal value of numOfTables %d", pQueryMsg, pQueryMsg->numOfTables); return -1; } if (pQueryMsg->numOfGroupCols < 0) { - dError("qmsg:%p illegal value of numOfGroupbyCols %d", pQueryMsg, pQueryMsg->numOfGroupCols); + qError("qmsg:%p illegal value of numOfGroupbyCols %d", pQueryMsg, pQueryMsg->numOfGroupCols); return -1; } if (pQueryMsg->numOfOutputCols > TSDB_MAX_COLUMNS || pQueryMsg->numOfOutputCols <= 0) { - dError("qmsg:%p illegal value of output columns %d", pQueryMsg, pQueryMsg->numOfOutputCols); + qError("qmsg:%p illegal value of output columns %d", pQueryMsg, pQueryMsg->numOfOutputCols); return -1; } @@ -5412,7 +5410,7 @@ static int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SArray **pTableIdList, memcpy(*tagCond, pMsg, pQueryMsg->tagCondLen); } - dTrace("qmsg:%p query on %d table(s), qrange:%" PRId64 "-%" PRId64 ", numOfGroupbyTagCols:%d, ts order:%d, " + qTrace("qmsg:%p query on %d table(s), qrange:%" PRId64 "-%" PRId64 ", numOfGroupbyTagCols:%d, ts order:%d, " "outputCols:%d, numOfCols:%d, interval:%d" PRId64 ", fillType:%d, comptsLen:%d, limit:%" PRId64 ", offset:%" PRId64, pQueryMsg, pQueryMsg->numOfTables, pQueryMsg->window.skey, pQueryMsg->window.ekey, pQueryMsg->numOfGroupCols, pQueryMsg->order, pQueryMsg->numOfOutputCols, @@ -5429,12 +5427,12 @@ static int32_t buildAirthmeticExprFromMsg(SSqlFunctionExpr *pExpr, SQueryTableMs tExprNode* pBinExpr = NULL; SSchema* pSchema = toSchema(pQueryMsg, pColMsg, pQueryMsg->numOfCols); - dTrace("qmsg:%p create binary expr from string:%s", pQueryMsg, pExpr->pBase.arg[0].argValue.pz); + qTrace("qmsg:%p create binary expr from string:%s", pQueryMsg, pExpr->pBase.arg[0].argValue.pz); tSQLBinaryExprFromString(&pBinExpr, pSchema, pQueryMsg->numOfCols, pExpr->pBase.arg[0].argValue.pz, pExpr->pBase.arg[0].argBytes); if (pBinExpr == NULL) { - dError("qmsg:%p failed to create arithmetic expression string from:%s", pQueryMsg, pExpr->pBase.arg[0].argValue.pz); + qError("qmsg:%p failed to create arithmetic expression string from:%s", pQueryMsg, pExpr->pBase.arg[0].argValue.pz); return TSDB_CODE_APP_ERROR; } @@ -5603,7 +5601,7 @@ static int32_t vnodeCreateFilterInfo(void *pQInfo, SQuery *pQuery) { int32_t upper = pSingleColFilter->filterInfo.upperRelOptr; if (lower == TSDB_RELATION_INVALID && upper == TSDB_RELATION_INVALID) { - dError("QInfo:%p invalid filter info", pQInfo); + qError("QInfo:%p invalid filter info", pQInfo); return TSDB_CODE_INVALID_QUERY_MSG; } @@ -5614,7 +5612,7 @@ static int32_t vnodeCreateFilterInfo(void *pQInfo, SQuery *pQuery) { __filter_func_t *filterArray = NULL; // vnodeGetValueFilterFuncArray(type); if (rangeFilterArray == NULL && filterArray == NULL) { - dError("QInfo:%p failed to get filter function, invalid data type:%d", pQInfo, type); + qError("QInfo:%p failed to get filter function, invalid data type:%d", pQInfo, type); return TSDB_CODE_INVALID_QUERY_MSG; } @@ -5638,7 +5636,7 @@ static int32_t vnodeCreateFilterInfo(void *pQInfo, SQuery *pQuery) { pSingleColFilter->fp = filterArray[lower]; if (upper != TSDB_RELATION_INVALID) { - dError("pQInfo:%p failed to get filter function, invalid filter condition", pQInfo, type); + qError("pQInfo:%p failed to get filter function, invalid filter condition", pQInfo, type); return TSDB_CODE_INVALID_QUERY_MSG; } } else { @@ -5797,13 +5795,13 @@ static SQInfo *createQInfoImpl(SQueryTableMsg *pQueryMsg, SSqlGroupbyExpr *pGrou pQuery->lastKey = pQuery->window.skey; if (sem_init(&pQInfo->dataReady, 0, 0) != 0) { - dError("QInfo:%p init dataReady sem failed, reason:%s", pQInfo, strerror(errno)); + qError("QInfo:%p init dataReady sem failed, reason:%s", pQInfo, strerror(errno)); goto _clean_memory; } vnodeParametersSafetyCheck(pQuery); - dTrace("qmsg:%p QInfo:%p created", pQueryMsg, pQInfo); + qTrace("qmsg:%p QInfo:%p created", pQueryMsg, pQInfo); return pQInfo; _clean_memory: @@ -5858,7 +5856,7 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void* tsdb, SQInfo *pQInfo, // only the successful complete requries the sem_post/over = 1 operations. if ((QUERY_IS_ASC_QUERY(pQuery) && (pQuery->window.skey > pQuery->window.ekey)) || (!QUERY_IS_ASC_QUERY(pQuery) && (pQuery->window.ekey > pQuery->window.skey))) { - dTrace("QInfo:%p no result in time range %" PRId64 "-%" PRId64 ", order %d", pQInfo, pQuery->window.skey, + qTrace("QInfo:%p no result in time range %" PRId64 "-%" PRId64 ", order %d", pQInfo, pQuery->window.skey, pQuery->window.ekey, pQuery->order.order); sem_post(&pQInfo->dataReady); @@ -5871,7 +5869,7 @@ static int32_t initQInfo(SQueryTableMsg *pQueryMsg, void* tsdb, SQInfo *pQInfo, goto _error; } - // dTrace("QInfo:%p set query flag and prepare runtime environment completed, ref:%d, wait for schedule", pQInfo, + // qTrace("QInfo:%p set query flag and prepare runtime environment completed, ref:%d, wait for schedule", pQInfo, // pQInfo->refCount); return code; @@ -5889,7 +5887,7 @@ static void freeQInfo(SQInfo *pQInfo) { SQuery* pQuery = pQInfo->runtimeEnv.pQuery; setQueryKilled(pQInfo); - dTrace("QInfo:%p start to free QInfo", pQInfo); + qTrace("QInfo:%p start to free QInfo", pQInfo); for (int32_t col = 0; col < pQuery->numOfOutputCols; ++col) { tfree(pQuery->sdata[col]); } @@ -5937,7 +5935,7 @@ static void freeQInfo(SQInfo *pQInfo) { taosArrayDestroy(pQInfo->groupInfo.pGroupList); - dTrace("QInfo:%p QInfo is freed", pQInfo); + qTrace("QInfo:%p QInfo is freed", pQInfo); // destroy signature, in order to avoid the query process pass the object safety check memset(pQInfo, 0, sizeof(SQInfo)); @@ -5958,7 +5956,7 @@ static size_t getResultSize(SQInfo *pQInfo, int64_t *numOfRows) { *numOfRows = fstat.st_size; return fstat.st_size; } else { - dError("QInfo:%p failed to get file info, path:%s, reason:%s", pQInfo, pQuery->sdata[0]->data, strerror(errno)); + qError("QInfo:%p failed to get file info, path:%s, reason:%s", pQInfo, pQuery->sdata[0]->data, strerror(errno)); return 0; } } else { @@ -5977,7 +5975,7 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) { // make sure file exist if (FD_VALID(fd)) { size_t s = lseek(fd, 0, SEEK_END); - dTrace("QInfo:%p ts comp data return, file:%s, size:%zu", pQInfo, pQuery->sdata[0]->data, s); + qTrace("QInfo:%p ts comp data return, file:%s, size:%zu", pQInfo, pQuery->sdata[0]->data, s); lseek(fd, 0, SEEK_SET); read(fd, data, s); @@ -5985,7 +5983,7 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) { unlink(pQuery->sdata[0]->data); } else { - dError("QInfo:%p failed to open tmp file to send ts-comp data to client, path:%s, reason:%s", pQInfo, + qError("QInfo:%p failed to open tmp file to send ts-comp data to client, path:%s, reason:%s", pQInfo, pQuery->sdata[0]->data, strerror(errno)); } } else { @@ -5993,7 +5991,7 @@ static int32_t doDumpQueryResult(SQInfo *pQInfo, char *data) { } pQuery->rec.total += pQuery->rec.rows; - dTrace("QInfo:%p current:%d, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total); + qTrace("QInfo:%p current:%d, total:%d", pQInfo, pQuery->rec.rows, pQuery->rec.total); return TSDB_CODE_SUCCESS; @@ -6015,14 +6013,14 @@ int32_t qCreateQueryInfo(void* tsdb, SQueryTableMsg *pQueryMsg, qinfo_t *pQInfo) } if (pQueryMsg->numOfTables <= 0) { - dError("Invalid number of tables to query, numOfTables:%d", pQueryMsg->numOfTables); + qError("Invalid number of tables to query, numOfTables:%d", pQueryMsg->numOfTables); code = TSDB_CODE_INVALID_QUERY_MSG; goto _query_over; } // todo check vnode status if (pTableIdList == NULL || taosArrayGetSize(pTableIdList) == 0) { - dError("qmsg:%p, SQueryTableMsg wrong format", pQueryMsg); + qError("qmsg:%p, SQueryTableMsg wrong format", pQueryMsg); code = TSDB_CODE_INVALID_QUERY_MSG; goto _query_over; } @@ -6091,7 +6089,7 @@ _query_over: } void qDestroyQueryInfo(qinfo_t pQInfo) { - dTrace("QInfo:%p query completed", pQInfo); + qTrace("QInfo:%p query completed", pQInfo); freeQInfo(pQInfo); } @@ -6099,16 +6097,16 @@ void qTableQuery(qinfo_t qinfo) { SQInfo* pQInfo = (SQInfo*) qinfo; if (pQInfo == NULL || pQInfo->signature != pQInfo) { - dTrace("%p freed abort query", pQInfo); + qTrace("%p freed abort query", pQInfo); return; } if (isQueryKilled(pQInfo)) { - dTrace("QInfo:%p it is already killed, abort", pQInfo); + qTrace("QInfo:%p it is already killed, abort", pQInfo); return; } - dTrace("QInfo:%p query task is launched", pQInfo); + qTrace("QInfo:%p query task is launched", pQInfo); if (pQInfo->runtimeEnv.stableQuery) { stableQueryImpl(pQInfo); @@ -6128,12 +6126,12 @@ int32_t qRetrieveQueryResultInfo(qinfo_t qinfo) { SQuery *pQuery = pQInfo->runtimeEnv.pQuery; if (isQueryKilled(pQInfo)) { - dTrace("QInfo:%p query is killed, code:%d", pQInfo, pQInfo->code); + qTrace("QInfo:%p query is killed, code:%d", pQInfo, pQInfo->code); return pQInfo->code; } sem_wait(&pQInfo->dataReady); - dTrace("QInfo:%p retrieve result info, rowsize:%d, rows:%d, code:%d", pQInfo, pQuery->rowSize, pQuery->rec.rows, + qTrace("QInfo:%p retrieve result info, rowsize:%d, rows:%d, code:%d", pQInfo, pQuery->rowSize, pQuery->rec.rows, pQInfo->code); return pQInfo->code; @@ -6196,7 +6194,7 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp** pRsp, int32_t* co return code; // if (numOfRows == 0 && (pRetrieve->qhandle == (uint64_t)pObj->qhandle) && (code != TSDB_CODE_ACTION_IN_PROGRESS)) { -// dTrace("QInfo:%p %s free qhandle code:%d", pObj->qhandle, __FUNCTION__, code); +// qTrace("QInfo:%p %s free qhandle code:%d", pObj->qhandle, __FUNCTION__, code); // vnodeDecRefCount(pObj->qhandle); // pObj->qhandle = NULL; // } diff --git a/src/query/src/tlosertree.c b/src/query/src/tlosertree.c index e6e45ed8d0..4e3063da03 100644 --- a/src/query/src/tlosertree.c +++ b/src/query/src/tlosertree.c @@ -15,8 +15,8 @@ #include "os.h" #include "taosmsg.h" -#include "tlog.h" #include "tlosertree.h" +#include "queryLog.h" // set initial value for loser tree void tLoserTreeInit(SLoserTreeInfo* pTree) { @@ -45,7 +45,7 @@ uint32_t tLoserTreeCreate(SLoserTreeInfo** pTree, int32_t numOfEntries, void* pa *pTree = (SLoserTreeInfo*)calloc(1, sizeof(SLoserTreeInfo) + sizeof(SLoserTreeNode) * totalEntries); if ((*pTree) == NULL) { - pError("allocate memory for loser-tree failed. reason:%s", strerror(errno)); + qError("allocate memory for loser-tree failed. reason:%s", strerror(errno)); return TSDB_CODE_CLI_OUT_OF_MEMORY; } diff --git a/src/rpc/CMakeLists.txt b/src/rpc/CMakeLists.txt index 141ae3499a..96c63b45ca 100644 --- a/src/rpc/CMakeLists.txt +++ b/src/rpc/CMakeLists.txt @@ -4,6 +4,7 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/lz4/inc) INCLUDE_DIRECTORIES(inc) diff --git a/src/rpc/inc/rpcLog.h b/src/rpc/inc/rpcLog.h new file mode 100644 index 0000000000..251863f1de --- /dev/null +++ b/src/rpc/inc/rpcLog.h @@ -0,0 +1,50 @@ +/* + * 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_RPC_LOG_H +#define TDENGINE_RPC_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tlog.h" + +extern int32_t rpcDebugFlag; + +#define tError(...) \ + if (rpcDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("ERROR RPC ", rpcDebugFlag, __VA_ARGS__); \ + } +#define tWarn(...) \ + if (rpcDebugFlag & DEBUG_WARN) { \ + taosPrintLog("WARN RPC ", rpcDebugFlag, __VA_ARGS__); \ + } +#define tTrace(...) \ + if (rpcDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("RPC ", rpcDebugFlag, __VA_ARGS__); \ + } +#define tPrint(...) \ + { taosPrintLog("RPC ", 255, __VA_ARGS__); } +#define tDump(x, y) \ + if (rpcDebugFlag & DEBUG_DUMP) { \ + taosDumpData((unsigned char *)x, y); \ + } + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_RPC_CACHE_H diff --git a/src/rpc/src/rpcCache.c b/src/rpc/src/rpcCache.c index 3370b31277..48d68c7511 100644 --- a/src/rpc/src/rpcCache.c +++ b/src/rpc/src/rpcCache.c @@ -14,12 +14,12 @@ */ #include "os.h" -#include "tglobalcfg.h" -#include "tlog.h" +#include "tglobal.h" #include "tmempool.h" #include "ttime.h" #include "ttimer.h" #include "tutil.h" +#include "rpcLog.h" #include "rpcCache.h" typedef struct SConnHash { diff --git a/src/rpc/src/rpcHaship.c b/src/rpc/src/rpcHaship.c index 43f2d138de..0183c87f70 100644 --- a/src/rpc/src/rpcHaship.c +++ b/src/rpc/src/rpcHaship.c @@ -14,8 +14,8 @@ */ #include "os.h" -#include "tlog.h" #include "tmempool.h" +#include "rpcLog.h" typedef struct SIpHash { uint32_t ip; diff --git a/src/rpc/src/rpcMain.c b/src/rpc/src/rpcMain.c index a51d9ee4b5..dede169349 100644 --- a/src/rpc/src/rpcMain.c +++ b/src/rpc/src/rpcMain.c @@ -15,7 +15,6 @@ #include "os.h" #include "tidpool.h" -#include "tlog.h" #include "tmd5.h" #include "tmempool.h" #include "ttime.h" @@ -24,13 +23,15 @@ #include "lz4.h" #include "taoserror.h" #include "tsocket.h" +#include "tglobal.h" #include "taosmsg.h" +#include "trpc.h" +#include "hash.h" +#include "rpcLog.h" #include "rpcUdp.h" #include "rpcCache.h" #include "rpcTcp.h" #include "rpcHead.h" -#include "trpc.h" -#include "hash.h" #define RPC_MSG_OVERHEAD (sizeof(SRpcReqContext) + sizeof(SRpcHead) + sizeof(SRpcDigest)) #define rpcHeadFromCont(cont) ((SRpcHead *) (cont - sizeof(SRpcHead))) @@ -124,6 +125,7 @@ typedef struct SRpcConn { SRpcReqContext *pContext; // request context } SRpcConn; +int tsRpcMaxUdpSize = 15000; // bytes int tsRpcProgressTime = 10; // milliseocnds // not configurable diff --git a/src/rpc/src/rpcTcp.c b/src/rpc/src/rpcTcp.c index 8e8b285621..75115d9ba0 100644 --- a/src/rpc/src/rpcTcp.c +++ b/src/rpc/src/rpcTcp.c @@ -14,10 +14,9 @@ */ #include "os.h" -#include "tlog.h" -#include "tlog.h" #include "tsocket.h" #include "tutil.h" +#include "rpcLog.h" #include "rpcHead.h" #include "rpcTcp.h" diff --git a/src/rpc/src/rpcUdp.c b/src/rpc/src/rpcUdp.c index 1e5ac3c6b5..25668fcb14 100644 --- a/src/rpc/src/rpcUdp.c +++ b/src/rpc/src/rpcUdp.c @@ -14,12 +14,12 @@ */ #include "os.h" -#include "tlog.h" #include "tsocket.h" #include "tsystem.h" #include "ttimer.h" #include "tutil.h" #include "thash.h" +#include "rpcLog.h" #include "rpcHaship.h" #include "rpcUdp.h" #include "rpcHead.h" diff --git a/src/rpc/test/CMakeLists.txt b/src/rpc/test/CMakeLists.txt index b519ae7578..6787de56f6 100644 --- a/src/rpc/test/CMakeLists.txt +++ b/src/rpc/test/CMakeLists.txt @@ -5,6 +5,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(../inc) LIST(APPEND CLIENT_SRC ./rclient.c) diff --git a/src/rpc/test/rclient.c b/src/rpc/test/rclient.c index 732d7eb81c..8fb549df8f 100644 --- a/src/rpc/test/rclient.c +++ b/src/rpc/test/rclient.c @@ -13,20 +13,11 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include #include "os.h" -#include "tlog.h" +#include "tglobal.h" +#include "rpcLog.h" #include "trpc.h" #include "taoserror.h" -#include -#include typedef struct { int index; @@ -168,7 +159,7 @@ int main(int argc, char *argv[]) { void *pRpc = rpcOpen(&rpcInit); if (pRpc == NULL) { - dError("failed to initialize RPC"); + tError("failed to initialize RPC"); return -1; } @@ -206,7 +197,7 @@ int main(int argc, char *argv[]) { getchar(); - taosCloseLogger(); + taosCloseLog(); return 0; } diff --git a/src/rpc/test/rsclient.c b/src/rpc/test/rsclient.c index b99387e097..786a6d69e5 100644 --- a/src/rpc/test/rsclient.c +++ b/src/rpc/test/rsclient.c @@ -13,20 +13,12 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include -#include -#include -#include + #include "os.h" -#include "tlog.h" +#include "tglobal.h" +#include "rpcLog.h" #include "trpc.h" #include "taoserror.h" -#include -#include typedef struct { int index; @@ -168,7 +160,7 @@ int main(int argc, char *argv[]) { void *pRpc = rpcOpen(&rpcInit); if (pRpc == NULL) { - dError("failed to initialize RPC"); + tError("failed to initialize RPC"); return -1; } @@ -204,7 +196,7 @@ int main(int argc, char *argv[]) { tPrint("it takes %.3f mseconds to send %d requests to server, error num:%d", usedTime, numOfReqs*appThreads, terror); tPrint("Performance: %.3f requests per second, msgSize:%d bytes", 1000.0*numOfReqs*appThreads/usedTime, msgSize); - taosCloseLogger(); + taosCloseLog(); return 0; } diff --git a/src/rpc/test/rserver.c b/src/rpc/test/rserver.c index 48ae02a1d5..e09eb7cd44 100644 --- a/src/rpc/test/rserver.c +++ b/src/rpc/test/rserver.c @@ -15,10 +15,10 @@ //#define _DEFAULT_SOURCE #include "os.h" -#include "tlog.h" +#include "tglobal.h" +#include "rpcLog.h" #include "trpc.h" #include "tqueue.h" -#include int msgSize = 128; int commit = 0; diff --git a/src/tsdb/inc/tsdbMain.h b/src/tsdb/inc/tsdbMain.h index bcf282ba51..312258a6d9 100644 --- a/src/tsdb/inc/tsdbMain.h +++ b/src/tsdb/inc/tsdbMain.h @@ -15,7 +15,7 @@ #ifndef _TD_TSDB_MAIN_H_ #define _TD_TSDB_MAIN_H_ -#include "tglobalcfg.h" +#include "tglobal.h" #include "tlist.h" #include "tsdb.h" #include "tskiplist.h" diff --git a/src/tsdb/src/tsdbMain.c b/src/tsdb/src/tsdbMain.c index a4241cdf7d..648188cdae 100644 --- a/src/tsdb/src/tsdbMain.c +++ b/src/tsdb/src/tsdbMain.c @@ -1,18 +1,5 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #include "os.h" +#include "tulog.h" #include "talgo.h" #include "tsdb.h" #include "tsdbMain.h" @@ -778,7 +765,7 @@ static int32_t tsdbInsertDataToTable(TsdbRepoT *repo, SSubmitBlk *pBlock) { STableId tableId = {.uid = pBlock->uid, .tid = pBlock->tid}; STable *pTable = tsdbIsValidTableToInsert(pRepo->tsdbMeta, tableId); if (pTable == NULL) { - dError("failed to get table for insert, uid:%" PRIu64 ", tid:%d", tableId.uid, tableId.tid); + uError("failed to get table for insert, uid:%" PRIu64 ", tid:%d", tableId.uid, tableId.tid); return TSDB_CODE_INVALID_TABLE_ID; } diff --git a/src/tsdb/src/tsdbRWHelper.c b/src/tsdb/src/tsdbRWHelper.c index 5aeed0c508..c0f509d1f2 100644 --- a/src/tsdb/src/tsdbRWHelper.c +++ b/src/tsdb/src/tsdbRWHelper.c @@ -12,6 +12,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ + +#include "os.h" #include "tsdbMain.h" #include "tchecksum.h" #include "tscompression.h" diff --git a/src/tsdb/src/tsdbRead.c b/src/tsdb/src/tsdbRead.c index 0458afa31f..43bb69e96a 100644 --- a/src/tsdb/src/tsdbRead.c +++ b/src/tsdb/src/tsdbRead.c @@ -14,9 +14,8 @@ */ #include "os.h" - +#include "tulog.h" #include "talgo.h" -#include "tlog.h" #include "tutil.h" #include "tcompare.h" @@ -173,7 +172,7 @@ TsdbQueryHandleT* tsdbQueryTables(TsdbRepoT* tsdb, STsdbQueryCond* pCond, STable } } - dTrace("%p total numOfTable:%d in query", pQueryHandle, taosArrayGetSize(pQueryHandle->pTableCheckInfo)); + uTrace("%p total numOfTable:%d in query", pQueryHandle, taosArrayGetSize(pQueryHandle->pTableCheckInfo)); /* * For ascending timestamp order query, query starts from data files. In contrast, buffer will be checked in the first place @@ -237,7 +236,7 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) { SDataRow row = SL_GET_NODE_DATA(node); pCheckInfo->lastKey = dataRowKey(row); // first timestamp in buffer - dTrace("%p uid:%" PRId64", tid:%d check data in buffer from skey:%" PRId64 ", order:%d", pHandle, + uTrace("%p uid:%" PRId64", tid:%d check data in buffer from skey:%" PRId64 ", order:%d", pHandle, pCheckInfo->tableId.uid, pCheckInfo->tableId.tid, pCheckInfo->lastKey, pHandle->order); // all data in mem are checked already. @@ -710,7 +709,7 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void* if (pLeftBlockInfoEx->pBlock.compBlock->offset == pRightBlockInfoEx->pBlock.compBlock->offset && pLeftBlockInfoEx->pBlock.compBlock->last == pRightBlockInfoEx->pBlock.compBlock->last) { // todo add more information - dError("error in header file, two block with same offset:%p", pLeftBlockInfoEx->pBlock.compBlock->offset); + uError("error in header file, two block with same offset:%p", pLeftBlockInfoEx->pBlock.compBlock->offset); } return pLeftBlockInfoEx->pBlock.compBlock->offset > pRightBlockInfoEx->pBlock.compBlock->offset ? 1 : -1; @@ -773,7 +772,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO numOfQualTables++; } - dTrace("%p create data blocks info struct completed, %d blocks in %d tables", pQueryHandle, cnt, numOfQualTables); + uTrace("%p create data blocks info struct completed, %d blocks in %d tables", pQueryHandle, cnt, numOfQualTables); assert(cnt <= numOfBlocks && numOfQualTables <= numOfTables); // the pMeterDataInfo[j]->numOfBlocks may be 0 sup.numOfTables = numOfQualTables; @@ -809,7 +808,7 @@ static int32_t createDataBlocksInfo(STsdbQueryHandle* pQueryHandle, int32_t numO * } */ - dTrace("%p %d data blocks sort completed", pQueryHandle, cnt); + uTrace("%p %d data blocks sort completed", pQueryHandle, cnt); cleanBlockOrderSupporter(&sup, numOfTables); free(pTree); @@ -831,7 +830,7 @@ static bool getDataBlocksInFilesImpl(STsdbQueryHandle* pQueryHandle) { } assert(numOfBlocks >= 0); - dTrace("%p %d blocks found in file for %d table(s), fid:%d", pQueryHandle, numOfBlocks, + uTrace("%p %d blocks found in file for %d table(s), fid:%d", pQueryHandle, numOfBlocks, numOfTables, pQueryHandle->pFileGroup->fileId); // todo return error code to query engine @@ -963,7 +962,7 @@ static int tsdbReadRowsFromCache(SSkipListIterator* pIter, TSKEY maxKey, int max if ((key > maxKey && ASCENDING_ORDER_TRAVERSE(pQueryHandle->order)) || (key < maxKey && !ASCENDING_ORDER_TRAVERSE(pQueryHandle->order))) { - dTrace("%p key:%"PRIu64" beyond qrange:%"PRId64" - %"PRId64", no more data in buffer", pQueryHandle, key, pQueryHandle->window.skey, + uTrace("%p key:%"PRIu64" beyond qrange:%"PRId64" - %"PRId64", no more data in buffer", pQueryHandle, key, pQueryHandle->window.skey, pQueryHandle->window.ekey); break; @@ -1328,7 +1327,7 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC size_t size = taosArrayGetSize(pTableList); if (size == 0) { - pTrace("no qualified tables"); + uTrace("no qualified tables"); return pTableGroup; } @@ -1344,7 +1343,7 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC } taosArrayPush(pTableGroup, &sa); - pTrace("all %d tables belong to one group", size); + uTrace("all %d tables belong to one group", size); #ifdef _DEBUG_VIEW tSidSetDisplay(pTableGroup); @@ -1444,7 +1443,7 @@ int32_t tsdbQueryTags(TsdbRepoT* tsdb, int64_t uid, const char* pTagCond, size_t STable* pSTable = tsdbGetTableByUid(tsdbGetMeta(tsdb), uid); if (pSTable == NULL) { - dError("failed to get stable, uid:%" PRIu64, uid); + uError("failed to get stable, uid:%" PRIu64, uid); return TSDB_CODE_INVALID_TABLE_ID; } @@ -1468,7 +1467,7 @@ int32_t tsdbQueryTags(TsdbRepoT* tsdb, int64_t uid, const char* pTagCond, size_t // failed to build expression, no result, return immediately if ((ret = exprTreeFromBinary(pTagCond, len, &pExprNode) != TSDB_CODE_SUCCESS) || (pExprNode == NULL)) { - dError("stable:%" PRIu64 ", failed to deserialize expression tree, error exists", uid); + uError("stable:%" PRIu64 ", failed to deserialize expression tree, error exists", uid); taosArrayDestroy(res); return ret; } diff --git a/src/tsdb/tests/tsdbTests.cpp b/src/tsdb/tests/tsdbTests.cpp index 58a7a0ae08..8c59d63cb2 100644 --- a/src/tsdb/tests/tsdbTests.cpp +++ b/src/tsdb/tests/tsdbTests.cpp @@ -2,7 +2,7 @@ #include #include -#include "dataformat.h" +#include "tdataformat.h" #include "tsdbMain.h" static double getCurTime() { diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index f875cfff94..a80e81f09f 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -4,6 +4,7 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) diff --git a/src/util/inc/tconfig.h b/src/util/inc/tconfig.h new file mode 100644 index 0000000000..79b19ff79d --- /dev/null +++ b/src/util/inc/tconfig.h @@ -0,0 +1,89 @@ +/* + * 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_CFG_H +#define TDENGINE_CFG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define TSDB_CFG_MAX_NUM 110 +#define TSDB_CFG_PRINT_LEN 23 +#define TSDB_CFG_OPTION_LEN 24 +#define TSDB_CFG_VALUE_LEN 41 + +#define TSDB_CFG_CTYPE_B_CONFIG 1U // can be configured from file +#define TSDB_CFG_CTYPE_B_SHOW 2U // can displayed by "show configs" commands +#define TSDB_CFG_CTYPE_B_LOG 4U // is a log type configuration +#define TSDB_CFG_CTYPE_B_CLIENT 8U // can be displayed in the client log +#define TSDB_CFG_CTYPE_B_OPTION 16U // can be configured by taos_options function +#define TSDB_CFG_CTYPE_B_NOT_PRINT 32U // such as password + +enum { + TAOS_CFG_CSTATUS_NONE, // not configured + TAOS_CFG_CSTATUS_DEFAULT, // use system default value + TAOS_CFG_CSTATUS_FILE, // configured from file + TAOS_CFG_CSTATUS_OPTION, // configured by taos_options function + TAOS_CFG_CSTATUS_ARG, // configured by program argument +}; + +enum { + TAOS_CFG_VTYPE_INT16, + TAOS_CFG_VTYPE_INT32, + TAOS_CFG_VTYPE_FLOAT, + TAOS_CFG_VTYPE_STRING, + TAOS_CFG_VTYPE_IPSTR, + TAOS_CFG_VTYPE_DIRECTORY, +}; + +enum { + TAOS_CFG_UTYPE_NONE, + TAOS_CFG_UTYPE_PERCENT, + TAOS_CFG_UTYPE_GB, + TAOS_CFG_UTYPE_Mb, + TAOS_CFG_UTYPE_BYTE, + TAOS_CFG_UTYPE_SECOND, + TAOS_CFG_UTYPE_MS +}; + +typedef struct { + char * option; + void * ptr; + float minValue; + float maxValue; + int8_t cfgType; + int8_t cfgStatus; + int8_t unitType; + int8_t valType; + uint32_t ptrLength; +} SGlobalCfg; + +extern SGlobalCfg tsGlobalConfig[]; +extern int32_t tsGlobalConfigNum; +extern char * tsCfgStatusStr[]; + +void taosReadGlobalLogCfg(); +bool taosReadGlobalCfg(); +void taosPrintGlobalCfg(); + +void taosInitConfigOption(SGlobalCfg cfg); +SGlobalCfg * taosGetConfigOption(const char *option); + +#ifdef __cplusplus +} +#endif + +#endif // TDENGINE_TGLOBALCFG_H diff --git a/src/util/inc/tkey.h b/src/util/inc/tkey.h index c8b3c87f5e..28a0d3a84e 100644 --- a/src/util/inc/tkey.h +++ b/src/util/inc/tkey.h @@ -21,7 +21,6 @@ extern "C" { #include #include -#include "tlog.h" #include "tmd5.h" #include "tutil.h" diff --git a/src/util/inc/tlog.h b/src/util/inc/tlog.h index 485f8644d3..284ea924b0 100644 --- a/src/util/inc/tlog.h +++ b/src/util/inc/tlog.h @@ -20,11 +20,6 @@ extern "C" { #endif -#include -#include -#include -#include "tglobalcfg.h" - #define DEBUG_ERROR 1U #define DEBUG_WARN 2U #define DEBUG_TRACE 4U @@ -33,149 +28,13 @@ extern "C" { #define DEBUG_FILE 0x80 #define DEBUG_SCREEN 0x40 -extern void (*taosLogFp)(int level, const char *const format, ...); +int32_t taosInitLog(char *logName, int32_t numOfLogLines, int32_t maxFiles); +void taosCloseLog(); +void taosResetLog(); -extern void (*taosLogSqlFp)(char *sql); - -extern void (*taosLogAcctFp)(char *acctId, int64_t currentPointsPerSecond, int64_t maxPointsPerSecond, - int64_t totalTimeSeries, int64_t maxTimeSeries, int64_t totalStorage, int64_t maxStorage, - int64_t totalQueryTime, int64_t maxQueryTime, int64_t totalInbound, int64_t maxInbound, - int64_t totalOutbound, int64_t maxOutbound, int64_t totalDbs, int64_t maxDbs, - int64_t totalUsers, int64_t maxUsers, int64_t totalStreams, int64_t maxStreams, - int64_t totalConns, int64_t maxConns, int8_t accessState); - -int taosInitLog(char *logName, int numOfLogLines, int maxFiles); - -void taosCloseLogger(); - -void taosDumpData(unsigned char *msg, int len); - -int taosOpenLogFile(char *fn); - -void tprintf(const char *const flags, int dflag, const char *const format, ...); - -void taosPrintLongString(const char *const flags, int dflag, const char *const format, ...); - -int taosOpenLogFileWithMaxLines(char *fn, int maxLines, int maxFileNum); - -void taosCloseLog(); - -void taosResetLogFile(); - -#define taosLogError(...) \ - if (taosLogFp) { \ - (*taosLogFp)(2, __VA_ARGS__); \ - } -#define taosLogWarn(...) \ - if (taosLogFp) { \ - (*taosLogFp)(1, __VA_ARGS__); \ - } -#define taosLogPrint(...) \ - if (taosLogFp) { \ - (*taosLogFp)(0, __VA_ARGS__); \ - } - -// utility log function -#define pError(...) \ - if (uDebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR UTL ", uDebugFlag, __VA_ARGS__); \ - } -#define pWarn(...) \ - if (uDebugFlag & DEBUG_WARN) { \ - tprintf("WARN UTL ", uDebugFlag, __VA_ARGS__); \ - } -#define pTrace(...) \ - if (uDebugFlag & DEBUG_TRACE) { \ - tprintf("UTL ", uDebugFlag, __VA_ARGS__); \ - } -#define pDump(x, y) \ - if (uDebugFlag & DEBUG_DUMP) { \ - taosDumpData(x, y); \ - } - -#define pPrint(...) \ - { tprintf("UTL ", tscEmbedded ? 255 : uDebugFlag, __VA_ARGS__); } - -// client log function -extern uint32_t cdebugFlag; - -#define tscError(...) \ - if (cdebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR TSC ", 255, __VA_ARGS__); \ - } -#define tscWarn(...) \ - if (cdebugFlag & DEBUG_WARN) { \ - tprintf("WARN TSC ", cdebugFlag, __VA_ARGS__); \ - } -#define tscTrace(...) \ - if (cdebugFlag & DEBUG_TRACE) { \ - tprintf("TSC ", cdebugFlag, __VA_ARGS__); \ - } -#define tscPrint(...) \ - { tprintf("TSC ", 255, __VA_ARGS__); } -#define tscDump(...) \ - if (cdebugFlag & DEBUG_TRACE) { \ - taosPrintLongString("TSC ", cdebugFlag, __VA_ARGS__); \ - } -#define jniError(...) \ - if (jnidebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR JNI ", jnidebugFlag, __VA_ARGS__); \ - } -#define jniWarn(...) \ - if (jnidebugFlag & DEBUG_WARN) { \ - tprintf("WARN JNI ", jnidebugFlag, __VA_ARGS__); \ - } -#define jniTrace(...) \ - if (jnidebugFlag & DEBUG_TRACE) { \ - tprintf("JNI ", jnidebugFlag, __VA_ARGS__); \ - } -#define jniPrint(...) \ - { tprintf("JNI ", 255, __VA_ARGS__); } - -// rpc log function -#define tError(...) \ - if (rpcDebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR RPC ", rpcDebugFlag, __VA_ARGS__); \ - } -#define tWarn(...) \ - if (rpcDebugFlag & DEBUG_WARN) { \ - tprintf("WARN RPC ", rpcDebugFlag, __VA_ARGS__); \ - } -#define tTrace(...) \ - if (rpcDebugFlag & DEBUG_TRACE) { \ - tprintf("RPC ", rpcDebugFlag, __VA_ARGS__); \ - } -#define tPrint(...) \ - { tprintf("RPC ", 255, __VA_ARGS__); } -#define tDump(x, y) \ - if (rpcDebugFlag & DEBUG_DUMP) { \ - taosDumpData((unsigned char *)x, y); \ - } - -// dnode log function -#define dError(...) \ - if (ddebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR DND ", 255, __VA_ARGS__); \ - } -#define dWarn(...) \ - if (ddebugFlag & DEBUG_WARN) { \ - tprintf("WARN DND ", ddebugFlag, __VA_ARGS__); \ - } -#define dTrace(...) \ - if (ddebugFlag & DEBUG_TRACE) { \ - tprintf("DND ", ddebugFlag, __VA_ARGS__); \ - } -#define dPrint(...) \ - { tprintf("DND ", 255, __VA_ARGS__); } - -#define dLError(...) taosLogError(__VA_ARGS__) dError(__VA_ARGS__) -#define dLWarn(...) taosLogWarn(__VA_ARGS__) dWarn(__VA_ARGS__) -#define dLPrint(...) taosLogPrint(__VA_ARGS__) dPrint(__VA_ARGS__) - -#define qTrace(...) \ - if (qdebugFlag & DEBUG_TRACE) { \ - tprintf("DND QRY ", qdebugFlag, __VA_ARGS__); \ - } +void taosPrintLog(const char *const flags, int32_t dflag, const char *const format, ...); +void taosPrintLongString(const char *const flags, int32_t dflag, const char *const format, ...); +void taosDumpData(unsigned char *msg, int32_t len); #ifdef __cplusplus } diff --git a/src/util/inc/tnote.h b/src/util/inc/tnote.h index 4f86736be4..552224abf0 100644 --- a/src/util/inc/tnote.h +++ b/src/util/inc/tnote.h @@ -22,7 +22,7 @@ extern "C" { #include "os.h" #include "tutil.h" -#include "tglobalcfg.h" +#include "tglobal.h" #define MAX_NOTE_LINE_SIZE 66000 #define NOTE_FILE_NAME_LEN 300 diff --git a/src/util/inc/ttimer.h b/src/util/inc/ttimer.h index b9bbbb04dd..9422312856 100644 --- a/src/util/inc/ttimer.h +++ b/src/util/inc/ttimer.h @@ -23,25 +23,9 @@ extern "C" { typedef void *tmr_h; typedef void (*TAOS_TMR_CALLBACK)(void *, void *); -extern uint32_t tmrDebugFlag; extern int taosTmrThreads; extern uint32_t taosMaxTmrCtrl; -#define tmrError(...) \ - do { if (tmrDebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR TMR ", tmrDebugFlag, __VA_ARGS__); \ - } } while(0) - -#define tmrWarn(...) \ - do { if (tmrDebugFlag & DEBUG_WARN) { \ - tprintf("WARN TMR ", tmrDebugFlag, __VA_ARGS__); \ - } } while(0) - -#define tmrTrace(...) \ - do { if (tmrDebugFlag & DEBUG_TRACE) { \ - tprintf("TMR ", tmrDebugFlag, __VA_ARGS__); \ - } } while(0) - #define MSECONDS_PER_TICK 5 void *taosTmrInit(int maxTmr, int resoultion, int longest, const char *label); diff --git a/src/util/src/hash.c b/src/util/src/hash.c index 6beb195d36..e0e13c1b22 100644 --- a/src/util/src/hash.c +++ b/src/util/src/hash.c @@ -16,7 +16,7 @@ #include "os.h" #include "hash.h" -#include "tlog.h" +#include "tulog.h" #include "ttime.h" #include "tutil.h" @@ -153,7 +153,7 @@ static void taosHashTableResize(SHashObj *pHashObj) { int32_t newSize = pHashObj->capacity << 1u; if (newSize > HASH_MAX_CAPACITY) { -// pTrace("current capacity:%d, maximum capacity:%d, no resize applied due to limitation is reached", +// uTrace("current capacity:%d, maximum capacity:%d, no resize applied due to limitation is reached", // pHashObj->capacity, HASH_MAX_CAPACITY); return; } @@ -162,7 +162,7 @@ static void taosHashTableResize(SHashObj *pHashObj) { SHashEntry **pNewEntry = realloc(pHashObj->hashList, sizeof(SHashEntry *) * newSize); if (pNewEntry == NULL) { -// pTrace("cache resize failed due to out of memory, capacity remain:%d", pHashObj->capacity); +// uTrace("cache resize failed due to out of memory, capacity remain:%d", pHashObj->capacity); return; } @@ -229,7 +229,7 @@ static void taosHashTableResize(SHashObj *pHashObj) { } // int64_t et = taosGetTimestampUs(); -// pTrace("hash table resize completed, new capacity:%d, load factor:%f, elapsed time:%fms", pHashObj->capacity, +// uTrace("hash table resize completed, new capacity:%d, load factor:%f, elapsed time:%fms", pHashObj->capacity, // ((double)pHashObj->size) / pHashObj->capacity, (et - st) / 1000.0); } @@ -245,7 +245,7 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool threadsafe) { SHashObj *pHashObj = (SHashObj *)calloc(1, sizeof(SHashObj)); if (pHashObj == NULL) { - pError("failed to allocate memory, reason:%s", strerror(errno)); + uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; } @@ -258,7 +258,7 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool threadsafe) { pHashObj->hashList = (SHashEntry **)calloc(pHashObj->capacity, sizeof(SHashEntry *)); if (pHashObj->hashList == NULL) { free(pHashObj); - pError("failed to allocate memory, reason:%s", strerror(errno)); + uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; } @@ -278,7 +278,7 @@ SHashObj *taosHashInit(size_t capacity, _hash_fn_t fn, bool threadsafe) { free(pHashObj->hashList); free(pHashObj); - pError("failed to init lock, reason:%s", strerror(errno)); + uError("failed to init lock, reason:%s", strerror(errno)); return NULL; } @@ -299,7 +299,7 @@ static SHashNode *doCreateHashNode(const char *key, size_t keyLen, const char *p SHashNode *pNewNode = calloc(1, totalSize); if (pNewNode == NULL) { - pError("failed to allocate memory, reason:%s", strerror(errno)); + uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; } diff --git a/src/util/src/shash.c b/src/util/src/shash.c index da97af84bb..807ba58951 100644 --- a/src/util/src/shash.c +++ b/src/util/src/shash.c @@ -13,14 +13,10 @@ * along with this program. If not, see . */ -#include -#include -#include -#include -#include - +#define _DEFAULT_SOURCE +#include "os.h" #include "shash.h" -#include "tlog.h" +#include "tulog.h" typedef struct _str_node_t { char * string; @@ -96,7 +92,7 @@ void *taosAddStrHashWithSize(void *handle, char *string, char *pData, int dataSi pthread_mutex_unlock(&pObj->mutex); - pTrace("hash:%d:%s is added", hash, string); + uTrace("hash:%d:%s is added", hash, string); return pNode->data; } @@ -145,7 +141,7 @@ void taosDeleteStrHashNode(void *handle, char *string, void *pDeleteNode) { pNode->next->prev = pNode->prev; } - pTrace("hash:%d:%s:%p is removed", hash, string, pNode); + uTrace("hash:%d:%s:%p is removed", hash, string, pNode); free(pNode); } @@ -184,7 +180,7 @@ void taosDeleteStrHash(void *handle, char *string) { pNode->next->prev = pNode->prev; } - pTrace("hash:%d:%s:%p is removed", hash, string, pNode); + uTrace("hash:%d:%s:%p is removed", hash, string, pNode); free(pNode); } @@ -209,7 +205,7 @@ void *taosGetStrHashData(void *handle, char *string) { while (pNode) { if (strcmp(pNode->string, string) == 0) { - pTrace("hash:%d:%s is retrieved", hash, string); + uTrace("hash:%d:%s is retrieved", hash, string); break; } diff --git a/src/util/src/tcache.c b/src/util/src/tcache.c index 47b358c052..e1e76173e6 100644 --- a/src/util/src/tcache.c +++ b/src/util/src/tcache.c @@ -13,14 +13,15 @@ * along with this program. If not, see . */ -#include "tcache.h" -#include "hash.h" -#include "hashfunc.h" - -#include "tlog.h" +#define _DEFAULT_SOURCE +#include "os.h" +#include "tulog.h" #include "ttime.h" #include "ttimer.h" #include "tutil.h" +#include "tcache.h" +#include "hash.h" +#include "hashfunc.h" static FORCE_INLINE void __cache_wr_lock(SCacheObj *pCacheObj) { #if defined(LINUX) @@ -82,7 +83,7 @@ static SCacheDataNode *taosCreateHashNode(const char *key, size_t keyLen, const SCacheDataNode *pNewNode = calloc(1, totalSize); if (pNewNode == NULL) { - pError("failed to allocate memory, reason:%s", strerror(errno)); + uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; } @@ -127,12 +128,12 @@ static void taosAddToTrash(SCacheObj *pCacheObj, SCacheDataNode *pNode) { pNode->inTrash = true; pCacheObj->numOfElemsInTrash++; - pTrace("key:%s %p move to trash, numOfElem in trash:%d", pNode->key, pNode, pCacheObj->numOfElemsInTrash); + uTrace("key:%s %p move to trash, numOfElem in trash:%d", pNode->key, pNode, pCacheObj->numOfElemsInTrash); } static void taosRemoveFromTrash(SCacheObj *pCacheObj, STrashElem *pElem) { if (pElem->pData->signature != (uint64_t)pElem->pData) { - pError("key:sig:%d %p data has been released, ignore", pElem->pData->signature, pElem->pData); + uError("key:sig:%d %p data has been released, ignore", pElem->pData->signature, pElem->pData); return; } @@ -163,7 +164,7 @@ static void taosTrashEmpty(SCacheObj *pCacheObj, bool force) { if (pCacheObj->numOfElemsInTrash == 0) { if (pCacheObj->pTrash != NULL) { - pError("key:inconsistency data in cache, numOfElem in trash:%d", pCacheObj->numOfElemsInTrash); + uError("key:inconsistency data in cache, numOfElem in trash:%d", pCacheObj->numOfElemsInTrash); } pCacheObj->pTrash = NULL; @@ -180,7 +181,7 @@ static void taosTrashEmpty(SCacheObj *pCacheObj, bool force) { } if (force || (T_REF_VAL_GET(pElem->pData) == 0)) { - pTrace("key:%s %p removed from trash. numOfElem in trash:%d", pElem->pData->key, pElem->pData, + uTrace("key:%s %p removed from trash. numOfElem in trash:%d", pElem->pData->key, pElem->pData, pCacheObj->numOfElemsInTrash - 1); STrashElem *p = pElem; @@ -202,14 +203,14 @@ static void taosTrashEmpty(SCacheObj *pCacheObj, bool force) { */ static FORCE_INLINE void taosCacheReleaseNode(SCacheObj *pCacheObj, SCacheDataNode *pNode) { if (pNode->signature != (uint64_t)pNode) { - pError("key:%s, %p data is invalid, or has been released", pNode->key, pNode); + uError("key:%s, %p data is invalid, or has been released", pNode->key, pNode); return; } int32_t size = pNode->size; taosHashRemove(pCacheObj->pHashTable, pNode->key, pNode->keySize); - pTrace("key:%s is removed from cache,total:%d,size:%ldbytes", pNode->key, pCacheObj->totalSize, size); + uTrace("key:%s is removed from cache,total:%d,size:%ldbytes", pNode->key, pCacheObj->totalSize, size); free(pNode); } @@ -324,7 +325,7 @@ static void taosCacheRefresh(void *handle, void *tmrId) { SCacheObj *pCacheObj = (SCacheObj *)handle; if (pCacheObj == NULL || taosHashGetSize(pCacheObj->pHashTable) == 0) { - pTrace("object is destroyed. no refresh retry"); + uTrace("object is destroyed. no refresh retry"); return; } @@ -370,14 +371,14 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) { SCacheObj *pCacheObj = (SCacheObj *)calloc(1, sizeof(SCacheObj)); if (pCacheObj == NULL) { - pError("failed to allocate memory, reason:%s", strerror(errno)); + uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; } pCacheObj->pHashTable = taosHashInit(1024, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false); if (pCacheObj->pHashTable == NULL) { free(pCacheObj); - pError("failed to allocate memory, reason:%s", strerror(errno)); + uError("failed to allocate memory, reason:%s", strerror(errno)); return NULL; } @@ -394,7 +395,7 @@ SCacheObj *taosCacheInit(void *tmrCtrl, int64_t refreshTime) { taosHashCleanup(pCacheObj->pHashTable); free(pCacheObj); - pError("failed to init lock, reason:%s", strerror(errno)); + uError("failed to init lock, reason:%s", strerror(errno)); return NULL; } @@ -419,12 +420,12 @@ void *taosCachePut(SCacheObj *pCacheObj, const char *key, const void *pData, siz if (NULL != pNode) { pCacheObj->totalSize += pNode->size; - pTrace("key:%s %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", total:%d, size:%" PRId64 " bytes", + uTrace("key:%s %p added into cache, added:%" PRIu64 ", expire:%" PRIu64 ", total:%d, size:%" PRId64 " bytes", key, pNode, pNode->addedTime, pNode->expiredTime, pCacheObj->totalSize, dataSize); } } else { // old data exists, update the node pNode = taosUpdateCacheImpl(pCacheObj, pOld, key, keyLen, pData, dataSize, duration * 1000L); - pTrace("key:%s %p exist in cache, updated", key, pNode); + uTrace("key:%s %p exist in cache, updated", key, pNode); } __cache_unlock(pCacheObj); @@ -450,10 +451,10 @@ void *taosCacheAcquireByName(SCacheObj *pCacheObj, const char *key) { if (ptNode != NULL) { atomic_add_fetch_32(&pCacheObj->statistics.hitCount, 1); - pTrace("key:%s is retrieved from cache, %p refcnt:%d", key, (*ptNode), T_REF_VAL_GET(*ptNode)); + uTrace("key:%s is retrieved from cache, %p refcnt:%d", key, (*ptNode), T_REF_VAL_GET(*ptNode)); } else { atomic_add_fetch_32(&pCacheObj->statistics.missCount, 1); - pTrace("key:%s not in cache, retrieved failed", key); + uTrace("key:%s not in cache, retrieved failed", key); } atomic_add_fetch_32(&pCacheObj->statistics.totalAccess, 1); @@ -467,12 +468,12 @@ void *taosCacheAcquireByData(SCacheObj *pCacheObj, void *data) { SCacheDataNode *ptNode = (SCacheDataNode *)((char *)data - offset); if (ptNode->signature != (uint64_t)ptNode) { - pError("key: %p the data from cache is invalid", ptNode); + uError("key: %p the data from cache is invalid", ptNode); return NULL; } int32_t ref = T_REF_INC(ptNode); - pTrace("%p acquired by data in cache, refcnt:%d", ptNode, ref) + uTrace("%p acquired by data in cache, refcnt:%d", ptNode, ref) // the data if referenced by at least one object, so the reference count must be greater than the value of 2. assert(ref >= 2); @@ -486,7 +487,7 @@ void *taosCacheTransfer(SCacheObj *pCacheObj, void **data) { SCacheDataNode *ptNode = (SCacheDataNode *)((char *)(*data) - offset); if (ptNode->signature != (uint64_t)ptNode) { - pError("key: %p the data from cache is invalid", ptNode); + uError("key: %p the data from cache is invalid", ptNode); return NULL; } @@ -510,13 +511,13 @@ void taosCacheRelease(SCacheObj *pCacheObj, void **data, bool _remove) { SCacheDataNode *pNode = (SCacheDataNode *)((char *)(*data) - offset); if (pNode->signature != (uint64_t)pNode) { - pError("key: %p release invalid cache data", pNode); + uError("key: %p release invalid cache data", pNode); return; } *data = NULL; int16_t ref = T_REF_DEC(pNode); - pTrace("%p data released, refcnt:%d", pNode, ref); + uTrace("%p data released, refcnt:%d", pNode, ref); if (_remove) { __cache_wr_lock(pCacheObj); diff --git a/src/util/src/tconfig.c b/src/util/src/tconfig.c new file mode 100644 index 0000000000..602fcb752b --- /dev/null +++ b/src/util/src/tconfig.c @@ -0,0 +1,369 @@ +/* + * 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" +#include "taosdef.h" +#include "taoserror.h" +#include "tconfig.h" +#include "tglobal.h" +#include "tkey.h" +#include "tulog.h" +#include "tsocket.h" +#include "tsystem.h" +#include "tutil.h" + +SGlobalCfg tsGlobalConfig[TSDB_CFG_MAX_NUM] = {0}; +int32_t tsGlobalConfigNum = 0; + +static char *tsGlobalUnit[] = { + " ", + "(%)", + "(GB)", + "(Mb)", + "(byte)", + "(s)", + "(ms)" +}; + +char *tsCfgStatusStr[] = { + "none", + "system default", + "config file", + "taos_options", + "program argument list" +}; + +static void taosReadFloatConfig(SGlobalCfg *cfg, char *input_value) { + float value = (float)atof(input_value); + float *option = (float *)cfg->ptr; + if (value < cfg->minValue || value > cfg->maxValue) { + uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f", + cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); + } else { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { + *option = value; + cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE; + } else { + uWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value, + tsCfgStatusStr[cfg->cfgStatus], *option); + } + } +} + +static void taosReadInt32Config(SGlobalCfg *cfg, char *input_value) { + int32_t value = atoi(input_value); + int32_t *option = (int32_t *)cfg->ptr; + if (value < cfg->minValue || value > cfg->maxValue) { + uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", + cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); + } else { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { + *option = value; + cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE; + } else { + uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, + tsCfgStatusStr[cfg->cfgStatus], *option); + } + } +} + +static void taosReadInt16Config(SGlobalCfg *cfg, char *input_value) { + int32_t value = atoi(input_value); + int16_t *option = (int16_t *)cfg->ptr; + if (value < cfg->minValue || value > cfg->maxValue) { + uError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", + cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); + } else { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { + *option = (int16_t)value; + cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE; + } else { + uWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, + tsCfgStatusStr[cfg->cfgStatus], *option); + } + } +} + +static void taosReadDirectoryConfig(SGlobalCfg *cfg, char *input_value) { + int length = strlen(input_value); + char *option = (char *)cfg->ptr; + if (length <= 0 || length > cfg->ptrLength) { + uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", + cfg->option, input_value, cfg->ptrLength, option); + } else { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { + wordexp_t full_path; + wordexp(input_value, &full_path, 0); + if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { + strcpy(option, full_path.we_wordv[0]); + } + wordfree(&full_path); + + struct stat dirstat; + if (stat(option, &dirstat) < 0) { + int code = mkdir(option, 0755); + uPrint("config option:%s, input value:%s, directory not exist, create with return code:%d", + cfg->option, input_value, code); + } + cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE; + } else { + uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, + tsCfgStatusStr[cfg->cfgStatus], option); + } + } +} + +static void taosReadIpStrConfig(SGlobalCfg *cfg, char *input_value) { + uint32_t value = inet_addr(input_value); + char * option = (char *)cfg->ptr; + if (value == INADDR_NONE) { + uError("config option:%s, input value:%s, is not a valid ip address, use default value:%s", + cfg->option, input_value, option); + } else { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { + strncpy(option, input_value, cfg->ptrLength); + cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE; + } else { + uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, + tsCfgStatusStr[cfg->cfgStatus], option); + } + } +} + +static void taosReadStringConfig(SGlobalCfg *cfg, char *input_value) { + int length = strlen(input_value); + char *option = (char *)cfg->ptr; + if (length <= 0 || length > cfg->ptrLength) { + uError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", + cfg->option, input_value, cfg->ptrLength, option); + } else { + if (cfg->cfgStatus <= TAOS_CFG_CSTATUS_FILE) { + strncpy(option, input_value, cfg->ptrLength); + cfg->cfgStatus = TAOS_CFG_CSTATUS_FILE; + } else { + uWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, + tsCfgStatusStr[cfg->cfgStatus], option); + } + } +} + +static void taosReadLogOption(char *option, char *value) { + for (int i = 0; i < tsGlobalConfigNum; ++i) { + SGlobalCfg *cfg = tsGlobalConfig + i; + if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG) || !(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue; + if (strcasecmp(cfg->option, option) != 0) continue; + + switch (cfg->valType) { + case TAOS_CFG_VTYPE_INT32: + taosReadInt32Config(cfg, value); + if (strcasecmp(cfg->option, "debugFlag") == 0) { + taosSetAllDebugFlag(); + } + break; + case TAOS_CFG_VTYPE_DIRECTORY: + taosReadDirectoryConfig(cfg, value); + break; + default: + break; + } + break; + } +} + +SGlobalCfg *taosGetConfigOption(const char *option) { + for (int i = 0; i < tsGlobalConfigNum; ++i) { + SGlobalCfg *cfg = tsGlobalConfig + i; + if (strcasecmp(cfg->option, option) != 0) continue; + return cfg; + } + return NULL; +} + +static void taosReadConfigOption(const char *option, char *value) { + for (int i = 0; i < tsGlobalConfigNum; ++i) { + SGlobalCfg *cfg = tsGlobalConfig + i; + if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue; + if (strcasecmp(cfg->option, option) != 0) continue; + + switch (cfg->valType) { + case TAOS_CFG_VTYPE_INT16: + taosReadInt16Config(cfg, value); + break; + case TAOS_CFG_VTYPE_INT32: + taosReadInt32Config(cfg, value); + break; + case TAOS_CFG_VTYPE_FLOAT: + taosReadFloatConfig(cfg, value); + break; + case TAOS_CFG_VTYPE_STRING: + taosReadStringConfig(cfg, value); + break; + case TAOS_CFG_VTYPE_IPSTR: + taosReadIpStrConfig(cfg, value); + break; + case TAOS_CFG_VTYPE_DIRECTORY: + taosReadDirectoryConfig(cfg, value); + break; + default: + uError("config option:%s, input value:%s, can't be recognized", option, value); + break; + } + break; + } +} + +void taosInitConfigOption(SGlobalCfg cfg) { + tsGlobalConfig[tsGlobalConfigNum++] = cfg; +} + +void taosReadGlobalLogCfg() { + FILE * fp; + char * line, *option, *value; + int olen, vlen; + char fileName[PATH_MAX] = {0}; + + mdebugFlag = 135; + sdbDebugFlag = 135; + + wordexp_t full_path; + wordexp(configDir, &full_path, 0); + if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { + strcpy(configDir, full_path.we_wordv[0]); + } else { + printf("configDir:%s not there, use default value: /etc/taos", configDir); + strcpy(configDir, "/etc/taos"); + } + wordfree(&full_path); + + taosReadLogOption("logDir", logDir); + + sprintf(fileName, "%s/taos.cfg", configDir); + fp = fopen(fileName, "r"); + if (fp == NULL) { + printf("\nconfig file:%s not found, all variables are set to default\n", fileName); + return; + } + + size_t len = 1024; + line = calloc(1, len); + + while (!feof(fp)) { + memset(line, 0, len); + + option = value = NULL; + olen = vlen = 0; + + getline(&line, &len, fp); + line[len - 1] = 0; + + paGetToken(line, &option, &olen); + if (olen == 0) continue; + option[olen] = 0; + + paGetToken(option + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + taosReadLogOption(option, value); + } + + tfree(line); + fclose(fp); +} + +bool taosReadGlobalCfg() { + char * line, *option, *value, *value1; + int olen, vlen, vlen1; + char fileName[PATH_MAX] = {0}; + + sprintf(fileName, "%s/taos.cfg", configDir); + FILE* fp = fopen(fileName, "r"); + + size_t len = 1024; + line = calloc(1, len); + + if (fp != NULL) { + while (!feof(fp)) { + memset(line, 0, len); + + option = value = NULL; + olen = vlen = 0; + + getline(&line, &len, fp); + line[len - 1] = 0; + + paGetToken(line, &option, &olen); + if (olen == 0) continue; + option[olen] = 0; + + paGetToken(option + olen + 1, &value, &vlen); + if (vlen == 0) continue; + value[vlen] = 0; + + // For dataDir, the format is: + // dataDir /mnt/disk1 0 + paGetToken(value + vlen + 1, &value1, &vlen1); + + taosReadConfigOption(option, value); + } + + fclose(fp); + } + + tfree(line); + + return true; +} + +void taosPrintGlobalCfg() { + uPrint(" taos config & system info:"); + uPrint("=================================="); + + for (int i = 0; i < tsGlobalConfigNum; ++i) { + SGlobalCfg *cfg = tsGlobalConfig + i; + if (tscEmbedded == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue; + if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue; + + int optionLen = (int)strlen(cfg->option); + int blankLen = TSDB_CFG_PRINT_LEN - optionLen; + blankLen = blankLen < 0 ? 0 : blankLen; + + char blank[TSDB_CFG_PRINT_LEN]; + memset(blank, ' ', TSDB_CFG_PRINT_LEN); + blank[blankLen] = 0; + + switch (cfg->valType) { + case TAOS_CFG_VTYPE_INT16: + uPrint(" %s:%s%d%s", cfg->option, blank, *((int16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); + break; + case TAOS_CFG_VTYPE_INT32: + uPrint(" %s:%s%d%s", cfg->option, blank, *((int32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); + break; + case TAOS_CFG_VTYPE_FLOAT: + uPrint(" %s:%s%f%s", cfg->option, blank, *((float *)cfg->ptr), tsGlobalUnit[cfg->unitType]); + break; + case TAOS_CFG_VTYPE_STRING: + case TAOS_CFG_VTYPE_IPSTR: + case TAOS_CFG_VTYPE_DIRECTORY: + uPrint(" %s:%s%s%s", cfg->option, blank, (char *)cfg->ptr, tsGlobalUnit[cfg->unitType]); + break; + default: + break; + } + } + + taosPrintOsInfo(); +} diff --git a/src/util/src/tglobalcfg.c b/src/util/src/tglobalcfg.c deleted file mode 100644 index d912301641..0000000000 --- a/src/util/src/tglobalcfg.c +++ /dev/null @@ -1,1207 +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 . - */ - -#include "os.h" - -#include "taosdef.h" -#include "taoserror.h" -#include "tglobalcfg.h" -#include "tkey.h" -#include "tlog.h" -#include "tsocket.h" -#include "tsystem.h" -#include "tutil.h" - -void (*tsReadStorageConfig)() = NULL; -void (*tsPrintStorageConfig)() = NULL; - -// monitor module api -int (*startMonitor)() = NULL; -void (*stopMonitor)() = NULL; - -// system info, not configurable -int64_t tsPageSize; -int64_t tsOpenMax; -int64_t tsStreamMax; -int32_t tsNumOfCores = 1; -int32_t tsAlternativeRole = 0; -float tsTotalLogDirGB = 0; -float tsTotalTmpDirGB = 0; -float tsTotalDataDirGB = 0; -float tsAvailLogDirGB = 0; -float tsAvailTmpDirGB = 0; -float tsAvailDataDirGB = 0; -float tsMinimalLogDirGB = 0.1; -float tsMinimalTmpDirGB = 0.1; -float tsMinimalDataDirGB = 0.5; -int32_t tsTotalMemoryMB = 0; -int32_t tsVersion = 0; - -// global, not configurable -int tscEmbedded = 0; - -/* - * minmum scale for whole system, millisecond by default - * for TSDB_TIME_PRECISION_MILLI: 86400000L - * TSDB_TIME_PRECISION_MICRO: 86400000000L - */ -int64_t tsMsPerDay[] = {86400000L, 86400000000L}; - -char tsMasterIp[TSDB_IPv4ADDR_LEN] = {0}; -char tsSecondIp[TSDB_IPv4ADDR_LEN] = {0}; -uint16_t tsMnodeShellPort = 6030; // udp[6030-6034] tcp[6030] -uint16_t tsDnodeShellPort = 6035; // udp[6035-6039] tcp[6035] -uint16_t tsMnodeDnodePort = 6040; // udp/tcp -uint16_t tsDnodeMnodePort = 6041; // udp/tcp -uint16_t tsVnodeVnodePort = 6045; // tcp[6045] -uint16_t tsMgmtMgmtPort = 6050; // udp, numOfVnodes fixed to 1, range udp[6050] -uint16_t tsMgmtSyncPort = 6050; // tcp, range tcp[6050] - -int tsStatusInterval = 1; // second -int tsShellActivityTimer = 3; // second -int tsVnodePeerHBTimer = 1; // second -int tsMgmtPeerHBTimer = 1; // second -int tsMeterMetaKeepTimer = 7200; // second -int tsMetricMetaKeepTimer = 600; // second - -float tsNumOfThreadsPerCore = 1.0; -float tsRatioOfQueryThreads = 0.5; -char tsPublicIp[TSDB_IPv4ADDR_LEN] = {0}; -char tsPrivateIp[TSDB_IPv4ADDR_LEN] = {0}; -short tsNumOfVnodesPerCore = 8; -short tsNumOfTotalVnodes = TSDB_INVALID_VNODE_NUM; -short tsCheckHeaderFile = 0; - -#ifdef _TD_ARM_32_ -int tsSessionsPerVnode = 100; -#else -int tsSessionsPerVnode = 1000; -#endif - -int tsCacheBlockSize = 16384; // 256 columns -int tsAverageCacheBlocks = TSDB_DEFAULT_AVG_BLOCKS; -/** - * Change the meaning of affected rows: - * 0: affected rows not include those duplicate records - * 1: affected rows include those duplicate records - */ -short tsAffectedRowsMod = 0; - -int tsRowsInFileBlock = 4096; -float tsFileBlockMinPercent = 0.05; - -short tsNumOfBlocksPerMeter = 100; -short tsCommitTime = 3600; // seconds -short tsCommitLog = 1; -short tsCompression = TSDB_MAX_COMPRESSION_LEVEL; -short tsDaysPerFile = 10; -int tsDaysToKeep = 3650; -int tsReplications = TSDB_REPLICA_MIN_NUM; - -int tsNumOfMPeers = 3; -int tsMaxShellConns = 2000; -int tsMaxTables = 100000; - -char tsLocalIp[TSDB_IPv4ADDR_LEN] = {0}; -char tsDefaultDB[TSDB_DB_NAME_LEN] = {0}; -char tsDefaultUser[64] = "root"; -char tsDefaultPass[64] = "taosdata"; -int tsMaxMeterConnections = 10000; -int tsMaxMgmtConnections = 2000; -int tsMaxVnodeConnections = 10000; - -int tsBalanceMonitorInterval = 2; // seconds -int tsBalanceStartInterval = 300; // seconds -int tsBalancePolicy = 0; // 1-use sys.montor -int tsOfflineThreshold = 864000; // seconds 10days -int tsMgmtEqualVnodeNum = 4; - -int tsEnableHttpModule = 1; -int tsEnableMonitorModule = 0; -int tsRestRowLimit = 10240; -int tsMaxSQLStringLen = TSDB_MAX_SQL_LEN; - -// the maximum number of results for projection query on super table that are returned from -// one virtual node, to order according to timestamp -int tsMaxNumOfOrderedResults = 100000; - -/* - * denote if the server needs to compress response message at the application layer to client, including query rsp, - * metricmeta rsp, and multi-meter query rsp message body. The client compress the submit message to server. - * - * 0: all data are compressed - * -1: all data are not compressed - * other values: if the message payload size is greater than the tsCompressMsgSize, the message will be compressed. - */ -int tsCompressMsgSize = -1; - -// use UDP by default[option: udp, tcp] -char tsSocketType[4] = "udp"; - -// time precision, millisecond by default -int tsTimePrecision = TSDB_TIME_PRECISION_MILLI; - -// 10 ms for sliding time, the value will changed in case of time precision changed -int tsMinSlidingTime = 10; - -// 10 ms for interval time range, changed accordingly -int tsMinIntervalTime = 10; - -// 20sec, the maximum value of stream computing delay, changed accordingly -int tsMaxStreamComputDelay = 20000; - -// 10sec, the first stream computing delay time after system launched successfully, changed accordingly -int tsStreamCompStartDelay = 10000; - -// the stream computing delay time after executing failed, change accordingly -int tsStreamCompRetryDelay = 10; - -// The delayed computing ration. 10% of the whole computing time window by default. -float tsStreamComputDelayRatio = 0.1; - -int tsProjectExecInterval = 10000; // every 10sec, the projection will be executed once -int64_t tsMaxRetentWindow = 24 * 3600L; // maximum time window tolerance - -char tsHttpIp[TSDB_IPv4ADDR_LEN] = "0.0.0.0"; -uint16_t tsHttpPort = 6020; // only tcp, range tcp[6020] -// uint16_t tsNginxPort = 6060; //only tcp, range tcp[6060] -int tsHttpCacheSessions = 100; -int tsHttpSessionExpire = 36000; -int tsHttpMaxThreads = 2; -int tsHttpEnableCompress = 0; -int tsHttpEnableRecordSql = 0; -int tsTelegrafUseFieldNum = 0; - -int tsTscEnableRecordSql = 0; -int tsEnableCoreFile = 0; -int tsAnyIp = 1; -uint32_t tsPublicIpInt = 0; - -#ifdef _CLUSTER -int tsIsCluster = 1; -#else -int tsIsCluster = 0; -#endif - -int tsRpcTimer = 300; -int tsRpcMaxTime = 600; // seconds; -int tsRpcMaxUdpSize = 15000; // bytes - -char tsMonitorDbName[TSDB_DB_NAME_LEN] = "log"; -int tsMonitorInterval = 30; // seconds -char tsInternalPass[] = "secretkey"; - -char tsTimezone[64] = {0}; -char tsLocale[TSDB_LOCALE_LEN] = {0}; -char tsCharset[TSDB_LOCALE_LEN] = {0}; // default encode string - -int tsNumOfLogLines = 10000000; -uint32_t rpcDebugFlag = 135; -uint32_t ddebugFlag = 131; -uint32_t mdebugFlag = 135; -uint32_t sdbDebugFlag = 135; -uint32_t cdebugFlag = 131; -uint32_t jnidebugFlag = 131; -uint32_t httpDebugFlag = 131; -uint32_t monitorDebugFlag = 131; -uint32_t debugFlag = 131; -uint32_t odbcdebugFlag = 131; -uint32_t qdebugFlag = 131; - -SGlobalConfig *tsGlobalConfig = NULL; -int tsGlobalConfigNum = 0; - -char *tsGlobalUnit[] = { - " ", "(%)", "(GB)", "(MB)", "(Mb)", "(byte)", "(s)", "(ms)", -}; - -char *tsCfgStatusStr[] = {"none", "system default", "config file", "taos_options", "program argument list"}; - -void tsReadFloatConfig(SGlobalConfig *cfg, char *input_value) { - float value = (float)atof(input_value); - float *option = (float *)cfg->ptr; - if (value < cfg->minValue || value > cfg->maxValue) { - pError("config option:%s, input value:%s, out of range[%f, %f], use default value:%f", - cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); - } else { - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_FILE) { - *option = value; - cfg->cfgStatus = TSDB_CFG_CSTATUS_FILE; - } else { - pWarn("config option:%s, input value:%s, is configured by %s, use %f", cfg->option, input_value, - tsCfgStatusStr[cfg->cfgStatus], *option); - } - } -} - -void tsReadIntConfig(SGlobalConfig *cfg, char *input_value) { - int32_t value = atoi(input_value); - int32_t *option = (int32_t *)cfg->ptr; - if (value < cfg->minValue || value > cfg->maxValue) { - pError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", - cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); - } else { - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_FILE) { - *option = value; - cfg->cfgStatus = TSDB_CFG_CSTATUS_FILE; - } else { - pWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, - tsCfgStatusStr[cfg->cfgStatus], *option); - } - } -} - -void tsReadUIntConfig(SGlobalConfig *cfg, char *input_value) { - uint32_t value = (uint32_t)atoi(input_value); - uint32_t *option = (uint32_t *)cfg->ptr; - if (value < (uint32_t)cfg->minValue || value > (uint32_t)cfg->maxValue) { - pError("config option:%s, input value:%s, out of range[%f, %f], use default value:%u", - cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); - } else { - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_FILE) { - *option = value; - cfg->cfgStatus = TSDB_CFG_CSTATUS_FILE; - } else { - pWarn("config option:%s, input value:%s, is configured by %s, use %u", cfg->option, input_value, - tsCfgStatusStr[cfg->cfgStatus], *option); - } - } -} - -void tsReadShortConfig(SGlobalConfig *cfg, char *input_value) { - int32_t value = atoi(input_value); - int16_t *option = (int16_t *)cfg->ptr; - if (value < cfg->minValue || value > cfg->maxValue) { - pError("config option:%s, input value:%s, out of range[%f, %f], use default value:%d", - cfg->option, input_value, cfg->minValue, cfg->maxValue, *option); - } else { - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_FILE) { - *option = (int16_t)value; - cfg->cfgStatus = TSDB_CFG_CSTATUS_FILE; - } else { - pWarn("config option:%s, input value:%s, is configured by %s, use %d", cfg->option, input_value, - tsCfgStatusStr[cfg->cfgStatus], *option); - } - } -} - -void tsReadFilePathConfig(SGlobalConfig *cfg, char *input_value) { - int length = strlen(input_value); - char *option = (char *)cfg->ptr; - if (length <= 0 || length > cfg->ptrLength) { - pError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", - cfg->option, input_value, cfg->ptrLength, option); - } else { - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_FILE) { - wordexp_t full_path; - wordexp(input_value, &full_path, 0); - if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { - strcpy(option, full_path.we_wordv[0]); - } - wordfree(&full_path); - - struct stat dirstat; - if (stat(option, &dirstat) < 0) { - int code = mkdir(option, 0755); - pPrint("config option:%s, input value:%s, directory not exist, create with return code:%d", - cfg->option, input_value, code); - } - cfg->cfgStatus = TSDB_CFG_CSTATUS_FILE; - } else { - pWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, - tsCfgStatusStr[cfg->cfgStatus], option); - } - } -} - -void tsExpandFilePath(char* option_name, char* input_value) { - wordexp_t full_path; - wordexp(input_value, &full_path, 0); - if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { - strcpy(input_value, full_path.we_wordv[0]); - } - wordfree(&full_path); - - struct stat dirstat; - if (stat(input_value, &dirstat) < 0) { - int code = mkdir(input_value, 0755); - pPrint("config option:%s, input value:%s, directory not exist, create with return code:%d", option_name, input_value, code); - } -} - -void tsReadIpConfig(SGlobalConfig *cfg, char *input_value) { - uint32_t value = inet_addr(input_value); - char * option = (char *)cfg->ptr; - if (value == INADDR_NONE) { - pError("config option:%s, input value:%s, is not a valid ip address, use default value:%s", - cfg->option, input_value, option); - } else { - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_FILE) { - strncpy(option, input_value, cfg->ptrLength); - cfg->cfgStatus = TSDB_CFG_CSTATUS_FILE; - } else { - pWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, - tsCfgStatusStr[cfg->cfgStatus], option); - } - } -} - -void tsReadStrConfig(SGlobalConfig *cfg, char *input_value) { - int length = strlen(input_value); - char *option = (char *)cfg->ptr; - if (length <= 0 || length > cfg->ptrLength) { - pError("config option:%s, input value:%s, length out of range[0, %d], use default value:%s", - cfg->option, input_value, cfg->ptrLength, option); - } else { - if (cfg->cfgStatus <= TSDB_CFG_CSTATUS_FILE) { - strncpy(option, input_value, cfg->ptrLength); - cfg->cfgStatus = TSDB_CFG_CSTATUS_FILE; - } else { - pWarn("config option:%s, input value:%s, is configured by %s, use %s", cfg->option, input_value, - tsCfgStatusStr[cfg->cfgStatus], option); - } - } -} - -void tsReadLogOption(char *option, char *value) { - for (int i = 0; i < tsGlobalConfigNum; ++i) { - SGlobalConfig *cfg = tsGlobalConfig + i; - if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG) || !(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue; - if (strcasecmp(cfg->option, option) != 0) continue; - - switch (cfg->valType) { - case TSDB_CFG_VTYPE_INT: - tsReadIntConfig(cfg, value); - if (strcasecmp(cfg->option, "debugFlag") == 0) { - tsSetAllDebugFlag(); - } - break; - case TSDB_CFG_VTYPE_DIRECTORY: - tsReadFilePathConfig(cfg, value); - break; - default: - break; - } - break; - } -} - -SGlobalConfig *tsGetConfigOption(const char *option) { - tsInitGlobalConfig(); - for (int i = 0; i < tsGlobalConfigNum; ++i) { - SGlobalConfig *cfg = tsGlobalConfig + i; - if (strcasecmp(cfg->option, option) != 0) continue; - return cfg; - } - return NULL; -} - -void tsReadConfigOption(const char *option, char *value) { - for (int i = 0; i < tsGlobalConfigNum; ++i) { - SGlobalConfig *cfg = tsGlobalConfig + i; - if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_CONFIG)) continue; - if (strcasecmp(cfg->option, option) != 0) continue; - - switch (cfg->valType) { - case TSDB_CFG_VTYPE_SHORT: - tsReadShortConfig(cfg, value); - break; - case TSDB_CFG_VTYPE_INT: - tsReadIntConfig(cfg, value); - break; - case TSDB_CFG_VTYPE_UINT: - tsReadUIntConfig(cfg, value); - break; - case TSDB_CFG_VTYPE_FLOAT: - tsReadFloatConfig(cfg, value); - break; - case TSDB_CFG_VTYPE_STRING: - tsReadStrConfig(cfg, value); - break; - case TSDB_CFG_VTYPE_IPSTR: - tsReadIpConfig(cfg, value); - break; - case TSDB_CFG_VTYPE_DIRECTORY: - tsReadFilePathConfig(cfg, value); - break; - default: - pError("config option:%s, input value:%s, can't be recognized", option, value); - break; - } - break; - } -} - -void tsInitConfigOption(SGlobalConfig *cfg, char *name, void *ptr, int8_t valType, int8_t cfgType, float minVal, - float maxVal, uint8_t ptrLength, int8_t unitType) { - cfg->option = name; - cfg->ptr = ptr; - cfg->valType = valType; - cfg->cfgType = cfgType; - cfg->minValue = minVal; - cfg->maxValue = maxVal; - cfg->ptrLength = ptrLength; - cfg->unitType = unitType; - cfg->cfgStatus = TSDB_CFG_CSTATUS_NONE; -} - -static void doInitGlobalConfig() { - tsGlobalConfig = (SGlobalConfig *) malloc(sizeof(SGlobalConfig) * TSDB_CFG_MAX_NUM); - memset(tsGlobalConfig, 0, sizeof(SGlobalConfig) * TSDB_CFG_MAX_NUM); - - SGlobalConfig *cfg = tsGlobalConfig; - - // ip address - tsInitConfigOption(cfg++, "masterIp", tsMasterIp, TSDB_CFG_VTYPE_IPSTR, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, TSDB_IPv4ADDR_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "secondIp", tsSecondIp, TSDB_CFG_VTYPE_IPSTR, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_CLUSTER, - 0, 0, TSDB_IPv4ADDR_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "publicIp", tsPublicIp, TSDB_CFG_VTYPE_IPSTR, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLUSTER, - 0, 0, TSDB_IPv4ADDR_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "privateIp", tsPrivateIp, TSDB_CFG_VTYPE_IPSTR, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLUSTER, - 0, 0, TSDB_IPv4ADDR_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "localIp", tsLocalIp, TSDB_CFG_VTYPE_IPSTR, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, TSDB_IPv4ADDR_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "httpIp", tsHttpIp, TSDB_CFG_VTYPE_IPSTR, - TSDB_CFG_CTYPE_B_CONFIG, - 0, 0, TSDB_IPv4ADDR_LEN, TSDB_CFG_UTYPE_NONE); - - // port - tsInitConfigOption(cfg++, "httpPort", &tsHttpPort, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 1, 65535, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "mgmtShellPort", &tsMnodeShellPort, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT, - 1, 65535, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "vnodeShellPort", &tsDnodeShellPort, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT, - 1, 65535, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "mgmtVnodePort", &tsMnodeDnodePort, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 1, 65535, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "vnodeVnodePort", &tsVnodeVnodePort, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 1, 65535, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "mgmtMgmtPort", &tsMgmtMgmtPort, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 1, 65535, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "mgmtSyncPort", &tsMgmtSyncPort, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 1, 65535, 0, TSDB_CFG_UTYPE_NONE); - - // directory - tsInitConfigOption(cfg++, "configDir", configDir, TSDB_CFG_VTYPE_DIRECTORY, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, TSDB_FILENAME_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "logDir", logDir, TSDB_CFG_VTYPE_DIRECTORY, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_LOG, - 0, 0, TSDB_FILENAME_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "scriptDir", scriptDir, TSDB_CFG_VTYPE_DIRECTORY, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, TSDB_FILENAME_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "dataDir", dataDir, TSDB_CFG_VTYPE_DIRECTORY, - TSDB_CFG_CTYPE_B_CONFIG, - 0, 0, TSDB_FILENAME_LEN, TSDB_CFG_UTYPE_NONE); - - // dnode configs - tsInitConfigOption(cfg++, "numOfThreadsPerCore", &tsNumOfThreadsPerCore, TSDB_CFG_VTYPE_FLOAT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 10, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "ratioOfQueryThreads", &tsRatioOfQueryThreads, TSDB_CFG_VTYPE_FLOAT, - TSDB_CFG_CTYPE_B_CONFIG, - 0.1, 0.9, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "numOfVnodesPerCore", &tsNumOfVnodesPerCore, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 1, 64, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "numOfTotalVnodes", &tsNumOfTotalVnodes, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG, - 0, TSDB_MAX_VNODES, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "tables", &tsSessionsPerVnode, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - TSDB_MIN_TABLES_PER_VNODE, TSDB_MAX_TABLES_PER_VNODE, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "cache", &tsCacheBlockSize, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 100, 1048576, 0, TSDB_CFG_UTYPE_BYTE); - tsInitConfigOption(cfg++, "rows", &tsRowsInFileBlock, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 200, 1048576, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "fileBlockMinPercent", &tsFileBlockMinPercent, TSDB_CFG_VTYPE_FLOAT, - TSDB_CFG_CTYPE_B_CONFIG, - 0, 1.0, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "ablocks", &tsAverageCacheBlocks, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - TSDB_MIN_AVG_BLOCKS, TSDB_MAX_AVG_BLOCKS, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "tblocks", &tsNumOfBlocksPerMeter, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 32, 4096, 0, TSDB_CFG_UTYPE_NONE); -#ifdef _SYNC - tsInitConfigOption(cfg++, "numOfMPeers", &tsNumOfMPeers, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 1, 3, 0, TSDB_CFG_UTYPE_NONE); -#endif - tsInitConfigOption(cfg++, "balanceInterval", &tsBalanceStartInterval, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 1, 30000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "alternativeRole", &tsAlternativeRole, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLUSTER, - 0, 2, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "affectedRowsMod", &tsAffectedRowsMod, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 1, 0, TSDB_CFG_UTYPE_NONE); - // 0-any, 1-mgmt, 2-dnode - - // timer - tsInitConfigOption(cfg++, "maxTmrCtrl", &taosMaxTmrCtrl, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 8, 2048, 0, TSDB_CFG_UTYPE_NONE); - - // time - tsInitConfigOption(cfg++, "monitorInterval", &tsMonitorInterval, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG, - 1, 600, 0, TSDB_CFG_UTYPE_SECOND); - tsInitConfigOption(cfg++, "offlineThreshold", &tsOfflineThreshold, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 5, 7200000, 0, TSDB_CFG_UTYPE_SECOND); - tsInitConfigOption(cfg++, "rpcTimer", &tsRpcTimer, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 100, 3000, 0, TSDB_CFG_UTYPE_MS); - tsInitConfigOption(cfg++, "rpcMaxTime", &tsRpcMaxTime, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 100, 7200, 0, TSDB_CFG_UTYPE_SECOND); - tsInitConfigOption(cfg++, "ctime", &tsCommitTime, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 30, 40960, 0, TSDB_CFG_UTYPE_SECOND); - tsInitConfigOption(cfg++, "statusInterval", &tsStatusInterval, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 1, 10, 0, TSDB_CFG_UTYPE_SECOND); - tsInitConfigOption(cfg++, "shellActivityTimer", &tsShellActivityTimer, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 1, 120, 0, TSDB_CFG_UTYPE_SECOND); - tsInitConfigOption(cfg++, "vnodePeerHBTimer", &tsVnodePeerHBTimer, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 1, 10, 0, TSDB_CFG_UTYPE_SECOND); - tsInitConfigOption(cfg++, "mgmtPeerHBTimer", &tsMgmtPeerHBTimer, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, 1, 10, 0, - TSDB_CFG_UTYPE_SECOND); - tsInitConfigOption(cfg++, "meterMetaKeepTimer", &tsMeterMetaKeepTimer, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 1, 8640000, 0, TSDB_CFG_UTYPE_SECOND); - tsInitConfigOption(cfg++, "metricMetaKeepTimer", &tsMetricMetaKeepTimer, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 1, 8640000, 0, TSDB_CFG_UTYPE_SECOND); - - // mgmt configs - tsInitConfigOption(cfg++, "maxTables", &tsMaxTables, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 1, 100000000, 0, TSDB_CFG_UTYPE_NONE); - - tsInitConfigOption(cfg++, "minSlidingTime", &tsMinSlidingTime, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 10, 1000000, 0, TSDB_CFG_UTYPE_MS); - tsInitConfigOption(cfg++, "minIntervalTime", &tsMinIntervalTime, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 10, 1000000, 0, TSDB_CFG_UTYPE_MS); - tsInitConfigOption(cfg++, "maxStreamCompDelay", &tsMaxStreamComputDelay, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 10, 1000000000, 0, TSDB_CFG_UTYPE_MS); - tsInitConfigOption(cfg++, "maxFirstStreamCompDelay", &tsStreamCompStartDelay, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 1000, 1000000000, 0, TSDB_CFG_UTYPE_MS); - tsInitConfigOption(cfg++, "retryStreamCompDelay", &tsStreamCompRetryDelay, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, 10, 1000000000, 0, TSDB_CFG_UTYPE_MS); - - - tsInitConfigOption(cfg++, "streamCompDelayRatio", &tsStreamComputDelayRatio, TSDB_CFG_VTYPE_FLOAT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, 0.1, 0.9, 0, TSDB_CFG_UTYPE_NONE); - - tsInitConfigOption(cfg++, "clog", &tsCommitLog, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 0, 2, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "comp", &tsCompression, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 0, 2, 0, TSDB_CFG_UTYPE_NONE); - - // database configs - tsInitConfigOption(cfg++, "days", &tsDaysPerFile, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 1, 365, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "keep", &tsDaysToKeep, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 1, 365000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "replica", &tsReplications, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 1, 3, 0, TSDB_CFG_UTYPE_NONE); - - // login configs - tsInitConfigOption(cfg++, "defaultDB", tsDefaultDB, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, TSDB_DB_NAME_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "defaultUser", tsDefaultUser, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, TSDB_USER_LEN, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "defaultPass", tsDefaultPass, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_NOT_PRINT, - 0, 0, TSDB_PASSWORD_LEN, TSDB_CFG_UTYPE_NONE); - - // socket type, udp by default - tsInitConfigOption(cfg++, "sockettype", tsSocketType, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW, - 0, 0, 3, TSDB_CFG_UTYPE_NONE); - - tsInitConfigOption(cfg++, "compressMsgSize", &tsCompressMsgSize, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW, - -1, 10000000, 0, TSDB_CFG_UTYPE_NONE); - - tsInitConfigOption(cfg++, "maxSQLLength", &tsMaxSQLStringLen, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW, - TSDB_MAX_SQL_LEN, TSDB_MAX_ALLOWED_SQL_LEN, 0, TSDB_CFG_UTYPE_BYTE); - - tsInitConfigOption(cfg++, "maxNumOfOrderedRes", &tsMaxNumOfOrderedResults, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT | TSDB_CFG_CTYPE_B_SHOW, - TSDB_MAX_SQL_LEN, TSDB_MAX_ALLOWED_SQL_LEN, 0, TSDB_CFG_UTYPE_NONE); - - // locale & charset - tsInitConfigOption(cfg++, "timezone", tsTimezone, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, tListLen(tsTimezone), TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "locale", tsLocale, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, tListLen(tsLocale), TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "charset", tsCharset, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, tListLen(tsCharset), TSDB_CFG_UTYPE_NONE); - - // connect configs - tsInitConfigOption(cfg++, "maxShellConns", &tsMaxShellConns, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 10, 50000000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "maxMeterConnections", &tsMaxMeterConnections, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 10, 50000000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "maxMgmtConnections", &tsMaxMgmtConnections, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 10, 50000000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "maxVnodeConnections", &tsMaxVnodeConnections, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 10, 50000000, 0, TSDB_CFG_UTYPE_NONE); - - tsInitConfigOption(cfg++, "minimalLogDirGB", &tsMinimalLogDirGB, TSDB_CFG_VTYPE_FLOAT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 0.001, 10000000, 0, TSDB_CFG_UTYPE_GB); - tsInitConfigOption(cfg++, "minimalTmpDirGB", &tsMinimalTmpDirGB, TSDB_CFG_VTYPE_FLOAT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 0.001, 10000000, 0, TSDB_CFG_UTYPE_GB); - tsInitConfigOption(cfg++, "minimalDataDirGB", &tsMinimalDataDirGB, TSDB_CFG_VTYPE_FLOAT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 0.001, 10000000, 0, TSDB_CFG_UTYPE_GB); - - // module configs - tsInitConfigOption(cfg++, "mgmtEqualVnodeNum", &tsMgmtEqualVnodeNum, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLUSTER, - 0, 1000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "http", &tsEnableHttpModule, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 0, 1, 1, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "monitor", &tsEnableMonitorModule, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 0, 1, 1, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "monitorDbName", tsMonitorDbName, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 0, 0, TSDB_DB_NAME_LEN, TSDB_CFG_UTYPE_NONE); - - // http configs - tsInitConfigOption(cfg++, "httpCacheSessions", &tsHttpCacheSessions, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG, - 1, 100000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "httpEnableRecordSql", &tsHttpEnableRecordSql, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG, - 0, 1, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "telegrafUseFieldNum", &tsTelegrafUseFieldNum, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_SHOW, - 0, 1, 1, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "httpMaxThreads", &tsHttpMaxThreads, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG, - 1, 1000000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "restfulRowLimit", &tsRestRowLimit, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG, - 1, 10000000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "httpEnableCompress", &tsHttpEnableCompress, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG, - 0, 1, 1, TSDB_CFG_UTYPE_NONE); - - // debug flag - tsInitConfigOption(cfg++, "numOfLogLines", &tsNumOfLogLines, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 10000, 2000000000, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "asyncLog", &tsAsyncLog, TSDB_CFG_VTYPE_SHORT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 1, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "debugFlag", &debugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "mDebugFlag", &mdebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "dDebugFlag", &ddebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "sdbDebugFlag", &sdbDebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "rpcDebugFlag", &rpcDebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "tmrDebugFlag", &tmrDebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "cDebugFlag", &cdebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "jniDebugFlag", &jnidebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "odbcDebugFlag", &odbcdebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "uDebugFlag", &uDebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "httpDebugFlag", &httpDebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "monitorDebugFlag", &monitorDebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG, - 0, 255, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "qDebugFlag", &qdebugFlag, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_LOG | TSDB_CFG_CTYPE_B_CLIENT, - 0, 255, 0, - TSDB_CFG_UTYPE_NONE); - - tsInitConfigOption(cfg++, "tscEnableRecordSql", &tsTscEnableRecordSql, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG, - 0, 1, 0, TSDB_CFG_UTYPE_NONE); - - tsInitConfigOption(cfg++, "enableCoreFile", &tsEnableCoreFile, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG, - 0, 1, 0, TSDB_CFG_UTYPE_NONE); - - tsInitConfigOption(cfg++, "anyIp", &tsAnyIp, TSDB_CFG_VTYPE_INT, - TSDB_CFG_CTYPE_B_CONFIG | TSDB_CFG_CTYPE_B_CLUSTER, - 0, 1, 0, TSDB_CFG_UTYPE_NONE); - - // version info - tsInitConfigOption(cfg++, "gitinfo", gitinfo, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "gitinfoOfInternal", gitinfoOfInternal, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "buildinfo", buildinfo, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, 0, TSDB_CFG_UTYPE_NONE); - tsInitConfigOption(cfg++, "version", version, TSDB_CFG_VTYPE_STRING, - TSDB_CFG_CTYPE_B_SHOW | TSDB_CFG_CTYPE_B_CLIENT, - 0, 0, 0, TSDB_CFG_UTYPE_NONE); - - tsGlobalConfigNum = (int)(cfg - tsGlobalConfig); - assert(tsGlobalConfigNum <= TSDB_CFG_MAX_NUM); -} - -static pthread_once_t initGlobalConfig = PTHREAD_ONCE_INIT; -void tsInitGlobalConfig() { - pthread_once(&initGlobalConfig, doInitGlobalConfig); -} - -void tsReadGlobalLogConfig() { - tsInitGlobalConfig(); - - FILE * fp; - char * line, *option, *value; - int olen, vlen; - char fileName[PATH_MAX] = {0}; - - mdebugFlag = 135; - sdbDebugFlag = 135; - - wordexp_t full_path; - wordexp(configDir, &full_path, 0); - if (full_path.we_wordv != NULL && full_path.we_wordv[0] != NULL) { - strcpy(configDir, full_path.we_wordv[0]); - } else { - printf("configDir:%s not there, use default value: /etc/taos", configDir); - strcpy(configDir, "/etc/taos"); - } - wordfree(&full_path); - - tsReadLogOption("logDir", logDir); - - sprintf(fileName, "%s/taos.cfg", configDir); - fp = fopen(fileName, "r"); - if (fp == NULL) { - printf("\nconfig file:%s not found, all variables are set to default\n", fileName); - return; - } - - size_t len = 1024; - line = calloc(1, len); - - while (!feof(fp)) { - memset(line, 0, len); - - option = value = NULL; - olen = vlen = 0; - - getline(&line, &len, fp); - line[len - 1] = 0; - - paGetToken(line, &option, &olen); - if (olen == 0) continue; - option[olen] = 0; - - paGetToken(option + olen + 1, &value, &vlen); - if (vlen == 0) continue; - value[vlen] = 0; - - tsReadLogOption(option, value); - } - - tfree(line); - fclose(fp); -} - -bool tsReadGlobalConfig() { - tsInitGlobalConfig(); - - char * line, *option, *value, *value1; - int olen, vlen, vlen1; - char fileName[PATH_MAX] = {0}; - - sprintf(fileName, "%s/taos.cfg", configDir); - FILE* fp = fopen(fileName, "r"); - - size_t len = 1024; - line = calloc(1, len); - - if (fp != NULL) { - while (!feof(fp)) { - memset(line, 0, len); - - option = value = NULL; - olen = vlen = 0; - - getline(&line, &len, fp); - line[len - 1] = 0; - - paGetToken(line, &option, &olen); - if (olen == 0) continue; - option[olen] = 0; - - paGetToken(option + olen + 1, &value, &vlen); - if (vlen == 0) continue; - value[vlen] = 0; - - // For dataDir, the format is: - // dataDir /mnt/disk1 0 - paGetToken(value + vlen + 1, &value1, &vlen1); - - tsReadConfigOption(option, value); - } - - fclose(fp); - } - - tfree(line); - - if (tsReadStorageConfig) { - tsReadStorageConfig(); - } - - if (tsPrivateIp[0] == 0) { - taosGetPrivateIp(tsPrivateIp); - } - - if (tsPublicIp[0] == 0) { - strcpy(tsPublicIp, tsPrivateIp); - } - tsPublicIpInt = inet_addr(tsPublicIp); - - if (tsLocalIp[0] == 0) { - strcpy(tsLocalIp, tsPrivateIp); - } - - if (tsMasterIp[0] == 0) { - strcpy(tsMasterIp, tsPrivateIp); - } - - if (tsSecondIp[0] == 0) { - strcpy(tsSecondIp, tsMasterIp); - } - - taosGetSystemInfo(); - - tsSetLocale(); - - SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone"); - if (cfg_timezone && cfg_timezone->cfgStatus == TSDB_CFG_CSTATUS_FILE) { - tsSetTimeZone(); - } - - if (tsNumOfCores <= 0) { - tsNumOfCores = 1; - } - - if (tsNumOfTotalVnodes == TSDB_INVALID_VNODE_NUM) { - tsNumOfTotalVnodes = tsNumOfCores * tsNumOfVnodesPerCore; - tsNumOfTotalVnodes = tsNumOfTotalVnodes > TSDB_MAX_VNODES ? TSDB_MAX_VNODES : tsNumOfTotalVnodes; - tsNumOfTotalVnodes = tsNumOfTotalVnodes < TSDB_MIN_VNODES ? TSDB_MIN_VNODES : tsNumOfTotalVnodes; - } - - if (strlen(tsPrivateIp) == 0) { - pError("privateIp is null"); - return false; - } - - if (tscEmbedded) { - strcpy(tsLocalIp, tsPrivateIp); - } - - // todo refactor - tsVersion = 0; - for (int i = 0; i < 10; i++) { - if (version[i] >= '0' && version[i] <= '9') { - tsVersion = tsVersion * 10 + (version[i] - '0'); - } else if (version[i] == 0) { - break; - } - } - - tsVersion = 10 * tsVersion; - - return true; -} - -int tsCfgDynamicOptions(char *msg) { - char *option, *value; - int olen, vlen, code = 0; - int vint = 0; - - paGetToken(msg, &option, &olen); - if (olen == 0) return TSDB_CODE_INVALID_MSG_CONTENT; - - paGetToken(option + olen + 1, &value, &vlen); - if (vlen == 0) - vint = 135; - else { - vint = atoi(value); - } - - pPrint("change dynamic option: %s, value: %d", option, vint); - - for (int i = 0; i < tsGlobalConfigNum; ++i) { - SGlobalConfig *cfg = tsGlobalConfig + i; - if (!(cfg->cfgType & TSDB_CFG_CTYPE_B_LOG)) continue; - if (cfg->valType != TSDB_CFG_VTYPE_INT) continue; - if (strncasecmp(option, cfg->option, olen) != 0) continue; - *((int *)cfg->ptr) = vint; - - if (strncasecmp(cfg->option, "monitor", olen) == 0) { - if (0 == vint) { - if(stopMonitor) (void)(*stopMonitor)(); - } else { - if(startMonitor) (*startMonitor)(); - } - return code; - } - - if (strncasecmp(cfg->option, "debugFlag", olen) == 0) { - tsSetAllDebugFlag(); - } - - return code; - } - - if (strncasecmp(option, "resetlog", 8) == 0) { - taosResetLogFile(); - tsPrintGlobalConfig(); - return code; - } - - if (strncasecmp(option, "resetQueryCache", 15) == 0) { - if (taosLogSqlFp) { - pPrint("the query cache of internal client will reset"); - taosLogSqlFp("reset query cache"); - } else { - pError("reset query cache can't be executed, for monitor not initialized"); - code = 169; - } - } else { - code = 169; // INVALID_OPTION - } - - return code; -} - -void tsPrintGlobalConfig() { - pPrint(" taos config & system info:"); - pPrint("=================================="); - - for (int i = 0; i < tsGlobalConfigNum; ++i) { - SGlobalConfig *cfg = tsGlobalConfig + i; - if (tscEmbedded == 0 && !(cfg->cfgType & TSDB_CFG_CTYPE_B_CLIENT)) continue; - if (cfg->cfgType & TSDB_CFG_CTYPE_B_NOT_PRINT) continue; - if (cfg->cfgType & TSDB_CFG_CTYPE_B_LITE) { -#ifdef _CLUSTER - continue; -#endif - } - if (cfg->cfgType & TSDB_CFG_CTYPE_B_CLUSTER) { -#ifndef _CLUSTER - continue; -#endif - } - - int optionLen = (int)strlen(cfg->option); - int blankLen = TSDB_CFG_PRINT_LEN - optionLen; - blankLen = blankLen < 0 ? 0 : blankLen; - - char blank[TSDB_CFG_PRINT_LEN]; - memset(blank, ' ', TSDB_CFG_PRINT_LEN); - blank[blankLen] = 0; - - switch (cfg->valType) { - case TSDB_CFG_VTYPE_SHORT: - pPrint(" %s:%s%d%s", cfg->option, blank, *((int16_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TSDB_CFG_VTYPE_INT: - pPrint(" %s:%s%d%s", cfg->option, blank, *((int32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TSDB_CFG_VTYPE_UINT: - pPrint(" %s:%s%d%s", cfg->option, blank, *((uint32_t *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TSDB_CFG_VTYPE_FLOAT: - pPrint(" %s:%s%f%s", cfg->option, blank, *((float *)cfg->ptr), tsGlobalUnit[cfg->unitType]); - break; - case TSDB_CFG_VTYPE_STRING: - case TSDB_CFG_VTYPE_IPSTR: - case TSDB_CFG_VTYPE_DIRECTORY: - pPrint(" %s:%s%s%s", cfg->option, blank, (char *)cfg->ptr, tsGlobalUnit[cfg->unitType]); - break; - default: - break; - } - } - - if (tsPrintStorageConfig) { - tsPrintStorageConfig(); - } else { - pPrint(" dataDir: %s", dataDir); - } - - tsPrintOsInfo(); -} - -void tsSetAllDebugFlag() { - if (mdebugFlag != debugFlag) mdebugFlag = debugFlag; - if (ddebugFlag != debugFlag) ddebugFlag = debugFlag; - if (sdbDebugFlag != debugFlag) sdbDebugFlag = debugFlag; - if (rpcDebugFlag != debugFlag) rpcDebugFlag = debugFlag; - if (cdebugFlag != debugFlag) cdebugFlag = debugFlag; - if (jnidebugFlag != debugFlag) jnidebugFlag = debugFlag; - if (uDebugFlag != debugFlag) uDebugFlag = debugFlag; - if (httpDebugFlag != debugFlag) httpDebugFlag = debugFlag; - if (monitorDebugFlag != debugFlag) monitorDebugFlag = debugFlag; - if (odbcdebugFlag != debugFlag) odbcdebugFlag = debugFlag; - pPrint("all debug flag are set to %d", debugFlag); -} - -/** - * In some Linux systems, setLocale(LC_CTYPE, "") may return NULL, in which case the launch of - * both the TDengine Server and the Client may be interrupted. - * - * In case that the setLocale failed to be executed, the right charset needs to be set. - */ -void tsSetLocale() { - char msgLocale[] = "Invalid locale:%s, please set the valid locale in config file\n"; - char msgCharset[] = "Invalid charset:%s, please set the valid charset in config file\n"; - char msgCharset1[] = "failed to get charset, please set the valid charset in config file\n"; - - char *locale = setlocale(LC_CTYPE, tsLocale); - - // default locale or user specified locale is not valid, abort launch - if (locale == NULL) { - printf(msgLocale, tsLocale); - pPrint(msgLocale, tsLocale); - } - - if (strlen(tsCharset) == 0) { - printf("%s\n", msgCharset1); - pPrint(msgCharset1); - exit(-1); - } - - if (!taosValidateEncodec(tsCharset)) { - printf(msgCharset, tsCharset); - pPrint(msgCharset, tsCharset); - exit(-1); - } -} - -void tsSetTimeZone() { - SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone"); - pPrint("timezone is set to %s by %s", tsTimezone, tsCfgStatusStr[cfg_timezone->cfgStatus]); - -#ifdef WINDOWS - char winStr[TSDB_LOCALE_LEN * 2]; - sprintf(winStr, "TZ=%s", tsTimezone); - putenv(winStr); -#else - setenv("TZ", tsTimezone, 1); -#endif - tzset(); - - /* - * get CURRENT time zone. - * system current time zone is affected by daylight saving time(DST) - * - * e.g., the local time zone of London in DST is GMT+01:00, - * otherwise is GMT+00:00 - */ -#ifdef _MSC_VER -#if _MSC_VER >= 1900 - // see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019 - int64_t timezone = _timezone; - int32_t daylight = _daylight; - char **tzname = _tzname; -#endif -#endif - - int32_t tz = (-timezone * MILLISECOND_PER_SECOND) / MILLISECOND_PER_HOUR; - tz += daylight; - - /* - * format: - * (CST, +0800) - * (BST, +0100) - */ - sprintf(tsTimezone, "(%s, %s%02d00)", tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); - - pPrint("timezone format changed to %s", tsTimezone); -} - diff --git a/src/util/src/tidpool.c b/src/util/src/tidpool.c index 04ae154267..98df9a9e7e 100644 --- a/src/util/src/tidpool.c +++ b/src/util/src/tidpool.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "tlog.h" +#include "tulog.h" #include typedef struct { @@ -41,7 +41,7 @@ void *taosInitIdPool(int maxId) { pthread_mutex_init(&pIdPool->mutex, NULL); - pTrace("pool:%p is setup, maxId:%d", pIdPool, pIdPool->maxId); + uTrace("pool:%p is setup, maxId:%d", pIdPool, pIdPool->maxId); return pIdPool; } @@ -91,7 +91,7 @@ void taosIdPoolCleanUp(void *handle) { if (pIdPool == NULL) return; - pTrace("pool:%p is cleaned", pIdPool); + uTrace("pool:%p is cleaned", pIdPool); if (pIdPool->freeList) free(pIdPool->freeList); diff --git a/src/util/src/tlog.c b/src/util/src/tlog.c index 52aa07d968..64ccfbc9da 100644 --- a/src/util/src/tlog.c +++ b/src/util/src/tlog.c @@ -13,7 +13,9 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "os.h" +#include "tulog.h" #include "tlog.h" #include "tutil.h" @@ -25,100 +27,95 @@ #define MAX_LOGLINE_DUMP_CONTENT_SIZE (MAX_LOGLINE_DUMP_SIZE - 100) #define LOG_FILE_NAME_LEN 300 -#define TSDB_DEFAULT_LOG_BUF_SIZE (512 * 1024) // 512K +#define TSDB_DEFAULT_LOG_BUF_SIZE (512 * 1024) // 512K #define TSDB_MIN_LOG_BUF_SIZE 1024 // 1K #define TSDB_MAX_LOG_BUF_SIZE (1024 * 1024) // 1M #define TSDB_DEFAULT_LOG_BUF_UNIT 1024 // 1K +#define LOG_BUF_BUFFER(x) ((x)->buffer) +#define LOG_BUF_START(x) ((x)->buffStart) +#define LOG_BUF_END(x) ((x)->buffEnd) +#define LOG_BUF_SIZE(x) ((x)->buffSize) +#define LOG_BUF_MUTEX(x) ((x)->buffMutex) + typedef struct { char * buffer; - int buffStart; - int buffEnd; - int buffSize; - int fd; - int stop; + int32_t buffStart; + int32_t buffEnd; + int32_t buffSize; + int32_t fd; + int32_t stop; pthread_t asyncThread; pthread_mutex_t buffMutex; - tsem_t buffNotEmpty; + tsem_t buffNotEmpty; } SLogBuff; -uint32_t uDebugFlag = 131; // all the messages -short tsAsyncLog = 1; +typedef struct { + int32_t fileNum; + int32_t maxLines; + int32_t lines; + int32_t flag; + int32_t openInProgress; + pid_t pid; + char logName[LOG_FILE_NAME_LEN]; + SLogBuff * logHandle; + pthread_mutex_t logMutex; +} SLogObj; -static pid_t logPid = 0; -static SLogBuff *logHandle = NULL; -static int taosLogFileNum = 1; -static int taosLogMaxLines = 0; -static int taosLogLines = 0; -static char taosLogName[LOG_FILE_NAME_LEN]; -static int taosLogFlag = 0; -// static int logFd = -1; -static int openInProgress = 0; -static pthread_mutex_t logMutex; -void (*taosLogFp)(int level, const char *const format, ...) = NULL; -void (*taosLogSqlFp)(char *sql) = NULL; -void (*taosLogAcctFp)(char *acctId, int64_t currentPointsPerSecond, int64_t maxPointsPerSecond, int64_t totalTimeSeries, - int64_t maxTimeSeries, int64_t totalStorage, int64_t maxStorage, int64_t totalQueryTime, - int64_t maxQueryTime, int64_t totalInbound, int64_t maxInbound, int64_t totalOutbound, - int64_t maxOutbound, int64_t totalDbs, int64_t maxDbs, int64_t totalUsers, int64_t maxUsers, - int64_t totalStreams, int64_t maxStreams, int64_t totalConns, int64_t maxConns, - int8_t accessState) = NULL; -void *taosAsyncOutputLog(void *param); -int taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int msgLen); -SLogBuff *taosLogBuffNew(int bufSize); -void taosLogBuffDestroy(SLogBuff *tLogBuff); +int32_t tsAsyncLog = 1; +float tsTotalLogDirGB = 0; +float tsAvailLogDirGB = 0; +float tsMinimalLogDirGB = 0.1; +char logDir[TSDB_FILENAME_LEN] = "/var/log/taos"; -int taosStartLog() { +static SLogObj tsLogObj = { .fileNum = 1 }; +static void * taosAsyncOutputLog(void *param); +static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen); +static SLogBuff *taosLogBuffNew(int32_t bufSize); +static void taosCloseLogByFd(int32_t oldFd); +static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum); + +static int32_t taosStartLog() { pthread_attr_t threadAttr; - pthread_attr_init(&threadAttr); - - if (pthread_create(&(logHandle->asyncThread), &threadAttr, taosAsyncOutputLog, logHandle) != 0) { + if (pthread_create(&(tsLogObj.logHandle->asyncThread), &threadAttr, taosAsyncOutputLog, tsLogObj.logHandle) != 0) { return -1; } - pthread_attr_destroy(&threadAttr); - return 0; } -int taosInitLog(char *logName, int numOfLogLines, int maxFiles) { - -#ifdef LINUX - logPid = (pid_t)syscall(SYS_gettid); -#endif - - logHandle = taosLogBuffNew(TSDB_DEFAULT_LOG_BUF_SIZE); - if (logHandle == NULL) return -1; - - if (taosOpenLogFileWithMaxLines(logName, numOfLogLines, maxFiles) < 0) return -1; - +int32_t taosInitLog(char *logName, int numOfLogLines, int maxFiles) { + tsLogObj.logHandle = taosLogBuffNew(TSDB_DEFAULT_LOG_BUF_SIZE); + if (tsLogObj.logHandle == NULL) return -1; + if (taosOpenLogFile(logName, numOfLogLines, maxFiles) < 0) return -1; if (taosStartLog() < 0) return -1; return 0; } -void taosStopLog() { - if (logHandle) logHandle->stop = 1; +static void taosStopLog() { + if (tsLogObj.logHandle) { + tsLogObj.logHandle->stop = 1; + } } -void taosCloseLogger() { +void taosCloseLog() { taosStopLog(); - tsem_post(&(logHandle->buffNotEmpty)); - if (taosCheckPthreadValid(logHandle->asyncThread)) { - pthread_join(logHandle->asyncThread, NULL); + tsem_post(&(tsLogObj.logHandle->buffNotEmpty)); + if (taosCheckPthreadValid(tsLogObj.logHandle->asyncThread)) { + pthread_join(tsLogObj.logHandle->asyncThread, NULL); } - // In case that other threads still use log resources causing invalid write in - // valgrind, we comment two lines below. - // taosLogBuffDestroy(logHandle); + // In case that other threads still use log resources causing invalid write in valgrind + // we comment two lines below. + // taosLogBuffDestroy(tsLogObj.logHandle); // taosCloseLog(); } -void taosCloseLogByFd(int oldFd); -bool taosLockFile(int fd) { +static bool taosLockFile(int32_t fd) { if (fd < 0) return false; - if (taosLogFileNum > 1) { - int ret = flock(fd, LOCK_EX | LOCK_NB); + if (tsLogObj.fileNum > 1) { + int32_t ret = flock(fd, LOCK_EX | LOCK_NB); if (ret == 0) { return true; } @@ -127,44 +124,44 @@ bool taosLockFile(int fd) { return false; } -void taosUnLockFile(int fd) { +static void taosUnLockFile(int32_t fd) { if (fd < 0) return; - if (taosLogFileNum > 1) { + if (tsLogObj.fileNum > 1) { flock(fd, LOCK_UN | LOCK_NB); } } -void *taosThreadToOpenNewFile(void *param) { - char name[LOG_FILE_NAME_LEN]; +static void *taosThreadToOpenNewFile(void *param) { + char name[LOG_FILE_NAME_LEN + 20]; - taosLogFlag ^= 1; - taosLogLines = 0; - sprintf(name, "%s.%d", taosLogName, taosLogFlag); + tsLogObj.flag ^= 1; + tsLogObj.lines = 0; + sprintf(name, "%s.%d", tsLogObj.logName, tsLogObj.flag); umask(0); - int fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(name, O_WRONLY | O_CREAT | O_TRUNC, S_IRWXU | S_IRWXG | S_IRWXO); taosLockFile(fd); lseek(fd, 0, SEEK_SET); - int oldFd = logHandle->fd; - logHandle->fd = fd; - taosLogLines = 0; - openInProgress = 0; - pPrint("new log file is opened!!!"); + int32_t oldFd = tsLogObj.logHandle->fd; + tsLogObj.logHandle->fd = fd; + tsLogObj.lines = 0; + tsLogObj.openInProgress = 0; + uPrint("new log file is opened!!!"); taosCloseLogByFd(oldFd); return NULL; } -int taosOpenNewLogFile() { - pthread_mutex_lock(&logMutex); +static int32_t taosOpenNewLogFile() { + pthread_mutex_lock(&tsLogObj.logMutex); - if (taosLogLines > taosLogMaxLines && openInProgress == 0) { - openInProgress = 1; + if (tsLogObj.lines > tsLogObj.maxLines && tsLogObj.openInProgress == 0) { + tsLogObj.openInProgress = 1; - pPrint("open new log file ......"); + uPrint("open new log file ......"); pthread_t thread; pthread_attr_t attr; pthread_attr_init(&attr); @@ -174,32 +171,32 @@ int taosOpenNewLogFile() { pthread_attr_destroy(&attr); } - pthread_mutex_unlock(&logMutex); + pthread_mutex_unlock(&tsLogObj.logMutex); return 0; } -void taosResetLogFile() { - char lastName[LOG_FILE_NAME_LEN]; - sprintf(lastName, "%s.%d", taosLogName, taosLogFlag); +void taosResetLog() { + char lastName[LOG_FILE_NAME_LEN + 20]; + sprintf(lastName, "%s.%d", tsLogObj.logName, tsLogObj.flag); // force create a new log file - taosLogLines = taosLogMaxLines + 10; + tsLogObj.lines = tsLogObj.maxLines + 10; taosOpenNewLogFile(); remove(lastName); - pPrint("=================================="); - pPrint(" reset log file "); + uPrint("=================================="); + uPrint(" reset log file "); } -bool taosCheckFileIsOpen(char *logFileName) { - int exist = access(logFileName, F_OK); +static bool taosCheckFileIsOpen(char *logFileName) { + int32_t exist = access(logFileName, F_OK); if (exist != 0) { return false; } - int fd = open(logFileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + int32_t fd = open(logFileName, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); if (fd < 0) { printf("\nfailed to open log file:%s, reason:%s\n", logFileName, strerror(errno)); return true; @@ -215,9 +212,9 @@ bool taosCheckFileIsOpen(char *logFileName) { } } -void taosGetLogFileName(char *fn) { - if (taosLogFileNum > 1) { - for (int i = 0; i < taosLogFileNum; i++) { +static void taosGetLogFileName(char *fn) { + if (tsLogObj.fileNum > 1) { + for (int32_t i = 0; i < tsLogObj.fileNum; i++) { char fileName[LOG_FILE_NAME_LEN]; sprintf(fileName, "%s%d.0", fn, i); @@ -227,16 +224,16 @@ void taosGetLogFileName(char *fn) { bool file2open = taosCheckFileIsOpen(fileName); if (!file1open && !file2open) { - sprintf(taosLogName, "%s%d", fn, i); + sprintf(tsLogObj.logName, "%s%d", fn, i); return; } } } - strcpy(taosLogName, fn); + strcpy(tsLogObj.logName, fn); } -int taosOpenLogFileWithMaxLines(char *fn, int maxLines, int maxFileNum) { +static int32_t taosOpenLogFile(char *fn, int32_t maxLines, int32_t maxFileNum) { #ifdef WINDOWS /* * always set maxFileNum to 1 @@ -245,12 +242,12 @@ int taosOpenLogFileWithMaxLines(char *fn, int maxLines, int maxFileNum) { maxFileNum = 1; #endif - char name[LOG_FILE_NAME_LEN] = "\0"; + char name[LOG_FILE_NAME_LEN + 50] = "\0"; struct stat logstat0, logstat1; - int size; + int32_t size; - taosLogMaxLines = maxLines; - taosLogFileNum = maxFileNum; + tsLogObj.maxLines = maxLines; + tsLogObj.fileNum = maxFileNum; taosGetLogFileName(fn); strcpy(name, fn); @@ -258,67 +255,48 @@ int taosOpenLogFileWithMaxLines(char *fn, int maxLines, int maxFileNum) { // if none of the log files exist, open 0, if both exists, open the old one if (stat(name, &logstat0) < 0) { - taosLogFlag = 0; + tsLogObj.flag = 0; } else { strcpy(name, fn); strcat(name, ".1"); if (stat(name, &logstat1) < 0) { - taosLogFlag = 1; + tsLogObj.flag = 1; } else { - taosLogFlag = (logstat0.st_mtime > logstat1.st_mtime) ? 0 : 1; + tsLogObj.flag = (logstat0.st_mtime > logstat1.st_mtime) ? 0 : 1; } } - sprintf(name, "%s.%d", taosLogName, taosLogFlag); - pthread_mutex_init(&logMutex, NULL); + sprintf(name, "%s.%d", tsLogObj.logName, tsLogObj.flag); + pthread_mutex_init(&tsLogObj.logMutex, NULL); umask(0); - logHandle->fd = open(name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); + tsLogObj.logHandle->fd = open(name, O_WRONLY | O_CREAT, S_IRWXU | S_IRWXG | S_IRWXO); - if (logHandle->fd < 0) { + if (tsLogObj.logHandle->fd < 0) { printf("\nfailed to open log file:%s, reason:%s\n", name, strerror(errno)); return -1; } - taosLockFile(logHandle->fd); + taosLockFile(tsLogObj.logHandle->fd); // only an estimate for number of lines struct stat filestat; - fstat(logHandle->fd, &filestat); - size = (int)filestat.st_size; - taosLogLines = size / 60; + fstat(tsLogObj.logHandle->fd, &filestat); + size = (int32_t)filestat.st_size; + tsLogObj.lines = size / 60; - lseek(logHandle->fd, 0, SEEK_END); + lseek(tsLogObj.logHandle->fd, 0, SEEK_END); sprintf(name, "==================================================\n"); - twrite(logHandle->fd, name, (uint32_t)strlen(name)); + twrite(tsLogObj.logHandle->fd, name, (uint32_t)strlen(name)); sprintf(name, " new log file \n"); - twrite(logHandle->fd, name, (uint32_t)strlen(name)); + twrite(tsLogObj.logHandle->fd, name, (uint32_t)strlen(name)); sprintf(name, "==================================================\n"); - twrite(logHandle->fd, name, (uint32_t)strlen(name)); + twrite(tsLogObj.logHandle->fd, name, (uint32_t)strlen(name)); return 0; } -char *tprefix(char *prefix) { - struct tm Tm, *ptm; - struct timeval timeSecs; - time_t curTime; - - gettimeofday(&timeSecs, NULL); - curTime = timeSecs.tv_sec; - ptm = localtime_r(&curTime, &Tm); - -#ifndef LINUX - sprintf(prefix, "%02d/%02d %02d:%02d:%02d.%06d 0x%lld ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, - ptm->tm_sec, (int)timeSecs.tv_usec, taosGetPthreadId()); -#else - sprintf(prefix, "%02d/%02d %02d:%02d:%02d.%06d %d 0x%lx ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, - ptm->tm_sec, (int)timeSecs.tv_usec, logPid, pthread_self()); -#endif - return prefix; -} - -void tprintf(const char *const flags, int dflag, const char *const format, ...) { +void taosPrintLog(const char *const flags, int32_t dflag, const char *const format, ...) { if (tsTotalLogDirGB != 0 && tsAvailLogDirGB < tsMinimalLogDirGB) { printf("server disk:%s space remain %.3f GB, total %.1f GB, stop print log.\n", logDir, tsAvailLogDirGB, tsTotalLogDirGB); fflush(stdout); @@ -327,7 +305,7 @@ void tprintf(const char *const flags, int dflag, const char *const format, ...) va_list argpointer; char buffer[MAX_LOGLINE_BUFFER_SIZE] = { 0 }; - int len; + int32_t len; struct tm Tm, *ptm; struct timeval timeSecs; time_t curTime; @@ -335,17 +313,13 @@ void tprintf(const char *const flags, int dflag, const char *const format, ...) gettimeofday(&timeSecs, NULL); curTime = timeSecs.tv_sec; ptm = localtime_r(&curTime, &Tm); -#ifndef LINUX - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%lld ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, - ptm->tm_min, ptm->tm_sec, (int)timeSecs.tv_usec, taosGetPthreadId()); -#else - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %d %lx ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, - ptm->tm_sec, (int)timeSecs.tv_usec, logPid, pthread_self()); -#endif + + len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, + ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetPthreadId()); len += sprintf(buffer + len, "%s", flags); va_start(argpointer, format); - int writeLen = vsnprintf(buffer + len, MAX_LOGLINE_CONTENT_SIZE, format, argpointer); + int32_t writeLen = vsnprintf(buffer + len, MAX_LOGLINE_CONTENT_SIZE, format, argpointer); if (writeLen <= 0) { char tmp[MAX_LOGLINE_DUMP_BUFFER_SIZE] = {0}; writeLen = vsnprintf(tmp, MAX_LOGLINE_DUMP_CONTENT_SIZE, format, argpointer); @@ -363,24 +337,24 @@ void tprintf(const char *const flags, int dflag, const char *const format, ...) buffer[len++] = '\n'; buffer[len] = 0; - if ((dflag & DEBUG_FILE) && logHandle && logHandle->fd >= 0) { + if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->fd >= 0) { if (tsAsyncLog) { - taosPushLogBuffer(logHandle, buffer, len); + taosPushLogBuffer(tsLogObj.logHandle, buffer, len); } else { - twrite(logHandle->fd, buffer, len); + twrite(tsLogObj.logHandle->fd, buffer, len); } - if (taosLogMaxLines > 0) { - atomic_add_fetch_32(&taosLogLines, 1); + if (tsLogObj.maxLines > 0) { + atomic_add_fetch_32(&tsLogObj.lines, 1); - if ((taosLogLines > taosLogMaxLines) && (openInProgress == 0)) taosOpenNewLogFile(); + if ((tsLogObj.lines > tsLogObj.maxLines) && (tsLogObj.openInProgress == 0)) taosOpenNewLogFile(); } } - if (dflag & DEBUG_SCREEN) twrite(1, buffer, (unsigned int)len); + if (dflag & DEBUG_SCREEN) twrite(1, buffer, (uint32_t)len); } -void taosDumpData(unsigned char *msg, int len) { +void taosDumpData(unsigned char *msg, int32_t len) { if (tsTotalLogDirGB != 0 && tsAvailLogDirGB < tsMinimalLogDirGB) { printf("server disk:%s space remain %.3f GB, total %.1f GB, stop dump log.\n", logDir, tsAvailLogDirGB, tsTotalLogDirGB); fflush(stdout); @@ -388,7 +362,7 @@ void taosDumpData(unsigned char *msg, int len) { } char temp[256]; - int i, pos = 0, c = 0; + int32_t i, pos = 0, c = 0; for (i = 0; i < len; ++i) { sprintf(temp + pos, "%02x ", msg[i]); @@ -396,7 +370,7 @@ void taosDumpData(unsigned char *msg, int len) { pos += 3; if (c >= 16) { temp[pos++] = '\n'; - twrite(logHandle->fd, temp, (unsigned int)pos); + twrite(tsLogObj.logHandle->fd, temp, (uint32_t)pos); c = 0; pos = 0; } @@ -404,12 +378,12 @@ void taosDumpData(unsigned char *msg, int len) { temp[pos++] = '\n'; - twrite(logHandle->fd, temp, (unsigned int)pos); + twrite(tsLogObj.logHandle->fd, temp, (uint32_t)pos); return; } -void taosPrintLongString(const char *const flags, int dflag, const char *const format, ...) { +void taosPrintLongString(const char *const flags, int32_t dflag, const char *const format, ...) { if (tsTotalLogDirGB != 0 && tsAvailLogDirGB < tsMinimalLogDirGB) { printf("server disk:%s space remain %.3f GB, total %.1f GB, stop write log.\n", logDir, tsAvailLogDirGB, tsTotalLogDirGB); fflush(stdout); @@ -418,7 +392,7 @@ void taosPrintLongString(const char *const flags, int dflag, const char *const f va_list argpointer; char buffer[MAX_LOGLINE_DUMP_BUFFER_SIZE]; - int len; + int32_t len; struct tm Tm, *ptm; struct timeval timeSecs; time_t curTime; @@ -426,13 +400,9 @@ void taosPrintLongString(const char *const flags, int dflag, const char *const f gettimeofday(&timeSecs, NULL); curTime = timeSecs.tv_sec; ptm = localtime_r(&curTime, &Tm); -#ifndef LINUX - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%lld ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, - ptm->tm_min, ptm->tm_sec, (int)timeSecs.tv_usec, taosGetPthreadId()); -#else - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %d %lx ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, ptm->tm_min, - ptm->tm_sec, (int)timeSecs.tv_usec, logPid, pthread_self()); -#endif + + len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d 0x%" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, + ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetPthreadId()); len += sprintf(buffer + len, "%s", flags); va_start(argpointer, format); @@ -444,35 +414,33 @@ void taosPrintLongString(const char *const flags, int dflag, const char *const f buffer[len++] = '\n'; buffer[len] = 0; - if ((dflag & DEBUG_FILE) && logHandle && logHandle->fd >= 0) { - taosPushLogBuffer(logHandle, buffer, len); + if ((dflag & DEBUG_FILE) && tsLogObj.logHandle && tsLogObj.logHandle->fd >= 0) { + taosPushLogBuffer(tsLogObj.logHandle, buffer, len); - if (taosLogMaxLines > 0) { - atomic_add_fetch_32(&taosLogLines, 1); + if (tsLogObj.maxLines > 0) { + atomic_add_fetch_32(&tsLogObj.lines, 1); - if ((taosLogLines > taosLogMaxLines) && (openInProgress == 0)) taosOpenNewLogFile(); + if ((tsLogObj.lines > tsLogObj.maxLines) && (tsLogObj.openInProgress == 0)) taosOpenNewLogFile(); } } - if (dflag & DEBUG_SCREEN) twrite(1, buffer, (unsigned int)len); + if (dflag & DEBUG_SCREEN) twrite(1, buffer, (uint32_t)len); } -void taosCloseLog() { taosCloseLogByFd(logHandle->fd); } +#if 0 +void taosCloseLog() { + taosCloseLogByFd(tsLogObj.logHandle->fd); +} +#endif -void taosCloseLogByFd(int fd) { +static void taosCloseLogByFd(int32_t fd) { if (fd >= 0) { taosUnLockFile(fd); tclose(fd); } } -#define LOG_BUF_BUFFER(x) ((x)->buffer) -#define LOG_BUF_START(x) ((x)->buffStart) -#define LOG_BUF_END(x) ((x)->buffEnd) -#define LOG_BUF_SIZE(x) ((x)->buffSize) -#define LOG_BUF_MUTEX(x) ((x)->buffMutex) - -SLogBuff *taosLogBuffNew(int bufSize) { +static SLogBuff *taosLogBuffNew(int32_t bufSize) { SLogBuff *tLogBuff = NULL; if (bufSize < TSDB_MIN_LOG_BUF_SIZE || bufSize > TSDB_MAX_LOG_BUF_SIZE) return NULL; @@ -498,17 +466,19 @@ _err: return NULL; } -void taosLogBuffDestroy(SLogBuff *tLogBuff) { +#if 0 +static void taosLogBuffDestroy(SLogBuff *tLogBuff) { tsem_destroy(&(tLogBuff->buffNotEmpty)); pthread_mutex_destroy(&(tLogBuff->buffMutex)); free(tLogBuff->buffer); tfree(tLogBuff); } +#endif -int taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int msgLen) { - int start = 0; - int end = 0; - int remainSize = 0; +static int32_t taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int32_t msgLen) { + int32_t start = 0; + int32_t end = 0; + int32_t remainSize = 0; if (tLogBuff == NULL || tLogBuff->stop) return -1; @@ -544,10 +514,10 @@ int taosPushLogBuffer(SLogBuff *tLogBuff, char *msg, int msgLen) { return 0; } -int taosPollLogBuffer(SLogBuff *tLogBuff, char *buf, int bufSize) { - int start = LOG_BUF_START(tLogBuff); - int end = LOG_BUF_END(tLogBuff); - int pollSize = 0; +static int32_t taosPollLogBuffer(SLogBuff *tLogBuff, char *buf, int32_t bufSize) { + int32_t start = LOG_BUF_START(tLogBuff); + int32_t end = LOG_BUF_END(tLogBuff); + int32_t pollSize = 0; if (start == end) { return 0; @@ -559,7 +529,7 @@ int taosPollLogBuffer(SLogBuff *tLogBuff, char *buf, int bufSize) { } else { pollSize = MIN(end + LOG_BUF_SIZE(tLogBuff) - start, bufSize); if (pollSize > LOG_BUF_SIZE(tLogBuff) - start) { - int tsize = LOG_BUF_SIZE(tLogBuff) - start; + int32_t tsize = LOG_BUF_SIZE(tLogBuff) - start; memcpy(buf, LOG_BUF_BUFFER(tLogBuff) + start, tsize); memcpy(buf + tsize, LOG_BUF_BUFFER(tLogBuff), pollSize - tsize); @@ -570,9 +540,9 @@ int taosPollLogBuffer(SLogBuff *tLogBuff, char *buf, int bufSize) { } } -void *taosAsyncOutputLog(void *param) { +static void *taosAsyncOutputLog(void *param) { SLogBuff *tLogBuff = (SLogBuff *)param; - int log_size = 0; + int32_t log_size = 0; char tempBuffer[TSDB_DEFAULT_LOG_BUF_UNIT]; diff --git a/src/util/src/tmem.c b/src/util/src/tmem.c index 2625e4e5e6..38d930ac4e 100644 --- a/src/util/src/tmem.c +++ b/src/util/src/tmem.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "tlog.h" +#include "tulog.h" #define TAOS_MEM_CHECK_IMPL #include "tutil.h" diff --git a/src/util/src/tmempool.c b/src/util/src/tmempool.c index f2cf31783c..5fe00c87a2 100644 --- a/src/util/src/tmempool.c +++ b/src/util/src/tmempool.c @@ -18,7 +18,7 @@ #include #include -#include "tlog.h" +#include "tulog.h" #include "tmempool.h" #include "tutil.h" @@ -37,13 +37,13 @@ mpool_h taosMemPoolInit(int numOfBlock, int blockSize) { pool_t *pool_p; if (numOfBlock <= 1 || blockSize <= 1) { - pError("invalid parameter in memPoolInit\n"); + uError("invalid parameter in memPoolInit\n"); return NULL; } pool_p = (pool_t *)malloc(sizeof(pool_t)); if (pool_p == NULL) { - pError("mempool malloc failed\n"); + uError("mempool malloc failed\n"); return NULL; } else { memset(pool_p, 0, sizeof(pool_t)); @@ -55,7 +55,7 @@ mpool_h taosMemPoolInit(int numOfBlock, int blockSize) { pool_p->freeList = (int *)malloc(sizeof(int) * (size_t)numOfBlock); if (pool_p->pool == NULL || pool_p->freeList == NULL) { - pError("failed to allocate memory\n"); + uError("failed to allocate memory\n"); tfree(pool_p->freeList); tfree(pool_p->pool); tfree(pool_p); @@ -88,7 +88,7 @@ char *taosMemPoolMalloc(mpool_h handle) { pthread_mutex_unlock(&(pool_p->mutex)); - if (pos == NULL) pTrace("mempool: out of memory"); + if (pos == NULL) uTrace("mempool: out of memory"); return pos; } @@ -100,13 +100,13 @@ void taosMemPoolFree(mpool_h handle, char *pMem) { index = (int)(pMem - pool_p->pool) % pool_p->blockSize; if (index != 0) { - pError("invalid free address:%p\n", pMem); + uError("invalid free address:%p\n", pMem); return; } index = (int)((pMem - pool_p->pool) / pool_p->blockSize); if (index < 0 || index >= pool_p->numOfBlock) { - pError("mempool: error, invalid address:%p\n", pMem); + uError("mempool: error, invalid address:%p\n", pMem); return; } diff --git a/src/util/src/tqueue.c b/src/util/src/tqueue.c index b9f1141d35..c639452823 100644 --- a/src/util/src/tqueue.c +++ b/src/util/src/tqueue.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "tlog.h" +#include "tulog.h" #include "taoserror.h" #include "tqueue.h" @@ -92,7 +92,7 @@ void *taosAllocateQitem(int size) { void taosFreeQitem(void *param) { if (param == NULL) return; - pTrace("item:%p is freed", param); + uTrace("item:%p is freed", param); char *temp = (char *)param; temp -= sizeof(STaosQnode); @@ -117,7 +117,7 @@ int taosWriteQitem(taos_queue param, int type, void *item) { queue->numOfItems++; if (queue->qset) atomic_add_fetch_32(&queue->qset->numOfItems, 1); - pTrace("item:%p is put into queue:%p, type:%d items:%d", item, queue, type, queue->numOfItems); + uTrace("item:%p is put into queue:%p, type:%d items:%d", item, queue, type, queue->numOfItems); pthread_mutex_unlock(&queue->mutex); @@ -141,7 +141,7 @@ int taosReadQitem(taos_queue param, int *type, void **pitem) { queue->numOfItems--; if (queue->qset) atomic_sub_fetch_32(&queue->qset->numOfItems, 1); code = 1; - //pTrace("item:%p is read out from queue, items:%d", *pitem, queue->numOfItems); + //uTrace("item:%p is read out from queue, items:%d", *pitem, queue->numOfItems); } pthread_mutex_unlock(&queue->mutex); @@ -197,7 +197,7 @@ int taosGetQitem(taos_qall param, int *type, void **pitem) { *pitem = pNode->item; *type = pNode->type; num = 1; - pTrace("item:%p is fetched, type:%d", *pitem, *type); + uTrace("item:%p is fetched, type:%d", *pitem, *type); } return num; diff --git a/src/util/src/tsched.c b/src/util/src/tsched.c index 8608b64057..39d8816310 100644 --- a/src/util/src/tsched.c +++ b/src/util/src/tsched.c @@ -14,7 +14,7 @@ */ #include "os.h" -#include "tlog.h" +#include "tulog.h" #include "tsched.h" #include "ttimer.h" @@ -42,20 +42,20 @@ static void taosDumpSchedulerStatus(void *qhandle, void *tmrId); void *taosInitScheduler(int queueSize, int numOfThreads, const char *label) { SSchedQueue *pSched = (SSchedQueue *)calloc(sizeof(SSchedQueue), 1); if (pSched == NULL) { - pError("%s: no enough memory for pSched", label); + uError("%s: no enough memory for pSched", label); return NULL; } pSched->queue = (SSchedMsg *)calloc(sizeof(SSchedMsg), queueSize); if (pSched->queue == NULL) { - pError("%s: no enough memory for queue", label); + uError("%s: no enough memory for queue", label); taosCleanUpScheduler(pSched); return NULL; } pSched->qthread = calloc(sizeof(pthread_t), numOfThreads); if (pSched->qthread == NULL) { - pError("%s: no enough memory for qthread", label); + uError("%s: no enough memory for qthread", label); taosCleanUpScheduler(pSched); return NULL; } @@ -68,19 +68,19 @@ void *taosInitScheduler(int queueSize, int numOfThreads, const char *label) { pSched->emptySlot = 0; if (pthread_mutex_init(&pSched->queueMutex, NULL) < 0) { - pError("init %s:queueMutex failed(%s)", label, strerror(errno)); + uError("init %s:queueMutex failed(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); return NULL; } if (tsem_init(&pSched->emptySem, 0, (unsigned int)pSched->queueSize) != 0) { - pError("init %s:empty semaphore failed(%s)", label, strerror(errno)); + uError("init %s:empty semaphore failed(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); return NULL; } if (tsem_init(&pSched->fullSem, 0, 0) != 0) { - pError("init %s:full semaphore failed(%s)", label, strerror(errno)); + uError("init %s:full semaphore failed(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); return NULL; } @@ -92,14 +92,14 @@ void *taosInitScheduler(int queueSize, int numOfThreads, const char *label) { int code = pthread_create(pSched->qthread + i, &attr, taosProcessSchedQueue, (void *)pSched); pthread_attr_destroy(&attr); if (code != 0) { - pError("%s: failed to create rpc thread(%s)", label, strerror(errno)); + uError("%s: failed to create rpc thread(%s)", label, strerror(errno)); taosCleanUpScheduler(pSched); return NULL; } ++pSched->numOfThreads; } - pTrace("%s scheduler is initialized, numOfThreads:%d", label, pSched->numOfThreads); + uTrace("%s scheduler is initialized, numOfThreads:%d", label, pSched->numOfThreads); return (void *)pSched; } @@ -123,24 +123,24 @@ void *taosProcessSchedQueue(void *param) { if (tsem_wait(&pSched->fullSem) != 0) { if (errno == EINTR) { /* sem_wait is interrupted by interrupt, ignore and continue */ - pTrace("wait %s fullSem was interrupted", pSched->label); + uTrace("wait %s fullSem was interrupted", pSched->label); continue; } - pError("wait %s fullSem failed(%s)", pSched->label, strerror(errno)); + uError("wait %s fullSem failed(%s)", pSched->label, strerror(errno)); } if (pthread_mutex_lock(&pSched->queueMutex) != 0) - pError("lock %s queueMutex failed(%s)", pSched->label, strerror(errno)); + uError("lock %s queueMutex failed(%s)", pSched->label, strerror(errno)); msg = pSched->queue[pSched->fullSlot]; memset(pSched->queue + pSched->fullSlot, 0, sizeof(SSchedMsg)); pSched->fullSlot = (pSched->fullSlot + 1) % pSched->queueSize; if (pthread_mutex_unlock(&pSched->queueMutex) != 0) - pError("unlock %s queueMutex failed(%s)", pSched->label, strerror(errno)); + uError("unlock %s queueMutex failed(%s)", pSched->label, strerror(errno)); if (tsem_post(&pSched->emptySem) != 0) - pError("post %s emptySem failed(%s)", pSched->label, strerror(errno)); + uError("post %s emptySem failed(%s)", pSched->label, strerror(errno)); if (msg.fp) (*(msg.fp))(&msg); @@ -154,29 +154,29 @@ void *taosProcessSchedQueue(void *param) { int taosScheduleTask(void *qhandle, SSchedMsg *pMsg) { SSchedQueue *pSched = (SSchedQueue *)qhandle; if (pSched == NULL) { - pError("sched is not ready, msg:%p is dropped", pMsg); + uError("sched is not ready, msg:%p is dropped", pMsg); return 0; } while (tsem_wait(&pSched->emptySem) != 0) { if (errno != EINTR) { - pError("wait %s emptySem failed(%s)", pSched->label, strerror(errno)); + uError("wait %s emptySem failed(%s)", pSched->label, strerror(errno)); break; } - pTrace("wait %s emptySem was interrupted", pSched->label); + uTrace("wait %s emptySem was interrupted", pSched->label); } if (pthread_mutex_lock(&pSched->queueMutex) != 0) - pError("lock %s queueMutex failed(%s)", pSched->label, strerror(errno)); + uError("lock %s queueMutex failed(%s)", pSched->label, strerror(errno)); pSched->queue[pSched->emptySlot] = *pMsg; pSched->emptySlot = (pSched->emptySlot + 1) % pSched->queueSize; if (pthread_mutex_unlock(&pSched->queueMutex) != 0) - pError("unlock %s queueMutex failed(%s)", pSched->label, strerror(errno)); + uError("unlock %s queueMutex failed(%s)", pSched->label, strerror(errno)); if (tsem_post(&pSched->fullSem) != 0) - pError("post %s fullSem failed(%s)", pSched->label, strerror(errno)); + uError("post %s fullSem failed(%s)", pSched->label, strerror(errno)); return 0; } @@ -216,7 +216,7 @@ void taosDumpSchedulerStatus(void *qhandle, void *tmrId) { int32_t size = ((pSched->emptySlot - pSched->fullSlot) + pSched->queueSize) % pSched->queueSize; if (size > 0) { - pTrace("scheduler:%s, current tasks in queue:%d, task thread:%d", pSched->label, size, pSched->numOfThreads); + uTrace("scheduler:%s, current tasks in queue:%d, task thread:%d", pSched->label, size, pSched->numOfThreads); } taosTmrReset(taosDumpSchedulerStatus, DUMP_SCHEDULER_TIME_WINDOW, pSched, pSched->pTmrCtrl, &pSched->pTimer); diff --git a/src/util/src/tskiplist.c b/src/util/src/tskiplist.c index 2add3ad849..ee09013099 100644 --- a/src/util/src/tskiplist.c +++ b/src/util/src/tskiplist.c @@ -13,8 +13,7 @@ * along with this program. If not, see . */ #include "os.h" - -#include "tlog.h" +#include "tulog.h" #include "tskiplist.h" #include "tutil.h" #include "tcompare.h" diff --git a/src/util/src/tsocket.c b/src/util/src/tsocket.c index 86be428af7..4d3687e50d 100644 --- a/src/util/src/tsocket.c +++ b/src/util/src/tsocket.c @@ -14,8 +14,8 @@ */ #include "os.h" -#include "tglobalcfg.h" -#include "tlog.h" +#include "tglobal.h" +#include "tulog.h" #include "tsocket.h" #include "tutil.h" @@ -194,13 +194,13 @@ int taosNonblockwrite(int fd, char *ptr, int nbytes) { FD_SET(fd, &fset); if ((nready = select(fd + 1, NULL, &fset, NULL, &tv)) == 0) { errno = ETIMEDOUT; - pError("fd %d timeout, no enough space to write", fd); + uError("fd %d timeout, no enough space to write", fd); break; } else if (nready < 0) { if (errno == EINTR) continue; - pError("select error, %d (%s)", errno, strerror(errno)); + uError("select error, %d (%s)", errno, strerror(errno)); return -1; } @@ -208,7 +208,7 @@ int taosNonblockwrite(int fd, char *ptr, int nbytes) { if (nwritten <= 0) { if (errno == EAGAIN || errno == EINTR) continue; - pError("write error, %d (%s)", errno, strerror(errno)); + uError("write error, %d (%s)", errno, strerror(errno)); return -1; } @@ -234,21 +234,21 @@ int taosReadn(int fd, char *ptr, int nbytes) { FD_SET(fd, &fset); if ((nready = select(fd + 1, NULL, &fset, NULL, &tv)) == 0) { errno = ETIMEDOUT; - pError("fd %d timeout\n", fd); + uError("fd %d timeout\n", fd); break; } else if (nready < 0) { if (errno == EINTR) continue; - pError("select error, %d (%s)", errno, strerror(errno)); + uError("select error, %d (%s)", errno, strerror(errno)); return -1; } if ((nread = (int)taosReadSocket(fd, ptr, (size_t)nleft)) < 0) { if (errno == EINTR) continue; - pError("read error, %d (%s)", errno, strerror(errno)); + uError("read error, %d (%s)", errno, strerror(errno)); return -1; } else if (nread == 0) { - pError("fd %d EOF", fd); + uError("fd %d EOF", fd); break; // EOF } @@ -266,7 +266,7 @@ int taosOpenUdpSocket(char *ip, uint16_t port) { int reuse, nocheck; int bufSize = 8192000; - pTrace("open udp socket:%s:%hu", ip, port); + uTrace("open udp socket:%s:%hu", ip, port); memset((char *)&localAddr, 0, sizeof(localAddr)); localAddr.sin_family = AF_INET; @@ -274,13 +274,13 @@ int taosOpenUdpSocket(char *ip, uint16_t port) { localAddr.sin_port = (uint16_t)htons(port); if ((sockFd = (int)socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - pError("failed to open udp socket: %d (%s)", errno, strerror(errno)); + uError("failed to open udp socket: %d (%s)", errno, strerror(errno)); return -1; } reuse = 1; if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { - pError("setsockopt SO_REUSEADDR failed): %d (%s)", errno, strerror(errno)); + uError("setsockopt SO_REUSEADDR failed): %d (%s)", errno, strerror(errno)); close(sockFd); return -1; }; @@ -288,36 +288,36 @@ int taosOpenUdpSocket(char *ip, uint16_t port) { nocheck = 1; if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_NO_CHECK, (void *)&nocheck, sizeof(nocheck)) < 0) { if (!taosSkipSocketCheck()) { - pError("setsockopt SO_NO_CHECK failed: %d (%s)", errno, strerror(errno)); + uError("setsockopt SO_NO_CHECK failed: %d (%s)", errno, strerror(errno)); close(sockFd); return -1; } else { - pPrint("Skipping setsockopt SO_NO_CHECK error: %d (%s)", errno, strerror(errno)); + uPrint("Skipping setsockopt SO_NO_CHECK error: %d (%s)", errno, strerror(errno)); } } ttl = 128; if (taosSetSockOpt(sockFd, IPPROTO_IP, IP_TTL, (void *)&ttl, sizeof(ttl)) < 0) { - pError("setsockopt IP_TTL failed: %d (%s)", errno, strerror(errno)); + uError("setsockopt IP_TTL failed: %d (%s)", errno, strerror(errno)); close(sockFd); return -1; } if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_SNDBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { - pError("failed to set the send buffer size for UDP socket\n"); + uError("failed to set the send buffer size for UDP socket\n"); close(sockFd); return -1; } if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_RCVBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { - pError("failed to set the receive buffer size for UDP socket\n"); + uError("failed to set the receive buffer size for UDP socket\n"); close(sockFd); return -1; } /* bind socket to local address */ if (bind(sockFd, (struct sockaddr *)&localAddr, sizeof(localAddr)) < 0) { - pError("failed to bind udp socket: %d (%s), %s:%hu", errno, strerror(errno), ip, port); + uError("failed to bind udp socket: %d (%s), %s:%hu", errno, strerror(errno), ip, port); taosCloseSocket(sockFd); return -1; } @@ -330,12 +330,12 @@ int taosOpenTcpClientSocket(char *destIp, uint16_t destPort, char *clientIp) { struct sockaddr_in serverAddr, clientAddr; int ret; - // pTrace("open tcp client socket:%s:%d, local Ip:%s", destIp, destPort, clientIp); + // uTrace("open tcp client socket:%s:%d, local Ip:%s", destIp, destPort, clientIp); sockFd = (int)socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sockFd < 0) { - pError("failed to open the socket: %d (%s)", errno, strerror(errno)); + uError("failed to open the socket: %d (%s)", errno, strerror(errno)); return -1; } @@ -347,7 +347,7 @@ int taosOpenTcpClientSocket(char *destIp, uint16_t destPort, char *clientIp) { /* bind socket to client address */ if (bind(sockFd, (struct sockaddr *)&clientAddr, sizeof(clientAddr)) < 0) { - pError("bind tcp client socket failed, client(%s:0), dest(%s:%d), reason:%d(%s)", + uError("bind tcp client socket failed, client(%s:0), dest(%s:%d), reason:%d(%s)", clientIp, destIp, destPort, errno, strerror(errno)); close(sockFd); return -1; @@ -362,7 +362,7 @@ int taosOpenTcpClientSocket(char *destIp, uint16_t destPort, char *clientIp) { ret = connect(sockFd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); if (ret != 0) { - //pError("failed to connect socket, ip:%s, port:%hu, reason: %s", destIp, destPort, strerror(errno)); + //uError("failed to connect socket, ip:%s, port:%hu, reason: %s", destIp, destPort, strerror(errno)); taosCloseSocket(sockFd); sockFd = -1; } @@ -375,7 +375,7 @@ void taosCloseTcpSocket(int sockFd) { linger.l_onoff = 1; linger.l_linger = 0; if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger)) < 0) { - pError("setsockopt SO_LINGER failed: %d (%s)", errno, strerror(errno)); + uError("setsockopt SO_LINGER failed: %d (%s)", errno, strerror(errno)); } taosCloseSocket(sockFd); @@ -384,35 +384,35 @@ void taosCloseTcpSocket(int sockFd) { int taosKeepTcpAlive(int sockFd) { int alive = 1; if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_KEEPALIVE, (void *)&alive, sizeof(alive)) < 0) { - pError("fd:%d setsockopt SO_KEEPALIVE failed: %d (%s)", sockFd, errno, strerror(errno)); + uError("fd:%d setsockopt SO_KEEPALIVE failed: %d (%s)", sockFd, errno, strerror(errno)); close(sockFd); return -1; } int probes = 3; if (taosSetSockOpt(sockFd, SOL_TCP, TCP_KEEPCNT, (void *)&probes, sizeof(probes)) < 0) { - pError("fd:%d setsockopt SO_KEEPCNT failed: %d (%s)", sockFd, errno, strerror(errno)); + uError("fd:%d setsockopt SO_KEEPCNT failed: %d (%s)", sockFd, errno, strerror(errno)); close(sockFd); return -1; } int alivetime = 10; if (taosSetSockOpt(sockFd, SOL_TCP, TCP_KEEPIDLE, (void *)&alivetime, sizeof(alivetime)) < 0) { - pError("fd:%d setsockopt SO_KEEPIDLE failed: %d (%s)", sockFd, errno, strerror(errno)); + uError("fd:%d setsockopt SO_KEEPIDLE failed: %d (%s)", sockFd, errno, strerror(errno)); close(sockFd); return -1; } int interval = 3; if (taosSetSockOpt(sockFd, SOL_TCP, TCP_KEEPINTVL, (void *)&interval, sizeof(interval)) < 0) { - pError("fd:%d setsockopt SO_KEEPINTVL failed: %d (%s)", sockFd, errno, strerror(errno)); + uError("fd:%d setsockopt SO_KEEPINTVL failed: %d (%s)", sockFd, errno, strerror(errno)); close(sockFd); return -1; } int nodelay = 1; if (taosSetSockOpt(sockFd, IPPROTO_TCP, TCP_NODELAY, (void *)&nodelay, sizeof(nodelay)) < 0) { - pError("fd:%d setsockopt TCP_NODELAY failed %d (%s)", sockFd, errno, strerror(errno)); + uError("fd:%d setsockopt TCP_NODELAY failed %d (%s)", sockFd, errno, strerror(errno)); close(sockFd); return -1; } @@ -425,7 +425,7 @@ int taosOpenTcpServerSocket(char *ip, uint16_t port) { int sockFd; int reuse; - pTrace("open tcp server socket:%s:%hu", ip, port); + uTrace("open tcp server socket:%s:%hu", ip, port); bzero((char *)&serverAdd, sizeof(serverAdd)); serverAdd.sin_family = AF_INET; @@ -433,21 +433,21 @@ int taosOpenTcpServerSocket(char *ip, uint16_t port) { serverAdd.sin_port = (uint16_t)htons(port); if ((sockFd = (int)socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { - pError("failed to open TCP socket: %d (%s)", errno, strerror(errno)); + uError("failed to open TCP socket: %d (%s)", errno, strerror(errno)); return -1; } /* set REUSEADDR option, so the portnumber can be re-used */ reuse = 1; if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { - pError("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); + uError("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); close(sockFd); return -1; }; /* bind socket to server address */ if (bind(sockFd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)) < 0) { - pError("bind tcp server socket failed, %s:%hu, reason:%d(%s)", ip, port, errno, strerror(errno)); + uError("bind tcp server socket failed, %s:%hu, reason:%d(%s)", ip, port, errno, strerror(errno)); close(sockFd); return -1; } @@ -455,7 +455,7 @@ int taosOpenTcpServerSocket(char *ip, uint16_t port) { if (taosKeepTcpAlive(sockFd) < 0) return -1; if (listen(sockFd, 10) < 0) { - pError("listen tcp server socket failed, %s:%hu, reason:%d(%s)", ip, port, errno, strerror(errno)); + uError("listen tcp server socket failed, %s:%hu, reason:%d(%s)", ip, port, errno, strerror(errno)); return -1; } @@ -466,17 +466,17 @@ int taosOpenRawSocket(char *ip) { int fd, hold; struct sockaddr_in rawAdd; - pTrace("open udp raw socket:%s", ip); + uTrace("open udp raw socket:%s", ip); fd = (int)socket(AF_INET, SOCK_RAW, IPPROTO_UDP); if (fd < 0) { - pError("failed to open raw socket: %d (%s)", errno, strerror(errno)); + uError("failed to open raw socket: %d (%s)", errno, strerror(errno)); return -1; } hold = 1; if (taosSetSockOpt(fd, IPPROTO_IP, IP_HDRINCL, (void *)&hold, sizeof(hold)) < 0) { - pError("failed to set hold option: %d (%s)", errno, strerror(errno)); + uError("failed to set hold option: %d (%s)", errno, strerror(errno)); close(fd); return -1; } @@ -486,7 +486,7 @@ int taosOpenRawSocket(char *ip) { rawAdd.sin_addr.s_addr = inet_addr(ip); if (bind(fd, (struct sockaddr *)&rawAdd, sizeof(rawAdd)) < 0) { - pError("failed to bind RAW socket: %d (%s)", errno, strerror(errno)); + uError("failed to bind RAW socket: %d (%s)", errno, strerror(errno)); close(fd); return -1; } @@ -516,7 +516,7 @@ int taosCopyFds(int sfd, int dfd, int64_t len) { int retLen = taosReadMsg(sfd, temp, (int)readLen); if (readLen != retLen) { - pError("read error, readLen:%d retLen:%d len:%" PRId64 " leftLen:%" PRId64 ", reason:%s", readLen, retLen, len, leftLen, + uError("read error, readLen:%d retLen:%d len:%" PRId64 " leftLen:%" PRId64 ", reason:%s", readLen, retLen, len, leftLen, strerror(errno)); return -1; } @@ -524,7 +524,7 @@ int taosCopyFds(int sfd, int dfd, int64_t len) { writeLen = taosWriteMsg(dfd, temp, readLen); if (readLen != writeLen) { - pError("copy error, readLen:%d writeLen:%d len:%" PRId64 " leftLen:%" PRId64 ", reason:%s", readLen, writeLen, len, leftLen, + uError("copy error, readLen:%d writeLen:%d len:%" PRId64 " leftLen:%" PRId64 ", reason:%s", readLen, writeLen, len, leftLen, strerror(errno)); return -1; } diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index 25862fbec3..42fd13b2cd 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -20,6 +20,20 @@ #include "ttimer.h" #include "tutil.h" +#define tmrError(...) \ + do { if (tmrDebugFlag & DEBUG_ERROR) { \ + taosPrintLog("ERROR TMR ", tmrDebugFlag, __VA_ARGS__); \ + } } while(0) + +#define tmrWarn(...) \ + do { if (tmrDebugFlag & DEBUG_WARN) { \ + taosPrintLog("WARN TMR ", tmrDebugFlag, __VA_ARGS__); \ + } } while(0) + +#define tmrTrace(...) \ + do { if (tmrDebugFlag & DEBUG_TRACE) { \ + taosPrintLog("TMR ", tmrDebugFlag, __VA_ARGS__); \ + } } while(0) #define TIMER_STATE_WAITING 0 #define TIMER_STATE_EXPIRED 1 @@ -75,7 +89,7 @@ typedef struct time_wheel_t { tmr_obj_t** slots; } time_wheel_t; -uint32_t tmrDebugFlag = DEBUG_ERROR | DEBUG_WARN | DEBUG_FILE; +int32_t tmrDebugFlag = 131; uint32_t taosMaxTmrCtrl = 512; static pthread_once_t tmrModuleInit = PTHREAD_ONCE_INIT; @@ -86,7 +100,6 @@ static void* tmrQhandle; static int numOfTmrCtrl = 0; int taosTmrThreads = 1; - static uintptr_t nextTimerId = 0; static time_wheel_t wheels[] = { diff --git a/src/util/src/tutil.c b/src/util/src/tutil.c index 1c55ab9457..3d91020365 100644 --- a/src/util/src/tutil.c +++ b/src/util/src/tutil.c @@ -20,11 +20,11 @@ #endif #include "tcrc32c.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "ttime.h" #include "taosdef.h" #include "tutil.h" -#include "tlog.h" +#include "tulog.h" #include "taoserror.h" int32_t tmpFileSerialNum = 0; @@ -559,18 +559,18 @@ int taosCheckVersion(char *input_client_version, char *input_server_version, int strcpy(server_version, input_server_version); if (!taosGetVersionNumber(client_version, clientVersionNumber)) { - pError("invalid client version:%s", client_version); + uError("invalid client version:%s", client_version); return TSDB_CODE_INVALID_CLIENT_VERSION; } if (!taosGetVersionNumber(server_version, serverVersionNumber)) { - pError("invalid server version:%s", server_version); + uError("invalid server version:%s", server_version); return TSDB_CODE_INVALID_CLIENT_VERSION; } for(int32_t i = 0; i < comparedSegments; ++i) { if (clientVersionNumber[i] != serverVersionNumber[i]) { - tscError("the %d-th number of server version:%s not matched with client version:%s", i, server_version, version); + uError("the %d-th number of server version:%s not matched with client version:%s", i, server_version, version); return TSDB_CODE_INVALID_CLIENT_VERSION; } } diff --git a/src/vnode/inc/vnodeLog.h b/src/vnode/inc/vnodeLog.h new file mode 100644 index 0000000000..5650321fdb --- /dev/null +++ b/src/vnode/inc/vnodeLog.h @@ -0,0 +1,50 @@ +/* + * 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_VNODE_LOG_H +#define TDENGINE_VNODE_LOG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "tlog.h" + +extern int32_t ddebugFlag; + +#define dError(...) \ + if (ddebugFlag & DEBUG_ERROR) { \ + taosPrintLog("ERROR DND ", 255, __VA_ARGS__); \ + } +#define dWarn(...) \ + if (ddebugFlag & DEBUG_WARN) { \ + taosPrintLog("WARN DND ", ddebugFlag, __VA_ARGS__); \ + } +#define dTrace(...) \ + if (ddebugFlag & DEBUG_TRACE) { \ + taosPrintLog("DND ", ddebugFlag, __VA_ARGS__); \ + } +#define dPrint(...) \ + { taosPrintLog("DND ", 255, __VA_ARGS__); } + +#define dLError(...) taosLogError(__VA_ARGS__) dError(__VA_ARGS__) +#define dLWarn(...) taosLogWarn(__VA_ARGS__) dWarn(__VA_ARGS__) +#define dLPrint(...) taosLogPrint(__VA_ARGS__) dPrint(__VA_ARGS__) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 472567784f..e007953a36 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -18,15 +18,16 @@ #include "ihash.h" #include "taoserror.h" #include "taosmsg.h" -#include "tlog.h" #include "trpc.h" #include "tsdb.h" #include "ttime.h" #include "ttimer.h" #include "twal.h" +#include "tglobal.h" #include "dnode.h" #include "vnode.h" #include "vnodeInt.h" +#include "vnodeLog.h" static int32_t tsOpennedVnodes; static void *tsDnodeVnodesHash; diff --git a/src/vnode/src/vnodeRead.c b/src/vnode/src/vnodeRead.c index 94ec707c2e..201214ded4 100644 --- a/src/vnode/src/vnodeRead.c +++ b/src/vnode/src/vnodeRead.c @@ -17,14 +17,14 @@ #include "os.h" #include "taosmsg.h" #include "taoserror.h" -#include "tlog.h" #include "tqueue.h" #include "trpc.h" #include "tsdb.h" #include "twal.h" -#include "dataformat.h" +#include "tdataformat.h" #include "vnode.h" #include "vnodeInt.h" +#include "vnodeLog.h" #include "query.h" static int32_t (*vnodeProcessReadMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *, void *pCont, int32_t contLen, SRspRet *pRet); diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index a47624b94f..81cba7b6fa 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -17,15 +17,15 @@ #include "os.h" #include "taosmsg.h" #include "taoserror.h" -#include "tlog.h" #include "tqueue.h" #include "trpc.h" +#include "tutil.h" #include "tsdb.h" #include "twal.h" -#include "dataformat.h" +#include "tdataformat.h" #include "vnode.h" #include "vnodeInt.h" -#include "tutil.h" +#include "vnodeLog.h" static int32_t (*vnodeProcessWriteMsgFp[TSDB_MSG_TYPE_MAX])(SVnodeObj *, void *, SRspRet *); static int32_t vnodeProcessSubmitMsg(SVnodeObj *pVnode, void *pMsg, SRspRet *); diff --git a/src/wal/CMakeLists.txt b/src/wal/CMakeLists.txt index d77a235bb9..684616ba0e 100644 --- a/src/wal/CMakeLists.txt +++ b/src/wal/CMakeLists.txt @@ -9,7 +9,7 @@ INCLUDE_DIRECTORIES(inc) AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/src SRC) ADD_LIBRARY(twal ${SRC}) -TARGET_LINK_LIBRARIES(twal tutil) +TARGET_LINK_LIBRARIES(twal tutil common) ADD_SUBDIRECTORY(test) diff --git a/src/wal/src/walMain.c b/src/wal/src/walMain.c index 6a9e3e0b9d..6a4ecee1c3 100644 --- a/src/wal/src/walMain.c +++ b/src/wal/src/walMain.c @@ -29,10 +29,10 @@ #include "tqueue.h" #define walPrefix "wal" -#define wError(...) if (wDebugFlag & DEBUG_ERROR) {tprintf("ERROR WAL ", wDebugFlag, __VA_ARGS__);} -#define wWarn(...) if (wDebugFlag & DEBUG_WARN) {tprintf("WARN WAL ", wDebugFlag, __VA_ARGS__);} -#define wTrace(...) if (wDebugFlag & DEBUG_TRACE) {tprintf("WAL ", wDebugFlag, __VA_ARGS__);} -#define wPrint(...) {tprintf("WAL ", 255, __VA_ARGS__);} +#define wError(...) if (wDebugFlag & DEBUG_ERROR) {taosPrintLog("ERROR WAL ", wDebugFlag, __VA_ARGS__);} +#define wWarn(...) if (wDebugFlag & DEBUG_WARN) {taosPrintLog("WARN WAL ", wDebugFlag, __VA_ARGS__);} +#define wTrace(...) if (wDebugFlag & DEBUG_TRACE) {taosPrintLog("WAL ", wDebugFlag, __VA_ARGS__);} +#define wPrint(...) {taosPrintLog("WAL ", 255, __VA_ARGS__);} typedef struct { uint64_t version; diff --git a/src/wal/test/CMakeLists.txt b/src/wal/test/CMakeLists.txt index 06591def40..f007bc3882 100644 --- a/src/wal/test/CMakeLists.txt +++ b/src/wal/test/CMakeLists.txt @@ -5,6 +5,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) + INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(../inc) LIST(APPEND WALTEST_SRC ./waltest.c) diff --git a/src/wal/test/waltest.c b/src/wal/test/waltest.c index 53f3477c7b..6bab8e0b23 100644 --- a/src/wal/test/waltest.c +++ b/src/wal/test/waltest.c @@ -14,7 +14,8 @@ */ //#define _DEFAULT_SOURCE -#include +#include "os.h" +#include "tglobal.h" #include "tlog.h" #include "twal.h" diff --git a/tests/test/c/CMakeLists.txt b/tests/test/c/CMakeLists.txt index 354aa2e05a..893abb8e82 100644 --- a/tests/test/c/CMakeLists.txt +++ b/tests/test/c/CMakeLists.txt @@ -3,6 +3,7 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) diff --git a/tests/test/c/importOneRow.c b/tests/test/c/importOneRow.c index 9c0b39f7c8..cf9e9b985d 100644 --- a/tests/test/c/importOneRow.c +++ b/tests/test/c/importOneRow.c @@ -16,9 +16,10 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taos.h" -#include "tlog.h" +#include "tulog.h" #include "ttimer.h" #include "tutil.h" +#include "tglobal.h" #define MAX_RANDOM_POINTS 20000 #define GREEN "\033[1;32m" @@ -65,9 +66,9 @@ void shellParseArgument(int argc, char *argv[]) { } } - dPrint("%s rowNum:%d %s", GREEN, rowNum, NC); - dPrint("%s threadNum:%d %s", GREEN, threadNum, NC); - dPrint("%s replica:%d %s", GREEN, replica, NC); + uPrint("%s rowNum:%d %s", GREEN, rowNum, NC); + uPrint("%s threadNum:%d %s", GREEN, threadNum, NC); + uPrint("%s replica:%d %s", GREEN, replica, NC); } int main(int argc, char *argv[]) { diff --git a/tests/test/c/importPerTabe.c b/tests/test/c/importPerTabe.c index d7c38c2b6a..62ef0ff33d 100644 --- a/tests/test/c/importPerTabe.c +++ b/tests/test/c/importPerTabe.c @@ -16,9 +16,10 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taos.h" -#include "tlog.h" +#include "tulog.h" #include "ttimer.h" #include "tutil.h" +#include "tglobal.h" #define MAX_RANDOM_POINTS 20000 #define GREEN "\033[1;32m" @@ -60,7 +61,7 @@ int main(int argc, char *argv[]) { } void createDbAndTable() { - dPrint("start to create table"); + uPrint("start to create table"); TAOS * con; struct timeval systemTime; @@ -69,19 +70,19 @@ void createDbAndTable() { con = taos_connect(tsMasterIp, tsDefaultUser, tsDefaultPass, NULL, 0); if (con == NULL) { - dError("failed to connect to DB, reason:%s", taos_errstr(con)); + uError("failed to connect to DB, reason:%s", taos_errstr(con)); exit(1); } sprintf(qstr, "create database if not exists %s cache %d tables %d", dbName, cache, tables); if (taos_query(con, qstr)) { - dError("failed to create database:%s, code:%d reason:%s", dbName, taos_errno(con), taos_errstr(con)); + uError("failed to create database:%s, code:%d reason:%s", dbName, taos_errno(con), taos_errstr(con)); exit(0); } sprintf(qstr, "use %s", dbName); if (taos_query(con, qstr)) { - dError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); + uError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); exit(0); } @@ -97,14 +98,14 @@ void createDbAndTable() { sprintf(qstr + len, ") tags(t int)"); if (taos_query(con, qstr)) { - dError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); + uError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); exit(0); } for (int64_t t = 0; t < totalTables; ++t) { sprintf(qstr, "create table if not exists %s%ld using %s tags(%ld)", stableName, t, stableName, t); if (taos_query(con, qstr)) { - dError("failed to create table %s%d, reason:%s", stableName, t, taos_errstr(con)); + uError("failed to create table %s%d, reason:%s", stableName, t, taos_errstr(con)); exit(0); } } @@ -117,7 +118,7 @@ void createDbAndTable() { sprintf(qstr + len, ")"); if (taos_query(con, qstr)) { - dError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); + uError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); exit(0); } } @@ -125,7 +126,7 @@ void createDbAndTable() { gettimeofday(&systemTime, NULL); et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - dPrint("%.1f seconds to create %ld tables", (et - st) / 1000.0 / 1000.0, totalTables); + uPrint("%.1f seconds to create %ld tables", (et - st) / 1000.0 / 1000.0, totalTables); } void insertData() { @@ -135,7 +136,7 @@ void insertData() { gettimeofday(&systemTime, NULL); st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - dPrint("%d threads are spawned to import data", numOfThreads); + uPrint("%d threads are spawned to import data", numOfThreads); pthread_attr_t thattr; pthread_attr_init(&thattr); @@ -169,12 +170,12 @@ void insertData() { double speedOfRows = totalRows / seconds; double speedOfPoints = totalPoints / seconds; - dPrint( + uPrint( "%sall threads:%ld finished, use %.1lf seconds, tables:%.ld rows:%ld points:%ld, speed RowsPerSecond:%.1lf " "PointsPerSecond:%.1lf%s", GREEN, numOfThreads, seconds, totalTables, totalRows, totalPoints, speedOfRows, speedOfPoints, NC); - dPrint("threads exit"); + uPrint("threads exit"); pthread_attr_destroy(&thattr); free(pInfo); @@ -188,11 +189,11 @@ void *syncTest(void *param) { char qstr[65000]; int maxBytes = 60000; - dPrint("thread:%d, start to run", pInfo->threadIndex); + uPrint("thread:%d, start to run", pInfo->threadIndex); con = taos_connect(tsMasterIp, tsDefaultUser, tsDefaultPass, NULL, 0); if (con == NULL) { - dError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); + uError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); exit(1); } @@ -220,7 +221,7 @@ void *syncTest(void *param) { len += sprintf(sql + len, ")"); if (len > maxBytes) { if (taos_query(con, qstr)) { - dError("thread:%d, failed to import table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, + uError("thread:%d, failed to import table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, table, row, taos_errstr(con)); } @@ -244,7 +245,7 @@ void *syncTest(void *param) { int64_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; int64_t totalRows = totalTables * pInfo->rowsPerTable; int64_t totalPoints = totalRows * pInfo->pointsPerTable; - dPrint("thread:%d, import finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, + uPrint("thread:%d, import finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, (et - st) / 1000.0 / 1000.0, totalTables, totalRows, totalPoints); return NULL; @@ -309,13 +310,13 @@ void shellParseArgument(int argc, char *argv[]) { } } - dPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); - dPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); - dPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); - dPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); - dPrint("%scache:%" PRId64 "%s", GREEN, cache, NC); - dPrint("%stables:%" PRId64 "%s", GREEN, tables, NC); - dPrint("%sdbName:%s%s", GREEN, dbName, NC); - dPrint("%stableName:%s%s", GREEN, stableName, NC); - dPrint("%sstart to run%s", GREEN, NC); + uPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); + uPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); + uPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); + uPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); + uPrint("%scache:%" PRId64 "%s", GREEN, cache, NC); + uPrint("%stables:%" PRId64 "%s", GREEN, tables, NC); + uPrint("%sdbName:%s%s", GREEN, dbName, NC); + uPrint("%stableName:%s%s", GREEN, stableName, NC); + uPrint("%sstart to run%s", GREEN, NC); } diff --git a/tests/test/c/insertPerRow.c b/tests/test/c/insertPerRow.c index 74ab238c3f..d4ef788be9 100644 --- a/tests/test/c/insertPerRow.c +++ b/tests/test/c/insertPerRow.c @@ -16,9 +16,10 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taos.h" -#include "tlog.h" +#include "tulog.h" #include "ttimer.h" #include "tutil.h" +#include "tglobal.h" #define MAX_RANDOM_POINTS 20000 #define GREEN "\033[1;32m" @@ -60,7 +61,7 @@ int main(int argc, char *argv[]) { } void createDbAndTable() { - dPrint("start to create table"); + uPrint("start to create table"); TAOS * con; struct timeval systemTime; @@ -69,19 +70,19 @@ void createDbAndTable() { con = taos_connect(tsMasterIp, tsDefaultUser, tsDefaultPass, NULL, 0); if (con == NULL) { - dError("failed to connect to DB, reason:%s", taos_errstr(con)); + uError("failed to connect to DB, reason:%s", taos_errstr(con)); exit(1); } sprintf(qstr, "create database if not exists %s cache %d tables %d", dbName, cache, tables); if (taos_query(con, qstr)) { - dError("failed to create database:%s, code:%d reason:%s", dbName, taos_errno(con), taos_errstr(con)); + uError("failed to create database:%s, code:%d reason:%s", dbName, taos_errno(con), taos_errstr(con)); exit(0); } sprintf(qstr, "use %s", dbName); if (taos_query(con, qstr)) { - dError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); + uError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); exit(0); } @@ -97,14 +98,14 @@ void createDbAndTable() { sprintf(qstr + len, ") tags(t int)"); if (taos_query(con, qstr)) { - dError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); + uError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); exit(0); } for (int64_t t = 0; t < totalTables; ++t) { sprintf(qstr, "create table if not exists %s%ld using %s tags(%ld)", stableName, t, stableName, t); if (taos_query(con, qstr)) { - dError("failed to create table %s%d, reason:%s", stableName, t, taos_errstr(con)); + uError("failed to create table %s%d, reason:%s", stableName, t, taos_errstr(con)); exit(0); } } @@ -117,7 +118,7 @@ void createDbAndTable() { sprintf(qstr + len, ")"); if (taos_query(con, qstr)) { - dError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); + uError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); exit(0); } } @@ -125,7 +126,7 @@ void createDbAndTable() { gettimeofday(&systemTime, NULL); et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - dPrint("%.1f seconds to create %ld tables", (et - st) / 1000.0 / 1000.0, totalTables); + uPrint("%.1f seconds to create %ld tables", (et - st) / 1000.0 / 1000.0, totalTables); } void insertData() { @@ -135,7 +136,7 @@ void insertData() { gettimeofday(&systemTime, NULL); st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - dPrint("%d threads are spawned to insert data", numOfThreads); + uPrint("%d threads are spawned to insert data", numOfThreads); pthread_attr_t thattr; pthread_attr_init(&thattr); @@ -169,12 +170,12 @@ void insertData() { double speedOfRows = totalRows / seconds; double speedOfPoints = totalPoints / seconds; - dPrint( + uPrint( "%sall threads:%ld finished, use %.1lf seconds, tables:%.ld rows:%ld points:%ld, speed RowsPerSecond:%.1lf " "PointsPerSecond:%.1lf%s", GREEN, numOfThreads, seconds, totalTables, totalRows, totalPoints, speedOfRows, speedOfPoints, NC); - dPrint("threads exit"); + uPrint("threads exit"); pthread_attr_destroy(&thattr); free(pInfo); @@ -188,11 +189,11 @@ void *syncTest(void *param) { char qstr[65000]; int maxBytes = 60000; - dPrint("thread:%d, start to run", pInfo->threadIndex); + uPrint("thread:%d, start to run", pInfo->threadIndex); con = taos_connect(tsMasterIp, tsDefaultUser, tsDefaultPass, NULL, 0); if (con == NULL) { - dError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); + uError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); exit(1); } @@ -220,7 +221,7 @@ void *syncTest(void *param) { len += sprintf(sql + len, ")"); if (len > maxBytes) { if (taos_query(con, qstr)) { - dError("thread:%d, failed to insert table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, + uError("thread:%d, failed to insert table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, table, row, taos_errstr(con)); } @@ -239,7 +240,7 @@ void *syncTest(void *param) { int64_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; int64_t totalRows = totalTables * pInfo->rowsPerTable; int64_t totalPoints = totalRows * pInfo->pointsPerTable; - dPrint("thread:%d, insert finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, + uPrint("thread:%d, insert finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, (et - st) / 1000.0 / 1000.0, totalTables, totalRows, totalPoints); return NULL; @@ -304,13 +305,13 @@ void shellParseArgument(int argc, char *argv[]) { } } - dPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); - dPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); - dPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); - dPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); - dPrint("%scache:%" PRId64 "%s", GREEN, cache, NC); - dPrint("%stables:%" PRId64 "%s", GREEN, tables, NC); - dPrint("%sdbName:%s%s", GREEN, dbName, NC); - dPrint("%stableName:%s%s", GREEN, stableName, NC); - dPrint("%sstart to run%s", GREEN, NC); + uPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); + uPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); + uPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); + uPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); + uPrint("%scache:%" PRId64 "%s", GREEN, cache, NC); + uPrint("%stables:%" PRId64 "%s", GREEN, tables, NC); + uPrint("%sdbName:%s%s", GREEN, dbName, NC); + uPrint("%stableName:%s%s", GREEN, stableName, NC); + uPrint("%sstart to run%s", GREEN, NC); } diff --git a/tests/test/c/insertPerTable.c b/tests/test/c/insertPerTable.c index ca63407463..c9ead1c5ca 100644 --- a/tests/test/c/insertPerTable.c +++ b/tests/test/c/insertPerTable.c @@ -16,9 +16,10 @@ #define _DEFAULT_SOURCE #include "os.h" #include "taos.h" -#include "tlog.h" +#include "tulog.h" #include "ttimer.h" #include "tutil.h" +#include "tglobal.h" #define MAX_RANDOM_POINTS 20000 #define GREEN "\033[1;32m" @@ -60,7 +61,7 @@ int main(int argc, char *argv[]) { } void createDbAndTable() { - dPrint("start to create table"); + uPrint("start to create table"); TAOS * con; struct timeval systemTime; @@ -69,19 +70,19 @@ void createDbAndTable() { con = taos_connect(tsMasterIp, tsDefaultUser, tsDefaultPass, NULL, 0); if (con == NULL) { - dError("failed to connect to DB, reason:%s", taos_errstr(con)); + uError("failed to connect to DB, reason:%s", taos_errstr(con)); exit(1); } sprintf(qstr, "create database if not exists %s cache %d tables %d", dbName, cache, tables); if (taos_query(con, qstr)) { - dError("failed to create database:%s, code:%d reason:%s", dbName, taos_errno(con), taos_errstr(con)); + uError("failed to create database:%s, code:%d reason:%s", dbName, taos_errno(con), taos_errstr(con)); exit(0); } sprintf(qstr, "use %s", dbName); if (taos_query(con, qstr)) { - dError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); + uError("failed to use db, code:%d reason:%s", taos_errno(con), taos_errstr(con)); exit(0); } @@ -97,14 +98,14 @@ void createDbAndTable() { sprintf(qstr + len, ") tags(t int)"); if (taos_query(con, qstr)) { - dError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); + uError("failed to create stable, code:%d reason:%s", taos_errno(con), taos_errstr(con)); exit(0); } for (int64_t t = 0; t < totalTables; ++t) { sprintf(qstr, "create table if not exists %s%ld using %s tags(%ld)", stableName, t, stableName, t); if (taos_query(con, qstr)) { - dError("failed to create table %s%d, reason:%s", stableName, t, taos_errstr(con)); + uError("failed to create table %s%d, reason:%s", stableName, t, taos_errstr(con)); exit(0); } } @@ -117,7 +118,7 @@ void createDbAndTable() { sprintf(qstr + len, ")"); if (taos_query(con, qstr)) { - dError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); + uError("failed to create table %s%ld, reason:%s", stableName, t, taos_errstr(con)); exit(0); } } @@ -125,7 +126,7 @@ void createDbAndTable() { gettimeofday(&systemTime, NULL); et = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - dPrint("%.1f seconds to create %ld tables", (et - st) / 1000.0 / 1000.0, totalTables); + uPrint("%.1f seconds to create %ld tables", (et - st) / 1000.0 / 1000.0, totalTables); } void insertData() { @@ -135,7 +136,7 @@ void insertData() { gettimeofday(&systemTime, NULL); st = systemTime.tv_sec * 1000000 + systemTime.tv_usec; - dPrint("%d threads are spawned to insert data", numOfThreads); + uPrint("%d threads are spawned to insert data", numOfThreads); pthread_attr_t thattr; pthread_attr_init(&thattr); @@ -169,12 +170,12 @@ void insertData() { double speedOfRows = totalRows / seconds; double speedOfPoints = totalPoints / seconds; - dPrint( + uPrint( "%sall threads:%ld finished, use %.1lf seconds, tables:%.ld rows:%ld points:%ld, speed RowsPerSecond:%.1lf " "PointsPerSecond:%.1lf%s", GREEN, numOfThreads, seconds, totalTables, totalRows, totalPoints, speedOfRows, speedOfPoints, NC); - dPrint("threads exit"); + uPrint("threads exit"); pthread_attr_destroy(&thattr); free(pInfo); @@ -188,11 +189,11 @@ void *syncTest(void *param) { char qstr[65000]; int maxBytes = 60000; - dPrint("thread:%d, start to run", pInfo->threadIndex); + uPrint("thread:%d, start to run", pInfo->threadIndex); con = taos_connect(tsMasterIp, tsDefaultUser, tsDefaultPass, NULL, 0); if (con == NULL) { - dError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); + uError("index:%d, failed to connect to DB, reason:%s", pInfo->threadIndex, taos_errstr(con)); exit(1); } @@ -220,7 +221,7 @@ void *syncTest(void *param) { len += sprintf(sql + len, ")"); if (len > maxBytes) { if (taos_query(con, qstr)) { - dError("thread:%d, failed to insert table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, + uError("thread:%d, failed to insert table:%s%ld row:%ld, reason:%s", pInfo->threadIndex, pInfo->stableName, table, row, taos_errstr(con)); } @@ -244,7 +245,7 @@ void *syncTest(void *param) { int64_t totalTables = pInfo->tableEndIndex - pInfo->tableBeginIndex; int64_t totalRows = totalTables * pInfo->rowsPerTable; int64_t totalPoints = totalRows * pInfo->pointsPerTable; - dPrint("thread:%d, insert finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, + uPrint("thread:%d, insert finished, use %.2f seconds, tables:%ld rows:%ld points:%ld", pInfo->threadIndex, (et - st) / 1000.0 / 1000.0, totalTables, totalRows, totalPoints); return NULL; @@ -309,13 +310,13 @@ void shellParseArgument(int argc, char *argv[]) { } } - dPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); - dPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); - dPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); - dPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); - dPrint("%scache:%" PRId64 "%s", GREEN, cache, NC); - dPrint("%stables:%" PRId64 "%s", GREEN, tables, NC); - dPrint("%sdbName:%s%s", GREEN, dbName, NC); - dPrint("%stableName:%s%s", GREEN, stableName, NC); - dPrint("%sstart to run%s", GREEN, NC); + uPrint("%srowsPerTable:%" PRId64 "%s", GREEN, rowsPerTable, NC); + uPrint("%spointsPerTable:%" PRId64 "%s", GREEN, pointsPerTable, NC); + uPrint("%snumOfThreads:%" PRId64 "%s", GREEN, numOfThreads, NC); + uPrint("%snumOfTablesPerThread:%" PRId64 "%s", GREEN, numOfTablesPerThread, NC); + uPrint("%scache:%" PRId64 "%s", GREEN, cache, NC); + uPrint("%stables:%" PRId64 "%s", GREEN, tables, NC); + uPrint("%sdbName:%s%s", GREEN, dbName, NC); + uPrint("%stableName:%s%s", GREEN, stableName, NC); + uPrint("%sstart to run%s", GREEN, NC); } diff --git a/tests/tsim/CMakeLists.txt b/tests/tsim/CMakeLists.txt index 2eaf3fe7cf..14ef791a4e 100644 --- a/tests/tsim/CMakeLists.txt +++ b/tests/tsim/CMakeLists.txt @@ -2,6 +2,7 @@ PROJECT(TDengine) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/util/inc) +INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/common/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/src/client/inc) INCLUDE_DIRECTORIES(${TD_COMMUNITY_DIR}/deps/cJson/inc) INCLUDE_DIRECTORIES(${TD_OS_DIR}/inc) diff --git a/tests/tsim/inc/sim.h b/tests/tsim/inc/sim.h index 01fd0789a9..304c488947 100644 --- a/tests/tsim/inc/sim.h +++ b/tests/tsim/inc/sim.h @@ -53,22 +53,22 @@ #define simError(...) \ if (simDebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR SIM ", 255, __VA_ARGS__); \ + taosPrintLog("ERROR SIM ", 255, __VA_ARGS__); \ } #define simWarn(...) \ if (simDebugFlag & DEBUG_WARN) { \ - tprintf("WARN SIM ", simDebugFlag, __VA_ARGS__); \ + taosPrintLog("WARN SIM ", simDebugFlag, __VA_ARGS__); \ } #define simTrace(...) \ if (simDebugFlag & DEBUG_TRACE) { \ - tprintf("SIM ", simDebugFlag, __VA_ARGS__); \ + taosPrintLog("SIM ", simDebugFlag, __VA_ARGS__); \ } #define simDump(x, y) \ if (simDebugFlag & DEBUG_DUMP) { \ taosDumpData(x, y); \ } #define simPrint(...) \ - { tprintf("SIM ", 255, __VA_ARGS__); } + { taosPrintLog("SIM ", 255, __VA_ARGS__); } enum { SIM_SCRIPT_TYPE_MAIN, SIM_SCRIPT_TYPE_BACKGROUND }; diff --git a/tests/tsim/src/simExe.c b/tests/tsim/src/simExe.c index 912f10ba2a..23f8f9173f 100644 --- a/tests/tsim/src/simExe.c +++ b/tests/tsim/src/simExe.c @@ -17,7 +17,7 @@ #include "sim.h" #include "taos.h" #include "taoserror.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "tutil.h" #include "cJSON.h" diff --git a/tests/tsim/src/simMain.c b/tests/tsim/src/simMain.c index 9cab6fb02b..2540851634 100644 --- a/tests/tsim/src/simMain.c +++ b/tests/tsim/src/simMain.c @@ -13,11 +13,9 @@ * along with this program. If not, see . */ +#include "os.h" +#include "tglobal.h" #include "sim.h" -#include -#include -#include -#include bool simAsyncQuery = false; diff --git a/tests/tsim/src/simSystem.c b/tests/tsim/src/simSystem.c index 73382744cf..55f1c97d3e 100644 --- a/tests/tsim/src/simSystem.c +++ b/tests/tsim/src/simSystem.c @@ -16,7 +16,7 @@ #include "os.h" #include "sim.h" #include "taos.h" -#include "tglobalcfg.h" +#include "tglobal.h" #include "ttimer.h" #include "tutil.h"