• 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/streamCheckStatus.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 "cos.h"
17
#include "rsync.h"
18
#include "streamBackendRocksdb.h"
19
#include "streamInt.h"
20

21
#define CHECK_NOT_RSP_DURATION 60 * 1000  // 60 sec
22

23
static void    processDownstreamReadyRsp(SStreamTask* pTask);
24
static void    rspMonitorFn(void* param, void* tmrId);
25
static void    streamTaskInitTaskCheckInfo(STaskCheckInfo* pInfo, STaskOutputInfo* pOutputInfo, int64_t startTs);
26
static int32_t streamTaskStartCheckDownstream(STaskCheckInfo* pInfo, const char* id);
27
static void    streamTaskCompleteCheckRsp(STaskCheckInfo* pInfo, bool lock, const char* id);
28
static void    streamTaskAddReqInfo(STaskCheckInfo* pInfo, int64_t reqId, int32_t taskId, int32_t vgId, const char* id);
29
static int32_t doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p);
30
static void    handleTimeoutDownstreamTasks(SStreamTask* pTask, SArray* pTimeoutList);
31
static void    handleNotReadyDownstreamTask(SStreamTask* pTask, SArray* pNotReadyList);
32
static int32_t streamTaskUpdateCheckInfo(STaskCheckInfo* pInfo, int32_t taskId, int32_t status, int64_t rspTs,
33
                                         int64_t reqId, int32_t* pNotReady, const char* id);
34
static void setCheckDownstreamReqInfo(SStreamTaskCheckReq* pReq, int64_t reqId, int32_t dstTaskId, int32_t dstNodeId);
35
static void getCheckRspStatus(STaskCheckInfo* pInfo, int64_t el, int32_t* numOfReady, int32_t* numOfFault,
36
                              int32_t* numOfNotRsp, SArray* pTimeoutList, SArray* pNotReadyList, const char* id);
37
static int32_t addDownstreamFailedStatusResultAsync(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId);
38
static void    findCheckRspStatus(STaskCheckInfo* pInfo, int32_t taskId, SDownstreamStatusInfo** pStatusInfo);
39

UNCOV
40
int32_t streamTaskCheckStatus(SStreamTask* pTask, int32_t upstreamTaskId, int32_t vgId, int64_t stage,
×
41
                              int64_t* oldStage) {
UNCOV
42
  SStreamUpstreamEpInfo* pInfo = NULL;
×
UNCOV
43
  streamTaskGetUpstreamTaskEpInfo(pTask, upstreamTaskId, &pInfo);
×
UNCOV
44
  if (pInfo == NULL) {
×
45
    return TSDB_CODE_STREAM_TASK_NOT_EXIST;
×
46
  }
47

UNCOV
48
  *oldStage = pInfo->stage;
×
UNCOV
49
  const char* id = pTask->id.idStr;
×
UNCOV
50
  if (stage == -1) {
×
51
    stDebug("s-task:%s receive check msg from upstream task:0x%x(vgId:%d), invalid stageId:%" PRId64 ", not ready", id,
×
52
            upstreamTaskId, vgId, stage);
53
    return 0;
×
54
  }
55

UNCOV
56
  if (pInfo->stage == -1) {
×
UNCOV
57
    pInfo->stage = stage;
×
UNCOV
58
    stDebug("s-task:%s receive check msg from upstream task:0x%x(vgId:%d) first time, init stage value:%" PRId64, id,
×
59
            upstreamTaskId, vgId, stage);
60
  }
61

UNCOV
62
  if (pInfo->stage < stage) {
×
UNCOV
63
    stError("s-task:%s receive check msg from upstream task:0x%x(vgId:%d), new stage received:%" PRId64
×
64
            ", prev:%" PRId64,
65
            id, upstreamTaskId, vgId, stage, pInfo->stage);
66
    // record the checkpoint failure id and sent to mnode
UNCOV
67
    streamTaskSetCheckpointFailed(pTask);
×
68
  }
69

UNCOV
70
  if (pInfo->stage != stage) {
×
UNCOV
71
    return TASK_UPSTREAM_NEW_STAGE;
×
UNCOV
72
  } else if (pTask->status.downstreamReady != 1) {
×
UNCOV
73
    stDebug("s-task:%s vgId:%d leader:%d, downstream not ready", id, vgId, (pTask->pMeta->role == NODE_ROLE_LEADER));
×
UNCOV
74
    return TASK_DOWNSTREAM_NOT_READY;
×
75
  } else {
UNCOV
76
    return TASK_DOWNSTREAM_READY;
×
77
  }
78
}
79

80
// check status
UNCOV
81
void streamTaskSendCheckMsg(SStreamTask* pTask) {
×
UNCOV
82
  SDataRange*  pRange = &pTask->dataRange;
×
UNCOV
83
  STimeWindow* pWindow = &pRange->window;
×
UNCOV
84
  const char*  idstr = pTask->id.idStr;
×
UNCOV
85
  int32_t      code = 0;
×
86

UNCOV
87
  SStreamTaskCheckReq req = {
×
UNCOV
88
      .streamId = pTask->id.streamId,
×
UNCOV
89
      .upstreamTaskId = pTask->id.taskId,
×
UNCOV
90
      .upstreamNodeId = pTask->info.nodeId,
×
UNCOV
91
      .childId = pTask->info.selfChildId,
×
UNCOV
92
      .stage = pTask->pMeta->stage,
×
93
  };
94

95
  // serialize streamProcessScanHistoryFinishRsp
UNCOV
96
  if (pTask->outputInfo.type == TASK_OUTPUT__FIXED_DISPATCH) {
×
UNCOV
97
    streamTaskStartMonitorCheckRsp(pTask);
×
98

UNCOV
99
    STaskDispatcherFixed* pDispatch = &pTask->outputInfo.fixedDispatcher;
×
100

UNCOV
101
    setCheckDownstreamReqInfo(&req, tGenIdPI64(), pDispatch->taskId, pDispatch->nodeId);
×
UNCOV
102
    streamTaskAddReqInfo(&pTask->taskCheckInfo, req.reqId, pDispatch->taskId, pDispatch->nodeId, idstr);
×
103

UNCOV
104
    stDebug("s-task:%s (vgId:%d) stage:%" PRId64 " check single downstream task:0x%x(vgId:%d) ver:%" PRId64 "-%" PRId64
×
105
            " window:%" PRId64 "-%" PRId64 " QID:0x%" PRIx64,
106
            idstr, pTask->info.nodeId, req.stage, req.downstreamTaskId, req.downstreamNodeId, pRange->range.minVer,
107
            pRange->range.maxVer, pWindow->skey, pWindow->ekey, req.reqId);
108

UNCOV
109
    code = streamSendCheckMsg(pTask, &req, pTask->outputInfo.fixedDispatcher.nodeId,
×
110
                              &pTask->outputInfo.fixedDispatcher.epSet);
111

UNCOV
112
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
UNCOV
113
    streamTaskStartMonitorCheckRsp(pTask);
×
114

UNCOV
115
    SArray* vgInfo = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
×
116

UNCOV
117
    int32_t numOfVgs = taosArrayGetSize(vgInfo);
×
UNCOV
118
    stDebug("s-task:%s check %d downstream tasks, ver:%" PRId64 "-%" PRId64 " window:%" PRId64 "-%" PRId64, idstr,
×
119
            numOfVgs, pRange->range.minVer, pRange->range.maxVer, pWindow->skey, pWindow->ekey);
120

UNCOV
121
    for (int32_t i = 0; i < numOfVgs; i++) {
×
UNCOV
122
      SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i);
×
UNCOV
123
      if (pVgInfo == NULL) {
×
124
        continue;
×
125
      }
126

UNCOV
127
      setCheckDownstreamReqInfo(&req, tGenIdPI64(), pVgInfo->taskId, pVgInfo->vgId);
×
UNCOV
128
      streamTaskAddReqInfo(&pTask->taskCheckInfo, req.reqId, pVgInfo->taskId, pVgInfo->vgId, idstr);
×
129

UNCOV
130
      stDebug("s-task:%s (vgId:%d) stage:%" PRId64
×
131
              " check downstream task:0x%x (vgId:%d) (shuffle), idx:%d, QID:0x%" PRIx64,
132
              idstr, pTask->info.nodeId, req.stage, req.downstreamTaskId, req.downstreamNodeId, i, req.reqId);
UNCOV
133
      code = streamSendCheckMsg(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet);
×
134
    }
135
  } else {  // for sink task, set it ready directly.
UNCOV
136
    stDebug("s-task:%s (vgId:%d) set downstream ready, since no downstream", idstr, pTask->info.nodeId);
×
UNCOV
137
    streamTaskStopMonitorCheckRsp(&pTask->taskCheckInfo, idstr);
×
UNCOV
138
    processDownstreamReadyRsp(pTask);
×
139
  }
140

UNCOV
141
  if (code) {
×
142
    stError("s-task:%s failed to send check msg to downstream, code:%s", idstr, tstrerror(code));
×
143
  }
UNCOV
144
}
×
145

UNCOV
146
void streamTaskProcessCheckMsg(SStreamMeta* pMeta, SStreamTaskCheckReq* pReq, SStreamTaskCheckRsp* pRsp) {
×
UNCOV
147
  int32_t taskId = pReq->downstreamTaskId;
×
148

UNCOV
149
  *pRsp = (SStreamTaskCheckRsp){
×
UNCOV
150
      .reqId = pReq->reqId,
×
UNCOV
151
      .streamId = pReq->streamId,
×
UNCOV
152
      .childId = pReq->childId,
×
UNCOV
153
      .downstreamNodeId = pReq->downstreamNodeId,
×
UNCOV
154
      .downstreamTaskId = pReq->downstreamTaskId,
×
UNCOV
155
      .upstreamNodeId = pReq->upstreamNodeId,
×
UNCOV
156
      .upstreamTaskId = pReq->upstreamTaskId,
×
157
  };
158

159
  // only the leader node handle the check request
UNCOV
160
  if (pMeta->role == NODE_ROLE_FOLLOWER) {
×
UNCOV
161
    stError(
×
162
        "s-task:0x%x invalid check msg from upstream:0x%x(vgId:%d), vgId:%d is follower, not handle check status msg",
163
        taskId, pReq->upstreamTaskId, pReq->upstreamNodeId, pMeta->vgId);
UNCOV
164
    pRsp->status = TASK_DOWNSTREAM_NOT_LEADER;
×
165
  } else {
UNCOV
166
    SStreamTask* pTask = NULL;
×
UNCOV
167
    int32_t      code = streamMetaAcquireTask(pMeta, pReq->streamId, taskId, &pTask);
×
UNCOV
168
    if (pTask != NULL) {
×
UNCOV
169
      pRsp->status =
×
UNCOV
170
          streamTaskCheckStatus(pTask, pReq->upstreamTaskId, pReq->upstreamNodeId, pReq->stage, &pRsp->oldStage);
×
171

UNCOV
172
      SStreamTaskState pState = streamTaskGetStatus(pTask);
×
UNCOV
173
      stDebug("s-task:%s status:%s, stage:%" PRId64 " recv task check req(QID:0x%" PRIx64
×
174
              ") task:0x%x (vgId:%d), check_status:%d",
175
              pTask->id.idStr, pState.name, pRsp->oldStage, pRsp->reqId, pRsp->upstreamTaskId, pRsp->upstreamNodeId,
176
              pRsp->status);
UNCOV
177
      streamMetaReleaseTask(pMeta, pTask);
×
178
    } else {
UNCOV
179
      pRsp->status = TASK_DOWNSTREAM_NOT_READY;
×
UNCOV
180
      stDebug("tq recv task check(taskId:0x%" PRIx64 "-0x%x not built yet) req(QID:0x%" PRIx64
×
181
              ") from task:0x%x (vgId:%d), rsp check_status %d",
182
              pReq->streamId, taskId, pRsp->reqId, pRsp->upstreamTaskId, pRsp->upstreamNodeId, pRsp->status);
183
    }
184
  }
UNCOV
185
}
×
186

UNCOV
187
int32_t streamTaskProcessCheckRsp(SStreamTask* pTask, const SStreamTaskCheckRsp* pRsp) {
×
UNCOV
188
  int64_t         now = taosGetTimestampMs();
×
UNCOV
189
  const char*     id = pTask->id.idStr;
×
UNCOV
190
  STaskCheckInfo* pInfo = &pTask->taskCheckInfo;
×
UNCOV
191
  int32_t         total = streamTaskGetNumOfDownstream(pTask);
×
UNCOV
192
  int32_t         left = -1;
×
193

UNCOV
194
  if (streamTaskShouldStop(pTask)) {
×
195
    stDebug("s-task:%s should stop, do not do check downstream again", id);
×
196
    return TSDB_CODE_SUCCESS;
×
197
  }
198

UNCOV
199
  if (pTask->id.taskId != pRsp->upstreamTaskId) {
×
200
    stError("s-task:%s invalid check downstream rsp, upstream task:0x%x discard", id, pRsp->upstreamTaskId);
×
201
    return TSDB_CODE_INVALID_MSG;
×
202
  }
203

UNCOV
204
  if (pRsp->status == TASK_DOWNSTREAM_READY) {
×
UNCOV
205
    int32_t code = streamTaskUpdateCheckInfo(pInfo, pRsp->downstreamTaskId, pRsp->status, now, pRsp->reqId, &left, id);
×
UNCOV
206
    if (code != TSDB_CODE_SUCCESS) {
×
207
      return TSDB_CODE_SUCCESS;
×
208
    }
209

UNCOV
210
    if (left == 0) {
×
UNCOV
211
      processDownstreamReadyRsp(pTask);  // all downstream tasks are ready, set the complete check downstream flag
×
UNCOV
212
      streamTaskStopMonitorCheckRsp(pInfo, id);
×
213
    } else {
UNCOV
214
      stDebug("s-task:%s (vgId:%d) recv check rsp from task:0x%x (vgId:%d) status:%d, total:%d not ready:%d", id,
×
215
              pRsp->upstreamNodeId, pRsp->downstreamTaskId, pRsp->downstreamNodeId, pRsp->status, total, left);
216
    }
217
  } else {  // not ready, wait for 100ms and retry
UNCOV
218
    int32_t code = streamTaskUpdateCheckInfo(pInfo, pRsp->downstreamTaskId, pRsp->status, now, pRsp->reqId, &left, id);
×
UNCOV
219
    if (code != TSDB_CODE_SUCCESS) {
×
UNCOV
220
      return TSDB_CODE_SUCCESS;  // return success in any cases.
×
221
    }
222

UNCOV
223
    if (pRsp->status == TASK_UPSTREAM_NEW_STAGE || pRsp->status == TASK_DOWNSTREAM_NOT_LEADER) {
×
UNCOV
224
      if (pRsp->status == TASK_UPSTREAM_NEW_STAGE) {
×
UNCOV
225
        stError("s-task:%s vgId:%d self vnode-transfer/leader-change/restart detected, old stage:%" PRId64
×
226
                ", current stage:%" PRId64 ", not check wait for downstream task nodeUpdate, and all tasks restart",
227
                id, pRsp->upstreamNodeId, pRsp->oldStage, pTask->pMeta->stage);
UNCOV
228
        code = streamTaskAddIntoNodeUpdateList(pTask, pRsp->upstreamNodeId);
×
229
      } else {
UNCOV
230
        stError(
×
231
            "s-task:%s downstream taskId:0x%x (vgId:%d) not leader, self dispatch epset needs to be updated, not check "
232
            "downstream again, nodeUpdate needed",
233
            id, pRsp->downstreamTaskId, pRsp->downstreamNodeId);
UNCOV
234
        code = streamTaskAddIntoNodeUpdateList(pTask, pRsp->downstreamNodeId);
×
235
      }
236

UNCOV
237
      streamMetaAddFailedTaskSelf(pTask, now);
×
238
    } else {  // TASK_DOWNSTREAM_NOT_READY, rsp-check monitor will retry in 300 ms
UNCOV
239
      stDebug("s-task:%s (vgId:%d) recv check rsp from task:0x%x (vgId:%d) status:%d, total:%d not ready:%d", id,
×
240
              pRsp->upstreamNodeId, pRsp->downstreamTaskId, pRsp->downstreamNodeId, pRsp->status, total, left);
241
    }
242
  }
243

UNCOV
244
  return 0;
×
245
}
246

UNCOV
247
int32_t streamTaskSendCheckRsp(const SStreamMeta* pMeta, int32_t vgId, SStreamTaskCheckRsp* pRsp,
×
248
                               SRpcHandleInfo* pRpcInfo, int32_t taskId) {
249
  SEncoder encoder;
UNCOV
250
  int32_t  code = 0;
×
251
  int32_t  len;
252

UNCOV
253
  tEncodeSize(tEncodeStreamTaskCheckRsp, pRsp, len, code);
×
UNCOV
254
  if (code < 0) {
×
255
    stError("vgId:%d failed to encode task check rsp, s-task:0x%x", pMeta->vgId, taskId);
×
256
    return TSDB_CODE_INVALID_MSG;
×
257
  }
258

UNCOV
259
  void* buf = rpcMallocCont(sizeof(SMsgHead) + len);
×
UNCOV
260
  if (buf == NULL) {
×
261
    stError("s-task:0x%x vgId:%d failed prepare msg, %s at line:%d code:%s", taskId, pMeta->vgId, __func__, __LINE__,
×
262
            tstrerror(code));
263
    return terrno;
×
264
  }
265

UNCOV
266
  ((SMsgHead*)buf)->vgId = htonl(vgId);
×
267

UNCOV
268
  void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
×
UNCOV
269
  tEncoderInit(&encoder, (uint8_t*)abuf, len);
×
UNCOV
270
  code = tEncodeStreamTaskCheckRsp(&encoder, pRsp);
×
UNCOV
271
  tEncoderClear(&encoder);
×
272

UNCOV
273
  SRpcMsg rspMsg = {.code = 0, .pCont = buf, .contLen = sizeof(SMsgHead) + len, .info = *pRpcInfo};
×
UNCOV
274
  tmsgSendRsp(&rspMsg);
×
275

UNCOV
276
  code = TMIN(code, 0);
×
UNCOV
277
  return code;
×
278
}
279

UNCOV
280
void streamTaskStartMonitorCheckRsp(SStreamTask* pTask) {
×
UNCOV
281
  int32_t         vgId = pTask->pMeta->vgId;
×
UNCOV
282
  STaskCheckInfo* pInfo = &pTask->taskCheckInfo;
×
283

UNCOV
284
  streamMutexLock(&pInfo->checkInfoLock);
×
285

286
  // drop procedure already started, not start check downstream now
UNCOV
287
  ETaskStatus s = streamTaskGetStatus(pTask).state;
×
UNCOV
288
  if (s == TASK_STATUS__DROPPING) {
×
289
    stDebug("s-task:%s task not in uninit status, status:%s not start monitor check-rsp", pTask->id.idStr,
×
290
            streamTaskGetStatusStr(s));
291
    streamMutexUnlock(&pInfo->checkInfoLock);
×
292
    return;
×
293
  }
294

UNCOV
295
  int32_t code = streamTaskStartCheckDownstream(pInfo, pTask->id.idStr);
×
UNCOV
296
  if (code != TSDB_CODE_SUCCESS) {
×
297
    streamMutexUnlock(&pInfo->checkInfoLock);
×
298
    return;
×
299
  }
300

UNCOV
301
  streamTaskInitTaskCheckInfo(pInfo, &pTask->outputInfo, taosGetTimestampMs());
×
302

UNCOV
303
  int64_t* pTaskRefId = NULL;
×
UNCOV
304
  code = streamTaskAllocRefId(pTask, &pTaskRefId);
×
UNCOV
305
  if (code == 0) {
×
UNCOV
306
    streamTmrStart(rspMonitorFn, CHECK_RSP_CHECK_INTERVAL, pTaskRefId, streamTimer, &pInfo->checkRspTmr, vgId,
×
307
                   "check-status-monitor");
308
  }
309

UNCOV
310
  streamMutexUnlock(&pInfo->checkInfoLock);
×
311
}
312

UNCOV
313
void streamTaskStopMonitorCheckRsp(STaskCheckInfo* pInfo, const char* id) {
×
UNCOV
314
  streamMutexLock(&pInfo->checkInfoLock);
×
UNCOV
315
  pInfo->stopCheckProcess = 1;
×
UNCOV
316
  streamMutexUnlock(&pInfo->checkInfoLock);
×
317

UNCOV
318
  stDebug("s-task:%s set stop check-rsp monitor flag", id);
×
UNCOV
319
}
×
320

UNCOV
321
void streamTaskCleanupCheckInfo(STaskCheckInfo* pInfo) {
×
UNCOV
322
  taosArrayDestroy(pInfo->pList);
×
UNCOV
323
  pInfo->pList = NULL;
×
324

UNCOV
325
  if (pInfo->checkRspTmr != NULL) {
×
UNCOV
326
    streamTmrStop(pInfo->checkRspTmr);
×
UNCOV
327
    pInfo->checkRspTmr = NULL;
×
328
  }
329

UNCOV
330
  streamMutexDestroy(&pInfo->checkInfoLock);
×
UNCOV
331
}
×
332

333
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
UNCOV
334
void processDownstreamReadyRsp(SStreamTask* pTask) {
×
UNCOV
335
  EStreamTaskEvent event = (pTask->info.fillHistory == 0) ? TASK_EVENT_INIT : TASK_EVENT_INIT_SCANHIST;
×
UNCOV
336
  int32_t          code = streamTaskOnHandleEventSuccess(pTask->status.pSM, event, NULL, NULL);
×
UNCOV
337
  if (code) {
×
338
    stError("s-task:%s failed to set event succ, code:%s", pTask->id.idStr, tstrerror(code));
×
339
  }
340

UNCOV
341
  int64_t checkTs = pTask->execInfo.checkTs;
×
UNCOV
342
  int64_t readyTs = pTask->execInfo.readyTs;
×
UNCOV
343
  code = streamMetaAddTaskLaunchResult(pTask->pMeta, pTask->id.streamId, pTask->id.taskId, checkTs, readyTs, true);
×
UNCOV
344
  if (code) {
×
UNCOV
345
    stError("s-task:%s failed to record the downstream task status, code:%s", pTask->id.idStr, tstrerror(code));
×
346
  }
347

UNCOV
348
  if (pTask->status.taskStatus == TASK_STATUS__HALT) {
×
UNCOV
349
    if (!HAS_RELATED_FILLHISTORY_TASK(pTask) || (pTask->info.fillHistory != 0)) {
×
350
      stError("s-task:%s status:halt fillhistory:%d not handle the ready rsp", pTask->id.idStr,
×
351
              pTask->info.fillHistory);
352
    }
353

354
    // halt it self for count window stream task until the related fill history task completed.
UNCOV
355
    stDebug("s-task:%s level:%d initial status is %s from mnode, set it to be halt", pTask->id.idStr,
×
356
            pTask->info.taskLevel, streamTaskGetStatusStr(pTask->status.taskStatus));
UNCOV
357
    code = streamTaskHandleEvent(pTask->status.pSM, TASK_EVENT_HALT);
×
UNCOV
358
    if (code != 0) {  // todo: handle error
×
359
      stError("s-task:%s failed to handle halt event, code:%s", pTask->id.idStr, tstrerror(code));
×
360
    }
361
  }
362

363
  // start the related fill-history task, when current task is ready
364
  // not invoke in success callback due to the deadlock.
365
  // todo: let's retry
UNCOV
366
  if (HAS_RELATED_FILLHISTORY_TASK(pTask)) {
×
UNCOV
367
    stDebug("s-task:%s try to launch related fill-history task", pTask->id.idStr);
×
UNCOV
368
    code = streamLaunchFillHistoryTask(pTask);
×
UNCOV
369
    if (code) {
×
370
      stError("s-task:%s failed to launch history task, code:%s", pTask->id.idStr, tstrerror(code));
×
371
    }
372
  }
UNCOV
373
}
×
374

UNCOV
375
int32_t streamTaskAddIntoNodeUpdateList(SStreamTask* pTask, int32_t nodeId) {
×
UNCOV
376
  int32_t vgId = pTask->pMeta->vgId;
×
UNCOV
377
  int32_t code = 0;
×
UNCOV
378
  bool    existed = false;
×
379

UNCOV
380
  streamMutexLock(&pTask->lock);
×
381

UNCOV
382
  int32_t num = taosArrayGetSize(pTask->outputInfo.pNodeEpsetUpdateList);
×
UNCOV
383
  for (int i = 0; i < num; ++i) {
×
UNCOV
384
    SDownstreamTaskEpset* p = taosArrayGet(pTask->outputInfo.pNodeEpsetUpdateList, i);
×
UNCOV
385
    if (p == NULL) {
×
386
      continue;
×
387
    }
388

UNCOV
389
    if (p->nodeId == nodeId) {
×
UNCOV
390
      existed = true;
×
UNCOV
391
      break;
×
392
    }
393
  }
394

UNCOV
395
  if (!existed) {
×
UNCOV
396
    SDownstreamTaskEpset t = {.nodeId = nodeId};
×
397

UNCOV
398
    void* p = taosArrayPush(pTask->outputInfo.pNodeEpsetUpdateList, &t);
×
UNCOV
399
    if (p == NULL) {
×
400
      code = terrno;
×
401
      stError("s-task:%s vgId:%d failed to update epset, code:%s", pTask->id.idStr, vgId, tstrerror(code));
×
402
    } else {
UNCOV
403
      stInfo("s-task:%s vgId:%d downstream nodeId:%d needs to be updated, total needs updated:%d", pTask->id.idStr,
×
404
             vgId, t.nodeId, (num + 1));
405
    }
406
  }
407

UNCOV
408
  streamMutexUnlock(&pTask->lock);
×
UNCOV
409
  return code;
×
410
}
411

UNCOV
412
void streamTaskInitTaskCheckInfo(STaskCheckInfo* pInfo, STaskOutputInfo* pOutputInfo, int64_t startTs) {
×
UNCOV
413
  taosArrayClear(pInfo->pList);
×
414

UNCOV
415
  if (pOutputInfo->type == TASK_OUTPUT__FIXED_DISPATCH) {
×
UNCOV
416
    pInfo->notReadyTasks = 1;
×
UNCOV
417
  } else if (pOutputInfo->type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
UNCOV
418
    pInfo->notReadyTasks = taosArrayGetSize(pOutputInfo->shuffleDispatcher.dbInfo.pVgroupInfos);
×
419
  }
420

UNCOV
421
  pInfo->startTs = startTs;
×
UNCOV
422
  pInfo->timeoutStartTs = startTs;
×
UNCOV
423
  pInfo->stopCheckProcess = 0;
×
UNCOV
424
}
×
425

UNCOV
426
void findCheckRspStatus(STaskCheckInfo* pInfo, int32_t taskId, SDownstreamStatusInfo** pStatusInfo) {
×
UNCOV
427
  if (pStatusInfo == NULL) {
×
428
    return;
×
429
  }
430

UNCOV
431
  *pStatusInfo = NULL;
×
UNCOV
432
  for (int32_t j = 0; j < taosArrayGetSize(pInfo->pList); ++j) {
×
UNCOV
433
    SDownstreamStatusInfo* p = taosArrayGet(pInfo->pList, j);
×
UNCOV
434
    if (p == NULL) {
×
435
      continue;
×
436
    }
437

UNCOV
438
    if (p->taskId == taskId) {
×
UNCOV
439
      *pStatusInfo = p;
×
440
    }
441
  }
442
}
443

UNCOV
444
int32_t streamTaskUpdateCheckInfo(STaskCheckInfo* pInfo, int32_t taskId, int32_t status, int64_t rspTs, int64_t reqId,
×
445
                                  int32_t* pNotReady, const char* id) {
UNCOV
446
  SDownstreamStatusInfo* p = NULL;
×
447

UNCOV
448
  streamMutexLock(&pInfo->checkInfoLock);
×
UNCOV
449
  findCheckRspStatus(pInfo, taskId, &p);
×
UNCOV
450
  if (p != NULL) {
×
UNCOV
451
    if (reqId != p->reqId) {
×
452
      stError("s-task:%sQID:0x%" PRIx64 " expected:0x%" PRIx64
×
453
              " expired check-rsp recv from downstream task:0x%x, discarded",
454
              id, reqId, p->reqId, taskId);
455
      streamMutexUnlock(&pInfo->checkInfoLock);
×
456
      return TSDB_CODE_FAILED;
×
457
    }
458

459
    // subtract one not-ready-task, since it is ready now
UNCOV
460
    if ((p->status != TASK_DOWNSTREAM_READY) && (status == TASK_DOWNSTREAM_READY)) {
×
UNCOV
461
      *pNotReady = atomic_sub_fetch_32(&pInfo->notReadyTasks, 1);
×
462
    } else {
UNCOV
463
      *pNotReady = pInfo->notReadyTasks;
×
464
    }
465

UNCOV
466
    p->status = status;
×
UNCOV
467
    p->rspTs = rspTs;
×
468

UNCOV
469
    streamMutexUnlock(&pInfo->checkInfoLock);
×
UNCOV
470
    return TSDB_CODE_SUCCESS;
×
471
  }
472

UNCOV
473
  streamMutexUnlock(&pInfo->checkInfoLock);
×
UNCOV
474
  stError("s-task:%s unexpected check rsp msg, invalid downstream task:0x%x,QID:%" PRIx64 " discarded", id, taskId,
×
475
          reqId);
UNCOV
476
  return TSDB_CODE_FAILED;
×
477
}
478

UNCOV
479
int32_t streamTaskStartCheckDownstream(STaskCheckInfo* pInfo, const char* id) {
×
UNCOV
480
  if (pInfo->inCheckProcess == 0) {
×
UNCOV
481
    pInfo->inCheckProcess = 1;
×
482
  } else {
483
    stError("s-task:%s already in check procedure, checkTs:%" PRId64 ", start monitor check rsp failed", id,
×
484
            pInfo->startTs);
485
    pInfo->stopCheckProcess = 0;  // disable auto stop of check process
×
486
    return TSDB_CODE_FAILED;
×
487
  }
488

UNCOV
489
  stDebug("s-task:%s set the in check-rsp flag", id);
×
UNCOV
490
  return TSDB_CODE_SUCCESS;
×
491
}
492

UNCOV
493
void streamTaskCompleteCheckRsp(STaskCheckInfo* pInfo, bool lock, const char* id) {
×
UNCOV
494
  if (lock) {
×
UNCOV
495
    streamMutexLock(&pInfo->checkInfoLock);
×
496
  }
497

UNCOV
498
  if (pInfo->inCheckProcess) {
×
UNCOV
499
    int64_t el = (pInfo->startTs != 0) ? (taosGetTimestampMs() - pInfo->startTs) : 0;
×
UNCOV
500
    stDebug("s-task:%s clear the in check-rsp flag, set the check-rsp done, elapsed time:%" PRId64 " ms", id, el);
×
501

UNCOV
502
    pInfo->startTs = 0;
×
UNCOV
503
    pInfo->timeoutStartTs = 0;
×
UNCOV
504
    pInfo->notReadyTasks = 0;
×
UNCOV
505
    pInfo->inCheckProcess = 0;
×
UNCOV
506
    pInfo->stopCheckProcess = 0;
×
507

UNCOV
508
    pInfo->notReadyRetryCount = 0;
×
UNCOV
509
    pInfo->timeoutRetryCount = 0;
×
510

UNCOV
511
    taosArrayClear(pInfo->pList);
×
512
  } else {
513
    stDebug("s-task:%s already not in check-rsp procedure", id);
×
514
  }
515

UNCOV
516
  if (lock) {
×
UNCOV
517
    streamMutexUnlock(&pInfo->checkInfoLock);
×
518
  }
UNCOV
519
}
×
520

521
// todo: retry until success
UNCOV
522
void streamTaskAddReqInfo(STaskCheckInfo* pInfo, int64_t reqId, int32_t taskId, int32_t vgId, const char* id) {
×
UNCOV
523
  SDownstreamStatusInfo info = {.taskId = taskId, .status = -1, .vgId = vgId, .reqId = reqId, .rspTs = 0};
×
UNCOV
524
  streamMutexLock(&pInfo->checkInfoLock);
×
525

UNCOV
526
  SDownstreamStatusInfo* p = NULL;
×
UNCOV
527
  findCheckRspStatus(pInfo, taskId, &p);
×
UNCOV
528
  if (p != NULL) {
×
529
    stDebug("s-task:%s check info to task:0x%x already sent", id, taskId);
×
530
    streamMutexUnlock(&pInfo->checkInfoLock);
×
531
    return;
×
532
  }
533

UNCOV
534
  void* px = taosArrayPush(pInfo->pList, &info);
×
535
  if (px == NULL) {
536
    // todo: retry
537
  }
538

UNCOV
539
  streamMutexUnlock(&pInfo->checkInfoLock);
×
540
}
541

UNCOV
542
int32_t doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p) {
×
UNCOV
543
  const char* id = pTask->id.idStr;
×
UNCOV
544
  int32_t     code = 0;
×
545

UNCOV
546
  SStreamTaskCheckReq req = {
×
UNCOV
547
      .streamId = pTask->id.streamId,
×
UNCOV
548
      .upstreamTaskId = pTask->id.taskId,
×
UNCOV
549
      .upstreamNodeId = pTask->info.nodeId,
×
UNCOV
550
      .childId = pTask->info.selfChildId,
×
UNCOV
551
      .stage = pTask->pMeta->stage,
×
552
  };
553

554
  // update the reqId for the new check msg
UNCOV
555
  p->reqId = tGenIdPI64();
×
556

UNCOV
557
  STaskOutputInfo* pOutputInfo = &pTask->outputInfo;
×
UNCOV
558
  if (pOutputInfo->type == TASK_OUTPUT__FIXED_DISPATCH) {
×
UNCOV
559
    STaskDispatcherFixed* pDispatch = &pOutputInfo->fixedDispatcher;
×
UNCOV
560
    setCheckDownstreamReqInfo(&req, p->reqId, pDispatch->taskId, pDispatch->nodeId);
×
561

UNCOV
562
    stDebug("s-task:%s (vgId:%d) stage:%" PRId64 " re-send check downstream task:0x%x(vgId:%d) QID:0x%" PRIx64, id,
×
563
            pTask->info.nodeId, req.stage, req.downstreamTaskId, req.downstreamNodeId, req.reqId);
564

UNCOV
565
    code = streamSendCheckMsg(pTask, &req, pOutputInfo->fixedDispatcher.nodeId, &pOutputInfo->fixedDispatcher.epSet);
×
UNCOV
566
  } else if (pOutputInfo->type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
×
UNCOV
567
    SArray* vgInfo = pOutputInfo->shuffleDispatcher.dbInfo.pVgroupInfos;
×
UNCOV
568
    int32_t numOfVgs = taosArrayGetSize(vgInfo);
×
569

UNCOV
570
    for (int32_t i = 0; i < numOfVgs; i++) {
×
UNCOV
571
      SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i);
×
UNCOV
572
      if (pVgInfo == NULL) {
×
573
        continue;
×
574
      }
575

UNCOV
576
      if (p->taskId == pVgInfo->taskId) {
×
UNCOV
577
        setCheckDownstreamReqInfo(&req, p->reqId, pVgInfo->taskId, pVgInfo->vgId);
×
578

UNCOV
579
        stDebug("s-task:%s (vgId:%d) stage:%" PRId64
×
580
                " re-send check downstream task:0x%x(vgId:%d) (shuffle), idx:%d QID:0x%" PRIx64,
581
                id, pTask->info.nodeId, req.stage, req.downstreamTaskId, req.downstreamNodeId, i, p->reqId);
UNCOV
582
        code = streamSendCheckMsg(pTask, &req, pVgInfo->vgId, &pVgInfo->epSet);
×
UNCOV
583
        break;
×
584
      }
585
    }
586
  }
587

UNCOV
588
  if (code) {
×
589
    stError("s-task:%s failed to send check msg to downstream, code:%s", pTask->id.idStr, tstrerror(code));
×
590
  }
UNCOV
591
  return code;
×
592
}
593

UNCOV
594
void getCheckRspStatus(STaskCheckInfo* pInfo, int64_t el, int32_t* numOfReady, int32_t* numOfFault,
×
595
                       int32_t* numOfNotRsp, SArray* pTimeoutList, SArray* pNotReadyList, const char* id) {
UNCOV
596
  for (int32_t i = 0; i < taosArrayGetSize(pInfo->pList); ++i) {
×
UNCOV
597
    SDownstreamStatusInfo* p = taosArrayGet(pInfo->pList, i);
×
UNCOV
598
    if (p == NULL) {
×
599
      continue;
×
600
    }
601

UNCOV
602
    if (p->status == TASK_DOWNSTREAM_READY) {
×
UNCOV
603
      (*numOfReady) += 1;
×
UNCOV
604
    } else if (p->status == TASK_UPSTREAM_NEW_STAGE || p->status == TASK_DOWNSTREAM_NOT_LEADER) {
×
UNCOV
605
      stDebug("s-task:%s recv status:NEW_STAGE/NOT_LEADER from downstream, task:0x%x, quit from check downstream", id,
×
606
              p->taskId);
UNCOV
607
      (*numOfFault) += 1;
×
608
    } else {                                 // TASK_DOWNSTREAM_NOT_READY
UNCOV
609
      if (p->rspTs == 0) {                   // not response yet
×
UNCOV
610
        if (el >= CHECK_NOT_RSP_DURATION) {  // not receive info for 10 sec.
×
UNCOV
611
          void* px = taosArrayPush(pTimeoutList, &p->taskId);
×
UNCOV
612
          if (px == NULL) {
×
613
            stError("s-task:%s failed to record time out task:0x%x", id, p->taskId);
×
614
          }
615
        } else {                // el < CHECK_NOT_RSP_DURATION
UNCOV
616
          (*numOfNotRsp) += 1;  // do nothing and continue waiting for their rsp
×
617
        }
618
      } else {
UNCOV
619
        void* px = taosArrayPush(pNotReadyList, &p->taskId);
×
UNCOV
620
        if (px == NULL) {
×
621
          stError("s-task:%s failed to record not ready task:0x%x", id, p->taskId);
×
622
        }
623
      }
624
    }
625
  }
UNCOV
626
}
×
627

UNCOV
628
void setCheckDownstreamReqInfo(SStreamTaskCheckReq* pReq, int64_t reqId, int32_t dstTaskId, int32_t dstNodeId) {
×
UNCOV
629
  pReq->reqId = reqId;
×
UNCOV
630
  pReq->downstreamTaskId = dstTaskId;
×
UNCOV
631
  pReq->downstreamNodeId = dstNodeId;
×
UNCOV
632
}
×
633

UNCOV
634
void handleTimeoutDownstreamTasks(SStreamTask* pTask, SArray* pTimeoutList) {
×
UNCOV
635
  STaskCheckInfo* pInfo = &pTask->taskCheckInfo;
×
UNCOV
636
  const char*     id = pTask->id.idStr;
×
UNCOV
637
  int32_t         vgId = pTask->pMeta->vgId;
×
UNCOV
638
  int32_t         numOfTimeout = taosArrayGetSize(pTimeoutList);
×
UNCOV
639
  int32_t         code = 0;
×
640

UNCOV
641
  pInfo->timeoutStartTs = taosGetTimestampMs();
×
UNCOV
642
  for (int32_t i = 0; i < numOfTimeout; ++i) {
×
UNCOV
643
    int32_t* px = taosArrayGet(pTimeoutList, i);
×
UNCOV
644
    if (px == NULL) {
×
645
      continue;
×
646
    }
647

UNCOV
648
    int32_t                taskId = *px;
×
UNCOV
649
    SDownstreamStatusInfo* p = NULL;
×
UNCOV
650
    findCheckRspStatus(pInfo, taskId, &p);
×
651

UNCOV
652
    if (p != NULL) {
×
UNCOV
653
      if (p->status != -1 || p->rspTs != 0) {
×
654
        stError("s-task:%s invalid rsp record entry, index:%d, status:%d, rspTs:%" PRId64, id, i, p->status, p->rspTs);
×
655
        continue;
×
656
      }
UNCOV
657
      code = doSendCheckMsg(pTask, p);
×
658
    }
659
  }
660

UNCOV
661
  pInfo->timeoutRetryCount += 1;
×
662

663
  // timeout more than 600 sec, add into node update list
UNCOV
664
  if (pInfo->timeoutRetryCount > 10) {
×
665
    pInfo->timeoutRetryCount = 0;
×
666

667
    for (int32_t i = 0; i < numOfTimeout; ++i) {
×
668
      int32_t* pTaskId = taosArrayGet(pTimeoutList, i);
×
669
      if (pTaskId == NULL) {
×
670
        continue;
×
671
      }
672

673
      SDownstreamStatusInfo* p = NULL;
×
674
      findCheckRspStatus(pInfo, *pTaskId, &p);
×
675
      if (p != NULL) {
×
676
        code = streamTaskAddIntoNodeUpdateList(pTask, p->vgId);
×
677
        stDebug("s-task:%s vgId:%d downstream task:0x%x (vgId:%d) timeout more than 600sec, add into nodeUpdate list",
×
678
                id, vgId, p->taskId, p->vgId);
679
      }
680
    }
681

682
    stDebug("s-task:%s vgId:%d %d downstream task(s) all add into nodeUpate list", id, vgId, numOfTimeout);
×
683
  } else {
UNCOV
684
    stDebug("s-task:%s vgId:%d %d downstream task(s) timeout, send check msg again, retry:%d start time:%" PRId64, id,
×
685
            vgId, numOfTimeout, pInfo->timeoutRetryCount, pInfo->timeoutStartTs);
686
  }
UNCOV
687
}
×
688

UNCOV
689
void handleNotReadyDownstreamTask(SStreamTask* pTask, SArray* pNotReadyList) {
×
UNCOV
690
  STaskCheckInfo* pInfo = &pTask->taskCheckInfo;
×
UNCOV
691
  const char*     id = pTask->id.idStr;
×
UNCOV
692
  int32_t         vgId = pTask->pMeta->vgId;
×
UNCOV
693
  int32_t         numOfNotReady = taosArrayGetSize(pNotReadyList);
×
694

695
  // reset the info, and send the check msg to failure downstream again
UNCOV
696
  for (int32_t i = 0; i < numOfNotReady; ++i) {
×
UNCOV
697
    int32_t* pTaskId = taosArrayGet(pNotReadyList, i);
×
UNCOV
698
    if (pTaskId == NULL) {
×
699
      continue;
×
700
    }
701

UNCOV
702
    SDownstreamStatusInfo* p = NULL;
×
UNCOV
703
    findCheckRspStatus(pInfo, *pTaskId, &p);
×
UNCOV
704
    if (p != NULL) {
×
UNCOV
705
      p->rspTs = 0;
×
UNCOV
706
      p->status = -1;
×
UNCOV
707
      int32_t code = doSendCheckMsg(pTask, p);
×
708
    }
709
  }
710

UNCOV
711
  pInfo->notReadyRetryCount += 1;
×
UNCOV
712
  stDebug("s-task:%s vgId:%d %d downstream task(s) not ready, send check msg again, retry:%d start time:%" PRId64, id,
×
713
          vgId, numOfNotReady, pInfo->notReadyRetryCount, pInfo->startTs);
UNCOV
714
}
×
715

716
// the action of add status may incur the restart procedure, which should NEVER be executed in the timer thread.
717
// The restart of all tasks requires that all tasks should not have active timer for now. Therefore, the execution
718
// of restart in timer thread will result in a deadlock.
719
int32_t addDownstreamFailedStatusResultAsync(SMsgCb* pMsgCb, int32_t vgId, int64_t streamId, int32_t taskId) {
×
720
  return streamTaskSchedTask(pMsgCb, vgId, streamId, taskId, STREAM_EXEC_T_ADD_FAILED_TASK);
×
721
}
722

UNCOV
723
static void doCleanup(SStreamTask* pTask, SArray* pNotReadyList, SArray* pTimeoutList, void* param) {
×
UNCOV
724
  streamMetaReleaseTask(pTask->pMeta, pTask);
×
725

UNCOV
726
  taosArrayDestroy(pNotReadyList);
×
UNCOV
727
  taosArrayDestroy(pTimeoutList);
×
UNCOV
728
  streamTaskFreeRefId(param);
×
UNCOV
729
}
×
730

731
// this function is executed in timer thread
UNCOV
732
void rspMonitorFn(void* param, void* tmrId) {
×
UNCOV
733
  int32_t         numOfReady = 0;
×
UNCOV
734
  int32_t         numOfFault = 0;
×
UNCOV
735
  int32_t         numOfNotRsp = 0;
×
UNCOV
736
  int32_t         numOfNotReady = 0;
×
UNCOV
737
  int32_t         numOfTimeout = 0;
×
UNCOV
738
  int64_t         taskRefId = *(int64_t*)param;
×
UNCOV
739
  int64_t         now = taosGetTimestampMs();
×
UNCOV
740
  SArray*         pNotReadyList = NULL;
×
UNCOV
741
  SArray*         pTimeoutList = NULL;
×
UNCOV
742
  SStreamMeta*    pMeta = NULL;
×
UNCOV
743
  STaskCheckInfo* pInfo = NULL;
×
UNCOV
744
  int32_t         vgId = -1;
×
UNCOV
745
  int64_t         timeoutDuration = 0;
×
UNCOV
746
  const char*     id = NULL;
×
UNCOV
747
  int32_t         total = 0;
×
748

UNCOV
749
  SStreamTask* pTask = taosAcquireRef(streamTaskRefPool, taskRefId);
×
UNCOV
750
  if (pTask == NULL) {
×
UNCOV
751
    stError("invalid task rid:%" PRId64 " failed to acquired stream-task at %s", taskRefId, __func__);
×
UNCOV
752
    streamTaskFreeRefId(param);
×
UNCOV
753
    return;
×
754
  }
755

UNCOV
756
  pMeta = pTask->pMeta;
×
UNCOV
757
  pInfo = &pTask->taskCheckInfo;
×
UNCOV
758
  vgId = pTask->pMeta->vgId;
×
UNCOV
759
  timeoutDuration = now - pInfo->timeoutStartTs;
×
UNCOV
760
  id = pTask->id.idStr;
×
UNCOV
761
  total = (int32_t) taosArrayGetSize(pInfo->pList);
×
762

UNCOV
763
  stDebug("s-task:%s start to do check-downstream-rsp check in tmr", id);
×
764

UNCOV
765
  streamMutexLock(&pTask->lock);
×
UNCOV
766
  SStreamTaskState state = streamTaskGetStatus(pTask);
×
UNCOV
767
  streamMutexUnlock(&pTask->lock);
×
768

UNCOV
769
  if (state.state == TASK_STATUS__STOP) {
×
770
    stDebug("s-task:%s status:%s vgId:%d quit from monitor check-rsp tmr", id, state.name, vgId);
×
771
    streamTaskCompleteCheckRsp(pInfo, true, id);
×
772

773
    // not record the failure of the current task if try to close current vnode
774
    // otherwise, the put of message operation may incur invalid read of message queue.
775
    if (!pMeta->closeFlag) {
×
776
      int32_t code = addDownstreamFailedStatusResultAsync(pTask->pMsgCb, vgId, pTask->id.streamId, pTask->id.taskId);
×
777
      if (code) {
×
778
        stError("s-task:%s failed to create async record start failed task, code:%s", id, tstrerror(code));
×
779
      }
780
    }
781

782
    doCleanup(pTask, pNotReadyList, pTimeoutList, param);
×
783
    return;
×
784
  }
785

UNCOV
786
  if (state.state == TASK_STATUS__DROPPING || state.state == TASK_STATUS__READY) {
×
UNCOV
787
    stDebug("s-task:%s status:%s vgId:%d quit from monitor check-rsp tmr", id, state.name, vgId);
×
788

UNCOV
789
    streamTaskCompleteCheckRsp(pInfo, true, id);
×
UNCOV
790
    doCleanup(pTask, pNotReadyList, pTimeoutList, param);
×
UNCOV
791
    return;
×
792
  }
793

UNCOV
794
  streamMutexLock(&pInfo->checkInfoLock);
×
UNCOV
795
  if (pInfo->notReadyTasks == 0) {
×
UNCOV
796
    stDebug("s-task:%s status:%s vgId:%d all downstream ready, quit from monitor rsp tmr", id, state.name, vgId);
×
797

UNCOV
798
    streamTaskCompleteCheckRsp(pInfo, false, id);
×
UNCOV
799
    streamMutexUnlock(&pInfo->checkInfoLock);
×
UNCOV
800
    doCleanup(pTask, pNotReadyList, pTimeoutList, param);
×
UNCOV
801
    return;
×
802
  }
803

UNCOV
804
  pNotReadyList = taosArrayInit(4, sizeof(int64_t));
×
UNCOV
805
  pTimeoutList = taosArrayInit(4, sizeof(int64_t));
×
806

UNCOV
807
  if (state.state == TASK_STATUS__UNINIT) {
×
UNCOV
808
    getCheckRspStatus(pInfo, timeoutDuration, &numOfReady, &numOfFault, &numOfNotRsp, pTimeoutList, pNotReadyList, id);
×
809

UNCOV
810
    numOfNotReady = (int32_t)taosArrayGetSize(pNotReadyList);
×
UNCOV
811
    numOfTimeout = (int32_t)taosArrayGetSize(pTimeoutList);
×
812

813
    // fault tasks detected, not try anymore
UNCOV
814
    bool jumpOut = false;
×
UNCOV
815
    if ((numOfReady + numOfFault + numOfNotReady + numOfTimeout + numOfNotRsp) != total) {
×
816
      stError(
×
817
          "s-task:%s vgId:%d internal error in handling the check downstream procedure, rsp number is inconsistent, "
818
          "stop rspMonitor tmr, total:%d, notRsp:%d, notReady:%d, fault:%d, timeout:%d, ready:%d",
819
          id, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady);
820
      jumpOut = true;
×
821
    }
822

UNCOV
823
    if (numOfFault > 0) {
×
UNCOV
824
      stDebug(
×
825
          "s-task:%s status:%s vgId:%d all rsp. quit from monitor rsp tmr, since vnode-transfer/leader-change/restart "
826
          "detected, total:%d, notRsp:%d, notReady:%d, fault:%d, timeout:%d, ready:%d",
827
          id, state.name, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady);
UNCOV
828
      jumpOut = true;
×
829
    }
830

UNCOV
831
    if (jumpOut) {
×
UNCOV
832
      streamTaskCompleteCheckRsp(pInfo, false, id);
×
UNCOV
833
      streamMutexUnlock(&pInfo->checkInfoLock);
×
UNCOV
834
      doCleanup(pTask, pNotReadyList, pTimeoutList, param);
×
UNCOV
835
      return;
×
836
    }
837
  } else {  // unexpected status
838
    stError("s-task:%s unexpected task status:%s during waiting for check rsp", id, state.name);
×
839
  }
840

841
  // checking of downstream tasks has been stopped by other threads
UNCOV
842
  if (pInfo->stopCheckProcess == 1) {
×
843
    stDebug(
×
844
        "s-task:%s status:%s vgId:%d stopped by other threads to check downstream process, total:%d, notRsp:%d, "
845
        "notReady:%d, fault:%d, timeout:%d, ready:%d",
846
        id, state.name, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady);
847

848
    streamTaskCompleteCheckRsp(pInfo, false, id);
×
849
    streamMutexUnlock(&pInfo->checkInfoLock);
×
850

851
    int32_t code = addDownstreamFailedStatusResultAsync(pTask->pMsgCb, vgId, pTask->id.streamId, pTask->id.taskId);
×
852
    if (code) {
×
853
      stError("s-task:%s failed to create async record start failed task, code:%s", id, tstrerror(code));
×
854
    }
855

856
    doCleanup(pTask, pNotReadyList, pTimeoutList, param);
×
857
    return;
×
858
  }
859

UNCOV
860
  if (numOfNotReady > 0) {  // check to make sure not in recheck timer
×
UNCOV
861
    handleNotReadyDownstreamTask(pTask, pNotReadyList);
×
862
  }
863

UNCOV
864
  if (numOfTimeout > 0) {
×
UNCOV
865
    handleTimeoutDownstreamTasks(pTask, pTimeoutList);
×
866
  }
867

UNCOV
868
  streamTmrStart(rspMonitorFn, CHECK_RSP_CHECK_INTERVAL, param, streamTimer, &pInfo->checkRspTmr, vgId,
×
869
                 "check-status-monitor");
UNCOV
870
  streamMutexUnlock(&pInfo->checkInfoLock);
×
871

UNCOV
872
  stDebug(
×
873
      "s-task:%s vgId:%d continue checking rsp in 300ms, total:%d, notRsp:%d, notReady:%d, fault:%d, timeout:%d, "
874
      "ready:%d",
875
      id, vgId, total, numOfNotRsp, numOfNotReady, numOfFault, numOfTimeout, numOfReady);
UNCOV
876
  doCleanup(pTask, pNotReadyList, pTimeoutList, NULL);
×
877
}
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