enh: adjust sync propose
This commit is contained in:
parent
4ddd25a29c
commit
848fd58402
|
@ -656,38 +656,34 @@ int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
|
int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
|
||||||
int32_t ret = 0;
|
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||||
sNTrace(pSyncNode, "propose message, type:%s", TMSG_INFO(pMsg->msgType));
|
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||||
|
sNError(pSyncNode, "sync propose not leader, %s, type:%s", syncStr(pSyncNode->state), TMSG_INFO(pMsg->msgType));
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
return -1;
|
||||||
// not restored, vnode enable
|
|
||||||
if (!pSyncNode->restoreFinish && pSyncNode->vgId != 1) {
|
|
||||||
ret = -1;
|
|
||||||
terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY;
|
|
||||||
sError("vgId:%d, failed to sync propose since not ready, type:%s, last:%" PRId64 ", cmt:%" PRId64,
|
|
||||||
pSyncNode->vgId, TMSG_INFO(pMsg->msgType), syncNodeGetLastIndex(pSyncNode), pSyncNode->commitIndex);
|
|
||||||
goto _END;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SRespStub stub = {.createTime = taosGetTimestampMs(), .rpcMsg = *pMsg};
|
// not restored, vnode enable
|
||||||
uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub);
|
if (!pSyncNode->restoreFinish && pSyncNode->vgId != 1) {
|
||||||
|
terrno = TSDB_CODE_SYN_PROPOSE_NOT_READY;
|
||||||
|
sNError(pSyncNode, "failed to sync propose since not ready, type:%s, last:%" PRId64 ", cmt:%" PRId64,
|
||||||
|
TMSG_INFO(pMsg->msgType), syncNodeGetLastIndex(pSyncNode), pSyncNode->commitIndex);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SyncClientRequest* pSyncMsg = syncClientRequestBuild(pMsg, seqNum, isWeak, pSyncNode->vgId);
|
int32_t ret = 0;
|
||||||
SRpcMsg rpcMsg = {0};
|
SyncClientRequest* pSyncMsg;
|
||||||
syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg);
|
|
||||||
|
|
||||||
// optimized one replica
|
// optimized one replica
|
||||||
if (syncNodeIsOptimizedOneReplica(pSyncNode, pMsg)) {
|
if (syncNodeIsOptimizedOneReplica(pSyncNode, pMsg)) {
|
||||||
|
pSyncMsg = syncClientRequestBuild(pMsg, 0, isWeak, pSyncNode->vgId);
|
||||||
|
|
||||||
SyncIndex retIndex;
|
SyncIndex retIndex;
|
||||||
int32_t code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, &retIndex);
|
int32_t code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, &retIndex);
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
pMsg->info.conn.applyIndex = retIndex;
|
pMsg->info.conn.applyIndex = retIndex;
|
||||||
pMsg->info.conn.applyTerm = pSyncNode->pRaftStore->currentTerm;
|
pMsg->info.conn.applyTerm = pSyncNode->pRaftStore->currentTerm;
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
|
||||||
syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum);
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
sDebug("vgId:%d, sync optimize index:%" PRId64 ", type:%s", pSyncNode->vgId, retIndex,
|
sTrace("vgId:%d, sync optimize index:%" PRId64 ", type:%s", pSyncNode->vgId, retIndex, TMSG_INFO(pMsg->msgType));
|
||||||
TMSG_INFO(pMsg->msgType));
|
|
||||||
} else {
|
} else {
|
||||||
ret = -1;
|
ret = -1;
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
@ -695,25 +691,22 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
|
||||||
TMSG_INFO(pMsg->msgType));
|
TMSG_INFO(pMsg->msgType));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
SRespStub stub = {.createTime = taosGetTimestampMs(), .rpcMsg = *pMsg};
|
||||||
|
uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub);
|
||||||
|
|
||||||
|
pSyncMsg = syncClientRequestBuild(pMsg, seqNum, isWeak, pSyncNode->vgId);
|
||||||
|
SRpcMsg rpcMsg = {0};
|
||||||
|
syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg);
|
||||||
|
|
||||||
|
sNTrace(pSyncNode, "propose message, type:%s", TMSG_INFO(pMsg->msgType));
|
||||||
ret = (*pSyncNode->syncEqMsg)(pSyncNode->msgcb, &rpcMsg);
|
ret = (*pSyncNode->syncEqMsg)(pSyncNode->msgcb, &rpcMsg);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
sError("vgId:%d, failed to enqueue msg since its null", pSyncNode->vgId);
|
sError("vgId:%d, failed to enqueue msg since %s", pSyncNode->vgId, terrstr());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
syncClientRequestDestroy(pSyncMsg);
|
||||||
goto _END;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
ret = -1;
|
|
||||||
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
|
||||||
sError("vgId:%d, sync propose not leader, %s, type:%s", pSyncNode->vgId, syncStr(pSyncNode->state),
|
|
||||||
TMSG_INFO(pMsg->msgType));
|
|
||||||
goto _END;
|
|
||||||
}
|
|
||||||
|
|
||||||
_END:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2522,7 +2515,7 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncInd
|
||||||
|
|
||||||
SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore);
|
SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore);
|
||||||
SyncTerm term = ths->pRaftStore->currentTerm;
|
SyncTerm term = ths->pRaftStore->currentTerm;
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuild2((SyncClientRequest*)pMsg, term, index);
|
SSyncRaftEntry* pEntry = syncEntryBuild2(pMsg, term, index);
|
||||||
ASSERT(pEntry != NULL);
|
ASSERT(pEntry != NULL);
|
||||||
|
|
||||||
LRUHandle* h = NULL;
|
LRUHandle* h = NULL;
|
||||||
|
|
|
@ -836,8 +836,6 @@ SyncClientRequest* syncClientRequestAlloc(uint32_t dataLen) {
|
||||||
SyncClientRequest* pMsg = taosMemoryCalloc(1, bytes);
|
SyncClientRequest* pMsg = taosMemoryCalloc(1, bytes);
|
||||||
pMsg->bytes = bytes;
|
pMsg->bytes = bytes;
|
||||||
pMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
pMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
||||||
pMsg->seqNum = 0;
|
|
||||||
pMsg->isWeak = false;
|
|
||||||
pMsg->dataLen = dataLen;
|
pMsg->dataLen = dataLen;
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
|
@ -178,29 +178,11 @@ void syncUtilMsgNtoH(void* msg) {
|
||||||
pHead->vgId = ntohl(pHead->vgId);
|
pHead->vgId = ntohl(pHead->vgId);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syncUtilUserPreCommit(tmsg_t msgType) {
|
bool syncUtilUserPreCommit(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; }
|
||||||
if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
bool syncUtilUserCommit(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; }
|
||||||
}
|
|
||||||
|
|
||||||
bool syncUtilUserCommit(tmsg_t msgType) {
|
bool syncUtilUserRollback(tmsg_t msgType) { return msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER; }
|
||||||
if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool syncUtilUserRollback(tmsg_t msgType) {
|
|
||||||
if (msgType != TDMT_SYNC_NOOP && msgType != TDMT_SYNC_LEADER_TRANSFER) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
|
void syncCfg2SimpleStr(const SSyncCfg* pCfg, char* buf, int32_t bufLen) {
|
||||||
int32_t len = snprintf(buf, bufLen, "{r-num:%d, my:%d, ", pCfg->replicaNum, pCfg->myIndex);
|
int32_t len = snprintf(buf, bufLen, "{r-num:%d, my:%d, ", pCfg->replicaNum, pCfg->myIndex);
|
||||||
|
|
Loading…
Reference in New Issue