From 239a79d405565f08a04c5239e22932b41bdffd2f Mon Sep 17 00:00:00 2001 From: Benguang Zhao Date: Tue, 15 Aug 2023 10:10:06 +0800 Subject: [PATCH] enh: add some vnode info in SStatusReq --- include/common/tmsg.h | 7 ++++-- include/libs/sync/sync.h | 1 + source/common/src/tmsg.c | 32 +++++++++++++++++++++---- source/dnode/vnode/src/vnd/vnodeQuery.c | 3 +++ source/libs/sync/src/syncMain.c | 1 + 5 files changed, 37 insertions(+), 7 deletions(-) diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 01923d2b30..ea3dca06f3 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -1163,6 +1163,9 @@ typedef struct { int32_t vgId; int8_t syncState; int8_t syncRestore; + int64_t syncTerm; + int64_t roleTimeMs; + int64_t startTimeMs; int8_t syncCanRead; int64_t cacheUsage; int64_t numOfTables; @@ -1179,9 +1182,9 @@ typedef struct { } SVnodeLoad; typedef struct { - int8_t syncState; - int8_t syncRestore; + int8_t syncState; int64_t syncTerm; + int8_t syncRestore; int64_t roleTimeMs; } SMnodeLoad; diff --git a/include/libs/sync/sync.h b/include/libs/sync/sync.h index 88ccf562c7..8844145652 100644 --- a/include/libs/sync/sync.h +++ b/include/libs/sync/sync.h @@ -241,6 +241,7 @@ typedef struct SSyncState { bool canRead; SyncTerm term; int64_t roleTimeMs; + int64_t startTimeMs; } SSyncState; int32_t syncInit(); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index ef0006e7ab..7e69184a00 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1079,8 +1079,8 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tEncodeI64(&encoder, pload->pointsWritten) < 0) return -1; if (tEncodeI32(&encoder, pload->numOfCachedTables) < 0) return -1; if (tEncodeI32(&encoder, reserved) < 0) return -1; - if (tEncodeI64(&encoder, reserved) < 0) return -1; - if (tEncodeI64(&encoder, reserved) < 0) return -1; + if (tEncodeI64(&encoder, pload->roleTimeMs) < 0) return -1; + if (tEncodeI64(&encoder, pload->startTimeMs) < 0) return -1; } // mnode loads @@ -1104,6 +1104,16 @@ int32_t tSerializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tEncodeI64(&encoder, pReq->mload.syncTerm) < 0) return -1; if (tEncodeI64(&encoder, pReq->mload.roleTimeMs) < 0) return -1; if (tEncodeI8(&encoder, pReq->clusterCfg.ttlChangeOnWrite) < 0) return -1; + + // vnode extra + for (int32_t i = 0; i < vlen; ++i) { + SVnodeLoad *pload = taosArrayGet(pReq->pVloads, i); + int64_t reserved = 0; + if (tEncodeI64(&encoder, pload->syncTerm) < 0) return -1; + if (tEncodeI64(&encoder, reserved) < 0) return -1; + if (tEncodeI64(&encoder, reserved) < 0) return -1; + if (tEncodeI64(&encoder, reserved) < 0) return -1; + } tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -1148,7 +1158,7 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { for (int32_t i = 0; i < vlen; ++i) { SVnodeLoad vload = {0}; - int64_t reserved64 = 0; + vload.syncTerm = -1; int32_t reserved32 = 0; if (tDecodeI32(&decoder, &vload.vgId) < 0) return -1; if (tDecodeI8(&decoder, &vload.syncState) < 0) return -1; @@ -1162,14 +1172,15 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tDecodeI64(&decoder, &vload.pointsWritten) < 0) return -1; if (tDecodeI32(&decoder, &vload.numOfCachedTables) < 0) return -1; if (tDecodeI32(&decoder, (int32_t *)&reserved32) < 0) return -1; - if (tDecodeI64(&decoder, &reserved64) < 0) return -1; - if (tDecodeI64(&decoder, &reserved64) < 0) return -1; + if (tDecodeI64(&decoder, &vload.roleTimeMs) < 0) return -1; + if (tDecodeI64(&decoder, &vload.startTimeMs) < 0) return -1; if (taosArrayPush(pReq->pVloads, &vload) == NULL) { terrno = TSDB_CODE_OUT_OF_MEMORY; return -1; } } + // mnode loads if (tDecodeI8(&decoder, &pReq->mload.syncState) < 0) return -1; if (tDecodeI8(&decoder, &pReq->mload.syncRestore) < 0) return -1; @@ -1200,6 +1211,17 @@ int32_t tDeserializeSStatusReq(void *buf, int32_t bufLen, SStatusReq *pReq) { if (tDecodeI8(&decoder, &pReq->clusterCfg.ttlChangeOnWrite) < 0) return -1; } + // vnode extra + if (!tDecodeIsEnd(&decoder)) { + for (int32_t i = 0; i < vlen; ++i) { + SVnodeLoad *pLoad = taosArrayGet(pReq->pVloads, i); + int64_t reserved = 0; + if (tDecodeI64(&decoder, &pLoad->syncTerm) < 0) return -1; + if (tDecodeI64(&decoder, &reserved) < 0) return -1; + if (tDecodeI64(&decoder, &reserved) < 0) return -1; + if (tDecodeI64(&decoder, &reserved) < 0) return -1; + } + } tEndDecode(&decoder); tDecoderClear(&decoder); return 0; diff --git a/source/dnode/vnode/src/vnd/vnodeQuery.c b/source/dnode/vnode/src/vnd/vnodeQuery.c index 51f4cee40c..ebc2e38a5a 100644 --- a/source/dnode/vnode/src/vnd/vnodeQuery.c +++ b/source/dnode/vnode/src/vnd/vnodeQuery.c @@ -380,6 +380,9 @@ int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) { pLoad->vgId = TD_VID(pVnode); pLoad->syncState = state.state; pLoad->syncRestore = state.restored; + pLoad->syncTerm = state.term; + pLoad->roleTimeMs = state.roleTimeMs; + pLoad->startTimeMs = state.startTimeMs; pLoad->syncCanRead = state.canRead; pLoad->cacheUsage = tsdbCacheGetUsage(pVnode); pLoad->numOfCachedTables = tsdbCacheGetElems(pVnode); diff --git a/source/libs/sync/src/syncMain.c b/source/libs/sync/src/syncMain.c index f1e3c35a49..9108090b87 100644 --- a/source/libs/sync/src/syncMain.c +++ b/source/libs/sync/src/syncMain.c @@ -509,6 +509,7 @@ SSyncState syncGetState(int64_t rid) { if (pSyncNode != NULL) { state.state = pSyncNode->state; state.roleTimeMs = pSyncNode->roleTimeMs; + state.startTimeMs = pSyncNode->startTime; state.restored = pSyncNode->restoreFinish; if (pSyncNode->vgId != 1) { state.canRead = syncNodeIsReadyForRead(pSyncNode);