clientInt.h 5.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * 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 TDENGINE_CLIENTINT_H
#define TDENGINE_CLIENTINT_H

#ifdef __cplusplus
extern "C" {
#endif

#include "taos.h"
H
Haojun Liao 已提交
24
#include "common.h"
25
#include "taosmsg.h"
26 27
#include "tdef.h"
#include "tep.h"
28 29
#include "thash.h"
#include "tlist.h"
30
#include "tmsgtype.h"
31
#include "trpc.h"
32 33

typedef struct SQueryExecMetric {
34 35 36 37
  int64_t      start;    // start timestamp
  int64_t      parsed;   // start to parse
  int64_t      send;     // start to send to server
  int64_t      rsp;      // receive response from server
38 39
} SQueryExecMetric;

40
typedef struct SInstanceSummary {
41 42 43 44 45 46 47 48 49 50
  uint64_t     numOfInsertsReq;
  uint64_t     numOfInsertRows;
  uint64_t     insertElapsedTime;
  uint64_t     insertBytes;         // submit to tsdb since launched.

  uint64_t     fetchBytes;
  uint64_t     queryElapsedTime;
  uint64_t     numOfSlowQueries;
  uint64_t     totalRequests;
  uint64_t     currentRequests;      // the number of SRequestObj
51
} SInstanceSummary;
52 53 54 55 56 57 58

typedef struct SHeartBeatInfo {
  void  *pTimer;   // timer, used to send request msg to mnode
} SHeartBeatInfo;

typedef struct SAppInstInfo {
  int64_t           numOfConns;
59
  SCorEpSet         mgmtEp;
60
  SInstanceSummary  summary;
61
  SList            *pConnList;  // STscObj linked list
H
Haojun Liao 已提交
62
  uint32_t          clusterId;
63
  void             *pTransporter;
64 65 66 67
} SAppInstInfo;

typedef struct SAppInfo {
  int64_t        startTime;
68
  char           appName[TSDB_APP_NAME_LEN];
69 70 71 72 73 74 75 76 77
  char          *ep;
  int32_t        pid;
  int32_t        numOfThreads;
  SHeartBeatInfo hb;
  SHashObj      *pInstMap;
} SAppInfo;

typedef struct STscObj {
  char               user[TSDB_USER_LEN];
78
  char               pass[TSDB_PASSWORD_LEN];
79
  char               db[TSDB_ACCT_ID_LEN + TSDB_DB_NAME_LEN];
H
Haojun Liao 已提交
80
  int32_t            acctId;
81 82
  uint32_t           connId;
  uint64_t           id;       // ref ID returned by taosAddRef
83
  void              *pTransporter;
84 85 86 87 88
  pthread_mutex_t    mutex;     // used to protect the operation on db
  int32_t            numOfReqs; // number of sqlObj from this tscObj
  SAppInstInfo      *pAppInfo;
} STscObj;

89 90
typedef struct SReqResultInfo {
  const char  *pRspMsg;
H
Haojun Liao 已提交
91 92
  const char  *pData;
  TAOS_FIELD  *fields;
93 94
  uint32_t     numOfCols;

H
Haojun Liao 已提交
95 96 97
  int32_t     *length;
  TAOS_ROW     row;
  char       **pCol;
98

99 100 101 102
  uint32_t     numOfRows;
  uint32_t     current;
} SReqResultInfo;

103 104
typedef struct SDataBuf {
  void     *pData;
105
  uint32_t  len;
106
} SDataBuf;
107 108 109 110 111

typedef struct SRequestSendRecvBody {
  tsem_t          rspSem;        // not used now
  void*           fp;
  int64_t         execId;        // showId/queryId
112
  SDataBuf        requestMsg;
113 114
  SReqResultInfo  resInfo;
} SRequestSendRecvBody;
115

116 117
#define ERROR_MSG_BUF_DEFAULT_SIZE  512

118 119 120 121 122 123
typedef struct SRequestObj {
  uint64_t         requestId;
  int32_t          type;   // request type
  STscObj         *pTscObj;
  SQueryExecMetric metric;
  char            *sqlstr;  // sql string
124
  SRequestSendRecvBody body;
125 126 127
  int64_t          self;
  char            *msgBuf;
  void            *pInfo;   // sql parse info, generated by parser module
128
  int32_t          code;
129 130
} SRequestObj;

131
typedef struct SRequestMsgBody {
132
  int32_t     msgType;
133
  SDataBuf    msgInfo;
134 135
  uint64_t    requestId;
  uint64_t    requestObjRefId;
136 137
} SRequestMsgBody;

138 139 140 141 142 143 144 145 146 147 148 149 150 151
typedef int (*__async_send_cb_fn_t)(void* param, const SDataBuf* pMsg, int32_t code);

typedef struct SMsgSendInfo {
  __async_send_cb_fn_t    fp;
  void    *param;
  uint64_t requestId;
  uint64_t requestObjRefId;
  int32_t  msgType;
  SDataBuf msgInfo;
} SMsgSendInfo;

extern SAppInfo appInfo;
extern int32_t  msgObjRefPool;
extern int32_t  clientConnRefPool;
152

153 154 155
SMsgSendInfo* buildSendMsgInfoImpl(SRequestObj *pRequest);
int genericExecCallback(void* param, const SDataBuf* pMsg, int32_t code);
extern int (*handleRequestRspFp[TSDB_MSG_TYPE_MAX])(void* param, const SDataBuf* pMsg, int32_t code);
156 157 158

int   taos_init();

159
void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo);
160
void  destroyTscObj(void*pObj);
161

162 163 164 165 166
void *createRequest(STscObj* pObj, __taos_async_fn_t fp, void* param, int32_t type);
void  destroyRequest(SRequestObj* pRequest);

char *getConnectionDB(STscObj* pObj);
void  setConnectionDB(STscObj* pTscObj, const char* db);
167 168

void taos_init_imp(void);
169
int taos_options_imp(TSDB_OPTION option, const char *str);
170

H
Haojun Liao 已提交
171
void* openTransporter(const char *user, const char *auth, int32_t numOfThreads);
172 173 174 175

void processMsgFromServer(void* parent, SRpcMsg* pMsg, SEpSet* pEpSet);
void initMsgHandleFp();

176
TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass, const char *auth, const char *db, uint16_t port);
H
Haojun Liao 已提交
177
TAOS_RES *taos_query_l(TAOS *taos, const char *sql, int sqlLen);
178

179
void* doFetchRow(SRequestObj* pRequest);
180
void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows);
181

182 183 184 185 186
#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_CLIENTINT_H