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;
D
dapan1121 已提交
67 68 69
  SRequestConnInfo     *pConn;
  SArray               *pNodeList;
  SQueryPlan           *pDag;
70
  int64_t               allocatorRefId;
D
dapan1121 已提交
71 72
  const char           *sql;
  int64_t               startTs;
D
dapan1121 已提交
73
  schedulerExecFp       execFp;
D
dapan1121 已提交
74 75
  schedulerFetchFp      fetchFp;
  void*                 cbParam;
D
dapan1121 已提交
76 77
  schedulerChkKillFp    chkKillFp;
  void*                 chkKillParam;
D
dapan1121 已提交
78
  SExecResult*          pExecRes;
D
dapan1121 已提交
79
  void**                pFetchRes;
D
dapan1121 已提交
80 81
} SSchedulerReq;

D
dapan1121 已提交
82

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

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

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

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

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

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

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

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

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

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

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

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

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