sync encode test
This commit is contained in:
parent
12c202aa31
commit
aaf5e20fdc
|
@ -97,14 +97,17 @@ typedef struct SRaftId {
|
||||||
} SRaftId;
|
} SRaftId;
|
||||||
|
|
||||||
typedef struct SSyncNode {
|
typedef struct SSyncNode {
|
||||||
int8_t replica;
|
|
||||||
int8_t quorum;
|
|
||||||
int32_t refCount;
|
|
||||||
int64_t rid;
|
|
||||||
|
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
SSyncCfg syncCfg;
|
SSyncCfg syncCfg;
|
||||||
char path[TSDB_FILENAME_LEN];
|
char path[TSDB_FILENAME_LEN];
|
||||||
|
SSyncFSM* pFsm;
|
||||||
|
|
||||||
|
// passed from outside
|
||||||
|
void* rpcClient;
|
||||||
|
int32_t (*FpSendMsg)(void* rpcClient, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||||
|
|
||||||
|
int32_t refCount;
|
||||||
|
int64_t rid;
|
||||||
|
|
||||||
SNodeInfo me;
|
SNodeInfo me;
|
||||||
SNodeInfo peers[TSDB_MAX_REPLICA];
|
SNodeInfo peers[TSDB_MAX_REPLICA];
|
||||||
|
@ -112,7 +115,6 @@ typedef struct SSyncNode {
|
||||||
|
|
||||||
ESyncRole role;
|
ESyncRole role;
|
||||||
SRaftId raftId;
|
SRaftId raftId;
|
||||||
SSyncFSM* pFsm;
|
|
||||||
|
|
||||||
tmr_h pPingTimer;
|
tmr_h pPingTimer;
|
||||||
int32_t pingTimerMS;
|
int32_t pingTimerMS;
|
||||||
|
@ -145,10 +147,6 @@ typedef struct SSyncNode {
|
||||||
|
|
||||||
int32_t (*FpOnAppendEntriesReply)(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
int32_t (*FpOnAppendEntriesReply)(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||||
|
|
||||||
// passed from outside
|
|
||||||
void* rpcClient;
|
|
||||||
int32_t (*FpSendMsg)(void* rpcClient, const SEpSet* pEpSet, SRpcMsg* pMsg);
|
|
||||||
|
|
||||||
} SSyncNode;
|
} SSyncNode;
|
||||||
|
|
||||||
SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo);
|
SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo);
|
||||||
|
|
|
@ -37,12 +37,19 @@ static void syncIODoRequest(void *pParent, SRpcMsg *pMsg, SEpSet *pEpSet);
|
||||||
static void syncIOTick(void *param, void *tmrId);
|
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) {
|
||||||
|
pMsg->handle = NULL;
|
||||||
|
rpcSendRequest(handle, pEpSet, pMsg, NULL);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t syncIOStart() {
|
int32_t syncIOStart() {
|
||||||
gSyncIO = syncIOCreate();
|
gSyncIO = syncIOCreate();
|
||||||
assert(gSyncIO != NULL);
|
assert(gSyncIO != NULL);
|
||||||
|
|
||||||
|
int32_t ret = doSyncIOStart(gSyncIO);
|
||||||
|
assert(ret == 0);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,8 +74,7 @@ static void syncIOTick(void *param, void *tmrId) {
|
||||||
|
|
||||||
taosWriteQitem(io->pMsgQ, pTemp);
|
taosWriteQitem(io->pMsgQ, pTemp);
|
||||||
|
|
||||||
bool b = taosTmrReset(syncIOTick, 1000, io, io->syncTimerManager, io->syncTimer);
|
taosTmrReset(syncIOTick, 1000, io, io->syncTimerManager, io->syncTimer);
|
||||||
assert(b);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void *syncIOConsumer(void *param) {
|
static void *syncIOConsumer(void *param) {
|
||||||
|
@ -215,8 +221,8 @@ 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(syncIOTick, 1000, io, io->syncTimerManager);
|
// io->syncTimer = taosTmrStart(syncIOTick, 1000, io, io->syncTimerManager);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,15 +69,34 @@ SSyncNode* syncNodeOpen(const SSyncInfo* pSyncInfo) {
|
||||||
assert(pSyncNode != NULL);
|
assert(pSyncNode != NULL);
|
||||||
memset(pSyncNode, 0, sizeof(SSyncNode));
|
memset(pSyncNode, 0, sizeof(SSyncNode));
|
||||||
|
|
||||||
|
pSyncNode->vgId = pSyncInfo->vgId;
|
||||||
|
pSyncNode->syncCfg = pSyncInfo->syncCfg;
|
||||||
|
memcpy(pSyncNode->path, pSyncInfo->path, sizeof(pSyncNode->path));
|
||||||
|
pSyncNode->pFsm = pSyncInfo->pFsm;
|
||||||
|
|
||||||
|
pSyncNode->rpcClient = pSyncInfo->rpcClient;
|
||||||
|
pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg;
|
||||||
|
|
||||||
|
pSyncNode->me = pSyncInfo->syncCfg.nodeInfo[pSyncInfo->syncCfg.myIndex];
|
||||||
|
pSyncNode->peersNum = pSyncInfo->syncCfg.replicaNum - 1;
|
||||||
|
|
||||||
|
int j = 0;
|
||||||
|
for (int i = 0; i < pSyncInfo->syncCfg.replicaNum; ++i) {
|
||||||
|
if (i != pSyncInfo->syncCfg.myIndex) {
|
||||||
|
pSyncNode->peers[j] = pSyncInfo->syncCfg.nodeInfo[i];
|
||||||
|
j++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pSyncNode->role = TAOS_SYNC_STATE_FOLLOWER;
|
||||||
|
syncUtilnodeInfo2raftId(&pSyncNode->me, pSyncNode->vgId, &pSyncNode->raftId);
|
||||||
|
|
||||||
pSyncNode->pPingTimer = NULL;
|
pSyncNode->pPingTimer = NULL;
|
||||||
pSyncNode->pingTimerMS = 1000;
|
pSyncNode->pingTimerMS = 1000;
|
||||||
atomic_store_8(&pSyncNode->pingTimerStart, 0);
|
atomic_store_8(&pSyncNode->pingTimerStart, 0);
|
||||||
pSyncNode->FpPingTimer = syncNodePingTimerCb;
|
pSyncNode->FpPingTimer = syncNodePingTimerCb;
|
||||||
pSyncNode->pingTimerCounter = 0;
|
pSyncNode->pingTimerCounter = 0;
|
||||||
|
|
||||||
pSyncNode->rpcClient = pSyncInfo->rpcClient;
|
|
||||||
pSyncNode->FpSendMsg = pSyncInfo->FpSendMsg;
|
|
||||||
|
|
||||||
pSyncNode->FpOnPing = syncNodeOnPingCb;
|
pSyncNode->FpOnPing = syncNodeOnPingCb;
|
||||||
pSyncNode->FpOnPingReply = syncNodeOnPingReplyCb;
|
pSyncNode->FpOnPingReply = syncNodeOnPingReplyCb;
|
||||||
pSyncNode->FpOnRequestVote = syncNodeOnRequestVoteCb;
|
pSyncNode->FpOnRequestVote = syncNodeOnRequestVoteCb;
|
||||||
|
@ -97,10 +116,11 @@ void syncNodePingAll(SSyncNode* pSyncNode) {
|
||||||
sTrace("syncNodePingAll %p ", pSyncNode);
|
sTrace("syncNodePingAll %p ", pSyncNode);
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
for (int i = 0; i < pSyncNode->syncCfg.replicaNum; ++i) {
|
for (int i = 0; i < pSyncNode->syncCfg.replicaNum; ++i) {
|
||||||
SyncPing* pSyncPing;
|
SyncPing* pMsg = syncPingBuild(strlen("ping") + 1);
|
||||||
SRaftId raftId;
|
memcpy(pMsg->data, "ping", strlen("ping") + 1);
|
||||||
syncUtilnodeInfo2raftId(&pSyncNode->syncCfg.nodeInfo[i], pSyncNode->vgId, &raftId);
|
syncUtilnodeInfo2raftId(&pSyncNode->syncCfg.nodeInfo[i], pSyncNode->vgId, &pMsg->destId);
|
||||||
ret = syncNodePing(pSyncNode, &raftId, pSyncPing);
|
pMsg->srcId = pSyncNode->raftId;
|
||||||
|
ret = syncNodePing(pSyncNode, &pMsg->destId, pMsg);
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,10 +138,11 @@ void syncNodePingPeers(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
void syncNodePingSelf(SSyncNode* pSyncNode) {
|
void syncNodePingSelf(SSyncNode* pSyncNode) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
SyncPing* pSyncPing;
|
SyncPing* pMsg = syncPingBuild(strlen("ping") + 1);
|
||||||
SRaftId raftId;
|
memcpy(pMsg->data, "ping", strlen("ping") + 1);
|
||||||
syncUtilnodeInfo2raftId(&pSyncNode->me, pSyncNode->vgId, &raftId);
|
pMsg->destId = pSyncNode->raftId;
|
||||||
ret = syncNodePing(pSyncNode, &raftId, pSyncPing);
|
pMsg->srcId = pSyncNode->raftId;
|
||||||
|
ret = syncNodePing(pSyncNode, &pMsg->destId, pMsg);
|
||||||
assert(ret == 0);
|
assert(ret == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,9 +168,9 @@ int32_t syncNodeStopPingTimer(SSyncNode* pSyncNode) {
|
||||||
// ------ local funciton ---------
|
// ------ local funciton ---------
|
||||||
static int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, SyncPing* pMsg) {
|
static int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, SyncPing* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
SRpcMsg* rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
syncPing2RpcMsg(pMsg, rpcMsg);
|
syncPing2RpcMsg(pMsg, &rpcMsg);
|
||||||
syncNodeSendMsgById(destRaftId, pSyncNode, rpcMsg);
|
syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
uint64_t syncUtilAddr2U64(const char* host, uint16_t port) {
|
uint64_t syncUtilAddr2U64(const char* host, uint16_t port) {
|
||||||
uint64_t u64;
|
uint64_t u64;
|
||||||
uint32_t hostU32 = (uint32_t)inet_addr(host);
|
uint32_t hostU32 = (uint32_t)inet_addr(host);
|
||||||
assert(hostU32 != (uint32_t)-1);
|
// assert(hostU32 != (uint32_t)-1);
|
||||||
u64 = (((uint64_t)hostU32) << 32) | (((uint32_t)port) << 16);
|
u64 = (((uint64_t)hostU32) << 32) | (((uint32_t)port) << 16);
|
||||||
return u64;
|
return u64;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue