Merge pull request #18589 from taosdata/feature/3.0_mhli
refactor(sync): help to display leader**
This commit is contained in:
commit
b6f1ce2027
|
@ -211,9 +211,14 @@ typedef struct SSyncInfo {
|
||||||
int32_t (*syncEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
int32_t (*syncEqCtrlMsg)(const SMsgCb* msgcb, SRpcMsg* pMsg);
|
||||||
} SSyncInfo;
|
} SSyncInfo;
|
||||||
|
|
||||||
|
// if state == leader
|
||||||
|
// if restored, display "leader"
|
||||||
|
// if !restored && canRead, display "leader*"
|
||||||
|
// if !restored && !canRead, display "leader**"
|
||||||
typedef struct SSyncState {
|
typedef struct SSyncState {
|
||||||
ESyncState state;
|
ESyncState state;
|
||||||
bool restored;
|
bool restored;
|
||||||
|
bool canRead;
|
||||||
} SSyncState;
|
} SSyncState;
|
||||||
|
|
||||||
int32_t syncInit();
|
int32_t syncInit();
|
||||||
|
|
|
@ -244,6 +244,7 @@ int32_t syncCacheEntry(SSyncLogStore* pLogStore, SSyncRaftEntry* pEntry, LRUHa
|
||||||
bool syncNodeHeartbeatReplyTimeout(SSyncNode* pSyncNode);
|
bool syncNodeHeartbeatReplyTimeout(SSyncNode* pSyncNode);
|
||||||
bool syncNodeSnapshotSending(SSyncNode* pSyncNode);
|
bool syncNodeSnapshotSending(SSyncNode* pSyncNode);
|
||||||
bool syncNodeSnapshotRecving(SSyncNode* pSyncNode);
|
bool syncNodeSnapshotRecving(SSyncNode* pSyncNode);
|
||||||
|
bool syncNodeIsReadyForRead(SSyncNode* pSyncNode);
|
||||||
|
|
||||||
// raft state change --------------
|
// raft state change --------------
|
||||||
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term);
|
void syncNodeUpdateTerm(SSyncNode* pSyncNode, SyncTerm term);
|
||||||
|
|
|
@ -381,15 +381,13 @@ int32_t syncStepDown(int64_t rid, SyncTerm newTerm) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool syncIsReadyForRead(int64_t rid) {
|
bool syncNodeIsReadyForRead(SSyncNode* pSyncNode) {
|
||||||
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
|
||||||
if (pSyncNode == NULL) {
|
if (pSyncNode == NULL) {
|
||||||
sError("sync ready for read error");
|
sError("sync ready for read error");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER && pSyncNode->restoreFinish) {
|
if (pSyncNode->state == TAOS_SYNC_STATE_LEADER && pSyncNode->restoreFinish) {
|
||||||
syncNodeRelease(pSyncNode);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,6 +441,18 @@ bool syncIsReadyForRead(int64_t rid) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ready;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool syncIsReadyForRead(int64_t rid) {
|
||||||
|
SSyncNode* pSyncNode = syncNodeAcquire(rid);
|
||||||
|
if (pSyncNode == NULL) {
|
||||||
|
sError("sync ready for read error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ready = syncNodeIsReadyForRead(pSyncNode);
|
||||||
|
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
return ready;
|
return ready;
|
||||||
}
|
}
|
||||||
|
@ -521,6 +531,7 @@ SSyncState syncGetState(int64_t rid) {
|
||||||
if (pSyncNode != NULL) {
|
if (pSyncNode != NULL) {
|
||||||
state.state = pSyncNode->state;
|
state.state = pSyncNode->state;
|
||||||
state.restored = pSyncNode->restoreFinish;
|
state.restored = pSyncNode->restoreFinish;
|
||||||
|
state.canRead = syncNodeIsReadyForRead(pSyncNode);
|
||||||
syncNodeRelease(pSyncNode);
|
syncNodeRelease(pSyncNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue