565 Commits

Author SHA1 Message Date
vraatikka
3e1322034d Added logging and som checks. 2013-09-24 15:13:25 +03:00
vraatikka
a7c3cd5f30 Related to bug #217, added command 'fail accept <errno>' to debug client's commands.
Reproduce #217 by connecting with telnet to debug client interface and execute command:

fail accept 23

and try to execute read query, for example, with

mysql -h 127.0.0.1 -P 4008 -u maxuser -pmaxpwd -e 'select current_user(), @@server_id'
2013-09-24 15:04:12 +03:00
vraatikka
3b3d3dbfe0 Merge 2013-09-20 15:05:19 +03:00
vraatikka
302090a168 Removed unused local variable. 2013-09-20 15:03:20 +03:00
vraatikka
74aa3638f9 dcb.c
dcb_final_free: Router session is not closed anymore when dcb is closed. Router session is shared among all dcbs and is closed and freed with session.
	dcb_connect: dcb's state must be switched fro DCB_STATE_ALLOC to DCB_STATE_DISCONNECTED before dcb_final_free can be called for it.
	dcb_close: poll_remove_dcb encapsulates dcb's state transition in the same way as poll_add_dcb. Removed state modification from dcb_close. Read return value of poll_remove_dcb and log accordingly.
	dcb_set state: remove dassert if dcb_set_state_nomutex returned false. False can be returned indicating that intented change didn't occur but the end state, for example, may be acceptable. Failures in state transitions are asserted in dcb_Set_state_nomutex.

poll.c
	poll_add_dcb: dcb state is now set here to either DCB_STATE_LISTENING or to DCB_STATE_POLLING according to dcb's role. Failures in state setting and in epoll_ctl are detected, logged and handled.
	poll_remove_dcb: Failures in state setting and epoll_ctl are detected, logged, and handled.

mysql_client_server_protocol.h 
	Removed macros MYSQL_FAILED_AUTHENTICATION & MYSQL_SUCCESFUL_AUTHENTICATION as they were not necessary and used with constant values 0 and 1 depending on the case.
	Renamed variable 'conn' to 'protocol' in cases where it meant protocol.

mysql_backend.c
	gw_read_backend_event: In case when there was nothing to read or read failed, backend dcb is closed because situation is assumed to be such that backend server closed its side of the socket. Removed macros MYSQL_FAILED/SUCCESFUL_AUTHENTICATION
	gw_create_backend_connection: Assigned protocol with fd which is connected to backend.
	backend_write_delayqueue: In case where dcb_write fails to write anything, close backend dcb to avoid it getting hanging.

mysql_client.c
	gw_read_client_event: Read return value of routeQuery and if it isn't == 1, call mysql_send_custom_error with client dcb and set client's protocol state to MYSQL_IDLE instead of MYSQL_ROUTING.
	gw_MySQLAccept: Static reply counter was erroneously used as a criteria for jumping to return point where return value was constantly 'success' (=0). Replaced static reply counter with private. Fixed return value in different cases.

mysql_common.c
	gw_receive_backend_auth: Changed to return boolean values indicating of success or failue. Used integers which were assigned to macroed values on the caller side. Added length check before accessing buffer. 

readconnroute.c
	Cut too long lines and removed statements with side effects.

skygw_debug.h
	Added macro STRPROTOCOLSTATE(s) to produce string representation of a given protocol state.
2013-09-20 14:32:28 +03:00
Massimiliano Pinto
85ac4d78dd HTTPD is now working:
changed dcb role to DCB_ROLE_REQUEST_HANDLER

removed session_alloc and put client->session = NULL instead
2013-09-19 12:23:17 +02:00
Mark Riddoch
c7b052aab3 Addition of CheckSessions debug entry point 2013-09-18 19:06:32 +02:00
Massimiliano Pinto
ace4252832 Added closeSession to gw_error_backend_event: the backend failure is handled without faults
Modified gw_send_change_user_to_backend ret code
2013-09-18 11:50:19 +02:00
vraatikka
4321861ed8 dcb_read : removed redundant or dead code.
dcb_write: if fail backendfd | clientfd is used, now listener operations don't cause failure.
2013-09-17 21:54:38 +03:00
vraatikka
4cf5b3293f Added check routine for gw_buffer. Only effective in debug build. 2013-09-17 15:10:16 +03:00
vraatikka
5fba84a4ee poll.c : forgot from previous commit
debugcmd.c : cannot compile.
2013-09-17 00:16:06 +03:00
vraatikka
8bf73ea154 Replaced write system function with wrapper gw_write. It allows for generating failures by using telnet commands, fail backendfd, fail clientfd, which are available in debug build only. 2013-09-17 00:07:56 +03:00
vraatikka
db7004e6ae dcb's fd wasn't stored to client's protocol structure. Changed mysql_protocol_init to take fd as the Second argument. 2013-09-14 23:01:26 +03:00
vraatikka
4815856017 session.c : session_alloc
If backend connection can't be created, backend_dcb is not create, router client session is not created and what already is created in session_alloc, is freed.
mysql_client.c : gw_read_client_event
If session creation failed, then - instead of sending ok to client, "failed to create new session" is sent and client dcb is closed.
 : gw_MySQLAccept
removed loop where accept was called again and again. With single thread looping forever is not possible because there's no one to free previously allocated resources.
If accept fails ten times in a row, then return without new client dcb.
2013-09-13 23:55:26 +03:00
vraatikka
710fc5cfa6 dcb.c
: dcb_alloc switched malloc to calloc, dcb->fd is initialized to -1. 
: dcb_process_zombies return value of close(fd) is checked. Closed fds are stored to conn_open array. 
: dcb_connect assigns new fd only if backend connection succeeds. Dcb is added to poll set in the same way, only if connect succeed.
gateway.c : conn_open array is initialized in main. For each created socket, a true is set to corresponding slot. Max. number of slots is 1024.
mysql_client_server_protocol.h : gw_do_connect_to declaration 
mysql_backend.c : gw_create_backend_connection returns rv >= 0 and a protocol which is assigned to backend_dcb. In error, -1 is returned and fd is not set.
mysql_client.c : conn_open array is kept up-to-date and protocol pointer is assigned also to dcb outside mysql_protocol_init.
mysql_common.c : gw_do_connect_to_backend 3rd argument is pointer to fd, not protocol. dcb is added to poll set later in dcb_connect.
skygw_debug.h : define conn_open[1024] array where open connections can be marked in debug build.
2013-09-13 22:10:40 +03:00
Massimiliano Pinto
c3fba63b45 Added break in routeQuery switch, avoiding the execution of default.
This was noticed during PHP tests with mysql_change_user


This bug is related to recent code modification in readconnroute.c, revno > 362

Now fixed
2013-09-13 19:17:20 +02:00
Massimiliano Pinto
b2b715fcae Fixed failed handshake handling, taking care of dcb->delayq before sending reply one time and not twice. 2013-09-13 18:22:24 +02:00
vraatikka
88174865a0 If accept fails due too many open fails, now ENFILE (system level file limit exceeded) and EMFILE (process limit) are separated and logged diffenretly. 2013-09-13 10:10:02 +03:00
vraatikka
ae12ef8f34 Added call to close(fp_tmp) 2013-09-12 23:13:22 +03:00
vraatikka
d7e793a411 poll.c:Returned checks for zombie
mysql_backend.c:don't write to session->client if session->client is NULL
mysql_common.c:assert if called with dcb==NULL
2013-09-12 22:34:49 +03:00
vraatikka
bbc9dcc9a3 poll.c: added maxscale thread id to log
session.c: Replaced free(session->router_sesision) with call to freeSession callback
users.c: Removed reference to uninitialized variable.
router.h: Added freeSession callback to function block.
mysql_backend.c: try to ensure that client dcb is still listening in epoll_wait when writing reply to it.
mysql_common.c: assert debug build is mysql_protocol_init is called with dcb == NULL
readconnroute.c, readwritesplit.c, debugcli.c and testroute.c : Added freeSession to function block and an inmplementation of it.
2013-09-12 22:17:11 +03:00
vraatikka
c4d01cdaed Backend sets session's client pointer to NULL before session_free is called for session. 2013-09-12 22:10:43 +03:00
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