319 Commits

Author SHA1 Message Date
vraatikka
d2a61c3f82 Added some checks and renamed according to changes made in elsewhere. 2013-09-08 23:38:38 +03:00
vraatikka
e7e44667c3 Added some checks for return values. 2013-09-08 23:37:34 +03:00
vraatikka
a13396bc66 Renamed struct CLIENT_SESSION to ROUTER_CLIENT_SESSION as it is router related thing. Client session refers more to SESSION.
'dcb' to 'backend_dcb' because it is more accurate.
'client_session' to 'router_client_session'.

Renamed struct instance and type INSTANCE to router_instance and to ROUTER_INSTANCE.:
2013-09-08 23:32:53 +03:00
vraatikka
e40aace963 Renamed MySQLProtocol member 'descriptor' to 'owner_dcb'. 2013-09-08 23:31:05 +03:00
vraatikka
66e9be814b dcb.h
-------
Removed DCB states DCB_STATE_IDLE, and DCB_STATE_PROCESSING.
Added DCB_STATE_UNDEFINED for initial content for state variable which doesn't have any specific value set, and DCB_STATE_NOPOLLING to indicate that dcb has been removed from poll set.

Added following dcb roles: DCB_ROLE_SERVICE_LISTENER for listeners of services, and DCB_ROLE_REQUEST_HANDLER for client/backend dcbs. Listeners may have state DCB_STATE_LISTENING, but not DCB_STATE_POLLING. Request handlers may have DCB_STATE_POLLING but not DCB_STATE_LISTENING. Role is passed as an argument to dcb.c:dcb_alloc.

From now on, struct check numbers of DCB are included and checked in DEBUG build only.

Added dcb_role_t dcb_role-member to DCB as well as SPINLOCK dcb_initlock, which protects state changes.

Removed extern keyword from function declarations because functions are by default externally visible if they are declared in header.

dcb.b
------
Function dcb_set_state, and dcb_set_state_nomutex provide functions for changing dcb states. Latter implements a state machine for dcb.
Function dcb_add_to_zombieslist replaces dcb_free. It adds in atomic step dcb to zombieslist and changes state to DCB_STATE_ZOMBIE.
Function dcb_final_free removes dcb from allDCBs list, terminates router and client sessions, and frees dcb and related memory.
Function dcb_process_zombies removes executing thread from dcb's bitmask, and it there are no further thread bits, moves dcb to a victim list, and finally, for each dcb on victim list, closes fd and sets state to DCB_STATE_DISCONNECTED.
Function dcb_close sets dcb state to DCB_STATE_NOPOLLIN, removes dcb from poll set and sets bit to bitmask for each server thread in an atomic step.  

poll.c
------
Function poll_add_dcb sets either DCB_STATE_LISTENING or DCB_STATE_POLLING state for newly created dcb, depending whether the role of dcb is DCB_ROLE_SERVICE_LISTENER, or DCB_ROLE_REQUEST_HANDLER, respectively. Then dcb is set to poll set.

poll_waitevents : commented out code which skipped event if dcb was added to zombieslist or if fd was closed. Added state checks.

service.c : Minor changes.
httpd.c : Removed dcb state changes. They are done in core.
mysql_backend.c : Added checks, removed dcb state changes.
mysql_client.c : Removed dcb state changes. Added checks.
mysql_common.c : Minor changes
telnetd.c : Removed state changes. Replaced some typecasts and pointer references with local variable reads.
skygw_debug.h : Removed two states, and added two to state printing macro.
2013-09-05 22:00:02 +03:00
Massimiliano Pinto
b01cf2365e Added log error or ss_dassert instead of silent returning 2013-09-04 15:31:04 +02:00
Mark Riddoch
f74f67540f Added spinlock protection for the session association to the DCB and
reworked the reference count mechanism on the session.  Introduced a
FREE state for the session and alter the session destruction flow so
that we only remove the session when all the DCB's have singled they
have finished processing events for the DCB rather than when the first
thread decides to clsoe the DCB.
2013-09-04 12:24:59 +02:00
Massimiliano Pinto
8debc4433c Added a client NULL check in clientReply 2013-09-04 11:37:56 +02:00
Massimiliano Pinto
be27d36f8c Added dcb NULL check in mysql_send_custom_error() 2013-09-04 11:26:14 +02:00
Massimiliano Pinto
61df7eb07d Added checks against NULL in gw_read_backend_event for dcb->session and dcb->session->client 2013-09-04 10:57:08 +02:00
Massimiliano Pinto
8e97974216 Fixed return rc after:
routeQuery()
(dcb->func).close(dcb);

This will prevent setting again dcb->sate = DCB_STATE_POLLING in return_rc label.

The log entry for 

[gw_read_client_event] ioctl FIONREAD for fd 21 failed. errno 9, Bad file descriptor. dcb->state = 3

now is not present anymore.
2013-09-03 14:42:47 +02:00
Massimiliano Pinto
31cda5ad65 Added session refcount in session.h
The refcount is incremented in dcb_connect and in mysql_client.c after session_alloc
2013-09-02 10:26:34 +02:00
vraatikka
ce0085a078 Clean up. 2013-09-01 00:37:49 +03:00
vraatikka
757a043386 Replaced oinlined protocol creation with call to mysql_protocol_init. Clean up. 2013-09-01 00:36:31 +03:00
vraatikka
9df2040a8a Removed unused variables, changed call to mysql_protocol_init to reflect new prototype. 2013-09-01 00:32:57 +03:00
vraatikka
88ffcaa3d4 Removed 'extern' keyword from function declaration in headers. Functions are 'extern' by default.
Changed mysql_protocol_init prototype and implementation to return MySQLProtocol pointer instead of boolean.
2013-09-01 00:30:46 +03:00
vraatikka
9bf0f58526 introduce mysql_protocol_init. 2013-08-31 23:54:35 +03:00
vraatikka
3dff91e80f In gw_create_backend_connection, replaced inlined protocol init with call to mysql_protocol_init (mysql_common.c). Replaced fprintfs with logging commands. 2013-08-31 23:51:54 +03:00
vraatikka
c23168ed71 gw_do_connect_to_backend returned zero in case where connect failed with errno EINPROGRESS. Should have returned 1 to indicate that connection will be established asynchronously.
In the same case, checking for error by using getsockopt should be done when select returns, not after connect (man 2 connect).
2013-08-31 23:45:40 +03:00
vraatikka
9d6b13c288 Replaced macros with enumereted type. 2013-08-31 12:04:02 +03:00
Mark Riddoch
a445b6ff37 Fixes for NULL test for function returns such as malloc() - as reported by Coverity 2013-08-29 13:34:21 +02:00
vraatikka
527df6c7f3 Merge, mostly. 2013-08-28 23:26:09 +03:00
vraatikka
48165bf5cd Removed unused protocol_mutex and references to it. 2013-08-28 23:25:27 +03:00
vraatikka
50a3cfdf49 Commented out some dead code. 2013-08-28 23:17:18 +03:00
vraatikka
786468fc5d Added status checks, removed some dead code, changed macros to enumerated types, renamed variables to reflect better what they mean. 2013-08-28 22:59:53 +03:00
Massimiliano Pinto
ff109c6319 dcb->state set wheere missing or changed 2013-08-27 10:52:43 +02:00
Massimiliano Pinto
d0d68a69ca Added DCB_STATE_XXX in EPOLLIN/EPOLLOUT handlers and in accept() 2013-08-27 10:08:03 +02:00
vraatikka
49036894f5 In gw_connect_to_backend, first create socket, and establish socket connection, then in the end, dcb is added to epoll set. 2013-08-24 00:18:46 +03:00
vraatikka
df5f2f29b2 Removed undefined function declaration. Added trace and error log. 2013-08-23 23:25:12 +03:00
vraatikka
e345b23bcf Merge 2013-08-23 22:47:16 +03:00
vraatikka
0a182913a1 in gw_MySQLAccept moved authentication packet send before adding new dcb to epoll set. 2013-08-23 22:39:42 +03:00
vraatikka
0612dae890 Added error log printing. 2013-08-23 22:31:08 +03:00
Massimiliano Pinto
52c30c3e58 Removed dcb->state set after func.close() 2013-08-23 14:17:00 +02:00
vraatikka
68a5a389ee Removed SS_DEBUG macros around necessary include directives. 2013-08-23 13:42:10 +03:00
vraatikka
481096ccef Added trace log to newSession and to closeSession. 2013-08-22 10:46:14 +03:00
vraatikka
0401290021 Added spinlock ses_lock to struct SESSION to ensure that for each session closeSession is called only once.
closeSession is called from mysql_backend.c:gw_read_backend_event, and from dcb.c:dcb_close.

This is part of Bug #163.
2013-08-22 10:42:18 +03:00
vraatikka
8dfd5de923 Fix merge 2013-08-22 00:01:44 +03:00
Jan Lindström
b6ba1954f5 Merge 2013-08-19 08:48:33 +03:00
Mark Riddoch
2135a76f7b Bug 172 - Compile errors in Galera Monitor 2013-08-21 17:25:43 +02:00
Mark Riddoch
1a18632920 Move fprintf to log 2013-08-21 16:35:01 +02:00
Mark Riddoch
4e41fc49f5 Bug 166 - NULL pointer dereferenced if candidate server is NULL 2013-08-21 12:08:41 +02:00
Mark Riddoch
2499378af9 Bug 160 - fixed freeing of username 2013-08-21 12:06:31 +02:00
Massimiliano Pinto
73ffa5a648 dcb->data is allocated before poll_add_dcb in httpd_accept()
This will prevent dcb->data to be NULL with threads
2013-08-20 11:37:57 +02:00
vraatikka
21dabda848 Removed redundant log writings. 2013-08-20 10:49:35 +03:00
vraatikka
2ad0b12d79 Check dcb->status and set new state with writeqlock on. 2013-08-19 19:41:47 +03:00
vraatikka
ea79b38e4f Check return value of dcb_read and if it failed, don't access head of linked list. 2013-08-19 19:39:47 +03:00
Mark Riddoch
0021eddfee Bug 154 - Added warning if options are set for the read/write splitter and updated example config file. 2013-08-19 15:53:08 +02:00
vraatikka
05a3978442 Modified gw_read_client_event so that it only calls mysql_send_ok after new sessions has been set up and initialized. 2013-08-19 13:02:04 +03:00
vraatikka
97b3da1d79 Added simple_mutex_t dcb->mutex to DCB struct to protect processing of single dcb in poll.c:poll_waitevents. This is a coarse locking but seems to work with multiple threads at least with very simple load.
Added trace logging to many locations.
2013-08-16 23:52:10 +03:00
Mark Riddoch
fbc311730c Bug 124: Add log message when an invalid router option is supplied 2013-08-13 15:14:32 +02:00