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

taosdata / TDengine / #4103

17 May 2025 02:18AM UTC coverage: 63.264% (+0.4%) from 62.905%
#4103

push

travis-ci

web-flow
Merge pull request #31110 from taosdata/3.0

merge 3.0

158149 of 318142 branches covered (49.71%)

Branch coverage included in aggregate %.

3 of 5 new or added lines in 1 file covered. (60.0%)

1725 existing lines in 138 files now uncovered.

243642 of 316962 relevant lines covered (76.87%)

16346281.8 hits per line

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

64.05
/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,922✔
33
  int32_t ref = atomic_val_compare_exchange_32(&exchangeObjRefPool, exchangeObjRefPool, 0);
2,922✔
34
  taosCloseRef(ref);
2,922✔
35
}
2,922✔
36

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

42
static int32_t doSetSMABlock(SOperatorInfo* pOperator, void* input, size_t numOfBlocks, int32_t type, char* id) {
2,644✔
43
  int32_t code = TSDB_CODE_SUCCESS;
2,644✔
44
  int32_t lino = 0;
2,644✔
45
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
2,644✔
46
    if (pOperator->numOfDownstream == 0) {
1,322!
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
1,322!
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;
1,322✔
56
    return doSetSMABlock(pOperator->pDownstream[0], input, numOfBlocks, type, id);
1,322✔
57
  } else {
58
    pOperator->status = OP_NOT_OPENED;
1,322✔
59

60
    SStreamScanInfo* pInfo = pOperator->info;
1,322✔
61

62
    if (type == STREAM_INPUT__MERGED_SUBMIT) {
1,322✔
63
      for (int32_t i = 0; i < numOfBlocks; i++) {
2,448✔
64
        SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
1,224✔
65
        void*        tmp = taosArrayPush(pInfo->pBlockLists, pReq);
1,224✔
66
        QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
1,224!
67
      }
68
      pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
1,224✔
69
    } else if (type == STREAM_INPUT__DATA_SUBMIT) {
98!
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) {
98✔
74
      for (int32_t i = 0; i < numOfBlocks; ++i) {
84✔
75
        SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
42✔
76
        SPackedData  tmp = {.pDataBlock = pDataBlock};
42✔
77
        void*        tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
42✔
78
        QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
42!
79
      }
80
      pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
42✔
81
    } else if (type == STREAM_INPUT__CHECKPOINT) {
56✔
82
      SPackedData tmp = {.pDataBlock = input};
40✔
83
      void*       tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
40✔
84
      QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
40!
85
      pInfo->blockType = STREAM_INPUT__CHECKPOINT;
40✔
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;
1,322✔
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) {
4,461✔
106
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
4,461✔
107
    if (pOperator->numOfDownstream == 0) {
2,673!
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
2,673!
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;
2,673✔
118
    return doSetStreamOpOpen(pOperator->pDownstream[0], id);
2,673✔
119
  }
120
  return 0;
1,788✔
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,
106,437✔
141
                                const char* id) {
142
  int32_t code = TSDB_CODE_SUCCESS;
106,437✔
143
  int32_t lino = 0;
106,437✔
144
  if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
106,437✔
145
    if (pOperator->numOfDownstream == 0) {
66,125!
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
66,125!
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;
66,125✔
155
    return doSetStreamBlock(pOperator->pDownstream[0], input, numOfBlocks, type, id);
66,125✔
156
  } else {
157
    pOperator->status = OP_NOT_OPENED;
40,312✔
158
    SStreamScanInfo* pInfo = pOperator->info;
40,312✔
159

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

164
    if (type == STREAM_INPUT__MERGED_SUBMIT) {
40,349✔
165
      for (int32_t i = 0; i < numOfBlocks; i++) {
500,094✔
166
        SPackedData* pReq = POINTER_SHIFT(input, i * sizeof(SPackedData));
476,920✔
167
        void*        tmp = taosArrayPush(pInfo->pBlockLists, pReq);
476,920✔
168
        QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
476,908!
169
      }
170

171
      pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
23,174✔
172
    } else if (type == STREAM_INPUT__DATA_SUBMIT) {
17,163✔
173
      void* tmp = taosArrayPush(pInfo->pBlockLists, input);
6,092✔
174
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
6,079!
175

176
      pInfo->blockType = STREAM_INPUT__DATA_SUBMIT;
6,079✔
177
    } else if (type == STREAM_INPUT__DATA_BLOCK) {
11,071✔
178
      for (int32_t i = 0; i < numOfBlocks; ++i) {
21,565✔
179
        SSDataBlock* pDataBlock = &((SSDataBlock*)input)[i];
12,284✔
180
        SPackedData  tmp = {.pDataBlock = pDataBlock};
12,284✔
181
        void*        tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
12,284✔
182
        QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
12,284!
183
        uTrace("%s,parName:%s, groupId:%"PRIu64, __FUNCTION__, pDataBlock->info.parTbName, pDataBlock->info.id.groupId)
12,284✔
184
      }
185

186
      pInfo->blockType = STREAM_INPUT__DATA_BLOCK;
9,281✔
187
    } else if (type == STREAM_INPUT__CHECKPOINT_TRIGGER || type == STREAM_INPUT__RECALCULATE) {
1,791!
188
      SPackedData tmp = {.pDataBlock = input};
1,791✔
189
      void*       tmpItem = taosArrayPush(pInfo->pBlockLists, &tmp);
1,791✔
190
      QUERY_CHECK_NULL(tmpItem, code, lino, _end, terrno);
1,796!
191

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

199
    return TSDB_CODE_SUCCESS;
40,330✔
200
  }
201

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

209
int32_t doSetTaskId(SOperatorInfo* pOperator, SStorageAPI* pAPI) {
638,216✔
210
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
638,216✔
211
  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
638,216✔
212
    SStreamScanInfo* pStreamScanInfo = pOperator->info;
317,301✔
213
    if (pStreamScanInfo->pTableScanOp != NULL) {
317,301✔
214
      STableScanInfo* pScanInfo = pStreamScanInfo->pTableScanOp->info;
317,027✔
215
      if (pScanInfo->base.dataReader != NULL) {
317,027✔
216
        int32_t code = pAPI->tsdReader.tsdSetReaderTaskId(pScanInfo->base.dataReader, pTaskInfo->id.str);
920✔
217
        if (code) {
920!
UNCOV
218
          qError("failed to set reader id for executor, code:%s", tstrerror(code));
×
219
          return code;
×
220
        }
221
      }
222
    }
223
  } else {
224
    return doSetTaskId(pOperator->pDownstream[0], pAPI);
320,915✔
225
  }
226

227
  return 0;
317,301✔
228
}
229

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

235
  // set the idstr for tsdbReader
236
  return doSetTaskId(pTaskInfo->pRoot, &pTaskInfo->storageAPI);
317,301✔
237
}
238

239
int32_t qSetStreamOpOpen(qTaskInfo_t tinfo) {
1,789✔
240
  if (tinfo == NULL) {
1,789!
241
    return TSDB_CODE_APP_ERROR;
×
242
  }
243

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

252
  return code;
1,789✔
253
}
254

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

260
  if (tinfo == 0 || eventTypes == 0 || pSchemaWrapper == NULL || stbFullName == NULL) {
6,357!
261
    goto _end;
6,357✔
262
  }
263

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

274
_end:
6,357✔
275
  return code;
6,357✔
276
}
277

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

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

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

292
  if (pBlocks == NULL || numOfBlocks == 0) {
40,328!
293
    return TSDB_CODE_SUCCESS;
×
294
  }
295

296
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
40,351✔
297

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

305
  return code;
40,332✔
306
}
307

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

313
  if (pBlocks == NULL || numOfBlocks == 0) {
1,322!
314
    return TSDB_CODE_SUCCESS;
×
315
  }
316

317
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
1,322✔
318

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

326
  return code;
1,322✔
327
}
328

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

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

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

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

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

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

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

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

377
  return pTaskInfo;
1,267✔
378
}
379

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

385
  *pTaskInfo = NULL;
6,403✔
386

387
  SSubplan* pPlan = NULL;
6,403✔
388
  int32_t   code = qStringToSubplan(msg, &pPlan);
6,403✔
389
  if (code != TSDB_CODE_SUCCESS) {
6,401!
390
    return code;
×
391
  }
392

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

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

404
  return code;
6,402✔
405
}
406

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

419
  STableScanInfo* pTableScanInfo = pScanInfo->pTableScanOp->info;
18,858✔
420

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

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

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

439
    tDecoderClear(&mr.coder);
38,545✔
440

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

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

467
      if (!qualified) {
956✔
468
        continue;
478✔
469
      }
470
    }
471

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

477
_end:
18,857✔
478

479
  pAPI->metaReaderFn.clearReader(&mr);
18,857✔
480
  (*ppArrayRes) = qa;
18,859✔
481

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

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

494
  if (isAdd) {
20,730✔
495
    qDebug("try to add %d tables id into query list, %s", (int32_t)taosArrayGetSize(tableIdList), id);
20,568✔
496
  }
497

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

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

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

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

537
    STableListInfo* pTableListInfo = ((STableScanInfo*)pScanInfo->pTableScanOp->info)->base.pTableListInfo;
20,561✔
538
    taosWLockLatch(&pTaskInfo->lock);
20,561✔
539

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

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

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

574
    taosWUnLockLatch(&pTaskInfo->lock);
20,558✔
575
    if (keyBuf != NULL) {
20,564✔
576
      taosMemoryFree(keyBuf);
8,917!
577
    }
578

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

587
  return code;
20,720✔
588
}
589

590
int32_t qGetQueryTableSchemaVersion(qTaskInfo_t tinfo, char* dbName, int32_t dbNameBuffLen, char* tableName,
13,245,139✔
591
                                    int32_t tbaleNameBuffLen, int32_t* sversion, int32_t* tversion, int32_t* rversion,
592
                                    int32_t idx, bool* tbGet) {
593
  *tbGet = false;
13,245,139✔
594

595
  if (tinfo == NULL || dbName == NULL || tableName == NULL) {
13,245,139!
596
    return TSDB_CODE_INVALID_PARA;
×
597
  }
598
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
13,248,081✔
599

600
  if (taosArrayGetSize(pTaskInfo->schemaInfos) <= idx) {
13,248,081✔
601
    return TSDB_CODE_SUCCESS;
8,223,095✔
602
  }
603

604
  SSchemaInfo* pSchemaInfo = taosArrayGet(pTaskInfo->schemaInfos, idx);
5,023,005✔
605
  if (!pSchemaInfo) {
5,026,866!
606
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
×
607
    return terrno;
×
608
  }
609

610
  *sversion = pSchemaInfo->sw->version;
5,030,998✔
611
  *tversion = pSchemaInfo->tversion;
5,030,998✔
612
  *rversion = pSchemaInfo->rversion;
5,030,998✔
613
  if (pSchemaInfo->dbname) {
5,030,998!
614
    tstrncpy(dbName, pSchemaInfo->dbname, dbNameBuffLen);
5,030,998✔
615
  } else {
616
    dbName[0] = 0;
×
617
  }
618
  if (pSchemaInfo->tablename) {
5,030,998!
619
    tstrncpy(tableName, pSchemaInfo->tablename, tbaleNameBuffLen);
5,033,278✔
620
  } else {
UNCOV
621
    tableName[0] = 0;
×
622
  }
623

624
  *tbGet = true;
5,030,998✔
625

626
  return TSDB_CODE_SUCCESS;
5,030,998✔
627
}
628

629
bool qIsDynamicExecTask(qTaskInfo_t tinfo) { return ((SExecTaskInfo*)tinfo)->dynamicTask; }
8,224,988✔
630

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

638
void qUpdateOperatorParam(qTaskInfo_t tinfo, void* pParam) {
1,281✔
639
  TSWAP(pParam, ((SExecTaskInfo*)tinfo)->pOpParam);
1,281✔
640
  ((SExecTaskInfo*)tinfo)->paramSet = false;
1,281✔
641
}
1,281✔
642

643
int32_t qExecutorInit(void) {
18,739✔
644
  (void)taosThreadOnce(&initPoolOnce, initRefPool);
18,739✔
645
  return TSDB_CODE_SUCCESS;
18,748✔
646
}
647

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

654
  qDebug("start to create task, TID:0x%" PRIx64 " QID:0x%" PRIx64 ", vgId:%d", taskId, pSubplan->id.queryId, vgId);
8,386,694✔
655

656
  int32_t code = createExecTaskInfo(pSubplan, pTask, readHandle, taskId, vgId, sql, model);
8,386,785✔
657
  if (code != TSDB_CODE_SUCCESS || NULL == *pTask) {
8,383,797!
658
    qError("failed to createExecTaskInfo, code:%s", tstrerror(code));
×
659
    goto _error;
361✔
660
  }
661

662
  if (handle) {
8,389,614✔
663
    SDataSinkMgtCfg cfg = {.maxDataBlockNum = 500, .maxDataBlockNumPerQuery = 50, .compress = compressResult};
8,377,858✔
664
    void*           pSinkManager = NULL;
8,377,858✔
665
    code = dsDataSinkMgtInit(&cfg, &(*pTask)->storageAPI, &pSinkManager);
8,377,858✔
666
    if (code != TSDB_CODE_SUCCESS) {
8,380,712!
667
      qError("failed to dsDataSinkMgtInit, code:%s, %s", tstrerror(code), (*pTask)->id.str);
×
668
      goto _error;
×
669
    }
670

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

679
    SDataSinkNode* pSink = NULL;
8,370,436✔
680
    if (readHandle->localExec) {
8,370,436✔
681
      code = nodesCloneNode((SNode *)pSubplan->pDataSink, (SNode **)&pSink);
73,698✔
682
      if (code != TSDB_CODE_SUCCESS) {
73,734✔
683
        qError("failed to nodesCloneNode, srcType:%d, code:%s, %s", nodeType(pSubplan->pDataSink), tstrerror(code), (*pTask)->id.str);
2,958!
684
        taosMemoryFree(pSinkManager);
2,958!
685
        goto _error;
×
686
      }
687
    }
688

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

696
  qDebug("subplan task create completed, TID:0x%" PRIx64 " QID:0x%" PRIx64 " code:%s", taskId, pSubplan->id.queryId,
8,381,849✔
697
         tstrerror(code));
698

699
_error:
8,145,843✔
700
  // if failed to add ref for all tables in this query, abort current query
701
  return code;
8,377,192✔
702
}
703

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

709
int32_t qExecTaskOpt(qTaskInfo_t tinfo, SArray* pResList, uint64_t* useconds, bool* hasMore, SLocalFetch* pLocal, bool processOneBlock) {
9,148,083✔
710
  int32_t        code = TSDB_CODE_SUCCESS;
9,148,083✔
711
  int32_t        lino = 0;
9,148,083✔
712
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
9,148,083✔
713
  int64_t        threadId = taosGetSelfPthreadId();
9,148,083✔
714

715
  if (pLocal) {
9,148,451✔
716
    memcpy(&pTaskInfo->localFetch, pLocal, sizeof(*pLocal));
9,147,648✔
717
  }
718

719
  taosArrayClear(pResList);
9,148,451✔
720

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

728
  if (pTaskInfo->cost.start == 0) {
9,158,926✔
729
    pTaskInfo->cost.start = taosGetTimestampUs();
8,341,961✔
730
  }
731

732
  if (isTaskKilled(pTaskInfo)) {
9,163,407✔
733
    atomic_store_64(&pTaskInfo->owner, 0);
5✔
734
    qDebug("%s already killed, abort", GET_TASKID(pTaskInfo));
5!
735
    return pTaskInfo->code;
5✔
736
  }
737

738
  // error occurs, record the error code and return to client
739
  int32_t ret = setjmp(pTaskInfo->env);
9,147,549✔
740
  if (ret != TSDB_CODE_SUCCESS) {
9,147,534✔
741
    pTaskInfo->code = ret;
15,698✔
742
    (void)cleanUpUdfs();
15,698✔
743

744
    qDebug("%s task abort due to error/cancel occurs, code:%s", GET_TASKID(pTaskInfo), tstrerror(pTaskInfo->code));
15,699✔
745
    atomic_store_64(&pTaskInfo->owner, 0);
15,699✔
746

747
    return pTaskInfo->code;
15,699✔
748
  }
749

750
  qDebug("%s execTask is launched", GET_TASKID(pTaskInfo));
9,131,836✔
751

752
  int32_t      current = 0;
9,131,838✔
753
  SSDataBlock* pRes = NULL;
9,131,838✔
754
  int64_t      st = taosGetTimestampUs();
9,148,087✔
755

756
  if (pTaskInfo->pOpParam && !pTaskInfo->paramSet) {
9,148,087!
757
    pTaskInfo->paramSet = true;
1,280✔
758
    code = pTaskInfo->pRoot->fpSet.getNextExtFn(pTaskInfo->pRoot, pTaskInfo->pOpParam, &pRes);
1,280✔
759
  } else {
760
    code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, &pRes);
9,146,807✔
761
  }
762

763
  QUERY_CHECK_CODE(code, lino, _end);
9,141,002!
764
  code = blockDataCheck(pRes);
9,141,002✔
765
  QUERY_CHECK_CODE(code, lino, _end);
9,141,740!
766

767
  if (pRes == NULL) {
9,141,740✔
768
    st = taosGetTimestampUs();
2,329,155✔
769
  }
770

771
  int32_t rowsThreshold = pTaskInfo->pSubplan->rowsThreshold;
9,142,413✔
772
  if (!pTaskInfo->pSubplan->dynamicRowThreshold || 4096 <= pTaskInfo->pSubplan->rowsThreshold) {
9,142,413✔
773
    rowsThreshold = 4096;
9,123,043✔
774
  }
775

776
  int32_t blockIndex = 0;
9,142,413✔
777
  while (pRes != NULL) {
22,960,172✔
778
    SSDataBlock* p = NULL;
14,632,680✔
779
    if (blockIndex >= taosArrayGetSize(pTaskInfo->pResultBlockList)) {
14,632,680✔
780
      SSDataBlock* p1 = NULL;
11,523,229✔
781
      code = createOneDataBlock(pRes, true, &p1);
11,523,229✔
782
      QUERY_CHECK_CODE(code, lino, _end);
11,530,500!
783

784
      void* tmp = taosArrayPush(pTaskInfo->pResultBlockList, &p1);
11,530,500✔
785
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
11,530,058!
786
      p = p1;
11,530,058✔
787
    } else {
788
      void* tmp = taosArrayGet(pTaskInfo->pResultBlockList, blockIndex);
3,110,358✔
789
      QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
3,107,171!
790

791
      p = *(SSDataBlock**)tmp;
3,107,171✔
792
      code = copyDataBlock(p, pRes);
3,107,171✔
793
      QUERY_CHECK_CODE(code, lino, _end);
3,152,684!
794
    }
795

796
    blockIndex += 1;
14,682,742✔
797

798
    current += p->info.rows;
14,682,742✔
799
    QUERY_CHECK_CONDITION((p->info.rows > 0 || p->info.type == STREAM_CHECKPOINT), code, lino, _end,
14,682,742!
800
                          TSDB_CODE_QRY_EXECUTOR_INTERNAL_ERROR);
801
    void* tmp = taosArrayPush(pResList, &p);
14,672,205✔
802
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
14,672,205!
803

804
    if (current >= rowsThreshold || processOneBlock) {
14,672,205✔
805
      break;
806
    }
807

808
    code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, &pRes);
13,857,446✔
809
    QUERY_CHECK_CODE(code, lino, _end);
13,826,668!
810
    code = blockDataCheck(pRes);
13,826,668✔
811
    QUERY_CHECK_CODE(code, lino, _end);
13,817,759!
812
  }
813

814
  if (pTaskInfo->pSubplan->dynamicRowThreshold) {
9,142,251✔
815
    pTaskInfo->pSubplan->rowsThreshold -= current;
19,712✔
816
  }
817

818
  *hasMore = (pRes != NULL);
9,142,251✔
819
  uint64_t el = (taosGetTimestampUs() - st);
9,143,102✔
820

821
  pTaskInfo->cost.elapsedTime += el;
9,143,102✔
822
  if (NULL == pRes) {
9,143,102✔
823
    *useconds = pTaskInfo->cost.elapsedTime;
8,326,722✔
824
  }
825

826
_end:
816,380✔
827
  (void)cleanUpUdfs();
9,143,102✔
828

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

833
  atomic_store_64(&pTaskInfo->owner, 0);
9,145,301✔
834
  if (code) {
9,145,267!
835
    pTaskInfo->code = code;
×
836
    qError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
837
  }
838

839
  return pTaskInfo->code;
9,145,147✔
840
}
841

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

853
  taosArrayClear(pTaskInfo->pResultBlockList);
1,362✔
854
}
1,362✔
855

856
int32_t qExecTask(qTaskInfo_t tinfo, SSDataBlock** pRes, uint64_t* useconds) {
812,279✔
857
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
812,279✔
858
  int64_t        threadId = taosGetSelfPthreadId();
812,279✔
859
  int64_t        curOwner = 0;
812,281✔
860

861
  *pRes = NULL;
812,281✔
862

863
  // todo extract method
864
  taosRLockLatch(&pTaskInfo->lock);
812,281✔
865
  bool isKilled = isTaskKilled(pTaskInfo);
812,312✔
866
  if (isKilled) {
812,290!
867
    clearStreamBlock(pTaskInfo->pRoot);
×
868
    qDebug("%s already killed, abort", GET_TASKID(pTaskInfo));
×
869

870
    taosRUnLockLatch(&pTaskInfo->lock);
×
871
    return pTaskInfo->code;
×
872
  }
873

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

878
    taosRUnLockLatch(&pTaskInfo->lock);
×
879
    return pTaskInfo->code;
×
880
  }
881

882
  pTaskInfo->owner = threadId;
812,290✔
883
  taosRUnLockLatch(&pTaskInfo->lock);
812,290✔
884

885
  if (pTaskInfo->cost.start == 0) {
812,309✔
886
    pTaskInfo->cost.start = taosGetTimestampUs();
6,702✔
887
  }
888

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

899
  qDebug("%s execTask is launched", GET_TASKID(pTaskInfo));
812,256✔
900

901
  int64_t st = taosGetTimestampUs();
812,293✔
902

903
  int32_t code = pTaskInfo->pRoot->fpSet.getNextFn(pTaskInfo->pRoot, pRes);
812,293✔
904
  if (code) {
811,772!
905
    pTaskInfo->code = code;
×
906
    qError("%s failed at line %d, code:%s %s", __func__, __LINE__, tstrerror(code), GET_TASKID(pTaskInfo));
×
907
  }
908

909
  code = blockDataCheck(*pRes);
811,772✔
910
  if (code) {
811,906!
911
    pTaskInfo->code = code;
×
912
    qError("%s failed at line %d, code:%s %s", __func__, __LINE__, tstrerror(code), GET_TASKID(pTaskInfo));
×
913
  }
914

915
  uint64_t el = (taosGetTimestampUs() - st);
812,026✔
916

917
  pTaskInfo->cost.elapsedTime += el;
812,026✔
918
  if (NULL == *pRes) {
812,026✔
919
    *useconds = pTaskInfo->cost.elapsedTime;
120,086✔
920
  }
921

922
  (void) cleanUpUdfs();
812,026✔
923

924
  int32_t  current = (*pRes != NULL) ? (*pRes)->info.rows : 0;
812,319✔
925
  uint64_t total = pTaskInfo->pRoot->resultInfo.totalRows;
812,319✔
926

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

930
  atomic_store_64(&pTaskInfo->owner, 0);
812,319✔
931
  return pTaskInfo->code;
812,319✔
932
}
933

934
int32_t qAppendTaskStopInfo(SExecTaskInfo* pTaskInfo, SExchangeOpStopInfo* pInfo) {
3,732,528✔
935
  taosWLockLatch(&pTaskInfo->stopInfo.lock);
3,732,528✔
936
  void* tmp = taosArrayPush(pTaskInfo->stopInfo.pStopInfo, pInfo);
3,732,758✔
937
  taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
3,732,684✔
938

939
  if (!tmp) {
3,732,814✔
940
    qError("%s failed at line %d since %s", __func__, __LINE__, tstrerror(terrno));
49!
941
    return terrno;
49✔
942
  }
943
  return TSDB_CODE_SUCCESS;
3,732,765✔
944
}
945

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

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

956
  return 0;
×
957
}
958

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

968
void qStopTaskOperators(SExecTaskInfo* pTaskInfo) {
15,155✔
969
  taosWLockLatch(&pTaskInfo->stopInfo.lock);
15,155✔
970

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

991
  taosWUnLockLatch(&pTaskInfo->stopInfo.lock);
15,146✔
992
}
15,162✔
993

994
int32_t qAsyncKillTask(qTaskInfo_t qinfo, int32_t rspCode) {
15,160✔
995
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qinfo;
15,160✔
996
  if (pTaskInfo == NULL) {
15,160!
997
    return TSDB_CODE_QRY_INVALID_QHANDLE;
×
998
  }
999

1000
  qDebug("%s execTask async killed", GET_TASKID(pTaskInfo));
15,160✔
1001

1002
  setTaskKilled(pTaskInfo, rspCode);
15,160✔
1003
  qStopTaskOperators(pTaskInfo);
15,155✔
1004

1005
  return TSDB_CODE_SUCCESS;
15,161✔
1006
}
1007

1008
int32_t qKillTask(qTaskInfo_t tinfo, int32_t rspCode, int64_t waitDuration) {
6,356✔
1009
  int64_t        st = taosGetTimestampMs();
6,357✔
1010
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
6,357✔
1011
  if (pTaskInfo == NULL) {
6,357!
1012
    return TSDB_CODE_QRY_INVALID_QHANDLE;
×
1013
  }
1014

1015
  if (waitDuration > 0) {
6,357✔
1016
    qDebug("%s sync killed execTask, and waiting for at most %.2fs", GET_TASKID(pTaskInfo), waitDuration/1000.0);
1,459✔
1017
  } else {
1018
    qDebug("%s async killed execTask", GET_TASKID(pTaskInfo));
4,898✔
1019
  }
1020

1021
  setTaskKilled(pTaskInfo, TSDB_CODE_TSC_QUERY_KILLED);
6,357✔
1022

1023
  if (waitDuration > 0) {
6,357✔
1024
    while (1) {
1025
      taosWLockLatch(&pTaskInfo->lock);
1,461✔
1026
      if (qTaskIsExecuting(pTaskInfo)) {  // let's wait for 100 ms and try again
1,461✔
1027
        taosWUnLockLatch(&pTaskInfo->lock);
2✔
1028

1029
        taosMsleep(200);
2✔
1030

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

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

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

1058
  return 0 != atomic_load_64(&pTaskInfo->owner);
1,461✔
1059
}
1060

1061
static void printTaskExecCostInLog(SExecTaskInfo* pTaskInfo) {
8,396,263✔
1062
  STaskCostInfo* pSummary = &pTaskInfo->cost;
8,396,263✔
1063
  int64_t        idleTime = pSummary->start - pSummary->created;
8,396,263✔
1064

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

1080
void qDestroyTask(qTaskInfo_t qTaskHandle) {
8,396,653✔
1081
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)qTaskHandle;
8,396,653✔
1082
  if (pTaskInfo == NULL) {
8,396,653✔
1083
    return;
407✔
1084
  }
1085

1086
  if (pTaskInfo->pRoot != NULL) {
8,396,246!
1087
    qDebug("%s execTask completed, numOfRows:%" PRId64, GET_TASKID(pTaskInfo), pTaskInfo->pRoot->resultInfo.totalRows);
8,397,395✔
1088
  } else {
1089
    qDebug("%s execTask completed", GET_TASKID(pTaskInfo));
×
1090
  }
1091

1092
  printTaskExecCostInLog(pTaskInfo);  // print the query cost summary
8,396,246✔
1093
  doDestroyTask(pTaskInfo);
8,396,697✔
1094
}
1095

1096
int32_t qGetExplainExecInfo(qTaskInfo_t tinfo, SArray* pExecInfoList) {
582,218✔
1097
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
582,218✔
1098
  return getOperatorExplainExecInfo(pTaskInfo->pRoot, pExecInfoList);
582,218✔
1099
}
1100

1101
void qExtractStreamScanner(qTaskInfo_t tinfo, void** scanner) {
1,267✔
1102
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
1,267✔
1103
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
1,267✔
1104

1105
  while (1) {
1,158✔
1106
    uint16_t type = pOperator->operatorType;
2,425✔
1107
    if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
2,425✔
1108
      *scanner = pOperator->info;
1,267✔
1109
      break;
1,267✔
1110
    } else {
1111
      pOperator = pOperator->pDownstream[0];
1,158✔
1112
    }
1113
  }
1114
}
1,267✔
1115

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

1123
  SStreamTaskInfo* pStreamInfo = &pTaskInfo->streamInfo;
1,789✔
1124

1125
  pStreamInfo->fillHistoryVer = *pVerRange;
1,789✔
1126
  pStreamInfo->fillHistoryWindow = *pWindow;
1,789✔
1127
  pStreamInfo->recoverStep = STREAM_RECOVER_STEP__PREPARE1;
1,789✔
1128

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

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

1150
  SStreamTaskInfo* pStreamInfo = &pTaskInfo->streamInfo;
2,602✔
1151

1152
  pStreamInfo->fillHistoryVer = *pVerRange;
2,602✔
1153
  pStreamInfo->fillHistoryWindow = *pWindow;
2,602✔
1154
  pStreamInfo->recoverStep = STREAM_RECOVER_STEP__PREPARE2;
2,602✔
1155

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

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

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

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

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

1200
int32_t qSetStreamOperatorOptionForScanHistory(qTaskInfo_t tinfo) {
1,851✔
1201
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
1,851✔
1202
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
1,851✔
1203

1204
  while (1) {
2,777✔
1205
    int32_t type = pOperator->operatorType;
4,628✔
1206
    if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL || type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_INTERVAL ||
4,628✔
1207
        type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_INTERVAL ||
3,897✔
1208
        type == QUERY_NODE_PHYSICAL_PLAN_STREAM_MID_INTERVAL) {
742✔
1209
      SStreamIntervalOperatorInfo* pInfo = pOperator->info;
744✔
1210
      STimeWindowAggSupp*          pSup = &pInfo->twAggSup;
744✔
1211

1212
      qInfo("save stream param for interval: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
744!
1213

1214
      pSup->calTriggerSaved = pSup->calTrigger;
742✔
1215
      pSup->deleteMarkSaved = pSup->deleteMark;
742✔
1216
      pSup->calTrigger = STREAM_TRIGGER_AT_ONCE;
742✔
1217
      pSup->deleteMark = INT64_MAX;
742✔
1218
      pInfo->ignoreExpiredDataSaved = pInfo->ignoreExpiredData;
742✔
1219
      pInfo->ignoreExpiredData = false;
742✔
1220
    } else if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SESSION ||
3,884✔
1221
               type == QUERY_NODE_PHYSICAL_PLAN_STREAM_SEMI_SESSION ||
3,700✔
1222
               type == QUERY_NODE_PHYSICAL_PLAN_STREAM_FINAL_SESSION) {
191✔
1223
      SStreamSessionAggOperatorInfo* pInfo = pOperator->info;
190✔
1224
      STimeWindowAggSupp*            pSup = &pInfo->twAggSup;
190✔
1225

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

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

1238
      qInfo("save stream param for state: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
85!
1239

1240
      pSup->calTriggerSaved = pSup->calTrigger;
85✔
1241
      pSup->deleteMarkSaved = pSup->deleteMark;
85✔
1242
      pSup->calTrigger = STREAM_TRIGGER_AT_ONCE;
85✔
1243
      pSup->deleteMark = INT64_MAX;
85✔
1244
      pInfo->ignoreExpiredDataSaved = pInfo->ignoreExpiredData;
85✔
1245
      pInfo->ignoreExpiredData = false;
85✔
1246
    } else if (type == QUERY_NODE_PHYSICAL_PLAN_STREAM_EVENT) {
3,609✔
1247
      SStreamEventAggOperatorInfo* pInfo = pOperator->info;
72✔
1248
      STimeWindowAggSupp*          pSup = &pInfo->twAggSup;
72✔
1249

1250
      qInfo("save stream param for state: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
72!
1251

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

1262
      qInfo("save stream param for state: %d,  %" PRId64, pSup->calTrigger, pSup->deleteMark);
78!
1263

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

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

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

1286
    // iterate operator tree
1287
    if (pOperator->numOfDownstream != 1 || pOperator->pDownstream[0] == NULL) {
4,633✔
1288
      if (pOperator->numOfDownstream > 1) {
1,856!
1289
        qError("unexpected stream, multiple downstream");
×
1290
        return -1;
×
1291
      }
1292
      return 0;
1,856✔
1293
    } else {
1294
      pOperator = pOperator->pDownstream[0];
2,777✔
1295
    }
1296
  }
1297

1298
  return 0;
1299
}
1300

1301
bool qStreamScanhistoryFinished(qTaskInfo_t tinfo) {
1,789✔
1302
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
1,789✔
1303
  return pTaskInfo->streamInfo.recoverScanFinished;
1,789✔
1304
}
1305

1306
int32_t qStreamInfoResetTimewindowFilter(qTaskInfo_t tinfo) {
7,997✔
1307
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
7,997✔
1308
  STimeWindow*   pWindow = &pTaskInfo->streamInfo.fillHistoryWindow;
7,997✔
1309

1310
  qDebug("%s remove timeWindow filter:%" PRId64 "-%" PRId64 ", set new window:%" PRId64 "-%" PRId64,
7,997✔
1311
         GET_TASKID(pTaskInfo), pWindow->skey, pWindow->ekey, INT64_MIN, INT64_MAX);
1312

1313
  pWindow->skey = INT64_MIN;
7,998✔
1314
  pWindow->ekey = INT64_MAX;
7,998✔
1315
  return 0;
7,998✔
1316
}
1317

1318
void* qExtractReaderFromStreamScanner(void* scanner) {
1,266✔
1319
  SStreamScanInfo* pInfo = scanner;
1,266✔
1320
  return (void*)pInfo->tqReader;
1,266✔
1321
}
1322

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

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

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

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

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

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

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

1374
    pCond->pSlotList[i] = i;
13,291✔
1375
  }
1376

1377
  return TSDB_CODE_SUCCESS;
2,508✔
1378
}
1379

1380
void qStreamSetOpen(qTaskInfo_t tinfo) {
644,509✔
1381
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
644,509✔
1382
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
644,509✔
1383
  pOperator->status = OP_NOT_OPENED;
644,509✔
1384
}
644,509✔
1385

1386
void qStreamSetSourceExcluded(qTaskInfo_t tinfo, int8_t sourceExcluded) {
78,035✔
1387
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
78,035✔
1388
  pTaskInfo->streamInfo.sourceExcluded = sourceExcluded;
78,035✔
1389
}
78,035✔
1390

1391
int32_t qStreamPrepareScan(qTaskInfo_t tinfo, STqOffsetVal* pOffset, int8_t subType) {
313,621✔
1392
  int32_t        code = TSDB_CODE_SUCCESS;
313,621✔
1393
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
313,621✔
1394
  SStorageAPI*   pAPI = &pTaskInfo->storageAPI;
313,621✔
1395

1396
  SOperatorInfo* pOperator = pTaskInfo->pRoot;
313,621✔
1397
  const char*    id = GET_TASKID(pTaskInfo);
313,621✔
1398

1399
  if (subType == TOPIC_SUB_TYPE__COLUMN && pOffset->type == TMQ_OFFSET__LOG) {
313,621✔
1400
    code = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pOperator);
76,961✔
1401
    if (pOperator == NULL || code != 0) {
76,961!
1402
      return code;
×
1403
    }
1404

1405
    SStreamScanInfo* pInfo = pOperator->info;
76,961✔
1406
    SStoreTqReader*  pReaderAPI = &pTaskInfo->storageAPI.tqReaderFn;
76,961✔
1407
    SWalReader*      pWalReader = pReaderAPI->tqReaderGetWalReader(pInfo->tqReader);
76,961✔
1408
    walReaderVerifyOffset(pWalReader, pOffset);
76,961✔
1409
  }
1410
  // if pOffset equal to current offset, means continue consume
1411
  if (tOffsetEqual(pOffset, &pTaskInfo->streamInfo.currentOffset)) {
313,621✔
1412
    return 0;
73,024✔
1413
  }
1414

1415
  if (subType == TOPIC_SUB_TYPE__COLUMN) {
240,597✔
1416
    code = extractOperatorInTree(pOperator, QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN, id, &pOperator);
238,038✔
1417
    if (pOperator == NULL || code != 0) {
238,038!
1418
      return code;
×
1419
    }
1420

1421
    SStreamScanInfo* pInfo = pOperator->info;
238,038✔
1422
    STableScanInfo*  pScanInfo = pInfo->pTableScanOp->info;
238,038✔
1423
    STableScanBase*  pScanBaseInfo = &pScanInfo->base;
238,038✔
1424
    STableListInfo*  pTableListInfo = pScanBaseInfo->pTableListInfo;
238,038✔
1425

1426
    if (pOffset->type == TMQ_OFFSET__LOG) {
238,038✔
1427
      pTaskInfo->storageAPI.tsdReader.tsdReaderClose(pScanBaseInfo->dataReader);
5,007✔
1428
      pScanBaseInfo->dataReader = NULL;
5,006✔
1429

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

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

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

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

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

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

1492
      STableKeyInfo keyInfo = {.uid = uid};
180✔
1493
      int64_t       oldSkey = pScanBaseInfo->cond.twindows.skey;
180✔
1494

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

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

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

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

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

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

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

1548
      STableListInfo* pTableListInfo = ((SStreamRawScanInfo*)(p->info))->pTableListInfo;
2,512✔
1549

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

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

1564
      cleanupQueryTableDataCond(&pTaskInfo->streamInfo.tableCond);
2,513✔
1565
      tableListClear(pTableListInfo);
2,513✔
1566

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

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

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

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

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

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

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

1639
end:
14✔
1640
  tOffsetCopy(&pTaskInfo->streamInfo.currentOffset, pOffset);
7,691✔
1641
  return 0;
7,690✔
1642
}
1643

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

1651
  SDataBuf buf = {.len = pMsg->contLen, .pData = NULL};
5,274,225✔
1652

1653
  if (pMsg->contLen > 0) {
5,274,225!
1654
    buf.pData = taosMemoryCalloc(1, pMsg->contLen);
5,279,826!
1655
    if (buf.pData == NULL) {
5,273,664!
1656
      pMsg->code = terrno;
×
1657
    } else {
1658
      memcpy(buf.pData, pMsg->pCont, pMsg->contLen);
5,273,664✔
1659
    }
1660
  }
1661

1662
  (void)pSendInfo->fp(pSendInfo->param, &buf, pMsg->code);
5,268,063✔
1663
  rpcFreeCont(pMsg->pCont);
5,283,990✔
1664
  destroySendMsgInfo(pSendInfo);
5,284,318✔
1665
}
1666

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

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

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

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

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

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

1695
  taosArrayDestroy(plist);
×
1696

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

1705
static int32_t extractTableList(SArray* pList, const SOperatorInfo* pOperator) {
166,596✔
1706
  int32_t        code = TSDB_CODE_SUCCESS;
166,596✔
1707
  int32_t        lino = 0;
166,596✔
1708
  SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
166,596✔
1709

1710
  if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN) {
166,596!
1711
    SStreamScanInfo* pScanInfo = pOperator->info;
×
1712
    STableScanInfo*  pTableScanInfo = pScanInfo->pTableScanOp->info;
×
1713

1714
    void* tmp = taosArrayPush(pList, &pTableScanInfo->base.pTableListInfo);
×
1715
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
×
1716
  } else if (pOperator->operatorType == QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
166,596✔
1717
    STableScanInfo* pScanInfo = pOperator->info;
83,300✔
1718

1719
    void* tmp = taosArrayPush(pList, &pScanInfo->base.pTableListInfo);
83,300✔
1720
    QUERY_CHECK_NULL(tmp, code, lino, _end, terrno);
83,310!
1721
  } else {
1722
    if (pOperator->pDownstream != NULL && pOperator->pDownstream[0] != NULL) {
83,296!
1723
      code = extractTableList(pList, pOperator->pDownstream[0]);
83,306✔
1724
    }
1725
  }
1726

1727
_end:
×
1728
  if (code != TSDB_CODE_SUCCESS) {
166,602!
1729
    qError("%s %s failed at line %d since %s", pTaskInfo->id.str, __func__, lino, tstrerror(code));
×
1730
  }
1731
  return code;
166,603✔
1732
}
1733

1734
int32_t getTableListInfo(const SExecTaskInfo* pTaskInfo, SArray** pList) {
83,295✔
1735
  if (pList == NULL) {
83,295!
1736
    return TSDB_CODE_INVALID_PARA;
×
1737
  }
1738

1739
  *pList = NULL;
83,295✔
1740
  SArray* pArray = taosArrayInit(0, POINTER_BYTES);
83,295✔
1741
  if (pArray == NULL) {
83,315!
1742
    return terrno;
×
1743
  }
1744

1745
  int32_t code = extractTableList(pArray, pTaskInfo->pRoot);
83,315✔
1746
  if (code == 0) {
83,309!
1747
    *pList = pArray;
83,310✔
1748
  } else {
1749
    taosArrayDestroy(pArray);
×
1750
  }
1751
  return code;
83,309✔
1752
}
1753

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

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

1770
void qResetTaskCode(qTaskInfo_t tinfo) {
5✔
1771
  SExecTaskInfo* pTaskInfo = (SExecTaskInfo*)tinfo;
5✔
1772

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