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

taosdata / TDengine / #3797

31 Mar 2025 11:16AM UTC coverage: 33.987% (+1.9%) from 32.122%
#3797

push

travis-ci

happyguoxy
test:alter cmake

147823 of 598399 branches covered (24.7%)

Branch coverage included in aggregate %.

221556 of 488413 relevant lines covered (45.36%)

759930.59 hits per line

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

53.12
/source/libs/stream/src/streamTask.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 "osDir.h"
18
#include "osMemory.h"
19
#include "streamInt.h"
20
#include "streamMsg.h"
21
#include "streamsm.h"
22
#include "tmisce.h"
23
#include "tstream.h"
24
#include "ttimer.h"
25
#include "wal.h"
26

27
static void    streamTaskDestroyUpstreamInfo(SUpstreamInfo* pUpstreamInfo);
28
static int32_t streamTaskUpdateUpstreamInfo(SStreamTask* pTask, int32_t nodeId, const SEpSet* pEpSet, bool* pUpdated);
29
static int32_t streamTaskUpdateDownstreamInfo(SStreamTask* pTask, int32_t nodeId, const SEpSet* pEpSet, bool* pUpdate);
30
static void    streamTaskDestroyActiveChkptInfo(SActiveCheckpointInfo* pInfo);
31

32
static int32_t addToTaskset(SArray* pArray, SStreamTask* pTask) {
31✔
33
  int32_t childId = taosArrayGetSize(pArray);
31✔
34
  pTask->info.selfChildId = childId;
31✔
35
  void* p = taosArrayPush(pArray, &pTask);
31✔
36
  return (p == NULL) ? terrno : TSDB_CODE_SUCCESS;
31!
37
}
38

39
static int32_t doUpdateTaskEpset(SStreamTask* pTask, int32_t nodeId, SEpSet* pEpSet, bool* pUpdated) {
10✔
40
  int32_t code = 0;
10✔
41
  char    buf[512] = {0};
10✔
42

43
  if (pTask->info.nodeId == nodeId) {  // execution task should be moved away
10✔
44
    bool isEqual = isEpsetEqual(&pTask->info.epSet, pEpSet);
2✔
45
    code = epsetToStr(pEpSet, buf, tListLen(buf));
2✔
46
    if (code) {  // print error and continue
2!
47
      stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
48
      return code;
×
49
    }
50

51
    if (!isEqual) {
2!
52
      (*pUpdated) = true;
×
53
      char tmp[512] = {0};
×
54
      code = epsetToStr(&pTask->info.epSet, tmp, tListLen(tmp));  // only for log file, ignore errors
×
55
      if (code) {                                                 // print error and continue
×
56
        stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
57
        return code;
×
58
      }
59

60
      epsetAssign(&pTask->info.epSet, pEpSet);
×
61
      stDebug("s-task:0x%x (vgId:%d) self node epset is updated %s, old:%s", pTask->id.taskId, nodeId, buf, tmp);
×
62
    } else {
63
      stDebug("s-task:0x%x (vgId:%d) not updated task epset, since epset identical, %s", pTask->id.taskId, nodeId, buf);
2!
64
    }
65
  }
66

67
  // check for the dispatch info and the upstream task info
68
  int32_t level = pTask->info.taskLevel;
10✔
69
  if (level == TASK_LEVEL__SOURCE) {
10✔
70
    code = streamTaskUpdateDownstreamInfo(pTask, nodeId, pEpSet, pUpdated);
4✔
71
  } else if (level == TASK_LEVEL__AGG) {
6✔
72
    code = streamTaskUpdateUpstreamInfo(pTask, nodeId, pEpSet, pUpdated);
2✔
73
    code = streamTaskUpdateDownstreamInfo(pTask, nodeId, pEpSet, pUpdated);
2✔
74
  } else {  // TASK_LEVEL__SINK
75
    code = streamTaskUpdateUpstreamInfo(pTask, nodeId, pEpSet, pUpdated);
4✔
76
  }
77

78
  return code;
10✔
79
}
80

81
static void freeItem(void* p) {
×
82
  SStreamContinueExecInfo* pInfo = p;
×
83
  rpcFreeCont(pInfo->msg.pCont);
×
84
}
×
85

86
static void freeUpstreamItem(void* p) {
95✔
87
  SStreamUpstreamEpInfo** pInfo = p;
95✔
88
  taosMemoryFree(*pInfo);
95!
89
}
95✔
90

91
static SStreamUpstreamEpInfo* createStreamTaskEpInfo(const SStreamTask* pTask) {
23✔
92
  SStreamUpstreamEpInfo* pEpInfo = taosMemoryMalloc(sizeof(SStreamUpstreamEpInfo));
23!
93
  if (pEpInfo == NULL) {
23!
94
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
95
    return NULL;
×
96
  }
97

98
  pEpInfo->childId = pTask->info.selfChildId;
23✔
99
  pEpInfo->epSet = pTask->info.epSet;
23✔
100
  pEpInfo->nodeId = pTask->info.nodeId;
23✔
101
  pEpInfo->taskId = pTask->id.taskId;
23✔
102
  pEpInfo->stage = -1;
23✔
103
  pEpInfo->lastMsgId = -1;
23✔
104

105
  return pEpInfo;
23✔
106
}
107

108
int32_t tNewStreamTask(int64_t streamId, int8_t taskLevel, SEpSet* pEpset, EStreamTaskType type, int32_t trigger,
31✔
109
                       int64_t triggerParam, SArray* pTaskList, bool hasFillhistory, int8_t subtableWithoutMd5,
110
                       int8_t hasAggTasks, SStreamTask** p) {
111
  *p = NULL;
31✔
112

113
  SStreamTask* pTask = (SStreamTask*)taosMemoryCalloc(1, sizeof(SStreamTask));
31!
114
  if (pTask == NULL) {
31!
115
    stError("s-task:0x%" PRIx64 " failed malloc new stream task, size:%d, code:%s", streamId,
×
116
            (int32_t)sizeof(SStreamTask), tstrerror(terrno));
117
    return terrno;
×
118
  }
119

120
  pTask->ver = SSTREAM_TASK_VER;
31✔
121
  pTask->id.taskId = tGenIdPI32();
31✔
122
  pTask->id.streamId = streamId;
31✔
123

124
  pTask->info.taskLevel = taskLevel;
31✔
125
  pTask->info.fillHistory = type;
31✔
126
  pTask->info.trigger = trigger;
31✔
127
  pTask->info.hasAggTasks = hasAggTasks;
31✔
128
  pTask->info.delaySchedParam = triggerParam;
31✔
129
  pTask->subtableWithoutMd5 = subtableWithoutMd5;
31✔
130

131
  int32_t code = streamCreateStateMachine(pTask);
31✔
132
  if (pTask->status.pSM == NULL || code != TSDB_CODE_SUCCESS) {
31!
133
    taosMemoryFreeClear(pTask);
×
134
    return code;
×
135
  }
136

137
  char    buf[128] = {0};
31✔
138
  int32_t ret = snprintf(buf, tListLen(buf), "0x%" PRIx64 "-0x%x", pTask->id.streamId, pTask->id.taskId);
31✔
139
  if (ret < 0 || ret >= tListLen(buf)) {
31!
140
    stError("s-task:0x%x failed to set the taskIdstr, code: out of buffer", pTask->id.taskId);
×
141
    return TSDB_CODE_OUT_OF_BUFFER;
×
142
  }
143

144
  pTask->id.idStr = taosStrdup(buf);
31!
145
  if (pTask->id.idStr == NULL) {
31!
146
    stError("s-task:0x%x failed to build task id, code: out of memory", pTask->id.taskId);
×
147
    return terrno;
×
148
  }
149

150
  pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
31✔
151
  pTask->status.taskStatus =
31✔
152
      (pTask->info.fillHistory == STREAM_HISTORY_TASK) ? TASK_STATUS__SCAN_HISTORY : TASK_STATUS__READY;
31✔
153
  pTask->inputq.status = TASK_INPUT_STATUS__NORMAL;
31✔
154
  pTask->outputq.status = TASK_OUTPUT_STATUS__NORMAL;
31✔
155

156
  pTask->taskCheckInfo.pList = taosArrayInit(4, sizeof(SDownstreamStatusInfo));
31✔
157

158
  if ((pTask->info.fillHistory == STREAM_HISTORY_TASK) && !hasFillhistory) {
31!
159
    stError("s-task:0x%x create task failed, due to inconsistent fill-history flag", pTask->id.taskId);
×
160
    return TSDB_CODE_INVALID_PARA;
×
161
  }
162

163
  epsetAssign(&(pTask->info.mnodeEpset), pEpset);
31✔
164

165
  code = addToTaskset(pTaskList, pTask);
31✔
166
  *p = pTask;
31✔
167

168
  return code;
31✔
169
}
170

171
int32_t tDecodeStreamTaskChkInfo(SDecoder* pDecoder, SCheckpointInfo* pChkpInfo) {
5✔
172
  int64_t skip64;
173
  int8_t  skip8;
174
  int32_t skip32;
175
  int16_t skip16;
176
  SEpSet  epSet;
177

178
  if (tStartDecode(pDecoder) < 0) return -1;
5!
179
  if (tDecodeI64(pDecoder, &pChkpInfo->msgVer) < 0) return -1;
10!
180
  // if (ver <= SSTREAM_TASK_INCOMPATIBLE_VER) return -1;
181

182
  if (tDecodeI64(pDecoder, &skip64) < 0) return -1;
5!
183
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
5!
184
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
5!
185
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
5!
186
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
5!
187
  if (tDecodeI16(pDecoder, &skip16) < 0) return -1;
5!
188

189
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
5!
190
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
5!
191

192
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
5!
193
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
5!
194
  if (tDecodeSEpSet(pDecoder, &epSet) < 0) return -1;
5!
195
  if (tDecodeSEpSet(pDecoder, &epSet) < 0) return -1;
5!
196

197
  if (tDecodeI64(pDecoder, &pChkpInfo->checkpointId) < 0) return -1;
10!
198
  if (tDecodeI64(pDecoder, &pChkpInfo->checkpointVer) < 0) return -1;
10!
199

200
  tEndDecode(pDecoder);
5✔
201
  return 0;
5✔
202
}
203

204
int32_t tDecodeStreamTaskId(SDecoder* pDecoder, STaskId* pTaskId) {
×
205
  int64_t ver;
206
  if (tStartDecode(pDecoder) < 0) return -1;
×
207
  if (tDecodeI64(pDecoder, &ver) < 0) return -1;
×
208
  if (ver <= SSTREAM_TASK_INCOMPATIBLE_VER) return -1;
×
209

210
  if (tDecodeI64(pDecoder, &pTaskId->streamId) < 0) return -1;
×
211

212
  int32_t taskId = 0;
×
213
  if (tDecodeI32(pDecoder, &taskId) < 0) return -1;
×
214

215
  pTaskId->taskId = taskId;
×
216
  tEndDecode(pDecoder);
×
217
  return 0;
×
218
}
219

220
void tFreeStreamTask(void* pParam) {
115✔
221
  char*        p = NULL;
115✔
222
  SStreamTask* pTask = pParam;
115✔
223
  int32_t      taskId = pTask->id.taskId;
115✔
224

225
  STaskExecStatisInfo* pStatis = &pTask->execInfo;
115✔
226

227
  ETaskStatus status1 = TASK_STATUS__UNINIT;
115✔
228
  if (pTask->status.pSM != NULL) {
115✔
229
    streamMutexLock(&pTask->lock);
56✔
230
    SStreamTaskState status = streamTaskGetStatus(pTask);
56✔
231
    p = status.name;
56✔
232
    status1 = status.state;
56✔
233
    streamMutexUnlock(&pTask->lock);
56✔
234
  }
235

236
  stDebug("start to free s-task:0x%x %p, state:%s, refId:%" PRId64, taskId, pTask, p, pTask->id.refId);
115✔
237

238
  SCheckpointInfo* pCkInfo = &pTask->chkInfo;
115✔
239
  stDebug("s-task:0x%x task exec summary: create:%" PRId64 ", init:%" PRId64 ", start:%" PRId64
115✔
240
          ", updateCount:%d latestUpdate:%" PRId64 ", latestCheckPoint:%" PRId64 ", ver:%" PRId64
241
          " nextProcessVer:%" PRId64 ", checkpointCount:%d",
242
          taskId, pStatis->created, pStatis->checkTs, pStatis->readyTs, pStatis->updateCount, pStatis->latestUpdateTs,
243
          pCkInfo->checkpointId, pCkInfo->checkpointVer, pCkInfo->nextProcessVer, pStatis->checkpoint);
244

245
  if (pTask->schedInfo.pDelayTimer != NULL) {
115!
246
    streamTmrStop(pTask->schedInfo.pDelayTimer);
×
247
    pTask->schedInfo.pDelayTimer = NULL;
×
248
  }
249

250
  if (pTask->hTaskInfo.pTimer != NULL) {
115✔
251
    streamTmrStop(pTask->hTaskInfo.pTimer);
1✔
252
    pTask->hTaskInfo.pTimer = NULL;
1✔
253
  }
254

255
  if (pTask->msgInfo.pRetryTmr != NULL) {
115✔
256
    streamTmrStop(pTask->msgInfo.pRetryTmr);
11✔
257
    pTask->msgInfo.pRetryTmr = NULL;
11✔
258
  }
259

260
  if (pTask->inputq.queue) {
115✔
261
    streamQueueClose(pTask->inputq.queue, pTask->id.taskId);
29✔
262
    pTask->inputq.queue = NULL;
29✔
263
  }
264

265
  if (pTask->outputq.queue) {
115✔
266
    streamQueueClose(pTask->outputq.queue, pTask->id.taskId);
29✔
267
    pTask->outputq.queue = NULL;
29✔
268
  }
269

270
  if (pTask->exec.qmsg) {
115✔
271
    taosMemoryFree(pTask->exec.qmsg);
68!
272
  }
273

274
  if (pTask->exec.pExecutor) {
115✔
275
    qDestroyTask(pTask->exec.pExecutor);
17✔
276
    pTask->exec.pExecutor = NULL;
17✔
277
  }
278

279
  if (pTask->exec.pWalReader != NULL) {
115✔
280
    walCloseReader(pTask->exec.pWalReader);
13✔
281
    pTask->exec.pWalReader = NULL;
13✔
282
  }
283

284
  streamClearChkptReadyMsg(pTask->chkInfo.pActiveInfo);
115✔
285

286
  if (pTask->msgInfo.pData != NULL) {
115!
287
    clearBufferedDispatchMsg(pTask);
×
288
  }
289

290
  if (pTask->outputInfo.type == TASK_OUTPUT__TABLE) {
115✔
291
    tDeleteSchemaWrapper(pTask->outputInfo.tbSink.pSchemaWrapper);
51!
292
    taosMemoryFree(pTask->outputInfo.tbSink.pTSchema);
51!
293
    tSimpleHashCleanup(pTask->outputInfo.tbSink.pTbInfo);
51✔
294
    tDeleteSchemaWrapper(pTask->outputInfo.tbSink.pTagSchema);
51✔
295
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
64✔
296
    taosArrayDestroy(pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos);
22✔
297
  } else if (pTask->outputInfo.type == TASK_OUTPUT__VTABLE_MAP) {
42!
298
    taosArrayDestroy(pTask->outputInfo.vtableMapDispatcher.taskInfos);
×
299
    tSimpleHashCleanup(pTask->outputInfo.vtableMapDispatcher.vtableMap);
×
300
  }
301

302
  streamTaskCleanupCheckInfo(&pTask->taskCheckInfo);
115✔
303
  streamFreeTaskState(pTask, pTask->status.removeBackendFiles ? 1 : 0);
115✔
304

305
  if (pTask->pNameMap) {
115✔
306
    tSimpleHashCleanup(pTask->pNameMap);
4✔
307
  }
308

309
  if (pTask->status.pSM != NULL) {
115✔
310
    streamMutexDestroy(&pTask->lock);
56✔
311
    streamMutexDestroy(&pTask->msgInfo.lock);
56✔
312
    streamMutexDestroy(&pTask->taskCheckInfo.checkInfoLock);
56✔
313
  }
314

315
  taosArrayDestroy(pTask->pVTables);
115✔
316
  pTask->pVTables = NULL;
115✔
317

318
  streamDestroyStateMachine(pTask->status.pSM);
115✔
319
  pTask->status.pSM = NULL;
115✔
320

321
  streamTaskDestroyUpstreamInfo(&pTask->upstreamInfo);
115✔
322

323
  taosMemoryFree(pTask->outputInfo.pTokenBucket);
115!
324

325
  taosArrayDestroy(pTask->msgInfo.pSendInfo);
115✔
326
  pTask->msgInfo.pSendInfo = NULL;
115✔
327

328
  taosArrayDestroy(pTask->outputInfo.pNodeEpsetUpdateList);
115✔
329
  pTask->outputInfo.pNodeEpsetUpdateList = NULL;
115✔
330

331
  if (pTask->id.idStr != NULL) {
115✔
332
    taosMemoryFree((void*)pTask->id.idStr);
56!
333
  }
334

335
  streamTaskDestroyActiveChkptInfo(pTask->chkInfo.pActiveInfo);
115✔
336
  pTask->chkInfo.pActiveInfo = NULL;
115✔
337

338
  taosArrayDestroyP(pTask->notifyInfo.pNotifyAddrUrls, NULL);
115✔
339
  taosMemoryFreeClear(pTask->notifyInfo.streamName);
115!
340
  taosMemoryFreeClear(pTask->notifyInfo.stbFullName);
115!
341
  tDeleteSchemaWrapper(pTask->notifyInfo.pSchemaWrapper);
115!
342

343
  pTask->notifyEventStat = (STaskNotifyEventStat){0};
115✔
344

345
  taosMemoryFree(pTask);
115!
346
  stDebug("s-task:0x%x free task completed", taskId);
115✔
347
}
115✔
348

349
void streamFreeTaskState(SStreamTask* pTask, int8_t remove) {
115✔
350
  stDebug("s-task:0x%x start to free task state/backend", pTask->id.taskId);
115✔
351
  if (pTask->pState != NULL) {
115✔
352
    stDebug("s-task:0x%x start to free task state", pTask->id.taskId);
17!
353
    streamStateClose(pTask->pState, remove);
17✔
354

355
    if (remove) taskDbSetClearFileFlag(pTask->pBackend);
17!
356
    taskDbRemoveRef(pTask->pBackend);
17✔
357
    pTask->pBackend = NULL;
17✔
358
    pTask->pState = NULL;
17✔
359

360
  } else {
361
    stDebug("s-task:0x%x task state is NULL, may del backend:%s", pTask->id.taskId,
98✔
362
            pTask->backendPath ? pTask->backendPath : "NULL");
363
    if (remove) {
98!
364
      if (pTask->backendPath != NULL) {
×
365
        stDebug("s-task:0x%x task state is NULL, do del backend:%s", pTask->id.taskId, pTask->backendPath);
×
366
        taosRemoveDir(pTask->backendPath);
×
367
      }
368
    }
369
  }
370

371
  if (pTask->backendPath != NULL) {
115✔
372
    taosMemoryFree(pTask->backendPath);
29!
373
    pTask->backendPath = NULL;
29✔
374
  }
375
  // clear recal backend
376

377
  if (pTask->pRecalState != NULL) {
115!
378
    stDebug("s-task:0x%x start to free recal task state", pTask->id.taskId);
×
379
    streamStateClose(pTask->pRecalState, remove);
×
380

381
    if (remove) taskDbSetClearFileFlag(pTask->pRecalBackend);
×
382
    taskDbRemoveRef(pTask->pRecalBackend);
×
383
    pTask->pRecalBackend = NULL;
×
384
    pTask->pRecalState = NULL;
×
385

386
  }  // else {
387
     //  stDebug("s-task:0x%x task state is NULL, may del backend:%s", pTask->id.taskId,
388
     //          pTask->backendPath ? pTask->backendPath : "NULL");
389
     //  if (remove) {
390
     //    if (pTask->backendPath != NULL) {
391
     //      stDebug("s-task:0x%x task state is NULL, do del backend:%s", pTask->id.taskId, pTask->backendPath);
392
     //      taosRemoveDir(pTask->backendPath);
393
     //    }
394
     //  }
395
  //}
396
  // if (pTask->backendPath != NULL) {
397
  //   taosMemoryFree(pTask->backendPath);
398
  //   pTask->backendPath = NULL;
399
  // }
400
}
115✔
401

402
static void setInitialVersionInfo(SStreamTask* pTask, int64_t ver) {
29✔
403
  SCheckpointInfo* pChkInfo = &pTask->chkInfo;
29✔
404
  SDataRange*      pRange = &pTask->dataRange;
29✔
405

406
  // only set the version info for stream tasks without fill-history task
407
  if ((pTask->info.fillHistory == 0) && (!HAS_RELATED_FILLHISTORY_TASK(pTask))) {
29✔
408
    pChkInfo->checkpointVer = ver - 1;  // only update when generating checkpoint
19✔
409
    pChkInfo->processedVer = ver - 1;   // already processed version
19✔
410
    pChkInfo->nextProcessVer = ver;     // next processed version
19✔
411

412
    pRange->range.maxVer = ver;
19✔
413
    pRange->range.minVer = ver;
19✔
414
  } else {
415
    // the initial value of processedVer/nextProcessVer/checkpointVer for stream task with related fill-history task
416
    // is set at the mnode.
417
    if (pTask->info.fillHistory == 1) {
10✔
418
      pChkInfo->checkpointVer = pRange->range.maxVer;
5✔
419
      pChkInfo->processedVer = pRange->range.maxVer;
5✔
420
      pChkInfo->nextProcessVer = pRange->range.maxVer + 1;
5✔
421
    } else {
422
      pChkInfo->checkpointVer = pRange->range.minVer - 1;
5✔
423
      pChkInfo->processedVer = pRange->range.minVer - 1;
5✔
424
      pChkInfo->nextProcessVer = pRange->range.minVer;
5✔
425

426
      {  // for compatible purpose, remove it later
427
        if (pRange->range.minVer == 0) {
5✔
428
          pChkInfo->checkpointVer = 0;
3✔
429
          pChkInfo->processedVer = 0;
3✔
430
          pChkInfo->nextProcessVer = 1;
3✔
431
          stDebug("s-task:%s update the processedVer to 0 from -1 due to compatible purpose", pTask->id.idStr);
3!
432
        }
433
      }
434
    }
435
  }
436
}
29✔
437

438
int32_t streamTaskSetBackendPath(SStreamTask* pTask) {
29✔
439
  int64_t streamId = 0;
29✔
440
  int32_t taskId = 0;
29✔
441

442
  if (pTask->info.fillHistory) {
29✔
443
    streamId = pTask->streamTaskId.streamId;
5✔
444
    taskId = pTask->streamTaskId.taskId;
5✔
445
  } else {
446
    streamId = pTask->id.streamId;
24✔
447
    taskId = pTask->id.taskId;
24✔
448
  }
449

450
  char    id[128] = {0};
29✔
451
  int32_t nBytes = snprintf(id, tListLen(id), "0x%" PRIx64 "-0x%x", streamId, taskId);
29✔
452
  if (nBytes < 0 || nBytes >= sizeof(id)) {
29!
453
    return TSDB_CODE_OUT_OF_BUFFER;
×
454
  }
455

456
  int32_t len = strlen(pTask->pMeta->path);
29✔
457
  pTask->backendPath = (char*)taosMemoryMalloc(len + nBytes + 2);
29!
458
  if (pTask->backendPath == NULL) {
29!
459
    return terrno;
×
460
  }
461

462
  int32_t code = snprintf(pTask->backendPath, len + nBytes + 2, "%s%s%s", pTask->pMeta->path, TD_DIRSEP, id);
29✔
463
  if (code < 0 || code >= len + nBytes + 2) {
29!
464
    stError("s-task:%s failed to set backend path:%s, code: out of buffer", pTask->id.idStr, pTask->backendPath);
×
465
    return TSDB_CODE_OUT_OF_BUFFER;
×
466
  } else {
467
    stDebug("s-task:%s set backend path:%s", pTask->id.idStr, pTask->backendPath);
29!
468
    return 0;
29✔
469
  }
470
}
471

472
int32_t streamTaskInit(SStreamTask* pTask, SStreamMeta* pMeta, SMsgCb* pMsgCb, int64_t ver) {
29✔
473
  int32_t code = createStreamTaskIdStr(pTask->id.streamId, pTask->id.taskId, &pTask->id.idStr);
29✔
474
  if (code) {
29!
475
    stError("0x%x failed create stream task id str, code:%s", pTask->id.taskId, tstrerror(code));
×
476
    return code;
×
477
  }
478

479
  pTask->id.refId = 0;
29✔
480
  pTask->inputq.status = TASK_INPUT_STATUS__NORMAL;
29✔
481
  pTask->outputq.status = TASK_OUTPUT_STATUS__NORMAL;
29✔
482

483
  int32_t code1 = streamQueueOpen(512 << 10, &pTask->inputq.queue);
29✔
484
  int32_t code2 = streamQueueOpen(512 << 10, &pTask->outputq.queue);
29✔
485
  if (code1 || code2) {
29!
486
    stError("s-task:%s failed to prepare the input/output queue, initialize task failed", pTask->id.idStr);
×
487
    return TSDB_CODE_OUT_OF_MEMORY;
×
488
  }
489

490
  pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
29✔
491

492
  code = streamCreateStateMachine(pTask);
29✔
493
  if (pTask->status.pSM == NULL || code != TSDB_CODE_SUCCESS) {
29!
494
    stError("s-task:%s failed create state-machine for stream task, initialization failed, code:%s", pTask->id.idStr,
×
495
            tstrerror(code));
496
    return code;
×
497
  }
498

499
  pTask->execInfo.created = taosGetTimestampMs();
29✔
500
  setInitialVersionInfo(pTask, ver);
29✔
501

502
  pTask->pMeta = pMeta;
29✔
503
  pTask->pMsgCb = pMsgCb;
29✔
504
  pTask->msgInfo.pSendInfo = taosArrayInit(4, sizeof(SDispatchEntry));
29✔
505
  if (pTask->msgInfo.pSendInfo == NULL) {
29!
506
    stError("s-task:%s failed to create sendInfo struct for stream task, code:Out of memory", pTask->id.idStr);
×
507
    return terrno;
×
508
  }
509

510
  code = taosThreadMutexInit(&pTask->msgInfo.lock, NULL);
29✔
511
  if (code) {
29!
512
    stError("s-task:0x%x failed to init msgInfo mutex, code:%s", pTask->id.taskId, tstrerror(code));
×
513
    return code;
×
514
  }
515

516
  TdThreadMutexAttr attr = {0};
29✔
517
  code = taosThreadMutexAttrInit(&attr);
29✔
518
  if (code != 0) {
29!
519
    stError("s-task:%s initElapsed mutex attr failed, code:%s", pTask->id.idStr, tstrerror(code));
×
520
    return code;
×
521
  }
522

523
  code = taosThreadMutexAttrSetType(&attr, PTHREAD_MUTEX_RECURSIVE);
29✔
524
  if (code != 0) {
29!
525
    stError("s-task:%s set mutex attr recursive, code:%s", pTask->id.idStr, tstrerror(code));
×
526
    return code;
×
527
  }
528

529
  code = taosThreadMutexInit(&pTask->lock, &attr);
29✔
530
  if (code) {
29!
531
    return code;
×
532
  }
533

534
  code = taosThreadMutexAttrDestroy(&attr);
29✔
535
  if (code) {
29!
536
    return code;
×
537
  }
538

539
  streamTaskOpenAllUpstreamInput(pTask);
29✔
540

541
  STaskOutputInfo* pOutputInfo = &pTask->outputInfo;
29✔
542
  pOutputInfo->pTokenBucket = taosMemoryCalloc(1, sizeof(STokenBucket));
29!
543
  if (pOutputInfo->pTokenBucket == NULL) {
29!
544
    stError("s-task:%s failed to prepare the tokenBucket, code:%s", pTask->id.idStr, tstrerror(terrno));
×
545
    return terrno;
×
546
  }
547

548
  // 2MiB per second for sink task
549
  // 50 times sink operator per second
550
  code = streamTaskInitTokenBucket(pOutputInfo->pTokenBucket, 35, 35, tsSinkDataRate, pTask->id.idStr);
29✔
551
  if (code) {
29!
552
    return code;
×
553
  }
554

555
  pOutputInfo->pNodeEpsetUpdateList = taosArrayInit(4, sizeof(SDownstreamTaskEpset));
29✔
556
  if (pOutputInfo->pNodeEpsetUpdateList == NULL) {
29!
557
    stError("s-task:%s failed to prepare downstreamUpdateList, code:%s", pTask->id.idStr, tstrerror(terrno));
×
558
    return terrno;
×
559
  }
560

561
  pTask->taskCheckInfo.pList = taosArrayInit(4, sizeof(SDownstreamStatusInfo));
29✔
562
  if (pTask->taskCheckInfo.pList == NULL) {
29!
563
    stError("s-task:%s failed to prepare taskCheckInfo list, code:%s", pTask->id.idStr, tstrerror(terrno));
×
564
    return terrno;
×
565
  }
566

567
  code = taosThreadMutexInit(&pTask->taskCheckInfo.checkInfoLock, NULL);
29✔
568
  if (code) {
29!
569
    return code;
×
570
  }
571

572
  if (pTask->chkInfo.pActiveInfo == NULL) {
29!
573
    code = streamTaskCreateActiveChkptInfo(&pTask->chkInfo.pActiveInfo);
29✔
574
    if (code) {
29!
575
      stError("s-task:%s failed to create active checkpoint info, code:%s", pTask->id.idStr, tstrerror(code));
×
576
      return code;
×
577
    }
578
  }
579

580
  return streamTaskSetBackendPath(pTask);
29✔
581
}
582

583
int32_t streamTaskGetNumOfDownstream(const SStreamTask* pTask) {
768✔
584
  if (pTask->info.taskLevel == TASK_LEVEL__SINK) {
768✔
585
    return 0;
11✔
586
  }
587

588
  int32_t type = pTask->outputInfo.type;
757✔
589
  if (type == TASK_OUTPUT__TABLE) {
757✔
590
    return 0;
2✔
591
  } else if (type == TASK_OUTPUT__FIXED_DISPATCH) {
755✔
592
    return 1;
427✔
593
  } else if (type == TASK_OUTPUT__VTABLE_MAP) {
328!
594
    SArray* pTaskInfos = pTask->outputInfo.vtableMapDispatcher.taskInfos;
×
595
    return taosArrayGetSize(pTaskInfos);
×
596
  } else {
597
    SArray* vgInfo = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
328✔
598
    return taosArrayGetSize(vgInfo);
328✔
599
  }
600
}
601

602
int32_t streamTaskGetNumOfUpstream(const SStreamTask* pTask) { return taosArrayGetSize(pTask->upstreamInfo.pList); }
13✔
603

604
int32_t streamTaskSetUpstreamInfo(SStreamTask* pTask, const SStreamTask* pUpstreamTask) {
23✔
605
  SStreamUpstreamEpInfo* pEpInfo = createStreamTaskEpInfo(pUpstreamTask);
23✔
606
  if (pEpInfo == NULL) {
23!
607
    return terrno;
×
608
  }
609

610
  if (pTask->upstreamInfo.pList == NULL) {
23✔
611
    pTask->upstreamInfo.pList = taosArrayInit(4, POINTER_BYTES);
15✔
612
  }
613

614
  void* p = taosArrayPush(pTask->upstreamInfo.pList, &pEpInfo);
23✔
615
  return (p == NULL) ? terrno : TSDB_CODE_SUCCESS;
23!
616
}
617

618
int32_t streamTaskUpdateUpstreamInfo(SStreamTask* pTask, int32_t nodeId, const SEpSet* pEpSet, bool* pUpdated) {
6✔
619
  int32_t code = 0;
6✔
620
  char    buf[512] = {0};
6✔
621
  code = epsetToStr(pEpSet, buf, tListLen(buf));  // ignore error since it is only for log file.
6✔
622
  if (code != 0) {                                // print error and continue
6!
623
    stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
624
    return code;
×
625
  }
626

627
  int32_t numOfUpstream = taosArrayGetSize(pTask->upstreamInfo.pList);
6✔
628
  for (int32_t i = 0; i < numOfUpstream; ++i) {
10✔
629
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
8✔
630
    if (pInfo->nodeId == nodeId) {
8✔
631
      bool equal = isEpsetEqual(&pInfo->epSet, pEpSet);
4✔
632
      if (!equal) {
4!
633
        *pUpdated = true;
×
634

635
        char tmp[512] = {0};
×
636
        code = epsetToStr(&pInfo->epSet, tmp, tListLen(tmp));
×
637
        if (code != 0) {  // print error and continue
×
638
          stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
639
          return code;
×
640
        }
641

642
        epsetAssign(&pInfo->epSet, pEpSet);
×
643
        stDebug("s-task:0x%x update the upstreamInfo taskId:0x%x(nodeId:%d) newEpset:%s old:%s", pTask->id.taskId,
×
644
                pInfo->taskId, nodeId, buf, tmp);
645
      } else {
646
        stDebug("s-task:0x%x not update upstreamInfo, since identical, task:0x%x(nodeId:%d) epset:%s", pTask->id.taskId,
4!
647
                pInfo->taskId, nodeId, buf);
648
      }
649

650
      break;
4✔
651
    }
652
  }
653

654
  return code;
6✔
655
}
656

657
void streamTaskDestroyUpstreamInfo(SUpstreamInfo* pUpstreamInfo) {
115✔
658
  if (pUpstreamInfo->pList != NULL) {
115✔
659
    taosArrayDestroyEx(pUpstreamInfo->pList, freeUpstreamItem);
100✔
660
    pUpstreamInfo->numOfClosed = 0;
100✔
661
    pUpstreamInfo->pList = NULL;
100✔
662
  }
663
}
115✔
664

665
void streamTaskSetFixedDownstreamInfo(SStreamTask* pTask, const SStreamTask* pDownstreamTask) {
7✔
666
  STaskDispatcherFixed* pDispatcher = &pTask->outputInfo.fixedDispatcher;
7✔
667
  pDispatcher->taskId = pDownstreamTask->id.taskId;
7✔
668
  pDispatcher->nodeId = pDownstreamTask->info.nodeId;
7✔
669
  pDispatcher->epSet = pDownstreamTask->info.epSet;
7✔
670

671
  pTask->outputInfo.type = TASK_OUTPUT__FIXED_DISPATCH;
7✔
672
  pTask->msgInfo.msgType = TDMT_STREAM_TASK_DISPATCH;
7✔
673
}
7✔
674

675
int32_t streamTaskUpdateDownstreamInfo(SStreamTask* pTask, int32_t nodeId, const SEpSet* pEpSet, bool* pUpdated) {
6✔
676
  char    buf[512] = {0};
6✔
677
  int32_t code = epsetToStr(pEpSet, buf, tListLen(buf));  // ignore the error since only for log files.
6✔
678
  if (code != 0) {                                        // print error and continue
6!
679
    stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
680
    return code;
×
681
  }
682

683
  int32_t id = pTask->id.taskId;
6✔
684
  int8_t  type = pTask->outputInfo.type;
6✔
685

686
  if (type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
6✔
687
    SArray* pVgs = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
2✔
688

689
    for (int32_t i = 0; i < taosArrayGetSize(pVgs); i++) {
6✔
690
      SVgroupInfo* pVgInfo = taosArrayGet(pVgs, i);
4✔
691
      if (pVgInfo == NULL) {
4!
692
        continue;
×
693
      }
694

695
      if (pVgInfo->vgId == nodeId) {
4!
696
        bool isEqual = isEpsetEqual(&pVgInfo->epSet, pEpSet);
×
697
        if (!isEqual) {
×
698
          *pUpdated = true;
×
699

700
          char tmp[512] = {0};
×
701
          code = epsetToStr(&pVgInfo->epSet, tmp, tListLen(tmp));
×
702
          if (code != 0) {  // print error and continue
×
703
            stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
704
            return code;
×
705
          }
706

707
          epsetAssign(&pVgInfo->epSet, pEpSet);
×
708
          stDebug("s-task:0x%x update dispatch info, task:0x%x(nodeId:%d) newEpset:%s old:%s", id, pVgInfo->taskId,
×
709
                  nodeId, buf, tmp);
710
        } else {
711
          stDebug("s-task:0x%x not update dispatch info, since identical, task:0x%x(nodeId:%d) epset:%s", id,
×
712
                  pVgInfo->taskId, nodeId, buf);
713
        }
714
        break;
×
715
      }
716
    }
717
  } else if (type == TASK_OUTPUT__FIXED_DISPATCH) {
4!
718
    STaskDispatcherFixed* pDispatcher = &pTask->outputInfo.fixedDispatcher;
4✔
719
    if (pDispatcher->nodeId == nodeId) {
4!
720
      bool equal = isEpsetEqual(&pDispatcher->epSet, pEpSet);
4✔
721
      if (!equal) {
4!
722
        *pUpdated = true;
×
723

724
        char tmp[512] = {0};
×
725
        code = epsetToStr(&pDispatcher->epSet, tmp, tListLen(tmp));
×
726
        if (code != 0) {  // print error and continue
×
727
          stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
728
          return code;
×
729
        }
730

731
        epsetAssign(&pDispatcher->epSet, pEpSet);
×
732
        stDebug("s-task:0x%x update dispatch info, task:0x%x(nodeId:%d) newEpset:%s old:%s", id, pDispatcher->taskId,
×
733
                nodeId, buf, tmp);
734
      } else {
735
        stDebug("s-task:0x%x not update dispatch info, since identical, task:0x%x(nodeId:%d) epset:%s", id,
4!
736
                pDispatcher->taskId, nodeId, buf);
737
      }
738
    }
739
  } else if (type == TASK_OUTPUT__VTABLE_MAP) {
×
740
    SArray* pTaskInfos = pTask->outputInfo.vtableMapDispatcher.taskInfos;
×
741

742
    for (int32_t i = 0; i < taosArrayGetSize(pTaskInfos); ++i) {
×
743
      STaskDispatcherFixed* pAddr = taosArrayGet(pTaskInfos, i);
×
744
      if (pAddr == NULL) {
×
745
        continue;
×
746
      }
747

748
      if (pAddr->nodeId == nodeId) {
×
749
        bool isEqual = isEpsetEqual(&pAddr->epSet, pEpSet);
×
750
        if (!isEqual) {
×
751
          *pUpdated = true;
×
752

753
          char tmp[512] = {0};
×
754
          code = epsetToStr(&pAddr->epSet, tmp, tListLen(tmp));
×
755
          if (code != 0) {  // print error and continue
×
756
            stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
757
            return code;
×
758
          }
759

760
          epsetAssign(&pAddr->epSet, pEpSet);
×
761
          stDebug("s-task:0x%x update dispatch info, task:0x%x(nodeId:%d) newEpset:%s old:%s", id, pAddr->taskId,
×
762
                  nodeId, buf, tmp);
763
        } else {
764
          stDebug("s-task:0x%x not update dispatch info, since identical, task:0x%x(nodeId:%d) epset:%s", id,
×
765
                  pAddr->taskId, nodeId, buf);
766
        }
767
        break;
×
768
      }
769
    }
770
  }
771

772
  return code;
6✔
773
}
774

775
int32_t streamTaskStop(SStreamTask* pTask) {
24✔
776
  int32_t     vgId = pTask->pMeta->vgId;
24✔
777
  int64_t     st = taosGetTimestampMs();
24✔
778
  const char* id = pTask->id.idStr;
24✔
779

780
  int32_t code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_STOP);
24✔
781
  if (code) {
24!
782
    stError("failed to handle STOP event, s-task:%s, code:%s", id, tstrerror(code));
×
783
    return code;
×
784
  }
785

786
  if (pTask->info.taskLevel != TASK_LEVEL__SINK && pTask->exec.pExecutor != NULL) {
24✔
787
    code = qKillTask(pTask->exec.pExecutor, TSDB_CODE_SUCCESS, 5000);
14✔
788
    if (code != TSDB_CODE_SUCCESS) {
14!
789
      stError("s-task:%s failed to kill task related query handle, code:%s", id, tstrerror(code));
×
790
    }
791
  }
792

793
  while (!streamTaskIsIdle(pTask)) {
24!
794
    stDebug("s-task:%s level:%d wait for task to be idle and then close, check again in 100ms", id,
×
795
            pTask->info.taskLevel);
796
    taosMsleep(100);
×
797
  }
798

799
  int64_t el = taosGetTimestampMs() - st;
24✔
800
  stDebug("vgId:%d s-task:%s is closed in %" PRId64 " ms", vgId, id, el);
24!
801
  return code;
24✔
802
}
803

804
bool streamTaskUpdateEpsetInfo(SStreamTask* pTask, SArray* pNodeList) {
10✔
805
  STaskExecStatisInfo* p = &pTask->execInfo;
10✔
806

807
  int32_t numOfNodes = taosArrayGetSize(pNodeList);
10✔
808
  int64_t prevTs = p->latestUpdateTs;
10✔
809

810
  p->latestUpdateTs = taosGetTimestampMs();
10✔
811
  p->updateCount += 1;
10✔
812
  stDebug("s-task:0x%x update task nodeEp epset, updatedNodes:%d, updateCount:%d, prevTs:%" PRId64, pTask->id.taskId,
10!
813
          numOfNodes, p->updateCount, prevTs);
814

815
  bool updated = false;
10✔
816
  for (int32_t i = 0; i < numOfNodes; ++i) {
20✔
817
    SNodeUpdateInfo* pInfo = taosArrayGet(pNodeList, i);
10✔
818
    if (pInfo == NULL) {
10!
819
      continue;
×
820
    }
821

822
    int32_t code = doUpdateTaskEpset(pTask, pInfo->nodeId, &pInfo->newEp, &updated);
10✔
823
    if (code) {
10!
824
      stError("s-task:0x%x failed to update the task nodeEp epset, code:%s", pTask->id.taskId, tstrerror(code));
×
825
    }
826
  }
827

828
  return updated;
10✔
829
}
830

831
void streamTaskResetUpstreamStageInfo(SStreamTask* pTask) {
29✔
832
  if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) {
29✔
833
    return;
13✔
834
  }
835

836
  int32_t size = taosArrayGetSize(pTask->upstreamInfo.pList);
16✔
837
  for (int32_t i = 0; i < size; ++i) {
40✔
838
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
24✔
839
    pInfo->stage = -1;
24✔
840
  }
841

842
  stDebug("s-task:%s reset all upstream tasks stage info", pTask->id.idStr);
16!
843
}
844

845
void streamTaskOpenAllUpstreamInput(SStreamTask* pTask) {
43✔
846
  int32_t num = taosArrayGetSize(pTask->upstreamInfo.pList);
43✔
847
  if (num == 0) {
43✔
848
    return;
15✔
849
  }
850

851
  for (int32_t i = 0; i < num; ++i) {
70✔
852
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
42✔
853
    pInfo->dataAllowed = true;
42✔
854
  }
855

856
  pTask->upstreamInfo.numOfClosed = 0;
28✔
857
  stDebug("s-task:%s opening up inputQ for %d upstream tasks", pTask->id.idStr, num);
28!
858
}
859

860
void streamTaskCloseUpstreamInput(SStreamTask* pTask, int32_t taskId) {
4✔
861
  SStreamUpstreamEpInfo* pInfo = NULL;
4✔
862
  streamTaskGetUpstreamTaskEpInfo(pTask, taskId, &pInfo);
4✔
863

864
  if ((pInfo != NULL) && pInfo->dataAllowed) {
4!
865
    pInfo->dataAllowed = false;
4✔
866
    if (pTask->upstreamInfo.numOfClosed < streamTaskGetNumOfUpstream(pTask)) {
4!
867
      int32_t t = atomic_add_fetch_32(&pTask->upstreamInfo.numOfClosed, 1);
4✔
868
    } else {
869
      stError("s-task:%s not inc closed input, since they have been all closed already", pTask->id.idStr);
×
870
    }
871
  }
872
}
4✔
873

874
void streamTaskOpenUpstreamInput(SStreamTask* pTask, int32_t taskId) {
1✔
875
  SStreamUpstreamEpInfo* pInfo = NULL;
1✔
876
  streamTaskGetUpstreamTaskEpInfo(pTask, taskId, &pInfo);
1✔
877

878
  if (pInfo != NULL && (!pInfo->dataAllowed)) {
1!
879
    int32_t t = atomic_sub_fetch_32(&pTask->upstreamInfo.numOfClosed, 1);
1✔
880
    stDebug("s-task:%s open inputQ for upstream:0x%x, remain closed:%d", pTask->id.idStr, taskId, t);
1!
881
    pInfo->dataAllowed = true;
1✔
882
  }
883
}
1✔
884

885
bool streamTaskIsAllUpstreamClosed(SStreamTask* pTask) {
×
886
  return pTask->upstreamInfo.numOfClosed == taosArrayGetSize(pTask->upstreamInfo.pList);
×
887
}
888

889
bool streamTaskSetSchedStatusWait(SStreamTask* pTask) {
616✔
890
  bool ret = false;
616✔
891

892
  streamMutexLock(&pTask->lock);
616✔
893
  if (pTask->status.schedStatus == TASK_SCHED_STATUS__INACTIVE) {
616✔
894
    pTask->status.schedStatus = TASK_SCHED_STATUS__WAITING;
601✔
895
    ret = true;
601✔
896
  }
897

898
  streamMutexUnlock(&pTask->lock);
616✔
899
  return ret;
616✔
900
}
901

902
int8_t streamTaskSetSchedStatusActive(SStreamTask* pTask) {
556✔
903
  streamMutexLock(&pTask->lock);
556✔
904
  int8_t status = pTask->status.schedStatus;
556✔
905
  if (status == TASK_SCHED_STATUS__WAITING) {
556!
906
    pTask->status.schedStatus = TASK_SCHED_STATUS__ACTIVE;
556✔
907
  }
908
  streamMutexUnlock(&pTask->lock);
556✔
909

910
  return status;
556✔
911
}
912

913
int8_t streamTaskSetSchedStatusInactive(SStreamTask* pTask) {
45✔
914
  streamMutexLock(&pTask->lock);
45✔
915
  int8_t status = pTask->status.schedStatus;
45✔
916
  pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
45✔
917
  streamMutexUnlock(&pTask->lock);
45✔
918

919
  return status;
45✔
920
}
921

922
int32_t streamTaskClearHTaskAttr(SStreamTask* pTask, int32_t resetRelHalt) {
×
923
  int32_t      code = 0;
×
924
  SStreamMeta* pMeta = pTask->pMeta;
×
925
  SStreamTask* pStreamTask = NULL;
×
926

927
  if (pTask->info.fillHistory == 0) {
×
928
    return code;
×
929
  }
930

931
  code = streamMetaAcquireTaskUnsafe(pMeta, &pTask->streamTaskId, &pStreamTask);
×
932
  if (code == 0) {
×
933
    stDebug("s-task:%s clear the related stream task:0x%x attr to fill-history task", pTask->id.idStr,
×
934
            (int32_t)pTask->streamTaskId.taskId);
935

936
    streamMutexLock(&(pStreamTask->lock));
×
937
    CLEAR_RELATED_FILLHISTORY_TASK(pStreamTask);
×
938

939
    if (resetRelHalt) {
×
940
      stDebug("s-task:0x%" PRIx64 " set the persistent status attr to be ready, prev:%s, status in sm:%s",
×
941
              pTask->streamTaskId.taskId, streamTaskGetStatusStr(pStreamTask->status.taskStatus),
942
              streamTaskGetStatus(pStreamTask).name);
943
      pStreamTask->status.taskStatus = TASK_STATUS__READY;
×
944
    }
945

946
    code = streamMetaSaveTaskInMeta(pMeta, pStreamTask);
×
947
    streamMutexUnlock(&(pStreamTask->lock));
×
948

949
    streamMetaReleaseTask(pMeta, pStreamTask);
×
950
  }
951

952
  return code;
×
953
}
954

955
int32_t streamBuildAndSendDropTaskMsg(SMsgCb* pMsgCb, int32_t vgId, SStreamTaskId* pTaskId, int64_t resetRelHalt) {
×
956
  SVDropStreamTaskReq* pReq = rpcMallocCont(sizeof(SVDropStreamTaskReq));
×
957
  if (pReq == NULL) {
×
958
    return terrno;
×
959
  }
960

961
  pReq->head.vgId = vgId;
×
962
  pReq->taskId = pTaskId->taskId;
×
963
  pReq->streamId = pTaskId->streamId;
×
964
  pReq->resetRelHalt = resetRelHalt;
×
965

966
  SRpcMsg msg = {.msgType = TDMT_STREAM_TASK_DROP, .pCont = pReq, .contLen = sizeof(SVDropStreamTaskReq)};
×
967
  int32_t code = tmsgPutToQueue(pMsgCb, WRITE_QUEUE, &msg);
×
968
  if (code != TSDB_CODE_SUCCESS) {
×
969
    stError("vgId:%d failed to send drop task:0x%x msg, code:%s", vgId, pTaskId->taskId, tstrerror(code));
×
970
  } else {
971
    stDebug("vgId:%d build and send drop task:0x%x msg", vgId, pTaskId->taskId);
×
972
  }
973

974
  return code;
×
975
}
976

977
int32_t streamSendChkptReportMsg(SStreamTask* pTask, SCheckpointInfo* pCheckpointInfo, int8_t dropRelHTask) {
5✔
978
  int32_t                code = 0;
5✔
979
  int32_t                tlen = 0;
5✔
980
  int32_t                vgId = pTask->pMeta->vgId;
5✔
981
  const char*            id = pTask->id.idStr;
5✔
982
  SActiveCheckpointInfo* pActive = pCheckpointInfo->pActiveInfo;
5✔
983

984
  SCheckpointReport req = {.streamId = pTask->id.streamId,
5✔
985
                           .taskId = pTask->id.taskId,
5✔
986
                           .nodeId = vgId,
987
                           .dropHTask = dropRelHTask,
988
                           .transId = pActive->transId,
5✔
989
                           .checkpointId = pActive->activeId,
5✔
990
                           .checkpointVer = pCheckpointInfo->processedVer,
5✔
991
                           .checkpointTs = pCheckpointInfo->startTs};
5✔
992

993
  tEncodeSize(tEncodeStreamTaskChkptReport, &req, tlen, code);
5!
994
  if (code < 0) {
5!
995
    stError("s-task:%s vgId:%d encode stream task checkpoint-report failed, code:%s", id, vgId, tstrerror(code));
×
996
    return -1;
×
997
  }
998

999
  void* buf = rpcMallocCont(tlen);
5✔
1000
  if (buf == NULL) {
5!
1001
    stError("s-task:%s vgId:%d encode stream task checkpoint-report msg failed, code:%s", id, vgId,
×
1002
            tstrerror(TSDB_CODE_OUT_OF_MEMORY));
1003
    return -1;
×
1004
  }
1005

1006
  SEncoder encoder;
1007
  tEncoderInit(&encoder, buf, tlen);
5✔
1008
  if ((code = tEncodeStreamTaskChkptReport(&encoder, &req)) < 0) {
5!
1009
    rpcFreeCont(buf);
×
1010
    tEncoderClear(&encoder);
×
1011
    stError("s-task:%s vgId:%d encode stream task checkpoint-report msg failed, code:%s", id, vgId, tstrerror(code));
×
1012
    return -1;
×
1013
  }
1014
  tEncoderClear(&encoder);
5✔
1015

1016
  SRpcMsg msg = {0};
5✔
1017
  initRpcMsg(&msg, TDMT_MND_STREAM_CHKPT_REPORT, buf, tlen);
5✔
1018
  stDebug("s-task:%s vgId:%d build and send task checkpoint-report to mnode", id, vgId);
5!
1019

1020
  return tmsgSendReq(&pTask->info.mnodeEpset, &msg);
5✔
1021
}
1022

1023
STaskId streamTaskGetTaskId(const SStreamTask* pTask) {
162✔
1024
  STaskId id = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId};
162✔
1025
  return id;
162✔
1026
}
1027

1028
void streamTaskInitForLaunchHTask(SHistoryTaskInfo* pInfo) {
1✔
1029
  pInfo->waitInterval = LAUNCH_HTASK_INTERVAL;
1✔
1030
  pInfo->tickCount = ceil(LAUNCH_HTASK_INTERVAL / WAIT_FOR_MINIMAL_INTERVAL);
1✔
1031
  pInfo->retryTimes = 0;
1✔
1032
}
1✔
1033

1034
void streamTaskSetRetryInfoForLaunch(SHistoryTaskInfo* pInfo) {
1✔
1035
  pInfo->waitInterval *= RETRY_LAUNCH_INTERVAL_INC_RATE;
1✔
1036
  pInfo->tickCount = ceil(pInfo->waitInterval / WAIT_FOR_MINIMAL_INTERVAL);
1✔
1037
  pInfo->retryTimes += 1;
1✔
1038
}
1✔
1039

1040
void streamTaskStatusInit(STaskStatusEntry* pEntry, const SStreamTask* pTask) {
30✔
1041
  pEntry->id.streamId = pTask->id.streamId;
30✔
1042
  pEntry->id.taskId = pTask->id.taskId;
30✔
1043
  pEntry->stage = -1;
30✔
1044
  pEntry->nodeId = pTask->info.nodeId;
30✔
1045
  pEntry->status = TASK_STATUS__STOP;
30✔
1046
}
30✔
1047

1048
void streamTaskStatusCopy(STaskStatusEntry* pDst, const STaskStatusEntry* pSrc) {
134✔
1049
  pDst->stage = pSrc->stage;
134✔
1050
  pDst->inputQUsed = pSrc->inputQUsed;
134✔
1051
  pDst->inputRate = pSrc->inputRate;
134✔
1052
  pDst->procsTotal = pSrc->procsTotal;
134✔
1053
  pDst->procsThroughput = pSrc->procsThroughput;
134✔
1054
  pDst->outputTotal = pSrc->outputTotal;
134✔
1055
  pDst->outputThroughput = pSrc->outputThroughput;
134✔
1056
  pDst->processedVer = pSrc->processedVer;
134✔
1057
  pDst->verRange = pSrc->verRange;
134✔
1058
  pDst->sinkQuota = pSrc->sinkQuota;
134✔
1059
  pDst->sinkDataSize = pSrc->sinkDataSize;
134✔
1060
  pDst->checkpointInfo = pSrc->checkpointInfo;
134✔
1061
  pDst->startCheckpointId = pSrc->startCheckpointId;
134✔
1062
  pDst->startCheckpointVer = pSrc->startCheckpointVer;
134✔
1063
  pDst->status = pSrc->status;
134✔
1064

1065
  pDst->startTime = pSrc->startTime;
134✔
1066
  pDst->hTaskId = pSrc->hTaskId;
134✔
1067
  pDst->notifyEventStat = pSrc->notifyEventStat;
134✔
1068
}
134✔
1069

1070
STaskStatusEntry streamTaskGetStatusEntry(SStreamTask* pTask) {
138✔
1071
  SStreamMeta*         pMeta = pTask->pMeta;
138✔
1072
  STaskExecStatisInfo* pExecInfo = &pTask->execInfo;
138✔
1073

1074
  STaskStatusEntry entry = {
414✔
1075
      .id = streamTaskGetTaskId(pTask),
138✔
1076
      .status = streamTaskGetStatus(pTask).state,
138✔
1077
      .nodeId = pMeta->vgId,
138✔
1078
      .stage = pMeta->stage,
138✔
1079

1080
      .inputQUsed = SIZE_IN_MiB(streamQueueGetItemSize(pTask->inputq.queue)),
138✔
1081
      .startTime = pExecInfo->readyTs,
138✔
1082
      .checkpointInfo.latestId = pTask->chkInfo.checkpointId,
138✔
1083
      .checkpointInfo.latestVer = pTask->chkInfo.checkpointVer,
138✔
1084
      .checkpointInfo.latestTime = pTask->chkInfo.checkpointTime,
138✔
1085
      .checkpointInfo.latestSize = 0,
1086
      .checkpointInfo.remoteBackup = 0,
1087
      .checkpointInfo.consensusChkptId = 0,
1088
      .checkpointInfo.consensusTs = 0,
1089
      .hTaskId = pTask->hTaskInfo.id.taskId,
138✔
1090
      .procsTotal = SIZE_IN_MiB(pExecInfo->inputDataSize),
138✔
1091
      .outputTotal = SIZE_IN_MiB(pExecInfo->outputDataSize),
138✔
1092
      .procsThroughput = SIZE_IN_KiB(pExecInfo->procsThroughput),
138✔
1093
      .outputThroughput = SIZE_IN_KiB(pExecInfo->outputThroughput),
138✔
1094
      .startCheckpointId = pExecInfo->startCheckpointId,
138✔
1095
      .startCheckpointVer = pExecInfo->startCheckpointVer,
138✔
1096
      .notifyEventStat = pTask->notifyEventStat,
1097
  };
1098
  return entry;
138✔
1099
}
1100

1101
static int32_t taskPauseCallback(SStreamTask* pTask, void* param) {
×
1102
  SStreamMeta* pMeta = pTask->pMeta;
×
1103
  int32_t      code = 0;
×
1104

1105
  int32_t num = atomic_add_fetch_32(&pMeta->numOfPausedTasks, 1);
×
1106
  stInfo("vgId:%d s-task:%s pause stream task. paused task num:%d", pMeta->vgId, pTask->id.idStr, num);
×
1107

1108
  // in case of fill-history task, stop the tsdb file scan operation.
1109
  if (pTask->info.fillHistory == 1) {
×
1110
    void* pExecutor = pTask->exec.pExecutor;
×
1111
    code = qKillTask(pExecutor, TSDB_CODE_SUCCESS, 10000);
×
1112
  }
1113

1114
  stDebug("vgId:%d s-task:%s set pause flag and pause task", pMeta->vgId, pTask->id.idStr);
×
1115
  return code;
×
1116
}
1117

1118
void streamTaskPause(SStreamTask* pTask) {
×
1119
  int32_t code = streamTaskHandleEventAsync(pTask->status.pSM, TASK_EVENT_PAUSE, taskPauseCallback, NULL);
×
1120
  if (code) {
×
1121
    stError("s-task:%s failed handle pause event async, code:%s", pTask->id.idStr, tstrerror(code));
×
1122
  }
1123
}
×
1124

1125
void streamTaskResume(SStreamTask* pTask) {
×
1126
  SStreamTaskState prevState = streamTaskGetStatus(pTask);
×
1127

1128
  SStreamMeta* pMeta = pTask->pMeta;
×
1129
  int32_t      code = streamTaskRestoreStatus(pTask);
×
1130
  if (code == TSDB_CODE_SUCCESS) {
×
1131
    char*   pNew = streamTaskGetStatus(pTask).name;
×
1132
    int32_t num = atomic_sub_fetch_32(&pMeta->numOfPausedTasks, 1);
×
1133
    stInfo("s-task:%s status:%s resume from %s, paused task(s):%d", pTask->id.idStr, pNew, prevState.name, num);
×
1134
  } else {
1135
    stInfo("s-task:%s status:%s no need to resume, paused task(s):%d", pTask->id.idStr, prevState.name,
×
1136
           pMeta->numOfPausedTasks);
1137
  }
1138
}
×
1139

1140
bool streamTaskIsSinkTask(const SStreamTask* pTask) { return pTask->info.taskLevel == TASK_LEVEL__SINK; }
617✔
1141

1142
// this task must success
1143
int32_t streamTaskSendCheckpointReq(SStreamTask* pTask) {
5✔
1144
  int32_t     code;
1145
  int32_t     tlen = 0;
5✔
1146
  int32_t     vgId = pTask->pMeta->vgId;
5✔
1147
  const char* id = pTask->id.idStr;
5✔
1148

1149
  SStreamTaskCheckpointReq req = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId, .nodeId = vgId};
5✔
1150
  tEncodeSize(tEncodeStreamTaskCheckpointReq, &req, tlen, code);
5!
1151
  if (code < 0) {
5!
1152
    stError("s-task:%s vgId:%d encode stream task req checkpoint failed, code:%s", id, vgId, tstrerror(code));
×
1153
    return TSDB_CODE_INVALID_MSG;
×
1154
  }
1155

1156
  void* buf = rpcMallocCont(tlen);
5✔
1157
  if (buf == NULL) {
5!
1158
    stError("s-task:%s vgId:%d encode stream task req checkpoint msg failed, code:Out of memory", id, vgId);
×
1159
    return terrno;
×
1160
  }
1161

1162
  SEncoder encoder;
1163
  tEncoderInit(&encoder, buf, tlen);
5✔
1164
  if ((code = tEncodeStreamTaskCheckpointReq(&encoder, &req)) < 0) {
5!
1165
    rpcFreeCont(buf);
×
1166
    tEncoderClear(&encoder);
×
1167
    stError("s-task:%s vgId:%d encode stream task req checkpoint msg failed, code:%s", id, vgId, tstrerror(code));
×
1168
    return code;
×
1169
  }
1170

1171
  tEncoderClear(&encoder);
5✔
1172

1173
  SRpcMsg msg = {0};
5✔
1174
  initRpcMsg(&msg, TDMT_MND_STREAM_REQ_CHKPT, buf, tlen);
5✔
1175
  stDebug("s-task:%s vgId:%d build and send task checkpoint req", id, vgId);
5!
1176

1177
  return tmsgSendReq(&pTask->info.mnodeEpset, &msg);
5✔
1178
}
1179

1180
void streamTaskGetUpstreamTaskEpInfo(SStreamTask* pTask, int32_t taskId, SStreamUpstreamEpInfo** pEpInfo) {
393✔
1181
  *pEpInfo = NULL;
393✔
1182

1183
  int32_t num = taosArrayGetSize(pTask->upstreamInfo.pList);
393✔
1184
  for (int32_t i = 0; i < num; ++i) {
509!
1185
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
509✔
1186
    if (pInfo == NULL) {
509!
1187
      return;
×
1188
    }
1189

1190
    if (pInfo->taskId == taskId) {
509✔
1191
      *pEpInfo = pInfo;
393✔
1192
      return;
393✔
1193
    }
1194
  }
1195

1196
  stError("s-task:%s failed to find upstream task:0x%x", pTask->id.idStr, taskId);
×
1197
}
1198

1199
SEpSet* streamTaskGetDownstreamEpInfo(SStreamTask* pTask, int32_t taskId) {
×
1200
  if (pTask->info.taskLevel == TASK_OUTPUT__FIXED_DISPATCH) {
×
1201
    if (pTask->outputInfo.fixedDispatcher.taskId == taskId) {
×
1202
      return &pTask->outputInfo.fixedDispatcher.epSet;
×
1203
    }
1204
  } else if (pTask->info.taskLevel == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
1205
    SArray* pList = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
×
1206
    for (int32_t i = 0; i < taosArrayGetSize(pList); ++i) {
×
1207
      SVgroupInfo* pVgInfo = taosArrayGet(pList, i);
×
1208
      if (pVgInfo == NULL) {
×
1209
        continue;
×
1210
      }
1211

1212
      if (pVgInfo->taskId == taskId) {
×
1213
        return &pVgInfo->epSet;
×
1214
      }
1215
    }
1216
  } else if (pTask->info.taskLevel == TASK_OUTPUT__VTABLE_MAP) {
×
1217
    SArray* pTaskInfos = pTask->outputInfo.vtableMapDispatcher.taskInfos;
×
1218
    for (int32_t i = 0; i < taosArrayGetSize(pTaskInfos); ++i) {
×
1219
      STaskDispatcherFixed* pAddr = taosArrayGet(pTaskInfos, i);
×
1220
      if (pAddr == NULL) {
×
1221
        continue;
×
1222
      }
1223

1224
      if (pAddr->taskId == taskId) {
×
1225
        return &pAddr->epSet;
×
1226
      }
1227
    }
1228
  }
1229

1230
  return NULL;
×
1231
}
1232

1233
int32_t createStreamTaskIdStr(int64_t streamId, int32_t taskId, const char** pId) {
29✔
1234
  char    buf[128] = {0};
29✔
1235
  int32_t code = snprintf(buf, tListLen(buf), "0x%" PRIx64 "-0x%x", streamId, taskId);
29✔
1236
  if (code < 0 || code >= tListLen(buf)) {
29!
1237
    return TSDB_CODE_OUT_OF_BUFFER;
×
1238
  }
1239

1240
  *pId = taosStrdup(buf);
29!
1241

1242
  if (*pId == NULL) {
29!
1243
    return terrno;
×
1244
  } else {
1245
    return TSDB_CODE_SUCCESS;
29✔
1246
  }
1247
}
1248

1249
static int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq) {
×
1250
  int32_t           code;
1251
  SStreamDataBlock* pData;
1252

1253
  code = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, sizeof(SStreamDataBlock), (void**)&pData);
×
1254
  if (code) {
×
1255
    stError("s-task:%s failed to allocated retrieve-block", pTask->id.idStr);
×
1256
    return terrno = code;
×
1257
  }
1258

1259
  pData->type = STREAM_INPUT__DATA_RETRIEVE;
×
1260
  pData->srcVgId = 0;
×
1261

1262
  code = streamRetrieveReqToData(pReq, pData, pTask->id.idStr);
×
1263
  if (code != TSDB_CODE_SUCCESS) {
×
1264
    stError("s-task:%s failed to convert retrieve-data to block, code:%s", pTask->id.idStr, tstrerror(code));
×
1265
    taosFreeQitem(pData);
×
1266
    return code;
×
1267
  }
1268

1269
  code = streamTaskPutDataIntoInputQ(pTask, (SStreamQueueItem*)pData);
×
1270
  if (code != TSDB_CODE_SUCCESS) {
×
1271
    stError("s-task:%s failed to put retrieve-block into inputQ, inputQ is full, discard the retrieve msg",
×
1272
            pTask->id.idStr);
1273
  }
1274

1275
  return code;
×
1276
}
1277

1278
int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq) {
×
1279
  int32_t code = streamTaskEnqueueRetrieve(pTask, pReq);
×
1280
  if (code != 0) {
×
1281
    return code;
×
1282
  }
1283
  return streamTrySchedExec(pTask, false);
×
1284
}
1285

1286
void streamTaskSetRemoveBackendFiles(SStreamTask* pTask) { pTask->status.removeBackendFiles = true; }
×
1287

1288
void streamTaskGetActiveCheckpointInfo(const SStreamTask* pTask, int32_t* pTransId, int64_t* pCheckpointId) {
×
1289
  if (pTransId != NULL) {
×
1290
    *pTransId = pTask->chkInfo.pActiveInfo->transId;
×
1291
  }
1292

1293
  if (pCheckpointId != NULL) {
×
1294
    *pCheckpointId = pTask->chkInfo.pActiveInfo->activeId;
×
1295
  }
1296
}
×
1297

1298
int32_t streamTaskSetActiveCheckpointInfo(SStreamTask* pTask, int64_t activeCheckpointId) {
×
1299
  pTask->chkInfo.pActiveInfo->activeId = activeCheckpointId;
×
1300
  return TSDB_CODE_SUCCESS;
×
1301
}
1302

1303
void streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t checkpointId) {
×
1304
  pTask->chkInfo.pActiveInfo->transId = transId;
×
1305
  pTask->chkInfo.pActiveInfo->activeId = checkpointId;
×
1306
  pTask->chkInfo.pActiveInfo->failedId = checkpointId;
×
1307
  stDebug("s-task:%s set failed checkpointId:%" PRId64, pTask->id.idStr, checkpointId);
×
1308
}
×
1309

1310
int32_t streamTaskCreateActiveChkptInfo(SActiveCheckpointInfo** pRes) {
39✔
1311
  SActiveCheckpointInfo* pInfo = taosMemoryCalloc(1, sizeof(SActiveCheckpointInfo));
39!
1312
  if (pInfo == NULL) {
39!
1313
    return terrno;
×
1314
  }
1315

1316
  int32_t code = taosThreadMutexInit(&pInfo->lock, NULL);
39✔
1317
  if (code != TSDB_CODE_SUCCESS) {
39!
1318
    return code;
×
1319
  }
1320

1321
  pInfo->pDispatchTriggerList = taosArrayInit(4, sizeof(STaskTriggerSendInfo));
39✔
1322
  pInfo->pReadyMsgList = taosArrayInit(4, sizeof(STaskCheckpointReadyInfo));
39✔
1323
  pInfo->pCheckpointReadyRecvList = taosArrayInit(4, sizeof(STaskDownstreamReadyInfo));
39✔
1324

1325
  *pRes = pInfo;
39✔
1326
  return code;
39✔
1327
}
1328

1329
void streamTaskDestroyActiveChkptInfo(SActiveCheckpointInfo* pInfo) {
115✔
1330
  if (pInfo == NULL) {
115✔
1331
    return;
80✔
1332
  }
1333

1334
  streamMutexDestroy(&pInfo->lock);
35✔
1335
  taosArrayDestroy(pInfo->pDispatchTriggerList);
35✔
1336
  pInfo->pDispatchTriggerList = NULL;
35✔
1337
  taosArrayDestroy(pInfo->pReadyMsgList);
35✔
1338
  pInfo->pReadyMsgList = NULL;
35✔
1339
  taosArrayDestroy(pInfo->pCheckpointReadyRecvList);
35✔
1340
  pInfo->pCheckpointReadyRecvList = NULL;
35✔
1341

1342
  SStreamTmrInfo* pTriggerTmr = &pInfo->chkptTriggerMsgTmr;
35✔
1343
  if (pTriggerTmr->tmrHandle != NULL) {
35✔
1344
    streamTmrStop(pTriggerTmr->tmrHandle);
3✔
1345
    pTriggerTmr->tmrHandle = NULL;
3✔
1346
  }
1347

1348
  SStreamTmrInfo* pReadyTmr = &pInfo->chkptReadyMsgTmr;
35✔
1349
  if (pReadyTmr->tmrHandle != NULL) {
35✔
1350
    streamTmrStop(pReadyTmr->tmrHandle);
3✔
1351
    pReadyTmr->tmrHandle = NULL;
3✔
1352
  }
1353

1354
  taosMemoryFree(pInfo);
35!
1355
}
1356

1357
// NOTE: clear the checkpoint id, and keep the failed id
1358
// failedId for a task will increase as the checkpoint I.D. increases.
1359
void streamTaskClearActiveInfo(SActiveCheckpointInfo* pInfo) {
5✔
1360
  pInfo->activeId = 0;
5✔
1361
  pInfo->transId = 0;
5✔
1362
  pInfo->allUpstreamTriggerRecv = 0;
5✔
1363
  pInfo->dispatchTrigger = false;
5✔
1364

1365
  taosArrayClear(pInfo->pDispatchTriggerList);
5✔
1366
  taosArrayClear(pInfo->pCheckpointReadyRecvList);
5✔
1367
}
5✔
1368

1369
const char* streamTaskGetExecType(int32_t type) {
1,536✔
1370
  switch (type) {
1,536!
1371
    case STREAM_EXEC_T_EXTRACT_WAL_DATA:
591✔
1372
      return "scan-wal-file";
591✔
1373
    case STREAM_EXEC_T_START_ALL_TASKS:
184✔
1374
      return "start-all-tasks";
184✔
1375
    case STREAM_EXEC_T_START_ONE_TASK:
23✔
1376
      return "start-one-task";
23✔
1377
    case STREAM_EXEC_T_RESTART_ALL_TASKS:
3✔
1378
      return "restart-all-tasks";
3✔
1379
    case STREAM_EXEC_T_STOP_ALL_TASKS:
118✔
1380
      return "stop-all-tasks";
118✔
1381
    case STREAM_EXEC_T_RESUME_TASK:
18✔
1382
      return "resume-task-from-idle";
18✔
1383
    case STREAM_EXEC_T_ADD_FAILED_TASK:
×
1384
      return "record-start-failed-task";
×
1385
    case STREAM_EXEC_T_STOP_ONE_TASK:
×
1386
      return "stop-one-task";
×
1387
    case 0:
599✔
1388
      return "exec-all-tasks";
599✔
1389
    default:
×
1390
      return "invalid-exec-type";
×
1391
  }
1392
}
1393

1394
int32_t streamTaskAllocRefId(SStreamTask* pTask, int64_t** pRefId) {
358✔
1395
  *pRefId = taosMemoryMalloc(sizeof(int64_t));
358!
1396
  if (*pRefId != NULL) {
358!
1397
    **pRefId = pTask->id.refId;
358✔
1398
    int32_t code = metaRefMgtAdd(pTask->pMeta->vgId, *pRefId);
358✔
1399
    if (code != 0) {
358!
1400
      stError("s-task:%s failed to add refId:%" PRId64 " into refId-mgmt, code:%s", pTask->id.idStr, pTask->id.refId,
×
1401
              tstrerror(code));
1402
    }
1403
    return code;
358✔
1404
  } else {
1405
    stError("s-task:%s failed to alloc new ref id, code:%s", pTask->id.idStr, tstrerror(terrno));
×
1406
    return terrno;
×
1407
  }
1408
}
1409

1410
void streamTaskFreeRefId(int64_t* pRefId) {
369✔
1411
  if (pRefId == NULL) {
369✔
1412
    return;
11✔
1413
  }
1414

1415
  metaRefMgtRemove(pRefId);
358✔
1416
}
1417

1418
static int32_t tEncodeStreamNotifyInfo(SEncoder* pEncoder, const SNotifyInfo* info) {
236✔
1419
  int32_t code = TSDB_CODE_SUCCESS;
236✔
1420
  int32_t lino = 0;
236✔
1421

1422
  QUERY_CHECK_NULL(pEncoder, code, lino, _exit, TSDB_CODE_INVALID_PARA);
236!
1423
  QUERY_CHECK_NULL(info, code, lino, _exit, TSDB_CODE_INVALID_PARA);
236!
1424

1425
  int32_t addrSize = taosArrayGetSize(info->pNotifyAddrUrls);
236✔
1426
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, addrSize));
236!
1427
  for (int32_t i = 0; i < addrSize; ++i) {
236!
1428
    const char* url = taosArrayGetP(info->pNotifyAddrUrls, i);
×
1429
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, url));
×
1430
  }
1431
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, info->notifyEventTypes));
472!
1432
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, info->notifyErrorHandle));
472!
1433
  if (addrSize > 0) {
236!
1434
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, info->streamName));
×
1435
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, info->stbFullName));
×
1436
    TAOS_CHECK_EXIT(tEncodeSSchemaWrapper(pEncoder, info->pSchemaWrapper));
×
1437
  }
1438

1439
_exit:
236✔
1440
  if (code != TSDB_CODE_SUCCESS) {
236!
1441
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1442
  }
1443
  return code;
236✔
1444
}
1445

1446
static int32_t tDecodeStreamNotifyInfo(SDecoder* pDecoder, SNotifyInfo* info) {
88✔
1447
  int32_t code = TSDB_CODE_SUCCESS;
88✔
1448
  int32_t lino = 0;
88✔
1449

1450
  QUERY_CHECK_NULL(pDecoder, code, lino, _exit, TSDB_CODE_INVALID_PARA);
88!
1451
  QUERY_CHECK_NULL(info, code, lino, _exit, TSDB_CODE_INVALID_PARA);
88!
1452

1453
  int32_t addrSize = 0;
88✔
1454
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &addrSize));
88!
1455
  info->pNotifyAddrUrls = taosArrayInit(addrSize, POINTER_BYTES);
88✔
1456
  QUERY_CHECK_NULL(info->pNotifyAddrUrls, code, lino, _exit, terrno);
88!
1457
  for (int32_t i = 0; i < addrSize; ++i) {
88!
1458
    char* url = NULL;
×
1459
    TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &url));
×
1460
    url = taosStrndup(url, TSDB_STREAM_NOTIFY_URL_LEN);
×
1461
    QUERY_CHECK_NULL(url, code, lino, _exit, terrno);
×
1462
    if (taosArrayPush(info->pNotifyAddrUrls, &url) == NULL) {
×
1463
      taosMemoryFree(url);
×
1464
      TAOS_CHECK_EXIT(terrno);
×
1465
    }
1466
  }
1467
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &info->notifyEventTypes));
176!
1468
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &info->notifyErrorHandle));
176!
1469
  if (addrSize > 0) {
88!
1470
    char* name = NULL;
×
1471
    TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &name));
×
1472
    info->streamName = taosStrndup(name, TSDB_STREAM_FNAME_LEN + 1);
×
1473
    QUERY_CHECK_NULL(info->streamName, code, lino, _exit, terrno);
×
1474
    TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &name));
×
1475
    info->stbFullName = taosStrndup(name, TSDB_STREAM_FNAME_LEN + 1);
×
1476
    QUERY_CHECK_NULL(info->stbFullName, code, lino, _exit, terrno);
×
1477
    info->pSchemaWrapper = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
×
1478
    if (info->pSchemaWrapper == NULL) {
×
1479
      TAOS_CHECK_EXIT(terrno);
×
1480
    }
1481
    TAOS_CHECK_EXIT(tDecodeSSchemaWrapper(pDecoder, info->pSchemaWrapper));
×
1482
  }
1483

1484
_exit:
88✔
1485
  if (code != TSDB_CODE_SUCCESS) {
88!
1486
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1487
  }
1488
  return code;
88✔
1489
}
1490

1491
int32_t tEncodeVTablesInfo(SEncoder* pEncoder, SArray* pVTables) {
236✔
1492
  int32_t code = TSDB_CODE_SUCCESS;
236✔
1493
  int32_t lino = 0;
236✔
1494
  SVCTableMergeInfo* pMergeInfo = NULL;
236✔
1495
  int32_t mergeNum = taosArrayGetSize(pVTables);
236✔
1496
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, mergeNum));
236!
1497
  for (int32_t i = 0; i < mergeNum; ++i) {
236!
1498
    pMergeInfo = (SVCTableMergeInfo*)taosArrayGet(pVTables, i);
×
1499
    TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pMergeInfo->uid));
×
1500
    TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pMergeInfo->numOfSrcTbls));
×
1501
  }
1502

1503
_exit:
236✔
1504
  if (code != TSDB_CODE_SUCCESS) {
236!
1505
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1506
  }
1507
  return code;
236✔
1508
}
1509

1510
static int32_t tDecodeVTablesInfo(SDecoder* pDecoder, SArray** pTables) {
88✔
1511
  int32_t code = TSDB_CODE_SUCCESS;
88✔
1512
  int32_t lino = 0;
88✔
1513

1514
  int32_t mergeNum = 0;
88✔
1515
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &mergeNum));
88!
1516
  if (mergeNum > 0) {
88!
1517
    *pTables = taosArrayInit(mergeNum, sizeof(SVCTableMergeInfo));
×
1518
    QUERY_CHECK_NULL(*pTables, code, lino, _exit, terrno);
×
1519
  }
1520

1521
  SVCTableMergeInfo mergeInfo;
1522
  for (int32_t i = 0; i < mergeNum; ++i) {
88!
1523
    TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &mergeInfo.uid));
×
1524
    TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &mergeInfo.numOfSrcTbls));
×
1525
    if (taosArrayPush(*pTables, &mergeInfo) == NULL) {
×
1526
      TAOS_CHECK_EXIT(terrno);
×
1527
    }
1528
  }
1529

1530
_exit:
88✔
1531
  if (code != TSDB_CODE_SUCCESS) {
88!
1532
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1533
  }
1534
  return code;
88✔
1535
}
1536

1537
int32_t tSerializeDispatcherTaskInfo(SEncoder* pEncoder, const SArray* pTaskInfos) {
×
1538
  int32_t code = TSDB_CODE_SUCCESS;
×
1539
  int32_t lino = 0;
×
1540
  int32_t nTasks = taosArrayGetSize(pTaskInfos);
×
1541
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, nTasks));
×
1542
  for (int32_t i = 0; i < nTasks; ++i) {
×
1543
    STaskDispatcherFixed* pAddr = taosArrayGet(pTaskInfos, i);
×
1544
    TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pAddr->taskId));
×
1545
    TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pAddr->nodeId));
×
1546
    TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pAddr->epSet));
×
1547
  }
1548

1549
_exit:
×
1550
  if (code != TSDB_CODE_SUCCESS) {
×
1551
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1552
  }
1553
  return code;
×
1554
}
1555

1556
int32_t tSerializeDispatcherVtableMap(SEncoder* pEncoder, const SSHashObj* pVtables) {
×
1557
  int32_t code = TSDB_CODE_SUCCESS;
×
1558
  int32_t lino = 0;
×
1559
  int32_t tbNum = tSimpleHashGetSize(pVtables);
×
1560
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, tbNum));
×
1561
  int32_t iter = 0;
×
1562
  void*   p = tSimpleHashIterate(pVtables, NULL, &iter);
×
1563
  while (p != NULL) {
×
1564
    int64_t* pUid = tSimpleHashGetKey(p, NULL);
×
1565
    int32_t* pIdx = p;
×
1566
    TAOS_CHECK_EXIT(tEncodeI64(pEncoder, *pUid));
×
1567
    TAOS_CHECK_EXIT(tEncodeI32(pEncoder, *pIdx));
×
1568
    p = tSimpleHashIterate(pVtables, p, &iter);
×
1569
  }
1570

1571
_exit:
×
1572
  if (code != TSDB_CODE_SUCCESS) {
×
1573
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1574
  }
1575
  return code;
×
1576
}
1577

1578
int32_t tDeserializeDispatcherTaskInfo(SDecoder* pDecoder, SArray** ppTaskInfos) {
×
1579
  int32_t code = TSDB_CODE_SUCCESS;
×
1580
  int32_t lino = 0;
×
1581
  int32_t nTasks = 0;
×
1582
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &nTasks));
×
1583
  if (nTasks <= 0) {
×
1584
    return code;
×
1585
  }
1586

1587
  *ppTaskInfos = taosArrayInit(nTasks, sizeof(STaskDispatcherFixed));
×
1588
  QUERY_CHECK_NULL(*ppTaskInfos, code, lino, _exit, terrno);
×
1589

1590
  STaskDispatcherFixed addr;
1591
  for (int32_t i = 0; i < nTasks; ++i) {
×
1592
    TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &addr.taskId));
×
1593
    TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &addr.nodeId));
×
1594
    TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &addr.epSet));
×
1595
    void* px = taosArrayPush(*ppTaskInfos, &addr);
×
1596
    QUERY_CHECK_NULL(px, code, lino, _exit, terrno);
×
1597
  }
1598

1599
_exit:
×
1600
  if (code != TSDB_CODE_SUCCESS) {
×
1601
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1602
  }
1603
  return code;
×
1604
}
1605

1606
int32_t tDeserializeDispatcherVtableMap(SDecoder* pDecoder, SSHashObj** ppVtables) {
×
1607
  int32_t code = TSDB_CODE_SUCCESS;
×
1608
  int32_t lino = 0;
×
1609
  int32_t tbNum = 0;
×
1610
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &tbNum));
×
1611
  if (tbNum <= 0) {
×
1612
    return code;
×
1613
  }
1614

1615
  *ppVtables = tSimpleHashInit(tbNum, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT));
×
1616
  QUERY_CHECK_NULL(*ppVtables, code, lino, _exit, terrno);
×
1617

1618
  uint64_t uid = 0;
×
1619
  int32_t  idx = 0;
×
1620
  for (int32_t i = 0; i < tbNum; ++i) {
×
1621
    TAOS_CHECK_EXIT(tDecodeU64(pDecoder, &uid));
×
1622
    TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &idx));
×
1623
    TAOS_CHECK_EXIT(tSimpleHashPut(*ppVtables, &uid, sizeof(uid), &idx, sizeof(idx)));
×
1624
  }
1625

1626
_exit:
×
1627

1628
  if (code != TSDB_CODE_SUCCESS) {
×
1629
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1630
  }
1631
  return code;
×
1632
}
1633

1634
int32_t tEncodeStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) {
236✔
1635
  int32_t code = 0;
236✔
1636
  int32_t lino;
1637

1638
  TAOS_CHECK_EXIT(tStartEncode(pEncoder));
236!
1639
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->ver));
472!
1640
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->id.streamId));
472!
1641
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->id.taskId));
472!
1642
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.trigger));
472!
1643
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->info.taskLevel));
472!
1644
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->outputInfo.type));
472!
1645
  TAOS_CHECK_EXIT(tEncodeI16(pEncoder, pTask->msgInfo.msgType));
472!
1646

1647
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->status.taskStatus));
472!
1648
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->status.schedStatus));
472!
1649

1650
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.selfChildId));
472!
1651
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.nodeId));
472!
1652
  TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->info.epSet));
236!
1653
  TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->info.mnodeEpset));
236!
1654

1655
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->chkInfo.checkpointId));
472!
1656
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->chkInfo.checkpointVer));
472!
1657
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->info.fillHistory));
472!
1658

1659
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->hTaskInfo.id.streamId));
472!
1660
  int32_t taskId = pTask->hTaskInfo.id.taskId;
236✔
1661
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, taskId));
236!
1662

1663
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->streamTaskId.streamId));
472!
1664
  taskId = pTask->streamTaskId.taskId;
236✔
1665
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, taskId));
236!
1666

1667
  TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTask->dataRange.range.minVer));
472!
1668
  TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTask->dataRange.range.maxVer));
472!
1669
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->dataRange.window.skey));
472!
1670
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->dataRange.window.ekey));
472!
1671

1672
  int32_t epSz = taosArrayGetSize(pTask->upstreamInfo.pList);
236✔
1673
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, epSz));
236!
1674
  for (int32_t i = 0; i < epSz; i++) {
436✔
1675
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
200✔
1676
    TAOS_CHECK_EXIT(tEncodeStreamEpInfo(pEncoder, pInfo));
200!
1677
  }
1678

1679
  if (pTask->info.taskLevel != TASK_LEVEL__SINK) {
236✔
1680
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->exec.qmsg));
280!
1681
  }
1682

1683
  if (pTask->outputInfo.type == TASK_OUTPUT__TABLE) {
236✔
1684
    TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->outputInfo.tbSink.stbUid));
208!
1685
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->outputInfo.tbSink.stbFullName));
208!
1686
    TAOS_CHECK_EXIT(tEncodeSSchemaWrapper(pEncoder, pTask->outputInfo.tbSink.pSchemaWrapper));
208!
1687
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SMA) {
132!
1688
    TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->outputInfo.smaSink.smaId));
×
1689
  } else if (pTask->outputInfo.type == TASK_OUTPUT__FETCH) {
132!
1690
    TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->outputInfo.fetchSink.reserved));
×
1691
  } else if (pTask->outputInfo.type == TASK_OUTPUT__FIXED_DISPATCH) {
132✔
1692
    TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->outputInfo.fixedDispatcher.taskId));
160!
1693
    TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->outputInfo.fixedDispatcher.nodeId));
160!
1694
    TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->outputInfo.fixedDispatcher.epSet));
80!
1695
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
52✔
1696
    TAOS_CHECK_EXIT(tSerializeSUseDbRspImp(pEncoder, &pTask->outputInfo.shuffleDispatcher.dbInfo));
50!
1697
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->outputInfo.shuffleDispatcher.stbFullName));
100!
1698
  } else if (pTask->outputInfo.type == TASK_OUTPUT__VTABLE_MAP) {
2!
1699
    TAOS_CHECK_EXIT(tSerializeDispatcherTaskInfo(pEncoder, pTask->outputInfo.vtableMapDispatcher.taskInfos));
×
1700
    TAOS_CHECK_EXIT(tSerializeDispatcherVtableMap(pEncoder, pTask->outputInfo.vtableMapDispatcher.vtableMap));
×
1701
  }
1702
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->info.delaySchedParam));
472!
1703
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->subtableWithoutMd5));
472!
1704
  TAOS_CHECK_EXIT(tEncodeCStrWithLen(pEncoder, pTask->reserve, sizeof(pTask->reserve) - 1));
472!
1705

1706
  if (pTask->ver >= SSTREAM_TASK_ADD_NOTIFY_VER) {
236!
1707
    TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->info.hasAggTasks));
472!
1708
    TAOS_CHECK_EXIT(tEncodeStreamNotifyInfo(pEncoder, &pTask->notifyInfo));
236!
1709
    TAOS_CHECK_EXIT(tEncodeVTablesInfo(pEncoder, pTask->pVTables));
236!
1710
  }
1711

1712
  tEndEncode(pEncoder);
236✔
1713
_exit:
236✔
1714
  return code;
236✔
1715
}
1716

1717
int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask) {
94✔
1718
  int32_t taskId = 0;
94✔
1719
  int32_t code = 0;
94✔
1720
  int32_t lino;
1721

1722
  TAOS_CHECK_EXIT(tStartDecode(pDecoder));
94!
1723
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->ver));
188!
1724
  if (pTask->ver <= SSTREAM_TASK_INCOMPATIBLE_VER || pTask->ver > SSTREAM_TASK_VER) {
94!
1725
    TAOS_CHECK_EXIT(TSDB_CODE_INVALID_MSG);
×
1726
  }
1727

1728
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->id.streamId));
188!
1729
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->id.taskId));
188!
1730
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.trigger));
188!
1731
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->info.taskLevel));
188!
1732
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->outputInfo.type));
188!
1733
  TAOS_CHECK_EXIT(tDecodeI16(pDecoder, &pTask->msgInfo.msgType));
188!
1734

1735
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->status.taskStatus));
188!
1736
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->status.schedStatus));
188!
1737

1738
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.selfChildId));
188!
1739
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.nodeId));
188!
1740
  TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->info.epSet));
94!
1741
  TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->info.mnodeEpset));
94!
1742

1743
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->chkInfo.checkpointId));
188!
1744
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->chkInfo.checkpointVer));
188!
1745
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->info.fillHistory));
188!
1746

1747
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->hTaskInfo.id.streamId));
188!
1748
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &taskId));
94!
1749
  pTask->hTaskInfo.id.taskId = taskId;
94✔
1750

1751
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->streamTaskId.streamId));
188!
1752
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &taskId));
94!
1753
  pTask->streamTaskId.taskId = taskId;
94✔
1754

1755
  TAOS_CHECK_EXIT(tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.minVer));
188!
1756
  TAOS_CHECK_EXIT(tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.maxVer));
188!
1757
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->dataRange.window.skey));
188!
1758
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->dataRange.window.ekey));
188!
1759

1760
  int32_t epSz = -1;
94✔
1761
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &epSz) < 0);
94!
1762

1763
  if ((pTask->upstreamInfo.pList = taosArrayInit(epSz, POINTER_BYTES)) == NULL) {
94!
1764
    TAOS_CHECK_EXIT(terrno);
×
1765
  }
1766
  for (int32_t i = 0; i < epSz; i++) {
176✔
1767
    SStreamUpstreamEpInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamUpstreamEpInfo));
82!
1768
    if (pInfo == NULL) {
82!
1769
      TAOS_CHECK_EXIT(terrno);
×
1770
    }
1771
    if ((code = tDecodeStreamEpInfo(pDecoder, pInfo)) < 0) {
82!
1772
      taosMemoryFreeClear(pInfo);
×
1773
      goto _exit;
×
1774
    }
1775
    if (taosArrayPush(pTask->upstreamInfo.pList, &pInfo) == NULL) {
164!
1776
      TAOS_CHECK_EXIT(terrno);
×
1777
    }
1778
  }
1779

1780
  if (pTask->info.taskLevel != TASK_LEVEL__SINK) {
94✔
1781
    TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg));
118!
1782
  }
1783

1784
  if (pTask->outputInfo.type == TASK_OUTPUT__TABLE) {
94✔
1785
    TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->outputInfo.tbSink.stbUid));
90!
1786
    TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTask->outputInfo.tbSink.stbFullName));
45!
1787
    pTask->outputInfo.tbSink.pSchemaWrapper = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
45!
1788
    if (pTask->outputInfo.tbSink.pSchemaWrapper == NULL) {
45!
1789
      TAOS_CHECK_EXIT(terrno);
×
1790
    }
1791
    TAOS_CHECK_EXIT(tDecodeSSchemaWrapper(pDecoder, pTask->outputInfo.tbSink.pSchemaWrapper));
90!
1792
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SMA) {
49!
1793
    TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->outputInfo.smaSink.smaId));
×
1794
  } else if (pTask->outputInfo.type == TASK_OUTPUT__FETCH) {
49!
1795
    TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->outputInfo.fetchSink.reserved));
×
1796
  } else if (pTask->outputInfo.type == TASK_OUTPUT__FIXED_DISPATCH) {
49✔
1797
    TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->outputInfo.fixedDispatcher.taskId));
62!
1798
    TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->outputInfo.fixedDispatcher.nodeId));
62!
1799
    TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->outputInfo.fixedDispatcher.epSet));
31!
1800
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
18!
1801
    TAOS_CHECK_EXIT(tDeserializeSUseDbRspImp(pDecoder, &pTask->outputInfo.shuffleDispatcher.dbInfo));
18!
1802
    TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTask->outputInfo.shuffleDispatcher.stbFullName));
18!
1803
  } else if (pTask->outputInfo.type == TASK_OUTPUT__VTABLE_MAP) {
×
1804
    TAOS_CHECK_EXIT(tDeserializeDispatcherTaskInfo(pDecoder, &pTask->outputInfo.vtableMapDispatcher.taskInfos));
×
1805
    TAOS_CHECK_EXIT(tDeserializeDispatcherVtableMap(pDecoder, &pTask->outputInfo.vtableMapDispatcher.vtableMap));
×
1806
  }
1807
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->info.delaySchedParam));
188!
1808
  if (pTask->ver >= SSTREAM_TASK_SUBTABLE_CHANGED_VER) {
94✔
1809
    TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->subtableWithoutMd5));
176!
1810
  }
1811
  TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTask->reserve));
94!
1812

1813
  if (pTask->ver >= SSTREAM_TASK_ADD_NOTIFY_VER) {
94✔
1814
    TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->info.hasAggTasks));
176!
1815
    TAOS_CHECK_EXIT(tDecodeStreamNotifyInfo(pDecoder, &pTask->notifyInfo));
88!
1816
    TAOS_CHECK_EXIT(tDecodeVTablesInfo(pDecoder, &pTask->pVTables));
88!
1817
  }
1818

1819
  tEndDecode(pDecoder);
94✔
1820

1821
_exit:
94✔
1822
  return code;
94✔
1823
}
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