From 771c263665e0acdac9c169adfb49f2f77be3d922 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Tue, 3 Aug 2021 10:20:42 +0800 Subject: [PATCH 1/2] [TD-5729]: add subquery states and obj_ids to show queries output --- src/client/inc/tsclient.h | 2 +- src/client/src/tscProfile.c | 10 +++--- src/client/src/tscUtil.c | 2 +- src/inc/taosdef.h | 1 + src/inc/taosmsg.h | 3 ++ src/mnode/src/mnodeProfile.c | 62 ++++++++++++++++++++++++++++++++---- 6 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/client/inc/tsclient.h b/src/client/inc/tsclient.h index 83ec28898c..780111f3ce 100644 --- a/src/client/inc/tsclient.h +++ b/src/client/inc/tsclient.h @@ -294,7 +294,7 @@ typedef struct SSqlObj { SSqlCmd cmd; SSqlRes res; bool isBind; - + SSubqueryState subState; struct SSqlObj **pSubs; diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 70a3e03d62..25c6d13822 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -255,10 +255,12 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { 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->stableQuery = pSql->cmd.pQueryInfo->stableQuery; + pQdesc->numOfSub = (pSql->subState.numOfSub <= TSDB_MAX_SUBQUERY_NUM) ? pSql->subState.numOfSub : TSDB_MAX_SUBQUERY_NUM; + + for (int i = 0; i < pQdesc->numOfSub; ++i) { + pQdesc->subSqlStates[i] = pSql->subState.states[i]; + pQdesc->subSqlObjIds[i] = htobe64(pSql->pSubs[i]->self); } pQdesc->numOfSub = htonl(pQdesc->numOfSub); diff --git a/src/client/src/tscUtil.c b/src/client/src/tscUtil.c index 0d69fe173f..91c577a21c 100644 --- a/src/client/src/tscUtil.c +++ b/src/client/src/tscUtil.c @@ -2141,7 +2141,7 @@ int tscAllocPayload(SSqlCmd* pCmd, int size) { pCmd->payload = b; pCmd->allocSize = size; } - + memset(pCmd->payload, 0, pCmd->allocSize); } diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index ca8ad3cc09..de79139061 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -339,6 +339,7 @@ do { \ #define PRIMARYKEY_TIMESTAMP_COL_INDEX 0 #define TSDB_MAX_RPC_THREADS 5 +#define TSDB_MAX_SUBQUERY_NUM 10 #define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type #define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 06b80eea4f..8958f3d1c6 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -877,7 +877,10 @@ typedef struct { uint64_t sqlObjId; int32_t pid; char fqdn[TSDB_FQDN_LEN]; + bool stableQuery; int32_t numOfSub; + int8_t subSqlStates[TSDB_MAX_SUBQUERY_NUM]; + int64_t subSqlObjIds[TSDB_MAX_SUBQUERY_NUM]; } SQueryDesc; typedef struct { diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 2c117310b3..0004dd5b17 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -32,7 +32,8 @@ #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_OBJ_ID_SIZE 18 +#define SUBQUERY_INFO_SIZE 6 #define QUERY_STREAM_SAVE_SIZE 20 static SCacheObj *tsMnodeConnCache = NULL; @@ -380,12 +381,30 @@ static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; + pShow->bytes[cols] = 1; + pSchema[cols].type = TSDB_DATA_TYPE_BOOL; + strcpy(pSchema[cols].name, "stable_query"); + 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] = SUBQUERY_INFO_SIZE * TSDB_MAX_SUBQUERY_NUM + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "sub_query_states"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = (SUBQUERY_INFO_SIZE + QUERY_OBJ_ID_SIZE) * TSDB_MAX_SUBQUERY_NUM + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "sub_query_obj_ids "); + 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"); @@ -459,12 +478,8 @@ 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)); + + snprintf(str, tListLen(str), "0x%" 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++; @@ -479,10 +494,43 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v STR_WITH_MAXSIZE_TO_VARSTR(pWrite, epBuf, pShow->bytes[cols]); cols++; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(bool *)pWrite = pDesc->stableQuery; + cols++; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int32_t *)pWrite = htonl(pDesc->numOfSub); cols++; + char subQInfo[(SUBQUERY_INFO_SIZE + QUERY_OBJ_ID_SIZE) * TSDB_MAX_SUBQUERY_NUM] = {0}; + char *p; + int32_t idx, len; + + p = subQInfo; + for (idx = 0; idx < htonl(pDesc->numOfSub); ++idx) { + len = snprintf(p, SUBQUERY_INFO_SIZE, "[%d]%d ", idx, pDesc->subSqlStates[idx]); + p += MIN(len, SUBQUERY_INFO_SIZE); + } + if (idx == 0) { + snprintf(p, sizeof(subQInfo), "N/A"); + } + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, subQInfo, pShow->bytes[cols]); + cols++; + + p = subQInfo; + for (idx = 0; idx < htonl(pDesc->numOfSub); ++idx) { + len = snprintf(p, SUBQUERY_INFO_SIZE + QUERY_OBJ_ID_SIZE, "[%d]0x%" PRIx64 " ", + idx, htobe64(pDesc->subSqlObjIds[idx])); + p += MIN(len, SUBQUERY_INFO_SIZE + QUERY_OBJ_ID_SIZE); + } + if (idx == 0) { + snprintf(p, sizeof(subQInfo), "N/A"); + } + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, subQInfo, pShow->bytes[cols]); + cols++; + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]); cols++; From 4c53af4f8d3a0a61dcac993183c56f60400a4a32 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Wed, 4 Aug 2021 17:43:11 +0800 Subject: [PATCH 2/2] [TD-5729]: display subquery states and objIDs as one column sub_query_info --- src/client/src/tscProfile.c | 21 ++++++++++++++++---- src/inc/taosdef.h | 2 +- src/inc/taosmsg.h | 3 +-- src/mnode/src/mnodeProfile.c | 37 +++--------------------------------- 4 files changed, 22 insertions(+), 41 deletions(-) diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 25c6d13822..92ad9b7924 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -256,11 +256,24 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { pQdesc->sqlObjId = htobe64(pSql->self); pQdesc->pid = pHeartbeat->pid; pQdesc->stableQuery = pSql->cmd.pQueryInfo->stableQuery; - pQdesc->numOfSub = (pSql->subState.numOfSub <= TSDB_MAX_SUBQUERY_NUM) ? pSql->subState.numOfSub : TSDB_MAX_SUBQUERY_NUM; + pQdesc->numOfSub = pSql->subState.numOfSub; - for (int i = 0; i < pQdesc->numOfSub; ++i) { - pQdesc->subSqlStates[i] = pSql->subState.states[i]; - pQdesc->subSqlObjIds[i] = htobe64(pSql->pSubs[i]->self); + char *p = pQdesc->subSqlInfo; + int32_t remainLen = sizeof(pQdesc->subSqlInfo); + if (pQdesc->numOfSub == 0) { + snprintf(p, remainLen, "N/A"); + } else { + int32_t len; + for (int32_t i = 0; i < pQdesc->numOfSub; ++i) { + len = snprintf(p, remainLen, "[%d]0x%" PRIx64 "(%c) ", i, + pSql->pSubs[i]->self, + pSql->subState.states[i] ? 'C' : 'I'); + if (len > remainLen) { + break; + } + remainLen -= len; + p += len; + } } pQdesc->numOfSub = htonl(pQdesc->numOfSub); diff --git a/src/inc/taosdef.h b/src/inc/taosdef.h index de79139061..1f396da514 100644 --- a/src/inc/taosdef.h +++ b/src/inc/taosdef.h @@ -223,6 +223,7 @@ do { \ #define TSDB_IPv4ADDR_LEN 16 #define TSDB_FILENAME_LEN 128 #define TSDB_SHOW_SQL_LEN 512 +#define TSDB_SHOW_SUBQUERY_LEN 1000 #define TSDB_SLOW_QUERY_SQL_LEN 512 #define TSDB_STEP_NAME_LEN 32 @@ -339,7 +340,6 @@ do { \ #define PRIMARYKEY_TIMESTAMP_COL_INDEX 0 #define TSDB_MAX_RPC_THREADS 5 -#define TSDB_MAX_SUBQUERY_NUM 10 #define TSDB_QUERY_TYPE_NON_TYPE 0x00u // none type #define TSDB_QUERY_TYPE_FREE_RESOURCE 0x01u // free qhandle at vnode diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 8958f3d1c6..1f3978c38c 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -879,8 +879,7 @@ typedef struct { char fqdn[TSDB_FQDN_LEN]; bool stableQuery; int32_t numOfSub; - int8_t subSqlStates[TSDB_MAX_SUBQUERY_NUM]; - int64_t subSqlObjIds[TSDB_MAX_SUBQUERY_NUM]; + char subSqlInfo[TSDB_SHOW_SUBQUERY_LEN]; //include subqueries' index, Obj IDs and states(C-complete/I-imcomplete) } SQueryDesc; typedef struct { diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index 0004dd5b17..15438fc234 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -393,15 +393,9 @@ static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; - pShow->bytes[cols] = SUBQUERY_INFO_SIZE * TSDB_MAX_SUBQUERY_NUM + VARSTR_HEADER_SIZE; + pShow->bytes[cols] = TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sub_query_states"); - pSchema[cols].bytes = htons(pShow->bytes[cols]); - cols++; - - pShow->bytes[cols] = (SUBQUERY_INFO_SIZE + QUERY_OBJ_ID_SIZE) * TSDB_MAX_SUBQUERY_NUM + VARSTR_HEADER_SIZE; - pSchema[cols].type = TSDB_DATA_TYPE_BINARY; - strcpy(pSchema[cols].name, "sub_query_obj_ids "); + strcpy(pSchema[cols].name, "sub_query_info"); pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; @@ -502,33 +496,8 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v *(int32_t *)pWrite = htonl(pDesc->numOfSub); cols++; - char subQInfo[(SUBQUERY_INFO_SIZE + QUERY_OBJ_ID_SIZE) * TSDB_MAX_SUBQUERY_NUM] = {0}; - char *p; - int32_t idx, len; - - p = subQInfo; - for (idx = 0; idx < htonl(pDesc->numOfSub); ++idx) { - len = snprintf(p, SUBQUERY_INFO_SIZE, "[%d]%d ", idx, pDesc->subSqlStates[idx]); - p += MIN(len, SUBQUERY_INFO_SIZE); - } - if (idx == 0) { - snprintf(p, sizeof(subQInfo), "N/A"); - } pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, subQInfo, pShow->bytes[cols]); - cols++; - - p = subQInfo; - for (idx = 0; idx < htonl(pDesc->numOfSub); ++idx) { - len = snprintf(p, SUBQUERY_INFO_SIZE + QUERY_OBJ_ID_SIZE, "[%d]0x%" PRIx64 " ", - idx, htobe64(pDesc->subSqlObjIds[idx])); - p += MIN(len, SUBQUERY_INFO_SIZE + QUERY_OBJ_ID_SIZE); - } - if (idx == 0) { - snprintf(p, sizeof(subQInfo), "N/A"); - } - pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; - STR_WITH_MAXSIZE_TO_VARSTR(pWrite, subQInfo, pShow->bytes[cols]); + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->subSqlInfo, pShow->bytes[cols]); cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows;