query.h 8.9 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

S
Shengliang Guan 已提交
28
typedef 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,
S
Shengliang Guan 已提交
38
} EJobTaskType;
D
dapan1121 已提交
39

S
Shengliang Guan 已提交
40
typedef enum {
D
dapan1121 已提交
41 42
  TASK_TYPE_PERSISTENT = 1,
  TASK_TYPE_TEMP,
S
Shengliang Guan 已提交
43
} ETaskType;
D
dapan1121 已提交
44

D
dapan1121 已提交
45
typedef struct STableComInfo {
46 47 48 49
  uint8_t  numOfTags;     // the number of tags in schema
  uint8_t  precision;     // the number of precision
  col_id_t numOfColumns;  // the number of columns
  int32_t  rowSize;       // row size of the schema
D
dapan1121 已提交
50 51
} STableComInfo;

D
dapan1121 已提交
52 53
typedef struct SIndexMeta {

wafwerar's avatar
wafwerar 已提交
54 55 56 57
#ifdef WINDOWS
  size_t avoidCompilationErrors;
#endif

D
dapan1121 已提交
58 59
} SIndexMeta;

D
dapan1121 已提交
60

D
dapan1121 已提交
61 62 63 64 65 66
/*
 * 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 {
L
Liu Jicong 已提交
67
  int32_t  vgId : 24;
D
dapan1121 已提交
68 69 70 71 72 73
  int8_t   tableType;
  uint64_t uid;
  uint64_t suid;
} SCTableMeta;

/*
L
Liu Jicong 已提交
74 75
 * Note that the first 24 bytes of STableMeta are identical to SCTableMeta, it is safe to cast a STableMeta to be a
 * SCTableMeta.
D
dapan1121 已提交
76 77
 */
typedef struct STableMeta {
L
Liu Jicong 已提交
78 79 80 81 82 83 84 85 86 87 88 89 90
  // 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[];
D
dapan1121 已提交
91 92
} STableMeta;

D
dapan1121 已提交
93
typedef struct SDBVgInfo {
L
Liu Jicong 已提交
94
  int32_t   vgVersion;
95
  int8_t    hashMethod;
D
dapan 已提交
96
  int32_t   numOfTable;  // DB's table num, unit is TSDB_TABLE_NUM_UNIT
D
dapan1121 已提交
97
  SHashObj *vgHash;  //key:vgId, value:SVgroupInfo
D
dapan1121 已提交
98
} SDBVgInfo;
D
dapan1121 已提交
99 100

typedef struct SUseDbOutput {
L
Liu Jicong 已提交
101 102 103
  char       db[TSDB_DB_FNAME_LEN];
  uint64_t   dbId;
  SDBVgInfo* dbVgroup;
D
dapan1121 已提交
104 105
} SUseDbOutput;

L
Liu Jicong 已提交
106
enum { META_TYPE_NULL_TABLE = 1, META_TYPE_CTABLE, META_TYPE_TABLE, META_TYPE_BOTH_TABLE };
D
dapan1121 已提交
107

D
dapan1121 已提交
108
typedef struct STableMetaOutput {
D
dapan1121 已提交
109
  int32_t     metaType;
D
dapan1121 已提交
110
  uint64_t    dbId;
D
dapan1121 已提交
111 112 113
  char        dbFName[TSDB_DB_FNAME_LEN];
  char        ctbName[TSDB_TABLE_NAME_LEN];
  char        tbName[TSDB_TABLE_NAME_LEN];
D
dapan1121 已提交
114
  SCTableMeta ctbMeta;
L
Liu Jicong 已提交
115
  STableMeta* tbMeta;
D
dapan1121 已提交
116
} STableMetaOutput;
D
dapan1121 已提交
117

L
Liu Jicong 已提交
118
typedef struct SDataBuf {
L
Liu Jicong 已提交
119 120 121
  void*    pData;
  uint32_t len;
  void*    handle;
L
Liu Jicong 已提交
122 123 124 125 126 127
} 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 {
L
Liu Jicong 已提交
128 129 130 131 132 133
  __async_send_cb_fn_t fp;  // async callback function
  void*                param;
  uint64_t             requestId;
  uint64_t             requestObjRefId;
  int32_t              msgType;
  SDataBuf             msgInfo;
L
Liu Jicong 已提交
134 135
} SMsgSendInfo;

D
dapan1121 已提交
136
typedef struct SQueryNodeStat {
D
dapan 已提交
137
  int32_t tableNum; // vg table number, unit is TSDB_TABLE_NUM_UNIT
D
dapan1121 已提交
138 139
} SQueryNodeStat;

L
Liu Jicong 已提交
140 141 142 143 144 145 146 147 148 149 150 151
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 已提交
152
int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo, bool persistHandle, void *ctx);
D
dapan1121 已提交
153

L
Liu Jicong 已提交
154 155 156 157 158 159 160 161 162
/**
 * Asynchronously send message to server, after the response received, the callback will be incured.
 *
 * @param pTransporter
 * @param epSet
 * @param pTransporterId
 * @param pInfo
 * @return
 */
L
Liu Jicong 已提交
163
int32_t asyncSendMsgToServer(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo);
L
Liu Jicong 已提交
164

L
Liu Jicong 已提交
165
int32_t queryBuildUseDbOutput(SUseDbOutput* pOut, SUseDbRsp* usedbRsp);
X
Xiaoyu Wang 已提交
166

167
void initQueryModuleMsgHandle();
D
dapan1121 已提交
168

L
Liu Jicong 已提交
169
const SSchema* tGetTbnameColumnSchema();
L
Liu Jicong 已提交
170
bool           tIsValidSchema(struct SSchema* pSchema, int32_t numOfCols, int32_t numOfTags);
L
Liu Jicong 已提交
171

L
Liu Jicong 已提交
172
int32_t queryCreateTableMetaFromMsg(STableMetaRsp* msg, bool isSuperTable, STableMeta** pMeta);
D
dapan1121 已提交
173
char *jobTaskStatusStr(int32_t status);
D
dapan1121 已提交
174

175
SSchema createSchema(int8_t type, int32_t bytes, col_id_t colId, const char* name);
D
dapan1121 已提交
176

L
Liu Jicong 已提交
177 178
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);
D
dapan1121 已提交
179

L
Liu Jicong 已提交
180 181 182
#define SET_META_TYPE_NULL(t)       (t) = META_TYPE_NULL_TABLE
#define SET_META_TYPE_CTABLE(t)     (t) = META_TYPE_CTABLE
#define SET_META_TYPE_TABLE(t)      (t) = META_TYPE_TABLE
D
dapan1121 已提交
183 184
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE

D
dapan 已提交
185
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID || (_code) == TSDB_CODE_VND_TB_NOT_EXIST)
D
dapan1121 已提交
186 187 188
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED)
#define NEED_CLIENT_HANDLE_ERROR(_code) (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
D
dapan 已提交
189

D
dapan1121 已提交
190
#define NEED_SCHEDULER_RETRY_ERROR(_code) ((_code) == TSDB_CODE_RPC_REDIRECT || (_code) == TSDB_CODE_RPC_NETWORK_UNAVAIL)
D
dapan1121 已提交
191

D
dapan1121 已提交
192
#define REQUEST_MAX_TRY_TIMES 5
D
dapan1121 已提交
193

L
Liu Jicong 已提交
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235
#define qFatal(...)                                                     \
  do {                                                                  \
    if (qDebugFlag & DEBUG_FATAL) {                                     \
      taosPrintLog("QRY FATAL ", DEBUG_FATAL, qDebugFlag, __VA_ARGS__); \
    }                                                                   \
  } while (0)
#define qError(...)                                                     \
  do {                                                                  \
    if (qDebugFlag & DEBUG_ERROR) {                                     \
      taosPrintLog("QRY ERROR ", DEBUG_ERROR, qDebugFlag, __VA_ARGS__); \
    }                                                                   \
  } while (0)
#define qWarn(...)                                                    \
  do {                                                                \
    if (qDebugFlag & DEBUG_WARN) {                                    \
      taosPrintLog("QRY WARN ", DEBUG_WARN, qDebugFlag, __VA_ARGS__); \
    }                                                                 \
  } while (0)
#define qInfo(...)                                               \
  do {                                                           \
    if (qDebugFlag & DEBUG_INFO) {                               \
      taosPrintLog("QRY ", DEBUG_INFO, qDebugFlag, __VA_ARGS__); \
    }                                                            \
  } while (0)
#define qDebug(...)                                               \
  do {                                                            \
    if (qDebugFlag & DEBUG_DEBUG) {                               \
      taosPrintLog("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \
    }                                                             \
  } while (0)
#define qTrace(...)                                               \
  do {                                                            \
    if (qDebugFlag & DEBUG_TRACE) {                               \
      taosPrintLog("QRY ", DEBUG_TRACE, qDebugFlag, __VA_ARGS__); \
    }                                                             \
  } while (0)
#define qDebugL(...)                                                     \
  do {                                                                   \
    if (qDebugFlag & DEBUG_DEBUG) {                                      \
      taosPrintLongString("QRY ", DEBUG_DEBUG, qDebugFlag, __VA_ARGS__); \
    }                                                                    \
  } while (0)
D
dapan1121 已提交
236

D
dapan1121 已提交
237 238 239 240 241
#define QRY_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define QRY_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
#define QRY_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)


D
dapan1121 已提交
242 243 244 245
#ifdef __cplusplus
}
#endif

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