schedulerInt.h 5.0 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"
28

29
#define SCHEDULE_DEFAULT_JOB_NUMBER 1000
D
dapan1121 已提交
30
#define SCHEDULE_DEFAULT_TASK_NUMBER 1000
31

D
dapan 已提交
32
#define SCH_MAX_CONDIDATE_EP_NUM TSDB_MAX_REPLICA
D
dapan 已提交
33

D
dapan1121 已提交
34 35 36 37 38
enum {
  SCH_READ = 1,
  SCH_WRITE,
};

39
typedef struct SSchedulerMgmt {
D
dapan1121 已提交
40
  uint64_t  taskId; 
D
dapan1121 已提交
41
  uint64_t  sId;
D
dapan 已提交
42
  SSchedulerCfg cfg;
D
dapan1121 已提交
43
  SHashObj *jobs;  // key: queryId, value: SQueryJob*
44
} SSchedulerMgmt;
45

D
dapan1121 已提交
46 47 48 49 50
typedef struct SSchCallbackParam {
  uint64_t queryId;
  uint64_t taskId;
} SSchCallbackParam;

D
dapan 已提交
51
typedef struct SSchLevel {
D
dapan1121 已提交
52 53 54 55 56 57 58
  int32_t  level;
  int8_t   status;
  SRWLatch lock;
  int32_t  taskFailed;
  int32_t  taskSucceed;
  int32_t  taskNum;
  SArray  *subTasks;  // Element is SQueryTask
D
dapan 已提交
59
} SSchLevel;
D
dapan1121 已提交
60 61


D
dapan 已提交
62
typedef struct SSchTask {
D
dapan1121 已提交
63 64 65 66 67 68 69 70 71 72 73 74 75
  uint64_t             taskId;         // task id
  SSchLevel           *level;          // level
  SSubplan            *plan;           // subplan
  char                *msg;            // operator tree
  int32_t              msgLen;         // msg length
  int8_t               status;         // task status
  SQueryNodeAddr       execAddr;       // task actual executed node address
  int8_t               condidateIdx;   // current try condidation index
  SArray              *condidateAddrs; // condidate node addresses, element is SQueryNodeAddr
  SQueryProfileSummary summary;        // task execution summary
  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
dapan 已提交
76
} SSchTask;
D
dapan1121 已提交
77

D
dapan 已提交
78
typedef struct SSchJobAttr {
D
dapan1121 已提交
79
  bool needFetch;
D
dapan 已提交
80 81 82
  bool syncSchedule;
  bool queryJob;
} SSchJobAttr;
D
dapan1121 已提交
83

D
dapan 已提交
84
typedef struct SSchJob {
85 86 87 88
  uint64_t  queryId;
  int32_t   levelNum;
  int32_t   levelIdx;
  int8_t    status;
D
dapan 已提交
89
  SSchJobAttr    attr;
90
  SQueryProfileSummary summary;
D
dapan1121 已提交
91 92
  SEpSet           dataSrcEps;
  SEpAddr          resEp;
D
dapan1121 已提交
93
  void            *transport;
D
dapan1121 已提交
94
  SArray          *nodeList;   // qnode/vnode list, element is SQueryNodeAddr
D
dapan 已提交
95 96
  tsem_t           rspSem;
  int32_t          userFetch;
D
dapan 已提交
97
  int32_t          remoteFetch;
D
dapan 已提交
98

D
dapan1121 已提交
99
  SSchTask        *fetchTask;
D
dapan 已提交
100
  int32_t          errCode;
D
dapan1121 已提交
101 102 103
  void            *res;
  int32_t          resNumOfRows;
  
D
dapan 已提交
104 105
  SHashObj *execTasks; // executing tasks, key:taskid, value:SQueryTask*
  SHashObj *succTasks; // succeed tasks, key:taskid, value:SQueryTask*
D
dapan1121 已提交
106
  SHashObj *failTasks; // failed tasks, key:taskid, value:SQueryTask*
D
dapan 已提交
107 108 109
    
  SArray   *levels;    // Element is SQueryLevel, starting from 0.
  SArray   *subPlans;  // Element is SArray*, and nested element is SSubplan. The execution level of subplan, starting from 0.
D
dapan 已提交
110
} SSchJob;
D
dapan1121 已提交
111

D
dapan 已提交
112
#define SCH_HAS_QNODE_IN_CLUSTER(type) (false) //TODO CLUSTER TYPE
D
dapan 已提交
113
#define SCH_TASK_READY_TO_LUNCH(task) ((task)->childReady >= taosArrayGetSize((task)->children))   // MAY NEED TO ENHANCE
D
dapan1121 已提交
114 115
#define SCH_IS_DATA_SRC_TASK(task) ((task)->plan->type == QUERY_TYPE_SCAN)
#define SCH_TASK_NEED_WAIT_ALL(task) ((task)->plan->type == QUERY_TYPE_MODIFY)
116

D
dapan1121 已提交
117 118 119
#define SCH_JOB_ELOG(param, ...) qError("QID:% "PRIx64 param, job->queryId, __VA_ARGS__)
#define SCH_TASK_ELOG(param, ...) qError("QID:%"PRIx64",TID:% "PRIx64 param, job->queryId, task->taskId, __VA_ARGS__)
#define SCH_TASK_DLOG(param, ...) qDebug("QID:%"PRIx64",TID:% "PRIx64 param, job->queryId, task->taskId, __VA_ARGS__)
D
dapan1121 已提交
120 121 122 123 124

#define SCH_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define SCH_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
#define SCH_ERR_LRET(c,...) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { qError(__VA_ARGS__); terrno = _code; return _code; } } while (0)
#define SCH_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
125

D
dapan1121 已提交
126 127 128
#define SCH_LOCK(type, _lock) (SCH_READ == (type) ? taosRLockLatch(_lock) : taosWLockLatch(_lock))
#define SCH_UNLOCK(type, _lock) (SCH_READ == (type) ? taosRUnLockLatch(_lock) : taosWUnLockLatch(_lock))

129

D
dapan 已提交
130
extern int32_t schLaunchTask(SSchJob *job, SSchTask *task);
D
dapan1121 已提交
131
extern int32_t schBuildAndSendMsg(SSchJob *job, SSchTask *task, int32_t msgType);
D
dapan 已提交
132

H
refact  
Hongze Cheng 已提交
133 134 135 136
#ifdef __cplusplus
}
#endif

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