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

taosdata / TDengine / #4994

18 Mar 2026 06:36AM UTC coverage: 72.244%. Remained the same
#4994

push

travis-ci

web-flow
Merge cab2af0c8 into b1e934936

143 of 168 new or added lines in 10 files covered. (85.12%)

1172 existing lines in 10 files now uncovered.

245100 of 339268 relevant lines covered (72.24%)

354029556.59 hits per line

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

56.52
/source/client/src/clientEnv.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 <ttimer.h>
17
#include "cJSON.h"
18
#include "catalog.h"
19
#include "clientInt.h"
20
#include "clientLog.h"
21
#include "clientMonitor.h"
22
#include "functionMgt.h"
23
#include "os.h"
24
#include "osSleep.h"
25
#include "query.h"
26
#include "qworker.h"
27
#include "scheduler.h"
28
#include "tcache.h"
29
#include "tcompare.h"
30
#include "tconv.h"
31
#include "tglobal.h"
32
#include "thttp.h"
33
#include "tmsg.h"
34
#include "tqueue.h"
35
#include "tref.h"
36
#include "trpc.h"
37
#include "tsched.h"
38
#include "ttime.h"
39
#include "tversion.h"
40

41
#include "clientSession.h"
42
#include "cus_name.h"
43

44
#define TSC_VAR_NOT_RELEASE 1
45
#define TSC_VAR_RELEASED    0
46

47
#define ENV_JSON_FALSE_CHECK(c)                     \
48
  do {                                              \
49
    if (!c) {                                       \
50
      tscError("faild to add item to JSON object"); \
51
      code = TSDB_CODE_TSC_FAIL_GENERATE_JSON;      \
52
      goto _end;                                    \
53
    }                                               \
54
  } while (0)
55

56
#define ENV_ERR_RET(c, info)          \
57
  do {                                \
58
    int32_t _code = (c);              \
59
    if (_code != TSDB_CODE_SUCCESS) { \
60
      terrno = _code;                 \
61
      tscInitRes = _code;             \
62
      tscError(info);                 \
63
      return;                         \
64
    }                                 \
65
  } while (0)
66

67
STscDbg   tscDbg = {0};
68
SAppInfo  appInfo;
69
int64_t   lastClusterId = 0;
70
int32_t   clientReqRefPool = -1;
71
int32_t   clientConnRefPool = -1;
72
int32_t   clientStop = -1;
73
SHashObj *pTimezoneMap = NULL;
74

75
static TdThreadOnce tscinit = PTHREAD_ONCE_INIT;
76
volatile int32_t    tscInitRes = 0;
77

78
static int32_t registerRequest(SRequestObj *pRequest, STscObj *pTscObj) {
2,147,483,647✔
79
  int32_t code = TSDB_CODE_SUCCESS;
2,147,483,647✔
80
  // connection has been released already, abort creating request.
81
  pRequest->self = taosAddRef(clientReqRefPool, pRequest);
2,147,483,647✔
82
  if (pRequest->self < 0) {
2,147,483,647✔
83
    tscError("failed to add ref to request");
×
84
    code = terrno;
×
85
    return code;
×
86
  }
87

88
  int32_t num = atomic_add_fetch_32(&pTscObj->numOfReqs, 1);
2,147,483,647✔
89

90
  if (pTscObj->pAppInfo) {
2,147,483,647✔
91
    SAppClusterSummary *pSummary = &pTscObj->pAppInfo->summary;
2,147,483,647✔
92

93
    int32_t total = atomic_add_fetch_64((int64_t *)&pSummary->totalRequests, 1);
2,147,483,647✔
94
    int32_t currentInst = atomic_add_fetch_64((int64_t *)&pSummary->currentRequests, 1);
2,147,483,647✔
95
    tscDebug("req:0x%" PRIx64 ", create request from conn:0x%" PRIx64
2,147,483,647✔
96
             ", current:%d, app current:%d, total:%d, QID:0x%" PRIx64,
97
             pRequest->self, pRequest->pTscObj->id, num, currentInst, total, pRequest->requestId);
98
  }
99

100
  return code;
2,147,483,647✔
101
}
102

103
static void concatStrings(SArray *list, char *buf, int size) {
×
104
  int len = 0;
×
105
  for (int i = 0; i < taosArrayGetSize(list); i++) {
×
106
    char *db = taosArrayGet(list, i);
×
107
    if (NULL == db) {
×
108
      tscError("get dbname failed, buf:%s", buf);
×
109
      break;
×
110
    }
111
    char *dot = strchr(db, '.');
×
112
    if (dot != NULL) {
×
113
      db = dot + 1;
×
114
    }
115
    if (i != 0) {
×
116
      (void)strncat(buf, ",", size - 1 - len);
×
117
      len += 1;
×
118
    }
119
    int ret = snprintf(buf + len, size - len, "%s", db);
×
120
    if (ret < 0) {
×
121
      tscError("snprintf failed, buf:%s, ret:%d", buf, ret);
×
122
      break;
×
123
    }
124
    len += ret;
×
125
    if (len >= size) {
×
126
      tscInfo("dbList is truncated, buf:%s, len:%d", buf, len);
×
127
      break;
×
128
    }
129
  }
130
}
×
131
#ifdef USE_REPORT
132
static int32_t generateWriteSlowLog(STscObj *pTscObj, SRequestObj *pRequest, int32_t reqType, int64_t duration) {
×
133
  cJSON  *json = cJSON_CreateObject();
×
134
  int32_t code = TSDB_CODE_SUCCESS;
×
135
  if (json == NULL) {
×
136
    tscError("failed to create monitor json");
×
137
    return TSDB_CODE_OUT_OF_MEMORY;
×
138
  }
139
  char clusterId[32] = {0};
×
140
  if (snprintf(clusterId, sizeof(clusterId), "%" PRId64, pTscObj->pAppInfo->clusterId) < 0) {
×
141
    tscError("failed to generate clusterId:%" PRId64, pTscObj->pAppInfo->clusterId);
×
142
    code = TSDB_CODE_FAILED;
×
143
    goto _end;
×
144
  }
145

146
  char startTs[32] = {0};
×
147
  if (snprintf(startTs, sizeof(startTs), "%" PRId64, pRequest->metric.start / 1000) < 0) {
×
148
    tscError("failed to generate startTs:%" PRId64, pRequest->metric.start / 1000);
×
149
    code = TSDB_CODE_FAILED;
×
150
    goto _end;
×
151
  }
152

153
  char requestId[32] = {0};
×
154
  if (snprintf(requestId, sizeof(requestId), "%" PRIu64, pRequest->requestId) < 0) {
×
155
    tscError("failed to generate requestId:%" PRIu64, pRequest->requestId);
×
156
    code = TSDB_CODE_FAILED;
×
157
    goto _end;
×
158
  }
159
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "cluster_id", cJSON_CreateString(clusterId)));
×
160
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "start_ts", cJSON_CreateString(startTs)));
×
161
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "request_id", cJSON_CreateString(requestId)));
×
162
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "query_time", cJSON_CreateNumber(duration / 1000)));
×
163
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "code", cJSON_CreateNumber(pRequest->code)));
×
164
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "error_info", cJSON_CreateString(tstrerror(pRequest->code))));
×
165
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "type", cJSON_CreateNumber(reqType)));
×
166
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(
×
167
      json, "rows_num", cJSON_CreateNumber(pRequest->body.resInfo.numOfRows + pRequest->body.resInfo.totalRows)));
168
  if (pRequest->sqlstr != NULL &&
×
169
      strlen(pRequest->sqlstr) > pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogMaxLen) {
×
170
    char tmp = pRequest->sqlstr[pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogMaxLen];
×
171
    pRequest->sqlstr[pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogMaxLen] = '\0';
×
172
    ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr)));
×
173
    pRequest->sqlstr[pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogMaxLen] = tmp;
×
174
  } else {
175
    ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "sql", cJSON_CreateString(pRequest->sqlstr)));
×
176
  }
177

178
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "user", cJSON_CreateString(pTscObj->user)));
×
179
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "process_name", cJSON_CreateString(appInfo.appName)));
×
180
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "ip", cJSON_CreateString(tsLocalFqdn)));
×
181

182
  char pid[32] = {0};
×
183
  if (snprintf(pid, sizeof(pid), "%d", appInfo.pid) < 0) {
×
184
    tscError("failed to generate pid:%d", appInfo.pid);
×
185
    code = TSDB_CODE_FAILED;
×
186
    goto _end;
×
187
  }
188

189
  ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "process_id", cJSON_CreateString(pid)));
×
190
  if (pRequest->dbList != NULL) {
×
191
    char dbList[1024] = {0};
×
192
    concatStrings(pRequest->dbList, dbList, sizeof(dbList) - 1);
×
193
    ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString(dbList)));
×
194
  } else if (pRequest->pDb != NULL) {
×
195
    ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString(pRequest->pDb)));
×
196
  } else {
197
    ENV_JSON_FALSE_CHECK(cJSON_AddItemToObject(json, "db", cJSON_CreateString("")));
×
198
  }
199

200
  char *value = cJSON_PrintUnformatted(json);
×
201
  if (value == NULL || strlen(value) == 0) {
×
202
    tscError("failed to print json, data:%s", value == NULL ? "null" : value);
×
203
    code = TSDB_CODE_FAILED;
×
204
    goto _end;
×
205
  }
206
  MonitorSlowLogData data = {0};
×
207
  data.clusterId = pTscObj->pAppInfo->clusterId;
×
208
  data.type = SLOW_LOG_WRITE;
×
209
  data.data = value;
×
210
  code = monitorPutData2MonitorQueue(data);
×
211
  if (TSDB_CODE_SUCCESS != code) {
×
212
    taosMemoryFree(value);
×
213
    goto _end;
×
214
  }
215

216
_end:
×
217
  cJSON_Delete(json);
×
218
  return code;
×
219
}
220
#endif
221
static bool checkSlowLogExceptDb(SRequestObj *pRequest, char *exceptDb) {
6,779,871✔
222
  if (pRequest->pDb != NULL) {
6,779,871✔
223
    return strcmp(pRequest->pDb, exceptDb) != 0;
4,023,137✔
224
  }
225

226
  for (int i = 0; i < taosArrayGetSize(pRequest->dbList); i++) {
4,885,476✔
227
    char *db = taosArrayGet(pRequest->dbList, i);
2,128,742✔
228
    if (NULL == db) {
2,128,742✔
229
      tscError("get dbname failed, exceptDb:%s", exceptDb);
×
230
      return false;
×
231
    }
232
    char *dot = strchr(db, '.');
2,128,742✔
233
    if (dot != NULL) {
2,128,742✔
234
      db = dot + 1;
2,128,742✔
235
    }
236
    if (strcmp(db, exceptDb) == 0) {
2,128,742✔
237
      return false;
×
238
    }
239
  }
240
  return true;
2,756,734✔
241
}
242

243
static void deregisterRequest(SRequestObj *pRequest) {
2,147,483,647✔
244
  if (pRequest == NULL) {
2,147,483,647✔
245
    tscError("pRequest == NULL");
×
246
    return;
×
247
  }
248

249
  STscObj            *pTscObj = pRequest->pTscObj;
2,147,483,647✔
250
  SAppClusterSummary *pActivity = &pTscObj->pAppInfo->summary;
2,147,483,647✔
251

252
  int32_t currentInst = atomic_sub_fetch_64((int64_t *)&pActivity->currentRequests, 1);
2,147,483,647✔
253
  int32_t num = atomic_sub_fetch_32(&pTscObj->numOfReqs, 1);
2,147,483,647✔
254
  int32_t reqType = SLOW_LOG_TYPE_OTHERS;
2,147,483,647✔
255

256
  int64_t duration = taosGetTimestampUs() - pRequest->metric.start;
2,147,483,647✔
257
  tscDebug("req:0x%" PRIx64 ", free from conn:0x%" PRIx64 ", QID:0x%" PRIx64
2,147,483,647✔
258
           ", elapsed:%.2f ms, current:%d, app current:%d",
259
           pRequest->self, pTscObj->id, pRequest->requestId, duration / 1000.0, num, currentInst);
260

261
  if (TSDB_CODE_SUCCESS == nodesSimAcquireAllocator(pRequest->allocatorRefId)) {
2,147,483,647✔
262
    if ((pRequest->pQuery && pRequest->pQuery->pRoot && QUERY_NODE_VNODE_MODIFY_STMT == pRequest->pQuery->pRoot->type &&
2,147,483,647✔
263
         (0 == ((SVnodeModifyOpStmt *)pRequest->pQuery->pRoot)->sqlNodeType)) ||
2,147,483,647✔
264
        QUERY_NODE_VNODE_MODIFY_STMT == pRequest->stmtType) {
2,147,483,647✔
265
      tscDebug("req:0x%" PRIx64 ", insert duration:%" PRId64 "us, parseCost:%" PRId64 "us, ctgCost:%" PRId64
2,147,483,647✔
266
               "us, analyseCost:%" PRId64 "us, planCost:%" PRId64 "us, exec:%" PRId64 "us, QID:0x%" PRIx64,
267
               pRequest->self, duration, pRequest->metric.parseCostUs, pRequest->metric.ctgCostUs,
268
               pRequest->metric.analyseCostUs, pRequest->metric.planCostUs, pRequest->metric.execCostUs,
269
               pRequest->requestId);
270
      (void)atomic_add_fetch_64((int64_t *)&pActivity->insertElapsedTime, duration);
2,147,483,647✔
271
      reqType = SLOW_LOG_TYPE_INSERT;
2,147,483,647✔
272
    } else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) {
2,147,483,647✔
273
      tscDebug("req:0x%" PRIx64 ", query duration:%" PRId64 "us, parseCost:%" PRId64 "us, ctgCost:%" PRId64
2,147,483,647✔
274
               "us, analyseCost:%" PRId64 "us, planCost:%" PRId64 "us, exec:%" PRId64 "us, QID:0x%" PRIx64,
275
               pRequest->self, duration, pRequest->metric.parseCostUs, pRequest->metric.ctgCostUs,
276
               pRequest->metric.analyseCostUs, pRequest->metric.planCostUs, pRequest->metric.execCostUs,
277
               pRequest->requestId);
278

279
      (void)atomic_add_fetch_64((int64_t *)&pActivity->queryElapsedTime, duration);
2,147,483,647✔
280
      reqType = SLOW_LOG_TYPE_QUERY;
2,147,483,647✔
281
    }
282

283
    if (TSDB_CODE_SUCCESS != nodesSimReleaseAllocator(pRequest->allocatorRefId)) {
2,147,483,647✔
284
      tscError("failed to release allocator");
×
285
    }
286
  }
287

288
#ifdef USE_REPORT
289
  if (pTscObj->pAppInfo->serverCfg.monitorParas.tsEnableMonitor) {
2,147,483,647✔
290
    if (QUERY_NODE_VNODE_MODIFY_STMT == pRequest->stmtType || QUERY_NODE_INSERT_STMT == pRequest->stmtType) {
10,921,389✔
291
      sqlReqLog(pTscObj->id, pRequest->killed, pRequest->code, MONITORSQLTYPEINSERT);
5,657,402✔
292
    } else if (QUERY_NODE_SELECT_STMT == pRequest->stmtType) {
5,263,987✔
293
      sqlReqLog(pTscObj->id, pRequest->killed, pRequest->code, MONITORSQLTYPESELECT);
1,166,606✔
294
    } else if (QUERY_NODE_DELETE_STMT == pRequest->stmtType) {
4,097,381✔
295
      sqlReqLog(pTscObj->id, pRequest->killed, pRequest->code, MONITORSQLTYPEDELETE);
12,144✔
296
    }
297
  }
298

299
  if ((duration >= pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogThreshold * 1000000UL) &&
2,147,483,647✔
300
      checkSlowLogExceptDb(pRequest, pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogExceptDb)) {
6,779,871✔
301
    (void)atomic_add_fetch_64((int64_t *)&pActivity->numOfSlowQueries, 1);
6,779,871✔
302
    if (pTscObj->pAppInfo->serverCfg.monitorParas.tsSlowLogScope & reqType) {
6,779,871✔
303
      taosPrintSlowLog("PID:%d, connId:%u, QID:0x%" PRIx64 ", Start:%" PRId64 "us, Duration:%" PRId64 "us, SQL:%s",
3,046,488✔
304
                       taosGetPId(), pTscObj->connId, pRequest->requestId, pRequest->metric.start, duration,
305
                       pRequest->sqlstr);
306
      if (pTscObj->pAppInfo->serverCfg.monitorParas.tsEnableMonitor) {
3,046,488✔
307
        slowQueryLog(pTscObj->id, pRequest->killed, pRequest->code, duration);
×
308
        if (TSDB_CODE_SUCCESS != generateWriteSlowLog(pTscObj, pRequest, reqType, duration)) {
×
309
          tscError("failed to generate write slow log");
×
310
        }
311
      }
312
    }
313
  }
314
#endif
315

316
  releaseTscObj(pTscObj->id);
2,147,483,647✔
317
}
318

319
// todo close the transporter properly
320
void closeTransporter(SAppInstInfo *pAppInfo) {
33,420,472✔
321
  if (pAppInfo == NULL || pAppInfo->pTransporter == NULL) {
33,420,472✔
322
    return;
×
323
  }
324

325
  tscDebug("free transporter:%p in app inst %p", pAppInfo->pTransporter, pAppInfo);
33,420,472✔
326
  rpcClose(pAppInfo->pTransporter);
33,420,472✔
327
}
328

329
static bool clientRpcRfp(int32_t code, tmsg_t msgType) {
368,925,175✔
330
  if (NEED_REDIRECT_ERROR(code)) {
368,925,175✔
331
    if (msgType == TDMT_SCH_QUERY || msgType == TDMT_SCH_MERGE_QUERY || msgType == TDMT_SCH_FETCH ||
277,873,097✔
332
        msgType == TDMT_SCH_MERGE_FETCH || msgType == TDMT_SCH_QUERY_HEARTBEAT || msgType == TDMT_SCH_DROP_TASK ||
277,873,442✔
333
        msgType == TDMT_SCH_TASK_NOTIFY) {
334
      return false;
×
335
    }
336
    return true;
277,873,442✔
337
  } else if (code == TSDB_CODE_UTIL_QUEUE_OUT_OF_MEMORY || code == TSDB_CODE_OUT_OF_RPC_MEMORY_QUEUE ||
91,052,078✔
338
             code == TSDB_CODE_SYN_WRITE_STALL || code == TSDB_CODE_SYN_PROPOSE_NOT_READY ||
91,052,400✔
339
             code == TSDB_CODE_SYN_RESTORING) {
340
    tscDebug("client msg type %s should retry since %s", TMSG_INFO(msgType), tstrerror(code));
13,984✔
341
    return true;
×
342
  } else {
343
    return false;
91,038,094✔
344
  }
345
}
346

347
// start timer for particular msgType
348
static bool clientRpcTfp(int32_t code, tmsg_t msgType) {
×
349
  if (msgType == TDMT_VND_SUBMIT || msgType == TDMT_VND_CREATE_TABLE) {
×
350
    return true;
×
351
  }
352
  return false;
×
353
}
354

355
// TODO refactor
356
int32_t openTransporter(const char *user, const char *auth, int32_t numOfThread, void **pDnodeConn) {
33,420,472✔
357
  SRpcInit rpcInit;
32,989,429✔
358
  (void)memset(&rpcInit, 0, sizeof(rpcInit));
33,420,472✔
359
  rpcInit.localPort = 0;
33,420,472✔
360
  rpcInit.label = "TSC";
33,420,472✔
361
  rpcInit.numOfThreads = tsNumOfRpcThreads;
33,420,472✔
362
  rpcInit.cfp = processMsgFromServer;
33,420,472✔
363
  rpcInit.rfp = clientRpcRfp;
33,420,472✔
364
  rpcInit.sessions = 1024;
33,420,472✔
365
  rpcInit.connType = TAOS_CONN_CLIENT;
33,420,472✔
366
  rpcInit.user = (char *)(user ? user : auth);
33,420,472✔
367
  rpcInit.idleTime = tsShellActivityTimer * 1000;
33,420,472✔
368
  rpcInit.compressSize = tsCompressMsgSize;
33,420,472✔
369
  rpcInit.dfp = destroyAhandle;
33,420,472✔
370

371
  rpcInit.retryMinInterval = tsRedirectPeriod;
33,420,472✔
372
  rpcInit.retryStepFactor = tsRedirectFactor;
33,420,472✔
373
  rpcInit.retryMaxInterval = tsRedirectMaxPeriod;
33,420,472✔
374
  rpcInit.retryMaxTimeout = tsMaxRetryWaitTime;
33,420,472✔
375

376
  int32_t connLimitNum = tsNumOfRpcSessions / (tsNumOfRpcThreads * 3);
33,420,472✔
377
  connLimitNum = TMAX(connLimitNum, 10);
33,420,472✔
378
  connLimitNum = TMIN(connLimitNum, 1000);
33,420,472✔
379
  rpcInit.connLimitNum = connLimitNum;
33,420,472✔
380
  rpcInit.shareConnLimit = tsShareConnLimit;
33,420,472✔
381
  rpcInit.timeToGetConn = tsTimeToGetAvailableConn;
33,420,472✔
382
  rpcInit.startReadTimer = 1;
33,420,472✔
383
  rpcInit.readTimeout = tsReadTimeout;
33,420,472✔
384
  rpcInit.ipv6 = tsEnableIpv6;
33,420,472✔
385
  rpcInit.enableSSL = tsEnableTLS;
33,420,472✔
386
  rpcInit.enableSasl = tsEnableSasl;
33,420,472✔
387
  rpcInit.isToken = user == NULL ? 1 : 0;
33,420,472✔
388

389
  memcpy(rpcInit.caPath, tsTLSCaPath, strlen(tsTLSCaPath));
33,420,472✔
390
  memcpy(rpcInit.certPath, tsTLSSvrCertPath, strlen(tsTLSSvrCertPath));
33,420,472✔
391
  memcpy(rpcInit.keyPath, tsTLSSvrKeyPath, strlen(tsTLSSvrKeyPath));
33,420,472✔
392
  memcpy(rpcInit.cliCertPath, tsTLSCliCertPath, strlen(tsTLSCliCertPath));
33,420,472✔
393
  memcpy(rpcInit.cliKeyPath, tsTLSCliKeyPath, strlen(tsTLSCliKeyPath));
33,420,472✔
394

395
  int32_t code = taosVersionStrToInt(td_version, &rpcInit.compatibilityVer);
33,420,472✔
396
  if (TSDB_CODE_SUCCESS != code) {
33,420,472✔
397
    tscError("invalid version string.");
×
398
    return code;
×
399
  }
400

401
  tscInfo("rpc max retry timeout %" PRId64 "", rpcInit.retryMaxTimeout);
33,420,472✔
402
  *pDnodeConn = rpcOpen(&rpcInit);
33,420,472✔
403
  if (*pDnodeConn == NULL) {
33,420,472✔
404
    tscError("failed to init connection to server since %s", tstrerror(terrno));
×
405
    code = terrno;
×
406
  }
407

408
  return code;
33,420,472✔
409
}
410

411
void destroyAllRequests(SHashObj *pRequests) {
2,145,773,569✔
412
  void *pIter = taosHashIterate(pRequests, NULL);
2,145,773,569✔
413
  while (pIter != NULL) {
2,145,764,898✔
414
    int64_t *rid = pIter;
×
415

416
    SRequestObj *pRequest = acquireRequest(*rid);
×
417
    if (pRequest) {
×
418
      destroyRequest(pRequest);
×
419
      (void)releaseRequest(*rid);  // ignore error
×
420
    }
421

422
    pIter = taosHashIterate(pRequests, pIter);
×
423
  }
424
}
2,145,764,898✔
425

426
void stopAllRequests(SHashObj *pRequests) {
6,992✔
427
  void *pIter = taosHashIterate(pRequests, NULL);
6,992✔
428
  while (pIter != NULL) {
6,992✔
429
    int64_t *rid = pIter;
×
430

431
    SRequestObj *pRequest = acquireRequest(*rid);
×
432
    if (pRequest) {
×
433
      taos_stop_query(pRequest);
×
434
      (void)releaseRequest(*rid);  // ignore error
×
435
    }
436

437
    pIter = taosHashIterate(pRequests, pIter);
×
438
  }
439
}
6,992✔
440

441
void destroyAppInst(void *info) {
33,420,472✔
442
  SAppInstInfo *pAppInfo = *(SAppInstInfo **)info;
33,420,472✔
443
  tscInfo("destroy app inst mgr %p", pAppInfo);
33,420,472✔
444

445
  int32_t code = taosThreadMutexLock(&appInfo.mutex);
33,420,472✔
446
  if (TSDB_CODE_SUCCESS != code) {
33,420,472✔
447
    tscError("failed to lock app info, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
448
  }
449

450
  hbRemoveAppHbMrg(&pAppInfo->pAppHbMgr);
33,420,472✔
451

452
  code = taosThreadMutexUnlock(&appInfo.mutex);
33,420,472✔
453
  if (TSDB_CODE_SUCCESS != code) {
33,420,472✔
454
    tscError("failed to unlock app info, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
455
  }
456

457
  taosMemoryFreeClear(pAppInfo->instKey);
33,420,472✔
458
  closeTransporter(pAppInfo);
33,420,472✔
459

460
  code = taosThreadMutexLock(&pAppInfo->qnodeMutex);
33,420,472✔
461
  if (TSDB_CODE_SUCCESS != code) {
33,420,472✔
462
    tscError("failed to lock qnode mutex, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
463
  }
464

465
  taosArrayDestroy(pAppInfo->pQnodeList);
33,420,472✔
466
  code = taosThreadMutexUnlock(&pAppInfo->qnodeMutex);
33,420,472✔
467
  if (TSDB_CODE_SUCCESS != code) {
33,420,472✔
468
    tscError("failed to unlock qnode mutex, code:%s", tstrerror(TAOS_SYSTEM_ERROR(code)));
×
469
  }
470

471
  taosMemoryFree(pAppInfo);
33,420,472✔
472
}
33,420,472✔
473

474
//  tscObj 1--->conn1
475
/// tscObj 2-->conn1
476
//  tscObj 3-->conn1
477

478
void destroyTscObj(void *pObj) {
2,145,765,473✔
479
  if (NULL == pObj) {
2,145,765,473✔
480
    return;
×
481
  }
482

483
  STscObj *pTscObj = pObj;
2,145,765,473✔
484
  int64_t  tscId = pTscObj->id;
2,145,765,473✔
485
  tscTrace("conn:%" PRIx64 ", begin destroy, p:%p", tscId, pTscObj);
2,145,765,473✔
486

487
  SClientHbKey connKey = {.tscRid = pTscObj->id, .connType = pTscObj->connType};
2,145,765,473✔
488
  hbDeregisterConn(pTscObj, connKey);
2,145,765,473✔
489

490
  destroyAllRequests(pTscObj->pRequests);
2,145,748,890✔
491
  taosHashCleanup(pTscObj->pRequests);
2,145,781,274✔
492

493
  schedulerStopQueryHb(pTscObj->pAppInfo->pTransporter);
2,145,781,274✔
494
  tscDebug("conn:0x%" PRIx64 ", p:%p destroyed, remain inst totalConn:%" PRId64, pTscObj->id, pTscObj,
2,145,775,386✔
495
           pTscObj->pAppInfo->numOfConns);
496

497
  // In any cases, we should not free app inst here. Or an race condition rises.
498
  /*int64_t connNum = */ (void)atomic_sub_fetch_64(&pTscObj->pAppInfo->numOfConns, 1);
2,145,775,386✔
499

500
  (void)taosThreadMutexDestroy(&pTscObj->mutex);
2,145,775,869✔
501
  taosMemoryFree(pTscObj);
2,145,721,658✔
502

503
  tscTrace("conn:0x%" PRIx64 ", end destroy, p:%p", tscId, pTscObj);
2,145,691,206✔
504
}
505

506
int32_t createTscObj(const char *user, const char *auth, const char *db, int32_t connType, SAppInstInfo *pAppInfo,
2,147,483,647✔
507
                     STscObj **pObj) {
508
  *pObj = (STscObj *)taosMemoryCalloc(1, sizeof(STscObj));
2,147,483,647✔
509
  if (NULL == *pObj) {
2,147,483,647✔
510
    return terrno;
×
511
  }
512

513
  (*pObj)->pRequests = taosHashInit(64, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_ENTRY_LOCK);
2,147,483,647✔
514
  if (NULL == (*pObj)->pRequests) {
2,147,483,647✔
515
    taosMemoryFree(*pObj);
×
516
    return terrno ? terrno : TSDB_CODE_OUT_OF_MEMORY;
×
517
  }
518

519
  (*pObj)->connType = connType;
2,147,483,647✔
520
  (*pObj)->pAppInfo = pAppInfo;
2,147,483,647✔
521
  (*pObj)->appHbMgrIdx = pAppInfo->pAppHbMgr->idx;
2,147,483,647✔
522
  if (user == NULL) {
2,147,483,647✔
523
    (*pObj)->user[0] = 0;
56,557✔
524
    (*pObj)->pass[0] = 0;
56,557✔
525
    tstrncpy((*pObj)->token, auth, sizeof((*pObj)->token));
56,557✔
526
  } else {
527
    tstrncpy((*pObj)->user, user, sizeof((*pObj)->user));
2,147,483,647✔
528
    (void)memcpy((*pObj)->pass, auth, TSDB_PASSWORD_LEN);
2,147,483,647✔
529
  }
530
  (*pObj)->tokenName[0] = 0;
2,147,483,647✔
531

532
  if (db != NULL) {
2,147,483,647✔
533
    tstrncpy((*pObj)->db, db, tListLen((*pObj)->db));
2,147,483,647✔
534
  }
535

536
  TSC_ERR_RET(taosThreadMutexInit(&(*pObj)->mutex, NULL));
2,147,483,647✔
537

538
  int32_t code = TSDB_CODE_SUCCESS;
2,147,483,647✔
539

540
  (*pObj)->id = taosAddRef(clientConnRefPool, *pObj);
2,147,483,647✔
541
  if ((*pObj)->id < 0) {
2,147,483,647✔
542
    tscError("failed to add object to clientConnRefPool");
×
543
    code = terrno;
×
544
    taosMemoryFree(*pObj);
×
545
    return code;
×
546
  }
547

548
  (void)atomic_add_fetch_64(&(*pObj)->pAppInfo->numOfConns, 1);
2,147,483,647✔
549

550
  updateConnAccessInfo(&(*pObj)->sessInfo);
2,147,483,647✔
551
  tscInfo("conn:0x%" PRIx64 ", created, p:%p", (*pObj)->id, *pObj);
2,147,483,647✔
552
  return code;
2,147,483,647✔
553
}
554

555
STscObj *acquireTscObj(int64_t rid) { return (STscObj *)taosAcquireRef(clientConnRefPool, rid); }
2,147,483,647✔
556

557
void releaseTscObj(int64_t rid) {
2,147,483,647✔
558
  int32_t code = taosReleaseRef(clientConnRefPool, rid);
2,147,483,647✔
559
  if (TSDB_CODE_SUCCESS != code) {
2,147,483,647✔
560
    tscWarn("failed to release TscObj, code:%s", tstrerror(code));
×
561
  }
562
}
2,147,483,647✔
563

564
int32_t createRequest(uint64_t connId, int32_t type, int64_t reqid, SRequestObj **pRequest) {
2,147,483,647✔
565
  int32_t code = TSDB_CODE_SUCCESS;
2,147,483,647✔
566
  *pRequest = (SRequestObj *)taosMemoryCalloc(1, sizeof(SRequestObj));
2,147,483,647✔
567
  if (NULL == *pRequest) {
2,147,483,647✔
568
    return terrno;
×
569
  }
570

571
  STscObj *pTscObj = acquireTscObj(connId);
2,147,483,647✔
572
  if (pTscObj == NULL) {
2,147,483,647✔
573
    TSC_ERR_JRET(TSDB_CODE_TSC_DISCONNECTED);
×
574
  }
575
  SSyncQueryParam *interParam = taosMemoryCalloc(1, sizeof(SSyncQueryParam));
2,147,483,647✔
576
  if (interParam == NULL) {
2,147,483,647✔
577
    releaseTscObj(connId);
×
578
    TSC_ERR_JRET(terrno);
×
579
  }
580
  TSC_ERR_JRET(tsem_init(&interParam->sem, 0, 0));
2,147,483,647✔
581
  interParam->pRequest = *pRequest;
2,147,483,647✔
582
  (*pRequest)->body.interParam = interParam;
2,147,483,647✔
583

584
  (*pRequest)->resType = RES_TYPE__QUERY;
2,147,483,647✔
585
  (*pRequest)->requestId = reqid == 0 ? generateRequestId() : reqid;
2,147,483,647✔
586
  (*pRequest)->metric.start = taosGetTimestampUs();
2,147,483,647✔
587
  (*pRequest)->execPhase = QUERY_PHASE_NONE;
588
  (*pRequest)->phaseStartTime = 0;
2,147,483,647✔
589

2,147,483,647✔
590
  (*pRequest)->body.resInfo.convertUcs4 = true;  // convert ucs4 by default
2,147,483,647✔
591
  (*pRequest)->body.resInfo.charsetCxt = pTscObj->optionInfo.charsetCxt;
2,147,483,647✔
592
  (*pRequest)->type = type;
593
  (*pRequest)->allocatorRefId = -1;
2,147,483,647✔
594

2,147,483,647✔
595
  (*pRequest)->pDb = getDbOfConnection(pTscObj);
2,147,483,647✔
596
  if (NULL == (*pRequest)->pDb) {
597
    TSC_ERR_JRET(terrno);
2,147,483,647✔
598
  }
2,147,483,647✔
599
  (*pRequest)->pTscObj = pTscObj;
2,147,483,647✔
600
  (*pRequest)->inCallback = false;
2,147,483,647✔
UNCOV
601
  (*pRequest)->msgBuf = taosMemoryCalloc(1, ERROR_MSG_BUF_DEFAULT_SIZE);
×
UNCOV
602
  if (NULL == (*pRequest)->msgBuf) {
×
603
    code = terrno;
604
    goto _return;
2,147,483,647✔
605
  }
2,147,483,647✔
606
  (*pRequest)->msgBufLen = ERROR_MSG_BUF_DEFAULT_SIZE;
2,147,483,647✔
607
  TSC_ERR_JRET(tsem_init(&(*pRequest)->body.rspSem, 0, 0));
608
  TSC_ERR_JRET(registerRequest(*pRequest, pTscObj));
2,147,483,647✔
UNCOV
609

×
UNCOV
610
  return TSDB_CODE_SUCCESS;
×
611
_return:
×
612
  if ((*pRequest)->pTscObj) {
613
    doDestroyRequest(*pRequest);
×
614
  } else {
615
    taosMemoryFree(*pRequest);
×
616
  }
617
  return code;
618
}
2,147,483,647✔
619

2,147,483,647✔
620
void doFreeReqResultInfo(SReqResultInfo *pResInfo) {
2,147,483,647✔
621
  taosMemoryFreeClear(pResInfo->pRspMsg);
2,147,483,647✔
622
  taosMemoryFreeClear(pResInfo->length);
2,147,483,647✔
623
  taosMemoryFreeClear(pResInfo->row);
2,147,483,647✔
624
  taosMemoryFreeClear(pResInfo->pCol);
2,147,483,647✔
625
  taosMemoryFreeClear(pResInfo->fields);
2,147,483,647✔
626
  taosMemoryFreeClear(pResInfo->userFields);
2,147,483,647✔
627
  taosMemoryFreeClear(pResInfo->convertJson);
628
  taosMemoryFreeClear(pResInfo->decompBuf);
2,147,483,647✔
629

2,147,483,647✔
630
  if (pResInfo->convertBuf != NULL) {
2,147,483,647✔
631
    for (int32_t i = 0; i < pResInfo->numOfCols; ++i) {
632
      taosMemoryFreeClear(pResInfo->convertBuf[i]);
2,147,483,647✔
633
    }
634
    taosMemoryFreeClear(pResInfo->convertBuf);
2,147,483,647✔
635
  }
636
}
2,147,483,647✔
637

638
SRequestObj *acquireRequest(int64_t rid) { return (SRequestObj *)taosAcquireRef(clientReqRefPool, rid); }
2,147,483,647✔
639

640
int32_t releaseRequest(int64_t rid) { return taosReleaseRef(clientReqRefPool, rid); }
2,147,483,647✔
641

642
int32_t removeRequest(int64_t rid) { return taosRemoveRef(clientReqRefPool, rid); }
643

2,147,483,647✔
644
/// return the most previous req ref id
2,147,483,647✔
645
int64_t removeFromMostPrevReq(SRequestObj *pRequest) {
2,147,483,647✔
646
  int64_t      mostPrevReqRefId = pRequest->self;
2,147,483,647✔
UNCOV
647
  SRequestObj *pTmp = pRequest;
×
UNCOV
648
  while (pTmp->relation.prevRefId) {
×
649
    pTmp = acquireRequest(pTmp->relation.prevRefId);
×
650
    if (pTmp) {
×
651
      mostPrevReqRefId = pTmp->self;
652
      (void)releaseRequest(mostPrevReqRefId);  // ignore error
×
653
    } else {
654
      break;
655
    }
2,147,483,647✔
656
  }
2,147,483,647✔
657
  (void)removeRequest(mostPrevReqRefId);  // ignore error
658
  return mostPrevReqRefId;
659
}
2,147,483,647✔
660

2,147,483,647✔
UNCOV
661
void destroyNextReq(int64_t nextRefId) {
×
UNCOV
662
  if (nextRefId) {
×
663
    SRequestObj *pObj = acquireRequest(nextRefId);
×
664
    if (pObj) {
×
665
      (void)releaseRequest(nextRefId);  // ignore error
666
      (void)releaseRequest(nextRefId);  // ignore error
667
    }
2,147,483,647✔
668
  }
UNCOV
669
}
×
UNCOV
670

×
671
void destroySubRequests(SRequestObj *pRequest) {
×
672
  int32_t      reqIdx = -1;
×
673
  SRequestObj *pReqList[16] = {NULL};
674
  uint64_t     tmpRefId = 0;
×
UNCOV
675

×
676
  if (pRequest->relation.userRefId && pRequest->relation.userRefId != pRequest->self) {
677
    return;
UNCOV
678
  }
×
UNCOV
679

×
680
  SRequestObj *pTmp = pRequest;
×
681
  while (pTmp->relation.prevRefId) {
×
682
    tmpRefId = pTmp->relation.prevRefId;
×
683
    pTmp = acquireRequest(tmpRefId);
×
684
    if (pTmp) {
×
685
      pReqList[++reqIdx] = pTmp;
686
      (void)releaseRequest(tmpRefId);  // ignore error
×
UNCOV
687
    } else {
×
688
      tscError("prev req ref 0x%" PRIx64 " is not there", tmpRefId);
689
      break;
690
    }
UNCOV
691
  }
×
UNCOV
692

×
693
  for (int32_t i = reqIdx; i >= 0; i--) {
694
    (void)removeRequest(pReqList[i]->self);  // ignore error
UNCOV
695
  }
×
UNCOV
696

×
697
  tmpRefId = pRequest->relation.nextRefId;
×
698
  while (tmpRefId) {
×
699
    pTmp = acquireRequest(tmpRefId);
×
700
    if (pTmp) {
×
701
      tmpRefId = pTmp->relation.nextRefId;
×
702
      (void)removeRequest(pTmp->self);   // ignore error
703
      (void)releaseRequest(pTmp->self);  // ignore error
×
UNCOV
704
    } else {
×
705
      tscError("next req ref 0x%" PRIx64 " is not there", tmpRefId);
706
      break;
707
    }
708
  }
709
}
2,147,483,647✔
710

2,147,483,647✔
UNCOV
711
void doDestroyRequest(void *p) {
×
712
  if (NULL == p) {
713
    return;
714
  }
2,147,483,647✔
715

716
  SRequestObj *pRequest = (SRequestObj *)p;
2,147,483,647✔
717

2,147,483,647✔
718
  uint64_t reqId = pRequest->requestId;
719
  tscTrace("QID:0x%" PRIx64 ", begin destroy request, res:%p", reqId, pRequest);
2,147,483,647✔
720

721
  int64_t nextReqRefId = pRequest->relation.nextRefId;
2,147,483,647✔
722

2,147,483,647✔
723
  int32_t code = taosHashRemove(pRequest->pTscObj->pRequests, &pRequest->self, sizeof(pRequest->self));
2,147,483,647✔
724
  if (TSDB_CODE_SUCCESS != code) {
725
    tscDebug("failed to remove request from hash since %s", tstrerror(code));
2,147,483,647✔
726
  }
727
  schedulerFreeJob(&pRequest->body.queryJob, 0);
2,147,483,647✔
728

729
  destorySqlCallbackWrapper(pRequest->pWrapper);
2,147,483,647✔
730

731
  taosMemoryFreeClear(pRequest->msgBuf);
2,147,483,647✔
732

2,147,483,647✔
UNCOV
733
  doFreeReqResultInfo(&pRequest->body.resInfo);
×
734
  if (TSDB_CODE_SUCCESS != tsem_destroy(&pRequest->body.rspSem)) {
735
    tscError("failed to destroy semaphore");
736
  }
2,147,483,647✔
737

2,147,483,647✔
738
  SSessParam para = {.type = SESSION_MAX_CONCURRENCY, .value = -1, .noCheck = 1};
2,147,483,647✔
UNCOV
739
  code = tscUpdateSessMetric(pRequest->pTscObj, &para);
×
740
  if (TSDB_CODE_SUCCESS != code) {
741
    tscError("failed to update session metric, code:%s", tstrerror(code));
742
  }
2,147,483,647✔
743

2,147,483,647✔
744
  taosArrayDestroy(pRequest->tableList);
2,147,483,647✔
745
  taosArrayDestroy(pRequest->targetTableList);
746
  destroyQueryExecRes(&pRequest->body.resInfo.execRes);
2,147,483,647✔
747

2,147,483,647✔
748
  if (pRequest->self) {
749
    deregisterRequest(pRequest);
750
  }
2,147,483,647✔
751

2,147,483,647✔
752
  taosMemoryFreeClear(pRequest->pDb);
2,147,483,647✔
753
  taosArrayDestroy(pRequest->dbList);
2,147,483,647✔
UNCOV
754
  if (pRequest->body.interParam) {
×
755
    if (TSDB_CODE_SUCCESS != tsem_destroy(&((SSyncQueryParam *)pRequest->body.interParam)->sem)) {
756
      tscError("failed to destroy semaphore in pRequest");
757
    }
2,147,483,647✔
758
  }
759
  taosMemoryFree(pRequest->body.interParam);
2,147,483,647✔
760

2,147,483,647✔
761
  qDestroyQuery(pRequest->pQuery);
762
  nodesDestroyAllocator(pRequest->allocatorRefId);
2,147,483,647✔
763

2,147,483,647✔
764
  taosMemoryFreeClear(pRequest->effectiveUser);
2,147,483,647✔
765
  taosMemoryFreeClear(pRequest->sqlstr);
2,147,483,647✔
766
  taosMemoryFree(pRequest);
2,147,483,647✔
767
  tscTrace("QID:0x%" PRIx64 ", end destroy request, res:%p", reqId, pRequest);
768
  destroyNextReq(nextReqRefId);
769
}
2,147,483,647✔
770

2,147,483,647✔
771
void destroyRequest(SRequestObj *pRequest) {
772
  if (pRequest == NULL) return;
2,147,483,647✔
773

2,147,483,647✔
774
  taos_stop_query(pRequest);
775
  (void)removeFromMostPrevReq(pRequest);
776
}
2,147,483,647✔
777

2,147,483,647✔
778
void taosStopQueryImpl(SRequestObj *pRequest) {
779
  pRequest->killed = true;
780

2,147,483,647✔
781
  // It is not a query, no need to stop.
2,147,483,647✔
782
  if (NULL == pRequest->pQuery || QUERY_EXEC_MODE_SCHEDULE != pRequest->pQuery->execMode) {
2,147,483,647✔
783
    tscDebug("QID:0x%" PRIx64 ", no need to be killed since not query", pRequest->requestId);
784
    return;
785
  }
2,147,483,647✔
786

2,147,483,647✔
787
  schedulerFreeJob(&pRequest->body.queryJob, TSDB_CODE_TSC_QUERY_KILLED);
788
  tscDebug("QID:0x%" PRIx64 ", killed", pRequest->requestId);
789
}
2,147,483,647✔
790

2,147,483,647✔
791
void stopAllQueries(SRequestObj *pRequest) {
2,147,483,647✔
792
  int32_t      reqIdx = -1;
2,147,483,647✔
793
  SRequestObj *pReqList[16] = {NULL};
794
  uint64_t     tmpRefId = 0;
2,147,483,647✔
UNCOV
795

×
796
  if (pRequest->relation.userRefId && pRequest->relation.userRefId != pRequest->self) {
797
    return;
798
  }
2,147,483,647✔
799

2,147,483,647✔
UNCOV
800
  SRequestObj *pTmp = pRequest;
×
UNCOV
801
  while (pTmp->relation.prevRefId) {
×
802
    tmpRefId = pTmp->relation.prevRefId;
×
803
    pTmp = acquireRequest(tmpRefId);
×
804
    if (pTmp) {
805
      pReqList[++reqIdx] = pTmp;
×
UNCOV
806
    } else {
×
807
      tscError("prev req ref 0x%" PRIx64 " is not there", tmpRefId);
808
      break;
809
    }
810
  }
2,147,483,647✔
UNCOV
811

×
UNCOV
812
  for (int32_t i = reqIdx; i >= 0; i--) {
×
813
    taosStopQueryImpl(pReqList[i]);
814
    (void)releaseRequest(pReqList[i]->self);  // ignore error
815
  }
2,147,483,647✔
816

817
  taosStopQueryImpl(pRequest);
2,147,483,647✔
818

2,147,483,647✔
UNCOV
819
  tmpRefId = pRequest->relation.nextRefId;
×
UNCOV
820
  while (tmpRefId) {
×
821
    pTmp = acquireRequest(tmpRefId);
×
822
    if (pTmp) {
×
823
      tmpRefId = pTmp->relation.nextRefId;
×
824
      taosStopQueryImpl(pTmp);
825
      (void)releaseRequest(pTmp->self);  // ignore error
×
UNCOV
826
    } else {
×
827
      tscError("next req ref 0x%" PRIx64 " is not there", tmpRefId);
828
      break;
829
    }
830
  }
UNCOV
831
}
×
832
#ifdef USE_REPORT
833
void crashReportThreadFuncUnexpectedStopped(void) { atomic_store_32(&clientStop, -1); }
×
UNCOV
834

×
835
static void *tscCrashReportThreadFp(void *param) {
×
836
  int32_t code = 0;
×
837
  setThreadName("client-crashReport");
×
838
  char filepath[PATH_MAX] = {0};
×
839
  (void)snprintf(filepath, sizeof(filepath), "%s%s.taosCrashLog", tsLogDir, TD_DIRSEP);
×
840
  char     *pMsg = NULL;
×
841
  int64_t   msgLen = 0;
×
842
  TdFilePtr pFile = NULL;
×
843
  bool      truncateFile = false;
×
844
  int32_t   sleepTime = 200;
×
845
  int32_t   reportPeriodNum = 3600 * 1000 / sleepTime;
846
  int32_t   loopTimes = reportPeriodNum;
847

848
#ifdef WINDOWS
849
  if (taosCheckCurrentInDll()) {
850
    atexit(crashReportThreadFuncUnexpectedStopped);
851
  }
UNCOV
852
#endif
×
UNCOV
853

×
854
  if (-1 != atomic_val_compare_exchange_32(&clientStop, -1, 0)) {
855
    return NULL;
×
UNCOV
856
  }
×
857
  STelemAddrMgmt mgt;
×
858
  code = taosTelemetryMgtInit(&mgt, tsTelemServer);
×
859
  if (code) {
×
860
    tscError("failed to init telemetry management, code:%s", tstrerror(code));
861
    return NULL;
UNCOV
862
  }
×
UNCOV
863

×
864
  code = initCrashLogWriter();
×
865
  if (code) {
×
866
    tscError("failed to init crash log writer, code:%s", tstrerror(code));
867
    return NULL;
868
  }
UNCOV
869

×
UNCOV
870
  while (1) {
×
871
    checkAndPrepareCrashInfo();
×
872
    if (clientStop > 0 && reportThreadSetQuit()) break;
×
873
    if (loopTimes++ < reportPeriodNum) {
×
874
      if (loopTimes < 0) loopTimes = reportPeriodNum;
×
875
      taosMsleep(sleepTime);
876
      continue;
UNCOV
877
    }
×
UNCOV
878

×
879
    taosReadCrashInfo(filepath, &pMsg, &msgLen, &pFile);
×
880
    if (pMsg && msgLen > 0) {
×
881
      if (taosSendTelemReport(&mgt, tsClientCrashReportUri, tsTelemPort, pMsg, msgLen, HTTP_FLAT) != 0) {
×
882
        tscError("failed to send crash report");
×
883
        if (pFile) {
×
884
          taosReleaseCrashLogFile(pFile, false);
885
          pFile = NULL;
×
UNCOV
886

×
887
          taosMsleep(sleepTime);
×
888
          loopTimes = 0;
889
          continue;
UNCOV
890
        }
×
UNCOV
891
      } else {
×
892
        tscInfo("succeed to send crash report");
893
        truncateFile = true;
UNCOV
894
      }
×
895
    } else {
896
      tscInfo("no crash info was found");
UNCOV
897
    }
×
898

899
    taosMemoryFree(pMsg);
×
UNCOV
900

×
901
    if (pMsg && msgLen > 0) {
×
902
      pMsg = NULL;
903
      continue;
UNCOV
904
    }
×
UNCOV
905

×
906
    if (pFile) {
×
907
      taosReleaseCrashLogFile(pFile, truncateFile);
×
908
      pFile = NULL;
909
      truncateFile = false;
UNCOV
910
    }
×
UNCOV
911

×
912
    taosMsleep(sleepTime);
913
    loopTimes = 0;
×
914
  }
915
  taosTelemetryDestroy(&mgt);
×
UNCOV
916

×
917
  clientStop = -2;
918
  return NULL;
919
}
31,551,561✔
920

31,551,561✔
921
int32_t tscCrashReportInit() {
31,551,561✔
922
  if (!tsEnableCrashReport) {
UNCOV
923
    return TSDB_CODE_SUCCESS;
×
UNCOV
924
  }
×
925
  int32_t      code = TSDB_CODE_SUCCESS;
×
926
  TdThreadAttr thAttr;
×
927
  TSC_ERR_JRET(taosThreadAttrInit(&thAttr));
×
928
  TSC_ERR_JRET(taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE));
×
929
  TdThread crashReportThread;
×
930
  if (taosThreadCreate(&crashReportThread, &thAttr, tscCrashReportThreadFp, NULL) != 0) {
×
931
    tscError("failed to create crashReport thread since %s", strerror(ERRNO));
×
932
    terrno = TAOS_SYSTEM_ERROR(ERRNO);
933
    TSC_ERR_RET(terrno);
UNCOV
934
  }
×
UNCOV
935

×
936
  (void)taosThreadAttrDestroy(&thAttr);
×
937
_return:
×
938
  if (code) {
×
939
    terrno = TAOS_SYSTEM_ERROR(ERRNO);
940
    TSC_ERR_RET(terrno);
UNCOV
941
  }
×
942

943
  return code;
944
}
31,552,941✔
945

31,552,941✔
946
void tscStopCrashReport() {
31,552,941✔
947
  if (!tsEnableCrashReport) {
948
    return;
UNCOV
949
  }
×
UNCOV
950

×
951
  if (atomic_val_compare_exchange_32(&clientStop, 0, 1)) {
×
952
    tscDebug("crash report thread already stopped");
953
    return;
UNCOV
954
  }
×
UNCOV
955

×
956
  while (atomic_load_32(&clientStop) > 0) {
957
    taosMsleep(100);
958
  }
UNCOV
959
}
×
UNCOV
960

×
961
void taos_write_crashinfo(int signum, void *sigInfo, void *context) {
×
962
  writeCrashLogToFile(signum, sigInfo, CUS_PROMPT, lastClusterId, appInfo.startTime);
963
}
964
#endif
965

966
#ifdef TAOSD_INTEGRATED
967
typedef struct {
968
  TdThread pid;
969
  int32_t  stat;  // < 0: start failed, 0: init(not start), 1: start successfully
970
} SDaemonObj;
971

972
extern int  dmStartDaemon(int argc, char const *argv[]);
973
extern void dmStopDaemon();
974

975
SDaemonObj daemonObj = {0};
976

977
typedef struct {
978
  int32_t argc;
979
  char  **argv;
980
} SExecArgs;
981

982
static void *dmStartDaemonFunc(void *param) {
983
  int32_t    code = 0;
984
  SExecArgs *pArgs = (SExecArgs *)param;
985
  int32_t    argc = pArgs->argc;
986
  char     **argv = pArgs->argv;
987

988
  code = dmStartDaemon(argc, (const char **)argv);
989
  if (code != 0) {
990
    printf("failed to start taosd since %s\r\n", tstrerror(code));
991
    goto _exit;
992
  }
993

994
_exit:
995
  if (code != 0) {
996
    atomic_store_32(&daemonObj.stat, code);
997
  }
998
  return NULL;
999
}
1000

1001
static int32_t shellStartDaemon(int argc, char *argv[]) {
1002
  int32_t    code = 0, lino = 0;
1003
  SExecArgs *pArgs = NULL;
1004
  int64_t    startMs = taosGetTimestampMs(), endMs = startMs;
1005

1006
  TdThreadAttr thAttr;
1007
  (void)taosThreadAttrInit(&thAttr);
1008
  (void)taosThreadAttrSetDetachState(&thAttr, PTHREAD_CREATE_JOINABLE);
1009
#ifdef TD_COMPACT_OS
1010
  (void)taosThreadAttrSetStackSize(&thAttr, STACK_SIZE_SMALL);
1011
#endif
1012
  pArgs = (SExecArgs *)taosMemoryCalloc(1, sizeof(SExecArgs));
1013
  if (pArgs == NULL) {
1014
    code = terrno;
1015
    TAOS_CHECK_EXIT(code);
1016
  }
1017
  pArgs->argc = argc;
1018
  pArgs->argv = argv;
1019

1020
#ifndef TD_AS_LIB
1021
  tsLogEmbedded = 1;
1022
#endif
1023

1024
  TAOS_CHECK_EXIT(taosThreadCreate(&daemonObj.pid, &thAttr, dmStartDaemonFunc, pArgs));
1025

1026
  while (true) {
1027
    if (atomic_load_64(&tsDndStart)) {
1028
      atomic_store_32(&daemonObj.stat, 1);
1029
      break;
1030
    }
1031
    int32_t daemonstat = atomic_load_32(&daemonObj.stat);
1032
    if (daemonstat < 0) {
1033
      code = daemonstat;
1034
      TAOS_CHECK_EXIT(code);
1035
    }
1036

1037
    if (daemonstat > 1) {
1038
      code = TSDB_CODE_APP_ERROR;
1039
      TAOS_CHECK_EXIT(code);
1040
    }
1041
    taosMsleep(1000);
1042
  }
1043

1044
_exit:
1045
  endMs = taosGetTimestampMs();
1046
  (void)taosThreadAttrDestroy(&thAttr);
1047
  taosMemoryFreeClear(pArgs);
1048
  if (code) {
1049
    printf("\r\n The daemon start failed at line %d since %s, cost %" PRIi64 " ms\r\n", lino, tstrerror(code),
1050
           endMs - startMs);
1051
  } else {
1052
    printf("\r\n The daemon started successfully, cost %" PRIi64 " ms\r\n", endMs - startMs);
1053
  }
1054
#ifndef TD_AS_LIB
1055
  tsLogEmbedded = 0;
1056
#endif
1057
  return code;
1058
}
1059

1060
void shellStopDaemon() {
1061
#ifndef TD_AS_LIB
1062
  tsLogEmbedded = 1;
1063
#endif
1064
  dmStopDaemon();
1065
  if (taosCheckPthreadValid(daemonObj.pid)) {
1066
    (void)taosThreadJoin(daemonObj.pid, NULL);
1067
    taosThreadClear(&daemonObj.pid);
1068
  }
1069
}
1070
#endif
31,552,941✔
1071

1072
void taos_init_imp(void) {
31,552,941✔
UNCOV
1073
#if defined(LINUX)
×
UNCOV
1074
  if (tscDbg.memEnable) {
×
1075
    int32_t code = taosMemoryDbgInit();
×
1076
    if (code) {
1077
      (void)printf("failed to init memory dbg, error:%s\n", tstrerror(code));
×
UNCOV
1078
    } else {
×
1079
      tsAsyncLog = false;
1080
      (void)printf("memory dbg enabled\n");
1081
    }
1082
  }
1083
#endif
1084

1085
  // In the APIs of other program language, taos_cleanup is not available yet.
31,552,941✔
1086
  // So, to make sure taos_cleanup will be invoked to clean up the allocated resource to suppress the valgrind warning.
31,552,941✔
1087
  (void)atexit(taos_cleanup);
31,552,941✔
1088
  SET_ERRNO(TSDB_CODE_SUCCESS);
31,552,941✔
1089
  terrno = TSDB_CODE_SUCCESS;
1090
  taosSeedRand(taosGetTimestampSec());
31,552,941✔
1091

31,552,941✔
1092
  appInfo.pid = taosGetPId();
31,552,941✔
1093
  appInfo.startTime = taosGetTimestampMs();
31,552,941✔
1094
  appInfo.pInstMap = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, HASH_ENTRY_LOCK);
31,552,941✔
1095
  appInfo.pInstMapByClusterId =
31,552,941✔
UNCOV
1096
      taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), true, HASH_ENTRY_LOCK);
×
UNCOV
1097
  if (NULL == appInfo.pInstMap || NULL == appInfo.pInstMapByClusterId) {
×
1098
    (void)printf("failed to allocate memory when init appInfo\n");
×
1099
    tscInitRes = terrno;
1100
    return;
31,552,941✔
1101
  }
1102
  taosHashSetFreeFp(appInfo.pInstMap, destroyAppInst);
31,552,941✔
1103

31,552,941✔
1104
  const char *logName = CUS_PROMPT "log";
31,552,941✔
1105
  ENV_ERR_RET(taosInitLogOutput(&logName), "failed to init log output");
1,380✔
1106
  if (taosCreateLog(logName, 10, configDir, NULL, NULL, NULL, NULL, 1) != 0) {
1,380✔
1107
    (void)printf(" WARING: Create %s failed:%s. configDir=%s\n", logName, strerror(ERRNO), configDir);
1,380✔
1108
    SET_ERROR_MSG("Create %s failed:%s. configDir=%s", logName, strerror(ERRNO), configDir);
1,380✔
1109
    tscInitRes = terrno;
1110
    return;
1111
  }
1112

1113
#ifdef TAOSD_INTEGRATED
1114
  ENV_ERR_RET(taosInitCfg(configDir, NULL, NULL, NULL, NULL, 0), "failed to init cfg");
31,551,561✔
1115
#else
1116
  ENV_ERR_RET(taosInitCfg(configDir, NULL, NULL, NULL, NULL, 1), "failed to init cfg");
1117
#endif
31,551,561✔
1118

1119
  initQueryModuleMsgHandle();
31,551,561✔
UNCOV
1120
#ifndef DISALLOW_NCHAR_WITHOUT_ICONV
×
UNCOV
1121
  if ((tsCharsetCxt = taosConvInit(tsCharset)) == NULL) {
×
1122
    tscInitRes = terrno;
×
1123
    tscError("failed to init conv");
1124
    return;
1125
  }
1126
#endif
31,551,561✔
1127
#if !defined(TD_ASTRA)
1128
  ENV_ERR_RET(tzInit(), "failed to init timezone");
31,551,561✔
1129
#endif
31,551,561✔
1130
  ENV_ERR_RET(monitorInit(), "failed to init monitor");
1131
  ENV_ERR_RET(rpcInit(), "failed to init rpc");
31,551,561✔
UNCOV
1132

×
UNCOV
1133
  if (InitRegexCache() != 0) {
×
1134
    tscInitRes = terrno;
×
1135
    (void)printf("failed to init regex cache\n");
1136
    return;
1137
  }
31,551,561✔
1138

1139
  tscInfo("starting to initialize TAOS driver");
31,551,561✔
1140

31,551,561✔
1141
  SCatalogCfg cfg = {.maxDBCacheNum = 100, .maxTblCacheNum = 100};
31,551,561✔
1142
  ENV_ERR_RET(catalogInit(&cfg), "failed to init catalog");
31,551,561✔
1143
  ENV_ERR_RET(schedulerInit(), "failed to init scheduler");
1144
  ENV_ERR_RET(initClientId(), "failed to init clientId");
31,551,561✔
1145

31,551,561✔
1146
  ENV_ERR_RET(initTaskQueue(), "failed to init task queue");
31,551,561✔
1147
  ENV_ERR_RET(fmFuncMgtInit(), "failed to init funcMgt");
1148
  ENV_ERR_RET(nodesInitAllocatorSet(), "failed to init allocator set");
31,551,561✔
1149

31,551,561✔
1150
  clientConnRefPool = taosOpenRef(200, destroyTscObj);
1151
  clientReqRefPool = taosOpenRef(40960, doDestroyRequest);
31,551,561✔
1152

31,551,561✔
1153
  ENV_ERR_RET(taosGetAppName(appInfo.appName, NULL), "failed to get app name");
1154
  ENV_ERR_RET(taosThreadMutexInit(&appInfo.mutex, NULL), "failed to init thread mutex");
31,551,561✔
1155
#ifdef USE_REPORT
1156
  ENV_ERR_RET(tscCrashReportInit(), "failed to init crash report");
31,551,561✔
1157
#endif
1158
  ENV_ERR_RET(qInitKeywordsTable(), "failed to init parser keywords table");
1159
#ifdef TAOSD_INTEGRATED
1160
  ENV_ERR_RET(shellStartDaemon(0, NULL), "failed to start taosd daemon");
1161
#endif
31,551,561✔
1162

31,551,561✔
1163
  if (tsSessionControl) {
1164
    ENV_ERR_RET(sessMgtInit(), "failed to init session management");
1165
  }
31,551,561✔
1166

1167
  tscInfo("TAOS driver is initialized successfully");
1168
}
2,145,298,665✔
1169

2,145,298,665✔
1170
int taos_init() {
2,145,322,286✔
1171
  (void)taosThreadOnce(&tscinit, taos_init_imp);
1172
  return tscInitRes;
1173
}
92,414✔
1174

92,414✔
1175
const char *getCfgName(TSDB_OPTION option) {
1176
  const char *name = NULL;
92,414✔
1177

3,864✔
1178
  switch (option) {
3,864✔
1179
    case TSDB_OPTION_SHELL_ACTIVITY_TIMER:
3,864✔
UNCOV
1180
      name = "shellActivityTimer";
×
UNCOV
1181
      break;
×
1182
    case TSDB_OPTION_LOCALE:
×
1183
      name = "locale";
×
1184
      break;
×
1185
    case TSDB_OPTION_CHARSET:
×
1186
      name = "charset";
79,649✔
1187
      break;
79,649✔
1188
    case TSDB_OPTION_TIMEZONE:
79,649✔
1189
      name = "timezone";
2,208✔
1190
      break;
2,208✔
1191
    case TSDB_OPTION_USE_ADAPTER:
2,208✔
1192
      name = "useAdapter";
6,693✔
1193
      break;
6,693✔
1194
    default:
1195
      break;
1196
  }
92,414✔
1197

1198
  return name;
1199
}
2,100,966,786✔
1200

2,100,966,786✔
1201
int taos_options_imp(TSDB_OPTION option, const char *str) {
1202
  if (option == TSDB_OPTION_CONFIGDIR) {
14,723,680✔
1203
#ifndef WINDOWS
2,100,874,372✔
1204
    char newstr[PATH_MAX];
2,100,874,372✔
1205
    int  len = strlen(str);
2,100,849,992✔
UNCOV
1206
    if (len > 1 && str[0] != '"' && str[0] != '\'') {
×
UNCOV
1207
      if (len + 2 >= PATH_MAX) {
×
1208
        tscError("Too long path %s", str);
1209
        return -1;
2,100,849,992✔
1210
      }
2,100,849,992✔
1211
      newstr[0] = '"';
2,100,849,992✔
1212
      (void)memcpy(newstr + 1, str, len);
2,100,849,992✔
1213
      newstr[len + 1] = '"';
2,100,849,992✔
1214
      newstr[len + 2] = '\0';
1215
      str = newstr;
1216
    }
2,100,874,372✔
1217
#endif
2,100,874,372✔
1218
    tstrncpy(configDir, str, PATH_MAX);
2,100,874,372✔
1219
    tscInfo("set cfg:%s to %s", configDir, str);
1220
    return 0;
1221
  }
1222

92,414✔
UNCOV
1223
  // initialize global config
×
1224
  if (taos_init() != 0) {
1225
    return -1;
1226
  }
92,414✔
1227

92,414✔
1228
  SConfig     *pCfg = taosGetCfg();
92,414✔
1229
  SConfigItem *pItem = NULL;
1230
  const char  *name = getCfgName(option);
92,414✔
1231

6,693✔
1232
  if (name == NULL) {
6,693✔
1233
    tscError("Invalid option %d", option);
1234
    return -1;
1235
  }
85,721✔
1236

85,721✔
UNCOV
1237
  pItem = cfgGetItem(pCfg, name);
×
UNCOV
1238
  if (pItem == NULL) {
×
1239
    tscError("Invalid option %d", option);
1240
    return -1;
1241
  }
85,721✔
1242

85,721✔
1243
  int code = cfgSetItem(pCfg, name, str, CFG_STYPE_TAOS_OPTIONS, true);
3,864✔
1244
  if (code != 0) {
1245
    tscError("failed to set cfg:%s to %s since %s", name, str, terrstr());
81,857✔
1246
  } else {
81,857✔
1247
    tscInfo("set cfg:%s to %s", name, str);
2,208✔
1248
    if (TSDB_OPTION_SHELL_ACTIVITY_TIMER == option || TSDB_OPTION_USE_ADAPTER == option) {
1249
      code = taosCfgDynamicOptions(pCfg, name, false);
1250
    }
1251
  }
85,721✔
1252

1253
  return code;
1254
}
1255

1256
/**
1257
 * The request id is an unsigned integer format of 64bit.
1258
 *+------------+-----+-----------+---------------+
1259
 *| uid|localIp| PId | timestamp | serial number |
1260
 *+------------+-----+-----------+---------------+
1261
 *| 12bit      |12bit|24bit      |16bit          |
1262
 *+------------+-----+-----------+---------------+
1263
 * @return
2,147,483,647✔
1264
 */
1265
uint64_t generateRequestId() {
1266
  static uint32_t hashId = 0;
1267
  static int32_t  requestSerialId = 0;
2,147,483,647✔
1268

31,516,877✔
1269
  if (hashId == 0) {
31,516,877✔
UNCOV
1270
    int32_t code = taosGetSystemUUIDU32(&hashId);
×
1271
    if (code != TSDB_CODE_SUCCESS) {
1272
      tscError("Failed to get the system uid to generated request id, reason:%s. use ip address instead",
1273
               tstrerror(code));
1274
    }
1275
  }
2,147,483,647✔
1276

UNCOV
1277
  uint64_t id = 0;
×
1278

2,147,483,647✔
1279
  while (true) {
2,147,483,647✔
1280
    int64_t  ts = taosGetTimestampMs();
2,147,483,647✔
1281
    uint64_t pid = taosGetPId();
2,147,483,647✔
1282
    uint32_t val = atomic_add_fetch_32(&requestSerialId, 1);
1283
    if (val >= 0xFFFF) atomic_store_32(&requestSerialId, 0);
2,147,483,647✔
1284

2,147,483,647✔
1285
    id = (((uint64_t)(hashId & 0x0FFF)) << 52) | ((pid & 0x0FFF) << 40) | ((ts & 0xFFFFFF) << 16) | (val & 0xFFFF);
2,147,483,647✔
1286
    if (id) {
1287
      break;
1288
    }
2,147,483,647✔
1289
  }
1290
  return id;
1291
}
1292

1293
#if 0
1294
#include "cJSON.h"
1295
static setConfRet taos_set_config_imp(const char *config){
1296
  setConfRet ret = {SET_CONF_RET_SUCC, {0}};
1297
  static bool setConfFlag = false;
1298
  if (setConfFlag) {
1299
    ret.retCode = SET_CONF_RET_ERR_ONLY_ONCE;
1300
    tstrncpy(ret.retMsg, "configuration can only set once", RET_MSG_LENGTH);
1301
    return ret;
1302
  }
1303
  taosInitGlobalCfg();
1304
  cJSON *root = cJSON_Parse(config);
1305
  if (root == NULL){
1306
    ret.retCode = SET_CONF_RET_ERR_JSON_PARSE;
1307
    tstrncpy(ret.retMsg, "parse json error", RET_MSG_LENGTH);
1308
    return ret;
1309
  }
1310

1311
  int size = cJSON_GetArraySize(root);
1312
  if(!cJSON_IsObject(root) || size == 0) {
1313
    ret.retCode = SET_CONF_RET_ERR_JSON_INVALID;
1314
    tstrncpy(ret.retMsg, "json content is invalid, must be not empty object", RET_MSG_LENGTH);
1315
    return ret;
1316
  }
1317

1318
  if(size >= 1000) {
1319
    ret.retCode = SET_CONF_RET_ERR_TOO_LONG;
1320
    tstrncpy(ret.retMsg, "json object size is too long", RET_MSG_LENGTH);
1321
    return ret;
1322
  }
1323

1324
  for(int i = 0; i < size; i++){
1325
    cJSON *item = cJSON_GetArrayItem(root, i);
1326
    if(!item) {
1327
      ret.retCode = SET_CONF_RET_ERR_INNER;
1328
      tstrncpy(ret.retMsg, "inner error", RET_MSG_LENGTH);
1329
      return ret;
1330
    }
1331
    if(!taosReadConfigOption(item->string, item->valuestring, NULL, NULL, TAOS_CFG_CSTATUS_OPTION, TSDB_CFG_CTYPE_B_CLIENT)){
1332
      ret.retCode = SET_CONF_RET_ERR_PART;
1333
      if (strlen(ret.retMsg) == 0){
1334
        snprintf(ret.retMsg, RET_MSG_LENGTH, "part error|%s", item->string);
1335
      }else{
1336
        int tmp = RET_MSG_LENGTH - 1 - (int)strlen(ret.retMsg);
1337
        size_t leftSize = tmp >= 0 ? tmp : 0;
1338
        strncat(ret.retMsg, "|",  leftSize);
1339
        tmp = RET_MSG_LENGTH - 1 - (int)strlen(ret.retMsg);
1340
        leftSize = tmp >= 0 ? tmp : 0;
1341
        strncat(ret.retMsg, item->string, leftSize);
1342
      }
1343
    }
1344
  }
1345
  cJSON_Delete(root);
1346
  setConfFlag = true;
1347
  return ret;
1348
}
1349

1350
setConfRet taos_set_config(const char *config){
1351
  taosThreadMutexLock(&setConfMutex);
1352
  setConfRet ret = taos_set_config_imp(config);
1353
  taosThreadMutexUnlock(&setConfMutex);
1354
  return ret;
1355
}
1356
#endif
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