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

taosdata / TDengine / #4876

10 Dec 2025 05:56AM UTC coverage: 64.632% (+0.2%) from 64.472%
#4876

push

travis-ci

guanshengliang
test: fix idmp case with checkDataMemLoop checked (#33862)

4 of 9 new or added lines in 3 files covered. (44.44%)

380 existing lines in 104 files now uncovered.

162866 of 251990 relevant lines covered (64.63%)

107950382.52 hits per line

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

73.85
/source/client/src/clientHb.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
#include "catalog.h"
17
#include "clientInt.h"
18
#include "clientLog.h"
19
#include "clientMonitor.h"
20
#include "scheduler.h"
21
#include "tglobal.h"
22
#include "trpc.h"
23

24
typedef struct {
25
  union {
26
    struct {
27
      SAppHbMgr *pAppHbMgr;
28
      int64_t    clusterId;
29
      int32_t    reqCnt;
30
      int8_t     connHbFlag;
31
    };
32
  };
33
} SHbParam;
34

35
SClientHbMgr clientHbMgr = {0};
36

37
static int32_t hbCreateThread();
38
static void    hbStopThread();
39
static int32_t hbUpdateUserAuthInfo(SAppHbMgr *pAppHbMgr, SUserAuthBatchRsp *batchRsp);
40

41
static int32_t hbMqHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) { return 0; }
×
42

43
static int32_t hbMqHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) { return 0; }
×
44

45
static int32_t hbProcessUserAuthInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog,
958,254✔
46
                                        SAppHbMgr *pAppHbMgr) {
47
  int32_t code = TSDB_CODE_SUCCESS;
958,254✔
48

49
  SUserAuthBatchRsp batchRsp = {0};
958,254✔
50
  if (tDeserializeSUserAuthBatchRsp(value, valueLen, &batchRsp) != 0) {
958,254✔
51
    return TSDB_CODE_INVALID_MSG;
×
52
  }
53

54
  int32_t numOfBatchs = taosArrayGetSize(batchRsp.pArray);
958,254✔
55
  for (int32_t i = 0; i < numOfBatchs; ++i) {
1,939,264✔
56
    SGetUserAuthRsp *rsp = taosArrayGet(batchRsp.pArray, i);
981,010✔
57
    if (NULL == rsp) {
981,010✔
58
      code = terrno;
×
59
      goto _return;
×
60
    }
61
    tscDebug("hb to update user auth, user:%s, version:%d", rsp->user, rsp->version);
981,010✔
62

63
    TSC_ERR_JRET(catalogUpdateUserAuthInfo(pCatalog, rsp));
981,010✔
64
  }
65

66
  if (numOfBatchs > 0) {
958,254✔
67
    TSC_ERR_JRET(hbUpdateUserAuthInfo(pAppHbMgr, &batchRsp));
958,254✔
68
  }
69

70
  (void)atomic_val_compare_exchange_8(&pAppHbMgr->connHbFlag, 1, 2);
958,254✔
71

72
_return:
958,254✔
73
  taosArrayDestroy(batchRsp.pArray);
958,254✔
74
  return code;
958,254✔
75
}
76

77
static int32_t hbUpdateUserAuthInfo(SAppHbMgr *pAppHbMgr, SUserAuthBatchRsp *batchRsp) {
958,254✔
78
  int64_t clusterId = pAppHbMgr->pAppInstInfo->clusterId;
958,254✔
79
  for (int i = 0; i < TARRAY_SIZE(clientHbMgr.appHbMgrs); ++i) {
2,573,716✔
80
    SAppHbMgr *hbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, i);
1,615,462✔
81
    if (!hbMgr || hbMgr->pAppInstInfo->clusterId != clusterId) {
1,615,462✔
82
      continue;
23,689✔
83
    }
84

85
    SClientHbReq    *pReq = NULL;
1,591,773✔
86
    SGetUserAuthRsp *pRsp = NULL;
1,591,773✔
87
    while ((pReq = taosHashIterate(hbMgr->activeInfo, pReq))) {
3,114,477✔
88
      STscObj *pTscObj = (STscObj *)acquireTscObj(pReq->connKey.tscRid);
1,789,240✔
89
      if (!pTscObj) {
1,789,240✔
90
        continue;
167,356✔
91
      }
92

93
      if (!pRsp) {
1,621,884✔
94
        for (int32_t j = 0; j < TARRAY_SIZE(batchRsp->pArray); ++j) {
1,574,209✔
95
          SGetUserAuthRsp *rsp = TARRAY_GET_ELEM(batchRsp->pArray, j);
1,307,673✔
96
          if (0 == strncmp(rsp->user, pTscObj->user, TSDB_USER_LEN)) {
1,307,673✔
97
            pRsp = rsp;
1,009,458✔
98
            break;
1,009,458✔
99
          }
100
        }
101
        if (!pRsp) {
1,275,994✔
102
          releaseTscObj(pReq->connKey.tscRid);
266,536✔
103
          taosHashCancelIterate(hbMgr->activeInfo, pReq);
266,536✔
104
          break;
266,536✔
105
        }
106
      }
107

108
      if (pRsp->dropped == 1) {
1,355,348✔
109
        if (atomic_val_compare_exchange_8(&pTscObj->dropped, 0, 1) == 0) {
17,042✔
110
          if (pTscObj->userDroppedInfo.fp) {
15,290✔
111
            SPassInfo *dropInfo = &pTscObj->userDroppedInfo;
13,350✔
112
            if (dropInfo->fp) {
13,350✔
113
              (*dropInfo->fp)(dropInfo->param, NULL, TAOS_NOTIFY_USER_DROPPED);
13,350✔
114
            }
115
          }
116
        }
117
        releaseTscObj(pReq->connKey.tscRid);
17,042✔
118
        continue;
17,042✔
119
      }
120

121
      pTscObj->authVer = pRsp->version;
1,338,306✔
122

123
      if (pTscObj->sysInfo != pRsp->sysInfo) {
1,338,306✔
124
        tscDebug("update sysInfo of user %s from %" PRIi8 " to %" PRIi8 ", conn:%" PRIi64, pRsp->user,
26,700✔
125
                 pTscObj->sysInfo, pRsp->sysInfo, pTscObj->id);
126
        pTscObj->sysInfo = pRsp->sysInfo;
26,700✔
127
      }
128

129
      if (pTscObj->passInfo.fp) {
1,338,306✔
130
        SPassInfo *passInfo = &pTscObj->passInfo;
6,990✔
131
        int32_t    oldVer = atomic_load_32(&passInfo->ver);
6,990✔
132
        if (oldVer < pRsp->passVer) {
6,990✔
133
          atomic_store_32(&passInfo->ver, pRsp->passVer);
5,340✔
134
          if (passInfo->fp) {
5,340✔
135
            (*passInfo->fp)(passInfo->param, &pRsp->passVer, TAOS_NOTIFY_PASSVER);
5,340✔
136
          }
137
          tscDebug("update passVer of user %s from %d to %d, conn:%" PRIi64, pRsp->user, oldVer,
5,340✔
138
                   atomic_load_32(&passInfo->ver), pTscObj->id);
139
        }
140
      }
141

142
      if (pTscObj->whiteListInfo.fp) {
1,338,306✔
143
        SWhiteListInfo *whiteListInfo = &pTscObj->whiteListInfo;
×
144
        int64_t         oldVer = atomic_load_64(&whiteListInfo->ver);
×
145
        if (oldVer != pRsp->whiteListVer) {
×
146
          atomic_store_64(&whiteListInfo->ver, pRsp->whiteListVer);
×
147
          if (whiteListInfo->fp) {
×
148
            (*whiteListInfo->fp)(whiteListInfo->param, &pRsp->whiteListVer, TAOS_NOTIFY_WHITELIST_VER);
×
149
          }
150
          tscDebug("update whitelist version of user %s from %" PRId64 " to %" PRId64 ", conn:%" PRIi64, pRsp->user,
×
151
                   oldVer, atomic_load_64(&whiteListInfo->ver), pTscObj->id);
152
        }
153
      } else {
154
        // Need to update version information to prevent frequent fetching of authentication
155
        // information.
156
        SWhiteListInfo *whiteListInfo = &pTscObj->whiteListInfo;
1,338,306✔
157
        int64_t         oldVer = atomic_load_64(&whiteListInfo->ver);
1,338,306✔
158
        atomic_store_64(&whiteListInfo->ver, pRsp->whiteListVer);
1,338,306✔
159
        tscDebug("update whitelist version of user %s from %" PRId64 " to %" PRId64 ", conn:%" PRIi64, pRsp->user,
1,338,306✔
160
                 oldVer, atomic_load_64(&whiteListInfo->ver), pTscObj->id);
161
      }
162

163
      if (pTscObj->dateTimeWhiteListInfo.fp) {
1,338,306✔
164
        SWhiteListInfo *whiteListInfo = &pTscObj->dateTimeWhiteListInfo;
×
165
        int64_t         oldVer = atomic_load_64(&whiteListInfo->ver);
×
166
        if (oldVer != pRsp->timeWhiteListVer) {
×
167
          atomic_store_64(&whiteListInfo->ver, pRsp->timeWhiteListVer);
×
168
          if (whiteListInfo->fp) {
×
169
            (*whiteListInfo->fp)(whiteListInfo->param, &pRsp->timeWhiteListVer, TAOS_NOTIFY_DATETIME_WHITELIST_VER);
×
170
          }
171
          tscDebug("update date time whitelist version of user %s from %" PRId64 " to %" PRId64 ", conn:%" PRIi64, pRsp->user,
×
172
                   oldVer, atomic_load_64(&whiteListInfo->ver), pTscObj->id);
173
        }
174
      } else {
175
        SWhiteListInfo *whiteListInfo = &pTscObj->dateTimeWhiteListInfo;
1,338,306✔
176
        int64_t         oldVer = atomic_load_64(&whiteListInfo->ver);
1,338,306✔
177
        atomic_store_64(&whiteListInfo->ver, pRsp->timeWhiteListVer);
1,338,306✔
178
        tscDebug("update date time whitelist version of user %s from %" PRId64 " to %" PRId64 ", conn:%" PRIi64, pRsp->user,
1,338,306✔
179
                 oldVer, atomic_load_64(&whiteListInfo->ver), pTscObj->id);
180
      }
181
      releaseTscObj(pReq->connKey.tscRid);
1,338,306✔
182
    }
183
  }
184
  return 0;
958,254✔
185
}
186

187
static int32_t hbGenerateVgInfoFromRsp(SDBVgInfo **pInfo, SUseDbRsp *rsp) {
1,442,978✔
188
  int32_t    code = 0;
1,442,978✔
189
  SDBVgInfo *vgInfo = taosMemoryCalloc(1, sizeof(SDBVgInfo));
1,442,978✔
190
  if (NULL == vgInfo) {
1,442,978✔
191
    return terrno;
×
192
  }
193

194
  vgInfo->vgVersion = rsp->vgVersion;
1,442,978✔
195
  vgInfo->stateTs = rsp->stateTs;
1,442,978✔
196
  vgInfo->flags = rsp->flags;
1,442,978✔
197
  vgInfo->hashMethod = rsp->hashMethod;
1,442,978✔
198
  vgInfo->hashPrefix = rsp->hashPrefix;
1,442,978✔
199
  vgInfo->hashSuffix = rsp->hashSuffix;
1,442,978✔
200
  vgInfo->vgHash = taosHashInit(rsp->vgNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_INT), true, HASH_ENTRY_LOCK);
1,442,978✔
201
  if (NULL == vgInfo->vgHash) {
1,442,978✔
202
    tscError("hash init[%d] failed", rsp->vgNum);
×
203
    code = terrno;
×
204
    goto _return;
×
205
  }
206

207
  for (int32_t j = 0; j < rsp->vgNum; ++j) {
5,377,762✔
208
    SVgroupInfo *pInfo = taosArrayGet(rsp->pVgroupInfos, j);
3,934,784✔
209
    if (taosHashPut(vgInfo->vgHash, &pInfo->vgId, sizeof(int32_t), pInfo, sizeof(SVgroupInfo)) != 0) {
3,934,784✔
210
      tscError("hash push failed, terrno:%d", terrno);
×
211
      code = terrno;
×
212
      goto _return;
×
213
    }
214
  }
215

216
_return:
1,442,978✔
217
  if (code) {
1,442,978✔
218
    taosHashCleanup(vgInfo->vgHash);
×
219
    taosMemoryFreeClear(vgInfo);
×
220
  }
221

222
  *pInfo = vgInfo;
1,442,978✔
223
  return code;
1,442,978✔
224
}
225

226
static int32_t hbProcessDBInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
7,230,906✔
227
  int32_t code = 0;
7,230,906✔
228

229
  SDbHbBatchRsp batchRsp = {0};
7,230,906✔
230
  if (tDeserializeSDbHbBatchRsp(value, valueLen, &batchRsp) != 0) {
7,230,906✔
231
    terrno = TSDB_CODE_INVALID_MSG;
×
232
    code = terrno;
×
233
    goto _return;
×
234
  }
235

236
  int32_t numOfBatchs = taosArrayGetSize(batchRsp.pArray);
7,230,906✔
237
  for (int32_t i = 0; i < numOfBatchs; ++i) {
8,834,847✔
238
    SDbHbRsp *rsp = taosArrayGet(batchRsp.pArray, i);
1,603,941✔
239
    if (NULL == rsp) {
1,603,941✔
240
      code = terrno;
×
241
      goto _return;
×
242
    }
243
    if (rsp->useDbRsp) {
1,603,941✔
244
      tscDebug("hb use db rsp, db:%s, vgVersion:%d, stateTs:%" PRId64 ", uid:%" PRIx64, rsp->useDbRsp->db,
1,220,946✔
245
               rsp->useDbRsp->vgVersion, rsp->useDbRsp->stateTs, rsp->useDbRsp->uid);
246

247
      if (rsp->useDbRsp->vgVersion < 0) {
1,220,946✔
248
        tscDebug("hb to remove db, db:%s", rsp->useDbRsp->db);
34,557✔
249
        code = catalogRemoveDB(pCatalog, rsp->useDbRsp->db, rsp->useDbRsp->uid);
34,557✔
250
      } else {
251
        SDBVgInfo *vgInfo = NULL;
1,186,389✔
252
        code = hbGenerateVgInfoFromRsp(&vgInfo, rsp->useDbRsp);
1,186,389✔
253
        if (TSDB_CODE_SUCCESS != code) {
1,186,389✔
254
          goto _return;
×
255
        }
256

257
        tscDebug("hb to update db vgInfo, db:%s", rsp->useDbRsp->db);
1,186,389✔
258

259
        TSC_ERR_JRET(catalogUpdateDBVgInfo(pCatalog, rsp->useDbRsp->db, rsp->useDbRsp->uid, vgInfo));
1,186,389✔
260

261
        if (IS_SYS_DBNAME(rsp->useDbRsp->db)) {
1,186,389✔
262
          code = hbGenerateVgInfoFromRsp(&vgInfo, rsp->useDbRsp);
256,589✔
263
          if (TSDB_CODE_SUCCESS != code) {
256,589✔
264
            goto _return;
×
265
          }
266

267
          TSC_ERR_JRET(catalogUpdateDBVgInfo(
256,589✔
268
              pCatalog, (rsp->useDbRsp->db[0] == 'i') ? TSDB_PERFORMANCE_SCHEMA_DB : TSDB_INFORMATION_SCHEMA_DB,
269
              rsp->useDbRsp->uid, vgInfo));
270
        }
271
      }
272
    }
273

274
    if (rsp->cfgRsp) {
1,603,941✔
275
      tscDebug("hb db cfg rsp, db:%s, cfgVersion:%d", rsp->cfgRsp->db, rsp->cfgRsp->cfgVersion);
262,879✔
276
      code = catalogUpdateDbCfg(pCatalog, rsp->cfgRsp->db, rsp->cfgRsp->dbId, rsp->cfgRsp);
262,879✔
277
      rsp->cfgRsp = NULL;
262,879✔
278
    }
279
    if (rsp->pTsmaRsp) {
1,603,941✔
280
      if (rsp->pTsmaRsp->pTsmas) {
848,592✔
281
        for (int32_t i = 0; i < rsp->pTsmaRsp->pTsmas->size; ++i) {
3,064✔
282
          STableTSMAInfo *pTsma = taosArrayGetP(rsp->pTsmaRsp->pTsmas, i);
1,532✔
283
          if (NULL == pTsma) {
1,532✔
284
            TSC_ERR_JRET(TSDB_CODE_OUT_OF_RANGE);
×
285
          }
286
          TSC_ERR_JRET(catalogAsyncUpdateTSMA(pCatalog, &pTsma, rsp->dbTsmaVersion));
1,532✔
287
        }
288
        taosArrayClear(rsp->pTsmaRsp->pTsmas);
1,532✔
289
      } else {
290
        TSC_ERR_JRET(catalogAsyncUpdateDbTsmaVersion(pCatalog, rsp->dbTsmaVersion, rsp->db, rsp->dbId));
847,060✔
291
      }
292
    }
293
  }
294

295
_return:
7,230,906✔
296

297
  tFreeSDbHbBatchRsp(&batchRsp);
7,230,906✔
298
  return code;
7,230,906✔
299
}
300

301
static int32_t hbProcessStbInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
5,185,704✔
302
  int32_t code = TSDB_CODE_SUCCESS;
5,185,704✔
303

304
  SSTbHbRsp hbRsp = {0};
5,185,704✔
305
  if (tDeserializeSSTbHbRsp(value, valueLen, &hbRsp) != 0) {
5,185,704✔
306
    terrno = TSDB_CODE_INVALID_MSG;
×
307
    return -1;
×
308
  }
309

310
  int32_t numOfMeta = taosArrayGetSize(hbRsp.pMetaRsp);
5,185,704✔
311
  for (int32_t i = 0; i < numOfMeta; ++i) {
5,287,135✔
312
    STableMetaRsp *rsp = taosArrayGet(hbRsp.pMetaRsp, i);
101,431✔
313
    if (NULL == rsp) {
101,431✔
314
      code = terrno;
×
315
      goto _return;
×
316
    }
317
    if (rsp->numOfColumns < 0) {
101,431✔
318
      tscDebug("hb to remove stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
66,610✔
319
      TSC_ERR_JRET(catalogRemoveStbMeta(pCatalog, rsp->dbFName, rsp->dbId, rsp->stbName, rsp->suid));
66,610✔
320
    } else {
321
      tscDebug("hb to update stb, db:%s, stb:%s", rsp->dbFName, rsp->stbName);
34,821✔
322
      if (rsp->pSchemas[0].colId != PRIMARYKEY_TIMESTAMP_COL_ID) {
34,821✔
323
        tscError("invalid colId[%" PRIi16 "] for the first column in table meta rsp msg", rsp->pSchemas[0].colId);
×
324
        tFreeSSTbHbRsp(&hbRsp);
×
325
        return TSDB_CODE_TSC_INVALID_VALUE;
×
326
      }
327

328
      TSC_ERR_JRET(catalogAsyncUpdateTableMeta(pCatalog, rsp));
34,821✔
329
    }
330
  }
331

332
  int32_t numOfIndex = taosArrayGetSize(hbRsp.pIndexRsp);
5,185,704✔
333
  for (int32_t i = 0; i < numOfIndex; ++i) {
5,185,704✔
334
    STableIndexRsp *rsp = taosArrayGet(hbRsp.pIndexRsp, i);
×
335
    if (NULL == rsp) {
×
336
      code = terrno;
×
337
      goto _return;
×
338
    }
339
    TSC_ERR_JRET(catalogUpdateTableIndex(pCatalog, rsp));
×
340
  }
341

342
_return:
5,185,704✔
343
  taosArrayDestroy(hbRsp.pIndexRsp);
5,185,704✔
344
  hbRsp.pIndexRsp = NULL;
5,185,704✔
345

346
  tFreeSSTbHbRsp(&hbRsp);
5,185,704✔
347
  return code;
5,185,704✔
348
}
349

350
static int32_t hbProcessDynViewRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
6,553✔
351
  return catalogUpdateDynViewVer(pCatalog, (SDynViewVersion *)value);
6,553✔
352
}
353

354
static void hbFreeSViewMetaInRsp(void *p) {
×
355
  if (NULL == p || NULL == *(void **)p) {
×
356
    return;
×
357
  }
358
  SViewMetaRsp *pRsp = *(SViewMetaRsp **)p;
×
359
  tFreeSViewMetaRsp(pRsp);
×
360
  taosMemoryFreeClear(pRsp);
×
361
}
362

363
static int32_t hbProcessViewInfoRsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
6,553✔
364
  int32_t code = TSDB_CODE_SUCCESS;
6,553✔
365

366
  SViewHbRsp hbRsp = {0};
6,553✔
367
  if (tDeserializeSViewHbRsp(value, valueLen, &hbRsp) != 0) {
6,553✔
368
    taosArrayDestroyEx(hbRsp.pViewRsp, hbFreeSViewMetaInRsp);
×
369
    terrno = TSDB_CODE_INVALID_MSG;
×
370
    return -1;
×
371
  }
372

373
  int32_t numOfMeta = taosArrayGetSize(hbRsp.pViewRsp);
6,553✔
374
  for (int32_t i = 0; i < numOfMeta; ++i) {
8,883✔
375
    SViewMetaRsp *rsp = taosArrayGetP(hbRsp.pViewRsp, i);
2,330✔
376
    if (NULL == rsp) {
2,330✔
377
      code = terrno;
×
378
      goto _return;
×
379
    }
380
    if (rsp->numOfCols < 0) {
2,330✔
381
      tscDebug("hb to remove view, db:%s, view:%s", rsp->dbFName, rsp->name);
2,330✔
382
      code = catalogRemoveViewMeta(pCatalog, rsp->dbFName, rsp->dbId, rsp->name, rsp->viewId);
2,330✔
383
      tFreeSViewMetaRsp(rsp);
2,330✔
384
      taosMemoryFreeClear(rsp);
2,330✔
385
    } else {
386
      tscDebug("hb to update view, db:%s, view:%s", rsp->dbFName, rsp->name);
×
387
      code = catalogUpdateViewMeta(pCatalog, rsp);
×
388
    }
389
    TSC_ERR_JRET(code);
2,330✔
390
  }
391

392
_return:
6,553✔
393
  taosArrayDestroy(hbRsp.pViewRsp);
6,553✔
394
  return code;
6,553✔
395
}
396

397
static int32_t hbprocessTSMARsp(void *value, int32_t valueLen, struct SCatalog *pCatalog) {
100,346✔
398
  int32_t code = 0;
100,346✔
399

400
  STSMAHbRsp hbRsp = {0};
100,346✔
401
  if (tDeserializeTSMAHbRsp(value, valueLen, &hbRsp)) {
100,346✔
402
    terrno = TSDB_CODE_INVALID_MSG;
×
403
    return -1;
×
404
  }
405

406
  int32_t numOfTsma = taosArrayGetSize(hbRsp.pTsmas);
100,346✔
407
  for (int32_t i = 0; i < numOfTsma; ++i) {
100,346✔
408
    STableTSMAInfo *pTsmaInfo = taosArrayGetP(hbRsp.pTsmas, i);
×
409

410
    if (!pTsmaInfo->pFuncs) {
×
411
      tscDebug("hb to remove tsma:%s.%s", pTsmaInfo->dbFName, pTsmaInfo->name);
×
412
      code = catalogRemoveTSMA(pCatalog, pTsmaInfo);
×
413
      tFreeAndClearTableTSMAInfo(pTsmaInfo);
×
414
    } else {
415
      tscDebug("hb to update tsma:%s.%s", pTsmaInfo->dbFName, pTsmaInfo->name);
×
416
      code = catalogUpdateTSMA(pCatalog, &pTsmaInfo);
×
417
      tFreeAndClearTableTSMAInfo(pTsmaInfo);
×
418
    }
419
    TSC_ERR_JRET(code);
×
420
  }
421

422
_return:
100,346✔
423
  taosArrayDestroy(hbRsp.pTsmas);
100,346✔
424
  return code;
100,346✔
425
}
426

427
static void hbProcessQueryRspKvs(int32_t kvNum, SArray *pKvs, struct SCatalog *pCatalog, SAppHbMgr *pAppHbMgr) {
11,206,583✔
428
  for (int32_t i = 0; i < kvNum; ++i) {
24,694,899✔
429
    SKv *kv = taosArrayGet(pKvs, i);
13,488,316✔
430
    if (NULL == kv) {
13,488,316✔
431
      tscError("invalid hb kv, idx:%d", i);
×
432
      continue;
×
433
    }
434
    switch (kv->key) {
13,488,316✔
435
      case HEARTBEAT_KEY_USER_AUTHINFO: {
958,254✔
436
        if (kv->valueLen <= 0 || NULL == kv->value) {
958,254✔
437
          tscError("invalid hb user auth info, len:%d, value:%p", kv->valueLen, kv->value);
×
438
          break;
×
439
        }
440
        if (TSDB_CODE_SUCCESS != hbProcessUserAuthInfoRsp(kv->value, kv->valueLen, pCatalog, pAppHbMgr)) {
958,254✔
441
          tscError("process user auth info response faild, len:%d, value:%p", kv->valueLen, kv->value);
×
442
          break;
×
443
        }
444
        break;
958,254✔
445
      }
446
      case HEARTBEAT_KEY_DBINFO: {
7,230,906✔
447
        if (kv->valueLen <= 0 || NULL == kv->value) {
7,230,906✔
448
          tscError("invalid hb db info, len:%d, value:%p", kv->valueLen, kv->value);
×
449
          break;
×
450
        }
451
        if (TSDB_CODE_SUCCESS != hbProcessDBInfoRsp(kv->value, kv->valueLen, pCatalog)) {
7,230,906✔
452
          tscError("process db info response faild, len:%d, value:%p", kv->valueLen, kv->value);
×
453
          break;
×
454
        }
455
        break;
7,230,906✔
456
      }
457
      case HEARTBEAT_KEY_STBINFO: {
5,185,704✔
458
        if (kv->valueLen <= 0 || NULL == kv->value) {
5,185,704✔
459
          tscError("invalid hb stb info, len:%d, value:%p", kv->valueLen, kv->value);
×
460
          break;
×
461
        }
462
        if (TSDB_CODE_SUCCESS != hbProcessStbInfoRsp(kv->value, kv->valueLen, pCatalog)) {
5,185,704✔
463
          tscError("process stb info response faild, len:%d, value:%p", kv->valueLen, kv->value);
×
464
          break;
×
465
        }
466
        break;
5,185,704✔
467
      }
468
#ifdef TD_ENTERPRISE
469
      case HEARTBEAT_KEY_DYN_VIEW: {
6,553✔
470
        if (kv->valueLen <= 0 || NULL == kv->value) {
6,553✔
471
          tscError("invalid dyn view info, len:%d, value:%p", kv->valueLen, kv->value);
×
472
          break;
×
473
        }
474
        if (TSDB_CODE_SUCCESS != hbProcessDynViewRsp(kv->value, kv->valueLen, pCatalog)) {
6,553✔
475
          tscError("Process dyn view response failed, len:%d, value:%p", kv->valueLen, kv->value);
×
476
          break;
×
477
        }
478
        break;
6,553✔
479
      }
480
      case HEARTBEAT_KEY_VIEWINFO: {
6,553✔
481
        if (kv->valueLen <= 0 || NULL == kv->value) {
6,553✔
482
          tscError("invalid view info, len:%d, value:%p", kv->valueLen, kv->value);
×
483
          break;
×
484
        }
485
        if (TSDB_CODE_SUCCESS != hbProcessViewInfoRsp(kv->value, kv->valueLen, pCatalog)) {
6,553✔
486
          tscError("Process view info response failed, len:%d, value:%p", kv->valueLen, kv->value);
×
487
          break;
×
488
        }
489
        break;
6,553✔
490
      }
491
#endif
492
      case HEARTBEAT_KEY_TSMA: {
100,346✔
493
        if (kv->valueLen <= 0 || !kv->value) {
100,346✔
494
          tscError("Invalid tsma info, len:%d, value:%p", kv->valueLen, kv->value);
×
495
        }
496
        if (TSDB_CODE_SUCCESS != hbprocessTSMARsp(kv->value, kv->valueLen, pCatalog)) {
100,346✔
497
          tscError("Process tsma info response failed, len:%d, value:%p", kv->valueLen, kv->value);
×
498
        }
499
        break;
100,346✔
500
      }
501
      default:
×
502
        tscError("invalid hb key type:%d", kv->key);
×
503
        break;
×
504
    }
505
  }
506
}
11,206,583✔
507

508
static int32_t hbQueryHbRspHandle(SAppHbMgr *pAppHbMgr, SClientHbRsp *pRsp) {
39,053,774✔
509
  SClientHbReq *pReq = taosHashAcquire(pAppHbMgr->activeInfo, &pRsp->connKey, sizeof(SClientHbKey));
39,053,774✔
510
  if (NULL == pReq) {
39,053,774✔
511
    tscWarn("pReq to get activeInfo, may be dropped, refId:%" PRIx64 ", type:%d", pRsp->connKey.tscRid,
14,160✔
512
            pRsp->connKey.connType);
513
    return TSDB_CODE_SUCCESS;
14,160✔
514
  }
515

516
  if (pRsp->query) {
39,039,614✔
517
    STscObj *pTscObj = (STscObj *)acquireTscObj(pRsp->connKey.tscRid);
34,318,430✔
518
    if (NULL == pTscObj) {
34,318,430✔
519
      tscDebug("tscObj rid %" PRIx64 " not exist", pRsp->connKey.tscRid);
1,485✔
520
    } else {
521
      if (pRsp->query->totalDnodes > 1) {
34,316,945✔
522
        SEpSet  originEpset = getEpSet_s(&pTscObj->pAppInfo->mgmtEp);
9,472,924✔
523
        if (!isEpsetEqual(&originEpset, &pRsp->query->epSet)) {
9,472,924✔
524
          SEpSet *pOrig = &originEpset;
62,919✔
525
          SEp    *pOrigEp = &pOrig->eps[pOrig->inUse];
62,919✔
526
          SEp    *pNewEp = &pRsp->query->epSet.eps[pRsp->query->epSet.inUse];
62,919✔
527
          tscDebug("mnode epset updated from %d/%d=>%s:%d to %d/%d=>%s:%d in hb", pOrig->inUse, pOrig->numOfEps,
62,919✔
528
                   pOrigEp->fqdn, pOrigEp->port, pRsp->query->epSet.inUse, pRsp->query->epSet.numOfEps, pNewEp->fqdn,
529
                   pNewEp->port);
530

531
          updateEpSet_s(&pTscObj->pAppInfo->mgmtEp, &pRsp->query->epSet);
62,919✔
532
        }
533
      }
534

535
      pTscObj->pAppInfo->totalDnodes = pRsp->query->totalDnodes;
34,316,945✔
536
      pTscObj->pAppInfo->onlineDnodes = pRsp->query->onlineDnodes;
34,316,945✔
537
      pTscObj->connId = pRsp->query->connId;
34,316,945✔
538
      tscTrace("connId:%u, hb rsp, dnodes %d/%d", pTscObj->connId, pTscObj->pAppInfo->onlineDnodes,
34,316,945✔
539
               pTscObj->pAppInfo->totalDnodes);
540

541
      if (pRsp->query->killRid) {
34,316,945✔
542
        tscDebug("QID:0x%" PRIx64 ", need to be killed now", pRsp->query->killRid);
×
543
        SRequestObj *pRequest = acquireRequest(pRsp->query->killRid);
×
544
        if (NULL == pRequest) {
×
545
          tscDebug("QID:0x%" PRIx64 ", not exist to kill", pRsp->query->killRid);
×
546
        } else {
547
          taos_stop_query((TAOS_RES *)pRequest);
×
548
          (void)releaseRequest(pRsp->query->killRid);
×
549
        }
550
      }
551

552
      if (pRsp->query->killConnection) {
34,316,945✔
553
        taos_close_internal(pTscObj);
×
554
      }
555

556
      if (pRsp->query->pQnodeList) {
34,316,945✔
557
        if (TSDB_CODE_SUCCESS != updateQnodeList(pTscObj->pAppInfo, pRsp->query->pQnodeList)) {
171,388✔
558
          tscWarn("update qnode list failed");
×
559
        }
560
      }
561

562
      releaseTscObj(pRsp->connKey.tscRid);
34,316,945✔
563
    }
564
  }
565

566
  int32_t kvNum = pRsp->info ? taosArrayGetSize(pRsp->info) : 0;
39,039,614✔
567

568
  tscDebug("hb got %d rsp kv", kvNum);
39,039,614✔
569

570
  if (kvNum > 0) {
39,039,614✔
571
    struct SCatalog *pCatalog = NULL;
11,206,583✔
572
    int32_t          code = catalogGetHandle(pReq->clusterId, &pCatalog);
11,206,583✔
573
    if (code != TSDB_CODE_SUCCESS) {
11,206,583✔
574
      tscWarn("catalogGetHandle failed, clusterId:0x%" PRIx64 ", error:%s", pReq->clusterId, tstrerror(code));
×
575
    } else {
576
      hbProcessQueryRspKvs(kvNum, pRsp->info, pCatalog, pAppHbMgr);
11,206,583✔
577
    }
578
  }
579

580
  taosHashRelease(pAppHbMgr->activeInfo, pReq);
39,039,614✔
581

582
  return TSDB_CODE_SUCCESS;
39,039,614✔
583
}
584

585
static int32_t hbAsyncCallBack(void *param, SDataBuf *pMsg, int32_t code) {
32,395,572✔
586
  if (0 == atomic_load_8(&clientHbMgr.inited)) {
32,395,572✔
587
    goto _return;
×
588
  }
589

590
  static int32_t    emptyRspNum = 0;
591
  int32_t           idx = *(int32_t *)param;
32,395,598✔
592
  SClientHbBatchRsp pRsp = {0};
32,395,598✔
593
  if (TSDB_CODE_SUCCESS == code) {
32,395,167✔
594
    code = tDeserializeSClientHbBatchRsp(pMsg->pData, pMsg->len, &pRsp);
31,727,027✔
595
    if (TSDB_CODE_SUCCESS != code) {
31,725,433✔
596
      tscError("deserialize hb rsp failed");
1,150✔
597
    }
598
    int32_t now = taosGetTimestampSec();
31,725,433✔
599
    int32_t delta = abs(now - pRsp.svrTimestamp);
31,725,614✔
600
    if (delta > tsTimestampDeltaLimit) {
31,725,614✔
601
      code = TSDB_CODE_TIME_UNSYNCED;
1,150✔
602
      tscError("time diff:%ds is too big", delta);
1,150✔
603
    }
604
  }
605

606
  int32_t rspNum = taosArrayGetSize(pRsp.rsps);
32,393,754✔
607

608
  (void)taosThreadMutexLock(&clientHbMgr.lock);
32,394,867✔
609

610
  SAppHbMgr *pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, idx);
32,395,796✔
611
  if (pAppHbMgr == NULL) {
32,395,796✔
612
    (void)taosThreadMutexUnlock(&clientHbMgr.lock);
×
613
    tscError("appHbMgr not exist, idx:%d", idx);
×
614
    taosMemoryFree(pMsg->pData);
×
615
    taosMemoryFree(pMsg->pEpSet);
×
616
    tFreeClientHbBatchRsp(&pRsp);
617
    return TSDB_CODE_OUT_OF_RANGE;
×
618
  }
619

620
  SAppInstInfo *pInst = pAppHbMgr->pAppInstInfo;
32,395,796✔
621

622
  if (code != 0) {
32,395,796✔
623
    pInst->onlineDnodes = pInst->totalDnodes ? 0 : -1;
669,919✔
624
    tscDebug("hb rsp error %s, update server status %d/%d", tstrerror(code), pInst->onlineDnodes, pInst->totalDnodes);
669,919✔
625
    (void)taosThreadMutexUnlock(&clientHbMgr.lock);
669,919✔
626
    taosMemoryFree(pMsg->pData);
669,919✔
627
    taosMemoryFree(pMsg->pEpSet);
669,919✔
628
    tFreeClientHbBatchRsp(&pRsp);
629
    return code;
669,919✔
630
  }
631

632
  pInst->serverCfg.monitorParas = pRsp.monitorParas;
31,725,877✔
633
  pInst->serverCfg.enableAuditDelete = pRsp.enableAuditDelete;
31,725,877✔
634
  pInst->serverCfg.enableStrongPass = pRsp.enableStrongPass;
31,725,877✔
635
  tsEnableStrongPassword = pInst->serverCfg.enableStrongPass;
31,725,877✔
636
  tscDebug("monitor paras from hb, clusterId:0x%" PRIx64 ", threshold:%d scope:%d", pInst->clusterId,
31,725,877✔
637
           pRsp.monitorParas.tsSlowLogThreshold, pRsp.monitorParas.tsSlowLogScope);
638

639
  if (rspNum) {
31,725,877✔
640
    tscDebug("hb got %d rsp, %d empty rsp received before", rspNum,
30,783,333✔
641
             atomic_val_compare_exchange_32(&emptyRspNum, emptyRspNum, 0));
642
  } else {
643
    (void)atomic_add_fetch_32(&emptyRspNum, 1);
942,544✔
644
  }
645

646
  for (int32_t i = 0; i < rspNum; ++i) {
70,779,651✔
647
    SClientHbRsp *rsp = taosArrayGet(pRsp.rsps, i);
39,053,774✔
648
    code = (*clientHbMgr.rspHandle[rsp->connKey.connType])(pAppHbMgr, rsp);
39,053,774✔
649
    if (code) {
39,053,774✔
650
      break;
×
651
    }
652
  }
653

654
  (void)taosThreadMutexUnlock(&clientHbMgr.lock);
31,725,877✔
655

656
  tFreeClientHbBatchRsp(&pRsp);
657

658
_return:
31,725,877✔
659
  taosMemoryFree(pMsg->pData);
31,725,877✔
660
  taosMemoryFree(pMsg->pEpSet);
31,725,877✔
661
  return code;
31,725,877✔
662
}
663

664
int32_t hbBuildQueryDesc(SQueryHbReqBasic *hbBasic, STscObj *pObj) {
36,781,819✔
665
  int64_t    now = taosGetTimestampUs();
36,781,819✔
666
  SQueryDesc desc = {0};
36,781,819✔
667
  int32_t    code = 0;
36,781,819✔
668

669
  void *pIter = taosHashIterate(pObj->pRequests, NULL);
36,781,819✔
670
  while (pIter != NULL) {
73,847,690✔
671
    int64_t     *rid = pIter;
37,065,871✔
672
    SRequestObj *pRequest = acquireRequest(*rid);
37,065,871✔
673
    if (NULL == pRequest) {
37,065,871✔
674
      pIter = taosHashIterate(pObj->pRequests, pIter);
24,028✔
675
      continue;
24,028✔
676
    }
677

678
    if (pRequest->killed || 0 == pRequest->body.queryJob) {
37,041,843✔
679
      (void)releaseRequest(*rid);
15,667,366✔
680
      pIter = taosHashIterate(pObj->pRequests, pIter);
15,667,366✔
681
      continue;
15,667,366✔
682
    }
683

684
    tstrncpy(desc.sql, pRequest->sqlstr, sizeof(desc.sql));
21,374,477✔
685
    desc.stime = pRequest->metric.start / 1000;
21,374,477✔
686
    desc.queryId = pRequest->requestId;
21,374,477✔
687
    desc.useconds = now - pRequest->metric.start;
21,374,477✔
688
    desc.reqRid = pRequest->self;
21,374,477✔
689
    desc.stableQuery = pRequest->stableQuery;
21,374,477✔
690
    desc.isSubQuery = pRequest->isSubReq;
21,374,477✔
691
    code = taosGetFqdn(desc.fqdn);
21,374,477✔
692
    if (TSDB_CODE_SUCCESS != code) {
21,374,477✔
693
      (void)releaseRequest(*rid);
×
694
      tscError("get fqdn failed");
×
695
      return TSDB_CODE_FAILED;
×
696
    }
697
    desc.subPlanNum = pRequest->body.subplanNum;
21,374,477✔
698

699
    if (desc.subPlanNum) {
21,374,477✔
700
      desc.subDesc = taosArrayInit(desc.subPlanNum, sizeof(SQuerySubDesc));
21,374,477✔
701
      if (NULL == desc.subDesc) {
21,374,477✔
702
        (void)releaseRequest(*rid);
×
703
        return terrno;
×
704
      }
705

706
      code = schedulerGetTasksStatus(pRequest->body.queryJob, desc.subDesc);
21,374,477✔
707
      if (code) {
21,374,477✔
708
        taosArrayDestroy(desc.subDesc);
4,929,897✔
709
        desc.subDesc = NULL;
4,929,897✔
710
      }
711
      desc.subPlanNum = taosArrayGetSize(desc.subDesc);
21,374,477✔
712
    } else {
713
      desc.subDesc = NULL;
×
714
    }
715

716
    (void)releaseRequest(*rid);
21,374,477✔
717
    if (NULL == taosArrayPush(hbBasic->queryDesc, &desc)) {
42,748,954✔
718
      taosArrayDestroy(desc.subDesc);
×
719
      return terrno;
×
720
    }
721

722
    pIter = taosHashIterate(pObj->pRequests, pIter);
21,374,477✔
723
  }
724

725
  return code;
36,781,819✔
726
}
727

728
int32_t hbGetQueryBasicInfo(SClientHbKey *connKey, SClientHbReq *req) {
39,735,270✔
729
  STscObj *pTscObj = (STscObj *)acquireTscObj(connKey->tscRid);
39,735,270✔
730
  if (NULL == pTscObj) {
39,735,270✔
731
    tscWarn("tscObj rid 0x%" PRIx64 " not exist", connKey->tscRid);
264✔
732
    return terrno;
264✔
733
  }
734

735
  SQueryHbReqBasic *hbBasic = (SQueryHbReqBasic *)taosMemoryCalloc(1, sizeof(SQueryHbReqBasic));
39,735,006✔
736
  if (NULL == hbBasic) {
39,735,006✔
737
    tscError("calloc %d failed", (int32_t)sizeof(SQueryHbReqBasic));
×
738
    releaseTscObj(connKey->tscRid);
×
739
    return terrno;
×
740
  }
741

742
  hbBasic->connId = pTscObj->connId;
39,735,006✔
743

744
  int32_t numOfQueries = pTscObj->pRequests ? taosHashGetSize(pTscObj->pRequests) : 0;
39,735,006✔
745
  if (numOfQueries <= 0) {
39,735,006✔
746
    req->query = hbBasic;
2,953,187✔
747
    releaseTscObj(connKey->tscRid);
2,953,187✔
748
    tscDebug("no queries on connection");
2,953,187✔
749
    return TSDB_CODE_SUCCESS;
2,953,187✔
750
  }
751

752
  hbBasic->queryDesc = taosArrayInit(numOfQueries, sizeof(SQueryDesc));
36,781,819✔
753
  if (NULL == hbBasic->queryDesc) {
36,781,819✔
754
    tscWarn("taosArrayInit %d queryDesc failed", numOfQueries);
×
755
    releaseTscObj(connKey->tscRid);
×
756
    taosMemoryFree(hbBasic);
×
757
    return terrno;
×
758
  }
759

760
  int32_t code = hbBuildQueryDesc(hbBasic, pTscObj);
36,781,819✔
761
  if (code) {
36,781,819✔
762
    releaseTscObj(connKey->tscRid);
4,791,916✔
763
    if (hbBasic->queryDesc) {
4,791,916✔
764
      taosArrayDestroyEx(hbBasic->queryDesc, tFreeClientHbQueryDesc);
4,791,916✔
765
    }
766
    taosMemoryFree(hbBasic);
4,791,916✔
767
    return code;
4,791,916✔
768
  }
769

770
  req->query = hbBasic;
31,989,903✔
771
  releaseTscObj(connKey->tscRid);
31,989,903✔
772

773
  return TSDB_CODE_SUCCESS;
31,989,903✔
774
}
775

776
static int32_t hbGetUserAuthInfo(SClientHbKey *connKey, SHbParam *param, SClientHbReq *req) {
915,190✔
777
  STscObj *pTscObj = (STscObj *)acquireTscObj(connKey->tscRid);
915,190✔
778
  if (!pTscObj) {
915,190✔
UNCOV
779
    tscWarn("tscObj rid 0x%" PRIx64 " not exist", connKey->tscRid);
×
UNCOV
780
    return terrno;
×
781
  }
782

783
  int32_t code = 0;
915,190✔
784

785
  SKv  kv = {.key = HEARTBEAT_KEY_USER_AUTHINFO};
915,190✔
786
  SKv *pKv = NULL;
915,190✔
787
  if ((pKv = taosHashGet(req->info, &kv.key, sizeof(kv.key)))) {
915,190✔
788
    int32_t           userNum = pKv->valueLen / sizeof(SUserAuthVersion);
368,255✔
789
    SUserAuthVersion *userAuths = (SUserAuthVersion *)pKv->value;
368,255✔
790
    for (int32_t i = 0; i < userNum; ++i) {
374,101✔
791
      SUserAuthVersion *pUserAuth = userAuths + i;
374,101✔
792
      // both key and user exist, update version
793
      if (strncmp(pUserAuth->user, pTscObj->user, TSDB_USER_LEN) == 0) {
374,101✔
794
        pUserAuth->version = htonl(-1);  // force get userAuthInfo
368,255✔
795
        goto _return;
368,255✔
796
      }
797
    }
798
    // key exists, user not exist, append user
UNCOV
799
    SUserAuthVersion *qUserAuth =
×
UNCOV
800
        (SUserAuthVersion *)taosMemoryRealloc(pKv->value, (userNum + 1) * sizeof(SUserAuthVersion));
×
UNCOV
801
    if (qUserAuth) {
×
UNCOV
802
      tstrncpy((qUserAuth + userNum)->user, pTscObj->user, TSDB_USER_LEN);
×
UNCOV
803
      (qUserAuth + userNum)->version = htonl(-1);  // force get userAuthInfo
×
UNCOV
804
      pKv->value = qUserAuth;
×
UNCOV
805
      pKv->valueLen += sizeof(SUserAuthVersion);
×
806
    } else {
807
      code = terrno;
×
808
    }
UNCOV
809
    goto _return;
×
810
  }
811

812
  // key/user not exist, add user
813
  SUserAuthVersion *user = taosMemoryMalloc(sizeof(SUserAuthVersion));
546,935✔
814
  if (!user) {
546,935✔
815
    code = terrno;
×
816
    goto _return;
×
817
  }
818
  tstrncpy(user->user, pTscObj->user, TSDB_USER_LEN);
546,935✔
819
  user->version = htonl(-1);  // force get userAuthInfo
546,935✔
820
  kv.valueLen = sizeof(SUserAuthVersion);
546,935✔
821
  kv.value = user;
546,935✔
822

823
  tscDebug("hb got user auth info, valueLen:%d, user:%s, authVer:%d, tscRid:%" PRIi64, kv.valueLen, user->user,
546,935✔
824
           pTscObj->authVer, connKey->tscRid);
825

826
  if (!req->info) {
546,935✔
827
    req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
546,935✔
828
    if (NULL == req->info) {
546,935✔
829
      code = terrno;
×
830
      goto _return;
×
831
    }
832
  }
833

834
  if (taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv)) != 0) {
546,935✔
835
    taosMemoryFree(user);
×
836
    code = terrno ? terrno : TSDB_CODE_APP_ERROR;
×
837
    goto _return;
×
838
  }
839

840
_return:
856,854✔
841
  releaseTscObj(connKey->tscRid);
915,190✔
842
  if (code) {
915,190✔
843
    tscError("hb got user auth info failed since %s", tstrerror(code));
×
844
  }
845

846
  return code;
915,190✔
847
}
848

849
int32_t hbGetExpiredUserInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *req) {
25,263,438✔
850
  SUserAuthVersion *users = NULL;
25,263,438✔
851
  uint32_t          userNum = 0;
25,263,438✔
852
  int32_t           code = 0;
25,263,438✔
853

854
  code = catalogGetExpiredUsers(pCatalog, &users, &userNum);
25,263,438✔
855
  if (TSDB_CODE_SUCCESS != code) {
25,263,438✔
856
    return code;
×
857
  }
858

859
  if (userNum <= 0) {
25,263,438✔
860
    taosMemoryFree(users);
729,046✔
861
    return TSDB_CODE_SUCCESS;
729,046✔
862
  }
863

864
  for (int32_t i = 0; i < userNum; ++i) {
49,474,554✔
865
    SUserAuthVersion *user = &users[i];
24,940,162✔
866
    user->version = htonl(user->version);
24,940,162✔
867
  }
868

869
  SKv kv = {
24,534,392✔
870
      .key = HEARTBEAT_KEY_USER_AUTHINFO,
871
      .valueLen = sizeof(SUserAuthVersion) * userNum,
24,534,392✔
872
      .value = users,
873
  };
874

875
  tscDebug("hb got %d expired users, valueLen:%d", userNum, kv.valueLen);
24,534,392✔
876

877
  if (NULL == req->info) {
24,534,392✔
878
    req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
24,534,392✔
879
    if (NULL == req->info) {
24,534,392✔
880
      taosMemoryFree(users);
×
881
      return terrno;
×
882
    }
883
  }
884

885
  code = taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
24,534,392✔
886
  if (TSDB_CODE_SUCCESS != code) {
24,534,392✔
887
    taosMemoryFree(users);
×
888
    return code;
×
889
  }
890

891
  return TSDB_CODE_SUCCESS;
24,534,392✔
892
}
893

894
int32_t hbGetExpiredDBInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *req) {
26,856,303✔
895
  SDbCacheInfo *dbs = NULL;
26,856,303✔
896
  uint32_t      dbNum = 0;
26,856,303✔
897
  int32_t       code = 0;
26,856,303✔
898

899
  code = catalogGetExpiredDBs(pCatalog, &dbs, &dbNum);
26,856,303✔
900
  if (TSDB_CODE_SUCCESS != code) {
26,856,303✔
901
    return code;
×
902
  }
903

904
  if (dbNum <= 0) {
26,856,303✔
905
    taosMemoryFree(dbs);
19,585,667✔
906
    return TSDB_CODE_SUCCESS;
19,585,667✔
907
  }
908

909
  for (int32_t i = 0; i < dbNum; ++i) {
16,119,129✔
910
    SDbCacheInfo *db = &dbs[i];
8,848,493✔
911
    tscDebug("the %dth expired db:%s, dbId:%" PRId64
8,848,493✔
912
             ", vgVersion:%d, cfgVersion:%d, numOfTable:%d, startTs:%" PRId64,
913
             i, db->dbFName, db->dbId, db->vgVersion, db->cfgVersion, db->numOfTable, db->stateTs);
914

915
    db->dbId = htobe64(db->dbId);
8,848,493✔
916
    db->vgVersion = htonl(db->vgVersion);
8,848,493✔
917
    db->cfgVersion = htonl(db->cfgVersion);
8,848,493✔
918
    db->numOfTable = htonl(db->numOfTable);
8,848,493✔
919
    db->stateTs = htobe64(db->stateTs);
8,848,493✔
920
    db->tsmaVersion = htonl(db->tsmaVersion);
8,848,493✔
921
  }
922

923
  SKv kv = {
7,270,636✔
924
      .key = HEARTBEAT_KEY_DBINFO,
925
      .valueLen = sizeof(SDbCacheInfo) * dbNum,
7,270,636✔
926
      .value = dbs,
927
  };
928

929
  tscDebug("hb got %d expired db, valueLen:%d", dbNum, kv.valueLen);
7,270,636✔
930

931
  if (NULL == req->info) {
7,270,636✔
932
    req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
33,204✔
933
    if (NULL == req->info) {
33,204✔
934
      taosMemoryFree(dbs);
×
935
      return terrno;
×
936
    }
937
  }
938

939
  code = taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
7,270,636✔
940
  if (TSDB_CODE_SUCCESS != code) {
7,270,636✔
941
    taosMemoryFree(dbs);
×
942
    return code;
×
943
  }
944

945
  return TSDB_CODE_SUCCESS;
7,270,636✔
946
}
947

948
int32_t hbGetExpiredStbInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *req) {
26,856,303✔
949
  SSTableVersion *stbs = NULL;
26,856,303✔
950
  uint32_t        stbNum = 0;
26,856,303✔
951
  int32_t         code = 0;
26,856,303✔
952

953
  code = catalogGetExpiredSTables(pCatalog, &stbs, &stbNum);
26,856,303✔
954
  if (TSDB_CODE_SUCCESS != code) {
26,856,303✔
955
    return code;
×
956
  }
957

958
  if (stbNum <= 0) {
26,856,303✔
959
    taosMemoryFree(stbs);
21,635,900✔
960
    return TSDB_CODE_SUCCESS;
21,635,900✔
961
  }
962

963
  for (int32_t i = 0; i < stbNum; ++i) {
14,289,515✔
964
    SSTableVersion *stb = &stbs[i];
9,069,112✔
965
    stb->suid = htobe64(stb->suid);
9,069,112✔
966
    stb->sversion = htonl(stb->sversion);
9,069,112✔
967
    stb->tversion = htonl(stb->tversion);
9,069,112✔
968
    stb->smaVer = htonl(stb->smaVer);
9,069,112✔
969
  }
970

971
  SKv kv = {
5,220,403✔
972
      .key = HEARTBEAT_KEY_STBINFO,
973
      .valueLen = sizeof(SSTableVersion) * stbNum,
5,220,403✔
974
      .value = stbs,
975
  };
976

977
  tscDebug("hb got %d expired stb, valueLen:%d", stbNum, kv.valueLen);
5,220,403✔
978

979
  if (NULL == req->info) {
5,220,403✔
980
    req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
1,449✔
981
    if (NULL == req->info) {
1,449✔
982
      taosMemoryFree(stbs);
×
983
      return terrno;
×
984
    }
985
  }
986

987
  code = taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
5,220,403✔
988
  if (TSDB_CODE_SUCCESS != code) {
5,220,403✔
989
    taosMemoryFree(stbs);
×
990
    return code;
×
991
  }
992

993
  return TSDB_CODE_SUCCESS;
5,220,403✔
994
}
995

996
int32_t hbGetExpiredViewInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *req) {
26,856,303✔
997
  SViewVersion    *views = NULL;
26,856,303✔
998
  uint32_t         viewNum = 0;
26,856,303✔
999
  int32_t          code = 0;
26,856,303✔
1000
  SDynViewVersion *pDynViewVer = NULL;
26,856,303✔
1001

1002
  TSC_ERR_JRET(catalogGetExpiredViews(pCatalog, &views, &viewNum, &pDynViewVer));
26,856,303✔
1003

1004
  if (viewNum <= 0) {
26,856,303✔
1005
    taosMemoryFree(views);
26,838,547✔
1006
    taosMemoryFree(pDynViewVer);
26,838,547✔
1007
    return TSDB_CODE_SUCCESS;
26,838,547✔
1008
  }
1009

1010
  for (int32_t i = 0; i < viewNum; ++i) {
36,910✔
1011
    SViewVersion *view = &views[i];
19,154✔
1012
    view->dbId = htobe64(view->dbId);
19,154✔
1013
    view->viewId = htobe64(view->viewId);
19,154✔
1014
    view->version = htonl(view->version);
19,154✔
1015
  }
1016

1017
  tscDebug("hb got %u expired view, valueLen:%lu", viewNum, sizeof(SViewVersion) * viewNum);
17,756✔
1018

1019
  if (NULL == req->info) {
17,756✔
1020
    req->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
×
1021
    if (NULL == req->info) {
×
1022
      TSC_ERR_JRET(terrno);
×
1023
    }
1024
  }
1025

1026
  SKv kv = {
17,756✔
1027
      .key = HEARTBEAT_KEY_DYN_VIEW,
1028
      .valueLen = sizeof(SDynViewVersion),
1029
      .value = pDynViewVer,
1030
  };
1031

1032
  TSC_ERR_JRET(taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv)));
17,756✔
1033

1034
  kv.key = HEARTBEAT_KEY_VIEWINFO;
17,756✔
1035
  kv.valueLen = sizeof(SViewVersion) * viewNum;
17,756✔
1036
  kv.value = views;
17,756✔
1037

1038
  TSC_ERR_JRET(taosHashPut(req->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv)));
17,756✔
1039
  return TSDB_CODE_SUCCESS;
17,756✔
1040
_return:
×
1041
  taosMemoryFree(views);
×
1042
  taosMemoryFree(pDynViewVer);
×
1043
  return code;
×
1044
}
1045

1046
int32_t hbGetExpiredTSMAInfo(SClientHbKey *connKey, struct SCatalog *pCatalog, SClientHbReq *pReq) {
26,856,303✔
1047
  int32_t       code = 0;
26,856,303✔
1048
  uint32_t      tsmaNum = 0;
26,856,303✔
1049
  STSMAVersion *tsmas = NULL;
26,856,303✔
1050

1051
  code = catalogGetExpiredTsmas(pCatalog, &tsmas, &tsmaNum);
26,856,303✔
1052
  if (code) {
26,856,303✔
1053
    taosMemoryFree(tsmas);
×
1054
    return code;
×
1055
  }
1056

1057
  if (tsmaNum <= 0) {
26,856,303✔
1058
    taosMemoryFree(tsmas);
26,755,957✔
1059
    return TSDB_CODE_SUCCESS;
26,755,957✔
1060
  }
1061

1062
  for (int32_t i = 0; i < tsmaNum; ++i) {
200,692✔
1063
    STSMAVersion *tsma = &tsmas[i];
100,346✔
1064
    tsma->dbId = htobe64(tsma->dbId);
100,346✔
1065
    tsma->tsmaId = htobe64(tsma->tsmaId);
100,346✔
1066
    tsma->version = htonl(tsma->version);
100,346✔
1067
  }
1068

1069
  tscDebug("hb got %d expred tsmas, valueLen:%lu", tsmaNum, sizeof(STSMAVersion) * tsmaNum);
100,346✔
1070

1071
  if (!pReq->info) {
100,346✔
1072
    pReq->info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
×
1073
    if (!pReq->info) {
×
1074
      taosMemoryFree(tsmas);
×
1075
      return terrno;
×
1076
    }
1077
  }
1078

1079
  SKv kv = {.key = HEARTBEAT_KEY_TSMA, .valueLen = sizeof(STSMAVersion) * tsmaNum, .value = tsmas};
100,346✔
1080
  code = taosHashPut(pReq->info, &kv.key, sizeof(kv.key), &kv, sizeof(kv));
100,346✔
1081
  if (TSDB_CODE_SUCCESS != code) {
100,346✔
1082
    taosMemoryFree(tsmas);
×
1083
    return code;
×
1084
  }
1085
  return TSDB_CODE_SUCCESS;
100,346✔
1086
}
1087

1088
int32_t hbGetAppInfo(int64_t clusterId, SClientHbReq *req) {
34,943,090✔
1089
  SAppHbReq *pApp = taosHashGet(clientHbMgr.appSummary, &clusterId, sizeof(clusterId));
34,943,090✔
1090
  if (NULL != pApp) {
34,943,090✔
1091
    (void)memcpy(&req->app, pApp, sizeof(*pApp));
34,943,090✔
1092
  } else {
1093
    (void)memset(&req->app.summary, 0, sizeof(req->app.summary));
×
1094
    req->app.pid = taosGetPId();
×
1095
    req->app.appId = clientHbMgr.appId;
×
1096
    TSC_ERR_RET(taosGetAppName(req->app.name, NULL));
×
1097
  }
1098

1099
  return TSDB_CODE_SUCCESS;
34,943,090✔
1100
}
1101

1102
int32_t hbQueryHbReqHandle(SClientHbKey *connKey, void *param, SClientHbReq *req) {
39,735,270✔
1103
  int32_t   code = 0;
39,735,270✔
1104
  SHbParam *hbParam = (SHbParam *)param;
39,735,270✔
1105
  SCatalog *pCatalog = NULL;
39,735,270✔
1106

1107
  code = hbGetQueryBasicInfo(connKey, req);
39,735,270✔
1108
  if (code != TSDB_CODE_SUCCESS) {
39,735,270✔
1109
    tscWarn("hbGetQueryBasicInfo failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
4,792,180✔
1110
    return code;
4,792,180✔
1111
  }
1112

1113
  if (hbParam->reqCnt == 0) {
34,943,090✔
1114
    code = catalogGetHandle(hbParam->clusterId, &pCatalog);
26,856,303✔
1115
    if (code != TSDB_CODE_SUCCESS) {
26,856,303✔
1116
      tscWarn("catalogGetHandle failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
×
1117
      return code;
×
1118
    }
1119

1120
    code = hbGetAppInfo(hbParam->clusterId, req);
26,856,303✔
1121
    if (TSDB_CODE_SUCCESS != code) {
26,856,303✔
1122
      tscWarn("getAppInfo failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
×
1123
      return code;
×
1124
    }
1125

1126
    if (!taosHashGet(clientHbMgr.appHbHash, &hbParam->clusterId, sizeof(hbParam->clusterId))) {
26,856,303✔
1127
      code = hbGetExpiredUserInfo(connKey, pCatalog, req);
25,263,438✔
1128
      if (TSDB_CODE_SUCCESS != code) {
25,263,438✔
1129
        tscWarn("hbGetExpiredUserInfo failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
×
1130
        return code;
×
1131
      }
1132
      if (clientHbMgr.appHbHash) {
25,263,438✔
1133
        code = taosHashPut(clientHbMgr.appHbHash, &hbParam->clusterId, sizeof(uint64_t), NULL, 0);
2,822,670✔
1134
        if (TSDB_CODE_SUCCESS != code) {
2,822,670✔
1135
          tscWarn("hbQueryHbReqHandle put clusterId failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId,
×
1136
                  tstrerror(code));
1137
          return code;
×
1138
        }
1139
      }
1140
    }
1141

1142
    // invoke after hbGetExpiredUserInfo
1143
    if (2 != atomic_load_8(&hbParam->pAppHbMgr->connHbFlag)) {
26,856,303✔
1144
      code = hbGetUserAuthInfo(connKey, hbParam, req);
915,190✔
1145
      if (TSDB_CODE_SUCCESS != code) {
915,190✔
UNCOV
1146
        tscWarn("hbGetUserAuthInfo failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
×
UNCOV
1147
        return code;
×
1148
      }
1149
      atomic_store_8(&hbParam->pAppHbMgr->connHbFlag, 1);
915,190✔
1150
    }
1151

1152
    code = hbGetExpiredDBInfo(connKey, pCatalog, req);
26,856,303✔
1153
    if (TSDB_CODE_SUCCESS != code) {
26,856,303✔
1154
      tscWarn("hbGetExpiredDBInfo failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
×
1155
      return code;
×
1156
    }
1157

1158
    code = hbGetExpiredStbInfo(connKey, pCatalog, req);
26,856,303✔
1159
    if (TSDB_CODE_SUCCESS != code) {
26,856,303✔
1160
      tscWarn("hbGetExpiredStbInfo failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
×
1161
      return code;
×
1162
    }
1163

1164
#ifdef TD_ENTERPRISE
1165
    code = hbGetExpiredViewInfo(connKey, pCatalog, req);
26,856,303✔
1166
    if (TSDB_CODE_SUCCESS != code) {
26,856,303✔
1167
      tscWarn("hbGetExpiredViewInfo failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
×
1168
      return code;
×
1169
    }
1170
#endif
1171
    code = hbGetExpiredTSMAInfo(connKey, pCatalog, req);
26,856,303✔
1172
    if (TSDB_CODE_SUCCESS != code) {
26,856,303✔
1173
      tscWarn("hbGetExpiredTSMAInfo failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
×
1174
      return code;
×
1175
    }
1176
  } else {
1177
    code = hbGetAppInfo(hbParam->clusterId, req);
8,086,787✔
1178
    if (TSDB_CODE_SUCCESS != code) {
8,086,787✔
1179
      tscWarn("hbGetAppInfo failed, clusterId:0x%" PRIx64 ", error:%s", hbParam->clusterId, tstrerror(code));
×
1180
      return code;
×
1181
    }
1182
  }
1183

1184
  ++hbParam->reqCnt;  // success to get catalog info
34,943,090✔
1185

1186
  return TSDB_CODE_SUCCESS;
34,943,090✔
1187
}
1188

1189
static FORCE_INLINE void hbMgrInitHandle() {
1190
  // init all handle
1191
  clientHbMgr.reqHandle[CONN_TYPE__QUERY] = hbQueryHbReqHandle;
1,790,236✔
1192
  clientHbMgr.reqHandle[CONN_TYPE__TMQ] = hbMqHbReqHandle;
1,790,236✔
1193

1194
  clientHbMgr.rspHandle[CONN_TYPE__QUERY] = hbQueryHbRspHandle;
1,790,236✔
1195
  clientHbMgr.rspHandle[CONN_TYPE__TMQ] = hbMqHbRspHandle;
1,790,236✔
1196
}
1,790,236✔
1197

1198
int32_t hbGatherAllInfo(SAppHbMgr *pAppHbMgr, SClientHbBatchReq **pBatchReq) {
32,408,836✔
1199
  *pBatchReq = taosMemoryCalloc(1, sizeof(SClientHbBatchReq));
32,408,836✔
1200
  if (pBatchReq == NULL) {
32,408,836✔
1201
    return terrno;
×
1202
  }
1203
  int32_t connKeyCnt = atomic_load_32(&pAppHbMgr->connKeyCnt);
32,408,836✔
1204
  (*pBatchReq)->reqs = taosArrayInit(connKeyCnt, sizeof(SClientHbReq));
32,408,836✔
1205
  if (!(*pBatchReq)->reqs) {
32,408,836✔
1206
    tFreeClientHbBatchReq(*pBatchReq);
×
1207
    return terrno;
×
1208
  }
1209

1210
  int64_t  maxIpWhiteVer = 0;
32,408,836✔
1211
  void    *pIter = NULL;
32,408,836✔
1212
  SHbParam param = {0};
32,408,836✔
1213
  while ((pIter = taosHashIterate(pAppHbMgr->activeInfo, pIter))) {
74,774,341✔
1214
    SClientHbReq *pOneReq = pIter;
42,365,505✔
1215
    SClientHbKey *connKey = &pOneReq->connKey;
42,365,505✔
1216
    STscObj      *pTscObj = (STscObj *)acquireTscObj(connKey->tscRid);
42,365,505✔
1217

1218
    if (!pTscObj || atomic_load_8(&pTscObj->dropped) == 1) {
42,365,505✔
1219
      if (pTscObj) releaseTscObj(connKey->tscRid);
2,630,235✔
1220
      continue;
2,630,235✔
1221
    }
1222

1223
    tstrncpy(pOneReq->userApp, pTscObj->optionInfo.userApp, sizeof(pOneReq->userApp));
39,735,270✔
1224
    tstrncpy(pOneReq->cInfo, pTscObj->optionInfo.cInfo, sizeof(pOneReq->cInfo));
39,735,270✔
1225
    pOneReq->userIp = pTscObj->optionInfo.userIp;
39,735,270✔
1226
    pOneReq->userDualIp = pTscObj->optionInfo.userDualIp;
39,735,270✔
1227
    tstrncpy(pOneReq->sVer, td_version, TSDB_VERSION_LEN);
39,735,270✔
1228

1229
    pOneReq = taosArrayPush((*pBatchReq)->reqs, pOneReq);
39,735,270✔
1230
    if (NULL == pOneReq) {
39,735,270✔
1231
      releaseTscObj(connKey->tscRid);
×
1232
      continue;
×
1233
    }
1234

1235
    switch (connKey->connType) {
39,735,270✔
1236
      case CONN_TYPE__QUERY: {
39,735,270✔
1237
        if (param.clusterId == 0) {
39,735,270✔
1238
          // init
1239
          param.clusterId = pOneReq->clusterId;
31,464,829✔
1240
          param.pAppHbMgr = pAppHbMgr;
31,464,829✔
1241
          param.connHbFlag = atomic_load_8(&pAppHbMgr->connHbFlag);
31,464,829✔
1242
        }
1243
        break;
39,735,270✔
1244
      }
1245
      default:
×
1246
        break;
×
1247
    }
1248
    if (clientHbMgr.reqHandle[connKey->connType]) {
39,735,270✔
1249
      int32_t code = (*clientHbMgr.reqHandle[connKey->connType])(connKey, &param, pOneReq);
39,735,270✔
1250
      if (code) {
39,735,270✔
1251
        tscWarn("hbGatherAllInfo failed since %s, tscRid:%" PRIi64 ", connType:%" PRIi8, tstrerror(code),
4,792,180✔
1252
                connKey->tscRid, connKey->connType);
1253
      }
1254
    }
1255

1256
    int64_t ver = atomic_load_64(&pTscObj->whiteListInfo.ver);
39,735,270✔
1257
    maxIpWhiteVer = TMAX(maxIpWhiteVer, ver);
39,735,270✔
1258
    releaseTscObj(connKey->tscRid);
39,735,270✔
1259
  }
1260
  (*pBatchReq)->ipWhiteListVer = maxIpWhiteVer;
32,408,836✔
1261

1262
  return TSDB_CODE_SUCCESS;
32,408,836✔
1263
}
1264

1265
void hbThreadFuncUnexpectedStopped(void) { atomic_store_8(&clientHbMgr.threadStop, 2); }
×
1266

1267
void hbMergeSummary(SAppClusterSummary *dst, SAppClusterSummary *src) {
3,832,737✔
1268
  dst->numOfInsertsReq += src->numOfInsertsReq;
3,832,737✔
1269
  dst->numOfInsertRows += src->numOfInsertRows;
3,832,737✔
1270
  dst->insertElapsedTime += src->insertElapsedTime;
3,832,737✔
1271
  dst->insertBytes += src->insertBytes;
3,832,737✔
1272
  dst->fetchBytes += src->fetchBytes;
3,832,737✔
1273
  dst->queryElapsedTime += src->queryElapsedTime;
3,832,737✔
1274
  dst->numOfSlowQueries += src->numOfSlowQueries;
3,832,737✔
1275
  dst->totalRequests += src->totalRequests;
3,832,737✔
1276
  dst->currentRequests += src->currentRequests;
3,832,737✔
1277
}
3,832,737✔
1278

1279
int32_t hbGatherAppInfo(void) {
32,134,547✔
1280
  SAppHbReq req = {0};
32,134,547✔
1281
  int32_t   code = TSDB_CODE_SUCCESS;
32,134,547✔
1282
  int       sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
32,134,547✔
1283
  if (sz > 0) {
32,134,547✔
1284
    req.pid = taosGetPId();
32,134,547✔
1285
    req.appId = clientHbMgr.appId;
32,134,547✔
1286
    TSC_ERR_RET(taosGetAppName(req.name, NULL));
32,134,547✔
1287
  }
1288

1289
  taosHashClear(clientHbMgr.appSummary);
32,134,547✔
1290

1291
  for (int32_t i = 0; i < sz; ++i) {
68,422,773✔
1292
    SAppHbMgr *pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, i);
36,288,226✔
1293
    if (pAppHbMgr == NULL) continue;
36,288,226✔
1294

1295
    int64_t    clusterId = pAppHbMgr->pAppInstInfo->clusterId;
36,288,226✔
1296
    SAppHbReq *pApp = taosHashGet(clientHbMgr.appSummary, &clusterId, sizeof(clusterId));
36,288,226✔
1297
    if (NULL == pApp) {
36,288,226✔
1298
      (void)memcpy(&req.summary, &pAppHbMgr->pAppInstInfo->summary, sizeof(req.summary));
32,455,489✔
1299
      req.startTime = pAppHbMgr->startTime;
32,455,489✔
1300
      TSC_ERR_RET(taosHashPut(clientHbMgr.appSummary, &clusterId, sizeof(clusterId), &req, sizeof(req)));
32,455,489✔
1301
    } else {
1302
      if (pAppHbMgr->startTime < pApp->startTime) {
3,832,737✔
1303
        pApp->startTime = pAppHbMgr->startTime;
×
1304
      }
1305

1306
      hbMergeSummary(&pApp->summary, &pAppHbMgr->pAppInstInfo->summary);
3,832,737✔
1307
    }
1308
  }
1309

1310
  return TSDB_CODE_SUCCESS;
32,134,547✔
1311
}
1312

1313
static void *hbThreadFunc(void *param) {
1,790,236✔
1314
  setThreadName("hb");
1,790,236✔
1315
#ifdef WINDOWS
1316
  if (taosCheckCurrentInDll()) {
1317
    atexit(hbThreadFuncUnexpectedStopped);
1318
  }
1319
#endif
1320
  while (1) {
31,030,345✔
1321
    if (1 == clientHbMgr.threadStop) {
32,820,581✔
1322
      break;
676,713✔
1323
    }
1324

1325
    if (TSDB_CODE_SUCCESS != taosThreadMutexLock(&clientHbMgr.lock)) {
32,143,868✔
1326
      tscError("taosThreadMutexLock failed");
×
1327
      return NULL;
×
1328
    }
1329

1330
    int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
32,143,868✔
1331
    if (sz > 0) {
32,143,868✔
1332
      if (TSDB_CODE_SUCCESS != hbGatherAppInfo()) {
32,134,547✔
1333
        tscError("hbGatherAppInfo failed");
×
1334
        return NULL;
×
1335
      }
1336
      if (sz > 1 && !clientHbMgr.appHbHash) {
32,134,547✔
1337
        clientHbMgr.appHbHash = taosHashInit(0, taosGetDefaultHashFunction(TSDB_DATA_TYPE_UBIGINT), true, HASH_NO_LOCK);
43,749✔
1338
        if (NULL == clientHbMgr.appHbHash) {
43,749✔
1339
          tscError("taosHashInit failed");
×
1340
          return NULL;
×
1341
        }
1342
      }
1343
      taosHashClear(clientHbMgr.appHbHash);
32,134,547✔
1344
    }
1345

1346
    for (int i = 0; i < sz; i++) {
68,432,094✔
1347
      SAppHbMgr *pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, i);
36,288,226✔
1348
      if (pAppHbMgr == NULL) {
36,288,226✔
1349
        continue;
1,052,460✔
1350
      }
1351

1352
      int32_t connCnt = atomic_load_32(&pAppHbMgr->connKeyCnt);
36,288,226✔
1353
      if (connCnt == 0) {
36,288,226✔
1354
        continue;
3,879,390✔
1355
      }
1356
      SClientHbBatchReq *pReq = NULL;
32,408,836✔
1357
      int32_t            code = hbGatherAllInfo(pAppHbMgr, &pReq);
32,408,836✔
1358
      if (TSDB_CODE_SUCCESS != code || taosArrayGetP(clientHbMgr.appHbMgrs, i) == NULL) {
32,408,836✔
1359
        terrno = code ? code : TSDB_CODE_OUT_OF_RANGE;
×
1360
        tFreeClientHbBatchReq(pReq);
×
1361
        continue;
×
1362
      }
1363
      int tlen = tSerializeSClientHbBatchReq(NULL, 0, pReq);
32,408,836✔
1364
      if (tlen == -1) {
32,408,836✔
1365
        tFreeClientHbBatchReq(pReq);
×
1366
        break;
×
1367
      }
1368
      void *buf = taosMemoryMalloc(tlen);
32,408,836✔
1369
      if (buf == NULL) {
32,408,836✔
1370
        tFreeClientHbBatchReq(pReq);
×
1371
        // hbClearReqInfo(pAppHbMgr);
1372
        break;
×
1373
      }
1374

1375
      if (tSerializeSClientHbBatchReq(buf, tlen, pReq) == -1) {
32,408,836✔
1376
        tFreeClientHbBatchReq(pReq);
×
1377
        taosMemoryFree(buf);
×
1378
        break;
×
1379
      }
1380
      SMsgSendInfo *pInfo = taosMemoryCalloc(1, sizeof(SMsgSendInfo));
32,408,836✔
1381

1382
      if (pInfo == NULL) {
32,408,836✔
1383
        tFreeClientHbBatchReq(pReq);
×
1384
        // hbClearReqInfo(pAppHbMgr);
1385
        taosMemoryFree(buf);
×
1386
        break;
×
1387
      }
1388
      pInfo->fp = hbAsyncCallBack;
32,408,836✔
1389
      pInfo->msgInfo.pData = buf;
32,408,836✔
1390
      pInfo->msgInfo.len = tlen;
32,408,836✔
1391
      pInfo->msgType = TDMT_MND_HEARTBEAT;
32,408,836✔
1392
      pInfo->param = taosMemoryMalloc(sizeof(int32_t));
32,408,836✔
1393
      if (pInfo->param  == NULL) {
32,408,836✔
1394
        tFreeClientHbBatchReq(pReq);
×
1395
        // hbClearReqInfo(pAppHbMgr);
1396
        taosMemoryFree(buf);
×
1397
        taosMemoryFree(pInfo);
×
1398
        break;
×
1399
      }
1400
      *(int32_t *)pInfo->param = i;
32,408,836✔
1401
      pInfo->paramFreeFp = taosAutoMemoryFree;
32,408,836✔
1402
      pInfo->requestId = generateRequestId();
32,408,836✔
1403
      pInfo->requestObjRefId = 0;
32,408,836✔
1404

1405
      SAppInstInfo *pAppInstInfo = pAppHbMgr->pAppInstInfo;
32,408,836✔
1406
      SEpSet        epSet = getEpSet_s(&pAppInstInfo->mgmtEp);
32,408,836✔
1407
      if (TSDB_CODE_SUCCESS != asyncSendMsgToServer(pAppInstInfo->pTransporter, &epSet, NULL, pInfo)) {
32,408,836✔
1408
        tscWarn("failed to async send msg to server");
×
1409
      }
1410
      tFreeClientHbBatchReq(pReq);
32,408,836✔
1411
      // hbClearReqInfo(pAppHbMgr);
1412
      (void)atomic_add_fetch_32(&pAppHbMgr->reportCnt, 1);
32,408,836✔
1413
    }
1414

1415
    if (TSDB_CODE_SUCCESS != taosThreadMutexUnlock(&clientHbMgr.lock)) {
32,143,868✔
1416
      tscError("taosThreadMutexLock failed");
×
1417
      return NULL;
×
1418
    }
1419
    taosMsleep(HEARTBEAT_INTERVAL);
32,143,868✔
1420
  }
1421
  taosHashCleanup(clientHbMgr.appHbHash);
676,713✔
1422
  return NULL;
676,713✔
1423
}
1424

1425
static int32_t hbCreateThread() {
1,790,236✔
1426
  int32_t      code = TSDB_CODE_SUCCESS;
1,790,236✔
1427
  TdThreadAttr thAttr;
1,666,564✔
1428
  TSC_ERR_JRET(taosThreadAttrInit(&thAttr));
1,790,236✔
1429
  TSC_ERR_JRET(taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE));
1,790,236✔
1430
#ifdef TD_COMPACT_OS
1431
  TSC_ERR_JRET(taosThreadAttrSetStackSize(&thAttr, STACK_SIZE_SMALL));
1432
#endif
1433

1434
  if (taosThreadCreate(&clientHbMgr.thread, &thAttr, hbThreadFunc, NULL) != 0) {
1,790,236✔
1435
    terrno = TAOS_SYSTEM_ERROR(ERRNO);
×
1436
    TSC_ERR_RET(terrno);
×
1437
  }
1438
  (void)taosThreadAttrDestroy(&thAttr);
1,790,236✔
1439
_return:
1,790,236✔
1440

1441
  if (code) {
1,790,236✔
1442
    terrno = TAOS_SYSTEM_ERROR(ERRNO);
×
1443
    TSC_ERR_RET(terrno);
×
1444
  }
1445

1446
  return code;
1,790,236✔
1447
}
1448

1449
static void hbStopThread() {
1,792,353✔
1450
  if (0 == atomic_load_8(&clientHbMgr.inited)) {
1,792,353✔
1451
    return;
2,117✔
1452
  }
1453
  if (atomic_val_compare_exchange_8(&clientHbMgr.threadStop, 0, 1)) {
1,790,236✔
1454
    tscDebug("hb thread already stopped");
×
1455
    return;
×
1456
  }
1457

1458
  int32_t code = TSDB_CODE_SUCCESS;
1,790,236✔
1459
  // thread quit mode kill or inner exit from self-thread
1460
  if (clientHbMgr.quitByKill) {
1,790,236✔
1461
    code = taosThreadKill(clientHbMgr.thread, 0);
1,254,115✔
1462
    if (TSDB_CODE_SUCCESS != code) {
1,254,115✔
1463
      tscError("taosThreadKill failed since %s", tstrerror(code));
×
1464
    }
1465
  } else {
1466
    code = taosThreadJoin(clientHbMgr.thread, NULL);
536,121✔
1467
    if (TSDB_CODE_SUCCESS != code) {
536,121✔
1468
      tscError("taosThreadJoin failed since %s", tstrerror(code));
×
1469
    }
1470
  }
1471

1472
  tscDebug("hb thread stopped");
1,790,236✔
1473
}
1474

1475
int32_t appHbMgrInit(SAppInstInfo *pAppInstInfo, char *key, SAppHbMgr **pAppHbMgr) {
1,861,414✔
1476
  int32_t code = TSDB_CODE_SUCCESS;
1,861,414✔
1477
  TSC_ERR_RET(hbMgrInit());
1,861,414✔
1478
  *pAppHbMgr = taosMemoryMalloc(sizeof(SAppHbMgr));
1,861,414✔
1479
  if (*pAppHbMgr == NULL) {
1,861,414✔
1480
    TSC_ERR_JRET(terrno);
×
1481
  }
1482
  // init stat
1483
  (*pAppHbMgr)->startTime = taosGetTimestampMs();
3,587,159✔
1484
  (*pAppHbMgr)->connKeyCnt = 0;
1,861,414✔
1485
  (*pAppHbMgr)->connHbFlag = 0;
1,861,414✔
1486
  (*pAppHbMgr)->reportCnt = 0;
1,861,414✔
1487
  (*pAppHbMgr)->reportBytes = 0;
1,861,414✔
1488
  (*pAppHbMgr)->key = taosStrdup(key);
1,861,414✔
1489
  if ((*pAppHbMgr)->key == NULL) {
1,861,414✔
1490
    TSC_ERR_JRET(terrno);
×
1491
  }
1492

1493
  // init app info
1494
  (*pAppHbMgr)->pAppInstInfo = pAppInstInfo;
1,861,414✔
1495

1496
  // init hash info
1497
  (*pAppHbMgr)->activeInfo = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
1,861,414✔
1498

1499
  if ((*pAppHbMgr)->activeInfo == NULL) {
1,861,414✔
1500
    TSC_ERR_JRET(terrno);
×
1501
  }
1502

1503
  // taosHashSetFreeFp(pAppHbMgr->activeInfo, tFreeClientHbReq);
1504

1505
  TSC_ERR_JRET(taosThreadMutexLock(&clientHbMgr.lock));
1,861,414✔
1506
  if (taosArrayPush(clientHbMgr.appHbMgrs, &(*pAppHbMgr)) == NULL) {
3,722,828✔
1507
    code = terrno;
×
1508
    (void)taosThreadMutexUnlock(&clientHbMgr.lock);
×
1509
    goto _return;
×
1510
  }
1511
  (*pAppHbMgr)->idx = taosArrayGetSize(clientHbMgr.appHbMgrs) - 1;
1,861,414✔
1512
  TSC_ERR_JRET(taosThreadMutexUnlock(&clientHbMgr.lock));
1,861,414✔
1513

1514
  return TSDB_CODE_SUCCESS;
1,861,414✔
1515
_return:
×
1516
  taosMemoryFree(*pAppHbMgr);
×
1517
  return code;
×
1518
}
1519

1520
void hbFreeAppHbMgr(SAppHbMgr *pTarget) {
1,861,414✔
1521
  void *pIter = taosHashIterate(pTarget->activeInfo, NULL);
1,861,414✔
1522
  while (pIter != NULL) {
2,115,955✔
1523
    SClientHbReq *pOneReq = pIter;
254,541✔
1524
    tFreeClientHbReq(pOneReq);
1525
    pIter = taosHashIterate(pTarget->activeInfo, pIter);
254,541✔
1526
  }
1527
  taosHashCleanup(pTarget->activeInfo);
1,861,414✔
1528
  pTarget->activeInfo = NULL;
1,861,414✔
1529

1530
  taosMemoryFree(pTarget->key);
1,861,414✔
1531
  taosMemoryFree(pTarget);
1,861,414✔
1532
}
1,861,414✔
1533

1534
void hbRemoveAppHbMrg(SAppHbMgr **pAppHbMgr) {
1,861,414✔
1535
  int32_t code = TSDB_CODE_SUCCESS;
1,861,414✔
1536
  code = taosThreadMutexLock(&clientHbMgr.lock);
1,861,414✔
1537
  if (TSDB_CODE_SUCCESS != code) {
1,861,414✔
1538
    tscError("failed to lock clientHbMgr, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
1539
  }
1540
  int32_t mgrSize = taosArrayGetSize(clientHbMgr.appHbMgrs);
1,861,414✔
1541
  for (int32_t i = 0; i < mgrSize; ++i) {
1,861,414✔
1542
    SAppHbMgr *pItem = taosArrayGetP(clientHbMgr.appHbMgrs, i);
×
1543
    if (pItem == *pAppHbMgr) {
×
1544
      hbFreeAppHbMgr(*pAppHbMgr);
×
1545
      *pAppHbMgr = NULL;
×
1546
      taosArraySet(clientHbMgr.appHbMgrs, i, pAppHbMgr);
×
1547
      break;
×
1548
    }
1549
  }
1550
  code = taosThreadMutexUnlock(&clientHbMgr.lock);
1,861,414✔
1551
  if (TSDB_CODE_SUCCESS != code) {
1,861,414✔
1552
    tscError("failed to unlock clientHbMgr, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
1553
  }
1554
}
1,861,414✔
1555

1556
void appHbMgrCleanup(void) {
1,790,236✔
1557
  int sz = taosArrayGetSize(clientHbMgr.appHbMgrs);
1,790,236✔
1558
  for (int i = 0; i < sz; i++) {
3,651,650✔
1559
    SAppHbMgr *pTarget = taosArrayGetP(clientHbMgr.appHbMgrs, i);
1,861,414✔
1560
    if (pTarget == NULL) continue;
1,861,414✔
1561
    hbFreeAppHbMgr(pTarget);
1,861,414✔
1562
  }
1563
}
1,790,236✔
1564

1565
int32_t hbMgrInit() {
1,861,414✔
1566
  // init once
1567
  int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 0, 1);
1,861,414✔
1568
  if (old == 1) return 0;
1,861,414✔
1569

1570
  clientHbMgr.appId = tGenIdPI64();
1,790,236✔
1571
  tscInfo("app initialized, appId:0x%" PRIx64, clientHbMgr.appId);
1,790,236✔
1572

1573
  clientHbMgr.appSummary = taosHashInit(10, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_NO_LOCK);
1,790,236✔
1574
  if (NULL == clientHbMgr.appSummary) {
1,790,236✔
1575
    uError("hbMgrInit:taosHashInit error") return terrno;
×
1576
  }
1577
  clientHbMgr.appHbMgrs = taosArrayInit(0, sizeof(void *));
1,790,236✔
1578
  if (NULL == clientHbMgr.appHbMgrs) {
1,790,236✔
1579
    uError("hbMgrInit:taosArrayInit error") return terrno;
×
1580
  }
1581
  TdThreadMutexAttr attr = {0};
1,790,236✔
1582

1583
  int ret = taosThreadMutexAttrInit(&attr);
1,790,236✔
1584
  if (ret != 0) {
1,790,236✔
1585
    uError("hbMgrInit:taosThreadMutexAttrInit error") return ret;
×
1586
  }
1587

1588
  ret = taosThreadMutexAttrSetType(&attr, PTHREAD_MUTEX_RECURSIVE);
1,790,236✔
1589
  if (ret != 0) {
1,790,236✔
1590
    uError("hbMgrInit:taosThreadMutexAttrSetType error") return ret;
×
1591
  }
1592

1593
  ret = taosThreadMutexInit(&clientHbMgr.lock, &attr);
1,790,236✔
1594
  if (ret != 0) {
1,790,236✔
1595
    uError("hbMgrInit:taosThreadMutexInit error") return ret;
×
1596
  }
1597

1598
  ret = taosThreadMutexAttrDestroy(&attr);
1,790,236✔
1599
  if (ret != 0) {
1,790,236✔
1600
    uError("hbMgrInit:taosThreadMutexAttrDestroy error") return ret;
×
1601
  }
1602

1603
  // init handle funcs
1604
  hbMgrInitHandle();
1605

1606
  // init backgroud thread
1607
  ret = hbCreateThread();
1,790,236✔
1608
  if (ret != 0) {
1,790,236✔
1609
    uError("hbMgrInit:hbCreateThread error") return ret;
×
1610
  }
1611

1612
  return 0;
1,790,236✔
1613
}
1614

1615
void hbMgrCleanUp() {
1,792,353✔
1616
  hbStopThread();
1,792,353✔
1617

1618
  // destroy all appHbMgr
1619
  int8_t old = atomic_val_compare_exchange_8(&clientHbMgr.inited, 1, 0);
1,792,353✔
1620
  if (old == 0) return;
1,792,353✔
1621

1622
  int32_t code = taosThreadMutexLock(&clientHbMgr.lock);
1,790,236✔
1623
  if (TSDB_CODE_SUCCESS != code) {
1,790,236✔
1624
    tscError("failed to lock clientHbMgr, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
1625
  }
1626
  appHbMgrCleanup();
1,790,236✔
1627
  taosArrayDestroy(clientHbMgr.appHbMgrs);
1,790,236✔
1628
  clientHbMgr.appHbMgrs = NULL;
1,790,236✔
1629
  code = taosThreadMutexUnlock(&clientHbMgr.lock);
1,790,236✔
1630
  if (TSDB_CODE_SUCCESS != code) {
1,790,236✔
1631
    tscError("failed to unlock clientHbMgr, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
1632
  }
1633
}
1634

1635
int32_t hbRegisterConnImpl(SAppHbMgr *pAppHbMgr, SClientHbKey connKey, int64_t clusterId) {
3,692,508✔
1636
  // init hash in activeinfo
1637
  void *data = taosHashGet(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
3,692,508✔
1638
  if (data != NULL) {
3,692,508✔
1639
    return 0;
×
1640
  }
1641
  SClientHbReq hbReq = {0};
3,692,508✔
1642
  hbReq.connKey = connKey;
3,692,508✔
1643
  hbReq.clusterId = clusterId;
3,692,508✔
1644
  // hbReq.info = taosHashInit(64, hbKeyHashFunc, 1, HASH_ENTRY_LOCK);
1645

1646
  TSC_ERR_RET(taosHashPut(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey), &hbReq, sizeof(SClientHbReq)));
3,692,508✔
1647

1648
  (void)atomic_add_fetch_32(&pAppHbMgr->connKeyCnt, 1);
3,692,508✔
1649
  return 0;
3,692,508✔
1650
}
1651

1652
int32_t hbRegisterConn(SAppHbMgr *pAppHbMgr, int64_t tscRefId, int64_t clusterId, int8_t connType) {
3,775,816✔
1653
  SClientHbKey connKey = {
3,775,816✔
1654
      .tscRid = tscRefId,
1655
      .connType = connType,
1656
  };
1657

1658
  switch (connType) {
3,775,816✔
1659
    case CONN_TYPE__QUERY: {
3,692,508✔
1660
      return hbRegisterConnImpl(pAppHbMgr, connKey, clusterId);
3,692,508✔
1661
    }
1662
    case CONN_TYPE__TMQ: {
83,308✔
1663
      return 0;
83,308✔
1664
    }
1665
    default:
×
1666
      return 0;
×
1667
  }
1668
}
1669

1670
void hbDeregisterConn(STscObj *pTscObj, SClientHbKey connKey) {
3,535,400✔
1671
  int32_t code = taosThreadMutexLock(&clientHbMgr.lock);
3,535,400✔
1672
  if (TSDB_CODE_SUCCESS != code) {
3,535,518✔
1673
    tscError("failed to lock clientHbMgr, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
1674
  }
1675
  SAppHbMgr *pAppHbMgr = taosArrayGetP(clientHbMgr.appHbMgrs, pTscObj->appHbMgrIdx);
3,535,518✔
1676
  if (pAppHbMgr) {
3,535,518✔
1677
    SClientHbReq *pReq = taosHashAcquire(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
3,535,518✔
1678
    if (pReq) {
3,535,518✔
1679
      tFreeClientHbReq(pReq);
1680
      code = taosHashRemove(pAppHbMgr->activeInfo, &connKey, sizeof(SClientHbKey));
3,437,967✔
1681
      if (TSDB_CODE_SUCCESS != code) {
3,437,967✔
1682
        tscError("hbDeregisterConn taosHashRemove error, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
1683
      }
1684
      taosHashRelease(pAppHbMgr->activeInfo, pReq);
3,437,967✔
1685
      (void)atomic_sub_fetch_32(&pAppHbMgr->connKeyCnt, 1);
3,437,967✔
1686
    }
1687
  }
1688
  code = taosThreadMutexUnlock(&clientHbMgr.lock);
3,535,518✔
1689
  if (TSDB_CODE_SUCCESS != code) {
3,535,518✔
1690
    tscError("failed to unlock clientHbMgr, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
1691
  }
1692
}
3,535,518✔
1693

1694
// set heart beat thread quit mode , if quicByKill 1 then kill thread else quit from inner
1695
void taos_set_hb_quit(int8_t quitByKill) { clientHbMgr.quitByKill = quitByKill; }
1,255,689✔
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