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

taosdata / TDengine / #3847

11 Apr 2025 06:14AM UTC coverage: 62.612% (+0.2%) from 62.398%
#3847

push

travis-ci

web-flow
Merge pull request #30758 from taosdata/merge/mainto3.0

merge: from main to 3.0 branch

154571 of 315259 branches covered (49.03%)

Branch coverage included in aggregate %.

63 of 80 new or added lines in 9 files covered. (78.75%)

946 existing lines in 106 files now uncovered.

240135 of 315138 relevant lines covered (76.2%)

19768383.08 hits per line

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

64.17
/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 "executorInt.h"
18
#include "operator.h"
19
#include "planner.h"
20
#include "querytask.h"
21
#include "tdatablock.h"
22
#include "tref.h"
23
#include "trpc.h"
24
#include "tudf.h"
25
#include "wal.h"
26

27
#include "storageapi.h"
28

29
static TdThreadOnce initPoolOnce = PTHREAD_ONCE_INIT;
30
int32_t             exchangeObjRefPool = -1;
31

32
static void cleanupRefPool() {
2,269✔
33
  int32_t ref = atomic_val_compare_exchange_32(&exchangeObjRefPool, exchangeObjRefPool, 0);
2,269✔
34
  taosCloseRef(ref);
2,269✔
35
}
2,269✔
36

37
static void initRefPool() {
2,269✔
38
  exchangeObjRefPool = taosOpenRef(1024, doDestroyExchangeOperatorInfo);
2,269✔
39
  (void)atexit(cleanupRefPool);
2,269✔
40
}
2,269✔
41

42
static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) {
1,392✔
43
  int32_t code = TSDB_CODE_SUCCESS;
1,392✔
44
  int32_t lino = 0;
1,392✔
45
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
1,392✔
46
    if (pOperator->numOfDownstream == 0) {
696!
47
      qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
×
48
      return TSDB_CODE_APP_ERROR;
×
49
    }
50

51
    if (pOperator->numOfDownstream > 1) {  // not handle this in join query
696!
52
      qError("join not supported for stream block scan, %s" PRIx64, id);
×
53
      return TSDB_CODE_APP_ERROR;
×
54
    }
55
    pOperator->status = OP_NOT_OPENED;
696✔
56
    return doSetSMABlock(pOperator->pDownstream[0], input, numOfBlocks, type, id);
696✔
57
  } else {
58
    pOperator->status = OP_NOT_OPENED;
696✔
59

60
    SStreamScanInfo* pInfo = pOperator->info;
696✔
61

62
    if (type == STREAM_INPUT__MERGED_SUBMIT) {
696✔
63
      for (int32_t i = 0; i < numOfBlocks; i++) {
1,248✔
64
        SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
624✔
65
        void*        tmp = taosArrayPush(pInfo->pBlockLists, pReq);
624✔
66
        QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
624!
67
      }
68
      pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
624✔
69
    } else if (type == STREAM_INPUT__DATA_SUBMIT) {
72!
70
      void* tmp = taosArrayPush(pInfo->pBlockLists, &input);
×
71
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
72
      pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
×
73
    } else if (type == STREAM_INPUT__DATA_BLOCK) {
72✔
74
      for (int32_t i = 0; i < numOfBlocks; ++i) {
56✔
75
        SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
28✔
76
        SPackedData  tmp = {.pDataBlock = pDataBlock};
28✔
77
        void*        tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
28✔
78
        QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
28!
79
      }
80
      pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
28✔
81
    } else if (type == STREAM_INPUT__CHECKPOINT) {
44✔
82
      SPackedData tmp = {.pDataBlock = input};
28✔
83
      void*       tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
28✔
84
      QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
28!
85
      pInfo->blockType = STREAM_INPUT__CHECKPOINT;
28✔
86
    } else if (type == STREAM_INPUT__REF_DATA_BLOCK) {
16!
87
      for (int32_t i = 0; i < numOfBlocks; ++i) {
32✔
88
        SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
16✔
89
        void*        tmp = taosArrayPush(pInfo->pBlockLists, pReq);
16✔
90
        QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
16!
91
      }
92
      pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
16✔
93
    }
94

95
    return TSDB_CODE_SUCCESS;
696✔
96
  }
97

98
_end:
×
99
  if (code != TSDB_CODE_SUCCESS) {
×
100
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
101
  }
102
  return code;
×
103
}
104

105
static int32_t doSetStreamOpOpen(SOperatorInfo* pOperator, char* id) {
5,595✔
106
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
5,595✔
107
    if (pOperator->numOfDownstream == 0) {
3,245!
108
      qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
×
109
      return TSDB_CODE_APP_ERROR;
×
110
    }
111

112
    if (pOperator->numOfDownstream > 1) {  // not handle this in join query
3,245!
113
      qError("join not supported for stream block scan, %s" PRIx64, id);
×
114
      return TSDB_CODE_APP_ERROR;
×
115
    }
116

117
    pOperator->status = OP_NOT_OPENED;
3,245✔
118
    return doSetStreamOpOpen(pOperator->pDownstream[0], id);
3,245✔
119
  }
120
  return 0;
2,350✔
121
}
122

123
static void clearStreamBlock(SOperatorInfo* pOperator) {
×
124
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
×
125
    if (pOperator->numOfDownstream == 1) {
×
126
      return clearStreamBlock(pOperator->pDownstream[0]);
×
127
    }
128
  } else {
129
    SStreamScanInfo* pInfo = pOperator->info;
×
130
    doClearBufferedBlocks(pInfo);
×
131
  }
132
}
133

134
void qResetTaskInfoCode(qTaskInfo_t tinfo) {
×
135
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
136
  pTaskInfo->code = 0;
×
137
  clearStreamBlock(pTaskInfo->pRoot);
×
138
}
×
139

140
static int32_t doSetStreamBlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type,
122,449✔
141
                                const char* id) {
142
  int32_t code = TSDB_CODE_SUCCESS;
122,449✔
143
  int32_t lino = 0;
122,449✔
144
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
122,449✔
145
    if (pOperator->numOfDownstream == 0) {
74,370!
146
      qError("failed to find stream scan operator to set the input data block, %s" PRIx64, id);
×
147
      return TSDB_CODE_APP_ERROR;
×
148
    }
149

150
    if (pOperator->numOfDownstream > 1) {  // not handle this in join query
74,370!
151
      qError("join not supported for stream block scan, %s" PRIx64, id);
×
152
      return TSDB_CODE_APP_ERROR;
×
153
    }
154
    pOperator->status = OP_NOT_OPENED;
74,370✔
155
    return doSetStreamBlock(pOperator->pDownstream[0], input, numOfBlocks, type, id);
74,370✔
156
  } else {
157
    pOperator->status = OP_NOT_OPENED;
48,079✔
158
    SStreamScanInfo* pInfo = pOperator->info;
48,079✔
159

160
    qDebug("s-task:%s in this batch, %d blocks need to be processed", id, (int32_t)numOfBlocks);
48,079✔
161
    QUERY_CHECK_CONDITION((pInfo->validBlockIndex == 0 && taosArrayGetSize(pInfo->pBlockLists) == 0), code, lino, _end,
48,146!
162
                          TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
163

164
    if (type == STREAM_INPUT__MERGED_SUBMIT) {
48,146✔
165
      for (int32_t i = 0; i < numOfBlocks; i++) {
611,588✔
166
        SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
584,420✔
167
        void*        tmp = taosArrayPush(pInfo->pBlockLists, pReq);
584,420✔
168
        QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
584,420!
169
      }
170

171
      pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
27,168✔
172
    } else if (type == STREAM_INPUT__DATA_SUBMIT) {
20,978✔
173
      void* tmp = taosArrayPush(pInfo->pBlockLists, input);
6,844✔
174
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
6,835!
175

176
      pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
6,835✔
177
    } else if (type == STREAM_INPUT__DATA_BLOCK) {
14,134✔
178
      for (int32_t i = 0; i < numOfBlocks; ++i) {
25,081✔
179
        SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
14,596✔
180
        SPackedData  tmp = {.pDataBlock = pDataBlock};
14,596✔
181
        void*        tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
14,596✔
182
        QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
14,596!
183
      }
184

185
      pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
10,485✔
186
    } else if (type == STREAM_INPUT__CHECKPOINT_TRIGGER || type == STREAM_INPUT__RECALCULATE) {
3,649!
187
      SPackedData tmp = {.pDataBlock = input};
3,649✔
188
      void*       tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
3,649✔
189
      QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
3,648!
190

191
      pInfo->blockType =
3,648✔
192
          (type == STREAM_INPUT__CHECKPOINT_TRIGGER) ? STREAM_INPUT__CHECKPOINT : STREAM_INPUT__RECALCULATE;
3,648✔
193
    } else {
194
      code = TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR;
×
195
      QUERY_CHECK_CODE(code, lino, _end);
×
196
    }
197

198
    return TSDB_CODE_SUCCESS;
48,136✔
199
  }
200

201
_end:
×
202
  if (code != TSDB_CODE_SUCCESS) {
×
203
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
204
  }
205
  return code;
×
206
}
207

208
int32_t doSetTaskId(SOperatorInfo* pOperator, SStorageAPI* pAPI) {
611,894✔
209
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
611,894✔
210
  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
611,894✔
211
    SStreamScanInfo* pStreamScanInfo = pOperator->info;
304,122✔
212
    if (pStreamScanInfo->pTableScanOp != NULL) {
304,122✔
213
      STableScanInfo* pScanInfo = pStreamScanInfo->pTableScanOp->info;
303,827✔
214
      if (pScanInfo->base.dataReader != NULL) {
303,827✔
215
        int32_t code = pAPI->tsdReader.tsdSetReaderTaskId(pScanInfo->base.dataReader, pTaskInfo->id.str);
911✔
216
        if (code) {
911!
217
          qError("failed to set reader id for executor, code:%s", tstrerror(code));
×
218
          return code;
×
219
        }
220
      }
221
    }
222
  } else {
223
    return doSetTaskId(pOperator->pDownstream[0], pAPI);
307,772✔
224
  }
225

226
  return 0;
304,123✔
227
}
228

229
int32_t qSetTaskId(qTaskInfo_t tinfo, uint64_t taskId, uint64_t queryId) {
304,118✔
230
  SExecTaskInfo* pTaskInfo = tinfo;
304,118✔
231
  pTaskInfo->id.queryId = queryId;
304,118✔
232
  buildTaskId(taskId, queryId, pTaskInfo->id.str);
304,118✔
233

234
  // set the idstr for tsdbReader
235
  return doSetTaskId(pTaskInfo->pRoot, &pTaskInfo->storageAPI);
304,121✔
236
}
237

238
int32_t qSetStreamOpOpen(qTaskInfo_t tinfo) {
2,351✔
239
  if (tinfo == NULL) {
2,351!
240
    return TSDB_CODE_APP_ERROR;
×
241
  }
242

243
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
2,351✔
244
  int32_t        code = doSetStreamOpOpen(pTaskInfo->pRoot, GET_TASKID(pTaskInfo));
2,351✔
245
  if (code != TSDB_CODE_SUCCESS) {
2,350!
246
    qError("%s failed to set the stream block data", GET_TASKID(pTaskInfo));
×
247
  } else {
248
    qDebug("%s set the stream block successfully", GET_TASKID(pTaskInfo));
2,350✔
249
  }
250

251
  return code;
2,351✔
252
}
253

254
int32_t qSetStreamNotifyInfo(qTaskInfo_t tinfo, int32_t eventTypes, const SSchemaWrapper* pSchemaWrapper,
7,467✔
255
                             const char* stbFullName, bool newSubTableRule, STaskNotifyEventStat* pNotifyEventStat) {
256
  int32_t code = TSDB_CODE_SUCCESS;
7,467✔
257
  SStreamTaskInfo *pStreamInfo = NULL;
7,467✔
258

259
  if (tinfo == 0 || eventTypes == 0 || pSchemaWrapper == NULL || stbFullName == NULL) {
7,467!
260
    goto _end;
7,467✔
261
  }
262

263
  pStreamInfo = &((SExecTaskInfo*)tinfo)->streamInfo;
×
264
  pStreamInfo->eventTypes = eventTypes;
×
265
  pStreamInfo->notifyResultSchema = tCloneSSchemaWrapper(pSchemaWrapper);
×
266
  if (pStreamInfo->notifyResultSchema == NULL) {
×
267
    code = terrno;
×
268
  }
269
  pStreamInfo->stbFullName = taosStrdup(stbFullName);
×
270
  pStreamInfo->newSubTableRule = newSubTableRule;
×
271
  pStreamInfo->pNotifyEventStat = pNotifyEventStat;
×
272

273
_end:
7,467✔
274
  return code;
7,467✔
275
}
276

277
void qSetStreamMergeInfo(qTaskInfo_t tinfo, SArray* pVTables) {
7,467✔
278
  if (tinfo == 0 || pVTables == NULL) {
7,467!
279
    return;
7,467✔
280
  }
281

282
  SStreamTaskInfo* pStreamInfo = &((SExecTaskInfo*)tinfo)->streamInfo;
×
283
  pStreamInfo->pVTables = pVTables;
×
284
}
285

286
int32_t qSetMultiStreamInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) {
48,121✔
287
  if (tinfo == NULL) {
48,121!
288
    return TSDB_CODE_APP_ERROR;
×
289
  }
290

291
  if (pBlocks == NULL || numOfBlocks == 0) {
48,121!
292
    return TSDB_CODE_SUCCESS;
×
293
  }
294

295
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
48,137✔
296

297
  int32_t code = doSetStreamBlock(pTaskInfo->pRoot, (void*)pBlocks, numOfBlocks, type, GET_TASKID(pTaskInfo));
48,137✔
298
  if (code != TSDB_CODE_SUCCESS) {
48,125!
299
    qError("%s failed to set the stream block data", GET_TASKID(pTaskInfo));
×
300
  } else {
301
    qDebug("%s set the stream block successfully", GET_TASKID(pTaskInfo));
48,125✔
302
  }
303

304
  return code;
48,127✔
305
}
306

307
int32_t qSetSMAInput(qTaskInfo_t tinfo, const void* pBlocks, size_t numOfBlocks, int32_t type) {
696✔
308
  if (tinfo == NULL) {
696!
309
    return TSDB_CODE_APP_ERROR;
×
310
  }
311

312
  if (pBlocks == NULL || numOfBlocks == 0) {
696!
313
    return TSDB_CODE_SUCCESS;
×
314
  }
315

316
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
696✔
317

318
  int32_t code = doSetSMABlock(pTaskInfo->pRoot, (void*)pBlocks, numOfBlocks, type, GET_TASKID(pTaskInfo));
696✔
319
  if (code != TSDB_CODE_SUCCESS) {
696!
320
    qError("%s failed to set the sma block data", GET_TASKID(pTaskInfo));
×
321
  } else {
322
    qDebug("%s set the sma block successfully", GET_TASKID(pTaskInfo));
696!
323
  }
324

325
  return code;
696✔
326
}
327

328
qTaskInfo_t qCreateQueueExecTaskInfo(void* msg, SReadHandle* pReaderHandle, int32_t vgId, int32_t* numOfCols,
1,576✔
329
                                     uint64_t id) {
330
  if (msg == NULL) {  // create raw scan
1,576✔
331
    SExecTaskInfo* pTaskInfo = NULL;
340✔
332

333
    int32_t code = doCreateTask(0, id, vgId, OPTR_EXEC_MODEL_QUEUE, &pReaderHandle->api, &pTaskInfo);
340✔
334
    if (NULL == pTaskInfo || code != 0) {
340!
335
      return NULL;
×
336
    }
337

338
    code = createRawScanOperatorInfo(pReaderHandle, pTaskInfo, &pTaskInfo->pRoot);
340✔
339
    if (NULL == pTaskInfo->pRoot || code != 0) {
340!
340
      taosMemoryFree(pTaskInfo);
×
341
      return NULL;
×
342
    }
343

344
    pTaskInfo->storageAPI = pReaderHandle->api;
340✔
345
    qDebug("create raw scan task info completed, vgId:%d, %s", vgId, GET_TASKID(pTaskInfo));
340✔
346
    return pTaskInfo;
340✔
347
  }
348

349
  SSubplan* pPlan = NULL;
1,236✔
350
  int32_t   code = qStringToSubplan(msg, &pPlan);
1,236✔
351
  if (code != TSDB_CODE_SUCCESS) {
1,229!
352
    terrno = code;
×
353
    return NULL;
×
354
  }
355

356
  qTaskInfo_t pTaskInfo = NULL;
1,229✔
357
  code = qCreateExecTask(pReaderHandle, vgId, 0, pPlan, &pTaskInfo, NULL, 0, NULL, OPTR_EXEC_MODEL_QUEUE);
1,229✔
358
  if (code != TSDB_CODE_SUCCESS) {
1,235!
359
    qDestroyTask(pTaskInfo);
×
360
    terrno = code;
×
361
    return NULL;
×
362
  }
363

364
  // extract the number of output columns
365
  SDataBlockDescNode* pDescNode = pPlan->pNode->pOutputDataBlockDesc;
1,236✔
366
  *numOfCols = 0;
1,236✔
367

368
  SNode* pNode;
369
  FOREACH(pNode, pDescNode->pSlots) {
8,282!
370
    SSlotDescNode* pSlotDesc = (SSlotDescNode*)pNode;
7,046✔
371
    if (pSlotDesc->output) {
7,046✔
372
      ++(*numOfCols);
7,044✔
373
    }
374
  }
375

376
  return pTaskInfo;
1,236✔
377
}
378

379
int32_t qCreateStreamExecTaskInfo(qTaskInfo_t* pTaskInfo, void* msg, SReadHandle* readers, int32_t vgId, int32_t taskId) {
7,502✔
380
  if (msg == NULL) {
7,502!
381
    return TSDB_CODE_INVALID_PARA;
×
382
  }
383

384
  *pTaskInfo = NULL;
7,502✔
385

386
  SSubplan* pPlan = NULL;
7,502✔
387
  int32_t   code = qStringToSubplan(msg, &pPlan);
7,502✔
388
  if (code != TSDB_CODE_SUCCESS) {
7,500!
389
    return code;
×
390
  }
391

392
  code = qCreateExecTask(readers, vgId, taskId, pPlan, pTaskInfo, NULL, 0, NULL, OPTR_EXEC_MODEL_STREAM);
7,500✔
393
  if (code != TSDB_CODE_SUCCESS) {
7,500!
394
    qDestroyTask(*pTaskInfo);
×
395
    return code;
×
396
  }
397

398
  code = qStreamInfoResetTimewindowFilter(*pTaskInfo);
7,500✔
399
  if (code != TSDB_CODE_SUCCESS) {
7,500!
400
    qDestroyTask(*pTaskInfo);
×
401
  }
402

403
  return code;
7,501✔
404
}
405

406
static int32_t filterUnqualifiedTables(const SStreamScanInfo* pScanInfo, const SArray* tableIdList, const char* idstr,
26,279✔
407
                                       SStorageAPI* pAPI, SArray** ppArrayRes) {
408
  int32_t code = TSDB_CODE_SUCCESS;
26,279✔
409
  int32_t lino = 0;
26,279✔
410
  SArray* qa = taosArrayInit(4, sizeof(tb_uid_t));
26,279✔
411
  QUERY_CHECK_NULL(qa, code, lino, _error, terrno);
26,280!
412
  int32_t numOfUids = taosArrayGetSize(tableIdList);
26,280✔
413
  if (numOfUids == 0) {
26,279✔
414
    (*ppArrayRes) = qa;
1,772✔
415
    goto _error;
1,772✔
416
  }
417

418
  STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
24,507✔
419

420
  uint64_t suid = 0;
24,507✔
421
  uint64_t uid = 0;
24,507✔
422
  int32_t  type = 0;
24,507✔
423
  tableListGetSourceTableInfo(pTableScanInfo->base.pTableListInfo, &suid, &uid, &type);
24,507✔
424

425
  // let's discard the tables those are not created according to the queried super table.
426
  SMetaReader mr = {0};
24,507✔
427
  pAPI->metaReaderFn.initReader(&mr, pScanInfo->readHandle.vnode, META_READER_LOCK, &pAPI->metaFn);
24,507✔
428
  for (int32_t i = 0; i < numOfUids; ++i) {
68,568✔
429
    uint64_t* id = (uint64_t*)taosArrayGet(tableIdList, i);
44,061✔
430
    QUERY_CHECK_NULL(id, code, lino, _end, terrno);
44,061!
431

432
    int32_t code = pAPI->metaReaderFn.getTableEntryByUid(&mr, *id);
44,061✔
433
    if (code != TSDB_CODE_SUCCESS) {
44,048!
434
      qError("failed to get table meta, uid:%" PRIu64 " code:%s, %s", *id, tstrerror(terrno), idstr);
×
435
      continue;
×
436
    }
437

438
    tDecoderClear(&mr.coder);
44,048✔
439

440
    if (mr.me.type == TSDB_SUPER_TABLE) {
44,060!
441
      continue;
×
442
    } else {
443
      if (type == TSDB_SUPER_TABLE) {
44,060✔
444
        // this new created child table does not belong to the scanned super table.
445
        if (mr.me.type != TSDB_CHILD_TABLE || mr.me.ctbEntry.suid != suid) {
36,681✔
446
          continue;
35,092✔
447
        }
448
      } else {  // ordinary table
449
        // In case that the scanned target table is an ordinary table. When replay the WAL during restore the vnode, we
450
        // should check all newly created ordinary table to make sure that this table isn't the destination table.
451
        if (mr.me.uid != uid) {
7,379!
452
          continue;
7,380✔
453
        }
454
      }
455
    }
456

457
    if (pScanInfo->pTagCond != NULL) {
1,588✔
458
      bool          qualified = false;
1,061✔
459
      STableKeyInfo info = {.groupId = 0, .uid = mr.me.uid};
1,061✔
460
      code = isQualifiedTable(&info, pScanInfo->pTagCond, pScanInfo->readHandle.vnode, &qualified, pAPI);
1,061✔
461
      if (code != TSDB_CODE_SUCCESS) {
1,061!
462
        qError("failed to filter new table, uid:0x%" PRIx64 ", %s", info.uid, idstr);
×
463
        continue;
531✔
464
      }
465

466
      if (!qualified) {
1,061✔
467
        continue;
531✔
468
      }
469
    }
470

471
    // handle multiple partition
472
    void* tmp = taosArrayPush(qa, id);
1,057✔
473
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
1,057!
474
  }
475

476
_end:
24,507✔
477

478
  pAPI->metaReaderFn.clearReader(&mr);
24,507✔
479
  (*ppArrayRes) = qa;
24,505✔
480

481
_error:
26,277✔
482
  if (code != TSDB_CODE_SUCCESS) {
26,277!
483
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
484
  }
485
  return code;
26,277✔
486
}
487

488
int32_t qUpdateTableListForStreamScanner(qTaskInfo_t tinfo, const SArray* tableIdList, bool isAdd) {
27,061✔
489
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
27,061✔
490
  const char*    id = GET_TASKID(pTaskInfo);
27,061✔
491
  int32_t        code = 0;
27,061✔
492

493
  if (isAdd) {
27,061✔
494
    qDebug("try to add %d tables id into query list, %s", (int32_t)taosArrayGetSize(tableIdList), id);
26,284✔
495
  }
496

497
  // traverse to the stream scanner node to add this table id
498
  SOperatorInfo* pInfo = NULL;
27,061✔
499
  code = extractOperatorInTree(pTaskInfo->pRoot, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pInfo);
27,061✔
500
  if (code != 0 || pInfo == NULL) {
27,059!
501
    return code;
4✔
502
  }
503

504
  SStreamScanInfo* pScanInfo = pInfo->info;
27,055✔
505
  if (pInfo->pTaskInfo->execModel == OPTR_EXEC_MODEL_QUEUE) {  // clear meta cache for subscription if tag is changed
27,055✔
506
    for (int32_t i = 0; i < taosArrayGetSize(tableIdList); ++i) {
2,405✔
507
      int64_t*        uid = (int64_t*)taosArrayGet(tableIdList, i);
1,232✔
508
      STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
1,232✔
509
      taosLRUCacheErase(pTableScanInfo->base.metaCache.pTableMetaEntryCache, uid, LONG_BYTES);
1,232✔
510
    }
511
  }
512

513
  if (isAdd) {  // add new table id
27,055✔
514
    SArray* qa = NULL;
26,279✔
515
    code = filterUnqualifiedTables(pScanInfo, tableIdList, id, &pTaskInfo->storageAPI, &qa);
26,279✔
516
    if (code != TSDB_CODE_SUCCESS) {
26,277!
517
      taosArrayDestroy(qa);
×
518
      return code;
×
519
    }
520
    int32_t numOfQualifiedTables = taosArrayGetSize(qa);
26,277✔
521
    qDebug("%d qualified child tables added into stream scanner, %s", numOfQualifiedTables, id);
26,276✔
522
    pTaskInfo->storageAPI.tqReaderFn.tqReaderAddTables(pScanInfo->tqReader, qa);
26,277✔
523

524
    bool   assignUid = false;
26,275✔
525
    size_t bufLen = (pScanInfo->pGroupTags != NULL) ? getTableTagsBufLen(pScanInfo->pGroupTags) : 0;
26,275✔
526
    char*  keyBuf = NULL;
26,277✔
527
    if (bufLen > 0) {
26,277✔
528
      assignUid = groupbyTbname(pScanInfo->pGroupTags);
13,916✔
529
      keyBuf = taosMemoryMalloc(bufLen);
13,916!
530
      if (keyBuf == NULL) {
13,916!
531
        taosArrayDestroy(qa);
×
532
        return terrno;
×
533
      }
534
    }
535

536
    STableListInfo* pTableListInfo = ((STableScanInfo*)pScanInfo->pTableScanOp->info)->base.pTableListInfo;
26,277✔
537
    taosWLockLatch(&pTaskInfo->lock);
26,277✔
538

539
    for (int32_t i = 0; i < numOfQualifiedTables; ++i) {
27,337✔
540
      uint64_t* uid = taosArrayGet(qa, i);
1,057✔
541
      if (!uid) {
1,057!
542
        taosMemoryFree(keyBuf);
×
543
        taosArrayDestroy(qa);
×
544
        taosWUnLockLatch(&pTaskInfo->lock);
×
545
        return terrno;
×
546
      }
547
      STableKeyInfo keyInfo = {.uid = *uid, .groupId = 0};
1,057✔
548

549
      if (bufLen > 0) {
1,057✔
550
        if (assignUid) {
228✔
551
          keyInfo.groupId = keyInfo.uid;
212✔
552
        } else {
553
          code = getGroupIdFromTagsVal(pScanInfo->readHandle.vnode, keyInfo.uid, pScanInfo->pGroupTags, keyBuf,
16✔
554
                                       &keyInfo.groupId, &pTaskInfo->storageAPI);
555
          if (code != TSDB_CODE_SUCCESS) {
16!
556
            taosMemoryFree(keyBuf);
×
557
            taosArrayDestroy(qa);
×
558
            taosWUnLockLatch(&pTaskInfo->lock);
×
559
            return code;
×
560
          }
561
        }
562
      }
563

564
      code = tableListAddTableInfo(pTableListInfo, keyInfo.uid, keyInfo.groupId);
1,057✔
565
      if (code != TSDB_CODE_SUCCESS) {
1,057!
566
        taosMemoryFree(keyBuf);
×
567
        taosArrayDestroy(qa);
×
568
        taosWUnLockLatch(&pTaskInfo->lock);
×
569
        return code;
×
570
      }
571
    }
572

573
    taosWUnLockLatch(&pTaskInfo->lock);
26,280✔
574
    if (keyBuf != NULL) {
26,280✔
575
      taosMemoryFree(keyBuf);
13,917!
576
    }
577

578
    taosArrayDestroy(qa);
26,280✔
579
  } else {  // remove the table id in current list
580
    qDebug("%d remove child tables from the stream scanner, %s", (int32_t)taosArrayGetSize(tableIdList), id);
776✔
581
    taosWLockLatch(&pTaskInfo->lock);
776✔
582
    pTaskInfo->storageAPI.tqReaderFn.tqReaderRemoveTables(pScanInfo->tqReader, tableIdList);
776✔
583
    taosWUnLockLatch(&pTaskInfo->lock);
776✔
584
  }
585

586
  return code;
27,056✔
587
}
588

589
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, int32_t dbNameBuffLen, char* tableName,
12,994,086✔
590
                                    int32_t tbaleNameBuffLen, int32_t* sversion, int32_t* tversion, int32_t idx,
591
                                    bool* tbGet) {
592
  *tbGet = false;
12,994,086✔
593

594
  if (tinfo == NULL || dbName == NULL || tableName == NULL) {
12,994,086!
595
    return TSDB_CODE_INVALID_PARA;
×
596
  }
597
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
13,010,519✔
598

599
  if (taosArrayGetSize(pTaskInfo->schemaInfos) <= idx) {
13,010,519✔
600
    return TSDB_CODE_SUCCESS;
8,162,516✔
601
  }
602

603
  SSchemaInfo* pSchemaInfo = taosArrayGet(pTaskInfo->schemaInfos, idx);
4,839,403✔
604
  if (!pSchemaInfo) {
4,838,674!
605
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
606
    return terrno;
×
607
  }
608

609
  *sversion = pSchemaInfo->sw->version;
4,842,174✔
610
  *tversion = pSchemaInfo->tversion;
4,842,174✔
611
  if (pSchemaInfo->dbname) {
4,842,174!
612
    tstrncpy(dbName, pSchemaInfo->dbname, dbNameBuffLen);
4,842,174✔
613
  } else {
614
    dbName[0] = 0;
×
615
  }
616
  if (pSchemaInfo->tablename) {
4,842,174!
617
    tstrncpy(tableName, pSchemaInfo->tablename, tbaleNameBuffLen);
4,844,649✔
618
  } else {
619
    tableName[0] = 0;
×
620
  }
621

622
  *tbGet = true;
4,842,174✔
623

624
  return TSDB_CODE_SUCCESS;
4,842,174✔
625
}
626

627
bool qIsDynamicExecTask(qTaskInfo_t tinfo) { return ((SExecTaskInfo*)tinfo)->dynamicTask; }
8,161,776✔
628

629
void qDestroyOperatorParam(SOperatorParam* pParam) {
×
630
  if (NULL == pParam) {
×
631
    return;
×
632
  }
633
  freeOperatorParam(pParam, OP_GET_PARAM);
×
634
}
635

636
void qUpdateOperatorParam(qTaskInfo_t tinfo, void* pParam) {
968✔
637
  TSWAP(pParam, ((SExecTaskInfo*)tinfo)->pOpParam);
968✔
638
  ((SExecTaskInfo*)tinfo)->paramSet = false;
968✔
639
}
968✔
640

641
int32_t qExecutorInit(void) {
14,187✔
642
  (void)taosThreadOnce(&initPoolOnce, initRefPool);
14,187✔
643
  return TSDB_CODE_SUCCESS;
14,197✔
644
}
645

646
int32_t qCreateExecTask(SReadHandle* readHandle, int32_t vgId, uint64_t taskId, SSubplan* pSubplan,
8,346,620✔
647
                        qTaskInfo_t* pTaskInfo, DataSinkHandle* handle, int8_t compressResult, char* sql,
648
                        EOPTR_EXEC_MODEL model) {
649
  SExecTaskInfo** pTask = (SExecTaskInfo**)pTaskInfo;
8,346,620✔
650
  (void)taosThreadOnce(&initPoolOnce, initRefPool);
8,346,620✔
651

652
  qDebug("start to create task, TID:0x%" PRIx64 " QID:0x%" PRIx64 ", vgId:%d", taskId, pSubplan->id.queryId, vgId);
8,351,448✔
653

654
  int32_t code = createExecTaskInfo(pSubplan, pTask, readHandle, taskId, vgId, sql, model);
8,351,552✔
655
  if (code != TSDB_CODE_SUCCESS || NULL == *pTask) {
8,344,992!
656
    qError("failed to createExecTaskInfo, code:%s", tstrerror(code));
×
657
    goto _error;
363✔
658
  }
659

660
  if (handle) {
8,354,381✔
661
    SDataSinkMgtCfg cfg = {.maxDataBlockNum = 500, .maxDataBlockNumPerQuery = 50, .compress = compressResult};
8,347,807✔
662
    void*           pSinkManager = NULL;
8,347,807✔
663
    code = dsDataSinkMgtInit(&cfg, &(*pTask)->storageAPI, &pSinkManager);
8,347,807✔
664
    if (code != TSDB_CODE_SUCCESS) {
8,344,529!
665
      qError("failed to dsDataSinkMgtInit, code:%s, %s", tstrerror(code), (*pTask)->id.str);
×
666
      goto _error;
×
667
    }
668

669
    void* pSinkParam = NULL;
8,344,529✔
670
    code = createDataSinkParam(pSubplan->pDataSink, &pSinkParam, (*pTask), readHandle);
8,344,529✔
671
    if (code != TSDB_CODE_SUCCESS) {
8,335,303!
672
      qError("failed to createDataSinkParam, vgId:%d, code:%s, %s", vgId, tstrerror(code), (*pTask)->id.str);
×
673
      taosMemoryFree(pSinkManager);
×
674
      goto _error;
×
675
    }
676

677
    SDataSinkNode* pSink = NULL;
8,335,303✔
678
    if (readHandle->localExec) {
8,335,303✔
679
      code = nodesCloneNode((SNode *)pSubplan->pDataSink, (SNode **)&pSink);
71,864✔
680
      if (code != TSDB_CODE_SUCCESS) {
71,872✔
681
        qError("failed to nodesCloneNode, srcType:%d, code:%s, %s", nodeType(pSubplan->pDataSink), tstrerror(code), (*pTask)->id.str);
6,080!
682
        taosMemoryFree(pSinkManager);
6,080!
683
        goto _error;
×
684
      }
685
    }
686

687
    // pSinkParam has been freed during create sinker.
688
    code = dsCreateDataSinker(pSinkManager, readHandle->localExec ? &pSink : &pSubplan->pDataSink, handle, pSinkParam, (*pTask)->id.str, pSubplan->processOneBlock);
8,329,231✔
689
    if (code) {
8,335,179!
690
      qError("s-task:%s failed to create data sinker, code:%s", (*pTask)->id.str, tstrerror(code));
×
691
    }
692
  }
693

694
  qDebug("subplan task create completed, TID:0x%" PRIx64 " QID:0x%" PRIx64 " code:%s", taskId, pSubplan->id.queryId,
8,337,181✔
695
         tstrerror(code));
696

697
_error:
8,080,090✔
698
  // if failed to add ref for all tables in this query, abort current query
699
  return code;
8,344,346✔
700
}
701

702
static void freeBlock(void* param) {
×
703
  SSDataBlock* pBlock = *(SSDataBlock**)param;
×
704
  blockDataDestroy(pBlock);
×
705
}
×
706

707
int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bool* hasMore, SLocalFetch* pLocal, bool processOneBlock) {
10,411,045✔
708
  int32_t        code = TSDB_CODE_SUCCESS;
10,411,045✔
709
  int32_t        lino = 0;
10,411,045✔
710
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
10,411,045✔
711
  int64_t        threadId = taosGetSelfPthreadId();
10,411,045✔
712

713
  if (pLocal) {
10,413,690!
714
    memcpy(&pTaskInfo->localFetch, pLocal, sizeof(*pLocal));
10,416,813✔
715
  }
716

717
  taosArrayClear(pResList);
10,413,690✔
718

719
  int64_t curOwner = 0;
10,405,074✔
720
  if ((curOwner = atomic_val_compare_exchange_64(&pTaskInfo->owner, 0, threadId)) != 0) {
10,405,074!
721
    qError("%s-%p execTask is now executed by thread:%p", GET_TASKID(pTaskInfo), pTaskInfo, (void*)curOwner);
×
722
    pTaskInfo->code = TSDB_CODE_QRY_IN_EXEC;
×
723
    return pTaskInfo->code;
×
724
  }
725

726
  if (pTaskInfo->cost.start == 0) {
10,421,699✔
727
    pTaskInfo->cost.start = taosGetTimestampUs();
8,304,632✔
728
  }
729

730
  if (isTaskKilled(pTaskInfo)) {
10,417,918✔
731
    atomic_store_64(&pTaskInfo->owner, 0);
14✔
732
    qDebug("%s already killed, abort", GET_TASKID(pTaskInfo));
14!
733
    return pTaskInfo->code;
14✔
734
  }
735

736
  // error occurs, record the error code and return to client
737
  int32_t ret = setjmp(pTaskInfo->env);
10,409,439✔
738
  if (ret != TSDB_CODE_SUCCESS) {
10,435,199✔
739
    pTaskInfo->code = ret;
18,209✔
740
    (void)cleanUpUdfs();
18,209✔
741

742
    qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
18,207✔
743
    atomic_store_64(&pTaskInfo->owner, 0);
18,207✔
744

745
    return pTaskInfo->code;
18,213✔
746
  }
747

748
  qDebug("%s execTask is launched", GET_TASKID(pTaskInfo));
10,416,990✔
749

750
  int32_t      current = 0;
10,416,990✔
751
  SSDataBlock* pRes = NULL;
10,416,990✔
752
  int64_t      st = taosGetTimestampUs();
10,414,408✔
753

754
  if (pTaskInfo->pOpParam && !pTaskInfo->paramSet) {
10,414,408!
755
    pTaskInfo->paramSet = true;
968✔
756
    code = pTaskInfo->pRoot->fpSet.getNextExtFn(pTaskInfo->pRoot, pTaskInfo->pOpParam, &pRes);
968✔
757
  } else {
758
    code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, &pRes);
10,413,440✔
759
  }
760

761
  QUERY_CHECK_CODE(code, lino, _end);
10,402,388!
762
  code = blockDataCheck(pRes);
10,402,388✔
763
  QUERY_CHECK_CODE(code, lino, _end);
10,403,292!
764

765
  if (pRes == NULL) {
10,403,292✔
766
    st = taosGetTimestampUs();
2,210,611✔
767
  }
768

769
  int32_t rowsThreshold = pTaskInfo->pSubplan->rowsThreshold;
10,403,907✔
770
  if (!pTaskInfo->pSubplan->dynamicRowThreshold || 4096 <= pTaskInfo->pSubplan->rowsThreshold) {
10,403,907✔
771
    rowsThreshold = 4096;
10,383,292✔
772
  }
773

774
  int32_t blockIndex = 0;
10,403,907✔
775
  while (pRes != NULL) {
27,766,834✔
776
    SSDataBlock* p = NULL;
19,477,171✔
777
    if (blockIndex >= taosArrayGetSize(pTaskInfo->pResultBlockList)) {
19,477,171✔
778
      SSDataBlock* p1 = NULL;
11,172,991✔
779
      code = createOneDataBlock(pRes, true, &p1);
11,172,991✔
780
      QUERY_CHECK_CODE(code, lino, _end);
11,177,653!
781

782
      void* tmp = taosArrayPush(pTaskInfo->pResultBlockList, &p1);
11,177,653✔
783
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
11,176,899!
784
      p = p1;
11,176,899✔
785
    } else {
786
      void* tmp = taosArrayGet(pTaskInfo->pResultBlockList, blockIndex);
8,304,494✔
787
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
8,301,616!
788

789
      p = *(SSDataBlock**)tmp;
8,301,616✔
790
      code = copyDataBlock(p, pRes);
8,301,616✔
791
      QUERY_CHECK_CODE(code, lino, _end);
8,340,077!
792
    }
793

794
    blockIndex += 1;
19,516,976✔
795

796
    current += p->info.rows;
19,516,976✔
797
    QUERY_CHECK_CONDITION((p->info.rows > 0 || p->info.type == STREAM_CHECKPOINT), code, lino, _end,
19,516,976!
798
                          TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
799
    void* tmp = taosArrayPush(pResList, &p);
19,507,640✔
800
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
19,507,640!
801

802
    if (current >= rowsThreshold || processOneBlock) {
19,507,640!
803
      break;
804
    }
805

806
    code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, &pRes);
17,394,504✔
807
    QUERY_CHECK_CODE(code, lino, _end);
17,365,628!
808
    code = blockDataCheck(pRes);
17,365,628✔
809
    QUERY_CHECK_CODE(code, lino, _end);
17,362,927!
810
  }
811

812
  if (pTaskInfo->pSubplan->dynamicRowThreshold) {
10,402,799✔
813
    pTaskInfo->pSubplan->rowsThreshold -= current;
20,877✔
814
  }
815

816
  *hasMore = (pRes != NULL);
10,402,799✔
817
  uint64_t el = (taosGetTimestampUs() - st);
10,404,781✔
818

819
  pTaskInfo->cost.elapsedTime += el;
10,404,781✔
820
  if (NULL == pRes) {
10,404,781✔
821
    *useconds = pTaskInfo->cost.elapsedTime;
8,289,995✔
822
  }
823

824
_end:
2,114,786✔
825
  (void)cleanUpUdfs();
10,404,781✔
826

827
  uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
10,407,414✔
828
  qDebug("%s task suspended, %d rows in %d blocks returned, total:%" PRId64 " rows, in sinkNode:%d, elapsed:%.2f ms",
10,407,414✔
829
         GET_TASKID(pTaskInfo), current, (int32_t)taosArrayGetSize(pResList), total, 0, el / 1000.0);
830

831
  atomic_store_64(&pTaskInfo->owner, 0);
10,407,414✔
832
  if (code) {
10,407,411!
833
    pTaskInfo->code = code;
×
834
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
835
  }
836

837
  return pTaskInfo->code;
10,407,411✔
838
}
839

840
void qCleanExecTaskBlockBuf(qTaskInfo_t tinfo) {
724✔
841
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
724✔
842
  SArray*        pList = pTaskInfo->pResultBlockList;
724✔
843
  size_t         num = taosArrayGetSize(pList);
724✔
844
  for (int32_t i = 0; i < num; ++i) {
1,394✔
845
    SSDataBlock** p = taosArrayGet(pTaskInfo->pResultBlockList, i);
670✔
846
    if (p) {
670!
847
      blockDataDestroy(*p);
670✔
848
    }
849
  }
850

851
  taosArrayClear(pTaskInfo->pResultBlockList);
724✔
852
}
724✔
853

854
int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) {
780,360✔
855
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
780,360✔
856
  int64_t        threadId = taosGetSelfPthreadId();
780,360✔
857
  int64_t        curOwner = 0;
780,363✔
858

859
  *pRes = NULL;
780,363✔
860

861
  // todo extract method
862
  taosRLockLatch(&pTaskInfo->lock);
780,363✔
863
  bool isKilled = isTaskKilled(pTaskInfo);
780,391✔
864
  if (isKilled) {
780,378!
865
    clearStreamBlock(pTaskInfo->pRoot);
×
866
    qDebug("%s already killed, abort", GET_TASKID(pTaskInfo));
×
867

868
    taosRUnLockLatch(&pTaskInfo->lock);
×
869
    return pTaskInfo->code;
×
870
  }
871

872
  if (pTaskInfo->owner != 0) {
780,378!
873
    qError("%s-%p execTask is now executed by thread:%p", GET_TASKID(pTaskInfo), pTaskInfo, (void*)curOwner);
×
874
    pTaskInfo->code = TSDB_CODE_QRY_IN_EXEC;
×
875

876
    taosRUnLockLatch(&pTaskInfo->lock);
×
877
    return pTaskInfo->code;
×
878
  }
879

880
  pTaskInfo->owner = threadId;
780,378✔
881
  taosRUnLockLatch(&pTaskInfo->lock);
780,378✔
882

883
  if (pTaskInfo->cost.start == 0) {
780,391✔
884
    pTaskInfo->cost.start = taosGetTimestampUs();
7,794✔
885
  }
886

887
  // error occurs, record the error code and return to client
888
  int32_t ret = setjmp(pTaskInfo->env);
780,391✔
889
  if (ret != TSDB_CODE_SUCCESS) {
780,381✔
890
    pTaskInfo->code = ret;
19✔
891
    (void)cleanUpUdfs();
19✔
892
    qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
19!
893
    atomic_store_64(&pTaskInfo->owner, 0);
19✔
894
    return pTaskInfo->code;
19✔
895
  }
896

897
  qDebug("%s execTask is launched", GET_TASKID(pTaskInfo));
780,362✔
898

899
  int64_t st = taosGetTimestampUs();
780,377✔
900

901
  int32_t code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, pRes);
780,377✔
902
  if (code) {
780,047!
903
    pTaskInfo->code = code;
×
904
    qError("%s failed at line %d, code:%s %s", __func__, __LINE__, tstrerror(code), GET_TASKID(pTaskInfo));
×
905
  }
906

907
  code = blockDataCheck(*pRes);
780,047✔
908
  if (code) {
780,078!
909
    pTaskInfo->code = code;
×
910
    qError("%s failed at line %d, code:%s %s", __func__, __LINE__, tstrerror(code), GET_TASKID(pTaskInfo));
×
911
  }
912

913
  uint64_t el = (taosGetTimestampUs() - st);
780,106✔
914

915
  pTaskInfo->cost.elapsedTime += el;
780,106✔
916
  if (NULL == *pRes) {
780,106✔
917
    *useconds = pTaskInfo->cost.elapsedTime;
129,555✔
918
  }
919

920
  (void) cleanUpUdfs();
780,106✔
921

922
  int32_t  current = (*pRes != NULL) ? (*pRes)->info.rows : 0;
780,374✔
923
  uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
780,374✔
924

925
  qDebug("%s task suspended, %d rows returned, total:%" PRId64 " rows, in sinkNode:%d, elapsed:%.2f ms",
780,374✔
926
         GET_TASKID(pTaskInfo), current, total, 0, el / 1000.0);
927

928
  atomic_store_64(&pTaskInfo->owner, 0);
780,370✔
929
  return pTaskInfo->code;
780,374✔
930
}
931

932
int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo) {
3,665,750✔
933
  taosWLockLatch(&pTaskInfo->stopInfo.lock);
3,665,750✔
934
  void* tmp = taosArrayPush(pTaskInfo->stopInfo.pStopInfo, pInfo);
3,665,950✔
935
  taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
3,665,891✔
936

937
  if (!tmp) {
3,665,956✔
938
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
67!
939
    return terrno;
67✔
940
  }
941
  return TSDB_CODE_SUCCESS;
3,665,889✔
942
}
943

944
int32_t stopInfoComp(void const* lp, void const* rp) {
×
945
  SExchangeOpStopInfo* key = (SExchangeOpStopInfo*)lp;
×
946
  SExchangeOpStopInfo* pInfo = (SExchangeOpStopInfo*)rp;
×
947

948
  if (key->refId < pInfo->refId) {
×
949
    return -1;
×
950
  } else if (key->refId > pInfo->refId) {
×
951
    return 1;
×
952
  }
953

954
  return 0;
×
955
}
956

957
void qRemoveTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo) {
×
958
  taosWLockLatch(&pTaskInfo->stopInfo.lock);
×
959
  int32_t idx = taosArraySearchIdx(pTaskInfo->stopInfo.pStopInfo, pInfo, stopInfoComp, TD_EQ);
×
960
  if (idx >= 0) {
×
961
    taosArrayRemove(pTaskInfo->stopInfo.pStopInfo, idx);
×
962
  }
963
  taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
×
964
}
×
965

966
void qStopTaskOperators(SExecTaskInfo* pTaskInfo) {
17,711✔
967
  taosWLockLatch(&pTaskInfo->stopInfo.lock);
17,711✔
968

969
  int32_t num = taosArrayGetSize(pTaskInfo->stopInfo.pStopInfo);
17,712✔
970
  for (int32_t i = 0; i < num; ++i) {
17,729✔
971
    SExchangeOpStopInfo* pStop = taosArrayGet(pTaskInfo->stopInfo.pStopInfo, i);
21✔
972
    if (!pStop) {
21!
973
      qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
974
      continue;
×
975
    }
976
    SExchangeInfo* pExchangeInfo = taosAcquireRef(exchangeObjRefPool, pStop->refId);
21✔
977
    if (pExchangeInfo) {
21!
978
      int32_t code = tsem_post(&pExchangeInfo->ready);
21✔
979
      if (code != TSDB_CODE_SUCCESS) {
21!
980
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
981
      }
982
      code = taosReleaseRef(exchangeObjRefPool, pStop->refId);
21✔
983
      if (code != TSDB_CODE_SUCCESS) {
21!
984
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
985
      }
986
    }
987
  }
988

989
  taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
17,708✔
990
}
17,722✔
991

992
int32_t qAsyncKillTask(qTaskInfo_t qinfo, int32_t rspCode) {
17,717✔
993
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo;
17,717✔
994
  if (pTaskInfo == NULL) {
17,717!
995
    return TSDB_CODE_QRY_INVALID_QHANDLE;
×
996
  }
997

998
  qDebug("%s execTask async killed", GET_TASKID(pTaskInfo));
17,717✔
999

1000
  setTaskKilled(pTaskInfo, rspCode);
17,717✔
1001
  qStopTaskOperators(pTaskInfo);
17,712✔
1002

1003
  return TSDB_CODE_SUCCESS;
17,722✔
1004
}
1005

1006
int32_t qKillTask(qTaskInfo_t tinfo, int32_t rspCode, int64_t waitDuration) {
7,457✔
1007
  int64_t        st = taosGetTimestampMs();
7,458✔
1008
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
7,458✔
1009
  if (pTaskInfo == NULL) {
7,458!
1010
    return TSDB_CODE_QRY_INVALID_QHANDLE;
×
1011
  }
1012

1013
  if (waitDuration > 0) {
7,458✔
1014
    qDebug("%s sync killed execTask, and waiting for at most %.2fs", GET_TASKID(pTaskInfo), waitDuration/1000.0);
1,556✔
1015
  } else {
1016
    qDebug("%s async killed execTask", GET_TASKID(pTaskInfo));
5,902✔
1017
  }
1018

1019
  setTaskKilled(pTaskInfo, TSDB_CODE_TSC_QUERY_KILLED);
7,458✔
1020

1021
  if (waitDuration > 0) {
7,456✔
1022
    while (1) {
1023
      taosWLockLatch(&pTaskInfo->lock);
1,559✔
1024
      if (qTaskIsExecuting(pTaskInfo)) {  // let's wait for 100 ms and try again
1,560✔
1025
        taosWUnLockLatch(&pTaskInfo->lock);
4✔
1026

1027
        taosMsleep(200);
4✔
1028

1029
        int64_t d = taosGetTimestampMs() - st;
4✔
1030
        if (d >= waitDuration && waitDuration >= 0) {
4!
1031
          qWarn("%s waiting more than %.2fs, not wait anymore", GET_TASKID(pTaskInfo), waitDuration / 1000.0);
×
1032
          return TSDB_CODE_SUCCESS;
×
1033
        }
1034
      } else {  // not running now
1035
        pTaskInfo->code = rspCode;
1,556✔
1036
        taosWUnLockLatch(&pTaskInfo->lock);
1,556✔
1037
        return TSDB_CODE_SUCCESS;
1,556✔
1038
      }
1039
    }
1040
  }
1041

1042
  int64_t et = taosGetTimestampMs() - st;
5,901✔
1043
  if (et < waitDuration) {
5,901!
1044
    qInfo("%s  waiting %.2fs for executor stopping", GET_TASKID(pTaskInfo), et / 1000.0);
×
1045
    return TSDB_CODE_SUCCESS;
×
1046
  }
1047
  return TSDB_CODE_SUCCESS;
5,901✔
1048
}
1049

1050
bool qTaskIsExecuting(qTaskInfo_t qinfo) {
1,560✔
1051
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo;
1,560✔
1052
  if (NULL == pTaskInfo) {
1,560!
1053
    return false;
×
1054
  }
1055

1056
  return 0 != atomic_load_64(&pTaskInfo->owner);
1,560✔
1057
}
1058

1059
static void printTaskExecCostInLog(SExecTaskInfo* pTaskInfo) {
8,362,317✔
1060
  STaskCostInfo* pSummary = &pTaskInfo->cost;
8,362,317✔
1061
  int64_t        idleTime = pSummary->start - pSummary->created;
8,362,317✔
1062

1063
  SFileBlockLoadRecorder* pRecorder = pSummary->pRecoder;
8,362,317✔
1064
  if (pSummary->pRecoder != NULL) {
8,362,317✔
1065
    qDebug(
4,961,611✔
1066
        "%s :cost summary: idle:%.2f ms, elapsed time:%.2f ms, extract tableList:%.2f ms, "
1067
        "createGroupIdMap:%.2f ms, total blocks:%d, "
1068
        "load block SMA:%d, load data block:%d, total rows:%" PRId64 ", check rows:%" PRId64,
1069
        GET_TASKID(pTaskInfo), idleTime / 1000.0, pSummary->elapsedTime / 1000.0, pSummary->extractListTime,
1070
        pSummary->groupIdMapTime, pRecorder->totalBlocks, pRecorder->loadBlockStatis, pRecorder->loadBlocks,
1071
        pRecorder->totalRows, pRecorder->totalCheckedRows);
1072
  } else {
1073
    qDebug("%s :cost summary: idle in queue:%.2f ms, elapsed time:%.2f ms", GET_TASKID(pTaskInfo), idleTime / 1000.0,
3,400,706✔
1074
           pSummary->elapsedTime / 1000.0);
1075
  }
1076
}
8,362,318✔
1077

1078
void qDestroyTask(qTaskInfo_t qTaskHandle) {
8,365,233✔
1079
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qTaskHandle;
8,365,233✔
1080
  if (pTaskInfo == NULL) {
8,365,233✔
1081
    return;
2,375✔
1082
  }
1083

1084
  if (pTaskInfo->pRoot != NULL) {
8,362,858!
1085
    qDebug("%s execTask completed, numOfRows:%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->pRoot->resultInfo.totalRows);
8,363,774✔
1086
  } else {
1087
    qDebug("%s execTask completed", GET_TASKID(pTaskInfo));
×
1088
  }
1089

1090
  printTaskExecCostInLog(pTaskInfo);  // print the query cost summary
8,362,857✔
1091
  doDestroyTask(pTaskInfo);
8,362,775✔
1092
}
1093

1094
int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, SArray* pExecInfoList) {
566,097✔
1095
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
566,097✔
1096
  return getOperatorExplainExecInfo(pTaskInfo->pRoot, pExecInfoList);
566,097✔
1097
}
1098

1099
void qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner) {
1,235✔
1100
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
1,235✔
1101
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
1,235✔
1102

1103
  while (1) {
1,126✔
1104
    uint16_t type = pOperator->operatorType;
2,361✔
1105
    if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
2,361✔
1106
      *scanner = pOperator->info;
1,235✔
1107
      break;
1,235✔
1108
    } else {
1109
      pOperator = pOperator->pDownstream[0];
1,126✔
1110
    }
1111
  }
1112
}
1,235✔
1113

1114
int32_t qStreamSourceScanParamForHistoryScanStep1(qTaskInfo_t tinfo, SVersionRange* pVerRange, STimeWindow* pWindow) {
2,345✔
1115
  int32_t        code = TSDB_CODE_SUCCESS;
2,345✔
1116
  int32_t        lino = 0;
2,345✔
1117
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
2,345✔
1118
  QUERY_CHECK_CONDITION((pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM), code, lino, _end,
2,345!
1119
                        TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
1120

1121
  SStreamTaskInfo* pStreamInfo = &pTaskInfo->streamInfo;
2,345✔
1122

1123
  pStreamInfo->fillHistoryVer = *pVerRange;
2,345✔
1124
  pStreamInfo->fillHistoryWindow = *pWindow;
2,345✔
1125
  pStreamInfo->recoverStep = STREAM_RECOVER_STEP__PREPARE1;
2,345✔
1126

1127
  qDebug("%s step 1. set param for stream scanner for scan-history data, verRange:%" PRId64 " - %" PRId64
2,345✔
1128
         ", window:%" PRId64 " - %" PRId64,
1129
         GET_TASKID(pTaskInfo), pStreamInfo->fillHistoryVer.minVer, pStreamInfo->fillHistoryVer.maxVer, pWindow->skey,
1130
         pWindow->ekey);
1131
_end:
932✔
1132
  if (code != TSDB_CODE_SUCCESS) {
2,345!
1133
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1134
  }
1135
  return code;
2,344✔
1136
}
1137

1138
int32_t qStreamSourceScanParamForHistoryScanStep2(qTaskInfo_t tinfo, SVersionRange* pVerRange, STimeWindow* pWindow) {
3,340✔
1139
  int32_t        code = TSDB_CODE_SUCCESS;
3,340✔
1140
  int32_t        lino = 0;
3,340✔
1141
  if (tinfo == NULL){
3,340!
1142
    return TSDB_CODE_INTERNAL_ERROR;
×
1143
  }
1144
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
3,340✔
1145
  QUERY_CHECK_CONDITION((pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM), code, lino, _end,
3,340!
1146
                        TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
1147

1148
  SStreamTaskInfo* pStreamInfo = &pTaskInfo->streamInfo;
3,340✔
1149

1150
  pStreamInfo->fillHistoryVer = *pVerRange;
3,340✔
1151
  pStreamInfo->fillHistoryWindow = *pWindow;
3,340✔
1152
  pStreamInfo->recoverStep = STREAM_RECOVER_STEP__PREPARE2;
3,340✔
1153

1154
  qDebug("%s step 2. set param for stream scanner scan wal, verRange:%" PRId64 "-%" PRId64 ", window:%" PRId64
3,340✔
1155
         "-%" PRId64,
1156
         GET_TASKID(pTaskInfo), pStreamInfo->fillHistoryVer.minVer, pStreamInfo->fillHistoryVer.maxVer, pWindow->skey,
1157
         pWindow->ekey);
1158
_end:
1,217✔
1159
  if (code != TSDB_CODE_SUCCESS) {
3,340!
1160
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1161
  }
1162
  return code;
3,341✔
1163
}
1164

1165
int32_t qStreamRecoverFinish(qTaskInfo_t tinfo) {
×
1166
  int32_t        code = TSDB_CODE_SUCCESS;
×
1167
  int32_t        lino = 0;
×
1168
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
×
1169
  QUERY_CHECK_CONDITION((pTaskInfo->execModel == OPTR_EXEC_MODEL_STREAM), code, lino, _end,
×
1170
                        TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
1171
  pTaskInfo->streamInfo.recoverStep = STREAM_RECOVER_STEP__NONE;
×
1172

1173
_end:
×
1174
  if (code != TSDB_CODE_SUCCESS) {
×
1175
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1176
  }
1177
  return code;
×
1178
}
1179

1180
static int32_t getOpratorIntervalInfo(SOperatorInfo* pOperator, int64_t* pWaterMark, SInterval* pInterval, STimeWindow* pLastWindow, TSKEY* pRecInteral) {
611✔
1181
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
611✔
1182
    return getOpratorIntervalInfo(pOperator->pDownstream[0], pWaterMark, pInterval, pLastWindow, pRecInteral);
387✔
1183
  }
1184
  SStreamScanInfo* pScanOp = (SStreamScanInfo*) pOperator->info;
224✔
1185
  *pWaterMark = pScanOp->twAggSup.waterMark;
224✔
1186
  *pInterval = pScanOp->interval;
224✔
1187
  *pLastWindow = pScanOp->lastScanRange;
224✔
1188
  *pRecInteral = pScanOp->recalculateInterval;
224✔
1189
  return TSDB_CODE_SUCCESS; 
224✔
1190
}
1191

1192
int32_t qGetStreamIntervalExecInfo(qTaskInfo_t tinfo, int64_t* pWaterMark, SInterval* pInterval, STimeWindow* pLastWindow, TSKEY* pRecInteral) {
224✔
1193
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
224✔
1194
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
224✔
1195
  return getOpratorIntervalInfo(pOperator, pWaterMark, pInterval, pLastWindow, pRecInteral);
224✔
1196
}
1197

1198
int32_t qSetStreamOperatorOptionForScanHistory(qTaskInfo_t tinfo) {
2,412✔
1199
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
2,412✔
1200
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
2,412✔
1201

1202
  while (1) {
3,346✔
1203
    int32_t type = pOperator->operatorType;
5,758✔
1204
    if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL ||
5,758✔
1205
        type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL ||
4,478✔
1206
        type == QUERY_NODE_PHYSICAL_PLAN_STREAM_MID_INTERVAL) {
1,291✔
1207
      SStreamIntervalOperatorInfo* pInfo = pOperator->info;
1,289✔
1208
      STimeWindowAggSupp*          pSup = &pInfo->twAggSup;
1,289✔
1209

1210
      qInfo("save stream param for interval: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
1,289!
1211

1212
      pSup->calTriggerSaved = pSup->calTrigger;
1,291✔
1213
      pSup->deleteMarkSaved = pSup->deleteMark;
1,291✔
1214
      pSup->calTrigger = STREAM_TRIGGER_AT_ONCE;
1,291✔
1215
      pSup->deleteMark = INT64_MAX;
1,291✔
1216
      pInfo->ignoreExpiredDataSaved = pInfo->ignoreExpiredData;
1,291✔
1217
      pInfo->ignoreExpiredData = false;
1,291✔
1218
    } else if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION ||
4,469✔
1219
               type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION ||
4,284✔
1220
               type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) {
191✔
1221
      SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
190✔
1222
      STimeWindowAggSupp*            pSup = &pInfo->twAggSup;
190✔
1223

1224
      qInfo("save stream param for session: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
190!
1225

1226
      pSup->calTriggerSaved = pSup->calTrigger;
191✔
1227
      pSup->deleteMarkSaved = pSup->deleteMark;
191✔
1228
      pSup->calTrigger = STREAM_TRIGGER_AT_ONCE;
191✔
1229
      pSup->deleteMark = INT64_MAX;
191✔
1230
      pInfo->ignoreExpiredDataSaved = pInfo->ignoreExpiredData;
191✔
1231
      pInfo->ignoreExpiredData = false;
191✔
1232
    } else if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_STATE) {
4,279✔
1233
      SStreamStateAggOperatorInfo* pInfo = pOperator->info;
87✔
1234
      STimeWindowAggSupp*          pSup = &pInfo->twAggSup;
87✔
1235

1236
      qInfo("save stream param for state: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
87!
1237

1238
      pSup->calTriggerSaved = pSup->calTrigger;
87✔
1239
      pSup->deleteMarkSaved = pSup->deleteMark;
87✔
1240
      pSup->calTrigger = STREAM_TRIGGER_AT_ONCE;
87✔
1241
      pSup->deleteMark = INT64_MAX;
87✔
1242
      pInfo->ignoreExpiredDataSaved = pInfo->ignoreExpiredData;
87✔
1243
      pInfo->ignoreExpiredData = false;
87✔
1244
    } else if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT) {
4,192✔
1245
      SStreamEventAggOperatorInfo* pInfo = pOperator->info;
73✔
1246
      STimeWindowAggSupp*          pSup = &pInfo->twAggSup;
73✔
1247

1248
      qInfo("save stream param for state: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
73!
1249

1250
      pSup->calTriggerSaved = pSup->calTrigger;
73✔
1251
      pSup->deleteMarkSaved = pSup->deleteMark;
73✔
1252
      pSup->calTrigger = STREAM_TRIGGER_AT_ONCE;
73✔
1253
      pSup->deleteMark = INT64_MAX;
73✔
1254
      pInfo->ignoreExpiredDataSaved = pInfo->ignoreExpiredData;
73✔
1255
      pInfo->ignoreExpiredData = false;
73✔
1256
    } else if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_COUNT) {
4,119✔
1257
      SStreamCountAggOperatorInfo* pInfo = pOperator->info;
79✔
1258
      STimeWindowAggSupp*          pSup = &pInfo->twAggSup;
79✔
1259

1260
      qInfo("save stream param for state: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
79!
1261

1262
      pSup->calTriggerSaved = pSup->calTrigger;
79✔
1263
      pSup->deleteMarkSaved = pSup->deleteMark;
79✔
1264
      pSup->calTrigger = STREAM_TRIGGER_AT_ONCE;
79✔
1265
      pSup->deleteMark = INT64_MAX;
79✔
1266
      pInfo->ignoreExpiredDataSaved = pInfo->ignoreExpiredData;
79✔
1267
      pInfo->ignoreExpiredData = false;
79✔
1268
      qInfo("save stream task:%s, param for state: %d", GET_TASKID(pTaskInfo), pInfo->ignoreExpiredData);
79!
1269
    } else if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERP_FUNC) {
4,040✔
1270
      SStreamTimeSliceOperatorInfo* pInfo = pOperator->info;
8✔
1271
      STimeWindowAggSupp*           pSup = &pInfo->twAggSup;
8✔
1272

1273
      qInfo("save stream param for state: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
8!
1274

1275
      pSup->calTriggerSaved = pSup->calTrigger;
8✔
1276
      pSup->deleteMarkSaved = pSup->deleteMark;
8✔
1277
      pSup->calTrigger = STREAM_TRIGGER_AT_ONCE;
8✔
1278
      pSup->deleteMark = INT64_MAX;
8✔
1279
      pInfo->ignoreExpiredDataSaved = pInfo->ignoreExpiredData;
8✔
1280
      pInfo->ignoreExpiredData = false;
8✔
1281
      qInfo("save stream task:%s, param for state: %d", GET_TASKID(pTaskInfo), pInfo->ignoreExpiredData);
8!
1282
    }
1283

1284
    // iterate operator tree
1285
    if (pOperator->numOfDownstream != 1 || pOperator->pDownstream[0] == NULL) {
5,761!
1286
      if (pOperator->numOfDownstream > 1) {
2,415!
1287
        qError("unexpected stream, multiple downstream");
×
1288
        return -1;
×
1289
      }
1290
      return 0;
2,415✔
1291
    } else {
1292
      pOperator = pOperator->pDownstream[0];
3,346✔
1293
    }
1294
  }
1295

1296
  return 0;
1297
}
1298

1299
bool qStreamScanhistoryFinished(qTaskInfo_t tinfo) {
2,354✔
1300
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
2,354✔
1301
  return pTaskInfo->streamInfo.recoverScanFinished;
2,354✔
1302
}
1303

1304
int32_t qStreamInfoResetTimewindowFilter(qTaskInfo_t tinfo) {
9,659✔
1305
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
9,659✔
1306
  STimeWindow*   pWindow = &pTaskInfo->streamInfo.fillHistoryWindow;
9,659✔
1307

1308
  qDebug("%s remove timeWindow filter:%" PRId64 "-%" PRId64 ", set new window:%" PRId64 "-%" PRId64,
9,659✔
1309
         GET_TASKID(pTaskInfo), pWindow->skey, pWindow->ekey, INT64_MIN, INT64_MAX);
1310

1311
  pWindow->skey = INT64_MIN;
9,659✔
1312
  pWindow->ekey = INT64_MAX;
9,659✔
1313
  return 0;
9,659✔
1314
}
1315

1316
void* qExtractReaderFromStreamScanner(void* scanner) {
1,235✔
1317
  SStreamScanInfo* pInfo = scanner;
1,235✔
1318
  return (void*)pInfo->tqReader;
1,235✔
1319
}
1320

1321
const SSchemaWrapper* qExtractSchemaFromTask(qTaskInfo_t tinfo) {
2,509✔
1322
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
2,509✔
1323
  return pTaskInfo->streamInfo.schema;
2,509✔
1324
}
1325

1326
const char* qExtractTbnameFromTask(qTaskInfo_t tinfo) {
2,509✔
1327
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
2,509✔
1328
  return pTaskInfo->streamInfo.tbName;
2,509✔
1329
}
1330

1331
SMqBatchMetaRsp* qStreamExtractMetaMsg(qTaskInfo_t tinfo) {
2,629✔
1332
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
2,629✔
1333
  return &pTaskInfo->streamInfo.btMetaRsp;
2,629✔
1334
}
1335

1336
int32_t qStreamExtractOffset(qTaskInfo_t tinfo, STqOffsetVal* pOffset) {
81,955✔
1337
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
81,955✔
1338
  tOffsetCopy(pOffset, &pTaskInfo->streamInfo.currentOffset);
81,955✔
1339
  return 0;
81,955✔
1340
  /*if (code != TSDB_CODE_SUCCESS) {
1341
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
1342
    pTaskInfo->code = code;
1343
    T_LONG_JMP(pTaskInfo->env, code);
1344
  }*/
1345
}
1346

1347
int32_t initQueryTableDataCondForTmq(SQueryTableDataCond* pCond, SSnapContext* sContext, SMetaTableInfo* pMtInfo) {
2,507✔
1348
  memset(pCond, 0, sizeof(SQueryTableDataCond));
2,507✔
1349
  pCond->order = TSDB_ORDER_ASC;
2,507✔
1350
  pCond->numOfCols = pMtInfo->schema->nCols;
2,507✔
1351
  pCond->colList = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnInfo));
2,507!
1352
  pCond->pSlotList = taosMemoryMalloc(sizeof(int32_t) * pCond->numOfCols);
2,507!
1353
  if (pCond->colList == NULL || pCond->pSlotList == NULL) {
2,507!
1354
    taosMemoryFreeClear(pCond->colList);
×
1355
    taosMemoryFreeClear(pCond->pSlotList);
×
1356
    return terrno;
×
1357
  }
1358

1359
  TAOS_SET_OBJ_ALIGNED(&pCond->twindows, TSWINDOW_INITIALIZER);
2,507✔
1360
  pCond->suid = pMtInfo->suid;
2,507✔
1361
  pCond->type = TIMEWINDOW_RANGE_CONTAINED;
2,507✔
1362
  pCond->startVersion = -1;
2,507✔
1363
  pCond->endVersion = sContext->snapVersion;
2,507✔
1364

1365
  for (int32_t i = 0; i < pCond->numOfCols; ++i) {
15,810✔
1366
    SColumnInfo* pColInfo = &pCond->colList[i];
13,303✔
1367
    pColInfo->type = pMtInfo->schema->pSchema[i].type;
13,303✔
1368
    pColInfo->bytes = pMtInfo->schema->pSchema[i].bytes;
13,303✔
1369
    pColInfo->colId = pMtInfo->schema->pSchema[i].colId;
13,303✔
1370
    pColInfo->pk = pMtInfo->schema->pSchema[i].flags & COL_IS_KEY;
13,303✔
1371

1372
    pCond->pSlotList[i] = i;
13,303✔
1373
  }
1374

1375
  return TSDB_CODE_SUCCESS;
2,507✔
1376
}
1377

1378
void qStreamSetOpen(qTaskInfo_t tinfo) {
581,591✔
1379
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
581,591✔
1380
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
581,591✔
1381
  pOperator->status = OP_NOT_OPENED;
581,591✔
1382
}
581,591✔
1383

1384
void qStreamSetSourceExcluded(qTaskInfo_t tinfo, int8_t sourceExcluded) {
79,268✔
1385
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
79,268✔
1386
  pTaskInfo->streamInfo.sourceExcluded = sourceExcluded;
79,268✔
1387
}
79,268✔
1388

1389
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType) {
299,327✔
1390
  int32_t        code = TSDB_CODE_SUCCESS;
299,327✔
1391
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
299,327✔
1392
  SStorageAPI*   pAPI = &pTaskInfo->storageAPI;
299,327✔
1393

1394
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
299,327✔
1395
  const char*    id = GET_TASKID(pTaskInfo);
299,327✔
1396

1397
  if (subType == TOPIC_SUB_TYPE__COLUMN && pOffset->type == TMQ_OFFSET__LOG) {
299,327✔
1398
    code = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pOperator);
78,199✔
1399
    if (pOperator == NULL || code != 0) {
78,199!
1400
      return code;
×
1401
    }
1402

1403
    SStreamScanInfo* pInfo = pOperator->info;
78,199✔
1404
    SStoreTqReader*  pReaderAPI = &pTaskInfo->storageAPI.tqReaderFn;
78,199✔
1405
    SWalReader*      pWalReader = pReaderAPI->tqReaderGetWalReader(pInfo->tqReader);
78,199✔
1406
    walReaderVerifyOffset(pWalReader, pOffset);
78,199✔
1407
  }
1408
  // if pOffset equal to current offset, means continue consume
1409
  if (tOffsetEqual(pOffset, &pTaskInfo->streamInfo.currentOffset)) {
299,327✔
1410
    return 0;
73,635✔
1411
  }
1412

1413
  if (subType == TOPIC_SUB_TYPE__COLUMN) {
225,692✔
1414
    code = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pOperator);
223,134✔
1415
    if (pOperator == NULL || code != 0) {
223,133!
1416
      return code;
1✔
1417
    }
1418

1419
    SStreamScanInfo* pInfo = pOperator->info;
223,132✔
1420
    STableScanInfo*  pScanInfo = pInfo->pTableScanOp->info;
223,132✔
1421
    STableScanBase*  pScanBaseInfo = &pScanInfo->base;
223,132✔
1422
    STableListInfo*  pTableListInfo = pScanBaseInfo->pTableListInfo;
223,132✔
1423

1424
    if (pOffset->type == TMQ_OFFSET__LOG) {
223,132✔
1425
      pTaskInfo->storageAPI.tsdReader.tsdReaderClose(pScanBaseInfo->dataReader);
5,619✔
1426
      pScanBaseInfo->dataReader = NULL;
5,618✔
1427

1428
      SStoreTqReader* pReaderAPI = &pTaskInfo->storageAPI.tqReaderFn;
5,618✔
1429
      SWalReader*     pWalReader = pReaderAPI->tqReaderGetWalReader(pInfo->tqReader);
5,618✔
1430
      walReaderVerifyOffset(pWalReader, pOffset);
5,619✔
1431
      code = pReaderAPI->tqReaderSeek(pInfo->tqReader, pOffset->version, id);
5,618✔
1432
      if (code < 0) {
5,619✔
1433
        qError("tqReaderSeek failed ver:%" PRId64 ", %s", pOffset->version, id);
50!
1434
        return code;
50✔
1435
      }
1436
    } else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
217,513!
1437
      // iterate all tables from tableInfoList, and retrieve rows from each table one-by-one
1438
      // those data are from the snapshot in tsdb, besides the data in the wal file.
1439
      int64_t uid = pOffset->uid;
217,513✔
1440
      int64_t ts = pOffset->ts;
217,513✔
1441
      int32_t index = 0;
217,513✔
1442

1443
      // this value may be changed if new tables are created
1444
      taosRLockLatch(&pTaskInfo->lock);
217,513✔
1445
      int32_t numOfTables = 0;
217,517✔
1446
      code = tableListGetSize(pTableListInfo, &numOfTables);
217,517✔
1447
      if (code != TSDB_CODE_SUCCESS) {
217,515!
1448
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1449
        taosRUnLockLatch(&pTaskInfo->lock);
×
1450
        return code;
217,337✔
1451
      }
1452

1453
      if (uid == 0) {
217,515✔
1454
        if (numOfTables != 0) {
217,495✔
1455
          STableKeyInfo* tmp = tableListGetInfo(pTableListInfo, 0);
159✔
1456
          if (!tmp) {
159!
1457
            qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
1458
            taosRUnLockLatch(&pTaskInfo->lock);
×
1459
            return terrno;
×
1460
          }
1461
          if (tmp) uid = tmp->uid;
159!
1462
          ts = INT64_MIN;
159✔
1463
          pScanInfo->currentTable = 0;
159✔
1464
        } else {
1465
          taosRUnLockLatch(&pTaskInfo->lock);
217,336✔
1466
          qError("no table in table list, %s", id);
217,338!
1467
          return TSDB_CODE_TMQ_NO_TABLE_QUALIFIED;
217,338✔
1468
        }
1469
      }
1470
      pTaskInfo->storageAPI.tqReaderFn.tqSetTablePrimaryKey(pInfo->tqReader, uid);
179✔
1471

1472
      qDebug("switch to table uid:%" PRId64 " ts:%" PRId64 "% " PRId64 " rows returned", uid, ts,
179✔
1473
             pInfo->pTableScanOp->resultInfo.totalRows);
1474
      pInfo->pTableScanOp->resultInfo.totalRows = 0;
179✔
1475

1476
      // start from current accessed position
1477
      // we cannot start from the pScanInfo->currentTable, since the commit offset may cause the rollback of the start
1478
      // position, let's find it from the beginning.
1479
      index = tableListFind(pTableListInfo, uid, 0);
179✔
1480
      taosRUnLockLatch(&pTaskInfo->lock);
178✔
1481

1482
      if (index >= 0) {
179!
1483
        pScanInfo->currentTable = index;
179✔
1484
      } else {
1485
        qError("vgId:%d uid:%" PRIu64 " not found in table list, total:%d, index:%d %s", pTaskInfo->id.vgId, uid,
×
1486
               numOfTables, pScanInfo->currentTable, id);
1487
        return TSDB_CODE_TMQ_NO_TABLE_QUALIFIED;
×
1488
      }
1489

1490
      STableKeyInfo keyInfo = {.uid = uid};
179✔
1491
      int64_t       oldSkey = pScanBaseInfo->cond.twindows.skey;
179✔
1492

1493
      // let's start from the next ts that returned to consumer.
1494
      if (pTaskInfo->storageAPI.tqReaderFn.tqGetTablePrimaryKey(pInfo->tqReader)) {
179!
1495
        pScanBaseInfo->cond.twindows.skey = ts;
×
1496
      } else {
1497
        pScanBaseInfo->cond.twindows.skey = ts + 1;
179✔
1498
      }
1499
      pScanInfo->scanTimes = 0;
179✔
1500

1501
      if (pScanBaseInfo->dataReader == NULL) {
179✔
1502
        code = pTaskInfo->storageAPI.tsdReader.tsdReaderOpen(pScanBaseInfo->readHandle.vnode, &pScanBaseInfo->cond,
160✔
1503
                                                             &keyInfo, 1, pScanInfo->pResBlock,
1504
                                                             (void**)&pScanBaseInfo->dataReader, id, NULL);
160✔
1505
        if (code != TSDB_CODE_SUCCESS) {
160!
1506
          qError("prepare read tsdb snapshot failed, uid:%" PRId64 ", code:%s %s", pOffset->uid, tstrerror(code), id);
×
1507
          return code;
×
1508
        }
1509

1510
        qDebug("tsdb reader created with offset(snapshot) uid:%" PRId64 " ts:%" PRId64 " table index:%d, total:%d, %s",
160✔
1511
               uid, pScanBaseInfo->cond.twindows.skey, pScanInfo->currentTable, numOfTables, id);
1512
      } else {
1513
        code = pTaskInfo->storageAPI.tsdReader.tsdSetQueryTableList(pScanBaseInfo->dataReader, &keyInfo, 1);
19✔
1514
        if (code != TSDB_CODE_SUCCESS) {
19!
1515
          qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1516
          return code;
×
1517
        }
1518

1519
        code = pTaskInfo->storageAPI.tsdReader.tsdReaderResetStatus(pScanBaseInfo->dataReader, &pScanBaseInfo->cond);
19✔
1520
        if (code != TSDB_CODE_SUCCESS) {
19!
1521
          qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1522
          return code;
×
1523
        }
1524
        qDebug("tsdb reader offset seek snapshot to uid:%" PRId64 " ts %" PRId64 "  table index:%d numOfTable:%d, %s",
19!
1525
               uid, pScanBaseInfo->cond.twindows.skey, pScanInfo->currentTable, numOfTables, id);
1526
      }
1527

1528
      // restore the key value
1529
      pScanBaseInfo->cond.twindows.skey = oldSkey;
179✔
1530
    } else {
UNCOV
1531
      qError("invalid pOffset->type:%d, %s", pOffset->type, id);
×
1532
      return TSDB_CODE_PAR_INTERNAL_ERROR;
×
1533
    }
1534

1535
  } else {  // subType == TOPIC_SUB_TYPE__TABLE/TOPIC_SUB_TYPE__DB
1536
    if (pOffset->type == TMQ_OFFSET__SNAPSHOT_DATA) {
2,558✔
1537
      SStreamRawScanInfo* pInfo = pOperator->info;
2,512✔
1538
      SSnapContext*       sContext = pInfo->sContext;
2,512✔
1539
      SOperatorInfo*      p = NULL;
2,512✔
1540

1541
      code = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN, id, &p);
2,512✔
1542
      if (code != 0) {
2,511!
1543
        return code;
×
1544
      }
1545

1546
      STableListInfo* pTableListInfo = ((SStreamRawScanInfo*)(p->info))->pTableListInfo;
2,511✔
1547

1548
      if (pAPI->snapshotFn.setForSnapShot(sContext, pOffset->uid) != 0) {
2,511!
1549
        qError("setDataForSnapShot error. uid:%" PRId64 " , %s", pOffset->uid, id);
×
1550
        return TSDB_CODE_PAR_INTERNAL_ERROR;
×
1551
      }
1552

1553
      SMetaTableInfo mtInfo = {0};
2,511✔
1554
      code = pTaskInfo->storageAPI.snapshotFn.getMetaTableInfoFromSnapshot(sContext, &mtInfo);
2,511✔
1555
      if (code != 0) {
2,511!
1556
        destroyMetaTableInfo(&mtInfo);
1557
        return code;
×
1558
      }
1559
      pTaskInfo->storageAPI.tsdReader.tsdReaderClose(pInfo->dataReader);
2,511✔
1560
      pInfo->dataReader = NULL;
2,512✔
1561

1562
      cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
2,512✔
1563
      tableListClear(pTableListInfo);
2,512✔
1564

1565
      if (mtInfo.uid == 0) {
2,512✔
1566
        destroyMetaTableInfo(&mtInfo);
1567
        goto end;  // no data
5✔
1568
      }
1569

1570
      pAPI->snapshotFn.taosXSetTablePrimaryKey(sContext, mtInfo.uid);
2,507✔
1571
      code = initQueryTableDataCondForTmq(&pTaskInfo->streamInfo.tableCond, sContext, &mtInfo);
2,507✔
1572
      if (code != TSDB_CODE_SUCCESS) {
2,507!
1573
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1574
        destroyMetaTableInfo(&mtInfo);
1575
        return code;
×
1576
      }
1577
      if (pAPI->snapshotFn.taosXGetTablePrimaryKey(sContext)) {
2,507!
1578
        pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts;
×
1579
      } else {
1580
        pTaskInfo->streamInfo.tableCond.twindows.skey = pOffset->ts + 1;
2,507✔
1581
      }
1582

1583
      code = tableListAddTableInfo(pTableListInfo, mtInfo.uid, 0);
2,507✔
1584
      if (code != TSDB_CODE_SUCCESS) {
2,507!
1585
        destroyMetaTableInfo(&mtInfo);
1586
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1587
        return code;
×
1588
      }
1589

1590
      STableKeyInfo* pList = tableListGetInfo(pTableListInfo, 0);
2,507✔
1591
      if (!pList) {
2,507!
1592
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1593
        destroyMetaTableInfo(&mtInfo);
1594
        return code;
×
1595
      }
1596
      int32_t size = 0;
2,507✔
1597
      code = tableListGetSize(pTableListInfo, &size);
2,507✔
1598
      if (code != TSDB_CODE_SUCCESS) {
2,506!
1599
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1600
        destroyMetaTableInfo(&mtInfo);
1601
        return code;
×
1602
      }
1603

1604
      code = pTaskInfo->storageAPI.tsdReader.tsdReaderOpen(pInfo->vnode, &pTaskInfo->streamInfo.tableCond, pList, size,
2,506✔
1605
                                                           NULL, (void**)&pInfo->dataReader, NULL, NULL);
2,506✔
1606
      if (code != TSDB_CODE_SUCCESS) {
2,507!
1607
        qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(code));
×
1608
        destroyMetaTableInfo(&mtInfo);
1609
        return code;
×
1610
      }
1611

1612
      cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
2,507✔
1613
      tstrncpy(pTaskInfo->streamInfo.tbName, mtInfo.tbName, TSDB_TABLE_NAME_LEN);
2,507✔
1614
//      pTaskInfo->streamInfo.suid = mtInfo.suid == 0 ? mtInfo.uid : mtInfo.suid;
1615
      tDeleteSchemaWrapper(pTaskInfo->streamInfo.schema);
2,507✔
1616
      pTaskInfo->streamInfo.schema = mtInfo.schema;
2,507✔
1617

1618
      qDebug("tmqsnap qStreamPrepareScan snapshot data uid:%" PRId64 " ts %" PRId64 " %s", mtInfo.uid, pOffset->ts, id);
2,507✔
1619
    } else if (pOffset->type == TMQ_OFFSET__SNAPSHOT_META) {
46✔
1620
      SStreamRawScanInfo* pInfo = pOperator->info;
16✔
1621
      SSnapContext*       sContext = pInfo->sContext;
16✔
1622
      code = pTaskInfo->storageAPI.snapshotFn.setForSnapShot(sContext, pOffset->uid);
16✔
1623
      if (code != 0) {
16!
1624
        qError("setForSnapShot error. uid:%" PRIu64 " ,version:%" PRId64, pOffset->uid, pOffset->version);
×
1625
        return code;
×
1626
      }
1627
      qDebug("tmqsnap qStreamPrepareScan snapshot meta uid:%" PRId64 " ts %" PRId64 " %s", pOffset->uid, pOffset->ts,
16!
1628
             id);
1629
    } else if (pOffset->type == TMQ_OFFSET__LOG) {
30!
1630
      SStreamRawScanInfo* pInfo = pOperator->info;
30✔
1631
      pTaskInfo->storageAPI.tsdReader.tsdReaderClose(pInfo->dataReader);
30✔
1632
      pInfo->dataReader = NULL;
30✔
1633
      qDebug("tmqsnap qStreamPrepareScan snapshot log, %s", id);
30✔
1634
    }
1635
  }
1636

1637
end:
14✔
1638
  tOffsetCopy(&pTaskInfo->streamInfo.currentOffset, pOffset);
8,306✔
1639
  return 0;
8,306✔
1640
}
1641

1642
void qProcessRspMsg(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet) {
5,639,729✔
1643
  SMsgSendInfo* pSendInfo = (SMsgSendInfo*)pMsg->info.ahandle;
5,639,729✔
1644
  if (pMsg->info.ahandle == NULL) {
5,639,729!
1645
    qError("pMsg->info.ahandle is NULL");
×
1646
    return;
×
1647
  }
1648

1649
  SDataBuf buf = {.len = pMsg->contLen, .pData = NULL};
5,639,729✔
1650

1651
  if (pMsg->contLen > 0) {
5,639,729!
1652
    buf.pData = taosMemoryCalloc(1, pMsg->contLen);
5,639,934!
1653
    if (buf.pData == NULL) {
5,642,121!
1654
      pMsg->code = terrno;
×
1655
    } else {
1656
      memcpy(buf.pData, pMsg->pCont, pMsg->contLen);
5,642,121✔
1657
    }
1658
  }
1659

1660
  (void)pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
5,641,916✔
1661
  rpcFreeCont(pMsg->pCont);
5,650,875✔
1662
  destroySendMsgInfo(pSendInfo);
5,650,936✔
1663
}
1664

1665
SArray* qGetQueriedTableListInfo(qTaskInfo_t tinfo) {
×
1666
  int32_t        code = TSDB_CODE_SUCCESS;
×
1667
  int32_t        lino = 0;
×
1668
  SExecTaskInfo* pTaskInfo = tinfo;
×
1669
  SArray*        plist = NULL;
×
1670

1671
  code = getTableListInfo(pTaskInfo, &plist);
×
1672
  if (code || plist == NULL) {
×
1673
    return NULL;
×
1674
  }
1675

1676
  // only extract table in the first elements
1677
  STableListInfo* pTableListInfo = taosArrayGetP(plist, 0);
×
1678

1679
  SArray* pUidList = taosArrayInit(10, sizeof(uint64_t));
×
1680
  QUERY_CHECK_NULL(pUidList, code, lino, _end, terrno);
×
1681

1682
  int32_t numOfTables = 0;
×
1683
  code = tableListGetSize(pTableListInfo, &numOfTables);
×
1684
  QUERY_CHECK_CODE(code, lino, _end);
×
1685

1686
  for (int32_t i = 0; i < numOfTables; ++i) {
×
1687
    STableKeyInfo* pKeyInfo = tableListGetInfo(pTableListInfo, i);
×
1688
    QUERY_CHECK_NULL(pKeyInfo, code, lino, _end, terrno);
×
1689
    void* tmp = taosArrayPush(pUidList, &pKeyInfo->uid);
×
1690
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
1691
  }
1692

1693
  taosArrayDestroy(plist);
×
1694

1695
_end:
×
1696
  if (code != TSDB_CODE_SUCCESS) {
×
1697
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1698
    T_LONG_JMP(pTaskInfo->env, code);
×
1699
  }
1700
  return pUidList;
×
1701
}
1702

1703
static int32_t extractTableList(SArray* pList, const SOperatorInfo* pOperator) {
224,272✔
1704
  int32_t        code = TSDB_CODE_SUCCESS;
224,272✔
1705
  int32_t        lino = 0;
224,272✔
1706
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
224,272✔
1707

1708
  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
224,272!
1709
    SStreamScanInfo* pScanInfo = pOperator->info;
×
1710
    STableScanInfo*  pTableScanInfo = pScanInfo->pTableScanOp->info;
×
1711

1712
    void* tmp = taosArrayPush(pList, &pTableScanInfo->base.pTableListInfo);
×
1713
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
1714
  } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
224,272✔
1715
    STableScanInfo* pScanInfo = pOperator->info;
112,139✔
1716

1717
    void* tmp = taosArrayPush(pList, &pScanInfo->base.pTableListInfo);
112,139✔
1718
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
112,137!
1719
  } else {
1720
    if (pOperator->pDownstream != NULL && pOperator->pDownstream[0] != NULL) {
112,133!
1721
      code = extractTableList(pList, pOperator->pDownstream[0]);
112,138✔
1722
    }
1723
  }
1724

1725
_end:
×
1726
  if (code != TSDB_CODE_SUCCESS) {
224,267!
1727
    qError("%s %s failed at line %d since %s", pTaskInfo->id.str, __func__, lino, tstrerror(code));
×
1728
  }
1729
  return code;
224,269✔
1730
}
1731

1732
int32_t getTableListInfo(const SExecTaskInfo* pTaskInfo, SArray** pList) {
112,137✔
1733
  if (pList == NULL) {
112,137!
1734
    return TSDB_CODE_INVALID_PARA;
×
1735
  }
1736

1737
  *pList = NULL;
112,137✔
1738
  SArray* pArray = taosArrayInit(0, POINTER_BYTES);
112,137✔
1739
  if (pArray == NULL) {
112,142!
1740
    return terrno;
×
1741
  }
1742

1743
  int32_t code = extractTableList(pArray, pTaskInfo->pRoot);
112,142✔
1744
  if (code == 0) {
112,135!
1745
    *pList = pArray;
112,136✔
1746
  } else {
1747
    taosArrayDestroy(pArray);
×
1748
  }
1749
  return code;
112,137✔
1750
}
1751

1752
int32_t qStreamOperatorReleaseState(qTaskInfo_t tInfo) {
2,168✔
1753
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tInfo;
2,168✔
1754
  if (pTaskInfo->pRoot->fpSet.releaseStreamStateFn != NULL) {
2,168!
1755
    pTaskInfo->pRoot->fpSet.releaseStreamStateFn(pTaskInfo->pRoot);
2,168✔
1756
  }
1757
  return 0;
2,168✔
1758
}
1759

1760
int32_t qStreamOperatorReloadState(qTaskInfo_t tInfo) {
2,168✔
1761
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tInfo;
2,168✔
1762
  if (pTaskInfo->pRoot->fpSet.reloadStreamStateFn != NULL) {
2,168!
1763
    pTaskInfo->pRoot->fpSet.reloadStreamStateFn(pTaskInfo->pRoot);
2,168✔
1764
  }
1765
  return 0;
2,168✔
1766
}
1767

1768
void qResetTaskCode(qTaskInfo_t tinfo) {
27✔
1769
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
27✔
1770

1771
  int32_t code = pTaskInfo->code;
27✔
1772
  pTaskInfo->code = 0;
27✔
1773
  qDebug("0x%" PRIx64 " reset task code to be success, prev:%s", pTaskInfo->id.taskId, tstrerror(code));
27✔
1774
}
27✔
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