CUBRID Engine
latest
Main Page
Namespaces
Classes
Files
File List
File Members
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
;
58
struct
t_io_buffer
59
{
60
int
length
;
61
62
int
offset
;
63
char
*
data
;
64
};
65
66
enum
E_PROXY_EVENT
67
{
68
PROXY_EVENT_IO_READ
= 0,
69
PROXY_EVENT_IO_WRITE
= 1,
70
PROXY_EVENT_CLIENT_REQUEST
= 2,
71
PROXY_EVENT_CAS_RESPONSE
= 3,
72
PROXY_EVENT_CLIENT_CONN_ERROR
= 4,
73
PROXY_EVENT_CAS_CONN_ERROR
= 5,
74
PROXY_EVENT_CLIENT_WAKEUP_BY_SHARD
= 6,
75
PROXY_EVENT_CLIENT_WAKEUP_BY_STATEMENT
= 7
76
};
77
78
typedef
struct
t_proxy_event
T_PROXY_EVENT
;
79
struct
t_proxy_event
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
91
T_IO_BUFFER
buffer
;
92
};
93
94
typedef
struct
t_wait_context
T_WAIT_CONTEXT
;
95
struct
t_wait_context
96
{
97
int
ctx_cid
;
98
int
ctx_uid
;
99
time_t
expire_time
;
100
};
101
102
enum
T_SOCKET_IO_STATUS
103
{
104
SOCK_IO_IDLE
= 0,
105
SOCK_IO_REG_WAIT
= 1,
106
SOCK_IO_ESTABLISHED
= 2,
107
SOCK_IO_CLOSE_WAIT
= 3
108
};
109
110
typedef
struct
t_socket_io
T_SOCKET_IO
;
111
struct
t_socket_io
112
{
113
SOCKET
fd
;
114
int
status
;
115
int
ip_addr
;
116
117
bool
from_cas
;
118
union
119
{
120
int
client_id
;
121
struct
122
{
123
int
shard_id
;
124
int
cas_id
;
125
} shard;
126
}
id
;
127
128
T_PROXY_EVENT
*
read_event
;
129
T_PROXY_EVENT
*
write_event
;
130
};
131
132
typedef
struct
t_socket_io_global
T_SOCKET_IO_GLOBAL
;
133
struct
t_socket_io_global
134
{
135
int
max_socket
;
136
int
cur_socket
;
137
138
T_SOCKET_IO
*
ent
;
139
};
140
141
142
typedef
struct
t_client_io
T_CLIENT_IO
;
143
struct
t_client_io
144
{
145
int
client_id
;
146
bool
is_busy
;
147
148
SOCKET
fd
;
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
158
typedef
struct
t_client_io_global
T_CLIENT_IO_GLOBAL
;
159
struct
t_client_io_global
160
{
161
int
max_client
;
162
int
cur_client
;
163
int
max_context
;
164
165
T_SHARD_CQUEUE
freeq
;
166
T_CLIENT_IO
*
ent
;
167
};
168
169
enum
T_CAS_IO_STATUS
170
{
171
CAS_IO_NOT_CONNECTED
= 0,
172
CAS_IO_CONNECTED
= 1,
173
CAS_IO_CLOSE_WAIT
= 2
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
;
183
bool
is_in_tran
;
184
185
int
ctx_cid
;
186
unsigned
int
ctx_uid
;
187
188
SOCKET
fd
;
189
190
/* send queue ? */
191
};
192
193
typedef
struct
t_shard_io
T_SHARD_IO
;
194
struct
t_shard_io
195
{
196
int
shard_id
;
197
198
int
max_num_cas
;
199
int
cur_num_cas
;
200
201
int
num_cas_in_tran
;
202
203
T_SHARD_QUEUE
waitq
;
204
T_CAS_IO
*
ent
;
205
};
206
207
typedef
struct
t_shard_io_global
T_SHARD_IO_GLOBAL
;
208
struct
t_shard_io_global
209
{
210
int
max_shard
;
211
212
T_SHARD_IO
*
ent
;
213
};
214
215
typedef
struct
t_context_stmt
T_CONTEXT_STMT
;
216
struct
t_context_stmt
217
{
218
T_CONTEXT_STMT
*
next
;
219
int
stmt_h_id
;
220
};
221
222
typedef
struct
t_proxy_context
T_PROXY_CONTEXT
;
223
struct
t_proxy_context
224
{
225
int
cid
;
/* context id */
226
unsigned
int
uid
;
/* unique id */
227
228
/* flags */
229
bool
is_busy
;
230
bool
is_in_tran
;
231
bool
is_prepare_for_execute
;
232
bool
free_on_end_tran
;
233
bool
free_on_client_io_write
;
234
bool
free_context
;
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 */
239
bool
waiting_dummy_prepare
;
240
bool
dont_free_statement
;
241
242
/* context */
243
T_PROXY_EVENT
*
waiting_event
;
244
int
func_code
;
245
int
stmt_h_id
;
246
int
stmt_hint_type
;
247
T_SHARD_STMT
*
prepared_stmt
;
248
int
wait_timeout
;
249
250
/* connection info */
251
bool
is_connected
;
252
char
database_user
[
SRV_CON_DBUSER_SIZE
];
253
char
database_passwd
[
SRV_CON_DBPASSWD_SIZE
];
254
255
/* statement list */
256
T_CONTEXT_STMT
*
stmt_list
;
257
258
/* client, shard/cas */
259
int
client_id
;
260
int
shard_id
;
261
int
cas_id
;
262
263
/* error */
264
int
error_ind
;
265
int
error_code
;
266
char
error_msg[256];
267
};
268
269
typedef
struct
t_proxy_context_global
T_PROXY_CONTEXT_GLOBAL
;
270
struct
t_proxy_context_global
271
{
272
int
size
;
273
274
T_SHARD_CQUEUE
freeq
;
275
T_PROXY_CONTEXT
*
ent
;
276
};
277
278
typedef
struct
t_proxy_handler
T_PROXY_HANDLER
;
279
struct
t_proxy_handler
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
287
T_SHARD_QUEUE
cas_rcv_q
;
288
T_SHARD_QUEUE
cli_ret_q
;
289
T_SHARD_QUEUE
cli_rcv_q
;
290
};
291
292
#endif
/* _SHARD_PROXY_COMMON_H_ */
shard_proxy_queue.h
t_proxy_handler::cli_ret_q
T_SHARD_QUEUE cli_ret_q
Definition:
shard_proxy_common.h:288
T_SOCKET_IO_STATUS
T_SOCKET_IO_STATUS
Definition:
shard_proxy_common.h:102
T_CAS_IO_STATUS
T_CAS_IO_STATUS
Definition:
shard_proxy_common.h:169
t_proxy_context::stmt_h_id
int stmt_h_id
Definition:
shard_proxy_common.h:245
t_shard_io_global::ent
T_SHARD_IO * ent
Definition:
shard_proxy_common.h:212
t_client_io_global::max_context
int max_context
Definition:
shard_proxy_common.h:163
t_cas_io::cas_id
int cas_id
Definition:
shard_proxy_common.h:181
SOCKET
int SOCKET
Definition:
porting.h:482
t_proxy_context::is_connected
bool is_connected
Definition:
shard_proxy_common.h:251
t_shard_io_global
Definition:
shard_proxy_common.h:208
SRV_CON_CLIENT_INFO_SIZE
#define SRV_CON_CLIENT_INFO_SIZE
Definition:
cas_protocol.h:34
t_proxy_context::is_cas_in_tran
bool is_cas_in_tran
Definition:
shard_proxy_common.h:238
t_proxy_event
Definition:
shard_proxy_common.h:79
shard_proxy_log.h
t_proxy_event::cid
int cid
Definition:
shard_proxy_common.h:84
t_proxy_context_global::ent
T_PROXY_CONTEXT * ent
Definition:
shard_proxy_common.h:275
CAS_IO_CONNECTED
Definition:
shard_proxy_common.h:172
t_proxy_context::cas_id
int cas_id
Definition:
shard_proxy_common.h:261
t_proxy_context::free_context
bool free_context
Definition:
shard_proxy_common.h:234
t_proxy_context
Definition:
shard_proxy_common.h:223
t_cas_io::fd
SOCKET fd
Definition:
shard_proxy_common.h:188
t_proxy_handler
Definition:
shard_proxy_common.h:279
porting.h
PROXY_EVENT_IO_WRITE
Definition:
shard_proxy_common.h:69
SOCK_IO_REG_WAIT
Definition:
shard_proxy_common.h:105
t_shard_io::max_num_cas
int max_num_cas
Definition:
shard_proxy_common.h:198
PROXY_EVENT_CLIENT_WAKEUP_BY_SHARD
Definition:
shard_proxy_common.h:74
t_proxy_event::buffer
T_IO_BUFFER buffer
Definition:
shard_proxy_common.h:91
t_proxy_event::shard_id
int shard_id
Definition:
shard_proxy_common.h:88
t_socket_io::from_cas
bool from_cas
Definition:
shard_proxy_common.h:117
t_proxy_handler::cli_rcv_q
T_SHARD_QUEUE cli_rcv_q
Definition:
shard_proxy_common.h:289
PROXY_EVENT_CLIENT_REQUEST
Definition:
shard_proxy_common.h:70
SRV_CON_DBPASSWD_SIZE
#define SRV_CON_DBPASSWD_SIZE
Definition:
cas_protocol.h:56
t_proxy_context::client_id
int client_id
Definition:
shard_proxy_common.h:259
t_proxy_context::is_in_tran
bool is_in_tran
Definition:
shard_proxy_common.h:230
t_context_stmt::next
T_CONTEXT_STMT * next
Definition:
shard_proxy_common.h:218
t_client_io_global::ent
T_CLIENT_IO * ent
Definition:
shard_proxy_common.h:166
t_client_io_global::cur_client
int cur_client
Definition:
shard_proxy_common.h:162
t_client_io::client_id
int client_id
Definition:
shard_proxy_common.h:145
t_shard_io::shard_id
int shard_id
Definition:
shard_proxy_common.h:196
t_client_io
Definition:
shard_proxy_common.h:143
t_proxy_handler::state
unsigned char state
Definition:
shard_proxy_common.h:282
t_proxy_context_global::freeq
T_SHARD_CQUEUE freeq
Definition:
shard_proxy_common.h:274
t_proxy_context::prepared_stmt
T_SHARD_STMT * prepared_stmt
Definition:
shard_proxy_common.h:247
memory_hash.h
t_proxy_context::stmt_list
T_CONTEXT_STMT * stmt_list
Definition:
shard_proxy_common.h:256
t_shard_cqueue
Definition:
shard_proxy_queue.h:55
t_proxy_context::free_on_client_io_write
bool free_on_client_io_write
Definition:
shard_proxy_common.h:233
SOCK_IO_ESTABLISHED
Definition:
shard_proxy_common.h:106
t_context_stmt::stmt_h_id
int stmt_h_id
Definition:
shard_proxy_common.h:219
PROXY_EVENT_CLIENT_WAKEUP_BY_STATEMENT
Definition:
shard_proxy_common.h:75
t_socket_io_global::ent
T_SOCKET_IO * ent
Definition:
shard_proxy_common.h:138
t_socket_io_global::max_socket
int max_socket
Definition:
shard_proxy_common.h:135
shard_statement.h
t_proxy_handler::cas_rcv_q
T_SHARD_QUEUE cas_rcv_q
Definition:
shard_proxy_common.h:287
t_proxy_context::stmt_hint_type
int stmt_hint_type
Definition:
shard_proxy_common.h:246
t_context_stmt
Definition:
shard_proxy_common.h:216
t_wait_context::ctx_uid
int ctx_uid
Definition:
shard_proxy_common.h:98
broker_shm.h
t_socket_io
Definition:
shard_proxy_common.h:111
t_socket_io_global::cur_socket
int cur_socket
Definition:
shard_proxy_common.h:136
t_client_io::ctx_cid
int ctx_cid
Definition:
shard_proxy_common.h:150
CAS_IO_NOT_CONNECTED
Definition:
shard_proxy_common.h:171
t_proxy_handler::thread_id
pthread_t thread_id
Definition:
shard_proxy_common.h:285
t_io_buffer::length
int length
Definition:
shard_proxy_common.h:60
t_socket_io::client_id
int client_id
Definition:
shard_proxy_common.h:120
SOCK_IO_IDLE
Definition:
shard_proxy_common.h:104
t_wait_context::expire_time
time_t expire_time
Definition:
shard_proxy_common.h:99
t_proxy_context_global::size
int size
Definition:
shard_proxy_common.h:272
t_socket_io_global
Definition:
shard_proxy_common.h:133
t_cas_io::shard_id
int shard_id
Definition:
shard_proxy_common.h:182
database_passwd
static char database_passwd[SRV_CON_DBPASSWD_SIZE]
Definition:
cas_execute.c:389
PROXY_EVENT_CLIENT_CONN_ERROR
Definition:
shard_proxy_common.h:72
t_shard_io::waitq
T_SHARD_QUEUE waitq
Definition:
shard_proxy_common.h:203
t_shard_stmt
Definition:
shard_statement.h:54
t_client_io::fd
SOCKET fd
Definition:
shard_proxy_common.h:148
t_socket_io::read_event
T_PROXY_EVENT * read_event
Definition:
shard_proxy_common.h:128
t_client_io_global::max_client
int max_client
Definition:
shard_proxy_common.h:161
t_cas_io::status
int status
Definition:
shard_proxy_common.h:179
PROXY_EVENT_IO_READ
Definition:
shard_proxy_common.h:68
t_proxy_context::error_ind
int error_ind
Definition:
shard_proxy_common.h:264
PROXY_EVENT_CAS_RESPONSE
Definition:
shard_proxy_common.h:71
t_socket_io::shard_id
int shard_id
Definition:
shard_proxy_common.h:123
t_proxy_event::from_cas
bool from_cas
Definition:
shard_proxy_common.h:82
t_shard_io::num_cas_in_tran
int num_cas_in_tran
Definition:
shard_proxy_common.h:201
t_socket_io::fd
SOCKET fd
Definition:
shard_proxy_common.h:113
t_proxy_event::type
unsigned short type
Definition:
shard_proxy_common.h:81
t_proxy_context::waiting_dummy_prepare
bool waiting_dummy_prepare
Definition:
shard_proxy_common.h:239
t_proxy_context::uid
unsigned int uid
Definition:
shard_proxy_common.h:226
t_shard_io::cur_num_cas
int cur_num_cas
Definition:
shard_proxy_common.h:199
t_cas_io::is_in_tran
bool is_in_tran
Definition:
shard_proxy_common.h:183
CAS_IO_CLOSE_WAIT
Definition:
shard_proxy_common.h:173
t_proxy_context::cid
int cid
Definition:
shard_proxy_common.h:225
t_proxy_context::error_code
int error_code
Definition:
shard_proxy_common.h:265
SRV_CON_DBUSER_SIZE
#define SRV_CON_DBUSER_SIZE
Definition:
cas_protocol.h:55
t_socket_io::cas_id
int cas_id
Definition:
shard_proxy_common.h:124
t_proxy_context::is_prepare_for_execute
bool is_prepare_for_execute
Definition:
shard_proxy_common.h:231
t_proxy_context::waiting_event
T_PROXY_EVENT * waiting_event
Definition:
shard_proxy_common.h:243
t_proxy_context::free_on_end_tran
bool free_on_end_tran
Definition:
shard_proxy_common.h:232
lockfree::tran::id
std::uint64_t id
Definition:
lockfree_transaction_def.hpp:33
t_proxy_event::cas_id
int cas_id
Definition:
shard_proxy_common.h:89
t_shard_io_global::max_shard
int max_shard
Definition:
shard_proxy_common.h:210
t_proxy_handler::shutdown
bool shutdown
Definition:
shard_proxy_common.h:283
t_wait_context
Definition:
shard_proxy_common.h:95
t_client_io::is_busy
bool is_busy
Definition:
shard_proxy_common.h:146
t_shard_io::ent
T_CAS_IO * ent
Definition:
shard_proxy_common.h:204
t_proxy_context::dont_free_statement
bool dont_free_statement
Definition:
shard_proxy_common.h:240
t_proxy_context_global
Definition:
shard_proxy_common.h:270
PROXY_EVENT_CAS_CONN_ERROR
Definition:
shard_proxy_common.h:73
t_proxy_context::wait_timeout
int wait_timeout
Definition:
shard_proxy_common.h:248
t_socket_io::ip_addr
int ip_addr
Definition:
shard_proxy_common.h:115
t_cas_io
Definition:
shard_proxy_common.h:177
database_user
static char database_user[SRV_CON_DBUSER_SIZE]
Definition:
cas_execute.c:388
t_cas_io::ctx_uid
unsigned int ctx_uid
Definition:
shard_proxy_common.h:186
t_proxy_event::uid
unsigned int uid
Definition:
shard_proxy_common.h:85
t_wait_context::ctx_cid
int ctx_cid
Definition:
shard_proxy_common.h:97
t_proxy_context::func_code
int func_code
Definition:
shard_proxy_common.h:244
E_PROXY_EVENT
E_PROXY_EVENT
Definition:
shard_proxy_common.h:66
t_proxy_handler::index
short index
Definition:
shard_proxy_common.h:281
SOCK_IO_CLOSE_WAIT
Definition:
shard_proxy_common.h:107
t_proxy_context::shard_id
int shard_id
Definition:
shard_proxy_common.h:260
t_socket_io::status
int status
Definition:
shard_proxy_common.h:114
t_proxy_context::is_busy
bool is_busy
Definition:
shard_proxy_common.h:229
t_io_buffer::offset
int offset
Definition:
shard_proxy_common.h:62
t_client_io_global
Definition:
shard_proxy_common.h:159
t_shard_queue
Definition:
shard_proxy_queue.h:45
t_io_buffer
Definition:
shard_proxy_common.h:58
t_cas_io::ctx_cid
int ctx_cid
Definition:
shard_proxy_common.h:185
t_shard_io
Definition:
shard_proxy_common.h:194
t_client_io::ctx_uid
unsigned int ctx_uid
Definition:
shard_proxy_common.h:151
t_client_io_global::freeq
T_SHARD_CQUEUE freeq
Definition:
shard_proxy_common.h:165
t_socket_io::write_event
T_PROXY_EVENT * write_event
Definition:
shard_proxy_common.h:129
t_proxy_context::is_client_in_tran
bool is_client_in_tran
Definition:
shard_proxy_common.h:235
t_io_buffer::data
char * data
Definition:
shard_proxy_common.h:63
src
broker
shard_proxy_common.h
Generated by
1.8.11