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

taosdata / TDengine / #4881

14 Dec 2025 03:48AM UTC coverage: 60.617% (+0.5%) from 60.092%
#4881

push

travis-ci

web-flow
test: update coverage workflow time (#33918)

156854 of 258761 relevant lines covered (60.62%)

75258957.81 hits per line

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

46.14
/source/libs/executor/src/executor.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 "executor.h"
17
#include <stdint.h>
18
#include "cmdnodes.h"
19
#include "dataSinkInt.h"
20
#include "executil.h"
21
#include "executorInt.h"
22
#include "libs/new-stream/stream.h"
23
#include "operator.h"
24
#include "osMemPool.h"
25
#include "osMemory.h"
26
#include "planner.h"
27
#include "query.h"
28
#include "querytask.h"
29
#include "storageapi.h"
30
#include "streamexecutorInt.h"
31
#include "taosdef.h"
32
#include "tarray.h"
33
#include "tdatablock.h"
34
#include "tref.h"
35
#include "trpc.h"
36
#include "tudf.h"
37
#include "wal.h"
38

39
static TdThreadOnce initPoolOnce = PTHREAD_ONCE_INIT;
40
int32_t             exchangeObjRefPool = -1;
41
SGlobalExecInfo     gExecInfo = {0};
42

43
void gExecInfoInit(void* pDnode, getDnodeId_f getDnodeId, getMnodeEpset_f getMnode) {
326,281✔
44
  gExecInfo.dnode = pDnode;
326,281✔
45
  gExecInfo.getMnode = getMnode;
326,281✔
46
  gExecInfo.getDnodeId = getDnodeId;
326,281✔
47
  return;
326,281✔
48
}
49

50
int32_t getCurrentMnodeEpset(SEpSet* pEpSet) {
3,566✔
51
  if (gExecInfo.dnode == NULL || gExecInfo.getMnode == NULL) {
3,566✔
52
    qError("gExecInfo is not initialized");
×
53
    return TSDB_CODE_APP_ERROR;
×
54
  }
55
  gExecInfo.getMnode(gExecInfo.dnode, pEpSet);
3,566✔
56
  return TSDB_CODE_SUCCESS;
3,566✔
57
}
58

59
static void cleanupRefPool() {
307,465✔
60
  int32_t ref = atomic_val_compare_exchange_32(&exchangeObjRefPool, exchangeObjRefPool, 0);
307,465✔
61
  taosCloseRef(ref);
307,465✔
62
}
307,465✔
63

64
static void initRefPool() {
307,465✔
65
  exchangeObjRefPool = taosOpenRef(1024, doDestroyExchangeOperatorInfo);
307,465✔
66
  (void)atexit(cleanupRefPool);
307,465✔
67
}
307,465✔
68

69
static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) {
×
70
  int32_t code = TSDB_CODE_SUCCESS;
×
71
  int32_t lino = 0;
×
72
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
×
73
    if (pOperator->numOfDownstream == 0) {
×
74
      qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
×
75
      return TSDB_CODE_APP_ERROR;
×
76
    }
77

78
    if (pOperator->numOfDownstream > 1) {  // not handle this in join query
×
79
      qError("join not supported for stream block scan, %s" PRIx64, id);
×
80
      return TSDB_CODE_APP_ERROR;
×
81
    }
82
    pOperator->status = OP_NOT_OPENED;
×
83
    return doSetSMABlock(pOperator->pDownstream[0], input, numOfBlocks, type, id);
×
84
  } else {
85
    pOperator->status = OP_NOT_OPENED;
×
86

87
    SStreamScanInfo* pInfo = pOperator->info;
×
88

89
    if (type == STREAM_INPUT__MERGED_SUBMIT) {
×
90
      for (int32_t i = 0; i < numOfBlocks; i++) {
×
91
        SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
×
92
        void*        tmp = taosArrayPush(pInfo->pBlockLists, pReq);
×
93
        QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
94
      }
95
      pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
×
96
    } else if (type == STREAM_INPUT__DATA_SUBMIT) {
×
97
      void* tmp = taosArrayPush(pInfo->pBlockLists, &input);
×
98
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
99
      pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
×
100
    } else if (type == STREAM_INPUT__DATA_BLOCK) {
×
101
      for (int32_t i = 0; i < numOfBlocks; ++i) {
×
102
        SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
×
103
        SPackedData  tmp = {.pDataBlock = pDataBlock};
×
104
        void*        tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
×
105
        QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
×
106
      }
107
      pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
×
108
    } else if (type == STREAM_INPUT__CHECKPOINT) {
×
109
      SPackedData tmp = {.pDataBlock = input};
×
110
      void*       tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
×
111
      QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
×
112
      pInfo->blockType = STREAM_INPUT__CHECKPOINT;
×
113
    } else if (type == STREAM_INPUT__REF_DATA_BLOCK) {
×
114
      for (int32_t i = 0; i < numOfBlocks; ++i) {
×
115
        SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
×
116
        void*        tmp = taosArrayPush(pInfo->pBlockLists, pReq);
×
117
        QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
118
      }
119
      pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
×
120
    }
121

122
    return TSDB_CODE_SUCCESS;
×
123
  }
124

125
_end:
×
126
  if (code != TSDB_CODE_SUCCESS) {
×
127
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
128
  }
129
  return code;
×
130
}
131

132
static int32_t doSetStreamOpOpen(SOperatorInfo* pOperator, char* id) {
×
133
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
×
134
    if (pOperator->numOfDownstream == 0) {
×
135
      qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
×
136
      return TSDB_CODE_APP_ERROR;
×
137
    }
138

139
    if (pOperator->numOfDownstream > 1) {  // not handle this in join query
×
140
      qError("join not supported for stream block scan, %s" PRIx64, id);
×
141
      return TSDB_CODE_APP_ERROR;
×
142
    }
143

144
    pOperator->status = OP_NOT_OPENED;
×
145
    return doSetStreamOpOpen(pOperator->pDownstream[0], id);
×
146
  }
147
  return 0;
×
148
}
149

150
int32_t doSetTaskId(SOperatorInfo* pOperator, SStorageAPI* pAPI) {
424,291✔
151
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
424,291✔
152
  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
424,291✔
153
    SStreamScanInfo* pStreamScanInfo = pOperator->info;
178,053✔
154
    if (pStreamScanInfo->pTableScanOp != NULL) {
178,053✔
155
      STableScanInfo* pScanInfo = pStreamScanInfo->pTableScanOp->info;
178,053✔
156
      if (pScanInfo->base.dataReader != NULL) {
177,518✔
157
        int32_t code = pAPI->tsdReader.tsdSetReaderTaskId(pScanInfo->base.dataReader, pTaskInfo->id.str);
×
158
        if (code) {
×
159
          qError("failed to set reader id for executor, code:%s", tstrerror(code));
×
160
          return code;
×
161
        }
162
      }
163
    }
164
  } else {
165
    if (pOperator->pDownstream) return doSetTaskId(pOperator->pDownstream[0], pAPI);
246,016✔
166
  }
167

168
  return 0;
230,808✔
169
}
170

171
int32_t qSetTaskId(qTaskInfo_t tinfo, uint64_t taskId, uint64_t queryId) {
230,808✔
172
  SExecTaskInfo* pTaskInfo = tinfo;
230,808✔
173
  pTaskInfo->id.queryId = queryId;
230,808✔
174
  buildTaskId(taskId, queryId, pTaskInfo->id.str, 64);
230,808✔
175

176
  // set the idstr for tsdbReader
177
  return doSetTaskId(pTaskInfo->pRoot, &pTaskInfo->storageAPI);
230,808✔
178
}
179

180
bool qTaskIsDone(qTaskInfo_t tinfo) {
×
181
  SExecTaskInfo* pTaskInfo = tinfo;
×
182
  return pTaskInfo->status == OP_EXEC_DONE;
×
183
}
184

185
int32_t qSetSMAInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) {
×
186
  if (tinfo == NULL) {
×
187
    return TSDB_CODE_APP_ERROR;
×
188
  }
189

190
  if (pBlocks == NULL || numOfBlocks == 0) {
×
191
    return TSDB_CODE_SUCCESS;
×
192
  }
193

194
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
195

196
  int32_t code = doSetSMABlock(pTaskInfo->pRoot, (void*)pBlocks, numOfBlocks, type, GET_TASKID(pTaskInfo));
×
197
  if (code != TSDB_CODE_SUCCESS) {
×
198
    qError("%s failed to set the sma block data", GET_TASKID(pTaskInfo));
×
199
  } else {
200
    qDebug("%s set the sma block successfully", GET_TASKID(pTaskInfo));
×
201
  }
202

203
  return code;
×
204
}
205

206
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* pReaderHandle, int32_t vgId, int32_t* numOfCols,
32,954✔
207
                                     uint64_t id) {
208
  if (msg == NULL) {  // create raw scan
32,954✔
209
    SExecTaskInfo* pTaskInfo = NULL;
560✔
210

211
    int32_t code = doCreateTask(0, id, vgId, OPTR_EXEC_MODEL_QUEUE, &pReaderHandle->api, &pTaskInfo);
560✔
212
    if (NULL == pTaskInfo || code != 0) {
560✔
213
      return NULL;
×
214
    }
215

216
    code = createTmqRawScanOperatorInfo(pReaderHandle, pTaskInfo, &pTaskInfo->pRoot);
560✔
217
    if (NULL == pTaskInfo->pRoot || code != 0) {
560✔
218
      taosMemoryFree(pTaskInfo);
×
219
      return NULL;
×
220
    }
221

222
    pTaskInfo->storageAPI = pReaderHandle->api;
560✔
223
    qDebug("create raw scan task info completed, vgId:%d, %s", vgId, GET_TASKID(pTaskInfo));
560✔
224
    return pTaskInfo;
560✔
225
  }
226

227
  SSubplan* pPlan = NULL;
32,394✔
228
  int32_t   code = qStringToSubplan(msg, &pPlan);
32,394✔
229
  if (code != TSDB_CODE_SUCCESS) {
32,394✔
230
    terrno = code;
×
231
    return NULL;
×
232
  }
233

234
  qTaskInfo_t pTaskInfo = NULL;
32,394✔
235
  code = qCreateExecTask(pReaderHandle, vgId, 0, pPlan, &pTaskInfo, NULL, 0, NULL, OPTR_EXEC_MODEL_QUEUE);
32,394✔
236
  if (code != TSDB_CODE_SUCCESS) {
32,394✔
237
    qDestroyTask(pTaskInfo);
×
238
    terrno = code;
×
239
    return NULL;
×
240
  }
241

242
  // extract the number of output columns
243
  SDataBlockDescNode* pDescNode = pPlan->pNode->pOutputDataBlockDesc;
32,394✔
244
  *numOfCols = 0;
32,394✔
245

246
  SNode* pNode;
247
  FOREACH(pNode, pDescNode->pSlots) {
461,350✔
248
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
428,956✔
249
    if (pSlotDesc->output) {
428,956✔
250
      ++(*numOfCols);
428,956✔
251
    }
252
  }
253

254
  return pTaskInfo;
32,394✔
255
}
256

257
static int32_t checkInsertParam(SStreamInserterParam* streamInserterParam) {
15,290✔
258
  if (streamInserterParam == NULL) {
15,290✔
259
    return TSDB_CODE_SUCCESS;
7,575✔
260
  }
261

262
  if (streamInserterParam->tbType == TSDB_SUPER_TABLE && streamInserterParam->suid <= 0) {
7,715✔
263
    stError("insertParam: invalid suid:%" PRIx64 " for child table", streamInserterParam->suid);
×
264
    return TSDB_CODE_INVALID_PARA;
×
265
  }
266

267
  if (streamInserterParam->dbFName == NULL || strlen(streamInserterParam->dbFName) == 0) {
7,715✔
268
    stError("insertParam: invalid db/table name");
×
269
    return TSDB_CODE_INVALID_PARA;
×
270
  }
271

272
  if (streamInserterParam->suid <= 0 &&
7,715✔
273
      (streamInserterParam->tbname == NULL || strlen(streamInserterParam->tbname) == 0)) {
1,715✔
274
    stError("insertParam: invalid table name, suid:%" PRIx64 "", streamInserterParam->suid);
×
275
    return TSDB_CODE_INVALID_PARA;
×
276
  }
277

278
  return TSDB_CODE_SUCCESS;
7,715✔
279
}
280

281
static int32_t qCreateStreamExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan,
15,290✔
282
                                     qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, int8_t compressResult, char* sql,
283
                                     EOPTR_EXEC_MODEL model, SStreamInserterParam* streamInserterParam) {
284
  if (pSubplan == NULL || pTaskInfo == NULL) {
15,290✔
285
    qError("invalid parameter, pSubplan:%p, pTaskInfo:%p", pSubplan, pTaskInfo);
×
286
    nodesDestroyNode((SNode *)pSubplan);
×
287
    return TSDB_CODE_INVALID_PARA;
×
288
  }
289
  int32_t lino = 0;
15,290✔
290
  int32_t code = checkInsertParam(streamInserterParam);
15,290✔
291
  if (code != TSDB_CODE_SUCCESS) {
15,290✔
292
    qError("invalid stream inserter param, code:%s", tstrerror(code));
×
293
    nodesDestroyNode((SNode *)pSubplan);
×
294
    return code;
×
295
  }
296
  SInserterParam* pInserterParam = NULL;
15,290✔
297
  SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo;
15,290✔
298
  (void)taosThreadOnce(&initPoolOnce, initRefPool);
15,290✔
299
  qDebug("start to create task, TID:0x%" PRIx64 " QID:0x%" PRIx64 ", vgId:%d", taskId, pSubplan->id.queryId, vgId);
15,290✔
300

301
  code = createExecTaskInfo(pSubplan, pTask, readHandle, taskId, vgId, sql, model);
15,290✔
302
  if (code != TSDB_CODE_SUCCESS || NULL == *pTask) {
15,290✔
303
    qError("failed to createExecTaskInfo, code:%s", tstrerror(code));
×
304
    goto _error;
×
305
  }
306

307
  if (streamInserterParam) {
15,290✔
308
    SDataSinkMgtCfg cfg = {.maxDataBlockNum = 500, .maxDataBlockNumPerQuery = 50, .compress = compressResult};
7,715✔
309
    void*           pSinkManager = NULL;
7,715✔
310
    code = dsDataSinkMgtInit(&cfg, &(*pTask)->storageAPI, &pSinkManager);
7,715✔
311
    if (code != TSDB_CODE_SUCCESS) {
7,715✔
312
      qError("failed to dsDataSinkMgtInit, code:%s, %s", tstrerror(code), (*pTask)->id.str);
×
313
      goto _error;
×
314
    }
315

316
    pInserterParam = taosMemoryCalloc(1, sizeof(SInserterParam));
7,715✔
317
    if (NULL == pInserterParam) {
7,715✔
318
      qError("failed to taosMemoryCalloc, code:%s, %s", tstrerror(terrno), (*pTask)->id.str);
×
319
      code = terrno;
×
320
      goto _error;
×
321
    }
322
    code = cloneStreamInserterParam(&pInserterParam->streamInserterParam, streamInserterParam);
7,715✔
323
    TSDB_CHECK_CODE(code, lino, _error);
7,715✔
324
    
325
    pInserterParam->readHandle = taosMemCalloc(1, sizeof(SReadHandle));
7,715✔
326
    pInserterParam->readHandle->pMsgCb = readHandle->pMsgCb;
7,715✔
327

328
    code = createStreamDataInserter(pSinkManager, handle, pInserterParam);
7,715✔
329
    if (code) {
7,715✔
330
      qError("failed to createStreamDataInserter, code:%s, %s", tstrerror(code), (*pTask)->id.str);
×
331
    }
332
  }
333
  qDebug("subplan task create completed, TID:0x%" PRIx64 " QID:0x%" PRIx64 " code:%s", taskId, pSubplan->id.queryId,
15,290✔
334
         tstrerror(code));
335

336
_error:
×
337

338
  if (code != TSDB_CODE_SUCCESS) {
15,290✔
339
    qError("%s failed at line %d, error:%s", __FUNCTION__, lino, tstrerror(code));
×
340
    if (pInserterParam != NULL) {
×
341
      taosMemoryFree(pInserterParam);
×
342
    }
343
  }
344
  return code;
15,290✔
345
}
346

347
bool qNeedReset(qTaskInfo_t pInfo) {
37,465✔
348
  if (pInfo == NULL) {
37,465✔
349
    return false;
×
350
  }
351
  SExecTaskInfo*  pTaskInfo = (SExecTaskInfo*)pInfo;
37,465✔
352
  SOperatorInfo*  pOperator = pTaskInfo->pRoot;
37,465✔
353
  if (pOperator == NULL || pOperator->pPhyNode == NULL) {
37,465✔
354
    return false;
×
355
  }
356
  int32_t node = nodeType(pOperator->pPhyNode);
37,465✔
357
  return (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == node || 
×
358
          QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == node ||
37,465✔
359
          QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN == node);
360
}
361

362
static void setReadHandle(SReadHandle* pHandle, STableScanBase* pScanBaseInfo) {
37,465✔
363
  if (pHandle == NULL || pScanBaseInfo == NULL) {
37,465✔
364
    return;
×
365
  }
366

367
  pScanBaseInfo->readHandle.uid = pHandle->uid;
37,465✔
368
  pScanBaseInfo->readHandle.winRangeValid = pHandle->winRangeValid;
37,465✔
369
  pScanBaseInfo->readHandle.winRange = pHandle->winRange;
37,465✔
370
  pScanBaseInfo->readHandle.extWinRangeValid = pHandle->extWinRangeValid;
37,465✔
371
  pScanBaseInfo->readHandle.extWinRange = pHandle->extWinRange;
37,465✔
372
  pScanBaseInfo->readHandle.cacheSttStatis = pHandle->cacheSttStatis;
37,465✔
373
}
374

375
int32_t qResetTableScan(qTaskInfo_t pInfo, SReadHandle* handle) {
37,465✔
376
  if (pInfo == NULL) {
37,465✔
377
    return TSDB_CODE_INVALID_PARA;
×
378
  }
379
  SExecTaskInfo*  pTaskInfo = (SExecTaskInfo*)pInfo;
37,465✔
380
  SOperatorInfo*  pOperator = pTaskInfo->pRoot;
37,465✔
381

382
  void*           info = pOperator->info;
37,465✔
383
  STableScanBase* pScanBaseInfo = NULL;
37,465✔
384

385
  if (QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN == nodeType(pOperator->pPhyNode)) {
37,465✔
386
    pScanBaseInfo = &((STableScanInfo*)info)->base;
37,465✔
387
    setReadHandle(handle, pScanBaseInfo);
37,465✔
388
  } else if (QUERY_NODE_PHYSICAL_PLAN_TABLE_MERGE_SCAN == nodeType(pOperator->pPhyNode)) {
×
389
    pScanBaseInfo = &((STableMergeScanInfo*)info)->base;
×
390
    setReadHandle(handle, pScanBaseInfo);
×
391
  }
392

393
  qDebug("reset table scan, name:%s, id:%s, time range: [%" PRId64 ", %" PRId64 "]", pOperator->name, GET_TASKID(pTaskInfo), handle->winRange.skey,
37,465✔
394
  handle->winRange.ekey);
395
  return pOperator->fpSet.resetStateFn(pOperator);
37,465✔
396
}
397

398
int32_t qCreateStreamExecTaskInfo(qTaskInfo_t* pTaskInfo, void* msg, SReadHandle* readers,
15,290✔
399
                                  SStreamInserterParam* pInserterParams, int32_t vgId, int32_t taskId) {
400
  if (msg == NULL) {
15,290✔
401
    return TSDB_CODE_INVALID_PARA;
×
402
  }
403

404
  *pTaskInfo = NULL;
15,290✔
405

406
  SSubplan* pPlan = NULL;
15,290✔
407
  int32_t   code = qStringToSubplan(msg, &pPlan);
15,290✔
408
  if (code != TSDB_CODE_SUCCESS) {
15,290✔
409
    nodesDestroyNode((SNode *)pPlan);
×
410
    return code;
×
411
  }
412
  // todo: add stream inserter param
413
  code = qCreateStreamExecTask(readers, vgId, taskId, pPlan, pTaskInfo,
15,290✔
414
                               pInserterParams ? &pInserterParams->pSinkHandle : NULL, 0, NULL, OPTR_EXEC_MODEL_STREAM,
415
                               pInserterParams);
416
  if (code != TSDB_CODE_SUCCESS) {
15,290✔
417
    qDestroyTask(*pTaskInfo);
×
418
    return code;
×
419
  }
420

421
  return code;
15,290✔
422
}
423

424
typedef struct {
425
  tb_uid_t tableUid;
426
  tb_uid_t childUid;
427
  int8_t   check;
428
} STqPair;
429

430
static int32_t filterUnqualifiedTables(const SStreamScanInfo* pScanInfo, const SArray* tableIdList, const char* idstr,
×
431
                                       SStorageAPI* pAPI, SArray** ppArrayRes) {
432
  int32_t code = TSDB_CODE_SUCCESS;
×
433
  int32_t lino = 0;
×
434
  int8_t  locked = 0;
×
435
  SArray* qa = taosArrayInit(4, sizeof(tb_uid_t));
×
436

437
  QUERY_CHECK_NULL(qa, code, lino, _error, terrno);
×
438

439
  SArray* tUid = taosArrayInit(4, sizeof(STqPair));
×
440
  QUERY_CHECK_NULL(tUid, code, lino, _error, terrno);
×
441

442
  int32_t numOfUids = taosArrayGetSize(tableIdList);
×
443
  if (numOfUids == 0) {
×
444
    (*ppArrayRes) = qa;
×
445
    goto _error;
×
446
  }
447

448
  STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
×
449

450
  uint64_t suid = 0;
×
451
  uint64_t uid = 0;
×
452
  int32_t  type = 0;
×
453
  tableListGetSourceTableInfo(pTableScanInfo->base.pTableListInfo, &suid, &uid, &type);
×
454

455
  // let's discard the tables those are not created according to the queried super table.
456
  SMetaReader mr = {0};
×
457
  pAPI->metaReaderFn.initReader(&mr, pScanInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn);
×
458

459
  locked = 1;
×
460
  for (int32_t i = 0; i < numOfUids; ++i) {
×
461
    uint64_t* id = (uint64_t*)taosArrayGet(tableIdList, i);
×
462
    QUERY_CHECK_NULL(id, code, lino, _end, terrno);
×
463

464
    int32_t code = pAPI->metaReaderFn.getTableEntryByUid(&mr, *id);
×
465
    if (code != TSDB_CODE_SUCCESS) {
×
466
      qError("failed to get table meta, uid:%" PRIu64 " code:%s, %s", *id, tstrerror(terrno), idstr);
×
467
      continue;
×
468
    }
469

470
    tDecoderClear(&mr.coder);
×
471

472
    if (mr.me.type == TSDB_SUPER_TABLE) {
×
473
      continue;
×
474
    } else {
475
      if (type == TSDB_SUPER_TABLE) {
×
476
        // this new created child table does not belong to the scanned super table.
477
        if (mr.me.type != TSDB_CHILD_TABLE || mr.me.ctbEntry.suid != suid) {
×
478
          continue;
×
479
        }
480
      } else {  // ordinary table
481
        // In case that the scanned target table is an ordinary table. When replay the WAL during restore the vnode, we
482
        // should check all newly created ordinary table to make sure that this table isn't the destination table.
483
        if (mr.me.uid != uid) {
×
484
          continue;
×
485
        }
486
      }
487
    }
488

489
    STqPair item = {.tableUid = *id, .childUid = mr.me.uid, .check = 0};
×
490
    if (pScanInfo->pTagCond != NULL) {
×
491
      // tb_uid_t id = mr.me.uid;
492
      item.check = 1;
×
493
    }
494
    if (taosArrayPush(tUid, &item) == NULL) {
×
495
      QUERY_CHECK_NULL(NULL, code, lino, _end, terrno);
×
496
    }
497
  }
498

499
  pAPI->metaReaderFn.clearReader(&mr);
×
500
  locked = 0;
×
501

502
  for (int32_t j = 0; j < taosArrayGetSize(tUid); ++j) {
×
503
    bool     qualified = false;
×
504
    STqPair* t = (STqPair*)taosArrayGet(tUid, j);
×
505
    if (t == NULL) {
×
506
      continue;
×
507
    }
508

509
    if (t->check == 1) {
×
510
      STableKeyInfo info = {.groupId = 0, .uid = t->childUid};
×
511
      code = isQualifiedTable(&info, pScanInfo->pTagCond, pScanInfo->readHandle.vnode, &qualified, pAPI);
×
512
      if (code != TSDB_CODE_SUCCESS) {
×
513
        qError("failed to filter new table, uid:0x%" PRIx64 ", %s", info.uid, idstr);
×
514
        continue;
×
515
      }
516

517
      if (!qualified) {
×
518
        continue;
×
519
      }
520
    }
521

522
    void* tmp = taosArrayPush(qa, &t->tableUid);
×
523
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
524
  }
525

526
  // handle multiple partition
527

528
_end:
×
529

530
  if (locked) {
×
531
    pAPI->metaReaderFn.clearReader(&mr);
×
532
  }
533
  (*ppArrayRes) = qa;
×
534
_error:
×
535

536
  taosArrayDestroy(tUid);
×
537
  if (code != TSDB_CODE_SUCCESS) {
×
538
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
539
  }
540
  return code;
×
541
}
542

543
int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) {
×
544
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
545
  const char*    id = GET_TASKID(pTaskInfo);
×
546
  int32_t        code = 0;
×
547

548
  if (isAdd) {
×
549
    qDebug("try to add %d tables id into query list, %s", (int32_t)taosArrayGetSize(tableIdList), id);
×
550
  }
551

552
  // traverse to the stream scanner node to add this table id
553
  SOperatorInfo* pInfo = NULL;
×
554
  code = extractOperatorInTree(pTaskInfo->pRoot, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pInfo);
×
555
  if (code != 0 || pInfo == NULL) {
×
556
    return code;
×
557
  }
558

559
  SStreamScanInfo* pScanInfo = pInfo->info;
×
560
  if (pInfo->pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {  // clear meta cache for subscription if tag is changed
×
561
    for (int32_t i = 0; i < taosArrayGetSize(tableIdList); ++i) {
×
562
      int64_t*        uid = (int64_t*)taosArrayGet(tableIdList, i);
×
563
      STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
×
564
      taosLRUCacheErase(pTableScanInfo->base.metaCache.pTableMetaEntryCache, uid, LONG_BYTES);
×
565
    }
566
  }
567

568
  if (isAdd) {  // add new table id
×
569
    SArray* qa = NULL;
×
570
    code = filterUnqualifiedTables(pScanInfo, tableIdList, id, &pTaskInfo->storageAPI, &qa);
×
571
    if (code != TSDB_CODE_SUCCESS) {
×
572
      taosArrayDestroy(qa);
×
573
      return code;
×
574
    }
575
    int32_t numOfQualifiedTables = taosArrayGetSize(qa);
×
576
    qDebug("%d qualified child tables added into stream scanner, %s", numOfQualifiedTables, id);
×
577
    pTaskInfo->storageAPI.tqReaderFn.tqReaderAddTables(pScanInfo->tqReader, qa);
×
578

579
    bool   assignUid = false;
×
580
    size_t bufLen = (pScanInfo->pGroupTags != NULL) ? getTableTagsBufLen(pScanInfo->pGroupTags) : 0;
×
581
    char*  keyBuf = NULL;
×
582
    if (bufLen > 0) {
×
583
      assignUid = groupbyTbname(pScanInfo->pGroupTags);
×
584
      keyBuf = taosMemoryMalloc(bufLen);
×
585
      if (keyBuf == NULL) {
×
586
        taosArrayDestroy(qa);
×
587
        return terrno;
×
588
      }
589
    }
590

591
    STableListInfo* pTableListInfo = ((STableScanInfo*)pScanInfo->pTableScanOp->info)->base.pTableListInfo;
×
592
    taosWLockLatch(&pTaskInfo->lock);
×
593

594
    for (int32_t i = 0; i < numOfQualifiedTables; ++i) {
×
595
      uint64_t* uid = taosArrayGet(qa, i);
×
596
      if (!uid) {
×
597
        taosMemoryFree(keyBuf);
×
598
        taosArrayDestroy(qa);
×
599
        taosWUnLockLatch(&pTaskInfo->lock);
×
600
        return terrno;
×
601
      }
602
      STableKeyInfo keyInfo = {.uid = *uid, .groupId = 0};
×
603

604
      if (bufLen > 0) {
×
605
        if (assignUid) {
×
606
          keyInfo.groupId = keyInfo.uid;
×
607
        } else {
608
          code = getGroupIdFromTagsVal(pScanInfo->readHandle.vnode, keyInfo.uid, pScanInfo->pGroupTags, keyBuf,
×
609
                                       &keyInfo.groupId, &pTaskInfo->storageAPI);
610
          if (code != TSDB_CODE_SUCCESS) {
×
611
            taosMemoryFree(keyBuf);
×
612
            taosArrayDestroy(qa);
×
613
            taosWUnLockLatch(&pTaskInfo->lock);
×
614
            return code;
×
615
          }
616
        }
617
      }
618

619
      code = tableListAddTableInfo(pTableListInfo, keyInfo.uid, keyInfo.groupId);
×
620
      if (code != TSDB_CODE_SUCCESS) {
×
621
        taosMemoryFree(keyBuf);
×
622
        taosArrayDestroy(qa);
×
623
        taosWUnLockLatch(&pTaskInfo->lock);
×
624
        return code;
×
625
      }
626
    }
627

628
    taosWUnLockLatch(&pTaskInfo->lock);
×
629
    if (keyBuf != NULL) {
×
630
      taosMemoryFree(keyBuf);
×
631
    }
632

633
    taosArrayDestroy(qa);
×
634
  } else {  // remove the table id in current list
635
    qDebug("%d remove child tables from the stream scanner, %s", (int32_t)taosArrayGetSize(tableIdList), id);
×
636
    taosWLockLatch(&pTaskInfo->lock);
×
637
    pTaskInfo->storageAPI.tqReaderFn.tqReaderRemoveTables(pScanInfo->tqReader, tableIdList);
×
638
    taosWUnLockLatch(&pTaskInfo->lock);
×
639
  }
640

641
  return code;
×
642
}
643

644
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, int32_t dbNameBuffLen, char* tableName,
138,797,180✔
645
                                    int32_t tbaleNameBuffLen, int32_t* sversion, int32_t* tversion, int32_t* rversion,
646
                                    int32_t idx, bool* tbGet) {
647
  *tbGet = false;
138,797,180✔
648

649
  if (tinfo == NULL || dbName == NULL || tableName == NULL) {
138,798,456✔
650
    return TSDB_CODE_INVALID_PARA;
×
651
  }
652
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
138,802,378✔
653

654
  if (taosArrayGetSize(pTaskInfo->schemaInfos) <= idx) {
138,802,378✔
655
    return TSDB_CODE_SUCCESS;
79,480,774✔
656
  }
657

658
  SSchemaInfo* pSchemaInfo = taosArrayGet(pTaskInfo->schemaInfos, idx);
59,320,518✔
659
  if (!pSchemaInfo) {
59,315,379✔
660
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
661
    return terrno;
×
662
  }
663

664
  *sversion = pSchemaInfo->sw->version;
59,315,379✔
665
  *tversion = pSchemaInfo->tversion;
59,323,636✔
666
  *rversion = pSchemaInfo->rversion;
59,323,057✔
667
  if (pSchemaInfo->dbname) {
59,325,068✔
668
    tstrncpy(dbName, pSchemaInfo->dbname, dbNameBuffLen);
59,323,080✔
669
  } else {
670
    dbName[0] = 0;
×
671
  }
672
  if (pSchemaInfo->tablename) {
59,328,642✔
673
    tstrncpy(tableName, pSchemaInfo->tablename, tbaleNameBuffLen);
59,325,635✔
674
  } else {
675
    tableName[0] = 0;
×
676
  }
677

678
  *tbGet = true;
59,328,537✔
679

680
  return TSDB_CODE_SUCCESS;
59,324,705✔
681
}
682

683
bool qIsDynamicExecTask(qTaskInfo_t tinfo) { return ((SExecTaskInfo*)tinfo)->dynamicTask; }
79,478,897✔
684

685
void qDestroyOperatorParam(SOperatorParam* pParam) {
×
686
  if (NULL == pParam) {
×
687
    return;
×
688
  }
689
  freeOperatorParam(pParam, OP_GET_PARAM);
×
690
}
691

692
void qUpdateOperatorParam(qTaskInfo_t tinfo, void* pParam) {
1,996,243✔
693
  TSWAP(pParam, ((SExecTaskInfo*)tinfo)->pOpParam);
1,996,243✔
694
  ((SExecTaskInfo*)tinfo)->paramSet = false;
1,996,243✔
695
}
1,996,243✔
696

697
int32_t qExecutorInit(void) {
2,479,524✔
698
  (void)taosThreadOnce(&initPoolOnce, initRefPool);
2,479,524✔
699
  return TSDB_CODE_SUCCESS;
2,479,524✔
700
}
701

702
int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan,
80,550,808✔
703
                        qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, int8_t compressResult, char* sql,
704
                        EOPTR_EXEC_MODEL model) {
705
  SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo;
80,550,808✔
706
  (void)taosThreadOnce(&initPoolOnce, initRefPool);
80,550,808✔
707

708
  qDebug("start to create task, TID:0x%" PRIx64 " QID:0x%" PRIx64 ", vgId:%d", taskId, pSubplan->id.queryId, vgId);
80,556,073✔
709

710
  readHandle->uid = 0;
80,564,881✔
711
  int32_t code = createExecTaskInfo(pSubplan, pTask, readHandle, taskId, vgId, sql, model);
80,570,243✔
712
  if (code != TSDB_CODE_SUCCESS || NULL == *pTask) {
80,522,453✔
713
    qError("failed to createExecTaskInfo, code:%s", tstrerror(code));
72,484✔
714
    goto _error;
17,350✔
715
  }
716

717
  if (handle) {
80,462,685✔
718
    SDataSinkMgtCfg cfg = {.maxDataBlockNum = 500, .maxDataBlockNumPerQuery = 50, .compress = compressResult};
80,468,612✔
719
    void*           pSinkManager = NULL;
80,481,121✔
720
    code = dsDataSinkMgtInit(&cfg, &(*pTask)->storageAPI, &pSinkManager);
80,372,088✔
721
    if (code != TSDB_CODE_SUCCESS) {
80,475,697✔
722
      qError("failed to dsDataSinkMgtInit, code:%s, %s", tstrerror(code), (*pTask)->id.str);
×
723
      goto _error;
×
724
    }
725

726
    void* pSinkParam = NULL;
80,475,697✔
727
    code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, (*pTask), readHandle);
80,474,664✔
728
    if (code != TSDB_CODE_SUCCESS) {
80,430,654✔
729
      qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str);
×
730
      taosMemoryFree(pSinkManager);
×
731
      goto _error;
×
732
    }
733

734
    SDataSinkNode* pSink = NULL;
80,430,654✔
735
    if (readHandle->localExec) {
80,467,007✔
736
      code = nodesCloneNode((SNode*)pSubplan->pDataSink, (SNode**)&pSink);
1,100✔
737
      if (code != TSDB_CODE_SUCCESS) {
1,100✔
738
        qError("failed to nodesCloneNode, srcType:%d, code:%s, %s", nodeType(pSubplan->pDataSink), tstrerror(code),
×
739
               (*pTask)->id.str);
740
        taosMemoryFree(pSinkManager);
×
741
        goto _error;
×
742
      }
743
    }
744

745
    // pSinkParam has been freed during create sinker.
746
    code = dsCreateDataSinker(pSinkManager, readHandle->localExec ? &pSink : &pSubplan->pDataSink, handle, pSinkParam,
80,418,643✔
747
                              (*pTask)->id.str, pSubplan->processOneBlock);
80,470,842✔
748
    if (code) {
80,413,951✔
749
      qError("s-task:%s failed to create data sinker, code:%s", (*pTask)->id.str, tstrerror(code));
414✔
750
    }
751
  }
752

753
  qDebug("subplan task create completed, TID:0x%" PRIx64 " QID:0x%" PRIx64 " code:%s", taskId, pSubplan->id.queryId,
80,494,001✔
754
         tstrerror(code));
755

756
_error:
4,420,002✔
757
  // if failed to add ref for all tables in this query, abort current query
758
  return code;
80,566,543✔
759
}
760

761
static void freeBlock(void* param) {
×
762
  SSDataBlock* pBlock = *(SSDataBlock**)param;
×
763
  blockDataDestroy(pBlock);
×
764
}
×
765

766
int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bool* hasMore, SLocalFetch* pLocal,
89,086,704✔
767
                     bool processOneBlock) {
768
  int32_t        code = TSDB_CODE_SUCCESS;
89,086,704✔
769
  int32_t        lino = 0;
89,086,704✔
770
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
89,086,704✔
771
  int64_t        threadId = taosGetSelfPthreadId();
89,086,704✔
772

773
  if (pLocal) {
89,084,646✔
774
    memcpy(&pTaskInfo->localFetch, pLocal, sizeof(*pLocal));
89,041,567✔
775
  }
776

777
  taosArrayClear(pResList);
89,076,547✔
778

779
  int64_t curOwner = 0;
89,080,679✔
780
  if ((curOwner = atomic_val_compare_exchange_64(&pTaskInfo->owner, 0, threadId)) != 0) {
89,080,679✔
781
    qError("%s-%p execTask is now executed by thread:%p", GET_TASKID(pTaskInfo), pTaskInfo, (void*)curOwner);
×
782
    pTaskInfo->code = TSDB_CODE_QRY_IN_EXEC;
×
783
    return pTaskInfo->code;
×
784
  }
785

786
  if (pTaskInfo->cost.start == 0) {
89,079,088✔
787
    pTaskInfo->cost.start = taosGetTimestampUs();
79,629,679✔
788
  }
789

790
  if (isTaskKilled(pTaskInfo)) {
89,084,888✔
791
    atomic_store_64(&pTaskInfo->owner, 0);
18✔
792
    qDebug("%s already killed, abort", GET_TASKID(pTaskInfo));
18✔
793
    return pTaskInfo->code;
18✔
794
  }
795

796
  // error occurs, record the error code and return to client
797
  int32_t ret = setjmp(pTaskInfo->env);
89,083,296✔
798
  if (ret != TSDB_CODE_SUCCESS) {
89,176,050✔
799
    pTaskInfo->code = ret;
103,056✔
800
    (void)cleanUpUdfs();
103,056✔
801

802
    qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
103,056✔
803
    atomic_store_64(&pTaskInfo->owner, 0);
103,056✔
804

805
    return pTaskInfo->code;
103,056✔
806
  }
807

808
  qDebug("%s execTask is launched", GET_TASKID(pTaskInfo));
89,072,994✔
809

810
  int32_t      current = 0;
89,074,083✔
811
  SSDataBlock* pRes = NULL;
89,074,083✔
812
  int64_t      st = taosGetTimestampUs();
89,087,451✔
813

814
  if (pTaskInfo->pOpParam && !pTaskInfo->paramSet) {
89,087,451✔
815
    pTaskInfo->paramSet = true;
1,996,243✔
816
    code = pTaskInfo->pRoot->fpSet.getNextExtFn(pTaskInfo->pRoot, pTaskInfo->pOpParam, &pRes);
1,996,243✔
817
  } else {
818
    code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, &pRes);
87,083,537✔
819
  }
820

821
  QUERY_CHECK_CODE(code, lino, _end);
88,983,720✔
822
  code = blockDataCheck(pRes);
88,983,720✔
823
  QUERY_CHECK_CODE(code, lino, _end);
88,982,930✔
824

825
  if (pRes == NULL) {
88,982,930✔
826
    st = taosGetTimestampUs();
13,455,415✔
827
  }
828

829
  int32_t rowsThreshold = pTaskInfo->pSubplan->rowsThreshold;
88,984,836✔
830
  if (!pTaskInfo->pSubplan->dynamicRowThreshold || 4096 <= pTaskInfo->pSubplan->rowsThreshold) {
88,980,896✔
831
    rowsThreshold = 4096;
88,649,380✔
832
  }
833

834
  int32_t blockIndex = 0;
88,981,522✔
835
  while (pRes != NULL) {
294,073,305✔
836
    SSDataBlock* p = NULL;
214,340,436✔
837
    if (blockIndex >= taosArrayGetSize(pTaskInfo->pResultBlockList)) {
214,338,307✔
838
      SSDataBlock* p1 = NULL;
158,832,706✔
839
      code = createOneDataBlock(pRes, true, &p1);
158,832,603✔
840
      QUERY_CHECK_CODE(code, lino, _end);
158,825,317✔
841

842
      void* tmp = taosArrayPush(pTaskInfo->pResultBlockList, &p1);
158,825,317✔
843
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
158,831,534✔
844
      p = p1;
158,831,534✔
845
    } else {
846
      void* tmp = taosArrayGet(pTaskInfo->pResultBlockList, blockIndex);
55,511,275✔
847
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
55,511,601✔
848

849
      p = *(SSDataBlock**)tmp;
55,511,601✔
850
      code = copyDataBlock(p, pRes);
55,511,704✔
851
      QUERY_CHECK_CODE(code, lino, _end);
55,510,199✔
852
    }
853

854
    blockIndex += 1;
214,341,975✔
855

856
    current += p->info.rows;
214,341,975✔
857
    QUERY_CHECK_CONDITION((p->info.rows > 0 || p->info.type == STREAM_CHECKPOINT), code, lino, _end,
214,342,553✔
858
                          TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
859
    void* tmp = taosArrayPush(pResList, &p);
214,343,261✔
860
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
214,343,261✔
861

862
    if (current >= rowsThreshold || processOneBlock) {
214,343,261✔
863
      break;
864
    }
865

866
    code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, &pRes);
205,093,642✔
867
    QUERY_CHECK_CODE(code, lino, _end);
205,090,001✔
868
    code = blockDataCheck(pRes);
205,090,001✔
869
    QUERY_CHECK_CODE(code, lino, _end);
205,096,940✔
870
  }
871

872
  if (pTaskInfo->pSubplan->dynamicRowThreshold) {
88,982,488✔
873
    pTaskInfo->pSubplan->rowsThreshold -= current;
327,752✔
874
  }
875

876
  *hasMore = (pRes != NULL);
88,986,102✔
877
  uint64_t el = (taosGetTimestampUs() - st);
88,976,928✔
878

879
  pTaskInfo->cost.elapsedTime += el;
88,976,928✔
880
  if (NULL == pRes) {
88,977,358✔
881
    *useconds = pTaskInfo->cost.elapsedTime;
79,727,739✔
882
  }
883

884
_end:
88,975,028✔
885
  (void)cleanUpUdfs();
88,978,169✔
886

887
  uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
88,987,706✔
888
  qDebug("%s task suspended, %d rows in %d blocks returned, total:%" PRId64 " rows, in sinkNode:%d, elapsed:%.2f ms",
88,987,706✔
889
         GET_TASKID(pTaskInfo), current, (int32_t)taosArrayGetSize(pResList), total, 0, el / 1000.0);
890

891
  atomic_store_64(&pTaskInfo->owner, 0);
88,987,706✔
892
  if (code) {
88,987,605✔
893
    pTaskInfo->code = code;
×
894
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
895
  }
896

897
  return pTaskInfo->code;
88,987,605✔
898
}
899

900
void qCleanExecTaskBlockBuf(qTaskInfo_t tinfo) {
×
901
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
902
  SArray*        pList = pTaskInfo->pResultBlockList;
×
903
  size_t         num = taosArrayGetSize(pList);
×
904
  for (int32_t i = 0; i < num; ++i) {
×
905
    SSDataBlock** p = taosArrayGet(pTaskInfo->pResultBlockList, i);
×
906
    if (p) {
×
907
      blockDataDestroy(*p);
×
908
    }
909
  }
910

911
  taosArrayClear(pTaskInfo->pResultBlockList);
×
912
}
×
913

914
int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) {
10,814,049✔
915
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
10,814,049✔
916
  int64_t        threadId = taosGetSelfPthreadId();
10,814,049✔
917
  int64_t        curOwner = 0;
10,814,049✔
918

919
  *pRes = NULL;
10,814,049✔
920

921
  // todo extract method
922
  taosRLockLatch(&pTaskInfo->lock);
10,814,049✔
923
  bool isKilled = isTaskKilled(pTaskInfo);
10,814,049✔
924
  if (isKilled) {
10,814,049✔
925
    qDebug("%s already killed, abort", GET_TASKID(pTaskInfo));
×
926

927
    taosRUnLockLatch(&pTaskInfo->lock);
×
928
    return pTaskInfo->code;
×
929
  }
930

931
  if (pTaskInfo->owner != 0) {
10,814,049✔
932
    qError("%s-%p execTask is now executed by thread:%p", GET_TASKID(pTaskInfo), pTaskInfo, (void*)curOwner);
×
933
    pTaskInfo->code = TSDB_CODE_QRY_IN_EXEC;
×
934

935
    taosRUnLockLatch(&pTaskInfo->lock);
×
936
    return pTaskInfo->code;
×
937
  }
938

939
  pTaskInfo->owner = threadId;
10,814,049✔
940
  taosRUnLockLatch(&pTaskInfo->lock);
10,814,049✔
941

942
  if (pTaskInfo->cost.start == 0) {
10,814,049✔
943
    pTaskInfo->cost.start = taosGetTimestampUs();
25,128✔
944
  }
945

946
  // error occurs, record the error code and return to client
947
  int32_t ret = setjmp(pTaskInfo->env);
10,814,049✔
948
  if (ret != TSDB_CODE_SUCCESS) {
10,814,049✔
949
    pTaskInfo->code = ret;
×
950
    (void)cleanUpUdfs();
×
951
    qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
×
952
    atomic_store_64(&pTaskInfo->owner, 0);
×
953
    return pTaskInfo->code;
×
954
  }
955

956
  qDebug("%s execTask is launched", GET_TASKID(pTaskInfo));
10,814,049✔
957

958
  int64_t st = taosGetTimestampUs();
10,814,049✔
959
  int32_t code = TSDB_CODE_SUCCESS;
10,814,049✔
960
  if (pTaskInfo->pOpParam && !pTaskInfo->paramSet) {
10,814,049✔
961
    pTaskInfo->paramSet = true;
×
962
    code = pTaskInfo->pRoot->fpSet.getNextExtFn(pTaskInfo->pRoot, pTaskInfo->pOpParam, pRes);
×
963
  } else {
964
    code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, pRes);
10,814,049✔
965
  }
966
  if (code) {
10,802,279✔
967
    pTaskInfo->code = code;
×
968
    qError("%s failed at line %d, code:%s %s", __func__, __LINE__, tstrerror(code), GET_TASKID(pTaskInfo));
×
969
  }
970

971
  code = blockDataCheck(*pRes);
10,802,279✔
972
  if (code) {
10,812,444✔
973
    pTaskInfo->code = code;
×
974
    qError("%s failed at line %d, code:%s %s", __func__, __LINE__, tstrerror(code), GET_TASKID(pTaskInfo));
×
975
  }
976

977
  uint64_t el = (taosGetTimestampUs() - st);
10,807,094✔
978

979
  pTaskInfo->cost.elapsedTime += el;
10,807,094✔
980
  if (NULL == *pRes) {
10,812,444✔
981
    *useconds = pTaskInfo->cost.elapsedTime;
79,130✔
982
  }
983

984
  (void)cleanUpUdfs();
10,812,757✔
985

986
  int32_t  current = (*pRes != NULL) ? (*pRes)->info.rows : 0;
10,814,049✔
987
  uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
10,814,049✔
988

989
  qDebug("%s task suspended, %d rows returned, total:%" PRId64 " rows, in sinkNode:%d, elapsed:%.2f ms",
10,814,049✔
990
         GET_TASKID(pTaskInfo), current, total, 0, el / 1000.0);
991

992
  atomic_store_64(&pTaskInfo->owner, 0);
10,814,049✔
993
  return pTaskInfo->code;
10,814,049✔
994
}
995

996
int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo) {
24,889,413✔
997
  taosWLockLatch(&pTaskInfo->stopInfo.lock);
24,889,413✔
998
  void* tmp = taosArrayPush(pTaskInfo->stopInfo.pStopInfo, pInfo);
24,889,587✔
999
  taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
24,889,587✔
1000

1001
  if (!tmp) {
24,889,413✔
1002
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
1003
    return terrno;
×
1004
  }
1005
  return TSDB_CODE_SUCCESS;
24,889,413✔
1006
}
1007

1008
int32_t stopInfoComp(void const* lp, void const* rp) {
×
1009
  SExchangeOpStopInfo* key = (SExchangeOpStopInfo*)lp;
×
1010
  SExchangeOpStopInfo* pInfo = (SExchangeOpStopInfo*)rp;
×
1011

1012
  if (key->refId < pInfo->refId) {
×
1013
    return -1;
×
1014
  } else if (key->refId > pInfo->refId) {
×
1015
    return 1;
×
1016
  }
1017

1018
  return 0;
×
1019
}
1020

1021
void qRemoveTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo) {
×
1022
  taosWLockLatch(&pTaskInfo->stopInfo.lock);
×
1023
  int32_t idx = taosArraySearchIdx(pTaskInfo->stopInfo.pStopInfo, pInfo, stopInfoComp, TD_EQ);
×
1024
  if (idx >= 0) {
×
1025
    taosArrayRemove(pTaskInfo->stopInfo.pStopInfo, idx);
×
1026
  }
1027
  taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
×
1028
}
×
1029

1030
void qStopTaskOperators(SExecTaskInfo* pTaskInfo) {
8,805✔
1031
  taosWLockLatch(&pTaskInfo->stopInfo.lock);
8,805✔
1032

1033
  int32_t num = taosArrayGetSize(pTaskInfo->stopInfo.pStopInfo);
8,805✔
1034
  for (int32_t i = 0; i < num; ++i) {
9,540✔
1035
    SExchangeOpStopInfo* pStop = taosArrayGet(pTaskInfo->stopInfo.pStopInfo, i);
735✔
1036
    if (!pStop) {
735✔
1037
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
1038
      continue;
×
1039
    }
1040
    SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pStop->refId);
735✔
1041
    if (pExchangeInfo) {
735✔
1042
      int32_t code = tsem_post(&pExchangeInfo->ready);
735✔
1043
      if (code != TSDB_CODE_SUCCESS) {
735✔
1044
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1045
      } else {
1046
        qDebug("post to exchange %" PRId64 " to stop", pStop->refId);
735✔
1047
      }
1048
      code = taosReleaseRef(exchangeObjRefPool, pStop->refId);
735✔
1049
      if (code != TSDB_CODE_SUCCESS) {
735✔
1050
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1051
      }
1052
    }
1053
  }
1054

1055
  taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
8,805✔
1056
}
8,805✔
1057

1058
int32_t qAsyncKillTask(qTaskInfo_t qinfo, int32_t rspCode) {
8,805✔
1059
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo;
8,805✔
1060
  if (pTaskInfo == NULL) {
8,805✔
1061
    return TSDB_CODE_QRY_INVALID_QHANDLE;
×
1062
  }
1063

1064
  qDebug("%s execTask async killed", GET_TASKID(pTaskInfo));
8,805✔
1065

1066
  setTaskKilled(pTaskInfo, rspCode);
8,805✔
1067
  qStopTaskOperators(pTaskInfo);
8,805✔
1068

1069
  return TSDB_CODE_SUCCESS;
8,805✔
1070
}
1071

1072
int32_t qKillTask(qTaskInfo_t tinfo, int32_t rspCode, int64_t waitDuration) {
×
1073
  int64_t        st = taosGetTimestampMs();
×
1074
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
1075
  if (pTaskInfo == NULL) {
×
1076
    return TSDB_CODE_QRY_INVALID_QHANDLE;
×
1077
  }
1078

1079
  if (waitDuration > 0) {
×
1080
    qDebug("%s sync killed execTask, and waiting for at most %.2fs", GET_TASKID(pTaskInfo), waitDuration / 1000.0);
×
1081
  } else {
1082
    qDebug("%s async killed execTask", GET_TASKID(pTaskInfo));
×
1083
  }
1084

1085
  setTaskKilled(pTaskInfo, TSDB_CODE_TSC_QUERY_KILLED);
×
1086

1087
  if (waitDuration > 0) {
×
1088
    while (1) {
1089
      taosWLockLatch(&pTaskInfo->lock);
×
1090
      if (qTaskIsExecuting(pTaskInfo)) {  // let's wait for 100 ms and try again
×
1091
        taosWUnLockLatch(&pTaskInfo->lock);
×
1092

1093
        taosMsleep(200);
×
1094

1095
        int64_t d = taosGetTimestampMs() - st;
×
1096
        if (d >= waitDuration && waitDuration >= 0) {
×
1097
          qWarn("%s waiting more than %.2fs, not wait anymore", GET_TASKID(pTaskInfo), waitDuration / 1000.0);
×
1098
          return TSDB_CODE_SUCCESS;
×
1099
        }
1100
      } else {  // not running now
1101
        pTaskInfo->code = rspCode;
×
1102
        taosWUnLockLatch(&pTaskInfo->lock);
×
1103
        return TSDB_CODE_SUCCESS;
×
1104
      }
1105
    }
1106
  }
1107

1108
  int64_t et = taosGetTimestampMs() - st;
×
1109
  if (et < waitDuration) {
×
1110
    qInfo("%s  waiting %.2fs for executor stopping", GET_TASKID(pTaskInfo), et / 1000.0);
×
1111
    return TSDB_CODE_SUCCESS;
×
1112
  }
1113
  return TSDB_CODE_SUCCESS;
×
1114
}
1115

1116
bool qTaskIsExecuting(qTaskInfo_t qinfo) {
×
1117
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo;
×
1118
  if (NULL == pTaskInfo) {
×
1119
    return false;
×
1120
  }
1121

1122
  return 0 != atomic_load_64(&pTaskInfo->owner);
×
1123
}
1124

1125
static void printTaskExecCostInLog(SExecTaskInfo* pTaskInfo) {
80,569,431✔
1126
  STaskCostInfo* pSummary = &pTaskInfo->cost;
80,569,431✔
1127
  int64_t        idleTime = pSummary->start - pSummary->created;
80,569,952✔
1128

1129
  SFileBlockLoadRecorder* pRecorder = pSummary->pRecoder;
80,568,883✔
1130
  if (pSummary->pRecoder != NULL) {
80,568,864✔
1131
    qDebug(
59,167,380✔
1132
        "%s :cost summary: idle:%.2f ms, elapsed time:%.2f ms, extract tableList:%.2f ms, "
1133
        "createGroupIdMap:%.2f ms, total blocks:%d, "
1134
        "load block SMA:%d, load data block:%d, total rows:%" PRId64 ", check rows:%" PRId64,
1135
        GET_TASKID(pTaskInfo), idleTime / 1000.0, pSummary->elapsedTime / 1000.0, pSummary->extractListTime,
1136
        pSummary->groupIdMapTime, pRecorder->totalBlocks, pRecorder->loadBlockStatis, pRecorder->loadBlocks,
1137
        pRecorder->totalRows, pRecorder->totalCheckedRows);
1138
  } else {
1139
    qDebug("%s :cost summary: idle in queue:%.2f ms, elapsed time:%.2f ms", GET_TASKID(pTaskInfo), idleTime / 1000.0,
21,401,357✔
1140
           pSummary->elapsedTime / 1000.0);
1141
  }
1142
}
80,568,833✔
1143

1144
void qDestroyTask(qTaskInfo_t qTaskHandle) {
80,800,747✔
1145
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qTaskHandle;
80,800,747✔
1146
  if (pTaskInfo == NULL) {
80,800,747✔
1147
    return;
231,785✔
1148
  }
1149

1150
  if (pTaskInfo->pRoot != NULL) {
80,568,962✔
1151
    qDebug("%s execTask completed, numOfRows:%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->pRoot->resultInfo.totalRows);
80,569,760✔
1152
  } else {
1153
    qDebug("%s execTask completed", GET_TASKID(pTaskInfo));
×
1154
  }
1155

1156
  printTaskExecCostInLog(pTaskInfo);  // print the query cost summary
80,570,285✔
1157
  doDestroyTask(pTaskInfo);
80,569,328✔
1158
}
1159

1160
int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, SArray* pExecInfoList) {
1,315,910✔
1161
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
1,315,910✔
1162
  return getOperatorExplainExecInfo(pTaskInfo->pRoot, pExecInfoList);
1,315,910✔
1163
}
1164

1165
void qExtractTmqScanner(qTaskInfo_t tinfo, void** scanner) {
32,394✔
1166
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
32,394✔
1167
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
32,394✔
1168

1169
  while (1) {
32,394✔
1170
    uint16_t type = pOperator->operatorType;
64,788✔
1171
    if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
64,788✔
1172
      *scanner = pOperator->info;
32,394✔
1173
      break;
32,394✔
1174
    } else {
1175
      pOperator = pOperator->pDownstream[0];
32,394✔
1176
    }
1177
  }
1178
}
32,394✔
1179

1180
void* qExtractReaderFromTmqScanner(void* scanner) {
32,394✔
1181
  SStreamScanInfo* pInfo = scanner;
32,394✔
1182
  return (void*)pInfo->tqReader;
32,394✔
1183
}
1184

1185
const SSchemaWrapper* qExtractSchemaFromTask(qTaskInfo_t tinfo) {
×
1186
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
1187
  return pTaskInfo->streamInfo.schema;
×
1188
}
1189

1190
const char* qExtractTbnameFromTask(qTaskInfo_t tinfo) {
×
1191
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
1192
  return pTaskInfo->streamInfo.tbName;
×
1193
}
1194

1195
SMqBatchMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo) {
×
1196
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
1197
  return &pTaskInfo->streamInfo.btMetaRsp;
×
1198
}
1199

1200
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
176,050✔
1201
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
176,050✔
1202
  tOffsetCopy(pOffset, &pTaskInfo->streamInfo.currentOffset);
176,050✔
1203
  return 0;
176,050✔
1204
  /*if (code != TSDB_CODE_SUCCESS) {
1205
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
1206
    pTaskInfo->code = code;
1207
    T_LONG_JMP(pTaskInfo->env, code);
1208
  }*/
1209
}
1210

1211
int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* sContext, SMetaTableInfo* pMtInfo) {
×
1212
  memset(pCond, 0, sizeof(SQueryTableDataCond));
×
1213
  pCond->order = TSDB_ORDER_ASC;
×
1214
  pCond->numOfCols = pMtInfo->schema->nCols;
×
1215
  pCond->colList = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnInfo));
×
1216
  pCond->pSlotList = taosMemoryMalloc(sizeof(int32_t) * pCond->numOfCols);
×
1217
  if (pCond->colList == NULL || pCond->pSlotList == NULL) {
×
1218
    taosMemoryFreeClear(pCond->colList);
×
1219
    taosMemoryFreeClear(pCond->pSlotList);
×
1220
    return terrno;
×
1221
  }
1222

1223
  TAOS_SET_OBJ_ALIGNED(&pCond->twindows, TSWINDOW_INITIALIZER);
×
1224
  pCond->suid = pMtInfo->suid;
×
1225
  pCond->type = TIMEWINDOW_RANGE_CONTAINED;
×
1226
  pCond->startVersion = -1;
×
1227
  pCond->endVersion = sContext->snapVersion;
×
1228

1229
  for (int32_t i = 0; i < pCond->numOfCols; ++i) {
×
1230
    SColumnInfo* pColInfo = &pCond->colList[i];
×
1231
    pColInfo->type = pMtInfo->schema->pSchema[i].type;
×
1232
    pColInfo->bytes = pMtInfo->schema->pSchema[i].bytes;
×
1233
    if (pMtInfo->pExtSchemas != NULL) {
×
1234
      decimalFromTypeMod(pMtInfo->pExtSchemas[i].typeMod, &pColInfo->precision, &pColInfo->scale);
×
1235
    }
1236
    pColInfo->colId = pMtInfo->schema->pSchema[i].colId;
×
1237
    pColInfo->pk = pMtInfo->schema->pSchema[i].flags & COL_IS_KEY;
×
1238

1239
    pCond->pSlotList[i] = i;
×
1240
  }
1241

1242
  return TSDB_CODE_SUCCESS;
×
1243
}
1244

1245
void qStreamSetOpen(qTaskInfo_t tinfo) {
10,812,747✔
1246
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
10,812,747✔
1247
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
10,812,747✔
1248
  pOperator->status = OP_NOT_OPENED;
10,812,979✔
1249
}
10,813,282✔
1250

1251
void qStreamSetSourceExcluded(qTaskInfo_t tinfo, int8_t sourceExcluded) {
175,818✔
1252
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
175,818✔
1253
  pTaskInfo->streamInfo.sourceExcluded = sourceExcluded;
175,818✔
1254
}
175,818✔
1255

1256
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType) {
177,286✔
1257
  int32_t        code = TSDB_CODE_SUCCESS;
177,286✔
1258
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
177,286✔
1259
  SStorageAPI*   pAPI = &pTaskInfo->storageAPI;
177,286✔
1260

1261
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
178,053✔
1262
  const char*    id = GET_TASKID(pTaskInfo);
177,821✔
1263

1264
  if (subType == TOPIC_SUB_TYPE__COLUMN && pOffset->type == TMQ_OFFSET__LOG) {
177,821✔
1265
    code = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pOperator);
177,821✔
1266
    if (pOperator == NULL || code != 0) {
177,518✔
1267
      return code;
×
1268
    }
1269

1270
    SStreamScanInfo* pInfo = pOperator->info;
177,518✔
1271
    SStoreTqReader*  pReaderAPI = &pTaskInfo->storageAPI.tqReaderFn;
177,286✔
1272
    SWalReader*      pWalReader = pReaderAPI->tqReaderGetWalReader(pInfo->tqReader);
177,286✔
1273
    walReaderVerifyOffset(pWalReader, pOffset);
178,053✔
1274
  }
1275
  // if pOffset equal to current offset, means continue consume
1276
  if (tOffsetEqual(pOffset, &pTaskInfo->streamInfo.currentOffset)) {
178,356✔
1277
    return 0;
145,340✔
1278
  }
1279

1280
  if (subType == TOPIC_SUB_TYPE__COLUMN) {
32,481✔
1281
    code = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pOperator);
32,481✔
1282
    if (pOperator == NULL || code != 0) {
32,481✔
1283
      return code;
×
1284
    }
1285

1286
    SStreamScanInfo* pInfo = pOperator->info;
32,481✔
1287
    STableScanInfo*  pScanInfo = pInfo->pTableScanOp->info;
32,481✔
1288
    STableScanBase*  pScanBaseInfo = &pScanInfo->base;
32,481✔
1289
    STableListInfo*  pTableListInfo = pScanBaseInfo->pTableListInfo;
32,481✔
1290

1291
    if (pOffset->type == TMQ_OFFSET__LOG) {
32,481✔
1292
      pTaskInfo->storageAPI.tsdReader.tsdReaderClose(pScanBaseInfo->dataReader);
32,481✔
1293
      pScanBaseInfo->dataReader = NULL;
32,481✔
1294

1295
      SStoreTqReader* pReaderAPI = &pTaskInfo->storageAPI.tqReaderFn;
32,481✔
1296
      SWalReader*     pWalReader = pReaderAPI->tqReaderGetWalReader(pInfo->tqReader);
32,481✔
1297
      walReaderVerifyOffset(pWalReader, pOffset);
32,481✔
1298
      code = pReaderAPI->tqReaderSeek(pInfo->tqReader, pOffset->version, id);
32,481✔
1299
      if (code < 0) {
32,481✔
1300
        qError("tqReaderSeek failed ver:%" PRId64 ", %s", pOffset->version, id);
2,003✔
1301
        return code;
2,003✔
1302
      }
1303
    } else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
×
1304
      // iterate all tables from tableInfoList, and retrieve rows from each table one-by-one
1305
      // those data are from the snapshot in tsdb, besides the data in the wal file.
1306
      int64_t uid = pOffset->uid;
×
1307
      int64_t ts = pOffset->ts;
×
1308
      int32_t index = 0;
×
1309

1310
      // this value may be changed if new tables are created
1311
      taosRLockLatch(&pTaskInfo->lock);
×
1312
      int32_t numOfTables = 0;
×
1313
      code = tableListGetSize(pTableListInfo, &numOfTables);
×
1314
      if (code != TSDB_CODE_SUCCESS) {
×
1315
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1316
        taosRUnLockLatch(&pTaskInfo->lock);
×
1317
        return code;
×
1318
      }
1319

1320
      if (uid == 0) {
×
1321
        if (numOfTables != 0) {
×
1322
          STableKeyInfo* tmp = tableListGetInfo(pTableListInfo, 0);
×
1323
          if (!tmp) {
×
1324
            qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
1325
            taosRUnLockLatch(&pTaskInfo->lock);
×
1326
            return terrno;
×
1327
          }
1328
          if (tmp) uid = tmp->uid;
×
1329
          ts = INT64_MIN;
×
1330
          pScanInfo->currentTable = 0;
×
1331
        } else {
1332
          taosRUnLockLatch(&pTaskInfo->lock);
×
1333
          qError("no table in table list, %s", id);
×
1334
          return TSDB_CODE_TMQ_NO_TABLE_QUALIFIED;
×
1335
        }
1336
      }
1337
      pTaskInfo->storageAPI.tqReaderFn.tqSetTablePrimaryKey(pInfo->tqReader, uid);
×
1338

1339
      qDebug("switch to table uid:%" PRId64 " ts:%" PRId64 "% " PRId64 " rows returned", uid, ts,
×
1340
             pInfo->pTableScanOp->resultInfo.totalRows);
1341
      pInfo->pTableScanOp->resultInfo.totalRows = 0;
×
1342

1343
      // start from current accessed position
1344
      // we cannot start from the pScanInfo->currentTable, since the commit offset may cause the rollback of the start
1345
      // position, let's find it from the beginning.
1346
      index = tableListFind(pTableListInfo, uid, 0);
×
1347
      taosRUnLockLatch(&pTaskInfo->lock);
×
1348

1349
      if (index >= 0) {
×
1350
        pScanInfo->currentTable = index;
×
1351
      } else {
1352
        qError("vgId:%d uid:%" PRIu64 " not found in table list, total:%d, index:%d %s", pTaskInfo->id.vgId, uid,
×
1353
               numOfTables, pScanInfo->currentTable, id);
1354
        return TSDB_CODE_TMQ_NO_TABLE_QUALIFIED;
×
1355
      }
1356

1357
      STableKeyInfo keyInfo = {.uid = uid};
×
1358
      int64_t       oldSkey = pScanBaseInfo->cond.twindows.skey;
×
1359

1360
      // let's start from the next ts that returned to consumer.
1361
      if (pTaskInfo->storageAPI.tqReaderFn.tqGetTablePrimaryKey(pInfo->tqReader)) {
×
1362
        pScanBaseInfo->cond.twindows.skey = ts;
×
1363
      } else {
1364
        pScanBaseInfo->cond.twindows.skey = ts + 1;
×
1365
      }
1366
      pScanInfo->scanTimes = 0;
×
1367

1368
      if (pScanBaseInfo->dataReader == NULL) {
×
1369
        code = pTaskInfo->storageAPI.tsdReader.tsdReaderOpen(pScanBaseInfo->readHandle.vnode, &pScanBaseInfo->cond,
×
1370
                                                             &keyInfo, 1, pScanInfo->pResBlock,
1371
                                                             (void**)&pScanBaseInfo->dataReader, id, NULL);
×
1372
        if (code != TSDB_CODE_SUCCESS) {
×
1373
          qError("prepare read tsdb snapshot failed, uid:%" PRId64 ", code:%s %s", pOffset->uid, tstrerror(code), id);
×
1374
          return code;
×
1375
        }
1376

1377
        qDebug("tsdb reader created with offset(snapshot) uid:%" PRId64 " ts:%" PRId64 " table index:%d, total:%d, %s",
×
1378
               uid, pScanBaseInfo->cond.twindows.skey, pScanInfo->currentTable, numOfTables, id);
1379
      } else {
1380
        code = pTaskInfo->storageAPI.tsdReader.tsdSetQueryTableList(pScanBaseInfo->dataReader, &keyInfo, 1);
×
1381
        if (code != TSDB_CODE_SUCCESS) {
×
1382
          qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1383
          return code;
×
1384
        }
1385

1386
        code = pTaskInfo->storageAPI.tsdReader.tsdReaderResetStatus(pScanBaseInfo->dataReader, &pScanBaseInfo->cond);
×
1387
        if (code != TSDB_CODE_SUCCESS) {
×
1388
          qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1389
          return code;
×
1390
        }
1391
        qDebug("tsdb reader offset seek snapshot to uid:%" PRId64 " ts %" PRId64 "  table index:%d numOfTable:%d, %s",
×
1392
               uid, pScanBaseInfo->cond.twindows.skey, pScanInfo->currentTable, numOfTables, id);
1393
      }
1394

1395
      // restore the key value
1396
      pScanBaseInfo->cond.twindows.skey = oldSkey;
×
1397
    } else {
1398
      qError("invalid pOffset->type:%d, %s", pOffset->type, id);
×
1399
      return TSDB_CODE_PAR_INTERNAL_ERROR;
×
1400
    }
1401

1402
  } else {  // subType == TOPIC_SUB_TYPE__TABLE/TOPIC_SUB_TYPE__DB
1403
    if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
×
1404
      SStreamRawScanInfo* pInfo = pOperator->info;
×
1405
      SSnapContext*       sContext = pInfo->sContext;
×
1406
      SOperatorInfo*      p = NULL;
×
1407

1408
      code = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, id, &p);
×
1409
      if (code != 0) {
×
1410
        return code;
×
1411
      }
1412

1413
      STableListInfo* pTableListInfo = ((SStreamRawScanInfo*)(p->info))->pTableListInfo;
×
1414

1415
      if (pAPI->snapshotFn.setForSnapShot(sContext, pOffset->uid) != 0) {
×
1416
        qError("setDataForSnapShot error. uid:%" PRId64 " , %s", pOffset->uid, id);
×
1417
        return TSDB_CODE_PAR_INTERNAL_ERROR;
×
1418
      }
1419

1420
      SMetaTableInfo mtInfo = {0};
×
1421
      code = pTaskInfo->storageAPI.snapshotFn.getMetaTableInfoFromSnapshot(sContext, &mtInfo);
×
1422
      if (code != 0) {
×
1423
        destroyMetaTableInfo(&mtInfo);
1424
        return code;
×
1425
      }
1426
      pTaskInfo->storageAPI.tsdReader.tsdReaderClose(pInfo->dataReader);
×
1427
      pInfo->dataReader = NULL;
×
1428

1429
      cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
×
1430
      tableListClear(pTableListInfo);
×
1431

1432
      if (mtInfo.uid == 0) {
×
1433
        destroyMetaTableInfo(&mtInfo);
1434
        goto end;  // no data
×
1435
      }
1436

1437
      pAPI->snapshotFn.taosXSetTablePrimaryKey(sContext, mtInfo.uid);
×
1438
      code = initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo);
×
1439
      if (code != TSDB_CODE_SUCCESS) {
×
1440
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1441
        destroyMetaTableInfo(&mtInfo);
1442
        return code;
×
1443
      }
1444
      if (pAPI->snapshotFn.taosXGetTablePrimaryKey(sContext)) {
×
1445
        pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts;
×
1446
      } else {
1447
        pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts + 1;
×
1448
      }
1449

1450
      code = tableListAddTableInfo(pTableListInfo, mtInfo.uid, 0);
×
1451
      if (code != TSDB_CODE_SUCCESS) {
×
1452
        destroyMetaTableInfo(&mtInfo);
1453
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1454
        return code;
×
1455
      }
1456

1457
      STableKeyInfo* pList = tableListGetInfo(pTableListInfo, 0);
×
1458
      if (!pList) {
×
1459
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1460
        destroyMetaTableInfo(&mtInfo);
1461
        return code;
×
1462
      }
1463
      int32_t size = 0;
×
1464
      code = tableListGetSize(pTableListInfo, &size);
×
1465
      if (code != TSDB_CODE_SUCCESS) {
×
1466
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1467
        destroyMetaTableInfo(&mtInfo);
1468
        return code;
×
1469
      }
1470

1471
      code = pTaskInfo->storageAPI.tsdReader.tsdReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size,
×
1472
                                                           NULL, (void**)&pInfo->dataReader, NULL, NULL);
×
1473
      if (code != TSDB_CODE_SUCCESS) {
×
1474
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1475
        destroyMetaTableInfo(&mtInfo);
1476
        return code;
×
1477
      }
1478

1479
      cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
×
1480
      tstrncpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName, TSDB_TABLE_NAME_LEN);
×
1481
      //      pTaskInfo->streamInfo.suid = mtInfo.suid == 0 ? mtInfo.uid : mtInfo.suid;
1482
      tDeleteSchemaWrapper(pTaskInfo->streamInfo.schema);
×
1483
      pTaskInfo->streamInfo.schema = mtInfo.schema;
×
1484
      taosMemoryFreeClear(mtInfo.pExtSchemas);
×
1485

1486
      qDebug("tmqsnap qStreamPrepareScan snapshot data uid:%" PRId64 " ts %" PRId64 " %s", mtInfo.uid, pOffset->ts, id);
×
1487
    } else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_META) {
×
1488
      SStreamRawScanInfo* pInfo = pOperator->info;
×
1489
      SSnapContext*       sContext = pInfo->sContext;
×
1490
      code = pTaskInfo->storageAPI.snapshotFn.setForSnapShot(sContext, pOffset->uid);
×
1491
      if (code != 0) {
×
1492
        qError("setForSnapShot error. uid:%" PRIu64 " ,version:%" PRId64, pOffset->uid, pOffset->version);
×
1493
        return code;
×
1494
      }
1495
      qDebug("tmqsnap qStreamPrepareScan snapshot meta uid:%" PRId64 " ts %" PRId64 " %s", pOffset->uid, pOffset->ts,
×
1496
             id);
1497
    } else if (pOffset->type == TMQ_OFFSET__LOG) {
×
1498
      SStreamRawScanInfo* pInfo = pOperator->info;
×
1499
      pTaskInfo->storageAPI.tsdReader.tsdReaderClose(pInfo->dataReader);
×
1500
      pInfo->dataReader = NULL;
×
1501
      qDebug("tmqsnap qStreamPrepareScan snapshot log, %s", id);
×
1502
    }
1503
  }
1504

1505
end:
30,478✔
1506
  tOffsetCopy(&pTaskInfo->streamInfo.currentOffset, pOffset);
30,478✔
1507
  return 0;
30,478✔
1508
}
1509

1510
void qProcessRspMsg(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
45,107,180✔
1511
  SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->info.ahandle;
45,107,180✔
1512
  if (pMsg->info.ahandle == NULL) {
45,111,215✔
1513
    rpcFreeCont(pMsg->pCont);
×
1514
    qError("pMsg->info.ahandle is NULL");
×
1515
    return;
×
1516
  }
1517

1518
  qDebug("rsp msg got, code:%x, len:%d, 0x%" PRIx64 ":0x%" PRIx64, 
45,104,428✔
1519
      pMsg->code, pMsg->contLen, TRACE_GET_ROOTID(&pMsg->info.traceId), TRACE_GET_MSGID(&pMsg->info.traceId));
1520

1521
  SDataBuf buf = {.len = pMsg->contLen, .pData = NULL};
45,107,840✔
1522

1523
  if (pMsg->contLen > 0) {
45,112,370✔
1524
    buf.pData = taosMemoryCalloc(1, pMsg->contLen);
45,105,845✔
1525
    if (buf.pData == NULL) {
45,106,069✔
1526
      pMsg->code = terrno;
×
1527
    } else {
1528
      memcpy(buf.pData, pMsg->pCont, pMsg->contLen);
45,106,069✔
1529
    }
1530
  }
1531

1532
  (void)pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
45,112,630✔
1533
  rpcFreeCont(pMsg->pCont);
45,113,304✔
1534
  destroySendMsgInfo(pSendInfo);
45,100,392✔
1535
}
1536

1537
SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo) {
×
1538
  int32_t        code = TSDB_CODE_SUCCESS;
×
1539
  int32_t        lino = 0;
×
1540
  SExecTaskInfo* pTaskInfo = tinfo;
×
1541
  SArray*        plist = NULL;
×
1542

1543
  code = getTableListInfo(pTaskInfo, &plist);
×
1544
  if (code || plist == NULL) {
×
1545
    return NULL;
×
1546
  }
1547

1548
  // only extract table in the first elements
1549
  STableListInfo* pTableListInfo = taosArrayGetP(plist, 0);
×
1550

1551
  SArray* pUidList = taosArrayInit(10, sizeof(uint64_t));
×
1552
  QUERY_CHECK_NULL(pUidList, code, lino, _end, terrno);
×
1553

1554
  int32_t numOfTables = 0;
×
1555
  code = tableListGetSize(pTableListInfo, &numOfTables);
×
1556
  QUERY_CHECK_CODE(code, lino, _end);
×
1557

1558
  for (int32_t i = 0; i < numOfTables; ++i) {
×
1559
    STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i);
×
1560
    QUERY_CHECK_NULL(pKeyInfo, code, lino, _end, terrno);
×
1561
    void* tmp = taosArrayPush(pUidList, &pKeyInfo->uid);
×
1562
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
1563
  }
1564

1565
  taosArrayDestroy(plist);
×
1566

1567
_end:
×
1568
  if (code != TSDB_CODE_SUCCESS) {
×
1569
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1570
    T_LONG_JMP(pTaskInfo->env, code);
×
1571
  }
1572
  return pUidList;
×
1573
}
1574

1575
static int32_t extractTableList(SArray* pList, const SOperatorInfo* pOperator) {
2,075,612✔
1576
  int32_t        code = TSDB_CODE_SUCCESS;
2,075,612✔
1577
  int32_t        lino = 0;
2,075,612✔
1578
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
2,075,612✔
1579

1580
  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
2,075,612✔
1581
    SStreamScanInfo* pScanInfo = pOperator->info;
×
1582
    STableScanInfo*  pTableScanInfo = pScanInfo->pTableScanOp->info;
×
1583

1584
    void* tmp = taosArrayPush(pList, &pTableScanInfo->base.pTableListInfo);
×
1585
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
1586
  } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
2,075,612✔
1587
    STableScanInfo* pScanInfo = pOperator->info;
1,037,615✔
1588

1589
    void* tmp = taosArrayPush(pList, &pScanInfo->base.pTableListInfo);
1,037,999✔
1590
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
1,037,999✔
1591
  } else {
1592
    if (pOperator->pDownstream != NULL && pOperator->pDownstream[0] != NULL) {
1,037,997✔
1593
      code = extractTableList(pList, pOperator->pDownstream[0]);
1,037,233✔
1594
    }
1595
  }
1596

1597
_end:
×
1598
  if (code != TSDB_CODE_SUCCESS) {
2,075,998✔
1599
    qError("%s %s failed at line %d since %s", pTaskInfo->id.str, __func__, lino, tstrerror(code));
×
1600
  }
1601
  return code;
2,075,230✔
1602
}
1603

1604
int32_t getTableListInfo(const SExecTaskInfo* pTaskInfo, SArray** pList) {
1,037,464✔
1605
  if (pList == NULL) {
1,037,464✔
1606
    return TSDB_CODE_INVALID_PARA;
×
1607
  }
1608

1609
  *pList = NULL;
1,037,464✔
1610
  SArray* pArray = taosArrayInit(0, POINTER_BYTES);
1,037,997✔
1611
  if (pArray == NULL) {
1,038,381✔
1612
    return terrno;
×
1613
  }
1614

1615
  int32_t code = extractTableList(pArray, pTaskInfo->pRoot);
1,038,381✔
1616
  if (code == 0) {
1,037,615✔
1617
    *pList = pArray;
1,037,615✔
1618
  } else {
1619
    taosArrayDestroy(pArray);
×
1620
  }
1621
  return code;
1,037,999✔
1622
}
1623

1624
int32_t qStreamOperatorReleaseState(qTaskInfo_t tInfo) {
×
1625
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tInfo;
×
1626
  if (pTaskInfo->pRoot->fpSet.releaseStreamStateFn != NULL) {
×
1627
    pTaskInfo->pRoot->fpSet.releaseStreamStateFn(pTaskInfo->pRoot);
×
1628
  }
1629
  return 0;
×
1630
}
1631

1632
int32_t qStreamOperatorReloadState(qTaskInfo_t tInfo) {
×
1633
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tInfo;
×
1634
  if (pTaskInfo->pRoot->fpSet.reloadStreamStateFn != NULL) {
×
1635
    pTaskInfo->pRoot->fpSet.reloadStreamStateFn(pTaskInfo->pRoot);
×
1636
  }
1637
  return 0;
×
1638
}
1639

1640
void qResetTaskCode(qTaskInfo_t tinfo) {
×
1641
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
1642

1643
  int32_t code = pTaskInfo->code;
×
1644
  pTaskInfo->code = 0;
×
1645
  qDebug("0x%" PRIx64 " reset task code to be success, prev:%s", pTaskInfo->id.taskId, tstrerror(code));
×
1646
}
×
1647

1648
int32_t collectExprsToReplaceForStream(SOperatorInfo* pOper, SArray* pExprs) {
×
1649
  int32_t code = 0;
×
1650
  return code;
×
1651
}
1652

1653
int32_t streamCollectExprsForReplace(qTaskInfo_t tInfo, SArray* pExprs) {
×
1654
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tInfo;
×
1655
  int32_t        code = collectExprsToReplaceForStream(pTaskInfo->pRoot, pExprs);
×
1656
  return code;
×
1657
}
1658

1659
int32_t clearStatesForOperator(SOperatorInfo* pOper) {
163,620✔
1660
  int32_t code = 0;
163,620✔
1661

1662
  freeResetOperatorParams(pOper, OP_GET_PARAM, true);
163,620✔
1663
  freeResetOperatorParams(pOper, OP_NOTIFY_PARAM, true);
163,620✔
1664

1665
  if (pOper->fpSet.resetStateFn) {
163,620✔
1666
    code = pOper->fpSet.resetStateFn(pOper);
163,620✔
1667
  }
1668
  pOper->status = OP_NOT_OPENED;
163,620✔
1669
  for (int32_t i = 0; i < pOper->numOfDownstream && code == 0; ++i) {
272,700✔
1670
    code = clearStatesForOperator(pOper->pDownstream[i]);
109,080✔
1671
  }
1672
  return code;
163,620✔
1673
}
1674

1675
int32_t streamClearStatesForOperators(qTaskInfo_t tInfo) {
54,540✔
1676
  int32_t        code = 0;
54,540✔
1677
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tInfo;
54,540✔
1678
  SOperatorInfo* pOper = pTaskInfo->pRoot;
54,540✔
1679
  pTaskInfo->code = TSDB_CODE_SUCCESS;
54,540✔
1680
  code = clearStatesForOperator(pOper);
54,540✔
1681
  return code;
54,540✔
1682
}
1683

1684
int32_t streamExecuteTask(qTaskInfo_t tInfo, SSDataBlock** ppRes, uint64_t* useconds, bool* finished) {
67,680✔
1685
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tInfo;
67,680✔
1686
  int64_t        threadId = taosGetSelfPthreadId();
67,680✔
1687
  int64_t        curOwner = 0;
67,680✔
1688

1689
  *ppRes = NULL;
67,680✔
1690

1691
  // todo extract method
1692
  taosRLockLatch(&pTaskInfo->lock);
67,680✔
1693
  bool isKilled = isTaskKilled(pTaskInfo);
67,680✔
1694
  if (isKilled) {
67,680✔
1695
    // clearStreamBlock(pTaskInfo->pRoot);
1696
    qDebug("%s already killed, abort", GET_TASKID(pTaskInfo));
×
1697

1698
    taosRUnLockLatch(&pTaskInfo->lock);
×
1699
    return pTaskInfo->code;
×
1700
  }
1701

1702
  if (pTaskInfo->owner != 0) {
67,680✔
1703
    qError("%s-%p execTask is now executed by thread:%p", GET_TASKID(pTaskInfo), pTaskInfo, (void*)curOwner);
×
1704
    pTaskInfo->code = TSDB_CODE_QRY_IN_EXEC;
×
1705

1706
    taosRUnLockLatch(&pTaskInfo->lock);
×
1707
    return pTaskInfo->code;
×
1708
  }
1709

1710
  pTaskInfo->owner = threadId;
67,680✔
1711
  taosRUnLockLatch(&pTaskInfo->lock);
67,680✔
1712

1713
  if (pTaskInfo->cost.start == 0) {
67,680✔
1714
    pTaskInfo->cost.start = taosGetTimestampUs();
7,715✔
1715
  }
1716

1717
  // error occurs, record the error code and return to client
1718
  int32_t ret = setjmp(pTaskInfo->env);
67,680✔
1719
  if (ret != TSDB_CODE_SUCCESS) {
68,170✔
1720
    pTaskInfo->code = ret;
490✔
1721
    (void)cleanUpUdfs();
490✔
1722
    qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
490✔
1723
    atomic_store_64(&pTaskInfo->owner, 0);
490✔
1724
    return pTaskInfo->code;
490✔
1725
  }
1726

1727
  qDebug("%s execTask is launched", GET_TASKID(pTaskInfo));
67,680✔
1728

1729
  int64_t st = taosGetTimestampUs();
67,680✔
1730

1731
  int32_t code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, ppRes);
67,680✔
1732
  if (code) {
67,190✔
1733
    pTaskInfo->code = code;
×
1734
    qError("%s failed at line %d, code:%s %s", __func__, __LINE__, tstrerror(code), GET_TASKID(pTaskInfo));
×
1735
  } else {
1736
    *finished = *ppRes == NULL;
67,190✔
1737
    code = blockDataCheck(*ppRes);
67,190✔
1738
  }
1739
  if (code) {
67,190✔
1740
    pTaskInfo->code = code;
×
1741
    qError("%s failed at line %d, code:%s %s", __func__, __LINE__, tstrerror(code), GET_TASKID(pTaskInfo));
×
1742
  }
1743

1744
  uint64_t el = (taosGetTimestampUs() - st);
67,190✔
1745

1746
  pTaskInfo->cost.elapsedTime += el;
67,190✔
1747
  if (NULL == *ppRes) {
67,190✔
1748
    *useconds = pTaskInfo->cost.elapsedTime;
45,600✔
1749
  }
1750

1751
  (void)cleanUpUdfs();
67,190✔
1752

1753
  int32_t  current = (*ppRes != NULL) ? (*ppRes)->info.rows : 0;
67,190✔
1754
  uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
67,190✔
1755

1756
  qDebug("%s task suspended, %d rows returned, total:%" PRId64 " rows, in sinkNode:%d, elapsed:%.2f ms",
67,190✔
1757
         GET_TASKID(pTaskInfo), current, total, 0, el / 1000.0);
1758

1759
  atomic_store_64(&pTaskInfo->owner, 0);
67,190✔
1760
  return pTaskInfo->code;
67,190✔
1761
}
1762

1763
// void streamSetTaskRuntimeInfo(qTaskInfo_t tinfo, SStreamRuntimeInfo* pStreamRuntimeInfo) {
1764
//   SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
1765
//   pTaskInfo->pStreamRuntimeInfo = pStreamRuntimeInfo;
1766
// }
1767

1768
int32_t qStreamCreateTableListForReader(void* pVnode, uint64_t suid, uint64_t uid, int8_t tableType,
9,395✔
1769
                                        SNodeList* pGroupTags, bool groupSort, SNode* pTagCond, SNode* pTagIndexCond,
1770
                                        SStorageAPI* storageAPI, void** pTableListInfo, SHashObj* groupIdMap) {
1771
  int32_t code = 0;                                        
9,395✔
1772
  if (*pTableListInfo != NULL) {
9,395✔
1773
    qDebug("table list already exists, no need to create again");
×
1774
    goto end;
×
1775
  }
1776
  STableListInfo* pList = tableListCreate();
9,395✔
1777
  if (pList == NULL) {
9,395✔
1778
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
1779
    code = terrno;
×
1780
    goto end;
×
1781
  }
1782

1783
  SScanPhysiNode pScanNode = {.suid = suid, .uid = uid, .tableType = tableType};
9,395✔
1784
  SReadHandle    pHandle = {.vnode = pVnode};
9,395✔
1785
  SExecTaskInfo  pTaskInfo = {.id.str = "", .storageAPI = *storageAPI};
9,395✔
1786

1787
  code = createScanTableListInfo(&pScanNode, pGroupTags, groupSort, &pHandle, pList, pTagCond, pTagIndexCond, &pTaskInfo, groupIdMap);
9,395✔
1788
  if (code != 0) {
9,395✔
1789
    tableListDestroy(pList);
×
1790
    qError("failed to createScanTableListInfo, code:%s", tstrerror(code));
×
1791
    goto end;
×
1792
  }
1793
  *pTableListInfo = pList;
9,395✔
1794

1795
end:
9,395✔
1796
  return 0;
9,395✔
1797
}
1798

1799
static int32_t doFilterTableByTagCond(void* pVnode, void* pListInfo, SArray* pUidList, SNode* pTagCond, SStorageAPI* pStorageAPI){
×
1800
  bool   listAdded = false;
×
1801
  int32_t code = doFilterByTagCond(pListInfo, pUidList, pTagCond, pVnode, SFLT_NOT_INDEX, pStorageAPI, true, &listAdded, NULL);
×
1802
  if (code == 0 && !listAdded) {
×
1803
    int32_t numOfTables = taosArrayGetSize(pUidList);
×
1804
    for (int i = 0; i < numOfTables; i++) {
×
1805
      void* tmp = taosArrayGet(pUidList, i);
×
1806
      if (tmp == NULL) {
×
1807
        return terrno;
×
1808
      }
1809
      STableKeyInfo info = {.uid = *(uint64_t*)tmp, .groupId = 0};
×
1810

1811
      void* p = taosArrayPush(((STableListInfo*)pListInfo)->pTableList, &info);
×
1812
      if (p == NULL) {
×
1813
        return terrno;
×
1814
      }
1815
    }
1816
  }
1817
  return code;
×
1818
}
1819

1820
int32_t qStreamFilterTableListForReader(void* pVnode, SArray* uidList,
×
1821
                                        SNodeList* pGroupTags, SNode* pTagCond, SNode* pTagIndexCond,
1822
                                        SStorageAPI* storageAPI, SHashObj* groupIdMap, uint64_t suid, SArray** tableList) {
1823
  int32_t code = TSDB_CODE_SUCCESS;
×
1824
  STableListInfo* pList = tableListCreate();
×
1825
  if (pList == NULL) {
×
1826
    code = terrno;
×
1827
    goto end;
×
1828
  }
1829
  SArray* uidListCopy = taosArrayDup(uidList, NULL);
×
1830
  if (uidListCopy == NULL) {
×
1831
    code = terrno;
×
1832
    goto end;
×
1833
  }
1834
  SScanPhysiNode pScanNode = {.suid = suid, .tableType = TD_SUPER_TABLE};
×
1835
  SReadHandle    pHandle = {.vnode = pVnode};
×
1836

1837
  pList->idInfo.suid = suid;
×
1838
  pList->idInfo.tableType = TD_SUPER_TABLE;
×
1839
  code = doFilterTableByTagCond(pVnode, pList, uidList, pTagCond, storageAPI);
×
1840
  if (code != TSDB_CODE_SUCCESS) {
×
1841
    goto end;
×
1842
  }                                              
1843
  code = buildGroupIdMapForAllTables(pList, &pHandle, &pScanNode, pGroupTags, false, NULL, storageAPI, groupIdMap);
×
1844
  if (code != TSDB_CODE_SUCCESS) {
×
1845
    goto end;
×
1846
  }
1847
  *tableList = pList->pTableList;
×
1848
  pList->pTableList = NULL;
×
1849

1850
  taosArrayClear(uidList);
×
1851
  for (int32_t i = 0; i < taosArrayGetSize(uidListCopy); i++){
×
1852
    void* tmp = taosArrayGet(uidListCopy, i);
×
1853
    if (tmp == NULL) {
×
1854
      continue;
×
1855
    }
1856
    int32_t* slot = taosHashGet(pList->map, tmp, LONG_BYTES);
×
1857
    if (slot == NULL) {
×
1858
      if (taosArrayPush(uidList, tmp) == NULL) {
×
1859
        code = terrno;
×
1860
        goto end;
×
1861
      }
1862
    }
1863
  }
1864
end:
×
1865
  taosArrayDestroy(uidListCopy);
×
1866
  tableListDestroy(pList);
×
1867
  return code;
×
1868
}
1869

1870
// int32_t qStreamGetGroupIndex(void* pTableListInfo, int64_t gid, TdThreadRwlock* lock) {
1871
//   int32_t index = -1;
1872
//   (void)taosThreadRwlockRdlock(lock);
1873
//   if (((STableListInfo*)pTableListInfo)->groupOffset == NULL){
1874
//     index = 0;
1875
//     goto end;
1876
//   }
1877
//   for (int32_t i = 0; i < ((STableListInfo*)pTableListInfo)->numOfOuputGroups; ++i) {
1878
//     int32_t offset = ((STableListInfo*)pTableListInfo)->groupOffset[i];
1879

1880
//     STableKeyInfo* pKeyInfo = taosArrayGet(((STableListInfo*)pTableListInfo)->pTableList, offset);
1881
//     if (pKeyInfo != NULL && pKeyInfo->groupId == gid) {
1882
//       index = i;
1883
//       goto end;
1884
//     }
1885
//   }
1886
// end:
1887
//   (void)taosThreadRwlockUnlock(lock);
1888
//   return index;
1889
// }
1890

1891
void qStreamDestroyTableList(void* pTableListInfo) { tableListDestroy(pTableListInfo); }
9,395✔
1892
SArray*  qStreamGetTableListArray(void* pTableListInfo) {
9,395✔
1893
  STableListInfo* pList = pTableListInfo;
9,395✔
1894
  return pList->pTableList;
9,395✔
1895
}
1896

1897
int32_t qStreamFilter(SSDataBlock* pBlock, void* pFilterInfo, SColumnInfoData** pRet) { return doFilter(pBlock, pFilterInfo, NULL, pRet); }
6,755✔
1898

1899
void streamDestroyExecTask(qTaskInfo_t tInfo) {
83,325✔
1900
  qDebug("streamDestroyExecTask called, task:%p", tInfo);
83,325✔
1901
  qDestroyTask(tInfo);
83,325✔
1902
}
83,325✔
1903

1904
int32_t streamCalcOneScalarExpr(SNode* pExpr, SScalarParam* pDst, const SStreamRuntimeFuncInfo* pExtraParams) {
17,790✔
1905
  return streamCalcOneScalarExprInRange(pExpr, pDst, -1, -1, pExtraParams);
17,790✔
1906
}
1907

1908
int32_t streamCalcOneScalarExprInRange(SNode* pExpr, SScalarParam* pDst, int32_t rowStartIdx, int32_t rowEndIdx,
17,790✔
1909
                                       const SStreamRuntimeFuncInfo* pExtraParams) {
1910
  int32_t      code = 0;
17,790✔
1911
  SNode*       pNode = 0;
17,790✔
1912
  SNodeList*   pList = NULL;
17,790✔
1913
  SExprInfo*   pExprInfo = NULL;
17,790✔
1914
  int32_t      numOfExprs = 1;
17,790✔
1915
  int32_t*     offset = 0;
17,790✔
1916
  STargetNode* pTargetNode = NULL;
17,790✔
1917
  code = nodesMakeNode(QUERY_NODE_TARGET, (SNode**)&pTargetNode);
17,790✔
1918
  if (code == 0) code = nodesCloneNode(pExpr, &pNode);
17,790✔
1919

1920
  if (code == 0) {
17,790✔
1921
    pTargetNode->dataBlockId = 0;
17,790✔
1922
    pTargetNode->pExpr = pNode;
17,790✔
1923
    pTargetNode->slotId = 0;
17,790✔
1924
  }
1925
  if (code == 0) {
17,790✔
1926
    code = nodesMakeList(&pList);
17,790✔
1927
  }
1928
  if (code == 0) {
17,790✔
1929
    code = nodesListAppend(pList, (SNode*)pTargetNode);
17,790✔
1930
  }
1931
  if (code == 0) {
17,790✔
1932
    pNode = NULL;
17,790✔
1933
    code = createExprInfo(pList, NULL, &pExprInfo, &numOfExprs);
17,790✔
1934
  }
1935

1936
  if (code == 0) {
17,790✔
1937
    const char* pVal = NULL;
17,790✔
1938
    int32_t     len = 0;
17,790✔
1939
    SNode*      pSclNode = NULL;
17,790✔
1940
    switch (pExprInfo->pExpr->nodeType) {
17,790✔
1941
      case QUERY_NODE_FUNCTION:
17,790✔
1942
        pSclNode = (SNode*)pExprInfo->pExpr->_function.pFunctNode;
17,790✔
1943
        break;
17,790✔
1944
      case QUERY_NODE_OPERATOR:
×
1945
        pSclNode = pExprInfo->pExpr->_optrRoot.pRootNode;
×
1946
        break;
×
1947
      default:
×
1948
        code = TSDB_CODE_OPS_NOT_SUPPORT;
×
1949
        break;
×
1950
    }
1951
    SArray*     pBlockList = taosArrayInit(2, POINTER_BYTES);
17,790✔
1952
    SSDataBlock block = {0};
17,790✔
1953
    block.info.rows = 1;
17,790✔
1954
    SSDataBlock* pBlock = &block;
17,790✔
1955
    void*        tmp = taosArrayPush(pBlockList, &pBlock);
17,790✔
1956
    if (tmp == NULL) {
17,790✔
1957
      code = terrno;
×
1958
    }
1959
    if (code == 0) {
17,790✔
1960
      code = scalarCalculateInRange(pSclNode, pBlockList, pDst, rowStartIdx, rowEndIdx, pExtraParams, NULL);
17,790✔
1961
    }
1962
    taosArrayDestroy(pBlockList);
17,790✔
1963
  }
1964
  nodesDestroyList(pList);
17,790✔
1965
  destroyExprInfo(pExprInfo, numOfExprs);
17,790✔
1966
  taosMemoryFreeClear(pExprInfo);
17,790✔
1967
  return code;
17,790✔
1968
}
1969

1970
int32_t streamForceOutput(qTaskInfo_t tInfo, SSDataBlock** pRes, int32_t winIdx) {
24,010✔
1971
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tInfo;
24,010✔
1972
  const SArray*  pForceOutputCols = pTaskInfo->pStreamRuntimeInfo->pForceOutputCols;
24,010✔
1973
  int32_t        code = 0;
24,010✔
1974
  SNode*         pNode = NULL;
24,010✔
1975
  if (!pForceOutputCols) return 0;
24,010✔
1976
  if (!*pRes) {
×
1977
    code = createDataBlock(pRes);
×
1978
  }
1979

1980
  if (code == 0 && (!(*pRes)->pDataBlock || (*pRes)->pDataBlock->size == 0)) {
×
1981
    int32_t idx = 0;
×
1982
    for (int32_t i = 0; i < pForceOutputCols->size; ++i) {
×
1983
      SStreamOutCol*  pCol = (SStreamOutCol*)taosArrayGet(pForceOutputCols, i);
×
1984
      SColumnInfoData colInfo = createColumnInfoData(pCol->type.type, pCol->type.bytes, idx++);
×
1985
      colInfo.info.precision = pCol->type.precision;
×
1986
      colInfo.info.scale = pCol->type.scale;
×
1987
      code = blockDataAppendColInfo(*pRes, &colInfo);
×
1988
      if (code != 0) break;
×
1989
    }
1990
  }
1991

1992
  code = blockDataEnsureCapacity(*pRes, (*pRes)->info.rows + 1);
×
1993
  if (code != TSDB_CODE_SUCCESS) {
×
1994
    qError("failed to ensure capacity for force output, code:%s", tstrerror(code));
×
1995
    return code;
×
1996
  }
1997

1998
  // loop all exprs for force output, execute all exprs
1999
  int32_t idx = 0;
×
2000
  int32_t rowIdx = (*pRes)->info.rows;
×
2001
  int32_t tmpWinIdx = pTaskInfo->pStreamRuntimeInfo->funcInfo.curIdx;
×
2002
  pTaskInfo->pStreamRuntimeInfo->funcInfo.curIdx = winIdx;
×
2003
  for (int32_t i = 0; i < pForceOutputCols->size; ++i) {
×
2004
    SScalarParam   dst = {0};
×
2005
    SStreamOutCol* pCol = (SStreamOutCol*)taosArrayGet(pForceOutputCols, i);
×
2006
    code = nodesStringToNode(pCol->expr, &pNode);
×
2007
    if (code != 0) break;
×
2008
    SColumnInfoData* pInfo = taosArrayGet((*pRes)->pDataBlock, idx);
×
2009
    if (nodeType(pNode) == QUERY_NODE_VALUE) {
×
2010
      void* p = nodesGetValueFromNode((SValueNode*)pNode);
×
2011
      code = colDataSetVal(pInfo, rowIdx, p, ((SValueNode*)pNode)->isNull);
×
2012
    } else {
2013
      dst.columnData = pInfo;
×
2014
      dst.numOfRows = rowIdx;
×
2015
      dst.colAlloced = false;
×
2016
      code = streamCalcOneScalarExprInRange(pNode, &dst, rowIdx, rowIdx, &pTaskInfo->pStreamRuntimeInfo->funcInfo);
×
2017
    }
2018
    ++idx;
×
2019
    // TODO sclFreeParam(&dst);
2020
    nodesDestroyNode(pNode);
×
2021
    if (code != 0) break;
×
2022
  }
2023
  if (code == TSDB_CODE_SUCCESS) {
×
2024
    (*pRes)->info.rows++;
×
2025
  }
2026
  pTaskInfo->pStreamRuntimeInfo->funcInfo.curIdx = tmpWinIdx;
×
2027
  return code;
×
2028
}
2029

2030
int32_t streamCalcOutputTbName(SNode* pExpr, char* tbname, SStreamRuntimeFuncInfo* pStreamRuntimeInfo) {
8,895✔
2031
  int32_t      code = 0;
8,895✔
2032
  const char*  pVal = NULL;
8,895✔
2033
  SScalarParam dst = {0};
8,895✔
2034
  int32_t      len = 0;
8,895✔
2035
  int32_t      nextIdx = pStreamRuntimeInfo->curIdx;
8,895✔
2036
  pStreamRuntimeInfo->curIdx = 0;  // always use the first window to calc tbname
8,895✔
2037
  // execute the expr
2038
  switch (pExpr->type) {
8,895✔
2039
    case QUERY_NODE_VALUE: {
×
2040
      SValueNode* pValue = (SValueNode*)pExpr;
×
2041
      int32_t     type = pValue->node.resType.type;
×
2042
      if (!IS_STR_DATA_TYPE(type)) {
×
2043
        qError("invalid sub tb expr with non-str type");
×
2044
        code = TSDB_CODE_INVALID_PARA;
×
2045
        break;
×
2046
      }
2047
      void* pTmp = nodesGetValueFromNode((SValueNode*)pExpr);
×
2048
      if (pTmp == NULL) {
×
2049
        qError("invalid sub tb expr with null value");
×
2050
        code = TSDB_CODE_INVALID_PARA;
×
2051
        break;
×
2052
      }
2053
      pVal = varDataVal(pTmp);
×
2054
      len = varDataLen(pTmp);
×
2055
    } break;
×
2056
    case QUERY_NODE_FUNCTION: {
8,895✔
2057
      SFunctionNode* pFunc = (SFunctionNode*)pExpr;
8,895✔
2058
      if (!IS_STR_DATA_TYPE(pFunc->node.resType.type)) {
8,895✔
2059
        qError("invalid sub tb expr with non-str type func");
×
2060
        code = TSDB_CODE_INVALID_PARA;
×
2061
        break;
×
2062
      }
2063
      SColumnInfoData* pCol = taosMemoryCalloc(1, sizeof(SColumnInfoData));
8,895✔
2064
      if (!pCol) {
8,895✔
2065
        code = terrno;
×
2066
        qError("failed to allocate col info data at: %s, %d", __func__, __LINE__);
×
2067
        break;
×
2068
      }
2069

2070
      pCol->hasNull = true;
8,895✔
2071
      pCol->info.type = ((SExprNode*)pExpr)->resType.type;
8,895✔
2072
      pCol->info.colId = 0;
8,895✔
2073
      pCol->info.bytes = ((SExprNode*)pExpr)->resType.bytes;
8,895✔
2074
      pCol->info.precision = ((SExprNode*)pExpr)->resType.precision;
8,895✔
2075
      pCol->info.scale = ((SExprNode*)pExpr)->resType.scale;
8,895✔
2076
      code = colInfoDataEnsureCapacity(pCol, 1, true);
8,895✔
2077
      if (code != 0) {
8,895✔
2078
        qError("failed to ensure capacity for col info data at: %s, %d", __func__, __LINE__);
×
2079
        taosMemoryFree(pCol);
×
2080
        break;
×
2081
      }
2082
      dst.columnData = pCol;
8,895✔
2083
      dst.numOfRows = 1;
8,895✔
2084
      dst.colAlloced = true;
8,895✔
2085
      code = streamCalcOneScalarExpr(pExpr, &dst, pStreamRuntimeInfo);
8,895✔
2086
      if (colDataIsNull_var(dst.columnData, 0)) {
8,895✔
2087
        qInfo("invalid sub tb expr with null value");
×
2088
        code = TSDB_CODE_MND_STREAM_TBNAME_CALC_FAILED;
×
2089
      }
2090
      if (code == 0) {
8,895✔
2091
        pVal = varDataVal(colDataGetVarData(dst.columnData, 0));
8,895✔
2092
        len = varDataLen(colDataGetVarData(dst.columnData, 0));
8,895✔
2093
      }
2094
    } break;
8,895✔
2095
    default:
×
2096
      qError("wrong subtable expr with type: %d", pExpr->type);
×
2097
      code = TSDB_CODE_OPS_NOT_SUPPORT;
×
2098
      break;
×
2099
  }
2100
  if (code == 0) {
8,895✔
2101
    if (!pVal || len == 0) {
8,895✔
2102
      qError("tbname generated with no characters which is not allowed");
×
2103
      code = TSDB_CODE_INVALID_PARA;
×
2104
    }
2105
    if(len > TSDB_TABLE_NAME_LEN - 1) {
8,895✔
2106
      qError("tbname generated with too long characters, max allowed is %d, got %d, truncated.", TSDB_TABLE_NAME_LEN - 1, len);
×
2107
      len = TSDB_TABLE_NAME_LEN - 1;
×
2108
    }
2109

2110
    memcpy(tbname, pVal, len);
8,895✔
2111
    tbname[len] = '\0';  // ensure null terminated
8,895✔
2112
    if (NULL != strchr(tbname, '.')) {
8,895✔
2113
      code = TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME;
×
2114
      qError("tbname generated with invalid characters, '.' is not allowed");
×
2115
    }
2116
  }
2117
  // TODO free dst
2118
  sclFreeParam(&dst);
8,895✔
2119
  pStreamRuntimeInfo->curIdx = nextIdx; // restore
8,895✔
2120
  return code;
8,895✔
2121
}
2122

2123
void destroyStreamInserterParam(SStreamInserterParam* pParam) {
7,715✔
2124
  if (pParam) {
7,715✔
2125
    if (pParam->tbname) {
7,715✔
2126
      taosMemFree(pParam->tbname);
7,715✔
2127
      pParam->tbname = NULL;
7,715✔
2128
    }
2129
    if (pParam->stbname) {
7,715✔
2130
      taosMemFree(pParam->stbname);
7,715✔
2131
      pParam->stbname = NULL;
7,715✔
2132
    }
2133
    if (pParam->dbFName) {
7,715✔
2134
      taosMemFree(pParam->dbFName);
7,715✔
2135
      pParam->dbFName = NULL;
7,715✔
2136
    }
2137
    if (pParam->pFields) {
7,715✔
2138
      taosArrayDestroy(pParam->pFields);
7,715✔
2139
      pParam->pFields = NULL;
7,715✔
2140
    }
2141
    if (pParam->pTagFields) {
7,715✔
2142
      taosArrayDestroy(pParam->pTagFields);
6,000✔
2143
      pParam->pTagFields = NULL;
6,000✔
2144
    }
2145
    taosMemFree(pParam);
7,715✔
2146
  }
2147
}
7,715✔
2148

2149
int32_t cloneStreamInserterParam(SStreamInserterParam** ppDst, SStreamInserterParam* pSrc) {
7,715✔
2150
  int32_t code = 0, lino = 0;
7,715✔
2151
  if (ppDst == NULL || pSrc == NULL) {
7,715✔
2152
    TAOS_CHECK_EXIT(TSDB_CODE_INVALID_PARA);
×
2153
  }
2154
  *ppDst = (SStreamInserterParam*)taosMemoryCalloc(1, sizeof(SStreamInserterParam));
7,715✔
2155
  TSDB_CHECK_NULL(*ppDst, code, lino, _exit, terrno);
7,715✔
2156

2157
  (*ppDst)->suid = pSrc->suid;
7,715✔
2158
  (*ppDst)->sver = pSrc->sver;
7,715✔
2159
  (*ppDst)->tbType = pSrc->tbType;
7,715✔
2160
  (*ppDst)->tbname = taosStrdup(pSrc->tbname);
7,715✔
2161
  TSDB_CHECK_NULL((*ppDst)->tbname, code, lino, _exit, terrno);
7,715✔
2162

2163
  if (pSrc->stbname) {
7,715✔
2164
    (*ppDst)->stbname = taosStrdup(pSrc->stbname);
7,715✔
2165
    TSDB_CHECK_NULL((*ppDst)->stbname, code, lino, _exit, terrno);
7,715✔
2166
  }
2167

2168
  (*ppDst)->dbFName = taosStrdup(pSrc->dbFName);
7,715✔
2169
  TSDB_CHECK_NULL((*ppDst)->dbFName, code, lino, _exit, terrno);
7,715✔
2170

2171
  (*ppDst)->pSinkHandle = pSrc->pSinkHandle;  // don't need clone and free
7,715✔
2172

2173
  if (pSrc->pFields && pSrc->pFields->size > 0) {
7,715✔
2174
    (*ppDst)->pFields = taosArrayDup(pSrc->pFields, NULL);
7,715✔
2175
    TSDB_CHECK_NULL((*ppDst)->pFields, code, lino, _exit, terrno);
7,715✔
2176
  } else {
2177
    (*ppDst)->pFields = NULL;
×
2178
  }
2179
  
2180
  if (pSrc->pTagFields && pSrc->pTagFields->size > 0) {
7,715✔
2181
    (*ppDst)->pTagFields = taosArrayDup(pSrc->pTagFields, NULL);
6,000✔
2182
    TSDB_CHECK_NULL((*ppDst)->pTagFields, code, lino, _exit, terrno);
6,000✔
2183
  } else {
2184
    (*ppDst)->pTagFields = NULL;
1,715✔
2185
  }
2186

2187
_exit:
7,715✔
2188

2189
  if (code != 0) {
7,715✔
2190
    if (*ppDst) {
×
2191
      destroyStreamInserterParam(*ppDst);
×
2192
      *ppDst = NULL;
×
2193
    }
2194
    
2195
    stError("%s failed at line %d, error:%s", __FUNCTION__, lino, tstrerror(code));
×
2196
  }
2197
  return code;
7,715✔
2198
}
2199

2200
int32_t dropStreamTable(SMsgCb* pMsgCb, void* pOutput, SSTriggerDropRequest* pReq) {
×
2201
  return doDropStreamTable(pMsgCb, pOutput, pReq);
×
2202
}
2203

2204
int32_t dropStreamTableByTbName(SMsgCb* pMsgCb, void* pOutput, SSTriggerDropRequest* pReq, char* tbName) {
×
2205
  return doDropStreamTableByTbName(pMsgCb, pOutput, pReq, tbName);
×
2206
}
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