Merge branch '3.0' into fix/liao_cov
This commit is contained in:
commit
b06870f70f
|
@ -128,3 +128,4 @@ tools/NEWS
|
||||||
tools/COPYING
|
tools/COPYING
|
||||||
tools/BUGS
|
tools/BUGS
|
||||||
tools/taos-tools
|
tools/taos-tools
|
||||||
|
tools/taosws-rs
|
||||||
|
|
|
@ -1234,20 +1234,20 @@ int32_t tSerializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq*
|
||||||
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
|
int32_t tDeserializeSCompactVnodeReq(void* buf, int32_t bufLen, SCompactVnodeReq* pReq);
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t vgVersion;
|
int32_t vgVersion;
|
||||||
int32_t buffer;
|
int32_t buffer;
|
||||||
int32_t pageSize;
|
int32_t pageSize;
|
||||||
int32_t pages;
|
int32_t pages;
|
||||||
int32_t cacheLastSize;
|
int32_t cacheLastSize;
|
||||||
int32_t daysPerFile;
|
int32_t daysPerFile;
|
||||||
int32_t daysToKeep0;
|
int32_t daysToKeep0;
|
||||||
int32_t daysToKeep1;
|
int32_t daysToKeep1;
|
||||||
int32_t daysToKeep2;
|
int32_t daysToKeep2;
|
||||||
int32_t walFsyncPeriod;
|
int32_t walFsyncPeriod;
|
||||||
int8_t walLevel;
|
int8_t walLevel;
|
||||||
int8_t strict;
|
int8_t strict;
|
||||||
int8_t cacheLast;
|
int8_t cacheLast;
|
||||||
int64_t reserved[8];
|
int64_t reserved[8];
|
||||||
} SAlterVnodeConfigReq;
|
} SAlterVnodeConfigReq;
|
||||||
|
|
||||||
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
|
int32_t tSerializeSAlterVnodeConfigReq(void* buf, int32_t bufLen, SAlterVnodeConfigReq* pReq);
|
||||||
|
@ -3065,7 +3065,7 @@ static FORCE_INLINE void* tDecodeSMqAskEpRsp(void* buf, SMqAskEpRsp* pRsp) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
|
static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
|
||||||
taosArrayDestroyEx(pRsp->topics, (void (*)(void*))tDeleteSMqSubTopicEp);
|
taosArrayDestroyEx(pRsp->topics, (FDelete)tDeleteSMqSubTopicEp);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TD_AUTO_CREATE_TABLE 0x1
|
#define TD_AUTO_CREATE_TABLE 0x1
|
||||||
|
|
|
@ -340,7 +340,7 @@ typedef struct tDataTypeDescriptor {
|
||||||
} tDataTypeDescriptor;
|
} tDataTypeDescriptor;
|
||||||
|
|
||||||
extern tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX];
|
extern tDataTypeDescriptor tDataTypes[TSDB_DATA_TYPE_MAX];
|
||||||
bool isValidDataType(int32_t type);
|
bool isValidDataType(int32_t type);
|
||||||
|
|
||||||
void assignVal(char *val, const char *src, int32_t len, int32_t type);
|
void assignVal(char *val, const char *src, int32_t len, int32_t type);
|
||||||
void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type);
|
void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type);
|
||||||
|
|
|
@ -99,6 +99,7 @@ int32_t mndGetLoad(SMnode *pMnode, SMnodeLoad *pLoad);
|
||||||
*/
|
*/
|
||||||
int32_t mndProcessRpcMsg(SRpcMsg *pMsg);
|
int32_t mndProcessRpcMsg(SRpcMsg *pMsg);
|
||||||
int32_t mndProcessSyncMsg(SRpcMsg *pMsg);
|
int32_t mndProcessSyncMsg(SRpcMsg *pMsg);
|
||||||
|
int32_t mndProcessSyncCtrlMsg(SRpcMsg *pMsg);
|
||||||
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg);
|
int32_t mndPreProcessQueryMsg(SRpcMsg *pMsg);
|
||||||
void mndPostProcessQueryMsg(SRpcMsg *pMsg);
|
void mndPostProcessQueryMsg(SRpcMsg *pMsg);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,12 @@ extern bool gRaftDetailLog;
|
||||||
#define SYNC_MAX_PROGRESS_WAIT_MS 4000
|
#define SYNC_MAX_PROGRESS_WAIT_MS 4000
|
||||||
#define SYNC_MAX_START_TIME_RANGE_MS (1000 * 20)
|
#define SYNC_MAX_START_TIME_RANGE_MS (1000 * 20)
|
||||||
#define SYNC_MAX_RECV_TIME_RANGE_MS 1200
|
#define SYNC_MAX_RECV_TIME_RANGE_MS 1200
|
||||||
|
#define SYNC_DEL_WAL_MS (1000 * 60)
|
||||||
#define SYNC_ADD_QUORUM_COUNT 3
|
#define SYNC_ADD_QUORUM_COUNT 3
|
||||||
|
#define SYNC_MNODE_LOG_RETENTION 10000
|
||||||
|
#define SYNC_VNODE_LOG_RETENTION 500
|
||||||
|
|
||||||
|
#define SYNC_APPEND_ENTRIES_TIMEOUT_MS 10000
|
||||||
|
|
||||||
#define SYNC_MAX_BATCH_SIZE 1
|
#define SYNC_MAX_BATCH_SIZE 1
|
||||||
#define SYNC_INDEX_BEGIN 0
|
#define SYNC_INDEX_BEGIN 0
|
||||||
|
@ -157,32 +162,15 @@ typedef struct SSyncLogStore {
|
||||||
SLRUCache* pCache;
|
SLRUCache* pCache;
|
||||||
void* data;
|
void* data;
|
||||||
|
|
||||||
// append one log entry
|
int32_t (*syncLogUpdateCommitIndex)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
||||||
int32_t (*appendEntry)(struct SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
|
SyncIndex (*syncLogCommitIndex)(struct SSyncLogStore* pLogStore);
|
||||||
|
|
||||||
// get one log entry, user need to free pEntry->pCont
|
|
||||||
SSyncRaftEntry* (*getEntry)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
|
||||||
|
|
||||||
// truncate log with index, entries after the given index (>=index) will be deleted
|
|
||||||
int32_t (*truncate)(struct SSyncLogStore* pLogStore, SyncIndex fromIndex);
|
|
||||||
|
|
||||||
// return index of last entry
|
|
||||||
SyncIndex (*getLastIndex)(struct SSyncLogStore* pLogStore);
|
|
||||||
|
|
||||||
// return term of last entry
|
|
||||||
SyncTerm (*getLastTerm)(struct SSyncLogStore* pLogStore);
|
|
||||||
|
|
||||||
// update log store commit index with "index"
|
|
||||||
int32_t (*updateCommitIndex)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
|
||||||
|
|
||||||
// return commit index of log
|
|
||||||
SyncIndex (*getCommitIndex)(struct SSyncLogStore* pLogStore);
|
|
||||||
|
|
||||||
SyncIndex (*syncLogBeginIndex)(struct SSyncLogStore* pLogStore);
|
SyncIndex (*syncLogBeginIndex)(struct SSyncLogStore* pLogStore);
|
||||||
SyncIndex (*syncLogEndIndex)(struct SSyncLogStore* pLogStore);
|
SyncIndex (*syncLogEndIndex)(struct SSyncLogStore* pLogStore);
|
||||||
bool (*syncLogIsEmpty)(struct SSyncLogStore* pLogStore);
|
|
||||||
int32_t (*syncLogEntryCount)(struct SSyncLogStore* pLogStore);
|
int32_t (*syncLogEntryCount)(struct SSyncLogStore* pLogStore);
|
||||||
int32_t (*syncLogRestoreFromSnapshot)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
int32_t (*syncLogRestoreFromSnapshot)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
||||||
|
bool (*syncLogIsEmpty)(struct SSyncLogStore* pLogStore);
|
||||||
bool (*syncLogExist)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
bool (*syncLogExist)(struct SSyncLogStore* pLogStore, SyncIndex index);
|
||||||
|
|
||||||
SyncIndex (*syncLogWriteIndex)(struct SSyncLogStore* pLogStore);
|
SyncIndex (*syncLogWriteIndex)(struct SSyncLogStore* pLogStore);
|
||||||
|
@ -207,6 +195,7 @@ typedef struct SSyncInfo {
|
||||||
SMsgCb* msgcb;
|
SMsgCb* msgcb;
|
||||||
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||||
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
|
int32_t (*FpEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
} SSyncInfo;
|
} SSyncInfo;
|
||||||
|
|
||||||
int32_t syncInit();
|
int32_t syncInit();
|
||||||
|
@ -217,7 +206,6 @@ void syncStop(int64_t rid);
|
||||||
int32_t syncSetStandby(int64_t rid);
|
int32_t syncSetStandby(int64_t rid);
|
||||||
ESyncState syncGetMyRole(int64_t rid);
|
ESyncState syncGetMyRole(int64_t rid);
|
||||||
bool syncIsReady(int64_t rid);
|
bool syncIsReady(int64_t rid);
|
||||||
bool syncIsReadyForRead(int64_t rid);
|
|
||||||
const char* syncGetMyRoleStr(int64_t rid);
|
const char* syncGetMyRoleStr(int64_t rid);
|
||||||
bool syncRestoreFinish(int64_t rid);
|
bool syncRestoreFinish(int64_t rid);
|
||||||
SyncTerm syncGetMyTerm(int64_t rid);
|
SyncTerm syncGetMyTerm(int64_t rid);
|
||||||
|
@ -227,7 +215,7 @@ SyncGroupId syncGetVgId(int64_t rid);
|
||||||
void syncGetEpSet(int64_t rid, SEpSet* pEpSet);
|
void syncGetEpSet(int64_t rid, SEpSet* pEpSet);
|
||||||
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet);
|
void syncGetRetryEpSet(int64_t rid, SEpSet* pEpSet);
|
||||||
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak);
|
int32_t syncPropose(int64_t rid, SRpcMsg* pMsg, bool isWeak);
|
||||||
int32_t syncProposeBatch(int64_t rid, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize);
|
// int32_t syncProposeBatch(int64_t rid, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize);
|
||||||
bool syncEnvIsStart();
|
bool syncEnvIsStart();
|
||||||
const char* syncStr(ESyncState state);
|
const char* syncStr(ESyncState state);
|
||||||
bool syncIsRestoreFinish(int64_t rid);
|
bool syncIsRestoreFinish(int64_t rid);
|
||||||
|
@ -241,6 +229,9 @@ int32_t syncReconfigBuild(int64_t rid, const SSyncCfg* pNewCfg, SRpcMsg* pRpcMsg
|
||||||
int32_t syncLeaderTransfer(int64_t rid);
|
int32_t syncLeaderTransfer(int64_t rid);
|
||||||
int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader);
|
int32_t syncLeaderTransferTo(int64_t rid, SNodeInfo newLeader);
|
||||||
|
|
||||||
|
int32_t syncBeginSnapshot(int64_t rid, int64_t lastApplyIndex);
|
||||||
|
int32_t syncEndSnapshot(int64_t rid);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -157,6 +157,8 @@ typedef enum ESyncTimeoutType {
|
||||||
SYNC_TIMEOUT_HEARTBEAT,
|
SYNC_TIMEOUT_HEARTBEAT,
|
||||||
} ESyncTimeoutType;
|
} ESyncTimeoutType;
|
||||||
|
|
||||||
|
const char* syncTimerTypeStr(enum ESyncTimeoutType timerType);
|
||||||
|
|
||||||
typedef struct SyncTimeout {
|
typedef struct SyncTimeout {
|
||||||
uint32_t bytes;
|
uint32_t bytes;
|
||||||
int32_t vgId;
|
int32_t vgId;
|
||||||
|
@ -423,6 +425,7 @@ typedef struct SyncAppendEntriesReply {
|
||||||
SyncTerm privateTerm;
|
SyncTerm privateTerm;
|
||||||
bool success;
|
bool success;
|
||||||
SyncIndex matchIndex;
|
SyncIndex matchIndex;
|
||||||
|
SyncIndex lastSendIndex;
|
||||||
int64_t startTime;
|
int64_t startTime;
|
||||||
} SyncAppendEntriesReply;
|
} SyncAppendEntriesReply;
|
||||||
|
|
||||||
|
@ -456,6 +459,8 @@ typedef struct SyncHeartbeat {
|
||||||
SyncTerm term;
|
SyncTerm term;
|
||||||
SyncIndex commitIndex;
|
SyncIndex commitIndex;
|
||||||
SyncTerm privateTerm;
|
SyncTerm privateTerm;
|
||||||
|
SyncTerm minMatchIndex;
|
||||||
|
|
||||||
} SyncHeartbeat;
|
} SyncHeartbeat;
|
||||||
|
|
||||||
SyncHeartbeat* syncHeartbeatBuild(int32_t vgId);
|
SyncHeartbeat* syncHeartbeatBuild(int32_t vgId);
|
||||||
|
@ -676,24 +681,17 @@ void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg);
|
||||||
// on message ----------------------
|
// on message ----------------------
|
||||||
int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg);
|
int32_t syncNodeOnPingCb(SSyncNode* ths, SyncPing* pMsg);
|
||||||
int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg);
|
int32_t syncNodeOnPingReplyCb(SSyncNode* ths, SyncPingReply* pMsg);
|
||||||
int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg);
|
int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg);
|
||||||
int32_t syncNodeOnClientRequestCb(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex);
|
|
||||||
int32_t syncNodeOnClientRequestBatchCb(SSyncNode* ths, SyncClientRequestBatch* pMsg);
|
|
||||||
int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg);
|
|
||||||
int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
|
||||||
int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg);
|
|
||||||
int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
|
||||||
|
|
||||||
int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg);
|
int32_t syncNodeOnHeartbeat(SSyncNode* ths, SyncHeartbeat* pMsg);
|
||||||
int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
int32_t syncNodeOnHeartbeatReply(SSyncNode* ths, SyncHeartbeatReply* pMsg);
|
||||||
int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMsg);
|
int32_t syncNodeOnClientRequest(SSyncNode* ths, SyncClientRequest* pMsg, SyncIndex* pRetIndex);
|
||||||
int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg);
|
||||||
|
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||||
int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatch* pMsg);
|
int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||||
int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||||
|
int32_t syncNodeOnSnapshot(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
||||||
int32_t syncNodeOnSnapshotSendCb(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
int32_t syncNodeOnSnapshotReply(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
||||||
int32_t syncNodeOnSnapshotRspCb(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);
|
||||||
|
@ -707,8 +705,8 @@ typedef int32_t (*FpOnRequestVoteReplyCb)(SSyncNode* ths, SyncRequestVoteReply*
|
||||||
typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg);
|
typedef int32_t (*FpOnAppendEntriesCb)(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||||
typedef int32_t (*FpOnAppendEntriesReplyCb)(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
typedef int32_t (*FpOnAppendEntriesReplyCb)(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||||
typedef int32_t (*FpOnTimeoutCb)(SSyncNode* pSyncNode, SyncTimeout* pMsg);
|
typedef int32_t (*FpOnTimeoutCb)(SSyncNode* pSyncNode, SyncTimeout* pMsg);
|
||||||
typedef int32_t (*FpOnSnapshotSendCb)(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
typedef int32_t (*FpOnSnapshotCb)(SSyncNode* ths, SyncSnapshotSend* pMsg);
|
||||||
typedef int32_t (*FpOnSnapshotRspCb)(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
typedef int32_t (*FpOnSnapshotReplyCb)(SSyncNode* ths, SyncSnapshotRsp* pMsg);
|
||||||
|
|
||||||
// option ----------------------------------
|
// option ----------------------------------
|
||||||
bool syncNodeSnapshotEnable(SSyncNode* pSyncNode);
|
bool syncNodeSnapshotEnable(SSyncNode* pSyncNode);
|
||||||
|
|
|
@ -118,6 +118,7 @@ function kill_taosd() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function install_include() {
|
function install_include() {
|
||||||
|
${csudo}mkdir -p ${inc_link_dir}
|
||||||
${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/taosudf.h || :
|
${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h ${inc_link_dir}/taosudf.h || :
|
||||||
[ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h ||:
|
[ -f ${inc_link_dir}/taosws.h ] && ${csudo}rm -f ${inc_link_dir}/taosws.h ||:
|
||||||
|
|
||||||
|
|
|
@ -46,38 +46,38 @@ int32_t genericRspCallback(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
|
|
||||||
int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
SRequestObj* pRequest = param;
|
SRequestObj* pRequest = param;
|
||||||
|
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
taosMemoryFree(pMsg->pEpSet);
|
|
||||||
taosMemoryFree(pMsg->pData);
|
|
||||||
setErrno(pRequest, code);
|
setErrno(pRequest, code);
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return code;
|
goto End;
|
||||||
}
|
}
|
||||||
|
|
||||||
STscObj* pTscObj = pRequest->pTscObj;
|
STscObj* pTscObj = pRequest->pTscObj;
|
||||||
|
|
||||||
SConnectRsp connectRsp = {0};
|
SConnectRsp connectRsp = {0};
|
||||||
tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp);
|
if (tDeserializeSConnectRsp(pMsg->pData, pMsg->len, &connectRsp) != 0) {
|
||||||
|
code = TSDB_CODE_TSC_INVALID_VERSION;
|
||||||
|
setErrno(pRequest, code);
|
||||||
|
tsem_post(&pRequest->body.rspSem);
|
||||||
|
goto End;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t now = taosGetTimestampSec();
|
int32_t now = taosGetTimestampSec();
|
||||||
int32_t delta = abs(now - connectRsp.svrTimestamp);
|
int32_t delta = abs(now - connectRsp.svrTimestamp);
|
||||||
if (delta > timestampDeltaLimit) {
|
if (delta > timestampDeltaLimit) {
|
||||||
code = TSDB_CODE_TIME_UNSYNCED;
|
code = TSDB_CODE_TIME_UNSYNCED;
|
||||||
tscError("time diff:%ds is too big", delta);
|
tscError("time diff:%ds is too big", delta);
|
||||||
taosMemoryFree(pMsg->pEpSet);
|
|
||||||
taosMemoryFree(pMsg->pData);
|
|
||||||
setErrno(pRequest, code);
|
setErrno(pRequest, code);
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return code;
|
goto End;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*assert(connectRsp.epSet.numOfEps > 0);*/
|
/*assert(connectRsp.epSet.numOfEps > 0);*/
|
||||||
if (connectRsp.epSet.numOfEps == 0) {
|
if (connectRsp.epSet.numOfEps == 0) {
|
||||||
taosMemoryFree(pMsg->pEpSet);
|
|
||||||
taosMemoryFree(pMsg->pData);
|
|
||||||
setErrno(pRequest, TSDB_CODE_MND_APP_ERROR);
|
setErrno(pRequest, TSDB_CODE_MND_APP_ERROR);
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return code;
|
goto End;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connectRsp.dnodeNum == 1) {
|
if (connectRsp.dnodeNum == 1) {
|
||||||
|
@ -113,14 +113,15 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
|
|
||||||
hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType);
|
hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType);
|
||||||
|
|
||||||
// pRequest->body.resInfo.pRspMsg = pMsg->pData;
|
|
||||||
tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId,
|
tscDebug("0x%" PRIx64 " clusterId:%" PRId64 ", totalConn:%" PRId64, pRequest->requestId, connectRsp.clusterId,
|
||||||
pTscObj->pAppInfo->numOfConns);
|
pTscObj->pAppInfo->numOfConns);
|
||||||
|
|
||||||
taosMemoryFree(pMsg->pData);
|
|
||||||
taosMemoryFree(pMsg->pEpSet);
|
|
||||||
tsem_post(&pRequest->body.rspSem);
|
tsem_post(&pRequest->body.rspSem);
|
||||||
return 0;
|
End:
|
||||||
|
|
||||||
|
taosMemoryFree(pMsg->pEpSet);
|
||||||
|
taosMemoryFree(pMsg->pData);
|
||||||
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) {
|
SMsgSendInfo* buildMsgInfoImpl(SRequestObj* pRequest) {
|
||||||
|
@ -194,7 +195,7 @@ int32_t processUseDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
SUseDbRsp usedbRsp = {0};
|
SUseDbRsp usedbRsp = {0};
|
||||||
tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
|
tDeserializeSUseDbRsp(pMsg->pData, pMsg->len, &usedbRsp);
|
||||||
|
|
||||||
if(strlen(usedbRsp.db) == 0){
|
if (strlen(usedbRsp.db) == 0) {
|
||||||
return TSDB_CODE_MND_DB_NOT_EXIST;
|
return TSDB_CODE_MND_DB_NOT_EXIST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,7 +293,7 @@ int32_t processDropDbRsp(void* param, SDataBuf* pMsg, int32_t code) {
|
||||||
tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp);
|
tDeserializeSDropDbRsp(pMsg->pData, pMsg->len, &dropdbRsp);
|
||||||
|
|
||||||
struct SCatalog* pCatalog = NULL;
|
struct SCatalog* pCatalog = NULL;
|
||||||
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
int32_t code = catalogGetHandle(pRequest->pTscObj->pAppInfo->clusterId, &pCatalog);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid);
|
catalogRemoveDB(pCatalog, dropdbRsp.db, dropdbRsp.uid);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2394,7 +2394,7 @@ static int32_t smlParseLine(SSmlHandle *info, char *lines[], char* rawLine, char
|
||||||
code = smlParseJSON(info, rawLine);
|
code = smlParseJSON(info, rawLine);
|
||||||
}
|
}
|
||||||
if (code != TSDB_CODE_SUCCESS) {
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
uError("SML:0x%" PRIx64 " smlParseJSON failed:%s", info->id, *lines);
|
uError("SML:0x%" PRIx64 " smlParseJSON failed:%s", info->id, lines?*lines:rawLine);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
|
|
|
@ -1206,7 +1206,7 @@ CREATE_MSG_FAIL:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, SMqAskEpRsp* pRsp) {
|
bool tmqUpdateEp(tmq_t* tmq, int32_t epoch, const SMqAskEpRsp* pRsp) {
|
||||||
bool set = false;
|
bool set = false;
|
||||||
|
|
||||||
int32_t topicNumGet = taosArrayGetSize(pRsp->topics);
|
int32_t topicNumGet = taosArrayGetSize(pRsp->topics);
|
||||||
|
@ -1599,6 +1599,7 @@ int32_t tmqHandleNoPollRsp(tmq_t* tmq, SMqRspWrapper* rspWrapper, bool* pReset)
|
||||||
SMqAskEpRsp* rspMsg = &pEpRspWrapper->msg;
|
SMqAskEpRsp* rspMsg = &pEpRspWrapper->msg;
|
||||||
tmqUpdateEp(tmq, rspWrapper->epoch, rspMsg);
|
tmqUpdateEp(tmq, rspWrapper->epoch, rspMsg);
|
||||||
/*tmqClearUnhandleMsg(tmq);*/
|
/*tmqClearUnhandleMsg(tmq);*/
|
||||||
|
tDeleteSMqAskEpRsp(rspMsg);
|
||||||
*pReset = true;
|
*pReset = true;
|
||||||
} else {
|
} else {
|
||||||
*pReset = false;
|
*pReset = false;
|
||||||
|
|
|
@ -73,8 +73,8 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqConfDestroyImp
|
||||||
if (conf == NULL) {
|
if (conf == NULL) {
|
||||||
jniDebug("jobj:%p, tmq config is already destroyed", jobj);
|
jniDebug("jobj:%p, tmq config is already destroyed", jobj);
|
||||||
} else {
|
} else {
|
||||||
tmq_conf_destroy(conf);
|
|
||||||
jniDebug("jobj:%p, config:%p, tmq successfully destroy config", jobj, conf);
|
jniDebug("jobj:%p, config:%p, tmq successfully destroy config", jobj, conf);
|
||||||
|
tmq_conf_destroy(conf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +206,7 @@ JNIEXPORT void JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqCommitAsync(JN
|
||||||
tmq_t *tmq = (tmq_t *)jtmq;
|
tmq_t *tmq = (tmq_t *)jtmq;
|
||||||
if (tmq == NULL) {
|
if (tmq == NULL) {
|
||||||
jniError("jobj:%p, tmq is closed", jobj);
|
jniError("jobj:%p, tmq is closed", jobj);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
TAOS_RES *res = (TAOS_RES *)jres;
|
TAOS_RES *res = (TAOS_RES *)jres;
|
||||||
consumer = (*env)->NewGlobalRef(env, consumer);
|
consumer = (*env)->NewGlobalRef(env, consumer);
|
||||||
|
@ -252,6 +253,7 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTopicNam
|
||||||
TAOS_RES *res = (TAOS_RES *)jres;
|
TAOS_RES *res = (TAOS_RES *)jres;
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
jniDebug("jobj:%p, invalid res handle", jobj);
|
jniDebug("jobj:%p, invalid res handle", jobj);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return (*env)->NewStringUTF(env, tmq_get_topic_name(res));
|
return (*env)->NewStringUTF(env, tmq_get_topic_name(res));
|
||||||
}
|
}
|
||||||
|
@ -259,6 +261,7 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetDbName(J
|
||||||
TAOS_RES *res = (TAOS_RES *)jres;
|
TAOS_RES *res = (TAOS_RES *)jres;
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
jniDebug("jobj:%p, invalid res handle", jobj);
|
jniDebug("jobj:%p, invalid res handle", jobj);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return (*env)->NewStringUTF(env, tmq_get_db_name(res));
|
return (*env)->NewStringUTF(env, tmq_get_db_name(res));
|
||||||
}
|
}
|
||||||
|
@ -266,6 +269,7 @@ JNIEXPORT jint JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetVgroupId(JN
|
||||||
TAOS_RES *res = (TAOS_RES *)jres;
|
TAOS_RES *res = (TAOS_RES *)jres;
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
jniDebug("jobj:%p, invalid res handle", jobj);
|
jniDebug("jobj:%p, invalid res handle", jobj);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
return tmq_get_vgroup_id(res);
|
return tmq_get_vgroup_id(res);
|
||||||
}
|
}
|
||||||
|
@ -275,6 +279,7 @@ JNIEXPORT jstring JNICALL Java_com_taosdata_jdbc_tmq_TMQConnector_tmqGetTableNam
|
||||||
TAOS_RES *res = (TAOS_RES *)jres;
|
TAOS_RES *res = (TAOS_RES *)jres;
|
||||||
if (res == NULL) {
|
if (res == NULL) {
|
||||||
jniDebug("jobj:%p, invalid res handle", jobj);
|
jniDebug("jobj:%p, invalid res handle", jobj);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
return (*env)->NewStringUTF(env, tmq_get_table_name(res));
|
return (*env)->NewStringUTF(env, tmq_get_table_name(res));
|
||||||
}
|
}
|
||||||
|
|
|
@ -2030,21 +2030,24 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB
|
||||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, true,
|
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var, true,
|
||||||
offset, k);
|
offset, k);
|
||||||
|
|
||||||
|
} else if (colDataIsNull_s(pColInfoData, j)) {
|
||||||
|
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NULL, NULL,
|
||||||
|
false, offset, k);
|
||||||
} else {
|
} else {
|
||||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var,
|
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_TIMESTAMP, TD_VTYPE_NORM, var,
|
||||||
true, offset, k);
|
true, offset, k);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_NCHAR: {
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
void* data = colDataGetData(pColInfoData, j);
|
|
||||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_NCHAR, TD_VTYPE_NORM, data, true,
|
|
||||||
offset, k);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY
|
case TSDB_DATA_TYPE_VARCHAR: { // TSDB_DATA_TYPE_BINARY
|
||||||
void* data = colDataGetData(pColInfoData, j);
|
if (colDataIsNull_s(pColInfoData, j)) {
|
||||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, TSDB_DATA_TYPE_VARCHAR, TD_VTYPE_NORM, data, true,
|
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pColInfoData->info.type, TD_VTYPE_NULL, NULL,
|
||||||
offset, k);
|
false, offset, k);
|
||||||
|
} else {
|
||||||
|
void* data = colDataGetData(pColInfoData, j);
|
||||||
|
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pColInfoData->info.type, TD_VTYPE_NORM, data,
|
||||||
|
true, offset, k);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TSDB_DATA_TYPE_VARBINARY:
|
case TSDB_DATA_TYPE_VARBINARY:
|
||||||
|
@ -2057,7 +2060,10 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SSDataBlock* pDataB
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) {
|
if (pColInfoData->info.type < TSDB_DATA_TYPE_MAX && pColInfoData->info.type > TSDB_DATA_TYPE_NULL) {
|
||||||
if (pCol->type == pColInfoData->info.type) {
|
if (colDataIsNull_s(pColInfoData, j)) {
|
||||||
|
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NULL, NULL, false, offset,
|
||||||
|
k);
|
||||||
|
} else if (pCol->type == pColInfoData->info.type) {
|
||||||
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, var, true, offset,
|
tdAppendColValToRow(&rb, PRIMARYKEY_TIMESTAMP_COL_ID + k, pCol->type, TD_VTYPE_NORM, var, true, offset,
|
||||||
k);
|
k);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -34,6 +34,7 @@ typedef struct SMnodeMgmt {
|
||||||
SSingleWorker readWorker;
|
SSingleWorker readWorker;
|
||||||
SSingleWorker writeWorker;
|
SSingleWorker writeWorker;
|
||||||
SSingleWorker syncWorker;
|
SSingleWorker syncWorker;
|
||||||
|
SSingleWorker syncCtrlWorker;
|
||||||
bool stopped;
|
bool stopped;
|
||||||
int32_t refCount;
|
int32_t refCount;
|
||||||
TdThreadRwlock lock;
|
TdThreadRwlock lock;
|
||||||
|
@ -53,6 +54,7 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt);
|
||||||
void mmStopWorker(SMnodeMgmt *pMgmt);
|
void mmStopWorker(SMnodeMgmt *pMgmt);
|
||||||
int32_t mmPutMsgToWriteQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
int32_t mmPutMsgToWriteQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||||
int32_t mmPutMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
int32_t mmPutMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||||
|
int32_t mmPutMsgToSyncCtrlQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||||
int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||||
int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
int32_t mmPutMsgToQueryQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||||
int32_t mmPutMsgToFetchQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
int32_t mmPutMsgToFetchQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg);
|
||||||
|
|
|
@ -197,6 +197,9 @@ SArray *mmGetMsgHandles() {
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_SEND, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_SNAPSHOT_RSP, mmPutMsgToSyncQueue, 1) == NULL) goto _OVER;
|
||||||
|
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER;
|
||||||
|
if (dmSetMgmtHandle(pArray, TDMT_SYNC_HEARTBEAT_REPLY, mmPutMsgToSyncCtrlQueue, 1) == NULL) goto _OVER;
|
||||||
|
|
||||||
code = 0;
|
code = 0;
|
||||||
|
|
||||||
_OVER:
|
_OVER:
|
||||||
|
|
|
@ -67,6 +67,24 @@ static void mmProcessRpcMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
taosFreeQitem(pMsg);
|
taosFreeQitem(pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void mmProcessSyncCtrlMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
|
SMnodeMgmt *pMgmt = pInfo->ahandle;
|
||||||
|
pMsg->info.node = pMgmt->pMnode;
|
||||||
|
|
||||||
|
const STraceId *trace = &pMsg->info.traceId;
|
||||||
|
dGTrace("msg:%p, get from mnode-sync-ctrl queue", pMsg);
|
||||||
|
|
||||||
|
SMsgHead *pHead = pMsg->pCont;
|
||||||
|
pHead->contLen = ntohl(pHead->contLen);
|
||||||
|
pHead->vgId = ntohl(pHead->vgId);
|
||||||
|
|
||||||
|
int32_t code = mndProcessSyncCtrlMsg(pMsg);
|
||||||
|
|
||||||
|
dGTrace("msg:%p, is freed, code:0x%x", pMsg, code);
|
||||||
|
rpcFreeCont(pMsg->pCont);
|
||||||
|
taosFreeQitem(pMsg);
|
||||||
|
}
|
||||||
|
|
||||||
static void mmProcessSyncMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
static void mmProcessSyncMsg(SQueueInfo *pInfo, SRpcMsg *pMsg) {
|
||||||
SMnodeMgmt *pMgmt = pInfo->ahandle;
|
SMnodeMgmt *pMgmt = pInfo->ahandle;
|
||||||
pMsg->info.node = pMgmt->pMnode;
|
pMsg->info.node = pMgmt->pMnode;
|
||||||
|
@ -108,6 +126,10 @@ int32_t mmPutMsgToSyncQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
return mmPutMsgToWorker(pMgmt, &pMgmt->syncWorker, pMsg);
|
return mmPutMsgToWorker(pMgmt, &pMgmt->syncWorker, pMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mmPutMsgToSyncCtrlQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
|
return mmPutMsgToWorker(pMgmt, &pMgmt->syncCtrlWorker, pMsg);
|
||||||
|
}
|
||||||
|
|
||||||
int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t mmPutMsgToReadQueue(SMnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
return mmPutMsgToWorker(pMgmt, &pMgmt->readWorker, pMsg);
|
return mmPutMsgToWorker(pMgmt, &pMgmt->readWorker, pMsg);
|
||||||
}
|
}
|
||||||
|
@ -144,6 +166,9 @@ int32_t mmPutMsgToQueue(SMnodeMgmt *pMgmt, EQueueType qtype, SRpcMsg *pRpc) {
|
||||||
case SYNC_QUEUE:
|
case SYNC_QUEUE:
|
||||||
pWorker = &pMgmt->syncWorker;
|
pWorker = &pMgmt->syncWorker;
|
||||||
break;
|
break;
|
||||||
|
case SYNC_CTRL_QUEUE:
|
||||||
|
pWorker = &pMgmt->syncCtrlWorker;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
terrno = TSDB_CODE_INVALID_PARA;
|
terrno = TSDB_CODE_INVALID_PARA;
|
||||||
}
|
}
|
||||||
|
@ -223,6 +248,18 @@ int32_t mmStartWorker(SMnodeMgmt *pMgmt) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SSingleWorkerCfg scCfg = {
|
||||||
|
.min = 1,
|
||||||
|
.max = 1,
|
||||||
|
.name = "mnode-sync-ctrl",
|
||||||
|
.fp = (FItem)mmProcessSyncCtrlMsg,
|
||||||
|
.param = pMgmt,
|
||||||
|
};
|
||||||
|
if (tSingleWorkerInit(&pMgmt->syncCtrlWorker, &scCfg) != 0) {
|
||||||
|
dError("failed to start mnode mnode-sync-ctrl worker since %s", terrstr());
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
dDebug("mnode workers are initialized");
|
dDebug("mnode workers are initialized");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -235,5 +272,6 @@ void mmStopWorker(SMnodeMgmt *pMgmt) {
|
||||||
tSingleWorkerCleanup(&pMgmt->readWorker);
|
tSingleWorkerCleanup(&pMgmt->readWorker);
|
||||||
tSingleWorkerCleanup(&pMgmt->writeWorker);
|
tSingleWorkerCleanup(&pMgmt->writeWorker);
|
||||||
tSingleWorkerCleanup(&pMgmt->syncWorker);
|
tSingleWorkerCleanup(&pMgmt->syncWorker);
|
||||||
|
tSingleWorkerCleanup(&pMgmt->syncCtrlWorker);
|
||||||
dDebug("mnode workers are closed");
|
dDebug("mnode workers are closed");
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@ void vmGetMonitorInfo(SVnodeMgmt *pMgmt, SMonVmInfo *pInfo) {
|
||||||
|
|
||||||
pInfo->vstat.totalVnodes = totalVnodes;
|
pInfo->vstat.totalVnodes = totalVnodes;
|
||||||
pInfo->vstat.masterNum = masterNum;
|
pInfo->vstat.masterNum = masterNum;
|
||||||
pInfo->vstat.numOfSelectReqs = numOfSelectReqs - pMgmt->state.numOfSelectReqs;
|
pInfo->vstat.numOfSelectReqs = numOfSelectReqs;
|
||||||
pInfo->vstat.numOfInsertReqs = numOfInsertReqs; // delta
|
pInfo->vstat.numOfInsertReqs = numOfInsertReqs; // delta
|
||||||
pInfo->vstat.numOfInsertSuccessReqs = numOfInsertSuccessReqs; // delta
|
pInfo->vstat.numOfInsertSuccessReqs = numOfInsertSuccessReqs; // delta
|
||||||
pInfo->vstat.numOfBatchInsertReqs = numOfBatchInsertReqs; // delta
|
pInfo->vstat.numOfBatchInsertReqs = numOfBatchInsertReqs; // delta
|
||||||
|
@ -188,7 +188,7 @@ int32_t vmProcessCreateVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
req.walRollPeriod, req.walSegmentSize, req.hashMethod, req.hashBegin, req.hashEnd, req.hashPrefix,
|
req.walRollPeriod, req.walSegmentSize, req.hashMethod, req.hashBegin, req.hashEnd, req.hashPrefix,
|
||||||
req.hashSuffix, req.replica, req.selfIndex, req.strict);
|
req.hashSuffix, req.replica, req.selfIndex, req.strict);
|
||||||
for (int32_t i = 0; i < req.replica; ++i) {
|
for (int32_t i = 0; i < req.replica; ++i) {
|
||||||
dInfo("vgId:%d, replica:%d fqdn:%s port:%u", req.vgId, req.replicas[i].id, req.replicas[i].fqdn,
|
dInfo("vgId:%d, replica:%d id:%d fqdn:%s port:%u", req.vgId, i, req.replicas[i].id, req.replicas[i].fqdn,
|
||||||
req.replicas[i].port);
|
req.replicas[i].port);
|
||||||
}
|
}
|
||||||
vmGenerateVnodeCfg(&req, &vnodeCfg);
|
vmGenerateVnodeCfg(&req, &vnodeCfg);
|
||||||
|
@ -273,7 +273,17 @@ int32_t vmProcessAlterVnodeReq(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vgId = alterReq.vgId;
|
int32_t vgId = alterReq.vgId;
|
||||||
dInfo("vgId:%d, start to alter vnode replica", alterReq.vgId);
|
dInfo("vgId:%d, start to alter vnode, replica:%d selfIndex:%d strict:%d", alterReq.vgId, alterReq.replica,
|
||||||
|
alterReq.selfIndex, alterReq.strict);
|
||||||
|
for (int32_t i = 0; i < alterReq.replica; ++i) {
|
||||||
|
dInfo("vgId:%d, replica:%d ep:%s:%u", alterReq.vgId, i, alterReq.replicas[i].fqdn, alterReq.replicas[i].port);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (alterReq.replica <= 0 || alterReq.selfIndex < 0 || alterReq.selfIndex >= alterReq.replica) {
|
||||||
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
dError("vgId:%d, failed to alter replica since invalid msg", alterReq.vgId);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
|
SVnodeObj *pVnode = vmAcquireVnode(pMgmt, vgId);
|
||||||
if (pVnode == NULL) {
|
if (pVnode == NULL) {
|
||||||
|
|
|
@ -241,6 +241,8 @@ static void *vmCloseVnodeInThread(void *param) {
|
||||||
|
|
||||||
static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
static void vmCloseVnodes(SVnodeMgmt *pMgmt) {
|
||||||
dInfo("start to close all vnodes");
|
dInfo("start to close all vnodes");
|
||||||
|
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
||||||
|
dInfo("vnodes mgmt worker is stopped");
|
||||||
|
|
||||||
int32_t numOfVnodes = 0;
|
int32_t numOfVnodes = 0;
|
||||||
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
SVnodeObj **ppVnodes = vmGetVnodeListFromHash(pMgmt, &numOfVnodes);
|
||||||
|
|
|
@ -234,11 +234,9 @@ static int32_t vmPutMsgToQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg, EQueueType qtyp
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
|
int32_t vmPutMsgToSyncCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_CTRL_QUEUE); }
|
||||||
|
|
||||||
int32_t vmPutMsgToSyncCtrlQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
int32_t vmPutMsgToSyncQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, SYNC_QUEUE); }
|
||||||
return vmPutMsgToQueue(pMgmt, pMsg, SYNC_CTRL_QUEUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
|
int32_t vmPutMsgToWriteQueue(SVnodeMgmt *pMgmt, SRpcMsg *pMsg) { return vmPutMsgToQueue(pMgmt, pMsg, WRITE_QUEUE); }
|
||||||
|
|
||||||
|
@ -405,7 +403,6 @@ int32_t vmStartWorker(SVnodeMgmt *pMgmt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void vmStopWorker(SVnodeMgmt *pMgmt) {
|
void vmStopWorker(SVnodeMgmt *pMgmt) {
|
||||||
tSingleWorkerCleanup(&pMgmt->mgmtWorker);
|
|
||||||
tWWorkerCleanup(&pMgmt->writePool);
|
tWWorkerCleanup(&pMgmt->writePool);
|
||||||
tWWorkerCleanup(&pMgmt->applyPool);
|
tWWorkerCleanup(&pMgmt->applyPool);
|
||||||
tWWorkerCleanup(&pMgmt->syncPool);
|
tWWorkerCleanup(&pMgmt->syncPool);
|
||||||
|
|
|
@ -250,6 +250,7 @@ static int32_t mndInitSdb(SMnode *pMnode) {
|
||||||
opt.path = pMnode->path;
|
opt.path = pMnode->path;
|
||||||
opt.pMnode = pMnode;
|
opt.pMnode = pMnode;
|
||||||
opt.pWal = pMnode->pWal;
|
opt.pWal = pMnode->pWal;
|
||||||
|
opt.sync = pMnode->syncMgmt.sync;
|
||||||
|
|
||||||
pMnode->pSdb = sdbInit(&opt);
|
pMnode->pSdb = sdbInit(&opt);
|
||||||
if (pMnode->pSdb == NULL) {
|
if (pMnode->pSdb == NULL) {
|
||||||
|
@ -381,6 +382,7 @@ SMnode *mndOpen(const char *path, const SMnodeOpt *pOption) {
|
||||||
mError("failed to open mnode since %s", terrstr());
|
mError("failed to open mnode since %s", terrstr());
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
memset(pMnode, 0, sizeof(SMnode));
|
||||||
|
|
||||||
char timestr[24] = "1970-01-01 00:00:00.00";
|
char timestr[24] = "1970-01-01 00:00:00.00";
|
||||||
(void)taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
(void)taosParseTime(timestr, &pMnode->checkTime, (int32_t)strlen(timestr), TSDB_TIME_PRECISION_MILLI, 0);
|
||||||
|
@ -474,6 +476,45 @@ void mndStop(SMnode *pMnode) {
|
||||||
mndCleanupTimer(pMnode);
|
mndCleanupTimer(pMnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t mndProcessSyncCtrlMsg(SRpcMsg *pMsg) {
|
||||||
|
SMnode *pMnode = pMsg->info.node;
|
||||||
|
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||||
|
int32_t code = 0;
|
||||||
|
|
||||||
|
mInfo("vgId:%d, process sync ctrl msg", 1);
|
||||||
|
|
||||||
|
if (!syncEnvIsStart()) {
|
||||||
|
mError("failed to process sync msg:%p type:%s since syncEnv stop", pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SSyncNode *pSyncNode = syncNodeAcquire(pMgmt->sync);
|
||||||
|
if (pSyncNode == NULL) {
|
||||||
|
mError("failed to process sync msg:%p type:%s since syncNode is null", pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pMsg->msgType == TDMT_SYNC_HEARTBEAT) {
|
||||||
|
SyncHeartbeat *pSyncMsg = syncHeartbeatFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnHeartbeat(pSyncNode, pSyncMsg);
|
||||||
|
syncHeartbeatDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_HEARTBEAT_REPLY) {
|
||||||
|
SyncHeartbeatReply *pSyncMsg = syncHeartbeatReplyFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnHeartbeatReply(pSyncNode, pSyncMsg);
|
||||||
|
syncHeartbeatReplyDestroy(pSyncMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
syncNodeRelease(pSyncNode);
|
||||||
|
|
||||||
|
if (code != 0) {
|
||||||
|
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
||||||
SMnode *pMnode = pMsg->info.node;
|
SMnode *pMnode = pMsg->info.node;
|
||||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
||||||
|
@ -492,89 +533,64 @@ int32_t mndProcessSyncMsg(SRpcMsg *pMsg) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToDo: ugly! use function pointer
|
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
||||||
if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_STANDARD_SNAPSHOT) {
|
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
||||||
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
code = syncNodeOnTimer(pSyncNode, pSyncMsg);
|
||||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
syncTimeoutDestroy(pSyncMsg);
|
||||||
code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg);
|
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
||||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
code = syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
||||||
code = syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
syncPingDestroy(pSyncMsg);
|
||||||
syncPingDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
||||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
||||||
code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
syncPingReplyDestroy(pSyncMsg);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
|
||||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||||
code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL);
|
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
syncClientRequestDestroy(pSyncMsg);
|
||||||
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnRequestVoteSnapshotCb(pSyncNode, pSyncMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
||||||
syncRequestVoteDestroy(pSyncMsg);
|
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
code = syncNodeOnRequestVote(pSyncNode, pSyncMsg);
|
||||||
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
syncRequestVoteDestroy(pSyncMsg);
|
||||||
code = syncNodeOnRequestVoteReplySnapshotCb(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
||||||
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg);
|
||||||
code = syncNodeOnAppendEntriesSnapshotCb(pSyncNode, pSyncMsg);
|
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||||
syncAppendEntriesDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
||||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
||||||
code = syncNodeOnAppendEntriesReplySnapshotCb(pSyncNode, pSyncMsg);
|
code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg);
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
syncAppendEntriesDestroy(pSyncMsg);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
|
||||||
SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
||||||
code = syncNodeOnSnapshotSendCb(pSyncNode, pSyncMsg);
|
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
||||||
syncSnapshotSendDestroy(pSyncMsg);
|
code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||||
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnSnapshotRspCb(pSyncNode, pSyncMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
||||||
syncSnapshotRspDestroy(pSyncMsg);
|
SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg);
|
||||||
} else {
|
code = syncNodeOnSnapshot(pSyncNode, pSyncMsg);
|
||||||
mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
syncSnapshotSendDestroy(pSyncMsg);
|
||||||
code = -1;
|
|
||||||
}
|
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
||||||
|
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
||||||
|
code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg);
|
||||||
|
syncSnapshotRspDestroy(pSyncMsg);
|
||||||
|
|
||||||
|
} else if (pMsg->msgType == TDMT_SYNC_SET_MNODE_STANDBY) {
|
||||||
|
code = syncSetStandby(pMgmt->sync);
|
||||||
|
SRpcMsg rsp = {.code = code, .info = pMsg->info};
|
||||||
|
tmsgSendRsp(&rsp);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
code = -1;
|
||||||
code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg);
|
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
|
||||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
|
||||||
syncPingDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
|
||||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
|
||||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL);
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
|
||||||
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
|
||||||
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
|
||||||
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg);
|
|
||||||
syncAppendEntriesDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
|
||||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
|
||||||
code = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
|
||||||
} else {
|
|
||||||
mError("failed to process msg:%p since invalid type:%s", pMsg, TMSG_INFO(pMsg->msgType));
|
|
||||||
code = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
|
|
|
@ -71,8 +71,8 @@ void mndSyncCommitMsg(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbM
|
||||||
mInfo("trans:%d, is proposed and post sem", transId);
|
mInfo("trans:%d, is proposed and post sem", transId);
|
||||||
}
|
}
|
||||||
pMgmt->transId = 0;
|
pMgmt->transId = 0;
|
||||||
taosWUnLockLatch(&pMgmt->lock);
|
|
||||||
tsem_post(&pMgmt->syncSem);
|
tsem_post(&pMgmt->syncSem);
|
||||||
|
taosWUnLockLatch(&pMgmt->lock);
|
||||||
} else {
|
} else {
|
||||||
taosWUnLockLatch(&pMgmt->lock);
|
taosWUnLockLatch(&pMgmt->lock);
|
||||||
STrans *pTrans = mndAcquireTrans(pMnode, transId);
|
STrans *pTrans = mndAcquireTrans(pMnode, transId);
|
||||||
|
@ -113,27 +113,7 @@ void mndRestoreFinish(struct SSyncFSM *pFsm) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) {
|
void mndReConfig(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SReConfigCbMeta *cbMeta) {}
|
||||||
SMnode *pMnode = pFsm->data;
|
|
||||||
SSyncMgmt *pMgmt = &pMnode->syncMgmt;
|
|
||||||
|
|
||||||
pMgmt->errCode = cbMeta->code;
|
|
||||||
mInfo("trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%" PRId64 " term:%" PRId64, pMgmt->transId,
|
|
||||||
cbMeta->code, cbMeta->index, cbMeta->term);
|
|
||||||
|
|
||||||
taosWLockLatch(&pMgmt->lock);
|
|
||||||
if (pMgmt->transId == -1) {
|
|
||||||
if (pMgmt->errCode != 0) {
|
|
||||||
mError("trans:-1, failed to propose sync reconfig since %s, post sem", tstrerror(pMgmt->errCode));
|
|
||||||
} else {
|
|
||||||
mInfo("trans:-1, sync reconfig is proposed, saved:%d code:0x%x, index:%" PRId64 " term:%" PRId64 " post sem",
|
|
||||||
pMgmt->transId, cbMeta->code, cbMeta->index, cbMeta->term);
|
|
||||||
}
|
|
||||||
pMgmt->transId = 0;
|
|
||||||
tsem_post(&pMgmt->syncSem);
|
|
||||||
}
|
|
||||||
taosWUnLockLatch(&pMgmt->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t mndSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) {
|
int32_t mndSnapshotStartRead(struct SSyncFSM *pFsm, void *pParam, void **ppReader) {
|
||||||
mInfo("start to read snapshot from sdb");
|
mInfo("start to read snapshot from sdb");
|
||||||
|
@ -179,11 +159,14 @@ void mndLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cb
|
||||||
|
|
||||||
static void mndBecomeFollower(struct SSyncFSM *pFsm) {
|
static void mndBecomeFollower(struct SSyncFSM *pFsm) {
|
||||||
SMnode *pMnode = pFsm->data;
|
SMnode *pMnode = pFsm->data;
|
||||||
mInfo("vgId:1, become follower and post sem");
|
mInfo("vgId:1, become follower");
|
||||||
|
|
||||||
taosWLockLatch(&pMnode->syncMgmt.lock);
|
taosWLockLatch(&pMnode->syncMgmt.lock);
|
||||||
if (pMnode->syncMgmt.transId != 0) {
|
if (pMnode->syncMgmt.transId != 0) {
|
||||||
|
mInfo("vgId:1, become follower and post sem, trans:%d, failed to propose since not leader",
|
||||||
|
pMnode->syncMgmt.transId);
|
||||||
pMnode->syncMgmt.transId = 0;
|
pMnode->syncMgmt.transId = 0;
|
||||||
|
pMnode->syncMgmt.errCode = TSDB_CODE_SYN_NOT_LEADER;
|
||||||
tsem_post(&pMnode->syncMgmt.syncSem);
|
tsem_post(&pMnode->syncMgmt.syncSem);
|
||||||
}
|
}
|
||||||
taosWUnLockLatch(&pMnode->syncMgmt.lock);
|
taosWUnLockLatch(&pMnode->syncMgmt.lock);
|
||||||
|
@ -221,13 +204,21 @@ int32_t mndInitSync(SMnode *pMnode) {
|
||||||
taosInitRWLatch(&pMgmt->lock);
|
taosInitRWLatch(&pMgmt->lock);
|
||||||
pMgmt->transId = 0;
|
pMgmt->transId = 0;
|
||||||
|
|
||||||
SSyncInfo syncInfo = {.vgId = 1, .FpSendMsg = mndSyncSendMsg, .FpEqMsg = mndSyncEqMsg};
|
SSyncInfo syncInfo = {
|
||||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP);
|
.snapshotStrategy = SYNC_STRATEGY_STANDARD_SNAPSHOT,
|
||||||
syncInfo.pWal = pMnode->pWal;
|
.batchSize = 1,
|
||||||
syncInfo.pFsm = mndSyncMakeFsm(pMnode);
|
.vgId = 1,
|
||||||
syncInfo.snapshotStrategy = SYNC_STRATEGY_STANDARD_SNAPSHOT;
|
.pWal = pMnode->pWal,
|
||||||
|
.msgcb = NULL,
|
||||||
|
.FpSendMsg = mndSyncSendMsg,
|
||||||
|
.FpEqMsg = mndSyncEqMsg,
|
||||||
|
.FpEqCtrlMsg = NULL,
|
||||||
|
};
|
||||||
|
|
||||||
mInfo("vgId:1, start to open sync, selfIndex:%d replica:%d", pMgmt->selfIndex, pMgmt->numOfReplicas);
|
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", pMnode->path, TD_DIRSEP);
|
||||||
|
syncInfo.pFsm = mndSyncMakeFsm(pMnode);
|
||||||
|
|
||||||
|
mInfo("vgId:1, start to open sync, replica:%d selfIndex:%d", pMgmt->numOfReplicas, pMgmt->selfIndex);
|
||||||
SSyncCfg *pCfg = &syncInfo.syncCfg;
|
SSyncCfg *pCfg = &syncInfo.syncCfg;
|
||||||
pCfg->replicaNum = pMgmt->numOfReplicas;
|
pCfg->replicaNum = pMgmt->numOfReplicas;
|
||||||
pCfg->myIndex = pMgmt->selfIndex;
|
pCfg->myIndex = pMgmt->selfIndex;
|
||||||
|
@ -292,6 +283,7 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
|
||||||
int32_t code = syncPropose(pMgmt->sync, &req, isWeak);
|
int32_t code = syncPropose(pMgmt->sync, &req, isWeak);
|
||||||
|
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
|
mInfo("trans:%d, is proposing and wait sem", pMgmt->transId);
|
||||||
tsem_wait(&pMgmt->syncSem);
|
tsem_wait(&pMgmt->syncSem);
|
||||||
} else if (code > 0) {
|
} else if (code > 0) {
|
||||||
mInfo("trans:%d, confirm at once since replica is 1, continue execute", transId);
|
mInfo("trans:%d, confirm at once since replica is 1, continue execute", transId);
|
||||||
|
@ -301,12 +293,16 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
|
||||||
sdbWriteWithoutFree(pMnode->pSdb, pRaw);
|
sdbWriteWithoutFree(pMnode->pSdb, pRaw);
|
||||||
sdbSetApplyInfo(pMnode->pSdb, req.info.conn.applyIndex, req.info.conn.applyTerm, SYNC_INDEX_INVALID);
|
sdbSetApplyInfo(pMnode->pSdb, req.info.conn.applyIndex, req.info.conn.applyTerm, SYNC_INDEX_INVALID);
|
||||||
code = 0;
|
code = 0;
|
||||||
} else if (code == -1 && terrno == TSDB_CODE_SYN_NOT_LEADER) {
|
|
||||||
terrno = TSDB_CODE_APP_NOT_READY;
|
|
||||||
} else if (code == -1 && terrno == TSDB_CODE_SYN_INTERNAL_ERROR) {
|
|
||||||
terrno = TSDB_CODE_SYN_INTERNAL_ERROR;
|
|
||||||
} else {
|
} else {
|
||||||
terrno = TSDB_CODE_APP_ERROR;
|
taosWLockLatch(&pMgmt->lock);
|
||||||
|
mInfo("trans:%d, failed to proposed since %s", transId, terrstr());
|
||||||
|
pMgmt->transId = 0;
|
||||||
|
taosWUnLockLatch(&pMgmt->lock);
|
||||||
|
if (terrno == TSDB_CODE_SYN_NOT_LEADER) {
|
||||||
|
terrno = TSDB_CODE_APP_NOT_READY;
|
||||||
|
} else {
|
||||||
|
terrno = TSDB_CODE_APP_ERROR;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
rpcFreeCont(req.pCont);
|
rpcFreeCont(req.pCont);
|
||||||
|
@ -315,6 +311,7 @@ int32_t mndSyncPropose(SMnode *pMnode, SSdbRaw *pRaw, int32_t transId) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (pMgmt->errCode != 0) terrno = pMgmt->errCode;
|
||||||
return pMgmt->errCode;
|
return pMgmt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,6 +325,7 @@ void mndSyncStart(SMnode *pMnode) {
|
||||||
void mndSyncStop(SMnode *pMnode) {
|
void mndSyncStop(SMnode *pMnode) {
|
||||||
taosWLockLatch(&pMnode->syncMgmt.lock);
|
taosWLockLatch(&pMnode->syncMgmt.lock);
|
||||||
if (pMnode->syncMgmt.transId != 0) {
|
if (pMnode->syncMgmt.transId != 0) {
|
||||||
|
mInfo("vgId:1, is stopped and post sem, trans:%d", pMnode->syncMgmt.transId);
|
||||||
pMnode->syncMgmt.transId = 0;
|
pMnode->syncMgmt.transId = 0;
|
||||||
tsem_post(&pMnode->syncMgmt.syncSem);
|
tsem_post(&pMnode->syncMgmt.syncSem);
|
||||||
}
|
}
|
||||||
|
|
|
@ -778,7 +778,7 @@ static int32_t mndTransSync(SMnode *pMnode, STrans *pTrans) {
|
||||||
mInfo("trans:%d, sync to other mnodes, stage:%s", pTrans->id, mndTransStr(pTrans->stage));
|
mInfo("trans:%d, sync to other mnodes, stage:%s", pTrans->id, mndTransStr(pTrans->stage));
|
||||||
int32_t code = mndSyncPropose(pMnode, pRaw, pTrans->id);
|
int32_t code = mndSyncPropose(pMnode, pRaw, pTrans->id);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
mError("trans:%d, failed to sync since %s", pTrans->id, terrstr());
|
mError("trans:%d, failed to sync, errno:%s code:%s", pTrans->id, terrstr(), tstrerror(code));
|
||||||
sdbFreeRaw(pRaw);
|
sdbFreeRaw(pRaw);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -341,6 +341,12 @@ static void *mndBuildAlterVnodeReplicaReq(SMnode *pMnode, SDbObj *pDb, SVgObj *p
|
||||||
alterReq.selfIndex = v;
|
alterReq.selfIndex = v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
alterReq.replica = pVgroup->replica;
|
||||||
|
mInfo("vgId:%d, start to alter vnode, replica:%d selfIndex:%d strict:%d", alterReq.vgId, alterReq.replica,
|
||||||
|
alterReq.selfIndex, alterReq.strict);
|
||||||
|
for (int32_t i = 0; i < alterReq.replica; ++i) {
|
||||||
|
mInfo("vgId:%d, replica:%d ep:%s:%u", alterReq.vgId, i, alterReq.replicas[i].fqdn, alterReq.replicas[i].port);
|
||||||
|
}
|
||||||
|
|
||||||
if (alterReq.selfIndex == -1) {
|
if (alterReq.selfIndex == -1) {
|
||||||
terrno = TSDB_CODE_MND_APP_ERROR;
|
terrno = TSDB_CODE_MND_APP_ERROR;
|
||||||
|
@ -1580,10 +1586,11 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
|
||||||
if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1;
|
if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1;
|
||||||
if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1;
|
if (mndAddVnodeToVgroup(pMnode, &newVgroup, pArray) != 0) return -1;
|
||||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[1]) != 0) return -1;
|
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[1]) != 0) return -1;
|
||||||
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[2]) != 0) return -1;
|
|
||||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||||
|
if (mndAddCreateVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &newVgroup.vnodeGid[2]) != 0) return -1;
|
||||||
|
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||||
} else if (newVgroup.replica == 3 && pNewDb->cfg.replications == 1) {
|
} else if (newVgroup.replica == 3 && pNewDb->cfg.replications == 1) {
|
||||||
mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName,
|
mInfo("db:%s, vgId:%d, will remove 2 vnodes, vn:0 dnode:%d vn:1 dnode:%d vn:2 dnode:%d", pVgroup->dbName,
|
||||||
pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId);
|
pVgroup->vgId, pVgroup->vnodeGid[0].dnodeId, pVgroup->vnodeGid[1].dnodeId, pVgroup->vnodeGid[2].dnodeId);
|
||||||
|
@ -1593,6 +1600,7 @@ int32_t mndBuildAlterVgroupAction(SMnode *pMnode, STrans *pTrans, SDbObj *pOldDb
|
||||||
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del1) != 0) return -1;
|
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del1) != 0) return -1;
|
||||||
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del2) != 0) return -1;
|
if (mndRemoveVnodeFromVgroup(pMnode, &newVgroup, pArray, &del2) != 0) return -1;
|
||||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del1, true) != 0) return -1;
|
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del1, true) != 0) return -1;
|
||||||
|
if (mndAddAlterVnodeConfirmAction(pMnode, pTrans, pNewDb, &newVgroup) != 0) return -1;
|
||||||
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del2, true) != 0) return -1;
|
if (mndAddDropVnodeAction(pMnode, pTrans, pNewDb, &newVgroup, &del2, true) != 0) return -1;
|
||||||
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
if (mndAddAlterVnodeReplicaAction(pMnode, pTrans, pNewDb, &newVgroup, newVgroup.vnodeGid[0].dnodeId) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
enable_testing()
|
enable_testing()
|
||||||
|
|
||||||
add_subdirectory(acct)
|
add_subdirectory(acct)
|
||||||
add_subdirectory(db)
|
#add_subdirectory(db)
|
||||||
#add_subdirectory(dnode)
|
#add_subdirectory(dnode)
|
||||||
add_subdirectory(func)
|
add_subdirectory(func)
|
||||||
#add_subdirectory(mnode)
|
#add_subdirectory(mnode)
|
||||||
|
@ -14,4 +14,4 @@ add_subdirectory(snode)
|
||||||
add_subdirectory(stb)
|
add_subdirectory(stb)
|
||||||
add_subdirectory(topic)
|
add_subdirectory(topic)
|
||||||
add_subdirectory(trans)
|
add_subdirectory(trans)
|
||||||
add_subdirectory(user)
|
#add_subdirectory(user)
|
||||||
|
|
|
@ -5,7 +5,8 @@ target_link_libraries(
|
||||||
PUBLIC sut
|
PUBLIC sut
|
||||||
)
|
)
|
||||||
|
|
||||||
add_test(
|
|
||||||
NAME userTest
|
#add_test(
|
||||||
COMMAND userTest
|
# NAME userTest
|
||||||
)
|
# COMMAND userTest
|
||||||
|
#)
|
||||||
|
|
|
@ -5,5 +5,5 @@ target_include_directories(
|
||||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||||
)
|
)
|
||||||
target_link_libraries(
|
target_link_libraries(
|
||||||
sdb os common util wal
|
sdb os common util wal sync
|
||||||
)
|
)
|
|
@ -169,6 +169,7 @@ typedef struct SSdbRow {
|
||||||
typedef struct SSdb {
|
typedef struct SSdb {
|
||||||
SMnode *pMnode;
|
SMnode *pMnode;
|
||||||
SWal *pWal;
|
SWal *pWal;
|
||||||
|
int64_t sync;
|
||||||
char *currDir;
|
char *currDir;
|
||||||
char *tmpDir;
|
char *tmpDir;
|
||||||
int64_t commitIndex;
|
int64_t commitIndex;
|
||||||
|
@ -212,6 +213,7 @@ typedef struct SSdbOpt {
|
||||||
const char *path;
|
const char *path;
|
||||||
SMnode *pMnode;
|
SMnode *pMnode;
|
||||||
SWal *pWal;
|
SWal *pWal;
|
||||||
|
int64_t sync;
|
||||||
} SSdbOpt;
|
} SSdbOpt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -53,6 +53,7 @@ SSdb *sdbInit(SSdbOpt *pOption) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pSdb->pWal = pOption->pWal;
|
pSdb->pWal = pOption->pWal;
|
||||||
|
pSdb->sync = pOption->sync;
|
||||||
pSdb->applyIndex = -1;
|
pSdb->applyIndex = -1;
|
||||||
pSdb->applyTerm = -1;
|
pSdb->applyTerm = -1;
|
||||||
pSdb->applyConfig = -1;
|
pSdb->applyConfig = -1;
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
#include "sdb.h"
|
#include "sdb.h"
|
||||||
|
#include "sync.h"
|
||||||
#include "tchecksum.h"
|
#include "tchecksum.h"
|
||||||
#include "wal.h"
|
#include "wal.h"
|
||||||
|
|
||||||
|
@ -456,14 +457,25 @@ int32_t sdbWriteFile(SSdb *pSdb, int32_t delta) {
|
||||||
|
|
||||||
taosThreadMutexLock(&pSdb->filelock);
|
taosThreadMutexLock(&pSdb->filelock);
|
||||||
if (pSdb->pWal != NULL) {
|
if (pSdb->pWal != NULL) {
|
||||||
code = walBeginSnapshot(pSdb->pWal, pSdb->applyIndex);
|
// code = walBeginSnapshot(pSdb->pWal, pSdb->applyIndex);
|
||||||
|
if (pSdb->sync == 0) {
|
||||||
|
code = 0;
|
||||||
|
} else {
|
||||||
|
code = syncBeginSnapshot(pSdb->sync, pSdb->applyIndex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
code = sdbWriteFileImp(pSdb);
|
code = sdbWriteFileImp(pSdb);
|
||||||
}
|
}
|
||||||
if (code == 0) {
|
if (code == 0) {
|
||||||
if (pSdb->pWal != NULL) {
|
if (pSdb->pWal != NULL) {
|
||||||
code = walEndSnapshot(pSdb->pWal);
|
// code = walEndSnapshot(pSdb->pWal);
|
||||||
|
|
||||||
|
if (pSdb->sync == 0) {
|
||||||
|
code = 0;
|
||||||
|
} else {
|
||||||
|
code = syncEndSnapshot(pSdb->sync);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
|
|
|
@ -120,7 +120,11 @@ typedef struct SMetaFltParam {
|
||||||
|
|
||||||
} SMetaFltParam;
|
} SMetaFltParam;
|
||||||
|
|
||||||
|
// TODO, refactor later
|
||||||
int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *results);
|
int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *results);
|
||||||
|
int32_t metaFilterCreateTime(SMeta *pMeta, SMetaFltParam *parm, SArray *pUids);
|
||||||
|
int32_t metaFilterTableName(SMeta *pMeta, SMetaFltParam *param, SArray *pUids);
|
||||||
|
int32_t metaFilterTtl(SMeta *pMeta, SMetaFltParam *param, SArray *pUids);
|
||||||
|
|
||||||
#if 1 // refact APIs below (TODO)
|
#if 1 // refact APIs below (TODO)
|
||||||
typedef SVCreateTbReq STbCfg;
|
typedef SVCreateTbReq STbCfg;
|
||||||
|
|
|
@ -86,8 +86,12 @@ struct SMeta {
|
||||||
TTB* pSuidIdx;
|
TTB* pSuidIdx;
|
||||||
// ivt idx and idx
|
// ivt idx and idx
|
||||||
void* pTagIvtIdx;
|
void* pTagIvtIdx;
|
||||||
TTB* pTagIdx;
|
|
||||||
TTB* pTtlIdx;
|
TTB* pTagIdx;
|
||||||
|
TTB* pTtlIdx;
|
||||||
|
|
||||||
|
TTB* pCtimeIdx; // table created time idx
|
||||||
|
TTB* pNcolIdx; // ncol of table idx, normal table only
|
||||||
|
|
||||||
TTB* pSmaIdx;
|
TTB* pSmaIdx;
|
||||||
|
|
||||||
|
@ -142,6 +146,16 @@ typedef struct {
|
||||||
int64_t smaUid;
|
int64_t smaUid;
|
||||||
} SSmaIdxKey;
|
} SSmaIdxKey;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t ctime;
|
||||||
|
tb_uid_t uid;
|
||||||
|
} SCtimeIdxKey;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int64_t ncol;
|
||||||
|
tb_uid_t uid;
|
||||||
|
} SNcolIdxKey;
|
||||||
|
|
||||||
// metaTable ==================
|
// metaTable ==================
|
||||||
int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void* pTagData, int32_t nTagData, int8_t type, tb_uid_t uid,
|
int metaCreateTagIdxKey(tb_uid_t suid, int32_t cid, const void* pTagData, int32_t nTagData, int8_t type, tb_uid_t uid,
|
||||||
STagIdxKey** ppTagIdxKey, int32_t* nTagIdxKey);
|
STagIdxKey** ppTagIdxKey, int32_t* nTagIdxKey);
|
||||||
|
|
|
@ -24,6 +24,9 @@ static int uidIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
|
||||||
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||||
static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
static int taskIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||||
|
|
||||||
|
static int ctimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||||
|
static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2);
|
||||||
|
|
||||||
static int32_t metaInitLock(SMeta *pMeta) { return taosThreadRwlockInit(&pMeta->lock, NULL); }
|
static int32_t metaInitLock(SMeta *pMeta) { return taosThreadRwlockInit(&pMeta->lock, NULL); }
|
||||||
static int32_t metaDestroyLock(SMeta *pMeta) { return taosThreadRwlockDestroy(&pMeta->lock); }
|
static int32_t metaDestroyLock(SMeta *pMeta) { return taosThreadRwlockDestroy(&pMeta->lock); }
|
||||||
|
|
||||||
|
@ -139,6 +142,20 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
|
||||||
goto _err;
|
goto _err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// idx table create time
|
||||||
|
ret = tdbTbOpen("ctime.idx", sizeof(SCtimeIdxKey), 0, ctimeIdxCmpr, pMeta->pEnv, &pMeta->pCtimeIdx, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
metaError("vgId:%d, failed to open meta ctime index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
|
// idx num of col, normal table only
|
||||||
|
ret = tdbTbOpen("ncol.idx", sizeof(SNcolIdxKey), 0, ncolIdxCmpr, pMeta->pEnv, &pMeta->pNcolIdx, 0);
|
||||||
|
if (ret < 0) {
|
||||||
|
metaError("vgId:%d, failed to open meta ncol index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
ret = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb, 0);
|
ret = tdbTbOpen("stream.task.db", sizeof(int64_t), -1, taskIdxKeyCmpr, pMeta->pEnv, &pMeta->pStreamDb, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
metaError("vgId:%d, failed to open meta stream task index since %s", TD_VID(pVnode), tstrerror(terrno));
|
metaError("vgId:%d, failed to open meta stream task index since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||||
|
@ -166,6 +183,8 @@ int metaOpen(SVnode *pVnode, SMeta **ppMeta, int8_t rollback) {
|
||||||
_err:
|
_err:
|
||||||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||||
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
||||||
|
if (pMeta->pNcolIdx) tdbTbClose(pMeta->pNcolIdx);
|
||||||
|
if (pMeta->pCtimeIdx) tdbTbClose(pMeta->pCtimeIdx);
|
||||||
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
||||||
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
||||||
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
||||||
|
@ -187,6 +206,8 @@ int metaClose(SMeta *pMeta) {
|
||||||
if (pMeta->pCache) metaCacheClose(pMeta);
|
if (pMeta->pCache) metaCacheClose(pMeta);
|
||||||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||||
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
if (pMeta->pStreamDb) tdbTbClose(pMeta->pStreamDb);
|
||||||
|
if (pMeta->pNcolIdx) tdbTbClose(pMeta->pNcolIdx);
|
||||||
|
if (pMeta->pCtimeIdx) tdbTbClose(pMeta->pCtimeIdx);
|
||||||
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
if (pMeta->pSmaIdx) tdbTbClose(pMeta->pSmaIdx);
|
||||||
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
if (pMeta->pTtlIdx) tdbTbClose(pMeta->pTtlIdx);
|
||||||
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
if (pMeta->pTagIvtIdx) indexClose(pMeta->pTagIvtIdx);
|
||||||
|
@ -391,6 +412,43 @@ static int ttlIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kL
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ctimeIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||||
|
SCtimeIdxKey *pCtimeIdxKey1 = (SCtimeIdxKey *)pKey1;
|
||||||
|
SCtimeIdxKey *pCtimeIdxKey2 = (SCtimeIdxKey *)pKey2;
|
||||||
|
if (pCtimeIdxKey1->ctime > pCtimeIdxKey2->ctime) {
|
||||||
|
return 1;
|
||||||
|
} else if (pCtimeIdxKey1->ctime < pCtimeIdxKey2->ctime) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pCtimeIdxKey1->uid > pCtimeIdxKey2->uid) {
|
||||||
|
return 1;
|
||||||
|
} else if (pCtimeIdxKey1->uid < pCtimeIdxKey2->uid) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ncolIdxCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||||
|
SNcolIdxKey *pNcolIdxKey1 = (SNcolIdxKey *)pKey1;
|
||||||
|
SNcolIdxKey *pNcolIdxKey2 = (SNcolIdxKey *)pKey2;
|
||||||
|
|
||||||
|
if (pNcolIdxKey1->ncol > pNcolIdxKey2->ncol) {
|
||||||
|
return 1;
|
||||||
|
} else if (pNcolIdxKey1->ncol < pNcolIdxKey2->ncol) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pNcolIdxKey1->uid > pNcolIdxKey2->uid) {
|
||||||
|
return 1;
|
||||||
|
} else if (pNcolIdxKey1->uid < pNcolIdxKey2->uid) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
static int smaIdxKeyCmpr(const void *pKey1, int kLen1, const void *pKey2, int kLen2) {
|
||||||
SSmaIdxKey *pSmaIdxKey1 = (SSmaIdxKey *)pKey1;
|
SSmaIdxKey *pSmaIdxKey1 = (SSmaIdxKey *)pKey1;
|
||||||
SSmaIdxKey *pSmaIdxKey2 = (SSmaIdxKey *)pKey2;
|
SSmaIdxKey *pSmaIdxKey2 = (SSmaIdxKey *)pKey2;
|
||||||
|
|
|
@ -1038,6 +1038,143 @@ typedef struct {
|
||||||
int32_t vLen;
|
int32_t vLen;
|
||||||
} SIdxCursor;
|
} SIdxCursor;
|
||||||
|
|
||||||
|
int32_t metaFilterCreateTime(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
|
||||||
|
SIdxCursor *pCursor = NULL;
|
||||||
|
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
||||||
|
pCursor->pMeta = pMeta;
|
||||||
|
pCursor->suid = param->suid;
|
||||||
|
pCursor->cid = param->cid;
|
||||||
|
pCursor->type = param->type;
|
||||||
|
|
||||||
|
metaRLock(pMeta);
|
||||||
|
ret = tdbTbcOpen(pMeta->pCtimeIdx, &pCursor->pCur, NULL);
|
||||||
|
if (ret != 0) {
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
int64_t uidLimit = param->reverse ? INT64_MAX : 0;
|
||||||
|
|
||||||
|
SCtimeIdxKey ctimeKey = {.ctime = *(int64_t *)(param->val), .uid = uidLimit};
|
||||||
|
SCtimeIdxKey *pCtimeKey = &ctimeKey;
|
||||||
|
|
||||||
|
int cmp = 0;
|
||||||
|
if (tdbTbcMoveTo(pCursor->pCur, &ctimeKey, sizeof(ctimeKey), &cmp) < 0) {
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
bool first = true;
|
||||||
|
int32_t valid = 0;
|
||||||
|
while (1) {
|
||||||
|
void *entryKey = NULL;
|
||||||
|
int32_t nEntryKey = -1;
|
||||||
|
valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, NULL, NULL);
|
||||||
|
if (valid < 0) break;
|
||||||
|
|
||||||
|
SCtimeIdxKey *p = entryKey;
|
||||||
|
|
||||||
|
int32_t cmp = (*param->filterFunc)((void *)&p->ctime, (void *)&pCtimeKey->ctime, param->type);
|
||||||
|
if (cmp == 0) taosArrayPush(pUids, &p->uid);
|
||||||
|
if (cmp == -1) break;
|
||||||
|
valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur);
|
||||||
|
if (valid < 0) break;
|
||||||
|
}
|
||||||
|
|
||||||
|
END:
|
||||||
|
if (pCursor->pMeta) metaULock(pCursor->pMeta);
|
||||||
|
if (pCursor->pCur) tdbTbcClose(pCursor->pCur);
|
||||||
|
taosMemoryFree(pCursor);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t metaFilterTableName(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
char *buf = NULL;
|
||||||
|
|
||||||
|
STagIdxKey *pKey = NULL;
|
||||||
|
int32_t nKey = 0;
|
||||||
|
|
||||||
|
SIdxCursor *pCursor = NULL;
|
||||||
|
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
||||||
|
pCursor->pMeta = pMeta;
|
||||||
|
pCursor->suid = param->suid;
|
||||||
|
pCursor->cid = param->cid;
|
||||||
|
pCursor->type = param->type;
|
||||||
|
|
||||||
|
char *pName = param->val;
|
||||||
|
|
||||||
|
metaRLock(pMeta);
|
||||||
|
ret = tdbTbcOpen(pMeta->pNameIdx, &pCursor->pCur, NULL);
|
||||||
|
if (ret != 0) {
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
|
||||||
|
int cmp = 0;
|
||||||
|
if (tdbTbcMoveTo(pCursor->pCur, pName, strlen(pName) + 1, &cmp) < 0) {
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
bool first = true;
|
||||||
|
int32_t valid = 0;
|
||||||
|
while (1) {
|
||||||
|
void *pEntryKey = NULL, *pEntryVal = NULL;
|
||||||
|
int32_t nEntryKey = -1, nEntryVal = 0;
|
||||||
|
valid = tdbTbcGet(pCursor->pCur, (const void **)pEntryKey, &nEntryKey, (const void **)&pEntryVal, &nEntryVal);
|
||||||
|
if (valid < 0) break;
|
||||||
|
|
||||||
|
char *pTableKey = (char *)pEntryKey;
|
||||||
|
int32_t cmp = (*param->filterFunc)(pTableKey, pName, pCursor->type);
|
||||||
|
if (cmp == 0) {
|
||||||
|
tb_uid_t tuid = *(tb_uid_t *)pEntryVal;
|
||||||
|
taosArrayPush(pUids, &tuid);
|
||||||
|
} else if (cmp == 1) {
|
||||||
|
// next
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur);
|
||||||
|
if (valid < 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
END:
|
||||||
|
if (pCursor->pMeta) metaULock(pCursor->pMeta);
|
||||||
|
if (pCursor->pCur) tdbTbcClose(pCursor->pCur);
|
||||||
|
taosMemoryFree(buf);
|
||||||
|
taosMemoryFree(pKey);
|
||||||
|
|
||||||
|
taosMemoryFree(pCursor);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
int32_t metaFilterTtl(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
|
int32_t ret = 0;
|
||||||
|
char *buf = NULL;
|
||||||
|
|
||||||
|
STtlIdxKey *pKey = NULL;
|
||||||
|
int32_t nKey = 0;
|
||||||
|
|
||||||
|
SIdxCursor *pCursor = NULL;
|
||||||
|
pCursor = (SIdxCursor *)taosMemoryCalloc(1, sizeof(SIdxCursor));
|
||||||
|
pCursor->pMeta = pMeta;
|
||||||
|
pCursor->suid = param->suid;
|
||||||
|
pCursor->cid = param->cid;
|
||||||
|
pCursor->type = param->type;
|
||||||
|
|
||||||
|
metaRLock(pMeta);
|
||||||
|
ret = tdbTbcOpen(pMeta->pTtlIdx, &pCursor->pCur, NULL);
|
||||||
|
|
||||||
|
END:
|
||||||
|
if (pCursor->pMeta) metaULock(pCursor->pMeta);
|
||||||
|
if (pCursor->pCur) tdbTbcClose(pCursor->pCur);
|
||||||
|
taosMemoryFree(buf);
|
||||||
|
taosMemoryFree(pKey);
|
||||||
|
|
||||||
|
taosMemoryFree(pCursor);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
// impl later
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
|
@ -1053,7 +1190,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
pCursor->type = param->type;
|
pCursor->type = param->type;
|
||||||
|
|
||||||
metaRLock(pMeta);
|
metaRLock(pMeta);
|
||||||
ret = tdbTbcOpen(pMeta->pTagIdx, &pCursor->pCur, NULL);
|
ret = tdbTbcOpen(pMeta->pCtimeIdx, &pCursor->pCur, NULL);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
@ -1064,6 +1201,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
|
|
||||||
if (param->val == NULL) {
|
if (param->val == NULL) {
|
||||||
metaError("vgId:%d, failed to filter NULL data", TD_VID(pMeta->pVnode));
|
metaError("vgId:%d, failed to filter NULL data", TD_VID(pMeta->pVnode));
|
||||||
|
ret = -1;
|
||||||
goto END;
|
goto END;
|
||||||
} else {
|
} else {
|
||||||
if (IS_VAR_DATA_TYPE(param->type)) {
|
if (IS_VAR_DATA_TYPE(param->type)) {
|
||||||
|
@ -1104,9 +1242,11 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
|
|
||||||
valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal);
|
valid = tdbTbcGet(pCursor->pCur, (const void **)&entryKey, &nEntryKey, (const void **)&entryVal, &nEntryVal);
|
||||||
if (valid < 0) {
|
if (valid < 0) {
|
||||||
|
tdbFree(entryVal);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
STagIdxKey *p = entryKey;
|
STagIdxKey *p = entryKey;
|
||||||
|
if (p == NULL) break;
|
||||||
if (p->type != pCursor->type) {
|
if (p->type != pCursor->type) {
|
||||||
if (first) {
|
if (first) {
|
||||||
valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur);
|
valid = param->reverse ? tdbTbcMoveToPrev(pCursor->pCur) : tdbTbcMoveToNext(pCursor->pCur);
|
||||||
|
@ -1116,7 +1256,7 @@ int32_t metaFilterTableIds(SMeta *pMeta, SMetaFltParam *param, SArray *pUids) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (p == NULL || p->suid != pKey->suid) {
|
if (p->suid != pKey->suid) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
first = false;
|
first = false;
|
||||||
|
|
|
@ -27,6 +27,11 @@ static int metaUpdateSuidIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry);
|
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry);
|
||||||
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type);
|
static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type);
|
||||||
static void metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey);
|
static void metaDestroyTagIdxKey(STagIdxKey *pTagIdxKey);
|
||||||
|
// opt ins_tables query
|
||||||
|
static int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
|
static int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
|
static int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
|
static int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME);
|
||||||
|
|
||||||
static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
|
static void metaGetEntryInfo(const SMetaEntry *pEntry, SMetaInfo *pInfo) {
|
||||||
pInfo->uid = pEntry->uid;
|
pInfo->uid = pEntry->uid;
|
||||||
|
@ -551,6 +556,26 @@ static void metaBuildTtlIdxKey(STtlIdxKey *ttlKey, const SMetaEntry *pME) {
|
||||||
ttlKey->dtime = ctime / 1000 + ttlDays * tsTtlUnit;
|
ttlKey->dtime = ctime / 1000 + ttlDays * tsTtlUnit;
|
||||||
ttlKey->uid = pME->uid;
|
ttlKey->uid = pME->uid;
|
||||||
}
|
}
|
||||||
|
static int metaBuildCtimeIdxKey(SCtimeIdxKey *ctimeKey, const SMetaEntry *pME) {
|
||||||
|
int64_t ctime;
|
||||||
|
if (pME->type == TSDB_CHILD_TABLE) {
|
||||||
|
ctime = pME->ctbEntry.ctime;
|
||||||
|
} else if (pME->type == TSDB_NORMAL_TABLE) {
|
||||||
|
ctime = pME->ntbEntry.ctime;
|
||||||
|
} else {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctimeKey->ctime = ctime;
|
||||||
|
ctimeKey->uid = pME->uid;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int metaBuildNColIdxKey(SNcolIdxKey *ncolKey, const SMetaEntry *pME) {
|
||||||
|
ncolKey->ncol = pME->ntbEntry.schemaRow.nCols;
|
||||||
|
ncolKey->uid = pME->uid;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
static int metaDeleteTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
STtlIdxKey ttlKey = {0};
|
STtlIdxKey ttlKey = {0};
|
||||||
|
@ -632,6 +657,9 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||||
tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn);
|
tdbTbDelete(pMeta->pNameIdx, e.name, strlen(e.name) + 1, &pMeta->txn);
|
||||||
tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn);
|
tdbTbDelete(pMeta->pUidIdx, &uid, sizeof(uid), &pMeta->txn);
|
||||||
|
|
||||||
|
if (e.type == TSDB_CHILD_TABLE || e.type == TSDB_NORMAL_TABLE) metaDeleteCtimeIdx(pMeta, &e);
|
||||||
|
if (e.type == TSDB_NORMAL_TABLE) metaDeleteNcolIdx(pMeta, &e);
|
||||||
|
|
||||||
if (e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e);
|
if (e.type != TSDB_SUPER_TABLE) metaDeleteTtlIdx(pMeta, &e);
|
||||||
|
|
||||||
if (e.type == TSDB_CHILD_TABLE) {
|
if (e.type == TSDB_CHILD_TABLE) {
|
||||||
|
@ -658,6 +686,37 @@ static int metaDropTableByUid(SMeta *pMeta, tb_uid_t uid, int *type) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
// opt ins_tables
|
||||||
|
int metaUpdateCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
SCtimeIdxKey ctimeKey = {0};
|
||||||
|
if (metaBuildCtimeIdxKey(&ctimeKey, pME) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tdbTbInsert(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), NULL, 0, &pMeta->txn);
|
||||||
|
}
|
||||||
|
|
||||||
|
int metaDeleteCtimeIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
SCtimeIdxKey ctimeKey = {0};
|
||||||
|
if (metaBuildCtimeIdxKey(&ctimeKey, pME) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tdbTbDelete(pMeta->pCtimeIdx, &ctimeKey, sizeof(ctimeKey), &pMeta->txn);
|
||||||
|
}
|
||||||
|
int metaUpdateNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
SNcolIdxKey ncolKey = {0};
|
||||||
|
if (metaBuildNColIdxKey(&ncolKey, pME) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tdbTbInsert(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), NULL, 0, &pMeta->txn);
|
||||||
|
}
|
||||||
|
|
||||||
|
int metaDeleteNcolIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
|
SNcolIdxKey ncolKey = {0};
|
||||||
|
if (metaBuildNColIdxKey(&ncolKey, pME) < 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return tdbTbDelete(pMeta->pNcolIdx, &ncolKey, sizeof(ncolKey), &pMeta->txn);
|
||||||
|
}
|
||||||
|
|
||||||
static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq, STableMetaRsp *pMetaRsp) {
|
static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAlterTbReq, STableMetaRsp *pMetaRsp) {
|
||||||
void *pVal = NULL;
|
void *pVal = NULL;
|
||||||
|
@ -794,6 +853,10 @@ static int metaAlterTableColumn(SMeta *pMeta, int64_t version, SVAlterTbReq *pAl
|
||||||
pColumn->bytes = pAlterTbReq->colModBytes;
|
pColumn->bytes = pAlterTbReq->colModBytes;
|
||||||
break;
|
break;
|
||||||
case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME:
|
case TSDB_ALTER_TABLE_UPDATE_COLUMN_NAME:
|
||||||
|
if (pAlterTbReq->colNewName == NULL) {
|
||||||
|
terrno = TSDB_CODE_INVALID_MSG;
|
||||||
|
goto _err;
|
||||||
|
}
|
||||||
if (pColumn == NULL) {
|
if (pColumn == NULL) {
|
||||||
terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS;
|
terrno = TSDB_CODE_VND_TABLE_COL_NOT_EXISTS;
|
||||||
goto _err;
|
goto _err;
|
||||||
|
@ -1278,12 +1341,14 @@ static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pCtbEntry) {
|
||||||
ret = metaSaveJsonVarToIdx(pMeta, pCtbEntry, pTagColumn);
|
ret = metaSaveJsonVarToIdx(pMeta, pCtbEntry, pTagColumn);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
if (metaCreateTagIdxKey(pCtbEntry->ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type,
|
if (pTagData != NULL) {
|
||||||
pCtbEntry->uid, &pTagIdxKey, &nTagIdxKey) < 0) {
|
if (metaCreateTagIdxKey(pCtbEntry->ctbEntry.suid, pTagColumn->colId, pTagData, nTagData, pTagColumn->type,
|
||||||
ret = -1;
|
pCtbEntry->uid, &pTagIdxKey, &nTagIdxKey) < 0) {
|
||||||
goto end;
|
ret = -1;
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, &pMeta->txn);
|
||||||
}
|
}
|
||||||
tdbTbUpsert(pMeta->pTagIdx, pTagIdxKey, nTagIdxKey, NULL, 0, &pMeta->txn);
|
|
||||||
end:
|
end:
|
||||||
metaDestroyTagIdxKey(pTagIdxKey);
|
metaDestroyTagIdxKey(pTagIdxKey);
|
||||||
tDecoderClear(&dc);
|
tDecoderClear(&dc);
|
||||||
|
@ -1370,6 +1435,12 @@ int metaHandleEntry(SMeta *pMeta, const SMetaEntry *pME) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (metaUpdateCtimeIdx(pMeta, pME) < 0) goto _err;
|
||||||
|
|
||||||
|
if (pME->type == TSDB_NORMAL_TABLE) {
|
||||||
|
if (metaUpdateNcolIdx(pMeta, pME) < 0) goto _err;
|
||||||
|
}
|
||||||
|
|
||||||
if (pME->type != TSDB_SUPER_TABLE) {
|
if (pME->type != TSDB_SUPER_TABLE) {
|
||||||
if (metaUpdateTtlIdx(pMeta, pME) < 0) goto _err;
|
if (metaUpdateTtlIdx(pMeta, pME) < 0) goto _err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1492,4 +1492,11 @@ void tsdbCacheSetCapacity(SVnode *pVnode, size_t capacity) {
|
||||||
|
|
||||||
size_t tsdbCacheGetCapacity(SVnode *pVnode) { return taosLRUCacheGetCapacity(pVnode->pTsdb->lruCache); }
|
size_t tsdbCacheGetCapacity(SVnode *pVnode) { return taosLRUCacheGetCapacity(pVnode->pTsdb->lruCache); }
|
||||||
|
|
||||||
size_t tsdbCacheGetUsage(SVnode *pVnode) { return taosLRUCacheGetUsage(pVnode->pTsdb->lruCache); }
|
size_t tsdbCacheGetUsage(SVnode *pVnode) {
|
||||||
|
size_t usage = 0;
|
||||||
|
if (pVnode->pTsdb != NULL) {
|
||||||
|
usage = taosLRUCacheGetUsage(pVnode->pTsdb->lruCache);
|
||||||
|
}
|
||||||
|
|
||||||
|
return usage;
|
||||||
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
|
|
||||||
#include "vnd.h"
|
#include "vnd.h"
|
||||||
|
|
||||||
#define VND_INFO_FNAME "vnode.json"
|
#define VND_INFO_FNAME "vnode.json"
|
||||||
#define VND_INFO_FNAME_TMP "vnode_tmp.json"
|
#define VND_INFO_FNAME_TMP "vnode_tmp.json"
|
||||||
|
|
||||||
static int vnodeEncodeInfo(const SVnodeInfo *pInfo, char **ppData);
|
static int vnodeEncodeInfo(const SVnodeInfo *pInfo, char **ppData);
|
||||||
|
@ -107,7 +107,7 @@ int vnodeSaveInfo(const char *dir, const SVnodeInfo *pInfo) {
|
||||||
// free info binary
|
// free info binary
|
||||||
taosMemoryFree(data);
|
taosMemoryFree(data);
|
||||||
|
|
||||||
vInfo("vgId:%d, vnode info is saved, fname:%s", pInfo->config.vgId, fname);
|
vInfo("vgId:%d, vnode info is saved, fname:%s replica:%d", pInfo->config.vgId, fname, pInfo->config.syncCfg.replicaNum);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -228,7 +228,9 @@ int vnodeCommit(SVnode *pVnode) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
}
|
}
|
||||||
walBeginSnapshot(pVnode->pWal, pVnode->state.applied);
|
|
||||||
|
// walBeginSnapshot(pVnode->pWal, pVnode->state.applied);
|
||||||
|
syncBeginSnapshot(pVnode->sync, pVnode->state.applied);
|
||||||
|
|
||||||
code = smaPreCommit(pVnode->pSma);
|
code = smaPreCommit(pVnode->pSma);
|
||||||
TSDB_CHECK_CODE(code, lino, _exit);
|
TSDB_CHECK_CODE(code, lino, _exit);
|
||||||
|
@ -282,7 +284,8 @@ int vnodeCommit(SVnode *pVnode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// apply the commit (TODO)
|
// apply the commit (TODO)
|
||||||
walEndSnapshot(pVnode->pWal);
|
// walEndSnapshot(pVnode->pWal);
|
||||||
|
syncEndSnapshot(pVnode->sync);
|
||||||
|
|
||||||
_exit:
|
_exit:
|
||||||
if (code) {
|
if (code) {
|
||||||
|
|
|
@ -87,12 +87,19 @@ int32_t vnodeAlter(const char *path, SAlterVnodeReplicaReq *pReq, STfs *pTfs) {
|
||||||
vInfo("vgId:%d, save config, replica:%d ep:%s:%u", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
vInfo("vgId:%d, save config, replica:%d ep:%s:%u", pReq->vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info.config.syncCfg = *pCfg;
|
||||||
ret = vnodeSaveInfo(dir, &info);
|
ret = vnodeSaveInfo(dir, &info);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
vError("vgId:%d, failed to save vnode config since %s", pReq->vgId, tstrerror(terrno));
|
vError("vgId:%d, failed to save vnode config since %s", pReq->vgId, tstrerror(terrno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ret = vnodeCommitInfo(dir, &info);
|
||||||
|
if (ret < 0) {
|
||||||
|
vError("vgId:%d, failed to commit vnode config since %s", pReq->vgId, tstrerror(terrno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
vInfo("vgId:%d, vnode config is saved", info.config.vgId);
|
vInfo("vgId:%d, vnode config is saved", info.config.vgId);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,10 +15,13 @@
|
||||||
|
|
||||||
#include "vnd.h"
|
#include "vnd.h"
|
||||||
|
|
||||||
#define VNODE_GET_LOAD_RESET_VALS(pVar, oVal, vType) \
|
#define VNODE_GET_LOAD_RESET_VALS(pVar, oVal, vType, tags) \
|
||||||
do { \
|
do { \
|
||||||
int##vType##_t newVal = atomic_sub_fetch_##vType(&(pVar), (oVal)); \
|
int##vType##_t newVal = atomic_sub_fetch_##vType(&(pVar), (oVal)); \
|
||||||
ASSERT(newVal >= 0); \
|
ASSERT(newVal >= 0); \
|
||||||
|
if (newVal < 0) { \
|
||||||
|
vWarn("vgId:%d %s, abnormal val:%" PRIi64 ", old val:%" PRIi64, TD_VID(pVnode), tags, newVal, (oVal)); \
|
||||||
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
int vnodeQueryOpen(SVnode *pVnode) {
|
int vnodeQueryOpen(SVnode *pVnode) {
|
||||||
|
@ -435,10 +438,10 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
||||||
* @param pLoad
|
* @param pLoad
|
||||||
*/
|
*/
|
||||||
void vnodeResetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
void vnodeResetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
||||||
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsert, pLoad->numOfInsertReqs, 64);
|
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsert, pLoad->numOfInsertReqs, 64, "nInsert");
|
||||||
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsertSuccess, pLoad->numOfInsertSuccessReqs, 64);
|
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nInsertSuccess, pLoad->numOfInsertSuccessReqs, 64, "nInsertSuccess");
|
||||||
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsert, pLoad->numOfBatchInsertReqs, 64);
|
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsert, pLoad->numOfBatchInsertReqs, 64, "nBatchInsert");
|
||||||
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsertSuccess, pLoad->numOfBatchInsertSuccessReqs, 64);
|
VNODE_GET_LOAD_RESET_VALS(pVnode->statis.nBatchInsertSuccess, pLoad->numOfBatchInsertSuccessReqs, 64, "nBatchInsertSuccess");
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) {
|
void vnodeGetInfo(SVnode *pVnode, const char **dbname, int32_t *vgId) {
|
||||||
|
|
|
@ -292,116 +292,67 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
|
|
||||||
vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType));
|
vGTrace("vgId:%d, sync msg:%p will be processed, type:%s", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType));
|
||||||
|
|
||||||
if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_NO_SNAPSHOT) {
|
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
||||||
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
||||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
ASSERT(pSyncMsg != NULL);
|
||||||
ASSERT(pSyncMsg != NULL);
|
code = syncNodeOnTimer(pSyncNode, pSyncMsg);
|
||||||
code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg);
|
syncTimeoutDestroy(pSyncMsg);
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
|
||||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
|
||||||
syncPingDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
|
||||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
|
||||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL);
|
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_BATCH) {
|
|
||||||
SyncClientRequestBatch *pSyncMsg = syncClientRequestBatchFromRpcMsg(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnClientRequestBatchCb(pSyncNode, pSyncMsg);
|
|
||||||
syncClientRequestBatchDestroyDeep(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
|
||||||
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnRequestVoteCb(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
|
||||||
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnRequestVoteReplyCb(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
|
||||||
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnAppendEntriesCb(pSyncNode, pSyncMsg);
|
|
||||||
syncAppendEntriesDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
|
||||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnAppendEntriesReplyCb(pSyncNode, pSyncMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
|
||||||
} else {
|
|
||||||
vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType);
|
|
||||||
code = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (syncNodeStrategy(pSyncNode) == SYNC_STRATEGY_WAL_FIRST) {
|
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
||||||
// use wal first strategy
|
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
||||||
if (pMsg->msgType == TDMT_SYNC_TIMEOUT) {
|
ASSERT(pSyncMsg != NULL);
|
||||||
SyncTimeout *pSyncMsg = syncTimeoutFromRpcMsg2(pMsg);
|
code = syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
||||||
ASSERT(pSyncMsg != NULL);
|
syncPingDestroy(pSyncMsg);
|
||||||
code = syncNodeOnTimeoutCb(pSyncNode, pSyncMsg);
|
|
||||||
syncTimeoutDestroy(pSyncMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING) {
|
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
||||||
SyncPing *pSyncMsg = syncPingFromRpcMsg2(pMsg);
|
ASSERT(pSyncMsg != NULL);
|
||||||
ASSERT(pSyncMsg != NULL);
|
code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
||||||
code = syncNodeOnPingCb(pSyncNode, pSyncMsg);
|
syncPingReplyDestroy(pSyncMsg);
|
||||||
syncPingDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_PING_REPLY) {
|
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
||||||
SyncPingReply *pSyncMsg = syncPingReplyFromRpcMsg2(pMsg);
|
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
||||||
ASSERT(pSyncMsg != NULL);
|
ASSERT(pSyncMsg != NULL);
|
||||||
code = syncNodeOnPingReplyCb(pSyncNode, pSyncMsg);
|
code = syncNodeOnClientRequest(pSyncNode, pSyncMsg, NULL);
|
||||||
syncPingReplyDestroy(pSyncMsg);
|
syncClientRequestDestroy(pSyncMsg);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST) {
|
|
||||||
SyncClientRequest *pSyncMsg = syncClientRequestFromRpcMsg2(pMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
||||||
ASSERT(pSyncMsg != NULL);
|
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
||||||
code = syncNodeOnClientRequestCb(pSyncNode, pSyncMsg, NULL);
|
ASSERT(pSyncMsg != NULL);
|
||||||
syncClientRequestDestroy(pSyncMsg);
|
code = syncNodeOnRequestVote(pSyncNode, pSyncMsg);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_CLIENT_REQUEST_BATCH) {
|
syncRequestVoteDestroy(pSyncMsg);
|
||||||
SyncClientRequestBatch *pSyncMsg = syncClientRequestBatchFromRpcMsg(pMsg);
|
|
||||||
ASSERT(pSyncMsg != NULL);
|
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
||||||
code = syncNodeOnClientRequestBatchCb(pSyncNode, pSyncMsg);
|
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
||||||
syncClientRequestBatchDestroy(pSyncMsg);
|
ASSERT(pSyncMsg != NULL);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE) {
|
code = syncNodeOnRequestVoteReply(pSyncNode, pSyncMsg);
|
||||||
SyncRequestVote *pSyncMsg = syncRequestVoteFromRpcMsg2(pMsg);
|
syncRequestVoteReplyDestroy(pSyncMsg);
|
||||||
ASSERT(pSyncMsg != NULL);
|
|
||||||
code = syncNodeOnRequestVoteSnapshotCb(pSyncNode, pSyncMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES) {
|
||||||
syncRequestVoteDestroy(pSyncMsg);
|
SyncAppendEntries *pSyncMsg = syncAppendEntriesFromRpcMsg2(pMsg);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_REQUEST_VOTE_REPLY) {
|
ASSERT(pSyncMsg != NULL);
|
||||||
SyncRequestVoteReply *pSyncMsg = syncRequestVoteReplyFromRpcMsg2(pMsg);
|
code = syncNodeOnAppendEntries(pSyncNode, pSyncMsg);
|
||||||
ASSERT(pSyncMsg != NULL);
|
syncAppendEntriesDestroy(pSyncMsg);
|
||||||
code = syncNodeOnRequestVoteReplySnapshotCb(pSyncNode, pSyncMsg);
|
|
||||||
syncRequestVoteReplyDestroy(pSyncMsg);
|
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_BATCH) {
|
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
||||||
SyncAppendEntriesBatch *pSyncMsg = syncAppendEntriesBatchFromRpcMsg2(pMsg);
|
ASSERT(pSyncMsg != NULL);
|
||||||
ASSERT(pSyncMsg != NULL);
|
code = syncNodeOnAppendEntriesReply(pSyncNode, pSyncMsg);
|
||||||
code = syncNodeOnAppendEntriesSnapshot2Cb(pSyncNode, pSyncMsg);
|
syncAppendEntriesReplyDestroy(pSyncMsg);
|
||||||
syncAppendEntriesBatchDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_APPEND_ENTRIES_REPLY) {
|
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
||||||
SyncAppendEntriesReply *pSyncMsg = syncAppendEntriesReplyFromRpcMsg2(pMsg);
|
SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg);
|
||||||
ASSERT(pSyncMsg != NULL);
|
code = syncNodeOnSnapshot(pSyncNode, pSyncMsg);
|
||||||
code = syncNodeOnAppendEntriesReplySnapshot2Cb(pSyncNode, pSyncMsg);
|
syncSnapshotSendDestroy(pSyncMsg);
|
||||||
syncAppendEntriesReplyDestroy(pSyncMsg);
|
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
||||||
SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pMsg);
|
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
||||||
code = syncNodeOnSnapshotSendCb(pSyncNode, pSyncMsg);
|
code = syncNodeOnSnapshotReply(pSyncNode, pSyncMsg);
|
||||||
syncSnapshotSendDestroy(pSyncMsg);
|
syncSnapshotRspDestroy(pSyncMsg);
|
||||||
} else if (pMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
|
||||||
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pMsg);
|
} else {
|
||||||
code = syncNodeOnSnapshotRspCb(pSyncNode, pSyncMsg);
|
vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType);
|
||||||
syncSnapshotRspDestroy(pSyncMsg);
|
code = -1;
|
||||||
} else {
|
|
||||||
vGError("vgId:%d, msg:%p failed to process since error msg type:%d", pVnode->config.vgId, pMsg, pMsg->msgType);
|
|
||||||
code = -1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vTrace("vgId:%d, sync msg:%p is processed, type:%s code:0x%x", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType),
|
vTrace("vgId:%d, sync msg:%p is processed, type:%s code:0x%x", pVnode->config.vgId, pMsg, TMSG_INFO(pMsg->msgType),
|
||||||
|
@ -413,6 +364,19 @@ int32_t vnodeProcessSyncMsg(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int32_t vnodeSyncEqCtrlMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||||
|
if (msgcb == NULL) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t code = tmsgPutToQueue(msgcb, SYNC_CTRL_QUEUE, pMsg);
|
||||||
|
if (code != 0) {
|
||||||
|
rpcFreeCont(pMsg->pCont);
|
||||||
|
pMsg->pCont = NULL;
|
||||||
|
}
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
static int32_t vnodeSyncEqMsg(const SMsgCb *msgcb, SRpcMsg *pMsg) {
|
||||||
if (msgcb == NULL) {
|
if (msgcb == NULL) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -599,9 +563,7 @@ static int32_t vnodeSnapshotDoWrite(struct SSyncFSM *pFsm, void *pWriter, void *
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vnodeLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {
|
static void vnodeLeaderTransfer(struct SSyncFSM *pFsm, const SRpcMsg *pMsg, SFsmCbMeta cbMeta) {}
|
||||||
SVnode *pVnode = pFsm->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void vnodeRestoreFinish(struct SSyncFSM *pFsm) {
|
static void vnodeRestoreFinish(struct SSyncFSM *pFsm) {
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
|
@ -641,12 +603,14 @@ static void vnodeBecomeLeader(struct SSyncFSM *pFsm) {
|
||||||
SVnode *pVnode = pFsm->data;
|
SVnode *pVnode = pFsm->data;
|
||||||
vDebug("vgId:%d, become leader", pVnode->config.vgId);
|
vDebug("vgId:%d, become leader", pVnode->config.vgId);
|
||||||
|
|
||||||
// taosThreadMutexLock(&pVnode->lock);
|
#if 0
|
||||||
// if (pVnode->blocked) {
|
taosThreadMutexLock(&pVnode->lock);
|
||||||
// pVnode->blocked = false;
|
if (pVnode->blocked) {
|
||||||
// tsem_post(&pVnode->syncSem);
|
pVnode->blocked = false;
|
||||||
// }
|
tsem_post(&pVnode->syncSem);
|
||||||
// taosThreadMutexUnlock(&pVnode->lock);
|
}
|
||||||
|
taosThreadMutexUnlock(&pVnode->lock);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
||||||
|
@ -674,20 +638,26 @@ static SSyncFSM *vnodeSyncMakeFsm(SVnode *pVnode) {
|
||||||
int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
||||||
SSyncInfo syncInfo = {
|
SSyncInfo syncInfo = {
|
||||||
.snapshotStrategy = SYNC_STRATEGY_WAL_FIRST,
|
.snapshotStrategy = SYNC_STRATEGY_WAL_FIRST,
|
||||||
//.snapshotStrategy = SYNC_STRATEGY_NO_SNAPSHOT,
|
|
||||||
.batchSize = 1,
|
.batchSize = 1,
|
||||||
.vgId = pVnode->config.vgId,
|
.vgId = pVnode->config.vgId,
|
||||||
.isStandBy = pVnode->config.standby,
|
|
||||||
.syncCfg = pVnode->config.syncCfg,
|
.syncCfg = pVnode->config.syncCfg,
|
||||||
.pWal = pVnode->pWal,
|
.pWal = pVnode->pWal,
|
||||||
.msgcb = NULL,
|
.msgcb = NULL,
|
||||||
.FpSendMsg = vnodeSyncSendMsg,
|
.FpSendMsg = vnodeSyncSendMsg,
|
||||||
.FpEqMsg = vnodeSyncEqMsg,
|
.FpEqMsg = vnodeSyncEqMsg,
|
||||||
|
.FpEqCtrlMsg = vnodeSyncEqCtrlMsg,
|
||||||
};
|
};
|
||||||
|
|
||||||
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", path, TD_DIRSEP);
|
snprintf(syncInfo.path, sizeof(syncInfo.path), "%s%ssync", path, TD_DIRSEP);
|
||||||
syncInfo.pFsm = vnodeSyncMakeFsm(pVnode);
|
syncInfo.pFsm = vnodeSyncMakeFsm(pVnode);
|
||||||
|
|
||||||
|
SSyncCfg *pCfg = &syncInfo.syncCfg;
|
||||||
|
vInfo("vgId:%d, start to open sync, replica:%d selfIndex:%d", pVnode->config.vgId, pCfg->replicaNum, pCfg->myIndex);
|
||||||
|
for (int32_t i = 0; i < pCfg->replicaNum; ++i) {
|
||||||
|
SNodeInfo *pNode = &pCfg->nodeInfo[i];
|
||||||
|
vInfo("vgId:%d, index:%d ep:%s:%u", pVnode->config.vgId, i, pNode->nodeFqdn, pNode->nodePort);
|
||||||
|
}
|
||||||
|
|
||||||
pVnode->sync = syncOpen(&syncInfo);
|
pVnode->sync = syncOpen(&syncInfo);
|
||||||
if (pVnode->sync <= 0) {
|
if (pVnode->sync <= 0) {
|
||||||
vError("vgId:%d, failed to open sync since %s", pVnode->config.vgId, terrstr());
|
vError("vgId:%d, failed to open sync since %s", pVnode->config.vgId, terrstr());
|
||||||
|
@ -701,11 +671,15 @@ int32_t vnodeSyncOpen(SVnode *pVnode, char *path) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeSyncStart(SVnode *pVnode) {
|
void vnodeSyncStart(SVnode *pVnode) {
|
||||||
|
vDebug("vgId:%d, start sync", pVnode->config.vgId);
|
||||||
syncSetMsgCb(pVnode->sync, &pVnode->msgCb);
|
syncSetMsgCb(pVnode->sync, &pVnode->msgCb);
|
||||||
syncStart(pVnode->sync);
|
syncStart(pVnode->sync);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vnodeSyncClose(SVnode *pVnode) { syncStop(pVnode->sync); }
|
void vnodeSyncClose(SVnode *pVnode) {
|
||||||
|
vDebug("vgId:%d, close sync", pVnode->config.vgId);
|
||||||
|
syncStop(pVnode->sync);
|
||||||
|
}
|
||||||
|
|
||||||
bool vnodeIsRoleLeader(SVnode *pVnode) { return syncGetMyRole(pVnode->sync) == TAOS_SYNC_STATE_LEADER; }
|
bool vnodeIsRoleLeader(SVnode *pVnode) { return syncGetMyRole(pVnode->sync) == TAOS_SYNC_STATE_LEADER; }
|
||||||
|
|
||||||
|
|
|
@ -541,6 +541,12 @@ typedef struct {
|
||||||
SSnapContext* sContext;
|
SSnapContext* sContext;
|
||||||
} SStreamRawScanInfo;
|
} SStreamRawScanInfo;
|
||||||
|
|
||||||
|
typedef struct SSysTableIndex {
|
||||||
|
int8_t init;
|
||||||
|
SArray *uids;
|
||||||
|
int32_t lastIdx;
|
||||||
|
} SSysTableIndex;
|
||||||
|
|
||||||
typedef struct SSysTableScanInfo {
|
typedef struct SSysTableScanInfo {
|
||||||
SRetrieveMetaTableRsp* pRsp;
|
SRetrieveMetaTableRsp* pRsp;
|
||||||
SRetrieveTableReq req;
|
SRetrieveTableReq req;
|
||||||
|
@ -553,6 +559,7 @@ typedef struct SSysTableScanInfo {
|
||||||
bool showRewrite;
|
bool showRewrite;
|
||||||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
||||||
SMTbCursor* pCur; // cursor for iterate the local table meta store.
|
SMTbCursor* pCur; // cursor for iterate the local table meta store.
|
||||||
|
SSysTableIndex* pIdx; // idx for local table meta
|
||||||
SArray* scanCols; // SArray<int16_t> scan column id list
|
SArray* scanCols; // SArray<int16_t> scan column id list
|
||||||
SName name;
|
SName name;
|
||||||
SSDataBlock* pRes;
|
SSDataBlock* pRes;
|
||||||
|
|
|
@ -122,7 +122,7 @@ void initGroupedResultInfo(SGroupResInfo* pGroupResInfo, SSHashObj* pHashmap, in
|
||||||
|
|
||||||
if (order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC) {
|
if (order == TSDB_ORDER_ASC || order == TSDB_ORDER_DESC) {
|
||||||
__compar_fn_t fn = (order == TSDB_ORDER_ASC) ? resultrowComparAsc : resultrowComparDesc;
|
__compar_fn_t fn = (order == TSDB_ORDER_ASC) ? resultrowComparAsc : resultrowComparDesc;
|
||||||
int32_t size = POINTER_BYTES;
|
int32_t size = POINTER_BYTES;
|
||||||
taosSort(pGroupResInfo->pRows->pData, taosArrayGetSize(pGroupResInfo->pRows), size, fn);
|
taosSort(pGroupResInfo->pRows->pData, taosArrayGetSize(pGroupResInfo->pRows), size, fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,16 +422,6 @@ static SColumnInfoData* getColInfoResult(void* metaHandle, int64_t suid, SArray*
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*else {
|
|
||||||
code = metaGetTableTagsByUids(metaHandle, suid, uidList, tags);
|
|
||||||
if (code != 0) {
|
|
||||||
terrno = code;
|
|
||||||
qError("failed to get table from meta idx, reason: %s, suid:%" PRId64, tstrerror(code), suid);
|
|
||||||
goto end;
|
|
||||||
} else {
|
|
||||||
qInfo("succ to get table from meta idx, suid:%" PRId64, suid);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int32_t rows = taosArrayGetSize(uidList);
|
int32_t rows = taosArrayGetSize(uidList);
|
||||||
if (rows == 0) {
|
if (rows == 0) {
|
||||||
|
@ -762,8 +752,8 @@ end:
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tableUidCompare(const void* a, const void* b) {
|
static int tableUidCompare(const void* a, const void* b) {
|
||||||
uint64_t u1 = *(uint64_t*)a;
|
int64_t u1 = *(uint64_t*)a;
|
||||||
uint64_t u2 = *(uint64_t*)b;
|
int64_t u2 = *(uint64_t*)b;
|
||||||
if (u1 == u2) {
|
if (u1 == u2) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1212,11 +1202,10 @@ void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) {
|
||||||
#if 1
|
#if 1
|
||||||
// todo refactor: add the parameter for tbname function
|
// todo refactor: add the parameter for tbname function
|
||||||
const char* name = "tbname";
|
const char* name = "tbname";
|
||||||
int32_t len = strlen(name);
|
int32_t len = strlen(name);
|
||||||
|
|
||||||
if (!pFuncNode->pParameterList && (memcmp(pExprNode->_function.functionName, name, len) == 0) &&
|
if (!pFuncNode->pParameterList && (memcmp(pExprNode->_function.functionName, name, len) == 0) &&
|
||||||
pExprNode->_function.functionName[len] == 0) {
|
pExprNode->_function.functionName[len] == 0) {
|
||||||
|
|
||||||
pFuncNode->pParameterList = nodesMakeList();
|
pFuncNode->pParameterList = nodesMakeList();
|
||||||
ASSERT(LIST_LENGTH(pFuncNode->pParameterList) == 0);
|
ASSERT(LIST_LENGTH(pFuncNode->pParameterList) == 0);
|
||||||
SValueNode* res = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
SValueNode* res = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||||
|
@ -1266,8 +1255,8 @@ void createExprFromOneNode(SExprInfo* pExp, SNode* pNode, int16_t slotId) {
|
||||||
pExp->base.numOfParams = 1;
|
pExp->base.numOfParams = 1;
|
||||||
|
|
||||||
SDataType* pType = &pCaseNode->node.resType;
|
SDataType* pType = &pCaseNode->node.resType;
|
||||||
pExp->base.resSchema = createResSchema(pType->type, pType->bytes, slotId, pType->scale,
|
pExp->base.resSchema =
|
||||||
pType->precision, pCaseNode->node.aliasName);
|
createResSchema(pType->type, pType->bytes, slotId, pType->scale, pType->precision, pCaseNode->node.aliasName);
|
||||||
pExp->pExpr->_optrRoot.pRootNode = pNode;
|
pExp->pExpr->_optrRoot.pRootNode = pNode;
|
||||||
} else {
|
} else {
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -290,21 +290,21 @@ bool fstVerify(Fst* fst);
|
||||||
// refactor this function
|
// refactor this function
|
||||||
bool fstBuilderNodeCompileTo(FstBuilderNode* b, IdxFstFile* wrt, CompiledAddr lastAddr, CompiledAddr startAddr);
|
bool fstBuilderNodeCompileTo(FstBuilderNode* b, IdxFstFile* wrt, CompiledAddr lastAddr, CompiledAddr startAddr);
|
||||||
|
|
||||||
typedef struct StreamState {
|
typedef struct FstStreamState {
|
||||||
FstNode* node;
|
FstNode* node;
|
||||||
uint64_t trans;
|
uint64_t trans;
|
||||||
FstOutput out;
|
FstOutput out;
|
||||||
void* autState;
|
void* autState;
|
||||||
} StreamState;
|
} FstStreamState;
|
||||||
|
|
||||||
void streamStateDestroy(void* s);
|
void fstStreamStateDestroy(void* s);
|
||||||
|
|
||||||
typedef struct FStmSt {
|
typedef struct FStmSt {
|
||||||
Fst* fst;
|
Fst* fst;
|
||||||
FAutoCtx* aut;
|
FAutoCtx* aut;
|
||||||
SArray* inp;
|
SArray* inp;
|
||||||
FstOutput emptyOutput;
|
FstOutput emptyOutput;
|
||||||
SArray* stack; // <StreamState>
|
SArray* stack; // <FstStreamState>
|
||||||
FstBoundWithData* endAt;
|
FstBoundWithData* endAt;
|
||||||
} FStmSt;
|
} FStmSt;
|
||||||
|
|
||||||
|
@ -317,14 +317,14 @@ typedef struct FStmStRslt {
|
||||||
FStmStRslt* swsResultCreate(FstSlice* data, FstOutput fOut, void* state);
|
FStmStRslt* swsResultCreate(FstSlice* data, FstOutput fOut, void* state);
|
||||||
void swsResultDestroy(FStmStRslt* result);
|
void swsResultDestroy(FStmStRslt* result);
|
||||||
|
|
||||||
typedef void* (*StreamCallback)(void*);
|
typedef void* (*streamCallback__fn)(void*);
|
||||||
FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBoundWithData* max);
|
FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBoundWithData* max);
|
||||||
|
|
||||||
void stmStDestroy(FStmSt* sws);
|
void stmStDestroy(FStmSt* sws);
|
||||||
|
|
||||||
bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min);
|
bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min);
|
||||||
|
|
||||||
FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback);
|
FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback);
|
||||||
|
|
||||||
FStmBuilder* stmBuilderCreate(Fst* fst, FAutoCtx* aut);
|
FStmBuilder* stmBuilderCreate(Fst* fst, FAutoCtx* aut);
|
||||||
|
|
||||||
|
|
|
@ -1165,7 +1165,7 @@ FStmSt* stmStCreate(Fst* fst, FAutoCtx* automation, FstBoundWithData* min, FstBo
|
||||||
sws->emptyOutput.null = true;
|
sws->emptyOutput.null = true;
|
||||||
sws->emptyOutput.out = 0;
|
sws->emptyOutput.out = 0;
|
||||||
|
|
||||||
sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState));
|
sws->stack = (SArray*)taosArrayInit(256, sizeof(FstStreamState));
|
||||||
sws->endAt = max;
|
sws->endAt = max;
|
||||||
stmStSeekMin(sws, min);
|
stmStSeekMin(sws, min);
|
||||||
|
|
||||||
|
@ -1177,7 +1177,7 @@ void stmStDestroy(FStmSt* sws) {
|
||||||
}
|
}
|
||||||
|
|
||||||
taosArrayDestroy(sws->inp);
|
taosArrayDestroy(sws->inp);
|
||||||
taosArrayDestroyEx(sws->stack, streamStateDestroy);
|
taosArrayDestroyEx(sws->stack, fstStreamStateDestroy);
|
||||||
|
|
||||||
taosMemoryFree(sws);
|
taosMemoryFree(sws);
|
||||||
}
|
}
|
||||||
|
@ -1188,10 +1188,10 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) {
|
||||||
if (fstBoundWithDataIsIncluded(min)) {
|
if (fstBoundWithDataIsIncluded(min)) {
|
||||||
sws->emptyOutput.out = fstEmptyFinalOutput(sws->fst, &(sws->emptyOutput.null));
|
sws->emptyOutput.out = fstEmptyFinalOutput(sws->fst, &(sws->emptyOutput.null));
|
||||||
}
|
}
|
||||||
StreamState s = {.node = fstGetRoot(sws->fst),
|
FstStreamState s = {.node = fstGetRoot(sws->fst),
|
||||||
.trans = 0,
|
.trans = 0,
|
||||||
.out = {.null = false, .out = 0},
|
.out = {.null = false, .out = 0},
|
||||||
.autState = automFuncs[aut->type].start(aut)}; // auto.start callback
|
.autState = automFuncs[aut->type].start(aut)}; // auto.start callback
|
||||||
taosArrayPush(sws->stack, &s);
|
taosArrayPush(sws->stack, &s);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -1223,7 +1223,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) {
|
||||||
autState = automFuncs[aut->type].accept(aut, preState, b);
|
autState = automFuncs[aut->type].accept(aut, preState, b);
|
||||||
taosArrayPush(sws->inp, &b);
|
taosArrayPush(sws->inp, &b);
|
||||||
|
|
||||||
StreamState s = {.node = node, .trans = res + 1, .out = {.null = false, .out = out}, .autState = preState};
|
FstStreamState s = {.node = node, .trans = res + 1, .out = {.null = false, .out = out}, .autState = preState};
|
||||||
node = NULL;
|
node = NULL;
|
||||||
|
|
||||||
taosArrayPush(sws->stack, &s);
|
taosArrayPush(sws->stack, &s);
|
||||||
|
@ -1244,7 +1244,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StreamState s = {.node = node, .trans = i, .out = {.null = false, .out = out}, .autState = autState};
|
FstStreamState s = {.node = node, .trans = i, .out = {.null = false, .out = out}, .autState = autState};
|
||||||
taosArrayPush(sws->stack, &s);
|
taosArrayPush(sws->stack, &s);
|
||||||
taosMemoryFree(trans);
|
taosMemoryFree(trans);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1255,7 +1255,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) {
|
||||||
|
|
||||||
uint32_t sz = taosArrayGetSize(sws->stack);
|
uint32_t sz = taosArrayGetSize(sws->stack);
|
||||||
if (sz != 0) {
|
if (sz != 0) {
|
||||||
StreamState* s = taosArrayGet(sws->stack, sz - 1);
|
FstStreamState* s = taosArrayGet(sws->stack, sz - 1);
|
||||||
if (inclusize) {
|
if (inclusize) {
|
||||||
s->trans -= 1;
|
s->trans -= 1;
|
||||||
taosArrayPop(sws->inp);
|
taosArrayPop(sws->inp);
|
||||||
|
@ -1264,7 +1264,7 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) {
|
||||||
uint64_t trans = s->trans;
|
uint64_t trans = s->trans;
|
||||||
FstTransition trn;
|
FstTransition trn;
|
||||||
fstNodeGetTransitionAt(n, trans - 1, &trn);
|
fstNodeGetTransitionAt(n, trans - 1, &trn);
|
||||||
StreamState s = {
|
FstStreamState s = {
|
||||||
.node = fstGetNode(sws->fst, trn.addr), .trans = 0, .out = {.null = false, .out = out}, .autState = autState};
|
.node = fstGetNode(sws->fst, trn.addr), .trans = 0, .out = {.null = false, .out = out}, .autState = autState};
|
||||||
taosArrayPush(sws->stack, &s);
|
taosArrayPush(sws->stack, &s);
|
||||||
return true;
|
return true;
|
||||||
|
@ -1274,14 +1274,14 @@ bool stmStSeekMin(FStmSt* sws, FstBoundWithData* min) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) {
|
FStmStRslt* stmStNextWith(FStmSt* sws, streamCallback__fn callback) {
|
||||||
FAutoCtx* aut = sws->aut;
|
FAutoCtx* aut = sws->aut;
|
||||||
FstOutput output = sws->emptyOutput;
|
FstOutput output = sws->emptyOutput;
|
||||||
if (output.null == false) {
|
if (output.null == false) {
|
||||||
FstSlice emptySlice = fstSliceCreate(NULL, 0);
|
FstSlice emptySlice = fstSliceCreate(NULL, 0);
|
||||||
if (fstBoundWithDataExceededBy(sws->endAt, &emptySlice)) {
|
if (fstBoundWithDataExceededBy(sws->endAt, &emptySlice)) {
|
||||||
taosArrayDestroyEx(sws->stack, streamStateDestroy);
|
taosArrayDestroyEx(sws->stack, fstStreamStateDestroy);
|
||||||
sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState));
|
sws->stack = (SArray*)taosArrayInit(256, sizeof(FstStreamState));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
void* start = automFuncs[aut->type].start(aut);
|
void* start = automFuncs[aut->type].start(aut);
|
||||||
|
@ -1292,12 +1292,12 @@ FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) {
|
||||||
}
|
}
|
||||||
SArray* nodes = taosArrayInit(8, sizeof(FstNode*));
|
SArray* nodes = taosArrayInit(8, sizeof(FstNode*));
|
||||||
while (taosArrayGetSize(sws->stack) > 0) {
|
while (taosArrayGetSize(sws->stack) > 0) {
|
||||||
StreamState* p = (StreamState*)taosArrayPop(sws->stack);
|
FstStreamState* p = (FstStreamState*)taosArrayPop(sws->stack);
|
||||||
if (p->trans >= FST_NODE_LEN(p->node) || !automFuncs[aut->type].canMatch(aut, p->autState)) {
|
if (p->trans >= FST_NODE_LEN(p->node) || !automFuncs[aut->type].canMatch(aut, p->autState)) {
|
||||||
if (FST_NODE_ADDR(p->node) != fstGetRootAddr(sws->fst)) {
|
if (FST_NODE_ADDR(p->node) != fstGetRootAddr(sws->fst)) {
|
||||||
taosArrayPop(sws->inp);
|
taosArrayPop(sws->inp);
|
||||||
}
|
}
|
||||||
streamStateDestroy(p);
|
fstStreamStateDestroy(p);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
FstTransition trn;
|
FstTransition trn;
|
||||||
|
@ -1318,10 +1318,10 @@ FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) {
|
||||||
isMatch = automFuncs[aut->type].isMatch(aut, eofState);
|
isMatch = automFuncs[aut->type].isMatch(aut, eofState);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StreamState s1 = {.node = p->node, .trans = p->trans + 1, .out = p->out, .autState = p->autState};
|
FstStreamState s1 = {.node = p->node, .trans = p->trans + 1, .out = p->out, .autState = p->autState};
|
||||||
taosArrayPush(sws->stack, &s1);
|
taosArrayPush(sws->stack, &s1);
|
||||||
|
|
||||||
StreamState s2 = {.node = nextNode, .trans = 0, .out = {.null = false, .out = out}, .autState = nextState};
|
FstStreamState s2 = {.node = nextNode, .trans = 0, .out = {.null = false, .out = out}, .autState = nextState};
|
||||||
taosArrayPush(sws->stack, &s2);
|
taosArrayPush(sws->stack, &s2);
|
||||||
|
|
||||||
int32_t isz = taosArrayGetSize(sws->inp);
|
int32_t isz = taosArrayGetSize(sws->inp);
|
||||||
|
@ -1331,8 +1331,8 @@ FStmStRslt* stmStNextWith(FStmSt* sws, StreamCallback callback) {
|
||||||
}
|
}
|
||||||
FstSlice slice = fstSliceCreate(buf, isz);
|
FstSlice slice = fstSliceCreate(buf, isz);
|
||||||
if (fstBoundWithDataExceededBy(sws->endAt, &slice)) {
|
if (fstBoundWithDataExceededBy(sws->endAt, &slice)) {
|
||||||
taosArrayDestroyEx(sws->stack, streamStateDestroy);
|
taosArrayDestroyEx(sws->stack, fstStreamStateDestroy);
|
||||||
sws->stack = (SArray*)taosArrayInit(256, sizeof(StreamState));
|
sws->stack = (SArray*)taosArrayInit(256, sizeof(FstStreamState));
|
||||||
taosMemoryFreeClear(buf);
|
taosMemoryFreeClear(buf);
|
||||||
fstSliceDestroy(&slice);
|
fstSliceDestroy(&slice);
|
||||||
taosArrayDestroy(nodes);
|
taosArrayDestroy(nodes);
|
||||||
|
@ -1375,11 +1375,11 @@ void swsResultDestroy(FStmStRslt* result) {
|
||||||
taosMemoryFree(result);
|
taosMemoryFree(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
void streamStateDestroy(void* s) {
|
void fstStreamStateDestroy(void* s) {
|
||||||
if (NULL == s) {
|
if (NULL == s) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
StreamState* ss = (StreamState*)s;
|
FstStreamState* ss = (FstStreamState*)s;
|
||||||
fstNodeDestroy(ss->node);
|
fstNodeDestroy(ss->node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ int indexJsonPut(SIndexJson *index, SIndexJsonMultiTerm *terms, uint64_t uid) {
|
||||||
} else {
|
} else {
|
||||||
p->colType = TSDB_DATA_TYPE_DOUBLE;
|
p->colType = TSDB_DATA_TYPE_DOUBLE;
|
||||||
}
|
}
|
||||||
IDX_TYPE_ADD_EXTERN_TYPE(p->colType, TSDB_DATA_TYPE_JSON);
|
IDX_TYPE_ADD_EXTERN_TYPE((p->colType), TSDB_DATA_TYPE_JSON);
|
||||||
}
|
}
|
||||||
// handle put
|
// handle put
|
||||||
return indexPut(index, terms, uid);
|
return indexPut(index, terms, uid);
|
||||||
|
|
|
@ -92,9 +92,8 @@ extern "C" {
|
||||||
// /\ UNCHANGED <<serverVars, commitIndex, messages>>
|
// /\ UNCHANGED <<serverVars, commitIndex, messages>>
|
||||||
// /\ UNCHANGED <<candidateVars, leaderVars>>
|
// /\ UNCHANGED <<candidateVars, leaderVars>>
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg);
|
|
||||||
int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMsg);
|
int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg);
|
||||||
int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatch* pMsg);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,9 +40,7 @@ extern "C" {
|
||||||
// /\ Discard(m)
|
// /\ Discard(m)
|
||||||
// /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
|
// /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
||||||
int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
|
||||||
int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntriesReply* pMsg);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,10 @@ extern "C" {
|
||||||
// msource |-> i,
|
// msource |-> i,
|
||||||
// mdest |-> j])
|
// mdest |-> j])
|
||||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||||
//
|
|
||||||
int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode);
|
|
||||||
int32_t syncNodeRequestVotePeersSnapshot(SSyncNode* pSyncNode);
|
|
||||||
|
|
||||||
int32_t syncNodeElect(SSyncNode* pSyncNode);
|
int32_t syncNodeElect(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg);
|
int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode);
|
||||||
|
int32_t syncNodeSendRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,13 +28,13 @@ extern "C" {
|
||||||
#include "trpc.h"
|
#include "trpc.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
|
|
||||||
#define TIMER_MAX_MS 0x7FFFFFFF
|
#define TIMER_MAX_MS 0x7FFFFFFF
|
||||||
#define ENV_TICK_TIMER_MS 1000
|
#define ENV_TICK_TIMER_MS 1000
|
||||||
#define PING_TIMER_MS 5000
|
#define PING_TIMER_MS 5000
|
||||||
#define ELECT_TIMER_MS_MIN 5000
|
#define ELECT_TIMER_MS_MIN 5000
|
||||||
#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2)
|
#define ELECT_TIMER_MS_MAX (ELECT_TIMER_MS_MIN * 2)
|
||||||
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
|
#define ELECT_TIMER_MS_RANGE (ELECT_TIMER_MS_MAX - ELECT_TIMER_MS_MIN)
|
||||||
#define HEARTBEAT_TIMER_MS 900
|
#define HEARTBEAT_TIMER_MS 900
|
||||||
|
|
||||||
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
#define EMPTY_RAFT_ID ((SRaftId){.addr = 0, .vgId = 0})
|
||||||
|
|
||||||
|
|
|
@ -56,9 +56,8 @@ typedef struct SSyncIO {
|
||||||
int32_t (*FpOnSyncAppendEntries)(SSyncNode *pSyncNode, SyncAppendEntries *pMsg);
|
int32_t (*FpOnSyncAppendEntries)(SSyncNode *pSyncNode, SyncAppendEntries *pMsg);
|
||||||
int32_t (*FpOnSyncAppendEntriesReply)(SSyncNode *pSyncNode, SyncAppendEntriesReply *pMsg);
|
int32_t (*FpOnSyncAppendEntriesReply)(SSyncNode *pSyncNode, SyncAppendEntriesReply *pMsg);
|
||||||
int32_t (*FpOnSyncTimeout)(SSyncNode *pSyncNode, SyncTimeout *pMsg);
|
int32_t (*FpOnSyncTimeout)(SSyncNode *pSyncNode, SyncTimeout *pMsg);
|
||||||
|
int32_t (*FpOnSyncSnapshot)(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg);
|
||||||
int32_t (*FpOnSyncSnapshotSend)(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg);
|
int32_t (*FpOnSyncSnapshotReply)(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg);
|
||||||
int32_t (*FpOnSyncSnapshotRsp)(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg);
|
|
||||||
|
|
||||||
int8_t isStart;
|
int8_t isStart;
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ void syncIndexMgrDestroy(SSyncIndexMgr *pSyncIndexMgr);
|
||||||
void syncIndexMgrClear(SSyncIndexMgr *pSyncIndexMgr);
|
void syncIndexMgrClear(SSyncIndexMgr *pSyncIndexMgr);
|
||||||
void syncIndexMgrSetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncIndex index);
|
void syncIndexMgrSetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, SyncIndex index);
|
||||||
SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
||||||
cJSON *syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr);
|
cJSON * syncIndexMgr2Json(SSyncIndexMgr *pSyncIndexMgr);
|
||||||
char *syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr);
|
char * syncIndexMgr2Str(SSyncIndexMgr *pSyncIndexMgr);
|
||||||
|
|
||||||
void syncIndexMgrSetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, int64_t startTime);
|
void syncIndexMgrSetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId, int64_t startTime);
|
||||||
int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
int64_t syncIndexMgrGetStartTime(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId);
|
||||||
|
|
|
@ -57,9 +57,37 @@ typedef struct SRaftCfg SRaftCfg;
|
||||||
typedef struct SSyncRespMgr SSyncRespMgr;
|
typedef struct SSyncRespMgr SSyncRespMgr;
|
||||||
typedef struct SSyncSnapshotSender SSyncSnapshotSender;
|
typedef struct SSyncSnapshotSender SSyncSnapshotSender;
|
||||||
typedef struct SSyncSnapshotReceiver SSyncSnapshotReceiver;
|
typedef struct SSyncSnapshotReceiver SSyncSnapshotReceiver;
|
||||||
|
typedef struct SSyncTimer SSyncTimer;
|
||||||
|
typedef struct SSyncHbTimerData SSyncHbTimerData;
|
||||||
|
|
||||||
extern bool gRaftDetailLog;
|
extern bool gRaftDetailLog;
|
||||||
|
|
||||||
|
typedef struct SSyncHbTimerData {
|
||||||
|
SSyncNode* pSyncNode;
|
||||||
|
SSyncTimer* pTimer;
|
||||||
|
SRaftId destId;
|
||||||
|
uint64_t logicClock;
|
||||||
|
} SSyncHbTimerData;
|
||||||
|
|
||||||
|
typedef struct SSyncTimer {
|
||||||
|
void* pTimer;
|
||||||
|
TAOS_TMR_CALLBACK timerCb;
|
||||||
|
uint64_t logicClock;
|
||||||
|
uint64_t counter;
|
||||||
|
int32_t timerMS;
|
||||||
|
SRaftId destId;
|
||||||
|
void* pData;
|
||||||
|
} SSyncTimer;
|
||||||
|
|
||||||
|
int32_t syncHbTimerInit(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer, SRaftId destId);
|
||||||
|
int32_t syncHbTimerStart(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer);
|
||||||
|
int32_t syncHbTimerStop(SSyncNode* pSyncNode, SSyncTimer* pSyncTimer);
|
||||||
|
|
||||||
|
typedef struct SPeerState {
|
||||||
|
SyncIndex lastSendIndex;
|
||||||
|
int64_t lastSendTime;
|
||||||
|
} SPeerState;
|
||||||
|
|
||||||
typedef struct SSyncNode {
|
typedef struct SSyncNode {
|
||||||
// init by SSyncInfo
|
// init by SSyncInfo
|
||||||
SyncGroupId vgId;
|
SyncGroupId vgId;
|
||||||
|
@ -73,6 +101,7 @@ typedef struct SSyncNode {
|
||||||
const SMsgCb* msgcb;
|
const SMsgCb* msgcb;
|
||||||
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
int32_t (*FpSendMsg)(const SEpSet* pEpSet, SRpcMsg* pMsg);
|
||||||
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
int32_t (*FpEqMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
|
int32_t (*FpEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
|
|
||||||
// init internal
|
// init internal
|
||||||
SNodeInfo myNodeInfo;
|
SNodeInfo myNodeInfo;
|
||||||
|
@ -138,6 +167,9 @@ typedef struct SSyncNode {
|
||||||
TAOS_TMR_CALLBACK FpHeartbeatTimerCB; // Timer Fp
|
TAOS_TMR_CALLBACK FpHeartbeatTimerCB; // Timer Fp
|
||||||
uint64_t heartbeatTimerCounter;
|
uint64_t heartbeatTimerCounter;
|
||||||
|
|
||||||
|
// peer heartbeat timer
|
||||||
|
SSyncTimer peerHeartbeatTimerArr[TSDB_MAX_REPLICA];
|
||||||
|
|
||||||
// callback
|
// callback
|
||||||
FpOnPingCb FpOnPing;
|
FpOnPingCb FpOnPing;
|
||||||
FpOnPingReplyCb FpOnPingReply;
|
FpOnPingReplyCb FpOnPingReply;
|
||||||
|
@ -147,8 +179,8 @@ typedef struct SSyncNode {
|
||||||
FpOnRequestVoteReplyCb FpOnRequestVoteReply;
|
FpOnRequestVoteReplyCb FpOnRequestVoteReply;
|
||||||
FpOnAppendEntriesCb FpOnAppendEntries;
|
FpOnAppendEntriesCb FpOnAppendEntries;
|
||||||
FpOnAppendEntriesReplyCb FpOnAppendEntriesReply;
|
FpOnAppendEntriesReplyCb FpOnAppendEntriesReply;
|
||||||
FpOnSnapshotSendCb FpOnSnapshotSend;
|
FpOnSnapshotCb FpOnSnapshot;
|
||||||
FpOnSnapshotRspCb FpOnSnapshotRsp;
|
FpOnSnapshotReplyCb FpOnSnapshotReply;
|
||||||
|
|
||||||
// tools
|
// tools
|
||||||
SSyncRespMgr* pSyncRespMgr;
|
SSyncRespMgr* pSyncRespMgr;
|
||||||
|
@ -159,9 +191,15 @@ typedef struct SSyncNode {
|
||||||
SSyncSnapshotSender* senders[TSDB_MAX_REPLICA];
|
SSyncSnapshotSender* senders[TSDB_MAX_REPLICA];
|
||||||
SSyncSnapshotReceiver* pNewNodeReceiver;
|
SSyncSnapshotReceiver* pNewNodeReceiver;
|
||||||
|
|
||||||
|
SPeerState peerStates[TSDB_MAX_REPLICA];
|
||||||
|
|
||||||
// is config changing
|
// is config changing
|
||||||
bool changing;
|
bool changing;
|
||||||
|
|
||||||
|
int64_t snapshottingIndex;
|
||||||
|
int64_t snapshottingTime;
|
||||||
|
int64_t minMatchIndex;
|
||||||
|
|
||||||
int64_t startTime;
|
int64_t startTime;
|
||||||
int64_t leaderTime;
|
int64_t leaderTime;
|
||||||
int64_t lastReplicateTime;
|
int64_t lastReplicateTime;
|
||||||
|
@ -174,7 +212,6 @@ void syncNodeStart(SSyncNode* pSyncNode);
|
||||||
void syncNodeStartStandBy(SSyncNode* pSyncNode);
|
void syncNodeStartStandBy(SSyncNode* pSyncNode);
|
||||||
void syncNodeClose(SSyncNode* pSyncNode);
|
void syncNodeClose(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak);
|
int32_t syncNodePropose(SSyncNode* pSyncNode, SRpcMsg* pMsg, bool isWeak);
|
||||||
int32_t syncNodeProposeBatch(SSyncNode* pSyncNode, SRpcMsg** pMsgPArr, bool* pIsWeakArr, int32_t arrSize);
|
|
||||||
|
|
||||||
// option
|
// option
|
||||||
bool syncNodeSnapshotEnable(SSyncNode* pSyncNode);
|
bool syncNodeSnapshotEnable(SSyncNode* pSyncNode);
|
||||||
|
@ -197,23 +234,21 @@ int32_t syncNodeRestartElectTimer(SSyncNode* pSyncNode, int32_t ms);
|
||||||
int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode);
|
int32_t syncNodeResetElectTimer(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode);
|
int32_t syncNodeStartHeartbeatTimer(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeStartHeartbeatTimerNow(SSyncNode* pSyncNode);
|
|
||||||
int32_t syncNodeStartHeartbeatTimerMS(SSyncNode* pSyncNode, int32_t ms);
|
|
||||||
int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode);
|
int32_t syncNodeStopHeartbeatTimer(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode);
|
int32_t syncNodeRestartHeartbeatTimer(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeRestartHeartbeatTimerNow(SSyncNode* pSyncNode);
|
|
||||||
int32_t syncNodeRestartNowHeartbeatTimerMS(SSyncNode* pSyncNode, int32_t ms);
|
|
||||||
|
|
||||||
// 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);
|
cJSON* syncNode2Json(const SSyncNode* pSyncNode);
|
||||||
char* syncNode2Str(const SSyncNode* pSyncNode);
|
char* syncNode2Str(const SSyncNode* pSyncNode);
|
||||||
void syncNodeEventLog(const SSyncNode* pSyncNode, char* str);
|
void syncNodeEventLog(const SSyncNode* pSyncNode, char* str);
|
||||||
void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str);
|
void syncNodeErrorLog(const SSyncNode* pSyncNode, char* str);
|
||||||
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);
|
||||||
|
SyncIndex syncMinMatchIndex(SSyncNode* pSyncNode);
|
||||||
|
char* syncNodePeerState2Str(const SSyncNode* pSyncNode);
|
||||||
|
|
||||||
SSyncNode* syncNodeAcquire(int64_t rid);
|
SSyncNode* syncNodeAcquire(int64_t rid);
|
||||||
void syncNodeRelease(SSyncNode* pNode);
|
void syncNodeRelease(SSyncNode* pNode);
|
||||||
|
@ -221,6 +256,7 @@ void syncNodeRelease(SSyncNode* pNode);
|
||||||
// raft state change --------------
|
// raft state change --------------
|
||||||
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term);
|
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term);
|
||||||
void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term);
|
void syncNodeUpdateTermWithoutStepDown(SSyncNode* pSyncNode, SyncTerm term);
|
||||||
|
void syncNodeStepDown(SSyncNode* pSyncNode, SyncTerm newTerm);
|
||||||
void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr);
|
void syncNodeBecomeFollower(SSyncNode* pSyncNode, const char* debugStr);
|
||||||
void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr);
|
void syncNodeBecomeLeader(SSyncNode* pSyncNode, const char* debugStr);
|
||||||
|
|
||||||
|
@ -240,21 +276,23 @@ void syncNodeMaybeUpdateCommitBySnapshot(SSyncNode* pSyncNode);
|
||||||
SyncIndex syncNodeGetLastIndex(const SSyncNode* pSyncNode);
|
SyncIndex syncNodeGetLastIndex(const SSyncNode* pSyncNode);
|
||||||
SyncTerm syncNodeGetLastTerm(SSyncNode* pSyncNode);
|
SyncTerm syncNodeGetLastTerm(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm);
|
int32_t syncNodeGetLastIndexTerm(SSyncNode* pSyncNode, SyncIndex* pLastIndex, SyncTerm* pLastTerm);
|
||||||
|
|
||||||
SyncIndex syncNodeSyncStartIndex(SSyncNode* pSyncNode);
|
SyncIndex syncNodeSyncStartIndex(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index);
|
SyncIndex syncNodeGetPreIndex(SSyncNode* pSyncNode, SyncIndex index);
|
||||||
SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index);
|
SyncTerm syncNodeGetPreTerm(SSyncNode* pSyncNode, SyncIndex index);
|
||||||
int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm);
|
int32_t syncNodeGetPreIndexTerm(SSyncNode* pSyncNode, SyncIndex index, SyncIndex* pPreIndex, SyncTerm* pPreTerm);
|
||||||
|
|
||||||
bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg);
|
bool syncNodeIsOptimizedOneReplica(SSyncNode* ths, SRpcMsg* pMsg);
|
||||||
int32_t syncNodeCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag);
|
int32_t syncNodeDoCommit(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, uint64_t flag);
|
||||||
|
int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex);
|
||||||
int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry, int32_t code);
|
int32_t syncNodePreCommit(SSyncNode* ths, SSyncRaftEntry* pEntry, int32_t code);
|
||||||
|
|
||||||
int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg);
|
int32_t syncNodeUpdateNewConfigIndex(SSyncNode* ths, SSyncCfg* pNewCfg);
|
||||||
|
|
||||||
bool syncNodeInRaftGroup(SSyncNode* ths, SRaftId* pRaftId);
|
bool syncNodeInRaftGroup(SSyncNode* ths, SRaftId* pRaftId);
|
||||||
SSyncSnapshotSender* syncNodeGetSnapshotSender(SSyncNode* ths, SRaftId* pDestId);
|
SSyncSnapshotSender* syncNodeGetSnapshotSender(SSyncNode* ths, SRaftId* pDestId);
|
||||||
|
SSyncTimer* syncNodeGetHbTimer(SSyncNode* ths, SRaftId* pDestId);
|
||||||
|
SPeerState* syncNodeGetPeerState(SSyncNode* ths, const SRaftId* pDestId);
|
||||||
|
bool syncNodeNeedSendAppendEntries(SSyncNode* ths, const SRaftId* pDestId, const SyncAppendEntries* pMsg);
|
||||||
|
|
||||||
int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
|
int32_t syncGetSnapshotMeta(int64_t rid, struct SSnapshotMeta* sMeta);
|
||||||
int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta);
|
int32_t syncGetSnapshotMetaByIndex(int64_t rid, SyncIndex snapshotIndex, struct SSnapshotMeta* sMeta);
|
||||||
|
@ -271,7 +309,12 @@ int32_t syncDoLeaderTransfer(SSyncNode* ths, SRpcMsg* pRpcMsg, SSyncRaftEntry* p
|
||||||
|
|
||||||
int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode);
|
int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode);
|
||||||
|
|
||||||
|
bool syncNodeIsMnode(SSyncNode* pSyncNode);
|
||||||
|
int32_t syncNodePeerStateInit(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
// trace log
|
// trace log
|
||||||
|
void syncLogRecvTimer(SSyncNode* pSyncNode, const SyncTimeout* pMsg, const char* s);
|
||||||
|
|
||||||
void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
void syncLogSendRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
||||||
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
void syncLogRecvRequestVote(SSyncNode* pSyncNode, const SyncRequestVote* pMsg, const char* s);
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ int32_t raftCfgIndexClose(SRaftCfgIndex *pRaftCfgIndex);
|
||||||
int32_t raftCfgIndexPersist(SRaftCfgIndex *pRaftCfgIndex);
|
int32_t raftCfgIndexPersist(SRaftCfgIndex *pRaftCfgIndex);
|
||||||
int32_t raftCfgIndexAddConfigIndex(SRaftCfgIndex *pRaftCfgIndex, SyncIndex configIndex);
|
int32_t raftCfgIndexAddConfigIndex(SRaftCfgIndex *pRaftCfgIndex, SyncIndex configIndex);
|
||||||
|
|
||||||
cJSON *raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex);
|
cJSON * raftCfgIndex2Json(SRaftCfgIndex *pRaftCfgIndex);
|
||||||
char *raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex);
|
char * raftCfgIndex2Str(SRaftCfgIndex *pRaftCfgIndex);
|
||||||
int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex);
|
int32_t raftCfgIndexFromJson(const cJSON *pRoot, SRaftCfgIndex *pRaftCfgIndex);
|
||||||
int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex);
|
int32_t raftCfgIndexFromStr(const char *s, SRaftCfgIndex *pRaftCfgIndex);
|
||||||
|
|
||||||
|
@ -73,14 +73,14 @@ int32_t raftCfgClose(SRaftCfg *pRaftCfg);
|
||||||
int32_t raftCfgPersist(SRaftCfg *pRaftCfg);
|
int32_t raftCfgPersist(SRaftCfg *pRaftCfg);
|
||||||
int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex);
|
int32_t raftCfgAddConfigIndex(SRaftCfg *pRaftCfg, SyncIndex configIndex);
|
||||||
|
|
||||||
cJSON *syncCfg2Json(SSyncCfg *pSyncCfg);
|
cJSON * syncCfg2Json(SSyncCfg *pSyncCfg);
|
||||||
char *syncCfg2Str(SSyncCfg *pSyncCfg);
|
char * syncCfg2Str(SSyncCfg *pSyncCfg);
|
||||||
char *syncCfg2SimpleStr(SSyncCfg *pSyncCfg);
|
char * syncCfg2SimpleStr(SSyncCfg *pSyncCfg);
|
||||||
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg);
|
int32_t syncCfgFromJson(const cJSON *pRoot, SSyncCfg *pSyncCfg);
|
||||||
int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg);
|
int32_t syncCfgFromStr(const char *s, SSyncCfg *pSyncCfg);
|
||||||
|
|
||||||
cJSON *raftCfg2Json(SRaftCfg *pRaftCfg);
|
cJSON * raftCfg2Json(SRaftCfg *pRaftCfg);
|
||||||
char *raftCfg2Str(SRaftCfg *pRaftCfg);
|
char * raftCfg2Str(SRaftCfg *pRaftCfg);
|
||||||
int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg);
|
int32_t raftCfgFromJson(const cJSON *pRoot, SRaftCfg *pRaftCfg);
|
||||||
int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg);
|
int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg);
|
||||||
|
|
||||||
|
|
|
@ -50,16 +50,15 @@ extern "C" {
|
||||||
// msource |-> i,
|
// msource |-> i,
|
||||||
// mdest |-> j])
|
// mdest |-> j])
|
||||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||||
//
|
|
||||||
int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode);
|
|
||||||
int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode);
|
|
||||||
int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode);
|
|
||||||
|
|
||||||
int32_t syncNodeAppendEntriesOnePeer(SSyncNode* pSyncNode, SRaftId* pDestId, SyncIndex nextIndex);
|
int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode);
|
||||||
|
int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncHeartbeat* pMsg);
|
||||||
|
|
||||||
int32_t syncNodeReplicate(SSyncNode* pSyncNode, bool isTimer);
|
int32_t syncNodeReplicate(SSyncNode* pSyncNode);
|
||||||
int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg);
|
int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId);
|
||||||
int32_t syncNodeAppendEntriesBatch(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntriesBatch* pMsg);
|
|
||||||
|
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncAppendEntries* pMsg);
|
||||||
|
int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* pDestId, const SyncAppendEntries* pMsg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,8 +49,7 @@ extern "C" {
|
||||||
// m)
|
// m)
|
||||||
// /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
|
// /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg);
|
int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg);
|
||||||
int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,8 +44,7 @@ extern "C" {
|
||||||
// /\ Discard(m)
|
// /\ Discard(m)
|
||||||
// /\ UNCHANGED <<serverVars, votedFor, leaderVars, logVars>>
|
// /\ UNCHANGED <<serverVars, votedFor, leaderVars, logVars>>
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
||||||
int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,9 +32,9 @@ typedef struct SRespStub {
|
||||||
} SRespStub;
|
} SRespStub;
|
||||||
|
|
||||||
typedef struct SSyncRespMgr {
|
typedef struct SSyncRespMgr {
|
||||||
SHashObj *pRespHash;
|
SHashObj * pRespHash;
|
||||||
int64_t ttl;
|
int64_t ttl;
|
||||||
void *data;
|
void * data;
|
||||||
TdThreadMutex mutex;
|
TdThreadMutex mutex;
|
||||||
uint64_t seqNum;
|
uint64_t seqNum;
|
||||||
} SSyncRespMgr;
|
} SSyncRespMgr;
|
||||||
|
|
|
@ -28,10 +28,10 @@ extern "C" {
|
||||||
#include "syncMessage.h"
|
#include "syncMessage.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
|
|
||||||
#define SYNC_SNAPSHOT_SEQ_INVALID -1
|
#define SYNC_SNAPSHOT_SEQ_INVALID -1
|
||||||
#define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE -2
|
#define SYNC_SNAPSHOT_SEQ_FORCE_CLOSE -2
|
||||||
#define SYNC_SNAPSHOT_SEQ_BEGIN 0
|
#define SYNC_SNAPSHOT_SEQ_BEGIN 0
|
||||||
#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF
|
#define SYNC_SNAPSHOT_SEQ_END 0x7FFFFFFF
|
||||||
|
|
||||||
#define SYNC_SNAPSHOT_RETRY_MS 5000
|
#define SYNC_SNAPSHOT_RETRY_MS 5000
|
||||||
|
|
||||||
|
@ -51,6 +51,7 @@ typedef struct SSyncSnapshotSender {
|
||||||
int32_t replicaIndex;
|
int32_t replicaIndex;
|
||||||
SyncTerm term;
|
SyncTerm term;
|
||||||
SyncTerm privateTerm;
|
SyncTerm privateTerm;
|
||||||
|
int64_t startTime;
|
||||||
bool finish;
|
bool finish;
|
||||||
} SSyncSnapshotSender;
|
} SSyncSnapshotSender;
|
||||||
|
|
||||||
|
@ -67,6 +68,8 @@ cJSON *snapshotSender2Json(SSyncSnapshotSender *pSender);
|
||||||
char *snapshotSender2Str(SSyncSnapshotSender *pSender);
|
char *snapshotSender2Str(SSyncSnapshotSender *pSender);
|
||||||
char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event);
|
char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event);
|
||||||
|
|
||||||
|
int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId);
|
||||||
|
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
typedef struct SSyncSnapshotReceiver {
|
typedef struct SSyncSnapshotReceiver {
|
||||||
bool start;
|
bool start;
|
||||||
|
@ -94,8 +97,8 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event)
|
||||||
|
|
||||||
//---------------------------------------------------
|
//---------------------------------------------------
|
||||||
// on message
|
// on message
|
||||||
int32_t syncNodeOnSnapshotSendCb(SSyncNode *ths, SyncSnapshotSend *pMsg);
|
int32_t syncNodeOnSnapshot(SSyncNode *ths, SyncSnapshotSend *pMsg);
|
||||||
int32_t syncNodeOnSnapshotRspCb(SSyncNode *ths, SyncSnapshotRsp *pMsg);
|
int32_t syncNodeOnSnapshotReply(SSyncNode *ths, SyncSnapshotRsp *pMsg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ extern "C" {
|
||||||
// /\ voterLog' = [voterLog EXCEPT ![i] = [j \in {} |-> <<>>]]
|
// /\ voterLog' = [voterLog EXCEPT ![i] = [j \in {} |-> <<>>]]
|
||||||
// /\ UNCHANGED <<messages, leaderVars, logVars>>
|
// /\ UNCHANGED <<messages, leaderVars, logVars>>
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg);
|
int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,240 +89,6 @@
|
||||||
// /\ UNCHANGED <<candidateVars, leaderVars>>
|
// /\ UNCHANGED <<candidateVars, leaderVars>>
|
||||||
//
|
//
|
||||||
|
|
||||||
int32_t syncNodeOnAppendEntriesCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
|
||||||
int32_t ret = 0;
|
|
||||||
|
|
||||||
// if already drop replica, do not process
|
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "maybe replica already dropped");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// maybe update term
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
|
||||||
syncNodeUpdateTerm(ths, pMsg->term);
|
|
||||||
}
|
|
||||||
ASSERT(pMsg->term <= ths->pRaftStore->currentTerm);
|
|
||||||
|
|
||||||
// reset elect timer
|
|
||||||
if (pMsg->term == ths->pRaftStore->currentTerm) {
|
|
||||||
ths->leaderCache = pMsg->srcId;
|
|
||||||
syncNodeResetElectTimer(ths);
|
|
||||||
}
|
|
||||||
ASSERT(pMsg->dataLen >= 0);
|
|
||||||
|
|
||||||
// return to follower state
|
|
||||||
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "candidate to follower");
|
|
||||||
syncNodeBecomeFollower(ths, "from candidate by append entries");
|
|
||||||
return -1; // ret or reply?
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncTerm localPreLogTerm = 0;
|
|
||||||
if (pMsg->prevLogIndex >= SYNC_INDEX_BEGIN && pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
|
||||||
SSyncRaftEntry* pEntry = ths->pLogStore->getEntry(ths->pLogStore, pMsg->prevLogIndex);
|
|
||||||
if (pEntry == NULL) {
|
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "getEntry error, index:%" PRId64 ", since %s", pMsg->prevLogIndex, terrstr());
|
|
||||||
syncNodeErrorLog(ths, logBuf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
localPreLogTerm = pEntry->term;
|
|
||||||
syncEntryDestory(pEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool logOK =
|
|
||||||
(pMsg->prevLogIndex == SYNC_INDEX_INVALID) ||
|
|
||||||
((pMsg->prevLogIndex >= SYNC_INDEX_BEGIN) &&
|
|
||||||
(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) && (pMsg->prevLogTerm == localPreLogTerm));
|
|
||||||
|
|
||||||
// reject request
|
|
||||||
if ((pMsg->term < ths->pRaftStore->currentTerm) ||
|
|
||||||
((pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK)) {
|
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "reject");
|
|
||||||
|
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
|
||||||
pReply->srcId = ths->myRaftId;
|
|
||||||
pReply->destId = pMsg->srcId;
|
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
|
||||||
pReply->success = false;
|
|
||||||
pReply->matchIndex = SYNC_INDEX_INVALID;
|
|
||||||
pReply->startTime = ths->startTime;
|
|
||||||
|
|
||||||
// msg event log
|
|
||||||
syncLogSendAppendEntriesReply(ths, pReply, "");
|
|
||||||
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pReply);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
// accept request
|
|
||||||
if (pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_FOLLOWER && logOK) {
|
|
||||||
// preIndex = -1, or has preIndex entry in local log
|
|
||||||
ASSERT(pMsg->prevLogIndex <= ths->pLogStore->getLastIndex(ths->pLogStore));
|
|
||||||
|
|
||||||
// has extra entries (> preIndex) in local log
|
|
||||||
bool hasExtraEntries = pMsg->prevLogIndex < ths->pLogStore->getLastIndex(ths->pLogStore);
|
|
||||||
|
|
||||||
// has entries in SyncAppendEntries msg
|
|
||||||
bool hasAppendEntries = pMsg->dataLen > 0;
|
|
||||||
|
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "accept");
|
|
||||||
|
|
||||||
if (hasExtraEntries && hasAppendEntries) {
|
|
||||||
// not conflict by default
|
|
||||||
bool conflict = false;
|
|
||||||
|
|
||||||
SyncIndex extraIndex = pMsg->prevLogIndex + 1;
|
|
||||||
SSyncRaftEntry* pExtraEntry = ths->pLogStore->getEntry(ths->pLogStore, extraIndex);
|
|
||||||
if (pExtraEntry == NULL) {
|
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "getEntry error2, index:%" PRId64 ", since %s", extraIndex, terrstr());
|
|
||||||
syncNodeErrorLog(ths, logBuf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
|
||||||
if (pAppendEntry == NULL) {
|
|
||||||
syncNodeErrorLog(ths, "syncEntryDeserialize pAppendEntry error");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// log not match, conflict
|
|
||||||
ASSERT(extraIndex == pAppendEntry->index);
|
|
||||||
if (pExtraEntry->term != pAppendEntry->term) {
|
|
||||||
conflict = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (conflict) {
|
|
||||||
// roll back
|
|
||||||
SyncIndex delBegin = ths->pLogStore->getLastIndex(ths->pLogStore);
|
|
||||||
SyncIndex delEnd = extraIndex;
|
|
||||||
|
|
||||||
sTrace("syncNodeOnAppendEntriesCb --> conflict:%d, delBegin:%" PRId64 ", delEnd:%" PRId64, conflict, delBegin,
|
|
||||||
delEnd);
|
|
||||||
|
|
||||||
// notice! reverse roll back!
|
|
||||||
for (SyncIndex index = delEnd; index >= delBegin; --index) {
|
|
||||||
if (ths->pFsm->FpRollBackCb != NULL) {
|
|
||||||
SSyncRaftEntry* pRollBackEntry = ths->pLogStore->getEntry(ths->pLogStore, index);
|
|
||||||
if (pRollBackEntry == NULL) {
|
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "getEntry error3, index:%" PRId64 ", since %s", index, terrstr());
|
|
||||||
syncNodeErrorLog(ths, logBuf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (pRollBackEntry->msgType != TDMT_SYNC_NOOP) {
|
|
||||||
if (syncUtilUserRollback(pRollBackEntry->msgType)) {
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncEntry2OriginalRpc(pRollBackEntry, &rpcMsg);
|
|
||||||
|
|
||||||
SFsmCbMeta cbMeta = {0};
|
|
||||||
cbMeta.index = pRollBackEntry->index;
|
|
||||||
cbMeta.lastConfigIndex = syncNodeGetSnapshotConfigIndex(ths, cbMeta.index);
|
|
||||||
cbMeta.isWeak = pRollBackEntry->isWeak;
|
|
||||||
cbMeta.code = 0;
|
|
||||||
cbMeta.state = ths->state;
|
|
||||||
cbMeta.seqNum = pRollBackEntry->seqNum;
|
|
||||||
ths->pFsm->FpRollBackCb(ths->pFsm, &rpcMsg, cbMeta);
|
|
||||||
rpcFreeCont(rpcMsg.pCont);
|
|
||||||
}
|
|
||||||
|
|
||||||
syncEntryDestory(pRollBackEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// delete confict entries
|
|
||||||
ths->pLogStore->truncate(ths->pLogStore, extraIndex);
|
|
||||||
|
|
||||||
// append new entries
|
|
||||||
ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry);
|
|
||||||
|
|
||||||
// pre commit
|
|
||||||
syncNodePreCommit(ths, pAppendEntry, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// free memory
|
|
||||||
syncEntryDestory(pExtraEntry);
|
|
||||||
syncEntryDestory(pAppendEntry);
|
|
||||||
|
|
||||||
} else if (hasExtraEntries && !hasAppendEntries) {
|
|
||||||
// do nothing
|
|
||||||
|
|
||||||
} else if (!hasExtraEntries && hasAppendEntries) {
|
|
||||||
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
|
||||||
if (pAppendEntry == NULL) {
|
|
||||||
syncNodeErrorLog(ths, "syncEntryDeserialize pAppendEntry2 error");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// append new entries
|
|
||||||
ths->pLogStore->appendEntry(ths->pLogStore, pAppendEntry);
|
|
||||||
|
|
||||||
// pre commit
|
|
||||||
syncNodePreCommit(ths, pAppendEntry, 0);
|
|
||||||
|
|
||||||
// free memory
|
|
||||||
syncEntryDestory(pAppendEntry);
|
|
||||||
|
|
||||||
} else if (!hasExtraEntries && !hasAppendEntries) {
|
|
||||||
// do nothing
|
|
||||||
|
|
||||||
} else {
|
|
||||||
syncNodeLog3("", ths);
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
|
||||||
pReply->srcId = ths->myRaftId;
|
|
||||||
pReply->destId = pMsg->srcId;
|
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
|
||||||
pReply->success = true;
|
|
||||||
|
|
||||||
if (hasAppendEntries) {
|
|
||||||
pReply->matchIndex = pMsg->prevLogIndex + 1;
|
|
||||||
} else {
|
|
||||||
pReply->matchIndex = pMsg->prevLogIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
pReply->startTime = ths->startTime;
|
|
||||||
|
|
||||||
// msg event log
|
|
||||||
syncLogSendAppendEntriesReply(ths, pReply, "");
|
|
||||||
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pReply);
|
|
||||||
|
|
||||||
// maybe update commit index from leader
|
|
||||||
if (pMsg->commitIndex > ths->commitIndex) {
|
|
||||||
// has commit entry in local
|
|
||||||
if (pMsg->commitIndex <= ths->pLogStore->getLastIndex(ths->pLogStore)) {
|
|
||||||
SyncIndex beginIndex = ths->commitIndex + 1;
|
|
||||||
SyncIndex endIndex = pMsg->commitIndex;
|
|
||||||
|
|
||||||
// update commit index
|
|
||||||
ths->commitIndex = pMsg->commitIndex;
|
|
||||||
|
|
||||||
// call back Wal
|
|
||||||
ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex);
|
|
||||||
|
|
||||||
int32_t code = syncNodeCommit(ths, beginIndex, endIndex, ths->state);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
static int32_t syncNodeMakeLogSame(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
|
|
||||||
|
@ -505,544 +271,222 @@ static bool syncNodeOnAppendEntriesLogOK(SSyncNode* pSyncNode, SyncAppendEntries
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeOnAppendEntriesSnapshot2Cb(SSyncNode* ths, SyncAppendEntriesBatch* pMsg) {
|
int32_t syncNodeFollowerCommit(SSyncNode* ths, SyncIndex newCommitIndex) {
|
||||||
int32_t ret = 0;
|
// maybe update commit index, leader notice me
|
||||||
int32_t code = 0;
|
if (newCommitIndex > ths->commitIndex) {
|
||||||
|
// has commit entry in local
|
||||||
|
if (newCommitIndex <= ths->pLogStore->syncLogLastIndex(ths->pLogStore)) {
|
||||||
|
// advance commit index to sanpshot first
|
||||||
|
SSnapshot snapshot;
|
||||||
|
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
|
||||||
|
if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex > ths->commitIndex) {
|
||||||
|
SyncIndex commitBegin = ths->commitIndex;
|
||||||
|
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
||||||
|
ths->commitIndex = snapshot.lastApplyIndex;
|
||||||
|
|
||||||
// if already drop replica, do not process
|
char eventLog[128];
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64, commitBegin,
|
||||||
syncLogRecvAppendEntriesBatch(ths, pMsg, "maybe replica already dropped");
|
commitEnd);
|
||||||
return -1;
|
syncNodeEventLog(ths, eventLog);
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncIndex beginIndex = ths->commitIndex + 1;
|
||||||
|
SyncIndex endIndex = newCommitIndex;
|
||||||
|
|
||||||
|
// update commit index
|
||||||
|
ths->commitIndex = newCommitIndex;
|
||||||
|
|
||||||
|
// call back Wal
|
||||||
|
int32_t code = ths->pLogStore->syncLogUpdateCommitIndex(ths->pLogStore, ths->commitIndex);
|
||||||
|
ASSERT(code == 0);
|
||||||
|
|
||||||
|
code = syncNodeDoCommit(ths, beginIndex, endIndex, ths->state);
|
||||||
|
ASSERT(code == 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe update term
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
|
||||||
syncNodeUpdateTerm(ths, pMsg->term);
|
|
||||||
}
|
|
||||||
ASSERT(pMsg->term <= ths->pRaftStore->currentTerm);
|
|
||||||
|
|
||||||
// reset elect timer
|
|
||||||
if (pMsg->term == ths->pRaftStore->currentTerm) {
|
|
||||||
ths->leaderCache = pMsg->srcId;
|
|
||||||
syncNodeResetElectTimer(ths);
|
|
||||||
}
|
|
||||||
ASSERT(pMsg->dataLen >= 0);
|
|
||||||
|
|
||||||
// candidate to follower
|
|
||||||
//
|
|
||||||
// operation:
|
|
||||||
// to follower
|
|
||||||
do {
|
|
||||||
bool condition = pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE;
|
|
||||||
if (condition) {
|
|
||||||
syncLogRecvAppendEntriesBatch(ths, pMsg, "candidate to follower");
|
|
||||||
syncNodeBecomeFollower(ths, "from candidate by append entries");
|
|
||||||
return 0; // do not reply?
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
// fake match
|
|
||||||
//
|
|
||||||
// condition1:
|
|
||||||
// preIndex <= my commit index
|
|
||||||
//
|
|
||||||
// operation:
|
|
||||||
// if hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex, append entry
|
|
||||||
// match my-commit-index or my-commit-index + batchSize
|
|
||||||
do {
|
|
||||||
bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) &&
|
|
||||||
(pMsg->prevLogIndex <= ths->commitIndex);
|
|
||||||
if (condition) {
|
|
||||||
syncLogRecvAppendEntriesBatch(ths, pMsg, "fake match");
|
|
||||||
|
|
||||||
SyncIndex matchIndex = ths->commitIndex;
|
|
||||||
bool hasAppendEntries = pMsg->dataLen > 0;
|
|
||||||
SOffsetAndContLen* metaTableArr = syncAppendEntriesBatchMetaTableArray(pMsg);
|
|
||||||
|
|
||||||
if (hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex) {
|
|
||||||
int32_t pass = 0;
|
|
||||||
SyncIndex logLastIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
|
||||||
bool hasExtraEntries = logLastIndex > pMsg->prevLogIndex;
|
|
||||||
|
|
||||||
// make log same
|
|
||||||
if (hasExtraEntries) {
|
|
||||||
// make log same, rollback deleted entries
|
|
||||||
pass = syncNodeDoMakeLogSame(ths, pMsg->prevLogIndex + 1);
|
|
||||||
ASSERT(pass >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// append entry batch
|
|
||||||
if (pass == 0) {
|
|
||||||
// assert! no batch
|
|
||||||
ASSERT(pMsg->dataCount <= 1);
|
|
||||||
|
|
||||||
for (int32_t i = 0; i < pMsg->dataCount; ++i) {
|
|
||||||
SSyncRaftEntry* pAppendEntry = (SSyncRaftEntry*)(pMsg->data + metaTableArr[i].offset);
|
|
||||||
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
|
||||||
if (code != 0) {
|
|
||||||
sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = syncNodePreCommit(ths, pAppendEntry, 0);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
|
|
||||||
// syncEntryDestory(pAppendEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fsync once
|
|
||||||
SSyncLogStoreData* pData = ths->pLogStore->data;
|
|
||||||
SWal* pWal = pData->pWal;
|
|
||||||
walFsync(pWal, false);
|
|
||||||
|
|
||||||
// update match index
|
|
||||||
matchIndex = pMsg->prevLogIndex + pMsg->dataCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepare response msg
|
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
|
||||||
pReply->srcId = ths->myRaftId;
|
|
||||||
pReply->destId = pMsg->srcId;
|
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
|
||||||
pReply->privateTerm = ths->pNewNodeReceiver->privateTerm;
|
|
||||||
pReply->success = true;
|
|
||||||
pReply->matchIndex = matchIndex;
|
|
||||||
pReply->startTime = ths->startTime;
|
|
||||||
|
|
||||||
// msg event log
|
|
||||||
syncLogSendAppendEntriesReply(ths, pReply, "");
|
|
||||||
|
|
||||||
// send response
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pReply);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
// calculate logOK here, before will coredump, due to fake match
|
|
||||||
bool logOK = syncNodeOnAppendEntriesBatchLogOK(ths, pMsg);
|
|
||||||
|
|
||||||
// not match
|
|
||||||
//
|
|
||||||
// condition1:
|
|
||||||
// term < myTerm
|
|
||||||
//
|
|
||||||
// condition2:
|
|
||||||
// !logOK
|
|
||||||
//
|
|
||||||
// operation:
|
|
||||||
// not match
|
|
||||||
// no operation on log
|
|
||||||
do {
|
|
||||||
bool condition1 = pMsg->term < ths->pRaftStore->currentTerm;
|
|
||||||
bool condition2 =
|
|
||||||
(pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK;
|
|
||||||
bool condition = condition1 || condition2;
|
|
||||||
|
|
||||||
if (condition) {
|
|
||||||
syncLogRecvAppendEntriesBatch(ths, pMsg, "not match");
|
|
||||||
|
|
||||||
// maybe update commit index by snapshot
|
|
||||||
syncNodeMaybeUpdateCommitBySnapshot(ths);
|
|
||||||
|
|
||||||
// prepare response msg
|
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
|
||||||
pReply->srcId = ths->myRaftId;
|
|
||||||
pReply->destId = pMsg->srcId;
|
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
|
||||||
pReply->privateTerm = ths->pNewNodeReceiver->privateTerm;
|
|
||||||
pReply->success = false;
|
|
||||||
pReply->matchIndex = ths->commitIndex;
|
|
||||||
pReply->startTime = ths->startTime;
|
|
||||||
|
|
||||||
// msg event log
|
|
||||||
syncLogSendAppendEntriesReply(ths, pReply, "");
|
|
||||||
|
|
||||||
// send response
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pReply);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
// really match
|
|
||||||
//
|
|
||||||
// condition:
|
|
||||||
// logOK
|
|
||||||
//
|
|
||||||
// operation:
|
|
||||||
// match
|
|
||||||
// make log same
|
|
||||||
do {
|
|
||||||
bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && logOK;
|
|
||||||
if (condition) {
|
|
||||||
// has extra entries (> preIndex) in local log
|
|
||||||
SyncIndex myLastIndex = syncNodeGetLastIndex(ths);
|
|
||||||
bool hasExtraEntries = myLastIndex > pMsg->prevLogIndex;
|
|
||||||
|
|
||||||
// has entries in SyncAppendEntries msg
|
|
||||||
bool hasAppendEntries = pMsg->dataLen > 0;
|
|
||||||
SOffsetAndContLen* metaTableArr = syncAppendEntriesBatchMetaTableArray(pMsg);
|
|
||||||
|
|
||||||
syncLogRecvAppendEntriesBatch(ths, pMsg, "really match");
|
|
||||||
|
|
||||||
int32_t pass = 0;
|
|
||||||
|
|
||||||
if (hasExtraEntries) {
|
|
||||||
// make log same, rollback deleted entries
|
|
||||||
pass = syncNodeDoMakeLogSame(ths, pMsg->prevLogIndex + 1);
|
|
||||||
ASSERT(pass >= 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasAppendEntries) {
|
|
||||||
// append entry batch
|
|
||||||
if (pass == 0) {
|
|
||||||
// assert! no batch
|
|
||||||
ASSERT(pMsg->dataCount <= 1);
|
|
||||||
|
|
||||||
// append entry batch
|
|
||||||
for (int32_t i = 0; i < pMsg->dataCount; ++i) {
|
|
||||||
SSyncRaftEntry* pAppendEntry = (SSyncRaftEntry*)(pMsg->data + metaTableArr[i].offset);
|
|
||||||
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
|
||||||
if (code != 0) {
|
|
||||||
sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
code = syncNodePreCommit(ths, pAppendEntry, 0);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
|
|
||||||
// syncEntryDestory(pAppendEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// fsync once
|
|
||||||
SSyncLogStoreData* pData = ths->pLogStore->data;
|
|
||||||
SWal* pWal = pData->pWal;
|
|
||||||
walFsync(pWal, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepare response msg
|
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
|
||||||
pReply->srcId = ths->myRaftId;
|
|
||||||
pReply->destId = pMsg->srcId;
|
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
|
||||||
pReply->privateTerm = ths->pNewNodeReceiver->privateTerm;
|
|
||||||
pReply->success = true;
|
|
||||||
pReply->matchIndex = hasAppendEntries ? pMsg->prevLogIndex + pMsg->dataCount : pMsg->prevLogIndex;
|
|
||||||
pReply->startTime = ths->startTime;
|
|
||||||
|
|
||||||
// msg event log
|
|
||||||
syncLogSendAppendEntriesReply(ths, pReply, "");
|
|
||||||
|
|
||||||
// send response
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pReply);
|
|
||||||
|
|
||||||
// maybe update commit index, leader notice me
|
|
||||||
if (pMsg->commitIndex > ths->commitIndex) {
|
|
||||||
SyncIndex lastIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
|
||||||
|
|
||||||
SyncIndex beginIndex = 0;
|
|
||||||
SyncIndex endIndex = -1;
|
|
||||||
|
|
||||||
// has commit entry in local
|
|
||||||
if (pMsg->commitIndex <= lastIndex) {
|
|
||||||
beginIndex = ths->commitIndex + 1;
|
|
||||||
endIndex = pMsg->commitIndex;
|
|
||||||
|
|
||||||
// update commit index
|
|
||||||
ths->commitIndex = pMsg->commitIndex;
|
|
||||||
|
|
||||||
// call back Wal
|
|
||||||
code = ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
|
|
||||||
} else if (pMsg->commitIndex > lastIndex && ths->commitIndex < lastIndex) {
|
|
||||||
beginIndex = ths->commitIndex + 1;
|
|
||||||
endIndex = lastIndex;
|
|
||||||
|
|
||||||
// update commit index, speed up
|
|
||||||
ths->commitIndex = lastIndex;
|
|
||||||
|
|
||||||
// call back Wal
|
|
||||||
code = ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
code = syncNodeCommit(ths, beginIndex, endIndex, ths->state);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeOnAppendEntriesSnapshotCb(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
int32_t syncNodeOnAppendEntries(SSyncNode* ths, SyncAppendEntries* pMsg) {
|
||||||
int32_t ret = 0;
|
|
||||||
int32_t code = 0;
|
|
||||||
|
|
||||||
// if already drop replica, do not process
|
// if already drop replica, do not process
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "maybe replica already dropped");
|
syncLogRecvAppendEntries(ths, pMsg, "not in my config");
|
||||||
return -1;
|
goto _IGNORE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// prepare response msg
|
||||||
|
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
||||||
|
pReply->srcId = ths->myRaftId;
|
||||||
|
pReply->destId = pMsg->srcId;
|
||||||
|
pReply->term = ths->pRaftStore->currentTerm;
|
||||||
|
pReply->success = false;
|
||||||
|
// pReply->matchIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
||||||
|
pReply->matchIndex = SYNC_INDEX_INVALID;
|
||||||
|
pReply->lastSendIndex = pMsg->prevLogIndex + 1;
|
||||||
|
pReply->privateTerm = ths->pNewNodeReceiver->privateTerm;
|
||||||
|
pReply->startTime = ths->startTime;
|
||||||
|
|
||||||
|
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
||||||
|
syncLogRecvAppendEntries(ths, pMsg, "reject, small term");
|
||||||
|
goto _SEND_RESPONSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// maybe update term
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
syncNodeUpdateTerm(ths, pMsg->term);
|
pReply->term = pMsg->term;
|
||||||
}
|
}
|
||||||
ASSERT(pMsg->term <= ths->pRaftStore->currentTerm);
|
|
||||||
|
|
||||||
// reset elect timer
|
syncNodeStepDown(ths, pMsg->term);
|
||||||
if (pMsg->term == ths->pRaftStore->currentTerm) {
|
syncNodeResetElectTimer(ths);
|
||||||
ths->leaderCache = pMsg->srcId;
|
|
||||||
syncNodeResetElectTimer(ths);
|
SyncIndex startIndex = ths->pLogStore->syncLogBeginIndex(ths->pLogStore);
|
||||||
|
SyncIndex lastIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
||||||
|
|
||||||
|
if (pMsg->prevLogIndex > lastIndex) {
|
||||||
|
syncLogRecvAppendEntries(ths, pMsg, "reject, index not match");
|
||||||
|
goto _SEND_RESPONSE;
|
||||||
}
|
}
|
||||||
ASSERT(pMsg->dataLen >= 0);
|
|
||||||
|
|
||||||
// candidate to follower
|
if (pMsg->prevLogIndex >= startIndex) {
|
||||||
//
|
SyncTerm myPreLogTerm = syncNodeGetPreTerm(ths, pMsg->prevLogIndex + 1);
|
||||||
// operation:
|
ASSERT(myPreLogTerm != SYNC_TERM_INVALID);
|
||||||
// to follower
|
|
||||||
do {
|
if (myPreLogTerm != pMsg->prevLogTerm) {
|
||||||
bool condition = pMsg->term == ths->pRaftStore->currentTerm && ths->state == TAOS_SYNC_STATE_CANDIDATE;
|
syncLogRecvAppendEntries(ths, pMsg, "reject, pre-term not match");
|
||||||
if (condition) {
|
goto _SEND_RESPONSE;
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "candidate to follower");
|
|
||||||
syncNodeBecomeFollower(ths, "from candidate by append entries");
|
|
||||||
return 0; // do not reply?
|
|
||||||
}
|
}
|
||||||
} while (0);
|
}
|
||||||
|
|
||||||
// fake match
|
// accept
|
||||||
//
|
pReply->success = true;
|
||||||
// condition1:
|
bool hasAppendEntries = pMsg->dataLen > 0;
|
||||||
// preIndex <= my commit index
|
if (hasAppendEntries) {
|
||||||
//
|
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
||||||
// operation:
|
ASSERT(pAppendEntry != NULL);
|
||||||
// if hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex, append entry
|
|
||||||
// match my-commit-index or my-commit-index + 1
|
|
||||||
// no operation on log
|
|
||||||
do {
|
|
||||||
bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) &&
|
|
||||||
(pMsg->prevLogIndex <= ths->commitIndex);
|
|
||||||
if (condition) {
|
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "fake match");
|
|
||||||
|
|
||||||
SyncIndex matchIndex = ths->commitIndex;
|
SyncIndex appendIndex = pMsg->prevLogIndex + 1;
|
||||||
bool hasAppendEntries = pMsg->dataLen > 0;
|
SSyncRaftEntry* pLocalEntry = NULL;
|
||||||
if (hasAppendEntries && pMsg->prevLogIndex == ths->commitIndex) {
|
int32_t code = ths->pLogStore->syncLogGetEntry(ths->pLogStore, appendIndex, &pLocalEntry);
|
||||||
// append entry
|
if (code == 0) {
|
||||||
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
if (pLocalEntry->term == pAppendEntry->term) {
|
||||||
ASSERT(pAppendEntry != NULL);
|
// do nothing
|
||||||
|
|
||||||
{
|
char logBuf[128];
|
||||||
// has extra entries (> preIndex) in local log
|
snprintf(logBuf, sizeof(logBuf), "log match, do nothing, index:%" PRId64, appendIndex);
|
||||||
SyncIndex logLastIndex = ths->pLogStore->syncLogLastIndex(ths->pLogStore);
|
syncNodeEventLog(ths, logBuf);
|
||||||
bool hasExtraEntries = logLastIndex > pMsg->prevLogIndex;
|
|
||||||
|
|
||||||
if (hasExtraEntries) {
|
} else {
|
||||||
// make log same, rollback deleted entries
|
// truncate
|
||||||
code = syncNodeMakeLogSame(ths, pMsg);
|
code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex);
|
||||||
ASSERT(code == 0);
|
if (code != 0) {
|
||||||
}
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "ignore, truncate error, append-index:%" PRId64, appendIndex);
|
||||||
|
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||||
|
|
||||||
|
goto _IGNORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// append
|
||||||
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno));
|
char logBuf[128];
|
||||||
return -1;
|
snprintf(logBuf, sizeof(logBuf), "ignore, append error, append-index:%" PRId64, appendIndex);
|
||||||
|
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||||
|
|
||||||
|
goto _IGNORE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||||
|
// log not exist
|
||||||
|
|
||||||
|
// truncate
|
||||||
|
code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex);
|
||||||
|
if (code != 0) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, truncate error, append-index:%" PRId64, appendIndex);
|
||||||
|
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||||
|
|
||||||
|
goto _IGNORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pre commit
|
// append
|
||||||
code = syncNodePreCommit(ths, pAppendEntry, 0);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
|
|
||||||
// update match index
|
|
||||||
matchIndex = pMsg->prevLogIndex + 1;
|
|
||||||
|
|
||||||
syncEntryDestory(pAppendEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepare response msg
|
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
|
||||||
pReply->srcId = ths->myRaftId;
|
|
||||||
pReply->destId = pMsg->srcId;
|
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
|
||||||
pReply->privateTerm = ths->pNewNodeReceiver->privateTerm;
|
|
||||||
pReply->success = true;
|
|
||||||
pReply->matchIndex = matchIndex;
|
|
||||||
pReply->startTime = ths->startTime;
|
|
||||||
|
|
||||||
// msg event log
|
|
||||||
syncLogSendAppendEntriesReply(ths, pReply, "");
|
|
||||||
|
|
||||||
// send response
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pReply);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
// calculate logOK here, before will coredump, due to fake match
|
|
||||||
bool logOK = syncNodeOnAppendEntriesLogOK(ths, pMsg);
|
|
||||||
|
|
||||||
// not match
|
|
||||||
//
|
|
||||||
// condition1:
|
|
||||||
// term < myTerm
|
|
||||||
//
|
|
||||||
// condition2:
|
|
||||||
// !logOK
|
|
||||||
//
|
|
||||||
// operation:
|
|
||||||
// not match
|
|
||||||
// no operation on log
|
|
||||||
do {
|
|
||||||
bool condition1 = pMsg->term < ths->pRaftStore->currentTerm;
|
|
||||||
bool condition2 =
|
|
||||||
(pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && !logOK;
|
|
||||||
bool condition = condition1 || condition2;
|
|
||||||
|
|
||||||
if (condition) {
|
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "not match");
|
|
||||||
|
|
||||||
// prepare response msg
|
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
|
||||||
pReply->srcId = ths->myRaftId;
|
|
||||||
pReply->destId = pMsg->srcId;
|
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
|
||||||
pReply->privateTerm = ths->pNewNodeReceiver->privateTerm;
|
|
||||||
pReply->success = false;
|
|
||||||
pReply->matchIndex = SYNC_INDEX_INVALID;
|
|
||||||
pReply->startTime = ths->startTime;
|
|
||||||
|
|
||||||
// msg event log
|
|
||||||
syncLogSendAppendEntriesReply(ths, pReply, "");
|
|
||||||
|
|
||||||
// send response
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pReply);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
// really match
|
|
||||||
//
|
|
||||||
// condition:
|
|
||||||
// logOK
|
|
||||||
//
|
|
||||||
// operation:
|
|
||||||
// match
|
|
||||||
// make log same
|
|
||||||
do {
|
|
||||||
bool condition = (pMsg->term == ths->pRaftStore->currentTerm) && (ths->state == TAOS_SYNC_STATE_FOLLOWER) && logOK;
|
|
||||||
if (condition) {
|
|
||||||
// has extra entries (> preIndex) in local log
|
|
||||||
SyncIndex myLastIndex = syncNodeGetLastIndex(ths);
|
|
||||||
bool hasExtraEntries = myLastIndex > pMsg->prevLogIndex;
|
|
||||||
|
|
||||||
// has entries in SyncAppendEntries msg
|
|
||||||
bool hasAppendEntries = pMsg->dataLen > 0;
|
|
||||||
|
|
||||||
syncLogRecvAppendEntries(ths, pMsg, "really match");
|
|
||||||
|
|
||||||
if (hasExtraEntries) {
|
|
||||||
// make log same, rollback deleted entries
|
|
||||||
code = syncNodeMakeLogSame(ths, pMsg);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hasAppendEntries) {
|
|
||||||
// append entry
|
|
||||||
SSyncRaftEntry* pAppendEntry = syncEntryDeserialize(pMsg->data, pMsg->dataLen);
|
|
||||||
ASSERT(pAppendEntry != NULL);
|
|
||||||
|
|
||||||
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
sError("vgId:%d, failed to append log entry since %s", ths->vgId, tstrerror(terrno));
|
char logBuf[128];
|
||||||
return -1;
|
snprintf(logBuf, sizeof(logBuf), "ignore, log not exist, append error, append-index:%" PRId64, appendIndex);
|
||||||
|
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||||
|
|
||||||
|
goto _IGNORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pre commit
|
} else {
|
||||||
code = syncNodePreCommit(ths, pAppendEntry, 0);
|
// error
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "ignore, get local entry error, append-index:%" PRId64, appendIndex);
|
||||||
|
syncLogRecvAppendEntries(ths, pMsg, logBuf);
|
||||||
|
|
||||||
|
goto _IGNORE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
if (code != 0 && terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||||
|
code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex);
|
||||||
|
ASSERT(code == 0);
|
||||||
|
|
||||||
|
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
||||||
|
ASSERT(code == 0);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ASSERT(code == 0);
|
||||||
|
|
||||||
|
if (pLocalEntry->term == pAppendEntry->term) {
|
||||||
|
// do nothing
|
||||||
|
} else {
|
||||||
|
code = ths->pLogStore->syncLogTruncate(ths->pLogStore, appendIndex);
|
||||||
ASSERT(code == 0);
|
ASSERT(code == 0);
|
||||||
|
|
||||||
syncEntryDestory(pAppendEntry);
|
code = ths->pLogStore->syncLogAppendEntry(ths->pLogStore, pAppendEntry);
|
||||||
|
ASSERT(code == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare response msg
|
|
||||||
SyncAppendEntriesReply* pReply = syncAppendEntriesReplyBuild(ths->vgId);
|
|
||||||
pReply->srcId = ths->myRaftId;
|
|
||||||
pReply->destId = pMsg->srcId;
|
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
|
||||||
pReply->privateTerm = ths->pNewNodeReceiver->privateTerm;
|
|
||||||
pReply->success = true;
|
|
||||||
pReply->matchIndex = hasAppendEntries ? pMsg->prevLogIndex + 1 : pMsg->prevLogIndex;
|
|
||||||
pReply->startTime = ths->startTime;
|
|
||||||
|
|
||||||
// msg event log
|
|
||||||
syncLogSendAppendEntriesReply(ths, pReply, "");
|
|
||||||
|
|
||||||
// send response
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
|
||||||
syncAppendEntriesReplyDestroy(pReply);
|
|
||||||
|
|
||||||
// maybe update commit index, leader notice me
|
|
||||||
if (pMsg->commitIndex > ths->commitIndex) {
|
|
||||||
// has commit entry in local
|
|
||||||
if (pMsg->commitIndex <= ths->pLogStore->syncLogLastIndex(ths->pLogStore)) {
|
|
||||||
// advance commit index to sanpshot first
|
|
||||||
SSnapshot snapshot;
|
|
||||||
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &snapshot);
|
|
||||||
if (snapshot.lastApplyIndex >= 0 && snapshot.lastApplyIndex > ths->commitIndex) {
|
|
||||||
SyncIndex commitBegin = ths->commitIndex;
|
|
||||||
SyncIndex commitEnd = snapshot.lastApplyIndex;
|
|
||||||
ths->commitIndex = snapshot.lastApplyIndex;
|
|
||||||
|
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "commit by snapshot from index:%" PRId64 " to index:%" PRId64,
|
|
||||||
commitBegin, commitEnd);
|
|
||||||
syncNodeEventLog(ths, eventLog);
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex beginIndex = ths->commitIndex + 1;
|
|
||||||
SyncIndex endIndex = pMsg->commitIndex;
|
|
||||||
|
|
||||||
// update commit index
|
|
||||||
ths->commitIndex = pMsg->commitIndex;
|
|
||||||
|
|
||||||
// call back Wal
|
|
||||||
code = ths->pLogStore->updateCommitIndex(ths->pLogStore, ths->commitIndex);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
|
|
||||||
code = syncNodeCommit(ths, beginIndex, endIndex, ths->state);
|
|
||||||
ASSERT(code == 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
} while (0);
|
#endif
|
||||||
|
|
||||||
return ret;
|
// update match index
|
||||||
|
pReply->matchIndex = pAppendEntry->index;
|
||||||
|
|
||||||
|
syncEntryDestory(pLocalEntry);
|
||||||
|
syncEntryDestory(pAppendEntry);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// no append entries, do nothing
|
||||||
|
// maybe has extra entries, no harm
|
||||||
|
|
||||||
|
// update match index
|
||||||
|
pReply->matchIndex = pMsg->prevLogIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
// maybe update commit index, leader notice me
|
||||||
|
syncNodeFollowerCommit(ths, pMsg->commitIndex);
|
||||||
|
|
||||||
|
syncLogRecvAppendEntries(ths, pMsg, "accept");
|
||||||
|
goto _SEND_RESPONSE;
|
||||||
|
|
||||||
|
_IGNORE:
|
||||||
|
syncAppendEntriesReplyDestroy(pReply);
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
_SEND_RESPONSE:
|
||||||
|
// msg event log
|
||||||
|
syncLogSendAppendEntriesReply(ths, pReply, "");
|
||||||
|
|
||||||
|
// send response
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncAppendEntriesReply2RpcMsg(pReply, &rpcMsg);
|
||||||
|
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
||||||
|
syncAppendEntriesReplyDestroy(pReply);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
|
@ -20,6 +20,7 @@
|
||||||
#include "syncRaftCfg.h"
|
#include "syncRaftCfg.h"
|
||||||
#include "syncRaftLog.h"
|
#include "syncRaftLog.h"
|
||||||
#include "syncRaftStore.h"
|
#include "syncRaftStore.h"
|
||||||
|
#include "syncReplication.h"
|
||||||
#include "syncSnapshot.h"
|
#include "syncSnapshot.h"
|
||||||
#include "syncUtil.h"
|
#include "syncUtil.h"
|
||||||
#include "syncVoteMgr.h"
|
#include "syncVoteMgr.h"
|
||||||
|
@ -37,74 +38,6 @@
|
||||||
// /\ Discard(m)
|
// /\ Discard(m)
|
||||||
// /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
|
// /\ UNCHANGED <<serverVars, candidateVars, logVars, elections>>
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnAppendEntriesReplyCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
|
||||||
int32_t ret = 0;
|
|
||||||
|
|
||||||
// if already drop replica, do not process
|
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "maybe replica already dropped");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// drop stale response
|
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no need this code, because if I receive reply.term, then I must have sent for that term.
|
|
||||||
// if (pMsg->term > ths->pRaftStore->currentTerm) {
|
|
||||||
// syncNodeUpdateTerm(ths, pMsg->term);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
|
||||||
|
|
||||||
// update time
|
|
||||||
syncIndexMgrSetStartTime(ths->pNextIndex, &(pMsg->srcId), pMsg->startTime);
|
|
||||||
syncIndexMgrSetRecvTime(ths->pNextIndex, &(pMsg->srcId), taosGetTimestampMs());
|
|
||||||
|
|
||||||
SyncIndex beforeNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
|
||||||
SyncIndex beforeMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
|
||||||
|
|
||||||
if (pMsg->success) {
|
|
||||||
// nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
|
|
||||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1);
|
|
||||||
|
|
||||||
// matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
|
|
||||||
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
|
|
||||||
|
|
||||||
// maybe commit
|
|
||||||
syncMaybeAdvanceCommitIndex(ths);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
|
||||||
|
|
||||||
// notice! int64, uint64
|
|
||||||
if (nextIndex > SYNC_INDEX_BEGIN) {
|
|
||||||
--nextIndex;
|
|
||||||
} else {
|
|
||||||
nextIndex = SYNC_INDEX_BEGIN;
|
|
||||||
}
|
|
||||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex afterNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
|
||||||
SyncIndex afterMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
|
||||||
do {
|
|
||||||
char logBuf[256];
|
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
|
||||||
"before next:%" PRId64 ", match:%" PRId64 ", after next:%" PRId64 ", match:%" PRId64, beforeNextIndex,
|
|
||||||
beforeMatchIndex, afterNextIndex, afterMatchIndex);
|
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// only start once
|
// only start once
|
||||||
static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, SyncTerm lastApplyTerm,
|
static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, SyncIndex endIndex, SyncTerm lastApplyTerm,
|
||||||
|
@ -151,13 +84,13 @@ static void syncNodeStartSnapshotOnce(SSyncNode* ths, SyncIndex beginIndex, Sync
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
int32_t syncNodeOnAppendEntriesReply(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
// if already drop replica, do not process
|
// if already drop replica, do not process
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "maybe replica already dropped");
|
syncLogRecvAppendEntriesReply(ths, pMsg, "not in my config");
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// drop stale response
|
// drop stale response
|
||||||
|
@ -166,251 +99,40 @@ int32_t syncNodeOnAppendEntriesReplySnapshot2Cb(SSyncNode* ths, SyncAppendEntrie
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// error term
|
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
|
syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
|
||||||
return -1;
|
syncNodeStepDown(ths, pMsg->term);
|
||||||
}
|
return -1;
|
||||||
|
|
||||||
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
|
||||||
|
|
||||||
// update time
|
|
||||||
syncIndexMgrSetStartTime(ths->pNextIndex, &(pMsg->srcId), pMsg->startTime);
|
|
||||||
syncIndexMgrSetRecvTime(ths->pNextIndex, &(pMsg->srcId), taosGetTimestampMs());
|
|
||||||
|
|
||||||
SyncIndex beforeNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
|
||||||
SyncIndex beforeMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
|
||||||
|
|
||||||
if (pMsg->success) {
|
|
||||||
SyncIndex newNextIndex = pMsg->matchIndex + 1;
|
|
||||||
SyncIndex newMatchIndex = pMsg->matchIndex;
|
|
||||||
|
|
||||||
bool needStartSnapshot = false;
|
|
||||||
if (newMatchIndex >= SYNC_INDEX_BEGIN && !ths->pLogStore->syncLogExist(ths->pLogStore, newMatchIndex)) {
|
|
||||||
needStartSnapshot = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!needStartSnapshot) {
|
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
||||||
// update next-index, match-index
|
|
||||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), newNextIndex);
|
|
||||||
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), newMatchIndex);
|
|
||||||
|
|
||||||
// maybe commit
|
if (pMsg->success) {
|
||||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
SyncIndex oldMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
||||||
|
if (pMsg->matchIndex > oldMatchIndex) {
|
||||||
|
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
|
||||||
syncMaybeAdvanceCommitIndex(ths);
|
syncMaybeAdvanceCommitIndex(ths);
|
||||||
}
|
}
|
||||||
|
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// start snapshot <match+1, old snapshot.end>
|
SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
||||||
SSnapshot oldSnapshot;
|
if (nextIndex > SYNC_INDEX_BEGIN) {
|
||||||
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &oldSnapshot);
|
--nextIndex;
|
||||||
if (oldSnapshot.lastApplyIndex > newMatchIndex) {
|
|
||||||
syncNodeStartSnapshotOnce(ths, newMatchIndex + 1, oldSnapshot.lastApplyIndex, oldSnapshot.lastApplyTerm,
|
|
||||||
pMsg); // term maybe not ok?
|
|
||||||
}
|
}
|
||||||
|
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex);
|
||||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), oldSnapshot.lastApplyIndex + 1);
|
|
||||||
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), newMatchIndex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// event log, update next-index
|
// send next append entries
|
||||||
do {
|
SPeerState* pState = syncNodeGetPeerState(ths, &(pMsg->srcId));
|
||||||
char host[64];
|
ASSERT(pState != NULL);
|
||||||
int16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
char logBuf[256];
|
if (pMsg->lastSendIndex == pState->lastSendIndex) {
|
||||||
snprintf(logBuf, sizeof(logBuf), "reset next-index:%" PRId64 ", match-index:%" PRId64 " for %s:%d", newNextIndex,
|
syncNodeReplicateOne(ths, &(pMsg->srcId));
|
||||||
newMatchIndex, host, port);
|
|
||||||
syncNodeEventLog(ths, logBuf);
|
|
||||||
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
|
||||||
|
|
||||||
if (nextIndex > SYNC_INDEX_BEGIN) {
|
|
||||||
--nextIndex;
|
|
||||||
|
|
||||||
// speed up
|
|
||||||
if (nextIndex > pMsg->matchIndex + 1) {
|
|
||||||
nextIndex = pMsg->matchIndex + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool needStartSnapshot = false;
|
|
||||||
if (nextIndex >= SYNC_INDEX_BEGIN && !ths->pLogStore->syncLogExist(ths->pLogStore, nextIndex)) {
|
|
||||||
needStartSnapshot = true;
|
|
||||||
}
|
|
||||||
if (nextIndex - 1 >= SYNC_INDEX_BEGIN && !ths->pLogStore->syncLogExist(ths->pLogStore, nextIndex - 1)) {
|
|
||||||
needStartSnapshot = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!needStartSnapshot) {
|
|
||||||
// do nothing
|
|
||||||
|
|
||||||
} else {
|
|
||||||
SSnapshot oldSnapshot;
|
|
||||||
ths->pFsm->FpGetSnapshotInfo(ths->pFsm, &oldSnapshot);
|
|
||||||
SyncTerm newSnapshotTerm = oldSnapshot.lastApplyTerm;
|
|
||||||
|
|
||||||
SyncIndex endIndex;
|
|
||||||
if (ths->pLogStore->syncLogExist(ths->pLogStore, nextIndex + 1)) {
|
|
||||||
endIndex = nextIndex;
|
|
||||||
} else {
|
|
||||||
endIndex = oldSnapshot.lastApplyIndex;
|
|
||||||
}
|
|
||||||
syncNodeStartSnapshotOnce(ths, pMsg->matchIndex + 1, endIndex, newSnapshotTerm, pMsg);
|
|
||||||
|
|
||||||
// get sender
|
|
||||||
SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(pMsg->srcId));
|
|
||||||
ASSERT(pSender != NULL);
|
|
||||||
SyncIndex sentryIndex = pSender->snapshot.lastApplyIndex + 1;
|
|
||||||
|
|
||||||
// update nextIndex to sentryIndex
|
|
||||||
if (nextIndex <= sentryIndex) {
|
|
||||||
nextIndex = sentryIndex;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
nextIndex = SYNC_INDEX_BEGIN;
|
|
||||||
}
|
}
|
||||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex);
|
|
||||||
|
|
||||||
SyncIndex oldMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
|
||||||
if (pMsg->matchIndex > oldMatchIndex) {
|
|
||||||
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
// event log, update next-index
|
|
||||||
do {
|
|
||||||
char host[64];
|
|
||||||
int16_t port;
|
|
||||||
syncUtilU642Addr(pMsg->srcId.addr, host, sizeof(host), &port);
|
|
||||||
|
|
||||||
SyncIndex newNextIndex = nextIndex;
|
|
||||||
SyncIndex newMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
|
||||||
char logBuf[256];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "reset2 next-index:%" PRId64 ", match-index:%" PRId64 " for %s:%d", newNextIndex,
|
|
||||||
newMatchIndex, host, port);
|
|
||||||
syncNodeEventLog(ths, logBuf);
|
|
||||||
|
|
||||||
} while (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncIndex afterNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
syncLogRecvAppendEntriesReply(ths, pMsg, "process");
|
||||||
SyncIndex afterMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
|
||||||
do {
|
|
||||||
char logBuf[256];
|
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
|
||||||
"before next:%" PRId64 ", match:%" PRId64 ", after next:%" PRId64 ", match:%" PRId64, beforeNextIndex,
|
|
||||||
beforeMatchIndex, afterNextIndex, afterMatchIndex);
|
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncNodeOnAppendEntriesReplySnapshotCb(SSyncNode* ths, SyncAppendEntriesReply* pMsg) {
|
|
||||||
int32_t ret = 0;
|
|
||||||
|
|
||||||
// if already drop replica, do not process
|
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "maybe replica already dropped");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// drop stale response
|
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "drop stale response");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// no need this code, because if I receive reply.term, then I must have sent for that term.
|
|
||||||
// if (pMsg->term > ths->pRaftStore->currentTerm) {
|
|
||||||
// syncNodeUpdateTerm(ths, pMsg->term);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, "error term");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
|
||||||
|
|
||||||
// update time
|
|
||||||
syncIndexMgrSetStartTime(ths->pNextIndex, &(pMsg->srcId), pMsg->startTime);
|
|
||||||
syncIndexMgrSetRecvTime(ths->pNextIndex, &(pMsg->srcId), taosGetTimestampMs());
|
|
||||||
|
|
||||||
SyncIndex beforeNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
|
||||||
SyncIndex beforeMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
|
||||||
|
|
||||||
if (pMsg->success) {
|
|
||||||
// nextIndex' = [nextIndex EXCEPT ![i][j] = m.mmatchIndex + 1]
|
|
||||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), pMsg->matchIndex + 1);
|
|
||||||
|
|
||||||
// matchIndex' = [matchIndex EXCEPT ![i][j] = m.mmatchIndex]
|
|
||||||
syncIndexMgrSetIndex(ths->pMatchIndex, &(pMsg->srcId), pMsg->matchIndex);
|
|
||||||
|
|
||||||
// maybe commit
|
|
||||||
if (ths->state == TAOS_SYNC_STATE_LEADER) {
|
|
||||||
syncMaybeAdvanceCommitIndex(ths);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
SyncIndex nextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
|
||||||
|
|
||||||
// notice! int64, uint64
|
|
||||||
if (nextIndex > SYNC_INDEX_BEGIN) {
|
|
||||||
--nextIndex;
|
|
||||||
|
|
||||||
// get sender
|
|
||||||
SSyncSnapshotSender* pSender = syncNodeGetSnapshotSender(ths, &(pMsg->srcId));
|
|
||||||
ASSERT(pSender != NULL);
|
|
||||||
|
|
||||||
SSnapshot snapshot = {.data = NULL,
|
|
||||||
.lastApplyIndex = SYNC_INDEX_INVALID,
|
|
||||||
.lastApplyTerm = 0,
|
|
||||||
.lastConfigIndex = SYNC_INDEX_INVALID};
|
|
||||||
void* pReader = NULL;
|
|
||||||
ths->pFsm->FpGetSnapshot(ths->pFsm, &snapshot, NULL, &pReader);
|
|
||||||
if (snapshot.lastApplyIndex >= SYNC_INDEX_BEGIN && nextIndex <= snapshot.lastApplyIndex + 1 &&
|
|
||||||
!snapshotSenderIsStart(pSender) && pMsg->privateTerm < pSender->privateTerm) {
|
|
||||||
// has snapshot
|
|
||||||
ASSERT(pReader != NULL);
|
|
||||||
SSnapshotParam readerParam = {.start = 0, .end = snapshot.lastApplyIndex};
|
|
||||||
snapshotSenderStart(pSender, readerParam, snapshot, pReader);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// no snapshot
|
|
||||||
if (pReader != NULL) {
|
|
||||||
ths->pFsm->FpSnapshotStopRead(ths->pFsm, pReader);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex sentryIndex = pSender->snapshot.lastApplyIndex + 1;
|
|
||||||
|
|
||||||
// update nextIndex to sentryIndex
|
|
||||||
if (nextIndex <= sentryIndex) {
|
|
||||||
nextIndex = sentryIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
nextIndex = SYNC_INDEX_BEGIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
syncIndexMgrSetIndex(ths->pNextIndex, &(pMsg->srcId), nextIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex afterNextIndex = syncIndexMgrGetIndex(ths->pNextIndex, &(pMsg->srcId));
|
|
||||||
SyncIndex afterMatchIndex = syncIndexMgrGetIndex(ths->pMatchIndex, &(pMsg->srcId));
|
|
||||||
do {
|
|
||||||
char logBuf[256];
|
|
||||||
snprintf(logBuf, sizeof(logBuf),
|
|
||||||
"before next:%" PRId64 ", match:%" PRId64 ", after next:%" PRId64 ", match:%" PRId64, beforeNextIndex,
|
|
||||||
beforeMatchIndex, afterNextIndex, afterMatchIndex);
|
|
||||||
syncLogRecvAppendEntriesReply(ths, pMsg, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -45,8 +45,10 @@
|
||||||
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
// /\ UNCHANGED <<messages, serverVars, candidateVars, leaderVars, log>>
|
||||||
//
|
//
|
||||||
void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pNextIndex", pSyncNode->pNextIndex);
|
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||||
syncIndexMgrLog2("==syncNodeMaybeAdvanceCommitIndex== pMatchIndex", pSyncNode->pMatchIndex);
|
syncNodeErrorLog(pSyncNode, "not leader, can not advance commit index");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// advance commit index to sanpshot first
|
// advance commit index to sanpshot first
|
||||||
SSnapshot snapshot;
|
SSnapshot snapshot;
|
||||||
|
@ -75,9 +77,11 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
if (h) {
|
if (h) {
|
||||||
pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h);
|
pEntry = (SSyncRaftEntry*)taosLRUCacheValue(pCache, h);
|
||||||
} else {
|
} else {
|
||||||
pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, index);
|
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, index, &pEntry);
|
||||||
if (pEntry == NULL) {
|
if (code != 0) {
|
||||||
sError("failed to get entry since %s. index:%" PRId64, tstrerror(terrno), index);
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "advance commit index error, read wal index:%" PRId64, index);
|
||||||
|
syncNodeErrorLog(pSyncNode, logBuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,13 +129,17 @@ void syncMaybeAdvanceCommitIndex(SSyncNode* pSyncNode) {
|
||||||
pSyncNode->commitIndex = newCommitIndex;
|
pSyncNode->commitIndex = newCommitIndex;
|
||||||
|
|
||||||
// call back Wal
|
// call back Wal
|
||||||
pSyncNode->pLogStore->updateCommitIndex(pSyncNode->pLogStore, pSyncNode->commitIndex);
|
pSyncNode->pLogStore->syncLogUpdateCommitIndex(pSyncNode->pLogStore, pSyncNode->commitIndex);
|
||||||
|
|
||||||
// execute fsm
|
// execute fsm
|
||||||
if (pSyncNode->pFsm != NULL) {
|
if (pSyncNode->pFsm != NULL) {
|
||||||
int32_t code = syncNodeCommit(pSyncNode, beginIndex, endIndex, pSyncNode->state);
|
int32_t code = syncNodeDoCommit(pSyncNode, beginIndex, endIndex, pSyncNode->state);
|
||||||
if (code != 0) {
|
if (code != 0) {
|
||||||
wError("failed to commit sync node since %s", tstrerror(terrno));
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "advance commit index error, do commit begin:%" PRId64 ", end:%" PRId64,
|
||||||
|
beginIndex, endIndex);
|
||||||
|
syncNodeErrorLog(pSyncNode, logBuf);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,6 +170,8 @@ static inline int64_t syncNodeAbs64(int64_t a, int64_t b) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) {
|
int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) {
|
||||||
|
return pSyncNode->quorum;
|
||||||
|
|
||||||
int32_t quorum = 1; // self
|
int32_t quorum = 1; // self
|
||||||
|
|
||||||
int64_t timeNow = taosGetTimestampMs();
|
int64_t timeNow = taosGetTimestampMs();
|
||||||
|
@ -220,6 +230,7 @@ int32_t syncNodeDynamicQuorum(const SSyncNode* pSyncNode) {
|
||||||
return quorum;
|
return quorum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) {
|
bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) {
|
||||||
int agreeCount = 0;
|
int agreeCount = 0;
|
||||||
for (int i = 0; i < pSyncNode->replicaNum; ++i) {
|
for (int i = 0; i < pSyncNode->replicaNum; ++i) {
|
||||||
|
@ -232,8 +243,8 @@ bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) {
|
bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) {
|
||||||
int agreeCount = 0;
|
int agreeCount = 0;
|
||||||
for (int i = 0; i < pSyncNode->replicaNum; ++i) {
|
for (int i = 0; i < pSyncNode->replicaNum; ++i) {
|
||||||
|
@ -246,4 +257,3 @@ bool syncAgree(SSyncNode* pSyncNode, SyncIndex index) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -30,45 +30,6 @@
|
||||||
// msource |-> i,
|
// msource |-> i,
|
||||||
// mdest |-> j])
|
// mdest |-> j])
|
||||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||||
//
|
|
||||||
int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) {
|
|
||||||
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
|
|
||||||
|
|
||||||
int32_t ret = 0;
|
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
|
||||||
SyncRequestVote* pMsg = syncRequestVoteBuild(pSyncNode->vgId);
|
|
||||||
pMsg->srcId = pSyncNode->myRaftId;
|
|
||||||
pMsg->destId = pSyncNode->peersId[i];
|
|
||||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
|
||||||
pMsg->lastLogIndex = pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore);
|
|
||||||
pMsg->lastLogTerm = pSyncNode->pLogStore->getLastTerm(pSyncNode->pLogStore);
|
|
||||||
|
|
||||||
ret = syncNodeRequestVote(pSyncNode, &pSyncNode->peersId[i], pMsg);
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
syncRequestVoteDestroy(pMsg);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncNodeRequestVotePeersSnapshot(SSyncNode* pSyncNode) {
|
|
||||||
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_CANDIDATE);
|
|
||||||
|
|
||||||
int32_t ret = 0;
|
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
|
||||||
SyncRequestVote* pMsg = syncRequestVoteBuild(pSyncNode->vgId);
|
|
||||||
pMsg->srcId = pSyncNode->myRaftId;
|
|
||||||
pMsg->destId = pSyncNode->peersId[i];
|
|
||||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
|
||||||
|
|
||||||
ret = syncNodeGetLastIndexTerm(pSyncNode, &(pMsg->lastLogIndex), &(pMsg->lastLogTerm));
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
|
|
||||||
ret = syncNodeRequestVote(pSyncNode, &pSyncNode->peersId[i], pMsg);
|
|
||||||
ASSERT(ret == 0);
|
|
||||||
syncRequestVoteDestroy(pMsg);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
syncNodeEventLog(pSyncNode, "begin election");
|
syncNodeEventLog(pSyncNode, "begin election");
|
||||||
|
@ -111,27 +72,38 @@ int32_t syncNodeElect(SSyncNode* pSyncNode) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (pSyncNode->pRaftCfg->snapshotStrategy) {
|
ret = syncNodeRequestVotePeers(pSyncNode);
|
||||||
case SYNC_STRATEGY_NO_SNAPSHOT:
|
|
||||||
ret = syncNodeRequestVotePeers(pSyncNode);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SYNC_STRATEGY_STANDARD_SNAPSHOT:
|
|
||||||
case SYNC_STRATEGY_WAL_FIRST:
|
|
||||||
ret = syncNodeRequestVotePeersSnapshot(pSyncNode);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ret = syncNodeRequestVotePeers(pSyncNode);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
ASSERT(ret == 0);
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
syncNodeResetElectTimer(pSyncNode);
|
syncNodeResetElectTimer(pSyncNode);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg) {
|
int32_t syncNodeRequestVotePeers(SSyncNode* pSyncNode) {
|
||||||
|
if (pSyncNode->state != TAOS_SYNC_STATE_CANDIDATE) {
|
||||||
|
syncNodeEventLog(pSyncNode, "not candidate, stop elect");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t ret = 0;
|
||||||
|
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
|
SyncRequestVote* pMsg = syncRequestVoteBuild(pSyncNode->vgId);
|
||||||
|
pMsg->srcId = pSyncNode->myRaftId;
|
||||||
|
pMsg->destId = pSyncNode->peersId[i];
|
||||||
|
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||||
|
|
||||||
|
ret = syncNodeGetLastIndexTerm(pSyncNode, &(pMsg->lastLogIndex), &(pMsg->lastLogTerm));
|
||||||
|
ASSERT(ret == 0);
|
||||||
|
|
||||||
|
ret = syncNodeSendRequestVote(pSyncNode, &pSyncNode->peersId[i], pMsg);
|
||||||
|
ASSERT(ret == 0);
|
||||||
|
syncRequestVoteDestroy(pMsg);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syncNodeSendRequestVote(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncRequestVote* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
syncLogSendRequestVote(pSyncNode, pMsg, "");
|
syncLogSendRequestVote(pSyncNode, pMsg, "");
|
||||||
|
|
||||||
|
|
|
@ -326,18 +326,18 @@ static void *syncIOConsumerFunc(void *param) {
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
} else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_SEND) {
|
||||||
if (io->FpOnSyncSnapshotSend != NULL) {
|
if (io->FpOnSyncSnapshot != NULL) {
|
||||||
SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pRpcMsg);
|
SyncSnapshotSend *pSyncMsg = syncSnapshotSendFromRpcMsg2(pRpcMsg);
|
||||||
ASSERT(pSyncMsg != NULL);
|
ASSERT(pSyncMsg != NULL);
|
||||||
io->FpOnSyncSnapshotSend(io->pSyncNode, pSyncMsg);
|
io->FpOnSyncSnapshot(io->pSyncNode, pSyncMsg);
|
||||||
syncSnapshotSendDestroy(pSyncMsg);
|
syncSnapshotSendDestroy(pSyncMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
} else if (pRpcMsg->msgType == TDMT_SYNC_SNAPSHOT_RSP) {
|
||||||
if (io->FpOnSyncSnapshotRsp != NULL) {
|
if (io->FpOnSyncSnapshotReply != NULL) {
|
||||||
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pRpcMsg);
|
SyncSnapshotRsp *pSyncMsg = syncSnapshotRspFromRpcMsg2(pRpcMsg);
|
||||||
ASSERT(pSyncMsg != NULL);
|
ASSERT(pSyncMsg != NULL);
|
||||||
io->FpOnSyncSnapshotRsp(io->pSyncNode, pSyncMsg);
|
io->FpOnSyncSnapshotReply(io->pSyncNode, pSyncMsg);
|
||||||
syncSnapshotRspDestroy(pSyncMsg);
|
syncSnapshotRspDestroy(pSyncMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,6 +83,10 @@ void syncIndexMgrSetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId,
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId) {
|
SyncIndex syncIndexMgrGetIndex(SSyncIndexMgr *pSyncIndexMgr, const SRaftId *pRaftId) {
|
||||||
|
if (pSyncIndexMgr == NULL) {
|
||||||
|
return SYNC_INDEX_INVALID;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
for (int i = 0; i < pSyncIndexMgr->replicaNum; ++i) {
|
||||||
if (syncUtilSameId(&((*(pSyncIndexMgr->replicas))[i]), pRaftId)) {
|
if (syncUtilSameId(&((*(pSyncIndexMgr->replicas))[i]), pRaftId)) {
|
||||||
SyncIndex idx = (pSyncIndexMgr->index)[i];
|
SyncIndex idx = (pSyncIndexMgr->index)[i];
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -133,28 +133,28 @@ char* syncRpcMsg2Str(SRpcMsg* pRpcMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncRpcMsgPrint(SRpcMsg* pMsg) {
|
void syncRpcMsgPrint(SRpcMsg* pMsg) {
|
||||||
char* serialized = syncRpcMsg2Str(pMsg);
|
char* serialized = syncRpcMsg2Str(pMsg);
|
||||||
printf("syncRpcMsgPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncRpcMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) {
|
void syncRpcMsgPrint2(char* s, SRpcMsg* pMsg) {
|
||||||
char* serialized = syncRpcMsg2Str(pMsg);
|
char* serialized = syncRpcMsg2Str(pMsg);
|
||||||
printf("syncRpcMsgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncRpcMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRpcMsgLog(SRpcMsg* pMsg) {
|
void syncRpcMsgLog(SRpcMsg* pMsg) {
|
||||||
char* serialized = syncRpcMsg2Str(pMsg);
|
char* serialized = syncRpcMsg2Str(pMsg);
|
||||||
sTrace("syncRpcMsgLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncRpcMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) {
|
void syncRpcMsgLog2(char* s, SRpcMsg* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncRpcMsg2Str(pMsg);
|
char* serialized = syncRpcMsg2Str(pMsg);
|
||||||
sTrace("syncRpcMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncRpcMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -271,21 +271,21 @@ void syncTimeoutPrint(const SyncTimeout* pMsg) {
|
||||||
|
|
||||||
void syncTimeoutPrint2(char* s, const SyncTimeout* pMsg) {
|
void syncTimeoutPrint2(char* s, const SyncTimeout* pMsg) {
|
||||||
char* serialized = syncTimeout2Str(pMsg);
|
char* serialized = syncTimeout2Str(pMsg);
|
||||||
printf("syncTimeoutPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncTimeoutPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncTimeoutLog(const SyncTimeout* pMsg) {
|
void syncTimeoutLog(const SyncTimeout* pMsg) {
|
||||||
char* serialized = syncTimeout2Str(pMsg);
|
char* serialized = syncTimeout2Str(pMsg);
|
||||||
sTrace("syncTimeoutLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncTimeoutLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncTimeoutLog2(char* s, const SyncTimeout* pMsg) {
|
void syncTimeoutLog2(char* s, const SyncTimeout* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncTimeout2Str(pMsg);
|
char* serialized = syncTimeout2Str(pMsg);
|
||||||
sTrace("syncTimeoutLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncTimeoutLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -526,28 +526,28 @@ char* syncPing2Str(const SyncPing* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncPingPrint(const SyncPing* pMsg) {
|
void syncPingPrint(const SyncPing* pMsg) {
|
||||||
char* serialized = syncPing2Str(pMsg);
|
char* serialized = syncPing2Str(pMsg);
|
||||||
printf("syncPingPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncPingPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPingPrint2(char* s, const SyncPing* pMsg) {
|
void syncPingPrint2(char* s, const SyncPing* pMsg) {
|
||||||
char* serialized = syncPing2Str(pMsg);
|
char* serialized = syncPing2Str(pMsg);
|
||||||
printf("syncPingPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncPingPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPingLog(const SyncPing* pMsg) {
|
void syncPingLog(const SyncPing* pMsg) {
|
||||||
char* serialized = syncPing2Str(pMsg);
|
char* serialized = syncPing2Str(pMsg);
|
||||||
sTrace("syncPingLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncPingLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncPingLog2(char* s, const SyncPing* pMsg) {
|
void syncPingLog2(char* s, const SyncPing* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncPing2Str(pMsg);
|
char* serialized = syncPing2Str(pMsg);
|
||||||
sTrace("syncPingLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncPingLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -931,28 +931,28 @@ char* syncClientRequest2Str(const SyncClientRequest* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncClientRequestPrint(const SyncClientRequest* pMsg) {
|
void syncClientRequestPrint(const SyncClientRequest* pMsg) {
|
||||||
char* serialized = syncClientRequest2Str(pMsg);
|
char* serialized = syncClientRequest2Str(pMsg);
|
||||||
printf("syncClientRequestPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncClientRequestPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) {
|
void syncClientRequestPrint2(char* s, const SyncClientRequest* pMsg) {
|
||||||
char* serialized = syncClientRequest2Str(pMsg);
|
char* serialized = syncClientRequest2Str(pMsg);
|
||||||
printf("syncClientRequestPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncClientRequestPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncClientRequestLog(const SyncClientRequest* pMsg) {
|
void syncClientRequestLog(const SyncClientRequest* pMsg) {
|
||||||
char* serialized = syncClientRequest2Str(pMsg);
|
char* serialized = syncClientRequest2Str(pMsg);
|
||||||
sTrace("syncClientRequestLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncClientRequestLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) {
|
void syncClientRequestLog2(char* s, const SyncClientRequest* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncClientRequest2Str(pMsg);
|
char* serialized = syncClientRequest2Str(pMsg);
|
||||||
sTrace("syncClientRequestLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncClientRequestLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1101,28 +1101,28 @@ char* syncClientRequestBatch2Str(const SyncClientRequestBatch* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncClientRequestBatchPrint(const SyncClientRequestBatch* pMsg) {
|
void syncClientRequestBatchPrint(const SyncClientRequestBatch* pMsg) {
|
||||||
char* serialized = syncClientRequestBatch2Str(pMsg);
|
char* serialized = syncClientRequestBatch2Str(pMsg);
|
||||||
printf("syncClientRequestBatchPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncClientRequestBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncClientRequestBatchPrint2(char* s, const SyncClientRequestBatch* pMsg) {
|
void syncClientRequestBatchPrint2(char* s, const SyncClientRequestBatch* pMsg) {
|
||||||
char* serialized = syncClientRequestBatch2Str(pMsg);
|
char* serialized = syncClientRequestBatch2Str(pMsg);
|
||||||
printf("syncClientRequestBatchPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncClientRequestBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) {
|
void syncClientRequestBatchLog(const SyncClientRequestBatch* pMsg) {
|
||||||
char* serialized = syncClientRequestBatch2Str(pMsg);
|
char* serialized = syncClientRequestBatch2Str(pMsg);
|
||||||
sTrace("syncClientRequestBatchLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncClientRequestBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) {
|
void syncClientRequestBatchLog2(char* s, const SyncClientRequestBatch* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncClientRequestBatch2Str(pMsg);
|
char* serialized = syncClientRequestBatch2Str(pMsg);
|
||||||
sTraceLong("syncClientRequestBatchLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTraceLong("syncClientRequestBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1252,28 +1252,28 @@ char* syncRequestVote2Str(const SyncRequestVote* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncRequestVotePrint(const SyncRequestVote* pMsg) {
|
void syncRequestVotePrint(const SyncRequestVote* pMsg) {
|
||||||
char* serialized = syncRequestVote2Str(pMsg);
|
char* serialized = syncRequestVote2Str(pMsg);
|
||||||
printf("syncRequestVotePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncRequestVotePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRequestVotePrint2(char* s, const SyncRequestVote* pMsg) {
|
void syncRequestVotePrint2(char* s, const SyncRequestVote* pMsg) {
|
||||||
char* serialized = syncRequestVote2Str(pMsg);
|
char* serialized = syncRequestVote2Str(pMsg);
|
||||||
printf("syncRequestVotePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncRequestVotePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRequestVoteLog(const SyncRequestVote* pMsg) {
|
void syncRequestVoteLog(const SyncRequestVote* pMsg) {
|
||||||
char* serialized = syncRequestVote2Str(pMsg);
|
char* serialized = syncRequestVote2Str(pMsg);
|
||||||
sTrace("syncRequestVoteLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncRequestVoteLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg) {
|
void syncRequestVoteLog2(char* s, const SyncRequestVote* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncRequestVote2Str(pMsg);
|
char* serialized = syncRequestVote2Str(pMsg);
|
||||||
sTrace("syncRequestVoteLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncRequestVoteLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1400,28 +1400,28 @@ char* syncRequestVoteReply2Str(const SyncRequestVoteReply* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncRequestVoteReplyPrint(const SyncRequestVoteReply* pMsg) {
|
void syncRequestVoteReplyPrint(const SyncRequestVoteReply* pMsg) {
|
||||||
char* serialized = syncRequestVoteReply2Str(pMsg);
|
char* serialized = syncRequestVoteReply2Str(pMsg);
|
||||||
printf("syncRequestVoteReplyPrint | len:%ld | %s \n", strlen(serialized), serialized);
|
printf("syncRequestVoteReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg) {
|
void syncRequestVoteReplyPrint2(char* s, const SyncRequestVoteReply* pMsg) {
|
||||||
char* serialized = syncRequestVoteReply2Str(pMsg);
|
char* serialized = syncRequestVoteReply2Str(pMsg);
|
||||||
printf("syncRequestVoteReplyPrint2 | len:%ld | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncRequestVoteReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg) {
|
void syncRequestVoteReplyLog(const SyncRequestVoteReply* pMsg) {
|
||||||
char* serialized = syncRequestVoteReply2Str(pMsg);
|
char* serialized = syncRequestVoteReply2Str(pMsg);
|
||||||
sTrace("syncRequestVoteReplyLog | len:%ld | %s", strlen(serialized), serialized);
|
sTrace("syncRequestVoteReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) {
|
void syncRequestVoteReplyLog2(char* s, const SyncRequestVoteReply* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncRequestVoteReply2Str(pMsg);
|
char* serialized = syncRequestVoteReply2Str(pMsg);
|
||||||
sTrace("syncRequestVoteReplyLog2 | len:%ld | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncRequestVoteReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1571,28 +1571,28 @@ char* syncAppendEntries2Str(const SyncAppendEntries* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncAppendEntriesPrint(const SyncAppendEntries* pMsg) {
|
void syncAppendEntriesPrint(const SyncAppendEntries* pMsg) {
|
||||||
char* serialized = syncAppendEntries2Str(pMsg);
|
char* serialized = syncAppendEntries2Str(pMsg);
|
||||||
printf("syncAppendEntriesPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncAppendEntriesPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg) {
|
void syncAppendEntriesPrint2(char* s, const SyncAppendEntries* pMsg) {
|
||||||
char* serialized = syncAppendEntries2Str(pMsg);
|
char* serialized = syncAppendEntries2Str(pMsg);
|
||||||
printf("syncAppendEntriesPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncAppendEntriesPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncAppendEntriesLog(const SyncAppendEntries* pMsg) {
|
void syncAppendEntriesLog(const SyncAppendEntries* pMsg) {
|
||||||
char* serialized = syncAppendEntries2Str(pMsg);
|
char* serialized = syncAppendEntries2Str(pMsg);
|
||||||
sTrace("syncAppendEntriesLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncAppendEntriesLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) {
|
void syncAppendEntriesLog2(char* s, const SyncAppendEntries* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncAppendEntries2Str(pMsg);
|
char* serialized = syncAppendEntries2Str(pMsg);
|
||||||
sTrace("syncAppendEntriesLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncAppendEntriesLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1810,28 +1810,28 @@ char* syncAppendEntriesBatch2Str(const SyncAppendEntriesBatch* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg) {
|
void syncAppendEntriesBatchPrint(const SyncAppendEntriesBatch* pMsg) {
|
||||||
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
||||||
printf("syncAppendEntriesBatchPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncAppendEntriesBatchPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg) {
|
void syncAppendEntriesBatchPrint2(char* s, const SyncAppendEntriesBatch* pMsg) {
|
||||||
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
||||||
printf("syncAppendEntriesBatchPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncAppendEntriesBatchPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) {
|
void syncAppendEntriesBatchLog(const SyncAppendEntriesBatch* pMsg) {
|
||||||
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
||||||
sTrace("syncAppendEntriesBatchLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncAppendEntriesBatchLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) {
|
void syncAppendEntriesBatchLog2(char* s, const SyncAppendEntriesBatch* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
char* serialized = syncAppendEntriesBatch2Str(pMsg);
|
||||||
sTraceLong("syncAppendEntriesBatchLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTraceLong("syncAppendEntriesBatchLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1966,28 +1966,28 @@ char* syncAppendEntriesReply2Str(const SyncAppendEntriesReply* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg) {
|
void syncAppendEntriesReplyPrint(const SyncAppendEntriesReply* pMsg) {
|
||||||
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
||||||
printf("syncAppendEntriesReplyPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncAppendEntriesReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg) {
|
void syncAppendEntriesReplyPrint2(char* s, const SyncAppendEntriesReply* pMsg) {
|
||||||
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
||||||
printf("syncAppendEntriesReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncAppendEntriesReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg) {
|
void syncAppendEntriesReplyLog(const SyncAppendEntriesReply* pMsg) {
|
||||||
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
||||||
sTrace("syncAppendEntriesReplyLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncAppendEntriesReplyLog | len:%d| %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) {
|
void syncAppendEntriesReplyLog2(char* s, const SyncAppendEntriesReply* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
char* serialized = syncAppendEntriesReply2Str(pMsg);
|
||||||
sTrace("syncAppendEntriesReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncAppendEntriesReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2119,28 +2119,28 @@ char* syncHeartbeat2Str(const SyncHeartbeat* pMsg) {
|
||||||
|
|
||||||
void syncHeartbeatPrint(const SyncHeartbeat* pMsg) {
|
void syncHeartbeatPrint(const SyncHeartbeat* pMsg) {
|
||||||
char* serialized = syncHeartbeat2Str(pMsg);
|
char* serialized = syncHeartbeat2Str(pMsg);
|
||||||
printf("syncHeartbeatPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncHeartbeatPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncHeartbeatPrint2(char* s, const SyncHeartbeat* pMsg) {
|
void syncHeartbeatPrint2(char* s, const SyncHeartbeat* pMsg) {
|
||||||
char* serialized = syncHeartbeat2Str(pMsg);
|
char* serialized = syncHeartbeat2Str(pMsg);
|
||||||
printf("syncHeartbeatPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncHeartbeatPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncHeartbeatLog(const SyncHeartbeat* pMsg) {
|
void syncHeartbeatLog(const SyncHeartbeat* pMsg) {
|
||||||
char* serialized = syncHeartbeat2Str(pMsg);
|
char* serialized = syncHeartbeat2Str(pMsg);
|
||||||
sTrace("syncHeartbeatLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncHeartbeatLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncHeartbeatLog2(char* s, const SyncHeartbeat* pMsg) {
|
void syncHeartbeatLog2(char* s, const SyncHeartbeat* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncHeartbeat2Str(pMsg);
|
char* serialized = syncHeartbeat2Str(pMsg);
|
||||||
sTrace("syncHeartbeatLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncHeartbeatLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2273,28 +2273,28 @@ char* syncHeartbeatReply2Str(const SyncHeartbeatReply* pMsg) {
|
||||||
|
|
||||||
void syncHeartbeatReplyPrint(const SyncHeartbeatReply* pMsg) {
|
void syncHeartbeatReplyPrint(const SyncHeartbeatReply* pMsg) {
|
||||||
char* serialized = syncHeartbeatReply2Str(pMsg);
|
char* serialized = syncHeartbeatReply2Str(pMsg);
|
||||||
printf("syncHeartbeatReplyPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncHeartbeatReplyPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncHeartbeatReplyPrint2(char* s, const SyncHeartbeatReply* pMsg) {
|
void syncHeartbeatReplyPrint2(char* s, const SyncHeartbeatReply* pMsg) {
|
||||||
char* serialized = syncHeartbeatReply2Str(pMsg);
|
char* serialized = syncHeartbeatReply2Str(pMsg);
|
||||||
printf("syncHeartbeatReplyPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncHeartbeatReplyPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncHeartbeatReplyLog(const SyncHeartbeatReply* pMsg) {
|
void syncHeartbeatReplyLog(const SyncHeartbeatReply* pMsg) {
|
||||||
char* serialized = syncHeartbeatReply2Str(pMsg);
|
char* serialized = syncHeartbeatReply2Str(pMsg);
|
||||||
sTrace("syncHeartbeatReplyLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncHeartbeatReplyLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg) {
|
void syncHeartbeatReplyLog2(char* s, const SyncHeartbeatReply* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncHeartbeatReply2Str(pMsg);
|
char* serialized = syncHeartbeatReply2Str(pMsg);
|
||||||
sTrace("syncHeartbeatReplyLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncHeartbeatReplyLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2426,28 +2426,28 @@ char* syncApplyMsg2Str(const SyncApplyMsg* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncApplyMsgPrint(const SyncApplyMsg* pMsg) {
|
void syncApplyMsgPrint(const SyncApplyMsg* pMsg) {
|
||||||
char* serialized = syncApplyMsg2Str(pMsg);
|
char* serialized = syncApplyMsg2Str(pMsg);
|
||||||
printf("syncApplyMsgPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncApplyMsgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg) {
|
void syncApplyMsgPrint2(char* s, const SyncApplyMsg* pMsg) {
|
||||||
char* serialized = syncApplyMsg2Str(pMsg);
|
char* serialized = syncApplyMsg2Str(pMsg);
|
||||||
printf("syncApplyMsgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncApplyMsgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncApplyMsgLog(const SyncApplyMsg* pMsg) {
|
void syncApplyMsgLog(const SyncApplyMsg* pMsg) {
|
||||||
char* serialized = syncApplyMsg2Str(pMsg);
|
char* serialized = syncApplyMsg2Str(pMsg);
|
||||||
sTrace("ssyncApplyMsgLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("ssyncApplyMsgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) {
|
void syncApplyMsgLog2(char* s, const SyncApplyMsg* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncApplyMsg2Str(pMsg);
|
char* serialized = syncApplyMsg2Str(pMsg);
|
||||||
sTrace("syncApplyMsgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncApplyMsgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2603,28 +2603,28 @@ char* syncSnapshotSend2Str(const SyncSnapshotSend* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg) {
|
void syncSnapshotSendPrint(const SyncSnapshotSend* pMsg) {
|
||||||
char* serialized = syncSnapshotSend2Str(pMsg);
|
char* serialized = syncSnapshotSend2Str(pMsg);
|
||||||
printf("syncSnapshotSendPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncSnapshotSendPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg) {
|
void syncSnapshotSendPrint2(char* s, const SyncSnapshotSend* pMsg) {
|
||||||
char* serialized = syncSnapshotSend2Str(pMsg);
|
char* serialized = syncSnapshotSend2Str(pMsg);
|
||||||
printf("syncSnapshotSendPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncSnapshotSendPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncSnapshotSendLog(const SyncSnapshotSend* pMsg) {
|
void syncSnapshotSendLog(const SyncSnapshotSend* pMsg) {
|
||||||
char* serialized = syncSnapshotSend2Str(pMsg);
|
char* serialized = syncSnapshotSend2Str(pMsg);
|
||||||
sTrace("syncSnapshotSendLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncSnapshotSendLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) {
|
void syncSnapshotSendLog2(char* s, const SyncSnapshotSend* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncSnapshotSend2Str(pMsg);
|
char* serialized = syncSnapshotSend2Str(pMsg);
|
||||||
sTrace("syncSnapshotSendLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncSnapshotSendLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2763,28 +2763,28 @@ char* syncSnapshotRsp2Str(const SyncSnapshotRsp* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncSnapshotRspPrint(const SyncSnapshotRsp* pMsg) {
|
void syncSnapshotRspPrint(const SyncSnapshotRsp* pMsg) {
|
||||||
char* serialized = syncSnapshotRsp2Str(pMsg);
|
char* serialized = syncSnapshotRsp2Str(pMsg);
|
||||||
printf("syncSnapshotRspPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncSnapshotRspPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg) {
|
void syncSnapshotRspPrint2(char* s, const SyncSnapshotRsp* pMsg) {
|
||||||
char* serialized = syncSnapshotRsp2Str(pMsg);
|
char* serialized = syncSnapshotRsp2Str(pMsg);
|
||||||
printf("syncSnapshotRspPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncSnapshotRspPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncSnapshotRspLog(const SyncSnapshotRsp* pMsg) {
|
void syncSnapshotRspLog(const SyncSnapshotRsp* pMsg) {
|
||||||
char* serialized = syncSnapshotRsp2Str(pMsg);
|
char* serialized = syncSnapshotRsp2Str(pMsg);
|
||||||
sTrace("syncSnapshotRspLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncSnapshotRspLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) {
|
void syncSnapshotRspLog2(char* s, const SyncSnapshotRsp* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncSnapshotRsp2Str(pMsg);
|
char* serialized = syncSnapshotRsp2Str(pMsg);
|
||||||
sTrace("syncSnapshotRspLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncSnapshotRspLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2925,28 +2925,28 @@ char* syncLeaderTransfer2Str(const SyncLeaderTransfer* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg) {
|
void syncLeaderTransferPrint(const SyncLeaderTransfer* pMsg) {
|
||||||
char* serialized = syncLeaderTransfer2Str(pMsg);
|
char* serialized = syncLeaderTransfer2Str(pMsg);
|
||||||
printf("syncLeaderTransferPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncLeaderTransferPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg) {
|
void syncLeaderTransferPrint2(char* s, const SyncLeaderTransfer* pMsg) {
|
||||||
char* serialized = syncLeaderTransfer2Str(pMsg);
|
char* serialized = syncLeaderTransfer2Str(pMsg);
|
||||||
printf("syncLeaderTransferPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncLeaderTransferPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg) {
|
void syncLeaderTransferLog(const SyncLeaderTransfer* pMsg) {
|
||||||
char* serialized = syncLeaderTransfer2Str(pMsg);
|
char* serialized = syncLeaderTransfer2Str(pMsg);
|
||||||
sTrace("syncLeaderTransferLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncLeaderTransferLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg) {
|
void syncLeaderTransferLog2(char* s, const SyncLeaderTransfer* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncLeaderTransfer2Str(pMsg);
|
char* serialized = syncLeaderTransfer2Str(pMsg);
|
||||||
sTrace("syncLeaderTransferLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncLeaderTransferLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3054,28 +3054,28 @@ char* syncReconfigFinish2Str(const SyncReconfigFinish* pMsg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg) {
|
void syncReconfigFinishPrint(const SyncReconfigFinish* pMsg) {
|
||||||
char* serialized = syncReconfigFinish2Str(pMsg);
|
char* serialized = syncReconfigFinish2Str(pMsg);
|
||||||
printf("syncReconfigFinishPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncReconfigFinishPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg) {
|
void syncReconfigFinishPrint2(char* s, const SyncReconfigFinish* pMsg) {
|
||||||
char* serialized = syncReconfigFinish2Str(pMsg);
|
char* serialized = syncReconfigFinish2Str(pMsg);
|
||||||
printf("syncReconfigFinishPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncReconfigFinishPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncReconfigFinishLog(const SyncReconfigFinish* pMsg) {
|
void syncReconfigFinishLog(const SyncReconfigFinish* pMsg) {
|
||||||
char* serialized = syncReconfigFinish2Str(pMsg);
|
char* serialized = syncReconfigFinish2Str(pMsg);
|
||||||
sTrace("syncReconfigFinishLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncReconfigFinishLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) {
|
void syncReconfigFinishLog2(char* s, const SyncReconfigFinish* pMsg) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = syncReconfigFinish2Str(pMsg);
|
char* serialized = syncReconfigFinish2Str(pMsg);
|
||||||
sTrace("syncReconfigFinishLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncReconfigFinishLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -355,8 +355,6 @@ char *raftCfg2Str(SRaftCfg *pRaftCfg) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) {
|
int32_t raftCfgCreateFile(SSyncCfg *pCfg, SRaftCfgMeta meta, const char *path) {
|
||||||
ASSERT(pCfg != NULL);
|
|
||||||
|
|
||||||
TdFilePtr pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE);
|
TdFilePtr pFile = taosOpenFile(path, TD_FILE_CREATE | TD_FILE_WRITE);
|
||||||
if (pFile == NULL) {
|
if (pFile == NULL) {
|
||||||
int32_t err = terrno;
|
int32_t err = terrno;
|
||||||
|
@ -447,85 +445,85 @@ int32_t raftCfgFromStr(const char *s, SRaftCfg *pRaftCfg) {
|
||||||
// for debug ----------------------
|
// for debug ----------------------
|
||||||
void syncCfgPrint(SSyncCfg *pCfg) {
|
void syncCfgPrint(SSyncCfg *pCfg) {
|
||||||
char *serialized = syncCfg2Str(pCfg);
|
char *serialized = syncCfg2Str(pCfg);
|
||||||
printf("syncCfgPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("syncCfgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncCfgPrint2(char *s, SSyncCfg *pCfg) {
|
void syncCfgPrint2(char *s, SSyncCfg *pCfg) {
|
||||||
char *serialized = syncCfg2Str(pCfg);
|
char *serialized = syncCfg2Str(pCfg);
|
||||||
printf("syncCfgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("syncCfgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncCfgLog(SSyncCfg *pCfg) {
|
void syncCfgLog(SSyncCfg *pCfg) {
|
||||||
char *serialized = syncCfg2Str(pCfg);
|
char *serialized = syncCfg2Str(pCfg);
|
||||||
sTrace("syncCfgLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("syncCfgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncCfgLog2(char *s, SSyncCfg *pCfg) {
|
void syncCfgLog2(char *s, SSyncCfg *pCfg) {
|
||||||
char *serialized = syncCfg2Str(pCfg);
|
char *serialized = syncCfg2Str(pCfg);
|
||||||
sTrace("syncCfgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncCfgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void syncCfgLog3(char *s, SSyncCfg *pCfg) {
|
void syncCfgLog3(char *s, SSyncCfg *pCfg) {
|
||||||
char *serialized = syncCfg2SimpleStr(pCfg);
|
char *serialized = syncCfg2SimpleStr(pCfg);
|
||||||
sTrace("syncCfgLog3 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("syncCfgLog3 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCfgPrint(SRaftCfg *pCfg) {
|
void raftCfgPrint(SRaftCfg *pCfg) {
|
||||||
char *serialized = raftCfg2Str(pCfg);
|
char *serialized = raftCfg2Str(pCfg);
|
||||||
printf("raftCfgPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("raftCfgPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCfgPrint2(char *s, SRaftCfg *pCfg) {
|
void raftCfgPrint2(char *s, SRaftCfg *pCfg) {
|
||||||
char *serialized = raftCfg2Str(pCfg);
|
char *serialized = raftCfg2Str(pCfg);
|
||||||
printf("raftCfgPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("raftCfgPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCfgLog(SRaftCfg *pCfg) {
|
void raftCfgLog(SRaftCfg *pCfg) {
|
||||||
char *serialized = raftCfg2Str(pCfg);
|
char *serialized = raftCfg2Str(pCfg);
|
||||||
sTrace("raftCfgLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("raftCfgLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCfgLog2(char *s, SRaftCfg *pCfg) {
|
void raftCfgLog2(char *s, SRaftCfg *pCfg) {
|
||||||
char *serialized = raftCfg2Str(pCfg);
|
char *serialized = raftCfg2Str(pCfg);
|
||||||
sTrace("raftCfgLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("raftCfgLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------
|
// ---------
|
||||||
void raftCfgIndexPrint(SRaftCfgIndex *pCfg) {
|
void raftCfgIndexPrint(SRaftCfgIndex *pCfg) {
|
||||||
char *serialized = raftCfgIndex2Str(pCfg);
|
char *serialized = raftCfgIndex2Str(pCfg);
|
||||||
printf("raftCfgIndexPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("raftCfgIndexPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCfgIndexPrint2(char *s, SRaftCfgIndex *pCfg) {
|
void raftCfgIndexPrint2(char *s, SRaftCfgIndex *pCfg) {
|
||||||
char *serialized = raftCfgIndex2Str(pCfg);
|
char *serialized = raftCfgIndex2Str(pCfg);
|
||||||
printf("raftCfgIndexPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("raftCfgIndexPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCfgIndexLog(SRaftCfgIndex *pCfg) {
|
void raftCfgIndexLog(SRaftCfgIndex *pCfg) {
|
||||||
char *serialized = raftCfgIndex2Str(pCfg);
|
char *serialized = raftCfgIndex2Str(pCfg);
|
||||||
sTrace("raftCfgIndexLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("raftCfgIndexLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCfgIndexLog2(char *s, SRaftCfgIndex *pCfg) {
|
void raftCfgIndexLog2(char *s, SRaftCfgIndex *pCfg) {
|
||||||
char *serialized = raftCfgIndex2Str(pCfg);
|
char *serialized = raftCfgIndex2Str(pCfg);
|
||||||
sTrace("raftCfgIndexLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("raftCfgIndexLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
|
@ -418,28 +418,28 @@ char* raftCache2Str(SRaftEntryHashCache* pCache) {
|
||||||
|
|
||||||
void raftCachePrint(SRaftEntryHashCache* pCache) {
|
void raftCachePrint(SRaftEntryHashCache* pCache) {
|
||||||
char* serialized = raftCache2Str(pCache);
|
char* serialized = raftCache2Str(pCache);
|
||||||
printf("raftCachePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("raftCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCachePrint2(char* s, SRaftEntryHashCache* pCache) {
|
void raftCachePrint2(char* s, SRaftEntryHashCache* pCache) {
|
||||||
char* serialized = raftCache2Str(pCache);
|
char* serialized = raftCache2Str(pCache);
|
||||||
printf("raftCachePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("raftCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCacheLog(SRaftEntryHashCache* pCache) {
|
void raftCacheLog(SRaftEntryHashCache* pCache) {
|
||||||
char* serialized = raftCache2Str(pCache);
|
char* serialized = raftCache2Str(pCache);
|
||||||
sTrace("raftCacheLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("raftCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) {
|
void raftCacheLog2(char* s, SRaftEntryHashCache* pCache) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = raftCache2Str(pCache);
|
char* serialized = raftCache2Str(pCache);
|
||||||
sTraceLong("raftCacheLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTraceLong("raftCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -677,28 +677,28 @@ char* raftEntryCache2Str(SRaftEntryCache* pObj) {
|
||||||
|
|
||||||
void raftEntryCachePrint(SRaftEntryCache* pObj) {
|
void raftEntryCachePrint(SRaftEntryCache* pObj) {
|
||||||
char* serialized = raftEntryCache2Str(pObj);
|
char* serialized = raftEntryCache2Str(pObj);
|
||||||
printf("raftEntryCachePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("raftEntryCachePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj) {
|
void raftEntryCachePrint2(char* s, SRaftEntryCache* pObj) {
|
||||||
char* serialized = raftEntryCache2Str(pObj);
|
char* serialized = raftEntryCache2Str(pObj);
|
||||||
printf("raftEntryCachePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("raftEntryCachePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftEntryCacheLog(SRaftEntryCache* pObj) {
|
void raftEntryCacheLog(SRaftEntryCache* pObj) {
|
||||||
char* serialized = raftEntryCache2Str(pObj);
|
char* serialized = raftEntryCache2Str(pObj);
|
||||||
sTrace("raftEntryCacheLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("raftEntryCacheLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) {
|
void raftEntryCacheLog2(char* s, SRaftEntryCache* pObj) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = raftEntryCache2Str(pObj);
|
char* serialized = raftEntryCache2Str(pObj);
|
||||||
sTraceLong("raftEntryCacheLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTraceLong("raftEntryCacheLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,21 +33,11 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEn
|
||||||
static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index, SSyncRaftEntry** ppEntry);
|
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 SyncIndex raftlogCommitIndex(SSyncLogStore* pLogStore);
|
||||||
|
|
||||||
// private function
|
|
||||||
static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry);
|
static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** ppLastEntry);
|
||||||
|
|
||||||
//-------------------------------
|
|
||||||
// log[0 .. n]
|
|
||||||
static SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore);
|
|
||||||
static SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore);
|
|
||||||
static SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore);
|
|
||||||
static SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index);
|
|
||||||
static int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry);
|
|
||||||
static int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex);
|
|
||||||
static int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index);
|
|
||||||
static SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore);
|
|
||||||
|
|
||||||
//-------------------------------
|
//-------------------------------
|
||||||
SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
|
SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
|
||||||
SSyncLogStore* pLogStore = taosMemoryMalloc(sizeof(SSyncLogStore));
|
SSyncLogStore* pLogStore = taosMemoryMalloc(sizeof(SSyncLogStore));
|
||||||
|
@ -74,14 +64,8 @@ SSyncLogStore* logStoreCreate(SSyncNode* pSyncNode) {
|
||||||
pData->pWalHandle = walOpenReader(pData->pWal, NULL);
|
pData->pWalHandle = walOpenReader(pData->pWal, NULL);
|
||||||
ASSERT(pData->pWalHandle != NULL);
|
ASSERT(pData->pWalHandle != NULL);
|
||||||
|
|
||||||
pLogStore->appendEntry = logStoreAppendEntry;
|
pLogStore->syncLogUpdateCommitIndex = raftLogUpdateCommitIndex;
|
||||||
pLogStore->getEntry = logStoreGetEntry;
|
pLogStore->syncLogCommitIndex = raftlogCommitIndex;
|
||||||
pLogStore->truncate = logStoreTruncate;
|
|
||||||
pLogStore->getLastIndex = logStoreLastIndex;
|
|
||||||
pLogStore->getLastTerm = logStoreLastTerm;
|
|
||||||
pLogStore->updateCommitIndex = logStoreUpdateCommitIndex;
|
|
||||||
pLogStore->getCommitIndex = logStoreGetCommitIndex;
|
|
||||||
|
|
||||||
pLogStore->syncLogRestoreFromSnapshot = raftLogRestoreFromSnapshot;
|
pLogStore->syncLogRestoreFromSnapshot = raftLogRestoreFromSnapshot;
|
||||||
pLogStore->syncLogBeginIndex = raftLogBeginIndex;
|
pLogStore->syncLogBeginIndex = raftLogBeginIndex;
|
||||||
pLogStore->syncLogEndIndex = raftLogEndIndex;
|
pLogStore->syncLogEndIndex = raftLogEndIndex;
|
||||||
|
@ -234,6 +218,8 @@ static int32_t raftLogAppendEntry(struct SSyncLogStore* pLogStore, SSyncRaftEntr
|
||||||
snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
||||||
pEntry->index, err, err, errStr, sysErr, sysErrStr);
|
pEntry->index, err, err, errStr, sysErr, sysErrStr);
|
||||||
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
||||||
|
|
||||||
|
ASSERT(0);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
pEntry->index = index;
|
pEntry->index = index;
|
||||||
|
@ -277,11 +263,15 @@ static int32_t raftLogGetEntry(struct SSyncLogStore* pLogStore, SyncIndex index,
|
||||||
|
|
||||||
do {
|
do {
|
||||||
char logBuf[128];
|
char logBuf[128];
|
||||||
snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
|
||||||
index, err, err, errStr, sysErr, sysErrStr);
|
|
||||||
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||||
// syncNodeEventLog(pData->pSyncNode, logBuf);
|
snprintf(logBuf, sizeof(logBuf),
|
||||||
|
"wal read not exist, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s", index, err, err,
|
||||||
|
errStr, sysErr, sysErrStr);
|
||||||
|
syncNodeEventLog(pData->pSyncNode, logBuf);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
||||||
|
index, err, err, errStr, sysErr, sysErrStr);
|
||||||
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
||||||
}
|
}
|
||||||
} while (0);
|
} while (0);
|
||||||
|
@ -372,157 +362,7 @@ static int32_t raftLogGetLastEntry(SSyncLogStore* pLogStore, SSyncRaftEntry** pp
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------
|
int32_t raftLogUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {
|
||||||
// log[0 .. n]
|
|
||||||
|
|
||||||
int32_t logStoreAppendEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry) {
|
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
|
||||||
SWal* pWal = pData->pWal;
|
|
||||||
|
|
||||||
SyncIndex index = 0;
|
|
||||||
SWalSyncInfo syncMeta = {0};
|
|
||||||
syncMeta.isWeek = pEntry->isWeak;
|
|
||||||
syncMeta.seqNum = pEntry->seqNum;
|
|
||||||
syncMeta.term = pEntry->term;
|
|
||||||
|
|
||||||
index = walAppendLog(pWal, pEntry->originalRpcType, syncMeta, pEntry->data, pEntry->dataLen);
|
|
||||||
if (index < 0) {
|
|
||||||
int32_t err = terrno;
|
|
||||||
const char* errStr = tstrerror(err);
|
|
||||||
int32_t sysErr = errno;
|
|
||||||
const char* sysErrStr = strerror(errno);
|
|
||||||
|
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "wal write error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
|
||||||
pEntry->index, err, err, errStr, sysErr, sysErrStr);
|
|
||||||
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
|
||||||
|
|
||||||
ASSERT(0);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
pEntry->index = index;
|
|
||||||
|
|
||||||
do {
|
|
||||||
char eventLog[128];
|
|
||||||
snprintf(eventLog, sizeof(eventLog), "write2 index:%" PRId64 ", type:%s, origin type:%s", pEntry->index,
|
|
||||||
TMSG_INFO(pEntry->msgType), TMSG_INFO(pEntry->originalRpcType));
|
|
||||||
syncNodeEventLog(pData->pSyncNode, eventLog);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncRaftEntry* logStoreGetEntryWithoutLock(SSyncLogStore* pLogStore, SyncIndex index) {
|
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
|
||||||
SWal* pWal = pData->pWal;
|
|
||||||
|
|
||||||
if (index >= SYNC_INDEX_BEGIN && index <= logStoreLastIndex(pLogStore)) {
|
|
||||||
// SWalReadHandle* pWalHandle = walOpenReadHandle(pWal);
|
|
||||||
SWalReader* pWalHandle = pData->pWalHandle;
|
|
||||||
ASSERT(pWalHandle != NULL);
|
|
||||||
|
|
||||||
int32_t code = walReadVer(pWalHandle, index);
|
|
||||||
// int32_t code = walReadVerCached(pWalHandle, index);
|
|
||||||
if (code != 0) {
|
|
||||||
int32_t err = terrno;
|
|
||||||
const char* errStr = tstrerror(err);
|
|
||||||
int32_t sysErr = errno;
|
|
||||||
const char* sysErrStr = strerror(errno);
|
|
||||||
|
|
||||||
do {
|
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "wal read error, index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
|
||||||
index, err, err, errStr, sysErr, sysErrStr);
|
|
||||||
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
|
||||||
// syncNodeEventLog(pData->pSyncNode, logBuf);
|
|
||||||
} else {
|
|
||||||
syncNodeErrorLog(pData->pSyncNode, logBuf);
|
|
||||||
}
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
sError("failed to read ver since %s. index:%" PRId64 "", tstrerror(terrno), index);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncRaftEntry* pEntry = syncEntryBuild(pWalHandle->pHead->head.bodyLen);
|
|
||||||
ASSERT(pEntry != NULL);
|
|
||||||
|
|
||||||
pEntry->msgType = TDMT_SYNC_CLIENT_REQUEST;
|
|
||||||
pEntry->originalRpcType = pWalHandle->pHead->head.msgType;
|
|
||||||
pEntry->seqNum = pWalHandle->pHead->head.syncMeta.seqNum;
|
|
||||||
pEntry->isWeak = pWalHandle->pHead->head.syncMeta.isWeek;
|
|
||||||
pEntry->term = pWalHandle->pHead->head.syncMeta.term;
|
|
||||||
pEntry->index = index;
|
|
||||||
ASSERT(pEntry->dataLen == pWalHandle->pHead->head.bodyLen);
|
|
||||||
memcpy(pEntry->data, pWalHandle->pHead->head.body, pWalHandle->pHead->head.bodyLen);
|
|
||||||
|
|
||||||
/*
|
|
||||||
int32_t saveErr = terrno;
|
|
||||||
walCloseReadHandle(pWalHandle);
|
|
||||||
terrno = saveErr;
|
|
||||||
*/
|
|
||||||
|
|
||||||
return pEntry;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SSyncRaftEntry* logStoreGetEntry(SSyncLogStore* pLogStore, SyncIndex index) {
|
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
|
||||||
SSyncRaftEntry *pEntry = NULL;
|
|
||||||
|
|
||||||
taosThreadMutexLock(&pData->mutex);
|
|
||||||
pEntry = logStoreGetEntryWithoutLock(pLogStore, index);
|
|
||||||
taosThreadMutexUnlock(&pData->mutex);
|
|
||||||
return pEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t logStoreTruncate(SSyncLogStore* pLogStore, SyncIndex fromIndex) {
|
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
|
||||||
SWal* pWal = pData->pWal;
|
|
||||||
// ASSERT(walRollback(pWal, fromIndex) == 0);
|
|
||||||
int32_t code = walRollback(pWal, fromIndex);
|
|
||||||
if (code != 0) {
|
|
||||||
int32_t err = terrno;
|
|
||||||
const char* errStr = tstrerror(err);
|
|
||||||
int32_t sysErr = errno;
|
|
||||||
const char* sysErrStr = strerror(errno);
|
|
||||||
sError("vgId:%d, wal truncate error, from-index:%" PRId64 ", err:%d %X, msg:%s, syserr:%d, sysmsg:%s",
|
|
||||||
pData->pSyncNode->vgId, fromIndex, err, err, errStr, sysErr, sysErrStr);
|
|
||||||
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// event log
|
|
||||||
do {
|
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "wal truncate, from-index:%" PRId64, fromIndex);
|
|
||||||
syncNodeEventLog(pData->pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncIndex logStoreLastIndex(SSyncLogStore* pLogStore) {
|
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
|
||||||
SWal* pWal = pData->pWal;
|
|
||||||
SyncIndex lastIndex = walGetLastVer(pWal);
|
|
||||||
return lastIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncTerm logStoreLastTerm(SSyncLogStore* pLogStore) {
|
|
||||||
SyncTerm lastTerm = 0;
|
|
||||||
SSyncRaftEntry* pLastEntry = logStoreGetLastEntry(pLogStore);
|
|
||||||
if (pLastEntry != NULL) {
|
|
||||||
lastTerm = pLastEntry->term;
|
|
||||||
taosMemoryFree(pLastEntry);
|
|
||||||
}
|
|
||||||
return lastTerm;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {
|
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
SWal* pWal = pData->pWal;
|
SWal* pWal = pData->pWal;
|
||||||
// ASSERT(walCommit(pWal, index) == 0);
|
// ASSERT(walCommit(pWal, index) == 0);
|
||||||
|
@ -540,23 +380,11 @@ int32_t logStoreUpdateCommitIndex(SSyncLogStore* pLogStore, SyncIndex index) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyncIndex logStoreGetCommitIndex(SSyncLogStore* pLogStore) {
|
SyncIndex raftlogCommitIndex(SSyncLogStore* pLogStore) {
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
SSyncLogStoreData* pData = pLogStore->data;
|
||||||
return pData->pSyncNode->commitIndex;
|
return pData->pSyncNode->commitIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSyncRaftEntry* logStoreGetLastEntry(SSyncLogStore* pLogStore) {
|
|
||||||
SSyncLogStoreData* pData = pLogStore->data;
|
|
||||||
SWal* pWal = pData->pWal;
|
|
||||||
SyncIndex lastIndex = walGetLastVer(pWal);
|
|
||||||
|
|
||||||
SSyncRaftEntry* pEntry = NULL;
|
|
||||||
if (lastIndex > 0) {
|
|
||||||
pEntry = logStoreGetEntry(pLogStore, lastIndex);
|
|
||||||
}
|
|
||||||
return pEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
cJSON* logStore2Json(SSyncLogStore* pLogStore) {
|
cJSON* logStore2Json(SSyncLogStore* pLogStore) {
|
||||||
char u64buf[128] = {0};
|
char u64buf[128] = {0};
|
||||||
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
SSyncLogStoreData* pData = (SSyncLogStoreData*)pLogStore->data;
|
||||||
|
@ -595,7 +423,9 @@ cJSON* logStore2Json(SSyncLogStore* pLogStore) {
|
||||||
|
|
||||||
if (!raftLogIsEmpty(pLogStore)) {
|
if (!raftLogIsEmpty(pLogStore)) {
|
||||||
for (SyncIndex i = beginIndex; i <= endIndex; ++i) {
|
for (SyncIndex i = beginIndex; i <= endIndex; ++i) {
|
||||||
SSyncRaftEntry* pEntry = logStoreGetEntry(pLogStore, i);
|
SSyncRaftEntry* pEntry = NULL;
|
||||||
|
raftLogGetEntry(pLogStore, i, &pEntry);
|
||||||
|
|
||||||
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
cJSON_AddItemToArray(pEntries, syncEntry2Json(pEntry));
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pEntry);
|
||||||
}
|
}
|
||||||
|
@ -675,14 +505,14 @@ SyncIndex logStoreWalCommitVer(SSyncLogStore* pLogStore) {
|
||||||
// for debug -----------------
|
// for debug -----------------
|
||||||
void logStorePrint(SSyncLogStore* pLogStore) {
|
void logStorePrint(SSyncLogStore* pLogStore) {
|
||||||
char* serialized = logStore2Str(pLogStore);
|
char* serialized = logStore2Str(pLogStore);
|
||||||
printf("logStorePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("logStorePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logStorePrint2(char* s, SSyncLogStore* pLogStore) {
|
void logStorePrint2(char* s, SSyncLogStore* pLogStore) {
|
||||||
char* serialized = logStore2Str(pLogStore);
|
char* serialized = logStore2Str(pLogStore);
|
||||||
printf("logStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("logStorePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
@ -690,7 +520,7 @@ void logStorePrint2(char* s, SSyncLogStore* pLogStore) {
|
||||||
void logStoreLog(SSyncLogStore* pLogStore) {
|
void logStoreLog(SSyncLogStore* pLogStore) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = logStore2Str(pLogStore);
|
char* serialized = logStore2Str(pLogStore);
|
||||||
sTraceLong("logStoreLog | len:%lu | %s", strlen(serialized), serialized);
|
sTraceLong("logStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -698,7 +528,7 @@ void logStoreLog(SSyncLogStore* pLogStore) {
|
||||||
void logStoreLog2(char* s, SSyncLogStore* pLogStore) {
|
void logStoreLog2(char* s, SSyncLogStore* pLogStore) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = logStore2Str(pLogStore);
|
char* serialized = logStore2Str(pLogStore);
|
||||||
sTraceLong("logStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTraceLong("logStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -706,28 +536,28 @@ void logStoreLog2(char* s, SSyncLogStore* pLogStore) {
|
||||||
// for debug -----------------
|
// for debug -----------------
|
||||||
void logStoreSimplePrint(SSyncLogStore* pLogStore) {
|
void logStoreSimplePrint(SSyncLogStore* pLogStore) {
|
||||||
char* serialized = logStoreSimple2Str(pLogStore);
|
char* serialized = logStoreSimple2Str(pLogStore);
|
||||||
printf("logStoreSimplePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("logStoreSimplePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) {
|
void logStoreSimplePrint2(char* s, SSyncLogStore* pLogStore) {
|
||||||
char* serialized = logStoreSimple2Str(pLogStore);
|
char* serialized = logStoreSimple2Str(pLogStore);
|
||||||
printf("logStoreSimplePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("logStoreSimplePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logStoreSimpleLog(SSyncLogStore* pLogStore) {
|
void logStoreSimpleLog(SSyncLogStore* pLogStore) {
|
||||||
char* serialized = logStoreSimple2Str(pLogStore);
|
char* serialized = logStoreSimple2Str(pLogStore);
|
||||||
sTrace("logStoreSimpleLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("logStoreSimpleLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) {
|
void logStoreSimpleLog2(char* s, SSyncLogStore* pLogStore) {
|
||||||
if (gRaftDetailLog) {
|
if (gRaftDetailLog) {
|
||||||
char* serialized = logStoreSimple2Str(pLogStore);
|
char* serialized = logStoreSimple2Str(pLogStore);
|
||||||
sTrace("logStoreSimpleLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("logStoreSimpleLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -226,25 +226,25 @@ char *raftStore2Str(SRaftStore *pRaftStore) {
|
||||||
// for debug -------------------
|
// for debug -------------------
|
||||||
void raftStorePrint(SRaftStore *pObj) {
|
void raftStorePrint(SRaftStore *pObj) {
|
||||||
char *serialized = raftStore2Str(pObj);
|
char *serialized = raftStore2Str(pObj);
|
||||||
printf("raftStorePrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("raftStorePrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftStorePrint2(char *s, SRaftStore *pObj) {
|
void raftStorePrint2(char *s, SRaftStore *pObj) {
|
||||||
char *serialized = raftStore2Str(pObj);
|
char *serialized = raftStore2Str(pObj);
|
||||||
printf("raftStorePrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("raftStorePrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
void raftStoreLog(SRaftStore *pObj) {
|
void raftStoreLog(SRaftStore *pObj) {
|
||||||
char *serialized = raftStore2Str(pObj);
|
char *serialized = raftStore2Str(pObj);
|
||||||
sTrace("raftStoreLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("raftStoreLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void raftStoreLog2(char *s, SRaftStore *pObj) {
|
void raftStoreLog2(char *s, SRaftStore *pObj) {
|
||||||
char *serialized = raftStore2Str(pObj);
|
char *serialized = raftStore2Str(pObj);
|
||||||
sTrace("raftStoreLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("raftStoreLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,138 +47,75 @@
|
||||||
// msource |-> i,
|
// msource |-> i,
|
||||||
// mdest |-> j])
|
// mdest |-> j])
|
||||||
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
// /\ UNCHANGED <<serverVars, candidateVars, leaderVars, logVars>>
|
||||||
//
|
|
||||||
int32_t syncNodeAppendEntriesPeers(SSyncNode* pSyncNode) {
|
|
||||||
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_LEADER);
|
|
||||||
|
|
||||||
syncIndexMgrLog2("==syncNodeAppendEntriesPeers== pNextIndex", pSyncNode->pNextIndex);
|
int32_t syncNodeReplicateOne(SSyncNode* pSyncNode, SRaftId* pDestId) {
|
||||||
syncIndexMgrLog2("==syncNodeAppendEntriesPeers== pMatchIndex", pSyncNode->pMatchIndex);
|
// next index
|
||||||
logStoreSimpleLog2("==syncNodeAppendEntriesPeers==", pSyncNode->pLogStore);
|
SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId);
|
||||||
|
|
||||||
int32_t ret = 0;
|
// maybe start snapshot
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
SyncIndex logStartIndex = pSyncNode->pLogStore->syncLogBeginIndex(pSyncNode->pLogStore);
|
||||||
SRaftId* pDestId = &(pSyncNode->peersId[i]);
|
SyncIndex logEndIndex = pSyncNode->pLogStore->syncLogEndIndex(pSyncNode->pLogStore);
|
||||||
|
if (nextIndex < logStartIndex || nextIndex - 1 > logEndIndex) {
|
||||||
|
char logBuf[128];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "start snapshot for next-index:%" PRId64 ", start:%" PRId64 ", end:%" PRId64,
|
||||||
|
nextIndex, logStartIndex, logEndIndex);
|
||||||
|
syncNodeEventLog(pSyncNode, logBuf);
|
||||||
|
|
||||||
// set prevLogIndex
|
// start snapshot
|
||||||
SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId);
|
int32_t code = syncNodeStartSnapshot(pSyncNode, pDestId);
|
||||||
|
ASSERT(code == 0);
|
||||||
SyncIndex preLogIndex = nextIndex - 1;
|
return 0;
|
||||||
|
|
||||||
// set preLogTerm
|
|
||||||
SyncTerm preLogTerm = 0;
|
|
||||||
if (preLogIndex >= SYNC_INDEX_BEGIN) {
|
|
||||||
SSyncRaftEntry* pPreEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, preLogIndex);
|
|
||||||
ASSERT(pPreEntry != NULL);
|
|
||||||
|
|
||||||
preLogTerm = pPreEntry->term;
|
|
||||||
syncEntryDestory(pPreEntry);
|
|
||||||
}
|
|
||||||
|
|
||||||
// batch optimized
|
|
||||||
// SyncIndex lastIndex = syncUtilMinIndex(pSyncNode->pLogStore->getLastIndex(pSyncNode->pLogStore), nextIndex);
|
|
||||||
|
|
||||||
SyncAppendEntries* pMsg = NULL;
|
|
||||||
SSyncRaftEntry* pEntry = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, nextIndex);
|
|
||||||
if (pEntry != NULL) {
|
|
||||||
pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId);
|
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
// maybe overflow, send empty record
|
|
||||||
pMsg = syncAppendEntriesBuild(0, pSyncNode->vgId);
|
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
pMsg->srcId = pSyncNode->myRaftId;
|
|
||||||
pMsg->destId = *pDestId;
|
|
||||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
|
||||||
pMsg->prevLogIndex = preLogIndex;
|
|
||||||
pMsg->prevLogTerm = preLogTerm;
|
|
||||||
pMsg->commitIndex = pSyncNode->commitIndex;
|
|
||||||
|
|
||||||
syncAppendEntriesLog2("==syncNodeAppendEntriesPeers==", pMsg);
|
|
||||||
|
|
||||||
// send AppendEntries
|
|
||||||
syncNodeAppendEntries(pSyncNode, pDestId, pMsg);
|
|
||||||
syncAppendEntriesDestroy(pMsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncNodeAppendEntriesOnePeer(SSyncNode* pSyncNode, SRaftId* pDestId, SyncIndex nextIndex) {
|
|
||||||
int32_t ret = 0;
|
|
||||||
|
|
||||||
// pre index, pre term
|
// pre index, pre term
|
||||||
SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex);
|
SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex);
|
||||||
SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex);
|
SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex);
|
||||||
if (preLogTerm == SYNC_TERM_INVALID) {
|
|
||||||
SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1;
|
|
||||||
// SyncIndex newNextIndex = nextIndex + 1;
|
|
||||||
|
|
||||||
syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex);
|
// prepare entry
|
||||||
syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID);
|
SyncAppendEntries* pMsg = NULL;
|
||||||
sError("vgId:%d, sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64
|
|
||||||
", match-index:%d, raftid:%" PRId64,
|
|
||||||
pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// entry pointer array
|
SSyncRaftEntry* pEntry;
|
||||||
SSyncRaftEntry* entryPArr[SYNC_MAX_BATCH_SIZE];
|
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, nextIndex, &pEntry);
|
||||||
memset(entryPArr, 0, sizeof(entryPArr));
|
|
||||||
|
|
||||||
// get entry batch
|
if (code == 0) {
|
||||||
int32_t getCount = 0;
|
ASSERT(pEntry != NULL);
|
||||||
SyncIndex getEntryIndex = nextIndex;
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->batchSize; ++i) {
|
pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId);
|
||||||
SSyncRaftEntry* pEntry = NULL;
|
ASSERT(pMsg != NULL);
|
||||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, getEntryIndex, &pEntry);
|
|
||||||
if (code == 0) {
|
// add pEntry into msg
|
||||||
ASSERT(pEntry != NULL);
|
uint32_t len;
|
||||||
entryPArr[i] = pEntry;
|
char* serialized = syncEntrySerialize(pEntry, &len);
|
||||||
getCount++;
|
ASSERT(len == pEntry->bytes);
|
||||||
getEntryIndex++;
|
memcpy(pMsg->data, serialized, len);
|
||||||
|
|
||||||
|
taosMemoryFree(serialized);
|
||||||
|
syncEntryDestory(pEntry);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
||||||
|
// no entry in log
|
||||||
|
pMsg = syncAppendEntriesBuild(0, pSyncNode->vgId);
|
||||||
|
ASSERT(pMsg != NULL);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
break;
|
do {
|
||||||
}
|
char host[64];
|
||||||
}
|
uint16_t port;
|
||||||
|
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
// event log
|
char logBuf[128];
|
||||||
do {
|
snprintf(logBuf, sizeof(logBuf), "replicate to %s:%d error, next-index:%" PRId64, host, port, nextIndex);
|
||||||
char logBuf[128];
|
syncNodeErrorLog(pSyncNode, logBuf);
|
||||||
char host[64];
|
} while (0);
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "build batch:%d for %s:%d", getCount, host, port);
|
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
// build msg
|
syncAppendEntriesDestroy(pMsg);
|
||||||
SyncAppendEntriesBatch* pMsg = syncAppendEntriesBatchBuild(entryPArr, getCount, pSyncNode->vgId);
|
return -1;
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
|
|
||||||
// free entries
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->batchSize; ++i) {
|
|
||||||
SSyncRaftEntry* pEntry = entryPArr[i];
|
|
||||||
if (pEntry != NULL) {
|
|
||||||
syncEntryDestory(pEntry);
|
|
||||||
entryPArr[i] = NULL;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare msg
|
// prepare msg
|
||||||
|
ASSERT(pMsg != NULL);
|
||||||
pMsg->srcId = pSyncNode->myRaftId;
|
pMsg->srcId = pSyncNode->myRaftId;
|
||||||
pMsg->destId = *pDestId;
|
pMsg->destId = *pDestId;
|
||||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||||
|
@ -186,293 +123,69 @@ int32_t syncNodeAppendEntriesOnePeer(SSyncNode* pSyncNode, SRaftId* pDestId, Syn
|
||||||
pMsg->prevLogTerm = preLogTerm;
|
pMsg->prevLogTerm = preLogTerm;
|
||||||
pMsg->commitIndex = pSyncNode->commitIndex;
|
pMsg->commitIndex = pSyncNode->commitIndex;
|
||||||
pMsg->privateTerm = 0;
|
pMsg->privateTerm = 0;
|
||||||
pMsg->dataCount = getCount;
|
// pMsg->privateTerm = syncIndexMgrGetTerm(pSyncNode->pNextIndex, pDestId);
|
||||||
|
|
||||||
// send msg
|
// send msg
|
||||||
syncNodeAppendEntriesBatch(pSyncNode, pDestId, pMsg);
|
syncNodeMaybeSendAppendEntries(pSyncNode, pDestId, pMsg);
|
||||||
|
syncAppendEntriesDestroy(pMsg);
|
||||||
|
|
||||||
// speed up
|
return 0;
|
||||||
if (pMsg->dataCount > 0 && pSyncNode->commitIndex - pMsg->prevLogIndex > SYNC_SLOW_DOWN_RANGE) {
|
|
||||||
ret = 1;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
do {
|
|
||||||
char logBuf[128];
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "maybe speed up for %s:%d, pre-index:%ld", host, port, pMsg->prevLogIndex);
|
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
syncAppendEntriesBatchDestroy(pMsg);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode) {
|
int32_t syncNodeReplicate(SSyncNode* pSyncNode) {
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ret = 0;
|
syncNodeEventLog(pSyncNode, "do replicate");
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
|
||||||
SRaftId* pDestId = &(pSyncNode->peersId[i]);
|
|
||||||
|
|
||||||
// next index
|
|
||||||
SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId);
|
|
||||||
ret = syncNodeAppendEntriesOnePeer(pSyncNode, pDestId, nextIndex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
int32_t syncNodeAppendEntriesPeersSnapshot2(SSyncNode* pSyncNode) {
|
|
||||||
if (pSyncNode->state != TAOS_SYNC_STATE_LEADER) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
SRaftId* pDestId = &(pSyncNode->peersId[i]);
|
SRaftId* pDestId = &(pSyncNode->peersId[i]);
|
||||||
|
ret = syncNodeReplicateOne(pSyncNode, pDestId);
|
||||||
// next index
|
if (ret != 0) {
|
||||||
SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId);
|
char host[64];
|
||||||
|
int16_t port;
|
||||||
// pre index, pre term
|
|
||||||
SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex);
|
|
||||||
SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex);
|
|
||||||
if (preLogTerm == SYNC_TERM_INVALID) {
|
|
||||||
SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1;
|
|
||||||
// SyncIndex newNextIndex = nextIndex + 1;
|
|
||||||
|
|
||||||
syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex);
|
|
||||||
syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID);
|
|
||||||
sError("vgId:%d, sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64
|
|
||||||
", match-index:%d, raftid:%" PRId64,
|
|
||||||
pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// entry pointer array
|
|
||||||
SSyncRaftEntry* entryPArr[SYNC_MAX_BATCH_SIZE];
|
|
||||||
memset(entryPArr, 0, sizeof(entryPArr));
|
|
||||||
|
|
||||||
// get entry batch
|
|
||||||
int32_t getCount = 0;
|
|
||||||
SyncIndex getEntryIndex = nextIndex;
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->batchSize; ++i) {
|
|
||||||
SSyncRaftEntry* pEntry = NULL;
|
|
||||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, getEntryIndex, &pEntry);
|
|
||||||
if (code == 0) {
|
|
||||||
ASSERT(pEntry != NULL);
|
|
||||||
entryPArr[i] = pEntry;
|
|
||||||
getCount++;
|
|
||||||
getEntryIndex++;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// event log
|
|
||||||
do {
|
|
||||||
char logBuf[128];
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
||||||
snprintf(logBuf, sizeof(logBuf), "build batch:%d for %s:%d", getCount, host, port);
|
sError("vgId:%d, do append entries error for %s:%d", pSyncNode->vgId, host, port);
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
// build msg
|
|
||||||
SyncAppendEntriesBatch* pMsg = syncAppendEntriesBatchBuild(entryPArr, getCount, pSyncNode->vgId);
|
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
|
|
||||||
// free entries
|
|
||||||
for (int32_t i = 0; i < pSyncNode->pRaftCfg->batchSize; ++i) {
|
|
||||||
SSyncRaftEntry* pEntry = entryPArr[i];
|
|
||||||
if (pEntry != NULL) {
|
|
||||||
syncEntryDestory(pEntry);
|
|
||||||
entryPArr[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare msg
|
|
||||||
pMsg->srcId = pSyncNode->myRaftId;
|
|
||||||
pMsg->destId = *pDestId;
|
|
||||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
|
||||||
pMsg->prevLogIndex = preLogIndex;
|
|
||||||
pMsg->prevLogTerm = preLogTerm;
|
|
||||||
pMsg->commitIndex = pSyncNode->commitIndex;
|
|
||||||
pMsg->privateTerm = 0;
|
|
||||||
pMsg->dataCount = getCount;
|
|
||||||
|
|
||||||
// send msg
|
|
||||||
syncNodeAppendEntriesBatch(pSyncNode, pDestId, pMsg);
|
|
||||||
|
|
||||||
// speed up
|
|
||||||
if (pMsg->dataCount > 0 && pSyncNode->commitIndex - pMsg->prevLogIndex > SYNC_SLOW_DOWN_RANGE) {
|
|
||||||
ret = 1;
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
do {
|
|
||||||
char logBuf[128];
|
|
||||||
char host[64];
|
|
||||||
uint16_t port;
|
|
||||||
syncUtilU642Addr(pDestId->addr, host, sizeof(host), &port);
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "maybe speed up for %s:%d, pre-index:%ld", host, port, pMsg->prevLogIndex);
|
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
syncAppendEntriesBatchDestroy(pMsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
int32_t syncNodeAppendEntriesPeersSnapshot(SSyncNode* pSyncNode) {
|
|
||||||
ASSERT(pSyncNode->state == TAOS_SYNC_STATE_LEADER);
|
|
||||||
|
|
||||||
syncIndexMgrLog2("begin append entries peers pNextIndex:", pSyncNode->pNextIndex);
|
|
||||||
syncIndexMgrLog2("begin append entries peers pMatchIndex:", pSyncNode->pMatchIndex);
|
|
||||||
logStoreSimpleLog2("begin append entries peers LogStore:", pSyncNode->pLogStore);
|
|
||||||
|
|
||||||
|
int32_t syncNodeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
for (int i = 0; i < pSyncNode->peersNum; ++i) {
|
syncLogSendAppendEntries(pSyncNode, pMsg, "");
|
||||||
SRaftId* pDestId = &(pSyncNode->peersId[i]);
|
|
||||||
|
|
||||||
// next index
|
SRpcMsg rpcMsg;
|
||||||
SyncIndex nextIndex = syncIndexMgrGetIndex(pSyncNode->pNextIndex, pDestId);
|
syncAppendEntries2RpcMsg(pMsg, &rpcMsg);
|
||||||
|
syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg);
|
||||||
|
|
||||||
// pre index, pre term
|
SPeerState* pState = syncNodeGetPeerState(pSyncNode, destRaftId);
|
||||||
SyncIndex preLogIndex = syncNodeGetPreIndex(pSyncNode, nextIndex);
|
ASSERT(pState != NULL);
|
||||||
SyncTerm preLogTerm = syncNodeGetPreTerm(pSyncNode, nextIndex);
|
|
||||||
if (preLogTerm == SYNC_TERM_INVALID) {
|
|
||||||
SyncIndex newNextIndex = syncNodeGetLastIndex(pSyncNode) + 1;
|
|
||||||
// SyncIndex newNextIndex = nextIndex + 1;
|
|
||||||
|
|
||||||
syncIndexMgrSetIndex(pSyncNode->pNextIndex, pDestId, newNextIndex);
|
if (pMsg->dataLen > 0) {
|
||||||
syncIndexMgrSetIndex(pSyncNode->pMatchIndex, pDestId, SYNC_INDEX_INVALID);
|
pState->lastSendIndex = pMsg->prevLogIndex + 1;
|
||||||
sError("vgId:%d, sync get pre term error, nextIndex:%" PRId64 ", update next-index:%" PRId64
|
pState->lastSendTime = taosGetTimestampMs();
|
||||||
", match-index:%d, raftid:%" PRId64,
|
|
||||||
pSyncNode->vgId, nextIndex, newNextIndex, SYNC_INDEX_INVALID, pDestId->addr);
|
|
||||||
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepare entry
|
|
||||||
SyncAppendEntries* pMsg = NULL;
|
|
||||||
|
|
||||||
SSyncRaftEntry* pEntry;
|
|
||||||
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, nextIndex, &pEntry);
|
|
||||||
|
|
||||||
if (code == 0) {
|
|
||||||
ASSERT(pEntry != NULL);
|
|
||||||
|
|
||||||
pMsg = syncAppendEntriesBuild(pEntry->bytes, pSyncNode->vgId);
|
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
if (terrno == TSDB_CODE_WAL_LOG_NOT_EXIST) {
|
|
||||||
// no entry in log
|
|
||||||
pMsg = syncAppendEntriesBuild(0, pSyncNode->vgId);
|
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
syncNodeLog3("", pSyncNode);
|
|
||||||
ASSERT(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// prepare msg
|
|
||||||
ASSERT(pMsg != NULL);
|
|
||||||
pMsg->srcId = pSyncNode->myRaftId;
|
|
||||||
pMsg->destId = *pDestId;
|
|
||||||
pMsg->term = pSyncNode->pRaftStore->currentTerm;
|
|
||||||
pMsg->prevLogIndex = preLogIndex;
|
|
||||||
pMsg->prevLogTerm = preLogTerm;
|
|
||||||
pMsg->commitIndex = pSyncNode->commitIndex;
|
|
||||||
pMsg->privateTerm = 0;
|
|
||||||
// pMsg->privateTerm = syncIndexMgrGetTerm(pSyncNode->pNextIndex, pDestId);
|
|
||||||
|
|
||||||
// send msg
|
|
||||||
syncNodeAppendEntries(pSyncNode, pDestId, pMsg);
|
|
||||||
syncAppendEntriesDestroy(pMsg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeReplicate(SSyncNode* pSyncNode, bool isTimer) {
|
int32_t syncNodeMaybeSendAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncAppendEntries* pMsg) {
|
||||||
// start replicate
|
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
if (syncNodeNeedSendAppendEntries(pSyncNode, destRaftId, pMsg)) {
|
||||||
switch (pSyncNode->pRaftCfg->snapshotStrategy) {
|
ret = syncNodeSendAppendEntries(pSyncNode, destRaftId, pMsg);
|
||||||
case SYNC_STRATEGY_NO_SNAPSHOT:
|
|
||||||
ret = syncNodeAppendEntriesPeers(pSyncNode);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SYNC_STRATEGY_STANDARD_SNAPSHOT:
|
|
||||||
ret = syncNodeAppendEntriesPeersSnapshot(pSyncNode);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case SYNC_STRATEGY_WAL_FIRST:
|
|
||||||
ret = syncNodeAppendEntriesPeersSnapshot2(pSyncNode);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
ret = syncNodeAppendEntriesPeers(pSyncNode);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// start delay
|
|
||||||
int64_t timeNow = taosGetTimestampMs();
|
|
||||||
int64_t startDelay = timeNow - pSyncNode->startTime;
|
|
||||||
|
|
||||||
// replicate delay
|
|
||||||
int64_t replicateDelay = timeNow - pSyncNode->lastReplicateTime;
|
|
||||||
pSyncNode->lastReplicateTime = timeNow;
|
|
||||||
|
|
||||||
if (ret > 0 && isTimer && startDelay > SYNC_SPEED_UP_AFTER_MS) {
|
|
||||||
// speed up replicate
|
|
||||||
int32_t ms =
|
|
||||||
pSyncNode->heartbeatTimerMS < SYNC_SPEED_UP_HB_TIMER ? pSyncNode->heartbeatTimerMS : SYNC_SPEED_UP_HB_TIMER;
|
|
||||||
syncNodeRestartNowHeartbeatTimerMS(pSyncNode, ms);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
do {
|
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "replicate speed up");
|
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
syncNodeRestartHeartbeatTimer(pSyncNode);
|
char logBuf[128];
|
||||||
|
char host[64];
|
||||||
|
int16_t port;
|
||||||
|
syncUtilU642Addr(destRaftId->addr, host, sizeof(host), &port);
|
||||||
|
|
||||||
#if 0
|
snprintf(logBuf, sizeof(logBuf), "do not repcate to %s:%d for index:%" PRId64, host, port, pMsg->prevLogIndex + 1);
|
||||||
do {
|
syncNodeEventLog(pSyncNode, logBuf);
|
||||||
char logBuf[128];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "replicate slow down");
|
|
||||||
syncNodeEventLog(pSyncNode, logBuf);
|
|
||||||
} while (0);
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -488,12 +201,34 @@ int32_t syncNodeAppendEntries(SSyncNode* pSyncNode, const SRaftId* destRaftId, c
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeAppendEntriesBatch(SSyncNode* pSyncNode, const SRaftId* destRaftId,
|
int32_t syncNodeSendHeartbeat(SSyncNode* pSyncNode, const SRaftId* destRaftId, const SyncHeartbeat* pMsg) {
|
||||||
const SyncAppendEntriesBatch* pMsg) {
|
int32_t ret = 0;
|
||||||
syncLogSendAppendEntriesBatch(pSyncNode, pMsg, "");
|
syncLogSendHeartbeat(pSyncNode, pMsg, "");
|
||||||
|
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
syncAppendEntriesBatch2RpcMsg(pMsg, &rpcMsg);
|
syncHeartbeat2RpcMsg(pMsg, &rpcMsg);
|
||||||
syncNodeSendMsgById(destRaftId, pSyncNode, &rpcMsg);
|
syncNodeSendMsgById(&(pMsg->destId), pSyncNode, &rpcMsg);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t syncNodeHeartbeatPeers(SSyncNode* pSyncNode) {
|
||||||
|
for (int32_t i = 0; i < pSyncNode->peersNum; ++i) {
|
||||||
|
SyncHeartbeat* pSyncMsg = syncHeartbeatBuild(pSyncNode->vgId);
|
||||||
|
pSyncMsg->srcId = pSyncNode->myRaftId;
|
||||||
|
pSyncMsg->destId = pSyncNode->peersId[i];
|
||||||
|
pSyncMsg->term = pSyncNode->pRaftStore->currentTerm;
|
||||||
|
pSyncMsg->commitIndex = pSyncNode->commitIndex;
|
||||||
|
pSyncMsg->minMatchIndex = syncMinMatchIndex(pSyncNode);
|
||||||
|
pSyncMsg->privateTerm = 0;
|
||||||
|
|
||||||
|
SRpcMsg rpcMsg;
|
||||||
|
syncHeartbeat2RpcMsg(pSyncMsg, &rpcMsg);
|
||||||
|
|
||||||
|
// send msg
|
||||||
|
syncNodeSendHeartbeat(pSyncNode, &(pSyncMsg->destId), pSyncMsg);
|
||||||
|
|
||||||
|
syncHeartbeatDestroy(pSyncMsg);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
|
@ -42,65 +42,6 @@
|
||||||
// m)
|
// m)
|
||||||
// /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
|
// /\ UNCHANGED <<state, currentTerm, candidateVars, leaderVars, logVars>>
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnRequestVoteCb(SSyncNode* ths, SyncRequestVote* pMsg) {
|
|
||||||
int32_t ret = 0;
|
|
||||||
|
|
||||||
// if already drop replica, do not process
|
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
|
||||||
syncLogRecvRequestVote(ths, pMsg, "maybe replica already dropped");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool logOK = (pMsg->lastLogTerm > ths->pLogStore->getLastTerm(ths->pLogStore)) ||
|
|
||||||
((pMsg->lastLogTerm == ths->pLogStore->getLastTerm(ths->pLogStore)) &&
|
|
||||||
(pMsg->lastLogIndex >= ths->pLogStore->getLastIndex(ths->pLogStore)));
|
|
||||||
|
|
||||||
// maybe update term
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
|
||||||
syncNodeUpdateTerm(ths, pMsg->term);
|
|
||||||
#if 0
|
|
||||||
if (logOK) {
|
|
||||||
syncNodeUpdateTerm(ths, pMsg->term);
|
|
||||||
} else {
|
|
||||||
syncNodeUpdateTermWithoutStepDown(ths, pMsg->term);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
ASSERT(pMsg->term <= ths->pRaftStore->currentTerm);
|
|
||||||
|
|
||||||
bool grant = (pMsg->term == ths->pRaftStore->currentTerm) && logOK &&
|
|
||||||
((!raftStoreHasVoted(ths->pRaftStore)) || (syncUtilSameId(&(ths->pRaftStore->voteFor), &(pMsg->srcId))));
|
|
||||||
if (grant) {
|
|
||||||
// maybe has already voted for pMsg->srcId
|
|
||||||
// vote again, no harm
|
|
||||||
raftStoreVote(ths->pRaftStore, &(pMsg->srcId));
|
|
||||||
|
|
||||||
// forbid elect for this round
|
|
||||||
syncNodeResetElectTimer(ths);
|
|
||||||
}
|
|
||||||
|
|
||||||
// send msg
|
|
||||||
SyncRequestVoteReply* pReply = syncRequestVoteReplyBuild(ths->vgId);
|
|
||||||
pReply->srcId = ths->myRaftId;
|
|
||||||
pReply->destId = pMsg->srcId;
|
|
||||||
pReply->term = ths->pRaftStore->currentTerm;
|
|
||||||
pReply->voteGranted = grant;
|
|
||||||
|
|
||||||
// trace log
|
|
||||||
do {
|
|
||||||
char logBuf[32];
|
|
||||||
snprintf(logBuf, sizeof(logBuf), "grant:%d", pReply->voteGranted);
|
|
||||||
syncLogRecvRequestVote(ths, pMsg, logBuf);
|
|
||||||
syncLogSendRequestVoteReply(ths, pReply, "");
|
|
||||||
} while (0);
|
|
||||||
|
|
||||||
SRpcMsg rpcMsg;
|
|
||||||
syncRequestVoteReply2RpcMsg(pReply, &rpcMsg);
|
|
||||||
syncNodeSendMsgById(&pReply->destId, ths, &rpcMsg);
|
|
||||||
syncRequestVoteReplyDestroy(pReply);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pMsg) {
|
static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pMsg) {
|
||||||
SyncTerm myLastTerm = syncNodeGetLastTerm(pSyncNode);
|
SyncTerm myLastTerm = syncNodeGetLastTerm(pSyncNode);
|
||||||
|
@ -157,12 +98,12 @@ static bool syncNodeOnRequestVoteLogOK(SSyncNode* pSyncNode, SyncRequestVote* pM
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) {
|
int32_t syncNodeOnRequestVote(SSyncNode* ths, SyncRequestVote* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
// if already drop replica, do not process
|
// if already drop replica, do not process
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
||||||
syncLogRecvRequestVote(ths, pMsg, "maybe replica already dropped");
|
syncLogRecvRequestVote(ths, pMsg, "not in my config");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,14 +111,8 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) {
|
||||||
|
|
||||||
// maybe update term
|
// maybe update term
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
syncNodeUpdateTerm(ths, pMsg->term);
|
syncNodeStepDown(ths, pMsg->term);
|
||||||
#if 0
|
// syncNodeUpdateTerm(ths, pMsg->term);
|
||||||
if (logOK) {
|
|
||||||
syncNodeUpdateTerm(ths, pMsg->term);
|
|
||||||
} else {
|
|
||||||
syncNodeUpdateTermWithoutStepDown(ths, pMsg->term);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
ASSERT(pMsg->term <= ths->pRaftStore->currentTerm);
|
ASSERT(pMsg->term <= ths->pRaftStore->currentTerm);
|
||||||
|
|
||||||
|
@ -188,6 +123,9 @@ int32_t syncNodeOnRequestVoteSnapshotCb(SSyncNode* ths, SyncRequestVote* pMsg) {
|
||||||
// vote again, no harm
|
// vote again, no harm
|
||||||
raftStoreVote(ths->pRaftStore, &(pMsg->srcId));
|
raftStoreVote(ths->pRaftStore, &(pMsg->srcId));
|
||||||
|
|
||||||
|
// candidate ?
|
||||||
|
syncNodeStepDown(ths, ths->pRaftStore->currentTerm);
|
||||||
|
|
||||||
// forbid elect for this round
|
// forbid elect for this round
|
||||||
syncNodeResetElectTimer(ths);
|
syncNodeResetElectTimer(ths);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,68 +37,12 @@
|
||||||
// /\ Discard(m)
|
// /\ Discard(m)
|
||||||
// /\ UNCHANGED <<serverVars, votedFor, leaderVars, logVars>>
|
// /\ UNCHANGED <<serverVars, votedFor, leaderVars, logVars>>
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnRequestVoteReplyCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
int32_t syncNodeOnRequestVoteReply(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
|
|
||||||
// if already drop replica, do not process
|
// if already drop replica, do not process
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId))) {
|
||||||
syncLogRecvRequestVoteReply(ths, pMsg, "maybe replica already dropped");
|
syncLogRecvRequestVoteReply(ths, pMsg, "not in my config");
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// drop stale response
|
|
||||||
if (pMsg->term < ths->pRaftStore->currentTerm) {
|
|
||||||
syncLogRecvRequestVoteReply(ths, pMsg, "drop stale response");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ASSERT(!(pMsg->term > ths->pRaftStore->currentTerm));
|
|
||||||
// no need this code, because if I receive reply.term, then I must have sent for that term.
|
|
||||||
// if (pMsg->term > ths->pRaftStore->currentTerm) {
|
|
||||||
// syncNodeUpdateTerm(ths, pMsg->term);
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
|
||||||
syncLogRecvRequestVoteReply(ths, pMsg, "error term");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
syncLogRecvRequestVoteReply(ths, pMsg, "");
|
|
||||||
ASSERT(pMsg->term == ths->pRaftStore->currentTerm);
|
|
||||||
|
|
||||||
// This tallies votes even when the current state is not Candidate,
|
|
||||||
// but they won't be looked at, so it doesn't matter.
|
|
||||||
if (ths->state == TAOS_SYNC_STATE_CANDIDATE) {
|
|
||||||
votesRespondAdd(ths->pVotesRespond, pMsg);
|
|
||||||
if (pMsg->voteGranted) {
|
|
||||||
// add vote
|
|
||||||
voteGrantedVote(ths->pVotesGranted, pMsg);
|
|
||||||
|
|
||||||
// maybe to leader
|
|
||||||
if (voteGrantedMajority(ths->pVotesGranted)) {
|
|
||||||
if (!ths->pVotesGranted->toLeader) {
|
|
||||||
syncNodeCandidate2Leader(ths);
|
|
||||||
|
|
||||||
// prevent to leader again!
|
|
||||||
ths->pVotesGranted->toLeader = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
;
|
|
||||||
// do nothing
|
|
||||||
// UNCHANGED <<votesGranted, voterLog>>
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteReply* pMsg) {
|
|
||||||
int32_t ret = 0;
|
|
||||||
|
|
||||||
// if already drop replica, do not process
|
|
||||||
if (!syncNodeInRaftGroup(ths, &(pMsg->srcId)) && !ths->pRaftCfg->isStandBy) {
|
|
||||||
syncLogRecvRequestVoteReply(ths, pMsg, "maybe replica already dropped");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,6 +60,7 @@ int32_t syncNodeOnRequestVoteReplySnapshotCb(SSyncNode* ths, SyncRequestVoteRepl
|
||||||
|
|
||||||
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
if (pMsg->term > ths->pRaftStore->currentTerm) {
|
||||||
syncLogRecvRequestVoteReply(ths, pMsg, "error term");
|
syncLogRecvRequestVoteReply(ths, pMsg, "error term");
|
||||||
|
syncNodeStepDown(ths, pMsg->term);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ void syncRespCleanByTTL(SSyncRespMgr *pObj, int64_t ttl, bool rsp) {
|
||||||
|
|
||||||
while (pStub) {
|
while (pStub) {
|
||||||
size_t len;
|
size_t len;
|
||||||
void *key = taosHashGetKey(pStub, &len);
|
void * key = taosHashGetKey(pStub, &len);
|
||||||
uint64_t *pSeqNum = (uint64_t *)key;
|
uint64_t *pSeqNum = (uint64_t *)key;
|
||||||
sum++;
|
sum++;
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,8 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
|
||||||
}
|
}
|
||||||
memset(pSender, 0, sizeof(*pSender));
|
memset(pSender, 0, sizeof(*pSender));
|
||||||
|
|
||||||
|
int64_t timeNow = taosGetTimestampMs();
|
||||||
|
|
||||||
pSender->start = false;
|
pSender->start = false;
|
||||||
pSender->seq = SYNC_SNAPSHOT_SEQ_INVALID;
|
pSender->seq = SYNC_SNAPSHOT_SEQ_INVALID;
|
||||||
pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID;
|
pSender->ack = SYNC_SNAPSHOT_SEQ_INVALID;
|
||||||
|
@ -51,7 +53,8 @@ SSyncSnapshotSender *snapshotSenderCreate(SSyncNode *pSyncNode, int32_t replicaI
|
||||||
pSender->pSyncNode = pSyncNode;
|
pSender->pSyncNode = pSyncNode;
|
||||||
pSender->replicaIndex = replicaIndex;
|
pSender->replicaIndex = replicaIndex;
|
||||||
pSender->term = pSyncNode->pRaftStore->currentTerm;
|
pSender->term = pSyncNode->pRaftStore->currentTerm;
|
||||||
pSender->privateTerm = taosGetTimestampMs() + 100;
|
pSender->privateTerm = timeNow + 100;
|
||||||
|
pSender->startTime = timeNow;
|
||||||
pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &(pSender->snapshot));
|
pSender->pSyncNode->pFsm->FpGetSnapshotInfo(pSender->pSyncNode->pFsm, &(pSender->snapshot));
|
||||||
pSender->finish = false;
|
pSender->finish = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -402,6 +405,24 @@ char *snapshotSender2SimpleStr(SSyncSnapshotSender *pSender, char *event) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t syncNodeStartSnapshot(SSyncNode *pSyncNode, SRaftId *pDestId) {
|
||||||
|
// calculate <start, end> index
|
||||||
|
|
||||||
|
syncNodeEventLog(pSyncNode, "start snapshot ...");
|
||||||
|
|
||||||
|
SSyncSnapshotSender *pSender = syncNodeGetSnapshotSender(pSyncNode, pDestId);
|
||||||
|
if (pSender == NULL) {
|
||||||
|
// create sender
|
||||||
|
} else {
|
||||||
|
// if <start, end> is same
|
||||||
|
// return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// send begin msg
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// -------------------------------------
|
// -------------------------------------
|
||||||
SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId) {
|
SSyncSnapshotReceiver *snapshotReceiverCreate(SSyncNode *pSyncNode, SRaftId fromId) {
|
||||||
bool condition = (pSyncNode->pFsm->FpSnapshotStartWrite != NULL) && (pSyncNode->pFsm->FpSnapshotStopWrite != NULL) &&
|
bool condition = (pSyncNode->pFsm->FpSnapshotStartWrite != NULL) && (pSyncNode->pFsm->FpSnapshotStopWrite != NULL) &&
|
||||||
|
@ -721,7 +742,7 @@ char *snapshotReceiver2SimpleStr(SSyncSnapshotReceiver *pReceiver, char *event)
|
||||||
// condition 3, recv SYNC_SNAPSHOT_SEQ_FORCE_CLOSE, force close
|
// condition 3, recv SYNC_SNAPSHOT_SEQ_FORCE_CLOSE, force close
|
||||||
// condition 4, got data, update ack
|
// condition 4, got data, update ack
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
int32_t syncNodeOnSnapshot(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
// get receiver
|
// get receiver
|
||||||
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
SSyncSnapshotReceiver *pReceiver = pSyncNode->pNewNodeReceiver;
|
||||||
bool needRsp = false;
|
bool needRsp = false;
|
||||||
|
@ -834,7 +855,7 @@ int32_t syncNodeOnSnapshotSendCb(SSyncNode *pSyncNode, SyncSnapshotSend *pMsg) {
|
||||||
// condition 2 sender receives ack, set seq = ack + 1, send msg from seq
|
// condition 2 sender receives ack, set seq = ack + 1, send msg from seq
|
||||||
// condition 3 sender receives error msg, just print error log
|
// condition 3 sender receives error msg, just print error log
|
||||||
//
|
//
|
||||||
int32_t syncNodeOnSnapshotRspCb(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
int32_t syncNodeOnSnapshotReply(SSyncNode *pSyncNode, SyncSnapshotRsp *pMsg) {
|
||||||
// if already drop replica, do not process
|
// if already drop replica, do not process
|
||||||
if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId)) && pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
if (!syncNodeInRaftGroup(pSyncNode, &(pMsg->srcId)) && pSyncNode->state == TAOS_SYNC_STATE_LEADER) {
|
||||||
sError("vgId:%d, recv sync-snapshot-rsp, maybe replica already dropped", pSyncNode->vgId);
|
sError("vgId:%d, recv sync-snapshot-rsp, maybe replica already dropped", pSyncNode->vgId);
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "syncTimeout.h"
|
#include "syncTimeout.h"
|
||||||
#include "syncElection.h"
|
#include "syncElection.h"
|
||||||
#include "syncRaftCfg.h"
|
#include "syncRaftCfg.h"
|
||||||
|
#include "syncRaftLog.h"
|
||||||
#include "syncReplication.h"
|
#include "syncReplication.h"
|
||||||
#include "syncRespMgr.h"
|
#include "syncRespMgr.h"
|
||||||
|
|
||||||
|
@ -60,12 +61,36 @@ static void syncNodeCleanConfigIndex(SSyncNode* ths) {
|
||||||
int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
||||||
syncNodeEventLog(ths, "timer routines");
|
syncNodeEventLog(ths, "timer routines");
|
||||||
|
|
||||||
if (ths->vgId == 1) {
|
// timer replicate
|
||||||
|
syncNodeReplicate(ths);
|
||||||
|
|
||||||
|
// clean mnode index
|
||||||
|
if (syncNodeIsMnode(ths)) {
|
||||||
syncNodeCleanConfigIndex(ths);
|
syncNodeCleanConfigIndex(ths);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// end timeout wal snapshot
|
||||||
|
int64_t timeNow = taosGetTimestampMs();
|
||||||
|
if (timeNow - ths->snapshottingIndex > SYNC_DEL_WAL_MS &&
|
||||||
|
atomic_load_64(&ths->snapshottingIndex) != SYNC_INDEX_INVALID) {
|
||||||
|
SSyncLogStoreData* pData = ths->pLogStore->data;
|
||||||
|
int32_t code = walEndSnapshot(pData->pWal);
|
||||||
|
if (code != 0) {
|
||||||
|
sError("vgId:%d, wal snapshot end error since:%s", ths->vgId, terrstr(terrno));
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
do {
|
||||||
|
char logBuf[256];
|
||||||
|
snprintf(logBuf, sizeof(logBuf), "wal snapshot end, index:%" PRId64, atomic_load_64(&ths->snapshottingIndex));
|
||||||
|
syncNodeEventLog(ths, logBuf);
|
||||||
|
} while (0);
|
||||||
|
|
||||||
|
atomic_store_64(&ths->snapshottingIndex, SYNC_INDEX_INVALID);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
if (ths->vgId != 1) {
|
if (!syncNodeIsMnode(ths)) {
|
||||||
syncRespClean(ths->pSyncRespMgr);
|
syncRespClean(ths->pSyncRespMgr);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -73,9 +98,9 @@ int32_t syncNodeTimerRoutine(SSyncNode* ths) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) {
|
int32_t syncNodeOnTimer(SSyncNode* ths, SyncTimeout* pMsg) {
|
||||||
int32_t ret = 0;
|
int32_t ret = 0;
|
||||||
syncTimeoutLog2("==syncNodeOnTimeoutCb==", pMsg);
|
syncLogRecvTimer(ths, pMsg, "");
|
||||||
|
|
||||||
if (pMsg->timeoutType == SYNC_TIMEOUT_PING) {
|
if (pMsg->timeoutType == SYNC_TIMEOUT_PING) {
|
||||||
if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) {
|
if (atomic_load_64(&ths->pingTimerLogicClockUser) <= pMsg->logicClock) {
|
||||||
|
@ -84,27 +109,29 @@ int32_t syncNodeOnTimeoutCb(SSyncNode* ths, SyncTimeout* pMsg) {
|
||||||
// syncNodePingAll(ths);
|
// syncNodePingAll(ths);
|
||||||
// syncNodePingPeers(ths);
|
// syncNodePingPeers(ths);
|
||||||
|
|
||||||
// sTrace("vgId:%d, sync timeout, type:ping count:%d", ths->vgId, ths->pingTimerCounter);
|
|
||||||
syncNodeTimerRoutine(ths);
|
syncNodeTimerRoutine(ths);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) {
|
} else if (pMsg->timeoutType == SYNC_TIMEOUT_ELECTION) {
|
||||||
if (atomic_load_64(&ths->electTimerLogicClockUser) <= pMsg->logicClock) {
|
if (atomic_load_64(&ths->electTimerLogicClockUser) <= pMsg->logicClock) {
|
||||||
++(ths->electTimerCounter);
|
++(ths->electTimerCounter);
|
||||||
sTrace("vgId:%d, sync timer, type:election count:%" PRId64 ", electTimerLogicClockUser:%" PRId64 "", ths->vgId,
|
sTrace("vgId:%d, sync timer, type:election count:%" PRIu64 ", lc-user:%" PRIu64, ths->vgId,
|
||||||
ths->electTimerCounter, ths->electTimerLogicClockUser);
|
ths->electTimerCounter, ths->electTimerLogicClockUser);
|
||||||
|
|
||||||
syncNodeElect(ths);
|
syncNodeElect(ths);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (pMsg->timeoutType == SYNC_TIMEOUT_HEARTBEAT) {
|
} else if (pMsg->timeoutType == SYNC_TIMEOUT_HEARTBEAT) {
|
||||||
if (atomic_load_64(&ths->heartbeatTimerLogicClockUser) <= pMsg->logicClock) {
|
if (atomic_load_64(&ths->heartbeatTimerLogicClockUser) <= pMsg->logicClock) {
|
||||||
++(ths->heartbeatTimerCounter);
|
++(ths->heartbeatTimerCounter);
|
||||||
sTrace("vgId:%d, sync timer, type:replicate count:%" PRId64 ", heartbeatTimerLogicClockUser:%" PRId64 "",
|
sTrace("vgId:%d, sync timer, type:replicate count:%" PRIu64 ", lc-user:%" PRIu64, ths->vgId,
|
||||||
ths->vgId, ths->heartbeatTimerCounter, ths->heartbeatTimerLogicClockUser);
|
ths->heartbeatTimerCounter, ths->heartbeatTimerLogicClockUser);
|
||||||
syncNodeReplicate(ths, true);
|
|
||||||
|
// syncNodeReplicate(ths, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
sError("vgId:%d, unknown timeout-type:%d", ths->vgId, pMsg->timeoutType);
|
sError("vgId:%d, recv unknown timer-type:%d", ths->vgId, pMsg->timeoutType);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -138,27 +138,27 @@ char *voteGranted2Str(SVotesGranted *pVotesGranted) {
|
||||||
// for debug -------------------
|
// for debug -------------------
|
||||||
void voteGrantedPrint(SVotesGranted *pObj) {
|
void voteGrantedPrint(SVotesGranted *pObj) {
|
||||||
char *serialized = voteGranted2Str(pObj);
|
char *serialized = voteGranted2Str(pObj);
|
||||||
printf("voteGrantedPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("voteGrantedPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void voteGrantedPrint2(char *s, SVotesGranted *pObj) {
|
void voteGrantedPrint2(char *s, SVotesGranted *pObj) {
|
||||||
char *serialized = voteGranted2Str(pObj);
|
char *serialized = voteGranted2Str(pObj);
|
||||||
printf("voteGrantedPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("voteGrantedPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void voteGrantedLog(SVotesGranted *pObj) {
|
void voteGrantedLog(SVotesGranted *pObj) {
|
||||||
char *serialized = voteGranted2Str(pObj);
|
char *serialized = voteGranted2Str(pObj);
|
||||||
sTrace("voteGrantedLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("voteGrantedLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void voteGrantedLog2(char *s, SVotesGranted *pObj) {
|
void voteGrantedLog2(char *s, SVotesGranted *pObj) {
|
||||||
char *serialized = voteGranted2Str(pObj);
|
char *serialized = voteGranted2Str(pObj);
|
||||||
sTrace("voteGrantedLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("voteGrantedLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,26 +267,26 @@ char *votesRespond2Str(SVotesRespond *pVotesRespond) {
|
||||||
// for debug -------------------
|
// for debug -------------------
|
||||||
void votesRespondPrint(SVotesRespond *pObj) {
|
void votesRespondPrint(SVotesRespond *pObj) {
|
||||||
char *serialized = votesRespond2Str(pObj);
|
char *serialized = votesRespond2Str(pObj);
|
||||||
printf("votesRespondPrint | len:%lu | %s \n", strlen(serialized), serialized);
|
printf("votesRespondPrint | len:%d | %s \n", (int32_t)strlen(serialized), serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void votesRespondPrint2(char *s, SVotesRespond *pObj) {
|
void votesRespondPrint2(char *s, SVotesRespond *pObj) {
|
||||||
char *serialized = votesRespond2Str(pObj);
|
char *serialized = votesRespond2Str(pObj);
|
||||||
printf("votesRespondPrint2 | len:%lu | %s | %s \n", strlen(serialized), s, serialized);
|
printf("votesRespondPrint2 | len:%d | %s | %s \n", (int32_t)strlen(serialized), s, serialized);
|
||||||
fflush(NULL);
|
fflush(NULL);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void votesRespondLog(SVotesRespond *pObj) {
|
void votesRespondLog(SVotesRespond *pObj) {
|
||||||
char *serialized = votesRespond2Str(pObj);
|
char *serialized = votesRespond2Str(pObj);
|
||||||
sTrace("votesRespondLog | len:%lu | %s", strlen(serialized), serialized);
|
sTrace("votesRespondLog | len:%d | %s", (int32_t)strlen(serialized), serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
||||||
void votesRespondLog2(char *s, SVotesRespond *pObj) {
|
void votesRespondLog2(char *s, SVotesRespond *pObj) {
|
||||||
char *serialized = votesRespond2Str(pObj);
|
char *serialized = votesRespond2Str(pObj);
|
||||||
sTrace("votesRespondLog2 | len:%lu | %s | %s", strlen(serialized), s, serialized);
|
sTrace("votesRespondLog2 | len:%d | %s | %s", (int32_t)strlen(serialized), s, serialized);
|
||||||
taosMemoryFree(serialized);
|
taosMemoryFree(serialized);
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,8 +237,8 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
|
||||||
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||||
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||||
|
|
||||||
gSyncIO->FpOnSyncSnapshotSend = pSyncNode->FpOnSnapshotSend;
|
gSyncIO->FpOnSyncSnapshot = pSyncNode->FpOnSnapshot;
|
||||||
gSyncIO->FpOnSyncSnapshotRsp = pSyncNode->FpOnSnapshotRsp;
|
gSyncIO->FpOnSyncSnapshotReply = pSyncNode->FpOnSnapshotReply;
|
||||||
|
|
||||||
gSyncIO->pSyncNode = pSyncNode;
|
gSyncIO->pSyncNode = pSyncNode;
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
|
|
|
@ -181,8 +181,11 @@ int main(int argc, char **argv) {
|
||||||
SSyncNode *pSyncNode = syncNodeInit();
|
SSyncNode *pSyncNode = syncNodeInit();
|
||||||
assert(pSyncNode != NULL);
|
assert(pSyncNode != NULL);
|
||||||
SSyncRaftEntry *pEntry = pMsg4;
|
SSyncRaftEntry *pEntry = pMsg4;
|
||||||
pSyncNode->pLogStore->appendEntry(pSyncNode->pLogStore, pEntry);
|
pSyncNode->pLogStore->syncLogAppendEntry(pSyncNode->pLogStore, pEntry);
|
||||||
SSyncRaftEntry *pEntry2 = pSyncNode->pLogStore->getEntry(pSyncNode->pLogStore, pEntry->index);
|
|
||||||
|
int32_t code = pSyncNode->pLogStore->syncLogGetEntry(pSyncNode->pLogStore, pEntry->index, &pEntry);
|
||||||
|
ASSERT(code == 0);
|
||||||
|
|
||||||
syncEntryLog2((char *)"==pEntry2==", pEntry2);
|
syncEntryLog2((char *)"==pEntry2==", pEntry2);
|
||||||
|
|
||||||
// step5
|
// step5
|
||||||
|
|
|
@ -36,7 +36,7 @@ void test1() {
|
||||||
void test2() {
|
void test2() {
|
||||||
SyncHeartbeatReply *pMsg = createMsg();
|
SyncHeartbeatReply *pMsg = createMsg();
|
||||||
uint32_t len = pMsg->bytes;
|
uint32_t len = pMsg->bytes;
|
||||||
char *serialized = (char *)taosMemoryMalloc(len);
|
char * serialized = (char *)taosMemoryMalloc(len);
|
||||||
syncHeartbeatReplySerialize(pMsg, serialized, len);
|
syncHeartbeatReplySerialize(pMsg, serialized, len);
|
||||||
SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyBuild(1000);
|
SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyBuild(1000);
|
||||||
syncHeartbeatReplyDeserialize(serialized, len, pMsg2);
|
syncHeartbeatReplyDeserialize(serialized, len, pMsg2);
|
||||||
|
@ -50,7 +50,7 @@ void test2() {
|
||||||
void test3() {
|
void test3() {
|
||||||
SyncHeartbeatReply *pMsg = createMsg();
|
SyncHeartbeatReply *pMsg = createMsg();
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
char *serialized = syncHeartbeatReplySerialize2(pMsg, &len);
|
char * serialized = syncHeartbeatReplySerialize2(pMsg, &len);
|
||||||
SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyDeserialize2(serialized, len);
|
SyncHeartbeatReply *pMsg2 = syncHeartbeatReplyDeserialize2(serialized, len);
|
||||||
syncHeartbeatReplyLog2((char *)"test3: syncHeartbeatReplySerialize3 -> syncHeartbeatReplyDeserialize2 ", pMsg2);
|
syncHeartbeatReplyLog2((char *)"test3: syncHeartbeatReplySerialize3 -> syncHeartbeatReplyDeserialize2 ", pMsg2);
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ void test1() {
|
||||||
void test2() {
|
void test2() {
|
||||||
SyncHeartbeat *pMsg = createMsg();
|
SyncHeartbeat *pMsg = createMsg();
|
||||||
uint32_t len = pMsg->bytes;
|
uint32_t len = pMsg->bytes;
|
||||||
char *serialized = (char *)taosMemoryMalloc(len);
|
char * serialized = (char *)taosMemoryMalloc(len);
|
||||||
syncHeartbeatSerialize(pMsg, serialized, len);
|
syncHeartbeatSerialize(pMsg, serialized, len);
|
||||||
SyncHeartbeat *pMsg2 = syncHeartbeatBuild(789);
|
SyncHeartbeat *pMsg2 = syncHeartbeatBuild(789);
|
||||||
syncHeartbeatDeserialize(serialized, len, pMsg2);
|
syncHeartbeatDeserialize(serialized, len, pMsg2);
|
||||||
|
@ -49,7 +49,7 @@ void test2() {
|
||||||
void test3() {
|
void test3() {
|
||||||
SyncHeartbeat *pMsg = createMsg();
|
SyncHeartbeat *pMsg = createMsg();
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
char *serialized = syncHeartbeatSerialize2(pMsg, &len);
|
char * serialized = syncHeartbeatSerialize2(pMsg, &len);
|
||||||
SyncHeartbeat *pMsg2 = syncHeartbeatDeserialize2(serialized, len);
|
SyncHeartbeat *pMsg2 = syncHeartbeatDeserialize2(serialized, len);
|
||||||
syncHeartbeatLog2((char *)"test3: syncHeartbeatSerialize2 -> syncHeartbeatDeserialize2 ", pMsg2);
|
syncHeartbeatLog2((char *)"test3: syncHeartbeatSerialize2 -> syncHeartbeatDeserialize2 ", pMsg2);
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ void cleanup() {
|
||||||
void logStoreTest() {
|
void logStoreTest() {
|
||||||
pLogStore = logStoreCreate(pSyncNode);
|
pLogStore = logStoreCreate(pSyncNode);
|
||||||
assert(pLogStore);
|
assert(pLogStore);
|
||||||
assert(pLogStore->getLastIndex(pLogStore) == SYNC_INDEX_INVALID);
|
assert(pLogStore->syncLogLastIndex(pLogStore) == SYNC_INDEX_INVALID);
|
||||||
|
|
||||||
logStoreLog2((char*)"logStoreTest", pLogStore);
|
logStoreLog2((char*)"logStoreTest", pLogStore);
|
||||||
|
|
||||||
|
@ -65,22 +65,20 @@ void logStoreTest() {
|
||||||
pEntry->seqNum = 3;
|
pEntry->seqNum = 3;
|
||||||
pEntry->isWeak = true;
|
pEntry->isWeak = true;
|
||||||
pEntry->term = 100 + i;
|
pEntry->term = 100 + i;
|
||||||
pEntry->index = pLogStore->getLastIndex(pLogStore) + 1;
|
pEntry->index = pLogStore->syncLogLastIndex(pLogStore) + 1;
|
||||||
snprintf(pEntry->data, dataLen, "value%d", i);
|
snprintf(pEntry->data, dataLen, "value%d", i);
|
||||||
|
|
||||||
syncEntryLog2((char*)"==write entry== :", pEntry);
|
syncEntryLog2((char*)"==write entry== :", pEntry);
|
||||||
pLogStore->appendEntry(pLogStore, pEntry);
|
pLogStore->syncLogAppendEntry(pLogStore, pEntry);
|
||||||
syncEntryDestory(pEntry);
|
syncEntryDestory(pEntry);
|
||||||
|
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
assert(pLogStore->getLastIndex(pLogStore) == SYNC_INDEX_BEGIN);
|
assert(pLogStore->syncLogLastIndex(pLogStore) == SYNC_INDEX_BEGIN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
logStoreLog2((char*)"after appendEntry", pLogStore);
|
logStoreLog2((char*)"after appendEntry", pLogStore);
|
||||||
|
pLogStore->syncLogTruncate(pLogStore, 3);
|
||||||
pLogStore->truncate(pLogStore, 3);
|
|
||||||
logStoreLog2((char*)"after truncate 3", pLogStore);
|
logStoreLog2((char*)"after truncate 3", pLogStore);
|
||||||
|
|
||||||
logStoreDestory(pLogStore);
|
logStoreDestory(pLogStore);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -266,14 +266,12 @@ int64_t createSyncNode(int32_t replicaNum, int32_t myIndex, int32_t vgId, SWal*
|
||||||
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
gSyncIO->FpOnSyncPingReply = pSyncNode->FpOnPingReply;
|
||||||
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
gSyncIO->FpOnSyncTimeout = pSyncNode->FpOnTimeout;
|
||||||
gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest;
|
gSyncIO->FpOnSyncClientRequest = pSyncNode->FpOnClientRequest;
|
||||||
|
|
||||||
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
gSyncIO->FpOnSyncRequestVote = pSyncNode->FpOnRequestVote;
|
||||||
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
gSyncIO->FpOnSyncRequestVoteReply = pSyncNode->FpOnRequestVoteReply;
|
||||||
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
gSyncIO->FpOnSyncAppendEntries = pSyncNode->FpOnAppendEntries;
|
||||||
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
gSyncIO->FpOnSyncAppendEntriesReply = pSyncNode->FpOnAppendEntriesReply;
|
||||||
|
gSyncIO->FpOnSyncSnapshot = pSyncNode->FpOnSnapshot;
|
||||||
gSyncIO->FpOnSyncSnapshotSend = pSyncNode->FpOnSnapshotSend;
|
gSyncIO->FpOnSyncSnapshotReply = pSyncNode->FpOnSnapshotReply;
|
||||||
gSyncIO->FpOnSyncSnapshotRsp = pSyncNode->FpOnSnapshotRsp;
|
|
||||||
|
|
||||||
gSyncIO->pSyncNode = pSyncNode;
|
gSyncIO->pSyncNode = pSyncNode;
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
|
|
|
@ -69,6 +69,7 @@ void* rpcOpen(const SRpcInit* pInit) {
|
||||||
pRpc->idleTime = pInit->idleTime;
|
pRpc->idleTime = pInit->idleTime;
|
||||||
pRpc->tcphandle =
|
pRpc->tcphandle =
|
||||||
(*taosInitHandle[pRpc->connType])(ip, pInit->localPort, pRpc->label, pRpc->numOfThreads, NULL, pRpc);
|
(*taosInitHandle[pRpc->connType])(ip, pInit->localPort, pRpc->label, pRpc->numOfThreads, NULL, pRpc);
|
||||||
|
|
||||||
if (pRpc->tcphandle == NULL) {
|
if (pRpc->tcphandle == NULL) {
|
||||||
taosMemoryFree(pRpc);
|
taosMemoryFree(pRpc);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -439,12 +439,14 @@ void cliHandleExceptImpl(SCliConn* pConn, int32_t code) {
|
||||||
tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.info.ahandle,
|
tDebug("%s conn %p construct ahandle %p by %s", CONN_GET_INST_LABEL(pConn), pConn, transMsg.info.ahandle,
|
||||||
TMSG_INFO(transMsg.msgType));
|
TMSG_INFO(transMsg.msgType));
|
||||||
if (transMsg.info.ahandle == NULL) {
|
if (transMsg.info.ahandle == NULL) {
|
||||||
transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, (int32_t*)&(transMsg.msgType));
|
int32_t msgType = 0;
|
||||||
|
transMsg.info.ahandle = transCtxDumpBrokenlinkVal(&pConn->ctx, &msgType);
|
||||||
|
transMsg.msgType = msgType;
|
||||||
tDebug("%s conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn,
|
tDebug("%s conn %p construct ahandle %p due to brokenlink", CONN_GET_INST_LABEL(pConn), pConn,
|
||||||
transMsg.info.ahandle);
|
transMsg.info.ahandle);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
transMsg.info.ahandle = (pMsg->type != Release && pCtx) ? pCtx->ahandle : NULL;
|
transMsg.info.ahandle = (pMsg != NULL && pMsg->type != Release && pCtx) ? pCtx->ahandle : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCtx == NULL || pCtx->pSem == NULL) {
|
if (pCtx == NULL || pCtx->pSem == NULL) {
|
||||||
|
@ -1078,9 +1080,6 @@ static void cliPrepareCb(uv_prepare_t* handle) {
|
||||||
QUEUE_REMOVE(h);
|
QUEUE_REMOVE(h);
|
||||||
|
|
||||||
SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q);
|
SCliMsg* pMsg = QUEUE_DATA(h, SCliMsg, q);
|
||||||
if (pMsg == NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
(*cliAsyncHandle[pMsg->type])(pMsg, thrd);
|
(*cliAsyncHandle[pMsg->type])(pMsg, thrd);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
|
@ -388,8 +388,15 @@ char *taosDirEntryBaseName(char *name) {
|
||||||
_splitpath(name, NULL, NULL, Filename1, Ext1);
|
_splitpath(name, NULL, NULL, Filename1, Ext1);
|
||||||
return name + (strlen(name) - strlen(Filename1) - strlen(Ext1));
|
return name + (strlen(name) - strlen(Filename1) - strlen(Ext1));
|
||||||
#else
|
#else
|
||||||
char *pPoint = strchr(name, '.');
|
if (name == NULL || (name[0] == '/' && name[1] == '\0')) return name;
|
||||||
if (pPoint != NULL) pPoint = 0;
|
char *pPoint = strrchr(name, '/');
|
||||||
|
if (pPoint != NULL) {
|
||||||
|
if (*(pPoint + 1) == '\0') {
|
||||||
|
*pPoint = '\0';
|
||||||
|
return taosDirEntryBaseName(name);
|
||||||
|
}
|
||||||
|
return pPoint + 1;
|
||||||
|
}
|
||||||
return name;
|
return name;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,6 +73,7 @@ typedef struct TdEpoll {
|
||||||
EpollFd fd;
|
EpollFd fd;
|
||||||
} * TdEpollPtr, TdEpoll;
|
} * TdEpollPtr, TdEpoll;
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t taosSendto(TdSocketPtr pSocket, void *buf, int len, unsigned int flags, const struct sockaddr *dest_addr,
|
int32_t taosSendto(TdSocketPtr pSocket, void *buf, int len, unsigned int flags, const struct sockaddr *dest_addr,
|
||||||
int addrlen) {
|
int addrlen) {
|
||||||
if (pSocket == NULL || pSocket->fd < 0) {
|
if (pSocket == NULL || pSocket->fd < 0) {
|
||||||
|
@ -84,6 +85,7 @@ int32_t taosSendto(TdSocketPtr pSocket, void *buf, int len, unsigned int flags,
|
||||||
return sendto(pSocket->fd, buf, len, flags, dest_addr, addrlen);
|
return sendto(pSocket->fd, buf, len, flags, dest_addr, addrlen);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosWriteSocket(TdSocketPtr pSocket, void *buf, int len) {
|
int32_t taosWriteSocket(TdSocketPtr pSocket, void *buf, int len) {
|
||||||
if (pSocket == NULL || pSocket->fd < 0) {
|
if (pSocket == NULL || pSocket->fd < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -114,6 +116,8 @@ int32_t taosReadFromSocket(TdSocketPtr pSocket, void *buf, int32_t len, int32_t
|
||||||
}
|
}
|
||||||
return recvfrom(pSocket->fd, buf, len, flags, destAddr, addrLen);
|
return recvfrom(pSocket->fd, buf, len, flags, destAddr, addrLen);
|
||||||
}
|
}
|
||||||
|
#endif // endif 0
|
||||||
|
|
||||||
int32_t taosCloseSocketNoCheck1(SocketFd fd) {
|
int32_t taosCloseSocketNoCheck1(SocketFd fd) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
return closesocket(fd);
|
return closesocket(fd);
|
||||||
|
@ -121,6 +125,7 @@ int32_t taosCloseSocketNoCheck1(SocketFd fd) {
|
||||||
return close(fd);
|
return close(fd);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t taosCloseSocket(TdSocketPtr *ppSocket) {
|
int32_t taosCloseSocket(TdSocketPtr *ppSocket) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
if (ppSocket == NULL || *ppSocket == NULL || (*ppSocket)->fd < 0) {
|
if (ppSocket == NULL || *ppSocket == NULL || (*ppSocket)->fd < 0) {
|
||||||
|
@ -131,6 +136,8 @@ int32_t taosCloseSocket(TdSocketPtr *ppSocket) {
|
||||||
taosMemoryFree(*ppSocket);
|
taosMemoryFree(*ppSocket);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer) {
|
int32_t taosCloseSocketServer(TdSocketServerPtr *ppSocketServer) {
|
||||||
int32_t code;
|
int32_t code;
|
||||||
if (ppSocketServer == NULL || *ppSocketServer == NULL || (*ppSocketServer)->fd < 0) {
|
if (ppSocketServer == NULL || *ppSocketServer == NULL || (*ppSocketServer)->fd < 0) {
|
||||||
|
@ -216,20 +223,6 @@ int32_t taosShutDownSocketServerRDWR(TdSocketServerPtr pSocketServer) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void taosWinSocketInit() {
|
|
||||||
#ifdef WINDOWS
|
|
||||||
static char flag = 0;
|
|
||||||
if (flag == 0) {
|
|
||||||
WORD wVersionRequested;
|
|
||||||
WSADATA wsaData;
|
|
||||||
wVersionRequested = MAKEWORD(1, 1);
|
|
||||||
if (WSAStartup(wVersionRequested, &wsaData) == 0) {
|
|
||||||
flag = 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on) {
|
int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on) {
|
||||||
if (pSocket == NULL || pSocket->fd < 0) {
|
if (pSocket == NULL || pSocket->fd < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -262,6 +255,8 @@ int32_t taosSetNonblocking(TdSocketPtr pSocket, int32_t on) {
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif // endif 0
|
||||||
|
|
||||||
int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t optlen) {
|
int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t optlen) {
|
||||||
if (pSocket == NULL || pSocket->fd < 0) {
|
if (pSocket == NULL || pSocket->fd < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -296,6 +291,8 @@ int32_t taosSetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void
|
||||||
return setsockopt(pSocket->fd, level, optname, optval, (int)optlen);
|
return setsockopt(pSocket->fd, level, optname, optval, (int)optlen);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t *optlen) {
|
int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void *optval, int32_t *optlen) {
|
||||||
if (pSocket == NULL || pSocket->fd < 0) {
|
if (pSocket == NULL || pSocket->fd < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -307,6 +304,9 @@ int32_t taosGetSockOpt(TdSocketPtr pSocket, int32_t level, int32_t optname, void
|
||||||
return getsockopt(pSocket->fd, level, optname, optval, (int *)optlen);
|
return getsockopt(pSocket->fd, level, optname, optval, (int *)optlen);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
uint32_t taosInetAddr(const char *ipAddr) {
|
uint32_t taosInetAddr(const char *ipAddr) {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
uint32_t value;
|
uint32_t value;
|
||||||
|
@ -330,6 +330,7 @@ const char *taosInetNtoa(struct in_addr ipInt, char *dstStr, int32_t len) {
|
||||||
|
|
||||||
#define TCP_CONN_TIMEOUT 3000 // conn timeout
|
#define TCP_CONN_TIMEOUT 3000 // conn timeout
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t taosWriteMsg(TdSocketPtr pSocket, void *buf, int32_t nbytes) {
|
int32_t taosWriteMsg(TdSocketPtr pSocket, void *buf, int32_t nbytes) {
|
||||||
if (pSocket == NULL || pSocket->fd < 0) {
|
if (pSocket == NULL || pSocket->fd < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -726,6 +727,7 @@ int taosValidIp(uint32_t ip) {
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif // endif 0
|
||||||
|
|
||||||
bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
|
bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
|
||||||
struct sockaddr_in serverAdd;
|
struct sockaddr_in serverAdd;
|
||||||
|
@ -774,6 +776,8 @@ bool taosValidIpAndPort(uint32_t ip, uint16_t port) {
|
||||||
return true;
|
return true;
|
||||||
// return 0 == taosValidIp(ip) ? true : false;
|
// return 0 == taosValidIp(ip) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) {
|
TdSocketServerPtr taosOpenTcpServerSocket(uint32_t ip, uint16_t port) {
|
||||||
struct sockaddr_in serverAdd;
|
struct sockaddr_in serverAdd;
|
||||||
SocketFd fd;
|
SocketFd fd;
|
||||||
|
@ -888,6 +892,36 @@ int64_t taosCopyFds(TdSocketPtr pSrcSocket, TdSocketPtr pDestSocket, int64_t len
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Function converting an IP address string to an uint32_t.
|
||||||
|
uint32_t ip2uint(const char *const ip_addr) {
|
||||||
|
char ip_addr_cpy[20];
|
||||||
|
char ip[5];
|
||||||
|
|
||||||
|
tstrncpy(ip_addr_cpy, ip_addr, sizeof(ip_addr_cpy));
|
||||||
|
|
||||||
|
char *s_start, *s_end;
|
||||||
|
s_start = ip_addr_cpy;
|
||||||
|
s_end = ip_addr_cpy;
|
||||||
|
|
||||||
|
int32_t k;
|
||||||
|
|
||||||
|
for (k = 0; *s_start != '\0'; s_start = s_end) {
|
||||||
|
for (s_end = s_start; *s_end != '.' && *s_end != '\0'; s_end++) {
|
||||||
|
}
|
||||||
|
if (*s_end == '.') {
|
||||||
|
*s_end = '\0';
|
||||||
|
s_end++;
|
||||||
|
}
|
||||||
|
ip[k++] = (char)atoi(s_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
ip[k] = '\0';
|
||||||
|
|
||||||
|
return *((uint32_t *)ip);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // endif 0
|
||||||
|
|
||||||
void taosBlockSIGPIPE() {
|
void taosBlockSIGPIPE() {
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
// assert(0);
|
// assert(0);
|
||||||
|
@ -991,34 +1025,6 @@ int32_t taosGetFqdn(char *fqdn) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function converting an IP address string to an uint32_t.
|
|
||||||
uint32_t ip2uint(const char *const ip_addr) {
|
|
||||||
char ip_addr_cpy[20];
|
|
||||||
char ip[5];
|
|
||||||
|
|
||||||
tstrncpy(ip_addr_cpy, ip_addr, sizeof(ip_addr_cpy));
|
|
||||||
|
|
||||||
char *s_start, *s_end;
|
|
||||||
s_start = ip_addr_cpy;
|
|
||||||
s_end = ip_addr_cpy;
|
|
||||||
|
|
||||||
int32_t k;
|
|
||||||
|
|
||||||
for (k = 0; *s_start != '\0'; s_start = s_end) {
|
|
||||||
for (s_end = s_start; *s_end != '.' && *s_end != '\0'; s_end++) {
|
|
||||||
}
|
|
||||||
if (*s_end == '.') {
|
|
||||||
*s_end = '\0';
|
|
||||||
s_end++;
|
|
||||||
}
|
|
||||||
ip[k++] = (char)atoi(s_start);
|
|
||||||
}
|
|
||||||
|
|
||||||
ip[k] = '\0';
|
|
||||||
|
|
||||||
return *((uint32_t *)ip);
|
|
||||||
}
|
|
||||||
|
|
||||||
void tinet_ntoa(char *ipstr, uint32_t ip) {
|
void tinet_ntoa(char *ipstr, uint32_t ip) {
|
||||||
sprintf(ipstr, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24);
|
sprintf(ipstr, "%d.%d.%d.%d", ip & 0xFF, (ip >> 8) & 0xFF, (ip >> 16) & 0xFF, ip >> 24);
|
||||||
}
|
}
|
||||||
|
@ -1039,12 +1045,14 @@ void taosSetMaskSIGPIPE() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if 0
|
||||||
int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen) {
|
int32_t taosGetSocketName(TdSocketPtr pSocket, struct sockaddr *destAddr, int *addrLen) {
|
||||||
if (pSocket == NULL || pSocket->fd < 0) {
|
if (pSocket == NULL || pSocket->fd < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return getsockname(pSocket->fd, destAddr, addrLen);
|
return getsockname(pSocket->fd, destAddr, addrLen);
|
||||||
}
|
}
|
||||||
|
#endif // endif 0
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set TCP connection timeout per-socket level.
|
* Set TCP connection timeout per-socket level.
|
||||||
|
@ -1080,3 +1088,18 @@ int32_t taosCreateSocketWithTimeout(uint32_t timeout) {
|
||||||
|
|
||||||
return (int)fd;
|
return (int)fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void taosWinSocketInit() {
|
||||||
|
#ifdef WINDOWS
|
||||||
|
static char flag = 0;
|
||||||
|
if (flag == 0) {
|
||||||
|
WORD wVersionRequested;
|
||||||
|
WSADATA wsaData;
|
||||||
|
wVersionRequested = MAKEWORD(1, 1);
|
||||||
|
if (WSAStartup(wVersionRequested, &wsaData) == 0) {
|
||||||
|
flag = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
|
@ -141,14 +141,10 @@ int32_t taosQueueItemSize(STaosQueue *queue) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int64_t taosQueueMemorySize(STaosQueue *queue) {
|
int64_t taosQueueMemorySize(STaosQueue *queue) {
|
||||||
#if 1
|
|
||||||
return queue->memOfItems;
|
|
||||||
#else
|
|
||||||
taosThreadMutexLock(&queue->mutex);
|
taosThreadMutexLock(&queue->mutex);
|
||||||
int64_t memOfItems = queue->memOfItems;
|
int64_t memOfItems = queue->memOfItems;
|
||||||
taosThreadMutexUnlock(&queue->mutex);
|
taosThreadMutexUnlock(&queue->mutex);
|
||||||
return memOfItems;
|
return memOfItems;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void *taosAllocateQitem(int32_t size, EQItype itype) {
|
void *taosAllocateQitem(int32_t size, EQItype itype) {
|
||||||
|
|
|
@ -131,7 +131,7 @@ class TDDnode:
|
||||||
"qDebugFlag": "143",
|
"qDebugFlag": "143",
|
||||||
"rpcDebugFlag": "143",
|
"rpcDebugFlag": "143",
|
||||||
"tmrDebugFlag": "131",
|
"tmrDebugFlag": "131",
|
||||||
"uDebugFlag": "131",
|
"uDebugFlag": "143",
|
||||||
"sDebugFlag": "143",
|
"sDebugFlag": "143",
|
||||||
"wDebugFlag": "143",
|
"wDebugFlag": "143",
|
||||||
"numOfLogLines": "100000000",
|
"numOfLogLines": "100000000",
|
||||||
|
|
|
@ -9,8 +9,8 @@
|
||||||
|
|
||||||
# ---- db ----
|
# ---- db ----
|
||||||
./test.sh -f tsim/db/alter_option.sim
|
./test.sh -f tsim/db/alter_option.sim
|
||||||
# unsupport ./test.sh -f tsim/db/alter_replica_13.sim
|
./test.sh -f tsim/db/alter_replica_13.sim
|
||||||
# unsupport ./test.sh -f tsim/db/alter_replica_31.sim
|
./test.sh -f tsim/db/alter_replica_31.sim
|
||||||
./test.sh -f tsim/db/basic1.sim
|
./test.sh -f tsim/db/basic1.sim
|
||||||
./test.sh -f tsim/db/basic2.sim
|
./test.sh -f tsim/db/basic2.sim
|
||||||
./test.sh -f tsim/db/basic3.sim
|
./test.sh -f tsim/db/basic3.sim
|
||||||
|
@ -298,6 +298,7 @@
|
||||||
./test.sh -f tsim/stable/tag_rename.sim
|
./test.sh -f tsim/stable/tag_rename.sim
|
||||||
./test.sh -f tsim/stable/values.sim
|
./test.sh -f tsim/stable/values.sim
|
||||||
./test.sh -f tsim/stable/vnode3.sim
|
./test.sh -f tsim/stable/vnode3.sim
|
||||||
|
./test.sh -f tsim/stable/metrics_idx.sim
|
||||||
|
|
||||||
# --- sma
|
# --- sma
|
||||||
./test.sh -f tsim/sma/drop_sma.sim
|
./test.sh -f tsim/sma/drop_sma.sim
|
||||||
|
|
|
@ -127,8 +127,27 @@ if $data[0][8] != follower then
|
||||||
goto step4
|
goto step4
|
||||||
endi
|
endi
|
||||||
|
|
||||||
print ============= step5: stop dnode 2
|
print ============= step5: result
|
||||||
|
$i = 0
|
||||||
|
while $i < 10
|
||||||
|
$i = $i + 1
|
||||||
|
|
||||||
|
sleep 1000
|
||||||
|
sql show db.vgroups
|
||||||
|
print ===> loop: $i | v0: $data03 $data04 | v1: $data05 $data06 | v2: $data07 $data08
|
||||||
|
if $data[0][4] != leader then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data[0][6] != follower then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data[0][8] != follower then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
endw
|
||||||
|
|
||||||
|
|
||||||
|
print ============= step5: stop dnode 2
|
||||||
sql select * from db.stb
|
sql select * from db.stb
|
||||||
if $rows != 1 then
|
if $rows != 1 then
|
||||||
return -1
|
return -1
|
||||||
|
|
|
@ -183,7 +183,7 @@ $x = 0
|
||||||
step71:
|
step71:
|
||||||
$x = $x + 1
|
$x = $x + 1
|
||||||
sleep 1000
|
sleep 1000
|
||||||
if $x == 10 then
|
if $x == 50 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
sql select * from information_schema.ins_dnodes
|
sql select * from information_schema.ins_dnodes
|
||||||
|
|
|
@ -87,17 +87,17 @@ if $rows != 2 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
print $tbPrefix
|
#print $tbPrefix
|
||||||
$tb = $tbPrefix . 0
|
#$tb = $tbPrefix . 0
|
||||||
if $data00 != wh_tb1 then
|
#if $data00 != wh_tb1 then
|
||||||
print expect wh_tb1, actual:$data00
|
# print expect wh_tb1, actual:$data00
|
||||||
return -1
|
# return -1
|
||||||
endi
|
#endi
|
||||||
$tb = $tbPrefix . 1
|
#$tb = $tbPrefix . 1
|
||||||
if $data10 != wh_tb0 then
|
#if $data10 != wh_tb0 then
|
||||||
print expect wh_tb0, actual:$data00
|
# print expect wh_tb0, actual:$data00
|
||||||
return -1
|
# return -1
|
||||||
endi
|
#endi
|
||||||
|
|
||||||
## select specified columns
|
## select specified columns
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
sql connect
|
||||||
|
|
||||||
|
$dbPrefix = m_me_db_idx
|
||||||
|
$tbPrefix = m_me_tb_idx
|
||||||
|
$mtPrefix = m_me_mt_idx
|
||||||
|
|
||||||
|
print =============== step1
|
||||||
|
$i = 0
|
||||||
|
$db = $dbPrefix
|
||||||
|
$mt = $mtPrefix
|
||||||
|
|
||||||
|
sql drop database if exists $db
|
||||||
|
sql create database $db
|
||||||
|
|
||||||
|
sql use $db
|
||||||
|
|
||||||
|
sql create table $mt (ts timestamp, speed int) TAGS(sp int)
|
||||||
|
|
||||||
|
$tbNum = 10000
|
||||||
|
|
||||||
|
while $i < $tbNum
|
||||||
|
$tb = $tbPrefix . $i
|
||||||
|
sql insert into $tb using $mt tags( $i ) values(now, $i )
|
||||||
|
$i = $i + 1
|
||||||
|
endw
|
||||||
|
|
||||||
|
sql use information_schema
|
||||||
|
sql select count(*) from ins_tables where db_name = "m_me_db_idx" and create_time > now() - 10m
|
||||||
|
if $data[0][0] != $tbNum then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql select count(*) from ins_tables where db_name = "m_me_db_idx" and create_time < now();
|
||||||
|
if $data[0][0] != $tbNum then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sleep 1000
|
||||||
|
|
||||||
|
|
||||||
|
sql use $db
|
||||||
|
$doubletbNum = 20000
|
||||||
|
|
||||||
|
while $i < $doubletbNum
|
||||||
|
$tb = $tbPrefix . $i
|
||||||
|
sql insert into $tb using $mt tags( $i ) values(now, $i )
|
||||||
|
$i = $i + 1
|
||||||
|
endw
|
||||||
|
|
||||||
|
|
||||||
|
sql use information_schema
|
||||||
|
|
||||||
|
sql select count(*) from ins_tables where db_name = "m_me_db_idx" and create_time < now();
|
||||||
|
if $data[0][0] != $doubletbNum then
|
||||||
|
print ==== $data[0][0]
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,175 @@
|
||||||
|
system sh/stop_dnodes.sh
|
||||||
|
system sh/deploy.sh -n dnode1 -i 1
|
||||||
|
system sh/deploy.sh -n dnode2 -i 2
|
||||||
|
system sh/deploy.sh -n dnode3 -i 3
|
||||||
|
system sh/deploy.sh -n dnode4 -i 4
|
||||||
|
|
||||||
|
system sh/cfg.sh -n dnode1 -c supportVnodes -v 0
|
||||||
|
|
||||||
|
system sh/exec.sh -n dnode1 -s start
|
||||||
|
system sh/exec.sh -n dnode2 -s start
|
||||||
|
system sh/exec.sh -n dnode3 -s start
|
||||||
|
system sh/exec.sh -n dnode4 -s start
|
||||||
|
|
||||||
|
sql connect
|
||||||
|
sql create dnode $hostname port 7200
|
||||||
|
sql create dnode $hostname port 7300
|
||||||
|
sql create dnode $hostname port 7400
|
||||||
|
|
||||||
|
$x = 0
|
||||||
|
step1:
|
||||||
|
$x = $x + 1
|
||||||
|
sleep 1000
|
||||||
|
if $x == 10 then
|
||||||
|
print ====> dnode not ready!
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql select * from information_schema.ins_dnodes
|
||||||
|
print ===> $data00 $data01 $data02 $data03 $data04 $data05
|
||||||
|
print ===> $data10 $data11 $data12 $data13 $data14 $data15
|
||||||
|
print ===> $data20 $data21 $data22 $data23 $data24 $data25
|
||||||
|
print ===> $data30 $data31 $data32 $data33 $data34 $data35
|
||||||
|
if $rows != 4 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data(1)[4] != ready then
|
||||||
|
goto step1
|
||||||
|
endi
|
||||||
|
if $data(2)[4] != ready then
|
||||||
|
goto step1
|
||||||
|
endi
|
||||||
|
if $data(3)[4] != ready then
|
||||||
|
goto step1
|
||||||
|
endi
|
||||||
|
if $data(4)[4] != ready then
|
||||||
|
goto step1
|
||||||
|
endi
|
||||||
|
|
||||||
|
$replica = 3
|
||||||
|
$vgroups = 1
|
||||||
|
|
||||||
|
print ============= create database
|
||||||
|
sql create database db replica $replica vgroups $vgroups
|
||||||
|
|
||||||
|
$loop_cnt = 0
|
||||||
|
check_db_ready:
|
||||||
|
$loop_cnt = $loop_cnt + 1
|
||||||
|
sleep 200
|
||||||
|
if $loop_cnt == 100 then
|
||||||
|
print ====> db not ready!
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
sql select * from information_schema.ins_databases
|
||||||
|
print ===> rows: $rows
|
||||||
|
print $data[2][0] $data[2][1] $data[2][2] $data[2][3] $data[2][4] $data[2][5] $data[2][6] $data[2][7] $data[2][8] $data[2][9] $data[2][6] $data[2][11] $data[2][12] $data[2][13] $data[2][14] $data[2][15] $data[2][16] $data[2][17] $data[2][18] $data[2][19]
|
||||||
|
if $rows != 3 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
if $data[2][15] != ready then
|
||||||
|
goto check_db_ready
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql use db
|
||||||
|
|
||||||
|
$loop_cnt = 0
|
||||||
|
check_vg_ready:
|
||||||
|
$loop_cnt = $loop_cnt + 1
|
||||||
|
sleep 200
|
||||||
|
if $loop_cnt == 300 then
|
||||||
|
print ====> vgroups not ready!
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql show vgroups
|
||||||
|
print ===> rows: $rows
|
||||||
|
print $data[0][0] $data[0][1] $data[0][2] $data[0][3] $data[0][4] $data[0][5] $data[0][6] $data[0][7] $data[0][8] $data[0][9] $data[0][10] $data[0][11]
|
||||||
|
|
||||||
|
if $rows != $vgroups then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data[0][4] == leader then
|
||||||
|
if $data[0][6] == follower then
|
||||||
|
if $data[0][8] == follower then
|
||||||
|
print ---- vgroup $data[0][0] leader locate on dnode $data[0][3]
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
elif $data[0][6] == leader then
|
||||||
|
if $data[0][4] == follower then
|
||||||
|
if $data[0][8] == follower then
|
||||||
|
print ---- vgroup $data[0][0] leader locate on dnode $data[0][5]
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
elif $data[0][8] == leader then
|
||||||
|
if $data[0][4] == follower then
|
||||||
|
if $data[0][6] == follower then
|
||||||
|
print ---- vgroup $data[0][0] leader locate on dnode $data[0][7]
|
||||||
|
endi
|
||||||
|
endi
|
||||||
|
else
|
||||||
|
goto check_vg_ready
|
||||||
|
endi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
vg_ready:
|
||||||
|
print ====> create stable/child table
|
||||||
|
sql create table stb (ts timestamp, c1 int, c2 float, c3 double) tags (t1 int)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#return 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sql show stables
|
||||||
|
if $rows != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
sql create table ct1 using stb tags(1000)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
print ====> step1 insert 1000 records
|
||||||
|
$N = 1000
|
||||||
|
$count = 0
|
||||||
|
while $count < $N
|
||||||
|
$ms = 1591200000000 + $count
|
||||||
|
sql insert into ct1 values( $ms , $count , 2.1, 3.1)
|
||||||
|
$count = $count + 1
|
||||||
|
endw
|
||||||
|
|
||||||
|
print ====> step2 sleep 20s, checking data
|
||||||
|
sleep 20000
|
||||||
|
|
||||||
|
|
||||||
|
print ====> step3 sleep 30s, kill leader
|
||||||
|
sleep 30000
|
||||||
|
|
||||||
|
print ====> step4 insert 1000 records
|
||||||
|
$N = 1000
|
||||||
|
$count = 0
|
||||||
|
while $count < $N
|
||||||
|
$ms = 1591201000000 + $count
|
||||||
|
sql insert into ct1 values( $ms , $count , 2.1, 3.1)
|
||||||
|
$count = $count + 1
|
||||||
|
endw
|
||||||
|
|
||||||
|
print ====> step5 sleep 20s, checking data
|
||||||
|
sleep 20000
|
||||||
|
|
|
@ -43,7 +43,13 @@ class TDTestCase:
|
||||||
f'today(),3,3.333,333.333333,now()',
|
f'today(),3,3.333,333.333333,now()',
|
||||||
f'today()-1d,10,11.11,99.999999,now()',
|
f'today()-1d,10,11.11,99.999999,now()',
|
||||||
f'today()+1d,1,1.55,100.555555,today()']
|
f'today()+1d,1,1.55,100.555555,today()']
|
||||||
self.db_percision = ['ms','us','ns']
|
|
||||||
|
self.rest_tag = str(conn).lower().split('.')[0].replace("<taos","")
|
||||||
|
if self.rest_tag != 'rest':
|
||||||
|
self.db_percision = ['ms','us','ns']
|
||||||
|
else:
|
||||||
|
self.db_percision = ['ms','us']
|
||||||
|
|
||||||
def set_create_normaltable_sql(self, ntbname, column_dict):
|
def set_create_normaltable_sql(self, ntbname, column_dict):
|
||||||
column_sql = ''
|
column_sql = ''
|
||||||
for k, v in column_dict.items():
|
for k, v in column_dict.items():
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,76 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from util.cases import tdCases
|
||||||
|
from .nestedQuery import *
|
||||||
|
|
||||||
|
class TDTestCase(TDTestCase):
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
tdSql.prepare()
|
||||||
|
|
||||||
|
startTime = time.time()
|
||||||
|
|
||||||
|
#self.function_before_26()
|
||||||
|
|
||||||
|
# self.math_nest(['UNIQUE'])
|
||||||
|
# self.math_nest(['MODE'])
|
||||||
|
# self.math_nest(['SAMPLE'])
|
||||||
|
|
||||||
|
self.math_nest(['ABS','SQRT'])
|
||||||
|
self.math_nest(['SIN','COS','TAN','ASIN','ACOS','ATAN'])
|
||||||
|
self.math_nest(['POW','LOG'])
|
||||||
|
self.math_nest(['FLOOR','CEIL','ROUND'])
|
||||||
|
self.math_nest(['MAVG'])
|
||||||
|
self.math_nest(['HYPERLOGLOG'])
|
||||||
|
self.math_nest(['TAIL'])
|
||||||
|
self.math_nest(['CSUM'])
|
||||||
|
self.math_nest(['statecount','stateduration'])
|
||||||
|
self.math_nest(['HISTOGRAM'])
|
||||||
|
|
||||||
|
# self.str_nest(['LTRIM','RTRIM','LOWER','UPPER'])
|
||||||
|
# self.str_nest(['LENGTH','CHAR_LENGTH'])
|
||||||
|
# self.str_nest(['SUBSTR'])
|
||||||
|
# self.str_nest(['CONCAT'])
|
||||||
|
# self.str_nest(['CONCAT_WS'])
|
||||||
|
# self.time_nest(['CAST']) #放到time里起来弄
|
||||||
|
# self.time_nest(['CAST_1'])
|
||||||
|
# self.time_nest(['CAST_2'])
|
||||||
|
# self.time_nest(['CAST_3'])
|
||||||
|
# self.time_nest(['CAST_4'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# self.time_nest(['NOW','TODAY'])
|
||||||
|
# self.time_nest(['TIMEZONE'])
|
||||||
|
# self.time_nest(['TIMETRUNCATE'])
|
||||||
|
# self.time_nest(['TO_ISO8601'])
|
||||||
|
# self.time_nest(['TO_UNIXTIMESTAMP'])
|
||||||
|
# self.time_nest(['ELAPSED'])
|
||||||
|
# self.time_nest(['TIMEDIFF_1'])
|
||||||
|
# self.time_nest(['TIMEDIFF_2'])
|
||||||
|
|
||||||
|
|
||||||
|
endTime = time.time()
|
||||||
|
print("total time %ds" % (endTime - startTime))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,76 @@
|
||||||
|
###################################################################
|
||||||
|
# Copyright (c) 2016 by TAOS Technologies, Inc.
|
||||||
|
# All rights reserved.
|
||||||
|
#
|
||||||
|
# This file is proprietary and confidential to TAOS Technologies.
|
||||||
|
# No part of this file may be reproduced, stored, transmitted,
|
||||||
|
# disclosed or used in any form or by any means other than as
|
||||||
|
# expressly provided by the written permission from Jianhui Tao
|
||||||
|
#
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from util.cases import tdCases
|
||||||
|
from .nestedQuery import *
|
||||||
|
|
||||||
|
class TDTestCase(TDTestCase):
|
||||||
|
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
tdSql.prepare()
|
||||||
|
|
||||||
|
startTime = time.time()
|
||||||
|
|
||||||
|
# self.function_before_26()
|
||||||
|
|
||||||
|
# self.math_nest(['UNIQUE'])
|
||||||
|
# self.math_nest(['MODE'])
|
||||||
|
# self.math_nest(['SAMPLE'])
|
||||||
|
|
||||||
|
# self.math_nest(['ABS','SQRT'])
|
||||||
|
# self.math_nest(['SIN','COS','TAN','ASIN','ACOS','ATAN'])
|
||||||
|
# self.math_nest(['POW','LOG'])
|
||||||
|
# self.math_nest(['FLOOR','CEIL','ROUND'])
|
||||||
|
# self.math_nest(['MAVG'])
|
||||||
|
# self.math_nest(['HYPERLOGLOG'])
|
||||||
|
# self.math_nest(['TAIL'])
|
||||||
|
# self.math_nest(['CSUM'])
|
||||||
|
# self.math_nest(['statecount','stateduration'])
|
||||||
|
# self.math_nest(['HISTOGRAM'])
|
||||||
|
|
||||||
|
# self.str_nest(['LTRIM','RTRIM','LOWER','UPPER'])
|
||||||
|
# self.str_nest(['LENGTH','CHAR_LENGTH'])
|
||||||
|
# self.str_nest(['SUBSTR'])
|
||||||
|
# self.str_nest(['CONCAT'])
|
||||||
|
# self.str_nest(['CONCAT_WS'])
|
||||||
|
# self.time_nest(['CAST']) #放到time里起来弄
|
||||||
|
# self.time_nest(['CAST_1'])
|
||||||
|
# self.time_nest(['CAST_2'])
|
||||||
|
# self.time_nest(['CAST_3'])
|
||||||
|
# self.time_nest(['CAST_4'])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
self.time_nest(['NOW','TODAY'])
|
||||||
|
self.time_nest(['TIMEZONE'])
|
||||||
|
self.time_nest(['TIMETRUNCATE'])
|
||||||
|
self.time_nest(['TO_ISO8601'])
|
||||||
|
self.time_nest(['TO_UNIXTIMESTAMP'])
|
||||||
|
self.time_nest(['ELAPSED'])
|
||||||
|
#self.time_nest(['TIMEDIFF_1'])
|
||||||
|
#self.time_nest(['TIMEDIFF_2'])
|
||||||
|
|
||||||
|
|
||||||
|
endTime = time.time()
|
||||||
|
print("total time %ds" % (endTime - startTime))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
tdSql.close()
|
||||||
|
tdLog.success("%s successfully executed" % __file__)
|
||||||
|
|
||||||
|
|
||||||
|
tdCases.addWindows(__file__, TDTestCase())
|
||||||
|
tdCases.addLinux(__file__, TDTestCase())
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue