sync modify timer
This commit is contained in:
parent
02f0f85aab
commit
c9efe3dea7
|
@ -28,12 +28,16 @@ extern "C" {
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
|
|
||||||
|
#define TIMER_MAX_MS 0x7FFFFFFF
|
||||||
|
|
||||||
typedef struct SSyncEnv {
|
typedef struct SSyncEnv {
|
||||||
tmr_h pEnvTickTimer;
|
tmr_h pEnvTickTimer;
|
||||||
tmr_h pTimerManager;
|
tmr_h pTimerManager;
|
||||||
char name[128];
|
char name[128];
|
||||||
} SSyncEnv;
|
} SSyncEnv;
|
||||||
|
|
||||||
|
extern SSyncEnv *gSyncEnv;
|
||||||
|
|
||||||
int32_t syncEnvStart();
|
int32_t syncEnvStart();
|
||||||
|
|
||||||
int32_t syncEnvStop();
|
int32_t syncEnvStop();
|
||||||
|
|
|
@ -59,7 +59,6 @@ extern SSyncIO *gSyncIO;
|
||||||
int32_t syncIOStart();
|
int32_t syncIOStart();
|
||||||
int32_t syncIOStop();
|
int32_t syncIOStop();
|
||||||
int32_t syncIOSendMsg(void *handle, const SEpSet *pEpSet, SRpcMsg *pMsg);
|
int32_t syncIOSendMsg(void *handle, const SEpSet *pEpSet, SRpcMsg *pMsg);
|
||||||
SSyncIO *syncIOCreate();
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,6 +88,9 @@ typedef struct SyncAppendEntries SyncAppendEntries;
|
||||||
struct SyncAppendEntriesReply;
|
struct SyncAppendEntriesReply;
|
||||||
typedef struct SyncAppendEntriesReply SyncAppendEntriesReply;
|
typedef struct SyncAppendEntriesReply SyncAppendEntriesReply;
|
||||||
|
|
||||||
|
struct SSyncEnv;
|
||||||
|
typedef struct SSyncEnv SSyncEnv;
|
||||||
|
|
||||||
typedef struct SRaftId {
|
typedef struct SRaftId {
|
||||||
SyncNodeId addr;
|
SyncNodeId addr;
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
|
@ -103,32 +106,46 @@ typedef struct SSyncNode {
|
||||||
SSyncCfg syncCfg;
|
SSyncCfg syncCfg;
|
||||||
char path[TSDB_FILENAME_LEN];
|
char path[TSDB_FILENAME_LEN];
|
||||||
|
|
||||||
|
SNodeInfo me;
|
||||||
|
SNodeInfo peers[TSDB_MAX_REPLICA];
|
||||||
|
int32_t peersNum;
|
||||||
|
|
||||||
ESyncRole role;
|
ESyncRole role;
|
||||||
SRaftId raftId;
|
SRaftId raftId;
|
||||||
SSyncFSM* pFsm;
|
SSyncFSM* pFsm;
|
||||||
|
|
||||||
tmr_h pPingTimer;
|
tmr_h pPingTimer;
|
||||||
tmr_h pElectionTimer;
|
int32_t pingTimerMS;
|
||||||
|
uint8_t pingTimerStart;
|
||||||
|
TAOS_TMR_CALLBACK FpPingTimer; // Timer Fp
|
||||||
|
uint64_t pingTimerCounter;
|
||||||
|
|
||||||
|
tmr_h pElectTimer;
|
||||||
|
int32_t electTimerMS;
|
||||||
|
uint8_t electTimerStart;
|
||||||
|
TAOS_TMR_CALLBACK FpElectTimer; // Timer Fp
|
||||||
|
uint64_t electTimerCounter;
|
||||||
|
|
||||||
tmr_h pHeartbeatTimer;
|
tmr_h pHeartbeatTimer;
|
||||||
|
int32_t heartbeatTimerMS;
|
||||||
|
uint8_t heartbeatTimerStart;
|
||||||
|
TAOS_TMR_CALLBACK FpHeartbeatTimer; // Timer Fp
|
||||||
|
uint64_t heartbeatTimerCounter;
|
||||||
|
|
||||||
int32_t (*FpPing)(struct SSyncNode* ths, const SyncPing* pMsg);
|
// callback
|
||||||
|
|
||||||
int32_t (*FpOnPing)(struct SSyncNode* ths, SyncPing* pMsg);
|
int32_t (*FpOnPing)(struct SSyncNode* ths, SyncPing* pMsg);
|
||||||
|
|
||||||
int32_t (*FpOnPingReply)(struct SSyncNode* ths, SyncPingReply* pMsg);
|
int32_t (*FpOnPingReply)(struct SSyncNode* ths, SyncPingReply* pMsg);
|
||||||
|
|
||||||
int32_t (*FpRequestVote)(struct SSyncNode* ths, const SyncRequestVote* pMsg);
|
|
||||||
|
|
||||||
int32_t (*FpOnRequestVote)(struct SSyncNode* ths, SyncRequestVote* pMsg);
|
int32_t (*FpOnRequestVote)(struct SSyncNode* ths, SyncRequestVote* pMsg);
|
||||||
|
|
||||||
int32_t (*FpOnRequestVoteReply)(struct SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
int32_t (*FpOnRequestVoteReply)(struct SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||||
|
|
||||||
int32_t (*FpAppendEntries)(struct SSyncNode* ths, const SyncAppendEntries* pMsg);
|
|
||||||
|
|
||||||
int32_t (*FpOnAppendEntries)(struct SSyncNode* ths, SyncAppendEntries* pMsg);
|
int32_t (*FpOnAppendEntries)(struct SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||||
|
|
||||||
int32_t (*FpOnAppendEntriesReply)(struct SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
int32_t (*FpOnAppendEntriesReply)(struct SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||||
|
|
||||||
|
// passed from outside
|
||||||
int32_t (*FpSendMsg)(void* handle, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
int32_t (*FpSendMsg)(void* handle, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||||
|
|
||||||
} SSyncNode;
|
} SSyncNode;
|
||||||
|
@ -143,6 +160,10 @@ void syncNodePingPeers(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
void syncNodePingSelf(SSyncNode* pSyncNode);
|
void syncNodePingSelf(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
|
int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
|
int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -59,7 +59,7 @@ static int32_t doSyncEnvStart(SSyncEnv *pSyncEnv) {
|
||||||
// start tmr thread
|
// start tmr thread
|
||||||
pSyncEnv->pTimerManager = taosTmrInit(1000, 50, 10000, "SYNC-ENV");
|
pSyncEnv->pTimerManager = taosTmrInit(1000, 50, 10000, "SYNC-ENV");
|
||||||
|
|
||||||
pSyncEnv->pEnvTickTimer = taosTmrStart(syncEnvTick, 1000, pSyncEnv, pSyncEnv->pTimerManager);
|
// pSyncEnv->pEnvTickTimer = taosTmrStart(syncEnvTick, 1000, pSyncEnv, pSyncEnv->pTimerManager);
|
||||||
|
|
||||||
sTrace("SyncEnv start ok, name:%s", pSyncEnv->name);
|
sTrace("SyncEnv start ok, name:%s", pSyncEnv->name);
|
||||||
|
|
||||||
|
|
|
@ -23,17 +23,18 @@
|
||||||
SSyncIO *gSyncIO = NULL;
|
SSyncIO *gSyncIO = NULL;
|
||||||
|
|
||||||
// local function ------------
|
// local function ------------
|
||||||
static void *syncConsumer(void *param);
|
|
||||||
static int retrieveAuthInfo(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey);
|
|
||||||
static void processResponse(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
|
|
||||||
static void processRequestMsg(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
|
|
||||||
static void syncTick(void *param, void *tmrId);
|
|
||||||
|
|
||||||
static int32_t doSyncIOStart(SSyncIO *io);
|
static int32_t doSyncIOStart(SSyncIO *io);
|
||||||
static int32_t doSyncIOStop(SSyncIO *io);
|
static int32_t doSyncIOStop(SSyncIO *io);
|
||||||
static int32_t doSyncIOPing(SSyncIO *io);
|
static int32_t doSyncIOPing(SSyncIO *io);
|
||||||
static int32_t doSyncIOOnMsg(struct SSyncIO *io, void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
|
static int32_t doSyncIOOnMsg(struct SSyncIO *io, void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||||
static int32_t doSyncIODestroy(SSyncIO *io);
|
static int32_t doSyncIODestroy(SSyncIO *io);
|
||||||
|
|
||||||
|
static SSyncIO *syncIOCreate();
|
||||||
|
static void * syncIOConsumer(void *param);
|
||||||
|
static int syncIOAuth(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey);
|
||||||
|
static void syncIODoReply(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||||
|
static void syncIODoRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||||
|
static void syncIOTick(void *param, void *tmrId);
|
||||||
// ----------------------------
|
// ----------------------------
|
||||||
|
|
||||||
int32_t syncIOSendMsg(void *handle, const SEpSet *pEpSet, SRpcMsg *pMsg) { return 0; }
|
int32_t syncIOSendMsg(void *handle, const SEpSet *pEpSet, SRpcMsg *pMsg) { return 0; }
|
||||||
|
@ -47,27 +48,10 @@ int32_t syncIOStart() {
|
||||||
|
|
||||||
int32_t syncIOStop() { return 0; }
|
int32_t syncIOStop() { return 0; }
|
||||||
|
|
||||||
SSyncIO *syncIOCreate() {
|
|
||||||
SSyncIO *io = (SSyncIO *)malloc(sizeof(SSyncIO));
|
|
||||||
memset(io, 0, sizeof(*io));
|
|
||||||
|
|
||||||
io->pMsgQ = taosOpenQueue();
|
|
||||||
io->pQset = taosOpenQset();
|
|
||||||
taosAddIntoQset(io->pQset, io->pMsgQ, NULL);
|
|
||||||
|
|
||||||
io->start = doSyncIOStart;
|
|
||||||
io->stop = doSyncIOStop;
|
|
||||||
io->ping = doSyncIOPing;
|
|
||||||
io->onMsg = doSyncIOOnMsg;
|
|
||||||
io->destroy = doSyncIODestroy;
|
|
||||||
|
|
||||||
return io;
|
|
||||||
}
|
|
||||||
|
|
||||||
// local function ------------
|
// local function ------------
|
||||||
static void syncTick(void *param, void *tmrId) {
|
static void syncIOTick(void *param, void *tmrId) {
|
||||||
SSyncIO *io = (SSyncIO *)param;
|
SSyncIO *io = (SSyncIO *)param;
|
||||||
sDebug("syncTick ... ");
|
sDebug("syncIOTick ... ");
|
||||||
|
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
rpcMsg.pCont = rpcMallocCont(10);
|
rpcMsg.pCont = rpcMallocCont(10);
|
||||||
|
@ -83,11 +67,11 @@ static void syncTick(void *param, void *tmrId) {
|
||||||
|
|
||||||
taosWriteQitem(io->pMsgQ, pTemp);
|
taosWriteQitem(io->pMsgQ, pTemp);
|
||||||
|
|
||||||
bool b = taosTmrReset(syncTick, 1000, io, io->syncTimerManager, io->syncTimer);
|
bool b = taosTmrReset(syncIOTick, 1000, io, io->syncTimerManager, io->syncTimer);
|
||||||
assert(b);
|
assert(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *syncConsumer(void *param) {
|
static void *syncIOConsumer(void *param) {
|
||||||
SSyncIO *io = param;
|
SSyncIO *io = param;
|
||||||
|
|
||||||
STaosQall *qall;
|
STaosQall *qall;
|
||||||
|
@ -129,19 +113,19 @@ static void *syncConsumer(void *param) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int retrieveAuthInfo(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey) {
|
static int syncIOAuth(void *parent, char *meterId, char *spi, char *encrypt, char *secret, char *ckey) {
|
||||||
// app shall retrieve the auth info based on meterID from DB or a data file
|
// app shall retrieve the auth info based on meterID from DB or a data file
|
||||||
// demo code here only for simple demo
|
// demo code here only for simple demo
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void processResponse(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
static void syncIODoReply(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||||
sDebug("processResponse ... ");
|
sDebug("syncIODoReply ... ");
|
||||||
rpcFreeCont(pMsg->pCont);
|
rpcFreeCont(pMsg->pCont);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void processRequestMsg(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
static void syncIODoRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||||
SSyncIO *io = pParent;
|
SSyncIO *io = pParent;
|
||||||
SRpcMsg *pTemp;
|
SRpcMsg *pTemp;
|
||||||
|
|
||||||
|
@ -152,6 +136,23 @@ static void processRequestMsg(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||||
taosWriteQitem(io->pMsgQ, pTemp);
|
taosWriteQitem(io->pMsgQ, pTemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SSyncIO *syncIOCreate() {
|
||||||
|
SSyncIO *io = (SSyncIO *)malloc(sizeof(SSyncIO));
|
||||||
|
memset(io, 0, sizeof(*io));
|
||||||
|
|
||||||
|
io->pMsgQ = taosOpenQueue();
|
||||||
|
io->pQset = taosOpenQset();
|
||||||
|
taosAddIntoQset(io->pQset, io->pMsgQ, NULL);
|
||||||
|
|
||||||
|
io->start = doSyncIOStart;
|
||||||
|
io->stop = doSyncIOStop;
|
||||||
|
io->ping = doSyncIOPing;
|
||||||
|
io->onMsg = doSyncIOOnMsg;
|
||||||
|
io->destroy = doSyncIODestroy;
|
||||||
|
|
||||||
|
return io;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t doSyncIOStart(SSyncIO *io) {
|
static int32_t doSyncIOStart(SSyncIO *io) {
|
||||||
taosBlockSIGPIPE();
|
taosBlockSIGPIPE();
|
||||||
|
|
||||||
|
@ -164,7 +165,7 @@ static int32_t doSyncIOStart(SSyncIO *io) {
|
||||||
rpcInit.localPort = 0;
|
rpcInit.localPort = 0;
|
||||||
rpcInit.label = "SYNC-IO-CLIENT";
|
rpcInit.label = "SYNC-IO-CLIENT";
|
||||||
rpcInit.numOfThreads = 1;
|
rpcInit.numOfThreads = 1;
|
||||||
rpcInit.cfp = processResponse;
|
rpcInit.cfp = syncIODoReply;
|
||||||
rpcInit.sessions = 100;
|
rpcInit.sessions = 100;
|
||||||
rpcInit.idleTime = 100;
|
rpcInit.idleTime = 100;
|
||||||
rpcInit.user = "sync-io";
|
rpcInit.user = "sync-io";
|
||||||
|
@ -187,10 +188,10 @@ static int32_t doSyncIOStart(SSyncIO *io) {
|
||||||
rpcInit.localPort = 38000;
|
rpcInit.localPort = 38000;
|
||||||
rpcInit.label = "SYNC-IO-SERVER";
|
rpcInit.label = "SYNC-IO-SERVER";
|
||||||
rpcInit.numOfThreads = 1;
|
rpcInit.numOfThreads = 1;
|
||||||
rpcInit.cfp = processRequestMsg;
|
rpcInit.cfp = syncIODoRequest;
|
||||||
rpcInit.sessions = 1000;
|
rpcInit.sessions = 1000;
|
||||||
rpcInit.idleTime = 2 * 1500;
|
rpcInit.idleTime = 2 * 1500;
|
||||||
rpcInit.afp = retrieveAuthInfo;
|
rpcInit.afp = syncIOAuth;
|
||||||
rpcInit.parent = io;
|
rpcInit.parent = io;
|
||||||
rpcInit.connType = TAOS_CONN_SERVER;
|
rpcInit.connType = TAOS_CONN_SERVER;
|
||||||
|
|
||||||
|
@ -206,7 +207,7 @@ static int32_t doSyncIOStart(SSyncIO *io) {
|
||||||
|
|
||||||
// start consumer thread
|
// start consumer thread
|
||||||
{
|
{
|
||||||
if (pthread_create(&io->tid, NULL, syncConsumer, io) != 0) {
|
if (pthread_create(&io->tid, NULL, syncIOConsumer, io) != 0) {
|
||||||
sError("failed to create sync consumer thread since %s", strerror(errno));
|
sError("failed to create sync consumer thread since %s", strerror(errno));
|
||||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -215,7 +216,7 @@ static int32_t doSyncIOStart(SSyncIO *io) {
|
||||||
|
|
||||||
// start tmr thread
|
// start tmr thread
|
||||||
io->syncTimerManager = taosTmrInit(1000, 50, 10000, "SYNC");
|
io->syncTimerManager = taosTmrInit(1000, 50, 10000, "SYNC");
|
||||||
io->syncTimer = taosTmrStart(syncTick, 1000, io, io->syncTimerManager);
|
io->syncTimer = taosTmrStart(syncIOTick, 1000, io, io->syncTimerManager);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "sync.h"
|
#include "sync.h"
|
||||||
|
#include "syncEnv.h"
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "syncRaft.h"
|
#include "syncRaft.h"
|
||||||
|
|
||||||
|
@ -30,6 +31,7 @@ static int32_t onSyncNodeRequestVoteReply(struct SSyncNode* ths, SyncRequestVote
|
||||||
static int32_t doSyncNodeAppendEntries(struct SSyncNode* ths, const SyncAppendEntries* pMsg);
|
static int32_t doSyncNodeAppendEntries(struct SSyncNode* ths, const SyncAppendEntries* pMsg);
|
||||||
static int32_t onSyncNodeAppendEntries(struct SSyncNode* ths, SyncAppendEntries* pMsg);
|
static int32_t onSyncNodeAppendEntries(struct SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||||
static int32_t onSyncNodeAppendEntriesReply(struct SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
static int32_t onSyncNodeAppendEntriesReply(struct SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||||
|
static void syncNodePingTimerCb(void* param, void* tmrId);
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
|
|
||||||
int32_t syncInit() {
|
int32_t syncInit() {
|
||||||
|
@ -58,16 +60,19 @@ void syncGetNodesRole(int64_t rid, SNodesRole* pNodeRole) {}
|
||||||
SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
||||||
SSyncNode* pSyncNode = (SSyncNode*)malloc(sizeof(SSyncNode));
|
SSyncNode* pSyncNode = (SSyncNode*)malloc(sizeof(SSyncNode));
|
||||||
assert(pSyncNode != NULL);
|
assert(pSyncNode != NULL);
|
||||||
|
memset(pSyncNode, 0, sizeof(SSyncNode));
|
||||||
|
|
||||||
|
pSyncNode->pPingTimer = NULL;
|
||||||
|
pSyncNode->pingTimerMS = 1000;
|
||||||
|
atomic_store_8(&pSyncNode->pingTimerStart, 0);
|
||||||
|
pSyncNode->FpPingTimer = syncNodePingTimerCb;
|
||||||
|
pSyncNode->pingTimerCounter = 0;
|
||||||
|
|
||||||
pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg;
|
pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg;
|
||||||
|
|
||||||
pSyncNode->FpPing = doSyncNodePing;
|
|
||||||
pSyncNode->FpOnPing = onSyncNodePing;
|
pSyncNode->FpOnPing = onSyncNodePing;
|
||||||
pSyncNode->FpOnPingReply = onSyncNodePingReply;
|
pSyncNode->FpOnPingReply = onSyncNodePingReply;
|
||||||
pSyncNode->FpRequestVote = doSyncNodeRequestVote;
|
|
||||||
pSyncNode->FpOnRequestVote = onSyncNodeRequestVote;
|
pSyncNode->FpOnRequestVote = onSyncNodeRequestVote;
|
||||||
pSyncNode->FpOnRequestVoteReply = onSyncNodeRequestVoteReply;
|
pSyncNode->FpOnRequestVoteReply = onSyncNodeRequestVoteReply;
|
||||||
pSyncNode->FpAppendEntries = doSyncNodeAppendEntries;
|
|
||||||
pSyncNode->FpOnAppendEntries = onSyncNodeAppendEntries;
|
pSyncNode->FpOnAppendEntries = onSyncNodeAppendEntries;
|
||||||
pSyncNode->FpOnAppendEntriesReply = onSyncNodeAppendEntriesReply;
|
pSyncNode->FpOnAppendEntriesReply = onSyncNodeAppendEntriesReply;
|
||||||
|
|
||||||
|
@ -85,6 +90,25 @@ void syncNodePingPeers(SSyncNode* pSyncNode) {}
|
||||||
|
|
||||||
void syncNodePingSelf(SSyncNode* pSyncNode) {}
|
void syncNodePingSelf(SSyncNode* pSyncNode) {}
|
||||||
|
|
||||||
|
int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) {
|
||||||
|
if (pSyncNode->pPingTimer == NULL) {
|
||||||
|
pSyncNode->pPingTimer =
|
||||||
|
taosTmrStart(pSyncNode->FpPingTimer, pSyncNode->pingTimerCounter, pSyncNode, gSyncEnv->pTimerManager);
|
||||||
|
} else {
|
||||||
|
taosTmrReset(pSyncNode->FpPingTimer, pSyncNode->pingTimerCounter, pSyncNode, gSyncEnv->pTimerManager,
|
||||||
|
&pSyncNode->pPingTimer);
|
||||||
|
}
|
||||||
|
|
||||||
|
atomic_store_8(&pSyncNode->pingTimerStart, 1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode) {
|
||||||
|
atomic_store_8(&pSyncNode->pingTimerStart, 0);
|
||||||
|
pSyncNode->pingTimerCounter = TIMER_MAX_MS;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// ------ local funciton ---------
|
// ------ local funciton ---------
|
||||||
static int32_t doSyncNodePing(struct SSyncNode* ths, const SyncPing* pMsg) {
|
static int32_t doSyncNodePing(struct SSyncNode* ths, const SyncPing* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
@ -130,3 +154,19 @@ static int32_t onSyncNodeAppendEntriesReply(struct SSyncNode* ths, SyncAppendEnt
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void syncNodePingTimerCb(void* param, void* tmrId) {
|
||||||
|
SSyncNode* pSyncNode = (SSyncNode*)param;
|
||||||
|
if (atomic_load_8(&pSyncNode->pingTimerStart)) {
|
||||||
|
++(pSyncNode->pingTimerCounter);
|
||||||
|
// pSyncNode->pingTimerMS += 100;
|
||||||
|
|
||||||
|
sTrace("pSyncNode->pingTimerCounter:%lu, pSyncNode->pingTimerMS:%d, pSyncNode->pPingTimer:%p, tmrId:%p ",
|
||||||
|
pSyncNode->pingTimerCounter, pSyncNode->pingTimerMS, pSyncNode->pPingTimer, tmrId);
|
||||||
|
|
||||||
|
taosTmrReset(syncNodePingTimerCb, pSyncNode->pingTimerMS, pSyncNode, &gSyncEnv->pTimerManager,
|
||||||
|
&pSyncNode->pPingTimer);
|
||||||
|
|
||||||
|
syncNodePingSelf(pSyncNode);
|
||||||
|
}
|
||||||
|
}
|
|
@ -64,7 +64,13 @@ int main() {
|
||||||
|
|
||||||
SSyncNode* pSyncNode = doSync();
|
SSyncNode* pSyncNode = doSync();
|
||||||
|
|
||||||
pSyncNode->pPingTimer = syncEnvStartTimer(timerPingAll, 1000, pSyncNode);
|
ret = syncNodeStartPingTimer(pSyncNode);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
|
taosMsleep(5000);
|
||||||
|
|
||||||
|
ret = syncNodeStopPingTimer(pSyncNode);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
taosMsleep(1000);
|
taosMsleep(1000);
|
||||||
|
|
Loading…
Reference in New Issue