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

#ifdef __cplusplus
extern "C" {
#endif

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

D
dapan1121 已提交
26 27
extern tsem_t schdRspSem;

28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
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 已提交
51 52 53 54 55
typedef struct STaskInfo {
  SQueryNodeAddr addr;
  SSubQueryMsg  *msg;
} STaskInfo;

D
dapan1121 已提交
56 57 58 59 60
typedef struct SSchdFetchParam {
  void **pData;
  int32_t* code;
} SSchdFetchParam;

D
dapan1121 已提交
61
typedef void (*schedulerExecFp)(SExecResult* pResult, void* param, int32_t code);
D
dapan1121 已提交
62 63
typedef void (*schedulerFetchFp)(void* pResult, void* param, int32_t code);
typedef bool (*schedulerChkKillFp)(void* param);
D
dapan1121 已提交
64

D
dapan1121 已提交
65
typedef struct SSchedulerReq {
D
dapan1121 已提交
66
  bool                  syncReq;
H
Haojun Liao 已提交
67
  bool                  localReq;
D
dapan1121 已提交
68 69 70
  SRequestConnInfo     *pConn;
  SArray               *pNodeList;
  SQueryPlan           *pDag;
71
  int64_t               allocatorRefId;
D
dapan1121 已提交
72 73
  const char           *sql;
  int64_t               startTs;
D
dapan1121 已提交
74
  schedulerExecFp       execFp;
D
dapan1121 已提交
75 76
  schedulerFetchFp      fetchFp;
  void*                 cbParam;
D
dapan1121 已提交
77 78
  schedulerChkKillFp    chkKillFp;
  void*                 chkKillParam;
D
dapan1121 已提交
79
  SExecResult*          pExecRes;
D
dapan1121 已提交
80
  void**                pFetchRes;
D
dapan1121 已提交
81 82
} SSchedulerReq;

D
dapan1121 已提交
83

D
dapan1121 已提交
84
int32_t schedulerInit(void);
D
dapan1121 已提交
85

D
dapan1121 已提交
86
int32_t schedulerExecJob(SSchedulerReq *pReq, int64_t *pJob);
D
dapan1121 已提交
87

D
dapan1121 已提交
88
int32_t schedulerFetchRows(int64_t jobId, SSchedulerReq *pReq);
89

D
dapan1121 已提交
90
void schedulerFetchRowsA(int64_t job, schedulerFetchFp fp, void* param);
D
dapan1121 已提交
91

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

D
dapan1121 已提交
94 95
void schedulerStopQueryHb(void *pTrans);

D
dapan1121 已提交
96 97
int32_t schedulerUpdatePolicy(int32_t policy);
int32_t schedulerEnableReSchedule(bool enableResche);
98 99 100 101 102 103

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

H
Haojun Liao 已提交
106 107 108 109
/**
 * Free the query job
 * @param pJob
 */
D
dapan1121 已提交
110
void schedulerFreeJob(int64_t* job, int32_t errCode);
D
dapan1121 已提交
111

D
dapan1121 已提交
112 113
void schedulerDestroy(void);

D
dapan1121 已提交
114
void schdExecCallback(SExecResult* pResult, void* param, int32_t code);
D
dapan1121 已提交
115

H
refact  
Hongze Cheng 已提交
116 117 118 119
#ifdef __cplusplus
}
#endif

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