other: merge 3.0
This commit is contained in:
commit
015f1a1df8
|
@ -2,7 +2,7 @@
|
||||||
# taos-tools
|
# taos-tools
|
||||||
ExternalProject_Add(taos-tools
|
ExternalProject_Add(taos-tools
|
||||||
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
GIT_REPOSITORY https://github.com/taosdata/taos-tools.git
|
||||||
GIT_TAG 0fb640b
|
GIT_TAG a921bd4
|
||||||
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
SOURCE_DIR "${TD_SOURCE_DIR}/tools/taos-tools"
|
||||||
BINARY_DIR ""
|
BINARY_DIR ""
|
||||||
#BUILD_IN_SOURCE TRUE
|
#BUILD_IN_SOURCE TRUE
|
||||||
|
|
|
@ -1805,7 +1805,7 @@ int32_t tDeserializeSCMCreateTopicRsp(void* buf, int32_t bufLen, SCMCreateTopicR
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t consumerId;
|
int64_t consumerId;
|
||||||
} SMqConsumerLostMsg, SMqConsumerRecoverMsg;
|
} SMqConsumerLostMsg, SMqConsumerRecoverMsg, SMqConsumerClearMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t consumerId;
|
int64_t consumerId;
|
||||||
|
|
|
@ -149,7 +149,7 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DO_REBALANCE, "do-rebalance", SMqDoRebalanceMsg, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DO_REBALANCE, "do-rebalance", SMqDoRebalanceMsg, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DROP_CGROUP, "drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_DROP_CGROUP, "drop-cgroup", SMqDropCGroupReq, SMqDropCGroupRsp)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_UNUSED2, "unused2", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_UNUSED2, "unused2", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_TIMER, "mq-tmr", SMTimerReq, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_TIMER, "tmq-tmr", SMTimerReq, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq)
|
TD_DEF_MSG_TYPE(TDMT_MND_TELEM_TIMER, "telem-tmr", SMTimerReq, SMTimerReq)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TRANS_TIMER, "trans-tmr", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_TTL_TIMER, "ttl-tmr", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_TTL_TIMER, "ttl-tmr", NULL, NULL)
|
||||||
|
@ -171,6 +171,7 @@ enum {
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_SHOW_VARIABLES, "show-variables", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_SHOW_VARIABLES, "show-variables", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_SERVER_VERSION, "server-version", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_SERVER_VERSION, "server-version", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_UPTIME_TIMER, "uptime-timer", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_UPTIME_TIMER, "uptime-timer", NULL, NULL)
|
||||||
|
TD_DEF_MSG_TYPE(TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, "lost-consumer-clear", NULL, NULL)
|
||||||
TD_DEF_MSG_TYPE(TDMT_MND_MAX_MSG, "mnd-max", NULL, NULL)
|
TD_DEF_MSG_TYPE(TDMT_MND_MAX_MSG, "mnd-max", NULL, NULL)
|
||||||
|
|
||||||
TD_NEW_MSG_SEG(TDMT_VND_MSG)
|
TD_NEW_MSG_SEG(TDMT_VND_MSG)
|
||||||
|
|
|
@ -60,19 +60,19 @@ int32_t streamStateDel(SStreamState* pState, const SWinKey* key);
|
||||||
int32_t streamStateClear(SStreamState* pState);
|
int32_t streamStateClear(SStreamState* pState);
|
||||||
void streamStateSetNumber(SStreamState* pState, int32_t number);
|
void streamStateSetNumber(SStreamState* pState, int32_t number);
|
||||||
|
|
||||||
int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen);
|
int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal, int32_t* pVLen);
|
||||||
int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, const void* value, int32_t vLen);
|
int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, const void* value, int32_t vLen);
|
||||||
int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen);
|
int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen);
|
||||||
int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key);
|
int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key);
|
||||||
int32_t streamStateSessionClear(SStreamState* pState);
|
int32_t streamStateSessionClear(SStreamState* pState);
|
||||||
int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, const void** pVal, int32_t* pVLen);
|
int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen);
|
||||||
int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
||||||
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen);
|
state_key_cmpr_fn fn, void** pVal, int32_t* pVLen);
|
||||||
int32_t streamStateSessionGetKey(SStreamState* pState, const SSessionKey* key, SSessionKey* curKey);
|
int32_t streamStateSessionGetKeyByRange(SStreamState* pState, const SSessionKey* range, SSessionKey* curKey);
|
||||||
|
|
||||||
SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key);
|
SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key);
|
||||||
SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, const SSessionKey* key);
|
SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, const SSessionKey* key);
|
||||||
SStreamStateCur* streamStateSessionGetCur(SStreamState* pState, const SSessionKey* key);
|
SStreamStateCur* streamStateSessionSeekKeyCurrentNext(SStreamState* pState, const SSessionKey* key);
|
||||||
|
|
||||||
int32_t streamStateFillPut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
int32_t streamStateFillPut(SStreamState* pState, const SWinKey* key, const void* value, int32_t vLen);
|
||||||
int32_t streamStateFillGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
int32_t streamStateFillGet(SStreamState* pState, const SWinKey* key, void** pVal, int32_t* pVLen);
|
||||||
|
@ -99,7 +99,9 @@ int32_t streamStateSeekLast(SStreamState* pState, SStreamStateCur* pCur);
|
||||||
int32_t streamStateCurNext(SStreamState* pState, SStreamStateCur* pCur);
|
int32_t streamStateCurNext(SStreamState* pState, SStreamStateCur* pCur);
|
||||||
int32_t streamStateCurPrev(SStreamState* pState, SStreamStateCur* pCur);
|
int32_t streamStateCurPrev(SStreamState* pState, SStreamStateCur* pCur);
|
||||||
|
|
||||||
// char* streamStateSessionDump(SStreamState* pState);
|
#if 0
|
||||||
|
char* streamStateSessionDump(SStreamState* pState);
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,6 +139,7 @@ typedef struct SSyncFSM {
|
||||||
void (*FpReConfigCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SReConfigCbMeta* pMeta);
|
void (*FpReConfigCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SReConfigCbMeta* pMeta);
|
||||||
void (*FpLeaderTransferCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
void (*FpLeaderTransferCb)(const struct SSyncFSM* pFsm, const SRpcMsg* pMsg, const SFsmCbMeta* pMeta);
|
||||||
bool (*FpApplyQueueEmptyCb)(const struct SSyncFSM* pFsm);
|
bool (*FpApplyQueueEmptyCb)(const struct SSyncFSM* pFsm);
|
||||||
|
int32_t (*FpApplyQueueItems)(const struct SSyncFSM* pFsm);
|
||||||
|
|
||||||
void (*FpBecomeLeaderCb)(const struct SSyncFSM* pFsm);
|
void (*FpBecomeLeaderCb)(const struct SSyncFSM* pFsm);
|
||||||
void (*FpBecomeFollowerCb)(const struct SSyncFSM* pFsm);
|
void (*FpBecomeFollowerCb)(const struct SSyncFSM* pFsm);
|
||||||
|
|
|
@ -990,7 +990,7 @@ void taos_fetch_rows_a(TAOS_RES *res, __taos_async_fn_t fp, void *param) {
|
||||||
// all data has returned to App already, no need to try again
|
// all data has returned to App already, no need to try again
|
||||||
if (pResultInfo->completed) {
|
if (pResultInfo->completed) {
|
||||||
// it is a local executed query, no need to do async fetch
|
// it is a local executed query, no need to do async fetch
|
||||||
if (QUERY_EXEC_MODE_LOCAL == pRequest->body.execMode) {
|
if (QUERY_EXEC_MODE_SCHEDULE != pRequest->body.execMode) {
|
||||||
if (pResultInfo->localResultFetched) {
|
if (pResultInfo->localResultFetched) {
|
||||||
pResultInfo->numOfRows = 0;
|
pResultInfo->numOfRows = 0;
|
||||||
pResultInfo->current = 0;
|
pResultInfo->current = 0;
|
||||||
|
|
|
@ -44,6 +44,7 @@ SSdbRaw *mndConsumerActionEncode(SMqConsumerObj *pConsumer);
|
||||||
SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw);
|
SSdbRow *mndConsumerActionDecode(SSdbRaw *pRaw);
|
||||||
|
|
||||||
int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer);
|
int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer);
|
||||||
|
int32_t mndSetConsumerDropLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer);
|
||||||
|
|
||||||
bool mndRebTryStart();
|
bool mndRebTryStart();
|
||||||
void mndRebEnd();
|
void mndRebEnd();
|
||||||
|
|
|
@ -33,6 +33,7 @@
|
||||||
#define MND_CONSUMER_RESERVE_SIZE 64
|
#define MND_CONSUMER_RESERVE_SIZE 64
|
||||||
|
|
||||||
#define MND_CONSUMER_LOST_HB_CNT 3
|
#define MND_CONSUMER_LOST_HB_CNT 3
|
||||||
|
#define MND_CONSUMER_LOST_CLEAR_THRESHOLD 43200
|
||||||
|
|
||||||
static int8_t mqRebInExecCnt = 0;
|
static int8_t mqRebInExecCnt = 0;
|
||||||
|
|
||||||
|
@ -50,6 +51,7 @@ static int32_t mndProcessAskEpReq(SRpcMsg *pMsg);
|
||||||
static int32_t mndProcessMqHbReq(SRpcMsg *pMsg);
|
static int32_t mndProcessMqHbReq(SRpcMsg *pMsg);
|
||||||
static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg);
|
static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg);
|
||||||
static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg);
|
static int32_t mndProcessConsumerLostMsg(SRpcMsg *pMsg);
|
||||||
|
static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg);
|
||||||
static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg);
|
static int32_t mndProcessConsumerRecoverMsg(SRpcMsg *pMsg);
|
||||||
|
|
||||||
int32_t mndInitConsumer(SMnode *pMnode) {
|
int32_t mndInitConsumer(SMnode *pMnode) {
|
||||||
|
@ -69,6 +71,7 @@ int32_t mndInitConsumer(SMnode *pMnode) {
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_TIMER, mndProcessMqTimerMsg);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_TIMER, mndProcessMqTimerMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_LOST, mndProcessConsumerLostMsg);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_LOST, mndProcessConsumerLostMsg);
|
||||||
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_RECOVER, mndProcessConsumerRecoverMsg);
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_CONSUMER_RECOVER, mndProcessConsumerRecoverMsg);
|
||||||
|
mndSetMsgHandle(pMnode, TDMT_MND_TMQ_LOST_CONSUMER_CLEAR, mndProcessConsumerClearMsg);
|
||||||
|
|
||||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndRetrieveConsumer);
|
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndRetrieveConsumer);
|
||||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndCancelGetNextConsumer);
|
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONSUMERS, mndCancelGetNextConsumer);
|
||||||
|
@ -162,6 +165,43 @@ FAIL:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t mndProcessConsumerClearMsg(SRpcMsg *pMsg) {
|
||||||
|
SMnode *pMnode = pMsg->info.node;
|
||||||
|
SMqConsumerClearMsg *pClearMsg = pMsg->pCont;
|
||||||
|
SMqConsumerObj *pConsumer = mndAcquireConsumer(pMnode, pClearMsg->consumerId);
|
||||||
|
if (pConsumer == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
mInfo("receive consumer clear msg, consumer id %" PRId64 ", status %s", pClearMsg->consumerId,
|
||||||
|
mndConsumerStatusName(pConsumer->status));
|
||||||
|
|
||||||
|
if (pConsumer->status != MQ_CONSUMER_STATUS__LOST_REBD) {
|
||||||
|
mndReleaseConsumer(pMnode, pConsumer);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SMqConsumerObj *pConsumerNew = tNewSMqConsumerObj(pConsumer->consumerId, pConsumer->cgroup);
|
||||||
|
pConsumerNew->updateType = CONSUMER_UPDATE__LOST;
|
||||||
|
|
||||||
|
mndReleaseConsumer(pMnode, pConsumer);
|
||||||
|
|
||||||
|
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pMsg, "clear-csm");
|
||||||
|
if (pTrans == NULL) goto FAIL;
|
||||||
|
if (mndSetConsumerDropLogs(pMnode, pTrans, pConsumerNew) != 0) goto FAIL;
|
||||||
|
if (mndTransPrepare(pMnode, pTrans) != 0) goto FAIL;
|
||||||
|
|
||||||
|
tDeleteSMqConsumerObj(pConsumerNew);
|
||||||
|
taosMemoryFree(pConsumerNew);
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return 0;
|
||||||
|
FAIL:
|
||||||
|
tDeleteSMqConsumerObj(pConsumerNew);
|
||||||
|
taosMemoryFree(pConsumerNew);
|
||||||
|
mndTransDrop(pTrans);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
static SMqRebInfo *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) {
|
static SMqRebInfo *mndGetOrCreateRebSub(SHashObj *pHash, const char *key) {
|
||||||
SMqRebInfo *pRebInfo = taosHashGet(pHash, key, strlen(key) + 1);
|
SMqRebInfo *pRebInfo = taosHashGet(pHash, key, strlen(key) + 1);
|
||||||
if (pRebInfo == NULL) {
|
if (pRebInfo == NULL) {
|
||||||
|
@ -206,15 +246,28 @@ static int32_t mndProcessMqTimerMsg(SRpcMsg *pMsg) {
|
||||||
SMqConsumerLostMsg *pLostMsg = rpcMallocCont(sizeof(SMqConsumerLostMsg));
|
SMqConsumerLostMsg *pLostMsg = rpcMallocCont(sizeof(SMqConsumerLostMsg));
|
||||||
|
|
||||||
pLostMsg->consumerId = pConsumer->consumerId;
|
pLostMsg->consumerId = pConsumer->consumerId;
|
||||||
SRpcMsg pRpcMsg = {
|
SRpcMsg rpcMsg = {
|
||||||
.msgType = TDMT_MND_TMQ_CONSUMER_LOST,
|
.msgType = TDMT_MND_TMQ_CONSUMER_LOST,
|
||||||
.pCont = pLostMsg,
|
.pCont = pLostMsg,
|
||||||
.contLen = sizeof(SMqConsumerLostMsg),
|
.contLen = sizeof(SMqConsumerLostMsg),
|
||||||
};
|
};
|
||||||
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &pRpcMsg);
|
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
||||||
}
|
}
|
||||||
if (status == MQ_CONSUMER_STATUS__LOST_REBD || status == MQ_CONSUMER_STATUS__READY) {
|
|
||||||
|
if (status == MQ_CONSUMER_STATUS__READY) {
|
||||||
// do nothing
|
// do nothing
|
||||||
|
} else if (status == MQ_CONSUMER_STATUS__LOST_REBD) {
|
||||||
|
if (hbStatus > MND_CONSUMER_LOST_CLEAR_THRESHOLD) {
|
||||||
|
SMqConsumerClearMsg *pClearMsg = rpcMallocCont(sizeof(SMqConsumerClearMsg));
|
||||||
|
|
||||||
|
pClearMsg->consumerId = pConsumer->consumerId;
|
||||||
|
SRpcMsg rpcMsg = {
|
||||||
|
.msgType = TDMT_MND_TMQ_LOST_CONSUMER_CLEAR,
|
||||||
|
.pCont = pClearMsg,
|
||||||
|
.contLen = sizeof(SMqConsumerClearMsg),
|
||||||
|
};
|
||||||
|
tmsgPutToQueue(&pMnode->msgCb, WRITE_QUEUE, &rpcMsg);
|
||||||
|
}
|
||||||
} else if (status == MQ_CONSUMER_STATUS__LOST) {
|
} else if (status == MQ_CONSUMER_STATUS__LOST) {
|
||||||
taosRLockLatch(&pConsumer->lock);
|
taosRLockLatch(&pConsumer->lock);
|
||||||
int32_t topicNum = taosArrayGetSize(pConsumer->currentTopics);
|
int32_t topicNum = taosArrayGetSize(pConsumer->currentTopics);
|
||||||
|
@ -444,6 +497,14 @@ FAIL:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mndSetConsumerDropLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer) {
|
||||||
|
SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer);
|
||||||
|
if (pCommitRaw == NULL) return -1;
|
||||||
|
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||||
|
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer) {
|
int32_t mndSetConsumerCommitLogs(SMnode *pMnode, STrans *pTrans, SMqConsumerObj *pConsumer) {
|
||||||
SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer);
|
SSdbRaw *pCommitRaw = mndConsumerActionEncode(pConsumer);
|
||||||
if (pCommitRaw == NULL) return -1;
|
if (pCommitRaw == NULL) return -1;
|
||||||
|
|
|
@ -205,8 +205,23 @@ static void mndBecomeLeader(const SSyncFSM *pFsm) {
|
||||||
static bool mndApplyQueueEmpty(const SSyncFSM *pFsm) {
|
static bool mndApplyQueueEmpty(const SSyncFSM *pFsm) {
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
|
|
||||||
|
if (pMnode != NULL && pMnode->msgCb.qsizeFp != NULL) {
|
||||||
int32_t itemSize = tmsgGetQueueSize(&pMnode->msgCb, 1, APPLY_QUEUE);
|
int32_t itemSize = tmsgGetQueueSize(&pMnode->msgCb, 1, APPLY_QUEUE);
|
||||||
return (itemSize == 0);
|
return (itemSize == 0);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t mndApplyQueueItems(const SSyncFSM *pFsm) {
|
||||||
|
SMnode *pMnode = pFsm->data;
|
||||||
|
|
||||||
|
if (pMnode != NULL && pMnode->msgCb.qsizeFp != NULL) {
|
||||||
|
int32_t itemSize = tmsgGetQueueSize(&pMnode->msgCb, 1, APPLY_QUEUE);
|
||||||
|
return itemSize;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
|
SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
|
||||||
|
@ -218,6 +233,7 @@ SSyncFSM *mndSyncMakeFsm(SMnode *pMnode) {
|
||||||
pFsm->FpRestoreFinishCb = mndRestoreFinish;
|
pFsm->FpRestoreFinishCb = mndRestoreFinish;
|
||||||
pFsm->FpLeaderTransferCb = NULL;
|
pFsm->FpLeaderTransferCb = NULL;
|
||||||
pFsm->FpApplyQueueEmptyCb = mndApplyQueueEmpty;
|
pFsm->FpApplyQueueEmptyCb = mndApplyQueueEmpty;
|
||||||
|
pFsm->FpApplyQueueItems = mndApplyQueueItems;
|
||||||
pFsm->FpReConfigCb = NULL;
|
pFsm->FpReConfigCb = NULL;
|
||||||
pFsm->FpBecomeLeaderCb = mndBecomeLeader;
|
pFsm->FpBecomeLeaderCb = mndBecomeLeader;
|
||||||
pFsm->FpBecomeFollowerCb = mndBecomeFollower;
|
pFsm->FpBecomeFollowerCb = mndBecomeFollower;
|
||||||
|
|
|
@ -438,8 +438,24 @@ static void vnodeBecomeLeader(const SSyncFSM *pFsm) {
|
||||||
|
|
||||||
static bool vnodeApplyQueueEmpty(const SSyncFSM *pFsm) {
|
static bool vnodeApplyQueueEmpty(const SSyncFSM *pFsm) {
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
|
|
||||||
|
if (pVnode != NULL && pVnode->msgCb.qsizeFp != NULL) {
|
||||||
int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE);
|
int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE);
|
||||||
return (itemSize == 0);
|
return (itemSize == 0);
|
||||||
|
} else {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int32_t vnodeApplyQueueItems(const SSyncFSM *pFsm) {
|
||||||
|
SVnode *pVnode = pFsm->data;
|
||||||
|
|
||||||
|
if (pVnode != NULL && pVnode->msgCb.qsizeFp != NULL) {
|
||||||
|
int32_t itemSize = tmsgGetQueueSize(&pVnode->msgCb, pVnode->config.vgId, APPLY_QUEUE);
|
||||||
|
return itemSize;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
||||||
|
@ -452,6 +468,7 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
||||||
pFsm->FpRestoreFinishCb = vnodeRestoreFinish;
|
pFsm->FpRestoreFinishCb = vnodeRestoreFinish;
|
||||||
pFsm->FpLeaderTransferCb = NULL;
|
pFsm->FpLeaderTransferCb = NULL;
|
||||||
pFsm->FpApplyQueueEmptyCb = vnodeApplyQueueEmpty;
|
pFsm->FpApplyQueueEmptyCb = vnodeApplyQueueEmpty;
|
||||||
|
pFsm->FpApplyQueueItems = vnodeApplyQueueItems;
|
||||||
pFsm->FpBecomeLeaderCb = vnodeBecomeLeader;
|
pFsm->FpBecomeLeaderCb = vnodeBecomeLeader;
|
||||||
pFsm->FpBecomeFollowerCb = vnodeBecomeFollower;
|
pFsm->FpBecomeFollowerCb = vnodeBecomeFollower;
|
||||||
pFsm->FpReConfigCb = NULL;
|
pFsm->FpReConfigCb = NULL;
|
||||||
|
|
|
@ -908,6 +908,8 @@ static SSDataBlock* buildStreamPartitionResult(SOperatorInfo* pOperator) {
|
||||||
blockDataDestroy(pResBlock);
|
blockDataDestroy(pResBlock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
taosArrayDestroy(pParInfo->rowIds);
|
||||||
|
pParInfo->rowIds = NULL;
|
||||||
blockDataUpdateTsWindow(pDest, pInfo->tsColIndex);
|
blockDataUpdateTsWindow(pDest, pInfo->tsColIndex);
|
||||||
pDest->info.groupId = pParInfo->groupId;
|
pDest->info.groupId = pParInfo->groupId;
|
||||||
pOperator->resultInfo.totalRows += pDest->info.rows;
|
pOperator->resultInfo.totalRows += pDest->info.rows;
|
||||||
|
@ -1006,6 +1008,7 @@ static void destroyStreamPartitionOperatorInfo(void* param) {
|
||||||
cleanupExprSupp(&pInfo->tbnameCalSup);
|
cleanupExprSupp(&pInfo->tbnameCalSup);
|
||||||
cleanupExprSupp(&pInfo->tagCalSup);
|
cleanupExprSupp(&pInfo->tagCalSup);
|
||||||
blockDataDestroy(pInfo->pDelRes);
|
blockDataDestroy(pInfo->pDelRes);
|
||||||
|
taosHashCleanup(pInfo->pPartitions);
|
||||||
taosMemoryFreeClear(param);
|
taosMemoryFreeClear(param);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1420,7 +1420,7 @@ static int32_t generateSessionScanRange(SStreamScanInfo* pInfo, SSDataBlock* pSr
|
||||||
uint64_t groupId = getGroupIdByData(pInfo, uidCol[i], startData[i], version);
|
uint64_t groupId = getGroupIdByData(pInfo, uidCol[i], startData[i], version);
|
||||||
// gap must be 0.
|
// gap must be 0.
|
||||||
SSessionKey startWin = {0};
|
SSessionKey startWin = {0};
|
||||||
getCurSessionWindow(pInfo->windowSup.pStreamAggSup, startData[i], endData[i], groupId, &startWin);
|
getCurSessionWindow(pInfo->windowSup.pStreamAggSup, startData[i], startData[i], groupId, &startWin);
|
||||||
if (IS_INVALID_SESSION_WIN_KEY(startWin)) {
|
if (IS_INVALID_SESSION_WIN_KEY(startWin)) {
|
||||||
// window has been closed.
|
// window has been closed.
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -3528,7 +3528,7 @@ void getCurSessionWindow(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endT
|
||||||
pKey->win.skey = startTs;
|
pKey->win.skey = startTs;
|
||||||
pKey->win.ekey = endTs;
|
pKey->win.ekey = endTs;
|
||||||
pKey->groupId = groupId;
|
pKey->groupId = groupId;
|
||||||
int32_t code = streamStateSessionGetKey(pAggSup->pState, pKey, pKey);
|
int32_t code = streamStateSessionGetKeyByRange(pAggSup->pState, pKey, pKey);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
SET_SESSION_WIN_KEY_INVALID(pKey);
|
SET_SESSION_WIN_KEY_INVALID(pKey);
|
||||||
}
|
}
|
||||||
|
@ -3539,10 +3539,11 @@ bool isInvalidSessionWin(SResultWindowInfo* pWinInfo) { return pWinInfo->session
|
||||||
void setSessionOutputBuf(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId,
|
void setSessionOutputBuf(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endTs, uint64_t groupId,
|
||||||
SResultWindowInfo* pCurWin) {
|
SResultWindowInfo* pCurWin) {
|
||||||
pCurWin->sessionWin.groupId = groupId;
|
pCurWin->sessionWin.groupId = groupId;
|
||||||
pCurWin->sessionWin.win.skey = startTs - pAggSup->gap;
|
pCurWin->sessionWin.win.skey = startTs;
|
||||||
pCurWin->sessionWin.win.ekey = endTs + pAggSup->gap;
|
pCurWin->sessionWin.win.ekey = endTs;
|
||||||
int32_t size = pAggSup->resultRowSize;
|
int32_t size = pAggSup->resultRowSize;
|
||||||
int32_t code = streamStateSessionAddIfNotExist(pAggSup->pState, &pCurWin->sessionWin, &pCurWin->pOutputBuf, &size);
|
int32_t code =
|
||||||
|
streamStateSessionAddIfNotExist(pAggSup->pState, &pCurWin->sessionWin, pAggSup->gap, &pCurWin->pOutputBuf, &size);
|
||||||
if (code == TSDB_CODE_SUCCESS) {
|
if (code == TSDB_CODE_SUCCESS) {
|
||||||
pCurWin->isOutput = true;
|
pCurWin->isOutput = true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -3553,7 +3554,7 @@ void setSessionOutputBuf(SStreamAggSupporter* pAggSup, TSKEY startTs, TSKEY endT
|
||||||
|
|
||||||
int32_t getSessionWinBuf(SStreamAggSupporter* pAggSup, SStreamStateCur* pCur, SResultWindowInfo* pWinInfo) {
|
int32_t getSessionWinBuf(SStreamAggSupporter* pAggSup, SStreamStateCur* pCur, SResultWindowInfo* pWinInfo) {
|
||||||
int32_t size = 0;
|
int32_t size = 0;
|
||||||
int32_t code = streamStateSessionGetKVByCur(pCur, &pWinInfo->sessionWin, (const void**)&pWinInfo->pOutputBuf, &size);
|
int32_t code = streamStateSessionGetKVByCur(pCur, &pWinInfo->sessionWin, &pWinInfo->pOutputBuf, &size);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -3658,7 +3659,7 @@ SStreamStateCur* getNextSessionWinInfo(SStreamAggSupporter* pAggSup, SSHashObj*
|
||||||
setSessionWinOutputInfo(pStUpdated, pNextWin);
|
setSessionWinOutputInfo(pStUpdated, pNextWin);
|
||||||
int32_t size = 0;
|
int32_t size = 0;
|
||||||
pNextWin->sessionWin = pCurWin->sessionWin;
|
pNextWin->sessionWin = pCurWin->sessionWin;
|
||||||
int32_t code = streamStateSessionGetKVByCur(pCur, &pNextWin->sessionWin, (const void**)&pNextWin->pOutputBuf, &size);
|
int32_t code = streamStateSessionGetKVByCur(pCur, &pNextWin->sessionWin, &pNextWin->pOutputBuf, &size);
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
SET_SESSION_WIN_INVALID(*pNextWin);
|
SET_SESSION_WIN_INVALID(*pNextWin);
|
||||||
}
|
}
|
||||||
|
@ -3872,7 +3873,9 @@ static void rebuildSessionWindow(SOperatorInfo* pOperator, SArray* pWinArray, SS
|
||||||
SOperatorInfo* pChild = taosArrayGetP(pInfo->pChildren, j);
|
SOperatorInfo* pChild = taosArrayGetP(pInfo->pChildren, j);
|
||||||
SStreamSessionAggOperatorInfo* pChInfo = pChild->info;
|
SStreamSessionAggOperatorInfo* pChInfo = pChild->info;
|
||||||
SStreamAggSupporter* pChAggSup = &pChInfo->streamAggSup;
|
SStreamAggSupporter* pChAggSup = &pChInfo->streamAggSup;
|
||||||
SStreamStateCur* pCur = streamStateSessionGetCur(pChAggSup->pState, pWinKey);
|
SSessionKey chWinKey = *pWinKey;
|
||||||
|
chWinKey.win.ekey = chWinKey.win.skey;
|
||||||
|
SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentNext(pChAggSup->pState, &chWinKey);
|
||||||
SResultRow* pResult = NULL;
|
SResultRow* pResult = NULL;
|
||||||
SResultRow* pChResult = NULL;
|
SResultRow* pChResult = NULL;
|
||||||
while (1) {
|
while (1) {
|
||||||
|
@ -4090,6 +4093,12 @@ static SSDataBlock* doStreamSessionAgg(SOperatorInfo* pOperator) {
|
||||||
initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
||||||
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
char* pBuf = streamStateSessionDump(pAggSup->pState);
|
||||||
|
qDebug("===stream===final session%s", pBuf);
|
||||||
|
taosMemoryFree(pBuf);
|
||||||
|
#endif
|
||||||
|
|
||||||
doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
|
doBuildDeleteDataBlock(pInfo->pStDeleted, pInfo->pDelRes, &pInfo->pDelIterator);
|
||||||
if (pInfo->pDelRes->info.rows > 0) {
|
if (pInfo->pDelRes->info.rows > 0) {
|
||||||
printDataBlock(pInfo->pDelRes, IS_FINAL_OP(pInfo) ? "final session" : "single session");
|
printDataBlock(pInfo->pDelRes, IS_FINAL_OP(pInfo) ? "final session" : "single session");
|
||||||
|
@ -4282,6 +4291,12 @@ static SSDataBlock* doStreamSessionSemiAgg(SOperatorInfo* pOperator) {
|
||||||
initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
initGroupResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
||||||
blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity);
|
blockDataEnsureCapacity(pBInfo->pRes, pOperator->resultInfo.capacity);
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
char* pBuf = streamStateSessionDump(pAggSup->pState);
|
||||||
|
qDebug("===stream===semi session%s", pBuf);
|
||||||
|
taosMemoryFree(pBuf);
|
||||||
|
#endif
|
||||||
|
|
||||||
doBuildSessionResult(pOperator, pAggSup->pState, &pInfo->groupResInfo, pBInfo->pRes);
|
doBuildSessionResult(pOperator, pAggSup->pState, &pInfo->groupResInfo, pBInfo->pRes);
|
||||||
if (pBInfo->pRes->info.rows > 0) {
|
if (pBInfo->pRes->info.rows > 0) {
|
||||||
printDataBlock(pBInfo->pRes, "semi session");
|
printDataBlock(pBInfo->pRes, "semi session");
|
||||||
|
|
|
@ -2393,6 +2393,9 @@ static int32_t translateTable(STranslateContext* pCxt, SNode* pTable) {
|
||||||
if (TSDB_SUPER_TABLE == pRealTable->pMeta->tableType) {
|
if (TSDB_SUPER_TABLE == pRealTable->pMeta->tableType) {
|
||||||
pCxt->stableQuery = true;
|
pCxt->stableQuery = true;
|
||||||
}
|
}
|
||||||
|
if (TSDB_SYSTEM_TABLE == pRealTable->pMeta->tableType && isSelectStmt(pCxt->pCurrStmt)) {
|
||||||
|
((SSelectStmt*)pCxt->pCurrStmt)->isTimeLineResult = false;
|
||||||
|
}
|
||||||
code = addNamespace(pCxt, pRealTable);
|
code = addNamespace(pCxt, pRealTable);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -3428,6 +3431,19 @@ static SNode* createSetOperProject(const char* pTableAlias, SNode* pNode) {
|
||||||
return (SNode*)pCol;
|
return (SNode*)pCol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 0 means equal, 1 means the left shall prevail, -1 means the right shall prevail
|
||||||
|
static int32_t dataTypeComp(const SDataType* l, const SDataType* r) {
|
||||||
|
if (l->type != r->type) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (l->bytes != r->bytes) {
|
||||||
|
return l->bytes > r->bytes ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (l->precision == r->precision && l->scale == r->scale) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pSetOperator) {
|
static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pSetOperator) {
|
||||||
SNodeList* pLeftProjections = getProjectList(pSetOperator->pLeft);
|
SNodeList* pLeftProjections = getProjectList(pSetOperator->pLeft);
|
||||||
SNodeList* pRightProjections = getProjectList(pSetOperator->pRight);
|
SNodeList* pRightProjections = getProjectList(pSetOperator->pRight);
|
||||||
|
@ -3440,7 +3456,8 @@ static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pS
|
||||||
FORBOTH(pLeft, pLeftProjections, pRight, pRightProjections) {
|
FORBOTH(pLeft, pLeftProjections, pRight, pRightProjections) {
|
||||||
SExprNode* pLeftExpr = (SExprNode*)pLeft;
|
SExprNode* pLeftExpr = (SExprNode*)pLeft;
|
||||||
SExprNode* pRightExpr = (SExprNode*)pRight;
|
SExprNode* pRightExpr = (SExprNode*)pRight;
|
||||||
if (!dataTypeEqual(&pLeftExpr->resType, &pRightExpr->resType)) {
|
int32_t comp = dataTypeComp(&pLeftExpr->resType, &pRightExpr->resType);
|
||||||
|
if (comp > 0) {
|
||||||
SNode* pRightFunc = NULL;
|
SNode* pRightFunc = NULL;
|
||||||
int32_t code = createCastFunc(pCxt, pRight, pLeftExpr->resType, &pRightFunc);
|
int32_t code = createCastFunc(pCxt, pRight, pLeftExpr->resType, &pRightFunc);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
|
@ -3448,9 +3465,20 @@ static int32_t translateSetOperProject(STranslateContext* pCxt, SSetOperator* pS
|
||||||
}
|
}
|
||||||
REPLACE_LIST2_NODE(pRightFunc);
|
REPLACE_LIST2_NODE(pRightFunc);
|
||||||
pRightExpr = (SExprNode*)pRightFunc;
|
pRightExpr = (SExprNode*)pRightFunc;
|
||||||
|
} else if (comp < 0) {
|
||||||
|
SNode* pLeftFunc = NULL;
|
||||||
|
int32_t code = createCastFunc(pCxt, pLeft, pRightExpr->resType, &pLeftFunc);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
strcpy(pRightExpr->aliasName, pLeftExpr->aliasName);
|
REPLACE_LIST1_NODE(pLeftFunc);
|
||||||
pRightExpr->aliasName[strlen(pLeftExpr->aliasName)] = '\0';
|
SExprNode* pLeftFuncExpr = (SExprNode*)pLeftFunc;
|
||||||
|
snprintf(pLeftFuncExpr->aliasName, sizeof(pLeftFuncExpr->aliasName), "%s", pLeftExpr->aliasName);
|
||||||
|
snprintf(pLeftFuncExpr->userAlias, sizeof(pLeftFuncExpr->userAlias), "%s", pLeftExpr->userAlias);
|
||||||
|
pLeft = pLeftFunc;
|
||||||
|
pLeftExpr = pLeftFuncExpr;
|
||||||
|
}
|
||||||
|
snprintf(pRightExpr->aliasName, sizeof(pRightExpr->aliasName), "%s", pLeftExpr->aliasName);
|
||||||
if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pSetOperator->pProjectionList,
|
if (TSDB_CODE_SUCCESS != nodesListMakeStrictAppend(&pSetOperator->pProjectionList,
|
||||||
createSetOperProject(pSetOperator->stmtName, pLeft))) {
|
createSetOperProject(pSetOperator->stmtName, pLeft))) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
|
@ -425,6 +425,8 @@ TEST_F(ParserSelectTest, informationSchema) {
|
||||||
run("SELECT * FROM ins_databases WHERE name = 'information_schema'");
|
run("SELECT * FROM ins_databases WHERE name = 'information_schema'");
|
||||||
|
|
||||||
run("SELECT * FROM ins_tags WHERE db_name = 'test' and table_name = 'st1'");
|
run("SELECT * FROM ins_tags WHERE db_name = 'test' and table_name = 'st1'");
|
||||||
|
|
||||||
|
run("SELECT * FROM (SELECT table_name FROM ins_tables) t WHERE table_name = 'a'");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(ParserSelectTest, withoutFrom) {
|
TEST_F(ParserSelectTest, withoutFrom) {
|
||||||
|
|
|
@ -1028,11 +1028,11 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
|
||||||
int32_t type = GET_PARAM_TYPE(pInput);
|
int32_t type = GET_PARAM_TYPE(pInput);
|
||||||
|
|
||||||
bool tzPresent = (inputNum == 2) ? true : false;
|
bool tzPresent = (inputNum == 2) ? true : false;
|
||||||
char *tz;
|
char tz[20] = {0};
|
||||||
int32_t tzLen;
|
int32_t tzLen = 0;
|
||||||
if (tzPresent) {
|
if (tzPresent) {
|
||||||
tz = varDataVal(pInput[1].columnData->pData);
|
|
||||||
tzLen = varDataLen(pInput[1].columnData->pData);
|
tzLen = varDataLen(pInput[1].columnData->pData);
|
||||||
|
memcpy(tz, varDataVal(pInput[1].columnData->pData), tzLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
|
for (int32_t i = 0; i < pInput[0].numOfRows; ++i) {
|
||||||
|
@ -1071,8 +1071,10 @@ int32_t toISO8601Function(SScalarParam *pInput, int32_t inputNum, SScalarParam *
|
||||||
int32_t len = (int32_t)strlen(buf);
|
int32_t len = (int32_t)strlen(buf);
|
||||||
|
|
||||||
// add timezone string
|
// add timezone string
|
||||||
|
if (tzLen > 0) {
|
||||||
snprintf(buf + len, tzLen + 1, "%s", tz);
|
snprintf(buf + len, tzLen + 1, "%s", tz);
|
||||||
len += tzLen;
|
len += tzLen;
|
||||||
|
}
|
||||||
|
|
||||||
if (hasFraction) {
|
if (hasFraction) {
|
||||||
int32_t fracLen = (int32_t)strlen(fraction) + 1;
|
int32_t fracLen = (int32_t)strlen(fraction) + 1;
|
||||||
|
|
|
@ -29,7 +29,7 @@ typedef struct SStateSessionKey {
|
||||||
int64_t opNum;
|
int64_t opNum;
|
||||||
} SStateSessionKey;
|
} SStateSessionKey;
|
||||||
|
|
||||||
static inline int sessionKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pWin2) {
|
static inline int sessionRangeKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pWin2) {
|
||||||
if (pWin1->groupId > pWin2->groupId) {
|
if (pWin1->groupId > pWin2->groupId) {
|
||||||
return 1;
|
return 1;
|
||||||
} else if (pWin1->groupId < pWin2->groupId) {
|
} else if (pWin1->groupId < pWin2->groupId) {
|
||||||
|
@ -45,6 +45,28 @@ static inline int sessionKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pW
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int sessionWinKeyCmpr(const SSessionKey* pWin1, const SSessionKey* pWin2) {
|
||||||
|
if (pWin1->groupId > pWin2->groupId) {
|
||||||
|
return 1;
|
||||||
|
} else if (pWin1->groupId < pWin2->groupId) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pWin1->win.skey > pWin2->win.skey) {
|
||||||
|
return 1;
|
||||||
|
} else if (pWin1->win.skey < pWin2->win.skey) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pWin1->win.ekey > pWin2->win.ekey) {
|
||||||
|
return 1;
|
||||||
|
} else if (pWin1->win.ekey < pWin2->win.ekey) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static inline int stateSessionKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) {
|
static inline int stateSessionKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) {
|
||||||
SStateSessionKey* pWin1 = (SStateSessionKey*)pKey1;
|
SStateSessionKey* pWin1 = (SStateSessionKey*)pKey1;
|
||||||
SStateSessionKey* pWin2 = (SStateSessionKey*)pKey2;
|
SStateSessionKey* pWin2 = (SStateSessionKey*)pKey2;
|
||||||
|
@ -55,7 +77,7 @@ static inline int stateSessionKeyCmpr(const void* pKey1, int kLen1, const void*
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return sessionKeyCmpr(&pWin1->key, &pWin2->key);
|
return sessionWinKeyCmpr(&pWin1->key, &pWin2->key);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int stateKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) {
|
static inline int stateKeyCmpr(const void* pKey1, int kLen1, const void* pKey2, int kLen2) {
|
||||||
|
@ -400,7 +422,6 @@ SStreamStateCur* streamStateSeekKeyNext(SStreamState* pState, const SWinKey* key
|
||||||
SStateKey sKey = {.key = *key, .opNum = pState->number};
|
SStateKey sKey = {.key = *key, .opNum = pState->number};
|
||||||
int32_t c = 0;
|
int32_t c = 0;
|
||||||
if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateKey), &c) < 0) {
|
if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateKey), &c) < 0) {
|
||||||
tdbTbcClose(pCur->pCur);
|
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -426,7 +447,6 @@ SStreamStateCur* streamStateFillSeekKeyNext(SStreamState* pState, const SWinKey*
|
||||||
|
|
||||||
int32_t c = 0;
|
int32_t c = 0;
|
||||||
if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) {
|
if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) {
|
||||||
tdbTbcClose(pCur->pCur);
|
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -452,7 +472,6 @@ SStreamStateCur* streamStateFillSeekKeyPrev(SStreamState* pState, const SWinKey*
|
||||||
|
|
||||||
int32_t c = 0;
|
int32_t c = 0;
|
||||||
if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) {
|
if (tdbTbcMoveTo(pCur->pCur, key, sizeof(SWinKey), &c) < 0) {
|
||||||
tdbTbcClose(pCur->pCur);
|
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -496,33 +515,18 @@ int32_t streamStateSessionPut(SStreamState* pState, const SSessionKey* key, cons
|
||||||
return tdbTbUpsert(pState->pSessionStateDb, &sKey, sizeof(SStateSessionKey), value, vLen, &pState->txn);
|
return tdbTbUpsert(pState->pSessionStateDb, &sKey, sizeof(SStateSessionKey), value, vLen, &pState->txn);
|
||||||
}
|
}
|
||||||
|
|
||||||
SStreamStateCur* streamStateSessionGetRanomCur(SStreamState* pState, const SSessionKey* key) {
|
|
||||||
SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur));
|
|
||||||
if (pCur == NULL) return NULL;
|
|
||||||
tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL);
|
|
||||||
|
|
||||||
int32_t c = -2;
|
|
||||||
SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
|
|
||||||
tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c);
|
|
||||||
if (c != 0) {
|
|
||||||
streamStateFreeCur(pCur);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
pCur->number = pState->number;
|
|
||||||
return pCur;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen) {
|
int32_t streamStateSessionGet(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen) {
|
||||||
SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key);
|
SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentNext(pState, key);
|
||||||
|
SSessionKey resKey = *key;
|
||||||
void* tmp = NULL;
|
void* tmp = NULL;
|
||||||
if (streamStateSessionGetKVByCur(pCur, key, (const void**)&tmp, pVLen) == 0) {
|
int32_t code = streamStateSessionGetKVByCur(pCur, &resKey, &tmp, pVLen);
|
||||||
|
if (code == 0) {
|
||||||
|
*key = resKey;
|
||||||
*pVal = tdbRealloc(NULL, *pVLen);
|
*pVal = tdbRealloc(NULL, *pVLen);
|
||||||
memcpy(*pVal, tmp, *pVLen);
|
memcpy(*pVal, tmp, *pVLen);
|
||||||
streamStateFreeCur(pCur);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return -1;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key) {
|
int32_t streamStateSessionDel(SStreamState* pState, const SSessionKey* key) {
|
||||||
|
@ -544,7 +548,6 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, cons
|
||||||
SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
|
SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
|
||||||
int32_t c = 0;
|
int32_t c = 0;
|
||||||
if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) {
|
if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) {
|
||||||
tdbTbcClose(pCur->pCur);
|
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -558,6 +561,34 @@ SStreamStateCur* streamStateSessionSeekKeyCurrentPrev(SStreamState* pState, cons
|
||||||
return pCur;
|
return pCur;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SStreamStateCur* streamStateSessionSeekKeyCurrentNext(SStreamState* pState, const SSessionKey* key) {
|
||||||
|
SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur));
|
||||||
|
if (pCur == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
pCur->number = pState->number;
|
||||||
|
if (tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL) < 0) {
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
|
||||||
|
int32_t c = 0;
|
||||||
|
if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) {
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (c <= 0) return pCur;
|
||||||
|
|
||||||
|
if (tdbTbcMoveToNext(pCur->pCur) < 0) {
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pCur;
|
||||||
|
}
|
||||||
|
|
||||||
SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key) {
|
SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSessionKey* key) {
|
||||||
SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur));
|
SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur));
|
||||||
if (pCur == NULL) {
|
if (pCur == NULL) {
|
||||||
|
@ -572,7 +603,6 @@ SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSess
|
||||||
SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
|
SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
|
||||||
int32_t c = 0;
|
int32_t c = 0;
|
||||||
if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) {
|
if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) {
|
||||||
tdbTbcClose(pCur->pCur);
|
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -586,13 +616,13 @@ SStreamStateCur* streamStateSessionSeekKeyNext(SStreamState* pState, const SSess
|
||||||
return pCur;
|
return pCur;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, const void** pVal, int32_t* pVLen) {
|
int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, void** pVal, int32_t* pVLen) {
|
||||||
if (!pCur) {
|
if (!pCur) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
const SStateSessionKey* pKTmp = NULL;
|
SStateSessionKey* pKTmp = NULL;
|
||||||
int32_t kLen;
|
int32_t kLen;
|
||||||
if (tdbTbcGet(pCur->pCur, (const void**)&pKTmp, &kLen, pVal, pVLen) < 0) {
|
if (tdbTbcGet(pCur->pCur, (const void**)&pKTmp, &kLen, (const void**)pVal, pVLen) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (pKTmp->opNum != pCur->number) {
|
if (pKTmp->opNum != pCur->number) {
|
||||||
|
@ -607,14 +637,14 @@ int32_t streamStateSessionGetKVByCur(SStreamStateCur* pCur, SSessionKey* pKey, c
|
||||||
|
|
||||||
int32_t streamStateSessionClear(SStreamState* pState) {
|
int32_t streamStateSessionClear(SStreamState* pState) {
|
||||||
SSessionKey key = {.win.skey = 0, .win.ekey = 0, .groupId = 0};
|
SSessionKey key = {.win.skey = 0, .win.ekey = 0, .groupId = 0};
|
||||||
streamStateSessionPut(pState, &key, NULL, 0);
|
SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentNext(pState, &key);
|
||||||
SStreamStateCur* pCur = streamStateSessionSeekKeyNext(pState, &key);
|
|
||||||
while (1) {
|
while (1) {
|
||||||
SSessionKey delKey = {0};
|
SSessionKey delKey = {0};
|
||||||
void* buf = NULL;
|
void* buf = NULL;
|
||||||
int32_t size = 0;
|
int32_t size = 0;
|
||||||
int32_t code = streamStateSessionGetKVByCur(pCur, &delKey, buf, &size);
|
int32_t code = streamStateSessionGetKVByCur(pCur, &delKey, &buf, &size);
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
|
ASSERT(size > 0);
|
||||||
memset(buf, 0, size);
|
memset(buf, 0, size);
|
||||||
streamStateSessionPut(pState, &delKey, buf, size);
|
streamStateSessionPut(pState, &delKey, buf, size);
|
||||||
} else {
|
} else {
|
||||||
|
@ -623,61 +653,104 @@ int32_t streamStateSessionClear(SStreamState* pState) {
|
||||||
streamStateCurNext(pState, pCur);
|
streamStateCurNext(pState, pCur);
|
||||||
}
|
}
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
streamStateSessionDel(pState, &key);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SStreamStateCur* streamStateSessionGetCur(SStreamState* pState, const SSessionKey* key) {
|
int32_t streamStateSessionGetKeyByRange(SStreamState* pState, const SSessionKey* key, SSessionKey* curKey) {
|
||||||
SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key);
|
SStreamStateCur* pCur = taosMemoryCalloc(1, sizeof(SStreamStateCur));
|
||||||
SSessionKey resKey = *key;
|
if (pCur == NULL) {
|
||||||
while (1) {
|
return -1;
|
||||||
streamStateCurPrev(pState, pCur);
|
|
||||||
SSessionKey tmpKey = *key;
|
|
||||||
int32_t code = streamStateSessionGetKVByCur(pCur, &tmpKey, NULL, 0);
|
|
||||||
if (code == 0 && sessionKeyCmpr(key, &tmpKey) == 0) {
|
|
||||||
resKey = tmpKey;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
pCur->number = pState->number;
|
||||||
|
if (tdbTbcOpen(pState->pSessionStateDb, &pCur->pCur, NULL) < 0) {
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return streamStateSessionGetRanomCur(pState, &resKey);
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SStateSessionKey sKey = {.key = *key, .opNum = pState->number};
|
||||||
|
int32_t c = 0;
|
||||||
|
if (tdbTbcMoveTo(pCur->pCur, &sKey, sizeof(SStateSessionKey), &c) < 0) {
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamStateSessionGetKey(SStreamState* pState, const SSessionKey* key, SSessionKey* curKey) {
|
|
||||||
SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key);
|
|
||||||
SSessionKey resKey = *key;
|
SSessionKey resKey = *key;
|
||||||
int32_t res = -1;
|
int32_t code = streamStateSessionGetKVByCur(pCur, &resKey, NULL, 0);
|
||||||
while (1) {
|
if (code == 0 && sessionRangeKeyCmpr(key, &resKey) == 0) {
|
||||||
SSessionKey tmpKey = *key;
|
|
||||||
int32_t code = streamStateSessionGetKVByCur(pCur, &tmpKey, NULL, 0);
|
|
||||||
if (code == 0 && sessionKeyCmpr(key, &tmpKey) == 0) {
|
|
||||||
res = 0;
|
|
||||||
resKey = tmpKey;
|
|
||||||
streamStateCurPrev(pState, pCur);
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*curKey = resKey;
|
*curKey = resKey;
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return res;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, void** pVal, int32_t* pVLen) {
|
if (c > 0) {
|
||||||
// todo refactor
|
streamStateCurNext(pState, pCur);
|
||||||
SStreamStateCur* pCur = streamStateSessionGetRanomCur(pState, key);
|
code = streamStateSessionGetKVByCur(pCur, &resKey, NULL, 0);
|
||||||
int32_t size = *pVLen;
|
if (code == 0 && sessionRangeKeyCmpr(key, &resKey) == 0) {
|
||||||
void* tmp = NULL;
|
*curKey = resKey;
|
||||||
*pVal = tdbRealloc(NULL, size);
|
|
||||||
memset(*pVal, 0, size);
|
|
||||||
if (streamStateSessionGetKVByCur(pCur, key, (const void**)&tmp, pVLen) == 0) {
|
|
||||||
memcpy(*pVal, tmp, *pVLen);
|
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
} else if (c < 0) {
|
||||||
|
streamStateCurPrev(pState, pCur);
|
||||||
|
code = streamStateSessionGetKVByCur(pCur, &resKey, NULL, 0);
|
||||||
|
if (code == 0 && sessionRangeKeyCmpr(key, &resKey) == 0) {
|
||||||
|
*curKey = resKey;
|
||||||
streamStateFreeCur(pCur);
|
streamStateFreeCur(pCur);
|
||||||
return 1;
|
return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t streamStateSessionAddIfNotExist(SStreamState* pState, SSessionKey* key, TSKEY gap, void** pVal,
|
||||||
|
int32_t* pVLen) {
|
||||||
|
// todo refactor
|
||||||
|
int32_t res = 0;
|
||||||
|
SSessionKey originKey = *key;
|
||||||
|
SSessionKey searchKey = *key;
|
||||||
|
searchKey.win.skey = key->win.skey - gap;
|
||||||
|
searchKey.win.ekey = key->win.ekey + gap;
|
||||||
|
int32_t valSize = *pVLen;
|
||||||
|
void* tmp = tdbRealloc(NULL, valSize);
|
||||||
|
if (!tmp) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentPrev(pState, key);
|
||||||
|
int32_t code = streamStateSessionGetKVByCur(pCur, key, pVal, pVLen);
|
||||||
|
if (code == 0) {
|
||||||
|
if (sessionRangeKeyCmpr(&searchKey, key) == 0) {
|
||||||
|
memcpy(tmp, *pVal, valSize);
|
||||||
|
streamStateSessionDel(pState, key);
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
streamStateCurNext(pState, pCur);
|
||||||
|
} else {
|
||||||
|
*key = originKey;
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
|
pCur = streamStateSessionSeekKeyNext(pState, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
code = streamStateSessionGetKVByCur(pCur, key, pVal, pVLen);
|
||||||
|
if (code == 0) {
|
||||||
|
if (sessionRangeKeyCmpr(&searchKey, key) == 0) {
|
||||||
|
memcpy(tmp, *pVal, valSize);
|
||||||
|
streamStateSessionDel(pState, key);
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
*key = originKey;
|
||||||
|
res = 1;
|
||||||
|
memset(tmp, 0, valSize);
|
||||||
|
|
||||||
|
_end:
|
||||||
|
|
||||||
|
*pVal = tmp;
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, char* pKeyData, int32_t keyDataLen,
|
||||||
|
@ -692,16 +765,18 @@ int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, ch
|
||||||
}
|
}
|
||||||
|
|
||||||
SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentPrev(pState, key);
|
SStreamStateCur* pCur = streamStateSessionSeekKeyCurrentPrev(pState, key);
|
||||||
int32_t code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen);
|
int32_t code = streamStateSessionGetKVByCur(pCur, key, pVal, pVLen);
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
if (key->win.skey <= tmpKey.win.skey && tmpKey.win.ekey <= key->win.ekey) {
|
if (key->win.skey <= tmpKey.win.skey && tmpKey.win.ekey <= key->win.ekey) {
|
||||||
memcpy(tmp, *pVal, valSize);
|
memcpy(tmp, *pVal, valSize);
|
||||||
|
streamStateSessionDel(pState, key);
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* stateKey = (char*)(*pVal) + (valSize - keyDataLen);
|
void* stateKey = (char*)(*pVal) + (valSize - keyDataLen);
|
||||||
if (fn(pKeyData, stateKey) == true) {
|
if (fn(pKeyData, stateKey) == true) {
|
||||||
memcpy(tmp, *pVal, valSize);
|
memcpy(tmp, *pVal, valSize);
|
||||||
|
streamStateSessionDel(pState, key);
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -712,11 +787,12 @@ int32_t streamStateStateAddIfNotExist(SStreamState* pState, SSessionKey* key, ch
|
||||||
pCur = streamStateSessionSeekKeyNext(pState, key);
|
pCur = streamStateSessionSeekKeyNext(pState, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
code = streamStateSessionGetKVByCur(pCur, key, (const void**)pVal, pVLen);
|
code = streamStateSessionGetKVByCur(pCur, key, pVal, pVLen);
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
void* stateKey = (char*)(*pVal) + (valSize - keyDataLen);
|
void* stateKey = (char*)(*pVal) + (valSize - keyDataLen);
|
||||||
if (fn(pKeyData, stateKey) == true) {
|
if (fn(pKeyData, stateKey) == true) {
|
||||||
memcpy(tmp, *pVal, valSize);
|
memcpy(tmp, *pVal, valSize);
|
||||||
|
streamStateSessionDel(pState, key);
|
||||||
goto _end;
|
goto _end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -746,8 +822,11 @@ char* streamStateSessionDump(SStreamState* pState) {
|
||||||
tdbTbcMoveToFirst(pCur->pCur);
|
tdbTbcMoveToFirst(pCur->pCur);
|
||||||
|
|
||||||
SSessionKey key = {0};
|
SSessionKey key = {0};
|
||||||
int32_t code = streamStateSessionGetKVByCur(pCur, &key, NULL, 0);
|
void* buf = NULL;
|
||||||
|
int32_t bufSize = 0;
|
||||||
|
int32_t code = streamStateSessionGetKVByCur(pCur, &key, &buf, &bufSize);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -762,12 +841,14 @@ char* streamStateSessionDump(SStreamState* pState) {
|
||||||
key = (SSessionKey){0};
|
key = (SSessionKey){0};
|
||||||
code = streamStateSessionGetKVByCur(pCur, &key, NULL, 0);
|
code = streamStateSessionGetKVByCur(pCur, &key, NULL, 0);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
return dumpBuf;
|
return dumpBuf;
|
||||||
}
|
}
|
||||||
len += snprintf(dumpBuf + len, size - len, "||s:%15" PRId64 ",", key.win.skey);
|
len += snprintf(dumpBuf + len, size - len, "||s:%15" PRId64 ",", key.win.skey);
|
||||||
len += snprintf(dumpBuf + len, size - len, "e:%15" PRId64 ",", key.win.ekey);
|
len += snprintf(dumpBuf + len, size - len, "e:%15" PRId64 ",", key.win.ekey);
|
||||||
len += snprintf(dumpBuf + len, size - len, "g:%15" PRId64 "||", key.groupId);
|
len += snprintf(dumpBuf + len, size - len, "g:%15" PRId64 "||", key.groupId);
|
||||||
}
|
}
|
||||||
|
streamStateFreeCur(pCur);
|
||||||
return dumpBuf;
|
return dumpBuf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -268,8 +268,6 @@ int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode);
|
||||||
// utils --------------
|
// utils --------------
|
||||||
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
int32_t syncNodeSendMsgById(const SRaftId* destRaftId, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||||
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, SRpcMsg* pMsg);
|
||||||
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
|
|
||||||
char* syncNode2Str(const SSyncNode* pSyncNode);
|
|
||||||
char* syncNode2SimpleStr(const SSyncNode* pSyncNode);
|
char* syncNode2SimpleStr(const SSyncNode* pSyncNode);
|
||||||
bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config);
|
bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config);
|
||||||
void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex);
|
void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* newConfig, SyncIndex lastConfigChangeIndex);
|
||||||
|
|
|
@ -42,25 +42,14 @@ typedef struct SSyncRaftEntry {
|
||||||
char data[]; // origin RpcMsg.pCont
|
char data[]; // origin RpcMsg.pCont
|
||||||
} SSyncRaftEntry;
|
} SSyncRaftEntry;
|
||||||
|
|
||||||
SSyncRaftEntry* syncEntryBuild(uint32_t dataLen);
|
SSyncRaftEntry* syncEntryBuild(int32_t dataLen);
|
||||||
SSyncRaftEntry* syncEntryBuild2(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index); // step 4
|
SSyncRaftEntry* syncEntryBuildFromClientRequest(const SyncClientRequest* pMsg, SyncTerm term, SyncIndex index);
|
||||||
SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index);
|
SSyncRaftEntry* syncEntryBuildFromRpcMsg(const SRpcMsg* pMsg, SyncTerm term, SyncIndex index);
|
||||||
SSyncRaftEntry* syncEntryBuild4(SRpcMsg* pOriginalMsg, SyncTerm term, SyncIndex index);
|
SSyncRaftEntry* syncEntryBuildFromAppendEntries(const SyncAppendEntries* pMsg);
|
||||||
SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId);
|
SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId);
|
||||||
void syncEntryDestory(SSyncRaftEntry* pEntry);
|
void syncEntryDestory(SSyncRaftEntry* pEntry);
|
||||||
char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len); // step 5
|
|
||||||
SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len); // step 6
|
|
||||||
cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry);
|
|
||||||
char* syncEntry2Str(const SSyncRaftEntry* pEntry);
|
|
||||||
void syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg); // step 7
|
void syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg); // step 7
|
||||||
|
|
||||||
// for debug ----------------------
|
|
||||||
void syncEntryPrint(const SSyncRaftEntry* pObj);
|
|
||||||
void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj);
|
|
||||||
void syncEntryLog(const SSyncRaftEntry* pObj);
|
|
||||||
void syncEntryLog2(char* s, const SSyncRaftEntry* pObj);
|
|
||||||
|
|
||||||
//-----------------------------------
|
|
||||||
typedef struct SRaftEntryHashCache {
|
typedef struct SRaftEntryHashCache {
|
||||||
SHashObj* pEntryHash;
|
SHashObj* pEntryHash;
|
||||||
int32_t maxCount;
|
int32_t maxCount;
|
||||||
|
@ -78,14 +67,6 @@ int32_t raftCacheDelEntry(struct SRaftEntryHashCache* pCache, SyncI
|
||||||
int32_t raftCacheGetAndDel(struct SRaftEntryHashCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
int32_t raftCacheGetAndDel(struct SRaftEntryHashCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||||
int32_t raftCacheClear(struct SRaftEntryHashCache* pCache);
|
int32_t raftCacheClear(struct SRaftEntryHashCache* pCache);
|
||||||
|
|
||||||
cJSON* raftCache2Json(SRaftEntryHashCache* pObj);
|
|
||||||
char* raftCache2Str(SRaftEntryHashCache* pObj);
|
|
||||||
void raftCachePrint(SRaftEntryHashCache* pObj);
|
|
||||||
void raftCachePrint2(char* s, SRaftEntryHashCache* pObj);
|
|
||||||
void raftCacheLog(SRaftEntryHashCache* pObj);
|
|
||||||
void raftCacheLog2(char* s, SRaftEntryHashCache* pObj);
|
|
||||||
|
|
||||||
//-----------------------------------
|
|
||||||
typedef struct SRaftEntryCache {
|
typedef struct SRaftEntryCache {
|
||||||
SSkipList* pSkipList;
|
SSkipList* pSkipList;
|
||||||
int32_t maxCount;
|
int32_t maxCount;
|
||||||
|
@ -102,13 +83,6 @@ int32_t raftEntryCacheGetEntry(struct SRaftEntryCache* pCache, SyncInde
|
||||||
int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
int32_t raftEntryCacheGetEntryP(struct SRaftEntryCache* pCache, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||||
int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count);
|
int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count);
|
||||||
|
|
||||||
cJSON* raftEntryCache2Json(SRaftEntryCache* pObj);
|
|
||||||
char* raftEntryCache2Str(SRaftEntryCache* pObj);
|
|
||||||
void raftEntryCachePrint(SRaftEntryCache* pObj);
|
|
||||||
void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj);
|
|
||||||
void raftEntryCacheLog(SRaftEntryCache* pObj);
|
|
||||||
void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -40,25 +40,19 @@ typedef struct SSyncLogStoreData {
|
||||||
|
|
||||||
SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode);
|
SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode);
|
||||||
void logStoreDestory(SSyncLogStore* pLogStore);
|
void logStoreDestory(SSyncLogStore* pLogStore);
|
||||||
cJSON* logStore2Json(SSyncLogStore* pLogStore);
|
|
||||||
char* logStore2Str(SSyncLogStore* pLogStore);
|
|
||||||
cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore);
|
|
||||||
char* logStoreSimple2Str(SSyncLogStore* pLogStore);
|
|
||||||
|
|
||||||
SyncIndex logStoreFirstIndex(SSyncLogStore* pLogStore);
|
SyncIndex logStoreFirstIndex(SSyncLogStore* pLogStore);
|
||||||
|
|
||||||
SyncIndex logStoreWalCommitVer(SSyncLogStore* pLogStore);
|
SyncIndex logStoreWalCommitVer(SSyncLogStore* pLogStore);
|
||||||
|
|
||||||
// for debug
|
SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore);
|
||||||
void logStorePrint(SSyncLogStore* pLogStore);
|
bool raftLogIsEmpty(struct SSyncLogStore* pLogStore);
|
||||||
void logStorePrint2(char* s, SSyncLogStore* pLogStore);
|
SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore);
|
||||||
void logStoreLog(SSyncLogStore* pLogStore);
|
SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore);
|
||||||
void logStoreLog2(char* s, SSyncLogStore* pLogStore);
|
int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore);
|
||||||
|
SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore);
|
||||||
void logStoreSimplePrint(SSyncLogStore* pLogStore);
|
SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore);
|
||||||
void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore);
|
int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry);
|
||||||
void logStoreSimpleLog(SSyncLogStore* pLogStore);
|
|
||||||
void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,13 +41,12 @@ typedef struct SSyncRespMgr {
|
||||||
|
|
||||||
SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl);
|
SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl);
|
||||||
void syncRespMgrDestroy(SSyncRespMgr *pObj);
|
void syncRespMgrDestroy(SSyncRespMgr *pObj);
|
||||||
int64_t syncRespMgrAdd(SSyncRespMgr *pObj, SRespStub *pStub);
|
uint64_t syncRespMgrAdd(SSyncRespMgr *pObj, const SRespStub *pStub);
|
||||||
int32_t syncRespMgrDel(SSyncRespMgr *pObj, uint64_t index);
|
int32_t syncRespMgrDel(SSyncRespMgr *pObj, uint64_t seq);
|
||||||
int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub);
|
int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t seq, SRespStub *pStub);
|
||||||
int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub);
|
int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t seq, SRpcHandleInfo *pInfo);
|
||||||
void syncRespClean(SSyncRespMgr *pObj);
|
void syncRespClean(SSyncRespMgr *pObj);
|
||||||
void syncRespCleanRsp(SSyncRespMgr *pObj);
|
void syncRespCleanRsp(SSyncRespMgr *pObj);
|
||||||
void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,9 +26,6 @@ typedef struct SRaftId {
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
} SRaftId;
|
} SRaftId;
|
||||||
|
|
||||||
// for compatibility, the same as syncPropose
|
|
||||||
int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak);
|
|
||||||
|
|
||||||
// ------------------ for debug -------------------
|
// ------------------ for debug -------------------
|
||||||
void syncRpcMsgPrint(SRpcMsg* pMsg);
|
void syncRpcMsgPrint(SRpcMsg* pMsg);
|
||||||
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg);
|
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg);
|
||||||
|
@ -183,15 +180,11 @@ typedef struct SyncClientRequest {
|
||||||
} SyncClientRequest;
|
} SyncClientRequest;
|
||||||
|
|
||||||
SyncClientRequest* syncClientRequestAlloc(uint32_t dataLen);
|
SyncClientRequest* syncClientRequestAlloc(uint32_t dataLen);
|
||||||
SyncClientRequest* syncClientRequestBuild(const SRpcMsg* pMsg, uint64_t seqNum, bool isWeak, int32_t vgId); // step 1
|
int32_t syncClientRequestBuildFromRpcMsg(SRpcMsg* pClientRequestRpcMsg, const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum,
|
||||||
void syncClientRequestDestroy(SyncClientRequest* pMsg);
|
bool isWeak, int32_t vgId);
|
||||||
void syncClientRequestSerialize(const SyncClientRequest* pMsg, char* buf, uint32_t bufLen);
|
int32_t syncClientRequestBuildFromNoopEntry(SRpcMsg* pClientRequestRpcMsg, const SSyncRaftEntry* pEntry, int32_t vgId);
|
||||||
void syncClientRequestDeserialize(const char* buf, uint32_t len, SyncClientRequest* pMsg);
|
|
||||||
char* syncClientRequestSerialize2(const SyncClientRequest* pMsg, uint32_t* len);
|
|
||||||
SyncClientRequest* syncClientRequestDeserialize2(const char* buf, uint32_t len);
|
|
||||||
void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg); // step 2
|
void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg); // step 2
|
||||||
void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg);
|
void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg);
|
||||||
SyncClientRequest* syncClientRequestFromRpcMsg2(const SRpcMsg* pRpcMsg); // step 3
|
|
||||||
cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg);
|
cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg);
|
||||||
char* syncClientRequest2Str(const SyncClientRequest* pMsg);
|
char* syncClientRequest2Str(const SyncClientRequest* pMsg);
|
||||||
|
|
||||||
|
@ -384,14 +377,6 @@ SyncAppendEntriesBatch* syncAppendEntriesBatchDeserialize2(const char* buf, uint
|
||||||
void syncAppendEntriesBatch2RpcMsg(const SyncAppendEntriesBatch* pMsg, SRpcMsg* pRpcMsg);
|
void syncAppendEntriesBatch2RpcMsg(const SyncAppendEntriesBatch* pMsg, SRpcMsg* pRpcMsg);
|
||||||
void syncAppendEntriesBatchFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesBatch* pMsg);
|
void syncAppendEntriesBatchFromRpcMsg(const SRpcMsg* pRpcMsg, SyncAppendEntriesBatch* pMsg);
|
||||||
SyncAppendEntriesBatch* syncAppendEntriesBatchFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
SyncAppendEntriesBatch* syncAppendEntriesBatchFromRpcMsg2(const SRpcMsg* pRpcMsg);
|
||||||
cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg);
|
|
||||||
char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg);
|
|
||||||
|
|
||||||
// for debug ----------------------
|
|
||||||
void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg);
|
|
||||||
void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg);
|
|
||||||
void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg);
|
|
||||||
void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg);
|
|
||||||
|
|
||||||
// ---------------------------------------------
|
// ---------------------------------------------
|
||||||
typedef struct SyncAppendEntriesReply {
|
typedef struct SyncAppendEntriesReply {
|
||||||
|
@ -742,14 +727,14 @@ int32_t syncNodeOnSnapshotReply(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
||||||
int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg);
|
int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg);
|
||||||
int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg);
|
int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg);
|
||||||
|
|
||||||
int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex);
|
int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex);
|
||||||
int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg);
|
int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg);
|
||||||
int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg);
|
int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg);
|
||||||
|
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg);
|
typedef int32_t (*FpOnPingCb)(SSyncNode* ths, SyncPing* pMsg);
|
||||||
typedef int32_t (*FpOnPingReplyCb)(SSyncNode* ths, SyncPingReply* pMsg);
|
typedef int32_t (*FpOnPingReplyCb)(SSyncNode* ths, SyncPingReply* pMsg);
|
||||||
typedef int32_t (*FpOnClientRequestCb)(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex);
|
typedef int32_t (*FpOnClientRequestCb)(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex);
|
||||||
typedef int32_t (*FpOnRequestVoteCb)(SSyncNode* ths, SyncRequestVote* pMsg);
|
typedef int32_t (*FpOnRequestVoteCb)(SSyncNode* ths, SyncRequestVote* pMsg);
|
||||||
typedef int32_t (*FpOnRequestVoteReplyCb)(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
typedef int32_t (*FpOnRequestVoteReplyCb)(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||||
typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg);
|
typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||||
|
|
|
@ -179,7 +179,7 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
pReply->success = true;
|
pReply->success = true;
|
||||||
bool hasAppendEntries = pMsg->dataLen > 0;
|
bool hasAppendEntries = pMsg->dataLen > 0;
|
||||||
if (hasAppendEntries) {
|
if (hasAppendEntries) {
|
||||||
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
SSyncRaftEntry* pAppendEntry = syncEntryBuildFromAppendEntries(pMsg);
|
||||||
ASSERT(pAppendEntry != NULL);
|
ASSERT(pAppendEntry != NULL);
|
||||||
|
|
||||||
SyncIndex appendIndex = pMsg->prevLogIndex + 1;
|
SyncIndex appendIndex = pMsg->prevLogIndex + 1;
|
||||||
|
@ -246,7 +246,8 @@ int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
} else {
|
} else {
|
||||||
// error
|
// error
|
||||||
char logBuf[128];
|
char logBuf[128];
|
||||||
snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%" PRId64, appendIndex);
|
snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%" PRId64 " err:%d", appendIndex,
|
||||||
|
terrno);
|
||||||
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||||
|
|
||||||
syncEntryDestory(pLocalEntry);
|
syncEntryDestory(pLocalEntry);
|
||||||
|
|
|
@ -154,9 +154,7 @@ int32_t syncProcessMsg(int64_t rid, SRpcMsg* pMsg) {
|
||||||
code = syncNodeOnPingReply(pSyncNode, pSyncMsg);
|
code = syncNodeOnPingReply(pSyncNode, pSyncMsg);
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
syncPingReplyDestroy(pSyncMsg);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||||
SyncClientRequest* pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
code = syncNodeOnClientRequest(pSyncNode, pMsg, NULL);
|
||||||
code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL);
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
||||||
SyncRequestVote* pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
SyncRequestVote* pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
||||||
code = syncNodeOnRequestVote(pSyncNode, pSyncMsg);
|
code = syncNodeOnRequestVote(pSyncNode, pSyncMsg);
|
||||||
|
@ -452,11 +450,6 @@ int32_t syncNodeLeaderTransferTo(SSyncNode* pSyncNode, SNodeInfo newLeader) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncForwardToPeer(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
|
|
||||||
int32_t ret = syncPropose(rid, pMsg, isWeak);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncState syncGetState(int64_t rid) {
|
SSyncState syncGetState(int64_t rid) {
|
||||||
SSyncState state = {.state = TAOS_SYNC_STATE_ERROR};
|
SSyncState state = {.state = TAOS_SYNC_STATE_ERROR};
|
||||||
|
|
||||||
|
@ -558,109 +551,27 @@ SyncIndex syncNodeGetSnapshotConfigIndex(SSyncNode* pSyncNode, SyncIndex snapsho
|
||||||
return lastIndex;
|
return lastIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
SyncTerm syncGetMyTerm(int64_t rid) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return TAOS_SYNC_STATE_ERROR;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
SyncTerm term = pSyncNode->pRaftStore->currentTerm;
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return term;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex syncGetLastIndex(int64_t rid) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return SYNC_INDEX_INVALID;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
SyncIndex lastIndex = syncNodeGetLastIndex(pSyncNode);
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return lastIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex syncGetCommitIndex(int64_t rid) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return SYNC_INDEX_INVALID;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
SyncIndex cmtIndex = pSyncNode->commitIndex;
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return cmtIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncGroupId syncGetVgId(int64_t rid) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
return TAOS_SYNC_STATE_ERROR;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
SyncGroupId vgId = pSyncNode->vgId;
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return vgId;
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncGetEpSet(int64_t rid, SEpSet* pEpSet) {
|
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
memset(pEpSet, 0, sizeof(*pEpSet));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ASSERT(rid == pSyncNode->rid);
|
|
||||||
pEpSet->numOfEps = 0;
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
|
||||||
snprintf(pEpSet->eps[i].fqdn, sizeof(pEpSet->eps[i].fqdn), "%s", (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodeFqdn);
|
|
||||||
pEpSet->eps[i].port = (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodePort;
|
|
||||||
(pEpSet->numOfEps)++;
|
|
||||||
sInfo("vgId:%d, sync get epset: index:%d %s:%d", pSyncNode->vgId, i, pEpSet->eps[i].fqdn, pEpSet->eps[i].port);
|
|
||||||
}
|
|
||||||
pEpSet->inUse = pSyncNode->pRaftCfg->cfg.myIndex;
|
|
||||||
sInfo("vgId:%d, sync get epset in-use:%d", pSyncNode->vgId, pEpSet->inUse);
|
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
|
||||||
memset(pEpSet, 0, sizeof(*pEpSet));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
pEpSet->numOfEps = 0;
|
pEpSet->numOfEps = 0;
|
||||||
|
|
||||||
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
|
if (pSyncNode == NULL) return;
|
||||||
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
||||||
snprintf(pEpSet->eps[i].fqdn, sizeof(pEpSet->eps[i].fqdn), "%s", (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodeFqdn);
|
SEp* pEp = &pEpSet->eps[i];
|
||||||
pEpSet->eps[i].port = (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodePort;
|
tstrncpy(pEp->fqdn, pSyncNode->pRaftCfg->cfg.nodeInfo[i].nodeFqdn, TSDB_FQDN_LEN);
|
||||||
(pEpSet->numOfEps)++;
|
pEp->port = (pSyncNode->pRaftCfg->cfg.nodeInfo)[i].nodePort;
|
||||||
sInfo("vgId:%d, sync get retry epset: index:%d %s:%d", pSyncNode->vgId, i, pEpSet->eps[i].fqdn,
|
pEpSet->numOfEps++;
|
||||||
pEpSet->eps[i].port);
|
sInfo("vgId:%d, sync get retry epset, index:%d %s:%d", pSyncNode->vgId, i, pEp->fqdn, pEp->port);
|
||||||
}
|
}
|
||||||
if (pEpSet->numOfEps > 0) {
|
if (pEpSet->numOfEps > 0) {
|
||||||
pEpSet->inUse = (pSyncNode->pRaftCfg->cfg.myIndex + 1) % pEpSet->numOfEps;
|
pEpSet->inUse = (pSyncNode->pRaftCfg->cfg.myIndex + 1) % pEpSet->numOfEps;
|
||||||
}
|
}
|
||||||
sInfo("vgId:%d, sync get retry epset in-use:%d", pSyncNode->vgId, pEpSet->inUse);
|
|
||||||
|
|
||||||
|
sInfo("vgId:%d, sync get retry epset numOfEps:%d inUse:%d", pSyncNode->vgId, pEpSet->numOfEps, pEpSet->inUse);
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void syncGetAndDelRespRpc(SSyncNode* pSyncNode, uint64_t index, SRpcHandleInfo* pInfo) {
|
|
||||||
SRespStub stub;
|
|
||||||
int32_t ret = syncRespMgrGetAndDel(pSyncNode->pSyncRespMgr, index, &stub);
|
|
||||||
if (ret == 1) {
|
|
||||||
*pInfo = stub.rpcMsg.info;
|
|
||||||
}
|
|
||||||
|
|
||||||
sTrace("vgId:%d, get seq:%" PRIu64 " rpc handle:%p", pSyncNode->vgId, index, pInfo->handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
|
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
if (pSyncNode == NULL) {
|
if (pSyncNode == NULL) {
|
||||||
|
@ -688,44 +599,42 @@ int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ret = 0;
|
|
||||||
SyncClientRequest* pSyncMsg;
|
|
||||||
|
|
||||||
// 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, pMsg, &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;
|
||||||
ret = 1;
|
sTrace("vgId:%d, propose optimized msg, index:%" PRId64 " type:%s", pSyncNode->vgId, retIndex,
|
||||||
sTrace("vgId:%d, sync optimize index:%" PRId64 ", type:%s", pSyncNode->vgId, retIndex, TMSG_INFO(pMsg->msgType));
|
|
||||||
} else {
|
|
||||||
ret = -1;
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
sError("vgId:%d, failed to sync optimize index:%" PRId64 ", type:%s", pSyncNode->vgId, retIndex,
|
|
||||||
TMSG_INFO(pMsg->msgType));
|
TMSG_INFO(pMsg->msgType));
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
sError("vgId:%d, failed to propose optimized msg, index:%" PRId64 " type:%s", pSyncNode->vgId, retIndex,
|
||||||
|
TMSG_INFO(pMsg->msgType));
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SRespStub stub = {.createTime = taosGetTimestampMs(), .rpcMsg = *pMsg};
|
SRespStub stub = {.createTime = taosGetTimestampMs(), .rpcMsg = *pMsg};
|
||||||
uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub);
|
uint64_t seqNum = syncRespMgrAdd(pSyncNode->pSyncRespMgr, &stub);
|
||||||
|
|
||||||
pSyncMsg = syncClientRequestBuild(pMsg, seqNum, isWeak, pSyncNode->vgId);
|
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg);
|
int32_t code = syncClientRequestBuildFromRpcMsg(&rpcMsg, pMsg, seqNum, isWeak, pSyncNode->vgId);
|
||||||
|
if (code != 0) {
|
||||||
sNTrace(pSyncNode, "propose message, type:%s", TMSG_INFO(pMsg->msgType));
|
sError("vgId:%d, failed to propose msg while serialize since %s", pSyncNode->vgId, terrstr());
|
||||||
ret = (*pSyncNode->syncEqMsg)(pSyncNode->msgcb, &rpcMsg);
|
(void)syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum);
|
||||||
if (ret != 0) {
|
return -1;
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
sError("vgId:%d, failed to enqueue msg since %s", pSyncNode->vgId, terrstr());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
sNTrace(pSyncNode, "propose msg, type:%s", TMSG_INFO(pMsg->msgType));
|
||||||
return ret;
|
code = (*pSyncNode->syncEqMsg)(pSyncNode->msgcb, &rpcMsg);
|
||||||
|
if (code != 0) {
|
||||||
|
sError("vgId:%d, failed to propose msg while enqueue since %s", pSyncNode->vgId, terrstr());
|
||||||
|
(void)syncRespMgrDel(pSyncNode->pSyncRespMgr, seqNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId) {
|
static int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId) {
|
||||||
|
@ -1127,6 +1036,7 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
ret = raftStoreClose(pSyncNode->pRaftStore);
|
ret = raftStoreClose(pSyncNode->pRaftStore);
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
|
pSyncNode->pRaftStore = NULL;
|
||||||
|
|
||||||
syncRespMgrDestroy(pSyncNode->pSyncRespMgr);
|
syncRespMgrDestroy(pSyncNode->pSyncRespMgr);
|
||||||
pSyncNode->pSyncRespMgr = NULL;
|
pSyncNode->pSyncRespMgr = NULL;
|
||||||
|
@ -1171,53 +1081,6 @@ void syncNodeClose(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotStrategy; }
|
ESyncStrategy syncNodeStrategy(SSyncNode* pSyncNode) { return pSyncNode->pRaftCfg->snapshotStrategy; }
|
||||||
|
|
||||||
// ping --------------
|
|
||||||
int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, SyncPing* pMsg) {
|
|
||||||
syncPingLog2((char*)"==syncNodePing==", pMsg);
|
|
||||||
int32_t ret = 0;
|
|
||||||
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncPing2RpcMsg(pMsg, &rpcMsg);
|
|
||||||
syncRpcMsgLog2((char*)"==syncNodePing==", &rpcMsg);
|
|
||||||
|
|
||||||
ret = syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncNodePingSelf(SSyncNode* pSyncNode) {
|
|
||||||
int32_t ret = 0;
|
|
||||||
SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, &pSyncNode->myRaftId, pSyncNode->vgId);
|
|
||||||
ret = syncNodePing(pSyncNode, &pMsg->destId, pMsg);
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
|
|
||||||
syncPingDestroy(pMsg);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncNodePingPeers(SSyncNode* pSyncNode) {
|
|
||||||
int32_t ret = 0;
|
|
||||||
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
|
||||||
SRaftId* destId = &(pSyncNode->peersId[i]);
|
|
||||||
SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId);
|
|
||||||
ret = syncNodePing(pSyncNode, destId, pMsg);
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
syncPingDestroy(pMsg);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncNodePingAll(SSyncNode* pSyncNode) {
|
|
||||||
int32_t ret = 0;
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
|
||||||
SRaftId* destId = &(pSyncNode->replicasId[i]);
|
|
||||||
SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId);
|
|
||||||
ret = syncNodePing(pSyncNode, destId, pMsg);
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
syncPingDestroy(pMsg);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// timer control --------------
|
// timer control --------------
|
||||||
int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) {
|
int32_t syncNodeStartPingTimer(SSyncNode* pSyncNode) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
@ -1380,196 +1243,6 @@ int32_t syncNodeSendMsgByInfo(const SNodeInfo* nodeInfo, SSyncNode* pSyncNode, S
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pSyncNode != NULL) {
|
|
||||||
// init by SSyncInfo
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vgId", pSyncNode->vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "SRaftCfg", raftCfg2Json(pSyncNode->pRaftCfg));
|
|
||||||
cJSON_AddStringToObject(pRoot, "path", pSyncNode->path);
|
|
||||||
cJSON_AddStringToObject(pRoot, "raftStorePath", pSyncNode->raftStorePath);
|
|
||||||
cJSON_AddStringToObject(pRoot, "configPath", pSyncNode->configPath);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pWal);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
|
||||||
cJSON_AddStringToObject(pRoot, "rpcClient", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->syncSendMSg);
|
|
||||||
cJSON_AddStringToObject(pRoot, "syncSendMSg", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
|
||||||
cJSON_AddStringToObject(pRoot, "queue", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->syncEqMsg);
|
|
||||||
cJSON_AddStringToObject(pRoot, "syncEqMsg", u64buf);
|
|
||||||
|
|
||||||
// init internal
|
|
||||||
cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo);
|
|
||||||
cJSON_AddItemToObject(pRoot, "myNodeInfo", pMe);
|
|
||||||
cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId);
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "peersNum", pSyncNode->peersNum);
|
|
||||||
cJSON* pPeers = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "peersNodeInfo", pPeers);
|
|
||||||
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
|
||||||
cJSON_AddItemToArray(pPeers, syncUtilNodeInfo2Json(&pSyncNode->peersNodeInfo[i]));
|
|
||||||
}
|
|
||||||
cJSON* pPeersId = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "peersId", pPeersId);
|
|
||||||
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
|
||||||
cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncNode->replicaNum);
|
|
||||||
cJSON* pReplicasId = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "replicasId", pReplicasId);
|
|
||||||
for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
|
|
||||||
cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// raft algorithm
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pFsm);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pFsm", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "quorum", pSyncNode->quorum);
|
|
||||||
cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache);
|
|
||||||
cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache);
|
|
||||||
|
|
||||||
// life cycle
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->rid);
|
|
||||||
cJSON_AddStringToObject(pRoot, "rid", u64buf);
|
|
||||||
|
|
||||||
// tla+ server vars
|
|
||||||
cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state);
|
|
||||||
cJSON_AddStringToObject(pRoot, "state_str", syncStr(pSyncNode->state));
|
|
||||||
cJSON_AddItemToObject(pRoot, "pRaftStore", raftStore2Json(pSyncNode->pRaftStore));
|
|
||||||
|
|
||||||
// tla+ candidate vars
|
|
||||||
cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted));
|
|
||||||
cJSON_AddItemToObject(pRoot, "pVotesRespond", votesRespond2Json(pSyncNode->pVotesRespond));
|
|
||||||
|
|
||||||
// tla+ leader vars
|
|
||||||
cJSON_AddItemToObject(pRoot, "pNextIndex", syncIndexMgr2Json(pSyncNode->pNextIndex));
|
|
||||||
cJSON_AddItemToObject(pRoot, "pMatchIndex", syncIndexMgr2Json(pSyncNode->pMatchIndex));
|
|
||||||
|
|
||||||
// tla+ log vars
|
|
||||||
cJSON_AddItemToObject(pRoot, "pLogStore", logStore2Json(pSyncNode->pLogStore));
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->commitIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
|
|
||||||
|
|
||||||
// timer ms init
|
|
||||||
cJSON_AddNumberToObject(pRoot, "pingBaseLine", pSyncNode->pingBaseLine);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "electBaseLine", pSyncNode->electBaseLine);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "hbBaseLine", pSyncNode->hbBaseLine);
|
|
||||||
|
|
||||||
// ping timer
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->pingTimerLogicClock);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->pingTimerLogicClockUser);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimerCB);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpPingTimerCB", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->pingTimerCounter);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf);
|
|
||||||
|
|
||||||
// elect timer
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->electTimerLogicClock);
|
|
||||||
cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimerCB);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpElectTimerCB", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->electTimerCounter);
|
|
||||||
cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf);
|
|
||||||
|
|
||||||
// heartbeat timer
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->heartbeatTimerLogicClock);
|
|
||||||
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->heartbeatTimerLogicClockUser);
|
|
||||||
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimerCB);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpHeartbeatTimerCB", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pSyncNode->heartbeatTimerCounter);
|
|
||||||
cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf);
|
|
||||||
|
|
||||||
// callback
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPing);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnPing", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPingReply);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnPingReply", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVote);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnRequestVote", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVoteReply);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnRequestVoteReply", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntries);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnAppendEntries", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntriesReply);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnAppendEntriesReply", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnTimeout);
|
|
||||||
cJSON_AddStringToObject(pRoot, "FpOnTimeout", u64buf);
|
|
||||||
|
|
||||||
// restoreFinish
|
|
||||||
cJSON_AddNumberToObject(pRoot, "restoreFinish", pSyncNode->restoreFinish);
|
|
||||||
|
|
||||||
// snapshot senders
|
|
||||||
cJSON* pSenders = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "senders", pSenders);
|
|
||||||
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
|
||||||
cJSON_AddItemToArray(pSenders, snapshotSender2Json((pSyncNode->senders)[i]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// snapshot receivers
|
|
||||||
cJSON* pReceivers = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "receiver", snapshotReceiver2Json(pSyncNode->pNewNodeReceiver));
|
|
||||||
|
|
||||||
// changing
|
|
||||||
cJSON_AddNumberToObject(pRoot, "changing", pSyncNode->changing);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SSyncNode", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* syncNode2Str(const SSyncNode* pSyncNode) {
|
|
||||||
cJSON* pJson = syncNode2Json(pSyncNode);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
|
|
||||||
int32_t len = 256;
|
|
||||||
char* s = (char*)taosMemoryMalloc(len);
|
|
||||||
|
|
||||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
|
||||||
if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
|
|
||||||
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
|
||||||
}
|
|
||||||
SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
|
||||||
SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore);
|
|
||||||
|
|
||||||
snprintf(s, len,
|
|
||||||
"vgId:%d, sync %s, tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64
|
|
||||||
", sby:%d, "
|
|
||||||
"r-num:%d, "
|
|
||||||
"lcfg:%" PRId64 ", chging:%d, rsto:%d",
|
|
||||||
pSyncNode->vgId, syncStr(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex,
|
|
||||||
logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum,
|
|
||||||
pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config) {
|
inline bool syncNodeInConfig(SSyncNode* pSyncNode, const SSyncCfg* config) {
|
||||||
bool b1 = false;
|
bool b1 = false;
|
||||||
bool b2 = false;
|
bool b2 = false;
|
||||||
|
@ -1716,7 +1389,7 @@ void syncNodeDoConfigChange(SSyncNode* pSyncNode, SSyncCfg* pNewConfig, SyncInde
|
||||||
char host[128];
|
char host[128];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr((pSyncNode->replicasId)[i].addr, host, sizeof(host), &port);
|
syncUtilU642Addr((pSyncNode->replicasId)[i].addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "snapshot sender reset for: %" PRIu64 ", newIndex:%d, %s:%d, %p",
|
sNTrace(pSyncNode, "snapshot sender reset for: %" PRId64 ", newIndex:%d, %s:%d, %p",
|
||||||
(pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]);
|
(pSyncNode->replicasId)[i].addr, i, host, port, oldSenders[j]);
|
||||||
|
|
||||||
(pSyncNode->senders)[i] = oldSenders[j];
|
(pSyncNode->senders)[i] = oldSenders[j];
|
||||||
|
@ -1785,7 +1458,7 @@ void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term) {
|
||||||
if (term > pSyncNode->pRaftStore->currentTerm) {
|
if (term > pSyncNode->pRaftStore->currentTerm) {
|
||||||
raftStoreSetTerm(pSyncNode->pRaftStore, term);
|
raftStoreSetTerm(pSyncNode->pRaftStore, term);
|
||||||
char tmpBuf[64];
|
char tmpBuf[64];
|
||||||
snprintf(tmpBuf, sizeof(tmpBuf), "update term to %" PRIu64, term);
|
snprintf(tmpBuf, sizeof(tmpBuf), "update term to %" PRId64, term);
|
||||||
syncNodeBecomeFollower(pSyncNode, tmpBuf);
|
syncNodeBecomeFollower(pSyncNode, tmpBuf);
|
||||||
raftStoreClearVote(pSyncNode->pRaftStore);
|
raftStoreClearVote(pSyncNode->pRaftStore);
|
||||||
}
|
}
|
||||||
|
@ -1799,20 +1472,20 @@ void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term) {
|
||||||
|
|
||||||
void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) {
|
void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm) {
|
||||||
if (pSyncNode->pRaftStore->currentTerm > newTerm) {
|
if (pSyncNode->pRaftStore->currentTerm > newTerm) {
|
||||||
sNTrace(pSyncNode, "step down, ignore, new-term:%" PRIu64 ", current-term:%" PRIu64, newTerm,
|
sNTrace(pSyncNode, "step down, ignore, new-term:%" PRId64 ", current-term:%" PRId64, newTerm,
|
||||||
pSyncNode->pRaftStore->currentTerm);
|
pSyncNode->pRaftStore->currentTerm);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
sNTrace(pSyncNode, "step down, new-term:%" PRIu64 ", current-term:%" PRIu64, newTerm,
|
sNTrace(pSyncNode, "step down, new-term:%" PRId64 ", current-term:%" PRId64, newTerm,
|
||||||
pSyncNode->pRaftStore->currentTerm);
|
pSyncNode->pRaftStore->currentTerm);
|
||||||
} while (0);
|
} while (0);
|
||||||
|
|
||||||
if (pSyncNode->pRaftStore->currentTerm < newTerm) {
|
if (pSyncNode->pRaftStore->currentTerm < newTerm) {
|
||||||
raftStoreSetTerm(pSyncNode->pRaftStore, newTerm);
|
raftStoreSetTerm(pSyncNode->pRaftStore, newTerm);
|
||||||
char tmpBuf[64];
|
char tmpBuf[64];
|
||||||
snprintf(tmpBuf, sizeof(tmpBuf), "step down, update term to %" PRIu64, newTerm);
|
snprintf(tmpBuf, sizeof(tmpBuf), "step down, update term to %" PRId64, newTerm);
|
||||||
syncNodeBecomeFollower(pSyncNode, tmpBuf);
|
syncNodeBecomeFollower(pSyncNode, tmpBuf);
|
||||||
raftStoreClearVote(pSyncNode->pRaftStore);
|
raftStoreClearVote(pSyncNode->pRaftStore);
|
||||||
|
|
||||||
|
@ -2131,7 +1804,7 @@ SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sNError(pSyncNode, "sync node get pre term error, index:%" PRId64 ", snap-index:%" PRId64 ", snap-term:%" PRIu64,
|
sNError(pSyncNode, "sync node get pre term error, index:%" PRId64 ", snap-index:%" PRId64 ", snap-term:%" PRId64,
|
||||||
index, snapshot.lastApplyIndex, snapshot.lastApplyTerm);
|
index, snapshot.lastApplyIndex, snapshot.lastApplyTerm);
|
||||||
return SYNC_TERM_INVALID;
|
return SYNC_TERM_INVALID;
|
||||||
}
|
}
|
||||||
|
@ -2143,8 +1816,6 @@ int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------ local funciton ---------
|
|
||||||
// enqueue message ----
|
|
||||||
static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
||||||
SSyncNode* pSyncNode = (SSyncNode*)param;
|
SSyncNode* pSyncNode = (SSyncNode*)param;
|
||||||
if (atomic_load_64(&pSyncNode->pingTimerLogicClockUser) <= atomic_load_64(&pSyncNode->pingTimerLogicClock)) {
|
if (atomic_load_64(&pSyncNode->pingTimerLogicClockUser) <= atomic_load_64(&pSyncNode->pingTimerLogicClock)) {
|
||||||
|
@ -2152,7 +1823,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
||||||
pSyncNode->pingTimerMS, pSyncNode->vgId, pSyncNode);
|
pSyncNode->pingTimerMS, pSyncNode->vgId, pSyncNode);
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||||
syncRpcMsgLog2((char*)"==syncNodeEqPingTimer==", &rpcMsg);
|
sNTrace(pSyncNode, "enqueue ping timer");
|
||||||
if (pSyncNode->syncEqMsg != NULL) {
|
if (pSyncNode->syncEqMsg != NULL) {
|
||||||
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
@ -2174,7 +1845,7 @@ static void syncNodeEqPingTimer(void* param, void* tmrId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sTrace("==syncNodeEqPingTimer== pingTimerLogicClock:%" PRIu64 ", pingTimerLogicClockUser:%" PRIu64,
|
sTrace("==syncNodeEqPingTimer== pingTimerLogicClock:%" PRId64 ", pingTimerLogicClockUser:%" PRId64,
|
||||||
pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser);
|
pSyncNode->pingTimerLogicClock, pSyncNode->pingTimerLogicClockUser);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2196,7 +1867,7 @@ static void syncNodeEqElectTimer(void* param, void* tmrId) {
|
||||||
taosMemoryFree(pElectTimer);
|
taosMemoryFree(pElectTimer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
sNTrace(pSyncNode, "eq elect timer lc:%" PRIu64, pSyncMsg->logicClock);
|
sNTrace(pSyncNode, "eq elect timer lc:%" PRId64, pSyncMsg->logicClock);
|
||||||
} else {
|
} else {
|
||||||
sTrace("syncNodeEqElectTimer syncEqMsg is NULL");
|
sTrace("syncNodeEqElectTimer syncEqMsg is NULL");
|
||||||
}
|
}
|
||||||
|
@ -2228,7 +1899,7 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
|
||||||
pSyncNode->heartbeatTimerMS, pSyncNode->vgId, pSyncNode);
|
pSyncNode->heartbeatTimerMS, pSyncNode->vgId, pSyncNode);
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
syncTimeout2RpcMsg(pSyncMsg, &rpcMsg);
|
||||||
syncRpcMsgLog2((char*)"==syncNodeEqHeartbeatTimer==", &rpcMsg);
|
sNTrace(pSyncNode, "enqueue heartbeat timer");
|
||||||
if (pSyncNode->syncEqMsg != NULL) {
|
if (pSyncNode->syncEqMsg != NULL) {
|
||||||
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
int32_t code = pSyncNode->syncEqMsg(pSyncNode->msgcb, &rpcMsg);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
@ -2249,7 +1920,7 @@ static void syncNodeEqHeartbeatTimer(void* param, void* tmrId) {
|
||||||
sError("sync env is stop, syncNodeEqHeartbeatTimer");
|
sError("sync env is stop, syncNodeEqHeartbeatTimer");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%" PRIu64 ", heartbeatTimerLogicClockUser:%" PRIu64
|
sTrace("==syncNodeEqHeartbeatTimer== heartbeatTimerLogicClock:%" PRId64 ", heartbeatTimerLogicClockUser:%" PRId64
|
||||||
"",
|
"",
|
||||||
pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser);
|
pSyncNode->heartbeatTimerLogicClock, pSyncNode->heartbeatTimerLogicClockUser);
|
||||||
}
|
}
|
||||||
|
@ -2261,10 +1932,18 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
||||||
SSyncNode* pSyncNode = pData->pSyncNode;
|
SSyncNode* pSyncNode = pData->pSyncNode;
|
||||||
SSyncTimer* pSyncTimer = pData->pTimer;
|
SSyncTimer* pSyncTimer = pData->pTimer;
|
||||||
|
|
||||||
|
if (pSyncNode == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pSyncNode->pRaftStore == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// sNTrace(pSyncNode, "eq peer hb timer");
|
// sNTrace(pSyncNode, "eq peer hb timer");
|
||||||
|
|
||||||
int64_t timerLogicClock = atomic_load_64(&pSyncTimer->logicClock);
|
int64_t timerLogicClock = atomic_load_64(&pSyncTimer->logicClock);
|
||||||
|
@ -2311,40 +1990,34 @@ static void syncNodeEqPeerHeartbeatTimer(void* param, void* tmrId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sTrace("==syncNodeEqPeerHeartbeatTimer== timerLogicClock:%" PRIu64 ", msgLogicClock:%" PRIu64 "", timerLogicClock,
|
sTrace("==syncNodeEqPeerHeartbeatTimer== timerLogicClock:%" PRId64 ", msgLogicClock:%" PRId64 "", timerLogicClock,
|
||||||
msgLogicClock);
|
msgLogicClock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t syncNodeEqNoop(SSyncNode* ths) {
|
static int32_t syncNodeEqNoop(SSyncNode* pNode) {
|
||||||
int32_t ret = 0;
|
if (pNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
ASSERT(ths->state == TAOS_SYNC_STATE_LEADER);
|
terrno = TSDB_CODE_SYN_NOT_LEADER;
|
||||||
|
return -1;
|
||||||
SyncIndex index = ths->pLogStore->syncLogWriteIndex(ths->pLogStore);
|
|
||||||
SyncTerm term = ths->pRaftStore->currentTerm;
|
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, ths->vgId);
|
|
||||||
ASSERT(pEntry != NULL);
|
|
||||||
|
|
||||||
uint32_t entryLen;
|
|
||||||
char* serialized = syncEntrySerialize(pEntry, &entryLen);
|
|
||||||
SyncClientRequest* pSyncMsg = syncClientRequestAlloc(entryLen);
|
|
||||||
ASSERT(pSyncMsg->dataLen == entryLen);
|
|
||||||
memcpy(pSyncMsg->data, serialized, entryLen);
|
|
||||||
|
|
||||||
SRpcMsg rpcMsg = {0};
|
|
||||||
syncClientRequest2RpcMsg(pSyncMsg, &rpcMsg);
|
|
||||||
if (ths->syncEqMsg != NULL) {
|
|
||||||
ths->syncEqMsg(ths->msgcb, &rpcMsg);
|
|
||||||
} else {
|
|
||||||
sTrace("syncNodeEqNoop pSyncNode->syncEqMsg is NULL");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
syncEntryDestory(pEntry);
|
SyncIndex index = pNode->pLogStore->syncLogWriteIndex(pNode->pLogStore);
|
||||||
taosMemoryFree(serialized);
|
SyncTerm term = pNode->pRaftStore->currentTerm;
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
SSyncRaftEntry* pEntry = syncEntryBuildNoop(term, index, pNode->vgId);
|
||||||
|
if (pEntry == NULL) return -1;
|
||||||
|
|
||||||
return ret;
|
SRpcMsg rpcMsg = {0};
|
||||||
|
int32_t code = syncClientRequestBuildFromNoopEntry(&rpcMsg, pEntry, pNode->vgId);
|
||||||
|
syncEntryDestory(pEntry);
|
||||||
|
|
||||||
|
sNTrace(pNode, "propose msg, type:noop");
|
||||||
|
code = (*pNode->syncEqMsg)(pNode->msgcb, &rpcMsg);
|
||||||
|
if (code != 0) {
|
||||||
|
sNError(pNode, "failed to propose noop msg while enqueue since %s", terrstr());
|
||||||
|
}
|
||||||
|
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deleteCacheEntry(const void* key, size_t keyLen, void* value) { taosMemoryFree(value); }
|
static void deleteCacheEntry(const void* key, size_t keyLen, void* value) { taosMemoryFree(value); }
|
||||||
|
@ -2447,7 +2120,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
||||||
sError("vgId:%d, sync enqueue fc-commit msg error, code:%d", ths->vgId, code);
|
sError("vgId:%d, sync enqueue fc-commit msg error, code:%d", ths->vgId, code);
|
||||||
rpcFreeCont(rpcMsgLocalCmd.pCont);
|
rpcFreeCont(rpcMsgLocalCmd.pCont);
|
||||||
} else {
|
} else {
|
||||||
sTrace("vgId:%d, sync enqueue fc-commit msg, fc-index: %" PRIu64, ths->vgId, pSyncMsg->fcIndex);
|
sTrace("vgId:%d, sync enqueue fc-commit msg, fc-index:%" PRId64, ths->vgId, pSyncMsg->fcIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2468,7 +2141,7 @@ int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg) {
|
||||||
sError("vgId:%d, sync enqueue step-down msg error, code:%d", ths->vgId, code);
|
sError("vgId:%d, sync enqueue step-down msg error, code:%d", ths->vgId, code);
|
||||||
rpcFreeCont(rpcMsgLocalCmd.pCont);
|
rpcFreeCont(rpcMsgLocalCmd.pCont);
|
||||||
} else {
|
} else {
|
||||||
sTrace("vgId:%d, sync enqueue step-down msg, new-term: %" PRIu64, ths->vgId, pSyncMsg->sdNewTerm);
|
sTrace("vgId:%d, sync enqueue step-down msg, new-term: %" PRId64, ths->vgId, pSyncMsg->sdNewTerm);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2525,7 +2198,7 @@ int32_t syncNodeOnLocalCmd(SSyncNode* ths, SyncLocalCmd* pMsg) {
|
||||||
// leaderVars, commitIndex>>
|
// leaderVars, commitIndex>>
|
||||||
//
|
//
|
||||||
|
|
||||||
int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex) {
|
int32_t syncNodeOnClientRequest(SSyncNode* ths, SRpcMsg* pMsg, SyncIndex* pRetIndex) {
|
||||||
sNTrace(ths, "on client request");
|
sNTrace(ths, "on client request");
|
||||||
|
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
@ -2533,8 +2206,13 @@ 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(pMsg, term, index);
|
SSyncRaftEntry* pEntry;
|
||||||
ASSERT(pEntry != NULL);
|
|
||||||
|
if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||||
|
pEntry = syncEntryBuildFromClientRequest(pMsg->pCont, term, index);
|
||||||
|
} else {
|
||||||
|
pEntry = syncEntryBuildFromRpcMsg(pMsg, term, index);
|
||||||
|
}
|
||||||
|
|
||||||
LRUHandle* h = NULL;
|
LRUHandle* h = NULL;
|
||||||
syncCacheEntry(ths->pLogStore, pEntry, &h);
|
syncCacheEntry(ths->pLogStore, pEntry, &h);
|
||||||
|
@ -2549,11 +2227,30 @@ int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncInd
|
||||||
} else {
|
} else {
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// del resp mgr, call FpCommitCb
|
// del resp mgr, call FpCommitCb
|
||||||
ASSERT(0);
|
SFsmCbMeta cbMeta = {
|
||||||
|
.index = pEntry->index,
|
||||||
|
.lastConfigIndex = SYNC_INDEX_INVALID,
|
||||||
|
.isWeak = pEntry->isWeak,
|
||||||
|
.code = -1,
|
||||||
|
.state = ths->state,
|
||||||
|
.seqNum = pEntry->seqNum,
|
||||||
|
.term = pEntry->term,
|
||||||
|
.currentTerm = ths->pRaftStore->currentTerm,
|
||||||
|
.flag = 0,
|
||||||
|
};
|
||||||
|
ths->pFsm->FpCommitCb(ths->pFsm, pMsg, &cbMeta);
|
||||||
|
|
||||||
|
if (h) {
|
||||||
|
taosLRUCacheRelease(ths->pLogStore->pCache, h, false);
|
||||||
|
} else {
|
||||||
|
syncEntryDestory(pEntry);
|
||||||
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2615,7 +2312,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pEntry->term < ths->pRaftStore->currentTerm) {
|
if (pEntry->term < ths->pRaftStore->currentTerm) {
|
||||||
sNTrace(ths, "little term:%" PRIu64 ", can not do leader transfer", pEntry->term);
|
sNTrace(ths, "little term:%" PRId64 ", can not do leader transfer", pEntry->term);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2645,7 +2342,7 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
|
||||||
int32_t ret = syncNodeRestartElectTimer(ths, electMS);
|
int32_t ret = syncNodeRestartElectTimer(ths, electMS);
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
sNTrace(ths, "maybe leader transfer to %s:%d %" PRIu64, pSyncLeaderTransfer->newNodeInfo.nodeFqdn,
|
sNTrace(ths, "maybe leader transfer to %s:%d %" PRId64, pSyncLeaderTransfer->newNodeInfo.nodeFqdn,
|
||||||
pSyncLeaderTransfer->newNodeInfo.nodePort, pSyncLeaderTransfer->newLeaderId.addr);
|
pSyncLeaderTransfer->newNodeInfo.nodePort, pSyncLeaderTransfer->newLeaderId.addr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2733,7 +2430,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg = {0};
|
||||||
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
syncEntry2OriginalRpc(pEntry, &rpcMsg);
|
||||||
|
|
||||||
// user commit
|
// user commit
|
||||||
|
@ -2759,7 +2456,7 @@ int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endInde
|
||||||
.flag = flag,
|
.flag = flag,
|
||||||
};
|
};
|
||||||
|
|
||||||
syncGetAndDelRespRpc(ths, cbMeta.seqNum, &rpcMsg.info);
|
syncRespMgrGetAndDel(ths->pSyncRespMgr, cbMeta.seqNum, &rpcMsg.info);
|
||||||
ths->pFsm->FpCommitCb(ths->pFsm, &rpcMsg, &cbMeta);
|
ths->pFsm->FpCommitCb(ths->pFsm, &rpcMsg, &cbMeta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2893,7 +2590,7 @@ const char* syncTimerTypeStr(enum ESyncTimeoutType timerType) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s) {
|
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s) {
|
||||||
sNTrace(pSyncNode, "recv sync-timer {type:%s, lc:%" PRIu64 ", ms:%d, data:%p}, %s",
|
sNTrace(pSyncNode, "recv sync-timer {type:%s, lc:%" PRId64 ", ms:%d, data:%p}, %s",
|
||||||
syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->data, s);
|
syncTimerTypeStr(pMsg->timeoutType), pMsg->logicClock, pMsg->timerMS, pMsg->data, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2901,7 +2598,7 @@ void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, c
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "send sync-request-vote to %s:%d {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s",
|
sNTrace(pSyncNode, "send sync-request-vote to %s:%d {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s",
|
||||||
host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2910,7 +2607,7 @@ void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, c
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "recv sync-request-vote from %s:%d, {term:%" PRIu64 ", lindex:%" PRId64 ", lterm:%" PRIu64 "}, %s",
|
sNTrace(pSyncNode, "recv sync-request-vote from %s:%d, {term:%" PRId64 ", lindex:%" PRId64 ", lterm:%" PRId64 "}, %s",
|
||||||
host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
host, port, pMsg->term, pMsg->lastLogIndex, pMsg->lastLogTerm, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2918,7 +2615,7 @@ void syncLogSendRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteRepl
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "send sync-request-vote-reply to %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, port, pMsg->term,
|
sNTrace(pSyncNode, "send sync-request-vote-reply to %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term,
|
||||||
pMsg->voteGranted, s);
|
pMsg->voteGranted, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2926,7 +2623,7 @@ void syncLogRecvRequestVoteReply(SSyncNode* pSyncNode, const SyncRequestVoteRepl
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "recv sync-request-vote-reply from %s:%d {term:%" PRIu64 ", grant:%d}, %s", host, port, pMsg->term,
|
sNTrace(pSyncNode, "recv sync-request-vote-reply from %s:%d {term:%" PRId64 ", grant:%d}, %s", host, port, pMsg->term,
|
||||||
pMsg->voteGranted, s);
|
pMsg->voteGranted, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2935,8 +2632,8 @@ void syncLogSendAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMs
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"send sync-append-entries to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64
|
"send sync-append-entries to %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||||
", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d}, %s",
|
", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d}, %s",
|
||||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
||||||
pMsg->dataLen, s);
|
pMsg->dataLen, s);
|
||||||
}
|
}
|
||||||
|
@ -2947,8 +2644,8 @@ void syncLogRecvAppendEntries(SSyncNode* pSyncNode, const SyncAppendEntries* pMs
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"recv sync-append-entries from %s:%d {term:%" PRIu64 ", pre-index:%" PRIu64 ", pre-term:%" PRIu64
|
"recv sync-append-entries from %s:%d {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||||
", cmt:%" PRIu64 ", pterm:%" PRIu64 ", datalen:%d}, %s",
|
", cmt:%" PRId64 ", pterm:%" PRId64 ", datalen:%d}, %s",
|
||||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm,
|
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->commitIndex, pMsg->privateTerm,
|
||||||
pMsg->dataLen, s);
|
pMsg->dataLen, s);
|
||||||
}
|
}
|
||||||
|
@ -2959,8 +2656,8 @@ void syncLogSendAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"send sync-append-entries-batch to %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64
|
"send sync-append-entries-batch to %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||||
", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s",
|
", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s",
|
||||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
||||||
pMsg->dataLen, pMsg->dataCount, s);
|
pMsg->dataLen, pMsg->dataCount, s);
|
||||||
}
|
}
|
||||||
|
@ -2971,8 +2668,8 @@ void syncLogRecvAppendEntriesBatch(SSyncNode* pSyncNode, const SyncAppendEntries
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"recv sync-append-entries-batch from %s:%d, {term:%" PRIu64 ", pre-index:%" PRId64 ", pre-term:%" PRIu64
|
"recv sync-append-entries-batch from %s:%d, {term:%" PRId64 ", pre-index:%" PRId64 ", pre-term:%" PRId64
|
||||||
", pterm:%" PRIu64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s",
|
", pterm:%" PRId64 ", cmt:%" PRId64 ", datalen:%d, count:%d}, %s",
|
||||||
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
host, port, pMsg->term, pMsg->prevLogIndex, pMsg->prevLogTerm, pMsg->privateTerm, pMsg->commitIndex,
|
||||||
pMsg->dataLen, pMsg->dataCount, s);
|
pMsg->dataLen, pMsg->dataCount, s);
|
||||||
}
|
}
|
||||||
|
@ -2983,7 +2680,7 @@ void syncLogSendAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"send sync-append-entries-reply to %s:%d, {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64
|
"send sync-append-entries-reply to %s:%d, {term:%" PRId64 ", pterm:%" PRId64 ", success:%d, match:%" PRId64
|
||||||
"}, %s",
|
"}, %s",
|
||||||
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
|
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
|
||||||
}
|
}
|
||||||
|
@ -2994,7 +2691,7 @@ void syncLogRecvAppendEntriesReply(SSyncNode* pSyncNode, const SyncAppendEntries
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"recv sync-append-entries-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 ", success:%d, match:%" PRId64
|
"recv sync-append-entries-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 ", success:%d, match:%" PRId64
|
||||||
"}, %s",
|
"}, %s",
|
||||||
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
|
host, port, pMsg->term, pMsg->privateTerm, pMsg->success, pMsg->matchIndex, s);
|
||||||
}
|
}
|
||||||
|
@ -3005,7 +2702,7 @@ void syncLogSendHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"send sync-heartbeat to %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64
|
"send sync-heartbeat to %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRId64
|
||||||
"}, %s",
|
"}, %s",
|
||||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
|
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
|
||||||
}
|
}
|
||||||
|
@ -3016,7 +2713,7 @@ void syncLogRecvHeartbeat(SSyncNode* pSyncNode, const SyncHeartbeat* pMsg, const
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
sNTrace(pSyncNode,
|
sNTrace(pSyncNode,
|
||||||
"recv sync-heartbeat from %s:%d {term:%" PRIu64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRIu64
|
"recv sync-heartbeat from %s:%d {term:%" PRId64 ", cmt:%" PRId64 ", min-match:%" PRId64 ", pterm:%" PRId64
|
||||||
"}, %s",
|
"}, %s",
|
||||||
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
|
host, port, pMsg->term, pMsg->commitIndex, pMsg->minMatchIndex, pMsg->privateTerm, s);
|
||||||
}
|
}
|
||||||
|
@ -3026,7 +2723,7 @@ void syncLogSendHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* p
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
sNTrace(pSyncNode, "send sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", host, port,
|
sNTrace(pSyncNode, "send sync-heartbeat-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 "}, %s", host, port,
|
||||||
pMsg->term, pMsg->privateTerm, s);
|
pMsg->term, pMsg->privateTerm, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3034,34 +2731,34 @@ void syncLogRecvHeartbeatReply(SSyncNode* pSyncNode, const SyncHeartbeatReply* p
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "recv sync-heartbeat-reply from %s:%d {term:%" PRIu64 ", pterm:%" PRIu64 "}, %s", host, port,
|
sNTrace(pSyncNode, "recv sync-heartbeat-reply from %s:%d {term:%" PRId64 ", pterm:%" PRId64 "}, %s", host, port,
|
||||||
pMsg->term, pMsg->privateTerm, s);
|
pMsg->term, pMsg->privateTerm, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
|
void syncLogRecvLocalCmd(SSyncNode* pSyncNode, const SyncLocalCmd* pMsg, const char* s) {
|
||||||
sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRIu64 "}, %s", pMsg->cmd,
|
sNTrace(pSyncNode, "recv sync-local-cmd {cmd:%d-%s, sd-new-term:%" PRId64 ", fc-index:%" PRId64 "}, %s", pMsg->cmd,
|
||||||
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, s);
|
syncLocalCmdGetStr(pMsg->cmd), pMsg->sdNewTerm, pMsg->fcIndex, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
void syncLogSendSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "send sync-pre-snapshot to %s:%d {term:%" PRIu64 "}, %s", host, port, pMsg->term, s);
|
sNTrace(pSyncNode, "send sync-pre-snapshot to %s:%d {term:%" PRId64 "}, %s", host, port, pMsg->term, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
void syncLogRecvSyncPreSnapshot(SSyncNode* pSyncNode, const SyncPreSnapshot* pMsg, const char* s) {
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "recv sync-pre-snapshot from %s:%d {term:%" PRIu64 "}, %s", host, port, pMsg->term, s);
|
sNTrace(pSyncNode, "recv sync-pre-snapshot from %s:%d {term:%" PRId64 "}, %s", host, port, pMsg->term, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
|
void syncLogSendSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshotReply* pMsg, const char* s) {
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->destId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "send sync-pre-snapshot-reply to %s:%d {term:%" PRIu64 ", snap-start:%" PRId64 "}, %s", host, port,
|
sNTrace(pSyncNode, "send sync-pre-snapshot-reply to %s:%d {term:%" PRId64 ", snap-start:%" PRId64 "}, %s", host, port,
|
||||||
pMsg->term, pMsg->snapStart, s);
|
pMsg->term, pMsg->snapStart, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3069,7 +2766,7 @@ void syncLogRecvSyncPreSnapshotReply(SSyncNode* pSyncNode, const SyncPreSnapshot
|
||||||
char host[64];
|
char host[64];
|
||||||
uint16_t port;
|
uint16_t port;
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
||||||
sNTrace(pSyncNode, "recv sync-pre-snapshot-reply from %s:%d {term:%" PRIu64 ", snap-start:%" PRId64 "}, %s", host,
|
sNTrace(pSyncNode, "recv sync-pre-snapshot-reply from %s:%d {term:%" PRId64 ", snap-start:%" PRId64 "}, %s", host,
|
||||||
port, pMsg->term, pMsg->snapStart, s);
|
port, pMsg->term, pMsg->snapStart, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,146 +19,6 @@
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "tcoding.h"
|
#include "tcoding.h"
|
||||||
|
|
||||||
// ---------------------------------------------
|
|
||||||
cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) {
|
|
||||||
cJSON* pRoot;
|
|
||||||
|
|
||||||
// in compiler optimization, switch case = if else constants
|
|
||||||
if (pRpcMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
|
||||||
SyncTimeout* pSyncMsg = syncTimeoutDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncTimeout2Json(pSyncMsg);
|
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_PING) {
|
|
||||||
SyncPing* pSyncMsg = syncPingDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncPing2Json(pSyncMsg);
|
|
||||||
syncPingDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
|
||||||
SyncPingReply* pSyncMsg = syncPingReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncPingReply2Json(pSyncMsg);
|
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
|
||||||
SyncClientRequest* pSyncMsg = syncClientRequestDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncClientRequest2Json(pSyncMsg);
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_REPLY) {
|
|
||||||
pRoot = syncRpcUnknownMsg2Json();
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
|
||||||
SyncRequestVote* pSyncMsg = syncRequestVoteDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncRequestVote2Json(pSyncMsg);
|
|
||||||
syncRequestVoteDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
|
||||||
SyncRequestVoteReply* pSyncMsg = syncRequestVoteReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncRequestVoteReply2Json(pSyncMsg);
|
|
||||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
|
||||||
SyncAppendEntries* pSyncMsg = syncAppendEntriesDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncAppendEntries2Json(pSyncMsg);
|
|
||||||
syncAppendEntriesDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
|
||||||
SyncAppendEntriesReply* pSyncMsg = syncAppendEntriesReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncAppendEntriesReply2Json(pSyncMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
|
||||||
SyncSnapshotSend* pSyncMsg = syncSnapshotSendDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncSnapshotSend2Json(pSyncMsg);
|
|
||||||
syncSnapshotSendDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
|
||||||
SyncSnapshotRsp* pSyncMsg = syncSnapshotRspDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncSnapshotRsp2Json(pSyncMsg);
|
|
||||||
syncSnapshotRspDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_LEADER_TRANSFER) {
|
|
||||||
SyncLeaderTransfer* pSyncMsg = syncLeaderTransferDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
pRoot = syncLeaderTransfer2Json(pSyncMsg);
|
|
||||||
syncLeaderTransferDestroy(pSyncMsg);
|
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_COMMON_RESPONSE) {
|
|
||||||
pRoot = cJSON_CreateObject();
|
|
||||||
char* s;
|
|
||||||
s = syncUtilPrintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pCont", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
s = syncUtilPrintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pCont2", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
pRoot = cJSON_CreateObject();
|
|
||||||
char* s;
|
|
||||||
s = syncUtilPrintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pCont", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
s = syncUtilPrintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pCont2", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pRpcMsg->msgType);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "contLen", pRpcMsg->contLen);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "code", pRpcMsg->code);
|
|
||||||
// cJSON_AddNumberToObject(pRoot, "persist", pRpcMsg->persist);
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "RpcMsg", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* syncRpcUnknownMsg2Json() {
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", TDMT_SYNC_UNKNOWN);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data", "unknown message");
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SyncUnknown", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* syncRpcMsg2Str(SRpcMsg* pRpcMsg) {
|
|
||||||
cJSON* pJson = syncRpcMsg2Json(pRpcMsg);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for debug ----------------------
|
|
||||||
void syncRpcMsgPrint(SRpcMsg* pMsg) {
|
|
||||||
char* serialized = syncRpcMsg2Str(pMsg);
|
|
||||||
printf("syncRpcMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) {
|
|
||||||
char* serialized = syncRpcMsg2Str(pMsg);
|
|
||||||
printf("syncRpcMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncRpcMsgLog(SRpcMsg* pMsg) {
|
|
||||||
char* serialized = syncRpcMsg2Str(pMsg);
|
|
||||||
sTrace("syncRpcMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = syncRpcMsg2Str(pMsg);
|
|
||||||
sTrace("syncRpcMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- message process SyncTimeout----
|
// ---- message process SyncTimeout----
|
||||||
SyncTimeout* syncTimeoutBuild() {
|
SyncTimeout* syncTimeoutBuild() {
|
||||||
uint32_t bytes = sizeof(SyncTimeout);
|
uint32_t bytes = sizeof(SyncTimeout);
|
||||||
|
@ -840,69 +700,49 @@ SyncClientRequest* syncClientRequestAlloc(uint32_t dataLen) {
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 1. original SRpcMsg => SyncClientRequest, add seqNum, isWeak
|
int32_t syncClientRequestBuildFromRpcMsg(SRpcMsg* pClientRequestRpcMsg, const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum,
|
||||||
SyncClientRequest* syncClientRequestBuild(const SRpcMsg* pOriginalRpcMsg, uint64_t seqNum, bool isWeak, int32_t vgId) {
|
bool isWeak, int32_t vgId) {
|
||||||
SyncClientRequest* pMsg = syncClientRequestAlloc(pOriginalRpcMsg->contLen);
|
int32_t bytes = sizeof(SyncClientRequest) + pOriginalRpcMsg->contLen;
|
||||||
pMsg->vgId = vgId;
|
pClientRequestRpcMsg->pCont = rpcMallocCont(bytes);
|
||||||
pMsg->originalRpcType = pOriginalRpcMsg->msgType;
|
if (pClientRequestRpcMsg->pCont == NULL) {
|
||||||
pMsg->seqNum = seqNum;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
pMsg->isWeak = isWeak;
|
return -1;
|
||||||
memcpy(pMsg->data, pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen);
|
|
||||||
return pMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncClientRequestDestroy(SyncClientRequest* pMsg) {
|
SyncClientRequest* pClientRequest = pClientRequestRpcMsg->pCont;
|
||||||
if (pMsg != NULL) {
|
pClientRequest->bytes = bytes;
|
||||||
taosMemoryFree(pMsg);
|
pClientRequest->vgId = vgId;
|
||||||
}
|
pClientRequest->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
||||||
|
pClientRequest->originalRpcType = pOriginalRpcMsg->msgType;
|
||||||
|
pClientRequest->seqNum = seqNum;
|
||||||
|
pClientRequest->isWeak = isWeak;
|
||||||
|
pClientRequest->dataLen = pOriginalRpcMsg->contLen;
|
||||||
|
memcpy(pClientRequest->data, (char*)pOriginalRpcMsg->pCont, pOriginalRpcMsg->contLen);
|
||||||
|
|
||||||
|
pClientRequestRpcMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
||||||
|
pClientRequestRpcMsg->contLen = bytes;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncClientRequestSerialize(const SyncClientRequest* pMsg, char* buf, uint32_t bufLen) {
|
int32_t syncClientRequestBuildFromNoopEntry(SRpcMsg* pClientRequestRpcMsg, const SSyncRaftEntry* pEntry, int32_t vgId) {
|
||||||
ASSERT(pMsg->bytes <= bufLen);
|
int32_t bytes = sizeof(SyncClientRequest) + pEntry->bytes;
|
||||||
memcpy(buf, pMsg, pMsg->bytes);
|
pClientRequestRpcMsg->pCont = rpcMallocCont(bytes);
|
||||||
|
if (pClientRequestRpcMsg->pCont == NULL) {
|
||||||
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncClientRequestDeserialize(const char* buf, uint32_t len, SyncClientRequest* pMsg) {
|
SyncClientRequest* pClientRequest = pClientRequestRpcMsg->pCont;
|
||||||
memcpy(pMsg, buf, len);
|
pClientRequest->bytes = bytes;
|
||||||
ASSERT(len == pMsg->bytes);
|
pClientRequest->vgId = vgId;
|
||||||
}
|
pClientRequest->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
||||||
|
pClientRequest->originalRpcType = TDMT_SYNC_NOOP;
|
||||||
|
pClientRequest->dataLen = pEntry->bytes;
|
||||||
|
memcpy(pClientRequest->data, (char*)pEntry, pEntry->bytes);
|
||||||
|
|
||||||
char* syncClientRequestSerialize2(const SyncClientRequest* pMsg, uint32_t* len) {
|
pClientRequestRpcMsg->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
||||||
char* buf = taosMemoryMalloc(pMsg->bytes);
|
pClientRequestRpcMsg->contLen = bytes;
|
||||||
ASSERT(buf != NULL);
|
return 0;
|
||||||
syncClientRequestSerialize(pMsg, buf, pMsg->bytes);
|
|
||||||
if (len != NULL) {
|
|
||||||
*len = pMsg->bytes;
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncClientRequest* syncClientRequestDeserialize2(const char* buf, uint32_t len) {
|
|
||||||
uint32_t bytes = *((uint32_t*)buf);
|
|
||||||
SyncClientRequest* pMsg = taosMemoryMalloc(bytes);
|
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
syncClientRequestDeserialize(buf, len, pMsg);
|
|
||||||
ASSERT(len == pMsg->bytes);
|
|
||||||
return pMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
// step 2. SyncClientRequest => RpcMsg, to queue
|
|
||||||
void syncClientRequest2RpcMsg(const SyncClientRequest* pMsg, SRpcMsg* pRpcMsg) {
|
|
||||||
pRpcMsg->msgType = pMsg->msgType;
|
|
||||||
pRpcMsg->contLen = pMsg->bytes;
|
|
||||||
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
|
||||||
syncClientRequestSerialize(pMsg, pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncClientRequestFromRpcMsg(const SRpcMsg* pRpcMsg, SyncClientRequest* pMsg) {
|
|
||||||
syncClientRequestDeserialize(pRpcMsg->pCont, pRpcMsg->contLen, pMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// step 3. RpcMsg => SyncClientRequest, from queue
|
|
||||||
SyncClientRequest* syncClientRequestFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
|
||||||
SyncClientRequest* pMsg = syncClientRequestDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
return pMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) {
|
cJSON* syncClientRequest2Json(const SyncClientRequest* pMsg) {
|
||||||
|
@ -940,35 +780,6 @@ char* syncClientRequest2Str(const SyncClientRequest* pMsg) {
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
// for debug ----------------------
|
|
||||||
void syncClientRequestPrint(const SyncClientRequest* pMsg) {
|
|
||||||
char* serialized = syncClientRequest2Str(pMsg);
|
|
||||||
printf("syncClientRequestPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) {
|
|
||||||
char* serialized = syncClientRequest2Str(pMsg);
|
|
||||||
printf("syncClientRequestPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncClientRequestLog(const SyncClientRequest* pMsg) {
|
|
||||||
char* serialized = syncClientRequest2Str(pMsg);
|
|
||||||
sTrace("syncClientRequestLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = syncClientRequest2Str(pMsg);
|
|
||||||
sTrace("syncClientRequestLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- message process SyncClientRequestBatch----
|
// ---- message process SyncClientRequestBatch----
|
||||||
|
|
||||||
// block1:
|
// block1:
|
||||||
|
@ -1059,86 +870,6 @@ SyncClientRequestBatch* syncClientRequestBatchFromRpcMsg(const SRpcMsg* pRpcMsg)
|
||||||
return pSyncMsg;
|
return pSyncMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncClientRequestBatch2Json(const SyncClientRequestBatch* pMsg) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pMsg != NULL) {
|
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataCount", pMsg->dataCount);
|
|
||||||
|
|
||||||
SRaftMeta* metaArr = syncClientRequestBatchMetaArr(pMsg);
|
|
||||||
SRpcMsg* msgArr = syncClientRequestBatchRpcMsgArr(pMsg);
|
|
||||||
|
|
||||||
cJSON* pMetaArr = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "metaArr", pMetaArr);
|
|
||||||
for (int i = 0; i < pMsg->dataCount; ++i) {
|
|
||||||
cJSON* pMeta = cJSON_CreateObject();
|
|
||||||
cJSON_AddNumberToObject(pMeta, "seqNum", metaArr[i].seqNum);
|
|
||||||
cJSON_AddNumberToObject(pMeta, "isWeak", metaArr[i].isWeak);
|
|
||||||
cJSON_AddItemToArray(pMetaArr, pMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pMsgArr = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "msgArr", pMsgArr);
|
|
||||||
for (int i = 0; i < pMsg->dataCount; ++i) {
|
|
||||||
cJSON* pRpcMsgJson = syncRpcMsg2Json(&msgArr[i]);
|
|
||||||
cJSON_AddItemToArray(pMsgArr, pRpcMsgJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* s;
|
|
||||||
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SyncClientRequestBatch", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* syncClientRequestBatch2Str(const SyncClientRequestBatch* pMsg) {
|
|
||||||
cJSON* pJson = syncClientRequestBatch2Json(pMsg);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for debug ----------------------
|
|
||||||
void syncClientRequestBatchPrint(const SyncClientRequestBatch* pMsg) {
|
|
||||||
char* serialized = syncClientRequestBatch2Str(pMsg);
|
|
||||||
printf("syncClientRequestBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncClientRequestBatchPrint2(char* s, const SyncClientRequestBatch* pMsg) {
|
|
||||||
char* serialized = syncClientRequestBatch2Str(pMsg);
|
|
||||||
printf("syncClientRequestBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) {
|
|
||||||
char* serialized = syncClientRequestBatch2Str(pMsg);
|
|
||||||
sTrace("syncClientRequestBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = syncClientRequestBatch2Str(pMsg);
|
|
||||||
sLTrace("syncClientRequestBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- message process SyncRequestVote----
|
// ---- message process SyncRequestVote----
|
||||||
SyncRequestVote* syncRequestVoteBuild(int32_t vgId) {
|
SyncRequestVote* syncRequestVoteBuild(int32_t vgId) {
|
||||||
uint32_t bytes = sizeof(SyncRequestVote);
|
uint32_t bytes = sizeof(SyncRequestVote);
|
||||||
|
@ -1716,138 +1447,6 @@ SyncAppendEntriesBatch* syncAppendEntriesBatchFromRpcMsg2(const SRpcMsg* pRpcMsg
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pMsg != NULL) {
|
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
|
|
||||||
cJSON* pSrcId = cJSON_CreateObject();
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
|
|
||||||
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->srcId.addr;
|
|
||||||
cJSON* pTmp = pSrcId;
|
|
||||||
char host[128] = {0};
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
|
||||||
|
|
||||||
cJSON* pDestId = cJSON_CreateObject();
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
|
|
||||||
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->destId.addr;
|
|
||||||
cJSON* pTmp = pDestId;
|
|
||||||
char host[128] = {0};
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->prevLogIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "prevLogIndex", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->prevLogTerm);
|
|
||||||
cJSON_AddStringToObject(pRoot, "prevLogTerm", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
|
|
||||||
cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataCount", pMsg->dataCount);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
|
||||||
|
|
||||||
int32_t metaArrayLen = sizeof(SOffsetAndContLen) * pMsg->dataCount; // <offset, contLen>
|
|
||||||
int32_t entryArrayLen = pMsg->dataLen - metaArrayLen;
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "metaArrayLen", metaArrayLen);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "entryArrayLen", entryArrayLen);
|
|
||||||
|
|
||||||
SOffsetAndContLen* metaArr = (SOffsetAndContLen*)(pMsg->data);
|
|
||||||
|
|
||||||
cJSON* pMetaArr = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "metaArr", pMetaArr);
|
|
||||||
for (int i = 0; i < pMsg->dataCount; ++i) {
|
|
||||||
cJSON* pMeta = cJSON_CreateObject();
|
|
||||||
cJSON_AddNumberToObject(pMeta, "offset", metaArr[i].offset);
|
|
||||||
cJSON_AddNumberToObject(pMeta, "contLen", metaArr[i].contLen);
|
|
||||||
cJSON_AddItemToArray(pMetaArr, pMeta);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pEntryArr = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "entryArr", pEntryArr);
|
|
||||||
for (int i = 0; i < pMsg->dataCount; ++i) {
|
|
||||||
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)(pMsg->data + metaArr[i].offset);
|
|
||||||
cJSON* pEntryJson = syncEntry2Json(pEntry);
|
|
||||||
cJSON_AddItemToArray(pEntryArr, pEntryJson);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* s;
|
|
||||||
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SyncAppendEntriesBatch", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg) {
|
|
||||||
cJSON* pJson = syncAppendEntriesBatch2Json(pMsg);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for debug ----------------------
|
|
||||||
void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg) {
|
|
||||||
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
|
||||||
printf("syncAppendEntriesBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg) {
|
|
||||||
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
|
||||||
printf("syncAppendEntriesBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) {
|
|
||||||
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
|
||||||
sTrace("syncAppendEntriesBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
|
||||||
sLTrace("syncAppendEntriesBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---- message process SyncAppendEntriesReply----
|
// ---- message process SyncAppendEntriesReply----
|
||||||
SyncAppendEntriesReply* syncAppendEntriesReplyBuild(int32_t vgId) {
|
SyncAppendEntriesReply* syncAppendEntriesReplyBuild(int32_t vgId) {
|
||||||
uint32_t bytes = sizeof(SyncAppendEntriesReply);
|
uint32_t bytes = sizeof(SyncAppendEntriesReply);
|
||||||
|
@ -2827,118 +2426,6 @@ SyncSnapshotSend* syncSnapshotSendFromRpcMsg2(const SRpcMsg* pRpcMsg) {
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
|
|
||||||
char u64buf[128];
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pMsg != NULL) {
|
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
|
||||||
|
|
||||||
cJSON* pSrcId = cJSON_CreateObject();
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
|
|
||||||
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->srcId.addr;
|
|
||||||
cJSON* pTmp = pSrcId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
|
||||||
|
|
||||||
cJSON* pDestId = cJSON_CreateObject();
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
|
|
||||||
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
|
||||||
{
|
|
||||||
uint64_t u64 = pMsg->destId.addr;
|
|
||||||
cJSON* pTmp = pDestId;
|
|
||||||
char host[128];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
|
||||||
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
|
||||||
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
|
||||||
}
|
|
||||||
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
|
||||||
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
|
|
||||||
cJSON_AddStringToObject(pRoot, "startTime", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->beginIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "beginIndex", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "lastIndex", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastConfigIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "lastConfigIndex", u64buf);
|
|
||||||
cJSON_AddItemToObject(pRoot, "lastConfig", syncCfg2Json((SSyncCfg*)&(pMsg->lastConfig)));
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->lastTerm);
|
|
||||||
cJSON_AddStringToObject(pRoot, "lastTerm", u64buf);
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "seq", pMsg->seq);
|
|
||||||
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
|
||||||
char* s;
|
|
||||||
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SyncSnapshotSend", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* syncSnapshotSend2Str(const SyncSnapshotSend* pMsg) {
|
|
||||||
cJSON* pJson = syncSnapshotSend2Json(pMsg);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
// for debug ----------------------
|
|
||||||
void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg) {
|
|
||||||
char* serialized = syncSnapshotSend2Str(pMsg);
|
|
||||||
printf("syncSnapshotSendPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg) {
|
|
||||||
char* serialized = syncSnapshotSend2Str(pMsg);
|
|
||||||
printf("syncSnapshotSendPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncSnapshotSendLog(const SyncSnapshotSend* pMsg) {
|
|
||||||
char* serialized = syncSnapshotSend2Str(pMsg);
|
|
||||||
sTrace("syncSnapshotSendLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = syncSnapshotSend2Str(pMsg);
|
|
||||||
sTrace("syncSnapshotSendLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ---------------------------------------------
|
|
||||||
SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId) {
|
SyncSnapshotRsp* syncSnapshotRspBuild(int32_t vgId) {
|
||||||
uint32_t bytes = sizeof(SyncSnapshotRsp);
|
uint32_t bytes = sizeof(SyncSnapshotRsp);
|
||||||
SyncSnapshotRsp* pMsg = taosMemoryMalloc(bytes);
|
SyncSnapshotRsp* pMsg = taosMemoryMalloc(bytes);
|
||||||
|
|
|
@ -13,31 +13,28 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
#include "syncRaftEntry.h"
|
#include "syncRaftEntry.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
|
|
||||||
SSyncRaftEntry* syncEntryBuild(uint32_t dataLen) {
|
SSyncRaftEntry* syncEntryBuild(int32_t dataLen) {
|
||||||
uint32_t bytes = sizeof(SSyncRaftEntry) + dataLen;
|
int32_t bytes = sizeof(SSyncRaftEntry) + dataLen;
|
||||||
SSyncRaftEntry* pEntry = taosMemoryMalloc(bytes);
|
SSyncRaftEntry* pEntry = taosMemoryMalloc(bytes);
|
||||||
ASSERT(pEntry != NULL);
|
if (pEntry == NULL) {
|
||||||
memset(pEntry, 0, bytes);
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
pEntry->bytes = bytes;
|
pEntry->bytes = bytes;
|
||||||
pEntry->dataLen = dataLen;
|
pEntry->dataLen = dataLen;
|
||||||
pEntry->rid = -1;
|
pEntry->rid = -1;
|
||||||
return pEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
// step 4. SyncClientRequest => SSyncRaftEntry, add term, index
|
|
||||||
SSyncRaftEntry* syncEntryBuild2(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) {
|
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuild3(pMsg, term, index);
|
|
||||||
ASSERT(pEntry != NULL);
|
|
||||||
|
|
||||||
return pEntry;
|
return pEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) {
|
SSyncRaftEntry* syncEntryBuildFromClientRequest(const SyncClientRequest* pMsg, SyncTerm term, SyncIndex index) {
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->dataLen);
|
SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->dataLen);
|
||||||
ASSERT(pEntry != NULL);
|
if (pEntry == NULL) return NULL;
|
||||||
|
|
||||||
pEntry->msgType = pMsg->msgType;
|
pEntry->msgType = pMsg->msgType;
|
||||||
pEntry->originalRpcType = pMsg->originalRpcType;
|
pEntry->originalRpcType = pMsg->originalRpcType;
|
||||||
|
@ -45,42 +42,37 @@ SSyncRaftEntry* syncEntryBuild3(SyncClientRequest* pMsg, SyncTerm term, SyncInde
|
||||||
pEntry->isWeak = pMsg->isWeak;
|
pEntry->isWeak = pMsg->isWeak;
|
||||||
pEntry->term = term;
|
pEntry->term = term;
|
||||||
pEntry->index = index;
|
pEntry->index = index;
|
||||||
pEntry->dataLen = pMsg->dataLen;
|
|
||||||
memcpy(pEntry->data, pMsg->data, pMsg->dataLen);
|
memcpy(pEntry->data, pMsg->data, pMsg->dataLen);
|
||||||
|
|
||||||
return pEntry;
|
return pEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncRaftEntry* syncEntryBuild4(SRpcMsg* pOriginalMsg, SyncTerm term, SyncIndex index) {
|
SSyncRaftEntry* syncEntryBuildFromRpcMsg(const SRpcMsg* pMsg, SyncTerm term, SyncIndex index) {
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuild(pOriginalMsg->contLen);
|
SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->contLen);
|
||||||
ASSERT(pEntry != NULL);
|
if (pEntry == NULL) return NULL;
|
||||||
|
|
||||||
pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
||||||
pEntry->originalRpcType = pOriginalMsg->msgType;
|
pEntry->originalRpcType = pMsg->msgType;
|
||||||
pEntry->seqNum = 0;
|
pEntry->seqNum = 0;
|
||||||
pEntry->isWeak = 0;
|
pEntry->isWeak = 0;
|
||||||
pEntry->term = term;
|
pEntry->term = term;
|
||||||
pEntry->index = index;
|
pEntry->index = index;
|
||||||
pEntry->dataLen = pOriginalMsg->contLen;
|
memcpy(pEntry->data, pMsg->pCont, pMsg->contLen);
|
||||||
memcpy(pEntry->data, pOriginalMsg->pCont, pOriginalMsg->contLen);
|
|
||||||
|
|
||||||
return pEntry;
|
return pEntry;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId) {
|
SSyncRaftEntry* syncEntryBuildFromAppendEntries(const SyncAppendEntries* pMsg) {
|
||||||
// init rpcMsg
|
SSyncRaftEntry* pEntry = syncEntryBuild(pMsg->dataLen);
|
||||||
SMsgHead head;
|
if (pEntry == NULL) return NULL;
|
||||||
head.vgId = vgId;
|
|
||||||
head.contLen = sizeof(SMsgHead);
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
memset(&rpcMsg, 0, sizeof(SRpcMsg));
|
|
||||||
rpcMsg.contLen = head.contLen;
|
|
||||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
|
||||||
rpcMsg.msgType = TDMT_SYNC_NOOP;
|
|
||||||
memcpy(rpcMsg.pCont, &head, sizeof(head));
|
|
||||||
|
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuild(rpcMsg.contLen);
|
memcpy(pEntry, pMsg->data, pMsg->dataLen);
|
||||||
ASSERT(pEntry != NULL);
|
return pEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId) {
|
||||||
|
SSyncRaftEntry* pEntry = syncEntryBuild(sizeof(SMsgHead));
|
||||||
|
if (pEntry == NULL) return NULL;
|
||||||
|
|
||||||
pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
||||||
pEntry->originalRpcType = TDMT_SYNC_NOOP;
|
pEntry->originalRpcType = TDMT_SYNC_NOOP;
|
||||||
|
@ -89,9 +81,9 @@ SSyncRaftEntry* syncEntryBuildNoop(SyncTerm term, SyncIndex index, int32_t vgId)
|
||||||
pEntry->term = term;
|
pEntry->term = term;
|
||||||
pEntry->index = index;
|
pEntry->index = index;
|
||||||
|
|
||||||
ASSERT(pEntry->dataLen == rpcMsg.contLen);
|
SMsgHead* pHead = (SMsgHead*)pEntry->data;
|
||||||
memcpy(pEntry->data, rpcMsg.pCont, rpcMsg.contLen);
|
pHead->vgId = vgId;
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
pHead->contLen = sizeof(SMsgHead);
|
||||||
|
|
||||||
return pEntry;
|
return pEntry;
|
||||||
}
|
}
|
||||||
|
@ -102,104 +94,13 @@ void syncEntryDestory(SSyncRaftEntry* pEntry) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// step 5. SSyncRaftEntry => bin, to raft log
|
|
||||||
char* syncEntrySerialize(const SSyncRaftEntry* pEntry, uint32_t* len) {
|
|
||||||
char* buf = taosMemoryMalloc(pEntry->bytes);
|
|
||||||
ASSERT(buf != NULL);
|
|
||||||
memcpy(buf, pEntry, pEntry->bytes);
|
|
||||||
if (len != NULL) {
|
|
||||||
*len = pEntry->bytes;
|
|
||||||
}
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
// step 6. bin => SSyncRaftEntry, from raft log
|
|
||||||
SSyncRaftEntry* syncEntryDeserialize(const char* buf, uint32_t len) {
|
|
||||||
uint32_t bytes = *((uint32_t*)buf);
|
|
||||||
SSyncRaftEntry* pEntry = taosMemoryMalloc(bytes);
|
|
||||||
ASSERT(pEntry != NULL);
|
|
||||||
memcpy(pEntry, buf, len);
|
|
||||||
ASSERT(len == pEntry->bytes);
|
|
||||||
return pEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pEntry != NULL) {
|
|
||||||
cJSON_AddNumberToObject(pRoot, "bytes", pEntry->bytes);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "msgType", pEntry->msgType);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "originalRpcType", pEntry->originalRpcType);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->seqNum);
|
|
||||||
cJSON_AddStringToObject(pRoot, "seqNum", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "isWeak", pEntry->isWeak);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->term);
|
|
||||||
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->index);
|
|
||||||
cJSON_AddStringToObject(pRoot, "index", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->rid);
|
|
||||||
cJSON_AddStringToObject(pRoot, "rid", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen);
|
|
||||||
|
|
||||||
char* s;
|
|
||||||
s = syncUtilPrintBin((char*)(pEntry->data), pEntry->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
|
|
||||||
s = syncUtilPrintBin2((char*)(pEntry->data), pEntry->dataLen);
|
|
||||||
cJSON_AddStringToObject(pRoot, "data2", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SSyncRaftEntry", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* syncEntry2Str(const SSyncRaftEntry* pEntry) {
|
|
||||||
cJSON* pJson = syncEntry2Json(pEntry);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
// step 7. SSyncRaftEntry => original SRpcMsg, commit to user, delete seqNum, isWeak, term, index
|
|
||||||
void syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg) {
|
void syncEntry2OriginalRpc(const SSyncRaftEntry* pEntry, SRpcMsg* pRpcMsg) {
|
||||||
memset(pRpcMsg, 0, sizeof(*pRpcMsg));
|
|
||||||
pRpcMsg->msgType = pEntry->originalRpcType;
|
pRpcMsg->msgType = pEntry->originalRpcType;
|
||||||
pRpcMsg->contLen = pEntry->dataLen;
|
pRpcMsg->contLen = pEntry->dataLen;
|
||||||
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
pRpcMsg->pCont = rpcMallocCont(pRpcMsg->contLen);
|
||||||
memcpy(pRpcMsg->pCont, pEntry->data, pRpcMsg->contLen);
|
memcpy(pRpcMsg->pCont, pEntry->data, pRpcMsg->contLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for debug ----------------------
|
|
||||||
void syncEntryPrint(const SSyncRaftEntry* pObj) {
|
|
||||||
char* serialized = syncEntry2Str(pObj);
|
|
||||||
printf("syncEntryPrint | len:%zu | %s \n", strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj) {
|
|
||||||
char* serialized = syncEntry2Str(pObj);
|
|
||||||
printf("syncEntryPrint2 | len:%zu | %s | %s \n", strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncEntryLog(const SSyncRaftEntry* pObj) {
|
|
||||||
char* serialized = syncEntry2Str(pObj);
|
|
||||||
sTrace("syncEntryLog | len:%zu | %s", strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) {
|
|
||||||
char* serialized = syncEntry2Str(pObj);
|
|
||||||
sTrace("syncEntryLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------
|
//-----------------------------------
|
||||||
SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) {
|
SRaftEntryHashCache* raftCacheCreate(SSyncNode* pSyncNode, int32_t maxCount) {
|
||||||
SRaftEntryHashCache* pCache = taosMemoryMalloc(sizeof(SRaftEntryHashCache));
|
SRaftEntryHashCache* pCache = taosMemoryMalloc(sizeof(SRaftEntryHashCache));
|
||||||
|
@ -354,76 +255,6 @@ int32_t raftCacheClear(struct SRaftEntryHashCache* pCache) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------
|
|
||||||
cJSON* raftCache2Json(SRaftEntryHashCache* pCache) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pCache != NULL) {
|
|
||||||
taosThreadMutexLock(&pCache->mutex);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "currentCount", pCache->currentCount);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "maxCount", pCache->maxCount);
|
|
||||||
cJSON* pEntries = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "entries", pEntries);
|
|
||||||
|
|
||||||
SSyncRaftEntry* pIter = (SSyncRaftEntry*)taosHashIterate(pCache->pEntryHash, NULL);
|
|
||||||
if (pIter != NULL) {
|
|
||||||
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pIter;
|
|
||||||
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
|
||||||
}
|
|
||||||
while (pIter) {
|
|
||||||
pIter = taosHashIterate(pCache->pEntryHash, pIter);
|
|
||||||
if (pIter != NULL) {
|
|
||||||
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pIter;
|
|
||||||
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
taosThreadMutexUnlock(&pCache->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SRaftEntryHashCache", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* raftCache2Str(SRaftEntryHashCache* pCache) {
|
|
||||||
cJSON* pJson = raftCache2Json(pCache);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCachePrint(SRaftEntryHashCache* pCache) {
|
|
||||||
char* serialized = raftCache2Str(pCache);
|
|
||||||
printf("raftCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCachePrint2(char* s, SRaftEntryHashCache* pCache) {
|
|
||||||
char* serialized = raftCache2Str(pCache);
|
|
||||||
printf("raftCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCacheLog(SRaftEntryHashCache* pCache) {
|
|
||||||
char* serialized = raftCache2Str(pCache);
|
|
||||||
sTrace("raftCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = raftCache2Str(pCache);
|
|
||||||
sLTrace("raftCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------
|
//-----------------------------------
|
||||||
static char* keyFn(const void* pData) {
|
static char* keyFn(const void* pData) {
|
||||||
|
@ -612,69 +443,3 @@ int32_t raftEntryCacheClear(struct SRaftEntryCache* pCache, int32_t count) {
|
||||||
taosThreadMutexUnlock(&pCache->mutex);
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
return returnCnt;
|
return returnCnt;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pCache != NULL) {
|
|
||||||
taosThreadMutexLock(&pCache->mutex);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "currentCount", pCache->currentCount);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "maxCount", pCache->maxCount);
|
|
||||||
cJSON* pEntries = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "entries", pEntries);
|
|
||||||
|
|
||||||
SSkipListIterator* pIter = tSkipListCreateIter(pCache->pSkipList);
|
|
||||||
while (tSkipListIterNext(pIter)) {
|
|
||||||
SSkipListNode* pNode = tSkipListIterGet(pIter);
|
|
||||||
ASSERT(pNode != NULL);
|
|
||||||
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode);
|
|
||||||
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
|
||||||
}
|
|
||||||
tSkipListDestroyIter(pIter);
|
|
||||||
|
|
||||||
taosThreadMutexUnlock(&pCache->mutex);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SRaftEntryCache", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* raftEntryCache2Str(SRaftEntryCache* pObj) {
|
|
||||||
cJSON* pJson = raftEntryCache2Json(pObj);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftEntryCachePrint(SRaftEntryCache* pObj) {
|
|
||||||
char* serialized = raftEntryCache2Str(pObj);
|
|
||||||
printf("raftEntryCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj) {
|
|
||||||
char* serialized = raftEntryCache2Str(pObj);
|
|
||||||
printf("raftEntryCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftEntryCacheLog(SRaftEntryCache* pObj) {
|
|
||||||
char* serialized = raftEntryCache2Str(pObj);
|
|
||||||
sTrace("raftEntryCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = raftEntryCache2Str(pObj);
|
|
||||||
sLTrace("raftEntryCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -22,15 +22,8 @@
|
||||||
|
|
||||||
// public function
|
// public function
|
||||||
static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncIndex snapshotIndex);
|
static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncIndex snapshotIndex);
|
||||||
static SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore);
|
|
||||||
static SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore);
|
|
||||||
static SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore);
|
|
||||||
static bool raftLogIsEmpty(struct SSyncLogStore* pLogStore);
|
|
||||||
static int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore);
|
|
||||||
static SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore);
|
|
||||||
static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore);
|
|
||||||
static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
|
static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
|
||||||
static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry);
|
|
||||||
static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIndex);
|
static int32_t raftLogTruncate(struct SSyncLogStore* pLogStore, SyncIndex fromIndex);
|
||||||
static bool raftLogExist(struct SSyncLogStore* pLogStore, SyncIndex index);
|
static bool raftLogExist(struct SSyncLogStore* pLogStore, SyncIndex index);
|
||||||
static int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index);
|
static int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index);
|
||||||
|
@ -126,29 +119,29 @@ static int32_t raftLogRestoreFromSnapshot(struct SSyncLogStore* pLogStore, SyncI
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore) {
|
SyncIndex raftLogBeginIndex(struct SSyncLogStore* pLogStore) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
SyncIndex firstVer = walGetFirstVer(pWal);
|
SyncIndex firstVer = walGetFirstVer(pWal);
|
||||||
return firstVer;
|
return firstVer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore) { return raftLogLastIndex(pLogStore); }
|
SyncIndex raftLogEndIndex(struct SSyncLogStore* pLogStore) { return raftLogLastIndex(pLogStore); }
|
||||||
|
|
||||||
static bool raftLogIsEmpty(struct SSyncLogStore* pLogStore) {
|
bool raftLogIsEmpty(struct SSyncLogStore* pLogStore) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
return walIsEmpty(pWal);
|
return walIsEmpty(pWal);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore) {
|
int32_t raftLogEntryCount(struct SSyncLogStore* pLogStore) {
|
||||||
SyncIndex beginIndex = raftLogBeginIndex(pLogStore);
|
SyncIndex beginIndex = raftLogBeginIndex(pLogStore);
|
||||||
SyncIndex endIndex = raftLogEndIndex(pLogStore);
|
SyncIndex endIndex = raftLogEndIndex(pLogStore);
|
||||||
int32_t count = endIndex - beginIndex + 1;
|
int32_t count = endIndex - beginIndex + 1;
|
||||||
return count > 0 ? count : 0;
|
return count > 0 ? count : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore) {
|
SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore) {
|
||||||
SyncIndex lastIndex;
|
SyncIndex lastIndex;
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
|
@ -157,7 +150,7 @@ static SyncIndex raftLogLastIndex(struct SSyncLogStore* pLogStore) {
|
||||||
return lastVer;
|
return lastVer;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore) {
|
SyncIndex raftLogWriteIndex(struct SSyncLogStore* pLogStore) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
SyncIndex lastVer = walGetLastVer(pWal);
|
SyncIndex lastVer = walGetLastVer(pWal);
|
||||||
|
@ -174,7 +167,7 @@ static bool raftLogExist(struct SSyncLogStore* pLogStore, SyncIndex index) {
|
||||||
// if success, return last term
|
// if success, return last term
|
||||||
// if not log, return 0
|
// if not log, return 0
|
||||||
// if error, return SYNC_TERM_INVALID
|
// if error, return SYNC_TERM_INVALID
|
||||||
static SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) {
|
SyncTerm raftLogLastTerm(struct SSyncLogStore* pLogStore) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
if (walIsEmpty(pWal)) {
|
if (walIsEmpty(pWal)) {
|
||||||
|
@ -225,7 +218,7 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
|
||||||
// entry found, return 0
|
// entry found, return 0
|
||||||
// entry not found, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST
|
// entry not found, return -1, terrno = TSDB_CODE_WAL_LOG_NOT_EXIST
|
||||||
// other error, return -1
|
// other error, return -1
|
||||||
static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
int32_t code = 0;
|
int32_t code = 0;
|
||||||
|
@ -364,111 +357,6 @@ SyncIndex raftlogCommitIndex(SSyncLogStore* pLogStore) {
|
||||||
return pData->pSyncNode->commitIndex;
|
return pData->pSyncNode->commitIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
cJSON* logStore2Json(SSyncLogStore* pLogStore) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pData != NULL && pData->pWal != NULL) {
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
|
||||||
|
|
||||||
SyncIndex beginIndex = raftLogBeginIndex(pLogStore);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "beginIndex", u64buf);
|
|
||||||
|
|
||||||
SyncIndex endIndex = raftLogEndIndex(pLogStore);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "endIndex", u64buf);
|
|
||||||
|
|
||||||
int32_t count = raftLogEntryCount(pLogStore);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "entryCount", count);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "LastIndex", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "LastTerm", u64buf);
|
|
||||||
|
|
||||||
cJSON* pEntries = cJSON_CreateArray();
|
|
||||||
cJSON_AddItemToObject(pRoot, "pEntries", pEntries);
|
|
||||||
|
|
||||||
if (!raftLogIsEmpty(pLogStore)) {
|
|
||||||
for (SyncIndex i = beginIndex; i <= endIndex; ++i) {
|
|
||||||
SSyncRaftEntry* pEntry = NULL;
|
|
||||||
raftLogGetEntry(pLogStore, i, &pEntry);
|
|
||||||
|
|
||||||
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
|
||||||
syncEntryDestory(pEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SSyncLogStore", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* logStore2Str(SSyncLogStore* pLogStore) {
|
|
||||||
cJSON* pJson = logStore2Json(pLogStore);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore) {
|
|
||||||
char u64buf[128] = {0};
|
|
||||||
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
|
||||||
cJSON* pRoot = cJSON_CreateObject();
|
|
||||||
|
|
||||||
if (pData != NULL && pData->pWal != NULL) {
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal);
|
|
||||||
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
|
||||||
|
|
||||||
SyncIndex beginIndex = raftLogBeginIndex(pLogStore);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "beginIndex", u64buf);
|
|
||||||
|
|
||||||
SyncIndex endIndex = raftLogEndIndex(pLogStore);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex);
|
|
||||||
cJSON_AddStringToObject(pRoot, "endIndex", u64buf);
|
|
||||||
|
|
||||||
int32_t count = raftLogEntryCount(pLogStore);
|
|
||||||
cJSON_AddNumberToObject(pRoot, "entryCount", count);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf);
|
|
||||||
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "LastIndex", u64buf);
|
|
||||||
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore));
|
|
||||||
cJSON_AddStringToObject(pRoot, "LastTerm", u64buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* pJson = cJSON_CreateObject();
|
|
||||||
cJSON_AddItemToObject(pJson, "SSyncLogStoreSimple", pRoot);
|
|
||||||
return pJson;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* logStoreSimple2Str(SSyncLogStore* pLogStore) {
|
|
||||||
cJSON* pJson = logStoreSimple2Json(pLogStore);
|
|
||||||
char* serialized = cJSON_Print(pJson);
|
|
||||||
cJSON_Delete(pJson);
|
|
||||||
return serialized;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex logStoreFirstIndex(SSyncLogStore* pLogStore) {
|
SyncIndex logStoreFirstIndex(SSyncLogStore* pLogStore) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
|
@ -480,63 +368,3 @@ SyncIndex logStoreWalCommitVer(SSyncLogStore* pLogStore) {
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
return walGetCommittedVer(pWal);
|
return walGetCommittedVer(pWal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// for debug -----------------
|
|
||||||
void logStorePrint(SSyncLogStore* pLogStore) {
|
|
||||||
char* serialized = logStore2Str(pLogStore);
|
|
||||||
printf("logStorePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void logStorePrint2(char* s, SSyncLogStore* pLogStore) {
|
|
||||||
char* serialized = logStore2Str(pLogStore);
|
|
||||||
printf("logStorePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void logStoreLog(SSyncLogStore* pLogStore) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = logStore2Str(pLogStore);
|
|
||||||
sLTrace("logStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void logStoreLog2(char* s, SSyncLogStore* pLogStore) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = logStore2Str(pLogStore);
|
|
||||||
sLTrace("logStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// for debug -----------------
|
|
||||||
void logStoreSimplePrint(SSyncLogStore* pLogStore) {
|
|
||||||
char* serialized = logStoreSimple2Str(pLogStore);
|
|
||||||
printf("logStoreSimplePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) {
|
|
||||||
char* serialized = logStoreSimple2Str(pLogStore);
|
|
||||||
printf("logStoreSimplePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
fflush(NULL);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void logStoreSimpleLog(SSyncLogStore* pLogStore) {
|
|
||||||
char* serialized = logStoreSimple2Str(pLogStore);
|
|
||||||
sTrace("logStoreSimpleLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
|
|
||||||
void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) {
|
|
||||||
if (gRaftDetailLog) {
|
|
||||||
char* serialized = logStoreSimple2Str(pLogStore);
|
|
||||||
sTrace("logStoreSimpleLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -78,14 +78,7 @@ int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
|
||||||
|
|
||||||
pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId);
|
pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId);
|
||||||
ASSERT(pMsg != NULL);
|
ASSERT(pMsg != NULL);
|
||||||
|
memcpy(pMsg->data, pEntry, pEntry->bytes);
|
||||||
// add pEntry into msg
|
|
||||||
uint32_t len;
|
|
||||||
char* serialized = syncEntrySerialize(pEntry, &len);
|
|
||||||
ASSERT(len == pEntry->bytes);
|
|
||||||
memcpy(pMsg->data, serialized, len);
|
|
||||||
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pEntry);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -13,21 +13,22 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
#include "syncRespMgr.h"
|
#include "syncRespMgr.h"
|
||||||
#include "syncRaftEntry.h"
|
#include "syncRaftEntry.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
|
|
||||||
SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl) {
|
SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl) {
|
||||||
SSyncRespMgr *pObj = (SSyncRespMgr *)taosMemoryMalloc(sizeof(SSyncRespMgr));
|
SSyncRespMgr *pObj = taosMemoryCalloc(1, sizeof(SSyncRespMgr));
|
||||||
if (pObj == NULL) {
|
if (pObj == NULL) {
|
||||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
memset(pObj, 0, sizeof(SSyncRespMgr));
|
|
||||||
|
|
||||||
pObj->pRespHash =
|
pObj->pRespHash =
|
||||||
taosHashInit(sizeof(uint64_t), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
taosHashInit(sizeof(uint64_t), taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_NO_LOCK);
|
||||||
ASSERT(pObj->pRespHash != NULL);
|
if (pObj->pRespHash == NULL) return NULL;
|
||||||
|
|
||||||
pObj->ttl = ttl;
|
pObj->ttl = ttl;
|
||||||
pObj->data = data;
|
pObj->data = data;
|
||||||
pObj->seqNum = 0;
|
pObj->seqNum = 0;
|
||||||
|
@ -38,90 +39,81 @@ SSyncRespMgr *syncRespMgrCreate(void *data, int64_t ttl) {
|
||||||
|
|
||||||
void syncRespMgrDestroy(SSyncRespMgr *pObj) {
|
void syncRespMgrDestroy(SSyncRespMgr *pObj) {
|
||||||
if (pObj != NULL) {
|
if (pObj != NULL) {
|
||||||
taosThreadMutexLock(&(pObj->mutex));
|
taosThreadMutexLock(&pObj->mutex);
|
||||||
taosHashCleanup(pObj->pRespHash);
|
taosHashCleanup(pObj->pRespHash);
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
taosThreadMutexUnlock(&pObj->mutex);
|
||||||
taosThreadMutexDestroy(&(pObj->mutex));
|
taosThreadMutexDestroy(&(pObj->mutex));
|
||||||
taosMemoryFree(pObj);
|
taosMemoryFree(pObj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t syncRespMgrAdd(SSyncRespMgr *pObj, SRespStub *pStub) {
|
uint64_t syncRespMgrAdd(SSyncRespMgr *pObj, const SRespStub *pStub) {
|
||||||
taosThreadMutexLock(&(pObj->mutex));
|
taosThreadMutexLock(&pObj->mutex);
|
||||||
|
|
||||||
uint64_t keyCode = ++(pObj->seqNum);
|
uint64_t seq = ++(pObj->seqNum);
|
||||||
taosHashPut(pObj->pRespHash, &keyCode, sizeof(keyCode), pStub, sizeof(SRespStub));
|
int32_t code = taosHashPut(pObj->pRespHash, &seq, sizeof(uint64_t), pStub, sizeof(SRespStub));
|
||||||
|
sNTrace(pObj->data, "save message handle:%p, type:%s seq:%" PRIu64 " code:0x%x", pStub->rpcMsg.info.handle,
|
||||||
|
TMSG_INFO(pStub->rpcMsg.msgType), seq, code);
|
||||||
|
|
||||||
sNTrace(pObj->data, "save message handle, type:%s seq:%" PRIu64 " handle:%p", TMSG_INFO(pStub->rpcMsg.msgType),
|
taosThreadMutexUnlock(&pObj->mutex);
|
||||||
keyCode, pStub->rpcMsg.info.handle);
|
return seq;
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
|
||||||
return keyCode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncRespMgrDel(SSyncRespMgr *pObj, uint64_t index) {
|
int32_t syncRespMgrDel(SSyncRespMgr *pObj, uint64_t seq) {
|
||||||
taosThreadMutexLock(&(pObj->mutex));
|
taosThreadMutexLock(&pObj->mutex);
|
||||||
|
|
||||||
taosHashRemove(pObj->pRespHash, &index, sizeof(index));
|
int32_t code = taosHashRemove(pObj->pRespHash, &seq, sizeof(seq));
|
||||||
|
sNTrace(pObj->data, "remove message handle, seq:%" PRIu64 " code:%d", seq, code);
|
||||||
|
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
taosThreadMutexUnlock(&pObj->mutex);
|
||||||
return 0;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub) {
|
int32_t syncRespMgrGet(SSyncRespMgr *pObj, uint64_t seq, SRespStub *pStub) {
|
||||||
taosThreadMutexLock(&(pObj->mutex));
|
taosThreadMutexLock(&pObj->mutex);
|
||||||
|
|
||||||
void *pTmp = taosHashGet(pObj->pRespHash, &index, sizeof(index));
|
SRespStub *pTmp = taosHashGet(pObj->pRespHash, &seq, sizeof(uint64_t));
|
||||||
if (pTmp != NULL) {
|
if (pTmp != NULL) {
|
||||||
memcpy(pStub, pTmp, sizeof(SRespStub));
|
memcpy(pStub, pTmp, sizeof(SRespStub));
|
||||||
|
sNTrace(pObj->data, "get message handle, type:%s seq:%" PRIu64 " handle:%p", TMSG_INFO(pStub->rpcMsg.msgType), seq,
|
||||||
|
pStub->rpcMsg.info.handle);
|
||||||
|
|
||||||
sNTrace(pObj->data, "get message handle, type:%s seq:%" PRIu64 " handle:%p", TMSG_INFO(pStub->rpcMsg.msgType),
|
taosThreadMutexUnlock(&pObj->mutex);
|
||||||
index, pStub->rpcMsg.info.handle);
|
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
|
||||||
return 1; // get one object
|
return 1; // get one object
|
||||||
}
|
}
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
|
||||||
|
taosThreadMutexUnlock(&pObj->mutex);
|
||||||
return 0; // get none object
|
return 0; // get none object
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t index, SRespStub *pStub) {
|
int32_t syncRespMgrGetAndDel(SSyncRespMgr *pObj, uint64_t seq, SRpcHandleInfo *pInfo) {
|
||||||
taosThreadMutexLock(&(pObj->mutex));
|
taosThreadMutexLock(&pObj->mutex);
|
||||||
|
|
||||||
void *pTmp = taosHashGet(pObj->pRespHash, &index, sizeof(index));
|
SRespStub *pStub = taosHashGet(pObj->pRespHash, &seq, sizeof(uint64_t));
|
||||||
if (pTmp != NULL) {
|
if (pStub != NULL) {
|
||||||
memcpy(pStub, pTmp, sizeof(SRespStub));
|
*pInfo = pStub->rpcMsg.info;
|
||||||
|
sNTrace(pObj->data, "get-and-del message handle:%p, type:%s seq:%" PRIu64, pStub->rpcMsg.info.handle,
|
||||||
|
TMSG_INFO(pStub->rpcMsg.msgType), seq);
|
||||||
|
taosHashRemove(pObj->pRespHash, &seq, sizeof(uint64_t));
|
||||||
|
|
||||||
sNTrace(pObj->data, "get-and-del message handle, type:%s seq:%" PRIu64 " handle:%p",
|
taosThreadMutexUnlock(&pObj->mutex);
|
||||||
TMSG_INFO(pStub->rpcMsg.msgType), index, pStub->rpcMsg.info.handle);
|
|
||||||
taosHashRemove(pObj->pRespHash, &index, sizeof(index));
|
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
|
||||||
return 1; // get one object
|
return 1; // get one object
|
||||||
}
|
}
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
|
||||||
|
taosThreadMutexUnlock(&pObj->mutex);
|
||||||
return 0; // get none object
|
return 0; // get none object
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRespCleanRsp(SSyncRespMgr *pObj) {
|
static void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) {
|
||||||
taosThreadMutexLock(&(pObj->mutex));
|
|
||||||
syncRespCleanByTTL(pObj, -1, true);
|
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncRespClean(SSyncRespMgr *pObj) {
|
|
||||||
taosThreadMutexLock(&(pObj->mutex));
|
|
||||||
syncRespCleanByTTL(pObj, pObj->ttl, false);
|
|
||||||
taosThreadMutexUnlock(&(pObj->mutex));
|
|
||||||
}
|
|
||||||
|
|
||||||
void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) {
|
|
||||||
SRespStub *pStub = (SRespStub *)taosHashIterate(pObj->pRespHash, NULL);
|
SRespStub *pStub = (SRespStub *)taosHashIterate(pObj->pRespHash, NULL);
|
||||||
int cnt = 0;
|
int cnt = 0;
|
||||||
int sum = 0;
|
int sum = 0;
|
||||||
SSyncNode *pSyncNode = pObj->data;
|
SSyncNode *pSyncNode = pObj->data;
|
||||||
|
|
||||||
SArray *delIndexArray = taosArrayInit(0, sizeof(uint64_t));
|
SArray *delIndexArray = taosArrayInit(4, sizeof(uint64_t));
|
||||||
ASSERT(delIndexArray != NULL);
|
if (delIndexArray == NULL) return;
|
||||||
sDebug("vgId:%d, resp mgr begin clean by ttl", pSyncNode->vgId);
|
|
||||||
|
|
||||||
|
sDebug("vgId:%d, resp mgr begin clean by ttl", pSyncNode->vgId);
|
||||||
while (pStub) {
|
while (pStub) {
|
||||||
size_t len;
|
size_t len;
|
||||||
void *key = taosHashGetKey(pStub, &len);
|
void *key = taosHashGetKey(pStub, &len);
|
||||||
|
@ -149,15 +141,15 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) {
|
||||||
pStub->rpcMsg.contLen = 0;
|
pStub->rpcMsg.contLen = 0;
|
||||||
|
|
||||||
// TODO: and make rpcMsg body, call commit cb
|
// TODO: and make rpcMsg body, call commit cb
|
||||||
// pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &(pStub->rpcMsg), cbMeta);
|
// pSyncNode->pFsm->FpCommitCb(pSyncNode->pFsm, &pStub->rpcMsg, cbMeta);
|
||||||
|
|
||||||
pStub->rpcMsg.code = TSDB_CODE_SYN_NOT_LEADER;
|
pStub->rpcMsg.code = TSDB_CODE_SYN_NOT_LEADER;
|
||||||
if (pStub->rpcMsg.info.handle != NULL) {
|
if (pStub->rpcMsg.info.handle != NULL) {
|
||||||
tmsgSendRsp(&(pStub->rpcMsg));
|
tmsgSendRsp(&pStub->rpcMsg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pStub = (SRespStub *)taosHashIterate(pObj->pRespHash, pStub);
|
pStub = taosHashIterate(pObj->pRespHash, pStub);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t arraySize = taosArrayGetSize(delIndexArray);
|
int32_t arraySize = taosArrayGetSize(delIndexArray);
|
||||||
|
@ -170,3 +162,15 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) {
|
||||||
}
|
}
|
||||||
taosArrayDestroy(delIndexArray);
|
taosArrayDestroy(delIndexArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void syncRespCleanRsp(SSyncRespMgr *pObj) {
|
||||||
|
taosThreadMutexLock(&pObj->mutex);
|
||||||
|
syncRespCleanByTTL(pObj, -1, true);
|
||||||
|
taosThreadMutexUnlock(&pObj->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncRespClean(SSyncRespMgr *pObj) {
|
||||||
|
taosThreadMutexLock(&pObj->mutex);
|
||||||
|
syncRespCleanByTTL(pObj, pObj->ttl, false);
|
||||||
|
taosThreadMutexUnlock(&pObj->mutex);
|
||||||
|
}
|
||||||
|
|
|
@ -216,6 +216,9 @@ static void syncPeerState2Str(SSyncNode* pSyncNode, char* buf, int32_t bufLen) {
|
||||||
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
|
void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNode* pNode, const char* format, ...) {
|
||||||
if (pNode == NULL || pNode->pRaftCfg != NULL && pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
if (pNode == NULL || pNode->pRaftCfg != NULL && pNode->pRaftStore == NULL || pNode->pLogStore == NULL) return;
|
||||||
|
|
||||||
|
// save error code, otherwise it will be overwritten
|
||||||
|
int32_t errCode = terrno;
|
||||||
|
|
||||||
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
if (pNode->pFsm != NULL && pNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
|
pNode->pFsm->FpGetSnapshotInfo(pNode->pFsm, &snapshot);
|
||||||
|
@ -242,16 +245,21 @@ void syncPrintNodeLog(const char* flags, ELogLevel level, int32_t dflag, SSyncNo
|
||||||
int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
|
int32_t writeLen = vsnprintf(eventLog, sizeof(eventLog), format, argpointer);
|
||||||
va_end(argpointer);
|
va_end(argpointer);
|
||||||
|
|
||||||
|
int32_t aqItems = pNode->pFsm->FpApplyQueueItems(pNode->pFsm);
|
||||||
|
|
||||||
|
// restore error code
|
||||||
|
terrno = errCode;
|
||||||
|
|
||||||
taosPrintLog(flags, level, dflag,
|
taosPrintLog(flags, level, dflag,
|
||||||
"vgId:%d, sync %s "
|
"vgId:%d, sync %s "
|
||||||
"%s"
|
"%s"
|
||||||
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
", tm:%" PRIu64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", min:%" PRId64 ", snap:%" PRId64
|
||||||
", snap-tm:%" PRIu64 ", sby:%d, stgy:%d, bch:%d, r-num:%d, lcfg:%" PRId64
|
", snap-tm:%" PRIu64 ", sby:%d, aq:%d, bch:%d, r-num:%d, lcfg:%" PRId64
|
||||||
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
", chging:%d, rsto:%d, dquorum:%d, elt:%" PRId64 ", hb:%" PRId64 ", %s, %s",
|
||||||
pNode->vgId, syncStr(pNode->state), eventLog, pNode->pRaftStore->currentTerm, pNode->commitIndex,
|
pNode->vgId, syncStr(pNode->state), eventLog, pNode->pRaftStore->currentTerm, pNode->commitIndex,
|
||||||
logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
logBeginIndex, logLastIndex, pNode->minMatchIndex, snapshot.lastApplyIndex, snapshot.lastApplyTerm,
|
||||||
pNode->pRaftCfg->isStandBy, pNode->pRaftCfg->snapshotStrategy, pNode->pRaftCfg->batchSize,
|
pNode->pRaftCfg->isStandBy, aqItems, pNode->pRaftCfg->batchSize, pNode->replicaNum,
|
||||||
pNode->replicaNum, pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
|
pNode->pRaftCfg->lastConfigIndex, pNode->changing, pNode->restoreFinish, quorum,
|
||||||
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr);
|
pNode->electTimerLogicClock, pNode->heartbeatTimerLogicClockUser, peerStr, cfgStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
add_subdirectory(sync_test_lib)
|
||||||
add_executable(syncTest "")
|
add_executable(syncTest "")
|
||||||
add_executable(syncRaftIdCheck "")
|
add_executable(syncRaftIdCheck "")
|
||||||
add_executable(syncEnvTest "")
|
add_executable(syncEnvTest "")
|
||||||
|
@ -24,8 +25,6 @@ add_executable(syncRequestVoteReplyTest "")
|
||||||
add_executable(syncAppendEntriesTest "")
|
add_executable(syncAppendEntriesTest "")
|
||||||
add_executable(syncAppendEntriesBatchTest "")
|
add_executable(syncAppendEntriesBatchTest "")
|
||||||
add_executable(syncAppendEntriesReplyTest "")
|
add_executable(syncAppendEntriesReplyTest "")
|
||||||
add_executable(syncClientRequestTest "")
|
|
||||||
add_executable(syncClientRequestBatchTest "")
|
|
||||||
add_executable(syncTimeoutTest "")
|
add_executable(syncTimeoutTest "")
|
||||||
add_executable(syncPingTest "")
|
add_executable(syncPingTest "")
|
||||||
add_executable(syncPingReplyTest "")
|
add_executable(syncPingReplyTest "")
|
||||||
|
@ -167,14 +166,6 @@ target_sources(syncAppendEntriesReplyTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"syncAppendEntriesReplyTest.cpp"
|
"syncAppendEntriesReplyTest.cpp"
|
||||||
)
|
)
|
||||||
target_sources(syncClientRequestTest
|
|
||||||
PRIVATE
|
|
||||||
"syncClientRequestTest.cpp"
|
|
||||||
)
|
|
||||||
target_sources(syncClientRequestBatchTest
|
|
||||||
PRIVATE
|
|
||||||
"syncClientRequestBatchTest.cpp"
|
|
||||||
)
|
|
||||||
target_sources(syncTimeoutTest
|
target_sources(syncTimeoutTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"syncTimeoutTest.cpp"
|
"syncTimeoutTest.cpp"
|
||||||
|
@ -287,10 +278,6 @@ target_sources(syncLeaderTransferTest
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"syncLeaderTransferTest.cpp"
|
"syncLeaderTransferTest.cpp"
|
||||||
)
|
)
|
||||||
target_sources(syncReconfigFinishTest
|
|
||||||
PRIVATE
|
|
||||||
"syncReconfigFinishTest.cpp"
|
|
||||||
)
|
|
||||||
target_sources(syncRestoreFromSnapshot
|
target_sources(syncRestoreFromSnapshot
|
||||||
PRIVATE
|
PRIVATE
|
||||||
"syncRestoreFromSnapshot.cpp"
|
"syncRestoreFromSnapshot.cpp"
|
||||||
|
@ -451,16 +438,6 @@ target_include_directories(syncAppendEntriesReplyTest
|
||||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncClientRequestTest
|
|
||||||
PUBLIC
|
|
||||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
|
||||||
)
|
|
||||||
target_include_directories(syncClientRequestBatchTest
|
|
||||||
PUBLIC
|
|
||||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
|
||||||
)
|
|
||||||
target_include_directories(syncTimeoutTest
|
target_include_directories(syncTimeoutTest
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
|
@ -601,11 +578,6 @@ target_include_directories(syncLeaderTransferTest
|
||||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
||||||
)
|
)
|
||||||
target_include_directories(syncReconfigFinishTest
|
|
||||||
PUBLIC
|
|
||||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/../inc"
|
|
||||||
)
|
|
||||||
target_include_directories(syncRestoreFromSnapshot
|
target_include_directories(syncRestoreFromSnapshot
|
||||||
PUBLIC
|
PUBLIC
|
||||||
"${TD_SOURCE_DIR}/include/libs/sync"
|
"${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
|
@ -644,259 +616,247 @@ target_include_directories(syncPreSnapshotReplyTest
|
||||||
|
|
||||||
|
|
||||||
target_link_libraries(syncTest
|
target_link_libraries(syncTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRaftIdCheck
|
target_link_libraries(syncRaftIdCheck
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncEnvTest
|
target_link_libraries(syncEnvTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncPingTimerTest
|
target_link_libraries(syncPingTimerTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncIOTickQTest
|
target_link_libraries(syncIOTickQTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncIOTickPingTest
|
target_link_libraries(syncIOTickPingTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncIOSendMsgTest
|
target_link_libraries(syncIOSendMsgTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncIOClientTest
|
target_link_libraries(syncIOClientTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncIOServerTest
|
target_link_libraries(syncIOServerTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRaftStoreTest
|
target_link_libraries(syncRaftStoreTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncEnqTest
|
target_link_libraries(syncEnqTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncIndexTest
|
target_link_libraries(syncIndexTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncInitTest
|
target_link_libraries(syncInitTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncUtilTest
|
target_link_libraries(syncUtilTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncVotesGrantedTest
|
target_link_libraries(syncVotesGrantedTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncVotesRespondTest
|
target_link_libraries(syncVotesRespondTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncIndexMgrTest
|
target_link_libraries(syncIndexMgrTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncLogStoreTest
|
target_link_libraries(syncLogStoreTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncEntryTest
|
target_link_libraries(syncEntryTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncEntryCacheTest
|
target_link_libraries(syncEntryCacheTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncHashCacheTest
|
target_link_libraries(syncHashCacheTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRequestVoteTest
|
target_link_libraries(syncRequestVoteTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRequestVoteReplyTest
|
target_link_libraries(syncRequestVoteReplyTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncAppendEntriesTest
|
target_link_libraries(syncAppendEntriesTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncAppendEntriesBatchTest
|
target_link_libraries(syncAppendEntriesBatchTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncAppendEntriesReplyTest
|
target_link_libraries(syncAppendEntriesReplyTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
|
||||||
)
|
|
||||||
target_link_libraries(syncClientRequestTest
|
|
||||||
sync
|
|
||||||
gtest_main
|
|
||||||
)
|
|
||||||
target_link_libraries(syncClientRequestBatchTest
|
|
||||||
sync
|
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncTimeoutTest
|
target_link_libraries(syncTimeoutTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncPingTest
|
target_link_libraries(syncPingTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncPingReplyTest
|
target_link_libraries(syncPingReplyTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRpcMsgTest
|
target_link_libraries(syncRpcMsgTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncPingTimerTest2
|
target_link_libraries(syncPingTimerTest2
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncPingSelfTest
|
target_link_libraries(syncPingSelfTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncElectTest
|
target_link_libraries(syncElectTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncEncodeTest
|
target_link_libraries(syncEncodeTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncWriteTest
|
target_link_libraries(syncWriteTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncReplicateTest
|
target_link_libraries(syncReplicateTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRefTest
|
target_link_libraries(syncRefTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncLogStoreCheck
|
target_link_libraries(syncLogStoreCheck
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncLogStoreCheck2
|
target_link_libraries(syncLogStoreCheck2
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRaftCfgTest
|
target_link_libraries(syncRaftCfgTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRespMgrTest
|
target_link_libraries(syncRespMgrTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncSnapshotTest
|
target_link_libraries(syncSnapshotTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncApplyMsgTest
|
target_link_libraries(syncApplyMsgTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncConfigChangeTest
|
target_link_libraries(syncConfigChangeTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncConfigChangeSnapshotTest
|
target_link_libraries(syncConfigChangeSnapshotTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncSnapshotSendTest
|
target_link_libraries(syncSnapshotSendTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncSnapshotRspTest
|
target_link_libraries(syncSnapshotRspTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncSnapshotSenderTest
|
target_link_libraries(syncSnapshotSenderTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncSnapshotReceiverTest
|
target_link_libraries(syncSnapshotReceiverTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncTestTool
|
target_link_libraries(syncTestTool
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRaftLogTest
|
target_link_libraries(syncRaftLogTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRaftLogTest2
|
target_link_libraries(syncRaftLogTest2
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRaftLogTest3
|
target_link_libraries(syncRaftLogTest3
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncLeaderTransferTest
|
target_link_libraries(syncLeaderTransferTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
|
||||||
)
|
|
||||||
target_link_libraries(syncReconfigFinishTest
|
|
||||||
sync
|
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRestoreFromSnapshot
|
target_link_libraries(syncRestoreFromSnapshot
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncRaftCfgIndexTest
|
target_link_libraries(syncRaftCfgIndexTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncHeartbeatTest
|
target_link_libraries(syncHeartbeatTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncHeartbeatReplyTest
|
target_link_libraries(syncHeartbeatReplyTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncLocalCmdTest
|
target_link_libraries(syncLocalCmdTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncPreSnapshotTest
|
target_link_libraries(syncPreSnapshotTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
target_link_libraries(syncPreSnapshotReplyTest
|
target_link_libraries(syncPreSnapshotReplyTest
|
||||||
sync
|
sync_test_lib
|
||||||
gtest_main
|
gtest_main
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "syncRaftEntry.h"
|
#include "syncRaftEntry.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
void logTest() {
|
void logTest() {
|
||||||
sTrace("--- sync log test: trace");
|
sTrace("--- sync log test: trace");
|
||||||
|
|
|
@ -1,125 +0,0 @@
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "syncIO.h"
|
|
||||||
#include "syncInt.h"
|
|
||||||
#include "syncMessage.h"
|
|
||||||
#include "syncUtil.h"
|
|
||||||
|
|
||||||
void logTest() {
|
|
||||||
sTrace("--- sync log test: trace");
|
|
||||||
sDebug("--- sync log test: debug");
|
|
||||||
sInfo("--- sync log test: info");
|
|
||||||
sWarn("--- sync log test: warn");
|
|
||||||
sError("--- sync log test: error");
|
|
||||||
sFatal("--- sync log test: fatal");
|
|
||||||
}
|
|
||||||
|
|
||||||
SRpcMsg *createRpcMsg(int32_t i, int32_t dataLen) {
|
|
||||||
SyncPing *pSyncMsg = syncPingBuild(20);
|
|
||||||
snprintf(pSyncMsg->data, pSyncMsg->dataLen, "value_%d", i);
|
|
||||||
|
|
||||||
SRpcMsg *pRpcMsg = (SRpcMsg *)taosMemoryMalloc(sizeof(SRpcMsg));
|
|
||||||
memset(pRpcMsg, 0, sizeof(SRpcMsg));
|
|
||||||
pRpcMsg->code = 10 * i;
|
|
||||||
syncPing2RpcMsg(pSyncMsg, pRpcMsg);
|
|
||||||
|
|
||||||
syncPingDestroy(pSyncMsg);
|
|
||||||
return pRpcMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncClientRequestBatch *createMsg() {
|
|
||||||
SRpcMsg *rpcMsgPArr[5];
|
|
||||||
memset(rpcMsgPArr, 0, sizeof(rpcMsgPArr));
|
|
||||||
for (int32_t i = 0; i < 5; ++i) {
|
|
||||||
SRpcMsg *pRpcMsg = createRpcMsg(i, 20);
|
|
||||||
rpcMsgPArr[i] = pRpcMsg;
|
|
||||||
// taosMemoryFree(pRpcMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
SRaftMeta raftArr[5];
|
|
||||||
memset(raftArr, 0, sizeof(raftArr));
|
|
||||||
for (int32_t i = 0; i < 5; ++i) {
|
|
||||||
raftArr[i].seqNum = i * 10;
|
|
||||||
raftArr[i].isWeak = i % 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncClientRequestBatch *pMsg = syncClientRequestBatchBuild(rpcMsgPArr, raftArr, 5, 1234);
|
|
||||||
return pMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test1() {
|
|
||||||
SyncClientRequestBatch *pMsg = createMsg();
|
|
||||||
syncClientRequestBatchLog2((char *)"==test1==", pMsg);
|
|
||||||
syncClientRequestBatchDestroyDeep(pMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
void test2() {
|
|
||||||
SyncClientRequest *pMsg = createMsg();
|
|
||||||
uint32_t len = pMsg->bytes;
|
|
||||||
char * serialized = (char *)taosMemoryMalloc(len);
|
|
||||||
syncClientRequestSerialize(pMsg, serialized, len);
|
|
||||||
SyncClientRequest *pMsg2 = syncClientRequestAlloc(pMsg->dataLen);
|
|
||||||
syncClientRequestDeserialize(serialized, len, pMsg2);
|
|
||||||
syncClientRequestLog2((char *)"test2: syncClientRequestSerialize -> syncClientRequestDeserialize ", pMsg2);
|
|
||||||
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
syncClientRequestDestroy(pMsg);
|
|
||||||
syncClientRequestDestroy(pMsg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test3() {
|
|
||||||
SyncClientRequest *pMsg = createMsg();
|
|
||||||
uint32_t len;
|
|
||||||
char * serialized = syncClientRequestSerialize2(pMsg, &len);
|
|
||||||
SyncClientRequest *pMsg2 = syncClientRequestDeserialize2(serialized, len);
|
|
||||||
syncClientRequestLog2((char *)"test3: syncClientRequestSerialize3 -> syncClientRequestDeserialize2 ", pMsg2);
|
|
||||||
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
syncClientRequestDestroy(pMsg);
|
|
||||||
syncClientRequestDestroy(pMsg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test4() {
|
|
||||||
SyncClientRequest *pMsg = createMsg();
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncClientRequest2RpcMsg(pMsg, &rpcMsg);
|
|
||||||
SyncClientRequest *pMsg2 = (SyncClientRequest *)taosMemoryMalloc(rpcMsg.contLen);
|
|
||||||
syncClientRequestFromRpcMsg(&rpcMsg, pMsg2);
|
|
||||||
syncClientRequestLog2((char *)"test4: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg ", pMsg2);
|
|
||||||
|
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
|
||||||
syncClientRequestDestroy(pMsg);
|
|
||||||
syncClientRequestDestroy(pMsg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test5() {
|
|
||||||
SyncClientRequest *pMsg = createMsg();
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncClientRequest2RpcMsg(pMsg, &rpcMsg);
|
|
||||||
SyncClientRequest *pMsg2 = syncClientRequestFromRpcMsg2(&rpcMsg);
|
|
||||||
syncClientRequestLog2((char *)"test5: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg2 ", pMsg2);
|
|
||||||
|
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
|
||||||
syncClientRequestDestroy(pMsg);
|
|
||||||
syncClientRequestDestroy(pMsg2);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
gRaftDetailLog = true;
|
|
||||||
tsAsyncLog = 0;
|
|
||||||
sDebugFlag = DEBUG_DEBUG + DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
|
|
||||||
logTest();
|
|
||||||
|
|
||||||
test1();
|
|
||||||
|
|
||||||
/*
|
|
||||||
test2();
|
|
||||||
test3();
|
|
||||||
test4();
|
|
||||||
test5();
|
|
||||||
*/
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,98 +0,0 @@
|
||||||
#include <gtest/gtest.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "syncIO.h"
|
|
||||||
#include "syncInt.h"
|
|
||||||
#include "syncMessage.h"
|
|
||||||
#include "syncUtil.h"
|
|
||||||
|
|
||||||
void logTest() {
|
|
||||||
sTrace("--- sync log test: trace");
|
|
||||||
sDebug("--- sync log test: debug");
|
|
||||||
sInfo("--- sync log test: info");
|
|
||||||
sWarn("--- sync log test: warn");
|
|
||||||
sError("--- sync log test: error");
|
|
||||||
sFatal("--- sync log test: fatal");
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncClientRequest *createMsg() {
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
memset(&rpcMsg, 0, sizeof(rpcMsg));
|
|
||||||
rpcMsg.msgType = 12345;
|
|
||||||
rpcMsg.contLen = 20;
|
|
||||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
|
||||||
strcpy((char *)rpcMsg.pCont, "hello rpc");
|
|
||||||
SyncClientRequest *pMsg = syncClientRequestBuild(&rpcMsg, 123, true, 1000);
|
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
|
||||||
return pMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
void test1() {
|
|
||||||
SyncClientRequest *pMsg = createMsg();
|
|
||||||
syncClientRequestLog2((char *)"test1:", pMsg);
|
|
||||||
syncClientRequestDestroy(pMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test2() {
|
|
||||||
SyncClientRequest *pMsg = createMsg();
|
|
||||||
uint32_t len = pMsg->bytes;
|
|
||||||
char *serialized = (char *)taosMemoryMalloc(len);
|
|
||||||
syncClientRequestSerialize(pMsg, serialized, len);
|
|
||||||
SyncClientRequest *pMsg2 = syncClientRequestAlloc(pMsg->dataLen);
|
|
||||||
syncClientRequestDeserialize(serialized, len, pMsg2);
|
|
||||||
syncClientRequestLog2((char *)"test2: syncClientRequestSerialize -> syncClientRequestDeserialize ", pMsg2);
|
|
||||||
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
syncClientRequestDestroy(pMsg);
|
|
||||||
syncClientRequestDestroy(pMsg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test3() {
|
|
||||||
SyncClientRequest *pMsg = createMsg();
|
|
||||||
uint32_t len;
|
|
||||||
char *serialized = syncClientRequestSerialize2(pMsg, &len);
|
|
||||||
SyncClientRequest *pMsg2 = syncClientRequestDeserialize2(serialized, len);
|
|
||||||
syncClientRequestLog2((char *)"test3: syncClientRequestSerialize3 -> syncClientRequestDeserialize2 ", pMsg2);
|
|
||||||
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
syncClientRequestDestroy(pMsg);
|
|
||||||
syncClientRequestDestroy(pMsg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test4() {
|
|
||||||
SyncClientRequest *pMsg = createMsg();
|
|
||||||
SRpcMsg rpcMsg = {0};
|
|
||||||
syncClientRequest2RpcMsg(pMsg, &rpcMsg);
|
|
||||||
SyncClientRequest *pMsg2 = (SyncClientRequest *)taosMemoryMalloc(rpcMsg.contLen);
|
|
||||||
syncClientRequestFromRpcMsg(&rpcMsg, pMsg2);
|
|
||||||
syncClientRequestLog2((char *)"test4: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg ", pMsg2);
|
|
||||||
|
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
|
||||||
syncClientRequestDestroy(pMsg);
|
|
||||||
syncClientRequestDestroy(pMsg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test5() {
|
|
||||||
SyncClientRequest *pMsg = createMsg();
|
|
||||||
SRpcMsg rpcMsg = {0};
|
|
||||||
syncClientRequest2RpcMsg(pMsg, &rpcMsg);
|
|
||||||
SyncClientRequest *pMsg2 = syncClientRequestFromRpcMsg2(&rpcMsg);
|
|
||||||
syncClientRequestLog2((char *)"test5: syncClientRequest2RpcMsg -> syncClientRequestFromRpcMsg2 ", pMsg2);
|
|
||||||
|
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
|
||||||
syncClientRequestDestroy(pMsg);
|
|
||||||
syncClientRequestDestroy(pMsg2);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
tsAsyncLog = 0;
|
|
||||||
sDebugFlag = DEBUG_TRACE + DEBUG_SCREEN + DEBUG_FILE;
|
|
||||||
logTest();
|
|
||||||
|
|
||||||
test1();
|
|
||||||
test2();
|
|
||||||
test3();
|
|
||||||
test4();
|
|
||||||
test5();
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -7,9 +7,11 @@
|
||||||
#include "syncRaftEntry.h"
|
#include "syncRaftEntry.h"
|
||||||
#include "syncRaftLog.h"
|
#include "syncRaftLog.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncTest.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
|
|
||||||
|
#if 0
|
||||||
void logTest() {
|
void logTest() {
|
||||||
sTrace("--- sync log test: trace");
|
sTrace("--- sync log test: trace");
|
||||||
sDebug("--- sync log test: debug");
|
sDebug("--- sync log test: debug");
|
||||||
|
@ -118,17 +120,7 @@ SyncClientRequest *step3(const SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncRaftEntry *step4(const SyncClientRequest *pMsg) {
|
SSyncRaftEntry *step4(const SyncClientRequest *pMsg) {
|
||||||
SSyncRaftEntry *pRetMsg = syncEntryBuild2((SyncClientRequest *)pMsg, 100, 0);
|
SSyncRaftEntry *pRetMsg = syncEntryBuildFromClientRequest((SyncClientRequest *)pMsg, 100, 0);
|
||||||
return pRetMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
char *step5(const SSyncRaftEntry *pMsg, uint32_t *len) {
|
|
||||||
char *pRetMsg = syncEntrySerialize(pMsg, len);
|
|
||||||
return pRetMsg;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncRaftEntry *step6(const char *pMsg, uint32_t len) {
|
|
||||||
SSyncRaftEntry *pRetMsg = syncEntryDeserialize(pMsg, len);
|
|
||||||
return pRetMsg;
|
return pRetMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,13 +129,14 @@ SRpcMsg *step7(const SSyncRaftEntry *pMsg) {
|
||||||
syncEntry2OriginalRpc(pMsg, pRetMsg);
|
syncEntry2OriginalRpc(pMsg, pRetMsg);
|
||||||
return pRetMsg;
|
return pRetMsg;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
// taosInitLog((char *)"syncTest.log", 100000, 10);
|
||||||
tsAsyncLog = 0;
|
tsAsyncLog = 0;
|
||||||
sDebugFlag = 143 + 64;
|
sDebugFlag = 143 + 64;
|
||||||
void logTest();
|
void logTest();
|
||||||
|
|
||||||
|
#if 0
|
||||||
myIndex = 0;
|
myIndex = 0;
|
||||||
if (argc >= 2) {
|
if (argc >= 2) {
|
||||||
myIndex = atoi(argv[1]);
|
myIndex = atoi(argv[1]);
|
||||||
|
@ -188,20 +181,9 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
syncEntryLog2((char *)"==pEntry==", pEntry);
|
syncEntryLog2((char *)"==pEntry==", pEntry);
|
||||||
|
|
||||||
// step5
|
|
||||||
uint32_t len;
|
|
||||||
char *pMsg5 = step5(pMsg4, &len);
|
|
||||||
char *s = syncUtilPrintBin(pMsg5, len);
|
|
||||||
printf("==step5== [%s] \n", s);
|
|
||||||
taosMemoryFree(s);
|
|
||||||
|
|
||||||
// step6
|
|
||||||
SSyncRaftEntry *pMsg6 = step6(pMsg5, len);
|
|
||||||
syncEntryLog2((char *)"==step6==", pMsg6);
|
|
||||||
|
|
||||||
// step7
|
// step7
|
||||||
SRpcMsg *pMsg7 = step7(pMsg6);
|
SRpcMsg *pMsg7 = step7(pMsg6);
|
||||||
syncRpcMsgLog2((char *)"==step7==", pMsg7);
|
syncRpcMsgLog2((char *)"==step7==", pMsg7);
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "tref.h"
|
#include "tref.h"
|
||||||
#include "tskiplist.h"
|
#include "tskiplist.h"
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
void logTest() {
|
void logTest() {
|
||||||
sTrace("--- sync log test: trace");
|
sTrace("--- sync log test: trace");
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "syncRaftLog.h"
|
#include "syncRaftLog.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
void logTest() {
|
void logTest() {
|
||||||
sTrace("--- sync log test: trace");
|
sTrace("--- sync log test: trace");
|
||||||
|
@ -38,10 +39,10 @@ void test2() {
|
||||||
pSyncMsg->isWeak = 1;
|
pSyncMsg->isWeak = 1;
|
||||||
strcpy(pSyncMsg->data, "test2");
|
strcpy(pSyncMsg->data, "test2");
|
||||||
|
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuild2(pSyncMsg, 100, 200);
|
SSyncRaftEntry* pEntry = syncEntryBuildFromClientRequest(pSyncMsg, 100, 200);
|
||||||
syncEntryPrint(pEntry);
|
syncEntryPrint(pEntry);
|
||||||
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
taosMemoryFree(pSyncMsg);
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,10 +53,10 @@ void test3() {
|
||||||
pSyncMsg->isWeak = 1;
|
pSyncMsg->isWeak = 1;
|
||||||
strcpy(pSyncMsg->data, "test3");
|
strcpy(pSyncMsg->data, "test3");
|
||||||
|
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuild3(pSyncMsg, 100, 200);
|
SSyncRaftEntry* pEntry = syncEntryBuildFromClientRequest(pSyncMsg, 100, 200);
|
||||||
syncEntryPrint(pEntry);
|
syncEntryPrint(pEntry);
|
||||||
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
taosMemoryFree(pSyncMsg);
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,14 +72,7 @@ void test4() {
|
||||||
strcpy(pEntry->data, "test4");
|
strcpy(pEntry->data, "test4");
|
||||||
syncEntryPrint(pEntry);
|
syncEntryPrint(pEntry);
|
||||||
|
|
||||||
uint32_t len;
|
// syncEntryDestory(pEntry2);
|
||||||
char* serialized = syncEntrySerialize(pEntry, &len);
|
|
||||||
assert(serialized != NULL);
|
|
||||||
SSyncRaftEntry* pEntry2 = syncEntryDeserialize(serialized, len);
|
|
||||||
syncEntryPrint(pEntry2);
|
|
||||||
|
|
||||||
taosMemoryFree(serialized);
|
|
||||||
syncEntryDestory(pEntry2);
|
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pEntry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "syncRaftLog.h"
|
#include "syncRaftLog.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncTest.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "tskiplist.h"
|
#include "tskiplist.h"
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "syncRaftLog.h"
|
#include "syncRaftLog.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncTest.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
void logTest() {
|
void logTest() {
|
||||||
sTrace("--- sync log test: trace");
|
sTrace("--- sync log test: trace");
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "syncRaftLog.h"
|
#include "syncRaftLog.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncTest.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include "syncInt.h"
|
#include "syncInt.h"
|
||||||
#include "syncRaftLog.h"
|
#include "syncRaftLog.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncTest.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,5 @@
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <stdio.h>
|
#include "syncTest.h"
|
||||||
#include "syncEnv.h"
|
|
||||||
#include "syncIO.h"
|
|
||||||
#include "syncInt.h"
|
|
||||||
#include "syncRaftLog.h"
|
|
||||||
#include "syncRaftStore.h"
|
|
||||||
#include "syncUtil.h"
|
|
||||||
#include "wal.h"
|
|
||||||
|
|
||||||
void logTest() {
|
void logTest() {
|
||||||
sTrace("--- sync log test: trace");
|
sTrace("--- sync log test: trace");
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
#include "syncRespMgr.h"
|
#include "syncTest.h"
|
||||||
//#include <gtest/gtest.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "syncIO.h"
|
|
||||||
#include "syncInt.h"
|
|
||||||
|
|
||||||
void logTest() {
|
void logTest() {
|
||||||
sTrace("--- sync log test: trace");
|
sTrace("--- sync log test: trace");
|
||||||
|
@ -64,13 +60,13 @@ void syncRespMgrGetTest(uint64_t i) {
|
||||||
|
|
||||||
void syncRespMgrGetAndDelTest(uint64_t i) {
|
void syncRespMgrGetAndDelTest(uint64_t i) {
|
||||||
printf("------syncRespMgrGetAndDelTest-------%" PRIu64 "-- \n", i);
|
printf("------syncRespMgrGetAndDelTest-------%" PRIu64 "-- \n", i);
|
||||||
SRespStub stub;
|
// SRespStub stub;
|
||||||
int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub);
|
// int32_t ret = syncRespMgrGetAndDel(pMgr, i, &stub);
|
||||||
if (ret == 1) {
|
// if (ret == 1) {
|
||||||
printStub(&stub);
|
// printStub(&stub);
|
||||||
} else if (ret == 0) {
|
// } else if (ret == 0) {
|
||||||
printf("%" PRId64 " notFound \n", i);
|
// printf("%" PRId64 " notFound \n", i);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncNode *createSyncNode() {
|
SSyncNode *createSyncNode() {
|
||||||
|
|
|
@ -47,7 +47,11 @@ SyncClientRequest *createSyncClientRequest() {
|
||||||
rpcMsg.contLen = 20;
|
rpcMsg.contLen = 20;
|
||||||
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
rpcMsg.pCont = rpcMallocCont(rpcMsg.contLen);
|
||||||
strcpy((char *)rpcMsg.pCont, "hello rpc");
|
strcpy((char *)rpcMsg.pCont, "hello rpc");
|
||||||
SyncClientRequest *pMsg = syncClientRequestBuild(&rpcMsg, 123, true, 1000);
|
|
||||||
|
SRpcMsg clientRequestMsg;
|
||||||
|
syncClientRequestBuildFromRpcMsg(&clientRequestMsg, &rpcMsg, 123, true, 1000);
|
||||||
|
SyncClientRequest *pMsg = (SyncClientRequest *)taosMemoryMalloc(clientRequestMsg.contLen);
|
||||||
|
memcpy(pMsg->data, clientRequestMsg.pCont, clientRequestMsg.contLen);
|
||||||
return pMsg;
|
return pMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,11 +159,13 @@ void test7() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void test8() {
|
void test8() {
|
||||||
|
#if 0
|
||||||
SyncClientRequest *pMsg = createSyncClientRequest();
|
SyncClientRequest *pMsg = createSyncClientRequest();
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
syncClientRequest2RpcMsg(pMsg, &rpcMsg);
|
syncClientRequest2RpcMsg(pMsg, &rpcMsg);
|
||||||
syncRpcMsgLog2((char *)"test8", &rpcMsg);
|
syncRpcMsgLog2((char *)"test8", &rpcMsg);
|
||||||
syncClientRequestDestroy(pMsg);
|
taosMemoryFree(pMsg);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|
|
@ -162,8 +162,11 @@ SRpcMsg *step0() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncClientRequest *step1(const SRpcMsg *pMsg) {
|
SyncClientRequest *step1(const SRpcMsg *pMsg) {
|
||||||
SyncClientRequest *pRetMsg = syncClientRequestBuild(pMsg, 123, true, 1000);
|
SRpcMsg clientRequestMsg;
|
||||||
return pRetMsg;
|
syncClientRequestBuildFromRpcMsg(&clientRequestMsg, pMsg, 123, true, 1000);
|
||||||
|
SyncClientRequest *pMsg2 = (SyncClientRequest *)taosMemoryMalloc(clientRequestMsg.contLen);
|
||||||
|
memcpy(pMsg2->data, clientRequestMsg.pCont, clientRequestMsg.contLen);
|
||||||
|
return pMsg2;
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
@ -207,8 +210,8 @@ int main(int argc, char **argv) {
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
SyncClientRequest *pSyncClientRequest = pMsg1;
|
SyncClientRequest *pSyncClientRequest = pMsg1;
|
||||||
SRpcMsg rpcMsg = {0};
|
SRpcMsg rpcMsg = {0};
|
||||||
syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg);
|
// syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg);
|
||||||
gSyncNode->syncEqMsg(gSyncNode->msgcb, &rpcMsg);
|
// gSyncNode->syncEqMsg(gSyncNode->msgcb, &rpcMsg);
|
||||||
|
|
||||||
taosMsleep(1000);
|
taosMsleep(1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "syncVoteMgr.h"
|
#include "syncVoteMgr.h"
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
void logTest() {
|
void logTest() {
|
||||||
sTrace("--- sync log test: trace");
|
sTrace("--- sync log test: trace");
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "syncVoteMgr.h"
|
#include "syncVoteMgr.h"
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
|
|
||||||
void logTest() {
|
void logTest() {
|
||||||
sTrace("--- sync log test: trace");
|
sTrace("--- sync log test: trace");
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include "syncRaftEntry.h"
|
#include "syncRaftEntry.h"
|
||||||
#include "syncRaftLog.h"
|
#include "syncRaftLog.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncTest.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
|
|
||||||
|
@ -140,7 +141,8 @@ SRpcMsg *step0() {
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncClientRequest *step1(const SRpcMsg *pMsg) {
|
SyncClientRequest *step1(const SRpcMsg *pMsg) {
|
||||||
SyncClientRequest *pRetMsg = syncClientRequestBuild(pMsg, 123, true, 1000);
|
SyncClientRequest *pRetMsg = NULL;
|
||||||
|
// syncClientRequestBuild(pMsg, 123, true, 1000);
|
||||||
return pRetMsg;
|
return pRetMsg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,14 +181,14 @@ int main(int argc, char **argv) {
|
||||||
SyncClientRequest *pMsg1 = step1(pMsg0);
|
SyncClientRequest *pMsg1 = step1(pMsg0);
|
||||||
syncClientRequestLog2((char *)"==step1==", pMsg1);
|
syncClientRequestLog2((char *)"==step1==", pMsg1);
|
||||||
|
|
||||||
for (int i = 0; i < 10; ++i) {
|
// for (int i = 0; i < 10; ++i) {
|
||||||
SyncClientRequest *pSyncClientRequest = pMsg1;
|
// SyncClientRequest *pSyncClientRequest = pMsg1;
|
||||||
SRpcMsg rpcMsg = {0};
|
// SRpcMsg rpcMsg = {0};
|
||||||
syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg);
|
// syncClientRequest2RpcMsg(pSyncClientRequest, &rpcMsg);
|
||||||
gSyncNode->syncEqMsg(gSyncNode->msgcb, &rpcMsg);
|
// gSyncNode->syncEqMsg(gSyncNode->msgcb, &rpcMsg);
|
||||||
|
|
||||||
taosMsleep(1000);
|
// taosMsleep(1000);
|
||||||
}
|
// }
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
sTrace("while 1 sleep");
|
sTrace("while 1 sleep");
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
aux_source_directory(src SYNC_TEST_SRC)
|
||||||
|
add_library(sync_test_lib STATIC ${SYNC_TEST_SRC})
|
||||||
|
|
||||||
|
target_link_libraries(
|
||||||
|
sync_test_lib
|
||||||
|
PUBLIC sync
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(
|
||||||
|
sync_test_lib
|
||||||
|
PUBLIC "${TD_SOURCE_DIR}/include/libs/sync"
|
||||||
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../../inc"
|
||||||
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
|
)
|
|
@ -50,7 +50,7 @@ typedef struct SSyncIO {
|
||||||
void *pSyncNode;
|
void *pSyncNode;
|
||||||
int32_t (*FpOnSyncPing)(SSyncNode *pSyncNode, SyncPing *pMsg);
|
int32_t (*FpOnSyncPing)(SSyncNode *pSyncNode, SyncPing *pMsg);
|
||||||
int32_t (*FpOnSyncPingReply)(SSyncNode *pSyncNode, SyncPingReply *pMsg);
|
int32_t (*FpOnSyncPingReply)(SSyncNode *pSyncNode, SyncPingReply *pMsg);
|
||||||
int32_t (*FpOnSyncClientRequest)(SSyncNode *pSyncNode, SyncClientRequest *pMsg, SyncIndex *pRetIndex);
|
int32_t (*FpOnSyncClientRequest)(SSyncNode *pSyncNode, SRpcMsg *pMsg, SyncIndex *pRetIndex);
|
||||||
int32_t (*FpOnSyncRequestVote)(SSyncNode *pSyncNode, SyncRequestVote *pMsg);
|
int32_t (*FpOnSyncRequestVote)(SSyncNode *pSyncNode, SyncRequestVote *pMsg);
|
||||||
int32_t (*FpOnSyncRequestVoteReply)(SSyncNode *pSyncNode, SyncRequestVoteReply *pMsg);
|
int32_t (*FpOnSyncRequestVoteReply)(SSyncNode *pSyncNode, SyncRequestVoteReply *pMsg);
|
||||||
int32_t (*FpOnSyncAppendEntries)(SSyncNode *pSyncNode, SyncAppendEntries *pMsg);
|
int32_t (*FpOnSyncAppendEntries)(SSyncNode *pSyncNode, SyncAppendEntries *pMsg);
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _TD_LIBS_SYNC_TEST_H
|
||||||
|
#define _TD_LIBS_SYNC_TEST_H
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "syncInt.h"
|
||||||
|
|
||||||
|
#include "wal.h"
|
||||||
|
|
||||||
|
#include "syncEnv.h"
|
||||||
|
#include "syncIO.h"
|
||||||
|
#include "syncIndexMgr.h"
|
||||||
|
#include "syncInt.h"
|
||||||
|
#include "syncMessage.h"
|
||||||
|
#include "syncRaftCfg.h"
|
||||||
|
#include "syncRaftEntry.h"
|
||||||
|
#include "syncRaftLog.h"
|
||||||
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncRespMgr.h"
|
||||||
|
#include "syncSnapshot.h"
|
||||||
|
#include "syncUtil.h"
|
||||||
|
#include "syncVoteMgr.h"
|
||||||
|
|
||||||
|
cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry);
|
||||||
|
char* syncEntry2Str(const SSyncRaftEntry* pEntry);
|
||||||
|
void syncEntryPrint(const SSyncRaftEntry* pObj);
|
||||||
|
void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj);
|
||||||
|
void syncEntryLog(const SSyncRaftEntry* pObj);
|
||||||
|
void syncEntryLog2(char* s, const SSyncRaftEntry* pObj);
|
||||||
|
|
||||||
|
cJSON* raftCache2Json(SRaftEntryHashCache* pObj);
|
||||||
|
char* raftCache2Str(SRaftEntryHashCache* pObj);
|
||||||
|
void raftCachePrint(SRaftEntryHashCache* pObj);
|
||||||
|
void raftCachePrint2(char* s, SRaftEntryHashCache* pObj);
|
||||||
|
void raftCacheLog(SRaftEntryHashCache* pObj);
|
||||||
|
void raftCacheLog2(char* s, SRaftEntryHashCache* pObj);
|
||||||
|
|
||||||
|
cJSON* raftEntryCache2Json(SRaftEntryCache* pObj);
|
||||||
|
char* raftEntryCache2Str(SRaftEntryCache* pObj);
|
||||||
|
void raftEntryCachePrint(SRaftEntryCache* pObj);
|
||||||
|
void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj);
|
||||||
|
void raftEntryCacheLog(SRaftEntryCache* pObj);
|
||||||
|
void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj);
|
||||||
|
|
||||||
|
cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg);
|
||||||
|
char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg);
|
||||||
|
void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg);
|
||||||
|
void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg);
|
||||||
|
void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg);
|
||||||
|
void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg);
|
||||||
|
|
||||||
|
cJSON* logStore2Json(SSyncLogStore* pLogStore);
|
||||||
|
char* logStore2Str(SSyncLogStore* pLogStore);
|
||||||
|
cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore);
|
||||||
|
char* logStoreSimple2Str(SSyncLogStore* pLogStore);
|
||||||
|
void logStorePrint(SSyncLogStore* pLogStore);
|
||||||
|
void logStorePrint2(char* s, SSyncLogStore* pLogStore);
|
||||||
|
void logStoreLog(SSyncLogStore* pLogStore);
|
||||||
|
void logStoreLog2(char* s, SSyncLogStore* pLogStore);
|
||||||
|
void logStoreSimplePrint(SSyncLogStore* pLogStore);
|
||||||
|
void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore);
|
||||||
|
void logStoreSimpleLog(SSyncLogStore* pLogStore);
|
||||||
|
void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore);
|
||||||
|
|
||||||
|
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
|
||||||
|
char* syncNode2Str(const SSyncNode* pSyncNode);
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /*_TD_LIBS_SYNC_RAFT_ENTRY_H*/
|
|
@ -279,10 +279,7 @@ static void *syncIOConsumerFunc(void *param) {
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
} else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||||
if (io->FpOnSyncClientRequest != NULL) {
|
if (io->FpOnSyncClientRequest != NULL) {
|
||||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pRpcMsg);
|
io->FpOnSyncClientRequest(io->pSyncNode, pRpcMsg, NULL);
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
io->FpOnSyncClientRequest(io->pSyncNode, pSyncMsg, NULL);
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
} else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
|
@ -0,0 +1,255 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
|
cJSON* syncNode2Json(const SSyncNode* pSyncNode) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pSyncNode != NULL) {
|
||||||
|
// init by SSyncInfo
|
||||||
|
cJSON_AddNumberToObject(pRoot, "vgId", pSyncNode->vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "SRaftCfg", raftCfg2Json(pSyncNode->pRaftCfg));
|
||||||
|
cJSON_AddStringToObject(pRoot, "path", pSyncNode->path);
|
||||||
|
cJSON_AddStringToObject(pRoot, "raftStorePath", pSyncNode->raftStorePath);
|
||||||
|
cJSON_AddStringToObject(pRoot, "configPath", pSyncNode->configPath);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pWal);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
||||||
|
cJSON_AddStringToObject(pRoot, "rpcClient", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->syncSendMSg);
|
||||||
|
cJSON_AddStringToObject(pRoot, "syncSendMSg", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->msgcb);
|
||||||
|
cJSON_AddStringToObject(pRoot, "queue", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->syncEqMsg);
|
||||||
|
cJSON_AddStringToObject(pRoot, "syncEqMsg", u64buf);
|
||||||
|
|
||||||
|
// init internal
|
||||||
|
cJSON* pMe = syncUtilNodeInfo2Json(&pSyncNode->myNodeInfo);
|
||||||
|
cJSON_AddItemToObject(pRoot, "myNodeInfo", pMe);
|
||||||
|
cJSON* pRaftId = syncUtilRaftId2Json(&pSyncNode->myRaftId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "myRaftId", pRaftId);
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "peersNum", pSyncNode->peersNum);
|
||||||
|
cJSON* pPeers = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "peersNodeInfo", pPeers);
|
||||||
|
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
|
cJSON_AddItemToArray(pPeers, syncUtilNodeInfo2Json(&pSyncNode->peersNodeInfo[i]));
|
||||||
|
}
|
||||||
|
cJSON* pPeersId = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "peersId", pPeersId);
|
||||||
|
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
|
cJSON_AddItemToArray(pPeersId, syncUtilRaftId2Json(&pSyncNode->peersId[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "replicaNum", pSyncNode->replicaNum);
|
||||||
|
cJSON* pReplicasId = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "replicasId", pReplicasId);
|
||||||
|
for (int32_t i = 0; i < pSyncNode->replicaNum; ++i) {
|
||||||
|
cJSON_AddItemToArray(pReplicasId, syncUtilRaftId2Json(&pSyncNode->replicasId[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// raft algorithm
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pFsm);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pFsm", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "quorum", pSyncNode->quorum);
|
||||||
|
cJSON* pLaderCache = syncUtilRaftId2Json(&pSyncNode->leaderCache);
|
||||||
|
cJSON_AddItemToObject(pRoot, "leaderCache", pLaderCache);
|
||||||
|
|
||||||
|
// life cycle
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->rid);
|
||||||
|
cJSON_AddStringToObject(pRoot, "rid", u64buf);
|
||||||
|
|
||||||
|
// tla+ server vars
|
||||||
|
cJSON_AddNumberToObject(pRoot, "state", pSyncNode->state);
|
||||||
|
cJSON_AddStringToObject(pRoot, "state_str", syncStr(pSyncNode->state));
|
||||||
|
cJSON_AddItemToObject(pRoot, "pRaftStore", raftStore2Json(pSyncNode->pRaftStore));
|
||||||
|
|
||||||
|
// tla+ candidate vars
|
||||||
|
cJSON_AddItemToObject(pRoot, "pVotesGranted", voteGranted2Json(pSyncNode->pVotesGranted));
|
||||||
|
cJSON_AddItemToObject(pRoot, "pVotesRespond", votesRespond2Json(pSyncNode->pVotesRespond));
|
||||||
|
|
||||||
|
// tla+ leader vars
|
||||||
|
cJSON_AddItemToObject(pRoot, "pNextIndex", syncIndexMgr2Json(pSyncNode->pNextIndex));
|
||||||
|
cJSON_AddItemToObject(pRoot, "pMatchIndex", syncIndexMgr2Json(pSyncNode->pMatchIndex));
|
||||||
|
|
||||||
|
// tla+ log vars
|
||||||
|
cJSON_AddItemToObject(pRoot, "pLogStore", logStore2Json(pSyncNode->pLogStore));
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->commitIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
|
||||||
|
|
||||||
|
// timer ms init
|
||||||
|
cJSON_AddNumberToObject(pRoot, "pingBaseLine", pSyncNode->pingBaseLine);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "electBaseLine", pSyncNode->electBaseLine);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "hbBaseLine", pSyncNode->hbBaseLine);
|
||||||
|
|
||||||
|
// ping timer
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pPingTimer);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pPingTimer", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "pingTimerMS", pSyncNode->pingTimerMS);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->pingTimerLogicClock);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pingTimerLogicClock", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->pingTimerLogicClockUser);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pingTimerLogicClockUser", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpPingTimerCB);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpPingTimerCB", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->pingTimerCounter);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pingTimerCounter", u64buf);
|
||||||
|
|
||||||
|
// elect timer
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pElectTimer);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pElectTimer", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "electTimerMS", pSyncNode->electTimerMS);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->electTimerLogicClock);
|
||||||
|
cJSON_AddStringToObject(pRoot, "electTimerLogicClock", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpElectTimerCB);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpElectTimerCB", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->electTimerCounter);
|
||||||
|
cJSON_AddStringToObject(pRoot, "electTimerCounter", u64buf);
|
||||||
|
|
||||||
|
// heartbeat timer
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->pHeartbeatTimer);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pHeartbeatTimer", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "heartbeatTimerMS", pSyncNode->heartbeatTimerMS);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->heartbeatTimerLogicClock);
|
||||||
|
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClock", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->heartbeatTimerLogicClockUser);
|
||||||
|
cJSON_AddStringToObject(pRoot, "heartbeatTimerLogicClockUser", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpHeartbeatTimerCB);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpHeartbeatTimerCB", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pSyncNode->heartbeatTimerCounter);
|
||||||
|
cJSON_AddStringToObject(pRoot, "heartbeatTimerCounter", u64buf);
|
||||||
|
|
||||||
|
// callback
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPing);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnPing", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnPingReply);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnPingReply", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVote);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnRequestVote", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnRequestVoteReply);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnRequestVoteReply", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntries);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnAppendEntries", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnAppendEntriesReply);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnAppendEntriesReply", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pSyncNode->FpOnTimeout);
|
||||||
|
cJSON_AddStringToObject(pRoot, "FpOnTimeout", u64buf);
|
||||||
|
|
||||||
|
// restoreFinish
|
||||||
|
cJSON_AddNumberToObject(pRoot, "restoreFinish", pSyncNode->restoreFinish);
|
||||||
|
|
||||||
|
// snapshot senders
|
||||||
|
cJSON* pSenders = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "senders", pSenders);
|
||||||
|
for (int32_t i = 0; i < TSDB_MAX_REPLICA; ++i) {
|
||||||
|
cJSON_AddItemToArray(pSenders, snapshotSender2Json((pSyncNode->senders)[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// snapshot receivers
|
||||||
|
cJSON* pReceivers = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "receiver", snapshotReceiver2Json(pSyncNode->pNewNodeReceiver));
|
||||||
|
|
||||||
|
// changing
|
||||||
|
cJSON_AddNumberToObject(pRoot, "changing", pSyncNode->changing);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SSyncNode", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncNode2Str(const SSyncNode* pSyncNode) {
|
||||||
|
cJSON* pJson = syncNode2Json(pSyncNode);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline char* syncNode2SimpleStr(const SSyncNode* pSyncNode) {
|
||||||
|
int32_t len = 256;
|
||||||
|
char* s = (char*)taosMemoryMalloc(len);
|
||||||
|
|
||||||
|
SSnapshot snapshot = {.data = NULL, .lastApplyIndex = -1, .lastApplyTerm = 0};
|
||||||
|
if (pSyncNode->pFsm->FpGetSnapshotInfo != NULL) {
|
||||||
|
pSyncNode->pFsm->FpGetSnapshotInfo(pSyncNode->pFsm, &snapshot);
|
||||||
|
}
|
||||||
|
SyncIndex logLastIndex = pSyncNode->pLogStore->syncLogLastIndex(pSyncNode->pLogStore);
|
||||||
|
SyncIndex logBeginIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore);
|
||||||
|
|
||||||
|
snprintf(s, len,
|
||||||
|
"vgId:%d, sync %s, tm:%" PRId64 ", cmt:%" PRId64 ", fst:%" PRId64 ", lst:%" PRId64 ", snap:%" PRId64
|
||||||
|
", sby:%d, "
|
||||||
|
"r-num:%d, "
|
||||||
|
"lcfg:%" PRId64 ", chging:%d, rsto:%d",
|
||||||
|
pSyncNode->vgId, syncStr(pSyncNode->state), pSyncNode->pRaftStore->currentTerm, pSyncNode->commitIndex,
|
||||||
|
logBeginIndex, logLastIndex, snapshot.lastApplyIndex, pSyncNode->pRaftCfg->isStandBy, pSyncNode->replicaNum,
|
||||||
|
pSyncNode->pRaftCfg->lastConfigIndex, pSyncNode->changing, pSyncNode->restoreFinish);
|
||||||
|
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ping --------------
|
||||||
|
int32_t syncNodePing(SSyncNode* pSyncNode, const SRaftId* destRaftId, SyncPing* pMsg) {
|
||||||
|
syncPingLog2((char*)"==syncNodePing==", pMsg);
|
||||||
|
int32_t ret = 0;
|
||||||
|
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncPing2RpcMsg(pMsg, &rpcMsg);
|
||||||
|
syncRpcMsgLog2((char*)"==syncNodePing==", &rpcMsg);
|
||||||
|
|
||||||
|
ret = syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syncNodePingSelf(SSyncNode* pSyncNode) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, &pSyncNode->myRaftId, pSyncNode->vgId);
|
||||||
|
ret = syncNodePing(pSyncNode, &pMsg->destId, pMsg);
|
||||||
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
|
syncPingDestroy(pMsg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syncNodePingPeers(SSyncNode* pSyncNode) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
|
SRaftId* destId = &(pSyncNode->peersId[i]);
|
||||||
|
SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId);
|
||||||
|
ret = syncNodePing(pSyncNode, destId, pMsg);
|
||||||
|
ASSERT(ret == 0);
|
||||||
|
syncPingDestroy(pMsg);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syncNodePingAll(SSyncNode* pSyncNode) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
for (int32_t i = 0; i < pSyncNode->pRaftCfg->cfg.replicaNum; ++i) {
|
||||||
|
SRaftId* destId = &(pSyncNode->replicasId[i]);
|
||||||
|
SyncPing* pMsg = syncPingBuild3(&pSyncNode->myRaftId, destId, pSyncNode->vgId);
|
||||||
|
ret = syncNodePing(pSyncNode, destId, pMsg);
|
||||||
|
ASSERT(ret == 0);
|
||||||
|
syncPingDestroy(pMsg);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,508 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
|
// ---------------------------------------------
|
||||||
|
cJSON* syncRpcMsg2Json(SRpcMsg* pRpcMsg) {
|
||||||
|
cJSON* pRoot;
|
||||||
|
|
||||||
|
// in compiler optimization, switch case = if else constants
|
||||||
|
if (pRpcMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
||||||
|
SyncTimeout* pSyncMsg = syncTimeoutDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncTimeout2Json(pSyncMsg);
|
||||||
|
syncTimeoutDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_PING) {
|
||||||
|
SyncPing* pSyncMsg = syncPingDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncPing2Json(pSyncMsg);
|
||||||
|
syncPingDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
||||||
|
SyncPingReply* pSyncMsg = syncPingReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncPingReply2Json(pSyncMsg);
|
||||||
|
syncPingReplyDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||||
|
SyncClientRequest* pSyncMsg = pRpcMsg->pCont;
|
||||||
|
pRoot = syncClientRequest2Json(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_REPLY) {
|
||||||
|
pRoot = syncRpcUnknownMsg2Json();
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
||||||
|
SyncRequestVote* pSyncMsg = syncRequestVoteDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncRequestVote2Json(pSyncMsg);
|
||||||
|
syncRequestVoteDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
||||||
|
SyncRequestVoteReply* pSyncMsg = syncRequestVoteReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncRequestVoteReply2Json(pSyncMsg);
|
||||||
|
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
||||||
|
SyncAppendEntries* pSyncMsg = syncAppendEntriesDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncAppendEntries2Json(pSyncMsg);
|
||||||
|
syncAppendEntriesDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
||||||
|
SyncAppendEntriesReply* pSyncMsg = syncAppendEntriesReplyDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncAppendEntriesReply2Json(pSyncMsg);
|
||||||
|
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
||||||
|
SyncSnapshotSend* pSyncMsg = syncSnapshotSendDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncSnapshotSend2Json(pSyncMsg);
|
||||||
|
syncSnapshotSendDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
||||||
|
SyncSnapshotRsp* pSyncMsg = syncSnapshotRspDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncSnapshotRsp2Json(pSyncMsg);
|
||||||
|
syncSnapshotRspDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_LEADER_TRANSFER) {
|
||||||
|
SyncLeaderTransfer* pSyncMsg = syncLeaderTransferDeserialize2(pRpcMsg->pCont, pRpcMsg->contLen);
|
||||||
|
pRoot = syncLeaderTransfer2Json(pSyncMsg);
|
||||||
|
syncLeaderTransferDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pRpcMsg->msgType == TDMT_SYNC_COMMON_RESPONSE) {
|
||||||
|
pRoot = cJSON_CreateObject();
|
||||||
|
char* s;
|
||||||
|
s = syncUtilPrintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pCont", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
s = syncUtilPrintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pCont2", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
pRoot = cJSON_CreateObject();
|
||||||
|
char* s;
|
||||||
|
s = syncUtilPrintBin((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pCont", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
s = syncUtilPrintBin2((char*)(pRpcMsg->pCont), pRpcMsg->contLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pCont2", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "msgType", pRpcMsg->msgType);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "contLen", pRpcMsg->contLen);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "code", pRpcMsg->code);
|
||||||
|
// cJSON_AddNumberToObject(pRoot, "persist", pRpcMsg->persist);
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "RpcMsg", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* syncRpcUnknownMsg2Json() {
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
cJSON_AddNumberToObject(pRoot, "msgType", TDMT_SYNC_UNKNOWN);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", "unknown message");
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SyncUnknown", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncRpcMsg2Str(SRpcMsg* pRpcMsg) {
|
||||||
|
cJSON* pJson = syncRpcMsg2Json(pRpcMsg);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for debug ----------------------
|
||||||
|
void syncRpcMsgPrint(SRpcMsg* pMsg) {
|
||||||
|
char* serialized = syncRpcMsg2Str(pMsg);
|
||||||
|
printf("syncRpcMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) {
|
||||||
|
char* serialized = syncRpcMsg2Str(pMsg);
|
||||||
|
printf("syncRpcMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncRpcMsgLog(SRpcMsg* pMsg) {
|
||||||
|
char* serialized = syncRpcMsg2Str(pMsg);
|
||||||
|
sTrace("syncRpcMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = syncRpcMsg2Str(pMsg);
|
||||||
|
sTrace("syncRpcMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* syncAppendEntriesBatch2Json(const SyncAppendEntriesBatch* pMsg) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pMsg != NULL) {
|
||||||
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
|
|
||||||
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
|
||||||
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
|
cJSON* pTmp = pSrcId;
|
||||||
|
char host[128] = {0};
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
|
||||||
|
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128] = {0};
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->prevLogIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "prevLogIndex", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->prevLogTerm);
|
||||||
|
cJSON_AddStringToObject(pRoot, "prevLogTerm", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->commitIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "commitIndex", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->privateTerm);
|
||||||
|
cJSON_AddStringToObject(pRoot, "privateTerm", u64buf);
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataCount", pMsg->dataCount);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
|
|
||||||
|
int32_t metaArrayLen = sizeof(SOffsetAndContLen) * pMsg->dataCount; // <offset, contLen>
|
||||||
|
int32_t entryArrayLen = pMsg->dataLen - metaArrayLen;
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "metaArrayLen", metaArrayLen);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "entryArrayLen", entryArrayLen);
|
||||||
|
|
||||||
|
SOffsetAndContLen* metaArr = (SOffsetAndContLen*)(pMsg->data);
|
||||||
|
|
||||||
|
cJSON* pMetaArr = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "metaArr", pMetaArr);
|
||||||
|
for (int i = 0; i < pMsg->dataCount; ++i) {
|
||||||
|
cJSON* pMeta = cJSON_CreateObject();
|
||||||
|
cJSON_AddNumberToObject(pMeta, "offset", metaArr[i].offset);
|
||||||
|
cJSON_AddNumberToObject(pMeta, "contLen", metaArr[i].contLen);
|
||||||
|
cJSON_AddItemToArray(pMetaArr, pMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pEntryArr = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "entryArr", pEntryArr);
|
||||||
|
for (int i = 0; i < pMsg->dataCount; ++i) {
|
||||||
|
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)(pMsg->data + metaArr[i].offset);
|
||||||
|
cJSON* pEntryJson = syncEntry2Json(pEntry);
|
||||||
|
cJSON_AddItemToArray(pEntryArr, pEntryJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* s;
|
||||||
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SyncAppendEntriesBatch", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg) {
|
||||||
|
cJSON* pJson = syncAppendEntriesBatch2Json(pMsg);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for debug ----------------------
|
||||||
|
void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg) {
|
||||||
|
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
||||||
|
printf("syncAppendEntriesBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg) {
|
||||||
|
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
||||||
|
printf("syncAppendEntriesBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) {
|
||||||
|
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
||||||
|
sTrace("syncAppendEntriesBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
||||||
|
sLTrace("syncAppendEntriesBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* syncSnapshotSend2Json(const SyncSnapshotSend* pMsg) {
|
||||||
|
char u64buf[128];
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pMsg != NULL) {
|
||||||
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
|
|
||||||
|
cJSON* pSrcId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->srcId.addr);
|
||||||
|
cJSON_AddStringToObject(pSrcId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->srcId.addr;
|
||||||
|
cJSON* pTmp = pSrcId;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pSrcId, "vgId", pMsg->srcId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "srcId", pSrcId);
|
||||||
|
|
||||||
|
cJSON* pDestId = cJSON_CreateObject();
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->destId.addr);
|
||||||
|
cJSON_AddStringToObject(pDestId, "addr", u64buf);
|
||||||
|
{
|
||||||
|
uint64_t u64 = pMsg->destId.addr;
|
||||||
|
cJSON* pTmp = pDestId;
|
||||||
|
char host[128];
|
||||||
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(u64, host, sizeof(host), &port);
|
||||||
|
cJSON_AddStringToObject(pTmp, "addr_host", host);
|
||||||
|
cJSON_AddNumberToObject(pTmp, "addr_port", port);
|
||||||
|
}
|
||||||
|
cJSON_AddNumberToObject(pDestId, "vgId", pMsg->destId.vgId);
|
||||||
|
cJSON_AddItemToObject(pRoot, "destId", pDestId);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->startTime);
|
||||||
|
cJSON_AddStringToObject(pRoot, "startTime", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->beginIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "beginIndex", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "lastIndex", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, pMsg->lastConfigIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "lastConfigIndex", u64buf);
|
||||||
|
cJSON_AddItemToObject(pRoot, "lastConfig", syncCfg2Json((SSyncCfg*)&(pMsg->lastConfig)));
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pMsg->lastTerm);
|
||||||
|
cJSON_AddStringToObject(pRoot, "lastTerm", u64buf);
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "seq", pMsg->seq);
|
||||||
|
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
|
char* s;
|
||||||
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SyncSnapshotSend", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncSnapshotSend2Str(const SyncSnapshotSend* pMsg) {
|
||||||
|
cJSON* pJson = syncSnapshotSend2Json(pMsg);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for debug ----------------------
|
||||||
|
void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg) {
|
||||||
|
char* serialized = syncSnapshotSend2Str(pMsg);
|
||||||
|
printf("syncSnapshotSendPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg) {
|
||||||
|
char* serialized = syncSnapshotSend2Str(pMsg);
|
||||||
|
printf("syncSnapshotSendPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncSnapshotSendLog(const SyncSnapshotSend* pMsg) {
|
||||||
|
char* serialized = syncSnapshotSend2Str(pMsg);
|
||||||
|
sTrace("syncSnapshotSendLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = syncSnapshotSend2Str(pMsg);
|
||||||
|
sTrace("syncSnapshotSendLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* syncClientRequestBatch2Json(const SyncClientRequestBatch* pMsg) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pMsg != NULL) {
|
||||||
|
cJSON_AddNumberToObject(pRoot, "bytes", pMsg->bytes);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "vgId", pMsg->vgId);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "msgType", pMsg->msgType);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataLen", pMsg->dataLen);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataCount", pMsg->dataCount);
|
||||||
|
|
||||||
|
SRaftMeta* metaArr = syncClientRequestBatchMetaArr(pMsg);
|
||||||
|
SRpcMsg* msgArr = syncClientRequestBatchRpcMsgArr(pMsg);
|
||||||
|
|
||||||
|
cJSON* pMetaArr = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "metaArr", pMetaArr);
|
||||||
|
for (int i = 0; i < pMsg->dataCount; ++i) {
|
||||||
|
cJSON* pMeta = cJSON_CreateObject();
|
||||||
|
cJSON_AddNumberToObject(pMeta, "seqNum", metaArr[i].seqNum);
|
||||||
|
cJSON_AddNumberToObject(pMeta, "isWeak", metaArr[i].isWeak);
|
||||||
|
cJSON_AddItemToArray(pMetaArr, pMeta);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pMsgArr = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "msgArr", pMsgArr);
|
||||||
|
for (int i = 0; i < pMsg->dataCount; ++i) {
|
||||||
|
cJSON* pRpcMsgJson = syncRpcMsg2Json(&msgArr[i]);
|
||||||
|
cJSON_AddItemToArray(pMsgArr, pRpcMsgJson);
|
||||||
|
}
|
||||||
|
|
||||||
|
char* s;
|
||||||
|
s = syncUtilPrintBin((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
s = syncUtilPrintBin2((char*)(pMsg->data), pMsg->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SyncClientRequestBatch", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncClientRequestBatch2Str(const SyncClientRequestBatch* pMsg) {
|
||||||
|
cJSON* pJson = syncClientRequestBatch2Json(pMsg);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for debug ----------------------
|
||||||
|
void syncClientRequestBatchPrint(const SyncClientRequestBatch* pMsg) {
|
||||||
|
char* serialized = syncClientRequestBatch2Str(pMsg);
|
||||||
|
printf("syncClientRequestBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncClientRequestBatchPrint2(char* s, const SyncClientRequestBatch* pMsg) {
|
||||||
|
char* serialized = syncClientRequestBatch2Str(pMsg);
|
||||||
|
printf("syncClientRequestBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) {
|
||||||
|
char* serialized = syncClientRequestBatch2Str(pMsg);
|
||||||
|
sTrace("syncClientRequestBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = syncClientRequestBatch2Str(pMsg);
|
||||||
|
sLTrace("syncClientRequestBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for debug ----------------------
|
||||||
|
void syncClientRequestPrint(const SyncClientRequest* pMsg) {
|
||||||
|
char* serialized = syncClientRequest2Str(pMsg);
|
||||||
|
printf("syncClientRequestPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) {
|
||||||
|
char* serialized = syncClientRequest2Str(pMsg);
|
||||||
|
printf("syncClientRequestPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncClientRequestLog(const SyncClientRequest* pMsg) {
|
||||||
|
char* serialized = syncClientRequest2Str(pMsg);
|
||||||
|
sTrace("syncClientRequestLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = syncClientRequest2Str(pMsg);
|
||||||
|
sTrace("syncClientRequestLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,19 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,222 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
|
cJSON* syncEntry2Json(const SSyncRaftEntry* pEntry) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pEntry != NULL) {
|
||||||
|
cJSON_AddNumberToObject(pRoot, "bytes", pEntry->bytes);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "msgType", pEntry->msgType);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "originalRpcType", pEntry->originalRpcType);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->seqNum);
|
||||||
|
cJSON_AddStringToObject(pRoot, "seqNum", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "isWeak", pEntry->isWeak);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->term);
|
||||||
|
cJSON_AddStringToObject(pRoot, "term", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->index);
|
||||||
|
cJSON_AddStringToObject(pRoot, "index", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, pEntry->rid);
|
||||||
|
cJSON_AddStringToObject(pRoot, "rid", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "dataLen", pEntry->dataLen);
|
||||||
|
|
||||||
|
char* s;
|
||||||
|
s = syncUtilPrintBin((char*)(pEntry->data), pEntry->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
|
||||||
|
s = syncUtilPrintBin2((char*)(pEntry->data), pEntry->dataLen);
|
||||||
|
cJSON_AddStringToObject(pRoot, "data2", s);
|
||||||
|
taosMemoryFree(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SSyncRaftEntry", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* syncEntry2Str(const SSyncRaftEntry* pEntry) {
|
||||||
|
cJSON* pJson = syncEntry2Json(pEntry);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for debug ----------------------
|
||||||
|
void syncEntryPrint(const SSyncRaftEntry* pObj) {
|
||||||
|
char* serialized = syncEntry2Str(pObj);
|
||||||
|
printf("syncEntryPrint | len:%zu | %s \n", strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncEntryPrint2(char* s, const SSyncRaftEntry* pObj) {
|
||||||
|
char* serialized = syncEntry2Str(pObj);
|
||||||
|
printf("syncEntryPrint2 | len:%zu | %s | %s \n", strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncEntryLog(const SSyncRaftEntry* pObj) {
|
||||||
|
char* serialized = syncEntry2Str(pObj);
|
||||||
|
sTrace("syncEntryLog | len:%zu | %s", strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void syncEntryLog2(char* s, const SSyncRaftEntry* pObj) {
|
||||||
|
char* serialized = syncEntry2Str(pObj);
|
||||||
|
sTrace("syncEntryLog2 | len:%zu | %s | %s", strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------
|
||||||
|
cJSON* raftCache2Json(SRaftEntryHashCache* pCache) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pCache != NULL) {
|
||||||
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "currentCount", pCache->currentCount);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "maxCount", pCache->maxCount);
|
||||||
|
cJSON* pEntries = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "entries", pEntries);
|
||||||
|
|
||||||
|
SSyncRaftEntry* pIter = (SSyncRaftEntry*)taosHashIterate(pCache->pEntryHash, NULL);
|
||||||
|
if (pIter != NULL) {
|
||||||
|
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pIter;
|
||||||
|
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
||||||
|
}
|
||||||
|
while (pIter) {
|
||||||
|
pIter = taosHashIterate(pCache->pEntryHash, pIter);
|
||||||
|
if (pIter != NULL) {
|
||||||
|
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)pIter;
|
||||||
|
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SRaftEntryHashCache", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* raftCache2Str(SRaftEntryHashCache* pCache) {
|
||||||
|
cJSON* pJson = raftCache2Json(pCache);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
void raftCachePrint(SRaftEntryHashCache* pCache) {
|
||||||
|
char* serialized = raftCache2Str(pCache);
|
||||||
|
printf("raftCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void raftCachePrint2(char* s, SRaftEntryHashCache* pCache) {
|
||||||
|
char* serialized = raftCache2Str(pCache);
|
||||||
|
printf("raftCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void raftCacheLog(SRaftEntryHashCache* pCache) {
|
||||||
|
char* serialized = raftCache2Str(pCache);
|
||||||
|
sTrace("raftCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = raftCache2Str(pCache);
|
||||||
|
sLTrace("raftCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* raftEntryCache2Json(SRaftEntryCache* pCache) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pCache != NULL) {
|
||||||
|
taosThreadMutexLock(&pCache->mutex);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pCache->pSyncNode);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "currentCount", pCache->currentCount);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "maxCount", pCache->maxCount);
|
||||||
|
cJSON* pEntries = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "entries", pEntries);
|
||||||
|
|
||||||
|
SSkipListIterator* pIter = tSkipListCreateIter(pCache->pSkipList);
|
||||||
|
while (tSkipListIterNext(pIter)) {
|
||||||
|
SSkipListNode* pNode = tSkipListIterGet(pIter);
|
||||||
|
ASSERT(pNode != NULL);
|
||||||
|
SSyncRaftEntry* pEntry = (SSyncRaftEntry*)SL_GET_NODE_DATA(pNode);
|
||||||
|
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
||||||
|
}
|
||||||
|
tSkipListDestroyIter(pIter);
|
||||||
|
|
||||||
|
taosThreadMutexUnlock(&pCache->mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SRaftEntryCache", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* raftEntryCache2Str(SRaftEntryCache* pObj) {
|
||||||
|
cJSON* pJson = raftEntryCache2Json(pObj);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
void raftEntryCachePrint(SRaftEntryCache* pObj) {
|
||||||
|
char* serialized = raftEntryCache2Str(pObj);
|
||||||
|
printf("raftEntryCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj) {
|
||||||
|
char* serialized = raftEntryCache2Str(pObj);
|
||||||
|
printf("raftEntryCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void raftEntryCacheLog(SRaftEntryCache* pObj) {
|
||||||
|
char* serialized = raftEntryCache2Str(pObj);
|
||||||
|
sTrace("raftEntryCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = raftEntryCache2Str(pObj);
|
||||||
|
sLTrace("raftEntryCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,182 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can use, redistribute, and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License, version 3
|
||||||
|
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define _DEFAULT_SOURCE
|
||||||
|
#include "syncTest.h"
|
||||||
|
|
||||||
|
cJSON* logStore2Json(SSyncLogStore* pLogStore) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pData != NULL && pData->pWal != NULL) {
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
||||||
|
|
||||||
|
SyncIndex beginIndex = raftLogBeginIndex(pLogStore);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "beginIndex", u64buf);
|
||||||
|
|
||||||
|
SyncIndex endIndex = raftLogEndIndex(pLogStore);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "endIndex", u64buf);
|
||||||
|
|
||||||
|
int32_t count = raftLogEntryCount(pLogStore);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "entryCount", count);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore));
|
||||||
|
cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore));
|
||||||
|
cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore));
|
||||||
|
cJSON_AddStringToObject(pRoot, "LastIndex", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore));
|
||||||
|
cJSON_AddStringToObject(pRoot, "LastTerm", u64buf);
|
||||||
|
|
||||||
|
cJSON* pEntries = cJSON_CreateArray();
|
||||||
|
cJSON_AddItemToObject(pRoot, "pEntries", pEntries);
|
||||||
|
|
||||||
|
if (!raftLogIsEmpty(pLogStore)) {
|
||||||
|
for (SyncIndex i = beginIndex; i <= endIndex; ++i) {
|
||||||
|
SSyncRaftEntry* pEntry = NULL;
|
||||||
|
raftLogGetEntry(pLogStore, i, &pEntry);
|
||||||
|
|
||||||
|
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
||||||
|
syncEntryDestory(pEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SSyncLogStore", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* logStore2Str(SSyncLogStore* pLogStore) {
|
||||||
|
cJSON* pJson = logStore2Json(pLogStore);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* logStoreSimple2Json(SSyncLogStore* pLogStore) {
|
||||||
|
char u64buf[128] = {0};
|
||||||
|
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
||||||
|
cJSON* pRoot = cJSON_CreateObject();
|
||||||
|
|
||||||
|
if (pData != NULL && pData->pWal != NULL) {
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pData->pSyncNode);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pSyncNode", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%p", pData->pWal);
|
||||||
|
cJSON_AddStringToObject(pRoot, "pWal", u64buf);
|
||||||
|
|
||||||
|
SyncIndex beginIndex = raftLogBeginIndex(pLogStore);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, beginIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "beginIndex", u64buf);
|
||||||
|
|
||||||
|
SyncIndex endIndex = raftLogEndIndex(pLogStore);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, endIndex);
|
||||||
|
cJSON_AddStringToObject(pRoot, "endIndex", u64buf);
|
||||||
|
|
||||||
|
int32_t count = raftLogEntryCount(pLogStore);
|
||||||
|
cJSON_AddNumberToObject(pRoot, "entryCount", count);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogWriteIndex(pLogStore));
|
||||||
|
cJSON_AddStringToObject(pRoot, "WriteIndex", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%d", raftLogIsEmpty(pLogStore));
|
||||||
|
cJSON_AddStringToObject(pRoot, "IsEmpty", u64buf);
|
||||||
|
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRId64, raftLogLastIndex(pLogStore));
|
||||||
|
cJSON_AddStringToObject(pRoot, "LastIndex", u64buf);
|
||||||
|
snprintf(u64buf, sizeof(u64buf), "%" PRIu64, raftLogLastTerm(pLogStore));
|
||||||
|
cJSON_AddStringToObject(pRoot, "LastTerm", u64buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
cJSON* pJson = cJSON_CreateObject();
|
||||||
|
cJSON_AddItemToObject(pJson, "SSyncLogStoreSimple", pRoot);
|
||||||
|
return pJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* logStoreSimple2Str(SSyncLogStore* pLogStore) {
|
||||||
|
cJSON* pJson = logStoreSimple2Json(pLogStore);
|
||||||
|
char* serialized = cJSON_Print(pJson);
|
||||||
|
cJSON_Delete(pJson);
|
||||||
|
return serialized;
|
||||||
|
}
|
||||||
|
|
||||||
|
// for debug -----------------
|
||||||
|
void logStorePrint(SSyncLogStore* pLogStore) {
|
||||||
|
char* serialized = logStore2Str(pLogStore);
|
||||||
|
printf("logStorePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logStorePrint2(char* s, SSyncLogStore* pLogStore) {
|
||||||
|
char* serialized = logStore2Str(pLogStore);
|
||||||
|
printf("logStorePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logStoreLog(SSyncLogStore* pLogStore) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = logStore2Str(pLogStore);
|
||||||
|
sLTrace("logStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void logStoreLog2(char* s, SSyncLogStore* pLogStore) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = logStore2Str(pLogStore);
|
||||||
|
sLTrace("logStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for debug -----------------
|
||||||
|
void logStoreSimplePrint(SSyncLogStore* pLogStore) {
|
||||||
|
char* serialized = logStoreSimple2Str(pLogStore);
|
||||||
|
printf("logStoreSimplePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) {
|
||||||
|
char* serialized = logStoreSimple2Str(pLogStore);
|
||||||
|
printf("logStoreSimplePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
fflush(NULL);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logStoreSimpleLog(SSyncLogStore* pLogStore) {
|
||||||
|
char* serialized = logStoreSimple2Str(pLogStore);
|
||||||
|
sTrace("logStoreSimpleLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) {
|
||||||
|
if (gRaftDetailLog) {
|
||||||
|
char* serialized = logStoreSimple2Str(pLogStore);
|
||||||
|
sTrace("logStoreSimpleLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
}
|
||||||
|
}
|
|
@ -324,7 +324,7 @@ static void taosGetLogFileName(char *fn) {
|
||||||
bool file2open = taosCheckFileIsOpen(fileName);
|
bool file2open = taosCheckFileIsOpen(fileName);
|
||||||
|
|
||||||
if (!file1open && !file2open) {
|
if (!file1open && !file2open) {
|
||||||
snprintf(tsLogObj.logName, tListLen(tsLogObj.logName), "%s%d", fn, i);
|
snprintf(tsLogObj.logName, LOG_FILE_NAME_LEN, "%s%d", fn, i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -598,7 +598,7 @@ static int32_t taosPushLogBuffer(SLogBuff *pLogBuf, const char *msg, int32_t msg
|
||||||
remainSize = (start > end) ? (start - end - 1) : (start + LOG_BUF_SIZE(pLogBuf) - end - 1);
|
remainSize = (start > end) ? (start - end - 1) : (start + LOG_BUF_SIZE(pLogBuf) - end - 1);
|
||||||
|
|
||||||
if (lostLine > 0) {
|
if (lostLine > 0) {
|
||||||
sprintf(tmpBuf, "...Lost %" PRId64 " lines here...\n", lostLine);
|
snprintf(tmpBuf, tListLen(tmpBuf), "...Lost %" PRId64 " lines here...\n", lostLine);
|
||||||
tmpBufLen = (int32_t)strlen(tmpBuf);
|
tmpBufLen = (int32_t)strlen(tmpBuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,443 +23,516 @@ sql insert into t1 values(1648791223001,2,2,3,1.1);
|
||||||
sql insert into t1 values(1648791233002,3,2,3,2.1);
|
sql insert into t1 values(1648791233002,3,2,3,2.1);
|
||||||
sql insert into t1 values(1648791243003,4,2,3,3.1);
|
sql insert into t1 values(1648791243003,4,2,3,3.1);
|
||||||
sql insert into t1 values(1648791213004,4,2,3,4.1);
|
sql insert into t1 values(1648791213004,4,2,3,4.1);
|
||||||
sleep 1000
|
|
||||||
|
$loop_count = 0
|
||||||
|
|
||||||
|
loop0:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
||||||
|
|
||||||
if $rows != 4 then
|
$loop_count = $loop_count + 1
|
||||||
print ======$rows
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
if $rows != 4 then
|
||||||
|
print =====rows=$rows
|
||||||
|
goto loop0
|
||||||
|
endi
|
||||||
|
|
||||||
# row 0
|
# row 0
|
||||||
if $data01 != 2 then
|
if $data01 != 2 then
|
||||||
print ======$data01
|
print =====data01=$data01
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data02 != 2 then
|
if $data02 != 2 then
|
||||||
print ======$data02
|
print =====data02=$data02
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data03 != 5 then
|
if $data03 != 5 then
|
||||||
print ======$data03
|
print =====data03=$data03
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data04 != 2 then
|
if $data04 != 2 then
|
||||||
print ======$data04
|
print =====data04=$data04
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data05 != 3 then
|
if $data05 != 3 then
|
||||||
print ======$data05
|
print =====data05=$data05
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 1
|
# row 1
|
||||||
if $data11 != 1 then
|
if $data11 != 1 then
|
||||||
print ======$data11
|
print =====data11=$data11
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data12 != 1 then
|
if $data12 != 1 then
|
||||||
print ======$data12
|
print =====data12=$data12
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data13 != 2 then
|
if $data13 != 2 then
|
||||||
print ======$data13
|
print =====data13=$data13
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data14 != 2 then
|
if $data14 != 2 then
|
||||||
print ======$data14
|
print =====data14=$data14
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data15 != 3 then
|
if $data15 != 3 then
|
||||||
print ======$data15
|
print =====data15=$data15
|
||||||
return -1
|
goto loop0
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 2
|
# row 2
|
||||||
if $data21 != 1 then
|
if $data21 != 1 then
|
||||||
print ======$data21
|
print =====data21=$data21
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data22 != 1 then
|
if $data22 != 1 then
|
||||||
print ======$data22
|
print =====data22=$data22
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data23 != 3 then
|
if $data23 != 3 then
|
||||||
print ======$data23
|
print =====data23=$data23
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data24 != 2 then
|
if $data24 != 2 then
|
||||||
print ======$data24
|
print =====data24=$data24
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data25 != 3 then
|
if $data25 != 3 then
|
||||||
print ======$data25
|
print =====data25=$data25
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 3
|
# row 3
|
||||||
if $data31 != 1 then
|
if $data31 != 1 then
|
||||||
print ======$data31
|
print =====data31=$data31
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data32 != 1 then
|
if $data32 != 1 then
|
||||||
print ======$data32
|
print =====data32=$data32
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data33 != 4 then
|
if $data33 != 4 then
|
||||||
print ======$data33
|
print =====data33=$data33
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data34 != 2 then
|
if $data34 != 2 then
|
||||||
print ======$data34
|
print =====data34=$data34
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data35 != 3 then
|
if $data35 != 3 then
|
||||||
print ======$data35
|
print =====data35=$data35
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791223001,12,14,13,11.1);
|
sql insert into t1 values(1648791223001,12,14,13,11.1);
|
||||||
sleep 500
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop1:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
sql select * from streamt;
|
sql select * from streamt;
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 20 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
print count(*) , count(d) , sum(a) , max(b) , min(c)
|
print count(*) , count(d) , sum(a) , max(b) , min(c)
|
||||||
print 0: $data00 , $data01 , $data02 , $data03 , $data04 , $data05
|
print 0: $data00 , $data01 , $data02 , $data03 , $data04 , $data05
|
||||||
print 1: $data10 , $data11 , $data12 , $data13 , $data14 , $data15
|
print 1: $data10 , $data11 , $data12 , $data13 , $data14 , $data15
|
||||||
|
|
||||||
if $rows != 4 then
|
if $rows != 4 then
|
||||||
print ======$rows
|
print ======$rows
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 0
|
# row 0
|
||||||
if $data01 != 2 then
|
if $data01 != 2 then
|
||||||
print ======$data01
|
print =====data01=$data01
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data02 != 2 then
|
if $data02 != 2 then
|
||||||
print ======$data02
|
print =====data02=$data02
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data03 != 5 then
|
if $data03 != 5 then
|
||||||
print ======$data03
|
print =====data03=$data03
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data04 != 2 then
|
if $data04 != 2 then
|
||||||
print ======$data04
|
print =====data04=$data04
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data05 != 3 then
|
if $data05 != 3 then
|
||||||
print ======$data05
|
print =====data05=$data05
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 1
|
# row 1
|
||||||
if $data11 != 1 then
|
if $data11 != 1 then
|
||||||
print ======$data11
|
print =====data11=$data11
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data12 != 1 then
|
if $data12 != 1 then
|
||||||
print ======$data12
|
print =====data12=$data12
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data13 != 12 then
|
if $data13 != 12 then
|
||||||
print ======$data13
|
print =====data13=$data13
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data14 != 14 then
|
if $data14 != 14 then
|
||||||
print ======$data14
|
print =====data14=$data14
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data15 != 13 then
|
if $data15 != 13 then
|
||||||
print ======$data15
|
print =====data15=$data15
|
||||||
return -1
|
goto loop1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 2
|
# row 2
|
||||||
if $data21 != 1 then
|
if $data21 != 1 then
|
||||||
print ======$data21
|
print =====data21=$data21
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data22 != 1 then
|
if $data22 != 1 then
|
||||||
print ======$data22
|
print =====data22=$data22
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data23 != 3 then
|
if $data23 != 3 then
|
||||||
print ======$data23
|
print =====data23=$data23
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data24 != 2 then
|
if $data24 != 2 then
|
||||||
print ======$data24
|
print =====data24=$data24
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data25 != 3 then
|
if $data25 != 3 then
|
||||||
print ======$data25
|
print =====data25=$data25
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 3
|
# row 3
|
||||||
if $data31 != 1 then
|
if $data31 != 1 then
|
||||||
print ======$data31
|
print =====data31=$data31
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data32 != 1 then
|
if $data32 != 1 then
|
||||||
print ======$data32
|
print =====data32=$data32
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data33 != 4 then
|
if $data33 != 4 then
|
||||||
print ======$data33
|
print =====data33=$data33
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data34 != 2 then
|
if $data34 != 2 then
|
||||||
print ======$data34
|
print =====data34=$data34
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data35 != 3 then
|
if $data35 != 3 then
|
||||||
print ======$data35
|
print =====data35=$data35
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791223002,12,14,13,11.1);
|
sql insert into t1 values(1648791223002,12,14,13,11.1);
|
||||||
sleep 100
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop2:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 20 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
# row 1
|
# row 1
|
||||||
if $data11 != 2 then
|
if $data11 != 2 then
|
||||||
print ======$data11
|
print =====data11=$data11
|
||||||
return -1
|
goto loop2
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data12 != 2 then
|
if $data12 != 2 then
|
||||||
print ======$data12
|
print =====data12=$data12
|
||||||
return -1
|
goto loop2
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data13 != 24 then
|
if $data13 != 24 then
|
||||||
print ======$data13
|
print =====data13=$data13
|
||||||
return -1
|
goto loop2
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data14 != 14 then
|
if $data14 != 14 then
|
||||||
print ======$data14
|
print =====data14=$data14
|
||||||
return -1
|
goto loop2
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data15 != 13 then
|
if $data15 != 13 then
|
||||||
print ======$data15
|
print =====data15=$data15
|
||||||
return -1
|
goto loop2
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791223003,12,14,13,11.1);
|
sql insert into t1 values(1648791223003,12,14,13,11.1);
|
||||||
sleep 100
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop3:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 20 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
# row 1
|
# row 1
|
||||||
if $data11 != 3 then
|
if $data11 != 3 then
|
||||||
print ======$data11
|
print =====data11=$data11
|
||||||
return -1
|
goto loop3
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data12 != 3 then
|
if $data12 != 3 then
|
||||||
print ======$data12
|
print =====data12=$data12
|
||||||
return -1
|
goto loop3
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data13 != 36 then
|
if $data13 != 36 then
|
||||||
print ======$data13
|
print =====data13=$data13
|
||||||
return -1
|
goto loop3
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data14 != 14 then
|
if $data14 != 14 then
|
||||||
print ======$data14
|
print =====data14=$data14
|
||||||
return -1
|
goto loop3
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data15 != 13 then
|
if $data15 != 13 then
|
||||||
print ======$data15
|
print =====data15=$data15
|
||||||
return -1
|
goto loop3
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791223001,1,1,1,1.1);
|
sql insert into t1 values(1648791223001,1,1,1,1.1);
|
||||||
sql insert into t1 values(1648791223002,2,2,2,2.1);
|
sql insert into t1 values(1648791223002,2,2,2,2.1);
|
||||||
sql insert into t1 values(1648791223003,3,3,3,3.1);
|
sql insert into t1 values(1648791223003,3,3,3,3.1);
|
||||||
sleep 100
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop4:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 20 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
# row 1
|
# row 1
|
||||||
if $data11 != 3 then
|
if $data11 != 3 then
|
||||||
print ======$data11
|
print =====data11=$data11
|
||||||
return -1
|
goto loop4
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data12 != 3 then
|
if $data12 != 3 then
|
||||||
print ======$data12
|
print =====data12=$data12
|
||||||
return -1
|
goto loop4
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data13 != 6 then
|
if $data13 != 6 then
|
||||||
print ======$data13
|
print =====data13=$data13
|
||||||
return -1
|
goto loop4
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data14 != 3 then
|
if $data14 != 3 then
|
||||||
print ======$data14
|
print =====data14=$data14
|
||||||
return -1
|
goto loop4
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data15 != 1 then
|
if $data15 != 1 then
|
||||||
print ======$data15
|
print =====data15=$data15
|
||||||
return -1
|
goto loop4
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791233003,3,2,3,2.1);
|
sql insert into t1 values(1648791233003,3,2,3,2.1);
|
||||||
sql insert into t1 values(1648791233002,5,6,7,8.1);
|
sql insert into t1 values(1648791233002,5,6,7,8.1);
|
||||||
sql insert into t1 values(1648791233002,3,2,3,2.1);
|
sql insert into t1 values(1648791233002,3,2,3,2.1);
|
||||||
sleep 100
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop5:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 20 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
# row 2
|
# row 2
|
||||||
if $data21 != 2 then
|
if $data21 != 2 then
|
||||||
print ======$data21
|
print =====data21=$data21
|
||||||
return -1
|
goto loop5
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data22 != 2 then
|
if $data22 != 2 then
|
||||||
print ======$data22
|
print =====data22=$data22
|
||||||
return -1
|
goto loop5
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data23 != 6 then
|
if $data23 != 6 then
|
||||||
print ======$data23
|
print =====data23=$data23
|
||||||
return -1
|
goto loop5
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data24 != 2 then
|
if $data24 != 2 then
|
||||||
print ======$data24
|
print =====data24=$data24
|
||||||
return -1
|
goto loop5
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data25 != 3 then
|
if $data25 != 3 then
|
||||||
print ======$data25
|
print =====data25=$data25
|
||||||
return -1
|
goto loop5
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213004,4,2,3,4.1) (1648791213006,5,4,7,9.1) (1648791213004,40,20,30,40.1) (1648791213005,4,2,3,4.1);
|
sql insert into t1 values(1648791213004,4,2,3,4.1) (1648791213006,5,4,7,9.1) (1648791213004,40,20,30,40.1) (1648791213005,4,2,3,4.1);
|
||||||
sleep 100
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop6:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 20 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
# row 0
|
# row 0
|
||||||
if $data01 != 4 then
|
if $data01 != 4 then
|
||||||
print ======$data01
|
print =====data01=$data01
|
||||||
return -1
|
goto loop6
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data02 != 4 then
|
if $data02 != 4 then
|
||||||
print ======$data02
|
print =====data02=$data02
|
||||||
return -1
|
goto loop6
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data03 != 50 then
|
if $data03 != 50 then
|
||||||
print ======$data03 != 50
|
print =====data03=$data03 != 50
|
||||||
return -1
|
goto loop6
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data04 != 20 then
|
if $data04 != 20 then
|
||||||
print ======$data04 != 20
|
print =====data04=$data04 != 20
|
||||||
return -1
|
goto loop6
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data05 != 3 then
|
if $data05 != 3 then
|
||||||
print ======$data05
|
print =====data05=$data05
|
||||||
return -1
|
goto loop6
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791223004,4,2,3,4.1) (1648791233006,5,4,7,9.1) (1648791223004,40,20,30,40.1) (1648791233005,4,2,3,4.1);
|
sql insert into t1 values(1648791223004,4,2,3,4.1) (1648791233006,5,4,7,9.1) (1648791223004,40,20,30,40.1) (1648791233005,4,2,3,4.1);
|
||||||
sleep 100
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop7:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
sql select `_wstart`, c1, c2 ,c3 ,c4, c5 from streamt;
|
||||||
|
|
||||||
|
$loop_count = $loop_count + 1
|
||||||
|
if $loop_count == 20 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
# row 1
|
# row 1
|
||||||
if $data11 != 4 then
|
if $data11 != 4 then
|
||||||
print ======$data11
|
print =====data11=$data11
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data12 != 4 then
|
if $data12 != 4 then
|
||||||
print ======$data12
|
print =====data12=$data12
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data13 != 46 then
|
if $data13 != 46 then
|
||||||
print ======$data13 != 46
|
print =====data13=$data13 != 46
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data14 != 20 then
|
if $data14 != 20 then
|
||||||
print ======$data14 != 20
|
print =====data14=$data14 != 20
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data15 != 1 then
|
if $data15 != 1 then
|
||||||
print ======$data15
|
print =====data15=$data15
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 2
|
# row 2
|
||||||
if $data21 != 4 then
|
if $data21 != 4 then
|
||||||
print ======$data21
|
print =====data21=$data21
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data22 != 4 then
|
if $data22 != 4 then
|
||||||
print ======$data22
|
print =====data22=$data22
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data23 != 15 then
|
if $data23 != 15 then
|
||||||
print ======$data23
|
print =====data23=$data23
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data24 != 4 then
|
if $data24 != 4 then
|
||||||
print ======$data24
|
print =====data24=$data24
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data25 != 3 then
|
if $data25 != 3 then
|
||||||
print ======$data25
|
print =====data25=$data25
|
||||||
return -1
|
goto loop7
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql create database test2 vgroups 1;
|
sql create database test2 vgroups 1;
|
||||||
|
@ -479,11 +552,11 @@ sql insert into t1 values(1648791213000,1,1,1,1.0) t2 values(1648791213000,2,2,2
|
||||||
|
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop0:
|
loop8:
|
||||||
sleep 300
|
sleep 200
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -491,7 +564,7 @@ sql select * from streamt;
|
||||||
|
|
||||||
if $rows != 4 then
|
if $rows != 4 then
|
||||||
print =====rows=$rows
|
print =====rows=$rows
|
||||||
goto loop0
|
goto loop8
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,5,5,5,5.0) t2 values(1648791213000,6,6,6,6.0) t5 values(1648791213000,7,7,7,7.0);
|
sql insert into t1 values(1648791213000,5,5,5,5.0) t2 values(1648791213000,6,6,6,6.0) t5 values(1648791213000,7,7,7,7.0);
|
||||||
|
@ -499,11 +572,11 @@ sql insert into t1 values(1648791213000,5,5,5,5.0) t2 values(1648791213000,6,6,6
|
||||||
|
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop1:
|
loop9:
|
||||||
sleep 300
|
sleep 200
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -511,51 +584,51 @@ sql select * from streamt order by c4 desc;
|
||||||
|
|
||||||
if $rows != 5 then
|
if $rows != 5 then
|
||||||
print =====rows=$rows
|
print =====rows=$rows
|
||||||
goto loop1
|
goto loop9
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 0
|
# row 0
|
||||||
if $data01 != 1 then
|
if $data01 != 1 then
|
||||||
print =====data01=$data01
|
print =====data01=$data01
|
||||||
goto loop1
|
goto loop9
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data02 != 7 then
|
if $data02 != 7 then
|
||||||
print =====data02=$data02
|
print =====data02=$data02
|
||||||
goto loop1
|
goto loop9
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 1
|
# row 1
|
||||||
if $data11 != 1 then
|
if $data11 != 1 then
|
||||||
print =====data11=$data11
|
print =====data11=$data11
|
||||||
goto loop1
|
goto loop9
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data12 != 6 then
|
if $data12 != 6 then
|
||||||
print =====data12=$data12
|
print =====data12=$data12
|
||||||
goto loop1
|
goto loop9
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 2
|
# row 2
|
||||||
if $data21 != 1 then
|
if $data21 != 1 then
|
||||||
print =====data21=$data21
|
print =====data21=$data21
|
||||||
goto loop1
|
goto loop9
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data22 != 5 then
|
if $data22 != 5 then
|
||||||
print =====data22=$data22
|
print =====data22=$data22
|
||||||
goto loop1
|
goto loop9
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,8,8,8,8.0);
|
sql insert into t1 values(1648791213000,8,8,8,8.0);
|
||||||
|
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
|
|
||||||
loop2:
|
loop10:
|
||||||
sleep 300
|
sleep 200
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
@ -564,28 +637,29 @@ sql select * from streamt order by c4 desc;
|
||||||
# row 0
|
# row 0
|
||||||
if $data01 != 1 then
|
if $data01 != 1 then
|
||||||
print =====data01=$data01
|
print =====data01=$data01
|
||||||
goto loop2
|
goto loop10
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $data02 != 8 then
|
if $data02 != 8 then
|
||||||
print =====data02=$data02
|
print =====data02=$data02
|
||||||
goto loop2
|
goto loop10
|
||||||
endi
|
endi
|
||||||
|
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
loop3:
|
loop11:
|
||||||
sleep 300
|
sleep 200
|
||||||
|
|
||||||
|
sql select count(*) from streamt3;
|
||||||
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql select count(*) from streamt3;
|
|
||||||
# row 0
|
# row 0
|
||||||
if $data00 != 5 then
|
if $data00 != 5 then
|
||||||
print =====data00=$data00
|
print =====data00=$data00
|
||||||
goto loop3
|
goto loop11
|
||||||
endi
|
endi
|
||||||
|
|
||||||
#max,min selectivity
|
#max,min selectivity
|
||||||
|
@ -601,25 +675,26 @@ sql insert into ts1 values(1648791222001,2,2,3);
|
||||||
sleep 50
|
sleep 50
|
||||||
|
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
loop3:
|
loop12:
|
||||||
|
sleep 200
|
||||||
|
|
||||||
sql select * from streamtST3;
|
sql select * from streamtST3;
|
||||||
|
|
||||||
sleep 300
|
|
||||||
$loop_count = $loop_count + 1
|
$loop_count = $loop_count + 1
|
||||||
if $loop_count == 10 then
|
if $loop_count == 20 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 0
|
# row 0
|
||||||
if $data02 != 1 then
|
if $data02 != 1 then
|
||||||
print =====data02=$data02
|
print =====data02=$data02
|
||||||
goto loop3
|
goto loop12
|
||||||
endi
|
endi
|
||||||
|
|
||||||
# row 1
|
# row 1
|
||||||
if $data12 != 2 then
|
if $data12 != 2 then
|
||||||
print =====data12=$data12
|
print =====data12=$data12
|
||||||
goto loop3
|
goto loop12
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
@ -629,19 +704,22 @@ sql create table t1(ts timestamp, a int, b int , c int, d double);
|
||||||
sql create stream streams4 trigger at_once into streamt4 as select _wstart, count(*) c1 from t1 where a > 5 interval(10s);
|
sql create stream streams4 trigger at_once into streamt4 as select _wstart, count(*) c1 from t1 where a > 5 interval(10s);
|
||||||
sql insert into t1 values(1648791213000,1,2,3,1.0);
|
sql insert into t1 values(1648791213000,1,2,3,1.0);
|
||||||
|
|
||||||
|
$loop_count = 0
|
||||||
|
loop13:
|
||||||
sleep 200
|
sleep 200
|
||||||
|
|
||||||
sql select * from streamt4;
|
sql select * from streamt4;
|
||||||
|
|
||||||
# row 0
|
# row 0
|
||||||
if $rows != 0 then
|
if $rows != 0 then
|
||||||
print =====rows=$rows
|
print =====rows=$rows
|
||||||
return -1
|
goto loop13
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,6,2,3,1.0);
|
sql insert into t1 values(1648791213000,6,2,3,1.0);
|
||||||
|
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
loop4:
|
loop14:
|
||||||
sleep 200
|
sleep 200
|
||||||
sql select * from streamt4;
|
sql select * from streamt4;
|
||||||
|
|
||||||
|
@ -652,13 +730,13 @@ endi
|
||||||
|
|
||||||
if $data01 != 1 then
|
if $data01 != 1 then
|
||||||
print =====data01=$data01
|
print =====data01=$data01
|
||||||
goto loop4
|
goto loop14
|
||||||
endi
|
endi
|
||||||
|
|
||||||
sql insert into t1 values(1648791213000,2,2,3,1.0);
|
sql insert into t1 values(1648791213000,2,2,3,1.0);
|
||||||
|
|
||||||
$loop_count = 0
|
$loop_count = 0
|
||||||
loop5:
|
loop15:
|
||||||
sleep 200
|
sleep 200
|
||||||
sql select * from streamt4;
|
sql select * from streamt4;
|
||||||
|
|
||||||
|
@ -669,7 +747,7 @@ endi
|
||||||
|
|
||||||
if $rows != 0 then
|
if $rows != 0 then
|
||||||
print =====rows=$rows
|
print =====rows=$rows
|
||||||
goto loop5
|
goto loop15
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,7 @@ if $loop_count == 10 then
|
||||||
endi
|
endi
|
||||||
|
|
||||||
if $rows != 1 then
|
if $rows != 1 then
|
||||||
print ======$rows
|
print =====rows=$rows
|
||||||
goto loop2
|
goto loop2
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
|
@ -118,7 +118,7 @@ step7:
|
||||||
sql select count(*) from db.tb -x step7
|
sql select count(*) from db.tb -x step7
|
||||||
|
|
||||||
print select count(*) from db.tb ==> $data00 $lastRows
|
print select count(*) from db.tb ==> $data00 $lastRows
|
||||||
if $data00 <= $lastRows then
|
if $data00 < $lastRows then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
|
|
@ -76,8 +76,8 @@ python3 ./test.py -f 2-query/count_partition.py
|
||||||
python3 ./test.py -f 2-query/count_partition.py -R
|
python3 ./test.py -f 2-query/count_partition.py -R
|
||||||
python3 ./test.py -f 2-query/count.py
|
python3 ./test.py -f 2-query/count.py
|
||||||
python3 ./test.py -f 2-query/count.py -R
|
python3 ./test.py -f 2-query/count.py -R
|
||||||
# python3 ./test.py -f 2-query/countAlwaysReturnValue.py
|
python3 ./test.py -f 2-query/countAlwaysReturnValue.py
|
||||||
# python3 ./test.py -f 2-query/countAlwaysReturnValue.py -R
|
python3 ./test.py -f 2-query/countAlwaysReturnValue.py -R
|
||||||
python3 ./test.py -f 2-query/db.py
|
python3 ./test.py -f 2-query/db.py
|
||||||
python3 ./test.py -f 2-query/db.py -R
|
python3 ./test.py -f 2-query/db.py -R
|
||||||
python3 ./test.py -f 2-query/diff.py
|
python3 ./test.py -f 2-query/diff.py
|
||||||
|
@ -393,7 +393,7 @@ python3 ./test.py -f 2-query/max.py -Q 2
|
||||||
python3 ./test.py -f 2-query/min.py -Q 2
|
python3 ./test.py -f 2-query/min.py -Q 2
|
||||||
python3 ./test.py -f 2-query/mode.py -Q 2
|
python3 ./test.py -f 2-query/mode.py -Q 2
|
||||||
python3 ./test.py -f 2-query/count.py -Q 2
|
python3 ./test.py -f 2-query/count.py -Q 2
|
||||||
# python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 2
|
python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 2
|
||||||
python3 ./test.py -f 2-query/last.py -Q 2
|
python3 ./test.py -f 2-query/last.py -Q 2
|
||||||
python3 ./test.py -f 2-query/first.py -Q 2
|
python3 ./test.py -f 2-query/first.py -Q 2
|
||||||
python3 ./test.py -f 2-query/To_iso8601.py -Q 2
|
python3 ./test.py -f 2-query/To_iso8601.py -Q 2
|
||||||
|
@ -490,7 +490,7 @@ python3 ./test.py -f 2-query/max.py -Q 3
|
||||||
python3 ./test.py -f 2-query/min.py -Q 3
|
python3 ./test.py -f 2-query/min.py -Q 3
|
||||||
python3 ./test.py -f 2-query/mode.py -Q 3
|
python3 ./test.py -f 2-query/mode.py -Q 3
|
||||||
python3 ./test.py -f 2-query/count.py -Q 3
|
python3 ./test.py -f 2-query/count.py -Q 3
|
||||||
# python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 3
|
python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 3
|
||||||
python3 ./test.py -f 2-query/last.py -Q 3
|
python3 ./test.py -f 2-query/last.py -Q 3
|
||||||
python3 ./test.py -f 2-query/first.py -Q 3
|
python3 ./test.py -f 2-query/first.py -Q 3
|
||||||
python3 ./test.py -f 2-query/To_iso8601.py -Q 3
|
python3 ./test.py -f 2-query/To_iso8601.py -Q 3
|
||||||
|
@ -589,7 +589,7 @@ python3 ./test.py -f 2-query/max.py -Q 4
|
||||||
python3 ./test.py -f 2-query/min.py -Q 4
|
python3 ./test.py -f 2-query/min.py -Q 4
|
||||||
python3 ./test.py -f 2-query/mode.py -Q 4
|
python3 ./test.py -f 2-query/mode.py -Q 4
|
||||||
python3 ./test.py -f 2-query/count.py -Q 4
|
python3 ./test.py -f 2-query/count.py -Q 4
|
||||||
# python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 4
|
python3 ./test.py -f 2-query/countAlwaysReturnValue.py -Q 4
|
||||||
python3 ./test.py -f 2-query/last.py -Q 4
|
python3 ./test.py -f 2-query/last.py -Q 4
|
||||||
python3 ./test.py -f 2-query/first.py -Q 4
|
python3 ./test.py -f 2-query/first.py -Q 4
|
||||||
python3 ./test.py -f 2-query/To_iso8601.py -Q 4
|
python3 ./test.py -f 2-query/To_iso8601.py -Q 4
|
||||||
|
|
Loading…
Reference in New Issue