CUBRID Engine  latest
shard_proxy_common.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * shard_proxy_common.h -
22  *
23  */
24 
25 #ifndef _SHARD_PROXY_COMMON_H_
26 #define _SHARD_PROXY_COMMON_H_
27 
28 #ident "$Id$"
29 
30 #include "porting.h"
31 #include "broker_shm.h"
32 #include "shard_proxy_queue.h"
33 #include "shard_proxy_log.h"
34 #include "memory_hash.h"
35 #include "shard_statement.h"
36 
37 #if defined(WINDOWS)
38 #define MAX_FD 1024
39 #else /* WINDOWS */
40 #if !defined(LINUX)
41 #undef MAX_FD
42 #define MAX_FD FD_SETSIZE
43 #endif /* !LINUX */
44 #endif /* !WINDOWS */
45 
46 #define PROXY_INVALID_ID (-1)
47 #define PROXY_INVALID_SHARD (PROXY_INVALID_ID)
48 #define PROXY_INVALID_CAS (PROXY_INVALID_ID)
49 #define PROXY_INVALID_CLIENT (PROXY_INVALID_ID)
50 #define PROXY_INVALID_FUNC_CODE (-1)
51 #define PROXY_INVALID_CONTEXT (-1)
52 
53 #define PROXY_EVENT_NULL_BUFFER (NULL)
54 #define PROXY_EVENT_FROM_CAS (true)
55 #define PROXY_EVENT_FROM_CLIENT (false)
56 
57 typedef struct t_io_buffer T_IO_BUFFER;
59 {
60  int length;
61 
62  int offset;
63  char *data;
64 };
65 
67 {
76 };
77 
80 {
81  unsigned short type;
82  bool from_cas;
83 
84  int cid;
85  unsigned int uid;
86 
87  /* for EVENT_WAKEUP_BY_SHARD */
88  int shard_id;
89  int cas_id;
90 
92 };
93 
96 {
97  int ctx_cid;
98  int ctx_uid;
99  time_t expire_time;
100 };
101 
103 {
108 };
109 
110 typedef struct t_socket_io T_SOCKET_IO;
112 {
114  int status;
115  int ip_addr;
116 
117  bool from_cas;
118  union
119  {
121  struct
122  {
123  int shard_id;
124  int cas_id;
125  } shard;
126  } id;
127 
130 };
131 
134 {
137 
139 };
140 
141 
142 typedef struct t_client_io T_CLIENT_IO;
144 {
146  bool is_busy;
147 
149 
150  int ctx_cid;
151  unsigned int ctx_uid;
152 
153  char driver_info[SRV_CON_CLIENT_INFO_SIZE];
154 
155  /* send queue ? */
156 };
157 
160 {
164 
167 };
168 
170 {
174 };
175 
176 typedef struct t_cas_io T_CAS_IO;
177 struct t_cas_io
178 {
179  int status;
180 
181  int cas_id;
182  int shard_id;
184 
185  int ctx_cid;
186  unsigned int ctx_uid;
187 
189 
190  /* send queue ? */
191 };
192 
193 typedef struct t_shard_io T_SHARD_IO;
195 {
196  int shard_id;
197 
200 
202 
205 };
206 
209 {
211 
213 };
214 
217 {
220 };
221 
224 {
225  int cid; /* context id */
226  unsigned int uid; /* unique id */
227 
228  /* flags */
229  bool is_busy;
235  bool is_client_in_tran; /* it is only for faking cas status when check_cas is requested. after completion
236  * dummy prepare, context status will be out_tran. In this case we should fake
237  * transaction status to in_tran. */
238  bool is_cas_in_tran; /* cas transaction status */
241 
242  /* context */
249 
250  /* connection info */
254 
255  /* statement list */
257 
258  /* client, shard/cas */
260  int shard_id;
261  int cas_id;
262 
263  /* error */
266  char error_msg[256];
267 };
268 
271 {
272  int size;
273 
276 };
277 
280 {
281  short index; /* further use */
282  unsigned char state; /* further use */
283  bool shutdown; /* further use */
284 
285  pthread_t thread_id; /* further use */
286 
290 };
291 
292 #endif /* _SHARD_PROXY_COMMON_H_ */
T_SHARD_QUEUE cli_ret_q
T_SOCKET_IO_STATUS
T_CAS_IO_STATUS
int SOCKET
Definition: porting.h:482
#define SRV_CON_CLIENT_INFO_SIZE
Definition: cas_protocol.h:34
T_IO_BUFFER buffer
T_SHARD_QUEUE cli_rcv_q
#define SRV_CON_DBPASSWD_SIZE
Definition: cas_protocol.h:56
T_CONTEXT_STMT * next
unsigned char state
T_SHARD_STMT * prepared_stmt
T_CONTEXT_STMT * stmt_list
T_SHARD_QUEUE cas_rcv_q
static char database_passwd[SRV_CON_DBPASSWD_SIZE]
Definition: cas_execute.c:389
T_SHARD_QUEUE waitq
T_PROXY_EVENT * read_event
unsigned short type
#define SRV_CON_DBUSER_SIZE
Definition: cas_protocol.h:55
T_PROXY_EVENT * waiting_event
T_CAS_IO * ent
static char database_user[SRV_CON_DBUSER_SIZE]
Definition: cas_execute.c:388
unsigned int ctx_uid
unsigned int uid
E_PROXY_EVENT
unsigned int ctx_uid
T_PROXY_EVENT * write_event