scheduler.h 3.6 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_H_
#define _TD_SCHEDULER_H_

#ifdef __cplusplus
extern "C" {
#endif

D
dapan 已提交
23
#include "catalog.h"
24 25
#include "planner.h"

26
typedef struct SSchedulerCfg {
D
dapan1121 已提交
27
  uint32_t maxJobNum;
D
dapan 已提交
28
  int32_t  maxNodeTableNum;
29 30
} SSchedulerCfg;

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
typedef struct SQueryProfileSummary {
  int64_t startTs;      // Object created and added into the message queue
  int64_t endTs;        // the timestamp when the task is completed
  int64_t cputime;      // total cpu cost, not execute elapsed time

  int64_t loadRemoteDataDuration;       // remote io time
  int64_t loadNativeDataDuration;       // native disk io time

  uint64_t loadNativeData; // blocks + SMA + header files
  uint64_t loadRemoteData; // remote data acquired by exchange operator.

  uint64_t waitDuration; // the time to waiting to be scheduled in queue does matter, so we need to record it
  int64_t  addQTs;       // the time to be added into the message queue, used to calculate the waiting duration in queue.

  uint64_t totalRows;
  uint64_t loadRows;
  uint32_t totalBlocks;
  uint32_t loadBlocks;
  uint32_t loadBlockAgg;
  uint32_t skipBlocks;
  uint64_t resultSize;   // generated result size in Kb.
} SQueryProfileSummary;

D
dapan1121 已提交
54
typedef struct SQueryResult {
D
dapan1121 已提交
55 56 57 58
  int32_t         code;
  uint64_t        numOfRows;
  int32_t         msgSize;
  char           *msg;
D
dapan 已提交
59
  void           *res;
D
dapan1121 已提交
60 61
} SQueryResult;

D
dapan1121 已提交
62 63 64 65 66
typedef struct STaskInfo {
  SQueryNodeAddr addr;
  SSubQueryMsg  *msg;
} STaskInfo;

D
dapan1121 已提交
67 68
int32_t schedulerInit(SSchedulerCfg *cfg);

69 70 71
/**
 * Process the query job, generated according to the query physical plan.
 * This is a synchronized API, and is also thread-safety.
D
dapan1121 已提交
72
 * @param nodeList  Qnode/Vnode address list, element is SQueryNodeAddr
73 74
 * @return
 */
D
dapan1121 已提交
75
int32_t schedulerExecJob(void *transport, SArray *nodeList, SQueryPlan *pDag, int64_t *pJob, const char *sql, int64_t startTs, SQueryResult *pRes);
D
dapan1121 已提交
76 77 78 79

/**
 * Process the query job, generated according to the query physical plan.
 * This is a asynchronized API, and is also thread-safety.
80
 * @param pNodeList  Qnode/Vnode address list, element is SQueryNodeAddr
D
dapan1121 已提交
81 82
 * @return
 */
83
int32_t schedulerAsyncExecJob(void *transport, SArray *pNodeList, SQueryPlan* pDag, const char* sql, int64_t *pJob);
D
dapan1121 已提交
84

H
Haojun Liao 已提交
85 86 87 88 89 90
/**
 * Fetch query result from the remote query executor
 * @param pJob
 * @param data
 * @return
 */
D
dapan1121 已提交
91
int32_t schedulerFetchRows(int64_t job, void **data);
92

D
dapan1121 已提交
93 94
int32_t schedulerGetTasksStatus(int64_t job, SArray *pSub);

95 96 97 98 99 100

/**
 * Cancel query job
 * @param pJob
 * @return
 */
D
dapan1121 已提交
101
//int32_t scheduleCancelJob(void *pJob);
102

H
Haojun Liao 已提交
103 104 105 106
/**
 * Free the query job
 * @param pJob
 */
D
dapan1121 已提交
107
void schedulerFreeJob(int64_t job);
D
dapan1121 已提交
108

D
dapan1121 已提交
109 110
void schedulerDestroy(void);

111 112 113 114 115 116
/**
 * convert dag to task list
 * @param pDag
 * @param pTasks SArray**<STaskInfo>
 * @return
 */
X
Xiaoyu Wang 已提交
117
int32_t schedulerConvertDagToTaskList(SQueryPlan* pDag, SArray **pTasks);
D
dapan1121 已提交
118

D
dapan1121 已提交
119 120 121 122 123 124 125 126
/**
 * make one task info's multiple copies
 * @param src
 * @param dst SArray**<STaskInfo>
 * @return
 */
int32_t schedulerCopyTask(STaskInfo *src, SArray **dst, int32_t copyNum);

D
dapan1121 已提交
127 128 129
void schedulerFreeTaskList(SArray *taskList);


H
refact  
Hongze Cheng 已提交
130 131 132 133
#ifdef __cplusplus
}
#endif

D
dapan1121 已提交
134
#endif /*_TD_SCHEDULER_H_*/