scheduler.h 3.3 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
typedef struct SSchedulerCfg {
D
dapan1121 已提交
29
  uint32_t maxJobNum;
D
dapan 已提交
30
  int32_t  maxNodeTableNum;
31 32
} SSchedulerCfg;

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

D
dapan1121 已提交
61 62 63 64 65
typedef struct SSchdFetchParam {
  void **pData;
  int32_t* code;
} SSchdFetchParam;

D
dapan1121 已提交
66
typedef void (*schedulerExecFp)(SExecResult* pResult, void* param, int32_t code);
D
dapan1121 已提交
67 68
typedef void (*schedulerFetchFp)(void* pResult, void* param, int32_t code);
typedef bool (*schedulerChkKillFp)(void* param);
D
dapan1121 已提交
69

D
dapan1121 已提交
70
typedef struct SSchedulerReq {
D
dapan1121 已提交
71
  bool                  syncReq;
D
dapan1121 已提交
72 73 74 75 76
  SRequestConnInfo     *pConn;
  SArray               *pNodeList;
  SQueryPlan           *pDag;
  const char           *sql;
  int64_t               startTs;
D
dapan1121 已提交
77
  schedulerExecFp       execFp;
D
dapan1121 已提交
78 79
  schedulerFetchFp      fetchFp;
  void*                 cbParam;
D
dapan1121 已提交
80 81
  schedulerChkKillFp    chkKillFp;
  void*                 chkKillParam;
D
dapan1121 已提交
82
  SExecResult*          pExecRes;
D
dapan1121 已提交
83
  void**                pFetchRes;
D
dapan1121 已提交
84 85
} SSchedulerReq;

D
dapan1121 已提交
86

D
dapan1121 已提交
87 88
int32_t schedulerInit(SSchedulerCfg *cfg);

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

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

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

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

D
dapan1121 已提交
97 98
void schedulerStopQueryHb(void *pTrans);

99 100 101 102 103 104

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

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

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

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

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

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