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

taosdata / TDengine / #3653

14 Mar 2025 08:10AM UTC coverage: 22.565% (-41.0%) from 63.596%
#3653

push

travis-ci

web-flow
feat(keep): support keep on super table level. (#30097)

* Feat: support use keep while create super table.

* Test(keep): add test for create super table with keep option.

* Feat(keep): Add tmsg for create keep.

* Feat(keep): support alter table option keep.

* Fix(keep): Add baisc test for alter table option.

* Fix(keep): memory leek.

* Feat(keep): add keep to metaEntry&metaCache and fix earliestTs with stn keep.

* Test(keep): add some cases for select with stb keep.

* Fix: fix ci core while alter stb.

* Feat(keep): delete expired data in super table level.

* Feat: remove get stb keep while query.

* Fix : build error.

* Revert "Fix : build error."

This reverts commit 0ed66e4e8.

* Revert "Feat(keep): delete expired data in super table level."

This reverts commit 36330f6b4.

* Fix : build errors.

* Feat : support restart taosd.

* Fix : alter table comment problems.

* Test : add tests for super table keep.

* Fix: change sdb stb reserve size.

* Test: add more tests.

* Feat: Disable normal tables and sub tables from setting the keep parameter

* Fix: add more checks to avoid unknown address.

* Docs: Add docs for stable keep.

* Fix: some review changes.

* Fix: review errors.

49248 of 302527 branches covered (16.28%)

Branch coverage included in aggregate %.

53 of 99 new or added lines in 12 files covered. (53.54%)

155872 existing lines in 443 files now uncovered.

87359 of 302857 relevant lines covered (28.84%)

570004.22 hits per line

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

21.4
/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

32
static int32_t addToTaskset(SArray* pArray, SStreamTask* pTask) {
10✔
33
  int32_t childId = taosArrayGetSize(pArray);
10✔
34
  pTask->info.selfChildId = childId;
10✔
35
  void* p = taosArrayPush(pArray, &pTask);
10✔
36
  return (p == NULL) ? terrno : TSDB_CODE_SUCCESS;
10!
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

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

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

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

104
  return pEpInfo;
5✔
105
}
106

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

112
  SStreamTask* pTask = (SStreamTask*)taosMemoryCalloc(1, sizeof(SStreamTask));
10!
113
  if (pTask == NULL) {
10!
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

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

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

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

135
  char    buf[128] = {0};
10✔
136
  int32_t ret = snprintf(buf, tListLen(buf), "0x%" PRIx64 "-0x%x", pTask->id.streamId, pTask->id.taskId);
10✔
137
  if (ret < 0 || ret >= tListLen(buf)) {
10!
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

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

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

153
  pTask->taskCheckInfo.pList = taosArrayInit(4, sizeof(SDownstreamStatusInfo));
10✔
154

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

160
  epsetAssign(&(pTask->info.mnodeEpset), pEpset);
10✔
161

162
  code = addToTaskset(pTaskList, pTask);
10✔
163
  *p = pTask;
10✔
164

165
  return code;
10✔
166
}
167

UNCOV
168
int32_t tDecodeStreamTaskChkInfo(SDecoder* pDecoder, SCheckpointInfo* pChkpInfo) {
×
169
  int64_t skip64;
170
  int8_t  skip8;
171
  int32_t skip32;
172
  int16_t skip16;
173
  SEpSet  epSet;
174

UNCOV
175
  if (tStartDecode(pDecoder) < 0) return -1;
×
UNCOV
176
  if (tDecodeI64(pDecoder, &pChkpInfo->msgVer) < 0) return -1;
×
177
  // if (ver <= SSTREAM_TASK_INCOMPATIBLE_VER) return -1;
178

UNCOV
179
  if (tDecodeI64(pDecoder, &skip64) < 0) return -1;
×
UNCOV
180
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
×
UNCOV
181
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
×
UNCOV
182
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
×
UNCOV
183
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
×
UNCOV
184
  if (tDecodeI16(pDecoder, &skip16) < 0) return -1;
×
185

UNCOV
186
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
×
UNCOV
187
  if (tDecodeI8(pDecoder, &skip8) < 0) return -1;
×
188

UNCOV
189
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
×
UNCOV
190
  if (tDecodeI32(pDecoder, &skip32) < 0) return -1;
×
UNCOV
191
  if (tDecodeSEpSet(pDecoder, &epSet) < 0) return -1;
×
UNCOV
192
  if (tDecodeSEpSet(pDecoder, &epSet) < 0) return -1;
×
193

UNCOV
194
  if (tDecodeI64(pDecoder, &pChkpInfo->checkpointId) < 0) return -1;
×
UNCOV
195
  if (tDecodeI64(pDecoder, &pChkpInfo->checkpointVer) < 0) return -1;
×
196

UNCOV
197
  tEndDecode(pDecoder);
×
UNCOV
198
  return 0;
×
199
}
200

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

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

UNCOV
209
  int32_t taskId = 0;
×
UNCOV
210
  if (tDecodeI32(pDecoder, &taskId) < 0) return -1;
×
211

UNCOV
212
  pTaskId->taskId = taskId;
×
UNCOV
213
  tEndDecode(pDecoder);
×
UNCOV
214
  return 0;
×
215
}
216

217
void tFreeStreamTask(void* pParam) {
7✔
218
  char*        p = NULL;
7✔
219
  SStreamTask* pTask = pParam;
7✔
220
  int32_t      taskId = pTask->id.taskId;
7✔
221

222
  STaskExecStatisInfo* pStatis = &pTask->execInfo;
7✔
223

224
  ETaskStatus status1 = TASK_STATUS__UNINIT;
7✔
225
  if (pTask->status.pSM != NULL) {
7✔
226
    streamMutexLock(&pTask->lock);
6✔
227
    SStreamTaskState status = streamTaskGetStatus(pTask);
6✔
228
    p = status.name;
6✔
229
    status1 = status.state;
6✔
230
    streamMutexUnlock(&pTask->lock);
6✔
231
  }
232

233
  stDebug("start to free s-task:0x%x %p, state:%s, refId:%" PRId64, taskId, pTask, p, pTask->id.refId);
7!
234

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

242
  if (pTask->schedInfo.pDelayTimer != NULL) {
7!
UNCOV
243
    streamTmrStop(pTask->schedInfo.pDelayTimer);
×
UNCOV
244
    pTask->schedInfo.pDelayTimer = NULL;
×
245
  }
246

247
  if (pTask->hTaskInfo.pTimer != NULL) {
7!
UNCOV
248
    streamTmrStop(pTask->hTaskInfo.pTimer);
×
UNCOV
249
    pTask->hTaskInfo.pTimer = NULL;
×
250
  }
251

252
  if (pTask->msgInfo.pRetryTmr != NULL) {
7!
UNCOV
253
    streamTmrStop(pTask->msgInfo.pRetryTmr);
×
UNCOV
254
    pTask->msgInfo.pRetryTmr = NULL;
×
255
  }
256

257
  if (pTask->inputq.queue) {
7!
UNCOV
258
    streamQueueClose(pTask->inputq.queue, pTask->id.taskId);
×
UNCOV
259
    pTask->inputq.queue = NULL;
×
260
  }
261

262
  if (pTask->outputq.queue) {
7!
UNCOV
263
    streamQueueClose(pTask->outputq.queue, pTask->id.taskId);
×
UNCOV
264
    pTask->outputq.queue = NULL;
×
265
  }
266

267
  if (pTask->exec.qmsg) {
7✔
268
    taosMemoryFree(pTask->exec.qmsg);
1!
269
  }
270

271
  if (pTask->exec.pExecutor) {
7!
UNCOV
272
    qDestroyTask(pTask->exec.pExecutor);
×
UNCOV
273
    pTask->exec.pExecutor = NULL;
×
274
  }
275

276
  if (pTask->exec.pWalReader != NULL) {
7!
UNCOV
277
    walCloseReader(pTask->exec.pWalReader);
×
UNCOV
278
    pTask->exec.pWalReader = NULL;
×
279
  }
280

281
  streamClearChkptReadyMsg(pTask->chkInfo.pActiveInfo);
7✔
282

283
  if (pTask->msgInfo.pData != NULL) {
7!
UNCOV
284
    clearBufferedDispatchMsg(pTask);
×
285
  }
286

287
  if (pTask->outputInfo.type == TASK_OUTPUT__TABLE) {
7!
UNCOV
288
    tDeleteSchemaWrapper(pTask->outputInfo.tbSink.pSchemaWrapper);
×
UNCOV
289
    taosMemoryFree(pTask->outputInfo.tbSink.pTSchema);
×
UNCOV
290
    tSimpleHashCleanup(pTask->outputInfo.tbSink.pTbInfo);
×
UNCOV
291
    tDeleteSchemaWrapper(pTask->outputInfo.tbSink.pTagSchema);
×
292
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
7!
UNCOV
293
    taosArrayDestroy(pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos);
×
294
  }
295

296
  streamTaskCleanupCheckInfo(&pTask->taskCheckInfo);
7✔
297
  streamFreeTaskState(pTask, pTask->status.removeBackendFiles ? 1 : 0);
7✔
298

299
  if (pTask->pNameMap) {
7!
UNCOV
300
    tSimpleHashCleanup(pTask->pNameMap);
×
301
  }
302

303
  if (pTask->status.pSM != NULL) {
7✔
304
    streamMutexDestroy(&pTask->lock);
6✔
305
    streamMutexDestroy(&pTask->msgInfo.lock);
6✔
306
    streamMutexDestroy(&pTask->taskCheckInfo.checkInfoLock);
6✔
307
  }
308

309
  streamDestroyStateMachine(pTask->status.pSM);
7✔
310
  pTask->status.pSM = NULL;
7✔
311

312
  streamTaskDestroyUpstreamInfo(&pTask->upstreamInfo);
7✔
313

314
  taosMemoryFree(pTask->outputInfo.pTokenBucket);
7!
315

316
  taosArrayDestroy(pTask->msgInfo.pSendInfo);
7✔
317
  pTask->msgInfo.pSendInfo = NULL;
7✔
318

319
  taosArrayDestroy(pTask->outputInfo.pNodeEpsetUpdateList);
7✔
320
  pTask->outputInfo.pNodeEpsetUpdateList = NULL;
7✔
321

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

326
  streamTaskDestroyActiveChkptInfo(pTask->chkInfo.pActiveInfo);
7✔
327
  pTask->chkInfo.pActiveInfo = NULL;
7✔
328

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

334
  pTask->notifyEventStat = (STaskNotifyEventStat){0};
7✔
335

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

340
void streamFreeTaskState(SStreamTask* pTask, int8_t remove) {
7✔
341
  stDebug("s-task:0x%x start to free task state/backend", pTask->id.taskId);
7!
342
  if (pTask->pState != NULL) {
7!
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 {
351
    stDebug("s-task:0x%x task state is NULL, may del backend:%s", pTask->id.taskId,
7!
352
            pTask->backendPath ? pTask->backendPath : "NULL");
353
    if (remove) {
7!
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

361
  if (pTask->backendPath != NULL) {
7!
UNCOV
362
    taosMemoryFree(pTask->backendPath);
×
UNCOV
363
    pTask->backendPath = NULL;
×
364
  }
365
}
7✔
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)) {
×
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) {
×
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
  code = taosThreadMutexInit(&pTask->taskCheckInfo.checkInfoLock, NULL);
×
UNCOV
533
  if (code) {
×
UNCOV
534
    return code;
×
535
  }
536

UNCOV
537
  if (pTask->chkInfo.pActiveInfo == NULL) {
×
UNCOV
538
    code = streamTaskCreateActiveChkptInfo(&pTask->chkInfo.pActiveInfo);
×
UNCOV
539
    if (code) {
×
UNCOV
540
      stError("s-task:%s failed to create active checkpoint info, code:%s", pTask->id.idStr, tstrerror(code));
×
UNCOV
541
      return code;
×
542
    }
543
  }
544

UNCOV
545
  return streamTaskSetBackendPath(pTask);
×
546
}
547

UNCOV
548
int32_t streamTaskGetNumOfDownstream(const SStreamTask* pTask) {
×
UNCOV
549
  if (pTask->info.taskLevel == TASK_LEVEL__SINK) {
×
UNCOV
550
    return 0;
×
551
  }
552

UNCOV
553
  int32_t type = pTask->outputInfo.type;
×
UNCOV
554
  if (type == TASK_OUTPUT__TABLE) {
×
UNCOV
555
    return 0;
×
UNCOV
556
  } else if (type == TASK_OUTPUT__FIXED_DISPATCH) {
×
UNCOV
557
    return 1;
×
558
  } else {
UNCOV
559
    SArray* vgInfo = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
×
UNCOV
560
    return taosArrayGetSize(vgInfo);
×
561
  }
562
}
563

564
int32_t streamTaskGetNumOfUpstream(const SStreamTask* pTask) { return taosArrayGetSize(pTask->upstreamInfo.pList); }
2✔
565

566
int32_t streamTaskSetUpstreamInfo(SStreamTask* pTask, const SStreamTask* pUpstreamTask) {
5✔
567
  SStreamUpstreamEpInfo* pEpInfo = createStreamTaskEpInfo(pUpstreamTask);
5✔
568
  if (pEpInfo == NULL) {
5!
UNCOV
569
    return terrno;
×
570
  }
571

572
  if (pTask->upstreamInfo.pList == NULL) {
5✔
573
    pTask->upstreamInfo.pList = taosArrayInit(4, POINTER_BYTES);
3✔
574
  }
575

576
  void* p = taosArrayPush(pTask->upstreamInfo.pList, &pEpInfo);
5✔
577
  return (p == NULL) ? terrno : TSDB_CODE_SUCCESS;
5!
578
}
579

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

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

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

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

UNCOV
612
      break;
×
613
    }
614
  }
615

UNCOV
616
  return code;
×
617
}
618

619
void streamTaskDestroyUpstreamInfo(SUpstreamInfo* pUpstreamInfo) {
7✔
620
  if (pUpstreamInfo->pList != NULL) {
7✔
621
    taosArrayDestroyEx(pUpstreamInfo->pList, freeUpstreamItem);
1✔
622
    pUpstreamInfo->numOfClosed = 0;
1✔
623
    pUpstreamInfo->pList = NULL;
1✔
624
  }
625
}
7✔
626

UNCOV
627
void streamTaskSetFixedDownstreamInfo(SStreamTask* pTask, const SStreamTask* pDownstreamTask) {
×
UNCOV
628
  STaskDispatcherFixed* pDispatcher = &pTask->outputInfo.fixedDispatcher;
×
UNCOV
629
  pDispatcher->taskId = pDownstreamTask->id.taskId;
×
UNCOV
630
  pDispatcher->nodeId = pDownstreamTask->info.nodeId;
×
UNCOV
631
  pDispatcher->epSet = pDownstreamTask->info.epSet;
×
632

UNCOV
633
  pTask->outputInfo.type = TASK_OUTPUT__FIXED_DISPATCH;
×
UNCOV
634
  pTask->msgInfo.msgType = TDMT_STREAM_TASK_DISPATCH;
×
UNCOV
635
}
×
636

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

UNCOV
645
  int32_t id = pTask->id.taskId;
×
UNCOV
646
  int8_t  type = pTask->outputInfo.type;
×
647

UNCOV
648
  if (type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
649
    SArray* pVgs = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
×
650

UNCOV
651
    for (int32_t i = 0; i < taosArrayGetSize(pVgs); i++) {
×
UNCOV
652
      SVgroupInfo* pVgInfo = taosArrayGet(pVgs, i);
×
UNCOV
653
      if (pVgInfo == NULL) {
×
UNCOV
654
        continue;
×
655
      }
656

UNCOV
657
      if (pVgInfo->vgId == nodeId) {
×
UNCOV
658
        bool isEqual = isEpsetEqual(&pVgInfo->epSet, pEpSet);
×
UNCOV
659
        if (!isEqual) {
×
660
          *pUpdated = true;
×
661

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

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

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

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

UNCOV
703
  return code;
×
704
}
705

UNCOV
706
int32_t streamTaskStop(SStreamTask* pTask) {
×
UNCOV
707
  int32_t     vgId = pTask->pMeta->vgId;
×
708
  int64_t     st = taosGetTimestampMs();
×
709
  const char* id = pTask->id.idStr;
×
710

UNCOV
711
  int32_t code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_STOP);
×
UNCOV
712
  if (code) {
×
UNCOV
713
    stError("failed to handle STOP event, s-task:%s, code:%s", id, tstrerror(code));
×
UNCOV
714
    return code;
×
715
  }
716

UNCOV
717
  if (pTask->info.taskLevel != TASK_LEVEL__SINK && pTask->exec.pExecutor != NULL) {
×
UNCOV
718
    code = qKillTask(pTask->exec.pExecutor, TSDB_CODE_SUCCESS, 5000);
×
UNCOV
719
    if (code != TSDB_CODE_SUCCESS) {
×
720
      stError("s-task:%s failed to kill task related query handle, code:%s", id, tstrerror(code));
×
721
    }
722
  }
723

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

UNCOV
730
  int64_t el = taosGetTimestampMs() - st;
×
UNCOV
731
  stDebug("vgId:%d s-task:%s is closed in %" PRId64 " ms", vgId, id, el);
×
UNCOV
732
  return code;
×
733
}
734

UNCOV
735
bool streamTaskUpdateEpsetInfo(SStreamTask* pTask, SArray* pNodeList) {
×
UNCOV
736
  STaskExecStatisInfo* p = &pTask->execInfo;
×
737

UNCOV
738
  int32_t numOfNodes = taosArrayGetSize(pNodeList);
×
UNCOV
739
  int64_t prevTs = p->latestUpdateTs;
×
740

UNCOV
741
  p->latestUpdateTs = taosGetTimestampMs();
×
UNCOV
742
  p->updateCount += 1;
×
UNCOV
743
  stDebug("s-task:0x%x update task nodeEp epset, updatedNodes:%d, updateCount:%d, prevTs:%" PRId64, pTask->id.taskId,
×
744
          numOfNodes, p->updateCount, prevTs);
745

UNCOV
746
  bool updated = false;
×
UNCOV
747
  for (int32_t i = 0; i < numOfNodes; ++i) {
×
UNCOV
748
    SNodeUpdateInfo* pInfo = taosArrayGet(pNodeList, i);
×
UNCOV
749
    if (pInfo == NULL) {
×
750
      continue;
×
751
    }
752

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

UNCOV
759
  return updated;
×
760
}
761

UNCOV
762
void streamTaskResetUpstreamStageInfo(SStreamTask* pTask) {
×
UNCOV
763
  if (pTask->info.taskLevel == TASK_LEVEL__SOURCE) {
×
UNCOV
764
    return;
×
765
  }
766

UNCOV
767
  int32_t size = taosArrayGetSize(pTask->upstreamInfo.pList);
×
UNCOV
768
  for (int32_t i = 0; i < size; ++i) {
×
UNCOV
769
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
×
UNCOV
770
    pInfo->stage = -1;
×
771
  }
772

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

UNCOV
776
void streamTaskOpenAllUpstreamInput(SStreamTask* pTask) {
×
UNCOV
777
  int32_t num = taosArrayGetSize(pTask->upstreamInfo.pList);
×
UNCOV
778
  if (num == 0) {
×
UNCOV
779
    return;
×
780
  }
781

UNCOV
782
  for (int32_t i = 0; i < num; ++i) {
×
UNCOV
783
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
×
UNCOV
784
    pInfo->dataAllowed = true;
×
785
  }
786

UNCOV
787
  pTask->upstreamInfo.numOfClosed = 0;
×
UNCOV
788
  stDebug("s-task:%s opening up inputQ for %d upstream tasks", pTask->id.idStr, num);
×
789
}
790

UNCOV
791
void streamTaskCloseUpstreamInput(SStreamTask* pTask, int32_t taskId) {
×
UNCOV
792
  SStreamUpstreamEpInfo* pInfo = NULL;
×
UNCOV
793
  streamTaskGetUpstreamTaskEpInfo(pTask, taskId, &pInfo);
×
794

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

805
void streamTaskOpenUpstreamInput(SStreamTask* pTask, int32_t taskId) {
1✔
806
  SStreamUpstreamEpInfo* pInfo = NULL;
1✔
807
  streamTaskGetUpstreamTaskEpInfo(pTask, taskId, &pInfo);
1✔
808

809
  if (pInfo != NULL && (!pInfo->dataAllowed)) {
1!
810
    int32_t t = atomic_sub_fetch_32(&pTask->upstreamInfo.numOfClosed, 1);
1✔
811
    stDebug("s-task:%s open inputQ for upstream:0x%x, remain closed:%d", pTask->id.idStr, taskId, t);
1!
812
    pInfo->dataAllowed = true;
1✔
813
  }
814
}
1✔
815

UNCOV
816
bool streamTaskIsAllUpstreamClosed(SStreamTask* pTask) {
×
UNCOV
817
  return pTask->upstreamInfo.numOfClosed == taosArrayGetSize(pTask->upstreamInfo.pList);
×
818
}
819

UNCOV
820
bool streamTaskSetSchedStatusWait(SStreamTask* pTask) {
×
UNCOV
821
  bool ret = false;
×
822

UNCOV
823
  streamMutexLock(&pTask->lock);
×
UNCOV
824
  if (pTask->status.schedStatus == TASK_SCHED_STATUS__INACTIVE) {
×
UNCOV
825
    pTask->status.schedStatus = TASK_SCHED_STATUS__WAITING;
×
UNCOV
826
    ret = true;
×
827
  }
828

UNCOV
829
  streamMutexUnlock(&pTask->lock);
×
UNCOV
830
  return ret;
×
831
}
832

UNCOV
833
int8_t streamTaskSetSchedStatusActive(SStreamTask* pTask) {
×
UNCOV
834
  streamMutexLock(&pTask->lock);
×
UNCOV
835
  int8_t status = pTask->status.schedStatus;
×
UNCOV
836
  if (status == TASK_SCHED_STATUS__WAITING) {
×
UNCOV
837
    pTask->status.schedStatus = TASK_SCHED_STATUS__ACTIVE;
×
838
  }
UNCOV
839
  streamMutexUnlock(&pTask->lock);
×
840

UNCOV
841
  return status;
×
842
}
843

UNCOV
844
int8_t streamTaskSetSchedStatusInactive(SStreamTask* pTask) {
×
UNCOV
845
  streamMutexLock(&pTask->lock);
×
UNCOV
846
  int8_t status = pTask->status.schedStatus;
×
UNCOV
847
  pTask->status.schedStatus = TASK_SCHED_STATUS__INACTIVE;
×
UNCOV
848
  streamMutexUnlock(&pTask->lock);
×
849

UNCOV
850
  return status;
×
851
}
852

UNCOV
853
int32_t streamTaskClearHTaskAttr(SStreamTask* pTask, int32_t resetRelHalt) {
×
UNCOV
854
  int32_t      code = 0;
×
UNCOV
855
  SStreamMeta* pMeta = pTask->pMeta;
×
UNCOV
856
  SStreamTask* pStreamTask = NULL;
×
857

UNCOV
858
  if (pTask->info.fillHistory == 0) {
×
859
    return code;
×
860
  }
861

862
  code = streamMetaAcquireTaskUnsafe(pMeta, &pTask->streamTaskId, &pStreamTask);
×
863
  if (code == 0) {
×
UNCOV
864
    stDebug("s-task:%s clear the related stream task:0x%x attr to fill-history task", pTask->id.idStr,
×
865
            (int32_t)pTask->streamTaskId.taskId);
866

UNCOV
867
    streamMutexLock(&(pStreamTask->lock));
×
UNCOV
868
    CLEAR_RELATED_FILLHISTORY_TASK(pStreamTask);
×
869

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

UNCOV
877
    code = streamMetaSaveTaskInMeta(pMeta, pStreamTask);
×
UNCOV
878
    streamMutexUnlock(&(pStreamTask->lock));
×
879

UNCOV
880
    streamMetaReleaseTask(pMeta, pStreamTask);
×
881
  }
882

UNCOV
883
  return code;
×
884
}
885

UNCOV
886
int32_t streamBuildAndSendDropTaskMsg(SMsgCb* pMsgCb, int32_t vgId, SStreamTaskId* pTaskId, int64_t resetRelHalt) {
×
UNCOV
887
  SVDropStreamTaskReq* pReq = rpcMallocCont(sizeof(SVDropStreamTaskReq));
×
UNCOV
888
  if (pReq == NULL) {
×
UNCOV
889
    return terrno;
×
890
  }
891

UNCOV
892
  pReq->head.vgId = vgId;
×
UNCOV
893
  pReq->taskId = pTaskId->taskId;
×
UNCOV
894
  pReq->streamId = pTaskId->streamId;
×
895
  pReq->resetRelHalt = resetRelHalt;
×
896

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

UNCOV
905
  return code;
×
906
}
907

UNCOV
908
int32_t streamSendChkptReportMsg(SStreamTask* pTask, SCheckpointInfo* pCheckpointInfo, int8_t dropRelHTask) {
×
UNCOV
909
  int32_t                code = 0;
×
UNCOV
910
  int32_t                tlen = 0;
×
UNCOV
911
  int32_t                vgId = pTask->pMeta->vgId;
×
UNCOV
912
  const char*            id = pTask->id.idStr;
×
UNCOV
913
  SActiveCheckpointInfo* pActive = pCheckpointInfo->pActiveInfo;
×
914

UNCOV
915
  SCheckpointReport req = {.streamId = pTask->id.streamId,
×
UNCOV
916
                           .taskId = pTask->id.taskId,
×
917
                           .nodeId = vgId,
918
                           .dropHTask = dropRelHTask,
UNCOV
919
                           .transId = pActive->transId,
×
UNCOV
920
                           .checkpointId = pActive->activeId,
×
921
                           .checkpointVer = pCheckpointInfo->processedVer,
×
922
                           .checkpointTs = pCheckpointInfo->startTs};
×
923

UNCOV
924
  tEncodeSize(tEncodeStreamTaskChkptReport, &req, tlen, code);
×
UNCOV
925
  if (code < 0) {
×
UNCOV
926
    stError("s-task:%s vgId:%d encode stream task checkpoint-report failed, code:%s", id, vgId, tstrerror(code));
×
927
    return -1;
×
928
  }
929

UNCOV
930
  void* buf = rpcMallocCont(tlen);
×
UNCOV
931
  if (buf == NULL) {
×
UNCOV
932
    stError("s-task:%s vgId:%d encode stream task checkpoint-report msg failed, code:%s", id, vgId,
×
933
            tstrerror(TSDB_CODE_OUT_OF_MEMORY));
UNCOV
934
    return -1;
×
935
  }
936

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

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

UNCOV
951
  return tmsgSendReq(&pTask->info.mnodeEpset, &msg);
×
952
}
953

UNCOV
954
STaskId streamTaskGetTaskId(const SStreamTask* pTask) {
×
UNCOV
955
  STaskId id = {.streamId = pTask->id.streamId, .taskId = pTask->id.taskId};
×
UNCOV
956
  return id;
×
957
}
958

UNCOV
959
void streamTaskInitForLaunchHTask(SHistoryTaskInfo* pInfo) {
×
UNCOV
960
  pInfo->waitInterval = LAUNCH_HTASK_INTERVAL;
×
UNCOV
961
  pInfo->tickCount = ceil(LAUNCH_HTASK_INTERVAL / WAIT_FOR_MINIMAL_INTERVAL);
×
UNCOV
962
  pInfo->retryTimes = 0;
×
UNCOV
963
}
×
964

UNCOV
965
void streamTaskSetRetryInfoForLaunch(SHistoryTaskInfo* pInfo) {
×
UNCOV
966
  pInfo->waitInterval *= RETRY_LAUNCH_INTERVAL_INC_RATE;
×
UNCOV
967
  pInfo->tickCount = ceil(pInfo->waitInterval / WAIT_FOR_MINIMAL_INTERVAL);
×
UNCOV
968
  pInfo->retryTimes += 1;
×
UNCOV
969
}
×
970

971
void streamTaskStatusInit(STaskStatusEntry* pEntry, const SStreamTask* pTask) {
5✔
972
  pEntry->id.streamId = pTask->id.streamId;
5✔
973
  pEntry->id.taskId = pTask->id.taskId;
5✔
974
  pEntry->stage = -1;
5✔
975
  pEntry->nodeId = pTask->info.nodeId;
5✔
976
  pEntry->status = TASK_STATUS__STOP;
5✔
977
}
5✔
978

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

UNCOV
996
  pDst->startTime = pSrc->startTime;
×
UNCOV
997
  pDst->hTaskId = pSrc->hTaskId;
×
UNCOV
998
  pDst->notifyEventStat = pSrc->notifyEventStat;
×
UNCOV
999
}
×
1000

UNCOV
1001
STaskStatusEntry streamTaskGetStatusEntry(SStreamTask* pTask) {
×
UNCOV
1002
  SStreamMeta*         pMeta = pTask->pMeta;
×
UNCOV
1003
  STaskExecStatisInfo* pExecInfo = &pTask->execInfo;
×
1004

UNCOV
1005
  STaskStatusEntry entry = {
×
UNCOV
1006
      .id = streamTaskGetTaskId(pTask),
×
UNCOV
1007
      .status = streamTaskGetStatus(pTask).state,
×
UNCOV
1008
      .nodeId = pMeta->vgId,
×
UNCOV
1009
      .stage = pMeta->stage,
×
1010

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

UNCOV
1032
static int32_t taskPauseCallback(SStreamTask* pTask, void* param) {
×
UNCOV
1033
  SStreamMeta* pMeta = pTask->pMeta;
×
UNCOV
1034
  int32_t      code = 0;
×
1035

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

1039
  // in case of fill-history task, stop the tsdb file scan operation.
UNCOV
1040
  if (pTask->info.fillHistory == 1) {
×
UNCOV
1041
    void* pExecutor = pTask->exec.pExecutor;
×
UNCOV
1042
    code = qKillTask(pExecutor, TSDB_CODE_SUCCESS, 10000);
×
1043
  }
1044

UNCOV
1045
  stDebug("vgId:%d s-task:%s set pause flag and pause task", pMeta->vgId, pTask->id.idStr);
×
UNCOV
1046
  return code;
×
1047
}
1048

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

UNCOV
1056
void streamTaskResume(SStreamTask* pTask) {
×
UNCOV
1057
  SStreamTaskState prevState = streamTaskGetStatus(pTask);
×
1058

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

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

1073
// this task must success
UNCOV
1074
int32_t streamTaskSendCheckpointReq(SStreamTask* pTask) {
×
1075
  int32_t     code;
UNCOV
1076
  int32_t     tlen = 0;
×
UNCOV
1077
  int32_t     vgId = pTask->pMeta->vgId;
×
1078
  const char* id = pTask->id.idStr;
×
1079

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

UNCOV
1087
  void* buf = rpcMallocCont(tlen);
×
UNCOV
1088
  if (buf == NULL) {
×
UNCOV
1089
    stError("s-task:%s vgId:%d encode stream task req checkpoint msg failed, code:Out of memory", id, vgId);
×
UNCOV
1090
    return terrno;
×
1091
  }
1092

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

UNCOV
1102
  tEncoderClear(&encoder);
×
1103

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

UNCOV
1108
  return tmsgSendReq(&pTask->info.mnodeEpset, &msg);
×
1109
}
1110

1111
void streamTaskGetUpstreamTaskEpInfo(SStreamTask* pTask, int32_t taskId, SStreamUpstreamEpInfo** pEpInfo) {
2✔
1112
  *pEpInfo = NULL;
2✔
1113

1114
  int32_t num = taosArrayGetSize(pTask->upstreamInfo.pList);
2✔
1115
  for (int32_t i = 0; i < num; ++i) {
2!
1116
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
2✔
1117
    if (pInfo == NULL) {
2!
UNCOV
1118
      return;
×
1119
    }
1120

1121
    if (pInfo->taskId == taskId) {
2!
1122
      *pEpInfo = pInfo;
2✔
1123
      return;
2✔
1124
    }
1125
  }
1126

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

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

UNCOV
1143
      if (pVgInfo->taskId == taskId) {
×
1144
        return &pVgInfo->epSet;
×
1145
      }
1146
    }
1147
  }
1148

UNCOV
1149
  return NULL;
×
1150
}
1151

UNCOV
1152
int32_t createStreamTaskIdStr(int64_t streamId, int32_t taskId, const char** pId) {
×
UNCOV
1153
  char buf[128] = {0};
×
UNCOV
1154
  int32_t code = snprintf(buf, tListLen(buf),"0x%" PRIx64 "-0x%x", streamId, taskId);
×
UNCOV
1155
  if (code < 0 || code >= tListLen(buf)) {
×
UNCOV
1156
    return TSDB_CODE_OUT_OF_BUFFER;
×
1157
  }
1158

UNCOV
1159
  *pId = taosStrdup(buf);
×
1160

UNCOV
1161
  if (*pId == NULL) {
×
UNCOV
1162
    return terrno;
×
1163
  } else {
UNCOV
1164
    return TSDB_CODE_SUCCESS;
×
1165
  }
1166
}
1167

UNCOV
1168
static int32_t streamTaskEnqueueRetrieve(SStreamTask* pTask, SStreamRetrieveReq* pReq) {
×
1169
  int32_t           code;
1170
  SStreamDataBlock* pData;
1171

UNCOV
1172
  code = taosAllocateQitem(sizeof(SStreamDataBlock), DEF_QITEM, sizeof(SStreamDataBlock), (void**)&pData);
×
UNCOV
1173
  if (code) {
×
UNCOV
1174
    stError("s-task:%s failed to allocated retrieve-block", pTask->id.idStr);
×
UNCOV
1175
    return terrno = code;
×
1176
  }
1177

1178
  pData->type = STREAM_INPUT__DATA_RETRIEVE;
×
1179
  pData->srcVgId = 0;
×
1180

UNCOV
1181
  code = streamRetrieveReqToData(pReq, pData, pTask->id.idStr);
×
UNCOV
1182
  if (code != TSDB_CODE_SUCCESS) {
×
UNCOV
1183
    stError("s-task:%s failed to convert retrieve-data to block, code:%s", pTask->id.idStr, tstrerror(code));
×
UNCOV
1184
    taosFreeQitem(pData);
×
1185
    return code;
×
1186
  }
1187

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

UNCOV
1194
  return code;
×
1195
}
1196

UNCOV
1197
int32_t streamProcessRetrieveReq(SStreamTask* pTask, SStreamRetrieveReq* pReq) {
×
UNCOV
1198
  int32_t code = streamTaskEnqueueRetrieve(pTask, pReq);
×
UNCOV
1199
  if (code != 0) {
×
UNCOV
1200
    return code;
×
1201
  }
1202
  return streamTrySchedExec(pTask, false);
×
1203
}
1204

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

1207
void streamTaskGetActiveCheckpointInfo(const SStreamTask* pTask, int32_t* pTransId, int64_t* pCheckpointId) {
×
1208
  if (pTransId != NULL) {
×
UNCOV
1209
    *pTransId = pTask->chkInfo.pActiveInfo->transId;
×
1210
  }
1211

UNCOV
1212
  if (pCheckpointId != NULL) {
×
UNCOV
1213
    *pCheckpointId = pTask->chkInfo.pActiveInfo->activeId;
×
1214
  }
UNCOV
1215
}
×
1216

1217
int32_t streamTaskSetActiveCheckpointInfo(SStreamTask* pTask, int64_t activeCheckpointId) {
×
1218
  pTask->chkInfo.pActiveInfo->activeId = activeCheckpointId;
×
1219
  return TSDB_CODE_SUCCESS;
×
1220
}
1221

1222
void streamTaskSetFailedChkptInfo(SStreamTask* pTask, int32_t transId, int64_t checkpointId) {
×
UNCOV
1223
  pTask->chkInfo.pActiveInfo->transId = transId;
×
UNCOV
1224
  pTask->chkInfo.pActiveInfo->activeId = checkpointId;
×
UNCOV
1225
  pTask->chkInfo.pActiveInfo->failedId = checkpointId;
×
UNCOV
1226
  stDebug("s-task:%s set failed checkpointId:%"PRId64, pTask->id.idStr, checkpointId);
×
1227
}
×
1228

1229
int32_t streamTaskCreateActiveChkptInfo(SActiveCheckpointInfo** pRes) {
10✔
1230
  SActiveCheckpointInfo* pInfo = taosMemoryCalloc(1, sizeof(SActiveCheckpointInfo));
10!
1231
  if (pInfo == NULL) {
10!
1232
    return terrno;
×
1233
  }
1234

1235
  int32_t code = taosThreadMutexInit(&pInfo->lock, NULL);
10✔
1236
  if (code != TSDB_CODE_SUCCESS) {
10!
UNCOV
1237
    return code;
×
1238
  }
1239

1240
  pInfo->pDispatchTriggerList = taosArrayInit(4, sizeof(STaskTriggerSendInfo));
10✔
1241
  pInfo->pReadyMsgList = taosArrayInit(4, sizeof(STaskCheckpointReadyInfo));
10✔
1242
  pInfo->pCheckpointReadyRecvList = taosArrayInit(4, sizeof(STaskDownstreamReadyInfo));
10✔
1243

1244
  *pRes = pInfo;
10✔
1245
  return code;
10✔
1246
}
1247

1248
void streamTaskDestroyActiveChkptInfo(SActiveCheckpointInfo* pInfo) {
7✔
1249
  if (pInfo == NULL) {
7✔
1250
    return;
1✔
1251
  }
1252

1253
  streamMutexDestroy(&pInfo->lock);
6✔
1254
  taosArrayDestroy(pInfo->pDispatchTriggerList);
6✔
1255
  pInfo->pDispatchTriggerList = NULL;
6✔
1256
  taosArrayDestroy(pInfo->pReadyMsgList);
6✔
1257
  pInfo->pReadyMsgList = NULL;
6✔
1258
  taosArrayDestroy(pInfo->pCheckpointReadyRecvList);
6✔
1259
  pInfo->pCheckpointReadyRecvList = NULL;
6✔
1260

1261
  SStreamTmrInfo* pTriggerTmr = &pInfo->chkptTriggerMsgTmr;
6✔
1262
  if (pTriggerTmr->tmrHandle != NULL) {
6!
UNCOV
1263
    streamTmrStop(pTriggerTmr->tmrHandle);
×
UNCOV
1264
    pTriggerTmr->tmrHandle = NULL;
×
1265
  }
1266

1267
  SStreamTmrInfo* pReadyTmr = &pInfo->chkptReadyMsgTmr;
6✔
1268
  if (pReadyTmr->tmrHandle != NULL) {
6!
UNCOV
1269
    streamTmrStop(pReadyTmr->tmrHandle);
×
UNCOV
1270
    pReadyTmr->tmrHandle = NULL;
×
1271
  }
1272

1273
  taosMemoryFree(pInfo);
6!
1274
}
1275

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

UNCOV
1284
  taosArrayClear(pInfo->pDispatchTriggerList);
×
UNCOV
1285
  taosArrayClear(pInfo->pCheckpointReadyRecvList);
×
UNCOV
1286
}
×
1287

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

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

1329
void streamTaskFreeRefId(int64_t* pRefId) {
1✔
1330
  if (pRefId == NULL) {
1!
UNCOV
1331
    return;
×
1332
  }
1333

1334
  metaRefMgtRemove(pRefId);
1✔
1335
}
1336

1337
static int32_t tEncodeStreamNotifyInfo(SEncoder* pEncoder, const SNotifyInfo* info) {
2✔
1338
  int32_t code = TSDB_CODE_SUCCESS;
2✔
1339
  int32_t lino = 0;
2✔
1340

1341
  QUERY_CHECK_NULL(pEncoder, code, lino, _exit, TSDB_CODE_INVALID_PARA);
2!
1342
  QUERY_CHECK_NULL(info, code, lino, _exit, TSDB_CODE_INVALID_PARA);
2!
1343

1344
  int32_t addrSize = taosArrayGetSize(info->pNotifyAddrUrls);
2✔
1345
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, addrSize));
2!
1346
  for (int32_t i = 0; i < addrSize; ++i) {
2!
UNCOV
1347
    const char* url = taosArrayGetP(info->pNotifyAddrUrls, i);
×
1348
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, url));
×
1349
  }
1350
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, info->notifyEventTypes));
4!
1351
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, info->notifyErrorHandle));
4!
1352
  if (addrSize > 0) {
2!
UNCOV
1353
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, info->streamName));
×
UNCOV
1354
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, info->stbFullName));
×
UNCOV
1355
    TAOS_CHECK_EXIT(tEncodeSSchemaWrapper(pEncoder, info->pSchemaWrapper));
×
1356
  }
1357

1358
_exit:
2✔
1359
  if (code != TSDB_CODE_SUCCESS) {
2!
UNCOV
1360
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1361
  }
1362
  return code;
2✔
1363
}
1364

UNCOV
1365
static int32_t tDecodeStreamNotifyInfo(SDecoder* pDecoder, SNotifyInfo* info) {
×
UNCOV
1366
  int32_t code = TSDB_CODE_SUCCESS;
×
UNCOV
1367
  int32_t lino = 0;
×
1368

UNCOV
1369
  QUERY_CHECK_NULL(pDecoder, code, lino, _exit, TSDB_CODE_INVALID_PARA);
×
UNCOV
1370
  QUERY_CHECK_NULL(info, code, lino, _exit, TSDB_CODE_INVALID_PARA);
×
1371

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

UNCOV
1403
_exit:
×
UNCOV
1404
  if (code != TSDB_CODE_SUCCESS) {
×
UNCOV
1405
    stError("%s failed at line %d since %s", __func__, lino, tstrerror(code));
×
1406
  }
UNCOV
1407
  return code;
×
1408
}
1409

1410
int32_t tEncodeStreamTask(SEncoder* pEncoder, const SStreamTask* pTask) {
2✔
1411
  int32_t code = 0;
2✔
1412
  int32_t lino;
1413

1414
  TAOS_CHECK_EXIT(tStartEncode(pEncoder));
2!
1415
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->ver));
4!
1416
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->id.streamId));
4!
1417
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->id.taskId));
4!
1418
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.trigger));
4!
1419
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->info.taskLevel));
4!
1420
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->outputInfo.type));
4!
1421
  TAOS_CHECK_EXIT(tEncodeI16(pEncoder, pTask->msgInfo.msgType));
4!
1422

1423
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->status.taskStatus));
4!
1424
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->status.schedStatus));
4!
1425

1426
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.selfChildId));
4!
1427
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, pTask->info.nodeId));
4!
1428
  TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->info.epSet));
2!
1429
  TAOS_CHECK_EXIT(tEncodeSEpSet(pEncoder, &pTask->info.mnodeEpset));
2!
1430

1431
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->chkInfo.checkpointId));
4!
1432
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->chkInfo.checkpointVer));
4!
1433
  TAOS_CHECK_EXIT(tEncodeI8(pEncoder, pTask->info.fillHistory));
4!
1434

1435
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->hTaskInfo.id.streamId));
4!
1436
  int32_t taskId = pTask->hTaskInfo.id.taskId;
2✔
1437
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, taskId));
2!
1438

1439
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->streamTaskId.streamId));
4!
1440
  taskId = pTask->streamTaskId.taskId;
2✔
1441
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, taskId));
2!
1442

1443
  TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTask->dataRange.range.minVer));
4!
1444
  TAOS_CHECK_EXIT(tEncodeU64(pEncoder, pTask->dataRange.range.maxVer));
4!
1445
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->dataRange.window.skey));
4!
1446
  TAOS_CHECK_EXIT(tEncodeI64(pEncoder, pTask->dataRange.window.ekey));
4!
1447

1448
  int32_t epSz = taosArrayGetSize(pTask->upstreamInfo.pList);
2✔
1449
  TAOS_CHECK_EXIT(tEncodeI32(pEncoder, epSz));
2!
1450
  for (int32_t i = 0; i < epSz; i++) {
2!
UNCOV
1451
    SStreamUpstreamEpInfo* pInfo = taosArrayGetP(pTask->upstreamInfo.pList, i);
×
UNCOV
1452
    TAOS_CHECK_EXIT(tEncodeStreamEpInfo(pEncoder, pInfo));
×
1453
  }
1454

1455
  if (pTask->info.taskLevel != TASK_LEVEL__SINK) {
2!
1456
    TAOS_CHECK_EXIT(tEncodeCStr(pEncoder, pTask->exec.qmsg));
4!
1457
  }
1458

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

1479
  if (pTask->ver >= SSTREAM_TASK_ADD_NOTIFY_VER) {
2!
1480
    TAOS_CHECK_EXIT(tEncodeStreamNotifyInfo(pEncoder, &pTask->notifyInfo));
2!
1481
  }
1482

1483
  tEndEncode(pEncoder);
2✔
1484
_exit:
2✔
1485
  return code;
2✔
1486
}
1487

UNCOV
1488
int32_t tDecodeStreamTask(SDecoder* pDecoder, SStreamTask* pTask) {
×
UNCOV
1489
  int32_t taskId = 0;
×
UNCOV
1490
  int32_t code = 0;
×
1491
  int32_t lino;
1492

UNCOV
1493
  TAOS_CHECK_EXIT(tStartDecode(pDecoder));
×
UNCOV
1494
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->ver));
×
UNCOV
1495
  if (pTask->ver <= SSTREAM_TASK_INCOMPATIBLE_VER || pTask->ver > SSTREAM_TASK_VER) {
×
UNCOV
1496
    TAOS_CHECK_EXIT(TSDB_CODE_INVALID_MSG);
×
1497
  }
1498

UNCOV
1499
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->id.streamId));
×
UNCOV
1500
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->id.taskId));
×
UNCOV
1501
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.trigger));
×
UNCOV
1502
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->info.taskLevel));
×
UNCOV
1503
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->outputInfo.type));
×
UNCOV
1504
  TAOS_CHECK_EXIT(tDecodeI16(pDecoder, &pTask->msgInfo.msgType));
×
1505

UNCOV
1506
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->status.taskStatus));
×
UNCOV
1507
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->status.schedStatus));
×
1508

UNCOV
1509
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.selfChildId));
×
UNCOV
1510
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &pTask->info.nodeId));
×
UNCOV
1511
  TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->info.epSet));
×
UNCOV
1512
  TAOS_CHECK_EXIT(tDecodeSEpSet(pDecoder, &pTask->info.mnodeEpset));
×
1513

UNCOV
1514
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->chkInfo.checkpointId));
×
UNCOV
1515
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->chkInfo.checkpointVer));
×
UNCOV
1516
  TAOS_CHECK_EXIT(tDecodeI8(pDecoder, &pTask->info.fillHistory));
×
1517

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

UNCOV
1522
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->streamTaskId.streamId));
×
UNCOV
1523
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &taskId));
×
UNCOV
1524
  pTask->streamTaskId.taskId = taskId;
×
1525

UNCOV
1526
  TAOS_CHECK_EXIT(tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.minVer));
×
UNCOV
1527
  TAOS_CHECK_EXIT(tDecodeU64(pDecoder, (uint64_t*)&pTask->dataRange.range.maxVer));
×
UNCOV
1528
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->dataRange.window.skey));
×
UNCOV
1529
  TAOS_CHECK_EXIT(tDecodeI64(pDecoder, &pTask->dataRange.window.ekey));
×
1530

UNCOV
1531
  int32_t epSz = -1;
×
UNCOV
1532
  TAOS_CHECK_EXIT(tDecodeI32(pDecoder, &epSz) < 0);
×
1533

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

UNCOV
1551
  if (pTask->info.taskLevel != TASK_LEVEL__SINK) {
×
UNCOV
1552
    TAOS_CHECK_EXIT(tDecodeCStrAlloc(pDecoder, &pTask->exec.qmsg));
×
1553
  }
1554

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

UNCOV
1581
  if (pTask->ver >= SSTREAM_TASK_ADD_NOTIFY_VER) {
×
UNCOV
1582
    TAOS_CHECK_EXIT(tDecodeStreamNotifyInfo(pDecoder, &pTask->notifyInfo));
×
1583
  }
1584

UNCOV
1585
  tEndDecode(pDecoder);
×
1586

UNCOV
1587
_exit:
×
UNCOV
1588
  return code;
×
1589
}
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