From ce381225eba10db845b1b6fba3a811e0b16e475b Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Sun, 14 Nov 2021 20:03:45 +0800 Subject: [PATCH] fix negative req_insert numbers --- src/dnode/src/dnodeShell.c | 14 ++------- src/inc/dnode.h | 1 - src/inc/vnode.h | 1 - src/plugins/monitor/src/monMain.c | 47 ++++++++++++++++--------------- src/vnode/src/vnodeWrite.c | 12 ++------ 5 files changed, 30 insertions(+), 45 deletions(-) diff --git a/src/dnode/src/dnodeShell.c b/src/dnode/src/dnodeShell.c index 1fd9819d63..666fdcff86 100644 --- a/src/dnode/src/dnodeShell.c +++ b/src/dnode/src/dnodeShell.c @@ -243,23 +243,13 @@ SDnodeStatisInfo dnodeGetStatisInfo() { #ifdef HTTP_EMBEDDED info.httpReqNum = httpGetReqCount(); #endif - info.queryReqNum = atomic_load_32(&tsQueryReqNum); - info.submitReqNum = atomic_load_32(&tsSubmitReqNum); + info.queryReqNum = atomic_exchange_32(&tsQueryReqNum, 0); + info.submitReqNum = atomic_exchange_32(&tsSubmitReqNum, 0); } return info; } -void dnodeClearStatisInfo() { - if (dnodeGetRunStatus() == TSDB_RUN_STATUS_RUNING) { -#ifdef HTTP_EMBEDDED - httpClearReqCount(); -#endif - atomic_exchange_32(&tsQueryReqNum, 0); - atomic_exchange_32(&tsSubmitReqNum, 0); - } -} - int32_t dnodeGetHttpStatusInfo(int32_t index) { int32_t httpStatus = 0; #ifdef HTTP_EMBEDDED diff --git a/src/inc/dnode.h b/src/inc/dnode.h index 80c74de905..d638353e18 100644 --- a/src/inc/dnode.h +++ b/src/inc/dnode.h @@ -31,7 +31,6 @@ typedef struct { } SDnodeStatisInfo; SDnodeStatisInfo dnodeGetStatisInfo(); -void dnodeClearStatisInfo(); int32_t dnodeGetHttpStatusInfo(int32_t index); void dnodeClearHttpStatusInfo(); diff --git a/src/inc/vnode.h b/src/inc/vnode.h index 9b47fe532d..edbb158263 100644 --- a/src/inc/vnode.h +++ b/src/inc/vnode.h @@ -87,7 +87,6 @@ void vnodeFreeFromWQueue(void *pVnode, SVWriteMsg *pWrite); int32_t vnodeProcessWrite(void *pVnode, void *pHead, int32_t qtype, void *pRspRet); SVnodeStatisInfo vnodeGetStatisInfo(); -void vnodeClearStatisInfo(); // vnodeSync void vnodeConfirmForward(void *pVnode, uint64_t version, int32_t code, bool force); diff --git a/src/plugins/monitor/src/monMain.c b/src/plugins/monitor/src/monMain.c index fcfe9d03b6..1f244eb89e 100644 --- a/src/plugins/monitor/src/monMain.c +++ b/src/plugins/monitor/src/monMain.c @@ -149,10 +149,14 @@ typedef struct { } SMonConn; typedef struct { + SDnodeStatisInfo dInfo; + SVnodeStatisInfo vInfo; float io_read; float io_write; float io_read_disk; float io_write_disk; + int32_t monQueryReqCnt; + int32_t monSubmitReqCnt; } SMonStat; static void *monHttpStatusHashTable; @@ -170,7 +174,6 @@ static void monSaveSlowQueryInfo(); static void monSaveDisksInfo(); static void monSaveGrantsInfo(); static void monSaveHttpReqInfo(); -static void monClearStatisInfo(); static void monGetSysStats(); static void *monThreadFunc(void *param); static void monBuildMonitorSql(char *sql, int32_t cmd); @@ -503,6 +506,12 @@ static void monGetSysStats() { if (!suc) { monDebug("failed to get io info"); } + + tsMonStat.dInfo = dnodeGetStatisInfo(); + tsMonStat.vInfo = vnodeGetStatisInfo(); + + tsMonStat.monQueryReqCnt = monFetchQueryReqCnt(); + tsMonStat.monSubmitReqCnt = monFetchSubmitReqCnt(); } // unit is MB @@ -554,7 +563,7 @@ static int32_t monBuildBandSql(char *sql) { } static int32_t monBuildReqSql(char *sql) { - SDnodeStatisInfo info = dnodeGetStatisInfo(); + SDnodeStatisInfo info = tsMonStat.dInfo; return sprintf(sql, ", %d, %d, %d)", info.httpReqNum, info.queryReqNum, info.submitReqNum); } @@ -882,23 +891,22 @@ static int32_t monBuildNetworkIOSql(char *sql) { } static int32_t monBuildDnodeReqSql(char *sql) { - SDnodeStatisInfo dInfo = dnodeGetStatisInfo(); - SVnodeStatisInfo vInfo = vnodeGetStatisInfo(); - - int32_t monQueryReqCnt = monFetchQueryReqCnt(); - int32_t monSubmitReqCnt = monFetchSubmitReqCnt(); + int32_t queryReqNum = tsMonStat.dInfo.queryReqNum - tsMonStat.monQueryReqCnt; + int32_t submitReqNum = tsMonStat.dInfo.submitReqNum - tsMonStat.monSubmitReqCnt; + int32_t submitRowNum = tsMonStat.vInfo.submitRowNum - tsMonStat.monSubmitReqCnt; + int32_t submitReqSucNum = tsMonStat.vInfo.submitReqSucNum - tsMonStat.monSubmitReqCnt; + int32_t submitRowSucNum = tsMonStat.vInfo.submitRowSucNum - tsMonStat.monSubmitReqCnt; float interval = (float)(tsMonitorInterval * 1.0); - float httpReqRate = dInfo.httpReqNum / interval; - float queryReqRate = (dInfo.queryReqNum - monQueryReqCnt)/ interval; - float submitReqRate = (dInfo.submitReqNum - monSubmitReqCnt) / interval; - float submitRowRate = (vInfo.submitRowNum - monSubmitReqCnt) / interval; - monClearStatisInfo(); - - return sprintf(sql, ", %d, %f, %d, %f, %d, %d, %f, %d, %d, %f", dInfo.httpReqNum, httpReqRate, - dInfo.queryReqNum - monQueryReqCnt, queryReqRate, - vInfo.submitRowNum - monSubmitReqCnt, vInfo.submitRowSucNum - monSubmitReqCnt, submitRowRate, - dInfo.submitReqNum - monSubmitReqCnt, vInfo.submitReqSucNum - monSubmitReqCnt, submitReqRate); + float httpReqRate = tsMonStat.dInfo.httpReqNum / interval; + float queryReqRate = queryReqNum / interval; + float submitReqRate = submitReqNum / interval; + float submitRowRate = submitRowNum / interval; + + return sprintf(sql, ", %d, %f, %d, %f, %d, %d, %f, %d, %d, %f", tsMonStat.dInfo.httpReqNum, httpReqRate, + queryReqNum, queryReqRate, + submitRowNum, submitRowSucNum, submitRowRate, + submitReqNum, submitReqSucNum, submitReqRate); } static int32_t monBuildDnodeErrorsSql(char *sql) { @@ -1316,11 +1324,6 @@ static void monSaveHttpReqInfo() { } } -static void monClearStatisInfo() { - dnodeClearStatisInfo(); - vnodeClearStatisInfo(); -} - static void monExecSqlCb(void *param, TAOS_RES *result, int32_t code) { int32_t c = taos_errno(result); if (c != TSDB_CODE_SUCCESS) { diff --git a/src/vnode/src/vnodeWrite.c b/src/vnode/src/vnodeWrite.c index c76298ae11..e27b7615cf 100644 --- a/src/vnode/src/vnodeWrite.c +++ b/src/vnode/src/vnodeWrite.c @@ -441,15 +441,9 @@ void vnodeWaitWriteCompleted(SVnodeObj *pVnode) { SVnodeStatisInfo vnodeGetStatisInfo() { SVnodeStatisInfo info = {0}; - info.submitReqSucNum = atomic_load_32(&tsSubmitReqSucNum); - info.submitRowNum = atomic_load_32(&tsSubmitRowNum); - info.submitRowSucNum = atomic_load_32(&tsSubmitRowSucNum); + info.submitReqSucNum = atomic_exchange_32(&tsSubmitReqSucNum, 0); + info.submitRowNum = atomic_exchange_32(&tsSubmitRowNum, 0); + info.submitRowSucNum = atomic_exchange_32(&tsSubmitRowSucNum, 0); return info; } - -void vnodeClearStatisInfo() { - atomic_exchange_32(&tsSubmitReqSucNum, 0); - atomic_exchange_32(&tsSubmitRowNum, 0); - atomic_exchange_32(&tsSubmitRowSucNum, 0); -} -- GitLab