543 Commits

Author SHA1 Message Date
vraatikka
15adf134c4 Defined LOGFILE_DEBUG for future use. If there will be separate logfile for debug output then macro will be removed. Currently equals with LOGFILE_TRACE. 2013-09-12 22:01:05 +03:00
vraatikka
3841f95531 In error cases, called close(fp). 2013-09-12 22:00:08 +03:00
Massimiliano Pinto
775b318889 Added constants to gw_decode_mysql_server_handshake
Check status of gw_read_backend_handshake and gw_send_authentication_to_backend in gw_read_backend_event
2013-09-12 16:08:31 +02:00
vraatikka
33fc1737d5 One uninitialized read in dcb_set_state_nomutex. One read of freed memory in dcb_process_zombies.
The former may have affected on the program behavior.
The latter left in many cases fds open and dcbs not freed for real.
2013-09-12 10:00:55 +03:00
Massimiliano Pinto
092795d95b in dcb_final_free the dcb->session NULL check protects the access to dcb->session->router_session and all the code below 2013-09-10 15:50:47 +02:00
Mark Riddoch
22e9fb9a4d Bug 194: Crash starting listener if protocol module load fails 2013-09-09 16:33:04 +02:00
vraatikka
6813f760a5 Fix for bug #205 - http://bugs.skysql.com/show_bug.cgi?id=205 . In gw_read_backend_event, read client_protocol by using dcb->session->client pointer but only after it is sure that there is something to write to client. This doesn't ensure that client pointer in session is valid, but it should be.
Return value of dcb_read is checked and buffer pointer is not used if nothing was read.
2013-09-09 15:00:37 +03:00
vraatikka
83a7479236 Removed free(router_session) from closeSession. Router session is free in session.c:session_free. 2013-09-09 14:51:15 +03:00
vraatikka
46464d7723 Check if router_session pointer has value in session structure before calling free for it. 2013-09-09 14:36:45 +03:00
vraatikka
e1d7a5640d Put structure check fields behind SS_DEBUG macros. Thus, they are only included in debug builds. 2013-09-09 10:05:46 +03:00
vraatikka
27338c2537 Merge 2013-09-09 00:05:28 +03:00
vraatikka
189fdf35b8 Major changes: Removed NULL-pointer assignment after the call of backend_dcb->func.close because backend_dcb->func.close calls gw_client_close which _always_ returns true. Thus, its return value can't be used for deciding whether backend_dcb pointer can be set to NULL. There are typically multiple threads executing backend dcb. Setting NULL here will cause next caller to refer to NULL pointer, which makes maxscale to fail.
Removed freeing router session object because it is not know at this phase whether session is really closed or not. Router session can be freed only when session is.
2013-09-08 23:59:00 +03:00
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
d535346987 Removed dead code. 2013-09-08 23:32:13 +03:00
vraatikka
e40aace963 Renamed MySQLProtocol member 'descriptor' to 'owner_dcb'. 2013-09-08 23:31:05 +03:00
vraatikka
4c00cdac5e Cleaned up. Removed unnecessary extern keywords from function declarations so to fit them better to one line. 2013-09-08 23:29:50 +03:00
vraatikka
e61c19c6fe Major change. router_session is freed as a last operation before freeing session. Fixes frequently occurring failures when multiple threads are running. 2013-09-08 23:27:57 +03:00
vraatikka
6a07ef8245 Added debug logging to poll_remove_dcb. Removed dead code from poll_waitevents. 2013-09-08 23:26:15 +03:00
vraatikka
03fed73b64 Added missing spinlock_release to dcb_add_to_zombieslist to avoid deadlock. 2013-09-08 23:24:54 +03:00
Mark Riddoch
0d47aa2d3a Remove some contention on the DCB zombie queue spinlock
A fix for final free beign called when a DCB has not yet had a session created
2013-09-05 22:05:55 +02: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
vraatikka
17ec98fa3d session was assigned state SESSION_STATE_READY outside protected block, and backend dcb thread saw authentication data and session in SESSION_STATE_ALLOC state, which trapped. Moved state assignment inside protection block. 2013-09-05 19:47:42 +03:00
vraatikka
4f8057034a Protected temporarily with spinlock gethostbyname which is not thread safe. This should be changed permanently so that gethostbyname is replaced with getaddrinfo. 2013-09-05 19:42:59 +03:00
Massimiliano Pinto
8f98ae4751 Removed old mysql protocol files 2013-09-04 15:53:51 +02:00
Massimiliano Pinto
6888735f7b Removed old gateway_mysql_protocol.c
server/core/Makefile updtated
2013-09-04 15:41:08 +02:00
Massimiliano Pinto
b01cf2365e Added log error or ss_dassert instead of silent returning 2013-09-04 15:31:04 +02:00
Mark Riddoch
5c48239372 Fixed doxygen documentation generation 2013-09-04 13:13:54 +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
db164be946 Added spinlock protection for refcount increase in dcb_connect 2013-09-04 10:00:40 +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
vraatikka
a605b8fd9b Removed unused macros. 2013-09-02 22:21:28 +03:00
vraatikka
3d5c40e450 Removed unused macros. Fixed struct member order so that check field is again the last in struct and it detects memory overflows slightly better. 2013-09-02 21:54:24 +03:00
vraatikka
366441a4bb Added debug assert for checking return value of memory allocation. 2013-09-02 21:53:49 +03:00
vraatikka
c4ce2efd9f Added debug assert for DCB states prior processing. 2013-09-02 21:52:57 +03:00
vraatikka
5487f84532 Added logging to session refcount increment. Some minor improvements. 2013-09-02 21:52:09 +03:00
Massimiliano Pinto
f80bb51db1 dcb_close sets some session fields to NULL:
dcb->session->client = NULL;

dcb->session = NULL;

There is a local copy of dcb->seesion before setting it to NULL
2013-09-02 19:33:55 +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
b86d3f3dfd Holding error log's block buffer registration until all logs were written caused deadlock if block buffers were full. Now buffer registrations don't overlap. 2013-09-02 10:30:50 +03: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