From 24286fec398ee8a477d4367bbe709499cb521fac Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 21 Jul 2021 19:05:19 +0800 Subject: [PATCH] [TD-5237]:add additional info for "show queries" output --- src/client/src/tscProfile.c | 13 +++++++++- src/inc/taosmsg.h | 4 +++ src/mnode/src/mnodeProfile.c | 48 ++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 661bd602b3..70a3e03d62 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -16,6 +16,7 @@ #include "os.h" #include "tscLog.h" #include "tsclient.h" +#include "tsocket.h" #include "ttimer.h" #include "tutil.h" #include "taosmsg.h" @@ -228,7 +229,7 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { SHeartBeatMsg *pHeartbeat = pMsg; int allocedQueriesNum = pHeartbeat->numOfQueries; int allocedStreamsNum = pHeartbeat->numOfStreams; - + pHeartbeat->numOfQueries = 0; SQueryDesc *pQdesc = (SQueryDesc *)pHeartbeat->pData; @@ -252,6 +253,16 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { //pQdesc->useconds = htobe64(pSql->res.useconds); pQdesc->useconds = htobe64(now - pSql->stime); pQdesc->qId = htobe64(pSql->res.qId); + pQdesc->sqlObjId = htobe64(pSql->self); + pQdesc->pid = pHeartbeat->pid; + if (pSql->cmd.pQueryInfo->stableQuery == true) { + pQdesc->numOfSub = pSql->subState.numOfSub; + } else { + pQdesc->numOfSub = 1; + } + pQdesc->numOfSub = htonl(pQdesc->numOfSub); + + taosGetFqdn(pQdesc->fqdn); pHeartbeat->numOfQueries++; pQdesc++; diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 9ee241efc1..06b80eea4f 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -874,6 +874,10 @@ typedef struct { int64_t useconds; int64_t stime; uint64_t qId; + uint64_t sqlObjId; + int32_t pid; + char fqdn[TSDB_FQDN_LEN]; + int32_t numOfSub; } SQueryDesc; typedef struct { diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index cbf713af65..2c117310b3 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -32,6 +32,7 @@ #define CONN_KEEP_TIME (tsShellActivityTimer * 3) #define CONN_CHECK_TIME (tsShellActivityTimer * 2) #define QUERY_ID_SIZE 20 +#define QUERY_OBJ_ID_SIZE 10 #define QUERY_STREAM_SAVE_SIZE 20 static SCacheObj *tsMnodeConnCache = NULL; @@ -361,6 +362,30 @@ static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; + pShow->bytes[cols] = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "sql_obj_id"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "pid"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "ep"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "sub_queries"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "sql"); @@ -434,6 +459,29 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int64_t *)pWrite = htobe64(pDesc->useconds); cols++; + /* + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = htobe64(pDesc->sqlObjId); + cols++; + */ + snprintf(str, tListLen(str), "0x%08" PRIx64, htobe64(pDesc->sqlObjId)); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, str, pShow->bytes[cols]); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = htonl(pDesc->pid); + cols++; + + char epBuf[TSDB_EP_LEN + 1] = {0}; + snprintf(epBuf, tListLen(epBuf), "%s:%u", pDesc->fqdn, pConnObj->port); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, epBuf, pShow->bytes[cols]); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = htonl(pDesc->numOfSub); + cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]); -- GitLab