From ddf55f25aaaa1acfa22725a23adc7bd673970595 Mon Sep 17 00:00:00 2001 From: Shengliang Guan Date: Mon, 16 May 2022 22:34:43 +0800 Subject: [PATCH] refactor: make more object global --- source/dnode/mgmt/node_mgmt/src/dmNodes.c | 2 +- source/dnode/mgmt/test/sut/inc/server.h | 13 ++++--- source/dnode/mgmt/test/sut/src/server.cpp | 36 +++++++------------ source/dnode/mgmt/test/sut/src/sut.cpp | 2 +- source/dnode/mnode/impl/test/trans/trans2.cpp | 2 +- 5 files changed, 22 insertions(+), 33 deletions(-) diff --git a/source/dnode/mgmt/node_mgmt/src/dmNodes.c b/source/dnode/mgmt/node_mgmt/src/dmNodes.c index f6d7916f95..10b6db52c0 100644 --- a/source/dnode/mgmt/node_mgmt/src/dmNodes.c +++ b/source/dnode/mgmt/node_mgmt/src/dmNodes.c @@ -260,7 +260,7 @@ static void dmWatchNodes(SDnode *pDnode) { taosThreadMutexUnlock(&pDnode->mutex); } -int32_t dnRunDnode(SDnode *pDnode) { +int32_t dmRunDnode(SDnode *pDnode) { if (dmOpenNodes(pDnode) != 0) { dError("failed to open nodes since %s", terrstr()); return -1; diff --git a/source/dnode/mgmt/test/sut/inc/server.h b/source/dnode/mgmt/test/sut/inc/server.h index ad2d4a76e9..e29a5a2d43 100644 --- a/source/dnode/mgmt/test/sut/inc/server.h +++ b/source/dnode/mgmt/test/sut/inc/server.h @@ -24,15 +24,14 @@ class TestServer { bool DoStart(); private: - SDnodeOpt BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); + void BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp); private: - SDnode* pDnode; - TdThread threadId; - char path[PATH_MAX]; - char fqdn[TSDB_FQDN_LEN]; - char firstEp[TSDB_EP_LEN]; - uint16_t port; + TdThread threadId; + char path[PATH_MAX]; + char fqdn[TSDB_FQDN_LEN]; + char firstEp[TSDB_EP_LEN]; + uint16_t port; }; #endif /* _TD_TEST_SERVER_H_ */ \ No newline at end of file diff --git a/source/dnode/mgmt/test/sut/src/server.cpp b/source/dnode/mgmt/test/sut/src/server.cpp index 91db59757b..c7106d6cda 100644 --- a/source/dnode/mgmt/test/sut/src/server.cpp +++ b/source/dnode/mgmt/test/sut/src/server.cpp @@ -16,35 +16,29 @@ #include "sut.h" void* serverLoop(void* param) { - SDnode* pDnode = (SDnode*)param; - dmRun(pDnode); + dmRun(); return NULL; } -SDnodeOpt TestServer::BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { - SDnodeOpt option = {0}; - option.numOfSupportVnodes = 16; - option.serverPort = port; - strcpy(option.dataDir, path); - snprintf(option.localEp, TSDB_EP_LEN, "%s:%u", fqdn, port); - snprintf(option.localFqdn, TSDB_FQDN_LEN, "%s", fqdn); - snprintf(option.firstEp, TSDB_EP_LEN, "%s", firstEp); - return option; +void TestServer::BuildOption(const char* path, const char* fqdn, uint16_t port, const char* firstEp) { + tsNumOfSupportVnodes = 16; + tsServerPort = port; + strcpy(tsDataDir, path); + snprintf(tsLocalEp, TSDB_EP_LEN, "%s:%u", fqdn, port); + snprintf(tsLocalFqdn, TSDB_FQDN_LEN, "%s", fqdn); + snprintf(tsFirst, TSDB_EP_LEN, "%s", firstEp); + taosMkDir(path); } bool TestServer::DoStart() { - SDnodeOpt option = BuildOption(path, fqdn, port, firstEp); - taosMkDir(path); - - pDnode = dmCreate(&option); - if (pDnode == NULL) { + if (dmInit(0) != 0) { return false; } TdThreadAttr thAttr; taosThreadAttrInit(&thAttr); taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE); - taosThreadCreate(&threadId, &thAttr, serverLoop, pDnode); + taosThreadCreate(&threadId, &thAttr, serverLoop, NULL); taosThreadAttrDestroy(&thAttr); taosMsleep(2100); return true; @@ -68,11 +62,7 @@ bool TestServer::Start(const char* path, const char* fqdn, uint16_t port, const } void TestServer::Stop() { - dmSetEvent(pDnode, DND_EVENT_STOP); + dmStop(); taosThreadJoin(threadId, NULL); - - if (pDnode != NULL) { - dmClose(pDnode); - pDnode = NULL; - } + dmCleanup(); } diff --git a/source/dnode/mgmt/test/sut/src/sut.cpp b/source/dnode/mgmt/test/sut/src/sut.cpp index cc32f047af..ceaffbe572 100644 --- a/source/dnode/mgmt/test/sut/src/sut.cpp +++ b/source/dnode/mgmt/test/sut/src/sut.cpp @@ -40,7 +40,7 @@ void Testbase::InitLog(const char* path) { } void Testbase::Init(const char* path, int16_t port) { - dmInit(); + dmInit(0); char fqdn[] = "localhost"; char firstEp[TSDB_EP_LEN] = {0}; diff --git a/source/dnode/mnode/impl/test/trans/trans2.cpp b/source/dnode/mnode/impl/test/trans/trans2.cpp index 622ee25c5c..e33aecee8a 100644 --- a/source/dnode/mnode/impl/test/trans/trans2.cpp +++ b/source/dnode/mnode/impl/test/trans/trans2.cpp @@ -15,7 +15,7 @@ #include "mndUser.h" #include "tcache.h" -void reportStartup(SMgmtWrapper *pWrapper, const char *name, const char *desc) {} +void reportStartup(const char *name, const char *desc) {} class MndTestTrans2 : public ::testing::Test { protected: -- GitLab