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

taosdata / TDengine / #3520

06 Nov 2024 11:19AM UTC coverage: 56.943% (-0.8%) from 57.706%
#3520

push

travis-ci

web-flow
Merge pull request #28535 from taosdata/fix/TD-30837

feat(stream):stream interp && twa

108576 of 248375 branches covered (43.71%)

Branch coverage included in aggregate %.

2353 of 3792 new or added lines in 40 files covered. (62.05%)

8730 existing lines in 213 files now uncovered.

188369 of 273100 relevant lines covered (68.97%)

2375614.29 hits per line

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

60.26
/source/dnode/snode/src/snode.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 "rsync.h"
18
#include "sndInt.h"
19
#include "tqCommon.h"
20
#include "tuuid.h"
21

22
// clang-format off
23
#define sndError(...) do {  if (sndDebugFlag & DEBUG_ERROR) {taosPrintLog("SND ERROR ", DEBUG_ERROR, sndDebugFlag, __VA_ARGS__);}} while (0)
24
#define sndInfo(...)  do {   if (sndDebugFlag & DEBUG_INFO) { taosPrintLog("SND INFO ", DEBUG_INFO, sndDebugFlag, __VA_ARGS__);}} while (0)
25
#define sndDebug(...) do {  if (sndDebugFlag & DEBUG_DEBUG) { taosPrintLog("SND ", DEBUG_DEBUG, sndDebugFlag, __VA_ARGS__);}} while (0)
26
// clang-format on
27

28
int32_t sndBuildStreamTask(SSnode *pSnode, SStreamTask *pTask, int64_t nextProcessVer) {
4✔
29
  if (!(pTask->info.taskLevel == TASK_LEVEL__AGG && taosArrayGetSize(pTask->upstreamInfo.pList) != 0)) {
4!
30
    return TSDB_CODE_INVALID_PARA;
×
31
  }
32
  int32_t code = streamTaskInit(pTask, pSnode->pMeta, &pSnode->msgCb, nextProcessVer);
4✔
33
  if (code != TSDB_CODE_SUCCESS) {
4!
34
    return code;
×
35
  }
36

37
  pTask->pBackend = NULL;
4✔
38
  streamTaskOpenAllUpstreamInput(pTask);
4✔
39

40
  streamTaskResetUpstreamStageInfo(pTask);
4✔
41

42
  SCheckpointInfo *pChkInfo = &pTask->chkInfo;
4✔
43
  tqSetRestoreVersionInfo(pTask);
4✔
44

45
  char *p = streamTaskGetStatus(pTask).name;
4✔
46
  if (pTask->info.fillHistory) {
4✔
47
    sndInfo("vgId:%d build stream task, s-task:%s, %p checkpointId:%" PRId64 " checkpointVer:%" PRId64
1!
48
            " nextProcessVer:%" PRId64
49
            " child id:%d, level:%d, status:%s fill-history:%d, related stream task:0x%x trigger:%" PRId64 " ms",
50
            SNODE_HANDLE, pTask->id.idStr, pTask, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
51
            pTask->info.selfChildId, pTask->info.taskLevel, p, pTask->info.fillHistory,
52
            (int32_t)pTask->streamTaskId.taskId, pTask->info.delaySchedParam);
53
  } else {
54
    sndInfo("vgId:%d build stream task, s-task:%s, %p checkpointId:%" PRId64 " checkpointVer:%" PRId64
3!
55
            " nextProcessVer:%" PRId64
56
            " child id:%d, level:%d, status:%s fill-history:%d, related fill-task:0x%x trigger:%" PRId64 " ms",
57
            SNODE_HANDLE, pTask->id.idStr, pTask, pChkInfo->checkpointId, pChkInfo->checkpointVer, pChkInfo->nextProcessVer,
58
            pTask->info.selfChildId, pTask->info.taskLevel, p, pTask->info.fillHistory,
59
            (int32_t)pTask->hTaskInfo.id.taskId, pTask->info.delaySchedParam);
60
  }
61
  return 0;
4✔
62
}
63

64
SSnode *sndOpen(const char *path, const SSnodeOpt *pOption) {
9✔
65
  int32_t code = 0;
9✔
66
  SSnode *pSnode = taosMemoryCalloc(1, sizeof(SSnode));
9✔
67
  if (pSnode == NULL) {
9!
68
    return NULL;
×
69
  }
70

71
  stopRsync();
9✔
72
  code = startRsync();
9✔
73
  if (code != 0) {
9!
74
    terrno = code;
×
75
    goto FAIL;
×
76
  }
77

78
  pSnode->msgCb = pOption->msgCb;
9✔
79
  code = streamMetaOpen(path, pSnode, (FTaskBuild *)sndBuildStreamTask, tqExpandStreamTask, SNODE_HANDLE,
18✔
80
                        taosGetTimestampMs(), tqStartTaskCompleteCallback, &pSnode->pMeta);
81
  if (code != TSDB_CODE_SUCCESS) {
9!
82
    terrno = code;
×
83
    goto FAIL;
×
84
  }
85

86
  streamMetaLoadAllTasks(pSnode->pMeta);
9✔
87
  return pSnode;
9✔
88

89
FAIL:
×
90
  taosMemoryFree(pSnode);
×
91
  return NULL;
×
92
}
93

94
int32_t sndInit(SSnode *pSnode) {
9✔
95
  if (streamTaskSchedTask(&pSnode->msgCb, pSnode->pMeta->vgId, 0, 0, STREAM_EXEC_T_START_ALL_TASKS) != 0) {
9!
96
    sndError("failed to start all tasks");
×
97
  }
98
  return 0;
9✔
99
}
100

101
void sndClose(SSnode *pSnode) {
9✔
102
  stopRsync();
9✔
103
  streamMetaNotifyClose(pSnode->pMeta);
9✔
104
  if (streamMetaCommit(pSnode->pMeta) != 0) {
9!
105
    sndError("failed to commit stream meta");
×
106
  }
107
  streamMetaClose(pSnode->pMeta);
9✔
108
  taosMemoryFree(pSnode);
9✔
109
}
9✔
110

111
int32_t sndProcessStreamMsg(SSnode *pSnode, SRpcMsg *pMsg) {
412✔
112
  switch (pMsg->msgType) {
412!
113
    case TDMT_STREAM_TASK_RUN:
106✔
114
      return tqStreamTaskProcessRunReq(pSnode->pMeta, pMsg, true);
106✔
115
    case TDMT_STREAM_TASK_DISPATCH:
135✔
116
      return tqStreamTaskProcessDispatchReq(pSnode->pMeta, pMsg);
135✔
117
    case TDMT_STREAM_TASK_DISPATCH_RSP:
129✔
118
      return tqStreamTaskProcessDispatchRsp(pSnode->pMeta, pMsg);
129✔
119
    case TDMT_STREAM_RETRIEVE:
×
120
      return tqStreamTaskProcessRetrieveReq(pSnode->pMeta, pMsg);
×
121
    case TDMT_STREAM_RETRIEVE_RSP:  // 1036
8✔
122
      break;
8✔
123
    case TDMT_VND_STREAM_TASK_CHECK:
9✔
124
      return tqStreamTaskProcessCheckReq(pSnode->pMeta, pMsg);
9✔
125
    case TDMT_VND_STREAM_TASK_CHECK_RSP:
7✔
126
      return tqStreamTaskProcessCheckRsp(pSnode->pMeta, pMsg, true);
7✔
127
    case TDMT_STREAM_TASK_CHECKPOINT_READY:
2✔
128
      return tqStreamTaskProcessCheckpointReadyMsg(pSnode->pMeta, pMsg);
2✔
129
    case TDMT_MND_STREAM_HEARTBEAT_RSP:
12✔
130
      return tqStreamProcessStreamHbRsp(pSnode->pMeta, pMsg);
12✔
131
    case TDMT_MND_STREAM_REQ_CHKPT_RSP:
1✔
132
      return tqStreamProcessReqCheckpointRsp(pSnode->pMeta, pMsg);
1✔
133
    case TDMT_STREAM_TASK_CHECKPOINT_READY_RSP:
2✔
134
      return tqStreamProcessCheckpointReadyRsp(pSnode->pMeta, pMsg);
2✔
135
    case TDMT_MND_STREAM_CHKPT_REPORT_RSP:
1✔
136
      return tqStreamProcessChkptReportRsp(pSnode->pMeta, pMsg);
1✔
137
    case TDMT_STREAM_RETRIEVE_TRIGGER:
×
138
      return tqStreamTaskProcessRetrieveTriggerReq(pSnode->pMeta, pMsg);
×
139
    case TDMT_STREAM_RETRIEVE_TRIGGER_RSP:
×
140
      return tqStreamTaskProcessRetrieveTriggerRsp(pSnode->pMeta, pMsg);
×
141
    default:
×
142
      sndError("invalid snode msg:%d", pMsg->msgType);
×
143
      return TSDB_CODE_INVALID_MSG;
×
144
  }
145
  return 0;
8✔
146
}
147

148
int32_t sndProcessWriteMsg(SSnode *pSnode, SRpcMsg *pMsg, SRpcMsg *pRsp) {
5✔
149
  switch (pMsg->msgType) {
5!
150
    case TDMT_STREAM_TASK_DEPLOY: {
4✔
151
      void   *pReq = POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead));
4✔
152
      int32_t len = pMsg->contLen - sizeof(SMsgHead);
4✔
153
      return tqStreamTaskProcessDeployReq(pSnode->pMeta, &pSnode->msgCb, pMsg->info.conn.applyIndex, pReq, len, true,
4✔
154
                                          true);
155
    }
156

UNCOV
157
    case TDMT_STREAM_TASK_DROP:
×
UNCOV
158
      return tqStreamTaskProcessDropReq(pSnode->pMeta, pMsg->pCont, pMsg->contLen);
×
159
    case TDMT_VND_STREAM_TASK_UPDATE:
×
160
      return tqStreamTaskProcessUpdateReq(pSnode->pMeta, &pSnode->msgCb, pMsg, true);
×
161
    case TDMT_VND_STREAM_TASK_RESET:
×
162
      return tqStreamTaskProcessTaskResetReq(pSnode->pMeta, pMsg->pCont);
×
163
    case TDMT_STREAM_TASK_PAUSE:
×
164
      return tqStreamTaskProcessTaskPauseReq(pSnode->pMeta, pMsg->pCont);
×
165
    case TDMT_STREAM_TASK_RESUME:
×
166
      return tqStreamTaskProcessTaskResumeReq(pSnode->pMeta, pMsg->info.conn.applyIndex, pMsg->pCont, false);
×
167
    case TDMT_STREAM_TASK_UPDATE_CHKPT:
1✔
168
      return tqStreamTaskProcessUpdateCheckpointReq(pSnode->pMeta, true, pMsg->pCont);
1✔
UNCOV
169
    case TDMT_STREAM_CONSEN_CHKPT:
×
UNCOV
170
      return tqStreamTaskProcessConsenChkptIdReq(pSnode->pMeta, pMsg);
×
171
    default:
×
172
      return TSDB_CODE_INVALID_MSG;
×
173
  }
174
  return 0;
175
}
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