diff --git a/cmake/define.inc b/cmake/define.inc index 9f56dc654dea949784e885a98fb5f78e36a30e7e..da100f4260c7f824f2b2d3f2ba562d7ea03e4f51 100755 --- a/cmake/define.inc +++ b/cmake/define.inc @@ -6,7 +6,7 @@ IF (TD_SYNC) ENDIF () IF (TD_ACCOUNT) - ADD_DEFINITIONS(-D_ACCOUNT) + ADD_DEFINITIONS(-D_ACCT) ENDIF () IF (TD_ADMIN) diff --git a/cmake/input.inc b/cmake/input.inc index d29b7c5ff815a9d89222c296ba36be39da0e5ce0..5a17e0319c01d335e5940e0475db4f2f57d7bfd7 100755 --- a/cmake/input.inc +++ b/cmake/input.inc @@ -1,14 +1,6 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8) PROJECT(TDengine) -IF (${CLUSTER} MATCHES "true") - SET(TD_CLUSTER TRUE) - MESSAGE(STATUS "Build with cluster plugins") -ELSEIF (${CLUSTER} MATCHES "false") - SET(TD_CLUSTER FALSE) - MESSAGE(STATUS "Build without cluster plugins") -ENDIF () - IF (${ACCOUNT} MATCHES "true") SET(TD_ACCOUNT TRUE) MESSAGE(STATUS "Build with account plugins") diff --git a/src/dnode/inc/dnodeMClient.h b/src/dnode/inc/dnodeMClient.h index a8e97dd9def24fb35bb68905bda22fe273df9dd5..fdaf54e0e5a21f0ef79d3a4158d0e8b2bfe1322b 100644 --- a/src/dnode/inc/dnodeMClient.h +++ b/src/dnode/inc/dnodeMClient.h @@ -23,7 +23,7 @@ extern "C" { int32_t dnodeInitMClient(); void dnodeCleanupMClient(); void dnodeSendMsgToMnode(SRpcMsg *rpcMsg); -void * dnodeGetMpeerInfos(); +void * dnodeGetMnodeList(); int32_t dnodeGetDnodeId(); #ifdef __cplusplus diff --git a/src/dnode/src/dnodeMClient.c b/src/dnode/src/dnodeMClient.c index 42f947588ba8b016e8a4811147e45f5259c1b701..90a093560f7860a3414f803c7549f50f4388797f 100644 --- a/src/dnode/src/dnodeMClient.c +++ b/src/dnode/src/dnodeMClient.c @@ -332,7 +332,7 @@ uint32_t dnodeGetMnodeMasteIp() { return tsMnodeIpList.ip[tsMnodeIpList.inUse]; } -void* dnodeGetMpeerInfos() { +void* dnodeGetMnodeList() { return &tsMnodeInfos; } diff --git a/src/inc/mnode.h b/src/inc/mnode.h index c30e1e37ba569f19984a1d54e582eabb27b951dc..e7ad88d6b66398e14411bcbf9e74ffeedb18cbda 100644 --- a/src/inc/mnode.h +++ b/src/inc/mnode.h @@ -25,9 +25,6 @@ int32_t mgmtStartSystem(); void mgmtCleanUpSystem(); void mgmtStopSystem(); -extern char version[]; -extern char tsMnodeDir[]; - #ifdef __cplusplus } #endif diff --git a/src/inc/tadmin.h b/src/inc/tadmin.h index 4a883965f4ceb28cb37b411d6996e1d933c06782..b7de33576a3e73ea481bb75d01f1005b3bd942f6 100644 --- a/src/inc/tadmin.h +++ b/src/inc/tadmin.h @@ -20,15 +20,10 @@ extern "C" { #endif -#include -#include +struct HttpServer; -void adminInit(); - -struct _http_server_obj_; - -extern void (*adminInitHandleFp)(struct _http_server_obj_* pServer); -extern void (*opInitHandleFp)(struct _http_server_obj_* pServer); +void adminInitHandle(struct HttpServer* pServer); +void opInitHandle(struct HttpServer* pServer); #ifdef __cplusplus } diff --git a/src/mnode/src/mgmtAcct.c b/src/mnode/src/mgmtAcct.c index 792d5fa9b8b9b193beea945f95f2164da1704297..3a52715274059f0b386810bcd8eb36a7f679b636 100644 --- a/src/mnode/src/mgmtAcct.c +++ b/src/mnode/src/mgmtAcct.c @@ -26,9 +26,9 @@ #include "mgmtSdb.h" #include "mgmtUser.h" -static void * tsAcctSdb = NULL; -static int32_t tsAcctUpdateSize; -static void mgmtCreateRootAcct(); +void * tsAcctSdb = NULL; +int32_t tsAcctUpdateSize; +static void mgmtCreateRootAcct(); static int32_t mgmtActionAcctDestroy(SSdbOperDesc *pOper) { SAcctObj *pAcct = pOper->pObj; diff --git a/src/mnode/src/mgmtMnode.c b/src/mnode/src/mgmtMnode.c index ec3030f85ed37afb84483adb37f1d743effa1e8a..e469dc4f6f7ccbcf4a4ba3f2a878b1e0ffdcff1f 100644 --- a/src/mnode/src/mgmtMnode.c +++ b/src/mnode/src/mgmtMnode.c @@ -30,9 +30,9 @@ #include "mgmtShell.h" #include "mgmtUser.h" +int32_t tsMnodeIsMaster = true; static void * tsMnodeSdb = NULL; static int32_t tsMnodeUpdateSize = 0; -static int32_t tsMnodeIsMaster = true; static int32_t mgmtGetMnodeMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pConn); static int32_t mgmtRetrieveMnodes(SShowObj *pShow, char *data, int32_t rows, void *pConn); @@ -87,6 +87,14 @@ static int32_t mgmtMnodeActionDecode(SSdbOperDesc *pOper) { } static int32_t mgmtMnodeActionRestored() { + if (mgmtGetMnodesNum() == 1) { + SMnodeObj *pMnode = NULL; + mgmtGetNextMnode(NULL, &pMnode); + if (pMnode != NULL) { + pMnode->role = TAOS_SYNC_ROLE_MASTER; + mgmtReleaseMnode(pMnode); + } + } return TSDB_CODE_SUCCESS; } diff --git a/src/os/darwin/src/tdarwin.c b/src/os/darwin/src/tdarwin.c index 7896592030f8e18e5d4be5efad0bf7c78100dfb8..a8dfdb1e3ff9360f7196ca455b81f873dfef7fc6 100644 --- a/src/os/darwin/src/tdarwin.c +++ b/src/os/darwin/src/tdarwin.c @@ -243,6 +243,11 @@ int taosInitTimer(void (*callback)(int), int ms) { return setitimer(ITIMER_REAL, &tv, NULL); } +void taosUninitTimer() { + struct itimerval tv = { 0 }; + return setitimer(ITIMER_REAL, &tv, NULL); +} + void taosGetSystemTimezone() { // get and set default timezone SGlobalConfig *cfg_timezone = tsGetConfigOption("timezone"); diff --git a/src/os/linux/src/tlinux.c b/src/os/linux/src/tlinux.c index c1bd0ceb5f5059f09bec9023dc1c767fbc871b9e..88d69816abbc161d07d1f96f33c6558a3a2ac42c 100644 --- a/src/os/linux/src/tlinux.c +++ b/src/os/linux/src/tlinux.c @@ -286,20 +286,23 @@ void *taosProcessAlarmSignal(void *tharg) { return NULL; } +static pthread_t timerThread; + int taosInitTimer(void (*callback)(int), int ms) { - pthread_t thread; pthread_attr_t tattr; pthread_attr_init(&tattr); - pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED); - int code = pthread_create(&thread, &tattr, taosProcessAlarmSignal, callback); - pthread_detach(thread); + int code = pthread_create(&timerThread, &tattr, taosProcessAlarmSignal, callback); pthread_attr_destroy(&tattr); if (code != 0) { tmrError("failed to create timer thread"); return -1; } + return 0; +} - return thread; +void taosUninitTimer() { + pthread_cancel(timerThread); + pthread_join(timerThread, NULL); } ssize_t tread(int fd, void *buf, size_t count) { diff --git a/src/os/windows/src/twintimer.c b/src/os/windows/src/twintimer.c index 68899bea51e936678abfbe6004e8fdb2713ce11a..2bb8478f09dc61c395d425953e2c2251862df557 100644 --- a/src/os/windows/src/twintimer.c +++ b/src/os/windows/src/twintimer.c @@ -30,8 +30,8 @@ void WINAPI taosWinOnTimer(UINT wTimerID, UINT msg, DWORD_PTR dwUser, DWORD_PTR } } +static MMRESULT timerId; int taosInitTimer(win_timer_f callback, int ms) { - MMRESULT timerId; DWORD_PTR param = *((int64_t *) & callback); timerId = timeSetEvent(ms, 1, (LPTIMECALLBACK)taosWinOnTimer, param, TIME_PERIODIC); @@ -41,6 +41,10 @@ int taosInitTimer(win_timer_f callback, int ms) { return 0; } +void taosUninitTimer() { + timeKillEvent(timerId); +} + void taosMsleep(int mseconds) { Sleep(mseconds); } diff --git a/src/plugins/http/CMakeLists.txt b/src/plugins/http/CMakeLists.txt index 9b36f4029a7d5993435b5a0e45cde1d31d19b184..40dee941171b2a80499f9d9a4dc7c08a71ad0f14 100644 --- a/src/plugins/http/CMakeLists.txt +++ b/src/plugins/http/CMakeLists.txt @@ -15,7 +15,7 @@ IF ((TD_LINUX_64) OR (TD_LINUX_32 AND TD_ARM)) ADD_LIBRARY(http ${SRC}) TARGET_LINK_LIBRARIES(http taos_static z) - IF (TD_CLUSTER) - TARGET_LINK_LIBRARIES(http) + IF (TD_ADMIN) + TARGET_LINK_LIBRARIES(http admin) ENDIF () ENDIF () diff --git a/src/plugins/http/inc/httpHandle.h b/src/plugins/http/inc/httpHandle.h index 9c6a263c5bd328ca0fc59eb5365f7722324ef729..ad5a28e10e0d5c9a068511fd83b1518f2be10ba1 100644 --- a/src/plugins/http/inc/httpHandle.h +++ b/src/plugins/http/inc/httpHandle.h @@ -23,7 +23,7 @@ #include "taosdef.h" #include "tutil.h" #include "zlib.h" - +#include "tlog.h" #include "http.h" #include "httpJson.h" @@ -206,10 +206,10 @@ typedef struct HttpThread { int threadId; char label[HTTP_LABEL_SIZE]; bool (*processData)(HttpContext *pContext); - struct _http_server_obj_ *pServer; // handle passed by upper layer during pServer initialization + struct HttpServer *pServer; // handle passed by upper layer during pServer initialization } HttpThread; -typedef struct _http_server_obj_ { +typedef struct HttpServer { char label[HTTP_LABEL_SIZE]; char serverIp[16]; uint16_t serverPort; @@ -313,4 +313,27 @@ const char* httpContextStateStr(HttpContextState state); bool httpAlterContextState(HttpContext *pContext, HttpContextState srcState, HttpContextState destState); void httpRemoveContextFromEpoll(HttpThread *pThread, HttpContext *pContext); +#define httpError(...) \ + if (httpDebugFlag & DEBUG_ERROR) { \ + tprintf("ERROR HTP ", 255, __VA_ARGS__); \ + } +#define httpWarn(...) \ + if (httpDebugFlag & DEBUG_WARN) { \ + tprintf("WARN HTP ", httpDebugFlag, __VA_ARGS__); \ + } +#define httpTrace(...) \ + if (httpDebugFlag & DEBUG_TRACE) { \ + tprintf("HTP ", httpDebugFlag, __VA_ARGS__); \ + } +#define httpDump(...) \ + if (httpDebugFlag & DEBUG_TRACE) { \ + taosPrintLongString("HTP ", httpDebugFlag, __VA_ARGS__); \ + } +#define httpPrint(...) \ + { tprintf("HTP ", 255, __VA_ARGS__); } + +#define httpLError(...) taosLogError(__VA_ARGS__) httpError(__VA_ARGS__) +#define httpLWarn(...) taosLogWarn(__VA_ARGS__) httpWarn(__VA_ARGS__) +#define httpLPrint(...) taosLogPrint(__VA_ARGS__) httpPrint(__VA_ARGS__) + #endif diff --git a/src/plugins/http/src/httpSystem.c b/src/plugins/http/src/httpSystem.c index 2a118cc2b14d01a8600d85970318bbcd3676131e..52910cb1db1cbdd9225908383f5c298643cc06b9 100644 --- a/src/plugins/http/src/httpSystem.c +++ b/src/plugins/http/src/httpSystem.c @@ -13,11 +13,9 @@ * along with this program. If not, see . */ -#include -#include -#include -#include - +#define _DEFAULT_SOURCE +#include "os.h" +#include "tadmin.h" #include "http.h" #include "httpCode.h" #include "httpHandle.h" @@ -27,28 +25,17 @@ #include "tglobalcfg.h" #include "tsocket.h" #include "ttimer.h" - #include "gcHandle.h" #include "httpHandle.h" #include "restHandle.h" #include "tgHandle.h" -#include "tlog.h" +#ifndef _ADMIN -void (*adminInitHandleFp)(HttpServer* pServer) = NULL; -void (*opInitHandleFp)(HttpServer* pServer) = NULL; - -void adminInitHandle(HttpServer* pServer) { - if (adminInitHandleFp) { - (*adminInitHandleFp)(pServer); - } -} +void adminInitHandle(HttpServer* pServer) {} +void opInitHandle(HttpServer* pServer) {} -void opInitHandle(HttpServer* pServer) { - if (opInitHandleFp) { - (*opInitHandleFp)(pServer); - } -} +#endif static HttpServer *httpServer = NULL; void taosInitNote(int numOfNoteLines, int maxNotes, char* lable); diff --git a/src/plugins/monitor/src/monitorSystem.c b/src/plugins/monitor/src/monitorSystem.c index 4fb3ba2f5b55ee72452fd7e39793053394f9c51a..a547d1354563d012e8a5d6b76fdbe1413bce8cfd 100644 --- a/src/plugins/monitor/src/monitorSystem.c +++ b/src/plugins/monitor/src/monitorSystem.c @@ -13,17 +13,37 @@ * along with this program. If not, see . */ +#define _DEFAULT_SOURCE #include "os.h" - +#include "tlog.h" #include "monitor.h" #include "dnode.h" -#include "monitorSystem.h" #include "tsclient.h" #include "taosdef.h" #include "tsystem.h" #include "ttime.h" #include "ttimer.h" #include "tutil.h" +#include "monitorSystem.h" + +#define monitorError(...) \ + if (monitorDebugFlag & DEBUG_ERROR) { \ + tprintf("ERROR MON ", 255, __VA_ARGS__); \ + } +#define monitorWarn(...) \ + if (monitorDebugFlag & DEBUG_WARN) { \ + tprintf("WARN MON ", monitorDebugFlag, __VA_ARGS__); \ + } +#define monitorTrace(...) \ + if (monitorDebugFlag & DEBUG_TRACE) { \ + tprintf("MON ", monitorDebugFlag, __VA_ARGS__); \ + } +#define monitorPrint(...) \ + { tprintf("MON ", 255, __VA_ARGS__); } + +#define monitorLError(...) taosLogError(__VA_ARGS__) monitorError(__VA_ARGS__) +#define monitorLWarn(...) taosLogWarn(__VA_ARGS__) monitorWarn(__VA_ARGS__) +#define monitorLPrint(...) taosLogPrint(__VA_ARGS__) monitorPrint(__VA_ARGS__) #define SQL_LENGTH 1024 #define LOG_LEN_STR 80 diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt index a814bf52ab65aaf85f7c3042e6622ad9b4a3337f..f875cfff943d908a3efd27fdc1499fac4c705830 100644 --- a/src/util/CMakeLists.txt +++ b/src/util/CMakeLists.txt @@ -107,8 +107,4 @@ ELSEIF(TD_DARWIN_64) TARGET_LINK_LIBRARIES(tutil iconv pthread os) ENDIF() -#IF (TD_CLUSTER) # TARGET_LINK_LIBRARIES(tutil mstorage) -#ENDIF () - - diff --git a/src/util/inc/tlog.h b/src/util/inc/tlog.h index 591f53f4107541725b97c43bf586b4c4014f517b..485f8644d37bf9750f7a1898f5a9d1e4834d71a2 100644 --- a/src/util/inc/tlog.h +++ b/src/util/inc/tlog.h @@ -177,48 +177,6 @@ extern uint32_t cdebugFlag; tprintf("DND QRY ", qdebugFlag, __VA_ARGS__); \ } -#define httpError(...) \ - if (httpDebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR HTP ", 255, __VA_ARGS__); \ - } -#define httpWarn(...) \ - if (httpDebugFlag & DEBUG_WARN) { \ - tprintf("WARN HTP ", httpDebugFlag, __VA_ARGS__); \ - } -#define httpTrace(...) \ - if (httpDebugFlag & DEBUG_TRACE) { \ - tprintf("HTP ", httpDebugFlag, __VA_ARGS__); \ - } -#define httpDump(...) \ - if (httpDebugFlag & DEBUG_TRACE) { \ - taosPrintLongString("HTP ", httpDebugFlag, __VA_ARGS__); \ - } -#define httpPrint(...) \ - { tprintf("HTP ", 255, __VA_ARGS__); } - -#define httpLError(...) taosLogError(__VA_ARGS__) httpError(__VA_ARGS__) -#define httpLWarn(...) taosLogWarn(__VA_ARGS__) httpWarn(__VA_ARGS__) -#define httpLPrint(...) taosLogPrint(__VA_ARGS__) httpPrint(__VA_ARGS__) - -#define monitorError(...) \ - if (monitorDebugFlag & DEBUG_ERROR) { \ - tprintf("ERROR MON ", 255, __VA_ARGS__); \ - } -#define monitorWarn(...) \ - if (monitorDebugFlag & DEBUG_WARN) { \ - tprintf("WARN MON ", monitorDebugFlag, __VA_ARGS__); \ - } -#define monitorTrace(...) \ - if (monitorDebugFlag & DEBUG_TRACE) { \ - tprintf("MON ", monitorDebugFlag, __VA_ARGS__); \ - } -#define monitorPrint(...) \ - { tprintf("MON ", 255, __VA_ARGS__); } - -#define monitorLError(...) taosLogError(__VA_ARGS__) monitorError(__VA_ARGS__) -#define monitorLWarn(...) taosLogWarn(__VA_ARGS__) monitorWarn(__VA_ARGS__) -#define monitorLPrint(...) taosLogPrint(__VA_ARGS__) monitorPrint(__VA_ARGS__) - #ifdef __cplusplus } #endif diff --git a/src/util/inc/tutil.h b/src/util/inc/tutil.h index 8d201b8eb708893c433fc430a5ba210c04d2621e..3420e5b536ad8ea373ce77ece9299c44ef9195ef 100644 --- a/src/util/inc/tutil.h +++ b/src/util/inc/tutil.h @@ -139,6 +139,7 @@ int32_t taosFileRename(char *fullPath, char *suffix, char delimiter, char **dstP void getTmpfilePath(const char *fileNamePattern, char *dstPath); int32_t taosInitTimer(void (*callback)(int), int32_t ms); +void taosUninitTimer(); bool taosMbsToUcs4(char *mbs, int32_t mbs_len, char *ucs4, int32_t ucs4_max_len); diff --git a/src/util/src/ttimer.c b/src/util/src/ttimer.c index 04cad7565514e7dc4eea5385d4f8c19eb875556d..25862fbec3c969439a3a3c4186c5726869740315 100644 --- a/src/util/src/ttimer.c +++ b/src/util/src/ttimer.c @@ -84,8 +84,6 @@ static tmr_ctrl_t* tmrCtrls; static tmr_ctrl_t* unusedTmrCtrl = NULL; static void* tmrQhandle; static int numOfTmrCtrl = 0; -//static void* tmrContext = NULL; -static int athread = 0; int taosTmrThreads = 1; @@ -519,7 +517,7 @@ static void taosTmrModuleInit(void) { } tmrQhandle = taosInitScheduler(10000, taosTmrThreads, "tmr"); - athread = taosInitTimer(taosTimerLoopFunc, MSECONDS_PER_TICK); + taosInitTimer(taosTimerLoopFunc, MSECONDS_PER_TICK); tmrTrace("timer module is initialized, number of threads: %d", taosTmrThreads); } @@ -562,19 +560,29 @@ void taosTmrCleanUp(void* handle) { pthread_mutex_unlock(&tmrCtrlMutex); if (numOfTmrCtrl <=0) { -// pthread_cancel(athread); + taosUninitTimer(); + taosCleanUpScheduler(tmrQhandle); + for (int i = 0; i < tListLen(wheels); i++) { time_wheel_t* wheel = wheels + i; pthread_mutex_destroy(&wheel->mutex); free(wheel->slots); } - pthread_mutex_destroy(&tmrCtrlMutex); - free(timerMap.slots); + pthread_mutex_destroy(&tmrCtrlMutex); + + for (size_t i = 0; i < timerMap.size; i++) { + timer_list_t* list = timerMap.slots + i; + tmr_obj_t* t = list->timers; + while (t != NULL) { + tmr_obj_t* next = t->mnext; + free(t); + t = next; + } + } + free(timerMap.slots); free(tmrCtrls); - taosCleanUpScheduler(tmrQhandle); - tmrModuleInit = PTHREAD_ONCE_INIT; tmrTrace("timer module is cleaned up"); } diff --git a/src/vnode/src/vnodeMain.c b/src/vnode/src/vnodeMain.c index 33c979aa2e71b443c7960d8c8a82970e4e28b725..393758761d2fa63c22eaa0d93350b1f2ff58b661 100644 --- a/src/vnode/src/vnodeMain.c +++ b/src/vnode/src/vnodeMain.c @@ -42,7 +42,7 @@ static void vnodeNotifyRole(void *ahandle, int8_t role); static pthread_once_t vnodeModuleInit = PTHREAD_ONCE_INIT; -#ifndef _VPEER +#ifndef _SYNC tsync_h syncStart(const SSyncInfo *info) { return NULL; } int syncForwardToPeer(tsync_h shandle, void *pHead, void *mhandle) { return 0; } #endif