未验证 提交 e899d685 编写于 作者: S Shengliang Guan 提交者: GitHub

Merge pull request #3466 from taosdata/feature/crash

add syncInit and syncCleanUp functions
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
#define _DEFAULT_SOURCE #define _DEFAULT_SOURCE
#include "os.h" #include "os.h"
#include "taosdef.h" #include "taosdef.h"
#include "taosmsg.h"
#include "tglobal.h" #include "tglobal.h"
#include "mnode.h" #include "mnode.h"
#include "http.h" #include "http.h"
#include "tmqtt.h" #include "tmqtt.h"
#include "monitor.h" #include "monitor.h"
#include "dnode.h"
#include "dnodeInt.h" #include "dnodeInt.h"
#include "dnodeModule.h" #include "dnodeModule.h"
...@@ -129,17 +131,32 @@ void dnodeProcessModuleStatus(uint32_t moduleStatus) { ...@@ -129,17 +131,32 @@ void dnodeProcessModuleStatus(uint32_t moduleStatus) {
for (int32_t module = TSDB_MOD_MNODE; module < TSDB_MOD_HTTP; ++module) { for (int32_t module = TSDB_MOD_MNODE; module < TSDB_MOD_HTTP; ++module) {
bool enableModule = moduleStatus & (1 << module); bool enableModule = moduleStatus & (1 << module);
if (!tsModule[module].enable && enableModule) { if (!tsModule[module].enable && enableModule) {
dInfo("module status:%u is received, start %s module", tsModuleStatus, tsModule[module].name); dInfo("module status:%u is set, start %s module", moduleStatus, tsModule[module].name);
tsModule[module].enable = true; tsModule[module].enable = true;
dnodeSetModuleStatus(module); dnodeSetModuleStatus(module);
(*tsModule[module].startFp)(); (*tsModule[module].startFp)();
} }
if (tsModule[module].enable && !enableModule) { if (tsModule[module].enable && !enableModule) {
dInfo("module status:%u is received, stop %s module", tsModuleStatus, tsModule[module].name); dInfo("module status:%u is set, stop %s module", moduleStatus, tsModule[module].name);
tsModule[module].enable = false; tsModule[module].enable = false;
dnodeUnSetModuleStatus(module); dnodeUnSetModuleStatus(module);
(*tsModule[module].stopFp)(); (*tsModule[module].stopFp)();
} }
} }
} }
void dnodeCheckModules() {
if (tsModuleStatus & TSDB_MOD_MNODE) return;
SDMMnodeInfos *mnodes = dnodeGetMnodeInfos();
for (int32_t i = 0; i < mnodes->nodeNum; ++i) {
SDMMnodeInfo *node = &mnodes->nodeInfos[i];
if (node->nodeId == dnodeGetDnodeId()) {
uint32_t moduleStatus = tsModuleStatus | (1 << TSDB_MOD_MNODE);;
dInfo("start mnode module, module status:%d, new status:%d", tsModuleStatus, moduleStatus);
dnodeProcessModuleStatus(moduleStatus);
break;
}
}
}
...@@ -43,6 +43,7 @@ void dnodeGetMnodeEpSetForPeer(void *epSet); ...@@ -43,6 +43,7 @@ void dnodeGetMnodeEpSetForPeer(void *epSet);
void dnodeGetMnodeEpSetForShell(void *epSet); void dnodeGetMnodeEpSetForShell(void *epSet);
void * dnodeGetMnodeInfos(); void * dnodeGetMnodeInfos();
int32_t dnodeGetDnodeId(); int32_t dnodeGetDnodeId();
void dnodeCheckModules();
void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg)); void dnodeAddClientRspHandle(uint8_t msgType, void (*fp)(SRpcMsg *rpcMsg));
void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg); void dnodeSendMsgToDnode(SRpcEpSet *epSet, SRpcMsg *rpcMsg);
......
...@@ -103,6 +103,9 @@ typedef struct { ...@@ -103,6 +103,9 @@ typedef struct {
typedef void* tsync_h; typedef void* tsync_h;
int32_t syncInit();
void syncCleanUp();
tsync_h syncStart(const SSyncInfo *); tsync_h syncStart(const SSyncInfo *);
void syncStop(tsync_h shandle); void syncStop(tsync_h shandle);
int32_t syncReconfig(tsync_h shandle, const SSyncCfg *); int32_t syncReconfig(tsync_h shandle, const SSyncCfg *);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "tqueue.h" #include "tqueue.h"
#include "twal.h" #include "twal.h"
#include "tsync.h" #include "tsync.h"
#include "ttimer.h"
#include "tglobal.h" #include "tglobal.h"
#include "dnode.h" #include "dnode.h"
#include "mnode.h" #include "mnode.h"
...@@ -88,6 +89,8 @@ typedef struct { ...@@ -88,6 +89,8 @@ typedef struct {
SSdbWriteWorker *writeWorker; SSdbWriteWorker *writeWorker;
} SSdbWriteWorkerPool; } SSdbWriteWorkerPool;
extern void * tsMnodeTmr;
static void * tsUpdateSyncTmr;
static SSdbObject tsSdbObj = {0}; static SSdbObject tsSdbObj = {0};
static taos_qset tsSdbWriteQset; static taos_qset tsSdbWriteQset;
static taos_qall tsSdbWriteQall; static taos_qall tsSdbWriteQall;
...@@ -290,11 +293,16 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) { ...@@ -290,11 +293,16 @@ static void sdbConfirmForward(void *ahandle, void *param, int32_t code) {
taosFreeQitem(pOper); taosFreeQitem(pOper);
} }
static void sdbUpdateSyncTmrFp(void *param, void *tmrId) { sdbUpdateSync(); }
void sdbUpdateSync() { void sdbUpdateSync() {
if (!mnodeIsRunning()) { if (!mnodeIsRunning()) {
mDebug("mnode not start yet, update sync info later"); mDebug("mnode not start yet, update sync info later");
dnodeCheckModules();
taosTmrReset(sdbUpdateSyncTmrFp, 1000, NULL, tsMnodeTmr, &tsUpdateSyncTmr);
return; return;
} }
mDebug("update sync info in sdb");
SSyncCfg syncCfg = {0}; SSyncCfg syncCfg = {0};
int32_t index = 0; int32_t index = 0;
...@@ -387,8 +395,6 @@ int32_t sdbInit() { ...@@ -387,8 +395,6 @@ int32_t sdbInit() {
tsSdbObj.role = TAOS_SYNC_ROLE_MASTER; tsSdbObj.role = TAOS_SYNC_ROLE_MASTER;
} }
sdbUpdateSync();
tsSdbObj.status = SDB_STATUS_SERVING; tsSdbObj.status = SDB_STATUS_SERVING;
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
......
此差异已折叠。
...@@ -57,6 +57,9 @@ void syncConfirmForward(tsync_h shandle, uint64_t version, int32_t code) {} ...@@ -57,6 +57,9 @@ void syncConfirmForward(tsync_h shandle, uint64_t version, int32_t code) {}
#endif #endif
int32_t vnodeInitResources() { int32_t vnodeInitResources() {
int code = syncInit();
if (code != 0) return code;
vnodeInitWriteFp(); vnodeInitWriteFp();
vnodeInitReadFp(); vnodeInitReadFp();
...@@ -70,11 +73,12 @@ int32_t vnodeInitResources() { ...@@ -70,11 +73,12 @@ int32_t vnodeInitResources() {
} }
void vnodeCleanupResources() { void vnodeCleanupResources() {
if (tsDnodeVnodesHash != NULL) { if (tsDnodeVnodesHash != NULL) {
taosHashCleanup(tsDnodeVnodesHash); taosHashCleanup(tsDnodeVnodesHash);
tsDnodeVnodesHash = NULL; tsDnodeVnodesHash = NULL;
} }
syncCleanUp();
} }
int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) { int32_t vnodeCreate(SMDCreateVnodeMsg *pVnodeCfg) {
......
...@@ -105,6 +105,15 @@ if $dnode4Vnodes != null then ...@@ -105,6 +105,15 @@ if $dnode4Vnodes != null then
goto show1 goto show1
endi endi
sql show mnodes
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
print ============================== step2 print ============================== step2
print ========= start dnode4 print ========= start dnode4
sql create dnode $hostname4 sql create dnode $hostname4
...@@ -132,6 +141,15 @@ if $dnode4Vnodes != 2 then ...@@ -132,6 +141,15 @@ if $dnode4Vnodes != 2 then
goto show2 goto show2
endi endi
sql show mnodes
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
print ============================== step3 print ============================== step3
print ========= drop dnode2 print ========= drop dnode2
sql drop dnode $hostname2 sql drop dnode $hostname2
...@@ -167,6 +185,15 @@ if $dnode4Vnodes != 3 then ...@@ -167,6 +185,15 @@ if $dnode4Vnodes != 3 then
goto show3 goto show3
endi endi
sql show mnodes
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
system sh/exec.sh -n dnode2 -s stop -x SIGINT system sh/exec.sh -n dnode2 -s stop -x SIGINT
print ============================== step4 print ============================== step4
...@@ -195,6 +222,15 @@ if $dnode5Vnodes != 2 then ...@@ -195,6 +222,15 @@ if $dnode5Vnodes != 2 then
goto show4 goto show4
endi endi
sql show mnodes
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
print ============================== step5 print ============================== step5
print ========= drop dnode3 print ========= drop dnode3
sql drop dnode $hostname3 sql drop dnode $hostname3
...@@ -232,6 +268,15 @@ endi ...@@ -232,6 +268,15 @@ endi
system sh/exec.sh -n dnode3 -s stop -x SIGINT system sh/exec.sh -n dnode3 -s stop -x SIGINT
sql show mnodes
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
print ============================== step6 print ============================== step6
sql create dnode $hostname6 sql create dnode $hostname6
system sh/exec.sh -n dnode6 -s start system sh/exec.sh -n dnode6 -s start
...@@ -258,6 +303,15 @@ if $dnode6Vnodes != 2 then ...@@ -258,6 +303,15 @@ if $dnode6Vnodes != 2 then
goto show6 goto show6
endi endi
sql show mnodes
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
print ============================== step7 print ============================== step7
print ========= drop dnode4 print ========= drop dnode4
sql drop dnode $hostname4 sql drop dnode $hostname4
...@@ -294,6 +348,14 @@ if $dnode4Vnodes != null then ...@@ -294,6 +348,14 @@ if $dnode4Vnodes != null then
endi endi
system sh/exec.sh -n dnode4 -s stop -x SIGINT system sh/exec.sh -n dnode4 -s stop -x SIGINT
sql show mnodes
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
print ============================== step8 print ============================== step8
sql create dnode $hostname7 sql create dnode $hostname7
...@@ -321,6 +383,15 @@ if $dnode7Vnodes != 2 then ...@@ -321,6 +383,15 @@ if $dnode7Vnodes != 2 then
goto show8 goto show8
endi endi
sql show mnodes
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
print ============================== step9 print ============================== step9
print ========= drop dnode1 print ========= drop dnode1
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT
...@@ -335,15 +406,20 @@ sql show mnodes ...@@ -335,15 +406,20 @@ sql show mnodes
$dnode1Role = $data2_1 $dnode1Role = $data2_1
$dnode4Role = $data2_4 $dnode4Role = $data2_4
$dnode5Role = $data2_5 $dnode5Role = $data2_5
print dnode1 ==> $dnode1Role print dnode1 ==> $data2_1
print dnode4 ==> $dnode4Role print dnode2 ==> $data2_2
print dnode5 ==> $dnode5Role print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
if $dnode1Role != offline then if $dnode1Role != offline then
return -1 return -1
endi endi
print ============================== step9.1 print ============================== step9.1
sleep 2000
system sh/exec.sh -n dnode1 -s start system sh/exec.sh -n dnode1 -s start
$x = 0 $x = 0
...@@ -353,6 +429,19 @@ show9: ...@@ -353,6 +429,19 @@ show9:
if $x == 20 then if $x == 20 then
return -1 return -1
endi endi
sql show mnodes
$dnode1Role = $data2_1
$dnode4Role = $data2_4
$dnode5Role = $data2_5
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
sql show dnodes -x show9 sql show dnodes -x show9
$dnode5Vnodes = $data2_5 $dnode5Vnodes = $data2_5
print dnode5 $dnode5Vnodes print dnode5 $dnode5Vnodes
...@@ -374,6 +463,15 @@ endi ...@@ -374,6 +463,15 @@ endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT system sh/exec.sh -n dnode1 -s stop -x SIGINT
sleep 5000 sleep 5000
sql show mnodes
print dnode1 ==> $data2_1
print dnode2 ==> $data2_2
print dnode3 ==> $data2_3
print dnode4 ==> $data2_4
print dnode5 ==> $data2_5
print dnode6 ==> $data2_6
print dnode7 ==> $data2_7
print ============================== step11 print ============================== step11
print ========= add db4 print ========= add db4
......
...@@ -667,7 +667,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) { ...@@ -667,7 +667,7 @@ bool simExecuteNativeSqlCommand(SScript *script, char *rest, bool isSlow) {
TAOS_RES* pSql = NULL; TAOS_RES* pSql = NULL;
for (int attempt = 0; attempt < 3; ++attempt) { for (int attempt = 0; attempt < 10; ++attempt) {
simLogSql(rest, false); simLogSql(rest, false);
pSql = taos_query(script->taos, rest); pSql = taos_query(script->taos, rest);
ret = taos_errno(pSql); ret = taos_errno(pSql);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册