From 4c99c6eb0ecbf7d676dee2c4f022312d71a9e8e2 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Wed, 24 Nov 2021 14:20:18 +0800 Subject: [PATCH 01/16] rename file --- source/dnode/mgmt/impl/src/{dndInt.c => dnode.c} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename source/dnode/mgmt/impl/src/{dndInt.c => dnode.c} (100%) diff --git a/source/dnode/mgmt/impl/src/dndInt.c b/source/dnode/mgmt/impl/src/dnode.c similarity index 100% rename from source/dnode/mgmt/impl/src/dndInt.c rename to source/dnode/mgmt/impl/src/dnode.c From e10b4bc05e04356027a856c86b9acfdd994103eb Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 26 Nov 2021 00:16:42 +0800 Subject: [PATCH 02/16] update fst core struct --- source/libs/index/inc/index_fst.h | 3 ++ .../index/inc/index_fst_counting_writer.h | 4 ++- source/libs/index/src/index_fst.c | 29 +++++++++++++++++-- .../index/src/index_fst_counting_writer.c | 3 ++ 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 7ab9358cd1..87d740ddd9 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -80,6 +80,9 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in); OrderType fstBuilderCheckLastKey(FstBuilder *b, FstSlice bs, bool ckDup); void fstBuilderCompileFrom(FstBuilder *b, uint64_t istate); CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn); +void* fstBuilerIntoInner(FstBuilder *b); +void fstBuilderFinish(FstBuilder *b); + diff --git a/source/libs/index/inc/index_fst_counting_writer.h b/source/libs/index/inc/index_fst_counting_writer.h index fbb2f1cff7..4650804034 100644 --- a/source/libs/index/inc/index_fst_counting_writer.h +++ b/source/libs/index/inc/index_fst_counting_writer.h @@ -27,9 +27,11 @@ typedef struct FstCountingWriter { uint64_t fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t bufLen); -int FstCountingWriterFlush(FstCountingWriter *write); +int fstCountingWriterFlush(FstCountingWriter *write); +uint32_t fstCountingWriterMaskedCheckSum(FstCountingWriter *write); + FstCountingWriter *fstCountingWriterCreate(void *wtr); void fstCountingWriterDestroy(FstCountingWriter *w); diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 8b9aa22fc6..f8fc40fcb6 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -14,7 +14,7 @@ */ #include "index_fst.h" - +#include "tcoding.h" static void fstPackDeltaIn(FstCountingWriter *wrt, CompiledAddr nodeAddr, CompiledAddr transAddr, uint8_t nBytes) { @@ -98,7 +98,7 @@ void fstUnFinishedNodesAddSuffix(FstUnFinishedNodes *nodes, FstSlice bs, Output FstBuilderNodeUnfinished *un = taosArrayGet(nodes->stack, sz); assert(un->last == NULL); - + //FstLastTransition *trn = malloc(sizeof(FstLastTransition)); //trn->inp = s->data[s->start]; @@ -849,6 +849,31 @@ CompiledAddr fstBuilderCompile(FstBuilder *b, FstBuilderNode *bn) { return b->lastAddr; } +void* fstBuilderInsertInner(FstBuilder *b) { + fstBuilderCompileFrom(b, 0); + FstBuilderNode *rootNode = fstUnFinishedNodesPopRoot(b->unfinished); + CompiledAddr rootAddr = fstBuilderCompile(b, rootNode); + + uint8_t buf64[8] = {0}; + + taosEncodeFixedU64((void **)&buf64, b->len); + fstCountingWriterWrite(b->wrt, buf64, sizeof(buf64)); + + taosEncodeFixedU64((void **)&buf64, rootAddr); + fstCountingWriterWrite(b->wrt, buf64, sizeof(buf64)); + + uint8_t buf32[4] = {0}; + uint32_t sum = fstCountingWriterMaskedCheckSum(b->wrt); + taosEncodeFixedU32((void **)&buf32, sum); + fstCountingWriterWrite(b->wrt, buf32, sizeof(buf32)); + + fstCountingWriterFlush(b->wrt); + return b->wrt; + +} +void fstBuilderFinish(FstBuilder *b) { + fstBuilderInsertInner(b); +} diff --git a/source/libs/index/src/index_fst_counting_writer.c b/source/libs/index/src/index_fst_counting_writer.c index b253db986a..a0a2c380f1 100644 --- a/source/libs/index/src/index_fst_counting_writer.c +++ b/source/libs/index/src/index_fst_counting_writer.c @@ -37,6 +37,9 @@ uint64_t fstCountingWriterWrite(FstCountingWriter *write, uint8_t *buf, uint32_t return bufLen; } +uint32_t fstCountingWriterMaskedCheckSum(FstCountingWriter *write) { + return 0; +} int fstCountingWriterFlush(FstCountingWriter *write) { //write->wtr->flush return 1; From bbb280a770be2aad8f88ae76d27b9a7fe6143183 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 26 Nov 2021 10:26:08 +0800 Subject: [PATCH 03/16] minor changes --- source/dnode/mgmt/impl/inc/dndInt.h | 14 +++++++------- source/dnode/mgmt/impl/src/dnode.c | 10 +++++----- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/source/dnode/mgmt/impl/inc/dndInt.h b/source/dnode/mgmt/impl/inc/dndInt.h index 966781426b..fba589c73a 100644 --- a/source/dnode/mgmt/impl/inc/dndInt.h +++ b/source/dnode/mgmt/impl/inc/dndInt.h @@ -37,12 +37,12 @@ extern "C" { extern int32_t dDebugFlag; -#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("SRV FATAL ", 255, __VA_ARGS__); }} -#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("SRV ERROR ", 255, __VA_ARGS__); }} -#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("SRV WARN ", 255, __VA_ARGS__); }} -#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("SRV ", 255, __VA_ARGS__); }} -#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("SRV ", dDebugFlag, __VA_ARGS__); }} -#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("SRV ", dDebugFlag, __VA_ARGS__); }} +#define dFatal(...) { if (dDebugFlag & DEBUG_FATAL) { taosPrintLog("DND FATAL ", 255, __VA_ARGS__); }} +#define dError(...) { if (dDebugFlag & DEBUG_ERROR) { taosPrintLog("DND ERROR ", 255, __VA_ARGS__); }} +#define dWarn(...) { if (dDebugFlag & DEBUG_WARN) { taosPrintLog("DND WARN ", 255, __VA_ARGS__); }} +#define dInfo(...) { if (dDebugFlag & DEBUG_INFO) { taosPrintLog("DND ", 255, __VA_ARGS__); }} +#define dDebug(...) { if (dDebugFlag & DEBUG_DEBUG) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }} +#define dTrace(...) { if (dDebugFlag & DEBUG_TRACE) { taosPrintLog("DND ", dDebugFlag, __VA_ARGS__); }} typedef enum { DND_STAT_INIT, DND_STAT_RUNNING, DND_STAT_STOPPED } EStat; typedef void (*DndMsgFp)(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEps); @@ -119,7 +119,7 @@ EStat dndGetStat(SDnode *pDnode); void dndSetStat(SDnode *pDnode, EStat stat); char *dndStatStr(EStat stat); -void dndReportStartup(SDnode *pDnode, char *name, char *desc); +void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc); void dndGetStartup(SDnode *pDnode, SStartupMsg *pStartup); #ifdef __cplusplus diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index f4cee3f6fd..1261136fd3 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -20,8 +20,8 @@ #include "dndVnodes.h" #include "sync.h" #include "tcache.h" -#include "wal.h" #include "tcrc32c.h" +#include "wal.h" EStat dndGetStat(SDnode *pDnode) { return pDnode->stat; } @@ -43,10 +43,10 @@ char *dndStatStr(EStat stat) { } } -void dndReportStartup(SDnode *pDnode, char *name, char *desc) { +void dndReportStartup(SDnode *pDnode, char *pName, char *pDesc) { SStartupMsg *pStartup = &pDnode->startup; - tstrncpy(pStartup->name, name, strlen(pStartup->name)); - tstrncpy(pStartup->desc, desc, strlen(pStartup->desc)); + tstrncpy(pStartup->name, pName, TSDB_STEP_NAME_LEN); + tstrncpy(pStartup->desc, pDesc, TSDB_STEP_DESC_LEN); pStartup->finished = 0; } @@ -61,7 +61,7 @@ static int32_t dndCheckRunning(char *dataDir) { FileFd fd = taosOpenFileCreateWriteTrunc(filepath); if (fd < 0) { - dError("failed to open lock file:%s since %s, quit", filepath, strerror(errno)); + dError("failed to lock file:%s since %s, quit", filepath, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } From 04ea23584f789bd5650b8f6dc845828616dd1269 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 26 Nov 2021 11:13:45 +0800 Subject: [PATCH 04/16] refact dnode --- include/common/tglobal.h | 4 - include/dnode/mnode/mnode.h | 2 +- include/dnode/vnode/vnode.h | 2 +- include/util/tdef.h | 6 - source/common/src/tglobal.c | 9 - source/dnode/mgmt/impl/inc/dndDnode.h | 2 +- source/dnode/mgmt/impl/inc/dndInt.h | 26 +- source/dnode/mgmt/impl/src/dndDnode.c | 411 +++++++++++++------------- source/dnode/mnode/impl/src/mnode.c | 2 +- 9 files changed, 215 insertions(+), 249 deletions(-) diff --git a/include/common/tglobal.h b/include/common/tglobal.h index f3fce8becd..f478e96766 100644 --- a/include/common/tglobal.h +++ b/include/common/tglobal.h @@ -28,10 +28,6 @@ extern char tsSecond[]; extern char tsLocalFqdn[]; extern char tsLocalEp[]; extern uint16_t tsServerPort; -extern uint16_t tsDnodeShellPort; -extern uint16_t tsDnodeDnodePort; -extern uint16_t tsSyncPort; -extern uint16_t tsArbitratorPort; extern int32_t tsStatusInterval; extern int32_t tsNumOfMnodes; extern int8_t tsEnableVnodeBak; diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 98aefc6db3..b7b05f896f 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -26,7 +26,7 @@ typedef struct SMnode SMnode; typedef struct SMnodeMsg SMnodeMsg; typedef void (*SendMsgToDnodeFp)(SDnode *pDnd, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); typedef void (*SendMsgToMnodeFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg, bool forShell); +typedef void (*SendRedirectMsgFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg); typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnd, SMnodeMsg *pMsg); typedef struct SMnodeLoad { diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 586cb49d0f..8dc01b2a8a 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -187,7 +187,7 @@ typedef struct { typedef struct SDnode SDnode; typedef void (*SendMsgToDnodeFp)(SDnode *pDnd, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); typedef void (*SendMsgToMnodeFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg, bool forShell); +typedef void (*SendRedirectMsgFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg); typedef int32_t (*PutMsgToVnodeQFp)(SDnode *pDnd, int32_t vgId, SVnodeMsg *pMsg); typedef struct { diff --git a/include/util/tdef.h b/include/util/tdef.h index d61a3e7188..76df8887a0 100644 --- a/include/util/tdef.h +++ b/include/util/tdef.h @@ -358,12 +358,6 @@ do { \ #define TSDB_DEFAULT_STABLES_HASH_SIZE 100 #define TSDB_DEFAULT_CTABLES_HASH_SIZE 20000 -#define TSDB_PORT_DNODESHELL 0 -#define TSDB_PORT_DNODEDNODE 5 -#define TSDB_PORT_SYNC 10 -#define TSDB_PORT_HTTP 11 -#define TSDB_PORT_ARBITRATOR 12 - #define TSDB_MAX_WAL_SIZE (1024*1024*3) #define TSDB_ARB_DUMMY_TIME 4765104000000 // 2121-01-01 00:00:00.000, :P diff --git a/source/common/src/tglobal.c b/source/common/src/tglobal.c index 501936d354..8d57218a64 100644 --- a/source/common/src/tglobal.c +++ b/source/common/src/tglobal.c @@ -33,10 +33,6 @@ char tsArbitrator[TSDB_EP_LEN] = {0}; char tsLocalFqdn[TSDB_FQDN_LEN] = {0}; char tsLocalEp[TSDB_EP_LEN] = {0}; // Local End Point, hostname:port uint16_t tsServerPort = 6030; -uint16_t tsDnodeShellPort = 6030; // udp[6035-6039] tcp[6035] -uint16_t tsDnodeDnodePort = 6035; // udp/tcp -uint16_t tsSyncPort = 6040; -uint16_t tsArbitratorPort = 6042; int32_t tsStatusInterval = 1; // second int32_t tsNumOfMnodes = 1; int8_t tsEnableVnodeBak = 1; @@ -1726,11 +1722,6 @@ int32_t taosCheckGlobalCfg() { } } - tsDnodeShellPort = tsServerPort + TSDB_PORT_DNODESHELL; // udp[6035-6039] tcp[6035] - tsDnodeDnodePort = tsServerPort + TSDB_PORT_DNODEDNODE; // udp/tcp - tsSyncPort = tsServerPort + TSDB_PORT_SYNC; - tsHttpPort = tsServerPort + TSDB_PORT_HTTP; - if (tsQueryBufferSize >= 0) { tsQueryBufferSizeBytes = tsQueryBufferSize * 1048576UL; } diff --git a/source/dnode/mgmt/impl/inc/dndDnode.h b/source/dnode/mgmt/impl/inc/dndDnode.h index ef16b1c8f0..590a9611e1 100644 --- a/source/dnode/mgmt/impl/inc/dndDnode.h +++ b/source/dnode/mgmt/impl/inc/dndDnode.h @@ -30,7 +30,7 @@ int32_t dndGetDnodeId(SDnode *pDnd); int64_t dndGetClusterId(SDnode *pDnd); void dndGetDnodeEp(SDnode *pDnd, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); void dndGetMnodeEpSet(SDnode *pDnd, SEpSet *pEpSet); -void dndSendRedirectMsg(SDnode *pDnd, SRpcMsg *pMsg, bool forShell); +void dndSendRedirectMsg(SDnode *pDnd, SRpcMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/inc/dndInt.h b/source/dnode/mgmt/impl/inc/dndInt.h index fba589c73a..258f40aad6 100644 --- a/source/dnode/mgmt/impl/inc/dndInt.h +++ b/source/dnode/mgmt/impl/inc/dndInt.h @@ -31,9 +31,10 @@ extern "C" { #include "tthread.h" #include "ttime.h" #include "tworker.h" + +#include "dnode.h" #include "mnode.h" #include "vnode.h" -#include "dnode.h" extern int32_t dDebugFlag; @@ -54,17 +55,16 @@ typedef struct { } SDnodeDir; typedef struct { - int32_t dnodeId; - uint32_t rebootTime; - int32_t dropped; - int64_t clusterId; - SEpSet shellEpSet; - SEpSet peerEpSet; - char *file; - SHashObj *dnodeHash; - SDnodeEps *dnodeEps; - pthread_t *threadId; - pthread_mutex_t mutex; + int32_t dnodeId; + int32_t dropped; + uint32_t rebootTime; + int64_t clusterId; + SEpSet mnodeEpSet; + char *file; + SHashObj *dnodeHash; + SDnodeEps *dnodeEps; + pthread_t *threadId; + SRWLatch latch; } SDnodeMgmt; typedef struct { @@ -108,7 +108,7 @@ typedef struct SDnode { EStat stat; SDnodeOpt opt; SDnodeDir dir; - SDnodeMgmt d; + SDnodeMgmt dmgmt; SMnodeMgmt m; SVnodesMgmt vmgmt; STransMgmt t; diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 378d76e046..962ce2b73d 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -18,28 +18,32 @@ #include "dndTransport.h" #include "dndVnodes.h" -static inline void dndLockDnode(SDnode *pDnd) { pthread_mutex_lock(&pDnd->d.mutex); } +static inline void dndRLockDnode(SDnode *pDnode) { taosRLockLatch(&pDnode->dmgmt.latch); } -static inline void dndUnLockDnode(SDnode *pDnd) { pthread_mutex_unlock(&pDnd->d.mutex); } +static inline void dndRUnLockDnode(SDnode *pDnode) { taosRUnLockLatch(&pDnode->dmgmt.latch); } -int32_t dndGetDnodeId(SDnode *pDnd) { - dndLockDnode(pDnd); - int32_t dnodeId = pDnd->d.dnodeId; - dndUnLockDnode(pDnd); +static inline void dndWLockDnode(SDnode *pDnode) { taosWLockLatch(&pDnode->dmgmt.latch); } + +static inline void dndWUnLockDnode(SDnode *pDnode) { taosWUnLockLatch(&pDnode->dmgmt.latch); } + +int32_t dndGetDnodeId(SDnode *pDnode) { + dndRLockDnode(pDnode); + int32_t dnodeId = pDnode->dmgmt.dnodeId; + dndRUnLockDnode(pDnode); return dnodeId; } -int64_t dndGetClusterId(SDnode *pDnd) { - dndLockDnode(pDnd); - int64_t clusterId = pDnd->d.clusterId; - dndUnLockDnode(pDnd); +int64_t dndGetClusterId(SDnode *pDnode) { + dndRLockDnode(pDnode); + int64_t clusterId = pDnode->dmgmt.clusterId; + dndRUnLockDnode(pDnode); return clusterId; } -void dndGetDnodeEp(SDnode *pDnd, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { - dndLockDnode(pDnd); +void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort) { + dndRLockDnode(pDnode); - SDnodeEp *pDnodeEp = taosHashGet(pDnd->d.dnodeHash, &dnodeId, sizeof(int32_t)); + SDnodeEp *pDnodeEp = taosHashGet(pDnode->dmgmt.dnodeHash, &dnodeId, sizeof(int32_t)); if (pDnodeEp != NULL) { if (pPort != NULL) { *pPort = pDnodeEp->port; @@ -52,41 +56,26 @@ void dndGetDnodeEp(SDnode *pDnd, int32_t dnodeId, char *pEp, char *pFqdn, uint16 } } - dndUnLockDnode(pDnd); + dndRUnLockDnode(pDnode); } -void dndGetMnodeEpSet(SDnode *pDnd, SEpSet *pEpSet) { - dndLockDnode(pDnd); - *pEpSet = pDnd->d.peerEpSet; - dndUnLockDnode(pDnd); +void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { + dndRLockDnode(pDnode); + *pEpSet = pDnode->dmgmt.mnodeEpSet; + dndRUnLockDnode(pDnode); } -void dndGetShellEpSet(SDnode *pDnd, SEpSet *pEpSet) { - dndLockDnode(pDnd); - *pEpSet = pDnd->d.shellEpSet; - dndUnLockDnode(pDnd); -} - -void dndSendRedirectMsg(SDnode *pDnd, SRpcMsg *pMsg, bool forShell) { +void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { int32_t msgType = pMsg->msgType; SEpSet epSet = {0}; - if (forShell) { - dndGetShellEpSet(pDnd, &epSet); - } else { - dndGetMnodeEpSet(pDnd, &epSet); - } - - dDebug("RPC %p, msg:%s is redirected, num:%d use:%d", pMsg->handle, taosMsg[msgType], epSet.numOfEps, epSet.inUse); + dndGetMnodeEpSet(pDnode, &epSet); + dDebug("RPC %p, msg:%s is redirected, num:%d inUse:%d", pMsg->handle, taosMsg[msgType], epSet.numOfEps, epSet.inUse); for (int32_t i = 0; i < epSet.numOfEps; ++i) { dDebug("mnode index:%d %s:%u", i, epSet.fqdn[i], epSet.port[i]); - if (strcmp(epSet.fqdn[i], pDnd->opt.localFqdn) == 0) { - if ((epSet.port[i] == pDnd->opt.serverPort + TSDB_PORT_DNODEDNODE && !forShell) || - (epSet.port[i] == pDnd->opt.serverPort && forShell)) { - epSet.inUse = (i + 1) % epSet.numOfEps; - dDebug("mnode index:%d %s:%d set inUse to %d", i, epSet.fqdn[i], epSet.port[i], epSet.inUse); - } + if (strcmp(epSet.fqdn[i], pDnode->opt.localFqdn) == 0 && epSet.port[i] == pDnode->opt.serverPort) { + epSet.inUse = (i + 1) % epSet.numOfEps; } epSet.port[i] = htons(epSet.port[i]); @@ -96,220 +85,218 @@ void dndSendRedirectMsg(SDnode *pDnd, SRpcMsg *pMsg, bool forShell) { } static void dndUpdateMnodeEpSet(SDnode *pDnd, SEpSet *pEpSet) { - dInfo("mnode is changed, num:%d use:%d", pEpSet->numOfEps, pEpSet->inUse); + dInfo("mnode is changed, num:%d inUse:%d", pEpSet->numOfEps, pEpSet->inUse); - dndLockDnode(pDnd); + dndWLockDnode(pDnd); - pDnd->d.peerEpSet = *pEpSet; + pDnd->dmgmt.mnodeEpSet = *pEpSet; for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { - pEpSet->port[i] -= TSDB_PORT_DNODEDNODE; dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]); } - pDnd->d.shellEpSet = *pEpSet; - dndUnLockDnode(pDnd); + dndWUnLockDnode(pDnd); } -static void dndPrintDnodes(SDnode *pDnd) { - SDnodeMgmt *pDnode = &pDnd->d; +static void dndPrintDnodes(SDnode *pDnode) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; - dDebug("print dnode endpoint list, num:%d", pDnode->dnodeEps->num); - for (int32_t i = 0; i < pDnode->dnodeEps->num; i++) { - SDnodeEp *pEp = &pDnode->dnodeEps->eps[i]; + dDebug("print dnode ep list, num:%d", pMgmt->dnodeEps->num); + for (int32_t i = 0; i < pMgmt->dnodeEps->num; i++) { + SDnodeEp *pEp = &pMgmt->dnodeEps->eps[i]; dDebug("dnode:%d, fqdn:%s port:%u isMnode:%d", pEp->id, pEp->fqdn, pEp->port, pEp->isMnode); } } -static void dndResetDnodes(SDnode *pDnd, SDnodeEps *pDnodeEps) { - SDnodeMgmt *pDnode = &pDnd->d; +static void dndResetDnodes(SDnode *pDnode, SDnodeEps *pDnodeEps) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; int32_t size = sizeof(SDnodeEps) + pDnodeEps->num * sizeof(SDnodeEp); - - if (pDnodeEps->num > pDnode->dnodeEps->num) { + if (pDnodeEps->num > pMgmt->dnodeEps->num) { SDnodeEps *tmp = calloc(1, size); if (tmp == NULL) return; - tfree(pDnode->dnodeEps); - pDnode->dnodeEps = tmp; + tfree(pMgmt->dnodeEps); + pMgmt->dnodeEps = tmp; } - if (pDnode->dnodeEps != pDnodeEps) { - memcpy(pDnode->dnodeEps, pDnodeEps, size); + if (pMgmt->dnodeEps != pDnodeEps) { + memcpy(pMgmt->dnodeEps, pDnodeEps, size); } - pDnode->peerEpSet.inUse = 0; - pDnode->shellEpSet.inUse = 0; + pMgmt->mnodeEpSet.inUse = 0; int32_t mIndex = 0; - for (int32_t i = 0; i < pDnode->dnodeEps->num; i++) { - SDnodeEp *pDnodeEp = &pDnode->dnodeEps->eps[i]; + for (int32_t i = 0; i < pMgmt->dnodeEps->num; i++) { + SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i]; if (!pDnodeEp->isMnode) continue; if (mIndex >= TSDB_MAX_REPLICA) continue; - strcpy(pDnode->shellEpSet.fqdn[mIndex], pDnodeEp->fqdn); - strcpy(pDnode->peerEpSet.fqdn[mIndex], pDnodeEp->fqdn); - pDnode->shellEpSet.port[mIndex] = pDnodeEp->port; - pDnode->shellEpSet.port[mIndex] = pDnodeEp->port + TSDB_PORT_DNODEDNODE; + strcpy(pMgmt->mnodeEpSet.fqdn[mIndex], pDnodeEp->fqdn); + pMgmt->mnodeEpSet.port[mIndex] = pDnodeEp->port; mIndex++; } - for (int32_t i = 0; i < pDnode->dnodeEps->num; ++i) { - SDnodeEp *pDnodeEp = &pDnode->dnodeEps->eps[i]; - taosHashPut(pDnode->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); + for (int32_t i = 0; i < pMgmt->dnodeEps->num; ++i) { + SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i]; + taosHashPut(pMgmt->dnodeHash, &pDnodeEp->id, sizeof(int32_t), pDnodeEp, sizeof(SDnodeEp)); } - dndPrintDnodes(pDnd); + dndPrintDnodes(pDnode); } -static bool dndIsEpChanged(SDnode *pDnd, int32_t dnodeId) { +static bool dndIsEpChanged(SDnode *pDnode, int32_t dnodeId, char *pEp) { bool changed = false; - dndLockDnode(pDnd); + dndRLockDnode(pDnode); - SDnodeEp *pDnodeEp = taosHashGet(pDnd->d.dnodeHash, &dnodeId, sizeof(int32_t)); + SDnodeEp *pDnodeEp = taosHashGet(pDnode->dmgmt.dnodeHash, &dnodeId, sizeof(int32_t)); if (pDnodeEp != NULL) { char epstr[TSDB_EP_LEN + 1]; snprintf(epstr, TSDB_EP_LEN, "%s:%u", pDnodeEp->fqdn, pDnodeEp->port); - changed = strcmp(pDnd->opt.localEp, epstr) != 0; + changed = strcmp(pEp, epstr) != 0; } - dndUnLockDnode(pDnd); + dndRUnLockDnode(pDnode); return changed; } -static int32_t dndReadDnodes(SDnode *pDnd) { - SDnodeMgmt *pDnode = &pDnd->d; +static int32_t dndReadDnodes(SDnode *pDnode) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + int32_t code = TSDB_CODE_DND_DNODE_READ_FILE_ERROR; int32_t len = 0; int32_t maxLen = 30000; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; FILE *fp = NULL; - fp = fopen(pDnode->file, "r"); - if (!fp) { - dDebug("file %s not exist", pDnode->file); + fp = fopen(pMgmt->file, "r"); + if (fp == NULL) { + dDebug("file %s not exist", pMgmt->file); + code = 0; goto PRASE_DNODE_OVER; } len = (int32_t)fread(content, 1, maxLen, fp); if (len <= 0) { - dError("failed to read %s since content is null", pDnode->file); + dError("failed to read %s since content is null", pMgmt->file); goto PRASE_DNODE_OVER; } content[len] = 0; root = cJSON_Parse(content); if (root == NULL) { - dError("failed to read %s since invalid json format", pDnode->file); + dError("failed to read %s since invalid json format", pMgmt->file); goto PRASE_DNODE_OVER; } cJSON *dnodeId = cJSON_GetObjectItem(root, "dnodeId"); if (!dnodeId || dnodeId->type != cJSON_String) { - dError("failed to read %s since dnodeId not found", pDnode->file); + dError("failed to read %s since dnodeId not found", pMgmt->file); goto PRASE_DNODE_OVER; } - pDnode->dnodeId = atoi(dnodeId->valuestring); + pMgmt->dnodeId = atoi(dnodeId->valuestring); cJSON *clusterId = cJSON_GetObjectItem(root, "clusterId"); if (!clusterId || clusterId->type != cJSON_String) { - dError("failed to read %s since clusterId not found", pDnode->file); + dError("failed to read %s since clusterId not found", pMgmt->file); goto PRASE_DNODE_OVER; } - pDnode->clusterId = atoll(clusterId->valuestring); + pMgmt->clusterId = atoll(clusterId->valuestring); cJSON *dropped = cJSON_GetObjectItem(root, "dropped"); if (!dropped || dropped->type != cJSON_String) { - dError("failed to read %s since dropped not found", pDnode->file); + dError("failed to read %s since dropped not found", pMgmt->file); goto PRASE_DNODE_OVER; } - pDnode->dropped = atoi(dropped->valuestring); + pMgmt->dropped = atoi(dropped->valuestring); cJSON *dnodeInfos = cJSON_GetObjectItem(root, "dnodeInfos"); if (!dnodeInfos || dnodeInfos->type != cJSON_Array) { - dError("failed to read %s since dnodeInfos not found", pDnode->file); + dError("failed to read %s since dnodeInfos not found", pMgmt->file); goto PRASE_DNODE_OVER; } int32_t dnodeInfosSize = cJSON_GetArraySize(dnodeInfos); if (dnodeInfosSize <= 0) { - dError("failed to read %s since dnodeInfos size:%d invalid", pDnode->file, dnodeInfosSize); + dError("failed to read %s since dnodeInfos size:%d invalid", pMgmt->file, dnodeInfosSize); goto PRASE_DNODE_OVER; } - pDnode->dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps)); - if (pDnode->dnodeEps == NULL) { + pMgmt->dnodeEps = calloc(1, dnodeInfosSize * sizeof(SDnodeEp) + sizeof(SDnodeEps)); + if (pMgmt->dnodeEps == NULL) { dError("failed to calloc dnodeEpList since %s", strerror(errno)); goto PRASE_DNODE_OVER; } - pDnode->dnodeEps->num = dnodeInfosSize; + pMgmt->dnodeEps->num = dnodeInfosSize; for (int32_t i = 0; i < dnodeInfosSize; ++i) { cJSON *dnodeInfo = cJSON_GetArrayItem(dnodeInfos, i); if (dnodeInfo == NULL) break; - SDnodeEp *pDnodeEp = &pDnode->dnodeEps->eps[i]; + SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i]; cJSON *dnodeId = cJSON_GetObjectItem(dnodeInfo, "dnodeId"); if (!dnodeId || dnodeId->type != cJSON_String) { - dError("failed to read %s, dnodeId not found", pDnode->file); + dError("failed to read %s, dnodeId not found", pMgmt->file); goto PRASE_DNODE_OVER; } pDnodeEp->id = atoi(dnodeId->valuestring); cJSON *isMnode = cJSON_GetObjectItem(dnodeInfo, "isMnode"); if (!isMnode || isMnode->type != cJSON_String) { - dError("failed to read %s, isMnode not found", pDnode->file); + dError("failed to read %s, isMnode not found", pMgmt->file); goto PRASE_DNODE_OVER; } pDnodeEp->isMnode = atoi(isMnode->valuestring); cJSON *dnodeFqdn = cJSON_GetObjectItem(dnodeInfo, "dnodeFqdn"); if (!dnodeFqdn || dnodeFqdn->type != cJSON_String || dnodeFqdn->valuestring == NULL) { - dError("failed to read %s, dnodeFqdn not found", pDnode->file); + dError("failed to read %s, dnodeFqdn not found", pMgmt->file); goto PRASE_DNODE_OVER; } tstrncpy(pDnodeEp->fqdn, dnodeFqdn->valuestring, TSDB_FQDN_LEN); cJSON *dnodePort = cJSON_GetObjectItem(dnodeInfo, "dnodePort"); if (!dnodePort || dnodePort->type != cJSON_String) { - dError("failed to read %s, dnodePort not found", pDnode->file); + dError("failed to read %s, dnodePort not found", pMgmt->file); goto PRASE_DNODE_OVER; } pDnodeEp->port = atoi(dnodePort->valuestring); } - dInfo("succcessed to read file %s", pDnode->file); - dndPrintDnodes(pDnd); + code = 0; + dInfo("succcessed to read file %s", pMgmt->file); + dndPrintDnodes(pDnode); PRASE_DNODE_OVER: if (content != NULL) free(content); if (root != NULL) cJSON_Delete(root); if (fp != NULL) fclose(fp); - if (dndIsEpChanged(pDnd, pDnode->dnodeId)) { - dError("localEp %s different with %s and need reconfigured", pDnd->opt.localEp, pDnode->file); + if (dndIsEpChanged(pDnode, pMgmt->dnodeId, pDnode->opt.localEp)) { + dError("localEp %s different with %s and need reconfigured", pDnode->opt.localEp, pMgmt->file); return -1; } - if (pDnode->dnodeEps == NULL) { - pDnode->dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp)); - pDnode->dnodeEps->num = 1; - pDnode->dnodeEps->eps[0].port = pDnd->opt.serverPort; - tstrncpy(pDnode->dnodeEps->eps[0].fqdn, pDnd->opt.localFqdn, TSDB_FQDN_LEN); + if (pMgmt->dnodeEps == NULL) { + pMgmt->dnodeEps = calloc(1, sizeof(SDnodeEps) + sizeof(SDnodeEp)); + pMgmt->dnodeEps->num = 1; + pMgmt->dnodeEps->eps[0].port = pDnode->opt.serverPort; + tstrncpy(pMgmt->dnodeEps->eps[0].fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN); } - dndResetDnodes(pDnd, pDnode->dnodeEps); + dndResetDnodes(pDnode, pMgmt->dnodeEps); terrno = 0; return 0; } -static int32_t dndWriteDnodes(SDnode *pDnd) { - SDnodeMgmt *pDnode = &pDnd->d; +static int32_t dndWriteDnodes(SDnode *pDnode) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; - FILE *fp = fopen(pDnode->file, "w"); - if (!fp) { - dError("failed to write %s since %s", pDnode->file, strerror(errno)); + FILE *fp = fopen(pMgmt->file, "w"); + if (fp == NULL) { + dError("failed to write %s since %s", pMgmt->file, strerror(errno)); + terrno = TAOS_SYSTEM_ERROR(errno); return -1; } @@ -318,17 +305,17 @@ static int32_t dndWriteDnodes(SDnode *pDnd) { char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); - len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", pDnode->dnodeId); - len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pDnode->clusterId); - len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", pDnode->dropped); + len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", pMgmt->dnodeId); + len += snprintf(content + len, maxLen - len, " \"clusterId\": \"%" PRId64 "\",\n", pMgmt->clusterId); + len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", pMgmt->dropped); len += snprintf(content + len, maxLen - len, " \"dnodeInfos\": [{\n"); - for (int32_t i = 0; i < pDnode->dnodeEps->num; ++i) { - SDnodeEp *pDnodeEp = &pDnode->dnodeEps->eps[i]; + for (int32_t i = 0; i < pMgmt->dnodeEps->num; ++i) { + SDnodeEp *pDnodeEp = &pMgmt->dnodeEps->eps[i]; len += snprintf(content + len, maxLen - len, " \"dnodeId\": \"%d\",\n", pDnodeEp->id); len += snprintf(content + len, maxLen - len, " \"isMnode\": \"%d\",\n", pDnodeEp->isMnode); len += snprintf(content + len, maxLen - len, " \"dnodeFqdn\": \"%s\",\n", pDnodeEp->fqdn); len += snprintf(content + len, maxLen - len, " \"dnodePort\": \"%u\"\n", pDnodeEp->port); - if (i < pDnode->dnodeEps->num - 1) { + if (i < pMgmt->dnodeEps->num - 1) { len += snprintf(content + len, maxLen - len, " },{\n"); } else { len += snprintf(content + len, maxLen - len, " }]\n"); @@ -342,105 +329,105 @@ static int32_t dndWriteDnodes(SDnode *pDnd) { free(content); terrno = 0; - dInfo("successed to write %s", pDnode->file); + dInfo("successed to write %s", pMgmt->file); return 0; } -static void dndSendStatusMsg(SDnode *pDnd) { - int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad); +static void dndSendStatusMsg(SDnode *pDnode) { + int32_t contLen = sizeof(SStatusMsg) + TSDB_MAX_VNODES * sizeof(SVnodeLoad); + SStatusMsg *pStatus = rpcMallocCont(contLen); if (pStatus == NULL) { dError("failed to malloc status message"); return; } - dndLockDnode(pDnd); - pStatus->sversion = htonl(pDnd->opt.sver); - pStatus->dnodeId = htonl(pDnd->d.dnodeId); - pStatus->clusterId = htobe64(pDnd->d.clusterId); - pStatus->rebootTime = htonl(pDnd->d.rebootTime); - pStatus->numOfCores = htonl(pDnd->opt.numOfCores); - tstrncpy(pStatus->dnodeEp, pDnd->opt.localEp, TSDB_EP_LEN); - pStatus->clusterCfg.statusInterval = htonl(pDnd->opt.statusInterval); - tstrncpy(pStatus->clusterCfg.timezone, pDnd->opt.timezone, TSDB_TIMEZONE_LEN); - tstrncpy(pStatus->clusterCfg.locale, pDnd->opt.locale, TSDB_LOCALE_LEN); - tstrncpy(pStatus->clusterCfg.charset, pDnd->opt.charset, TSDB_LOCALE_LEN); + dndRLockDnode(pDnode); + pStatus->sversion = htonl(pDnode->opt.sver); + pStatus->dnodeId = htonl(pDnode->dmgmt.dnodeId); + pStatus->clusterId = htobe64(pDnode->dmgmt.clusterId); + pStatus->rebootTime = htonl(pDnode->dmgmt.rebootTime); + pStatus->numOfCores = htonl(pDnode->opt.numOfCores); + tstrncpy(pStatus->dnodeEp, pDnode->opt.localEp, TSDB_EP_LEN); + pStatus->clusterCfg.statusInterval = htonl(pDnode->opt.statusInterval); + tstrncpy(pStatus->clusterCfg.timezone, pDnode->opt.timezone, TSDB_TIMEZONE_LEN); + tstrncpy(pStatus->clusterCfg.locale, pDnode->opt.locale, TSDB_LOCALE_LEN); + tstrncpy(pStatus->clusterCfg.charset, pDnode->opt.charset, TSDB_LOCALE_LEN); pStatus->clusterCfg.checkTime = 0; char timestr[32] = "1970-01-01 00:00:00.00"; (void)taosParseTime(timestr, &pStatus->clusterCfg.checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0); - dndUnLockDnode(pDnd); + dndRUnLockDnode(pDnode); - dndGetVnodeLoads(pDnd, &pStatus->vnodeLoads); + dndGetVnodeLoads(pDnode, &pStatus->vnodeLoads); contLen = sizeof(SStatusMsg) + pStatus->vnodeLoads.num * sizeof(SVnodeLoad); SRpcMsg rpcMsg = {.pCont = pStatus, .contLen = contLen, .msgType = TSDB_MSG_TYPE_STATUS}; - dndSendMsgToMnode(pDnd, &rpcMsg); + dndSendMsgToMnode(pDnode, &rpcMsg); } -static void dndUpdateDnodeCfg(SDnode *pDnd, SDnodeCfg *pCfg) { - SDnodeMgmt *pDnode = &pDnd->d; - if (pDnode->dnodeId != 0 && pDnode->dropped != pCfg->dropped) return; +static void dndUpdateDnodeCfg(SDnode *pDnode, SDnodeCfg *pCfg) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; + if (pMgmt->dnodeId == 0 || pMgmt->dropped != pCfg->dropped) { + dInfo("set dnodeId:%d clusterId:%" PRId64 " dropped:%d", pCfg->dnodeId, pCfg->clusterId, pCfg->dropped); - dndLockDnode(pDnd); - - pDnode->dnodeId = pCfg->dnodeId; - pDnode->clusterId = pCfg->clusterId; - pDnode->dropped = pCfg->dropped; - dInfo("set dnodeId:%d clusterId:%" PRId64 " dropped:%d", pCfg->dnodeId, pCfg->clusterId, pCfg->dropped); - - dndWriteDnodes(pDnd); - dndUnLockDnode(pDnd); + dndWLockDnode(pDnode); + pMgmt->dnodeId = pCfg->dnodeId; + pMgmt->clusterId = pCfg->clusterId; + pMgmt->dropped = pCfg->dropped; + (void)dndWriteDnodes(pDnode); + dndWUnLockDnode(pDnode); + } } -static void dndUpdateDnodeEps(SDnode *pDnd, SDnodeEps *pDnodeEps) { +static void dndUpdateDnodeEps(SDnode *pDnode, SDnodeEps *pDnodeEps) { if (pDnodeEps == NULL || pDnodeEps->num <= 0) return; - dndLockDnode(pDnd); + dndWLockDnode(pDnode); - if (pDnodeEps->num != pDnd->d.dnodeEps->num) { - dndResetDnodes(pDnd, pDnodeEps); - dndWriteDnodes(pDnd); + if (pDnodeEps->num != pDnode->dmgmt.dnodeEps->num) { + dndResetDnodes(pDnode, pDnodeEps); + dndWriteDnodes(pDnode); } else { int32_t size = pDnodeEps->num * sizeof(SDnodeEp) + sizeof(SDnodeEps); - if (memcmp(pDnd->d.dnodeEps, pDnodeEps, size) != 0) { - dndResetDnodes(pDnd, pDnodeEps); - dndWriteDnodes(pDnd); + if (memcmp(pDnode->dmgmt.dnodeEps, pDnodeEps, size) != 0) { + dndResetDnodes(pDnode, pDnodeEps); + dndWriteDnodes(pDnode); } } - dndUnLockDnode(pDnd); + dndWUnLockDnode(pDnode); } -static void dndProcessStatusRsp(SDnode *pDnd, SRpcMsg *pMsg, SEpSet *pEpSet) { +static void dndProcessStatusRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { if (pEpSet && pEpSet->numOfEps > 0) { - dndUpdateMnodeEpSet(pDnd, pEpSet); + dndUpdateMnodeEpSet(pDnode, pEpSet); } if (pMsg->code != TSDB_CODE_SUCCESS) return; - SStatusRsp *pStatusRsp = pMsg->pCont; - SDnodeCfg *pCfg = &pStatusRsp->dnodeCfg; + SStatusRsp *pRsp = pMsg->pCont; + SDnodeCfg *pCfg = &pRsp->dnodeCfg; pCfg->dnodeId = htonl(pCfg->dnodeId); pCfg->clusterId = htobe64(pCfg->clusterId); - dndUpdateDnodeCfg(pDnd, pCfg); + dndUpdateDnodeCfg(pDnode, pCfg); if (pCfg->dropped) return; - SDnodeEps *pDnodeEps = &pStatusRsp->dnodeEps; + SDnodeEps *pDnodeEps = &pRsp->dnodeEps; pDnodeEps->num = htonl(pDnodeEps->num); for (int32_t i = 0; i < pDnodeEps->num; ++i) { pDnodeEps->eps[i].id = htonl(pDnodeEps->eps[i].id); pDnodeEps->eps[i].port = htons(pDnodeEps->eps[i].port); } - dndUpdateDnodeEps(pDnd, pDnodeEps); + dndUpdateDnodeEps(pDnode, pDnodeEps); } -static void dndProcessAuthRsp(SDnode *pDnd, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); } +static void dndProcessAuthRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); } -static void dndProcessGrantRsp(SDnode *pDnd, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); } +static void dndProcessGrantRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { assert(1); } -static void dndProcessConfigDnodeReq(SDnode *pDnd, SRpcMsg *pMsg) { +static void dndProcessConfigDnodeReq(SDnode *pDnode, SRpcMsg *pMsg) { SCfgDnodeMsg *pCfg = pMsg->pCont; int32_t code = TSDB_CODE_OPS_NOT_SUPPORT; @@ -449,11 +436,11 @@ static void dndProcessConfigDnodeReq(SDnode *pDnd, SRpcMsg *pMsg) { rpcFreeCont(pMsg->pCont); } -static void dndProcessStartupReq(SDnode *pDnd, SRpcMsg *pMsg) { +static void dndProcessStartupReq(SDnode *pDnode, SRpcMsg *pMsg) { dInfo("startup msg is received"); SStartupMsg *pStartup = rpcMallocCont(sizeof(SStartupMsg)); - dndGetStartup(pDnd, pStartup); + dndGetStartup(pDnode, pStartup); dInfo("startup msg is sent, step:%s desc:%s finished:%d", pStartup->name, pStartup->desc, pStartup->finished); @@ -463,52 +450,52 @@ static void dndProcessStartupReq(SDnode *pDnd, SRpcMsg *pMsg) { } static void *dnodeThreadRoutine(void *param) { - SDnode *pDnd = param; - int32_t ms = pDnd->opt.statusInterval * 1000; + SDnode *pDnode = param; + int32_t ms = pDnode->opt.statusInterval * 1000; while (true) { taosMsleep(ms); - if (dndGetStat(pDnd) != DND_STAT_RUNNING) { + if (dndGetStat(pDnode) != DND_STAT_RUNNING) { continue; } pthread_testcancel(); - dndSendStatusMsg(pDnd); + dndSendStatusMsg(pDnode); } } -int32_t dndInitDnode(SDnode *pDnd) { - SDnodeMgmt *pDnode = &pDnd->d; +int32_t dndInitDnode(SDnode *pDnode) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; - pDnode->dnodeId = 0; - pDnode->rebootTime = taosGetTimestampSec(); - pDnode->dropped = 0; - pDnode->clusterId = 0; + pMgmt->dnodeId = 0; + pMgmt->rebootTime = taosGetTimestampSec(); + pMgmt->dropped = 0; + pMgmt->clusterId = 0; char path[PATH_MAX]; - snprintf(path, PATH_MAX, "%s/dnode.json", pDnd->dir.dnode); - pDnode->file = strdup(path); - if (pDnode->file == NULL) { + snprintf(path, PATH_MAX, "%s/dnode.json", pDnode->dir.dnode); + pMgmt->file = strdup(path); + if (pMgmt->file == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - pDnode->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); - if (pDnode->dnodeHash == NULL) { + pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); + if (pMgmt->dnodeHash == NULL) { dError("failed to init dnode hash"); terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } - if (dndReadDnodes(pDnd) != 0) { - dError("failed to read file:%s since %s", pDnode->file, terrstr()); + if (dndReadDnodes(pDnode) != 0) { + dError("failed to read file:%s since %s", pMgmt->file, terrstr()); return -1; } - pthread_mutex_init(&pDnode->mutex, NULL); + taosInitRWLatch(&pMgmt->latch); - pDnode->threadId = taosCreateThread(dnodeThreadRoutine, pDnd); - if (pDnode->threadId == NULL) { + pMgmt->threadId = taosCreateThread(dnodeThreadRoutine, pDnode); + if (pMgmt->threadId == NULL) { dError("failed to init dnode thread"); terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; @@ -518,44 +505,42 @@ int32_t dndInitDnode(SDnode *pDnd) { return 0; } -void dndCleanupDnode(SDnode *pDnd) { - SDnodeMgmt *pDnode = &pDnd->d; +void dndCleanupDnode(SDnode *pDnode) { + SDnodeMgmt *pMgmt = &pDnode->dmgmt; - if (pDnode->threadId != NULL) { - taosDestoryThread(pDnode->threadId); - pDnode->threadId = NULL; + if (pMgmt->threadId != NULL) { + taosDestoryThread(pMgmt->threadId); + pMgmt->threadId = NULL; } - dndLockDnode(pDnd); + dndWLockDnode(pDnode); - if (pDnode->dnodeEps != NULL) { - free(pDnode->dnodeEps); - pDnode->dnodeEps = NULL; + if (pMgmt->dnodeEps != NULL) { + free(pMgmt->dnodeEps); + pMgmt->dnodeEps = NULL; } - if (pDnode->dnodeHash != NULL) { - taosHashCleanup(pDnode->dnodeHash); - pDnode->dnodeHash = NULL; + if (pMgmt->dnodeHash != NULL) { + taosHashCleanup(pMgmt->dnodeHash); + pMgmt->dnodeHash = NULL; } - if (pDnode->file != NULL) { - free(pDnode->file); - pDnode->file = NULL; + if (pMgmt->file != NULL) { + free(pMgmt->file); + pMgmt->file = NULL; } - dndUnLockDnode(pDnd); - pthread_mutex_destroy(&pDnode->mutex); - + dndWUnLockDnode(pDnode); dInfo("dnd-dnode is cleaned up"); } -void dndProcessDnodeReq(SDnode *pDnd, SRpcMsg *pMsg, SEpSet *pEpSet) { +void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { switch (pMsg->msgType) { case TSDB_MSG_TYPE_NETWORK_TEST: - dndProcessStartupReq(pDnd, pMsg); + dndProcessStartupReq(pDnode, pMsg); break; case TSDB_MSG_TYPE_CONFIG_DNODE_IN: - dndProcessConfigDnodeReq(pDnd, pMsg); + dndProcessConfigDnodeReq(pDnode, pMsg); break; default: dError("RPC %p, dnode req:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]); @@ -565,16 +550,16 @@ void dndProcessDnodeReq(SDnode *pDnd, SRpcMsg *pMsg, SEpSet *pEpSet) { } } -void dndProcessDnodeRsp(SDnode *pDnd, SRpcMsg *pMsg, SEpSet *pEpSet) { +void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { switch (pMsg->msgType) { case TSDB_MSG_TYPE_STATUS_RSP: - dndProcessStatusRsp(pDnd, pMsg, pEpSet); + dndProcessStatusRsp(pDnode, pMsg, pEpSet); break; case TSDB_MSG_TYPE_AUTH_RSP: - dndProcessAuthRsp(pDnd, pMsg, pEpSet); + dndProcessAuthRsp(pDnode, pMsg, pEpSet); break; case TSDB_MSG_TYPE_GRANT_RSP: - dndProcessGrantRsp(pDnd, pMsg, pEpSet); + dndProcessGrantRsp(pDnode, pMsg, pEpSet); break; default: dError("RPC %p, dnode rsp:%s not processed", pMsg->handle, taosMsg[pMsg->msgType]); diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 5eff8a37ca..bd89476cef 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -53,7 +53,7 @@ void mnodeSendMsgToMnode(SMnode *pMnode, struct SRpcMsg *rpcMsg) { void mnodeSendRedirectMsg(SMnode *pMnode, struct SRpcMsg *rpcMsg, bool forShell) { assert(pMnode); - (*pMnode->sendRedirectMsgFp)(pMnode->pServer, rpcMsg, forShell); + (*pMnode->sendRedirectMsgFp)(pMnode->pServer, rpcMsg); } static int32_t mnodeInitTimer() { From c0ca718eed2cc78deaea4773df12f0d951a78ec7 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 26 Nov 2021 11:29:43 +0800 Subject: [PATCH 05/16] update fst core struct --- source/libs/index/inc/index_fst.h | 4 +- source/libs/index/inc/index_fst_util.h | 4 +- source/libs/index/src/index_fst.c | 57 ++++++++++++++++++++++++++ source/libs/index/src/index_fst_util.c | 2 +- 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 87d740ddd9..44b6162d49 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -230,10 +230,12 @@ typedef struct FstMeta { } FstMeta; typedef struct Fst { - FstMeta meta; + FstMeta *meta; void *data; // } Fst; +Fst* fstCreate(FstSlice *data); +void fstDestroy(Fst *fst); // ops typedef struct FstIndexedValue { diff --git a/source/libs/index/inc/index_fst_util.h b/source/libs/index/inc/index_fst_util.h index 5b84632418..ff0946063d 100644 --- a/source/libs/index/inc/index_fst_util.h +++ b/source/libs/index/inc/index_fst_util.h @@ -32,9 +32,9 @@ extern const CompiledAddr EMPTY_ADDRESS; extern const CompiledAddr NONE_ADDRESS; // This version number is written to every finite state transducer created by -// this crate. When a finite state transducer is read, its version number is +// this version When a finite state transducer is read, its version number is // checked against this value. -extern const uint64_t version; +extern const uint64_t VERSION; // The threshold (in number of transitions) at which an index is created for // a node's transitions. This speeds up lookup time at the expense of FST size diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index f8fc40fcb6..70633de0e8 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -919,4 +919,61 @@ void fstBuilderNodeUnfinishedAddOutputPrefix(FstBuilderNodeUnfinished *unNode, O return; } +Fst* fstCreate(FstSlice *slice) { + + char *buf = slice->data; + uint64_t skip = 0; + uint64_t len = slice->dLen; + if (len < 36) { + return NULL; + } + + uint64_t version; + taosDecodeFixedU64(buf, &version); + skip += sizeof(version); + if (version == 0 || version > VERSION) { + return NULL; + } + + uint64_t type; + taosDecodeFixedU64(buf + skip, &type); + skip += sizeof(type); + + uint32_t checkSum = 0; + len -= sizeof(checkSum); + taosDecodeFixedU32(buf + len, &checkSum); + + CompiledAddr rootAddr; + len -= sizeof(rootAddr); + taosDecodeFixedU64(buf + len, &rootAddr); + + uint64_t fstLen; + len -= sizeof(fstLen); + taosDecodeFixedU64(buf + len, &fstLen); + //TODO(validat root addr) + // + Fst *fst= (Fst *)calloc(1, sizeof(Fst)); + if (fst == NULL) { return NULL; } + + fst->meta = (FstMeta *)malloc(sizeof(FstMeta)); + if (NULL == fst->meta) { + goto FST_CREAT_FAILED; + } + + fst->meta->version = version; + fst->meta->rootAddr = rootAddr; + fst->meta->ty = type; + fst->meta->len = fstLen; + fst->meta->checkSum = checkSum; + return fst; + +FST_CREAT_FAILED: + free(fst->meta); + free(fst); + +} +void fstDestroy(Fst *fst) { + +} + diff --git a/source/libs/index/src/index_fst_util.c b/source/libs/index/src/index_fst_util.c index c4499f8e0d..94bf650acd 100644 --- a/source/libs/index/src/index_fst_util.c +++ b/source/libs/index/src/index_fst_util.c @@ -25,7 +25,7 @@ const CompiledAddr NONE_ADDRESS = 1; // This version number is written to every finite state transducer created by // this crate. When a finite state transducer is read, its version number is // checked against this value. -const uint64_t version = 3; +const uint64_t VERSION = 3; // The threshold (in number of transitions) at which an index is created for // a node's transitions. This speeds up lookup time at the expense of FST size From b6c28a4914f2418194b1c79c8a85af0c971f7887 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 26 Nov 2021 11:42:56 +0800 Subject: [PATCH 06/16] update authentications --- source/dnode/mgmt/impl/inc/dndInt.h | 4 +- source/dnode/mgmt/impl/src/dndDnode.c | 8 +-- source/dnode/mgmt/impl/src/dndMnode.c | 76 +++++++++++----------- source/dnode/mgmt/impl/src/dndTransport.c | 78 +++++++++++++++++------ source/dnode/mnode/impl/src/mnodeAuth.c | 11 ---- 5 files changed, 101 insertions(+), 76 deletions(-) diff --git a/source/dnode/mgmt/impl/inc/dndInt.h b/source/dnode/mgmt/impl/inc/dndInt.h index 258f40aad6..4094871bcd 100644 --- a/source/dnode/mgmt/impl/inc/dndInt.h +++ b/source/dnode/mgmt/impl/inc/dndInt.h @@ -109,9 +109,9 @@ typedef struct SDnode { SDnodeOpt opt; SDnodeDir dir; SDnodeMgmt dmgmt; - SMnodeMgmt m; + SMnodeMgmt mmgmt; SVnodesMgmt vmgmt; - STransMgmt t; + STransMgmt tmgmt; SStartupMsg startup; } SDnode; diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index 962ce2b73d..fcafaf828f 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -84,17 +84,17 @@ void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg) { rpcSendRedirectRsp(pMsg->handle, &epSet); } -static void dndUpdateMnodeEpSet(SDnode *pDnd, SEpSet *pEpSet) { +static void dndUpdateMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet) { dInfo("mnode is changed, num:%d inUse:%d", pEpSet->numOfEps, pEpSet->inUse); - dndWLockDnode(pDnd); + dndWLockDnode(pDnode); - pDnd->dmgmt.mnodeEpSet = *pEpSet; + pDnode->dmgmt.mnodeEpSet = *pEpSet; for (int32_t i = 0; i < pEpSet->numOfEps; ++i) { dInfo("mnode index:%d %s:%u", i, pEpSet->fqdn[i], pEpSet->port[i]); } - dndWUnLockDnode(pDnd); + dndWUnLockDnode(pDnode); } static void dndPrintDnodes(SDnode *pDnode) { diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index 5f3e48d8a1..d581c7761c 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -67,7 +67,7 @@ static int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); static int32_t dndProcessDropMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); static SMnode *dndAcquireMnode(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = NULL; int32_t refCount = 0; @@ -85,7 +85,7 @@ static SMnode *dndAcquireMnode(SDnode *pDnode) { } static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; int32_t refCount = 0; taosRLockLatch(&pMgmt->latch); @@ -98,7 +98,7 @@ static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode) { } static int32_t dndReadMnodeFile(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; int32_t code = TSDB_CODE_DND_MNODE_READ_FILE_ERROR; int32_t len = 0; int32_t maxLen = 300; @@ -152,7 +152,7 @@ PRASE_MNODE_OVER: } static int32_t dndWriteMnodeFile(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; char file[PATH_MAX + 20] = {0}; snprintf(file, sizeof(file), "%s.bak", pMgmt->file); @@ -212,7 +212,7 @@ static int32_t dndStartMnodeWorker(SDnode *pDnode) { } static void dndStopMnodeWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; taosWLockLatch(&pMgmt->latch); pMgmt->deployed = 0; @@ -296,7 +296,7 @@ static int32_t dndBuildMnodeOptions(SDnode *pDnode, SMnodeOptions *pOptions, SCr } static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOptions *pOptions) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; int32_t code = dndStartMnodeWorker(pDnode); if (code != 0) { @@ -332,7 +332,7 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOptions *pOptions) { } static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOptions *pOptions) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode == NULL) { @@ -351,7 +351,7 @@ static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOptions *pOptions) { } static int32_t dndDropMnode(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode == NULL) { @@ -458,7 +458,7 @@ static void dndProcessMnodeMgmtQueue(SDnode *pDnode, SRpcMsg *pMsg) { } static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { @@ -472,7 +472,7 @@ static void dndProcessMnodeReadQueue(SDnode *pDnode, SMnodeMsg *pMsg) { } static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { @@ -486,7 +486,7 @@ static void dndProcessMnodeWriteQueue(SDnode *pDnode, SMnodeMsg *pMsg) { } static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { @@ -500,7 +500,7 @@ static void dndProcessMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { } static void dndProcessMnodeSyncQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode != NULL) { @@ -532,7 +532,7 @@ static int32_t dndWriteMnodeMsgToQueue(SMnode *pMnode, taos_queue pQueue, SRpcMs } void dndProcessMnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); SRpcMsg *pMsg = taosAllocateQitem(sizeof(SRpcMsg)); @@ -545,7 +545,7 @@ void dndProcessMnodeMgmtMsg(SDnode *pDnode, SRpcMsg *pRpcMsg, SEpSet *pEpSet) { } void dndProcessMnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode == NULL || dndWriteMnodeMsgToQueue(pMnode, pMgmt->pWriteQ, pMsg) != 0) { SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno}; @@ -557,7 +557,7 @@ void dndProcessMnodeWriteMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { } void dndProcessMnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode == NULL || dndWriteMnodeMsgToQueue(pMnode, pMgmt->pSyncQ, pMsg) != 0) { SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno}; @@ -569,7 +569,7 @@ void dndProcessMnodeSyncMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { } void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode == NULL || dndWriteMnodeMsgToQueue(pMnode, pMgmt->pSyncQ, pMsg) != 0) { SRpcMsg rsp = {.handle = pMsg->handle, .code = terrno}; @@ -581,7 +581,7 @@ void dndProcessMnodeReadMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { } static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode == NULL) { @@ -594,7 +594,7 @@ static int32_t dndPutMsgIntoMnodeApplyQueue(SDnode *pDnode, SMnodeMsg *pMsg) { } static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; pMgmt->pMgmtQ = tWorkerAllocQueue(&pMgmt->mgmtPool, NULL, (FProcessItem)dndProcessMnodeMgmtQueue); if (pMgmt->pMgmtQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -604,13 +604,13 @@ static int32_t dndAllocMnodeMgmtQueue(SDnode *pDnode) { } static void dndFreeMnodeMgmtQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerFreeQueue(&pMgmt->mgmtPool, pMgmt->pMgmtQ); pMgmt->pMgmtQ = NULL; } static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SWorkerPool *pPool = &pMgmt->mgmtPool; pPool->name = "mnode-mgmt"; pPool->min = 1; @@ -624,13 +624,13 @@ static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) { } static void dndCleanupMnodeMgmtWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; ; tWorkerCleanup(&pMgmt->mgmtPool); } static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; pMgmt->pReadQ = tWorkerAllocQueue(&pMgmt->readPool, NULL, (FProcessItem)dndProcessMnodeReadQueue); if (pMgmt->pReadQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -640,13 +640,13 @@ static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) { } static void dndFreeMnodeReadQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerFreeQueue(&pMgmt->readPool, pMgmt->pReadQ); pMgmt->pReadQ = NULL; } static int32_t dndInitMnodeReadWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SWorkerPool *pPool = &pMgmt->readPool; pPool->name = "mnode-read"; pPool->min = 0; @@ -660,12 +660,12 @@ static int32_t dndInitMnodeReadWorker(SDnode *pDnode) { } static void dndCleanupMnodeReadWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->readPool); } static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; pMgmt->pWriteQ = tWorkerAllocQueue(&pMgmt->writePool, NULL, (FProcessItem)dndProcessMnodeWriteQueue); if (pMgmt->pWriteQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -675,13 +675,13 @@ static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) { } static void dndFreeMnodeWriteQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerFreeQueue(&pMgmt->writePool, pMgmt->pWriteQ); pMgmt->pWriteQ = NULL; } static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; pMgmt->pApplyQ = tWorkerAllocQueue(&pMgmt->writePool, NULL, (FProcessItem)dndProcessMnodeApplyQueue); if (pMgmt->pApplyQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -691,13 +691,13 @@ static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) { } static void dndFreeMnodeApplyQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerFreeQueue(&pMgmt->writePool, pMgmt->pApplyQ); pMgmt->pApplyQ = NULL; } static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SWorkerPool *pPool = &pMgmt->writePool; pPool->name = "mnode-write"; pPool->min = 0; @@ -711,12 +711,12 @@ static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) { } static void dndCleanupMnodeWriteWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->writePool); } static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; pMgmt->pSyncQ = tWorkerAllocQueue(&pMgmt->syncPool, NULL, (FProcessItem)dndProcessMnodeSyncQueue); if (pMgmt->pSyncQ == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; @@ -726,13 +726,13 @@ static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) { } static void dndFreeMnodeSyncQueue(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerFreeQueue(&pMgmt->syncPool, pMgmt->pSyncQ); pMgmt->pSyncQ = NULL; } static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SWorkerPool *pPool = &pMgmt->syncPool; pPool->name = "mnode-sync"; pPool->min = 0; @@ -741,13 +741,13 @@ static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) { } static void dndCleanupMnodeSyncWorker(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->syncPool); } int32_t dndInitMnode(SDnode *pDnode) { dInfo("dnode-mnode start to init"); - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; taosInitRWLatch(&pMgmt->latch); if (dndInitMnodeMgmtWorker(pDnode) != 0) { @@ -791,7 +791,7 @@ int32_t dndInitMnode(SDnode *pDnode) { } void dndCleanupMnode(SDnode *pDnode) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; dInfo("dnode-mnode start to clean up"); dndStopMnodeWorker(pDnode); @@ -801,7 +801,7 @@ void dndCleanupMnode(SDnode *pDnode) { } int32_t dndGetUserAuthFromMnode(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { - SMnodeMgmt *pMgmt = &pDnode->m; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); if (pMnode == NULL) { diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index 679e3ef5f9..d5f52bac8b 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -25,6 +25,10 @@ #include "dndMnode.h" #include "dndVnodes.h" +#define INTERNAL_USER "_internal" +#define INTERNAL_CKEY "_key" +#define INTERNAL_SECRET "_secret" + static void dndInitMsgFp(STransMgmt *pMgmt) { // msg from client to dnode pMgmt->msgFp[TSDB_MSG_TYPE_SUBMIT] = dndProcessVnodeWriteMsg; @@ -121,7 +125,7 @@ static void dndInitMsgFp(STransMgmt *pMgmt) { static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { SDnode *pDnode = parent; - STransMgmt *pMgmt = &pDnode->t; + STransMgmt *pMgmt = &pDnode->tmgmt; int32_t msgType = pMsg->msgType; @@ -143,19 +147,19 @@ static void dndProcessResponse(void *parent, SRpcMsg *pMsg, SEpSet *pEpSet) { } static int32_t dndInitClient(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->t; + STransMgmt *pMgmt = &pDnode->tmgmt; SRpcInit rpcInit; memset(&rpcInit, 0, sizeof(rpcInit)); rpcInit.label = "DND-C"; rpcInit.numOfThreads = 1; rpcInit.cfp = dndProcessResponse; - rpcInit.sessions = TSDB_MAX_VNODES << 4; + rpcInit.sessions = 8; rpcInit.connType = TAOS_CONN_CLIENT; rpcInit.idleTime = pDnode->opt.shellActivityTimer * 1000; - rpcInit.user = "-internal"; - rpcInit.ckey = "-key"; - rpcInit.secret = "-secret"; + rpcInit.user = INTERNAL_USER; + rpcInit.ckey = INTERNAL_CKEY; + rpcInit.secret = INTERNAL_SECRET; pMgmt->clientRpc = rpcOpen(&rpcInit); if (pMgmt->clientRpc == NULL) { @@ -167,7 +171,7 @@ static int32_t dndInitClient(SDnode *pDnode) { } static void dndCleanupClient(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->t; + STransMgmt *pMgmt = &pDnode->tmgmt; if (pMgmt->clientRpc) { rpcClose(pMgmt->clientRpc); pMgmt->clientRpc = NULL; @@ -176,8 +180,8 @@ static void dndCleanupClient(SDnode *pDnode) { } static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { - SDnode *pDnode = param; - STransMgmt *pMgmt = &pDnode->t; + SDnode *pDnode = param; + STransMgmt *pMgmt = &pDnode->tmgmt; int32_t msgType = pMsg->msgType; if (msgType == TSDB_MSG_TYPE_NETWORK_TEST) { @@ -218,24 +222,56 @@ static void dndProcessRequest(void *param, SRpcMsg *pMsg, SEpSet *pEpSet) { } static void dndSendMsgToMnodeRecv(SDnode *pDnode, SRpcMsg *pRpcMsg, SRpcMsg *pRpcRsp) { - STransMgmt *pMgmt = &pDnode->t; + STransMgmt *pMgmt = &pDnode->tmgmt; SEpSet epSet = {0}; dndGetMnodeEpSet(pDnode, &epSet); rpcSendRecv(pMgmt->clientRpc, &epSet, pRpcMsg, pRpcRsp); } +static int32_t dndAuthInternalMsg(SDnode *pDnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { + if (strcmp(user, INTERNAL_USER) == 0) { + // A simple temporary implementation + char pass[32] = {0}; + taosEncryptPass((uint8_t *)(INTERNAL_SECRET), strlen(INTERNAL_SECRET), pass); + memcpy(secret, pass, TSDB_KEY_LEN); + *spi = 0; + *encrypt = 0; + *ckey = 0; + return 0; + } else if (strcmp(user, TSDB_NETTEST_USER) == 0) { + // A simple temporary implementation + char pass[32] = {0}; + taosEncryptPass((uint8_t *)(TSDB_NETTEST_USER), strlen(TSDB_NETTEST_USER), pass); + memcpy(secret, pass, TSDB_KEY_LEN); + *spi = 0; + *encrypt = 0; + *ckey = 0; + return 0; + } else { + return -1; + } +} + static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char *encrypt, char *secret, char *ckey) { SDnode *pDnode = parent; - if (dndGetUserAuthFromMnode(pDnode, user, spi, encrypt, secret, ckey) != 0) { - if (terrno != TSDB_CODE_APP_NOT_READY) { - dTrace("failed to get user auth from mnode since %s", terrstr()); - return -1; - } + if (dndAuthInternalMsg(parent, user, spi, encrypt, secret, ckey) == 0) { + dTrace("get internal auth success"); + return 0; } - dDebug("user:%s, send auth msg to mnodes", user); + if (dndGetUserAuthFromMnode(pDnode, user, spi, encrypt, secret, ckey) == 0) { + dTrace("get auth from internal mnode"); + return 0; + } + + if (terrno != TSDB_CODE_APP_NOT_READY) { + dTrace("failed to get user auth from internal mnode since %s", terrstr()); + return -1; + } + + dDebug("user:%s, send auth msg to other mnodes", user); SAuthMsg *pMsg = rpcMallocCont(sizeof(SAuthMsg)); tstrncpy(pMsg->user, user, TSDB_USER_LEN); @@ -246,14 +282,14 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char if (rpcRsp.code != 0) { terrno = rpcRsp.code; - dError("user:%s, failed to get user auth from mnodes since %s", user, terrstr()); + dError("user:%s, failed to get user auth from other mnodes since %s", user, terrstr()); } else { SAuthRsp *pRsp = rpcRsp.pCont; memcpy(secret, pRsp->secret, TSDB_KEY_LEN); memcpy(ckey, pRsp->ckey, TSDB_KEY_LEN); *spi = pRsp->spi; *encrypt = pRsp->encrypt; - dDebug("user:%s, success to get user auth from mnodes", user); + dDebug("user:%s, success to get user auth from other mnodes", user); } rpcFreeCont(rpcRsp.pCont); @@ -261,7 +297,7 @@ static int32_t dndRetrieveUserAuthInfo(void *parent, char *user, char *spi, char } static int32_t dndInitServer(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->t; + STransMgmt *pMgmt = &pDnode->tmgmt; dndInitMsgFp(pMgmt); int32_t numOfThreads = (int32_t)((pDnode->opt.numOfCores * pDnode->opt.numOfThreadsPerCore) / 2.0); @@ -290,7 +326,7 @@ static int32_t dndInitServer(SDnode *pDnode) { } static void dndCleanupServer(SDnode *pDnode) { - STransMgmt *pMgmt = &pDnode->t; + STransMgmt *pMgmt = &pDnode->tmgmt; if (pMgmt->serverRpc) { rpcClose(pMgmt->serverRpc); pMgmt->serverRpc = NULL; @@ -317,7 +353,7 @@ void dndCleanupTrans(SDnode *pDnode) { } void dndSendMsgToDnode(SDnode *pDnode, SEpSet *pEpSet, SRpcMsg *pMsg) { - STransMgmt *pMgmt = &pDnode->t; + STransMgmt *pMgmt = &pDnode->tmgmt; rpcSendRequest(pMgmt->clientRpc, pEpSet, pMsg, NULL); } diff --git a/source/dnode/mnode/impl/src/mnodeAuth.c b/source/dnode/mnode/impl/src/mnodeAuth.c index ddd2b91ff3..f8e704d16d 100644 --- a/source/dnode/mnode/impl/src/mnodeAuth.c +++ b/source/dnode/mnode/impl/src/mnodeAuth.c @@ -21,16 +21,5 @@ int32_t mnodeInitAuth() { return 0; } void mnodeCleanupAuth() {} int32_t mnodeRetriveAuth(SMnode *pMnode, char *user, char *spi, char *encrypt, char *secret, char *ckey) { - if (strcmp(user, TSDB_NETTEST_USER) == 0) { - char pass[32] = {0}; - taosEncryptPass((uint8_t *)user, strlen(user), pass); - *spi = 0; - *encrypt = 0; - *ckey = 0; - memcpy(secret, pass, TSDB_KEY_LEN); - mDebug("nettest user is authorized"); - return 0; - } - return 0; } \ No newline at end of file From 0d57a4beb70e0d1192c1768b4b22d4a02534172b Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 26 Nov 2021 14:15:22 +0800 Subject: [PATCH 07/16] TD-11265 invalid write in dnode.c --- include/dnode/mnode/mnode.h | 8 ++++---- include/dnode/vnode/vnode.h | 8 ++++---- source/dnode/mgmt/daemon/src/daemon.c | 12 ++++++------ source/dnode/mgmt/impl/inc/dndDnode.h | 18 +++++++++--------- source/dnode/mgmt/impl/src/dndDnode.c | 2 +- source/dnode/mgmt/impl/src/dnode.c | 8 ++++---- source/dnode/mnode/impl/inc/mnodeDef.h | 4 ++-- 7 files changed, 30 insertions(+), 30 deletions(-) diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index b7b05f896f..725bdaec3c 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -24,10 +24,10 @@ extern "C" { typedef struct SDnode SDnode; typedef struct SMnode SMnode; typedef struct SMnodeMsg SMnodeMsg; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnd, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg); -typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnd, SMnodeMsg *pMsg); +typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*PutMsgToMnodeQFp)(SDnode *pDnode, SMnodeMsg *pMsg); typedef struct SMnodeLoad { int64_t numOfDnode; diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 8dc01b2a8a..3f6705fac6 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -185,10 +185,10 @@ typedef struct { } SVnodeMsg; typedef struct SDnode SDnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnd, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnd, struct SRpcMsg *rpcMsg); -typedef int32_t (*PutMsgToVnodeQFp)(SDnode *pDnd, int32_t vgId, SVnodeMsg *pMsg); +typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); +typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); +typedef int32_t (*PutMsgToVnodeQFp)(SDnode *pDnode, int32_t vgId, SVnodeMsg *pMsg); typedef struct { PutMsgToVnodeQFp putMsgToApplyQueueFp; diff --git a/source/dnode/mgmt/daemon/src/daemon.c b/source/dnode/mgmt/daemon/src/daemon.c index 4d1116466c..429b097fb8 100644 --- a/source/dnode/mgmt/daemon/src/daemon.c +++ b/source/dnode/mgmt/daemon/src/daemon.c @@ -141,13 +141,13 @@ void dmnInitOption(SDnodeOpt *pOption) { pOption->shellActivityTimer = tsShellActivityTimer; pOption->statusInterval = tsStatusInterval; pOption->serverPort = tsServerPort; - tstrncpy(pOption->dataDir, tsDataDir, TSDB_EP_LEN); + tstrncpy(pOption->dataDir, tsDataDir, PATH_MAX); tstrncpy(pOption->localEp, tsLocalEp, TSDB_EP_LEN); - tstrncpy(pOption->localFqdn, tsLocalEp, TSDB_FQDN_LEN); - tstrncpy(pOption->firstEp, tsFirst, TSDB_FQDN_LEN); - tstrncpy(pOption->timezone, tsLocalEp, TSDB_TIMEZONE_LEN); - tstrncpy(pOption->locale, tsLocalEp, TSDB_LOCALE_LEN); - tstrncpy(pOption->charset, tsLocalEp, TSDB_LOCALE_LEN); + tstrncpy(pOption->localFqdn, tsLocalFqdn, TSDB_FQDN_LEN); + tstrncpy(pOption->firstEp, tsFirst, TSDB_EP_LEN); + tstrncpy(pOption->timezone, tsTimezone, TSDB_TIMEZONE_LEN); + tstrncpy(pOption->locale, tsLocale, TSDB_LOCALE_LEN); + tstrncpy(pOption->charset, tsCharset, TSDB_LOCALE_LEN); } int dmnRunDnode() { diff --git a/source/dnode/mgmt/impl/inc/dndDnode.h b/source/dnode/mgmt/impl/inc/dndDnode.h index 590a9611e1..4bb4cad8cc 100644 --- a/source/dnode/mgmt/impl/inc/dndDnode.h +++ b/source/dnode/mgmt/impl/inc/dndDnode.h @@ -21,16 +21,16 @@ extern "C" { #endif #include "dndInt.h" -int32_t dndInitDnode(SDnode *pDnd); -void dndCleanupDnode(SDnode *pDnd); -void dndProcessDnodeReq(SDnode *pDnd, SRpcMsg *pMsg, SEpSet *pEpSet); -void dndProcessDnodeRsp(SDnode *pDnd, SRpcMsg *pMsg, SEpSet *pEpSet); +int32_t dndInitDnode(SDnode *pDnode); +void dndCleanupDnode(SDnode *pDnode); +void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); +void dndProcessDnodeRsp(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet); -int32_t dndGetDnodeId(SDnode *pDnd); -int64_t dndGetClusterId(SDnode *pDnd); -void dndGetDnodeEp(SDnode *pDnd, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); -void dndGetMnodeEpSet(SDnode *pDnd, SEpSet *pEpSet); -void dndSendRedirectMsg(SDnode *pDnd, SRpcMsg *pMsg); +int32_t dndGetDnodeId(SDnode *pDnode); +int64_t dndGetClusterId(SDnode *pDnode); +void dndGetDnodeEp(SDnode *pDnode, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort); +void dndGetMnodeEpSet(SDnode *pDnode, SEpSet *pEpSet); +void dndSendRedirectMsg(SDnode *pDnode, SRpcMsg *pMsg); #ifdef __cplusplus } diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index fcafaf828f..ef30503494 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -480,7 +480,7 @@ int32_t dndInitDnode(SDnode *pDnode) { return -1; } - pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK); + pMgmt->dnodeHash = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); if (pMgmt->dnodeHash == NULL) { dError("failed to init dnode hash"); terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index 1261136fd3..0bfcf5d721 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -84,13 +84,13 @@ static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOptions) { char path[PATH_MAX + 100]; snprintf(path, sizeof(path), "%s%smnode", pOptions->dataDir, TD_DIRSEP); - pDnode->dir.mnode = strdup(path); + pDnode->dir.mnode = tstrdup(path); snprintf(path, sizeof(path), "%s%svnode", pOptions->dataDir, TD_DIRSEP); - pDnode->dir.vnodes = strdup(path); + pDnode->dir.vnodes = tstrdup(path); snprintf(path, sizeof(path), "%s%sdnode", pOptions->dataDir, TD_DIRSEP); - pDnode->dir.dnode = strdup(path); + pDnode->dir.dnode = tstrdup(path); if (pDnode->dir.mnode == NULL || pDnode->dir.vnodes == NULL || pDnode->dir.dnode == NULL) { dError("failed to malloc dir object"); @@ -140,7 +140,7 @@ SDnode *dndInit(SDnodeOpt *pOptions) { taosBlockSIGPIPE(); taosResolveCRC(); - SDnode *pDnode = calloc(1, sizeof(pDnode)); + SDnode *pDnode = calloc(1, sizeof(SDnode)); if (pDnode == NULL) { dError("failed to create dnode object"); terrno = TSDB_CODE_OUT_OF_MEMORY; diff --git a/source/dnode/mnode/impl/inc/mnodeDef.h b/source/dnode/mnode/impl/inc/mnodeDef.h index 4b4c4abdb3..ccdba13006 100644 --- a/source/dnode/mnode/impl/inc/mnodeDef.h +++ b/source/dnode/mnode/impl/inc/mnodeDef.h @@ -131,7 +131,7 @@ typedef struct SMnodeObj { int64_t roleTime; int64_t createdTime; int64_t updateTime; - SDnodeObj *pDnd; + SDnodeObj *pDnode; } SMnodeObj; typedef struct { @@ -215,7 +215,7 @@ typedef struct SDbObj { typedef struct { int32_t dnodeId; int8_t role; - SDnodeObj *pDnd; + SDnodeObj *pDnode; } SVnodeGid; typedef struct SVgObj { From 9f75ad065284275a8478e01ed9db39c6542fa9fe Mon Sep 17 00:00:00 2001 From: Liu Jicong Date: Fri, 26 Nov 2021 14:22:16 +0800 Subject: [PATCH 08/16] refactor wal --- include/libs/wal/wal.h | 68 +++++++++----- source/libs/wal/inc/walInt.h | 3 + source/libs/wal/src/wal.c | 3 +- source/libs/wal/src/walIndex.c | 85 +++++++++++++++++ source/libs/wal/src/walMgmt.c | 55 +++++------ source/libs/wal/src/walWrite.c | 162 +++++++++++---------------------- 6 files changed, 206 insertions(+), 170 deletions(-) create mode 100644 source/libs/wal/src/walIndex.c diff --git a/include/libs/wal/wal.h b/include/libs/wal/wal.h index 94346d705e..4d5b4d977a 100644 --- a/include/libs/wal/wal.h +++ b/include/libs/wal/wal.h @@ -53,45 +53,63 @@ typedef struct { EWalType walLevel; // wal level } SWalCfg; -#define WAL_PREFIX "wal" -#define WAL_PREFIX_LEN 3 -#define WAL_REFRESH_MS 1000 -#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead) + 16) -#define WAL_SIGNATURE ((uint32_t)(0xFAFBFDFE)) -#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12) -#define WAL_FILE_LEN (WAL_PATH_LEN + 32) -#define WAL_FILE_NUM 1 // 3 +#define WAL_PREFIX "wal" +#define WAL_LOG_SUFFIX "log" +#define WAL_INDEX_SUFFIX "idx" +#define WAL_PREFIX_LEN 3 +#define WAL_REFRESH_MS 1000 +#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead) + 16) +#define WAL_SIGNATURE ((uint32_t)(0xFAFBFDFEUL)) +#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12) +#define WAL_FILE_LEN (WAL_PATH_LEN + 32) +//#define WAL_FILE_NUM 1 // 3 + +#define WAL_CUR_POS_READ_ONLY 1 +#define WAL_CUR_FILE_READ_ONLY 2 typedef struct SWal { - int64_t version; - int64_t fileId; - int64_t rId; - int64_t tfd; - int32_t vgId; - int32_t keep; - int32_t level; - int32_t fsyncPeriod; + // cfg + int32_t vgId; + int32_t fsyncPeriod; // millisecond + EWalType level; + //reference + int64_t refId; + //current tfd + int64_t curLogTfd; + int64_t curIdxTfd; + //current version + int64_t curVersion; + int64_t curOffset; + //current file version + int64_t curFileFirstVersion; + int64_t curFileLastVersion; + //wal fileset version + int64_t firstVersion; + int64_t snapshotVersion; + int64_t lastVersion; + //fsync status int32_t fsyncSeq; - int8_t stop; - int8_t reseved[3]; - char path[WAL_PATH_LEN]; - char name[WAL_FILE_LEN]; + //ctl + int32_t curStatus; pthread_mutex_t mutex; + //path + char path[WAL_PATH_LEN]; } SWal; // WAL HANDLE -typedef int32_t (*FWalWrite)(void *ahandle, void *pHead, void *pMsg); +typedef int32_t (*FWalWrite)(void *ahandle, void *pHead); // module initialization int32_t walInit(); void walCleanUp(); // handle open and ctl -SWal *walOpen(char *path, SWalCfg *pCfg); +SWal *walOpen(const char *path, SWalCfg *pCfg); +void walStop(SWal *pWal); int32_t walAlter(SWal *, SWalCfg *pCfg); void walClose(SWal *); // write -// int64_t walWriteWithMsgType(SWal*, int8_t msgType, void* body, int32_t bodyLen); +//int64_t walWriteWithMsgType(SWal*, int8_t msgType, void* body, int32_t bodyLen); int64_t walWrite(SWal *, int64_t index, void *body, int32_t bodyLen); int64_t walWriteBatch(SWal *, void **bodies, int32_t *bodyLen, int32_t batchSize); @@ -101,7 +119,8 @@ int32_t walCommit(SWal *, int64_t ver); // truncate after int32_t walRollback(SWal *, int64_t ver); // notify that previous log can be pruned safely -int32_t walPrune(SWal *, int64_t ver); +int32_t walTakeSnapshot(SWal *, int64_t ver); +//int32_t walDataCorrupted(SWal*); // read int32_t walRead(SWal *, SWalHead **, int64_t ver); @@ -111,7 +130,6 @@ int32_t walReadWithFp(SWal *, FWalWrite writeFp, int64_t verStart, int32_t readN int64_t walGetFirstVer(SWal *); int64_t walGetSnapshotVer(SWal *); int64_t walGetLastVer(SWal *); -// int32_t walDataCorrupted(SWal*); //internal int32_t walGetNextFile(SWal *pWal, int64_t *nextFileId); diff --git a/source/libs/wal/inc/walInt.h b/source/libs/wal/inc/walInt.h index f5f944b12b..42ede49c6b 100644 --- a/source/libs/wal/inc/walInt.h +++ b/source/libs/wal/inc/walInt.h @@ -22,6 +22,9 @@ extern "C" { #endif +int walRotate(SWal* pWal); +int walGetFile(SWal* pWal, int32_t version); + #ifdef __cplusplus } #endif diff --git a/source/libs/wal/src/wal.c b/source/libs/wal/src/wal.c index 05d81e0867..59f9c48814 100644 --- a/source/libs/wal/src/wal.c +++ b/source/libs/wal/src/wal.c @@ -23,11 +23,10 @@ int32_t walRollback(SWal *pWal, int64_t ver) { return 0; } -int32_t walPrune(SWal *pWal, int64_t ver) { +int32_t walTakeSnapshot(SWal *pWal, int64_t ver) { return 0; } - int32_t walRead(SWal *pWal, SWalHead **ppHead, int64_t ver) { return 0; } diff --git a/source/libs/wal/src/walIndex.c b/source/libs/wal/src/walIndex.c new file mode 100644 index 0000000000..e1fa8c72dd --- /dev/null +++ b/source/libs/wal/src/walIndex.c @@ -0,0 +1,85 @@ +/* + * 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 "taoserror.h" +#include "tref.h" +#include "tfile.h" +#include "walInt.h" + +int walSetCurVerImpl(SWal *pWal, int64_t ver) { + //close old file + //iterate all files + //open right file + //set cur version, cur file version and cur status + return 0; +} + +int walSetCurVer(SWal *pWal, int64_t ver) { + if(ver > pWal->lastVersion + 1) { + //TODO: some records are skipped + return -1; + } + if(ver < pWal->firstVersion) { + //TODO: try to seek pruned log + return -1; + } + if(ver < pWal->snapshotVersion) { + //TODO: seek snapshotted log + } + if(ver < pWal->curFileFirstVersion || (pWal->curFileLastVersion != -1 && ver > pWal->curFileLastVersion)) { + //back up to avoid inconsistency + int64_t curVersion = pWal->curVersion; + int64_t curOffset = pWal->curOffset; + int64_t curFileFirstVersion = pWal->curFileFirstVersion; + int64_t curFileLastVersion = pWal->curFileLastVersion; + if(walSetCurVerImpl(pWal, ver) < 0) { + //TODO: errno + pWal->curVersion = curVersion; + pWal->curOffset = curOffset; + pWal->curFileFirstVersion = curFileFirstVersion; + pWal->curFileLastVersion = curFileLastVersion; + return -1; + } + } + + return 0; +} + +int walWriteIndex(SWal *pWal, int64_t ver, int64_t offset) { + int code = 0; + //get index file + if(!tfValid(pWal->curIdxTfd)) { + code = TAOS_SYSTEM_ERROR(errno); + wError("vgId:%d, file:%"PRId64".idx, failed to open since %s", pWal->vgId, pWal->curFileFirstVersion, strerror(errno)); + } + if(pWal->curVersion != ver) { + if(walSetCurVer(pWal, ver) != 0) { + //TODO: some records are skipped + return -1; + } + } + //check file checksum + //append index + return 0; +} + +int walRotateIndex(SWal *pWal) { + //check file checksum + //create new file + //switch file + return 0; +} diff --git a/source/libs/wal/src/walMgmt.c b/source/libs/wal/src/walMgmt.c index 2bc12b374c..4168c21a6e 100644 --- a/source/libs/wal/src/walMgmt.c +++ b/source/libs/wal/src/walMgmt.c @@ -21,7 +21,7 @@ #include "walInt.h" typedef struct { - int32_t refId; + int32_t refSetId; int32_t seq; int8_t stop; pthread_t thread; @@ -36,7 +36,7 @@ static void walFreeObj(void *pWal); int32_t walInit() { int32_t code = 0; - tsWal.refId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj); + tsWal.refSetId = taosOpenRef(TSDB_MIN_VNODES, walFreeObj); code = pthread_mutex_init(&tsWal.mutex, NULL); if (code) { @@ -45,23 +45,23 @@ int32_t walInit() { } code = walCreateThread(); - if (code != TSDB_CODE_SUCCESS) { + if (code != 0) { wError("failed to init wal module since %s", tstrerror(code)); return code; } - wInfo("wal module is initialized, rsetId:%d", tsWal.refId); + wInfo("wal module is initialized, rsetId:%d", tsWal.refSetId); return code; } void walCleanUp() { walStopThread(); - taosCloseRef(tsWal.refId); + taosCloseRef(tsWal.refSetId); pthread_mutex_destroy(&tsWal.mutex); wInfo("wal module is cleaned up"); } -SWal *walOpen(char *path, SWalCfg *pCfg) { +SWal *walOpen(const char *path, SWalCfg *pCfg) { SWal *pWal = malloc(sizeof(SWal)); if (pWal == NULL) { terrno = TAOS_SYSTEM_ERROR(errno); @@ -69,10 +69,9 @@ SWal *walOpen(char *path, SWalCfg *pCfg) { } pWal->vgId = pCfg->vgId; - pWal->tfd = -1; - pWal->fileId = -1; + pWal->curLogTfd = -1; + /*pWal->curFileId = -1;*/ pWal->level = pCfg->walLevel; - /*pWal->keep = pCfg->keep;*/ pWal->fsyncPeriod = pCfg->fsyncPeriod; tstrncpy(pWal->path, path, sizeof(pWal->path)); pthread_mutex_init(&pWal->mutex, NULL); @@ -80,13 +79,13 @@ SWal *walOpen(char *path, SWalCfg *pCfg) { pWal->fsyncSeq = pCfg->fsyncPeriod / 1000; if (pWal->fsyncSeq <= 0) pWal->fsyncSeq = 1; - if (walInitObj(pWal) != TSDB_CODE_SUCCESS) { + if (walInitObj(pWal) != 0) { walFreeObj(pWal); return NULL; } - pWal->rId = taosAddRef(tsWal.refId, pWal); - if (pWal->rId < 0) { + pWal->refId = taosAddRef(tsWal.refSetId, pWal); + if (pWal->refId < 0) { walFreeObj(pWal); return NULL; } @@ -102,7 +101,7 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) { if (pWal->level == pCfg->walLevel && pWal->fsyncPeriod == pCfg->fsyncPeriod) { wDebug("vgId:%d, old walLevel:%d fsync:%d, new walLevel:%d fsync:%d not change", pWal->vgId, pWal->level, pWal->fsyncPeriod, pCfg->walLevel, pCfg->fsyncPeriod); - return TSDB_CODE_SUCCESS; + return 0; } wInfo("vgId:%d, change old walLevel:%d fsync:%d, new walLevel:%d fsync:%d", pWal->vgId, pWal->level, @@ -113,26 +112,16 @@ int32_t walAlter(SWal *pWal, SWalCfg *pCfg) { pWal->fsyncSeq = pCfg->fsyncPeriod / 1000; if (pWal->fsyncSeq <= 0) pWal->fsyncSeq = 1; - return TSDB_CODE_SUCCESS; -} - -void walStop(void *handle) { - if (handle == NULL) return; - SWal *pWal = handle; - - pthread_mutex_lock(&pWal->mutex); - pWal->stop = 1; - pthread_mutex_unlock(&pWal->mutex); - wDebug("vgId:%d, stop write wal", pWal->vgId); + return 0; } void walClose(SWal *pWal) { if (pWal == NULL) return; pthread_mutex_lock(&pWal->mutex); - tfClose(pWal->tfd); + tfClose(pWal->curLogTfd); pthread_mutex_unlock(&pWal->mutex); - taosRemoveRef(tsWal.refId, pWal->rId); + taosRemoveRef(tsWal.refSetId, pWal->refId); } static int32_t walInitObj(SWal *pWal) { @@ -142,14 +131,14 @@ static int32_t walInitObj(SWal *pWal) { } wDebug("vgId:%d, object is initialized", pWal->vgId); - return TSDB_CODE_SUCCESS; + return 0; } static void walFreeObj(void *wal) { SWal *pWal = wal; wDebug("vgId:%d, wal:%p is freed", pWal->vgId, pWal); - tfClose(pWal->tfd); + tfClose(pWal->curLogTfd); pthread_mutex_destroy(&pWal->mutex); tfree(pWal); } @@ -174,16 +163,16 @@ static void walUpdateSeq() { } static void walFsyncAll() { - SWal *pWal = taosIterateRef(tsWal.refId, 0); + SWal *pWal = taosIterateRef(tsWal.refSetId, 0); while (pWal) { if (walNeedFsync(pWal)) { wTrace("vgId:%d, do fsync, level:%d seq:%d rseq:%d", pWal->vgId, pWal->level, pWal->fsyncSeq, tsWal.seq); - int32_t code = tfFsync(pWal->tfd); + int32_t code = tfFsync(pWal->curLogTfd); if (code != 0) { - wError("vgId:%d, file:%s, failed to fsync since %s", pWal->vgId, pWal->name, strerror(code)); + wError("vgId:%d, file:%"PRId64".log, failed to fsync since %s", pWal->vgId, pWal->curFileFirstVersion, strerror(code)); } } - pWal = taosIterateRef(tsWal.refId, pWal->rId); + pWal = taosIterateRef(tsWal.refSetId, pWal->refId); } } @@ -216,7 +205,7 @@ static int32_t walCreateThread() { pthread_attr_destroy(&thAttr); wDebug("wal thread is launched, thread:0x%08" PRIx64, taosGetPthreadId(tsWal.thread)); - return TSDB_CODE_SUCCESS; + return 0; } static void walStopThread() { diff --git a/source/libs/wal/src/walWrite.c b/source/libs/wal/src/walWrite.c index 023b1c4a48..a8123f9c25 100644 --- a/source/libs/wal/src/walWrite.c +++ b/source/libs/wal/src/walWrite.c @@ -21,6 +21,7 @@ #include "tfile.h" #include "walInt.h" +#if 0 static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, char *name, int64_t fileId); int32_t walRenew(void *handle) { @@ -29,16 +30,16 @@ int32_t walRenew(void *handle) { SWal * pWal = handle; int32_t code = 0; - if (pWal->stop) { - wDebug("vgId:%d, do not create a new wal file", pWal->vgId); - return 0; - } + /*if (pWal->stop) {*/ + /*wDebug("vgId:%d, do not create a new wal file", pWal->vgId);*/ + /*return 0;*/ + /*}*/ pthread_mutex_lock(&pWal->mutex); - if (tfValid(pWal->tfd)) { - tfClose(pWal->tfd); - wDebug("vgId:%d, file:%s, it is closed while renew", pWal->vgId, pWal->name); + if (tfValid(pWal->logTfd)) { + tfClose(pWal->logTfd); + wDebug("vgId:%d, file:%s, it is closed while renew", pWal->vgId, pWal->logName); } /*if (pWal->keep == TAOS_WAL_KEEP) {*/ @@ -48,14 +49,14 @@ int32_t walRenew(void *handle) { /*pWal->fileId++;*/ /*}*/ - snprintf(pWal->name, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->fileId); - pWal->tfd = tfOpenCreateWrite(pWal->name); + snprintf(pWal->logName, sizeof(pWal->logName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->curFileId); + pWal->logTfd = tfOpenCreateWrite(pWal->logName); - if (!tfValid(pWal->tfd)) { + if (!tfValid(pWal->logTfd)) { code = TAOS_SYSTEM_ERROR(errno); - wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->name, strerror(errno)); + wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->logName, strerror(errno)); } else { - wDebug("vgId:%d, file:%s, it is created and open while renew", pWal->vgId, pWal->name); + wDebug("vgId:%d, file:%s, it is created and open while renew", pWal->vgId, pWal->logName); } pthread_mutex_unlock(&pWal->mutex); @@ -67,13 +68,13 @@ void walRemoveOneOldFile(void *handle) { SWal *pWal = handle; if (pWal == NULL) return; /*if (pWal->keep == TAOS_WAL_KEEP) return;*/ - if (!tfValid(pWal->tfd)) return; + if (!tfValid(pWal->logTfd)) return; pthread_mutex_lock(&pWal->mutex); // remove the oldest wal file int64_t oldFileId = -1; - if (walGetOldFile(pWal, pWal->fileId, WAL_FILE_NUM, &oldFileId) == 0) { + if (walGetOldFile(pWal, pWal->curFileId, WAL_FILE_NUM, &oldFileId) == 0) { char walName[WAL_FILE_LEN] = {0}; snprintf(walName, sizeof(walName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, oldFileId); @@ -95,26 +96,24 @@ void walRemoveAllOldFiles(void *handle) { pthread_mutex_lock(&pWal->mutex); - tfClose(pWal->tfd); - wDebug("vgId:%d, file:%s, it is closed before remove all wals", pWal->vgId, pWal->name); + tfClose(pWal->logTfd); + wDebug("vgId:%d, file:%s, it is closed before remove all wals", pWal->vgId, pWal->logName); while (walGetNextFile(pWal, &fileId) >= 0) { - snprintf(pWal->name, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, fileId); + snprintf(pWal->logName, sizeof(pWal->logName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, fileId); - if (remove(pWal->name) < 0) { - wError("vgId:%d, wal:%p file:%s, failed to remove since %s", pWal->vgId, pWal, pWal->name, strerror(errno)); + if (remove(pWal->logName) < 0) { + wError("vgId:%d, wal:%p file:%s, failed to remove since %s", pWal->vgId, pWal, pWal->logName, strerror(errno)); } else { - wInfo("vgId:%d, wal:%p file:%s, it is removed", pWal->vgId, pWal, pWal->name); + wInfo("vgId:%d, wal:%p file:%s, it is removed", pWal->vgId, pWal, pWal->logName); } } pthread_mutex_unlock(&pWal->mutex); } - -#if defined(WAL_CHECKSUM_WHOLE) +#endif static void walUpdateChecksum(SWalHead *pHead) { pHead->sver = 2; - pHead->cksum = 0; pHead->cksum = taosCalcChecksum(0, (uint8_t *)pHead, sizeof(SWalHead) + pHead->len); } @@ -130,8 +129,6 @@ static int walValidateChecksum(SWalHead *pHead) { return 0; } -#endif - int64_t walWrite(SWal *pWal, int64_t index, void *body, int32_t bodyLen) { if (pWal == NULL) return -1; @@ -143,32 +140,27 @@ int64_t walWrite(SWal *pWal, int64_t index, void *body, int32_t bodyLen) { int32_t code = 0; // no wal - if (!tfValid(pWal->tfd)) return 0; + if (!tfValid(pWal->curLogTfd)) return 0; if (pWal->level == TAOS_WAL_NOLOG) return 0; - if (pHead->version <= pWal->version) return 0; + if (pHead->version <= pWal->curVersion) return 0; pHead->signature = WAL_SIGNATURE; pHead->len = bodyLen; memcpy(pHead->cont, body, bodyLen); -#if defined(WAL_CHECKSUM_WHOLE) walUpdateChecksum(pHead); -#else - pHead->sver = 0; - taosCalcChecksumAppend(0, (uint8_t *)pHead, sizeof(SWalHead)); -#endif int32_t contLen = pHead->len + sizeof(SWalHead); pthread_mutex_lock(&pWal->mutex); - if (tfWrite(pWal->tfd, pHead, contLen) != contLen) { + if (tfWrite(pWal->curLogTfd, pHead, contLen) != contLen) { code = TAOS_SYSTEM_ERROR(errno); - wError("vgId:%d, file:%s, failed to write since %s", pWal->vgId, pWal->name, strerror(errno)); + wError("vgId:%d, file:%"PRId64".log, failed to write since %s", pWal->vgId, pWal->curFileFirstVersion, strerror(errno)); } else { - wTrace("vgId:%d, write wal, fileId:%" PRId64 " tfd:%" PRId64 " hver:%" PRId64 " wver:%" PRIu64 " len:%d", pWal->vgId, - pWal->fileId, pWal->tfd, pHead->version, pWal->version, pHead->len); - pWal->version = pHead->version; + /*wTrace("vgId:%d, write wal, fileId:%" PRId64 " tfd:%" PRId64 " hver:%" PRId64 " wver:%" PRIu64 " len:%d", pWal->vgId,*/ + /*pWal->curFileId, pWal->logTfd, pHead->version, pWal->curVersion, pHead->len);*/ + pWal->curVersion = pHead->version; } pthread_mutex_unlock(&pWal->mutex); @@ -179,16 +171,17 @@ int64_t walWrite(SWal *pWal, int64_t index, void *body, int32_t bodyLen) { } void walFsync(SWal *pWal, bool forceFsync) { - if (pWal == NULL || !tfValid(pWal->tfd)) return; + if (pWal == NULL || !tfValid(pWal->curLogTfd)) return; if (forceFsync || (pWal->level == TAOS_WAL_FSYNC && pWal->fsyncPeriod == 0)) { - wTrace("vgId:%d, fileId:%" PRId64 ", do fsync", pWal->vgId, pWal->fileId); - if (tfFsync(pWal->tfd) < 0) { - wError("vgId:%d, fileId:%" PRId64 ", fsync failed since %s", pWal->vgId, pWal->fileId, strerror(errno)); + wTrace("vgId:%d, fileId:%"PRId64".log, do fsync", pWal->vgId, pWal->curFileFirstVersion); + if (tfFsync(pWal->curLogTfd) < 0) { + wError("vgId:%d, file:%"PRId64".log, fsync failed since %s", pWal->vgId, pWal->curFileFirstVersion, strerror(errno)); } } } +#if 0 int32_t walRestore(void *handle, void *pVnode, FWalWrite writeFp) { if (handle == NULL) return -1; @@ -198,10 +191,10 @@ int32_t walRestore(void *handle, void *pVnode, FWalWrite writeFp) { int64_t fileId = -1; while ((code = walGetNextFile(pWal, &fileId)) >= 0) { - if (fileId == pWal->fileId) continue; + /*if (fileId == pWal->curFileId) continue;*/ char walName[WAL_FILE_LEN]; - snprintf(walName, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, fileId); + snprintf(walName, sizeof(pWal->logName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, fileId); wInfo("vgId:%d, file:%s, will be restored", pWal->vgId, walName); code = walRestoreWalFile(pWal, pVnode, writeFp, walName, fileId); @@ -210,7 +203,7 @@ int32_t walRestore(void *handle, void *pVnode, FWalWrite writeFp) { continue; } - wInfo("vgId:%d, file:%s, restore success, wver:%" PRIu64, pWal->vgId, walName, pWal->version); + wInfo("vgId:%d, file:%s, restore success, wver:%" PRIu64, pWal->vgId, walName, pWal->curVersion); count++; } @@ -222,14 +215,14 @@ int32_t walRestore(void *handle, void *pVnode, FWalWrite writeFp) { return walRenew(pWal); } else { // open the existing WAL file in append mode - pWal->fileId = 0; - snprintf(pWal->name, sizeof(pWal->name), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->fileId); - pWal->tfd = tfOpenCreateWriteAppend(pWal->name); - if (!tfValid(pWal->tfd)) { - wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->name, strerror(errno)); + /*pWal->curFileId = 0;*/ + snprintf(pWal->logName, sizeof(pWal->logName), "%s/%s%" PRId64, pWal->path, WAL_PREFIX, pWal->curFileId); + pWal->logTfd = tfOpenCreateWriteAppend(pWal->logName); + if (!tfValid(pWal->logTfd)) { + wError("vgId:%d, file:%s, failed to open since %s", pWal->vgId, pWal->logName, strerror(errno)); return TAOS_SYSTEM_ERROR(errno); } - wDebug("vgId:%d, file:%s, it is created and open while restore", pWal->vgId, pWal->name); + wDebug("vgId:%d, file:%s, it is created and open while restore", pWal->vgId, pWal->logName); } return TSDB_CODE_SUCCESS; @@ -246,14 +239,15 @@ int32_t walGetWalFile(void *handle, char *fileName, int64_t *fileId) { int32_t code = walGetNextFile(pWal, fileId); if (code >= 0) { sprintf(fileName, "wal/%s%" PRId64, WAL_PREFIX, *fileId); - code = (*fileId == pWal->fileId) ? 0 : 1; + /*code = (*fileId == pWal->curFileId) ? 0 : 1;*/ } - wDebug("vgId:%d, get wal file, code:%d curId:%" PRId64 " outId:%" PRId64, pWal->vgId, code, pWal->fileId, *fileId); + wDebug("vgId:%d, get wal file, code:%d curId:%" PRId64 " outId:%" PRId64, pWal->vgId, code, pWal->curFileId, *fileId); pthread_mutex_unlock(&(pWal->mutex)); return code; } +#endif static void walFtruncate(SWal *pWal, int64_t tfd, int64_t offset) { tfFtruncate(tfd, offset); @@ -279,13 +273,6 @@ static int32_t walSkipCorruptedRecord(SWal *pWal, SWalHead *pHead, int64_t tfd, continue; } -#if defined(WAL_CHECKSUM_WHOLE) - if (pHead->sver == 0 && walValidateChecksum(pHead)) { - wInfo("vgId:%d, wal head cksum check passed, offset:%" PRId64, pWal->vgId, pos); - *offset = pos; - return TSDB_CODE_SUCCESS; - } - if (pHead->sver >= 1) { if (tfRead(tfd, pHead->cont, pHead->len) < pHead->len) { wError("vgId:%d, read to end of corrupted wal file, offset:%" PRId64, pWal->vgId, pos); @@ -298,15 +285,6 @@ static int32_t walSkipCorruptedRecord(SWal *pWal, SWalHead *pHead, int64_t tfd, return TSDB_CODE_SUCCESS; } } - -#else - if (taosCheckChecksumWhole((uint8_t *)pHead, sizeof(SWalHead))) { - wInfo("vgId:%d, wal head cksum check passed, offset:%" PRId64, pWal->vgId, pos); - *offset = pos; - return TSDB_CODE_SUCCESS; - } - -#endif } return TSDB_CODE_WAL_FILE_CORRUPTED; @@ -349,7 +327,6 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch break; } -#if defined(WAL_CHECKSUM_WHOLE) if ((pHead->sver == 0 && !walValidateChecksum(pHead)) || pHead->sver < 0 || pHead->sver > 2) { wError("vgId:%d, file:%s, wal head cksum is messed up, hver:%" PRIu64 " len:%d offset:%" PRId64, pWal->vgId, name, pHead->version, pHead->len, offset); @@ -393,50 +370,15 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch } } -#else - if (!taosCheckChecksumWhole((uint8_t *)pHead, sizeof(SWalHead))) { - wError("vgId:%d, file:%s, wal head cksum is messed up, hver:%" PRIu64 " len:%d offset:%" PRId64, pWal->vgId, name, - pHead->version, pHead->len, offset); - code = walSkipCorruptedRecord(pWal, pHead, tfd, &offset); - if (code != TSDB_CODE_SUCCESS) { - walFtruncate(pWal, tfd, offset); - break; - } - } - - if (pHead->len < 0 || pHead->len > size - sizeof(SWalHead)) { - wError("vgId:%d, file:%s, wal head len out of range, hver:%" PRIu64 " len:%d offset:%" PRId64, pWal->vgId, name, - pHead->version, pHead->len, offset); - code = walSkipCorruptedRecord(pWal, pHead, tfd, &offset); - if (code != TSDB_CODE_SUCCESS) { - walFtruncate(pWal, tfd, offset); - break; - } - } - - ret = (int32_t)tfRead(tfd, pHead->cont, pHead->len); - if (ret < 0) { - wError("vgId:%d, file:%s, failed to read wal body since %s", pWal->vgId, name, strerror(errno)); - code = TAOS_SYSTEM_ERROR(errno); - break; - } - - if (ret < pHead->len) { - wError("vgId:%d, file:%s, failed to read wal body, ret:%d len:%d", pWal->vgId, name, ret, pHead->len); - offset += sizeof(SWalHead); - continue; - } - -#endif offset = offset + sizeof(SWalHead) + pHead->len; wTrace("vgId:%d, restore wal, fileId:%" PRId64 " hver:%" PRIu64 " wver:%" PRIu64 " len:%d offset:%" PRId64, - pWal->vgId, fileId, pHead->version, pWal->version, pHead->len, offset); + pWal->vgId, fileId, pHead->version, pWal->curVersion, pHead->len, offset); - pWal->version = pHead->version; + pWal->curVersion = pHead->version; // wInfo("writeFp: %ld", offset); - (*writeFp)(pVnode, pHead, NULL); + (*writeFp)(pVnode, pHead); } tfClose(tfd); @@ -449,7 +391,7 @@ static int32_t walRestoreWalFile(SWal *pWal, void *pVnode, FWalWrite writeFp, ch uint64_t walGetVersion(SWal *pWal) { if (pWal == NULL) return 0; - return pWal->version; + return pWal->curVersion; } // Wal version in slave (dnode1) must be reset. @@ -459,7 +401,7 @@ uint64_t walGetVersion(SWal *pWal) { void walResetVersion(SWal *pWal, uint64_t newVer) { if (pWal == NULL) return; - wInfo("vgId:%d, version reset from %" PRIu64 " to %" PRIu64, pWal->vgId, pWal->version, newVer); + wInfo("vgId:%d, version reset from %" PRIu64 " to %" PRIu64, pWal->vgId, pWal->curVersion, newVer); - pWal->version = newVer; + pWal->curVersion = newVer; } From 7906e78257565977d4a5ac1f7a81ebfe267dd657 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 26 Nov 2021 14:43:56 +0800 Subject: [PATCH 09/16] TD-11265 refact dndVnodes --- include/dnode/mgmt/dnode.h | 2 +- include/dnode/vnode/vnode.h | 18 ----------- source/dnode/mgmt/daemon/src/daemon.c | 2 +- source/dnode/mgmt/impl/src/dndDnode.c | 13 ++++---- source/dnode/mgmt/impl/src/dndMnode.c | 6 ++-- source/dnode/mgmt/impl/src/dndVnodes.c | 44 +++++++++++++++++--------- source/dnode/mgmt/impl/src/dnode.c | 1 + source/dnode/vnode/impl/src/vnodeInt.c | 7 ++-- 8 files changed, 43 insertions(+), 50 deletions(-) diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index 7dd7730443..f43fe107fe 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -78,7 +78,7 @@ typedef struct { * @brief data file's directory. * */ - char dataDir[PATH_MAX]; + char dataDir[TSDB_FILENAME_LEN]; /** * @brief local endpoint. diff --git a/include/dnode/vnode/vnode.h b/include/dnode/vnode/vnode.h index 3f6705fac6..1edd93f509 100644 --- a/include/dnode/vnode/vnode.h +++ b/include/dnode/vnode/vnode.h @@ -184,27 +184,9 @@ typedef struct { SRpcMsg rpcMsg[]; } SVnodeMsg; -typedef struct SDnode SDnode; -typedef void (*SendMsgToDnodeFp)(SDnode *pDnode, struct SEpSet *epSet, struct SRpcMsg *rpcMsg); -typedef void (*SendMsgToMnodeFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef void (*SendRedirectMsgFp)(SDnode *pDnode, struct SRpcMsg *rpcMsg); -typedef int32_t (*PutMsgToVnodeQFp)(SDnode *pDnode, int32_t vgId, SVnodeMsg *pMsg); - -typedef struct { - PutMsgToVnodeQFp putMsgToApplyQueueFp; - SendMsgToDnodeFp sendMsgToDnodeFp; - SendMsgToMnodeFp sendMsgToMnodeFp; -} SVnodePara; - -int32_t vnodeInit(SVnodePara); -void vnodeCleanup(); - int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg); -SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg); -void vnodeDrop(SVnode *pVnode); int32_t vnodeCompact(SVnode *pVnode); int32_t vnodeSync(SVnode *pVnode); - int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad); SVnodeMsg *vnodeInitMsg(int32_t msgNum); diff --git a/source/dnode/mgmt/daemon/src/daemon.c b/source/dnode/mgmt/daemon/src/daemon.c index 429b097fb8..effaec66a8 100644 --- a/source/dnode/mgmt/daemon/src/daemon.c +++ b/source/dnode/mgmt/daemon/src/daemon.c @@ -141,7 +141,7 @@ void dmnInitOption(SDnodeOpt *pOption) { pOption->shellActivityTimer = tsShellActivityTimer; pOption->statusInterval = tsStatusInterval; pOption->serverPort = tsServerPort; - tstrncpy(pOption->dataDir, tsDataDir, PATH_MAX); + tstrncpy(pOption->dataDir, tsDataDir, TSDB_FILENAME_LEN); tstrncpy(pOption->localEp, tsLocalEp, TSDB_EP_LEN); tstrncpy(pOption->localFqdn, tsLocalFqdn, TSDB_FQDN_LEN); tstrncpy(pOption->firstEp, tsFirst, TSDB_EP_LEN); diff --git a/source/dnode/mgmt/impl/src/dndDnode.c b/source/dnode/mgmt/impl/src/dndDnode.c index ef30503494..fa601a0d99 100644 --- a/source/dnode/mgmt/impl/src/dndDnode.c +++ b/source/dnode/mgmt/impl/src/dndDnode.c @@ -455,12 +455,11 @@ static void *dnodeThreadRoutine(void *param) { while (true) { taosMsleep(ms); - if (dndGetStat(pDnode) != DND_STAT_RUNNING) { - continue; - } - pthread_testcancel(); - dndSendStatusMsg(pDnode); + + if (dndGetStat(pDnode) == DND_STAT_RUNNING) { + dndSendStatusMsg(pDnode); + } } } @@ -501,7 +500,7 @@ int32_t dndInitDnode(SDnode *pDnode) { return -1; } - dInfo("dnd-dnode is initialized"); + dInfo("dnode-dnode is initialized"); return 0; } @@ -531,7 +530,7 @@ void dndCleanupDnode(SDnode *pDnode) { } dndWUnLockDnode(pDnode); - dInfo("dnd-dnode is cleaned up"); + dInfo("dnode-dnode is cleaned up"); } void dndProcessDnodeReq(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) { diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index d581c7761c..9b3435a49e 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -616,7 +616,7 @@ static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) { pPool->min = 1; pPool->max = 1; if (tWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -652,7 +652,7 @@ static int32_t dndInitMnodeReadWorker(SDnode *pDnode) { pPool->min = 0; pPool->max = 1; if (tWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -703,7 +703,7 @@ static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) { pPool->min = 0; pPool->max = 1; if (tWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index d5e94106a7..ac3e55ffa7 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -22,6 +22,7 @@ typedef struct { int32_t refCount; int8_t dropped; int8_t accessState; + char *path; SVnode *pImpl; taos_queue pWriteQ; taos_queue pSyncQ; @@ -74,7 +75,7 @@ static int32_t dndPutMsgIntoVnodeApplyQueue(SDnode *pDnode, int32_t vgId, SVnode static SVnodeObj *dndAcquireVnode(SDnode *pDnode, int32_t vgId); static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode); -static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, SVnode *pImpl); +static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, SVnode *pImpl); static void dndDropVnodeWrapper(SDnode *pDnode, SVnodeObj *pVnode); static SVnodeObj **dndGetVnodesFromHash(SDnode *pDnode, int32_t *numOfVnodes); static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_t *numOfVnodes); @@ -125,7 +126,7 @@ static void dndReleaseVnode(SDnode *pDnode, SVnodeObj *pVnode) { } } -static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, SVnode *pImpl) { +static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, char *path, SVnode *pImpl) { SVnodesMgmt *pMgmt = &pDnode->vmgmt; SVnodeObj *pVnode = calloc(1, sizeof(SVnodeObj)); if (pVnode == NULL) { @@ -139,6 +140,12 @@ static int32_t dndCreateVnodeWrapper(SDnode *pDnode, int32_t vgId, SVnode *pImpl pVnode->accessState = TSDB_VN_ALL_ACCCESS; pVnode->pImpl = pImpl; + pVnode->path = tstrdup(path); + if (pVnode->path == NULL) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + if (dndAllocVnodeQueryQueue(pDnode, pVnode) != 0) { return -1; } @@ -354,22 +361,25 @@ static int32_t dndWriteVnodesToFile(SDnode *pDnode) { static int32_t dndCreateVnode(SDnode *pDnode, int32_t vgId, SVnodeCfg *pCfg) { char path[PATH_MAX + 20] = {0}; snprintf(path, sizeof(path), "%s/vnode%d", pDnode->dir.vnodes, vgId); - SVnode *pImpl = vnodeCreate(vgId, path, pCfg); + // SVnode *pImpl = vnodeCreate(vgId, path, pCfg); + SVnode *pImpl = vnodeOpen(path, NULL); if (pImpl == NULL) { return -1; } - int32_t code = dndCreateVnodeWrapper(pDnode, vgId, pImpl); + int32_t code = dndCreateVnodeWrapper(pDnode, vgId, path, pImpl); if (code != 0) { - vnodeDrop(pImpl); + vnodeClose(pImpl); + vnodeDestroy(path); terrno = code; return code; } code = dndWriteVnodesToFile(pDnode); if (code != 0) { - vnodeDrop(pImpl); + vnodeClose(pImpl); + vnodeDestroy(path); terrno = code; return code; } @@ -385,7 +395,8 @@ static int32_t dndDropVnode(SDnode *pDnode, SVnodeObj *pVnode) { } dndDropVnodeWrapper(pDnode, pVnode); - vnodeDrop(pVnode->pImpl); + vnodeClose(pVnode->pImpl); + vnodeDestroy(pVnode->path); dndWriteVnodesToFile(pDnode); return 0; } @@ -413,7 +424,7 @@ static void *dnodeOpenVnodeFunc(void *param) { dError("vgId:%d, failed to open vnode by thread:%d", pVnode->vgId, pThread->threadIndex); pThread->failed++; } else { - dndCreateVnodeWrapper(pDnode, pVnode->vgId, pImpl); + dndCreateVnodeWrapper(pDnode, pVnode->vgId, path, pImpl); dDebug("vgId:%d, is opened by thread:%d", pVnode->vgId, pThread->threadIndex); pThread->opened++; } @@ -433,7 +444,7 @@ static int32_t dndOpenVnodes(SDnode *pDnode) { pMgmt->hash = taosHashInit(TSDB_MIN_VNODES, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_NO_LOCK); if (pMgmt->hash == NULL) { dError("failed to init vnode hash"); - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -874,13 +885,13 @@ static int32_t dndInitVnodeMgmtWorker(SDnode *pDnode) { pPool->min = 1; pPool->max = 1; if (tWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } pMgmt->pMgmtQ = tWorkerAllocQueue(pPool, pDnode, (FProcessItem)dndProcessVnodeMgmtQueue); if (pMgmt->pMgmtQ == NULL) { - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -918,6 +929,7 @@ static int32_t dndAllocVnodeFetchQueue(SDnode *pDnode, SVnodeObj *pVnode) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } + return 0; } @@ -938,7 +950,8 @@ static int32_t dndInitVnodeReadWorker(SDnode *pDnode) { pPool->min = (int32_t)threadsForQuery; pPool->max = pPool->min; if (tWorkerInit(pPool) != 0) { - return TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; } pPool = &pMgmt->fetchPool; @@ -946,7 +959,8 @@ static int32_t dndInitVnodeReadWorker(SDnode *pDnode) { pPool->min = MIN(maxFetchThreads, pDnode->opt.numOfCores); pPool->max = pPool->min; if (tWorkerInit(pPool) != 0) { - TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; } return 0; @@ -998,7 +1012,7 @@ static int32_t dndInitVnodeWriteWorker(SDnode *pDnode) { pPool->name = "vnode-write"; pPool->max = tsNumOfCores; if (tMWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } @@ -1036,7 +1050,7 @@ static int32_t dndInitVnodeSyncWorker(SDnode *pDnode) { pPool->name = "vnode-sync"; pPool->max = maxThreads; if (tMWorkerInit(pPool) != 0) { - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index 0bfcf5d721..aa0070cfa9 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -116,6 +116,7 @@ static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOptions) { return -1; } + memcpy(&pDnode->opt, pOptions, sizeof(SDnodeOpt)); return 0; } diff --git a/source/dnode/vnode/impl/src/vnodeInt.c b/source/dnode/vnode/impl/src/vnodeInt.c index 2cbdf318a2..8a6fc8bf5e 100644 --- a/source/dnode/vnode/impl/src/vnodeInt.c +++ b/source/dnode/vnode/impl/src/vnodeInt.c @@ -17,9 +17,6 @@ #include "vnodeInt.h" #include "tqueue.h" -int32_t vnodeInit(SVnodePara para) { return 0; } -void vnodeCleanup() {} - int32_t vnodeAlter(SVnode *pVnode, const SVnodeCfg *pCfg) { return 0; } SVnode *vnodeCreate(int32_t vgId, const char *path, const SVnodeCfg *pCfg) { return NULL; } void vnodeDrop(SVnode *pVnode) {} @@ -31,7 +28,7 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { return 0; } SVnodeMsg *vnodeInitMsg(int32_t msgNum) { SVnodeMsg *pMsg = taosAllocateQitem(msgNum * sizeof(SRpcMsg *) + sizeof(SVnodeMsg)); if (pMsg == NULL) { - terrno = TSDB_CODE_VND_OUT_OF_MEMORY; + terrno = TSDB_CODE_OUT_OF_MEMORY; return NULL; } else { pMsg->allocNum = msgNum; @@ -41,7 +38,7 @@ SVnodeMsg *vnodeInitMsg(int32_t msgNum) { int32_t vnodeAppendMsg(SVnodeMsg *pMsg, SRpcMsg *pRpcMsg) { if (pMsg->curNum >= pMsg->allocNum) { - return TSDB_CODE_VND_OUT_OF_MEMORY; + return TSDB_CODE_OUT_OF_MEMORY; } pMsg->rpcMsg[pMsg->curNum++] = *pRpcMsg; From 16f089c39a7779bcc4d333648b4ca38d2402b576 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 26 Nov 2021 15:24:55 +0800 Subject: [PATCH 10/16] update fst core struct --- source/libs/index/src/index_fst.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 70633de0e8..c8ff23c1c8 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -146,24 +146,27 @@ uint64_t fstUnFinishedNodesFindCommPrefixAndSetOutput(FstUnFinishedNodes *node, size_t lsz = (size_t)(s->end - s->start + 1); // data len size_t ssz = taosArrayGetSize(node->stack); // stack size - uint64_t res = 0; - for (size_t i = 0; i < lsz && i < ssz; i++) { + uint64_t i = 0; + for (i = 0; i < lsz && i < ssz; i++) { FstBuilderNodeUnfinished *un = taosArrayGet(node->stack, i); - FstLastTransition *last = un->last; - if (last->inp == s->data[s->start + i]) { - uint64_t commPrefix = last->out; - uint64_t addPrefix = last->out - commPrefix; - out = out - commPrefix; - last->out = commPrefix; - if (addPrefix != 0) { - fstBuilderNodeUnfinishedAddOutputPrefix(un, addPrefix); - } + FstLastTransition *t = un->last; + uint64_t addPrefix = 0; + if (t && t->inp == s->data[s->start + i]) { + uint64_t commPrefix = MIN(t->out, *out); + uint64_t tAddPrefix = t->out - commPrefix; + (*out) = (*out) - commPrefix; + t->out = commPrefix; + addPrefix = tAddPrefix; } else { - break; + break; + } + if (addPrefix != 0) { + fstBuilderNodeUnfinishedAddOutputPrefix(un, addPrefix); + } } - return res; + return i; } @@ -780,7 +783,7 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) { } if (prefixLen == FST_SLICE_LEN(s)) { - assert(out != 0); + assert(out == 0); return; } From aad478d34f218bbd45ec11e4d900dde505b9aad3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Fri, 26 Nov 2021 16:28:38 +0800 Subject: [PATCH 11/16] TD-11265 refact dndMnode --- include/dnode/mgmt/dnode.h | 4 +- include/dnode/mnode/mnode.h | 10 +-- source/dnode/mgmt/impl/src/dndMnode.c | 107 ++++++++++++++----------- source/dnode/mgmt/impl/src/dndVnodes.c | 2 +- source/dnode/mgmt/impl/src/dnode.c | 16 ++-- source/dnode/mnode/impl/inc/mnodeInt.h | 2 +- source/dnode/mnode/impl/src/mnode.c | 28 +++---- 7 files changed, 91 insertions(+), 78 deletions(-) diff --git a/include/dnode/mgmt/dnode.h b/include/dnode/mgmt/dnode.h index f43fe107fe..fe9560d427 100644 --- a/include/dnode/mgmt/dnode.h +++ b/include/dnode/mgmt/dnode.h @@ -121,10 +121,10 @@ typedef struct { /** * @brief Initialize and start the dnode. * - * @param pOptions Options of the dnode. + * @param pOption Option of the dnode. * @return SDnode* The dnode object. */ -SDnode *dndInit(SDnodeOpt *pOptions); +SDnode *dndInit(SDnodeOpt *pOption); /** * @brief Stop and cleanup the dnode. diff --git a/include/dnode/mnode/mnode.h b/include/dnode/mnode/mnode.h index 725bdaec3c..824eb24191 100644 --- a/include/dnode/mnode/mnode.h +++ b/include/dnode/mnode/mnode.h @@ -53,17 +53,17 @@ typedef struct { SendMsgToDnodeFp sendMsgToDnodeFp; SendMsgToMnodeFp sendMsgToMnodeFp; SendRedirectMsgFp sendRedirectMsgFp; -} SMnodeOptions; +} SMnodeOpt; /* ------------------------ SMnode ------------------------ */ /** * @brief Open a mnode. * * @param path Path of the mnode - * @param pOptions Options of the mnode + * @param pOption Option of the mnode * @return SMnode* The mnode object */ -SMnode *mnodeOpen(const char *path, const SMnodeOptions *pOptions); +SMnode *mnodeOpen(const char *path, const SMnodeOpt *pOption); /** * @brief Close a mnode @@ -76,10 +76,10 @@ void mnodeClose(SMnode *pMnode); * @brief Close a mnode * * @param pMnode The mnode object to close - * @param pOptions Options of the mnode + * @param pOption Options of the mnode * @return int32_t 0 for success, -1 for failure */ -int32_t mnodeAlter(SMnode *pMnode, const SMnodeOptions *pOptions); +int32_t mnodeAlter(SMnode *pMnode, const SMnodeOpt *pOption); /** * @brief Drop a mnode. diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index 9b3435a49e..0a764af8dc 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -58,8 +58,8 @@ static void dndReleaseMnode(SDnode *pDnode, SMnode *pMnode); static int32_t dndReadMnodeFile(SDnode *pDnode); static int32_t dndWriteMnodeFile(SDnode *pDnode); -static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOptions *pOptions); -static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOptions *pOptions); +static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption); +static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOpt *pOption); static int32_t dndDropMnode(SDnode *pDnode); static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg); @@ -243,6 +243,7 @@ static bool dndNeedDeployMnode(SDnode *pDnode) { if (dndGetClusterId(pDnode) > 0) { return false; } + if (strcmp(pDnode->opt.localEp, pDnode->opt.firstEp) != 0) { return false; } @@ -250,43 +251,49 @@ static bool dndNeedDeployMnode(SDnode *pDnode) { return true; } -static void dndInitMnodeOptions(SDnode *pDnode, SMnodeOptions *pOptions) { - pOptions->pDnode = pDnode; - pOptions->sendMsgToDnodeFp = dndSendMsgToDnode; - pOptions->sendMsgToMnodeFp = dndSendMsgToMnode; - pOptions->sendRedirectMsgFp = dndSendRedirectMsg; - pOptions->putMsgToApplyMsgFp = dndPutMsgIntoMnodeApplyQueue; +static void dndInitMnodeOption(SDnode *pDnode, SMnodeOpt *pOption) { + pOption->pDnode = pDnode; + pOption->sendMsgToDnodeFp = dndSendMsgToDnode; + pOption->sendMsgToMnodeFp = dndSendMsgToMnode; + pOption->sendRedirectMsgFp = dndSendRedirectMsg; + pOption->putMsgToApplyMsgFp = dndPutMsgIntoMnodeApplyQueue; + pOption->dnodeId = dndGetDnodeId(pDnode); + pOption->clusterId = dndGetClusterId(pDnode); } -static int32_t dndBuildMnodeOptions(SDnode *pDnode, SMnodeOptions *pOptions, SCreateMnodeMsg *pMsg) { - dndInitMnodeOptions(pDnode, pOptions); +static void dndBuildMnodeDeployOption(SDnode *pDnode, SMnodeOpt *pOption) { + dndInitMnodeOption(pDnode, pOption); + pOption->replica = 1; + pOption->selfIndex = 0; + SReplica *pReplica = &pOption->replicas[0]; + pReplica->id = 1; + pReplica->port = pDnode->opt.serverPort; + tstrncpy(pReplica->fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN); +} - if (pMsg == NULL) { - pOptions->dnodeId = 1; - pOptions->clusterId = 1234; - pOptions->replica = 1; - pOptions->selfIndex = 0; - SReplica *pReplica = &pOptions->replicas[0]; - pReplica->id = 1; - pReplica->port = pDnode->opt.serverPort; - tstrncpy(pReplica->fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN); - } else { - pOptions->dnodeId = dndGetDnodeId(pDnode); - pOptions->clusterId = dndGetClusterId(pDnode); - pOptions->selfIndex = -1; - pOptions->replica = pMsg->replica; - for (int32_t index = 0; index < pMsg->replica; ++index) { - SReplica *pReplica = &pOptions->replicas[index]; - pReplica->id = pMsg->replicas[index].id; - pReplica->port = pMsg->replicas[index].port; - tstrncpy(pReplica->fqdn, pMsg->replicas[index].fqdn, TSDB_FQDN_LEN); - if (pReplica->id == pOptions->dnodeId) { - pOptions->selfIndex = index; - } +static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) { + dndInitMnodeOption(pDnode, pOption); + pOption->replica = 0; +} + +static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SCreateMnodeMsg *pMsg) { + dndInitMnodeOption(pDnode, pOption); + pOption->dnodeId = dndGetDnodeId(pDnode); + pOption->clusterId = dndGetClusterId(pDnode); + + pOption->replica = pMsg->replica; + pOption->selfIndex = -1; + for (int32_t index = 0; index < pMsg->replica; ++index) { + SReplica *pReplica = &pOption->replicas[index]; + pReplica->id = pMsg->replicas[index].id; + pReplica->port = pMsg->replicas[index].port; + tstrncpy(pReplica->fqdn, pMsg->replicas[index].fqdn, TSDB_FQDN_LEN); + if (pReplica->id == pOption->dnodeId) { + pOption->selfIndex = index; } } - if (pOptions->selfIndex == -1) { + if (pOption->selfIndex == -1) { terrno = TSDB_CODE_DND_MNODE_ID_NOT_FOUND; dError("failed to build mnode options since %s", terrstr()); return -1; @@ -295,7 +302,7 @@ static int32_t dndBuildMnodeOptions(SDnode *pDnode, SMnodeOptions *pOptions, SCr return 0; } -static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOptions *pOptions) { +static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOpt *pOption) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; int32_t code = dndStartMnodeWorker(pDnode); @@ -304,7 +311,7 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOptions *pOptions) { return code; } - SMnode *pMnode = mnodeOpen(pDnode->dir.mnode, pOptions); + SMnode *pMnode = mnodeOpen(pDnode->dir.mnode, pOption); if (pMnode == NULL) { dError("failed to open mnode since %s", terrstr()); code = terrno; @@ -331,7 +338,7 @@ static int32_t dndOpenMnode(SDnode *pDnode, SMnodeOptions *pOptions) { return 0; } -static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOptions *pOptions) { +static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOpt *pOption) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; SMnode *pMnode = dndAcquireMnode(pDnode); @@ -340,7 +347,7 @@ static int32_t dndAlterMnode(SDnode *pDnode, SMnodeOptions *pOptions) { return -1; } - if (mnodeAlter(pMnode, pOptions) != 0) { + if (mnodeAlter(pMnode, pOption) != 0) { dError("failed to alter mnode since %s", terrstr()); dndReleaseMnode(pDnode, pMnode); return -1; @@ -399,8 +406,8 @@ static int32_t dndProcessCreateMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { terrno = TSDB_CODE_DND_MNODE_ID_INVALID; return -1; } else { - SMnodeOptions option = {0}; - if (dndBuildMnodeOptions(pDnode, &option, pMsg) != 0) { + SMnodeOpt option = {0}; + if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) { return -1; } return dndOpenMnode(pDnode, &option); @@ -414,8 +421,8 @@ static int32_t dndProcessAlterMnodeReq(SDnode *pDnode, SRpcMsg *pRpcMsg) { terrno = TSDB_CODE_DND_MNODE_ID_INVALID; return -1; } else { - SMnodeOptions option = {0}; - if (dndBuildMnodeOptions(pDnode, &option, pMsg) != 0) { + SMnodeOpt option = {0}; + if (dndBuildMnodeOptionFromMsg(pDnode, &option, pMsg) != 0) { return -1; } return dndAlterMnode(pDnode, &option); @@ -625,7 +632,6 @@ static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) { static void dndCleanupMnodeMgmtWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; - ; tWorkerCleanup(&pMgmt->mgmtPool); } @@ -737,7 +743,12 @@ static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) { pPool->name = "mnode-sync"; pPool->min = 0; pPool->max = 1; - return tWorkerInit(pPool); + if (tWorkerInit(pPool) != 0) { + terrno = TSDB_CODE_OUT_OF_MEMORY; + return -1; + } + + return 0; } static void dndCleanupMnodeSyncWorker(SDnode *pDnode) { @@ -781,13 +792,15 @@ int32_t dndInitMnode(SDnode *pDnode) { } dInfo("start to deploy mnode"); + SMnodeOpt option = {0}; + dndBuildMnodeDeployOption(pDnode, &option); + return dndOpenMnode(pDnode, &option); } else { dInfo("start to open mnode"); + SMnodeOpt option = {0}; + dndBuildMnodeOpenOption(pDnode, &option); + return dndOpenMnode(pDnode, &option); } - - SMnodeOptions option = {0}; - dndInitMnodeOptions(pDnode, &option); - return dndOpenMnode(pDnode, &option); } void dndCleanupMnode(SDnode *pDnode) { diff --git a/source/dnode/mgmt/impl/src/dndVnodes.c b/source/dnode/mgmt/impl/src/dndVnodes.c index ac3e55ffa7..fd66695e32 100644 --- a/source/dnode/mgmt/impl/src/dndVnodes.c +++ b/source/dnode/mgmt/impl/src/dndVnodes.c @@ -239,7 +239,7 @@ static int32_t dndGetVnodesFromFile(SDnode *pDnode, SVnodeObj **ppVnodes, int32_ snprintf(file, PATH_MAX + 20, "%s/vnodes.json", pDnode->dir.vnodes); fp = fopen(file, "r"); - if (!fp) { + if (fp == NULL) { dDebug("file %s not exist", file); code = 0; goto PRASE_VNODE_OVER; diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index aa0070cfa9..8d72f83200 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -77,19 +77,19 @@ static int32_t dndCheckRunning(char *dataDir) { return 0; } -static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOptions) { - if (dndCheckRunning(pOptions->dataDir) != 0) { +static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOption) { + if (dndCheckRunning(pOption->dataDir) != 0) { return -1; } char path[PATH_MAX + 100]; - snprintf(path, sizeof(path), "%s%smnode", pOptions->dataDir, TD_DIRSEP); + snprintf(path, sizeof(path), "%s%smnode", pOption->dataDir, TD_DIRSEP); pDnode->dir.mnode = tstrdup(path); - snprintf(path, sizeof(path), "%s%svnode", pOptions->dataDir, TD_DIRSEP); + snprintf(path, sizeof(path), "%s%svnode", pOption->dataDir, TD_DIRSEP); pDnode->dir.vnodes = tstrdup(path); - snprintf(path, sizeof(path), "%s%sdnode", pOptions->dataDir, TD_DIRSEP); + snprintf(path, sizeof(path), "%s%sdnode", pOption->dataDir, TD_DIRSEP); pDnode->dir.dnode = tstrdup(path); if (pDnode->dir.mnode == NULL || pDnode->dir.vnodes == NULL || pDnode->dir.dnode == NULL) { @@ -116,7 +116,7 @@ static int32_t dndInitEnv(SDnode *pDnode, SDnodeOpt *pOptions) { return -1; } - memcpy(&pDnode->opt, pOptions, sizeof(SDnodeOpt)); + memcpy(&pDnode->opt, pOption, sizeof(SDnodeOpt)); return 0; } @@ -136,7 +136,7 @@ static void dndCleanupEnv(SDnode *pDnode) { taosStopCacheRefreshWorker(); } -SDnode *dndInit(SDnodeOpt *pOptions) { +SDnode *dndInit(SDnodeOpt *pOption) { taosIgnSIGPIPE(); taosBlockSIGPIPE(); taosResolveCRC(); @@ -151,7 +151,7 @@ SDnode *dndInit(SDnodeOpt *pOptions) { dInfo("start to initialize TDengine"); dndSetStat(pDnode, DND_STAT_INIT); - if (dndInitEnv(pDnode, pOptions) != 0) { + if (dndInitEnv(pDnode, pOption) != 0) { dError("failed to init env"); dndCleanup(pDnode); return NULL; diff --git a/source/dnode/mnode/impl/inc/mnodeInt.h b/source/dnode/mnode/impl/inc/mnodeInt.h index 43af281f27..7f7f91a3af 100644 --- a/source/dnode/mnode/impl/inc/mnodeInt.h +++ b/source/dnode/mnode/impl/inc/mnodeInt.h @@ -32,7 +32,7 @@ typedef struct SMnodeBak { tmr_h timer; SSteps *pInitSteps; SSteps *pStartSteps; - SMnodeOptions para; + SMnodeOpt para; MnodeRpcFp msgFp[TSDB_MSG_TYPE_MAX]; } SMnodeBak; diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index bd89476cef..43dd57bbf8 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -77,17 +77,17 @@ static void mnodeCleanupTimer() { tmr_h mnodeGetTimer() { return tsMint.timer; } -static int32_t mnodeSetOptions(SMnode *pMnode, const SMnodeOptions *pOptions) { - pMnode->dnodeId = pOptions->dnodeId; - pMnode->clusterId = pOptions->clusterId; - pMnode->replica = pOptions->replica; - pMnode->selfIndex = pOptions->selfIndex; - memcpy(&pMnode->replicas, pOptions->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); - pMnode->pServer = pOptions->pDnode; - pMnode->putMsgToApplyMsgFp = pOptions->putMsgToApplyMsgFp; - pMnode->sendMsgToDnodeFp = pOptions->sendMsgToDnodeFp; - pMnode->sendMsgToMnodeFp = pOptions->sendMsgToMnodeFp; - pMnode->sendRedirectMsgFp = pOptions->sendRedirectMsgFp; +static int32_t mnodeSetOptions(SMnode *pMnode, const SMnodeOpt *pOption) { + pMnode->dnodeId = pOption->dnodeId; + pMnode->clusterId = pOption->clusterId; + pMnode->replica = pOption->replica; + pMnode->selfIndex = pOption->selfIndex; + memcpy(&pMnode->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); + pMnode->pServer = pOption->pDnode; + pMnode->putMsgToApplyMsgFp = pOption->putMsgToApplyMsgFp; + pMnode->sendMsgToDnodeFp = pOption->sendMsgToDnodeFp; + pMnode->sendMsgToMnodeFp = pOption->sendMsgToMnodeFp; + pMnode->sendRedirectMsgFp = pOption->sendRedirectMsgFp; if (pMnode->sendMsgToDnodeFp == NULL || pMnode->sendMsgToMnodeFp == NULL || pMnode->sendRedirectMsgFp == NULL || pMnode->putMsgToApplyMsgFp == NULL || pMnode->dnodeId < 0 || pMnode->clusterId < 0) { @@ -136,10 +136,10 @@ static int32_t mnodeAllocStartSteps() { return 0; } -SMnode *mnodeOpen(const char *path, const SMnodeOptions *pOptions) { +SMnode *mnodeOpen(const char *path, const SMnodeOpt *pOption) { SMnode *pMnode = calloc(1, sizeof(SMnode)); - if (mnodeSetOptions(pMnode, pOptions) != 0) { + if (mnodeSetOptions(pMnode, pOption) != 0) { free(pMnode); mError("failed to init mnode options since %s", terrstr()); return NULL; @@ -173,7 +173,7 @@ SMnode *mnodeOpen(const char *path, const SMnodeOptions *pOptions) { void mnodeClose(SMnode *pMnode) { free(pMnode); } -int32_t mnodeAlter(SMnode *pMnode, const SMnodeOptions *pOptions) { return 0; } +int32_t mnodeAlter(SMnode *pMnode, const SMnodeOpt *pOption) { return 0; } void mnodeDestroy(const char *path) { sdbUnDeploy(); } From 500130daf70977634f459a2779117df3dd2da2bc Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Fri, 26 Nov 2021 18:34:24 +0800 Subject: [PATCH 12/16] update fst core struct --- source/libs/index/inc/index_fst.h | 41 ++++++++++++++----------- source/libs/index/src/index_fst.c | 50 ++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 18 deletions(-) diff --git a/source/libs/index/inc/index_fst.h b/source/libs/index/inc/index_fst.h index 44b6162d49..37feb79ac8 100644 --- a/source/libs/index/inc/index_fst.h +++ b/source/libs/index/inc/index_fst.h @@ -219,23 +219,6 @@ bool fstNodeFindInput(FstNode *node, uint8_t b, uint64_t *res); bool fstNodeCompile(FstNode *node, void *w, CompiledAddr lastAddr, CompiledAddr addr, FstBuilderNode *builderNode); FstSlice fstNodeAsSlice(FstNode *node); - - -typedef struct FstMeta { - uint64_t version; - CompiledAddr rootAddr; - FstType ty; - uint64_t len; - uint32_t checkSum; -} FstMeta; - -typedef struct Fst { - FstMeta *meta; - void *data; // -} Fst; - -Fst* fstCreate(FstSlice *data); -void fstDestroy(Fst *fst); // ops typedef struct FstIndexedValue { @@ -247,5 +230,29 @@ FstLastTransition *fstLastTransitionCreate(uint8_t inp, Output out); void fstLastTransitionDestroy(FstLastTransition *trn); +typedef struct FstMeta { + uint64_t version; + CompiledAddr rootAddr; + FstType ty; + uint64_t len; + uint32_t checkSum; +} FstMeta; +typedef struct Fst { + FstMeta *meta; + FstSlice *data; // + FstNode *root; // +} Fst; + +// refactor simple function + +Fst* fstCreate(FstSlice *data); +void fstDestroy(Fst *fst); + +bool fstGet(Fst *fst, FstSlice *b, Output *out); +FstNode* fstGetNode(Fst *fst, CompiledAddr); +FstType fstGetType(Fst *fst); +CompiledAddr fstGetRootAddr(Fst *fst); +Output fstEmptyFinalOutput(Fst *fst, bool *null); +bool fstVerify(Fst *fst); #endif diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index c8ff23c1c8..465b6d154a 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -15,6 +15,7 @@ #include "index_fst.h" #include "tcoding.h" +#include "tchecksum.h" static void fstPackDeltaIn(FstCountingWriter *wrt, CompiledAddr nodeAddr, CompiledAddr transAddr, uint8_t nBytes) { @@ -923,7 +924,6 @@ void fstBuilderNodeUnfinishedAddOutputPrefix(FstBuilderNodeUnfinished *unNode, O } Fst* fstCreate(FstSlice *slice) { - char *buf = slice->data; uint64_t skip = 0; uint64_t len = slice->dLen; @@ -968,6 +968,7 @@ Fst* fstCreate(FstSlice *slice) { fst->meta->ty = type; fst->meta->len = fstLen; fst->meta->checkSum = checkSum; + fst->data = slice; return fst; FST_CREAT_FAILED: @@ -976,7 +977,54 @@ FST_CREAT_FAILED: } void fstDestroy(Fst *fst) { + if (fst) { + free(fst->meta); + fstNodeDestroy(fst->root); + } + free(fst); +} +bool fstGet(Fst *fst, FstSlice *b, Output *out) { + + return false; +} + +FstNode* fstGetNode(Fst *fst, CompiledAddr addr) { + if (fst->root != NULL) { + return fst->root; + } + fst->root = fstNodeCreate(fst->meta->version, addr, fst->data); + return fst->root; + +} +FstType fstGetType(Fst *fst) { + return fst->meta->ty; +} +CompiledAddr fstGetRootAddr(Fst *fst) { + return fst->meta->rootAddr; +} + +Output fstEmptyFinalOutput(Fst *fst, bool *null) { + Output res = 0; + FstNode *node = fst->root; + if (FST_NODE_IS_FINAL(node)) { + *null = false; + res = FST_NODE_FINAL_OUTPUT(node); + } else { + *null = true; + } + return res; +} + + +bool fstVerify(Fst *fst) { + uint32_t checkSum = fst->meta->checkSum; + FstSlice *data = fst->data; + TSCKSUM initSum = 0; + if (taosCheckChecksumWhole(data->data, data->dLen)) { + return false; + } + } From 8bf34d89607ffedb0c4a09d3fd1271d945e73cf3 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Nov 2021 00:25:31 +0800 Subject: [PATCH 13/16] TD-11265 save mnode replicas in mnode.json --- source/dnode/mgmt/impl/inc/dndInt.h | 3 ++ source/dnode/mgmt/impl/src/dndMnode.c | 76 +++++++++++++++++++++++++-- 2 files changed, 74 insertions(+), 5 deletions(-) diff --git a/source/dnode/mgmt/impl/inc/dndInt.h b/source/dnode/mgmt/impl/inc/dndInt.h index 4094871bcd..106f192856 100644 --- a/source/dnode/mgmt/impl/inc/dndInt.h +++ b/source/dnode/mgmt/impl/inc/dndInt.h @@ -71,6 +71,9 @@ typedef struct { int32_t refCount; int8_t deployed; int8_t dropped; + int8_t replica; + int8_t selfIndex; + SReplica replicas[TSDB_MAX_REPLICA]; SWorkerPool mgmtPool; SWorkerPool readPool; SWorkerPool writePool; diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index 0a764af8dc..fa35e9b573 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -101,7 +101,7 @@ static int32_t dndReadMnodeFile(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; int32_t code = TSDB_CODE_DND_MNODE_READ_FILE_ERROR; int32_t len = 0; - int32_t maxLen = 300; + int32_t maxLen = 4096; char *content = calloc(1, maxLen + 1); cJSON *root = NULL; @@ -139,6 +139,46 @@ static int32_t dndReadMnodeFile(SDnode *pDnode) { } pMgmt->dropped = atoi(dropped->valuestring); + cJSON *nodes = cJSON_GetObjectItem(root, "nodes"); + if (!nodes || nodes->type != cJSON_Array) { + dError("failed to read %s since nodes not found", pMgmt->file); + goto PRASE_MNODE_OVER; + } + + pMgmt->replica = cJSON_GetArraySize(nodes); + if (pMgmt->replica <= 0 || pMgmt->replica > TSDB_MAX_REPLICA) { + dError("failed to read %s since nodes size %d invalid", pMgmt->file, pMgmt->replica); + goto PRASE_MNODE_OVER; + } + + for (int32_t i = 0; i < pMgmt->replica; ++i) { + cJSON *node = cJSON_GetArrayItem(nodes, i); + if (node == NULL) break; + + SReplica *pReplica = &pMgmt->replicas[i]; + + cJSON *id = cJSON_GetObjectItem(node, "id"); + if (!id || id->type != cJSON_String || id->valuestring == NULL) { + dError("failed to read %s since id not found", pMgmt->file); + goto PRASE_MNODE_OVER; + } + pReplica->id = atoi(id->valuestring); + + cJSON *fqdn = cJSON_GetObjectItem(node, "fqdn"); + if (!fqdn || fqdn->type != cJSON_String || fqdn->valuestring == NULL) { + dError("failed to read %s since fqdn not found", pMgmt->file); + goto PRASE_MNODE_OVER; + } + tstrncpy(pReplica->fqdn, fqdn->valuestring, TSDB_FQDN_LEN); + + cJSON *port = cJSON_GetObjectItem(node, "port"); + if (!port || port->type != cJSON_String || port->valuestring == NULL) { + dError("failed to read %s since port not found", pMgmt->file); + goto PRASE_MNODE_OVER; + } + pReplica->port = atoi(port->valuestring); + } + code = 0; dInfo("succcessed to read file %s", pMgmt->file); @@ -153,7 +193,8 @@ PRASE_MNODE_OVER: static int32_t dndWriteMnodeFile(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; - char file[PATH_MAX + 20] = {0}; + + char file[PATH_MAX + 20] = {0}; snprintf(file, sizeof(file), "%s.bak", pMgmt->file); FILE *fp = fopen(file, "w"); @@ -164,12 +205,25 @@ static int32_t dndWriteMnodeFile(SDnode *pDnode) { } int32_t len = 0; - int32_t maxLen = 300; + int32_t maxLen = 4096; char *content = calloc(1, maxLen + 1); len += snprintf(content + len, maxLen - len, "{\n"); len += snprintf(content + len, maxLen - len, " \"deployed\": \"%d\",\n", pMgmt->deployed); - len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\"\n", pMgmt->dropped); + + len += snprintf(content + len, maxLen - len, " \"dropped\": \"%d\",\n", pMgmt->dropped); + len += snprintf(content + len, maxLen - len, " \"nodes\": [{\n"); + for (int32_t i = 0; i < pMgmt->replica; ++i) { + SReplica *pReplica = &pMgmt->replicas[i]; + len += snprintf(content + len, maxLen - len, " \"id\": \"%d\",\n", pReplica->id); + len += snprintf(content + len, maxLen - len, " \"fqdn\": \"%s\",\n", pReplica->fqdn); + len += snprintf(content + len, maxLen - len, " \"port\": \"%u\"\n", pReplica->port); + if (i < pMgmt->replica - 1) { + len += snprintf(content + len, maxLen - len, " },{\n"); + } else { + len += snprintf(content + len, maxLen - len, " }]\n"); + } + } len += snprintf(content + len, maxLen - len, "}\n"); fwrite(content, 1, len, fp); @@ -269,11 +323,19 @@ static void dndBuildMnodeDeployOption(SDnode *pDnode, SMnodeOpt *pOption) { pReplica->id = 1; pReplica->port = pDnode->opt.serverPort; tstrncpy(pReplica->fqdn, pDnode->opt.localFqdn, TSDB_FQDN_LEN); + + SMnodeMgmt *pMgmt = &pDnode->mmgmt; + pMgmt->selfIndex = pOption->selfIndex; + pMgmt->replica = pOption->replica; + memcpy(&pMgmt->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); } static void dndBuildMnodeOpenOption(SDnode *pDnode, SMnodeOpt *pOption) { dndInitMnodeOption(pDnode, pOption); - pOption->replica = 0; + SMnodeMgmt *pMgmt = &pDnode->mmgmt; + pOption->selfIndex = pMgmt->selfIndex; + pOption->replica = pMgmt->replica; + memcpy(&pOption->replicas, pMgmt->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); } static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SCreateMnodeMsg *pMsg) { @@ -299,6 +361,10 @@ static int32_t dndBuildMnodeOptionFromMsg(SDnode *pDnode, SMnodeOpt *pOption, SC return -1; } + SMnodeMgmt *pMgmt = &pDnode->mmgmt; + pMgmt->selfIndex = pOption->selfIndex; + pMgmt->replica = pOption->replica; + memcpy(&pMgmt->replicas, pOption->replicas, sizeof(SReplica) * TSDB_MAX_REPLICA); return 0; } From 7330b0f8c870e39da440f5b5156806a6651ed135 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Nov 2021 14:57:16 +0800 Subject: [PATCH 14/16] remove printf --- source/dnode/mgmt/impl/src/dndMnode.c | 21 +++++- source/dnode/mnode/impl/src/mnode.c | 2 +- source/os/src/osDir.c | 10 +-- source/os/src/osFile.c | 4 +- source/os/src/osSocket.c | 96 +++++++++++++-------------- source/os/src/osString.c | 2 +- source/os/src/osSysinfo.c | 90 ++++++++++++------------- source/os/src/osSystem.c | 10 +-- source/os/src/osTimer.c | 14 ++-- 9 files changed, 134 insertions(+), 115 deletions(-) diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index fa35e9b573..a4f6d845fd 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -198,7 +198,7 @@ static int32_t dndWriteMnodeFile(SDnode *pDnode) { snprintf(file, sizeof(file), "%s.bak", pMgmt->file); FILE *fp = fopen(file, "w"); - if (fp != NULL) { + if (fp == NULL) { terrno = TSDB_CODE_DND_MNODE_WRITE_FILE_ERROR; dError("failed to write %s since %s", file, terrstr()); return -1; @@ -242,6 +242,21 @@ static int32_t dndWriteMnodeFile(SDnode *pDnode) { } static int32_t dndStartMnodeWorker(SDnode *pDnode) { + if (dndInitMnodeReadWorker(pDnode) != 0) { + dError("failed to start mnode read worker since %s", terrstr()); + return -1; + } + + if (dndInitMnodeWriteWorker(pDnode) != 0) { + dError("failed to start mnode write worker since %s", terrstr()); + return -1; + } + + if (dndInitMnodeSyncWorker(pDnode) != 0) { + dError("failed to start mnode sync worker since %s", terrstr()); + return -1; + } + if (dndAllocMnodeReadQueue(pDnode) != 0) { dError("failed to alloc mnode read queue since %s", terrstr()); return -1; @@ -708,6 +723,7 @@ static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } + return 0; } @@ -743,6 +759,7 @@ static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } + return 0; } @@ -759,6 +776,7 @@ static int32_t dndAllocMnodeApplyQueue(SDnode *pDnode) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } + return 0; } @@ -794,6 +812,7 @@ static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } + return 0; } diff --git a/source/dnode/mnode/impl/src/mnode.c b/source/dnode/mnode/impl/src/mnode.c index 43dd57bbf8..8fc5de588f 100644 --- a/source/dnode/mnode/impl/src/mnode.c +++ b/source/dnode/mnode/impl/src/mnode.c @@ -31,9 +31,9 @@ #include "mnodeStable.h" #include "mnodeSync.h" #include "mnodeTelem.h" +#include "mnodeTrans.h" #include "mnodeUser.h" #include "mnodeVgroup.h" -#include "mnodeTrans.h" SMnodeBak tsMint = {0}; diff --git a/source/os/src/osDir.c b/source/os/src/osDir.c index cfa0028925..070fe4a6c8 100644 --- a/source/os/src/osDir.c +++ b/source/os/src/osDir.c @@ -48,14 +48,14 @@ void taosRemoveDir(const char *dirname) { taosRemoveDir(filename); } else { (void)remove(filename); - printf("file:%s is removed\n", filename); + //printf("file:%s is removed\n", filename); } } closedir(dir); rmdir(dirname); - printf("dir:%s is removed\n", dirname); + //printf("dir:%s is removed\n", dirname); } int32_t taosDirExist(char *dirname) { return access(dirname, F_OK); } @@ -101,9 +101,9 @@ void taosRemoveOldFiles(char *dirname, int32_t keepDays) { int32_t days = (int32_t)(ABS(sec - fileSec) / 86400 + 1); if (days > keepDays) { (void)remove(filename); - printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays); + //printf("file:%s is removed, days:%d keepDays:%d", filename, days, keepDays); } else { - printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays); + //printf("file:%s won't be removed, days:%d keepDays:%d", filename, days, keepDays); } } } @@ -115,7 +115,7 @@ void taosRemoveOldFiles(char *dirname, int32_t keepDays) { int32_t taosExpandDir(char *dirname, char *outname, int32_t maxlen) { wordexp_t full_path; if (0 != wordexp(dirname, &full_path, 0)) { - printf("failed to expand path:%s since %s", dirname, strerror(errno)); + //printf("failed to expand path:%s since %s", dirname, strerror(errno)); wordfree(&full_path); return -1; } diff --git a/source/os/src/osFile.c b/source/os/src/osFile.c index b5d30d7c25..bdf3a53dcb 100644 --- a/source/os/src/osFile.c +++ b/source/os/src/osFile.c @@ -404,14 +404,14 @@ int32_t taosRenameFile(char *oldName, char *newName) { #if defined(_TD_WINDOWS_64) || defined(_TD_WINDOWS_32) int32_t code = MoveFileEx(oldName, newName, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED); if (code < 0) { - printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); + //printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); } return code; #else int32_t code = rename(oldName, newName); if (code < 0) { - printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); + //printf("failed to rename file %s to %s, reason:%s", oldName, newName, strerror(errno)); } return code; diff --git a/source/os/src/osSocket.c b/source/os/src/osSocket.c index fb1aeebe1c..e12f9493b3 100644 --- a/source/os/src/osSocket.c +++ b/source/os/src/osSocket.c @@ -95,7 +95,7 @@ void taosShutDownSocketWR(SOCKET fd) { int32_t taosSetNonblocking(SOCKET sock, int32_t on) { int32_t flags = 0; if ((flags = fcntl(sock, F_GETFL, 0)) < 0) { - printf("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno)); + //printf("fcntl(F_GETFL) error: %d (%s)\n", errno, strerror(errno)); return 1; } @@ -105,7 +105,7 @@ int32_t taosSetNonblocking(SOCKET sock, int32_t on) { flags &= ~O_NONBLOCK; if ((flags = fcntl(sock, F_SETFL, flags)) < 0) { - printf("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno)); + //printf("fcntl(F_SETFL) error: %d (%s)\n", errno, strerror(errno)); return 1; } @@ -120,7 +120,7 @@ void taosBlockSIGPIPE() { sigaddset(&signal_mask, SIGPIPE); int32_t rc = pthread_sigmask(SIG_BLOCK, &signal_mask, NULL); if (rc != 0) { - printf("failed to block SIGPIPE"); + //printf("failed to block SIGPIPE"); } } @@ -130,7 +130,7 @@ void taosSetMaskSIGPIPE() { sigaddset(&signal_mask, SIGPIPE); int32_t rc = pthread_sigmask(SIG_SETMASK, &signal_mask, NULL); if (rc != 0) { - printf("failed to setmask SIGPIPE"); + //printf("failed to setmask SIGPIPE"); } } @@ -277,7 +277,7 @@ int32_t taosGetFqdn(char *fqdn) { char hostname[1024]; hostname[1023] = '\0'; if (gethostname(hostname, 1023) == -1) { - printf("failed to get hostname, reason:%s", strerror(errno)); + //printf("failed to get hostname, reason:%s", strerror(errno)); return -1; } @@ -294,7 +294,7 @@ int32_t taosGetFqdn(char *fqdn) { #endif // __APPLE__ int32_t ret = getaddrinfo(hostname, NULL, &hints, &result); if (!result) { - printf("failed to get fqdn, code:%d, reason:%s", ret, gai_strerror(ret)); + //printf("failed to get fqdn, code:%d, reason:%s", ret, gai_strerror(ret)); return -1; } @@ -326,12 +326,12 @@ uint32_t taosGetIpv4FromFqdn(const char *fqdn) { } else { #ifdef EAI_SYSTEM if (ret == EAI_SYSTEM) { - printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, strerror(errno)); + //printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, strerror(errno)); } else { - printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, gai_strerror(ret)); + //printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, gai_strerror(ret)); } #else - printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, gai_strerror(ret)); + //printf("failed to get the ip address, fqdn:%s, since:%s", fqdn, gai_strerror(ret)); #endif return 0xFFFFFFFF; } @@ -437,13 +437,13 @@ int32_t taosNonblockwrite(SOCKET fd, char *ptr, int32_t nbytes) { FD_SET(fd, &fset); if ((nready = select((int32_t)(fd + 1), NULL, &fset, NULL, &tv)) == 0) { errno = ETIMEDOUT; - printf("fd %d timeout, no enough space to write", fd); + //printf("fd %d timeout, no enough space to write", fd); break; } else if (nready < 0) { if (errno == EINTR) continue; - printf("select error, %d (%s)", errno, strerror(errno)); + //printf("select error, %d (%s)", errno, strerror(errno)); return -1; } @@ -451,7 +451,7 @@ int32_t taosNonblockwrite(SOCKET fd, char *ptr, int32_t nbytes) { if (nwritten <= 0) { if (errno == EAGAIN || errno == EINTR) continue; - printf("write error, %d (%s)", errno, strerror(errno)); + //printf("write error, %d (%s)", errno, strerror(errno)); return -1; } @@ -477,21 +477,21 @@ int32_t taosReadn(SOCKET fd, char *ptr, int32_t nbytes) { FD_SET(fd, &fset); if ((nready = select((int32_t)(fd + 1), NULL, &fset, NULL, &tv)) == 0) { errno = ETIMEDOUT; - printf("fd %d timeout\n", fd); + //printf("fd %d timeout\n", fd); break; } else if (nready < 0) { if (errno == EINTR) continue; - printf("select error, %d (%s)", errno, strerror(errno)); + //printf("select error, %d (%s)", errno, strerror(errno)); return -1; } if ((nread = (int32_t)taosReadSocket(fd, ptr, (size_t)nleft)) < 0) { if (errno == EINTR) continue; - printf("read error, %d (%s)", errno, strerror(errno)); + //printf("read error, %d (%s)", errno, strerror(errno)); return -1; } else if (nread == 0) { - printf("fd %d EOF", fd); + //printf("fd %d EOF", fd); break; // EOF } @@ -507,7 +507,7 @@ SOCKET taosOpenUdpSocket(uint32_t ip, uint16_t port) { SOCKET sockFd; int32_t bufSize = 1024000; - printf("open udp socket:0x%x:%hu", ip, port); + //printf("open udp socket:0x%x:%hu", ip, port); memset((char *)&localAddr, 0, sizeof(localAddr)); localAddr.sin_family = AF_INET; @@ -515,26 +515,26 @@ SOCKET taosOpenUdpSocket(uint32_t ip, uint16_t port) { localAddr.sin_port = (uint16_t)htons(port); if ((sockFd = socket(AF_INET, SOCK_DGRAM, 0)) <= 2) { - printf("failed to open udp socket: %d (%s)", errno, strerror(errno)); + //printf("failed to open udp socket: %d (%s)", errno, strerror(errno)); taosCloseSocketNoCheck(sockFd); return -1; } if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_SNDBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { - printf("failed to set the send buffer size for UDP socket\n"); + //printf("failed to set the send buffer size for UDP socket\n"); taosCloseSocket(sockFd); return -1; } if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_RCVBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { - printf("failed to set the receive buffer size for UDP socket\n"); + //printf("failed to set the receive buffer size for UDP socket\n"); taosCloseSocket(sockFd); return -1; } /* bind socket to local address */ if (bind(sockFd, (struct sockaddr *)&localAddr, sizeof(localAddr)) < 0) { - printf("failed to bind udp socket: %d (%s), 0x%x:%hu", errno, strerror(errno), ip, port); + //printf("failed to bind udp socket: %d (%s), 0x%x:%hu", errno, strerror(errno), ip, port); taosCloseSocket(sockFd); return -1; } @@ -551,7 +551,7 @@ SOCKET taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clie sockFd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); if (sockFd <= 2) { - printf("failed to open the socket: %d (%s)", errno, strerror(errno)); + //printf("failed to open the socket: %d (%s)", errno, strerror(errno)); taosCloseSocketNoCheck(sockFd); return -1; } @@ -559,19 +559,19 @@ SOCKET taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clie /* set REUSEADDR option, so the portnumber can be re-used */ int32_t reuse = 1; if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { - printf("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); + //printf("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); taosCloseSocket(sockFd); return -1; } if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_SNDBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { - printf("failed to set the send buffer size for TCP socket\n"); + //printf("failed to set the send buffer size for TCP socket\n"); taosCloseSocket(sockFd); return -1; } if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_RCVBUF, (void *)&bufSize, sizeof(bufSize)) != 0) { - printf("failed to set the receive buffer size for TCP socket\n"); + //printf("failed to set the receive buffer size for TCP socket\n"); taosCloseSocket(sockFd); return -1; } @@ -584,8 +584,8 @@ SOCKET taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clie /* bind socket to client address */ if (bind(sockFd, (struct sockaddr *)&clientAddr, sizeof(clientAddr)) < 0) { - printf("bind tcp client socket failed, client(0x%x:0), dest(0x%x:%d), reason:(%s)", clientIp, destIp, destPort, - strerror(errno)); + //printf("bind tcp client socket failed, client(0x%x:0), dest(0x%x:%d), reason:(%s)", clientIp, destIp, destPort, + // strerror(errno)); taosCloseSocket(sockFd); return -1; } @@ -601,7 +601,7 @@ SOCKET taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clie ret = connect(sockFd, (struct sockaddr *)&serverAddr, sizeof(serverAddr)); if (ret == -1) { if (errno == EHOSTUNREACH) { - printf("failed to connect socket, ip:0x%x, port:%hu(%s)", destIp, destPort, strerror(errno)); + //printf("failed to connect socket, ip:0x%x, port:%hu(%s)", destIp, destPort, strerror(errno)); taosCloseSocket(sockFd); return -1; } else if (errno == EINPROGRESS || errno == EAGAIN || errno == EWOULDBLOCK) { @@ -612,19 +612,19 @@ SOCKET taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clie int res = poll(wfd, 1, TCP_CONN_TIMEOUT); if (res == -1 || res == 0) { - printf("failed to connect socket, ip:0x%x, port:%hu(poll error/conn timeout)", destIp, destPort); + //printf("failed to connect socket, ip:0x%x, port:%hu(poll error/conn timeout)", destIp, destPort); taosCloseSocket(sockFd); // return -1; } int optVal = -1, optLen = sizeof(int); if ((0 != taosGetSockOpt(sockFd, SOL_SOCKET, SO_ERROR, &optVal, &optLen)) || (optVal != 0)) { - printf("failed to connect socket, ip:0x%x, port:%hu(connect host error)", destIp, destPort); + //printf("failed to connect socket, ip:0x%x, port:%hu(connect host error)", destIp, destPort); taosCloseSocket(sockFd); // return -1; } ret = 0; } else { // Other error - printf("failed to connect socket, ip:0x%x, port:%hu(target host cannot be reached)", destIp, destPort); + //printf("failed to connect socket, ip:0x%x, port:%hu(target host cannot be reached)", destIp, destPort); taosCloseSocket(sockFd); // return -1; } @@ -636,7 +636,7 @@ SOCKET taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clie #endif if (ret != 0) { - printf("failed to connect socket, ip:0x%x, port:%hu(%s)", destIp, destPort, strerror(errno)); + //printf("failed to connect socket, ip:0x%x, port:%hu(%s)", destIp, destPort, strerror(errno)); taosCloseSocket(sockFd); sockFd = -1; } else { @@ -649,7 +649,7 @@ SOCKET taosOpenTcpClientSocket(uint32_t destIp, uint16_t destPort, uint32_t clie int32_t taosKeepTcpAlive(SOCKET sockFd) { int32_t alive = 1; if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_KEEPALIVE, (void *)&alive, sizeof(alive)) < 0) { - printf("fd:%d setsockopt SO_KEEPALIVE failed: %d (%s)", sockFd, errno, strerror(errno)); + //printf("fd:%d setsockopt SO_KEEPALIVE failed: %d (%s)", sockFd, errno, strerror(errno)); taosCloseSocket(sockFd); return -1; } @@ -658,21 +658,21 @@ int32_t taosKeepTcpAlive(SOCKET sockFd) { // all fails on macosx int32_t probes = 3; if (taosSetSockOpt(sockFd, SOL_TCP, TCP_KEEPCNT, (void *)&probes, sizeof(probes)) < 0) { - printf("fd:%d setsockopt SO_KEEPCNT failed: %d (%s)", sockFd, errno, strerror(errno)); + //printf("fd:%d setsockopt SO_KEEPCNT failed: %d (%s)", sockFd, errno, strerror(errno)); taosCloseSocket(sockFd); return -1; } int32_t alivetime = 10; if (taosSetSockOpt(sockFd, SOL_TCP, TCP_KEEPIDLE, (void *)&alivetime, sizeof(alivetime)) < 0) { - printf("fd:%d setsockopt SO_KEEPIDLE failed: %d (%s)", sockFd, errno, strerror(errno)); + //printf("fd:%d setsockopt SO_KEEPIDLE failed: %d (%s)", sockFd, errno, strerror(errno)); taosCloseSocket(sockFd); return -1; } int32_t interval = 3; if (taosSetSockOpt(sockFd, SOL_TCP, TCP_KEEPINTVL, (void *)&interval, sizeof(interval)) < 0) { - printf("fd:%d setsockopt SO_KEEPINTVL failed: %d (%s)", sockFd, errno, strerror(errno)); + //printf("fd:%d setsockopt SO_KEEPINTVL failed: %d (%s)", sockFd, errno, strerror(errno)); taosCloseSocket(sockFd); return -1; } @@ -680,7 +680,7 @@ int32_t taosKeepTcpAlive(SOCKET sockFd) { int32_t nodelay = 1; if (taosSetSockOpt(sockFd, IPPROTO_TCP, TCP_NODELAY, (void *)&nodelay, sizeof(nodelay)) < 0) { - printf("fd:%d setsockopt TCP_NODELAY failed %d (%s)", sockFd, errno, strerror(errno)); + //printf("fd:%d setsockopt TCP_NODELAY failed %d (%s)", sockFd, errno, strerror(errno)); taosCloseSocket(sockFd); return -1; } @@ -689,7 +689,7 @@ int32_t taosKeepTcpAlive(SOCKET sockFd) { linger.l_onoff = 1; linger.l_linger = 3; if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_LINGER, (void *)&linger, sizeof(linger)) < 0) { - printf("setsockopt SO_LINGER failed: %d (%s)", errno, strerror(errno)); + //printf("setsockopt SO_LINGER failed: %d (%s)", errno, strerror(errno)); taosCloseSocket(sockFd); return -1; } @@ -702,7 +702,7 @@ SOCKET taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { SOCKET sockFd; int32_t reuse; - printf("open tcp server socket:0x%x:%hu", ip, port); + //printf("open tcp server socket:0x%x:%hu", ip, port); bzero((char *)&serverAdd, sizeof(serverAdd)); serverAdd.sin_family = AF_INET; @@ -710,7 +710,7 @@ SOCKET taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { serverAdd.sin_port = (uint16_t)htons(port); if ((sockFd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) <= 2) { - printf("failed to open TCP socket: %d (%s)", errno, strerror(errno)); + //printf("failed to open TCP socket: %d (%s)", errno, strerror(errno)); taosCloseSocketNoCheck(sockFd); return -1; } @@ -718,26 +718,26 @@ SOCKET taosOpenTcpServerSocket(uint32_t ip, uint16_t port) { /* set REUSEADDR option, so the portnumber can be re-used */ reuse = 1; if (taosSetSockOpt(sockFd, SOL_SOCKET, SO_REUSEADDR, (void *)&reuse, sizeof(reuse)) < 0) { - printf("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); + //printf("setsockopt SO_REUSEADDR failed: %d (%s)", errno, strerror(errno)); taosCloseSocket(sockFd); return -1; } /* bind socket to server address */ if (bind(sockFd, (struct sockaddr *)&serverAdd, sizeof(serverAdd)) < 0) { - printf("bind tcp server socket failed, 0x%x:%hu(%s)", ip, port, strerror(errno)); + //printf("bind tcp server socket failed, 0x%x:%hu(%s)", ip, port, strerror(errno)); taosCloseSocket(sockFd); return -1; } if (taosKeepTcpAlive(sockFd) < 0) { - printf("failed to set tcp server keep-alive option, 0x%x:%hu(%s)", ip, port, strerror(errno)); + //printf("failed to set tcp server keep-alive option, 0x%x:%hu(%s)", ip, port, strerror(errno)); taosCloseSocket(sockFd); return -1; } if (listen(sockFd, 1024) < 0) { - printf("listen tcp server socket failed, 0x%x:%hu(%s)", ip, port, strerror(errno)); + //printf("listen tcp server socket failed, 0x%x:%hu(%s)", ip, port, strerror(errno)); taosCloseSocket(sockFd); return -1; } @@ -767,16 +767,16 @@ int64_t taosCopyFds(SOCKET sfd, int32_t dfd, int64_t len) { int64_t retLen = taosReadMsg(sfd, temp, (int32_t)readLen); if (readLen != retLen) { - printf("read error, readLen:%" PRId64 " retLen:%" PRId64 " len:%" PRId64 " leftLen:%" PRId64 ", reason:%s", - readLen, retLen, len, leftLen, strerror(errno)); + //printf("read error, readLen:%" PRId64 " retLen:%" PRId64 " len:%" PRId64 " leftLen:%" PRId64 ", reason:%s", + // readLen, retLen, len, leftLen, strerror(errno)); return -1; } writeLen = taosWriteMsg(dfd, temp, (int32_t)readLen); if (readLen != writeLen) { - printf("copy error, readLen:%" PRId64 " writeLen:%" PRId64 " len:%" PRId64 " leftLen:%" PRId64 ", reason:%s", - readLen, writeLen, len, leftLen, strerror(errno)); + //printf("copy error, readLen:%" PRId64 " writeLen:%" PRId64 " len:%" PRId64 " leftLen:%" PRId64 ", reason:%s", + // readLen, writeLen, len, leftLen, strerror(errno)); return -1; } diff --git a/source/os/src/osString.c b/source/os/src/osString.c index 10606a3d7b..8054dc42be 100644 --- a/source/os/src/osString.c +++ b/source/os/src/osString.c @@ -277,7 +277,7 @@ char *strsep(char **stringp, const char *delim) { char *getpass(const char *prefix) { static char passwd[TSDB_KEY_LEN] = {0}; memset(passwd, 0, TSDB_KEY_LEN); - printf("%s", prefix); + //printf("%s", prefix); int32_t index = 0; char ch; diff --git a/source/os/src/osSysinfo.c b/source/os/src/osSysinfo.c index 0344507f5e..e37e059b7d 100644 --- a/source/os/src/osSysinfo.c +++ b/source/os/src/osSysinfo.c @@ -134,7 +134,7 @@ int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { diskSize->used = (int64_t)(i64TotalBytes - i64FreeBytes); return 0; } else { - printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); + //printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } @@ -205,12 +205,12 @@ void taosGetSystemInfo() { } void taosKillSystem() { - printf("function taosKillSystem, exit!"); + //printf("function taosKillSystem, exit!"); exit(0); } int taosSystem(const char *cmd) { - printf("taosSystem not support"); + //printf("taosSystem not support"); return -1; } @@ -280,7 +280,7 @@ static void taosGetSystemTimezone() { { int n = readlink("/etc/localtime", buf, sizeof(buf)); if (n < 0) { - printf("read /etc/localtime error, reason:%s", strerror(errno)); + //printf("read /etc/localtime error, reason:%s", strerror(errno)); return; } buf[n] = '\0'; @@ -294,7 +294,7 @@ static void taosGetSystemTimezone() { } } if (!tz || 0 == strchr(tz, '/')) { - printf("parsing /etc/localtime failed"); + //printf("parsing /etc/localtime failed"); return; } @@ -321,7 +321,7 @@ static void taosGetSystemTimezone() { -timezone / 3600); // cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; - printf("timezone not configured, set to system default:%s", tsTimezone); + //printf("timezone not configured, set to system default:%s", tsTimezone); } /* @@ -348,11 +348,11 @@ static void taosGetSystemLocale() { // get and set default locale locale = setlocale(LC_CTYPE, ""); if (locale == NULL) { - printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno)); + //printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno)); strcpy(tsLocale, "en_US.UTF-8"); } else { tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN); - printf("locale not configured, set to system default:%s", tsLocale); + //printf("locale not configured, set to system default:%s", tsLocale); } /* if user does not specify the charset, extract it from locale */ @@ -364,15 +364,15 @@ static void taosGetSystemLocale() { // get and set default locale tstrncpy(tsCharset, revisedCharset, TSDB_LOCALE_LEN); free(revisedCharset); - printf("charset not configured, set to system default:%s", tsCharset); + //printf("charset not configured, set to system default:%s", tsCharset); } else { strcpy(tsCharset, "UTF-8"); - printf("can't get locale and charset from system, set it to UTF-8"); + //printf("can't get locale and charset from system, set it to UTF-8"); } } void taosKillSystem() { - printf("function taosKillSystem, exit!"); + //printf("function taosKillSystem, exit!"); exit(0); } @@ -432,7 +432,7 @@ bool taosGetSysMemory(float *memoryUsedMB) { } int taosSystem(const char *cmd) { - printf("un support funtion"); + //printf("un support funtion"); return -1; } @@ -441,7 +441,7 @@ void taosSetCoreDump() {} int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { struct statvfs info; if (statvfs(dataDir, &info)) { - printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); + //printf("failed to get disk size, dataDir:%s errno:%s", tsDataDir, strerror(errno)); terrno = TAOS_SYSTEM_ERROR(errno); return -1; } else { @@ -535,7 +535,7 @@ bool taosGetSysMemory(float *memoryUsedMB) { bool taosGetProcMemory(float *memoryUsedMB) { FILE *fp = fopen(tsProcMemFile, "r"); if (fp == NULL) { - printf("open file:%s failed", tsProcMemFile); + //printf("open file:%s failed", tsProcMemFile); return false; } @@ -555,7 +555,7 @@ bool taosGetProcMemory(float *memoryUsedMB) { } if (line == NULL) { - printf("read file:%s failed", tsProcMemFile); + //printf("read file:%s failed", tsProcMemFile); fclose(fp); return false; } @@ -573,7 +573,7 @@ bool taosGetProcMemory(float *memoryUsedMB) { static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { FILE *fp = fopen(tsSysCpuFile, "r"); if (fp == NULL) { - printf("open file:%s failed", tsSysCpuFile); + //printf("open file:%s failed", tsSysCpuFile); return false; } @@ -581,7 +581,7 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { char * line = NULL; ssize_t _bytes = getline(&line, &len, fp); if ((_bytes < 0) || (line == NULL)) { - printf("read file:%s failed", tsSysCpuFile); + //printf("read file:%s failed", tsSysCpuFile); fclose(fp); return false; } @@ -598,7 +598,7 @@ static bool taosGetSysCpuInfo(SysCpuInfo *cpuInfo) { static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { FILE *fp = fopen(tsProcCpuFile, "r"); if (fp == NULL) { - printf("open file:%s failed", tsProcCpuFile); + //printf("open file:%s failed", tsProcCpuFile); return false; } @@ -606,7 +606,7 @@ static bool taosGetProcCpuInfo(ProcCpuInfo *cpuInfo) { char * line = NULL; ssize_t _bytes = getline(&line, &len, fp); if ((_bytes < 0) || (line == NULL)) { - printf("read file:%s failed", tsProcCpuFile); + //printf("read file:%s failed", tsProcCpuFile); fclose(fp); return false; } @@ -642,7 +642,7 @@ static void taosGetSystemTimezone() { int len = fread(buf, 64, 1, f); if (len < 64 && ferror(f)) { fclose(f); - printf("read /etc/timezone error, reason:%s", strerror(errno)); + //printf("read /etc/timezone error, reason:%s", strerror(errno)); return; } @@ -681,7 +681,7 @@ static void taosGetSystemTimezone() { snprintf(tsTimezone, TSDB_TIMEZONE_LEN, "%s (%s, %s%02d00)", buf, tzname[daylight], tz >= 0 ? "+" : "-", abs(tz)); // cfg_timezone->cfgStatus = TAOS_CFG_CSTATUS_DEFAULT; - printf("timezone not configured, set to system default:%s", tsTimezone); + //printf("timezone not configured, set to system default:%s", tsTimezone); } /* @@ -707,11 +707,11 @@ static void taosGetSystemLocale() { // get and set default locale locale = setlocale(LC_CTYPE, ""); if (locale == NULL) { - printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno)); + //printf("can't get locale from system, set it to en_US.UTF-8 since error:%d:%s", errno, strerror(errno)); strcpy(tsLocale, "en_US.UTF-8"); } else { tstrncpy(tsLocale, locale, TSDB_LOCALE_LEN); - printf("locale not configured, set to system default:%s", tsLocale); + //printf("locale not configured, set to system default:%s", tsLocale); } /* if user does not specify the charset, extract it from locale */ @@ -723,10 +723,10 @@ static void taosGetSystemLocale() { // get and set default locale tstrncpy(tsCharset, revisedCharset, TSDB_LOCALE_LEN); free(revisedCharset); - printf("charset not configured, set to system default:%s", tsCharset); + //printf("charset not configured, set to system default:%s", tsCharset); } else { strcpy(tsCharset, "UTF-8"); - printf("can't get locale and charset from system, set it to UTF-8"); + //printf("can't get locale and charset from system, set it to UTF-8"); } } @@ -774,7 +774,7 @@ bool taosGetCpuUsage(float *sysCpuUsage, float *procCpuUsage) { int32_t taosGetDiskSize(char *dataDir, SysDiskSize *diskSize) { struct statvfs info; if (statvfs(dataDir, &info)) { - printf("failed to get disk size, dataDir:%s errno:%s", dataDir, strerror(errno)); + //printf("failed to get disk size, dataDir:%s errno:%s", dataDir, strerror(errno)); return -1; } else { diskSize->tsize = info.f_blocks * info.f_frsize; @@ -788,7 +788,7 @@ bool taosGetCardInfo(int64_t *bytes, int64_t *rbytes, int64_t *tbytes) { *bytes = 0; FILE *fp = fopen(tsSysNetFile, "r"); if (fp == NULL) { - printf("open file:%s failed", tsSysNetFile); + //printf("open file:%s failed", tsSysNetFile); return false; } @@ -864,7 +864,7 @@ bool taosGetBandSpeed(float *bandSpeedKb) { double totalBytes = (double)(curBytes - lastBytes) / 1024 * 8; // Kb *bandSpeedKb = (float)(totalBytes / (double)(curTime - lastTime)); - // printf("bandwidth lastBytes:%ld, lastTime:%ld, curBytes:%ld, curTime:%ld, + // //printf("bandwidth lastBytes:%ld, lastTime:%ld, curBytes:%ld, curTime:%ld, // speed:%f", lastBytes, lastTime, curBytes, curTime, *bandSpeed); lastTime = curTime; @@ -876,7 +876,7 @@ bool taosGetBandSpeed(float *bandSpeedKb) { bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { FILE *fp = fopen(tsProcIOFile, "r"); if (fp == NULL) { - printf("open file:%s failed", tsProcIOFile); + //printf("open file:%s failed", tsProcIOFile); return false; } @@ -909,7 +909,7 @@ bool taosReadProcIO(int64_t *rchars, int64_t *wchars) { fclose(fp); if (readIndex < 2) { - printf("read file:%s failed", tsProcIOFile); + //printf("read file:%s failed", tsProcIOFile); return false; } @@ -964,7 +964,7 @@ void taosGetSystemInfo() { void taosKillSystem() { // SIGINT - printf("taosd will shut down soon"); + //printf("taosd will shut down soon"); kill(tsProcId, 2); } @@ -973,22 +973,22 @@ int taosSystem(const char *cmd) { int res; char buf[1024]; if (cmd == NULL) { - printf("taosSystem cmd is NULL!"); + //printf("taosSystem cmd is NULL!"); return -1; } if ((fp = popen(cmd, "r")) == NULL) { - printf("popen cmd:%s error: %s", cmd, strerror(errno)); + //printf("popen cmd:%s error: %s", cmd, strerror(errno)); return -1; } else { while (fgets(buf, sizeof(buf), fp)) { - printf("popen result:%s", buf); + //printf("popen result:%s", buf); } if ((res = pclose(fp)) == -1) { - printf("close popen file pointer fp error!"); + //printf("close popen file pointer fp error!"); } else { - printf("popen res is :%d", res); + //printf("popen res is :%d", res); } return res; @@ -1003,14 +1003,14 @@ void taosSetCoreDump(bool enable) { struct rlimit rlim_new; if (getrlimit(RLIMIT_CORE, &rlim) == 0) { #ifndef _ALPINE - printf("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max); + //printf("the old unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max); #else - printf("the old unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max); + //printf("the old unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max); #endif rlim_new.rlim_cur = RLIM_INFINITY; rlim_new.rlim_max = RLIM_INFINITY; if (setrlimit(RLIMIT_CORE, &rlim_new) != 0) { - printf("set unlimited fail, error: %s", strerror(errno)); + //printf("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); @@ -1019,9 +1019,9 @@ void taosSetCoreDump(bool enable) { if (getrlimit(RLIMIT_CORE, &rlim) == 0) { #ifndef _ALPINE - printf("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max); + //printf("the new unlimited para: rlim_cur=%" PRIu64 ", rlim_max=%" PRIu64, rlim.rlim_cur, rlim.rlim_max); #else - printf("the new unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max); + //printf("the new unlimited para: rlim_cur=%llu, rlim_max=%llu", rlim.rlim_cur, rlim.rlim_max); #endif } @@ -1047,10 +1047,10 @@ void taosSetCoreDump(bool enable) { old_len = sizeof(old_usespid); if (syscall(SYS__sysctl, &args) == -1) { - printf("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno)); + //printf("_sysctl(kern_core_uses_pid) set fail: %s", strerror(errno)); } - printf("The old core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid); + //printf("The old core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid); old_usespid = 0; old_len = 0; @@ -1063,10 +1063,10 @@ void taosSetCoreDump(bool enable) { old_len = sizeof(old_usespid); if (syscall(SYS__sysctl, &args) == -1) { - printf("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno)); + //printf("_sysctl(kern_core_uses_pid) get fail: %s", strerror(errno)); } - printf("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid); + //printf("The new core_uses_pid[%" PRIu64 "]: %d", old_len, old_usespid); #endif } diff --git a/source/os/src/osSystem.c b/source/os/src/osSystem.c index 1a57e88c58..717cae0fbd 100644 --- a/source/os/src/osSystem.c +++ b/source/os/src/osSystem.c @@ -87,11 +87,11 @@ int taosSetConsoleEcho(bool on) { void* taosLoadDll(const char* filename) { void* handle = dlopen(filename, RTLD_LAZY); if (!handle) { - printf("load dll:%s failed, error:%s", filename, dlerror()); + //printf("load dll:%s failed, error:%s", filename, dlerror()); return NULL; } - printf("dll %s loaded", filename); + //printf("dll %s loaded", filename); return handle; } @@ -101,11 +101,11 @@ void* taosLoadSym(void* handle, char* name) { char* error = NULL; if ((error = dlerror()) != NULL) { - printf("load sym:%s failed, error:%s", name, dlerror()); + //printf("load sym:%s failed, error:%s", name, dlerror()); return NULL; } - printf("sym %s loaded", name); + //printf("sym %s loaded", name); return sym; } @@ -133,7 +133,7 @@ int taosSetConsoleEcho(bool on) { err = tcsetattr(STDIN_FILENO, TCSAFLUSH, &term); if (err == -1 || err == EINTR) { - printf("Cannot set the attribution of the terminal"); + //printf("Cannot set the attribution of the terminal"); return -1; } diff --git a/source/os/src/osTimer.c b/source/os/src/osTimer.c index b1bf1bcd2d..7e542ef80f 100644 --- a/source/os/src/osTimer.c +++ b/source/os/src/osTimer.c @@ -170,7 +170,7 @@ static void *taosProcessAlarmSignal(void *tharg) { sevent.sigev_signo = SIGALRM; if (timer_create(CLOCK_REALTIME, &sevent, &timerId) == -1) { - printf("Failed to create timer"); + //printf("Failed to create timer"); } pthread_cleanup_push(taosDeleteTimer, &timerId); @@ -182,17 +182,17 @@ static void *taosProcessAlarmSignal(void *tharg) { ts.it_interval.tv_nsec = 1000000 * MSECONDS_PER_TICK; if (timer_settime(timerId, 0, &ts, NULL)) { - printf("Failed to init timer"); + //printf("Failed to init timer"); return NULL; } int signo; while (!stopTimer) { if (sigwait(&sigset, &signo)) { - printf("Failed to wait signal: number %d", signo); + //printf("Failed to wait signal: number %d", signo); continue; } - /* printf("Signal handling: number %d ......\n", signo); */ + /* //printf("Signal handling: number %d ......\n", signo); */ callback(0); } @@ -208,10 +208,10 @@ int taosInitTimer(void (*callback)(int), int ms) { int code = pthread_create(&timerThread, &tattr, taosProcessAlarmSignal, callback); pthread_attr_destroy(&tattr); if (code != 0) { - printf("failed to create timer thread"); + //printf("failed to create timer thread"); return -1; } else { - printf("timer thread:0x%08" PRIx64 " is created", taosGetPthreadId(timerThread)); + //printf("timer thread:0x%08" PRIx64 " is created", taosGetPthreadId(timerThread)); } return 0; @@ -220,7 +220,7 @@ int taosInitTimer(void (*callback)(int), int ms) { void taosUninitTimer() { stopTimer = true; - printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread)); + //printf("join timer thread:0x%08" PRIx64, taosGetPthreadId(timerThread)); pthread_join(timerThread, NULL); } From c049678ade258de74d9b5b2cc6db2c9a5dc8fe4e Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Sat, 27 Nov 2021 15:57:54 +0800 Subject: [PATCH 15/16] TD-11265 fix deadlock while quit taosd --- include/util/tworker.h | 19 +++++++++++-------- source/dnode/mgmt/daemon/src/daemon.c | 5 ++++- source/dnode/mgmt/impl/inc/dndInt.h | 22 +++++++++++----------- source/dnode/mgmt/impl/src/dndMnode.c | 12 ++++++++---- source/dnode/mgmt/impl/src/dndTransport.c | 8 +++++++- source/dnode/mgmt/impl/src/dnode.c | 2 +- source/util/src/tqueue.c | 2 +- source/util/src/tworker.c | 4 ++-- 8 files changed, 45 insertions(+), 29 deletions(-) diff --git a/include/util/tworker.h b/include/util/tworker.h index 9b0fe4f3a5..2e5852cbba 100644 --- a/include/util/tworker.h +++ b/include/util/tworker.h @@ -22,10 +22,13 @@ extern "C" { #endif +typedef struct SWorkerPool SWorkerPool; +typedef struct SMWorkerPool SMWorkerPool; + typedef struct SWorker { - int32_t id; // worker ID - pthread_t thread; // thread - struct SWorkerPool *pool; + int32_t id; // worker ID + pthread_t thread; // thread + SWorkerPool *pool; } SWorker; typedef struct SWorkerPool { @@ -39,11 +42,11 @@ typedef struct SWorkerPool { } SWorkerPool; typedef struct SMWorker { - int32_t id; // worker id - pthread_t thread; // thread - taos_qall qall; - taos_qset qset; // queue set - struct SMWorkerPool *pool; + int32_t id; // worker id + pthread_t thread; // thread + taos_qall qall; + taos_qset qset; // queue set + SMWorkerPool *pool; } SMWorker; typedef struct SMWorkerPool { diff --git a/source/dnode/mgmt/daemon/src/daemon.c b/source/dnode/mgmt/daemon/src/daemon.c index effaec66a8..a0ca0dd390 100644 --- a/source/dnode/mgmt/daemon/src/daemon.c +++ b/source/dnode/mgmt/daemon/src/daemon.c @@ -30,7 +30,10 @@ static struct { char configDir[PATH_MAX]; } global = {0}; -void dmnSigintHandle(int signum, void *info, void *ctx) { global.stop = true; } +void dmnSigintHandle(int signum, void *info, void *ctx) { + uError("singal:%d is received", signum); + global.stop = true; +} void dmnSetSignalHandle() { taosSetSignal(SIGTERM, dmnSigintHandle); diff --git a/source/dnode/mgmt/impl/inc/dndInt.h b/source/dnode/mgmt/impl/inc/dndInt.h index 106f192856..39243a1795 100644 --- a/source/dnode/mgmt/impl/inc/dndInt.h +++ b/source/dnode/mgmt/impl/inc/dndInt.h @@ -74,31 +74,31 @@ typedef struct { int8_t replica; int8_t selfIndex; SReplica replicas[TSDB_MAX_REPLICA]; - SWorkerPool mgmtPool; - SWorkerPool readPool; - SWorkerPool writePool; - SWorkerPool syncPool; + char *file; + SMnode *pMnode; + SRWLatch latch; taos_queue pReadQ; taos_queue pWriteQ; taos_queue pApplyQ; taos_queue pSyncQ; taos_queue pMgmtQ; - char *file; - SMnode *pMnode; - SRWLatch latch; + SWorkerPool mgmtPool; + SWorkerPool readPool; + SWorkerPool writePool; + SWorkerPool syncPool; } SMnodeMgmt; typedef struct { SHashObj *hash; + int32_t openVnodes; + int32_t totalVnodes; + SRWLatch latch; + taos_queue pMgmtQ; SWorkerPool mgmtPool; SWorkerPool queryPool; SWorkerPool fetchPool; SMWorkerPool syncPool; SMWorkerPool writePool; - taos_queue pMgmtQ; - int32_t openVnodes; - int32_t totalVnodes; - SRWLatch latch; } SVnodesMgmt; typedef struct { diff --git a/source/dnode/mgmt/impl/src/dndMnode.c b/source/dnode/mgmt/impl/src/dndMnode.c index a4f6d845fd..fe3accdd84 100644 --- a/source/dnode/mgmt/impl/src/dndMnode.c +++ b/source/dnode/mgmt/impl/src/dndMnode.c @@ -294,14 +294,14 @@ static void dndStopMnodeWorker(SDnode *pDnode) { while (!taosQueueEmpty(pMgmt->pWriteQ)) taosMsleep(10); while (!taosQueueEmpty(pMgmt->pSyncQ)) taosMsleep(10); + dndCleanupMnodeReadWorker(pDnode); + dndCleanupMnodeWriteWorker(pDnode); + dndCleanupMnodeSyncWorker(pDnode); + dndFreeMnodeReadQueue(pDnode); dndFreeMnodeWriteQueue(pDnode); dndFreeMnodeApplyQueue(pDnode); dndFreeMnodeSyncQueue(pDnode); - - dndCleanupMnodeReadWorker(pDnode); - dndCleanupMnodeWriteWorker(pDnode); - dndCleanupMnodeSyncWorker(pDnode); } static bool dndNeedDeployMnode(SDnode *pDnode) { @@ -714,6 +714,7 @@ static int32_t dndInitMnodeMgmtWorker(SDnode *pDnode) { static void dndCleanupMnodeMgmtWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->mgmtPool); + dDebug("mnode mgmt worker is stopped"); } static int32_t dndAllocMnodeReadQueue(SDnode *pDnode) { @@ -750,6 +751,7 @@ static int32_t dndInitMnodeReadWorker(SDnode *pDnode) { static void dndCleanupMnodeReadWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->readPool); + dDebug("mnode read worker is stopped"); } static int32_t dndAllocMnodeWriteQueue(SDnode *pDnode) { @@ -803,6 +805,7 @@ static int32_t dndInitMnodeWriteWorker(SDnode *pDnode) { static void dndCleanupMnodeWriteWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->writePool); + dDebug("mnode write worker is stopped"); } static int32_t dndAllocMnodeSyncQueue(SDnode *pDnode) { @@ -839,6 +842,7 @@ static int32_t dndInitMnodeSyncWorker(SDnode *pDnode) { static void dndCleanupMnodeSyncWorker(SDnode *pDnode) { SMnodeMgmt *pMgmt = &pDnode->mmgmt; tWorkerCleanup(&pMgmt->syncPool); + dDebug("mnode sync worker is stopped"); } int32_t dndInitMnode(SDnode *pDnode) { diff --git a/source/dnode/mgmt/impl/src/dndTransport.c b/source/dnode/mgmt/impl/src/dndTransport.c index d5f52bac8b..c3940cd3cc 100644 --- a/source/dnode/mgmt/impl/src/dndTransport.c +++ b/source/dnode/mgmt/impl/src/dndTransport.c @@ -160,6 +160,7 @@ static int32_t dndInitClient(SDnode *pDnode) { rpcInit.user = INTERNAL_USER; rpcInit.ckey = INTERNAL_CKEY; rpcInit.secret = INTERNAL_SECRET; + rpcInit.parent = pDnode; pMgmt->clientRpc = rpcOpen(&rpcInit); if (pMgmt->clientRpc == NULL) { @@ -167,6 +168,7 @@ static int32_t dndInitClient(SDnode *pDnode) { return -1; } + dDebug("dnode rpc client is initialized"); return 0; } @@ -175,7 +177,7 @@ static void dndCleanupClient(SDnode *pDnode) { if (pMgmt->clientRpc) { rpcClose(pMgmt->clientRpc); pMgmt->clientRpc = NULL; - dInfo("dnode peer rpc client is closed"); + dDebug("dnode rpc client is closed"); } } @@ -315,6 +317,7 @@ static int32_t dndInitServer(SDnode *pDnode) { rpcInit.connType = TAOS_CONN_SERVER; rpcInit.idleTime = pDnode->opt.shellActivityTimer * 1000; rpcInit.afp = dndRetrieveUserAuthInfo; + rpcInit.parent = pDnode; pMgmt->serverRpc = rpcOpen(&rpcInit); if (pMgmt->serverRpc == NULL) { @@ -322,6 +325,7 @@ static int32_t dndInitServer(SDnode *pDnode) { return -1; } + dDebug("dnode rpc server is initialized"); return 0; } @@ -330,6 +334,7 @@ static void dndCleanupServer(SDnode *pDnode) { if (pMgmt->serverRpc) { rpcClose(pMgmt->serverRpc); pMgmt->serverRpc = NULL; + dDebug("dnode rpc server is closed"); } } @@ -347,6 +352,7 @@ int32_t dndInitTrans(SDnode *pDnode) { } void dndCleanupTrans(SDnode *pDnode) { + dInfo("dnode-transport start to clean up"); dndCleanupServer(pDnode); dndCleanupClient(pDnode); dInfo("dnode-transport is cleaned up"); diff --git a/source/dnode/mgmt/impl/src/dnode.c b/source/dnode/mgmt/impl/src/dnode.c index 8d72f83200..23c9ee0ebf 100644 --- a/source/dnode/mgmt/impl/src/dnode.c +++ b/source/dnode/mgmt/impl/src/dnode.c @@ -197,7 +197,7 @@ SDnode *dndInit(SDnodeOpt *pOption) { dndReportStartup(pDnode, "TDengine", "initialized successfully"); dInfo("TDengine is initialized successfully"); - return 0; + return pDnode; } void dndCleanup(SDnode *pDnode) { diff --git a/source/util/src/tqueue.c b/source/util/src/tqueue.c index 93008f7114..04bc0c8dc8 100644 --- a/source/util/src/tqueue.c +++ b/source/util/src/tqueue.c @@ -107,7 +107,7 @@ bool taosQueueEmpty(taos_queue param) { if (queue->head == NULL && queue->tail == NULL) { empty = true; } - pthread_mutex_destroy(&queue->mutex); + pthread_mutex_unlock(&queue->mutex); return empty; } diff --git a/source/util/src/tworker.c b/source/util/src/tworker.c index 136bc40482..11972e84cb 100644 --- a/source/util/src/tworker.c +++ b/source/util/src/tworker.c @@ -50,7 +50,7 @@ void tWorkerCleanup(SWorkerPool *pool) { } } - free(pool->workers); + tfree(pool->workers); taosCloseQset(pool->qset); pthread_mutex_destroy(&pool->mutex); @@ -159,7 +159,7 @@ void tMWorkerCleanup(SMWorkerPool *pool) { } } - free(pool->workers); + tfree(pool->workers); pthread_mutex_destroy(&pool->mutex); uInfo("worker:%s is closed", pool->name); From 53680b76bb4b4bbcee751eeb6936b24897190ee3 Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Sun, 28 Nov 2021 20:29:36 +0800 Subject: [PATCH 16/16] update fst core struct --- source/libs/index/src/index_fst.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/source/libs/index/src/index_fst.c b/source/libs/index/src/index_fst.c index 465b6d154a..6c1ea8cfeb 100644 --- a/source/libs/index/src/index_fst.c +++ b/source/libs/index/src/index_fst.c @@ -775,14 +775,14 @@ void fstBuilderInsertOutput(FstBuilder *b, FstSlice bs, Output in) { return; } Output out; - uint64_t prefixLen; - if (in != 0) { //if let Some(in) = in - prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out); - } else { - prefixLen = fstUnFinishedNodesFindCommPrefix(b->unfinished, bs); - out = 0; - } - + //if (in != 0) { //if let Some(in) = in + // prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out); + //} else { + // prefixLen = fstUnFinishedNodesFindCommPrefix(b->unfinished, bs); + // out = 0; + //} + uint64_t prefixLen = fstUnFinishedNodesFindCommPrefixAndSetOutput(b->unfinished, bs, in, &out); + if (prefixLen == FST_SLICE_LEN(s)) { assert(out == 0); return;