From e53540b5e777d83f01b10cebfb0e3cb12b9dc11a Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Feb 2022 21:18:40 +0800 Subject: [PATCH 1/4] rpc config --- include/common/tglobal.h | 15 --------------- include/dnode/mgmt/dnode.h | 2 ++ include/libs/transport/trpc.h | 10 ++++++++-- source/client/src/clientCfg.c | 12 +++++------- source/client/src/clientEnv.c | 6 +++++- source/client/test/clientTests.cpp | 2 +- source/client/test/tmqTest.cpp | 2 +- source/common/src/tglobal.c | 19 ------------------- source/dnode/mgmt/daemon/src/dmnCfg.c | 5 +++++ source/dnode/mgmt/impl/src/dndEnv.c | 3 ++- source/dnode/mgmt/impl/test/sut/src/sut.cpp | 2 ++ source/libs/transport/src/rpcMain.c | 9 ++++++--- source/os/src/osEnv.c | 4 +++- 13 files changed, 40 insertions(+), 51 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 8bce28d34c..2fc1765b41 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -55,23 +55,8 @@ extern float tsStreamComputDelayRatio; // the delayed computing ration of the extern int32_t tsProjectExecInterval; extern int64_t tsMaxRetentWindow; -// system info - -extern uint32_t tsVersion; - - -// lossy -extern char tsLossyColumns[]; -extern double tsFPrecision; -extern double tsDPrecision; -extern uint32_t tsMaxRange; -extern uint32_t tsCurRange; -extern char tsCompressor[]; - - #define NEEDTO_COMPRESSS_MSG(size) (tsCompressMsgSize != -1 && (size) > tsCompressMsgSize) -void taosInitGlobalCfg(); int32_t taosCfgDynamicOptions(char *msg); bool taosCheckBalanceCfgOptions(const char *option, int32_t *vnodeId, int32_t *dnodeId); void taosAddDataDir(int index, char *v1, int level, int primary); diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index 99fe2457a8..5d6c869b4d 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -32,6 +32,8 @@ typedef struct { uint16_t numOfCommitThreads; bool enableTelem; bool printAuth; + int32_t rpcTimer; + int32_t rpcMaxTime; char timezone[TSDB_TIMEZONE_LEN]; char locale[TSDB_LOCALE_LEN]; char charset[TSDB_LOCALE_LEN]; diff --git a/include/libs/transport/trpc.h b/include/libs/transport/trpc.h index 538aeb1a0e..60e23f132c 100644 --- a/include/libs/transport/trpc.h +++ b/include/libs/transport/trpc.h @@ -81,9 +81,15 @@ typedef struct SRpcInit { void *parent; } SRpcInit; -int32_t rpcInit(); +typedef struct { + int32_t rpcTimer; + int32_t rpcMaxTime; + int32_t sver; +} SRpcCfg; + +int32_t rpcInit(SRpcCfg *pCfg); void rpcCleanup(); -void * rpcOpen(const SRpcInit *pRpc); +void *rpcOpen(const SRpcInit *pRpc); void rpcClose(void *); void * rpcMallocCont(int contLen); void rpcFreeCont(void *pCont); diff --git a/source/client/src/clientCfg.c b/source/client/src/clientCfg.c index 22b1407a15..826626fd77 100644 --- a/source/client/src/clientCfg.c +++ b/source/client/src/clientCfg.c @@ -17,7 +17,7 @@ #include "clientInt.h" #include "ulog.h" -// todo refact +// todo refact SConfig *tscCfg; static int32_t tscLoadCfg(SConfig *pConfig, const char *inputCfgDir, const char *envFile, const char *apolloUrl) { @@ -125,7 +125,7 @@ static int32_t tscAddEpCfg(SConfig *pCfg) { return -1; } if (cfgAddString(pCfg, "fqdn", defaultFqdn) != 0) return -1; - + int32_t defaultServerPort = 6030; if (cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056) != 0) return -1; @@ -142,11 +142,10 @@ static int32_t tscAddEpCfg(SConfig *pCfg) { static int32_t tscAddCfg(SConfig *pCfg) { if (tscAddEpCfg(pCfg) != 0) return -1; - // if (cfgAddString(pCfg, "buildinfo", buildinfo) != 0) return -1; // if (cfgAddString(pCfg, "gitinfo", gitinfo) != 0) return -1; // if (cfgAddString(pCfg, "version", version) != 0) return -1; - + // if (cfgAddDir(pCfg, "dataDir", tsDataDir) != 0) return -1; if (cfgAddTimezone(pCfg, "timezone", "") != 0) return -1; if (cfgAddLocale(pCfg, "locale", "") != 0) return -1; @@ -160,7 +159,8 @@ static int32_t tscAddCfg(SConfig *pCfg) { if (cfgAddFloat(pCfg, "numOfThreadsPerCore", 1, 0, 10) != 0) return -1; if (cfgAddFloat(pCfg, "ratioOfQueryCores", 1, 0, 5) != 0) return -1; if (cfgAddInt32(pCfg, "shellActivityTimer", 3, 1, 120) != 0) return -1; - + if (cfgAddInt32(pCfg, "rpcTimer", 300, 100, 3000) != 0) return -1; + if (cfgAddInt32(pCfg, "rpcMaxTime", 600, 100, 7200) != 0) return -1; if (cfgAddInt32(pCfg, "maxConnections", 50000, 1, 100000) != 0) return -1; return 0; } @@ -169,8 +169,6 @@ int32_t tscCheckCfg(SConfig *pCfg) { bool enableCore = cfgGetItem(pCfg, "enableCoreFile")->bval; taosSetCoreDump(enableCore); - - return 0; } diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index 38f94ecae8..c982b24046 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -223,7 +223,11 @@ void taos_init_imp(void) { initMsgHandleFp(); initQueryModuleMsgHandle(); - rpcInit(); + SRpcCfg rpcCfg = {0}; + rpcCfg.rpcTimer = cfgGetItem(tscCfg, "rpcTimer")->i32; + rpcCfg.rpcMaxTime = cfgGetItem(tscCfg, "rpcMaxTime")->i32; + rpcCfg.sver = 30000000; + rpcInit(&rpcCfg); SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100}; catalogInit(&cfg); diff --git a/source/client/test/clientTests.cpp b/source/client/test/clientTests.cpp index 5414f17a62..ac36179a26 100644 --- a/source/client/test/clientTests.cpp +++ b/source/client/test/clientTests.cpp @@ -49,7 +49,7 @@ int main(int argc, char** argv) { } TEST(testCase, driverInit_Test) { - taosInitGlobalCfg(); + // taosInitGlobalCfg(); // taos_init(); } diff --git a/source/client/test/tmqTest.cpp b/source/client/test/tmqTest.cpp index 9f8ff7143a..c34c10d871 100644 --- a/source/client/test/tmqTest.cpp +++ b/source/client/test/tmqTest.cpp @@ -34,7 +34,7 @@ int main(int argc, char** argv) { } TEST(testCase, driverInit_Test) { - taosInitGlobalCfg(); + // taosInitGlobalCfg(); // taos_init(); } diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 72783bf4ab..be98a0e240 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -118,23 +118,6 @@ bool tsdbForceKeepFile = false; */ int64_t tsTickPerDay[] = {86400000L, 86400000000L, 86400000000000L}; -// system info -int32_t tsTotalMemoryMB = 0; -uint32_t tsVersion = 0; - -// -// lossy compress 6 -// -char tsLossyColumns[32] = ""; // "float|double" means all float and double columns can be lossy compressed. set empty - // can close lossy compress. -// below option can take effect when tsLossyColumns not empty -double tsFPrecision = 1E-8; // float column precision -double tsDPrecision = 1E-16; // double column precision -uint32_t tsMaxRange = 500; // max range -uint32_t tsCurRange = 100; // range -char tsCompressor[32] = "ZSTD_COMPRESSOR"; // ZSTD_COMPRESSOR or GZIP_COMPRESSOR - - int32_t (*monStartSystemFp)() = NULL; void (*monStopSystemFp)() = NULL; void (*monExecuteSQLFp)(char *sql) = NULL; @@ -529,8 +512,6 @@ static void doInitGlobalConfig(void) { #endif } -void taosInitGlobalCfg() { pthread_once(&tsInitGlobalCfgOnce, doInitGlobalConfig); } - /* * alter dnode 1 balance "vnode:1-dnode:2" */ diff --git a/source/dnode/mgmt/daemon/src/dmnCfg.c b/source/dnode/mgmt/daemon/src/dmnCfg.c index 7bf538caed..52aa22a533 100644 --- a/source/dnode/mgmt/daemon/src/dmnCfg.c +++ b/source/dnode/mgmt/daemon/src/dmnCfg.c @@ -80,6 +80,9 @@ static int32_t dmnAddDnodeCfg(SConfig *pCfg) { if (cfgAddFloat(pCfg, "ratioOfQueryCores", 1, 0, 5) != 0) return -1; if (cfgAddInt32(pCfg, "maxShellConns", 50000, 10, 50000000) != 0) return -1; if (cfgAddInt32(pCfg, "shellActivityTimer", 3, 1, 120) != 0) return -1; + if (cfgAddInt32(pCfg, "rpcTimer", 300, 100, 3000) != 0) return -1; + if (cfgAddInt32(pCfg, "rpcMaxTime", 600, 100, 7200) != 0) return -1; + return 0; } @@ -184,6 +187,8 @@ SDnodeEnvCfg dmnGetEnvCfg(SConfig *pCfg) { envCfg.numOfCores = cfgGetItem(pCfg, "numOfCores")->i32; envCfg.numOfCommitThreads = (uint16_t)cfgGetItem(pCfg, "numOfCommitThreads")->i32; envCfg.enableTelem = cfgGetItem(pCfg, "telemetryReporting")->bval; + envCfg.rpcMaxTime = cfgGetItem(pCfg, "rpcMaxTime")->i32; + envCfg.rpcTimer = cfgGetItem(pCfg, "rpcTimer")->i32; return envCfg; } diff --git a/source/dnode/mgmt/impl/src/dndEnv.c b/source/dnode/mgmt/impl/src/dndEnv.c index 58517c8151..b8f249f838 100644 --- a/source/dnode/mgmt/impl/src/dndEnv.c +++ b/source/dnode/mgmt/impl/src/dndEnv.c @@ -270,7 +270,8 @@ int32_t dndInit(const SDnodeEnvCfg *pCfg) { taosBlockSIGPIPE(); taosResolveCRC(); - if (rpcInit() != 0) { + SRpcCfg rpcCfg = {.rpcTimer = pCfg->rpcTimer, .rpcMaxTime = pCfg->rpcMaxTime, .sver = pCfg->sver}; + if (rpcInit(&rpcCfg) != 0) { dError("failed to init rpc since %s", terrstr()); dndCleanup(); return -1; diff --git a/source/dnode/mgmt/impl/test/sut/src/sut.cpp b/source/dnode/mgmt/impl/test/sut/src/sut.cpp index d32bdf29c6..9863fd9f54 100644 --- a/source/dnode/mgmt/impl/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/impl/test/sut/src/sut.cpp @@ -43,6 +43,8 @@ void Testbase::Init(const char* path, int16_t port) { SDnodeEnvCfg cfg = {0}; cfg.numOfCommitThreads = 1; cfg.numOfCores = 1; + cfg.rpcMaxTime = 600; + cfg.rpcTimer = 300; dndInit(&cfg); char fqdn[] = "localhost"; diff --git a/source/libs/transport/src/rpcMain.c b/source/libs/transport/src/rpcMain.c index 44bb6fdb70..cfd01bf3be 100644 --- a/source/libs/transport/src/rpcMain.c +++ b/source/libs/transport/src/rpcMain.c @@ -146,8 +146,9 @@ typedef struct SRpcConn { static int tsRpcRefId = -1; static int32_t tsRpcNum = 0; -int32_t tsRpcTimer = 300; -int32_t tsRpcMaxTime = 600; // seconds; +int32_t tsRpcTimer = 300; +int32_t tsRpcMaxTime = 600; // seconds; +uint32_t tsVersion = 0; // static pthread_once_t tsRpcInit = PTHREAD_ONCE_INIT; @@ -228,7 +229,9 @@ static void rpcInitImp(void) { tsFqdnHash = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), false, HASH_ENTRY_LOCK); } -int32_t rpcInit(void) { +int32_t rpcInit(SRpcCfg *pCfg) { + tsRpcTimer = pCfg->rpcTimer; + tsRpcMaxTime = pCfg->rpcMaxTime; pthread_once(&tsRpcInitOnce, rpcInitImp); return 0; } diff --git a/source/os/src/osEnv.c b/source/os/src/osEnv.c index b90d9fbe94..7417c6ff84 100644 --- a/source/os/src/osEnv.c +++ b/source/os/src/osEnv.c @@ -82,6 +82,8 @@ char tsDataDir[PATH_MAX] = "/var/lib/taos"; char tsLogDir[PATH_MAX] = "/var/log/taos"; char tsTempDir[PATH_MAX] = "/tmp/"; -void osInit() {} +void osInit() { + srand(taosSafeRand()); +} #endif From 9d091e90fdf1055afc1a3332780d58e2e258e608 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Feb 2022 21:22:43 +0800 Subject: [PATCH 2/4] remove tnote --- include/common/tglobal.h | 1 - include/util/tnote.h | 64 ------ source/client/src/clientEnv.c | 2 - source/client/src/clientImpl.c | 9 +- source/client/src/tmq.c | 1 - source/common/src/tglobal.c | 13 -- source/dnode/mgmt/impl/test/sut/inc/sut.h | 1 - source/util/src/tlog.c | 2 - source/util/src/tnote.c | 268 ---------------------- 9 files changed, 3 insertions(+), 358 deletions(-) delete mode 100644 include/util/tnote.h delete mode 100644 source/util/src/tnote.c diff --git a/include/common/tglobal.h b/include/common/tglobal.h index 2fc1765b41..5e245f3761 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -44,7 +44,6 @@ extern int8_t tsDeadLockKillQuery; // client extern int32_t tsMaxWildCardsLen; extern int32_t tsMaxRegexStringLen; -extern int8_t tsTscEnableRecordSql; extern int32_t tsMaxNumOfOrderedResults; extern int32_t tsMinSlidingTime; extern int32_t tsMinIntervalTime; diff --git a/include/util/tnote.h b/include/util/tnote.h deleted file mode 100644 index e613ec7e41..0000000000 --- a/include/util/tnote.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#ifndef _TD_UTIL_NOTE_H -#define _TD_UTIL_NOTE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAX_NOTE_LINE_SIZE 66000 -#define NOTE_FILE_NAME_LEN 300 - -typedef struct { - int32_t fileNum; - int32_t maxLines; - int32_t lines; - int32_t flag; - int32_t fd; - int32_t openInProgress; - char name[NOTE_FILE_NAME_LEN]; - pthread_mutex_t mutex; -} SNoteObj; - -extern SNoteObj tsHttpNote; -extern SNoteObj tsTscNote; -extern SNoteObj tsInfoNote; - -int32_t taosInitNotes(); -void taosNotePrint(SNoteObj* pNote, const char* const format, ...); -void taosNotePrintBuffer(SNoteObj* pNote, char* buffer, int32_t len); - -#define nPrintHttp(...) \ - if (tsHttpEnableRecordSql) { \ - taosNotePrint(&tsHttpNote, __VA_ARGS__); \ - } - -#define nPrintTsc(...) \ - if (tsTscEnableRecordSql) { \ - taosNotePrint(&tsTscNote, __VA_ARGS__); \ - } - -#define nInfo(buffer, len) \ - if (tscEmbeddedInUtil == 1) { \ - taosNotePrintBuffer(&tsInfoNote, buffer, len); \ - } - -#ifdef __cplusplus -} -#endif - -#endif /*_TD_UTIL_NOTE_H*/ diff --git a/source/client/src/clientEnv.c b/source/client/src/clientEnv.c index c982b24046..0af8dfad69 100644 --- a/source/client/src/clientEnv.c +++ b/source/client/src/clientEnv.c @@ -22,7 +22,6 @@ #include "tmsg.h" #include "tcache.h" #include "tglobal.h" -#include "tnote.h" #include "tref.h" #include "trpc.h" #include "ttime.h" @@ -219,7 +218,6 @@ void taos_init_imp(void) { return; } - taosInitNotes(); initMsgHandleFp(); initQueryModuleMsgHandle(); diff --git a/source/client/src/clientImpl.c b/source/client/src/clientImpl.c index c98a3695d9..c1e87c939f 100644 --- a/source/client/src/clientImpl.c +++ b/source/client/src/clientImpl.c @@ -8,7 +8,6 @@ #include "tep.h" #include "tglobal.h" #include "tmsgtype.h" -#include "tnote.h" #include "tpagedbuf.h" #include "tref.h" @@ -242,11 +241,9 @@ TAOS_RES* taos_query_l(TAOS* taos, const char* sql, int sqlLen) { return NULL; } - nPrintTsc("%s", sql) - - SRequestObj* pRequest = NULL; - SQueryNode* pQueryNode = NULL; - SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr)); + SRequestObj* pRequest = NULL; + SQueryNode* pQueryNode = NULL; + SArray* pNodeList = taosArrayInit(4, sizeof(struct SQueryNodeAddr)); terrno = TSDB_CODE_SUCCESS; CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return); diff --git a/source/client/src/tmq.c b/source/client/src/tmq.c index 9a1025c4bd..d3d9fce210 100644 --- a/source/client/src/tmq.c +++ b/source/client/src/tmq.c @@ -24,7 +24,6 @@ #include "tep.h" #include "tglobal.h" #include "tmsgtype.h" -#include "tnote.h" #include "tpagedbuf.h" #include "tref.h" diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index be98a0e240..ce8be66e82 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -60,8 +60,6 @@ int32_t tsCompatibleModel = 1; int32_t tsMaxWildCardsLen = TSDB_PATTERN_STRING_DEFAULT_LEN; int32_t tsMaxRegexStringLen = TSDB_REGEX_STRING_DEFAULT_LEN; -int8_t tsTscEnableRecordSql = 0; - // 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; @@ -410,17 +408,6 @@ static void doInitGlobalConfig(void) { taosAddConfigOption(cfg); - - cfg.option = "enableRecordSql"; - cfg.ptr = &tsTscEnableRecordSql; - cfg.valType = TAOS_CFG_VTYPE_INT8; - cfg.cfgType = TSDB_CFG_CTYPE_B_CONFIG; - cfg.minValue = 0; - cfg.maxValue = 1; - cfg.ptrLength = 0; - cfg.unitType = TAOS_CFG_UTYPE_NONE; - taosAddConfigOption(cfg); - cfg.option = "maxBinaryDisplayWidth"; cfg.ptr = &tsMaxBinaryDisplayWidth; cfg.valType = TAOS_CFG_VTYPE_INT32; diff --git a/source/dnode/mgmt/impl/test/sut/inc/sut.h b/source/dnode/mgmt/impl/test/sut/inc/sut.h index 5e42ee78df..c5c7ff2920 100644 --- a/source/dnode/mgmt/impl/test/sut/inc/sut.h +++ b/source/dnode/mgmt/impl/test/sut/inc/sut.h @@ -24,7 +24,6 @@ #include "tdataformat.h" #include "tglobal.h" #include "tmsg.h" -#include "tnote.h" #include "trpc.h" #include "tthread.h" #include "ulog.h" diff --git a/source/util/src/tlog.c b/source/util/src/tlog.c index f5d02df80d..f479203fce 100644 --- a/source/util/src/tlog.c +++ b/source/util/src/tlog.c @@ -16,7 +16,6 @@ #define _DEFAULT_SOURCE #include "tlog.h" #include "os.h" -#include "tnote.h" #include "tutil.h" #include "ulog.h" @@ -432,7 +431,6 @@ void taosPrintLog(const char *flags, int32_t dflag, const char *format, ...) { } if (dflag & DEBUG_SCREEN) taosWriteFile(1, buffer, (uint32_t)len); - if (dflag == 255) nInfo(buffer, len); } void taosDumpData(unsigned char *msg, int32_t len) { diff --git a/source/util/src/tnote.c b/source/util/src/tnote.c deleted file mode 100644 index d9356b7e40..0000000000 --- a/source/util/src/tnote.c +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright (c) 2019 TAOS Data, Inc. - * - * This program is free software: you can use, redistribute, and/or modify - * it under the terms of the GNU Affero General Public License, version 3 - * or later ("AGPL"), as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -#define _DEFAULT_SOURCE -#include "os.h" -#include "tutil.h" -#include "tdef.h" -#include "tnote.h" - -SNoteObj tsHttpNote; -SNoteObj tsTscNote; -SNoteObj tsInfoNote; - -static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxNoteNum, SNoteObj *pNote); -static void taosCloseNoteByFd(int32_t oldFd, SNoteObj *pNote); - -static void taosInitNote(int32_t numOfLines, int32_t maxNotes, SNoteObj *pNote, char *name) { - memset(pNote, 0, sizeof(SNoteObj)); - pNote->fileNum = 1; - pNote->fd = -1; - - if (taosOpenNoteWithMaxLines(name, numOfLines, maxNotes, pNote) < 0) { - fprintf(stderr, "failed to init note file\n"); - } - - taosNotePrint(pNote, "=================================================="); - taosNotePrint(pNote, "=================== new note ==================="); - taosNotePrint(pNote, "=================================================="); -} - -int32_t taosInitNotes() { - char name[TSDB_FILENAME_LEN * 2] = {0}; - -#if 0 - if (tsTscEnableRecordSql) { - snprintf(name, TSDB_FILENAME_LEN * 2, "%s/tscsql-%d", tsLogDir, taosGetPId()); - taosInitNote(tsNumOfLogLines, 1, &tsTscNote, name); - } - -#endif - return 0; -} - -static bool taosLockNote(int32_t fd, SNoteObj *pNote) { - if (fd < 0) return false; - - if (pNote->fileNum > 1) { - int32_t ret = (int32_t)taosLockFile(fd); - if (ret == 0) { - return true; - } - } - - return false; -} - -static void taosUnLockNote(int32_t fd, SNoteObj *pNote) { - if (fd < 0) return; - - if (pNote->fileNum > 1) { - taosUnLockFile(fd); - } -} - -static void *taosThreadToOpenNewNote(void *param) { - char name[NOTE_FILE_NAME_LEN * 2]; - SNoteObj *pNote = (SNoteObj *)param; - - setThreadName("openNewNote"); - - pNote->flag ^= 1; - pNote->lines = 0; - sprintf(name, "%s.%d", pNote->name, pNote->flag); - - taosUmaskFile(0); - - int32_t fd = taosOpenFileCreateWriteTrunc(name); - if (fd < 0) { - return NULL; - } - - taosLockNote(fd, pNote); - (void)taosLSeekFile(fd, 0, SEEK_SET); - - int32_t oldFd = pNote->fd; - pNote->fd = fd; - pNote->lines = 0; - pNote->openInProgress = 0; - taosNotePrint(pNote, "=============== new note is opened ============="); - - taosCloseNoteByFd(oldFd, pNote); - return NULL; -} - -static int32_t taosOpenNewNote(SNoteObj *pNote) { - pthread_mutex_lock(&pNote->mutex); - - if (pNote->lines > pNote->maxLines && pNote->openInProgress == 0) { - pNote->openInProgress = 1; - - taosNotePrint(pNote, "=============== open new note =================="); - pthread_t pattern; - pthread_attr_t attr; - pthread_attr_init(&attr); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - - pthread_create(&pattern, &attr, taosThreadToOpenNewNote, (void *)pNote); - pthread_attr_destroy(&attr); - } - - pthread_mutex_unlock(&pNote->mutex); - - return pNote->fd; -} - -static bool taosCheckNoteIsOpen(char *noteName, SNoteObj *pNote) { - int32_t fd = taosOpenFileCreateWrite(noteName); - if (fd < 0) { - fprintf(stderr, "failed to open note:%s reason:%s\n", noteName, strerror(errno)); - return true; - } - - if (taosLockNote(fd, pNote)) { - taosUnLockNote(fd, pNote); - taosCloseFile(fd); - return false; - } else { - taosCloseFile(fd); - return true; - } -} - -static void taosGetNoteName(char *fn, SNoteObj *pNote) { - if (pNote->fileNum > 1) { - for (int32_t i = 0; i < pNote->fileNum; i++) { - char fileName[NOTE_FILE_NAME_LEN]; - - sprintf(fileName, "%s%d.0", fn, i); - bool file1open = taosCheckNoteIsOpen(fileName, pNote); - - sprintf(fileName, "%s%d.1", fn, i); - bool file2open = taosCheckNoteIsOpen(fileName, pNote); - - if (!file1open && !file2open) { - sprintf(pNote->name, "%s%d", fn, i); - return; - } - } - } - - if (strlen(fn) < NOTE_FILE_NAME_LEN) { - strcpy(pNote->name, fn); - } -} - -static int32_t taosOpenNoteWithMaxLines(char *fn, int32_t maxLines, int32_t maxNoteNum, SNoteObj *pNote) { - char name[NOTE_FILE_NAME_LEN * 2] = {0}; - int32_t size; - int32_t logstat0_mtime, logstat1_mtime; - - pNote->maxLines = maxLines; - pNote->fileNum = maxNoteNum; - taosGetNoteName(fn, pNote); - - if (strlen(fn) < NOTE_FILE_NAME_LEN + 50 - 2) { - strcpy(name, fn); - strcat(name, ".0"); - } - bool log0Exist = taosStatFile(name, NULL, &logstat0_mtime) >= 0; - - if (strlen(fn) < NOTE_FILE_NAME_LEN + 50 - 2) { - strcpy(name, fn); - strcat(name, ".1"); - } - bool log1Exist = taosStatFile(name, NULL, &logstat1_mtime) >= 0; - - if (!log0Exist && !log1Exist) { - pNote->flag = 0; - } else if (!log1Exist) { - pNote->flag = 0; - } else if (!log0Exist) { - pNote->flag = 1; - } else { - pNote->flag = (logstat0_mtime > logstat1_mtime) ? 0 : 1; - } - - char noteName[NOTE_FILE_NAME_LEN * 2] = {0}; - sprintf(noteName, "%s.%d", pNote->name, pNote->flag); - pthread_mutex_init(&pNote->mutex, NULL); - - taosUmaskFile(0); - pNote->fd = taosOpenFileCreateWrite(noteName); - - if (pNote->fd < 0) { - fprintf(stderr, "failed to open note file:%s reason:%s\n", noteName, strerror(errno)); - return -1; - } - taosLockNote(pNote->fd, pNote); - - // only an estimate for number of lines - int64_t filestat_size; - if (taosFStatFile(pNote->fd, &filestat_size, NULL) < 0) { - fprintf(stderr, "failed to fstat note file:%s reason:%s\n", noteName, strerror(errno)); - return -1; - } - size = (int32_t)filestat_size; - pNote->lines = size / 60; - - taosLSeekFile(pNote->fd, 0, SEEK_END); - - return 0; -} - -void taosNotePrintBuffer(SNoteObj *pNote, char *buffer, int32_t len) { - if (pNote->fd <= 0) return; - taosWriteFile(pNote->fd, buffer, len); - - if (pNote->maxLines > 0) { - pNote->lines++; - if ((pNote->lines > pNote->maxLines) && (pNote->openInProgress == 0)) taosOpenNewNote(pNote); - } -} - -void taosNotePrint(SNoteObj *pNote, const char *const format, ...) { - va_list argpointer; - char buffer[MAX_NOTE_LINE_SIZE + 2]; - int32_t len; - struct tm Tm, *ptm; - struct timeval timeSecs; - time_t curTime; - - taosGetTimeOfDay(&timeSecs); - curTime = timeSecs.tv_sec; - ptm = localtime_r(&curTime, &Tm); - len = sprintf(buffer, "%02d/%02d %02d:%02d:%02d.%06d %08" PRId64 " ", ptm->tm_mon + 1, ptm->tm_mday, ptm->tm_hour, - ptm->tm_min, ptm->tm_sec, (int32_t)timeSecs.tv_usec, taosGetSelfPthreadId()); - va_start(argpointer, format); - len += vsnprintf(buffer + len, MAX_NOTE_LINE_SIZE - len, format, argpointer); - va_end(argpointer); - - if (len >= MAX_NOTE_LINE_SIZE) len = MAX_NOTE_LINE_SIZE - 2; - - buffer[len++] = '\n'; - buffer[len] = 0; - - taosNotePrintBuffer(pNote, buffer, len); -} - -// static void taosCloseNote(SNoteObj *pNote) { taosCloseNoteByFd(pNote->fd, pNote); } - -static void taosCloseNoteByFd(int32_t fd, SNoteObj *pNote) { - if (fd >= 0) { - taosUnLockNote(fd, pNote); - taosCloseFile(fd); - } -} From 4555886eeb03e0a88956ee421e085d04ded908f0 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 23 Feb 2022 21:29:00 +0800 Subject: [PATCH 3/4] minor changes --- source/libs/transport/src/trans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index 48c15ca286..9e4c54e0af 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -107,7 +107,7 @@ void rpcSendRedirectRsp(void* thandle, const SEpSet* pEpSet) { int rpcReportProgress(void* pConn, char* pCont, int contLen) { return -1; } void rpcCancelRequest(int64_t rid) { return; } -int32_t rpcInit(void) { +int32_t rpcInit(SRpcConfig *pCfg) { // impl later return 0; } From ca634993c5f8438b13f0e13713e1ce23cda5dbd2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Thu, 24 Feb 2022 10:17:37 +0800 Subject: [PATCH 4/4] fix compile error --- source/libs/transport/src/trans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/libs/transport/src/trans.c b/source/libs/transport/src/trans.c index b631b84b4c..09aee6c8bc 100644 --- a/source/libs/transport/src/trans.c +++ b/source/libs/transport/src/trans.c @@ -112,7 +112,7 @@ void rpcSendRedirectRsp(void* thandle, const SEpSet* pEpSet) { int rpcReportProgress(void* pConn, char* pCont, int contLen) { return -1; } void rpcCancelRequest(int64_t rid) { return; } -int32_t rpcInit(SRpcConfig *pCfg) { +int32_t rpcInit(SRpcCfg* pCfg) { // impl later return 0; }