sync refactor
This commit is contained in:
parent
996886e726
commit
d5188f14f9
|
@ -155,28 +155,6 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
|
||||
// accept request
|
||||
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_FOLLOWER && logOK) {
|
||||
/*
|
||||
bool preMatch = false;
|
||||
if (pMsg->prevLogIndex == SYNC_INDEX_INVALID &&
|
||||
ths->pLogStore->getLastIndex(ths->pLogStore) == SYNC_INDEX_INVALID) {
|
||||
preMatch = true;
|
||||
}
|
||||
if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <=
|
||||
ths->pLogStore->getLastIndex(ths->pLogStore)) { SSyncRaftEntry* pPreEntry = logStoreGetEntry(ths->pLogStore,
|
||||
pMsg->prevLogIndex); assert(pPreEntry != NULL); if (pMsg->prevLogTerm == pPreEntry->term) { preMatch = true;
|
||||
}
|
||||
syncEntryDestory(pPreEntry);
|
||||
}
|
||||
|
||||
sTrace(
|
||||
"syncNodeOnAppendEntriesCb --> accept, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, "
|
||||
"ths->state:%d, logOK:%d, preMatch:%d",
|
||||
pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK, preMatch);
|
||||
|
||||
if (preMatch) {
|
||||
*/
|
||||
|
||||
{
|
||||
// preIndex = -1, or has preIndex entry in local log
|
||||
assert(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore));
|
||||
|
||||
|
@ -186,6 +164,11 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
// has entries in SyncAppendEntries msg
|
||||
bool hasAppendEntries = pMsg->dataLen > 0;
|
||||
|
||||
sTrace(
|
||||
"syncNodeOnAppendEntriesCb --> accept, pMsg->term:%lu, ths->pRaftStore->currentTerm:%lu, ths->state:%d, "
|
||||
"logOK:%d, hasExtraEntries:%d, hasAppendEntries:%d",
|
||||
pMsg->term, ths->pRaftStore->currentTerm, ths->state, logOK, hasExtraEntries, hasAppendEntries);
|
||||
|
||||
if (hasExtraEntries && hasAppendEntries) {
|
||||
// not conflict by default
|
||||
bool conflict = false;
|
||||
|
@ -290,25 +273,7 @@ int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|||
SRpcMsg rpcMsg;
|
||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||
|
||||
syncAppendEntriesReplyDestroy(pReply);
|
||||
}
|
||||
|
||||
/*
|
||||
else {
|
||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild();
|
||||
pReply->srcId = ths->myRaftId;
|
||||
pReply->destId = pMsg->srcId;
|
||||
pReply->term = ths->pRaftStore->currentTerm;
|
||||
pReply->success = false;
|
||||
pReply->matchIndex = SYNC_INDEX_INVALID;
|
||||
|
||||
SRpcMsg rpcMsg;
|
||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||
syncAppendEntriesReplyDestroy(pReply);
|
||||
}
|
||||
*/
|
||||
|
||||
// maybe update commit index from leader
|
||||
if (pMsg->commitIndex > ths->commitIndex) {
|
||||
|
|
|
@ -63,7 +63,14 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
|||
if (pEntry->term == pSyncNode->pRaftStore->currentTerm) {
|
||||
// update commit index
|
||||
newCommitIndex = index;
|
||||
sTrace("syncMaybeAdvanceCommitIndex maybe to update, newCommitIndex:%ld commit, pSyncNode->commitIndex:%ld",
|
||||
newCommitIndex, pSyncNode->commitIndex);
|
||||
break;
|
||||
} else {
|
||||
sTrace(
|
||||
"syncMaybeAdvanceCommitIndex can not commit due to term not equal, pEntry->term:%lu, "
|
||||
"pSyncNode->pRaftStore->currentTerm:%lu",
|
||||
pEntry->term, pSyncNode->pRaftStore->currentTerm);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ SSyncFSM* pFsm;
|
|||
SWal* pWal;
|
||||
SSyncNode* pSyncNode;
|
||||
|
||||
SSyncNode* syncNodeInit(const char *path) {
|
||||
SSyncNode* syncNodeInit(const char* path) {
|
||||
syncInfo.vgId = 1234;
|
||||
syncInfo.rpcClient = gSyncIO->clientRpc;
|
||||
syncInfo.FpSendMsg = syncIOSendMsg;
|
||||
|
@ -78,9 +78,7 @@ SSyncNode* syncNodeInit(const char *path) {
|
|||
return pSyncNode;
|
||||
}
|
||||
|
||||
SSyncNode* logStoreCheck(const char *path) { return syncNodeInit(path); }
|
||||
|
||||
|
||||
SSyncNode* logStoreCheck(const char* path) { return syncNodeInit(path); }
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||
|
|
Loading…
Reference in New Issue