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

taosdata / TDengine / #3621

22 Feb 2025 11:44AM UTC coverage: 2.037% (-61.5%) from 63.573%
#3621

push

travis-ci

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

merge: from main to 3.0 branch

4357 of 287032 branches covered (1.52%)

Branch coverage included in aggregate %.

0 of 174 new or added lines in 18 files covered. (0.0%)

213359 existing lines in 469 files now uncovered.

7260 of 283369 relevant lines covered (2.56%)

23737.72 hits per line

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

0.0
/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 "streamsm.h"
21
#include "tmisce.h"
22
#include "tstream.h"
23
#include "ttimer.h"
24
#include "wal.h"
25
#include "streamMsg.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

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

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

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

UNCOV
51
    if (!isEqual) {
×
UNCOV
52
      (*pUpdated) = true;
×
UNCOV
53
      char tmp[512] = {0};
×
UNCOV
54
      code = epsetToStr(&pTask->info.epSet, tmp, tListLen(tmp));  // only for log file, ignore errors
×
UNCOV
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

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

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

UNCOV
78
  return code;
×
79
}
80

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

UNCOV
86
static void freeUpstreamItem(void* p) {
×
UNCOV
87
  SStreamUpstreamEpInfo** pInfo = p;
×
UNCOV
88
  taosMemoryFree(*pInfo);
×
UNCOV
89
}
×
90

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

UNCOV
98
  pEpInfo->childId = pTask->info.selfChildId;
×
UNCOV
99
  pEpInfo->epSet = pTask->info.epSet;
×
UNCOV
100
  pEpInfo->nodeId = pTask->info.nodeId;
×
UNCOV
101
  pEpInfo->taskId = pTask->id.taskId;
×
UNCOV
102
  pEpInfo->stage = -1;
×
103

UNCOV
104
  return pEpInfo;
×
105
}
106

UNCOV
107
int32_t tNewStreamTask(int64_t streamId, int8_t taskLevel, SEpSet* pEpset, bool fillHistory, int32_t trigger,
×
108
                       int64_t triggerParam, SArray* pTaskList, bool hasFillhistory, int8_t subtableWithoutMd5,
109
                       SStreamTask** p) {
UNCOV
110
  *p = NULL;
×
111

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

UNCOV
119
  pTask->ver = SSTREAM_TASK_VER;
×
UNCOV
120
  pTask->id.taskId = tGenIdPI32();
×
UNCOV
121
  pTask->id.streamId = streamId;
×
122

UNCOV
123
  pTask->info.taskLevel = taskLevel;
×
UNCOV
124
  pTask->info.fillHistory = fillHistory;
×
UNCOV
125
  pTask->info.trigger = trigger;
×
UNCOV
126
  pTask->info.delaySchedParam = triggerParam;
×
UNCOV
127
  pTask->subtableWithoutMd5 = subtableWithoutMd5;
×
128

UNCOV
129
  int32_t code = streamCreateStateMachine(pTask);
×
UNCOV
130
  if (pTask->status.pSM == NULL || code != TSDB_CODE_SUCCESS) {
×
131
    taosMemoryFreeClear(pTask);
×
132
    return code;
×
133
  }
134

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

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

UNCOV
148
  pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
×
UNCOV
149
  pTask->status.taskStatus = fillHistory ? TASK_STATUS__SCAN_HISTORY : TASK_STATUS__READY;
×
UNCOV
150
  pTask->inputq.status = TASK_INPUT_STATUS__NORMAL;
×
UNCOV
151
  pTask->outputq.status = TASK_OUTPUT_STATUS__NORMAL;
×
152

UNCOV
153
  pTask->taskCheckInfo.pList = taosArrayInit(4, sizeof(SDownstreamStatusInfo));
×
UNCOV
154
  code = taosThreadMutexInit(&pTask->taskCheckInfo.checkInfoLock, NULL);
×
UNCOV
155
  if (code) {
×
156
    return code;
×
157
  }
158

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

UNCOV
164
  epsetAssign(&(pTask->info.mnodeEpset), pEpset);
×
165

UNCOV
166
  code = addToTaskset(pTaskList, pTask);
×
UNCOV
167
  *p = pTask;
×
168

UNCOV
169
  return code;
×
170
}
171

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

UNCOV
179
  if (tStartDecode(pDecoder) < 0) return -1;
×
UNCOV
180
  if (tDecodeI64(pDecoder, &pChkpInfo->msgVer) < 0) return -1;
×
181
  // if (ver <= SSTREAM_TASK_INCOMPATIBLE_VER) return -1;
182

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

UNCOV
190
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
×
UNCOV
191
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
×
192

UNCOV
193
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
×
UNCOV
194
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
×
UNCOV
195
  if (tDecodeSEpSet(pDecoder, &epSet) < 0) return -1;
×
UNCOV
196
  if (tDecodeSEpSet(pDecoder, &epSet) < 0) return -1;
×
197

UNCOV
198
  if (tDecodeI64(pDecoder, &pChkpInfo->checkpointId) < 0) return -1;
×
UNCOV
199
  if (tDecodeI64(pDecoder, &pChkpInfo->checkpointVer) < 0) return -1;
×
200

UNCOV
201
  tEndDecode(pDecoder);
×
UNCOV
202
  return 0;
×
203
}
204

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

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

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

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

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

UNCOV
226
  STaskExecStatisInfo* pStatis = &pTask->execInfo;
×
227

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

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

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

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

UNCOV
251
  if (pTask->hTaskInfo.pTimer != NULL) {
×
UNCOV
252
    streamTmrStop(pTask->hTaskInfo.pTimer);
×
UNCOV
253
    pTask->hTaskInfo.pTimer = NULL;
×
254
  }
255

UNCOV
256
  if (pTask->msgInfo.pRetryTmr != NULL) {
×
UNCOV
257
    streamTmrStop(pTask->msgInfo.pRetryTmr);
×
UNCOV
258
    pTask->msgInfo.pRetryTmr = NULL;
×
259
  }
260

UNCOV
261
  if (pTask->inputq.queue) {
×
UNCOV
262
    streamQueueClose(pTask->inputq.queue, pTask->id.taskId);
×
UNCOV
263
    pTask->inputq.queue = NULL;
×
264
  }
265

UNCOV
266
  if (pTask->outputq.queue) {
×
UNCOV
267
    streamQueueClose(pTask->outputq.queue, pTask->id.taskId);
×
UNCOV
268
    pTask->outputq.queue = NULL;
×
269
  }
270

UNCOV
271
  if (pTask->exec.qmsg) {
×
UNCOV
272
    taosMemoryFree(pTask->exec.qmsg);
×
273
  }
274

UNCOV
275
  if (pTask->exec.pExecutor) {
×
UNCOV
276
    qDestroyTask(pTask->exec.pExecutor);
×
UNCOV
277
    pTask->exec.pExecutor = NULL;
×
278
  }
279

UNCOV
280
  if (pTask->exec.pWalReader != NULL) {
×
UNCOV
281
    walCloseReader(pTask->exec.pWalReader);
×
UNCOV
282
    pTask->exec.pWalReader = NULL;
×
283
  }
284

UNCOV
285
  streamClearChkptReadyMsg(pTask->chkInfo.pActiveInfo);
×
286

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

UNCOV
291
  if (pTask->outputInfo.type == TASK_OUTPUT__TABLE) {
×
UNCOV
292
    tDeleteSchemaWrapper(pTask->outputInfo.tbSink.pSchemaWrapper);
×
UNCOV
293
    taosMemoryFree(pTask->outputInfo.tbSink.pTSchema);
×
UNCOV
294
    tSimpleHashCleanup(pTask->outputInfo.tbSink.pTbInfo);
×
UNCOV
295
    tDeleteSchemaWrapper(pTask->outputInfo.tbSink.pTagSchema);
×
UNCOV
296
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
UNCOV
297
    taosArrayDestroy(pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos);
×
298
  }
299

UNCOV
300
  streamTaskCleanupCheckInfo(&pTask->taskCheckInfo);
×
UNCOV
301
  streamFreeTaskState(pTask, pTask->status.removeBackendFiles ? 1 : 0);
×
302

UNCOV
303
  if (pTask->pNameMap) {
×
UNCOV
304
    tSimpleHashCleanup(pTask->pNameMap);
×
305
  }
306

UNCOV
307
  streamDestroyStateMachine(pTask->status.pSM);
×
UNCOV
308
  pTask->status.pSM = NULL;
×
309

UNCOV
310
  streamTaskDestroyUpstreamInfo(&pTask->upstreamInfo);
×
311

UNCOV
312
  taosMemoryFree(pTask->outputInfo.pTokenBucket);
×
UNCOV
313
  streamMutexDestroy(&pTask->lock);
×
314

UNCOV
315
  taosArrayDestroy(pTask->msgInfo.pSendInfo);
×
UNCOV
316
  pTask->msgInfo.pSendInfo = NULL;
×
UNCOV
317
  streamMutexDestroy(&pTask->msgInfo.lock);
×
318

UNCOV
319
  taosArrayDestroy(pTask->outputInfo.pNodeEpsetUpdateList);
×
UNCOV
320
  pTask->outputInfo.pNodeEpsetUpdateList = NULL;
×
321

UNCOV
322
  if (pTask->id.idStr != NULL) {
×
UNCOV
323
    taosMemoryFree((void*)pTask->id.idStr);
×
324
  }
325

UNCOV
326
  streamTaskDestroyActiveChkptInfo(pTask->chkInfo.pActiveInfo);
×
UNCOV
327
  pTask->chkInfo.pActiveInfo = NULL;
×
328

UNCOV
329
  taosArrayDestroyP(pTask->notifyInfo.pNotifyAddrUrls, NULL);
×
UNCOV
330
  taosMemoryFreeClear(pTask->notifyInfo.streamName);
×
UNCOV
331
  taosMemoryFreeClear(pTask->notifyInfo.stbFullName);
×
UNCOV
332
  tDeleteSchemaWrapper(pTask->notifyInfo.pSchemaWrapper);
×
333

UNCOV
334
  pTask->notifyEventStat = (STaskNotifyEventStat){0};
×
335

UNCOV
336
  taosMemoryFree(pTask);
×
UNCOV
337
  stDebug("s-task:0x%x free task completed", taskId);
×
UNCOV
338
}
×
339

UNCOV
340
void streamFreeTaskState(SStreamTask* pTask, int8_t remove) {
×
UNCOV
341
  stDebug("s-task:0x%x start to free task state/backend", pTask->id.taskId);
×
UNCOV
342
  if (pTask->pState != NULL) {
×
UNCOV
343
    stDebug("s-task:0x%x start to free task state", pTask->id.taskId);
×
UNCOV
344
    streamStateClose(pTask->pState, remove);
×
345

UNCOV
346
    if (remove) taskDbSetClearFileFlag(pTask->pBackend);
×
UNCOV
347
    taskDbRemoveRef(pTask->pBackend);
×
UNCOV
348
    pTask->pBackend = NULL;
×
UNCOV
349
    pTask->pState = NULL;
×
350
  } else {
UNCOV
351
    stDebug("s-task:0x%x task state is NULL, may del backend:%s", pTask->id.taskId,
×
352
            pTask->backendPath ? pTask->backendPath : "NULL");
UNCOV
353
    if (remove) {
×
UNCOV
354
      if (pTask->backendPath != NULL) {
×
UNCOV
355
        stDebug("s-task:0x%x task state is NULL, do del backend:%s", pTask->id.taskId, pTask->backendPath);
×
UNCOV
356
        taosRemoveDir(pTask->backendPath);
×
357
      }
358
    }
359
  }
360

UNCOV
361
  if (pTask->backendPath != NULL) {
×
UNCOV
362
    taosMemoryFree(pTask->backendPath);
×
UNCOV
363
    pTask->backendPath = NULL;
×
364
  }
UNCOV
365
}
×
366

UNCOV
367
static void setInitialVersionInfo(SStreamTask* pTask, int64_t ver) {
×
UNCOV
368
  SCheckpointInfo* pChkInfo = &pTask->chkInfo;
×
UNCOV
369
  SDataRange*      pRange = &pTask->dataRange;
×
370

371
  // only set the version info for stream tasks without fill-history task
UNCOV
372
  if ((pTask->info.fillHistory == 0) && (!HAS_RELATED_FILLHISTORY_TASK(pTask))) {
×
UNCOV
373
    pChkInfo->checkpointVer = ver - 1;  // only update when generating checkpoint
×
UNCOV
374
    pChkInfo->processedVer = ver - 1;   // already processed version
×
UNCOV
375
    pChkInfo->nextProcessVer = ver;     // next processed version
×
376

UNCOV
377
    pRange->range.maxVer = ver;
×
UNCOV
378
    pRange->range.minVer = ver;
×
379
  } else {
380
    // the initial value of processedVer/nextProcessVer/checkpointVer for stream task with related fill-history task
381
    // is set at the mnode.
UNCOV
382
    if (pTask->info.fillHistory == 1) {
×
UNCOV
383
      pChkInfo->checkpointVer = pRange->range.maxVer;
×
UNCOV
384
      pChkInfo->processedVer = pRange->range.maxVer;
×
UNCOV
385
      pChkInfo->nextProcessVer = pRange->range.maxVer + 1;
×
386
    } else {
UNCOV
387
      pChkInfo->checkpointVer = pRange->range.minVer - 1;
×
UNCOV
388
      pChkInfo->processedVer = pRange->range.minVer - 1;
×
UNCOV
389
      pChkInfo->nextProcessVer = pRange->range.minVer;
×
390

391
      {  // for compatible purpose, remove it later
UNCOV
392
        if (pRange->range.minVer == 0) {
×
UNCOV
393
          pChkInfo->checkpointVer = 0;
×
UNCOV
394
          pChkInfo->processedVer = 0;
×
UNCOV
395
          pChkInfo->nextProcessVer = 1;
×
UNCOV
396
          stDebug("s-task:%s update the processedVer to 0 from -1 due to compatible purpose", pTask->id.idStr);
×
397
        }
398
      }
399
    }
400
  }
UNCOV
401
}
×
402

UNCOV
403
int32_t streamTaskSetBackendPath(SStreamTask* pTask) {
×
UNCOV
404
  int64_t streamId = 0;
×
UNCOV
405
  int32_t taskId = 0;
×
406

UNCOV
407
  if (pTask->info.fillHistory) {
×
UNCOV
408
    streamId = pTask->streamTaskId.streamId;
×
UNCOV
409
    taskId = pTask->streamTaskId.taskId;
×
410
  } else {
UNCOV
411
    streamId = pTask->id.streamId;
×
UNCOV
412
    taskId = pTask->id.taskId;
×
413
  }
414

UNCOV
415
  char    id[128] = {0};
×
UNCOV
416
  int32_t nBytes = snprintf(id, tListLen(id), "0x%" PRIx64 "-0x%x", streamId, taskId);
×
UNCOV
417
  if (nBytes < 0 || nBytes >= sizeof(id)) {
×
UNCOV
418
    return TSDB_CODE_OUT_OF_BUFFER;
×
419
  }
420

UNCOV
421
  int32_t len = strlen(pTask->pMeta->path);
×
UNCOV
422
  pTask->backendPath = (char*)taosMemoryMalloc(len + nBytes + 2);
×
UNCOV
423
  if (pTask->backendPath == NULL) {
×
424
    return terrno;
×
425
  }
426

UNCOV
427
  int32_t code = snprintf(pTask->backendPath, len + nBytes + 2, "%s%s%s", pTask->pMeta->path, TD_DIRSEP, id);
×
UNCOV
428
  if (code < 0 || code >= len + nBytes + 2) {
×
UNCOV
429
    stError("s-task:%s failed to set backend path:%s, code: out of buffer", pTask->id.idStr, pTask->backendPath);
×
430
    return TSDB_CODE_OUT_OF_BUFFER;
×
431
  } else {
UNCOV
432
    stDebug("s-task:%s set backend path:%s", pTask->id.idStr, pTask->backendPath);
×
UNCOV
433
    return 0;
×
434
  }
435
}
436

UNCOV
437
int32_t streamTaskInit(SStreamTask* pTask, SStreamMeta* pMeta, SMsgCb* pMsgCb, int64_t ver) {
×
UNCOV
438
  int32_t code = createStreamTaskIdStr(pTask->id.streamId, pTask->id.taskId, &pTask->id.idStr);
×
UNCOV
439
  if (code) {
×
440
    stError("0x%x failed create stream task id str, code:%s", pTask->id.taskId, tstrerror(code));
×
441
    return code;
×
442
  }
443

UNCOV
444
  pTask->id.refId = 0;
×
UNCOV
445
  pTask->inputq.status = TASK_INPUT_STATUS__NORMAL;
×
UNCOV
446
  pTask->outputq.status = TASK_OUTPUT_STATUS__NORMAL;
×
447

UNCOV
448
  int32_t code1 = streamQueueOpen(512 << 10, &pTask->inputq.queue);
×
UNCOV
449
  int32_t code2 = streamQueueOpen(512 << 10, &pTask->outputq.queue);
×
UNCOV
450
  if (code1 || code2) {
×
UNCOV
451
    stError("s-task:%s failed to prepare the input/output queue, initialize task failed", pTask->id.idStr);
×
452
    return TSDB_CODE_OUT_OF_MEMORY;
×
453
  }
454

UNCOV
455
  pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
×
456

UNCOV
457
  code = streamCreateStateMachine(pTask);
×
UNCOV
458
  if (pTask->status.pSM == NULL || code != TSDB_CODE_SUCCESS) {
×
459
    stError("s-task:%s failed create state-machine for stream task, initialization failed, code:%s", pTask->id.idStr,
×
460
            tstrerror(code));
461
    return code;
×
462
  }
463

UNCOV
464
  pTask->execInfo.created = taosGetTimestampMs();
×
UNCOV
465
  setInitialVersionInfo(pTask, ver);
×
466

UNCOV
467
  pTask->pMeta = pMeta;
×
UNCOV
468
  pTask->pMsgCb = pMsgCb;
×
UNCOV
469
  pTask->msgInfo.pSendInfo = taosArrayInit(4, sizeof(SDispatchEntry));
×
UNCOV
470
  if (pTask->msgInfo.pSendInfo == NULL) {
×
471
    stError("s-task:%s failed to create sendInfo struct for stream task, code:Out of memory", pTask->id.idStr);
×
472
    return terrno;
×
473
  }
474

UNCOV
475
  code = taosThreadMutexInit(&pTask->msgInfo.lock, NULL);
×
UNCOV
476
  if (code) {
×
477
    stError("s-task:0x%x failed to init msgInfo mutex, code:%s", pTask->id.taskId, tstrerror(code));
×
478
    return code;
×
479
  }
480

UNCOV
481
  TdThreadMutexAttr attr = {0};
×
UNCOV
482
  code = taosThreadMutexAttrInit(&attr);
×
UNCOV
483
  if (code != 0) {
×
484
    stError("s-task:%s initElapsed mutex attr failed, code:%s", pTask->id.idStr, tstrerror(code));
×
485
    return code;
×
486
  }
487

UNCOV
488
  code = taosThreadMutexAttrSetType(&attr, PTHREAD_MUTEX_RECURSIVE);
×
UNCOV
489
  if (code != 0) {
×
490
    stError("s-task:%s set mutex attr recursive, code:%s", pTask->id.idStr, tstrerror(code));
×
491
    return code;
×
492
  }
493

UNCOV
494
  code = taosThreadMutexInit(&pTask->lock, &attr);
×
UNCOV
495
  if (code) {
×
496
    return code;
×
497
  }
498

UNCOV
499
  code = taosThreadMutexAttrDestroy(&attr);
×
UNCOV
500
  if (code) {
×
501
    return code;
×
502
  }
503

UNCOV
504
  streamTaskOpenAllUpstreamInput(pTask);
×
505

UNCOV
506
  STaskOutputInfo* pOutputInfo = &pTask->outputInfo;
×
UNCOV
507
  pOutputInfo->pTokenBucket = taosMemoryCalloc(1, sizeof(STokenBucket));
×
UNCOV
508
  if (pOutputInfo->pTokenBucket == NULL) {
×
509
    stError("s-task:%s failed to prepare the tokenBucket, code:%s", pTask->id.idStr, tstrerror(terrno));
×
510
    return terrno;
×
511
  }
512

513
  // 2MiB per second for sink task
514
  // 50 times sink operator per second
UNCOV
515
  code = streamTaskInitTokenBucket(pOutputInfo->pTokenBucket, 35, 35, tsSinkDataRate, pTask->id.idStr);
×
UNCOV
516
  if (code) {
×
517
    return code;
×
518
  }
519

UNCOV
520
  pOutputInfo->pNodeEpsetUpdateList = taosArrayInit(4, sizeof(SDownstreamTaskEpset));
×
UNCOV
521
  if (pOutputInfo->pNodeEpsetUpdateList == NULL) {
×
522
    stError("s-task:%s failed to prepare downstreamUpdateList, code:%s", pTask->id.idStr, tstrerror(terrno));
×
523
    return terrno;
×
524
  }
525

UNCOV
526
  pTask->taskCheckInfo.pList = taosArrayInit(4, sizeof(SDownstreamStatusInfo));
×
UNCOV
527
  if (pTask->taskCheckInfo.pList == NULL) {
×
528
    stError("s-task:%s failed to prepare taskCheckInfo list, code:%s", pTask->id.idStr, tstrerror(terrno));
×
529
    return terrno;
×
530
  }
531

UNCOV
532
  if (pTask->chkInfo.pActiveInfo == NULL) {
×
UNCOV
533
    code = streamTaskCreateActiveChkptInfo(&pTask->chkInfo.pActiveInfo);
×
UNCOV
534
    if (code) {
×
535
      stError("s-task:%s failed to create active checkpoint info, code:%s", pTask->id.idStr, tstrerror(code));
×
536
      return code;
×
537
    }
538
  }
539

UNCOV
540
  return streamTaskSetBackendPath(pTask);
×
541
}
542

UNCOV
543
int32_t streamTaskGetNumOfDownstream(const SStreamTask* pTask) {
×
UNCOV
544
  if (pTask->info.taskLevel == TASK_LEVEL__SINK) {
×
UNCOV
545
    return 0;
×
546
  }
547

UNCOV
548
  int32_t type = pTask->outputInfo.type;
×
UNCOV
549
  if (type == TASK_OUTPUT__TABLE) {
×
UNCOV
550
    return 0;
×
UNCOV
551
  } else if (type == TASK_OUTPUT__FIXED_DISPATCH) {
×
UNCOV
552
    return 1;
×
553
  } else {
UNCOV
554
    SArray* vgInfo = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
×
UNCOV
555
    return taosArrayGetSize(vgInfo);
×
556
  }
557
}
558

UNCOV
559
int32_t streamTaskGetNumOfUpstream(const SStreamTask* pTask) { return taosArrayGetSize(pTask->upstreamInfo.pList); }
×
560

UNCOV
561
int32_t streamTaskSetUpstreamInfo(SStreamTask* pTask, const SStreamTask* pUpstreamTask) {
×
UNCOV
562
  SStreamUpstreamEpInfo* pEpInfo = createStreamTaskEpInfo(pUpstreamTask);
×
UNCOV
563
  if (pEpInfo == NULL) {
×
564
    return terrno;
×
565
  }
566

UNCOV
567
  if (pTask->upstreamInfo.pList == NULL) {
×
UNCOV
568
    pTask->upstreamInfo.pList = taosArrayInit(4, POINTER_BYTES);
×
569
  }
570

UNCOV
571
  void* p = taosArrayPush(pTask->upstreamInfo.pList, &pEpInfo);
×
UNCOV
572
  return (p == NULL) ? terrno : TSDB_CODE_SUCCESS;
×
573
}
574

UNCOV
575
int32_t streamTaskUpdateUpstreamInfo(SStreamTask* pTask, int32_t nodeId, const SEpSet* pEpSet, bool* pUpdated) {
×
UNCOV
576
  int32_t code = 0;
×
UNCOV
577
  char    buf[512] = {0};
×
UNCOV
578
  code = epsetToStr(pEpSet, buf, tListLen(buf));  // ignore error since it is only for log file.
×
UNCOV
579
  if (code != 0) {  // print error and continue
×
580
    stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
581
    return code;
×
582
  }
583

UNCOV
584
  int32_t numOfUpstream = taosArrayGetSize(pTask->upstreamInfo.pList);
×
UNCOV
585
  for (int32_t i = 0; i < numOfUpstream; ++i) {
×
UNCOV
586
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
×
UNCOV
587
    if (pInfo->nodeId == nodeId) {
×
UNCOV
588
      bool equal = isEpsetEqual(&pInfo->epSet, pEpSet);
×
UNCOV
589
      if (!equal) {
×
UNCOV
590
        *pUpdated = true;
×
591

UNCOV
592
        char tmp[512] = {0};
×
UNCOV
593
        code = epsetToStr(&pInfo->epSet, tmp, tListLen(tmp));
×
UNCOV
594
        if (code != 0) {  // print error and continue
×
595
          stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
596
          return code;
×
597
        }
598

UNCOV
599
        epsetAssign(&pInfo->epSet, pEpSet);
×
UNCOV
600
        stDebug("s-task:0x%x update the upstreamInfo taskId:0x%x(nodeId:%d) newEpset:%s old:%s", pTask->id.taskId,
×
601
                pInfo->taskId, nodeId, buf, tmp);
602
      } else {
UNCOV
603
        stDebug("s-task:0x%x not update upstreamInfo, since identical, task:0x%x(nodeId:%d) epset:%s", pTask->id.taskId,
×
604
                pInfo->taskId, nodeId, buf);
605
      }
606

UNCOV
607
      break;
×
608
    }
609
  }
610

UNCOV
611
  return code;
×
612
}
613

UNCOV
614
void streamTaskDestroyUpstreamInfo(SUpstreamInfo* pUpstreamInfo) {
×
UNCOV
615
  if (pUpstreamInfo->pList != NULL) {
×
UNCOV
616
    taosArrayDestroyEx(pUpstreamInfo->pList, freeUpstreamItem);
×
UNCOV
617
    pUpstreamInfo->numOfClosed = 0;
×
UNCOV
618
    pUpstreamInfo->pList = NULL;
×
619
  }
UNCOV
620
}
×
621

UNCOV
622
void streamTaskSetFixedDownstreamInfo(SStreamTask* pTask, const SStreamTask* pDownstreamTask) {
×
UNCOV
623
  STaskDispatcherFixed* pDispatcher = &pTask->outputInfo.fixedDispatcher;
×
UNCOV
624
  pDispatcher->taskId = pDownstreamTask->id.taskId;
×
UNCOV
625
  pDispatcher->nodeId = pDownstreamTask->info.nodeId;
×
UNCOV
626
  pDispatcher->epSet = pDownstreamTask->info.epSet;
×
627

UNCOV
628
  pTask->outputInfo.type = TASK_OUTPUT__FIXED_DISPATCH;
×
UNCOV
629
  pTask->msgInfo.msgType = TDMT_STREAM_TASK_DISPATCH;
×
UNCOV
630
}
×
631

UNCOV
632
int32_t streamTaskUpdateDownstreamInfo(SStreamTask* pTask, int32_t nodeId, const SEpSet* pEpSet, bool* pUpdated) {
×
UNCOV
633
  char    buf[512] = {0};
×
UNCOV
634
  int32_t code = epsetToStr(pEpSet, buf, tListLen(buf));  // ignore the error since only for log files.
×
UNCOV
635
  if (code != 0) {                                        // print error and continue
×
636
    stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
637
    return code;
×
638
  }
639

UNCOV
640
  int32_t id = pTask->id.taskId;
×
UNCOV
641
  int8_t  type = pTask->outputInfo.type;
×
642

UNCOV
643
  if (type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
UNCOV
644
    SArray* pVgs = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
×
645

UNCOV
646
    for (int32_t i = 0; i < taosArrayGetSize(pVgs); i++) {
×
UNCOV
647
      SVgroupInfo* pVgInfo = taosArrayGet(pVgs, i);
×
UNCOV
648
      if (pVgInfo == NULL) {
×
649
        continue;
×
650
      }
651

UNCOV
652
      if (pVgInfo->vgId == nodeId) {
×
UNCOV
653
        bool isEqual = isEpsetEqual(&pVgInfo->epSet, pEpSet);
×
UNCOV
654
        if (!isEqual) {
×
UNCOV
655
          *pUpdated = true;
×
656

UNCOV
657
          char tmp[512] = {0};
×
UNCOV
658
          code = epsetToStr(&pVgInfo->epSet, tmp, tListLen(tmp));
×
UNCOV
659
          if (code != 0) {  // print error and continue
×
660
            stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
661
            return code;
×
662
          }
663

UNCOV
664
          epsetAssign(&pVgInfo->epSet, pEpSet);
×
UNCOV
665
          stDebug("s-task:0x%x update dispatch info, task:0x%x(nodeId:%d) newEpset:%s old:%s", id, pVgInfo->taskId,
×
666
                  nodeId, buf, tmp);
667
        } else {
UNCOV
668
          stDebug("s-task:0x%x not update dispatch info, since identical, task:0x%x(nodeId:%d) epset:%s", id,
×
669
                  pVgInfo->taskId, nodeId, buf);
670
        }
UNCOV
671
        break;
×
672
      }
673
    }
UNCOV
674
  } else if (type == TASK_OUTPUT__FIXED_DISPATCH) {
×
UNCOV
675
    STaskDispatcherFixed* pDispatcher = &pTask->outputInfo.fixedDispatcher;
×
UNCOV
676
    if (pDispatcher->nodeId == nodeId) {
×
UNCOV
677
      bool equal = isEpsetEqual(&pDispatcher->epSet, pEpSet);
×
UNCOV
678
      if (!equal) {
×
679
        *pUpdated = true;
×
680

681
        char tmp[512] = {0};
×
682
        code = epsetToStr(&pDispatcher->epSet, tmp, tListLen(tmp));
×
683
        if (code != 0) {  // print error and continue
×
684
          stError("%s failed to convert epset to str, code:%s", pTask->id.idStr, tstrerror(code));
×
685
          return code;
×
686
        }
687

688
        epsetAssign(&pDispatcher->epSet, pEpSet);
×
689
        stDebug("s-task:0x%x update dispatch info, task:0x%x(nodeId:%d) newEpset:%s old:%s", id, pDispatcher->taskId,
×
690
                nodeId, buf, tmp);
691
      } else {
UNCOV
692
        stDebug("s-task:0x%x not update dispatch info, since identical, task:0x%x(nodeId:%d) epset:%s", id,
×
693
                pDispatcher->taskId, nodeId, buf);
694
      }
695
    }
696
  }
697

UNCOV
698
  return code;
×
699
}
700

UNCOV
701
int32_t streamTaskStop(SStreamTask* pTask) {
×
UNCOV
702
  int32_t     vgId = pTask->pMeta->vgId;
×
UNCOV
703
  int64_t     st = taosGetTimestampMs();
×
UNCOV
704
  const char* id = pTask->id.idStr;
×
705

UNCOV
706
  int32_t code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_STOP);
×
UNCOV
707
  if (code) {
×
708
    stError("failed to handle STOP event, s-task:%s, code:%s", id, tstrerror(code));
×
709
    return code;
×
710
  }
711

UNCOV
712
  if (pTask->info.taskLevel != TASK_LEVEL__SINK && pTask->exec.pExecutor != NULL) {
×
NEW
713
    code = qKillTask(pTask->exec.pExecutor, TSDB_CODE_SUCCESS, 5000);
×
UNCOV
714
    if (code != TSDB_CODE_SUCCESS) {
×
715
      stError("s-task:%s failed to kill task related query handle, code:%s", id, tstrerror(code));
×
716
    }
717
  }
718

UNCOV
719
  while (!streamTaskIsIdle(pTask)) {
×
720
    stDebug("s-task:%s level:%d wait for task to be idle and then close, check again in 100ms", id,
×
721
            pTask->info.taskLevel);
722
    taosMsleep(100);
×
723
  }
724

UNCOV
725
  int64_t el = taosGetTimestampMs() - st;
×
UNCOV
726
  stDebug("vgId:%d s-task:%s is closed in %" PRId64 " ms", vgId, id, el);
×
UNCOV
727
  return code;
×
728
}
729

UNCOV
730
bool streamTaskUpdateEpsetInfo(SStreamTask* pTask, SArray* pNodeList) {
×
UNCOV
731
  STaskExecStatisInfo* p = &pTask->execInfo;
×
732

UNCOV
733
  int32_t numOfNodes = taosArrayGetSize(pNodeList);
×
UNCOV
734
  int64_t prevTs = p->latestUpdateTs;
×
735

UNCOV
736
  p->latestUpdateTs = taosGetTimestampMs();
×
UNCOV
737
  p->updateCount += 1;
×
UNCOV
738
  stDebug("s-task:0x%x update task nodeEp epset, updatedNodes:%d, updateCount:%d, prevTs:%" PRId64, pTask->id.taskId,
×
739
          numOfNodes, p->updateCount, prevTs);
740

UNCOV
741
  bool updated = false;
×
UNCOV
742
  for (int32_t i = 0; i < numOfNodes; ++i) {
×
UNCOV
743
    SNodeUpdateInfo* pInfo = taosArrayGet(pNodeList, i);
×
UNCOV
744
    if (pInfo == NULL) {
×
745
      continue;
×
746
    }
747

UNCOV
748
    int32_t code = doUpdateTaskEpset(pTask, pInfo->nodeId, &pInfo->newEp, &updated);
×
UNCOV
749
    if (code) {
×
750
      stError("s-task:0x%x failed to update the task nodeEp epset, code:%s", pTask->id.taskId, tstrerror(code));
×
751
    }
752
  }
753

UNCOV
754
  return updated;
×
755
}
756

UNCOV
757
void streamTaskResetUpstreamStageInfo(SStreamTask* pTask) {
×
UNCOV
758
  if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) {
×
UNCOV
759
    return;
×
760
  }
761

UNCOV
762
  int32_t size = taosArrayGetSize(pTask->upstreamInfo.pList);
×
UNCOV
763
  for (int32_t i = 0; i < size; ++i) {
×
UNCOV
764
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
×
UNCOV
765
    pInfo->stage = -1;
×
766
  }
767

UNCOV
768
  stDebug("s-task:%s reset all upstream tasks stage info", pTask->id.idStr);
×
769
}
770

UNCOV
771
void streamTaskOpenAllUpstreamInput(SStreamTask* pTask) {
×
UNCOV
772
  int32_t num = taosArrayGetSize(pTask->upstreamInfo.pList);
×
UNCOV
773
  if (num == 0) {
×
UNCOV
774
    return;
×
775
  }
776

UNCOV
777
  for (int32_t i = 0; i < num; ++i) {
×
UNCOV
778
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
×
UNCOV
779
    pInfo->dataAllowed = true;
×
780
  }
781

UNCOV
782
  pTask->upstreamInfo.numOfClosed = 0;
×
UNCOV
783
  stDebug("s-task:%s opening up inputQ for %d upstream tasks", pTask->id.idStr, num);
×
784
}
785

UNCOV
786
void streamTaskCloseUpstreamInput(SStreamTask* pTask, int32_t taskId) {
×
UNCOV
787
  SStreamUpstreamEpInfo* pInfo = NULL;
×
UNCOV
788
  streamTaskGetUpstreamTaskEpInfo(pTask, taskId, &pInfo);
×
789

UNCOV
790
  if ((pInfo != NULL) && pInfo->dataAllowed) {
×
UNCOV
791
    pInfo->dataAllowed = false;
×
UNCOV
792
    if (pTask->upstreamInfo.numOfClosed < streamTaskGetNumOfUpstream(pTask)) {
×
UNCOV
793
      int32_t t = atomic_add_fetch_32(&pTask->upstreamInfo.numOfClosed, 1);
×
794
    } else {
795
      stError("s-task:%s not inc closed input, since they have been all closed already", pTask->id.idStr);
×
796
    }
797
  }
UNCOV
798
}
×
799

UNCOV
800
void streamTaskOpenUpstreamInput(SStreamTask* pTask, int32_t taskId) {
×
UNCOV
801
  SStreamUpstreamEpInfo* pInfo = NULL;
×
UNCOV
802
  streamTaskGetUpstreamTaskEpInfo(pTask, taskId, &pInfo);
×
803

UNCOV
804
  if (pInfo != NULL && (!pInfo->dataAllowed)) {
×
UNCOV
805
    int32_t t = atomic_sub_fetch_32(&pTask->upstreamInfo.numOfClosed, 1);
×
UNCOV
806
    stDebug("s-task:%s open inputQ for upstream:0x%x, remain closed:%d", pTask->id.idStr, taskId, t);
×
UNCOV
807
    pInfo->dataAllowed = true;
×
808
  }
UNCOV
809
}
×
810

811
bool streamTaskIsAllUpstreamClosed(SStreamTask* pTask) {
×
812
  return pTask->upstreamInfo.numOfClosed == taosArrayGetSize(pTask->upstreamInfo.pList);
×
813
}
814

UNCOV
815
bool streamTaskSetSchedStatusWait(SStreamTask* pTask) {
×
UNCOV
816
  bool ret = false;
×
817

UNCOV
818
  streamMutexLock(&pTask->lock);
×
UNCOV
819
  if (pTask->status.schedStatus == TASK_SCHED_STATUS__INACTIVE) {
×
UNCOV
820
    pTask->status.schedStatus = TASK_SCHED_STATUS__WAITING;
×
UNCOV
821
    ret = true;
×
822
  }
823

UNCOV
824
  streamMutexUnlock(&pTask->lock);
×
UNCOV
825
  return ret;
×
826
}
827

UNCOV
828
int8_t streamTaskSetSchedStatusActive(SStreamTask* pTask) {
×
UNCOV
829
  streamMutexLock(&pTask->lock);
×
UNCOV
830
  int8_t status = pTask->status.schedStatus;
×
UNCOV
831
  if (status == TASK_SCHED_STATUS__WAITING) {
×
UNCOV
832
    pTask->status.schedStatus = TASK_SCHED_STATUS__ACTIVE;
×
833
  }
UNCOV
834
  streamMutexUnlock(&pTask->lock);
×
835

UNCOV
836
  return status;
×
837
}
838

UNCOV
839
int8_t streamTaskSetSchedStatusInactive(SStreamTask* pTask) {
×
UNCOV
840
  streamMutexLock(&pTask->lock);
×
UNCOV
841
  int8_t status = pTask->status.schedStatus;
×
UNCOV
842
  pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
×
UNCOV
843
  streamMutexUnlock(&pTask->lock);
×
844

UNCOV
845
  return status;
×
846
}
847

UNCOV
848
int32_t streamTaskClearHTaskAttr(SStreamTask* pTask, int32_t resetRelHalt) {
×
UNCOV
849
  int32_t      code = 0;
×
UNCOV
850
  SStreamMeta* pMeta = pTask->pMeta;
×
UNCOV
851
  SStreamTask* pStreamTask = NULL;
×
852

UNCOV
853
  if (pTask->info.fillHistory == 0) {
×
UNCOV
854
    return code;
×
855
  }
856

857
  code = streamMetaAcquireTaskUnsafe(pMeta, &pTask->streamTaskId, &pStreamTask);
×
UNCOV
858
  if (code == 0) {
×
859
    stDebug("s-task:%s clear the related stream task:0x%x attr to fill-history task", pTask->id.idStr,
×
860
            (int32_t)pTask->streamTaskId.taskId);
861

862
    streamMutexLock(&(pStreamTask->lock));
×
863
    CLEAR_RELATED_FILLHISTORY_TASK(pStreamTask);
×
864

865
    if (resetRelHalt) {
×
866
      stDebug("s-task:0x%" PRIx64 " set the persistent status attr to be ready, prev:%s, status in sm:%s",
×
867
              pTask->streamTaskId.taskId, streamTaskGetStatusStr(pStreamTask->status.taskStatus),
868
              streamTaskGetStatus(pStreamTask).name);
869
      pStreamTask->status.taskStatus = TASK_STATUS__READY;
×
870
    }
871

NEW
872
    code = streamMetaSaveTaskInMeta(pMeta, pStreamTask);
×
873
    streamMutexUnlock(&(pStreamTask->lock));
×
874

875
    streamMetaReleaseTask(pMeta, pStreamTask);
×
876
  }
877

UNCOV
878
  return code;
×
879
}
880

UNCOV
881
int32_t streamBuildAndSendDropTaskMsg(SMsgCb* pMsgCb, int32_t vgId, SStreamTaskId* pTaskId, int64_t resetRelHalt) {
×
UNCOV
882
  SVDropStreamTaskReq* pReq = rpcMallocCont(sizeof(SVDropStreamTaskReq));
×
UNCOV
883
  if (pReq == NULL) {
×
884
    return terrno;
×
885
  }
886

UNCOV
887
  pReq->head.vgId = vgId;
×
UNCOV
888
  pReq->taskId = pTaskId->taskId;
×
UNCOV
889
  pReq->streamId = pTaskId->streamId;
×
UNCOV
890
  pReq->resetRelHalt = resetRelHalt;
×
891

UNCOV
892
  SRpcMsg msg = {.msgType = TDMT_STREAM_TASK_DROP, .pCont = pReq, .contLen = sizeof(SVDropStreamTaskReq)};
×
UNCOV
893
  int32_t code = tmsgPutToQueue(pMsgCb, WRITE_QUEUE, &msg);
×
UNCOV
894
  if (code != TSDB_CODE_SUCCESS) {
×
895
    stError("vgId:%d failed to send drop task:0x%x msg, code:%s", vgId, pTaskId->taskId, tstrerror(code));
×
896
  } else {
UNCOV
897
    stDebug("vgId:%d build and send drop task:0x%x msg", vgId, pTaskId->taskId);
×
898
  }
899

UNCOV
900
  return code;
×
901
}
902

UNCOV
903
int32_t streamSendChkptReportMsg(SStreamTask* pTask, SCheckpointInfo* pCheckpointInfo, int8_t dropRelHTask) {
×
UNCOV
904
  int32_t                code = 0;
×
UNCOV
905
  int32_t                tlen = 0;
×
UNCOV
906
  int32_t                vgId = pTask->pMeta->vgId;
×
UNCOV
907
  const char*            id = pTask->id.idStr;
×
UNCOV
908
  SActiveCheckpointInfo* pActive = pCheckpointInfo->pActiveInfo;
×
909

UNCOV
910
  SCheckpointReport req = {.streamId = pTask->id.streamId,
×
UNCOV
911
                           .taskId = pTask->id.taskId,
×
912
                           .nodeId = vgId,
913
                           .dropHTask = dropRelHTask,
UNCOV
914
                           .transId = pActive->transId,
×
UNCOV
915
                           .checkpointId = pActive->activeId,
×
UNCOV
916
                           .checkpointVer = pCheckpointInfo->processedVer,
×
UNCOV
917
                           .checkpointTs = pCheckpointInfo->startTs};
×
918

UNCOV
919
  tEncodeSize(tEncodeStreamTaskChkptReport, &req, tlen, code);
×
UNCOV
920
  if (code < 0) {
×
921
    stError("s-task:%s vgId:%d encode stream task checkpoint-report failed, code:%s", id, vgId, tstrerror(code));
×
922
    return -1;
×
923
  }
924

UNCOV
925
  void* buf = rpcMallocCont(tlen);
×
UNCOV
926
  if (buf == NULL) {
×
927
    stError("s-task:%s vgId:%d encode stream task checkpoint-report msg failed, code:%s", id, vgId,
×
928
            tstrerror(TSDB_CODE_OUT_OF_MEMORY));
929
    return -1;
×
930
  }
931

932
  SEncoder encoder;
UNCOV
933
  tEncoderInit(&encoder, buf, tlen);
×
UNCOV
934
  if ((code = tEncodeStreamTaskChkptReport(&encoder, &req)) < 0) {
×
935
    rpcFreeCont(buf);
×
936
    tEncoderClear(&encoder);
×
937
    stError("s-task:%s vgId:%d encode stream task checkpoint-report msg failed, code:%s", id, vgId, tstrerror(code));
×
938
    return -1;
×
939
  }
UNCOV
940
  tEncoderClear(&encoder);
×
941

UNCOV
942
  SRpcMsg msg = {0};
×
UNCOV
943
  initRpcMsg(&msg, TDMT_MND_STREAM_CHKPT_REPORT, buf, tlen);
×
UNCOV
944
  stDebug("s-task:%s vgId:%d build and send task checkpoint-report to mnode", id, vgId);
×
945

UNCOV
946
  return tmsgSendReq(&pTask->info.mnodeEpset, &msg);
×
947
}
948

UNCOV
949
STaskId streamTaskGetTaskId(const SStreamTask* pTask) {
×
UNCOV
950
  STaskId id = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId};
×
UNCOV
951
  return id;
×
952
}
953

UNCOV
954
void streamTaskInitForLaunchHTask(SHistoryTaskInfo* pInfo) {
×
UNCOV
955
  pInfo->waitInterval = LAUNCH_HTASK_INTERVAL;
×
UNCOV
956
  pInfo->tickCount = ceil(LAUNCH_HTASK_INTERVAL / WAIT_FOR_MINIMAL_INTERVAL);
×
UNCOV
957
  pInfo->retryTimes = 0;
×
UNCOV
958
}
×
959

UNCOV
960
void streamTaskSetRetryInfoForLaunch(SHistoryTaskInfo* pInfo) {
×
UNCOV
961
  pInfo->waitInterval *= RETRY_LAUNCH_INTERVAL_INC_RATE;
×
UNCOV
962
  pInfo->tickCount = ceil(pInfo->waitInterval / WAIT_FOR_MINIMAL_INTERVAL);
×
UNCOV
963
  pInfo->retryTimes += 1;
×
UNCOV
964
}
×
965

UNCOV
966
void streamTaskStatusInit(STaskStatusEntry* pEntry, const SStreamTask* pTask) {
×
UNCOV
967
  pEntry->id.streamId = pTask->id.streamId;
×
UNCOV
968
  pEntry->id.taskId = pTask->id.taskId;
×
UNCOV
969
  pEntry->stage = -1;
×
UNCOV
970
  pEntry->nodeId = pTask->info.nodeId;
×
UNCOV
971
  pEntry->status = TASK_STATUS__STOP;
×
UNCOV
972
}
×
973

UNCOV
974
void streamTaskStatusCopy(STaskStatusEntry* pDst, const STaskStatusEntry* pSrc) {
×
UNCOV
975
  pDst->stage = pSrc->stage;
×
UNCOV
976
  pDst->inputQUsed = pSrc->inputQUsed;
×
UNCOV
977
  pDst->inputRate = pSrc->inputRate;
×
UNCOV
978
  pDst->procsTotal = pSrc->procsTotal;
×
UNCOV
979
  pDst->procsThroughput = pSrc->procsThroughput;
×
UNCOV
980
  pDst->outputTotal = pSrc->outputTotal;
×
UNCOV
981
  pDst->outputThroughput = pSrc->outputThroughput;
×
UNCOV
982
  pDst->processedVer = pSrc->processedVer;
×
UNCOV
983
  pDst->verRange = pSrc->verRange;
×
UNCOV
984
  pDst->sinkQuota = pSrc->sinkQuota;
×
UNCOV
985
  pDst->sinkDataSize = pSrc->sinkDataSize;
×
UNCOV
986
  pDst->checkpointInfo = pSrc->checkpointInfo;
×
UNCOV
987
  pDst->startCheckpointId = pSrc->startCheckpointId;
×
UNCOV
988
  pDst->startCheckpointVer = pSrc->startCheckpointVer;
×
UNCOV
989
  pDst->status = pSrc->status;
×
990

UNCOV
991
  pDst->startTime = pSrc->startTime;
×
UNCOV
992
  pDst->hTaskId = pSrc->hTaskId;
×
UNCOV
993
  pDst->notifyEventStat = pSrc->notifyEventStat;
×
UNCOV
994
}
×
995

UNCOV
996
STaskStatusEntry streamTaskGetStatusEntry(SStreamTask* pTask) {
×
UNCOV
997
  SStreamMeta*         pMeta = pTask->pMeta;
×
UNCOV
998
  STaskExecStatisInfo* pExecInfo = &pTask->execInfo;
×
999

UNCOV
1000
  STaskStatusEntry entry = {
×
UNCOV
1001
      .id = streamTaskGetTaskId(pTask),
×
UNCOV
1002
      .status = streamTaskGetStatus(pTask).state,
×
UNCOV
1003
      .nodeId = pMeta->vgId,
×
UNCOV
1004
      .stage = pMeta->stage,
×
1005

UNCOV
1006
      .inputQUsed = SIZE_IN_MiB(streamQueueGetItemSize(pTask->inputq.queue)),
×
UNCOV
1007
      .startTime = pExecInfo->readyTs,
×
UNCOV
1008
      .checkpointInfo.latestId = pTask->chkInfo.checkpointId,
×
UNCOV
1009
      .checkpointInfo.latestVer = pTask->chkInfo.checkpointVer,
×
UNCOV
1010
      .checkpointInfo.latestTime = pTask->chkInfo.checkpointTime,
×
1011
      .checkpointInfo.latestSize = 0,
1012
      .checkpointInfo.remoteBackup = 0,
1013
      .checkpointInfo.consensusChkptId = 0,
1014
      .checkpointInfo.consensusTs = 0,
UNCOV
1015
      .hTaskId = pTask->hTaskInfo.id.taskId,
×
UNCOV
1016
      .procsTotal = SIZE_IN_MiB(pExecInfo->inputDataSize),
×
UNCOV
1017
      .outputTotal = SIZE_IN_MiB(pExecInfo->outputDataSize),
×
UNCOV
1018
      .procsThroughput = SIZE_IN_KiB(pExecInfo->procsThroughput),
×
UNCOV
1019
      .outputThroughput = SIZE_IN_KiB(pExecInfo->outputThroughput),
×
UNCOV
1020
      .startCheckpointId = pExecInfo->startCheckpointId,
×
UNCOV
1021
      .startCheckpointVer = pExecInfo->startCheckpointVer,
×
1022
      .notifyEventStat = pTask->notifyEventStat,
1023
  };
UNCOV
1024
  return entry;
×
1025
}
1026

UNCOV
1027
static int32_t taskPauseCallback(SStreamTask* pTask, void* param) {
×
UNCOV
1028
  SStreamMeta* pMeta = pTask->pMeta;
×
UNCOV
1029
  int32_t      code = 0;
×
1030

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

1034
  // in case of fill-history task, stop the tsdb file scan operation.
UNCOV
1035
  if (pTask->info.fillHistory == 1) {
×
UNCOV
1036
    void* pExecutor = pTask->exec.pExecutor;
×
NEW
1037
    code = qKillTask(pExecutor, TSDB_CODE_SUCCESS, 10000);
×
1038
  }
1039

UNCOV
1040
  stDebug("vgId:%d s-task:%s set pause flag and pause task", pMeta->vgId, pTask->id.idStr);
×
UNCOV
1041
  return code;
×
1042
}
1043

UNCOV
1044
void streamTaskPause(SStreamTask* pTask) {
×
UNCOV
1045
  int32_t code = streamTaskHandleEventAsync(pTask->status.pSM, TASK_EVENT_PAUSE, taskPauseCallback, NULL);
×
UNCOV
1046
  if (code) {
×
1047
    stError("s-task:%s failed handle pause event async, code:%s", pTask->id.idStr, tstrerror(code));
×
1048
  }
UNCOV
1049
}
×
1050

UNCOV
1051
void streamTaskResume(SStreamTask* pTask) {
×
UNCOV
1052
  SStreamTaskState prevState = streamTaskGetStatus(pTask);
×
1053

UNCOV
1054
  SStreamMeta* pMeta = pTask->pMeta;
×
UNCOV
1055
  int32_t      code = streamTaskRestoreStatus(pTask);
×
UNCOV
1056
  if (code == TSDB_CODE_SUCCESS) {
×
UNCOV
1057
    char*   pNew = streamTaskGetStatus(pTask).name;
×
UNCOV
1058
    int32_t num = atomic_sub_fetch_32(&pMeta->numOfPausedTasks, 1);
×
UNCOV
1059
    stInfo("s-task:%s status:%s resume from %s, paused task(s):%d", pTask->id.idStr, pNew, prevState.name, num);
×
1060
  } else {
UNCOV
1061
    stInfo("s-task:%s status:%s no need to resume, paused task(s):%d", pTask->id.idStr, prevState.name,
×
1062
           pMeta->numOfPausedTasks);
1063
  }
UNCOV
1064
}
×
1065

UNCOV
1066
bool streamTaskIsSinkTask(const SStreamTask* pTask) { return pTask->info.taskLevel == TASK_LEVEL__SINK; }
×
1067

1068
// this task must success
UNCOV
1069
int32_t streamTaskSendCheckpointReq(SStreamTask* pTask) {
×
1070
  int32_t     code;
UNCOV
1071
  int32_t     tlen = 0;
×
UNCOV
1072
  int32_t     vgId = pTask->pMeta->vgId;
×
UNCOV
1073
  const char* id = pTask->id.idStr;
×
1074

UNCOV
1075
  SStreamTaskCheckpointReq req = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId, .nodeId = vgId};
×
UNCOV
1076
  tEncodeSize(tEncodeStreamTaskCheckpointReq, &req, tlen, code);
×
UNCOV
1077
  if (code < 0) {
×
1078
    stError("s-task:%s vgId:%d encode stream task req checkpoint failed, code:%s", id, vgId, tstrerror(code));
×
1079
    return TSDB_CODE_INVALID_MSG;
×
1080
  }
1081

UNCOV
1082
  void* buf = rpcMallocCont(tlen);
×
UNCOV
1083
  if (buf == NULL) {
×
1084
    stError("s-task:%s vgId:%d encode stream task req checkpoint msg failed, code:Out of memory", id, vgId);
×
1085
    return terrno;
×
1086
  }
1087

1088
  SEncoder encoder;
UNCOV
1089
  tEncoderInit(&encoder, buf, tlen);
×
UNCOV
1090
  if ((code = tEncodeStreamTaskCheckpointReq(&encoder, &req)) < 0) {
×
1091
    rpcFreeCont(buf);
×
1092
    tEncoderClear(&encoder);
×
1093
    stError("s-task:%s vgId:%d encode stream task req checkpoint msg failed, code:%s", id, vgId, tstrerror(code));
×
1094
    return code;
×
1095
  }
1096

UNCOV
1097
  tEncoderClear(&encoder);
×
1098

UNCOV
1099
  SRpcMsg msg = {0};
×
UNCOV
1100
  initRpcMsg(&msg, TDMT_MND_STREAM_REQ_CHKPT, buf, tlen);
×
UNCOV
1101
  stDebug("s-task:%s vgId:%d build and send task checkpoint req", id, vgId);
×
1102

UNCOV
1103
  return tmsgSendReq(&pTask->info.mnodeEpset, &msg);
×
1104
}
1105

UNCOV
1106
void streamTaskGetUpstreamTaskEpInfo(SStreamTask* pTask, int32_t taskId, SStreamUpstreamEpInfo** pEpInfo) {
×
UNCOV
1107
  *pEpInfo = NULL;
×
1108

UNCOV
1109
  int32_t num = taosArrayGetSize(pTask->upstreamInfo.pList);
×
UNCOV
1110
  for (int32_t i = 0; i < num; ++i) {
×
UNCOV
1111
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
×
UNCOV
1112
    if (pInfo == NULL) {
×
1113
      return;
×
1114
    }
1115

UNCOV
1116
    if (pInfo->taskId == taskId) {
×
UNCOV
1117
      *pEpInfo = pInfo;
×
UNCOV
1118
      return;
×
1119
    }
1120
  }
1121

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

1125
SEpSet* streamTaskGetDownstreamEpInfo(SStreamTask* pTask, int32_t taskId) {
×
1126
  if (pTask->info.taskLevel == TASK_OUTPUT__FIXED_DISPATCH) {
×
1127
    if (pTask->outputInfo.fixedDispatcher.taskId == taskId) {
×
1128
      return &pTask->outputInfo.fixedDispatcher.epSet;
×
1129
    }
1130
  } else if (pTask->info.taskLevel == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
1131
    SArray* pList = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
×
1132
    for (int32_t i = 0; i < taosArrayGetSize(pList); ++i) {
×
1133
      SVgroupInfo* pVgInfo = taosArrayGet(pList, i);
×
1134
      if (pVgInfo == NULL) {
×
1135
        continue;
×
1136
      }
1137

1138
      if (pVgInfo->taskId == taskId) {
×
1139
        return &pVgInfo->epSet;
×
1140
      }
1141
    }
1142
  }
1143

1144
  return NULL;
×
1145
}
1146

UNCOV
1147
int32_t createStreamTaskIdStr(int64_t streamId, int32_t taskId, const char** pId) {
×
UNCOV
1148
  char buf[128] = {0};
×
UNCOV
1149
  int32_t code = snprintf(buf, tListLen(buf),"0x%" PRIx64 "-0x%x", streamId, taskId);
×
UNCOV
1150
  if (code < 0 || code >= tListLen(buf)) {
×
1151
    return TSDB_CODE_OUT_OF_BUFFER;
×
1152
  }
1153

UNCOV
1154
  *pId = taosStrdup(buf);
×
1155

UNCOV
1156
  if (*pId == NULL) {
×
1157
    return terrno;
×
1158
  } else {
UNCOV
1159
    return TSDB_CODE_SUCCESS;
×
1160
  }
1161
}
1162

UNCOV
1163
static int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq) {
×
1164
  int32_t           code;
1165
  SStreamDataBlock* pData;
1166

UNCOV
1167
  code = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, sizeof(SStreamDataBlock), (void**)&pData);
×
UNCOV
1168
  if (code) {
×
1169
    stError("s-task:%s failed to allocated retrieve-block", pTask->id.idStr);
×
1170
    return terrno = code;
×
1171
  }
1172

UNCOV
1173
  pData->type = STREAM_INPUT__DATA_RETRIEVE;
×
UNCOV
1174
  pData->srcVgId = 0;
×
1175

UNCOV
1176
  code = streamRetrieveReqToData(pReq, pData, pTask->id.idStr);
×
UNCOV
1177
  if (code != TSDB_CODE_SUCCESS) {
×
1178
    stError("s-task:%s failed to convert retrieve-data to block, code:%s", pTask->id.idStr, tstrerror(code));
×
1179
    taosFreeQitem(pData);
×
1180
    return code;
×
1181
  }
1182

UNCOV
1183
  code = streamTaskPutDataIntoInputQ(pTask, (SStreamQueueItem*)pData);
×
UNCOV
1184
  if (code != TSDB_CODE_SUCCESS) {
×
1185
    stError("s-task:%s failed to put retrieve-block into inputQ, inputQ is full, discard the retrieve msg",
×
1186
            pTask->id.idStr);
1187
  }
1188

UNCOV
1189
  return code;
×
1190
}
1191

UNCOV
1192
int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq) {
×
UNCOV
1193
  int32_t code = streamTaskEnqueueRetrieve(pTask, pReq);
×
UNCOV
1194
  if (code != 0) {
×
1195
    return code;
×
1196
  }
UNCOV
1197
  return streamTrySchedExec(pTask);
×
1198
}
1199

UNCOV
1200
void streamTaskSetRemoveBackendFiles(SStreamTask* pTask) { pTask->status.removeBackendFiles = true; }
×
1201

1202
void streamTaskGetActiveCheckpointInfo(const SStreamTask* pTask, int32_t* pTransId, int64_t* pCheckpointId) {
×
1203
  if (pTransId != NULL) {
×
1204
    *pTransId = pTask->chkInfo.pActiveInfo->transId;
×
1205
  }
1206

1207
  if (pCheckpointId != NULL) {
×
1208
    *pCheckpointId = pTask->chkInfo.pActiveInfo->activeId;
×
1209
  }
1210
}
×
1211

UNCOV
1212
int32_t streamTaskSetActiveCheckpointInfo(SStreamTask* pTask, int64_t activeCheckpointId) {
×
UNCOV
1213
  pTask->chkInfo.pActiveInfo->activeId = activeCheckpointId;
×
UNCOV
1214
  return TSDB_CODE_SUCCESS;
×
1215
}
1216

UNCOV
1217
void streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t checkpointId) {
×
UNCOV
1218
  pTask->chkInfo.pActiveInfo->transId = transId;
×
UNCOV
1219
  pTask->chkInfo.pActiveInfo->activeId = checkpointId;
×
UNCOV
1220
  pTask->chkInfo.pActiveInfo->failedId = checkpointId;
×
UNCOV
1221
  stDebug("s-task:%s set failed checkpointId:%"PRId64, pTask->id.idStr, checkpointId);
×
UNCOV
1222
}
×
1223

UNCOV
1224
int32_t streamTaskCreateActiveChkptInfo(SActiveCheckpointInfo** pRes) {
×
UNCOV
1225
  SActiveCheckpointInfo* pInfo = taosMemoryCalloc(1, sizeof(SActiveCheckpointInfo));
×
UNCOV
1226
  if (pInfo == NULL) {
×
1227
    return terrno;
×
1228
  }
1229

UNCOV
1230
  int32_t code = taosThreadMutexInit(&pInfo->lock, NULL);
×
UNCOV
1231
  if (code != TSDB_CODE_SUCCESS) {
×
1232
    return code;
×
1233
  }
1234

UNCOV
1235
  pInfo->pDispatchTriggerList = taosArrayInit(4, sizeof(STaskTriggerSendInfo));
×
UNCOV
1236
  pInfo->pReadyMsgList = taosArrayInit(4, sizeof(STaskCheckpointReadyInfo));
×
UNCOV
1237
  pInfo->pCheckpointReadyRecvList = taosArrayInit(4, sizeof(STaskDownstreamReadyInfo));
×
1238

UNCOV
1239
  *pRes = pInfo;
×
UNCOV
1240
  return code;
×
1241
}
1242

UNCOV
1243
void streamTaskDestroyActiveChkptInfo(SActiveCheckpointInfo* pInfo) {
×
UNCOV
1244
  if (pInfo == NULL) {
×
UNCOV
1245
    return;
×
1246
  }
1247

UNCOV
1248
  streamMutexDestroy(&pInfo->lock);
×
UNCOV
1249
  taosArrayDestroy(pInfo->pDispatchTriggerList);
×
UNCOV
1250
  pInfo->pDispatchTriggerList = NULL;
×
UNCOV
1251
  taosArrayDestroy(pInfo->pReadyMsgList);
×
UNCOV
1252
  pInfo->pReadyMsgList = NULL;
×
UNCOV
1253
  taosArrayDestroy(pInfo->pCheckpointReadyRecvList);
×
UNCOV
1254
  pInfo->pCheckpointReadyRecvList = NULL;
×
1255

UNCOV
1256
  SStreamTmrInfo* pTriggerTmr = &pInfo->chkptTriggerMsgTmr;
×
UNCOV
1257
  if (pTriggerTmr->tmrHandle != NULL) {
×
UNCOV
1258
    streamTmrStop(pTriggerTmr->tmrHandle);
×
UNCOV
1259
    pTriggerTmr->tmrHandle = NULL;
×
1260
  }
1261

UNCOV
1262
  SStreamTmrInfo* pReadyTmr = &pInfo->chkptReadyMsgTmr;
×
UNCOV
1263
  if (pReadyTmr->tmrHandle != NULL) {
×
UNCOV
1264
    streamTmrStop(pReadyTmr->tmrHandle);
×
UNCOV
1265
    pReadyTmr->tmrHandle = NULL;
×
1266
  }
1267

UNCOV
1268
  taosMemoryFree(pInfo);
×
1269
}
1270

1271
// NOTE: clear the checkpoint id, and keep the failed id
1272
// failedId for a task will increase as the checkpoint I.D. increases.
UNCOV
1273
void streamTaskClearActiveInfo(SActiveCheckpointInfo* pInfo) {
×
UNCOV
1274
  pInfo->activeId = 0;
×
UNCOV
1275
  pInfo->transId = 0;
×
UNCOV
1276
  pInfo->allUpstreamTriggerRecv = 0;
×
UNCOV
1277
  pInfo->dispatchTrigger = false;
×
1278

UNCOV
1279
  taosArrayClear(pInfo->pDispatchTriggerList);
×
UNCOV
1280
  taosArrayClear(pInfo->pCheckpointReadyRecvList);
×
UNCOV
1281
}
×
1282

UNCOV
1283
const char* streamTaskGetExecType(int32_t type) {
×
UNCOV
1284
  switch (type) {
×
UNCOV
1285
    case STREAM_EXEC_T_EXTRACT_WAL_DATA:
×
UNCOV
1286
      return "scan-wal-file";
×
UNCOV
1287
    case STREAM_EXEC_T_START_ALL_TASKS:
×
UNCOV
1288
      return "start-all-tasks";
×
UNCOV
1289
    case STREAM_EXEC_T_START_ONE_TASK:
×
UNCOV
1290
      return "start-one-task";
×
UNCOV
1291
    case STREAM_EXEC_T_RESTART_ALL_TASKS:
×
UNCOV
1292
      return "restart-all-tasks";
×
UNCOV
1293
    case STREAM_EXEC_T_STOP_ALL_TASKS:
×
UNCOV
1294
      return "stop-all-tasks";
×
UNCOV
1295
    case STREAM_EXEC_T_RESUME_TASK:
×
UNCOV
1296
      return "resume-task-from-idle";
×
1297
    case STREAM_EXEC_T_ADD_FAILED_TASK:
×
1298
      return "record-start-failed-task";
×
NEW
1299
    case STREAM_EXEC_T_STOP_ONE_TASK:
×
NEW
1300
      return "stop-one-task";
×
UNCOV
1301
    case 0:
×
UNCOV
1302
      return "exec-all-tasks";
×
1303
    default:
×
1304
      return "invalid-exec-type";
×
1305
  }
1306
}
1307

UNCOV
1308
int32_t streamTaskAllocRefId(SStreamTask* pTask, int64_t** pRefId) {
×
UNCOV
1309
  *pRefId = taosMemoryMalloc(sizeof(int64_t));
×
UNCOV
1310
  if (*pRefId != NULL) {
×
UNCOV
1311
    **pRefId = pTask->id.refId;
×
UNCOV
1312
    int32_t code = metaRefMgtAdd(pTask->pMeta->vgId, *pRefId);
×
UNCOV
1313
    if (code != 0) {
×
1314
      stError("s-task:%s failed to add refId:%" PRId64 " into refId-mgmt, code:%s", pTask->id.idStr, pTask->id.refId,
×
1315
              tstrerror(code));
1316
    }
UNCOV
1317
    return code;
×
1318
  } else {
1319
    stError("s-task:%s failed to alloc new ref id, code:%s", pTask->id.idStr, tstrerror(terrno));
×
1320
    return terrno;
×
1321
  }
1322
}
1323

UNCOV
1324
void streamTaskFreeRefId(int64_t* pRefId) {
×
UNCOV
1325
  if (pRefId == NULL) {
×
UNCOV
1326
    return;
×
1327
  }
1328

UNCOV
1329
  metaRefMgtRemove(pRefId);
×
1330
}
1331

UNCOV
1332
static int32_t tEncodeStreamNotifyInfo(SEncoder* pEncoder, const SNotifyInfo* info) {
×
UNCOV
1333
  int32_t code = TSDB_CODE_SUCCESS;
×
UNCOV
1334
  int32_t lino = 0;
×
1335

UNCOV
1336
  QUERY_CHECK_NULL(pEncoder, code, lino, _exit, TSDB_CODE_INVALID_PARA);
×
UNCOV
1337
  QUERY_CHECK_NULL(info, code, lino, _exit, TSDB_CODE_INVALID_PARA);
×
1338

UNCOV
1339
  int32_t addrSize = taosArrayGetSize(info->pNotifyAddrUrls);
×
UNCOV
1340
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, addrSize));
×
UNCOV
1341
  for (int32_t i = 0; i < addrSize; ++i) {
×
1342
    const char* url = taosArrayGetP(info->pNotifyAddrUrls, i);
×
1343
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, url));
×
1344
  }
UNCOV
1345
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, info->notifyEventTypes));
×
UNCOV
1346
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, info->notifyErrorHandle));
×
UNCOV
1347
  if (addrSize > 0) {
×
1348
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, info->streamName));
×
1349
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, info->stbFullName));
×
1350
    TAOS_CHECK_EXIT(tEncodeSSchemaWrapper(pEncoder, info->pSchemaWrapper));
×
1351
  }
1352

UNCOV
1353
_exit:
×
UNCOV
1354
  if (code != TSDB_CODE_SUCCESS) {
×
UNCOV
1355
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1356
  }
UNCOV
1357
  return code;
×
1358
}
1359

UNCOV
1360
static int32_t tDecodeStreamNotifyInfo(SDecoder* pDecoder, SNotifyInfo* info) {
×
UNCOV
1361
  int32_t code = TSDB_CODE_SUCCESS;
×
UNCOV
1362
  int32_t lino = 0;
×
1363

UNCOV
1364
  QUERY_CHECK_NULL(pDecoder, code, lino, _exit, TSDB_CODE_INVALID_PARA);
×
UNCOV
1365
  QUERY_CHECK_NULL(info, code, lino, _exit, TSDB_CODE_INVALID_PARA);
×
1366

UNCOV
1367
  int32_t addrSize = 0;
×
UNCOV
1368
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &addrSize));
×
UNCOV
1369
  info->pNotifyAddrUrls = taosArrayInit(addrSize, POINTER_BYTES);
×
UNCOV
1370
  QUERY_CHECK_NULL(info->pNotifyAddrUrls, code, lino, _exit, terrno);
×
UNCOV
1371
  for (int32_t i = 0; i < addrSize; ++i) {
×
1372
    char *url = NULL;
×
1373
    TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &url));
×
1374
    url = taosStrndup(url, TSDB_STREAM_NOTIFY_URL_LEN);
×
1375
    QUERY_CHECK_NULL(url, code, lino, _exit, terrno);
×
1376
    if (taosArrayPush(info->pNotifyAddrUrls, &url) == NULL) {
×
1377
      taosMemoryFree(url);
×
1378
      TAOS_CHECK_EXIT(terrno);
×
1379
    }
1380
  }
UNCOV
1381
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &info->notifyEventTypes));
×
UNCOV
1382
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &info->notifyErrorHandle));
×
UNCOV
1383
  if (addrSize > 0) {
×
1384
    char* name = NULL;
×
1385
    TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &name));
×
1386
    info->streamName = taosStrndup(name, TSDB_STREAM_FNAME_LEN + 1);
×
1387
    QUERY_CHECK_NULL(info->streamName, code, lino, _exit, terrno);
×
1388
    TAOS_CHECK_EXIT(tDecodeCStr(pDecoder, &name));
×
1389
    info->stbFullName = taosStrndup(name, TSDB_STREAM_FNAME_LEN + 1);
×
1390
    QUERY_CHECK_NULL(info->stbFullName, code, lino, _exit, terrno);
×
1391
    info->pSchemaWrapper = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
×
1392
    if (info->pSchemaWrapper == NULL) {
×
1393
      TAOS_CHECK_EXIT(terrno);
×
1394
    }
1395
    TAOS_CHECK_EXIT(tDecodeSSchemaWrapper(pDecoder, info->pSchemaWrapper));
×
1396
  }
1397

UNCOV
1398
_exit:
×
UNCOV
1399
  if (code != TSDB_CODE_SUCCESS) {
×
1400
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1401
  }
UNCOV
1402
  return code;
×
1403
}
1404

UNCOV
1405
int32_t tEncodeStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) {
×
UNCOV
1406
  int32_t code = 0;
×
1407
  int32_t lino;
1408

UNCOV
1409
  TAOS_CHECK_EXIT(tStartEncode(pEncoder));
×
UNCOV
1410
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->ver));
×
UNCOV
1411
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->id.streamId));
×
UNCOV
1412
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->id.taskId));
×
UNCOV
1413
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.trigger));
×
UNCOV
1414
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->info.taskLevel));
×
UNCOV
1415
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->outputInfo.type));
×
UNCOV
1416
  TAOS_CHECK_EXIT(tEncodeI16(pEncoder, pTask->msgInfo.msgType));
×
1417

UNCOV
1418
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->status.taskStatus));
×
UNCOV
1419
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->status.schedStatus));
×
1420

UNCOV
1421
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.selfChildId));
×
UNCOV
1422
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.nodeId));
×
UNCOV
1423
  TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->info.epSet));
×
UNCOV
1424
  TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->info.mnodeEpset));
×
1425

UNCOV
1426
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->chkInfo.checkpointId));
×
UNCOV
1427
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->chkInfo.checkpointVer));
×
UNCOV
1428
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->info.fillHistory));
×
1429

UNCOV
1430
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->hTaskInfo.id.streamId));
×
UNCOV
1431
  int32_t taskId = pTask->hTaskInfo.id.taskId;
×
UNCOV
1432
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, taskId));
×
1433

UNCOV
1434
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->streamTaskId.streamId));
×
UNCOV
1435
  taskId = pTask->streamTaskId.taskId;
×
UNCOV
1436
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, taskId));
×
1437

UNCOV
1438
  TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTask->dataRange.range.minVer));
×
UNCOV
1439
  TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTask->dataRange.range.maxVer));
×
UNCOV
1440
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->dataRange.window.skey));
×
UNCOV
1441
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->dataRange.window.ekey));
×
1442

UNCOV
1443
  int32_t epSz = taosArrayGetSize(pTask->upstreamInfo.pList);
×
UNCOV
1444
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, epSz));
×
UNCOV
1445
  for (int32_t i = 0; i < epSz; i++) {
×
UNCOV
1446
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
×
UNCOV
1447
    TAOS_CHECK_EXIT(tEncodeStreamEpInfo(pEncoder, pInfo));
×
1448
  }
1449

UNCOV
1450
  if (pTask->info.taskLevel != TASK_LEVEL__SINK) {
×
UNCOV
1451
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->exec.qmsg));
×
1452
  }
1453

UNCOV
1454
  if (pTask->outputInfo.type == TASK_OUTPUT__TABLE) {
×
UNCOV
1455
    TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->outputInfo.tbSink.stbUid));
×
UNCOV
1456
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->outputInfo.tbSink.stbFullName));
×
UNCOV
1457
    TAOS_CHECK_EXIT(tEncodeSSchemaWrapper(pEncoder, pTask->outputInfo.tbSink.pSchemaWrapper));
×
UNCOV
1458
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SMA) {
×
UNCOV
1459
    TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->outputInfo.smaSink.smaId));
×
UNCOV
1460
  } else if (pTask->outputInfo.type == TASK_OUTPUT__FETCH) {
×
1461
    TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->outputInfo.fetchSink.reserved));
×
UNCOV
1462
  } else if (pTask->outputInfo.type == TASK_OUTPUT__FIXED_DISPATCH) {
×
UNCOV
1463
    TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->outputInfo.fixedDispatcher.taskId));
×
UNCOV
1464
    TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->outputInfo.fixedDispatcher.nodeId));
×
UNCOV
1465
    TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->outputInfo.fixedDispatcher.epSet));
×
UNCOV
1466
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
UNCOV
1467
    TAOS_CHECK_EXIT(tSerializeSUseDbRspImp(pEncoder, &pTask->outputInfo.shuffleDispatcher.dbInfo));
×
UNCOV
1468
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->outputInfo.shuffleDispatcher.stbFullName));
×
1469
  }
UNCOV
1470
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->info.delaySchedParam));
×
UNCOV
1471
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->subtableWithoutMd5));
×
UNCOV
1472
  TAOS_CHECK_EXIT(tEncodeCStrWithLen(pEncoder, pTask->reserve, sizeof(pTask->reserve) - 1));
×
1473

UNCOV
1474
  if (pTask->ver >= SSTREAM_TASK_ADD_NOTIFY_VER) {
×
UNCOV
1475
    TAOS_CHECK_EXIT(tEncodeStreamNotifyInfo(pEncoder, &pTask->notifyInfo));
×
1476
  }
1477

UNCOV
1478
  tEndEncode(pEncoder);
×
UNCOV
1479
_exit:
×
UNCOV
1480
  return code;
×
1481
}
1482

UNCOV
1483
int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask) {
×
UNCOV
1484
  int32_t taskId = 0;
×
UNCOV
1485
  int32_t code = 0;
×
1486
  int32_t lino;
1487

UNCOV
1488
  TAOS_CHECK_EXIT(tStartDecode(pDecoder));
×
UNCOV
1489
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->ver));
×
UNCOV
1490
  if (pTask->ver <= SSTREAM_TASK_INCOMPATIBLE_VER || pTask->ver > SSTREAM_TASK_VER) {
×
UNCOV
1491
    TAOS_CHECK_EXIT(TSDB_CODE_INVALID_MSG);
×
1492
  }
1493

UNCOV
1494
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->id.streamId));
×
UNCOV
1495
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->id.taskId));
×
UNCOV
1496
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.trigger));
×
UNCOV
1497
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->info.taskLevel));
×
UNCOV
1498
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->outputInfo.type));
×
UNCOV
1499
  TAOS_CHECK_EXIT(tDecodeI16(pDecoder, &pTask->msgInfo.msgType));
×
1500

UNCOV
1501
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->status.taskStatus));
×
UNCOV
1502
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->status.schedStatus));
×
1503

UNCOV
1504
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.selfChildId));
×
UNCOV
1505
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.nodeId));
×
UNCOV
1506
  TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->info.epSet));
×
UNCOV
1507
  TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->info.mnodeEpset));
×
1508

UNCOV
1509
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->chkInfo.checkpointId));
×
UNCOV
1510
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->chkInfo.checkpointVer));
×
UNCOV
1511
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->info.fillHistory));
×
1512

UNCOV
1513
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->hTaskInfo.id.streamId));
×
UNCOV
1514
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &taskId));
×
UNCOV
1515
  pTask->hTaskInfo.id.taskId = taskId;
×
1516

UNCOV
1517
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->streamTaskId.streamId));
×
UNCOV
1518
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &taskId));
×
UNCOV
1519
  pTask->streamTaskId.taskId = taskId;
×
1520

UNCOV
1521
  TAOS_CHECK_EXIT(tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.minVer));
×
UNCOV
1522
  TAOS_CHECK_EXIT(tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.maxVer));
×
UNCOV
1523
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->dataRange.window.skey));
×
UNCOV
1524
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->dataRange.window.ekey));
×
1525

UNCOV
1526
  int32_t epSz = -1;
×
UNCOV
1527
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &epSz) < 0);
×
1528

UNCOV
1529
  if ((pTask->upstreamInfo.pList = taosArrayInit(epSz, POINTER_BYTES)) == NULL) {
×
1530
    TAOS_CHECK_EXIT(terrno);
×
1531
  }
UNCOV
1532
  for (int32_t i = 0; i < epSz; i++) {
×
UNCOV
1533
    SStreamUpstreamEpInfo* pInfo = taosMemoryCalloc(1, sizeof(SStreamUpstreamEpInfo));
×
UNCOV
1534
    if (pInfo == NULL) {
×
1535
      TAOS_CHECK_EXIT(terrno);
×
1536
    }
UNCOV
1537
    if ((code = tDecodeStreamEpInfo(pDecoder, pInfo)) < 0) {
×
1538
      taosMemoryFreeClear(pInfo);
×
1539
      goto _exit;
×
1540
    }
UNCOV
1541
    if (taosArrayPush(pTask->upstreamInfo.pList, &pInfo) == NULL) {
×
1542
      TAOS_CHECK_EXIT(terrno);
×
1543
    }
1544
  }
1545

UNCOV
1546
  if (pTask->info.taskLevel != TASK_LEVEL__SINK) {
×
UNCOV
1547
    TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg));
×
1548
  }
1549

UNCOV
1550
  if (pTask->outputInfo.type == TASK_OUTPUT__TABLE) {
×
UNCOV
1551
    TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->outputInfo.tbSink.stbUid));
×
UNCOV
1552
    TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTask->outputInfo.tbSink.stbFullName));
×
UNCOV
1553
    pTask->outputInfo.tbSink.pSchemaWrapper = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
×
UNCOV
1554
    if (pTask->outputInfo.tbSink.pSchemaWrapper == NULL) {
×
1555
      TAOS_CHECK_EXIT(terrno);
×
1556
    }
UNCOV
1557
    TAOS_CHECK_EXIT(tDecodeSSchemaWrapper(pDecoder, pTask->outputInfo.tbSink.pSchemaWrapper));
×
UNCOV
1558
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SMA) {
×
UNCOV
1559
    TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->outputInfo.smaSink.smaId));
×
UNCOV
1560
  } else if (pTask->outputInfo.type == TASK_OUTPUT__FETCH) {
×
1561
    TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->outputInfo.fetchSink.reserved));
×
UNCOV
1562
  } else if (pTask->outputInfo.type == TASK_OUTPUT__FIXED_DISPATCH) {
×
UNCOV
1563
    TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->outputInfo.fixedDispatcher.taskId));
×
UNCOV
1564
    TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->outputInfo.fixedDispatcher.nodeId));
×
UNCOV
1565
    TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->outputInfo.fixedDispatcher.epSet));
×
UNCOV
1566
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
UNCOV
1567
    TAOS_CHECK_EXIT(tDeserializeSUseDbRspImp(pDecoder, &pTask->outputInfo.shuffleDispatcher.dbInfo));
×
UNCOV
1568
    TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTask->outputInfo.shuffleDispatcher.stbFullName));
×
1569
  }
UNCOV
1570
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->info.delaySchedParam));
×
UNCOV
1571
  if (pTask->ver >= SSTREAM_TASK_SUBTABLE_CHANGED_VER) {
×
UNCOV
1572
    TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->subtableWithoutMd5));
×
1573
  }
UNCOV
1574
  TAOS_CHECK_EXIT(tDecodeCStrTo(pDecoder, pTask->reserve));
×
1575

UNCOV
1576
  if (pTask->ver >= SSTREAM_TASK_ADD_NOTIFY_VER) {
×
UNCOV
1577
    TAOS_CHECK_EXIT(tDecodeStreamNotifyInfo(pDecoder, &pTask->notifyInfo));
×
1578
  }
1579

UNCOV
1580
  tEndDecode(pDecoder);
×
1581

UNCOV
1582
_exit:
×
UNCOV
1583
  return code;
×
1584
}
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