schInt.h 18.4 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
 *
 * This program is free software: you can use, redistribute, and/or modify
 * it under the terms of the GNU Affero General Public License, version 3
 * or later ("AGPL"), as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _TD_SCHEDULER_INT_H_
#define _TD_SCHEDULER_INT_H_

#ifdef __cplusplus
extern "C" {
#endif

23 24 25 26
#include "os.h"
#include "tarray.h"
#include "planner.h"
#include "scheduler.h"
27
#include "thash.h"
D
dapan1121 已提交
28
#include "trpc.h"
D
dapan1121 已提交
29
#include "command.h"
30

D
dapan1121 已提交
31 32
#define SCHEDULE_DEFAULT_MAX_JOB_NUM 1000
#define SCHEDULE_DEFAULT_MAX_TASK_NUM 1000
D
dapan1121 已提交
33
#define SCHEDULE_DEFAULT_MAX_NODE_TABLE_NUM 200  // unit is TSDB_TABLE_NUM_UNIT
34

D
dapan1121 已提交
35 36 37
#define SCH_DEFAULT_TASK_TIMEOUT_USEC 10000000
#define SCH_MAX_TASK_TIMEOUT_USEC 60000000

D
dapan1121 已提交
38
#define SCH_TASK_MAX_EXEC_TIMES 8
39
#define SCH_MAX_CANDIDATE_EP_NUM TSDB_MAX_REPLICA
D
dapan 已提交
40

D
dapan1121 已提交
41 42 43 44 45
enum {
  SCH_READ = 1,
  SCH_WRITE,
};

D
dapan1121 已提交
46 47 48 49 50
enum {
  SCH_EXEC_CB = 1,
  SCH_FETCH_CB,
};

D
dapan1121 已提交
51 52 53 54
typedef enum {
  SCH_OP_NULL = 0,
  SCH_OP_EXEC,
  SCH_OP_FETCH,
D
dapan1121 已提交
55
  SCH_OP_GET_STATUS,
D
dapan1121 已提交
56 57
} SCH_OP_TYPE;

D
dapan1121 已提交
58
typedef struct SSchTrans {
D
dapan1121 已提交
59 60
  void *pTrans;
  void *pHandle;
D
dapan1121 已提交
61 62
} SSchTrans;

D
dapan1121 已提交
63 64
typedef struct SSchHbTrans {
  SRWLatch  lock;
D
dapan1121 已提交
65
  int64_t   taskNum;
D
dapan1121 已提交
66
  SRpcCtx   rpcCtx;
D
dapan1121 已提交
67 68 69
  SSchTrans trans;
} SSchHbTrans;

D
dapan1121 已提交
70 71
typedef struct SSchApiStat {

wafwerar's avatar
wafwerar 已提交
72
#if defined(WINDOWS) || defined(_TD_DARWIN_64)
wafwerar's avatar
wafwerar 已提交
73 74 75
  size_t avoidCompilationErrors;
#endif

D
dapan1121 已提交
76 77 78 79
} SSchApiStat;

typedef struct SSchRuntimeStat {

wafwerar's avatar
wafwerar 已提交
80
#if defined(WINDOWS) || defined(_TD_DARWIN_64)
wafwerar's avatar
wafwerar 已提交
81 82 83
  size_t avoidCompilationErrors;
#endif

D
dapan1121 已提交
84 85 86 87
} SSchRuntimeStat;

typedef struct SSchJobStat {

wafwerar's avatar
wafwerar 已提交
88
#if defined(WINDOWS) || defined(_TD_DARWIN_64)
wafwerar's avatar
wafwerar 已提交
89 90 91
  size_t avoidCompilationErrors;
#endif

D
dapan1121 已提交
92 93
} SSchJobStat;

D
dapan1121 已提交
94
typedef struct SSchStat {
D
dapan1121 已提交
95 96 97
  SSchApiStat      api;
  SSchRuntimeStat  runtime;
  SSchJobStat      job;
D
dapan1121 已提交
98
} SSchStat;
D
dapan1121 已提交
99

D
dapan1121 已提交
100
typedef struct SSchResInfo {
D
dapan1121 已提交
101
  SExecResult*           execRes;
D
dapan1121 已提交
102
  void**                 fetchRes;
D
dapan1121 已提交
103 104
  schedulerExecFp        execFp; 
  schedulerFetchFp       fetchFp; 
D
dapan1121 已提交
105
  void*                  cbParam;
D
dapan1121 已提交
106
} SSchResInfo;
D
dapan1121 已提交
107

D
dapan1121 已提交
108 109 110 111 112 113
typedef struct SSchOpEvent {
  SCH_OP_TYPE    type;
  bool           begin;
  SSchedulerReq *pReq;
} SSchOpEvent;

D
dapan1121 已提交
114 115 116 117 118 119 120 121 122 123 124
typedef int32_t (*schStatusEnterFp)(void* pHandle, void* pParam);
typedef int32_t (*schStatusLeaveFp)(void* pHandle, void* pParam);
typedef int32_t (*schStatusEventFp)(void* pHandle, void* pParam, void* pEvent);

typedef struct SSchStatusFps {
  EJobTaskType     status;
  schStatusEnterFp enterFp;
  schStatusLeaveFp leaveFp;
  schStatusEventFp eventFp;
} SSchStatusFps;

125
typedef struct SSchedulerMgmt {
D
dapan1121 已提交
126 127 128
  uint64_t        taskId; // sequential taksId
  uint64_t        sId;    // schedulerId
  SSchedulerCfg   cfg;
D
dapan1121 已提交
129
  bool            exit;
D
dapan1121 已提交
130
  int32_t         jobRef;
D
dapan1121 已提交
131
  int32_t         jobNum;
D
dapan1121 已提交
132
  SSchStat        stat;
D
dapan1121 已提交
133
  SRWLatch        hbLock;
D
dapan1121 已提交
134
  SHashObj       *hbConnections;
135
} SSchedulerMgmt;
136

D
dapan1121 已提交
137 138 139 140 141 142 143 144 145
typedef struct SSchCallbackParamHeader {
  bool isHbParam;
} SSchCallbackParamHeader;

typedef struct SSchTaskCallbackParam {
  SSchCallbackParamHeader head;
  uint64_t                queryId;
  int64_t                 refId;
  uint64_t                taskId;
D
dapan1121 已提交
146
  int32_t                 execId;
D
dapan1121 已提交
147
  void                   *pTrans;
D
dapan1121 已提交
148 149 150 151 152
} SSchTaskCallbackParam;

typedef struct SSchHbCallbackParam {
  SSchCallbackParamHeader head;
  SQueryNodeEpId          nodeEpId;
D
dapan1121 已提交
153
  void                   *pTrans;
D
dapan1121 已提交
154
} SSchHbCallbackParam;
D
dapan1121 已提交
155

D
dapan1121 已提交
156 157
typedef struct SSchFlowControl {
  SRWLatch  lock;
D
dapan1121 已提交
158
  bool      sorted;
D
dapan 已提交
159
  int32_t   tableNumSum;
D
dapan1121 已提交
160
  uint32_t  execTaskNum;
D
dapan1121 已提交
161
  SArray   *taskList;      // Element is SSchTask*
D
dapan1121 已提交
162 163
} SSchFlowControl;

D
dapan1121 已提交
164 165 166 167 168
typedef struct SSchNodeInfo {
  SQueryNodeAddr addr;
  void          *handle;
} SSchNodeInfo;

D
dapan 已提交
169
typedef struct SSchLevel {
D
dapan1121 已提交
170 171 172 173 174 175 176
  int32_t         level;
  int8_t          status;
  SRWLatch        lock;
  int32_t         taskFailed;
  int32_t         taskSucceed;
  int32_t         taskNum;
  int32_t         taskLaunchedNum;
D
dapan1121 已提交
177
  int32_t         taskDoneNum;
D
dapan1121 已提交
178
  SArray         *subTasks;      // Element is SSchTask
D
dapan 已提交
179
} SSchLevel;
D
dapan1121 已提交
180

D
dapan1121 已提交
181 182 183 184 185 186 187
typedef struct SSchTaskProfile {
  int64_t startTs;
  int64_t execUseTime[SCH_TASK_MAX_EXEC_TIMES];
  int64_t waitTime;
  int64_t endTs;
} SSchTaskProfile;

D
dapan 已提交
188
typedef struct SSchTask {
D
dapan1121 已提交
189
  uint64_t             taskId;         // task id
D
dapan1121 已提交
190
  SRWLatch             lock;           // task lock
D
dapan1121 已提交
191
  int32_t              maxExecTimes;   // task may exec times
D
dapan1121 已提交
192
  int32_t              execId;        // task current execute try index
D
dapan1121 已提交
193
  SSchLevel           *level;          // level
D
dapan1121 已提交
194
  SRWLatch             planLock;       // task update plan lock
D
dapan1121 已提交
195 196 197 198
  SSubplan            *plan;           // subplan
  char                *msg;            // operator tree
  int32_t              msgLen;         // msg length
  int8_t               status;         // task status
D
dapan1121 已提交
199
  int32_t              lastMsgType;    // last sent msg type
D
dapan1121 已提交
200
  int64_t              timeoutUsec;    // taks timeout useconds before reschedule
D
dapan1121 已提交
201
  SQueryNodeAddr       succeedAddr;    // task executed success node address
202 203
  int8_t               candidateIdx;   // current try condidation index
  SArray              *candidateAddrs; // condidate node addresses, element is SQueryNodeAddr
D
dapan1121 已提交
204 205
  SHashObj            *execNodes;      // all tried node for current task, element is SSchNodeInfo
  SSchTaskProfile      profile;        // task execution profile
D
dapan1121 已提交
206 207 208
  int32_t              childReady;     // child task ready number
  SArray              *children;       // the datasource tasks,from which to fetch the result, element is SQueryTask*
  SArray              *parents;        // the data destination tasks, get data from current task, element is SQueryTask*
D
dapan1121 已提交
209 210
  void*                handle;         // task send handle 
  bool                 registerdHb;    // registered in hb
D
dapan 已提交
211
} SSchTask;
D
dapan1121 已提交
212

D
dapan 已提交
213
typedef struct SSchJobAttr {
D
dapan1121 已提交
214 215
  EExplainMode explainMode;
  bool         queryJob;
D
dapan1121 已提交
216
  bool         needFetch;
D
dapan1121 已提交
217
  bool         needFlowCtrl;
D
dapan 已提交
218
} SSchJobAttr;
D
dapan1121 已提交
219

D
dapan1121 已提交
220 221
typedef struct {
  int32_t     op;
D
dapan1121 已提交
222
  bool        syncReq;
D
dapan1121 已提交
223 224
} SSchOpStatus;

D
dapan 已提交
225
typedef struct SSchJob {
D
dapan1121 已提交
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
  int64_t            refId;
  uint64_t           queryId;
  SSchJobAttr        attr;
  int32_t            levelNum;
  int32_t            taskNum;
  SRequestConnInfo   conn;
  SArray            *nodeList;   // qnode/vnode list, SArray<SQueryNodeLoad>
  SArray            *levels;    // starting from 0. SArray<SSchLevel>
  SQueryPlan        *pDag;  

  SArray            *dataSrcTasks; // SArray<SQueryTask*>
  int32_t            levelIdx;
  SEpSet             dataSrcEps;
  SHashObj          *taskList;
  SHashObj          *execTasks; // executing and executed tasks, key:taskid, value:SQueryTask*
  SHashObj          *flowCtrl;  // key is ep, element is SSchFlowControl

  SExplainCtx       *explainCtx;
  int8_t             status;  
  SQueryNodeAddr     resNode;
  tsem_t             rspSem;
  SSchOpStatus       opStatus;
  schedulerChkKillFp chkKillFp;
  void*              chkKillParam;
  SSchTask          *fetchTask;
  int32_t            errCode;
  SRWLatch           resLock;
D
dapan1121 已提交
253
  SExecResult        execRes;
D
dapan1121 已提交
254 255 256 257
  void              *resData;         //TODO free it or not
  int32_t            resNumOfRows;
  SSchResInfo        userRes;
  const char        *sql;
258
  SQueryProfileSummary summary;
D
dapan 已提交
259
} SSchJob;
D
dapan1121 已提交
260

D
dapan1121 已提交
261 262
extern SSchedulerMgmt schMgmt;

D
dapan1121 已提交
263 264 265
#define SCH_LOG_TASK_START_TS(_task)                          \
  do {                                                        \
    int64_t us = taosGetTimestampUs();                        \
D
dapan1121 已提交
266
    int32_t idx = (_task)->execId % SCH_TASK_MAX_EXEC_TIMES; \
D
dapan1121 已提交
267
    (_task)->profile.execUseTime[idx] = us;                    \
D
dapan1121 已提交
268
    if (0 == (_task)->execId) {                              \
D
dapan1121 已提交
269 270 271 272 273
      (_task)->profile.startTs = us;                          \
    }                                                         \
  } while (0)  

#define SCH_LOG_TASK_WAIT_TS(_task)                        \
D
dapan1121 已提交
274 275
  do {                                                    \
    int64_t us = taosGetTimestampUs();                    \
D
dapan1121 已提交
276
    int32_t idx = (_task)->execId % SCH_TASK_MAX_EXEC_TIMES; \
D
dapan1121 已提交
277
    (_task)->profile.waitTime += us - (_task)->profile.execUseTime[idx];    \
D
dapan1121 已提交
278 279
  } while (0)  

D
dapan1121 已提交
280

D
dapan1121 已提交
281 282 283
#define SCH_LOG_TASK_END_TS(_task)                        \
  do {                                                    \
    int64_t us = taosGetTimestampUs();                    \
D
dapan1121 已提交
284
    int32_t idx = (_task)->execId % SCH_TASK_MAX_EXEC_TIMES; \
D
dapan1121 已提交
285
    (_task)->profile.execUseTime[idx] = us - (_task)->profile.execUseTime[idx];    \
D
dapan1121 已提交
286 287 288
    (_task)->profile.endTs = us;                          \
  } while (0)  

D
dapan1121 已提交
289
#define SCH_TASK_TIMEOUT(_task) ((taosGetTimestampUs() - (_task)->profile.execUseTime[(_task)->execId % SCH_TASK_MAX_EXEC_TIMES]) > (_task)->timeoutUsec)
D
dapan1121 已提交
290

D
dapan1121 已提交
291
#define SCH_TASK_READY_FOR_LAUNCH(readyNum, task) ((readyNum) >= taosArrayGetSize((task)->children))
D
dapan1121 已提交
292

D
dapan1121 已提交
293 294 295
#define SCH_LOCK_TASK(_task) SCH_LOCK(SCH_WRITE, &(_task)->lock)
#define SCH_UNLOCK_TASK(_task) SCH_UNLOCK(SCH_WRITE, &(_task)->lock)

D
dapan1121 已提交
296
#define SCH_TASK_ID(_task) ((_task) ? (_task)->taskId : -1)
D
dapan1121 已提交
297
#define SCH_TASK_EID(_task) ((_task) ? (_task)->execId : -1)
D
dapan1121 已提交
298

D
dapan1121 已提交
299 300 301
#define SCH_IS_DATA_SRC_QRY_TASK(task) ((task)->plan->subplanType == SUBPLAN_TYPE_SCAN)
#define SCH_IS_DATA_SRC_TASK(task) (((task)->plan->subplanType == SUBPLAN_TYPE_SCAN) || ((task)->plan->subplanType == SUBPLAN_TYPE_MODIFY))
#define SCH_IS_LEAF_TASK(_job, _task) (((_task)->level->level + 1) == (_job)->levelNum)
302

H
Haojun Liao 已提交
303
#define SCH_SET_TASK_STATUS(task, st) atomic_store_8(&(task)->status, st)
D
dapan1121 已提交
304
#define SCH_GET_TASK_STATUS(task) atomic_load_8(&(task)->status)
D
dapan1121 已提交
305 306
#define SCH_GET_TASK_STATUS_STR(task) jobTaskStatusStr(SCH_GET_TASK_STATUS(task))

D
dapan1121 已提交
307 308
#define SCH_GET_TASK_HANDLE(_task) ((_task) ? (_task)->handle : NULL)
#define SCH_SET_TASK_HANDLE(_task, _handle) ((_task)->handle = (_handle))
D
dapan1121 已提交
309

H
Haojun Liao 已提交
310
#define SCH_SET_JOB_STATUS(job, st) atomic_store_8(&(job)->status, st)
D
dapan1121 已提交
311
#define SCH_GET_JOB_STATUS(job) atomic_load_8(&(job)->status)
D
dapan1121 已提交
312
#define SCH_GET_JOB_STATUS_STR(job) jobTaskStatusStr(SCH_GET_JOB_STATUS(job))
D
dapan1121 已提交
313

D
dapan1121 已提交
314 315 316
#define SCH_JOB_IN_SYNC_OP(job) ((job)->opStatus.op && (job)->opStatus.syncReq)
#define SCH_JOB_IN_ASYNC_EXEC_OP(job) ((SCH_OP_EXEC == atomic_val_compare_exchange_32(&(job)->opStatus.op, SCH_OP_EXEC, SCH_OP_NULL)) && (!(job)->opStatus.syncReq))
#define SCH_JOB_IN_ASYNC_FETCH_OP(job) ((SCH_OP_FETCH == atomic_val_compare_exchange_32(&(job)->opStatus.op, SCH_OP_FETCH, SCH_OP_NULL)) && (!(job)->opStatus.syncReq))
D
dapan1121 已提交
317

D
dapan1121 已提交
318 319
#define SCH_SET_JOB_NEED_FLOW_CTRL(_job) (_job)->attr.needFlowCtrl = true
#define SCH_JOB_NEED_FLOW_CTRL(_job) ((_job)->attr.needFlowCtrl)
D
dapan1121 已提交
320
#define SCH_TASK_NEED_FLOW_CTRL(_job, _task) (SCH_IS_DATA_SRC_QRY_TASK(_task) && SCH_JOB_NEED_FLOW_CTRL(_job) && SCH_IS_LEVEL_UNFINISHED((_task)->level))
D
dapan1121 已提交
321
#define SCH_FETCH_TYPE(_pSrcTask) (SCH_IS_DATA_SRC_QRY_TASK(_pSrcTask) ? TDMT_SCH_FETCH : TDMT_SCH_MERGE_FETCH)
D
dapan1121 已提交
322

D
dapan1121 已提交
323
#define SCH_SET_JOB_TYPE(_job, type) do { if ((type) != SUBPLAN_TYPE_MODIFY) { (_job)->attr.queryJob = true; } } while (0)
D
dapan1121 已提交
324
#define SCH_IS_QUERY_JOB(_job) ((_job)->attr.queryJob) 
D
dapan1121 已提交
325 326 327
#define SCH_JOB_NEED_FETCH(_job) ((_job)->attr.needFetch)
#define SCH_JOB_NEED_WAIT(_job) (!SCH_IS_QUERY_JOB(_job))
#define SCH_JOB_NEED_DROP(_job) (SCH_IS_QUERY_JOB(_job))
D
dapan1121 已提交
328
#define SCH_IS_EXPLAIN_JOB(_job) (EXPLAIN_MODE_ANALYZE == (_job)->attr.explainMode)
D
dapan1121 已提交
329
#define SCH_NETWORK_ERR(_code) ((_code) == TSDB_CODE_RPC_BROKEN_LINK || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
D
dapan1121 已提交
330
#define SCH_SUB_TASK_NETWORK_ERR(_code, _len) (SCH_NETWORK_ERR(_code) && ((_len) > 0))
D
dapan1121 已提交
331
#define SCH_NEED_REDIRECT_MSGTYPE(_msgType) ((_msgType) == TDMT_SCH_QUERY || (_msgType) == TDMT_SCH_MERGE_QUERY || (_msgType) == TDMT_SCH_FETCH || (_msgType) == TDMT_SCH_MERGE_FETCH)
D
dapan1121 已提交
332 333
#define SCH_NEED_REDIRECT(_msgType, _code, _rspLen) (SCH_NEED_REDIRECT_MSGTYPE(_msgType) && (NEED_SCHEDULER_REDIRECT_ERROR(_code) || SCH_SUB_TASK_NETWORK_ERR(_code, _rspLen)))
#define SCH_NEED_RETRY(_msgType, _code) ((SCH_NETWORK_ERR(_code) && SCH_NEED_REDIRECT_MSGTYPE(_msgType)) || (_code) == TSDB_CODE_SCH_TIMEOUT_ERROR)
D
dapan1121 已提交
334

D
dapan1121 已提交
335
#define SCH_IS_LEVEL_UNFINISHED(_level) ((_level)->taskLaunchedNum < (_level)->taskNum)
X
Xiaoyu Wang 已提交
336 337
#define SCH_GET_CUR_EP(_addr) (&(_addr)->epSet.eps[(_addr)->epSet.inUse])
#define SCH_SWITCH_EPSET(_addr) ((_addr)->epSet.inUse = ((_addr)->epSet.inUse + 1) % (_addr)->epSet.numOfEps)
D
dapan1121 已提交
338
#define SCH_TASK_NUM_OF_EPS(_addr) ((_addr)->epSet.numOfEps)
D
dapan1121 已提交
339

H
Haojun Liao 已提交
340 341
#define SCH_JOB_ELOG(param, ...) qError("QID:0x%" PRIx64 " " param, pJob->queryId, __VA_ARGS__)
#define SCH_JOB_DLOG(param, ...) qDebug("QID:0x%" PRIx64 " " param, pJob->queryId, __VA_ARGS__)
S
Shengliang Guan 已提交
342 343

#define SCH_TASK_ELOG(param, ...) \
D
dapan1121 已提交
344
  qError("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__)
S
Shengliang Guan 已提交
345
#define SCH_TASK_DLOG(param, ...) \
D
dapan1121 已提交
346
  qDebug("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__)
D
dapan1121 已提交
347
#define SCH_TASK_DLOGL(param, ...) \
D
dapan1121 已提交
348
  qDebugL("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__)
S
Shengliang Guan 已提交
349
#define SCH_TASK_WLOG(param, ...) \
D
dapan1121 已提交
350
  qWarn("QID:0x%" PRIx64 ",TID:0x%" PRIx64 ",EID:%d " param, pJob->queryId, SCH_TASK_ID(pTask), SCH_TASK_EID(pTask),__VA_ARGS__)
D
dapan1121 已提交
351

D
dapan1121 已提交
352 353 354
#define SCH_SET_ERRNO(_err) do { if (TSDB_CODE_SCH_IGNORE_ERROR != (_err)) { terrno = (_err); } } while (0)
#define SCH_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(_code); return _code; } } while (0)
#define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(_code); } return _code; } while (0)
D
dapan1121 已提交
355
#define SCH_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { SCH_SET_ERRNO(code); goto _return; } } while (0)
356

D
dapan1121 已提交
357 358 359
#define SCH_LOCK(type, _lock) (SCH_READ == (type) ? taosRLockLatch(_lock) : taosWLockLatch(_lock))
#define SCH_UNLOCK(type, _lock) (SCH_READ == (type) ? taosRUnLockLatch(_lock) : taosWUnLockLatch(_lock))

360

D
dapan1121 已提交
361 362
void    schDeregisterTaskHb(SSchJob *pJob, SSchTask *pTask);
void    schCleanClusterHb(void* pTrans);
D
dapan1121 已提交
363 364
int32_t schLaunchTask(SSchJob *job, SSchTask *task);
int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, SQueryNodeAddr *addr, int32_t msgType);
D
dapan1121 已提交
365 366
SSchJob *schAcquireJob(int64_t refId);
int32_t schReleaseJob(int64_t refId);
D
dapan1121 已提交
367
void    schFreeFlowCtrl(SSchJob *pJob);
D
dapan1121 已提交
368
int32_t schChkJobNeedFlowCtrl(SSchJob *pJob, SSchLevel *pLevel);
D
dapan1121 已提交
369 370 371 372
int32_t schDecTaskFlowQuota(SSchJob *pJob, SSchTask *pTask);
int32_t schCheckIncTaskFlowQuota(SSchJob *pJob, SSchTask *pTask, bool *enough);
int32_t schLaunchTasksInFlowCtrlList(SSchJob *pJob, SSchTask *pTask);
int32_t schLaunchTaskImpl(SSchJob *pJob, SSchTask *pTask);
D
dapan1121 已提交
373
int32_t schLaunchFetchTask(SSchJob *pJob);
D
dapan1121 已提交
374
int32_t schProcessOnTaskFailure(SSchJob *pJob, SSchTask *pTask, int32_t errCode);
D
dapan1121 已提交
375
int32_t schBuildAndSendHbMsg(SQueryNodeEpId *nodeEpId, SArray* taskAction);
D
dapan1121 已提交
376
int32_t schCloneSMsgSendInfo(void *src, void **dst);
D
dapan1121 已提交
377
int32_t schValidateAndBuildJob(SQueryPlan *pDag, SSchJob *pJob);
D
dapan1121 已提交
378
void    schFreeJobImpl(void *job);
D
dapan1121 已提交
379 380 381
int32_t schMakeHbRpcCtx(SSchJob *pJob, SSchTask *pTask, SRpcCtx *pCtx);
int32_t schEnsureHbConnection(SSchJob *pJob, SSchTask *pTask);
int32_t schUpdateHbConnection(SQueryNodeEpId *epId, SSchTrans *trans);
D
dapan1121 已提交
382
int32_t schHandleHbCallback(void *param, SDataBuf *pMsg, int32_t code);
D
dapan1121 已提交
383
void    schFreeRpcCtx(SRpcCtx *pCtx);
D
dapan1121 已提交
384
int32_t schGetCallbackFp(int32_t msgType, __async_send_cb_fn_t *fp);
D
dapan1121 已提交
385
bool    schJobNeedToStop(SSchJob *pJob, int8_t *pStatus);
D
dapan1121 已提交
386
int32_t schProcessOnTaskSuccess(SSchJob *pJob, SSchTask *pTask);
D
dapan1121 已提交
387
int32_t schSaveJobQueryRes(SSchJob *pJob, SQueryTableRsp *rsp);
D
dapan1121 已提交
388
int32_t schProcessOnExplainDone(SSchJob *pJob, SSchTask *pTask, SRetrieveTableRsp *pRsp);
D
dapan1121 已提交
389
void    schProcessOnDataFetched(SSchJob *job);
390
int32_t schGetTaskInJob(SSchJob *pJob, uint64_t taskId, SSchTask **pTask);
D
dapan1121 已提交
391
void    schFreeRpcCtxVal(const void *arg);
D
dapan1121 已提交
392
int32_t schMakeBrokenLinkVal(SSchJob *pJob, SSchTask *pTask, SRpcBrokenlinkVal *brokenVal, bool isHb);
D
dapan1121 已提交
393
int32_t schAppendTaskExecNode(SSchJob *pJob, SSchTask *pTask, SQueryNodeAddr *addr, int32_t execId);
D
dapan1121 已提交
394
int32_t schExecStaticExplainJob(SSchedulerReq *pReq, int64_t *job, bool sync);
D
dapan1121 已提交
395
int32_t schUpdateJobStatus(SSchJob *pJob, int8_t newStatus);
D
dapan1121 已提交
396 397 398
int32_t schCancelJob(SSchJob *pJob);
int32_t schProcessOnJobDropped(SSchJob *pJob, int32_t errCode);
uint64_t schGenTaskId(void);
D
dapan1121 已提交
399
void    schCloseJobRef(void);
D
dapan1121 已提交
400
int32_t schAsyncExecJob(SSchedulerReq *pReq, int64_t *pJob);
D
dapan1121 已提交
401 402
int32_t schJobFetchRows(SSchJob *pJob);
int32_t schJobFetchRowsA(SSchJob *pJob);
D
dapan1121 已提交
403
int32_t schUpdateTaskHandle(SSchJob *pJob, SSchTask *pTask, bool dropExecNode, void *handle, int32_t execId);
D
dapan1121 已提交
404
int32_t schProcessOnTaskStatusRsp(SQueryNodeEpId* pEpId, SArray* pStatusList);
D
dapan1121 已提交
405 406
void    schFreeSMsgSendInfo(SMsgSendInfo *msgSendInfo);
char*   schGetOpStr(SCH_OP_TYPE type);
D
dapan1121 已提交
407
int32_t schBeginOperation(SSchJob *pJob, SCH_OP_TYPE type, bool sync);
D
dapan1121 已提交
408
int32_t schInitJob(int64_t *pJobId, SSchedulerReq *pReq);
D
dapan1121 已提交
409
int32_t schExecJob(SSchJob *pJob, SSchedulerReq *pReq);
D
dapan1121 已提交
410
int32_t schDumpJobExecRes(SSchJob* pJob, SExecResult* pRes);
D
dapan1121 已提交
411 412
int32_t schUpdateTaskCandidateAddr(SSchJob *pJob, SSchTask *pTask, SEpSet* pEpSet);
int32_t schHandleRedirect(SSchJob *pJob, SSchTask *pTask, SDataBuf* pData, int32_t rspCode);
D
dapan1121 已提交
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
void    schProcessOnOpEnd(SSchJob *pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode);
int32_t schProcessOnOpBegin(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq);
void    schProcessOnCbEnd(SSchJob *pJob, SSchTask *pTask, int32_t errCode);
int32_t schProcessOnCbBegin(SSchJob** job, SSchTask** task, uint64_t qId, int64_t rId, uint64_t tId);
void    schDropTaskOnExecNode(SSchJob *pJob, SSchTask *pTask);
bool    schJobDone(SSchJob *pJob);
int32_t schRemoveTaskFromExecList(SSchJob *pJob, SSchTask *pTask);
int32_t schLaunchJobLowerLevel(SSchJob *pJob, SSchTask *pTask);
int32_t schSwitchJobStatus(SSchJob* pJob, int32_t status, void* param);
int32_t schHandleOpBeginEvent(int64_t jobId, SSchJob** job, SCH_OP_TYPE type, SSchedulerReq* pReq);
int32_t schHandleOpEndEvent(SSchJob* pJob, SCH_OP_TYPE type, SSchedulerReq* pReq, int32_t errCode);
int32_t schHandleTaskRetry(SSchJob *pJob, SSchTask *pTask);
void    schUpdateJobErrCode(SSchJob *pJob, int32_t errCode);
int32_t schTaskCheckSetRetry(SSchJob *pJob, SSchTask *pTask, int32_t errCode, bool *needRetry);
int32_t schProcessOnJobFailure(SSchJob *pJob, int32_t errCode);
int32_t schProcessOnJobPartialSuccess(SSchJob *pJob);
void    schFreeTask(SSchJob *pJob, SSchTask *pTask);
void    schDropTaskInHashList(SSchJob *pJob, SHashObj *list);
int32_t schLaunchLevelTasks(SSchJob *pJob, SSchLevel *level);
int32_t schGetTaskFromList(SHashObj *pTaskList, uint64_t taskId, SSchTask **pTask);
int32_t schInitTask(SSchJob *pJob, SSchTask *pTask, SSubplan *pPlan, SSchLevel *pLevel);
D
dapan1121 已提交
434

D
dapan 已提交
435

H
refact  
Hongze Cheng 已提交
436 437 438 439
#ifdef __cplusplus
}
#endif

D
dapan1121 已提交
440
#endif /*_TD_SCHEDULER_INT_H_*/