diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 80590a25c0e473342431f4cf2aaeea14b31f8820..681a5ec423c233a6a8a94a3cd1350c3cde4149b7 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1059,6 +1059,7 @@ typedef struct { int32_t vgId; int8_t syncState; int8_t syncRestore; + int8_t syncCanRead; int64_t cacheUsage; int64_t numOfTables; int64_t numOfTimeSeries; diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index c7e98415d16fb3aa878274ed52953ad20455d150..c7046c74226547c2480e97855255e9bbb814ebe1 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -992,15 +992,20 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tEncodeI32(&encoder, vlen) < 0) return -1; for (int32_t i = 0; i < vlen; ++i) { SVnodeLoad *pload = taosArrayGet(pReq->pVloads, i); + int64_t reserved = 0; if (tEncodeI32(&encoder, pload->vgId) < 0) return -1; if (tEncodeI8(&encoder, pload->syncState) < 0) return -1; if (tEncodeI8(&encoder, pload->syncRestore) < 0) return -1; + if (tEncodeI8(&encoder, pload->syncCanRead) < 0) return -1; if (tEncodeI64(&encoder, pload->cacheUsage) < 0) return -1; if (tEncodeI64(&encoder, pload->numOfTables) < 0) return -1; if (tEncodeI64(&encoder, pload->numOfTimeSeries) < 0) return -1; if (tEncodeI64(&encoder, pload->totalStorage) < 0) return -1; if (tEncodeI64(&encoder, pload->compStorage) < 0) return -1; if (tEncodeI64(&encoder, pload->pointsWritten) < 0) return -1; + if (tEncodeI64(&encoder, reserved) < 0) return -1; + if (tEncodeI64(&encoder, reserved) < 0) return -1; + if (tEncodeI64(&encoder, reserved) < 0) return -1; } // mnode loads @@ -1065,15 +1070,20 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { for (int32_t i = 0; i < vlen; ++i) { SVnodeLoad vload = {0}; + int64_t reserved = 0; if (tDecodeI32(&decoder, &vload.vgId) < 0) return -1; if (tDecodeI8(&decoder, &vload.syncState) < 0) return -1; if (tDecodeI8(&decoder, &vload.syncRestore) < 0) return -1; + if (tDecodeI8(&decoder, &vload.syncCanRead) < 0) return -1; if (tDecodeI64(&decoder, &vload.cacheUsage) < 0) return -1; if (tDecodeI64(&decoder, &vload.numOfTables) < 0) return -1; if (tDecodeI64(&decoder, &vload.numOfTimeSeries) < 0) return -1; if (tDecodeI64(&decoder, &vload.totalStorage) < 0) return -1; if (tDecodeI64(&decoder, &vload.compStorage) < 0) return -1; if (tDecodeI64(&decoder, &vload.pointsWritten) < 0) return -1; + if (tDecodeI64(&decoder, &reserved) < 0) return -1; + if (tDecodeI64(&decoder, &reserved) < 0) return -1; + if (tDecodeI64(&decoder, &reserved) < 0) return -1; if (taosArrayPush(pReq->pVloads, &vload) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; diff --git a/source/dnode/mnode/impl/inc/mndDef.h b/source/dnode/mnode/impl/inc/mndDef.h index 04ac5aba49dcc1622c81201c88524a7b1eed8591..d0d2930abe34819cc5918759e837ac247dd931c1 100644 --- a/source/dnode/mnode/impl/inc/mndDef.h +++ b/source/dnode/mnode/impl/inc/mndDef.h @@ -328,6 +328,7 @@ typedef struct { int32_t dnodeId; ESyncState syncState; bool syncRestore; + bool syncCanRead; } SVnodeGid; typedef struct { diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 2a3ecf1924654ebbc5c589f65a0d291e9754b0fa..49887c0dabdb9fe00ae18eeba171bcea1c6100d9 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -375,14 +375,18 @@ static int32_t mndProcessStatusReq(SRpcMsg *pReq) { } bool roleChanged = false; for (int32_t vg = 0; vg < pVgroup->replica; ++vg) { - if (pVgroup->vnodeGid[vg].dnodeId == statusReq.dnodeId) { - if (pVgroup->vnodeGid[vg].syncState != pVload->syncState || - pVgroup->vnodeGid[vg].syncRestore != pVload->syncRestore) { - mInfo("vgId:%d, state changed by status msg, old state:%s restored:%d new state:%s restored:%d", - pVgroup->vgId, syncStr(pVgroup->vnodeGid[vg].syncState), pVgroup->vnodeGid[vg].syncRestore, - syncStr(pVload->syncState), pVload->syncRestore); - pVgroup->vnodeGid[vg].syncState = pVload->syncState; - pVgroup->vnodeGid[vg].syncRestore = pVload->syncRestore; + SVnodeGid *pGid = &pVgroup->vnodeGid[vg]; + if (pGid->dnodeId == statusReq.dnodeId) { + if (pGid->syncState != pVload->syncState || pGid->syncRestore != pVload->syncRestore || + pGid->syncCanRead != pVload->syncCanRead) { + mInfo( + "vgId:%d, state changed by status msg, old state:%s restored:%d canRead:%d new state:%s restored:%d " + "canRead:%d", + pVgroup->vgId, syncStr(pGid->syncState), pGid->syncRestore, pGid->syncCanRead, + syncStr(pVload->syncState), pVload->syncRestore, pVload->syncCanRead); + pGid->syncState = pVload->syncState; + pGid->syncRestore = pVload->syncRestore; + pGid->syncCanRead = pVload->syncCanRead; roleChanged = true; } break; diff --git a/source/dnode/mnode/impl/src/mndMain.c b/source/dnode/mnode/impl/src/mndMain.c index f533fafeee81009266b650de241d69632259ae77..b16e4985c40d3d5986ed9e08baadc2e09ecd52cd 100644 --- a/source/dnode/mnode/impl/src/mndMain.c +++ b/source/dnode/mnode/impl/src/mndMain.c @@ -150,12 +150,16 @@ static void mndSetVgroupOffline(SMnode *pMnode, int32_t dnodeId, int64_t curMs) bool roleChanged = false; for (int32_t vg = 0; vg < pVgroup->replica; ++vg) { - if (pVgroup->vnodeGid[vg].dnodeId == dnodeId) { - if (pVgroup->vnodeGid[vg].syncState != TAOS_SYNC_STATE_OFFLINE) { - mInfo("vgId:%d, state changed by offline check, old state:%s restored:%d new state:error restored:0", - pVgroup->vgId, syncStr(pVgroup->vnodeGid[vg].syncState), pVgroup->vnodeGid[vg].syncRestore); - pVgroup->vnodeGid[vg].syncState = TAOS_SYNC_STATE_OFFLINE; - pVgroup->vnodeGid[vg].syncRestore = 0; + SVnodeGid *pGid = &pVgroup->vnodeGid[vg]; + if (pGid->dnodeId == dnodeId) { + if (pGid->syncState != TAOS_SYNC_STATE_OFFLINE) { + mInfo( + "vgId:%d, state changed by offline check, old state:%s restored:%d canRead:%d new state:error restored:0 " + "canRead:0", + pVgroup->vgId, syncStr(pGid->syncState), pGid->syncRestore, pGid->syncCanRead); + pGid->syncState = TAOS_SYNC_STATE_OFFLINE; + pGid->syncRestore = 0; + pGid->syncCanRead = 0; roleChanged = true; } break; diff --git a/source/dnode/mnode/impl/src/mndVgroup.c b/source/dnode/mnode/impl/src/mndVgroup.c index d06853e47054c3ff9ff25bd2aa7af3ca90e544e8..eec112d225195a354f44bb80f80577380ddaabde 100644 --- a/source/dnode/mnode/impl/src/mndVgroup.c +++ b/source/dnode/mnode/impl/src/mndVgroup.c @@ -186,6 +186,7 @@ static int32_t mndVgroupActionUpdate(SSdb *pSdb, SVgObj *pOld, SVgObj *pNew) { if (pNewGid->dnodeId == pOldGid->dnodeId) { pNewGid->syncState = pOldGid->syncState; pNewGid->syncRestore = pOldGid->syncRestore; + pNewGid->syncCanRead = pOldGid->syncCanRead; } } } @@ -696,8 +697,16 @@ static int32_t mndRetrieveVgroups(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *p if (!exist) { strcpy(role, "dropping"); } else if (online) { - bool show = (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER && !pVgroup->vnodeGid[i].syncRestore); - snprintf(role, sizeof(role), "%s%s", syncStr(pVgroup->vnodeGid[i].syncState), show ? "*" : ""); + char *star = ""; + if (pVgroup->vnodeGid[i].syncState == TAOS_SYNC_STATE_LEADER) { + if (!pVgroup->vnodeGid[i].syncRestore && !pVgroup->vnodeGid[i].syncCanRead) { + star = "**"; + } else if (!pVgroup->vnodeGid[i].syncRestore && pVgroup->vnodeGid[i].syncCanRead) { + star = "*"; + } else { + } + } + snprintf(role, sizeof(role), "%s%s", syncStr(pVgroup->vnodeGid[i].syncState), star); } else { } STR_WITH_MAXSIZE_TO_VARSTR(buf1, role, pShow->pMeta->pSchemas[cols].bytes); diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 8e9aab0afd129dbf1fab3d301d6da406590db3d2..1199127f6d42bf2d3f7488fb120e8fa9ab09c490 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -380,6 +380,7 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { pLoad->vgId = TD_VID(pVnode); pLoad->syncState = state.state; pLoad->syncRestore = state.restored; + pLoad->syncCanRead = state.canRead; pLoad->cacheUsage = tsdbCacheGetUsage(pVnode); pLoad->numOfTables = metaGetTbNum(pVnode->pMeta); pLoad->numOfTimeSeries = metaGetTimeSeriesNum(pVnode->pMeta);