enh: update pDb stateTs on stateChanged

This commit is contained in:
Benguang Zhao 2023-08-15 19:39:13 +08:00
parent dbdfee4c41
commit 94e0d97aa2
2 changed files with 8 additions and 6 deletions

View File

@ -496,11 +496,11 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
pVgroup->compStorage = pVload->compStorage; pVgroup->compStorage = pVload->compStorage;
pVgroup->pointsWritten = pVload->pointsWritten; pVgroup->pointsWritten = pVload->pointsWritten;
} }
bool roleChanged = false; bool stateChanged = false;
for (int32_t vg = 0; vg < pVgroup->replica; ++vg) { for (int32_t vg = 0; vg < pVgroup->replica; ++vg) {
SVnodeGid *pGid = &pVgroup->vnodeGid[vg]; SVnodeGid *pGid = &pVgroup->vnodeGid[vg];
if (pGid->dnodeId == statusReq.dnodeId) { if (pGid->dnodeId == statusReq.dnodeId) {
roleChanged = bool roleChanged =
pGid->syncState != pVload->syncState || (pVload->syncTerm != -1 && pGid->syncTerm != pVload->syncTerm); pGid->syncState != pVload->syncState || (pVload->syncTerm != -1 && pGid->syncTerm != pVload->syncTerm);
if (reboot || roleChanged || pGid->syncRestore != pVload->syncRestore || pGid->syncCanRead != pVload->syncCanRead) { if (reboot || roleChanged || pGid->syncRestore != pVload->syncRestore || pGid->syncCanRead != pVload->syncCanRead) {
mInfo( mInfo(
@ -513,6 +513,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
pGid->syncRestore = pVload->syncRestore; pGid->syncRestore = pVload->syncRestore;
pGid->syncCanRead = pVload->syncCanRead; pGid->syncCanRead = pVload->syncCanRead;
pGid->startTimeMs = (pVload->startTimeMs != 0) ? pVload->startTimeMs : statusReq.rebootTime; pGid->startTimeMs = (pVload->startTimeMs != 0) ? pVload->startTimeMs : statusReq.rebootTime;
stateChanged = true;
} }
if (roleChanged) { if (roleChanged) {
pGid->roleTimeMs = (pVload->roleTimeMs != 0) ? pVload->roleTimeMs : taosGetTimestampMs(); pGid->roleTimeMs = (pVload->roleTimeMs != 0) ? pVload->roleTimeMs : taosGetTimestampMs();
@ -520,7 +521,7 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) {
break; break;
} }
} }
if (roleChanged) { if (stateChanged) {
SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName); SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName);
if (pDb != NULL && pDb->stateTs != curMs) { if (pDb != NULL && pDb->stateTs != curMs) {
mInfo("db:%s, stateTs changed by status msg, old stateTs:%" PRId64 " new stateTs:%" PRId64, pDb->name, mInfo("db:%s, stateTs changed by status msg, old stateTs:%" PRId64 " new stateTs:%" PRId64, pDb->name,

View File

@ -185,7 +185,7 @@ static void mndSetVgroupOffline(SMnode *pMnode, int32_t dnodeId, int64_t curMs)
pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup); pIter = sdbFetch(pSdb, SDB_VGROUP, pIter, (void **)&pVgroup);
if (pIter == NULL) break; if (pIter == NULL) break;
bool roleChanged = false; bool stateChanged = false;
for (int32_t vg = 0; vg < pVgroup->replica; ++vg) { for (int32_t vg = 0; vg < pVgroup->replica; ++vg) {
SVnodeGid *pGid = &pVgroup->vnodeGid[vg]; SVnodeGid *pGid = &pVgroup->vnodeGid[vg];
if (pGid->dnodeId == dnodeId) { if (pGid->dnodeId == dnodeId) {
@ -197,13 +197,14 @@ static void mndSetVgroupOffline(SMnode *pMnode, int32_t dnodeId, int64_t curMs)
pGid->syncState = TAOS_SYNC_STATE_OFFLINE; pGid->syncState = TAOS_SYNC_STATE_OFFLINE;
pGid->syncRestore = 0; pGid->syncRestore = 0;
pGid->syncCanRead = 0; pGid->syncCanRead = 0;
roleChanged = true; pGid->startTimeMs = 0;
stateChanged = true;
} }
break; break;
} }
} }
if (roleChanged) { if (stateChanged) {
SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName); SDbObj *pDb = mndAcquireDb(pMnode, pVgroup->dbName);
if (pDb != NULL && pDb->stateTs != curMs) { if (pDb != NULL && pDb->stateTs != curMs) {
mInfo("db:%s, stateTs changed by offline check, old newTs:%" PRId64 " newTs:%" PRId64, pDb->name, pDb->stateTs, mInfo("db:%s, stateTs changed by offline check, old newTs:%" PRId64 " newTs:%" PRId64, pDb->name, pDb->stateTs,