query.h 5.5 KB
Newer Older
D
dapan1121 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

D
dapan1121 已提交
16 17
#ifndef _TD_QUERY_H_
#define _TD_QUERY_H_
D
dapan1121 已提交
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

D
dapan1121 已提交
23
#include "tarray.h"
24
#include "thash.h"
25
#include "tlog.h"
H
Haojun Liao 已提交
26
#include "tmsg.h"
D
dapan1121 已提交
27

D
dapan1121 已提交
28
enum {
D
dapan1121 已提交
29
  JOB_TASK_STATUS_NULL = 0,
D
dapan1121 已提交
30 31
  JOB_TASK_STATUS_NOT_START = 1,
  JOB_TASK_STATUS_EXECUTING,
D
dapan1121 已提交
32
  JOB_TASK_STATUS_PARTIAL_SUCCEED,
D
dapan1121 已提交
33 34 35
  JOB_TASK_STATUS_SUCCEED,
  JOB_TASK_STATUS_FAILED,
  JOB_TASK_STATUS_CANCELLING,
D
dapan1121 已提交
36 37
  JOB_TASK_STATUS_CANCELLED,
  JOB_TASK_STATUS_DROPPING,
D
dapan1121 已提交
38 39
};

D
dapan1121 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
typedef struct STableComInfo {
  uint8_t numOfTags;      // the number of tags in schema
  uint8_t precision;      // the number of precision
  int16_t numOfColumns;   // the number of columns
  int32_t rowSize;        // row size of the schema
} STableComInfo;

/*
 * ASSERT(sizeof(SCTableMeta) == 24)
 * ASSERT(tableType == TSDB_CHILD_TABLE)
 * The cached child table meta info. For each child table, 24 bytes are required to keep the essential table info.
 */
typedef struct SCTableMeta {
  int32_t  vgId:24;
  int8_t   tableType;
  uint64_t uid;
  uint64_t suid;
} SCTableMeta;

/*
 * Note that the first 24 bytes of STableMeta are identical to SCTableMeta, it is safe to cast a STableMeta to be a SCTableMeta.
 */
typedef struct STableMeta {
  //BEGIN: KEEP THIS PART SAME WITH SCTableMeta
  int32_t        vgId:24;
  int8_t         tableType;
  uint64_t       uid;
  uint64_t       suid;
  //END: KEEP THIS PART SAME WITH SCTableMeta
  
  // if the table is TSDB_CHILD_TABLE, the following information is acquired from the corresponding super table meta info
  int16_t        sversion;
  int16_t        tversion;
  STableComInfo  tableInfo;
  SSchema        schema[];
} STableMeta;

D
dapan1121 已提交
77
typedef struct SDBVgroupInfo {
D
dapan1121 已提交
78
  SRWLatch  lock;
D
dapan1121 已提交
79
  int64_t   dbId;
80 81 82
  int32_t   vgVersion;  
  int8_t    hashMethod;
  SHashObj *vgInfo;  //key:vgId, value:SVgroupInfo
D
dapan1121 已提交
83 84 85
} SDBVgroupInfo;

typedef struct SUseDbOutput {
86
  char db[TSDB_DB_FNAME_LEN];
87
  SDBVgroupInfo dbVgroup;
D
dapan1121 已提交
88 89
} SUseDbOutput;

D
dapan1121 已提交
90
enum {
D
dapan1121 已提交
91 92 93
  META_TYPE_NON_TABLE = 1,
  META_TYPE_CTABLE,
  META_TYPE_TABLE,
D
dapan1121 已提交
94
  META_TYPE_BOTH_TABLE
D
dapan1121 已提交
95 96
};

D
dapan1121 已提交
97

D
dapan1121 已提交
98
typedef struct STableMetaOutput {
D
dapan1121 已提交
99
  int32_t     metaType;
D
dapan1121 已提交
100
  char        ctbFname[TSDB_TABLE_FNAME_LEN];
H
Haojun Liao 已提交
101
  char        tbFname[TSDB_TABLE_FNAME_LEN];
D
dapan1121 已提交
102 103 104
  SCTableMeta ctbMeta;
  STableMeta *tbMeta;
} STableMetaOutput;
D
dapan1121 已提交
105

H
Haojun Liao 已提交
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
typedef struct SDataBuf {
  void     *pData;
  uint32_t  len;
} SDataBuf;

typedef int32_t (*__async_send_cb_fn_t)(void* param, const SDataBuf* pMsg, int32_t code);
typedef int32_t (*__async_exec_fn_t)(void* param);

typedef struct SMsgSendInfo {
  __async_send_cb_fn_t fp;        //async callback function
  void     *param;
  uint64_t  requestId;
  uint64_t  requestObjRefId;
  int32_t   msgType;
  SDataBuf  msgInfo;
} SMsgSendInfo;
H
Haojun Liao 已提交
122

X
Xiaoyu Wang 已提交
123 124 125 126 127 128 129
typedef struct SQueryNodeAddr{
  int32_t    nodeId; //vgId or qnodeId
  int8_t     inUse;
  int8_t     numOfEps;
  SEpAddrMsg epAddr[TSDB_MAX_REPLICA];
} SQueryNodeAddr;

H
Haojun Liao 已提交
130 131
bool tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);

H
Haojun Liao 已提交
132 133 134 135 136 137 138 139 140 141 142
int32_t initTaskQueue();
int32_t cleanupTaskQueue();

/**
 *
 * @param execFn      The asynchronously execution function
 * @param execParam   The parameters of the execFn
 * @param code        The response code during execution the execFn
 * @return
 */
int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code);
D
dapan1121 已提交
143

144 145 146 147 148 149 150 151 152
/**
 * Asynchronously send message to server, after the response received, the callback will be incured.
 *
 * @param pTransporter
 * @param epSet
 * @param pTransporterId
 * @param pInfo
 * @return
 */
H
Haojun Liao 已提交
153 154 155
int32_t asyncSendMsgToServer(void *pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo);

const SSchema* tGetTbnameColumnSchema();
156
void initQueryModuleMsgHandle();
D
dapan1121 已提交
157

H
Hongze Cheng 已提交
158 159
extern int32_t (*queryBuildMsg[TDMT_MAX])(void* input, char **msg, int32_t msgSize, int32_t *msgLen);
extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char *msg, int32_t msgSize);
160

D
dapan1121 已提交
161 162 163 164 165
#define SET_META_TYPE_NONE(t) (t) = META_TYPE_NON_TABLE
#define SET_META_TYPE_CTABLE(t) (t) = META_TYPE_CTABLE
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE

166 167 168 169 170 171 172 173
#define qFatal(...)  do { if (qDebugFlag & DEBUG_FATAL) { taosPrintLog("QRY FATAL ", qDebugFlag, __VA_ARGS__); }} while(0)
#define qError(...)  do { if (qDebugFlag & DEBUG_ERROR) { taosPrintLog("QRY ERROR ", qDebugFlag, __VA_ARGS__); }} while(0)
#define qWarn(...)   do { if (qDebugFlag & DEBUG_WARN)  { taosPrintLog("QRY WARN ", qDebugFlag, __VA_ARGS__); }}  while(0)
#define qInfo(...)   do { if (qDebugFlag & DEBUG_INFO)  { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
#define qDebug(...)  do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
#define qTrace(...)  do { if (qDebugFlag & DEBUG_TRACE) { taosPrintLog("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)
#define qDebugL(...) do { if (qDebugFlag & DEBUG_DEBUG) { taosPrintLongString("QRY ", qDebugFlag, __VA_ARGS__); }} while(0)

D
dapan1121 已提交
174 175 176 177 178

#ifdef __cplusplus
}
#endif

D
dapan1121 已提交
179
#endif /*_TD_QUERY_H_*/