• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #3564

24 Dec 2024 05:40AM UTC coverage: 62.21% (+1.2%) from 61.045%
#3564

push

travis-ci

web-flow
Merge pull request #29289 from taosdata/fix/TD-33270-2

ci(stream):add stream unit test

138331 of 285924 branches covered (48.38%)

Branch coverage included in aggregate %.

215800 of 283329 relevant lines covered (76.17%)

19198660.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.55
/source/dnode/mnode/impl/src/mndProfile.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define _DEFAULT_SOURCE
17
#include "audit.h"
18
#include "mndDb.h"
19
#include "mndDnode.h"
20
#include "mndMnode.h"
21
#include "mndPrivilege.h"
22
#include "mndProfile.h"
23
#include "mndQnode.h"
24
#include "mndShow.h"
25
#include "mndSma.h"
26
#include "mndStb.h"
27
#include "mndUser.h"
28
#include "mndView.h"
29
#include "tglobal.h"
30
#include "tversion.h"
31

32
typedef struct {
33
  uint32_t id;
34
  int8_t   connType;
35
  char     user[TSDB_USER_LEN];
36
  char     app[TSDB_APP_NAME_LEN];  // app name that invokes taosc
37
  int64_t  appStartTimeMs;          // app start time
38
  int32_t  pid;                     // pid of app that invokes taosc
39
  uint32_t ip;
40
  uint16_t port;
41
  int8_t   killed;
42
  int64_t  loginTimeMs;
43
  int64_t  lastAccessTimeMs;
44
  uint64_t killId;
45
  int32_t  numOfQueries;
46
  SRWLatch queryLock;
47
  SArray  *pQueries;  // SArray<SQueryDesc>
48
  char     userApp[TSDB_APP_NAME_LEN];
49
  uint32_t userIp;
50
} SConnObj;
51

52
typedef struct {
53
  int64_t            appId;
54
  uint32_t           ip;
55
  int32_t            pid;
56
  char               name[TSDB_APP_NAME_LEN];
57
  int64_t            startTime;
58
  SAppClusterSummary summary;
59
  int64_t            lastAccessTimeMs;
60
} SAppObj;
61

62
typedef struct {
63
  int32_t totalDnodes;
64
  int32_t onlineDnodes;
65
  SEpSet  epSet;
66
  SArray *pQnodeList;
67
  int64_t ipWhiteListVer;
68
} SConnPreparedObj;
69

70
#define CACHE_OBJ_KEEP_TIME 3  // s
71

72
static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType, uint32_t ip, uint16_t port,
73
                               int32_t pid, const char *app, int64_t startTime);
74
static void      mndFreeConn(SConnObj *pConn);
75
static SConnObj *mndAcquireConn(SMnode *pMnode, uint32_t connId);
76
static void      mndReleaseConn(SMnode *pMnode, SConnObj *pConn, bool extendLifespan);
77
static void     *mndGetNextConn(SMnode *pMnode, SCacheIter *pIter);
78
static void      mndCancelGetNextConn(SMnode *pMnode, void *pIter);
79
static int32_t   mndProcessHeartBeatReq(SRpcMsg *pReq);
80
static int32_t   mndProcessConnectReq(SRpcMsg *pReq);
81
static int32_t   mndProcessKillQueryReq(SRpcMsg *pReq);
82
static int32_t   mndProcessKillConnReq(SRpcMsg *pReq);
83
static int32_t   mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
84
static int32_t   mndRetrieveQueries(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
85
static void      mndCancelGetNextQuery(SMnode *pMnode, void *pIter);
86
static void      mndFreeApp(SAppObj *pApp);
87
static int32_t   mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
88
static void      mndCancelGetNextApp(SMnode *pMnode, void *pIter);
89
static int32_t   mndProcessSvrVerReq(SRpcMsg *pReq);
90

91
int32_t mndInitProfile(SMnode *pMnode) {
1,774✔
92
  int32_t       code = 0;
1,774✔
93
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
1,774✔
94

95
  // in ms
96
  int32_t checkTime = CACHE_OBJ_KEEP_TIME * 1000;
1,774✔
97
  pMgmt->connCache = taosCacheInit(TSDB_DATA_TYPE_UINT, checkTime, false, (__cache_free_fn_t)mndFreeConn, "conn");
1,774✔
98
  if (pMgmt->connCache == NULL) {
1,774!
99
    code = TSDB_CODE_OUT_OF_MEMORY;
×
100
    mError("failed to alloc profile cache since %s", terrstr());
×
101
    TAOS_RETURN(code);
×
102
  }
103

104
  pMgmt->appCache = taosCacheInit(TSDB_DATA_TYPE_BIGINT, checkTime, true, (__cache_free_fn_t)mndFreeApp, "app");
1,774✔
105
  if (pMgmt->appCache == NULL) {
1,774!
106
    code = TSDB_CODE_OUT_OF_MEMORY;
×
107
    mError("failed to alloc profile cache since %s", terrstr());
×
108
    TAOS_RETURN(code);
×
109
  }
110

111
  mndSetMsgHandle(pMnode, TDMT_MND_HEARTBEAT, mndProcessHeartBeatReq);
1,774✔
112
  mndSetMsgHandle(pMnode, TDMT_MND_CONNECT, mndProcessConnectReq);
1,774✔
113
  mndSetMsgHandle(pMnode, TDMT_MND_KILL_QUERY, mndProcessKillQueryReq);
1,774✔
114
  mndSetMsgHandle(pMnode, TDMT_MND_KILL_CONN, mndProcessKillConnReq);
1,774✔
115
  mndSetMsgHandle(pMnode, TDMT_MND_SERVER_VERSION, mndProcessSvrVerReq);
1,774✔
116

117
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndRetrieveConns);
1,774✔
118
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_CONNS, mndCancelGetNextConn);
1,774✔
119
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndRetrieveQueries);
1,774✔
120
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_QUERIES, mndCancelGetNextQuery);
1,774✔
121
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_APPS, mndRetrieveApps);
1,774✔
122
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_APPS, mndCancelGetNextApp);
1,774✔
123

124
  TAOS_RETURN(code);
1,774✔
125
}
126

127
void mndCleanupProfile(SMnode *pMnode) {
1,773✔
128
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
1,773✔
129
  if (pMgmt->connCache != NULL) {
1,773!
130
    taosCacheCleanup(pMgmt->connCache);
1,773✔
131
    pMgmt->connCache = NULL;
1,773✔
132
  }
133

134
  if (pMgmt->appCache != NULL) {
1,773!
135
    taosCacheCleanup(pMgmt->appCache);
1,773✔
136
    pMgmt->appCache = NULL;
1,773✔
137
  }
138
}
1,773✔
139

140
static void setUserInfo2Conn(SConnObj *connObj, char *userApp, uint32_t userIp) {
508,969✔
141
  if (connObj == NULL) {
508,969!
142
    return;
×
143
  }
144
  tstrncpy(connObj->userApp, userApp, sizeof(connObj->userApp));
508,969✔
145
  connObj->userIp = userIp;
508,969✔
146
}
147
static SConnObj *mndCreateConn(SMnode *pMnode, const char *user, int8_t connType, uint32_t ip, uint16_t port,
89,345✔
148
                               int32_t pid, const char *app, int64_t startTime) {
149
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
89,345✔
150

151
  char     connStr[255] = {0};
89,345✔
152
  int32_t  len = tsnprintf(connStr, sizeof(connStr), "%s%d%d%d%s", user, ip, port, pid, app);
89,345✔
153
  uint32_t connId = mndGenerateUid(connStr, len);
89,345✔
154
  if (startTime == 0) startTime = taosGetTimestampMs();
90,664✔
155

156
  SConnObj connObj = {
89,345✔
157
      .id = connId,
158
      .connType = connType,
159
      .appStartTimeMs = startTime,
160
      .pid = pid,
161
      .ip = ip,
162
      .port = port,
163
      .killed = 0,
164
      .loginTimeMs = taosGetTimestampMs(),
89,345✔
165
      .lastAccessTimeMs = 0,
166
      .killId = 0,
167
      .numOfQueries = 0,
168
      .pQueries = NULL,
169
  };
170

171
  connObj.lastAccessTimeMs = connObj.loginTimeMs;
89,345✔
172
  tstrncpy(connObj.user, user, TSDB_USER_LEN);
89,345✔
173
  tstrncpy(connObj.app, app, TSDB_APP_NAME_LEN);
89,345✔
174

175
  SConnObj *pConn =
176
      taosCachePut(pMgmt->connCache, &connId, sizeof(uint32_t), &connObj, sizeof(connObj), CACHE_OBJ_KEEP_TIME * 1000);
89,345✔
177
  if (pConn == NULL) {
89,345!
178
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
179
    mError("conn:%d, failed to put into cache since %s, user:%s", connId, user, terrstr());
×
180
    return NULL;
×
181
  } else {
182
    mTrace("conn:%u, is created, data:%p user:%s", pConn->id, pConn, user);
89,345✔
183
    return pConn;
89,344✔
184
  }
185
}
186

187
static void mndFreeConn(SConnObj *pConn) {
89,345✔
188
  taosWLockLatch(&pConn->queryLock);
89,345✔
189
  taosArrayDestroyEx(pConn->pQueries, tFreeClientHbQueryDesc);
89,345✔
190
  taosWUnLockLatch(&pConn->queryLock);
89,345✔
191

192
  mTrace("conn:%u, is destroyed, data:%p", pConn->id, pConn);
89,345✔
193
}
89,345✔
194

195
static SConnObj *mndAcquireConn(SMnode *pMnode, uint32_t connId) {
508,990✔
196
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
508,990✔
197

198
  SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &connId, sizeof(connId));
508,990✔
199
  if (pConn == NULL) {
509,029✔
200
    mDebug("conn:%u, already destroyed", connId);
1,317✔
201
    return NULL;
1,317✔
202
  }
203

204
  pConn->lastAccessTimeMs = taosGetTimestampMs();
507,698✔
205
  mTrace("conn:%u, acquired from cache, data:%p", pConn->id, pConn);
507,698✔
206
  return pConn;
507,670✔
207
}
208

209
static void mndReleaseConn(SMnode *pMnode, SConnObj *pConn, bool extendLifespan) {
597,042✔
210
  if (pConn == NULL) return;
597,042✔
211
  mTrace("conn:%u, released from cache, data:%p", pConn->id, pConn);
597,034✔
212

213
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
597,034✔
214
  if (extendLifespan) taosCacheTryExtendLifeSpan(pMgmt->connCache, (void **)&pConn);
597,034✔
215
  taosCacheRelease(pMgmt->connCache, (void **)&pConn, false);
597,041✔
216
}
217

218
void *mndGetNextConn(SMnode *pMnode, SCacheIter *pIter) {
1,013,867✔
219
  SConnObj *pConn = NULL;
1,013,867✔
220
  bool      hasNext = taosCacheIterNext(pIter);
1,013,867✔
221
  if (hasNext) {
1,020,271✔
222
    size_t dataLen = 0;
1,002,223✔
223
    pConn = taosCacheIterGetData(pIter, &dataLen);
1,002,223✔
224
  } else {
225
    taosCacheDestroyIter(pIter);
18,048✔
226
  }
227

228
  return pConn;
1,020,135✔
229
}
230

231
static void mndCancelGetNextConn(SMnode *pMnode, void *pIter) {
×
232
  if (pIter != NULL) {
×
233
    taosCacheDestroyIter(pIter);
×
234
  }
235
}
×
236

237
static int32_t mndProcessConnectReq(SRpcMsg *pReq) {
88,035✔
238
  SMnode         *pMnode = pReq->info.node;
88,035✔
239
  SUserObj       *pUser = NULL;
88,035✔
240
  SDbObj         *pDb = NULL;
88,035✔
241
  SConnObj       *pConn = NULL;
88,035✔
242
  int32_t         code = 0;
88,035✔
243
  SConnectReq     connReq = {0};
88,035✔
244
  char            ip[TD_IP_LEN] = {0};
88,035✔
245
  const STraceId *trace = &pReq->info.traceId;
88,035✔
246

247
  if ((code = tDeserializeSConnectReq(pReq->pCont, pReq->contLen, &connReq)) != 0) {
88,035!
248
    goto _OVER;
×
249
  }
250

251
  if ((code = taosCheckVersionCompatibleFromStr(connReq.sVer, td_version, 3)) != 0) {
88,035!
252
    mGError("version not compatible. client version: %s, server version: %s", connReq.sVer, td_version);
×
253
    goto _OVER;
×
254
  }
255

256
  taosInetNtoa(ip, pReq->info.conn.clientIp);
88,036✔
257
  if ((code = mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_CONNECT)) != 0) {
88,034✔
258
    mGError("user:%s, failed to login from %s since %s", pReq->info.conn.user, ip, tstrerror(code));
1!
259
    goto _OVER;
1✔
260
  }
261

262
  code = mndAcquireUser(pMnode, pReq->info.conn.user, &pUser);
88,035✔
263
  if (pUser == NULL) {
88,035!
264
    mGError("user:%s, failed to login from %s while acquire user since %s", pReq->info.conn.user, ip, tstrerror(code));
×
265
    goto _OVER;
×
266
  }
267

268
  if (strncmp(connReq.passwd, pUser->pass, TSDB_PASSWORD_LEN - 1) != 0 && !tsMndSkipGrant) {
88,035!
269
    mGError("user:%s, failed to login from %s since invalid pass, input:%s", pReq->info.conn.user, ip, connReq.passwd);
4!
270
    code = TSDB_CODE_MND_AUTH_FAILURE;
4✔
271
    goto _OVER;
4✔
272
  }
273

274
  if (connReq.db[0]) {
88,031✔
275
    char db[TSDB_DB_FNAME_LEN] = {0};
37✔
276
    (void)snprintf(db, TSDB_DB_FNAME_LEN, "%d%s%s", pUser->acctId, TS_PATH_DELIMITER, connReq.db);
37✔
277
    pDb = mndAcquireDb(pMnode, db);
37✔
278
    if (pDb == NULL) {
37✔
279
      if (0 != strcmp(connReq.db, TSDB_INFORMATION_SCHEMA_DB) &&
7✔
280
          (0 != strcmp(connReq.db, TSDB_PERFORMANCE_SCHEMA_DB))) {
5✔
281
        code = TSDB_CODE_MND_DB_NOT_EXIST;
3✔
282
        mGError("user:%s, failed to login from %s while use db:%s since %s", pReq->info.conn.user, ip, connReq.db,
3!
283
                tstrerror(code));
284
        goto _OVER;
3✔
285
      }
286
    }
287

288
    TAOS_CHECK_GOTO(mndCheckDbPrivilege(pMnode, pReq->info.conn.user, MND_OPER_READ_OR_WRITE_DB, pDb), NULL, _OVER);
34!
289
  }
290

291
  pConn = mndCreateConn(pMnode, pReq->info.conn.user, connReq.connType, pReq->info.conn.clientIp,
88,028✔
292
                        pReq->info.conn.clientPort, connReq.pid, connReq.app, connReq.startTime);
88,028✔
293
  if (pConn == NULL) {
88,027!
294
    code = terrno;
×
295
    mGError("user:%s, failed to login from %s while create connection since %s", pReq->info.conn.user, ip,
×
296
            tstrerror(code));
297
    goto _OVER;
×
298
  }
299

300
  SConnectRsp connectRsp = {0};
88,027✔
301
  connectRsp.acctId = pUser->acctId;
88,027✔
302
  connectRsp.superUser = pUser->superUser;
88,027✔
303
  connectRsp.sysInfo = pUser->sysInfo;
88,027✔
304
  connectRsp.clusterId = pMnode->clusterId;
88,027✔
305
  connectRsp.connId = pConn->id;
88,027✔
306
  connectRsp.connType = connReq.connType;
88,027✔
307
  connectRsp.dnodeNum = mndGetDnodeSize(pMnode);
88,027✔
308
  connectRsp.svrTimestamp = taosGetTimestampSec();
88,028✔
309
  connectRsp.passVer = pUser->passVersion;
88,026✔
310
  connectRsp.authVer = pUser->authVersion;
88,026✔
311
  connectRsp.monitorParas.tsEnableMonitor = tsEnableMonitor;
88,026✔
312
  connectRsp.monitorParas.tsMonitorInterval = tsMonitorInterval;
88,026✔
313
  connectRsp.monitorParas.tsSlowLogScope = tsSlowLogScope;
88,026✔
314
  connectRsp.monitorParas.tsSlowLogMaxLen = tsSlowLogMaxLen;
88,026✔
315
  connectRsp.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold;
88,026✔
316
  connectRsp.enableAuditDelete = tsEnableAuditDelete;
88,026✔
317
  tstrncpy(connectRsp.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN);
88,026✔
318
  connectRsp.whiteListVer = pUser->ipWhiteListVer;
88,026✔
319

320
  tstrncpy(connectRsp.sVer, td_version, sizeof(connectRsp.sVer));
88,026✔
321
  (void)snprintf(connectRsp.sDetailVer, sizeof(connectRsp.sDetailVer), "ver:%s\nbuild:%s\ngitinfo:%s", td_version,
88,026✔
322
                 td_buildinfo, td_gitinfo);
323
  mndGetMnodeEpSet(pMnode, &connectRsp.epSet);
88,026✔
324

325
  int32_t contLen = tSerializeSConnectRsp(NULL, 0, &connectRsp);
88,028✔
326
  if (contLen < 0) {
88,027!
327
    TAOS_CHECK_GOTO(contLen, NULL, _OVER);
×
328
  }
329
  void *pRsp = rpcMallocCont(contLen);
88,027✔
330
  if (pRsp == NULL) {
88,028!
331
    TAOS_CHECK_GOTO(terrno, NULL, _OVER);
×
332
  }
333

334
  contLen = tSerializeSConnectRsp(pRsp, contLen, &connectRsp);
88,028✔
335
  if (contLen < 0) {
88,028!
336
    rpcFreeCont(pRsp);
×
337
    TAOS_CHECK_GOTO(contLen, NULL, _OVER);
×
338
  }
339

340
  pReq->info.rspLen = contLen;
88,028✔
341
  pReq->info.rsp = pRsp;
88,028✔
342

343
  mGDebug("user:%s, login from %s:%d, conn:%u, app:%s", pReq->info.conn.user, ip, pConn->port, pConn->id, connReq.app);
88,028!
344

345
  code = 0;
88,028✔
346

347
  char    detail[1000] = {0};
88,028✔
348
  int32_t nBytes = snprintf(detail, sizeof(detail), "app:%s", connReq.app);
88,028✔
349
  if ((uint32_t)nBytes < sizeof(detail)) {
88,028!
350
    auditRecord(pReq, pMnode->clusterId, "login", "", "", detail, strlen(detail));
88,028✔
351
  } else {
352
    mError("failed to audit logic since %s", tstrerror(TSDB_CODE_OUT_OF_RANGE));
×
353
  }
354

355
_OVER:
×
356

357
  mndReleaseUser(pMnode, pUser);
88,036✔
358
  mndReleaseDb(pMnode, pDb);
88,036✔
359
  mndReleaseConn(pMnode, pConn, true);
88,036✔
360

361
  TAOS_RETURN(code);
88,036✔
362
}
363

364
static int32_t mndSaveQueryList(SConnObj *pConn, SQueryHbReqBasic *pBasic) {
508,958✔
365
  taosWLockLatch(&pConn->queryLock);
508,958✔
366

367
  taosArrayDestroyEx(pConn->pQueries, tFreeClientHbQueryDesc);
509,013✔
368

369
  pConn->pQueries = pBasic->queryDesc;
509,010✔
370
  pConn->numOfQueries = pBasic->queryDesc ? taosArrayGetSize(pBasic->queryDesc) : 0;
509,010✔
371
  pBasic->queryDesc = NULL;
509,005✔
372

373
  mDebug("queries updated in conn %u, num:%d", pConn->id, pConn->numOfQueries);
509,005✔
374

375
  taosWUnLockLatch(&pConn->queryLock);
509,005✔
376

377
  return TSDB_CODE_SUCCESS;
509,023✔
378
}
379

380
static SAppObj *mndCreateApp(SMnode *pMnode, uint32_t clientIp, SAppHbReq *pReq) {
2,049✔
381
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
2,049✔
382

383
  SAppObj app;
384
  app.appId = pReq->appId;
2,049✔
385
  app.ip = clientIp;
2,049✔
386
  app.pid = pReq->pid;
2,049✔
387
  tstrncpy(app.name, pReq->name, sizeof(app.name));
2,049✔
388
  app.startTime = pReq->startTime;
2,049✔
389
  (void)memcpy(&app.summary, &pReq->summary, sizeof(pReq->summary));
2,049✔
390
  app.lastAccessTimeMs = taosGetTimestampMs();
2,049✔
391

392
  SAppObj *pApp =
393
      taosCachePut(pMgmt->appCache, &pReq->appId, sizeof(pReq->appId), &app, sizeof(app), CACHE_OBJ_KEEP_TIME * 1000);
2,049✔
394
  if (pApp == NULL) {
2,049!
395
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
396
    mError("failed to app %" PRIx64 " into cache since %s", pReq->appId, terrstr());
×
397
    return NULL;
×
398
  }
399

400
  mTrace("app %" PRIx64 " is put into cache", pReq->appId);
2,049✔
401
  return pApp;
2,049✔
402
}
403

404
static void mndFreeApp(SAppObj *pApp) { mTrace("app %" PRIx64 " is destroyed", pApp->appId); }
2,049✔
405

406
static SAppObj *mndAcquireApp(SMnode *pMnode, int64_t appId) {
509,002✔
407
  terrno = 0;
509,002✔
408
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
509,018✔
409

410
  SAppObj *pApp = taosCacheAcquireByKey(pMgmt->appCache, &appId, sizeof(appId));
509,018✔
411
  if (pApp == NULL) {
509,026✔
412
    mDebug("app %" PRIx64 " not in cache", appId);
2,049✔
413
    return NULL;
2,049✔
414
  }
415

416
  pApp->lastAccessTimeMs = (uint64_t)taosGetTimestampMs();
506,967✔
417

418
  mTrace("app %" PRIx64 " acquired from cache", appId);
506,967✔
419
  return pApp;
506,962✔
420
}
421

422
static void mndReleaseApp(SMnode *pMnode, SAppObj *pApp) {
508,990✔
423
  if (pApp == NULL) return;
508,990!
424
  mTrace("release app %" PRIx64 " to cache", pApp->appId);
508,990✔
425

426
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
508,990✔
427
  taosCacheRelease(pMgmt->appCache, (void **)&pApp, false);
508,990✔
428
}
429

430
SAppObj *mndGetNextApp(SMnode *pMnode, SCacheIter *pIter) {
224,677✔
431
  SAppObj *pApp = NULL;
224,677✔
432
  bool     hasNext = taosCacheIterNext(pIter);
224,677✔
433
  if (hasNext) {
226,471✔
434
    size_t dataLen = 0;
215,692✔
435
    pApp = taosCacheIterGetData(pIter, &dataLen);
215,692✔
436
  } else {
437
    taosCacheDestroyIter(pIter);
10,779✔
438
  }
439

440
  return pApp;
226,483✔
441
}
442

443
static void mndCancelGetNextApp(SMnode *pMnode, void *pIter) {
×
444
  if (pIter != NULL) {
×
445
    taosCacheDestroyIter(pIter);
×
446
  }
447
}
×
448

449
static SClientHbRsp *mndMqHbBuildRsp(SMnode *pMnode, SClientHbReq *pReq) {
1✔
450
  //
451
  return NULL;
1✔
452
}
453

454
static int32_t mndUpdateAppInfo(SMnode *pMnode, SClientHbReq *pHbReq, SRpcConnInfo *connInfo) {
509,001✔
455
  int32_t    code = 0;
509,001✔
456
  SAppHbReq *pReq = &pHbReq->app;
509,001✔
457
  SAppObj   *pApp = mndAcquireApp(pMnode, pReq->appId);
509,001✔
458
  if (pApp == NULL) {
509,012✔
459
    pApp = mndCreateApp(pMnode, connInfo->clientIp, pReq);
2,049✔
460
    if (pApp == NULL) {
2,049!
461
      mError("failed to create new app %" PRIx64 " since %s", pReq->appId, terrstr());
×
462
      code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
463
      if (terrno != 0) code = terrno;
×
464
      TAOS_RETURN(code);
×
465
    } else {
466
      mDebug("a new app %" PRIx64 " is created", pReq->appId);
2,049✔
467
      mndReleaseApp(pMnode, pApp);
2,049✔
468
      return TSDB_CODE_SUCCESS;
2,049✔
469
    }
470
  }
471

472
  (void)memcpy(&pApp->summary, &pReq->summary, sizeof(pReq->summary));
506,963✔
473

474
  mndReleaseApp(pMnode, pApp);
506,963✔
475

476
  return TSDB_CODE_SUCCESS;
506,951✔
477
}
478

479
static int32_t mndGetOnlineDnodeNum(SMnode *pMnode, int32_t *num) {
394,367✔
480
  SSdb      *pSdb = pMnode->pSdb;
394,367✔
481
  SDnodeObj *pDnode = NULL;
394,367✔
482
  int64_t    curMs = taosGetTimestampMs();
394,397✔
483
  void      *pIter = NULL;
394,397✔
484

485
  while (true) {
433,682✔
486
    pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pDnode);
828,079✔
487
    if (pIter == NULL) break;
828,110✔
488

489
    bool online = mndIsDnodeOnline(pDnode, curMs);
433,626✔
490
    if (online) {
433,546✔
491
      (*num)++;
430,794✔
492
    }
493

494
    sdbRelease(pSdb, pDnode);
433,546✔
495
  }
496

497
  return TSDB_CODE_SUCCESS;
394,484✔
498
}
499

500
static int32_t mndProcessQueryHeartBeat(SMnode *pMnode, SRpcMsg *pMsg, SClientHbReq *pHbReq,
513,383✔
501
                                        SClientHbBatchRsp *pBatchRsp, SConnPreparedObj *pObj) {
502
  int32_t       code = 0;
513,383✔
503
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
513,383✔
504
  SClientHbRsp  hbRsp = {.connKey = pHbReq->connKey, .status = 0, .info = NULL, .query = NULL};
513,383✔
505
  SRpcConnInfo  connInfo = pMsg->info.conn;
513,383✔
506

507
  if (0 != pHbReq->app.appId) {
513,383✔
508
    TAOS_CHECK_RETURN(mndUpdateAppInfo(pMnode, pHbReq, &connInfo));
509,021!
509
  }
510

511
  if (pHbReq->query) {
513,388✔
512
    SQueryHbReqBasic *pBasic = pHbReq->query;
509,009✔
513

514
    SConnObj *pConn = mndAcquireConn(pMnode, pBasic->connId);
509,009✔
515
    if (pConn == NULL) {
508,989✔
516
      pConn = mndCreateConn(pMnode, connInfo.user, CONN_TYPE__QUERY, connInfo.clientIp, connInfo.clientPort,
1,317✔
517
                            pHbReq->app.pid, pHbReq->app.name, 0);
1,317✔
518
      if (pConn == NULL) {
1,317!
519
        mError("user:%s, conn:%u is freed and failed to create new since %s", connInfo.user, pBasic->connId, terrstr());
×
520
        code = TSDB_CODE_MND_RETURN_VALUE_NULL;
×
521
        if (terrno != 0) code = terrno;
×
522
        TAOS_RETURN(code);
×
523
      } else {
524
        mDebug("user:%s, conn:%u is freed, will create a new conn:%u", connInfo.user, pBasic->connId, pConn->id);
1,317✔
525
      }
526
    }
527

528
    setUserInfo2Conn(pConn, pHbReq->userApp, pHbReq->userIp);
508,989✔
529
    SQueryHbRspBasic *rspBasic = taosMemoryCalloc(1, sizeof(SQueryHbRspBasic));
508,984!
530
    if (rspBasic == NULL) {
508,940!
531
      mndReleaseConn(pMnode, pConn, true);
×
532
      code = terrno;
×
533
      mError("user:%s, conn:%u failed to process hb while since %s", pConn->user, pBasic->connId, terrstr());
×
534
      TAOS_RETURN(code);
×
535
    }
536

537
    TAOS_CHECK_RETURN(mndSaveQueryList(pConn, pBasic));
508,940!
538
    if (pConn->killed != 0) {
509,021!
539
      rspBasic->killConnection = 1;
×
540
    }
541

542
    if (pConn->killId != 0) {
509,021!
543
      rspBasic->killRid = pConn->killId;
×
544
      pConn->killId = 0;
×
545
    }
546

547
    rspBasic->connId = pConn->id;
509,021✔
548
    rspBasic->connId = pConn->id;
509,021✔
549
    rspBasic->totalDnodes = pObj->totalDnodes;
509,021✔
550
    rspBasic->onlineDnodes = pObj->onlineDnodes;
509,021✔
551
    rspBasic->epSet = pObj->epSet;
509,021✔
552
    rspBasic->pQnodeList = taosArrayDup(pObj->pQnodeList, NULL);
509,021✔
553

554
    mndReleaseConn(pMnode, pConn, true);
509,007✔
555

556
    hbRsp.query = rspBasic;
509,021✔
557
  } else {
558
    mDebug("no query info in hb msg");
4,379✔
559
  }
560

561
  int32_t kvNum = taosHashGetSize(pHbReq->info);
513,400✔
562
  if (NULL == pHbReq->info || kvNum <= 0) {
513,381!
563
    if (taosArrayPush(pBatchRsp->rsps, &hbRsp) == NULL) {
573,559!
564
      mError("failed to put rsp into array, but continue at this heartbeat");
×
565
    }
566
    return TSDB_CODE_SUCCESS;
286,793✔
567
  }
568

569
  hbRsp.info = taosArrayInit(kvNum, sizeof(SKv));
226,615✔
570
  if (NULL == hbRsp.info) {
226,618!
571
    mError("taosArrayInit %d rsp kv failed", kvNum);
×
572
    code = terrno;
×
573
    tFreeClientHbRsp(&hbRsp);
574
    TAOS_RETURN(code);
×
575
  }
576

577
#ifdef TD_ENTERPRISE
578
  bool             needCheck = true;
226,618✔
579
  int32_t          key = HEARTBEAT_KEY_DYN_VIEW;
226,618✔
580
  SDynViewVersion *pDynViewVer = NULL;
226,618✔
581
  SKv             *pKv = taosHashGet(pHbReq->info, &key, sizeof(key));
226,618✔
582
  if (NULL != pKv) {
226,611✔
583
    pDynViewVer = pKv->value;
2✔
584
    mTrace("recv view dyn ver, bootTs:%" PRId64 ", ver:%" PRIu64, pDynViewVer->svrBootTs, pDynViewVer->dynViewVer);
2!
585

586
    SDynViewVersion *pRspVer = NULL;
2✔
587
    if (0 != (code = mndValidateDynViewVersion(pMnode, pDynViewVer, &needCheck, &pRspVer))) {
2!
588
      TAOS_RETURN(code);
×
589
    }
590

591
    if (needCheck) {
2!
592
      SKv kv1 = {.key = HEARTBEAT_KEY_DYN_VIEW, .valueLen = sizeof(*pDynViewVer), .value = pRspVer};
2✔
593
      if (taosArrayPush(hbRsp.info, &kv1) == NULL) {
4!
594
        if (terrno != 0) code = terrno;
×
595
        TAOS_RETURN(code);
×
596
      };
597
      mTrace("need to check view ver, lastest bootTs:%" PRId64 ", ver:%" PRIu64, pRspVer->svrBootTs,
2!
598
             pRspVer->dynViewVer);
599
    }
600
  }
601
#endif
602

603
  void *pIter = taosHashIterate(pHbReq->info, NULL);
226,611✔
604
  while (pIter != NULL) {
563,774✔
605
    SKv *kv = pIter;
337,157✔
606

607
    switch (kv->key) {
337,157!
608
      case HEARTBEAT_KEY_USER_AUTHINFO: {
226,594✔
609
        void   *rspMsg = NULL;
226,594✔
610
        int32_t rspLen = 0;
226,594✔
611
        (void)mndValidateUserAuthInfo(pMnode, kv->value, kv->valueLen / sizeof(SUserAuthVersion), &rspMsg, &rspLen,
226,594✔
612
                                      pObj->ipWhiteListVer);
613
        if (rspMsg && rspLen > 0) {
226,597!
614
          SKv kv1 = {.key = HEARTBEAT_KEY_USER_AUTHINFO, .valueLen = rspLen, .value = rspMsg};
14,677✔
615
          if (taosArrayPush(hbRsp.info, &kv1) == NULL) {
29,354!
616
            mError("failed to put kv into array, but continue at this heartbeat");
×
617
          }
618
        }
619
        break;
226,597✔
620
      }
621
      case HEARTBEAT_KEY_DBINFO: {
45,878✔
622
        void   *rspMsg = NULL;
45,878✔
623
        int32_t rspLen = 0;
45,878✔
624
        (void)mndValidateDbInfo(pMnode, kv->value, kv->valueLen / sizeof(SDbCacheInfo), &rspMsg, &rspLen);
45,878✔
625
        if (rspMsg && rspLen > 0) {
45,878!
626
          SKv kv1 = {.key = HEARTBEAT_KEY_DBINFO, .valueLen = rspLen, .value = rspMsg};
45,878✔
627
          if (taosArrayPush(hbRsp.info, &kv1) == NULL) {
91,756!
628
            mError("failed to put kv into array, but continue at this heartbeat");
×
629
          }
630
        }
631
        break;
45,878✔
632
      }
633
      case HEARTBEAT_KEY_STBINFO: {
64,249✔
634
        void   *rspMsg = NULL;
64,249✔
635
        int32_t rspLen = 0;
64,249✔
636
        (void)mndValidateStbInfo(pMnode, kv->value, kv->valueLen / sizeof(SSTableVersion), &rspMsg, &rspLen);
64,249✔
637
        if (rspMsg && rspLen > 0) {
64,249!
638
          SKv kv1 = {.key = HEARTBEAT_KEY_STBINFO, .valueLen = rspLen, .value = rspMsg};
64,249✔
639
          if (taosArrayPush(hbRsp.info, &kv1) == NULL) {
128,498!
640
            mError("failed to put kv into array, but continue at this heartbeat");
×
641
          }
642
        }
643
        break;
64,249✔
644
      }
645
#ifdef TD_ENTERPRISE
646
      case HEARTBEAT_KEY_DYN_VIEW: {
2✔
647
        break;
2✔
648
      }
649
      case HEARTBEAT_KEY_VIEWINFO: {
2✔
650
        if (!needCheck) {
2!
651
          break;
×
652
        }
653

654
        void   *rspMsg = NULL;
2✔
655
        int32_t rspLen = 0;
2✔
656
        (void)mndValidateViewInfo(pMnode, kv->value, kv->valueLen / sizeof(SViewVersion), &rspMsg, &rspLen);
2✔
657
        if (rspMsg && rspLen > 0) {
2!
658
          SKv kv1 = {.key = HEARTBEAT_KEY_VIEWINFO, .valueLen = rspLen, .value = rspMsg};
2✔
659
          if (taosArrayPush(hbRsp.info, &kv1) == NULL) {
4!
660
            mError("failed to put kv into array, but continue at this heartbeat");
×
661
          }
662
        }
663
        break;
2✔
664
      }
665
#endif
666
      case HEARTBEAT_KEY_TSMA: {
432✔
667
        void   *rspMsg = NULL;
432✔
668
        int32_t rspLen = 0;
432✔
669
        (void)mndValidateTSMAInfo(pMnode, kv->value, kv->valueLen / sizeof(STSMAVersion), &rspMsg, &rspLen);
432✔
670
        if (rspMsg && rspLen > 0) {
432!
671
          SKv kv = {.key = HEARTBEAT_KEY_TSMA, .valueLen = rspLen, .value = rspMsg};
432✔
672
          if (taosArrayPush(hbRsp.info, &kv) == NULL) {
864!
673
            mError("failed to put kv into array, but continue at this heartbeat");
×
674
          }
675
        }
676
        break;
432✔
677
      }
678
      default:
×
679
        mError("invalid kv key:%d", kv->key);
×
680
        hbRsp.status = TSDB_CODE_APP_ERROR;
×
681
        break;
×
682
    }
683

684
    pIter = taosHashIterate(pHbReq->info, pIter);
337,160✔
685
  }
686

687
  if (taosArrayPush(pBatchRsp->rsps, &hbRsp) == NULL) {
453,233!
688
    if (terrno != 0) code = terrno;
×
689
  }
690
  TAOS_RETURN(code);
226,616✔
691
}
692

693
static int32_t mndProcessHeartBeatReq(SRpcMsg *pReq) {
394,361✔
694
  int32_t code = 0;
394,361✔
695
  int32_t lino = 0;
394,361✔
696
  SMnode *pMnode = pReq->info.node;
394,361✔
697

698
  SClientHbBatchReq batchReq = {0};
394,361✔
699
  if (tDeserializeSClientHbBatchReq(pReq->pCont, pReq->contLen, &batchReq) != 0) {
394,361!
700
    taosArrayDestroyEx(batchReq.reqs, tFreeClientHbReq);
×
701
    code = TSDB_CODE_INVALID_MSG;
×
702
    TAOS_RETURN(code);
×
703
  }
704

705
  SConnPreparedObj obj = {0};
394,416✔
706
  obj.totalDnodes = mndGetDnodeSize(pMnode);
394,416✔
707
  obj.ipWhiteListVer = batchReq.ipWhiteList;
394,436✔
708
  TAOS_CHECK_RETURN(mndGetOnlineDnodeNum(pMnode, &obj.onlineDnodes));
394,436!
709
  mndGetMnodeEpSet(pMnode, &obj.epSet);
394,479✔
710
  TAOS_CHECK_RETURN(mndCreateQnodeList(pMnode, &obj.pQnodeList, -1));
394,477!
711

712
  SClientHbBatchRsp batchRsp = {0};
394,491✔
713
  batchRsp.svrTimestamp = taosGetTimestampSec();
394,491✔
714
  batchRsp.rsps = taosArrayInit(0, sizeof(SClientHbRsp));
394,484✔
715
  if (batchRsp.rsps == NULL) {
394,490!
716
    TAOS_CHECK_EXIT(terrno);
×
717
  }
718
  batchRsp.monitorParas.tsEnableMonitor = tsEnableMonitor;
394,490✔
719
  batchRsp.monitorParas.tsMonitorInterval = tsMonitorInterval;
394,490✔
720
  batchRsp.monitorParas.tsSlowLogThreshold = tsSlowLogThreshold;
394,490✔
721
  tstrncpy(batchRsp.monitorParas.tsSlowLogExceptDb, tsSlowLogExceptDb, TSDB_DB_NAME_LEN);
394,490✔
722
  batchRsp.monitorParas.tsSlowLogMaxLen = tsSlowLogMaxLen;
394,490✔
723
  batchRsp.monitorParas.tsSlowLogScope = tsSlowLogScope;
394,490✔
724
  batchRsp.enableAuditDelete = tsEnableAuditDelete;
394,490✔
725

726
  int32_t sz = taosArrayGetSize(batchReq.reqs);
394,490✔
727
  for (int i = 0; i < sz; i++) {
907,755✔
728
    SClientHbReq *pHbReq = taosArrayGet(batchReq.reqs, i);
513,389✔
729
    if (pHbReq->connKey.connType == CONN_TYPE__QUERY) {
513,387!
730
      TAOS_CHECK_EXIT(mndProcessQueryHeartBeat(pMnode, pReq, pHbReq, &batchRsp, &obj));
513,387!
731
    } else if (pHbReq->connKey.connType == CONN_TYPE__TMQ) {
×
732
      SClientHbRsp *pRsp = mndMqHbBuildRsp(pMnode, pHbReq);
1✔
733
      if (pRsp != NULL) {
1!
734
        if (taosArrayPush(batchRsp.rsps, pRsp) == NULL) {
×
735
          mError("failed to put kv into array, but continue at this heartbeat");
×
736
        }
737
        taosMemoryFree(pRsp);
×
738
      }
739
    }
740
  }
741
  taosArrayDestroyEx(batchReq.reqs, tFreeClientHbReq);
394,366✔
742

743
  int32_t tlen = tSerializeSClientHbBatchRsp(NULL, 0, &batchRsp);
394,427✔
744
  if (tlen < 0) {
393,076!
745
    TAOS_CHECK_EXIT(tlen);
×
746
  }
747
  void *buf = rpcMallocCont(tlen);
393,076✔
748
  if (!buf) {
393,924!
749
    TAOS_CHECK_EXIT(terrno);
×
750
  }
751
  tlen = tSerializeSClientHbBatchRsp(buf, tlen, &batchRsp);
393,924✔
752
  if (tlen < 0) {
394,179!
753
    rpcFreeCont(buf);
×
754
    TAOS_CHECK_EXIT(tlen);
×
755
  }
756
  pReq->info.rspLen = tlen;
394,258✔
757
  pReq->info.rsp = buf;
394,258✔
758
_exit:
394,258✔
759
  tFreeClientHbBatchRsp(&batchRsp);
760

761
  taosArrayDestroy(obj.pQnodeList);
394,405✔
762

763
  TAOS_RETURN(code);
394,382✔
764
}
765

766
static int32_t mndProcessKillQueryReq(SRpcMsg *pReq) {
1✔
767
  int32_t       code = 0;
1✔
768
  SMnode       *pMnode = pReq->info.node;
1✔
769
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
1✔
770

771
  SKillQueryReq killReq = {0};
1✔
772
  TAOS_CHECK_RETURN(tDeserializeSKillQueryReq(pReq->pCont, pReq->contLen, &killReq));
1!
773

774
  mInfo("kill query msg is received, queryId:%s", killReq.queryStrId);
1!
775
  TAOS_CHECK_RETURN(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_QUERY));
1!
776

777
  int32_t  connId = 0;
1✔
778
  uint64_t queryId = 0;
1✔
779
  char    *p = strchr(killReq.queryStrId, ':');
1✔
780
  if (NULL == p) {
1!
781
    mError("invalid query id %s", killReq.queryStrId);
×
782
    code = TSDB_CODE_MND_INVALID_QUERY_ID;
×
783
    TAOS_RETURN(code);
×
784
  }
785
  *p = 0;
1✔
786
  connId = taosStr2Int32(killReq.queryStrId, NULL, 16);
1✔
787
  queryId = taosStr2UInt64(p + 1, NULL, 16);
1✔
788

789
  SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &connId, sizeof(int32_t));
1✔
790
  if (pConn == NULL) {
1!
791
    mError("connId:%x, failed to kill queryId:%" PRIx64 ", conn not exist", connId, queryId);
1!
792
    code = TSDB_CODE_MND_INVALID_CONN_ID;
1✔
793
    TAOS_RETURN(code);
1✔
794
  } else {
795
    mInfo("connId:%x, queryId:%" PRIx64 " is killed by user:%s", connId, queryId, pReq->info.conn.user);
×
796
    pConn->killId = queryId;
×
797
    taosCacheRelease(pMgmt->connCache, (void **)&pConn, false);
×
798
    TAOS_RETURN(code);
×
799
  }
800
}
801

802
static int32_t mndProcessKillConnReq(SRpcMsg *pReq) {
2✔
803
  int32_t       code = 0;
2✔
804
  SMnode       *pMnode = pReq->info.node;
2✔
805
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
2✔
806

807
  SKillConnReq killReq = {0};
2✔
808
  TAOS_CHECK_RETURN(tDeserializeSKillConnReq(pReq->pCont, pReq->contLen, &killReq));
2!
809

810
  TAOS_CHECK_RETURN(mndCheckOperPrivilege(pMnode, pReq->info.conn.user, MND_OPER_KILL_CONN));
2✔
811

812
  SConnObj *pConn = taosCacheAcquireByKey(pMgmt->connCache, &killReq.connId, sizeof(uint32_t));
1✔
813
  if (pConn == NULL) {
1!
814
    mError("connId:%u, failed to kill connection, conn not exist", killReq.connId);
1!
815
    code = TSDB_CODE_MND_INVALID_CONN_ID;
1✔
816
    TAOS_RETURN(code);
1✔
817
  } else {
818
    mInfo("connId:%u, is killed by user:%s", killReq.connId, pReq->info.conn.user);
×
819
    pConn->killed = 1;
×
820
    taosCacheRelease(pMgmt->connCache, (void **)&pConn, false);
×
821
    TAOS_RETURN(code);
×
822
  }
823
}
824

825
static int32_t mndProcessSvrVerReq(SRpcMsg *pReq) {
×
826
  int32_t       code = 0;
×
827
  int32_t       lino = 0;
×
828
  SServerVerRsp rsp = {0};
×
829
  tstrncpy(rsp.ver, td_version, sizeof(rsp.ver));
×
830

831
  int32_t contLen = tSerializeSServerVerRsp(NULL, 0, &rsp);
×
832
  if (contLen < 0) {
×
833
    TAOS_CHECK_EXIT(contLen);
×
834
  }
835
  void *pRsp = rpcMallocCont(contLen);
×
836
  if (pRsp == NULL) {
×
837
    TAOS_CHECK_EXIT(terrno);
×
838
  }
839
  contLen = tSerializeSServerVerRsp(pRsp, contLen, &rsp);
×
840
  if (contLen < 0) {
×
841
    rpcFreeCont(pRsp);
×
842
    TAOS_CHECK_EXIT(contLen);
×
843
  }
844

845
  pReq->info.rspLen = contLen;
×
846
  pReq->info.rsp = pRsp;
×
847

848
_exit:
×
849

850
  TAOS_RETURN(code);
×
851
}
852

853
static int32_t mndRetrieveConns(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
6,509✔
854
  SMnode   *pMnode = pReq->info.node;
6,509✔
855
  SSdb     *pSdb = pMnode->pSdb;
6,509✔
856
  int32_t   numOfRows = 0;
6,509✔
857
  int32_t   cols = 0;
6,509✔
858
  int32_t   code = 0;
6,509✔
859
  SConnObj *pConn = NULL;
6,509✔
860

861
  if (pShow->pIter == NULL) {
6,509!
862
    SProfileMgmt *pMgmt = &pMnode->profileMgmt;
6,514✔
863
    pShow->pIter = taosCacheCreateIter(pMgmt->connCache);
6,514✔
864
    if (!pShow->pIter) return terrno;
6,517!
865
  }
866

867
  while (numOfRows < rows) {
382,301✔
868
    pConn = mndGetNextConn(pMnode, pShow->pIter);
381,776✔
869
    if (pConn == NULL) {
387,781✔
870
      pShow->pIter = NULL;
6,520✔
871
      break;
6,520✔
872
    }
873

874
    if ((taosGetTimestampMs() - pConn->lastAccessTimeMs) > ((int64_t)CACHE_OBJ_KEEP_TIME * 1000)) {
381,186✔
875
      continue;
34,412✔
876
    }
877

878
    cols = 0;
346,774✔
879

880
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
346,774✔
881
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->id, false);
345,299✔
882
    if (code != 0) {
342,875!
883
      mError("failed to set conn id:%u since %s", pConn->id, tstrerror(code));
×
884
      return code;
×
885
    }
886

887
    char user[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0};
342,875✔
888
    STR_TO_VARSTR(user, pConn->user);
342,875✔
889
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
342,875✔
890
    code = colDataSetVal(pColInfo, numOfRows, (const char *)user, false);
342,180✔
891
    if (code != 0) {
341,994!
892
      mError("failed to set user since %s", tstrerror(code));
×
893
      return code;
×
894
    }
895

896
    char app[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE];
897
    STR_TO_VARSTR(app, pConn->app);
341,994✔
898
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
341,994✔
899
    code = colDataSetVal(pColInfo, numOfRows, (const char *)app, false);
341,823✔
900
    if (code != 0) {
341,737!
901
      mError("failed to set app since %s", tstrerror(code));
×
902
      return code;
×
903
    }
904

905
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
341,737✔
906
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->pid, false);
340,353✔
907
    if (code != 0) {
340,901!
908
      mError("failed to set conn id:%u since %s", pConn->id, tstrerror(code));
×
909
      return code;
×
910
    }
911

912
    char endpoint[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
340,901✔
913
    taosInetNtoa(varDataVal(endpoint), pConn->ip);
340,901✔
914
    (void)tsnprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)),
346,524✔
915
              sizeof(endpoint) - VARSTR_HEADER_SIZE - strlen(varDataVal(endpoint)), ":%d", pConn->port);
346,524✔
916
    varDataLen(endpoint) = strlen(varDataVal(endpoint));
346,683✔
917
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
346,683✔
918
    code = colDataSetVal(pColInfo, numOfRows, (const char *)endpoint, false);
344,181✔
919
    if (code != 0) {
341,833!
920
      mError("failed to set endpoint since %s", tstrerror(code));
×
921
      return code;
×
922
    }
923

924
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
341,833✔
925
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->loginTimeMs, false);
340,137✔
926
    if (code != 0) {
339,917!
927
      mError("failed to set login time since %s", tstrerror(code));
×
928
      return code;
×
929
    }
930

931
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
339,917✔
932
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pConn->lastAccessTimeMs, false);
338,426✔
933
    if (code != 0) {
339,136!
934
      mError("failed to set last access time since %s", tstrerror(code));
×
935
      return code;
×
936
    }
937

938
    char userApp[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE];
939
    STR_TO_VARSTR(userApp, pConn->userApp);
339,136✔
940
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
339,136✔
941
    code = colDataSetVal(pColInfo, numOfRows, (const char *)userApp, false);
338,438✔
942
    if (code != 0) {
340,886!
943
      mError("failed to set user app since %s", tstrerror(code));
×
944
      return code;
×
945
    }
946

947
    char userIp[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
340,886✔
948
    if (pConn->userIp != 0 && pConn->userIp != INADDR_NONE) {
340,886!
949
      taosInetNtoa(varDataVal(userIp), pConn->userIp);
×
950
      varDataLen(userIp) = strlen(varDataVal(userIp));
×
951
    }
952
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
340,886✔
953
    code = colDataSetVal(pColInfo, numOfRows, (const char *)userIp, false);
341,087✔
954
    if (code != 0) {
341,372!
955
      mError("failed to set user ip since %s", tstrerror(code));
×
956
      return code;
×
957
    }
958

959
    numOfRows++;
341,372✔
960
  }
961

962
  pShow->numOfRows += numOfRows;
7,045✔
963
  return numOfRows;
7,045✔
964
}
965

966
/**
967
 * @param pConn the conn queries pack from
968
 * @param[out] pBlock the block data packed into
969
 * @param offset skip [offset] queries in pConn
970
 * @param rowsToPack at most rows to pack
971
 * @return rows packed
972
 */
973
static int32_t packQueriesIntoBlock(SShowObj *pShow, SConnObj *pConn, SSDataBlock *pBlock, uint32_t offset,
620,774✔
974
                                    uint32_t rowsToPack) {
975
  int32_t cols = 0;
620,774✔
976
  int32_t code = 0;
620,774✔
977
  taosRLockLatch(&pConn->queryLock);
620,774✔
978
  int32_t numOfQueries = taosArrayGetSize(pConn->pQueries);
620,799✔
979
  if (NULL == pConn->pQueries || numOfQueries <= offset) {
620,098✔
980
    taosRUnLockLatch(&pConn->queryLock);
187,911✔
981
    return 0;
188,273✔
982
  }
983

984
  int32_t i = offset;
432,187✔
985
  for (; i < numOfQueries && (i - offset) < rowsToPack; ++i) {
909,549!
986
    int32_t     curRowIndex = pBlock->info.rows;
480,877✔
987
    SQueryDesc *pQuery = taosArrayGet(pConn->pQueries, i);
480,877✔
988
    cols = 0;
480,233✔
989

990
    char queryId[26 + VARSTR_HEADER_SIZE] = {0};
480,233✔
991
    (void)tsnprintf(&queryId[VARSTR_HEADER_SIZE], sizeof(queryId) - VARSTR_HEADER_SIZE, "%x:%" PRIx64, pConn->id,
480,233✔
992
              pQuery->reqRid);
993
    varDataLen(queryId) = strlen(&queryId[VARSTR_HEADER_SIZE]);
481,732✔
994
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
481,732✔
995
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)queryId, false);
480,228✔
996
    if (code != 0) {
478,621!
997
      mError("failed to set query id:%s since %s", queryId, tstrerror(code));
×
998
      taosRUnLockLatch(&pConn->queryLock);
×
999
      return code;
×
1000
    }
1001

1002
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
478,621✔
1003
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->queryId, false);
477,858✔
1004
    if (code != 0) {
477,494!
1005
      mError("failed to set query id:%" PRIx64 " since %s", pQuery->queryId, tstrerror(code));
×
1006
      taosRUnLockLatch(&pConn->queryLock);
×
1007
      return code;
×
1008
    }
1009

1010
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
477,494✔
1011
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->id, false);
476,644✔
1012
    if (code != 0) {
476,766!
1013
      mError("failed to set conn id:%u since %s", pConn->id, tstrerror(code));
×
1014
      taosRUnLockLatch(&pConn->queryLock);
×
1015
      return code;
×
1016
    }
1017

1018
    char app[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE];
1019
    STR_TO_VARSTR(app, pConn->app);
476,766✔
1020
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
476,766✔
1021
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)app, false);
476,457✔
1022
    if (code != 0) {
477,844!
1023
      mError("failed to set app since %s", tstrerror(code));
×
1024
      taosRUnLockLatch(&pConn->queryLock);
×
1025
      return code;
×
1026
    }
1027

1028
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
477,844✔
1029
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pConn->pid, false);
477,008✔
1030
    if (code != 0) {
476,849!
1031
      mError("failed to set conn id:%u since %s", pConn->id, tstrerror(code));
×
1032
      taosRUnLockLatch(&pConn->queryLock);
×
1033
      return code;
×
1034
    }
1035

1036
    char user[TSDB_USER_LEN + VARSTR_HEADER_SIZE] = {0};
476,849✔
1037
    STR_TO_VARSTR(user, pConn->user);
476,849✔
1038
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
476,849✔
1039
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)user, false);
476,826✔
1040
    if (code != 0) {
478,018!
1041
      mError("failed to set user since %s", tstrerror(code));
×
1042
      taosRUnLockLatch(&pConn->queryLock);
×
1043
      return code;
×
1044
    }
1045

1046
    char endpoint[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
478,018✔
1047
    taosInetNtoa(varDataVal(endpoint), pConn->ip);
478,018✔
1048
    (void)tsnprintf(varDataVal(endpoint) + strlen(varDataVal(endpoint)),
481,599✔
1049
              sizeof(endpoint) - VARSTR_HEADER_SIZE - strlen(varDataVal(endpoint)), ":%d", pConn->port);
481,599✔
1050
    varDataLen(endpoint) = strlen(&endpoint[VARSTR_HEADER_SIZE]);
481,634✔
1051
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
481,634✔
1052
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)endpoint, false);
480,079✔
1053
    if (code != 0) {
477,905!
1054
      mError("failed to set endpoint since %s", tstrerror(code));
×
1055
      taosRUnLockLatch(&pConn->queryLock);
×
1056
      return code;
×
1057
    }
1058

1059
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
477,905✔
1060
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stime, false);
477,006✔
1061
    if (code != 0) {
476,601!
1062
      mError("failed to set start time since %s", tstrerror(code));
×
1063
      taosRUnLockLatch(&pConn->queryLock);
×
1064
      return code;
×
1065
    }
1066

1067
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
476,601✔
1068
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->useconds, false);
475,823✔
1069
    if (code != 0) {
476,014!
1070
      mError("failed to set useconds since %s", tstrerror(code));
×
1071
      taosRUnLockLatch(&pConn->queryLock);
×
1072
      return code;
×
1073
    }
1074

1075
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
476,014✔
1076
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->stableQuery, false);
475,284✔
1077
    if (code != 0) {
475,922!
1078
      mError("failed to set stable query since %s", tstrerror(code));
×
1079
      taosRUnLockLatch(&pConn->queryLock);
×
1080
      return code;
×
1081
    }
1082

1083
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
475,922✔
1084
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->isSubQuery, false);
475,246✔
1085
    if (code != 0) {
475,834!
1086
      mError("failed to set sub query since %s", tstrerror(code));
×
1087
      taosRUnLockLatch(&pConn->queryLock);
×
1088
      return code;
×
1089
    }
1090

1091
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
475,834✔
1092
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)&pQuery->subPlanNum, false);
475,133✔
1093
    if (code != 0) {
481,290!
1094
      mError("failed to set sub plan num since %s", tstrerror(code));
×
1095
      taosRUnLockLatch(&pConn->queryLock);
×
1096
      return code;
×
1097
    }
1098

1099
    char    subStatus[TSDB_SHOW_SUBQUERY_LEN + VARSTR_HEADER_SIZE] = {0};
481,290✔
1100
    int64_t reserve = 64;
481,290✔
1101
    int32_t strSize = sizeof(subStatus);
481,290✔
1102
    int32_t offset = VARSTR_HEADER_SIZE;
481,290✔
1103
    for (int32_t i = 0; i < pQuery->subPlanNum && offset + reserve < strSize; ++i) {
1,693,732✔
1104
      if (i) {
1,211,914✔
1105
        offset += tsnprintf(subStatus + offset, sizeof(subStatus) - offset, ",");
731,548✔
1106
      }
1107
      if (offset + reserve < strSize) {
1,211,518!
1108
        SQuerySubDesc *pDesc = taosArrayGet(pQuery->subDesc, i);
1,211,518✔
1109
        offset +=
1,212,442✔
1110
            tsnprintf(subStatus + offset, sizeof(subStatus) - offset, "%" PRIu64 ":%s", pDesc->tid, pDesc->status);
1,203,620✔
1111
      } else {
1112
        break;
×
1113
      }
1114
    }
1115
    varDataLen(subStatus) = strlen(&subStatus[VARSTR_HEADER_SIZE]);
481,818✔
1116
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
481,818✔
1117
    code = colDataSetVal(pColInfo, curRowIndex, subStatus, (varDataLen(subStatus) == 0) ? true : false);
479,790✔
1118
    if (code != 0) {
478,463!
1119
      mError("failed to set sub status since %s", tstrerror(code));
×
1120
      taosRUnLockLatch(&pConn->queryLock);
×
1121
      return code;
×
1122
    }
1123

1124
    char sql[TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE] = {0};
478,463✔
1125
    STR_TO_VARSTR(sql, pQuery->sql);
478,463✔
1126
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
478,463✔
1127
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)sql, false);
479,826✔
1128
    if (code != 0) {
477,848!
1129
      mError("failed to set sql since %s", tstrerror(code));
×
1130
      taosRUnLockLatch(&pConn->queryLock);
×
1131
      return code;
×
1132
    }
1133

1134
    char userApp[TSDB_APP_NAME_LEN + VARSTR_HEADER_SIZE];
1135
    STR_TO_VARSTR(userApp, pConn->userApp);
477,848✔
1136
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
477,848✔
1137
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)userApp, false);
477,346✔
1138
    if (code != 0) {
477,060!
1139
      mError("failed to set user app since %s", tstrerror(code));
×
1140
      taosRUnLockLatch(&pConn->queryLock);
×
1141
      return code;
×
1142
    }
1143

1144
    char userIp[TD_IP_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
477,060✔
1145
    if (pConn->userIp != 0 && pConn->userIp != INADDR_NONE) {
477,060!
1146
      taosInetNtoa(varDataVal(userIp), pConn->userIp);
×
1147
      varDataLen(userIp) = strlen(varDataVal(userIp));
×
1148
    }
1149
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
477,060✔
1150
    code = colDataSetVal(pColInfo, curRowIndex, (const char *)userIp, false);
477,238✔
1151
    if (code != 0) {
477,362!
1152
      mError("failed to set user ip since %s", tstrerror(code));
×
1153
      taosRUnLockLatch(&pConn->queryLock);
×
1154
      return code;
×
1155
    }
1156

1157
    pBlock->info.rows++;
477,362✔
1158
  }
1159

1160
  taosRUnLockLatch(&pConn->queryLock);
428,672✔
1161
  return i - offset;
432,492✔
1162
}
1163

1164
static int32_t mndRetrieveQueries(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
11,522✔
1165
  SMnode   *pMnode = pReq->info.node;
11,522✔
1166
  SSdb     *pSdb = pMnode->pSdb;
11,522✔
1167
  int32_t   numOfRows = 0;
11,522✔
1168
  SConnObj *pConn = NULL;
11,522✔
1169

1170
  if (pShow->pIter == NULL) {
11,522!
1171
    SProfileMgmt *pMgmt = &pMnode->profileMgmt;
11,523✔
1172
    pShow->pIter = taosCacheCreateIter(pMgmt->connCache);
11,523✔
1173
    if (!pShow->pIter) return terrno;
11,531!
1174
  }
1175

1176
  // means fetched some data last time for this conn
1177
  if (pShow->curIterPackedRows > 0) {
11,530!
1178
    size_t len = 0;
×
1179
    pConn = taosCacheIterGetData(pShow->pIter, &len);
×
1180
    if (pConn && (taosArrayGetSize(pConn->pQueries) > pShow->curIterPackedRows)) {
×
1181
      numOfRows = packQueriesIntoBlock(pShow, pConn, pBlock, pShow->curIterPackedRows, rows);
×
1182
      pShow->curIterPackedRows += numOfRows;
×
1183
    }
1184
  }
1185

1186
  while (numOfRows < rows) {
632,078✔
1187
    pConn = mndGetNextConn(pMnode, pShow->pIter);
632,076✔
1188
    if (pConn == NULL) {
632,346✔
1189
      pShow->pIter = NULL;
11,536✔
1190
      break;
11,536✔
1191
    }
1192

1193
    int32_t packedRows = packQueriesIntoBlock(pShow, pConn, pBlock, 0, rows - numOfRows);
620,810✔
1194
    pShow->curIterPackedRows = packedRows;
620,548✔
1195
    numOfRows += packedRows;
620,548✔
1196
  }
1197
  pShow->numOfRows += numOfRows;
11,538✔
1198
  return numOfRows;
11,538✔
1199
}
1200

1201
static int32_t mndRetrieveApps(SRpcMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
10,810✔
1202
  SMnode  *pMnode = pReq->info.node;
10,810✔
1203
  SSdb    *pSdb = pMnode->pSdb;
10,810✔
1204
  int32_t  numOfRows = 0;
10,810✔
1205
  int32_t  cols = 0;
10,810✔
1206
  SAppObj *pApp = NULL;
10,810✔
1207
  int32_t  code = 0;
10,810✔
1208

1209
  if (pShow->pIter == NULL) {
10,810!
1210
    SProfileMgmt *pMgmt = &pMnode->profileMgmt;
10,810✔
1211
    pShow->pIter = taosCacheCreateIter(pMgmt->appCache);
10,810✔
1212
    if (!pShow->pIter) return terrno;
10,811!
1213
  }
1214

1215
  while (numOfRows < rows) {
224,329✔
1216
    pApp = mndGetNextApp(pMnode, pShow->pIter);
224,326✔
1217
    if (pApp == NULL) {
226,480✔
1218
      pShow->pIter = NULL;
10,811✔
1219
      break;
10,811✔
1220
    }
1221

1222
    cols = 0;
215,669✔
1223

1224
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
215,669✔
1225
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->appId, false);
215,397✔
1226
    if (code != 0) {
214,763!
1227
      mError("failed to set app id since %s", tstrerror(code));
×
1228
      return code;
×
1229
    }
1230

1231
    char ip[TD_IP_LEN + VARSTR_HEADER_SIZE] = {0};
214,763✔
1232
    taosInetNtoa(varDataVal(ip), pApp->ip);
214,763✔
1233
    varDataLen(ip) = strlen(varDataVal(ip));
215,793✔
1234
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
215,793✔
1235
    code = colDataSetVal(pColInfo, numOfRows, (const char *)ip, false);
215,276✔
1236
    if (code != 0) {
214,733!
1237
      mError("failed to set ip since %s", tstrerror(code));
×
1238
      return code;
×
1239
    }
1240

1241
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
214,733✔
1242
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->pid, false);
214,396✔
1243
    if (code != 0) {
214,241!
1244
      mError("failed to set pid since %s", tstrerror(code));
×
1245
      return code;
×
1246
    }
1247

1248
    char name[TSDB_APP_NAME_LEN + 6 + VARSTR_HEADER_SIZE] = {0};
214,241✔
1249
    (void)tsnprintf(&name[VARSTR_HEADER_SIZE], sizeof(name) - VARSTR_HEADER_SIZE, "%s", pApp->name);
214,241✔
1250
    varDataLen(name) = strlen(&name[VARSTR_HEADER_SIZE]);
215,879✔
1251
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
215,879✔
1252
    code = colDataSetVal(pColInfo, numOfRows, (const char *)name, false);
215,332✔
1253
    if (code != 0) {
214,643!
1254
      mError("failed to set app name since %s", tstrerror(code));
×
1255
      return code;
×
1256
    }
1257

1258
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
214,643✔
1259
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->startTime, false);
214,247✔
1260
    if (code != 0) {
214,039!
1261
      mError("failed to set start time since %s", tstrerror(code));
×
1262
      return code;
×
1263
    }
1264

1265
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
214,039✔
1266
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertsReq, false);
213,686✔
1267
    if (code != 0) {
213,770!
1268
      mError("failed to set insert req since %s", tstrerror(code));
×
1269
      return code;
×
1270
    }
1271

1272
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
213,770✔
1273
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfInsertRows, false);
213,409✔
1274
    if (code != 0) {
213,541!
1275
      mError("failed to set insert rows since %s", tstrerror(code));
×
1276
      return code;
×
1277
    }
1278

1279
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
213,541✔
1280
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertElapsedTime, false);
213,302✔
1281
    if (code != 0) {
213,607!
1282
      mError("failed to set insert elapsed time since %s", tstrerror(code));
×
1283
      return code;
×
1284
    }
1285

1286
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
213,607✔
1287
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.insertBytes, false);
213,318✔
1288
    if (code != 0) {
213,547!
1289
      mError("failed to set insert bytes since %s", tstrerror(code));
×
1290
      return code;
×
1291
    }
1292

1293
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
213,547✔
1294
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.fetchBytes, false);
213,317✔
1295
    if (code != 0) {
213,520!
1296
      mError("failed to set fetch bytes since %s", tstrerror(code));
×
1297
      return code;
×
1298
    }
1299

1300
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
213,520✔
1301
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.queryElapsedTime, false);
213,323✔
1302
    if (code != 0) {
213,499!
1303
      mError("failed to set query elapsed time since %s", tstrerror(code));
×
1304
      return code;
×
1305
    }
1306

1307
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
213,499✔
1308
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.numOfSlowQueries, false);
213,184✔
1309
    if (code != 0) {
213,388!
1310
      mError("failed to set slow queries since %s", tstrerror(code));
×
1311
      return code;
×
1312
    }
1313

1314
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
213,388✔
1315
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.totalRequests, false);
213,171✔
1316
    if (code != 0) {
213,459!
1317
      mError("failed to set total requests since %s", tstrerror(code));
×
1318
      return code;
×
1319
    }
1320

1321
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
213,459✔
1322
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->summary.currentRequests, false);
213,311✔
1323
    if (code != 0) {
213,486!
1324
      mError("failed to set current requests since %s", tstrerror(code));
×
1325
      return code;
×
1326
    }
1327

1328
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
213,486✔
1329
    code = colDataSetVal(pColInfo, numOfRows, (const char *)&pApp->lastAccessTimeMs, false);
213,184✔
1330
    if (code != 0) {
213,518!
1331
      mError("failed to set last access time since %s", tstrerror(code));
×
1332
      return code;
×
1333
    }
1334

1335
    numOfRows++;
213,518✔
1336
  }
1337

1338
  pShow->numOfRows += numOfRows;
10,814✔
1339
  return numOfRows;
10,814✔
1340
}
1341

1342
static void mndCancelGetNextQuery(SMnode *pMnode, void *pIter) {
×
1343
  if (pIter != NULL) {
×
1344
    taosCacheDestroyIter(pIter);
×
1345
  }
1346
}
×
1347

1348
int32_t mndGetNumOfConnections(SMnode *pMnode) {
12✔
1349
  SProfileMgmt *pMgmt = &pMnode->profileMgmt;
12✔
1350
  return taosCacheGetNumOfObj(pMgmt->connCache);
12✔
1351
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc