clientInt.h 5.3 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"
H
Hongze Cheng 已提交
25
#include "tmsg.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"
H
Haojun Liao 已提交
32
#include "query.h"
33 34

typedef struct SQueryExecMetric {
35 36 37 38
  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
39 40
} SQueryExecMetric;

41
typedef struct SInstanceSummary {
42 43 44 45 46 47 48 49 50 51
  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
52
} SInstanceSummary;
53 54 55 56 57 58 59

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

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

typedef struct SAppInfo {
  int64_t        startTime;
70
  char           appName[TSDB_APP_NAME_LEN];
71 72 73
  char          *ep;
  int32_t        pid;
  int32_t        numOfThreads;
H
Haojun Liao 已提交
74

75 76 77 78
  SHashObj      *pInstMap;
} SAppInfo;

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

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

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

101 102 103 104
  uint32_t     numOfRows;
  uint32_t     current;
} SReqResultInfo;

105 106 107 108 109 110 111
typedef struct SShowReqInfo {
  int64_t         execId;        // showId/queryId
  int32_t         vgId;
  SArray         *pArray;        // SArray<SVgroupInfo>
  int32_t         currentIndex;  // current accessed vgroup index.
} SShowReqInfo;

112 113 114
typedef struct SRequestSendRecvBody {
  tsem_t          rspSem;        // not used now
  void*           fp;
115
  SShowReqInfo    showInfo;      // todo this attribute will be removed after the query framework being completed.
116
  struct SSchJob *pQueryJob;     // query job, created according to sql query DAG.
117
  SDataBuf        requestMsg;
118 119
  SReqResultInfo  resInfo;
} SRequestSendRecvBody;
120

121 122
#define ERROR_MSG_BUF_DEFAULT_SIZE  512

123 124 125 126 127
typedef struct SRequestObj {
  uint64_t         requestId;
  int32_t          type;   // request type
  STscObj         *pTscObj;
  char            *sqlstr;  // sql string
X
Xiaoyu Wang 已提交
128
  int32_t          sqlLen;
129 130 131
  int64_t          self;
  char            *msgBuf;
  void            *pInfo;   // sql parse info, generated by parser module
132
  int32_t          code;
133
  uint64_t         affectedRows;  // todo remove it
H
Haojun Liao 已提交
134 135
  SQueryExecMetric metric;
  SRequestSendRecvBody body;
136 137
} SRequestObj;

138
extern SAppInfo appInfo;
H
Haojun Liao 已提交
139
extern int32_t  clientReqRefPool;
140
extern int32_t  clientConnRefPool;
141

H
Haojun Liao 已提交
142
extern int (*handleRequestRspFp[TDMT_MAX])(void*, const SDataBuf* pMsg, int32_t code);
H
Haojun Liao 已提交
143
int genericRspCallback(void* param, const SDataBuf* pMsg, int32_t code);
144
SMsgSendInfo* buildMsgInfoImpl(SRequestObj*);
145 146 147

int   taos_init();

148
void* createTscObj(const char* user, const char* auth, const char *db, SAppInstInfo* pAppInfo);
149
void  destroyTscObj(void*pObj);
150

151 152
uint64_t generateRequestId();

153 154 155 156 157
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);
158 159

void taos_init_imp(void);
H
Haojun Liao 已提交
160
int  taos_options_imp(TSDB_OPTION option, const char *str);
161

H
Haojun Liao 已提交
162
void* openTransporter(const char *user, const char *auth, int32_t numOfThreads);
163 164

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

166 167
void initMsgHandleFp();

168 169
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 已提交
170
void *doFetchRow(SRequestObj* pRequest);
171

H
Haojun Liao 已提交
172
void  setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t numOfCols, int32_t numOfRows);
173

174 175 176 177 178
#ifdef __cplusplus
}
#endif

#endif  // TDENGINE_CLIENTINT_H