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

taosdata / TDengine / #3533

20 Nov 2024 07:11AM UTC coverage: 58.848% (-1.9%) from 60.78%
#3533

push

travis-ci

web-flow
Merge pull request #28823 from taosdata/fix/3.0/TD-32587

fix:[TD-32587]fix stmt segmentation fault

115578 of 252434 branches covered (45.79%)

Branch coverage included in aggregate %.

1 of 4 new or added lines in 1 file covered. (25.0%)

8038 existing lines in 233 files now uncovered.

194926 of 275199 relevant lines covered (70.83%)

1494459.59 hits per line

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

62.99
/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 10 * 1000  // 10 sec
22

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

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

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

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

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

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

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

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

96
  // serialize streamProcessScanHistoryFinishRsp
97
  if (pTask->outputInfo.type == TASK_OUTPUT__FIXED_DISPATCH) {
3,232✔
98
    streamTaskStartMonitorCheckRsp(pTask);
541✔
99

100
    STaskDispatcherFixed* pDispatch = &pTask->outputInfo.fixedDispatcher;
541✔
101

102
    setCheckDownstreamReqInfo(&req, tGenIdPI64(), pDispatch->taskId, pDispatch->nodeId);
541✔
103
    streamTaskAddReqInfo(&pTask->taskCheckInfo, req.reqId, pDispatch->taskId, pDispatch->nodeId, idstr);
541✔
104

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

110
    code = streamSendCheckMsg(pTask, &req, pTask->outputInfo.fixedDispatcher.nodeId,
541✔
111
                              &pTask->outputInfo.fixedDispatcher.epSet);
112

113
  } else if (pTask->outputInfo.type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
2,691✔
114
    streamTaskStartMonitorCheckRsp(pTask);
1,126✔
115

116
    SArray* vgInfo = pTask->outputInfo.shuffleDispatcher.dbInfo.pVgroupInfos;
1,126✔
117

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

122
    for (int32_t i = 0; i < numOfVgs; i++) {
3,950✔
123
      SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i);
2,824✔
124
      if (pVgInfo == NULL) {
2,824!
125
        continue;
×
126
      }
127

128
      setCheckDownstreamReqInfo(&req, tGenIdPI64(), pVgInfo->taskId, pVgInfo->vgId);
2,824✔
129
      streamTaskAddReqInfo(&pTask->taskCheckInfo, req.reqId, pVgInfo->taskId, pVgInfo->vgId, idstr);
2,824✔
130

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

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

147
void streamTaskProcessCheckMsg(SStreamMeta* pMeta, SStreamTaskCheckReq* pReq, SStreamTaskCheckRsp* pRsp) {
3,891✔
148
  int32_t taskId = pReq->downstreamTaskId;
3,891✔
149

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

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

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

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

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

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

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

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

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

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

245
  return 0;
3,883✔
246
}
247

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

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

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

267
  ((SMsgHead*)buf)->vgId = htonl(vgId);
3,893✔
268

269
  void* abuf = POINTER_SHIFT(buf, sizeof(SMsgHead));
3,893✔
270
  tEncoderInit(&encoder, (uint8_t*)abuf, len);
3,893✔
271
  code = tEncodeStreamTaskCheckRsp(&encoder, pRsp);
3,893✔
272
  tEncoderClear(&encoder);
3,893✔
273

274
  SRpcMsg rspMsg = {.code = 0, .pCont = buf, .contLen = sizeof(SMsgHead) + len, .info = *pRpcInfo};
3,893✔
275
  tmsgSendRsp(&rspMsg);
3,893✔
276

277
  code = TMIN(code, 0);
3,893✔
278
  return code;
3,893✔
279
}
280

281
void streamTaskStartMonitorCheckRsp(SStreamTask* pTask) {
1,667✔
282
  int32_t         vgId = pTask->pMeta->vgId;
1,667✔
283
  STaskCheckInfo* pInfo = &pTask->taskCheckInfo;
1,667✔
284

285
  streamMutexLock(&pInfo->checkInfoLock);
1,667✔
286

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

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

302
  streamTaskInitTaskCheckInfo(pInfo, &pTask->outputInfo, taosGetTimestampMs());
1,667✔
303

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

311
  streamMutexUnlock(&pInfo->checkInfoLock);
1,667✔
312
}
313

314
void streamTaskStopMonitorCheckRsp(STaskCheckInfo* pInfo, const char* id) {
3,212✔
315
  streamMutexLock(&pInfo->checkInfoLock);
3,212✔
316
  pInfo->stopCheckProcess = 1;
3,212✔
317
  streamMutexUnlock(&pInfo->checkInfoLock);
3,212✔
318

319
  stDebug("s-task:%s set stop check-rsp monitor flag", id);
3,212✔
320
}
3,212✔
321

322
void streamTaskCleanupCheckInfo(STaskCheckInfo* pInfo) {
11,696✔
323
  taosArrayDestroy(pInfo->pList);
11,696✔
324
  pInfo->pList = NULL;
11,696✔
325

326
  if (pInfo->checkRspTmr != NULL) {
11,696✔
327
    streamTmrStop(pInfo->checkRspTmr);
1,652✔
328
    pInfo->checkRspTmr = NULL;
1,652✔
329
  }
330

331
  streamMutexDestroy(&pInfo->checkInfoLock);
11,696✔
332
}
11,696✔
333

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

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

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

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

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

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

UNCOV
382
  streamMutexLock(&pTask->lock);
×
383

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

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

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

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

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

414
void streamTaskInitTaskCheckInfo(STaskCheckInfo* pInfo, STaskOutputInfo* pOutputInfo, int64_t startTs) {
1,667✔
415
  taosArrayClear(pInfo->pList);
1,667✔
416

417
  if (pOutputInfo->type == TASK_OUTPUT__FIXED_DISPATCH) {
1,667✔
418
    pInfo->notReadyTasks = 1;
541✔
419
  } else if (pOutputInfo->type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
1,126!
420
    pInfo->notReadyTasks = taosArrayGetSize(pOutputInfo->shuffleDispatcher.dbInfo.pVgroupInfos);
1,126✔
421
  }
422

423
  pInfo->startTs = startTs;
1,667✔
424
  pInfo->timeoutStartTs = startTs;
1,667✔
425
  pInfo->stopCheckProcess = 0;
1,667✔
426
}
1,667✔
427

428
void findCheckRspStatus(STaskCheckInfo* pInfo, int32_t taskId, SDownstreamStatusInfo** pStatusInfo) {
7,803✔
429
  if (pStatusInfo == NULL) {
7,803!
430
    return;
×
431
  }
432

433
  *pStatusInfo = NULL;
7,803✔
434
  for (int32_t j = 0; j < taosArrayGetSize(pInfo->pList); ++j) {
22,013✔
435
    SDownstreamStatusInfo* p = taosArrayGet(pInfo->pList, j);
14,210✔
436
    if (p == NULL) {
14,210!
437
      continue;
×
438
    }
439

440
    if (p->taskId == taskId) {
14,210✔
441
      *pStatusInfo = p;
4,436✔
442
    }
443
  }
444
}
445

446
int32_t streamTaskUpdateCheckInfo(STaskCheckInfo* pInfo, int32_t taskId, int32_t status, int64_t rspTs, int64_t reqId,
3,885✔
447
                                  int32_t* pNotReady, const char* id) {
448
  SDownstreamStatusInfo* p = NULL;
3,885✔
449

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

461
    // subtract one not-ready-task, since it is ready now
462
    if ((p->status != TASK_DOWNSTREAM_READY) && (status == TASK_DOWNSTREAM_READY)) {
3,883!
463
      *pNotReady = atomic_sub_fetch_32(&pInfo->notReadyTasks, 1);
3,326✔
464
    } else {
465
      *pNotReady = pInfo->notReadyTasks;
557✔
466
    }
467

468
    p->status = status;
3,883✔
469
    p->rspTs = rspTs;
3,883✔
470

471
    streamMutexUnlock(&pInfo->checkInfoLock);
3,883✔
472
    return TSDB_CODE_SUCCESS;
3,883✔
473
  }
474

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

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

491
  stDebug("s-task:%s set the in check-rsp flag", id);
1,667✔
492
  return TSDB_CODE_SUCCESS;
1,667✔
493
}
494

495
void streamTaskCompleteCheckRsp(STaskCheckInfo* pInfo, bool lock, const char* id) {
1,476✔
496
  if (lock) {
1,476✔
497
    streamMutexLock(&pInfo->checkInfoLock);
1,065✔
498
  }
499

500
  if (pInfo->inCheckProcess) {
1,476!
501
    int64_t el = (pInfo->startTs != 0) ? (taosGetTimestampMs() - pInfo->startTs) : 0;
2,952!
502
    stDebug("s-task:%s clear the in check-rsp flag, set the check-rsp done, elapsed time:%" PRId64 " ms", id, el);
1,476✔
503

504
    pInfo->startTs = 0;
1,476✔
505
    pInfo->timeoutStartTs = 0;
1,476✔
506
    pInfo->notReadyTasks = 0;
1,476✔
507
    pInfo->inCheckProcess = 0;
1,476✔
508
    pInfo->stopCheckProcess = 0;
1,476✔
509

510
    pInfo->notReadyRetryCount = 0;
1,476✔
511
    pInfo->timeoutRetryCount = 0;
1,476✔
512

513
    taosArrayClear(pInfo->pList);
1,476✔
514
  } else {
515
    stDebug("s-task:%s already not in check-rsp procedure", id);
×
516
  }
517

518
  if (lock) {
1,476✔
519
    streamMutexUnlock(&pInfo->checkInfoLock);
1,065✔
520
  }
521
}
1,476✔
522

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

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

536
  void* px = taosArrayPush(pInfo->pList, &info);
6,729✔
537
  if (px == NULL) {
538
    // todo: retry
539
  }
540

541
  streamMutexUnlock(&pInfo->checkInfoLock);
3,364✔
542
}
543

544
int32_t doSendCheckMsg(SStreamTask* pTask, SDownstreamStatusInfo* p) {
553✔
545
  const char* id = pTask->id.idStr;
553✔
546
  int32_t     code = 0;
553✔
547

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

556
  // update the reqId for the new check msg
557
  p->reqId = tGenIdPI64();
553✔
558

559
  STaskOutputInfo* pOutputInfo = &pTask->outputInfo;
553✔
560
  if (pOutputInfo->type == TASK_OUTPUT__FIXED_DISPATCH) {
553✔
561
    STaskDispatcherFixed* pDispatch = &pOutputInfo->fixedDispatcher;
361✔
562
    setCheckDownstreamReqInfo(&req, p->reqId, pDispatch->taskId, pDispatch->nodeId);
361✔
563

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

567
    code = streamSendCheckMsg(pTask, &req, pOutputInfo->fixedDispatcher.nodeId, &pOutputInfo->fixedDispatcher.epSet);
361✔
568
  } else if (pOutputInfo->type == TASK_OUTPUT__SHUFFLE_DISPATCH) {
192!
569
    SArray* vgInfo = pOutputInfo->shuffleDispatcher.dbInfo.pVgroupInfos;
192✔
570
    int32_t numOfVgs = taosArrayGetSize(vgInfo);
192✔
571

572
    for (int32_t i = 0; i < numOfVgs; i++) {
302!
573
      SVgroupInfo* pVgInfo = taosArrayGet(vgInfo, i);
302✔
574
      if (pVgInfo == NULL) {
302!
575
        continue;
×
576
      }
577

578
      if (p->taskId == pVgInfo->taskId) {
302✔
579
        setCheckDownstreamReqInfo(&req, p->reqId, pVgInfo->taskId, pVgInfo->vgId);
192✔
580

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

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

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

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

630
void setCheckDownstreamReqInfo(SStreamTaskCheckReq* pReq, int64_t reqId, int32_t dstTaskId, int32_t dstNodeId) {
3,918✔
631
  pReq->reqId = reqId;
3,918✔
632
  pReq->downstreamTaskId = dstTaskId;
3,918✔
633
  pReq->downstreamNodeId = dstNodeId;
3,918✔
634
}
3,918✔
635

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

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

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

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

UNCOV
663
  pInfo->timeoutRetryCount += 1;
×
664

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

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

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

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

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

697
  // reset the info, and send the check msg to failure downstream again
698
  for (int32_t i = 0; i < numOfNotReady; ++i) {
1,033✔
699
    int32_t* pTaskId = taosArrayGet(pNotReadyList, i);
553✔
700
    if (pTaskId == NULL) {
553!
701
      continue;
×
702
    }
703

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

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

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

725
static void doCleanup(SStreamTask* pTask, SArray* pNotReadyList, SArray* pTimeoutList, void* param) {
2,090✔
726
  streamMetaReleaseTask(pTask->pMeta, pTask);
2,090✔
727

728
  taosArrayDestroy(pNotReadyList);
2,090✔
729
  taosArrayDestroy(pTimeoutList);
2,090✔
730
  streamTaskFreeRefId(param);
2,090✔
731
}
2,090✔
732

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

751
  SStreamTask* pTask = taosAcquireRef(streamTaskRefPool, taskRefId);
2,091✔
752
  if (pTask == NULL) {
2,091✔
753
    stError("invalid task rid:%" PRId64 " failed to acquired stream-task at %s", taskRefId, __func__);
1!
754
    streamTaskFreeRefId(param);
1✔
755
    return;
1,477✔
756
  }
757

758
  pMeta = pTask->pMeta;
2,090✔
759
  pInfo = &pTask->taskCheckInfo;
2,090✔
760
  vgId = pTask->pMeta->vgId;
2,090✔
761
  timeoutDuration = now - pInfo->timeoutStartTs;
2,090✔
762
  id = pTask->id.idStr;
2,090✔
763
  total = (int32_t) taosArrayGetSize(pInfo->pList);
2,090✔
764

765
  stDebug("s-task:%s start to do check-downstream-rsp check in tmr", id);
2,090✔
766

767
  streamMutexLock(&pTask->lock);
2,090✔
768
  SStreamTaskState state = streamTaskGetStatus(pTask);
2,090✔
769
  streamMutexUnlock(&pTask->lock);
2,090✔
770

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

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

784
    doCleanup(pTask, pNotReadyList, pTimeoutList, param);
×
785
    return;
×
786
  }
787

788
  if (state.state == TASK_STATUS__DROPPING || state.state == TASK_STATUS__READY) {
2,090✔
789
    stDebug("s-task:%s status:%s vgId:%d quit from monitor check-rsp tmr", id, state.name, vgId);
1,065✔
790

791
    streamTaskCompleteCheckRsp(pInfo, true, id);
1,065✔
792
    doCleanup(pTask, pNotReadyList, pTimeoutList, param);
1,065✔
793
    return;
1,065✔
794
  }
795

796
  streamMutexLock(&pInfo->checkInfoLock);
1,025✔
797
  if (pInfo->notReadyTasks == 0) {
1,025✔
798
    stDebug("s-task:%s status:%s vgId:%d all downstream ready, quit from monitor rsp tmr", id, state.name, vgId);
411✔
799

800
    streamTaskCompleteCheckRsp(pInfo, false, id);
411✔
801
    streamMutexUnlock(&pInfo->checkInfoLock);
411✔
802
    doCleanup(pTask, pNotReadyList, pTimeoutList, param);
411✔
803
    return;
411✔
804
  }
805

806
  pNotReadyList = taosArrayInit(4, sizeof(int64_t));
614✔
807
  pTimeoutList = taosArrayInit(4, sizeof(int64_t));
614✔
808

809
  if (state.state == TASK_STATUS__UNINIT) {
614!
810
    getCheckRspStatus(pInfo, timeoutDuration, &numOfReady, &numOfFault, &numOfNotRsp, pTimeoutList, pNotReadyList, id);
614✔
811

812
    numOfNotReady = (int32_t)taosArrayGetSize(pNotReadyList);
614✔
813
    numOfTimeout = (int32_t)taosArrayGetSize(pTimeoutList);
614✔
814

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

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

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

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

850
    streamTaskCompleteCheckRsp(pInfo, false, id);
×
851
    streamMutexUnlock(&pInfo->checkInfoLock);
×
852

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

858
    doCleanup(pTask, pNotReadyList, pTimeoutList, param);
×
859
    return;
×
860
  }
861

862
  if (numOfNotReady > 0) {  // check to make sure not in recheck timer
614✔
863
    handleNotReadyDownstreamTask(pTask, pNotReadyList);
480✔
864
  }
865

866
  if (numOfTimeout > 0) {
614!
UNCOV
867
    handleTimeoutDownstreamTasks(pTask, pTimeoutList);
×
868
  }
869

870
  streamTmrStart(rspMonitorFn, CHECK_RSP_CHECK_INTERVAL, param, streamTimer, &pInfo->checkRspTmr, vgId,
614✔
871
                 "check-status-monitor");
872
  streamMutexUnlock(&pInfo->checkInfoLock);
614✔
873

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