schedulerInt.h 3.8 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

34 35 36 37 38 39 40 41 42 43
enum {
  SCH_STATUS_NOT_START = 1,
  SCH_STATUS_EXECUTING,
  SCH_STATUS_SUCCEED,
  SCH_STATUS_FAILED,
  SCH_STATUS_CANCELLING,
  SCH_STATUS_CANCELLED
};

typedef struct SSchedulerMgmt {
D
dapan1121 已提交
44
  uint64_t  taskId;
D
dapan 已提交
45
  SSchedulerCfg cfg;
46 47
  SHashObj *Jobs;  // key: queryId, value: SQueryJob*
} SSchedulerMgmt;
48

D
dapan1121 已提交
49
typedef struct SQueryTask {
D
dapan 已提交
50 51 52 53 54 55 56
  uint64_t             taskId;     // task id
  SSubplan            *plan;       // subplan
  char                *msg;        // operator tree
  int8_t               status;     // task status
  SEpAddr              execAddr;   // task actual executed node address
  SQueryProfileSummary summary;    // task execution summary
  int32_t              childReady; // child task ready number
D
dapan 已提交
57
  SArray              *children;   // the datasource tasks,from which to fetch the result, element is SQueryTask*
D
dapan 已提交
58
  SArray              *parents;    // the data destination tasks, get data from current task, element is SQueryTask*
D
dapan1121 已提交
59 60
} SQueryTask;

61
typedef struct SQueryLevel {
D
dapan1121 已提交
62
  int32_t level;
63 64 65 66 67
  int8_t  status;
  int32_t taskNum;
  SArray *subTasks;  // Element is SQueryTask
} SQueryLevel;

D
dapan1121 已提交
68
typedef struct SQueryJob {
69 70 71 72 73
  uint64_t  queryId;
  int32_t   levelNum;
  int32_t   levelIdx;
  int8_t    status;
  SQueryProfileSummary summary;
D
dapan 已提交
74
  SEpSet    dataSrcEps;
D
dapan 已提交
75
  SEpAddr   resEp;
D
dapan1121 已提交
76 77
  void            *transport;
  SArray          *qnodeList;
D
dapan 已提交
78 79
  tsem_t           rspSem;
  int32_t          userFetch;
D
dapan 已提交
80
  int32_t          remoteFetch;
D
dapan 已提交
81
  void            *res;
D
dapan 已提交
82 83 84 85 86 87

  SHashObj *execTasks; // executing tasks, key:taskid, value:SQueryTask*
  SHashObj *succTasks; // succeed tasks, key:taskid, value:SQueryTask*
    
  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
dapan1121 已提交
88 89
} SQueryJob;

D
dapan 已提交
90
#define SCH_HAS_QNODE_IN_CLUSTER(type) (false) //TODO CLUSTER TYPE
D
dapan 已提交
91
#define SCH_TASK_READY_TO_LUNCH(task) ((task)->childReady >= taosArrayGetSize((task)->children))   // MAY NEED TO ENHANCE
D
dapan 已提交
92
#define SCH_IS_DATA_SRC_TASK(task) (task->plan->type == QUERY_TYPE_SCAN)
93

D
dapan1121 已提交
94
#define SCH_JOB_ERR_LOG(param, ...) qError("QID:%"PRIx64 param, job->queryId, __VA_ARGS__)
D
dapan1121 已提交
95
#define SCH_TASK_ERR_LOG(param, ...) qError("QID:%"PRIx64",TID:%"PRIx64 param, job->queryId, task->taskId, __VA_ARGS__)
D
dapan1121 已提交
96 97 98 99 100

#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)
101 102


D
dapan1121 已提交
103
extern int32_t schLaunchTask(SQueryJob *job, SQueryTask *task);
D
dapan 已提交
104

H
refact  
Hongze Cheng 已提交
105 106 107 108
#ifdef __cplusplus
}
#endif

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