625 Commits

Author SHA1 Message Date
vraatikka
594f1c294f Added include of stdlib.h because malloc needs it to work. Malloc time to time fails in server/core/buffer.c and produces the following error:
*** Error in `./maxscale': malloc(): memory corruption (fast): 0x00007f3988005510 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7afc6)[0x7f39c67a9fc6]
/lib64/libc.so.6(+0x7d245)[0x7f39c67ac245]
/lib64/libc.so.6(__libc_malloc+0x63)[0x7f39c67ad633]
./maxscale(gwbuf_alloc+0x34)[0x406250]
/home/raatikka/bin/tmp/MaxScale/modules/libMySQLClient.so(MySQLSendHandshake+0x19b)[0x7f39afb09bc0]
/home/raatikka/bin/tmp/MaxScale/modules/libMySQLClient.so(+0x4d1b)[0x7f39afb0ad1b]
./maxscale(poll_waitevents+0x42a)[0x40d0c3]
/lib64/libpthread.so.0(+0x7e0f)[0x7f39c6ae5e0f]
/lib64/libc.so.6(clone+0x6d)[0x7f39c681844d]
======= Memory map: ========
00400000-0041a000 r-xp 00000000 08:03 6686345                            /home/raatikka/bin/tmp/bin/maxscale
00619000-0061a000 r--p 00019000 08:03 6686345                            /home/raatikka/bin/tmp/bin/maxscale
0061a000-0061b000 rw-p 0001a000 08:03 6686345                            /home/raatikka/bin/tmp/bin/maxscale
012fa000-0141e000 rw-p 00000000 00:00 0                                  [heap]
7f3984000000-7f3984021000 rw-p 00000000 00:00 0 

- and so forth.
2013-11-03 20:54:41 +02:00
vraatikka
38b44a3a3a gw_client_hangup_event, didn't take into account the possibility that session_alloc had failed in which case the session pointer of client dcb is NULL. 2013-10-31 22:57:04 +02:00
vraatikka
3769a02957 query_classifier.cc
resolve_query_type, added GSYSVAR_FUNC type for functions that read system variables and can be executed in Maxscale instead of backend server.

dcb.c
	dcb_read, if read returns value <= 0 and if error is EAGAIN/EWOULDBLOCK so there was nothing to read in sthe socket, that is not an error because some other thread may have read the data that was expected to be available.

mysql_backend.c
	gw_read_backend_event, used dcb->authlock to ensure that dcb's protocol state is read and modified serially. This removes issues with false authentication failures which may happen when two threads modify and read the state without any control.

mysql_client.c 
	removed dead code.

readconnroute.c, readwritesplit.c
	removed invalid assert which assumed that spinlock can not have larger value than one when itis locked.
2013-10-31 22:24:51 +02:00
vraatikka
e803acb036 dcb.c, gateway.c little tuning.
poll.c
	Removed mutex from epoll_wait.
	Removed read and write mutexes from poll_waitevents.

session.c
	If session_alloc fails, instead of calling directly free(session), call session_free, which decreases refcounter and only frees session when there are no references left. 
	Added session_unlink_dcb function which removes link from session and optionally sets the dcb->session pointer to NULL.

readconnection.h, readwritesplit.h
	Added check fields to ROUTER_CLIENT_SES strct as well as lock, version number (not used yet) and closed flag.

mysql_backend.c
	gw_read_backend_event: if backend_protocol->state was set to MYSQL_AUTH_RECV, function returned, which was unnecessary. If mysql state became MYSQL_AUTH_FAILED, router client session was closed. Removed unnecessary NULL checks because rsession is not allowed to be NULL. Similarly, removed other NULL checks and replaced them with asserts checking that router client session is not NULL at any phase.

mysql_client.c
	Removed unused code blocks. Polished log commands. Replaced router client sessions NULL checks with asserts.

mysql_common.c
	mysql_send_custom_error: if called with dcb == NULL, return.

readconnroute.c
	Replaced malloc with calloc. Added functions rses_begin_router_action and rses_exit_router_action. If router client session is not closed, they take a lock and release it, respectively. Those functions are used for protecting all operations which modify the contents of router client session struct.

readwritesplit.c
	Identical changes than in readconnroute.c

skygw_debug.h
	Added check number and - macro for ROUTER_CLIENT_SES, and added COM_QUIT to STRPACKETTYPE.
2013-10-30 22:07:51 +02:00
vraatikka
5e6b0a3b1a Included log_manager in query classifier's makefile, replaced fprintf's with log manager commands. 2013-10-28 10:44:05 +02:00
vraatikka
86c64ab3f4 Merge 2013-10-25 11:59:08 +03:00
vraatikka
f32cfe8546 query_classifier.cc
resolve_query_type, traverse through the list of items of thd->free_list, identify functions and reason query type according to the function type. This phase can only increase the restrictiviness level of the query.

query_classifier.h
        Added new query type QUERY_TYPE_LOCAL_READ, for functions that can be executed in Maxscale. This type is the least restrict
ive query type. It is not used currently.

testmain.c
	Added a few test cases and fixed expected return values for query type tests.

readwritesplit.c
	polish

skygw_debug.h
	Added string macro for Item types.
2013-10-25 11:55:45 +03:00
Massimiliano Pinto
2cbe46b506 gwbuf_consume is protected by spinlock 2013-10-24 17:53:38 +02:00
vraatikka
241a0a6175 Used sizeof operator for calculating the length of a string. 2013-10-24 10:51:54 +03:00
vraatikka
ddab34fe72 mysql_libraray_init failed due to invalid datadir setting. Fixed this by setting the working directory/data as data directory. 2013-10-23 14:16:50 +03:00
vraatikka
d7550f40c0 Merge 2013-10-23 09:24:42 +03:00
vraatikka
da60fe701c Cleanup, added also a macro for printing dcb state. 2013-10-23 09:11:20 +03:00
Massimiliano Pinto
8e9b7fb26a Added new entry point in router: errorReply
The routine if called from backend will ido:

1 reply error messages to client closing or not the session
2 open a new backend connection

An action flag is passed to the routine.
2013-10-22 10:30:16 +02:00
Massimiliano Pinto
4a189696bd In mysql_backend.c:gw_read_backend_event
the delay queue is now consumed when backend_protocol->state == MYSQL_AUTH_FAILED.

This will avoid sending more times the custom error in the threaded configuration.
2013-10-21 16:28:07 +02:00
vraatikka
1ef015196b Another case where gw_write fails in EAGAIN/EWOULDBLOCK. 2013-10-16 22:30:59 +03:00
vraatikka
81b52c6256 If gw_write returns -1 with errno EAGAIN or EWOULDBLOCK it is not treated like an error. 2013-10-16 21:59:22 +03:00
vraatikka
44c7914f2b Increased size of following arrays to prevent memory overwrites: dcb_fake_write_errno, dcb_fake_write_ev, conn_open. Note that these are use in DEBUG build only. 2013-10-16 17:32:30 +03:00
vraatikka
a696e041e0 gateway.c
file_write_footer, added checks for the case of failed memory allocation. 

service.c
	serviceRestart, added check for return value of poll_add_dcb. In failure, service is not moved to SESSION_STATE_LISTENER state and listener counter is not increased.
2013-10-16 17:13:50 +03:00
Massimiliano Pinto
76af245eac Added the \0 byte to user and db in musql_session 2013-10-16 11:01:16 +02:00
vraatikka
94c37799b1 dcb.c
dcb_write earlier returned an error (== 0) if errno was not set and other conditions were satisfied. In practice, if write was done in write queue, queue pointer was not updated and dcb_write returned and error. Changed the error detection condition so that it requires errno being set, at least.

readwritesplit.c
	Clean up.
2013-10-16 08:29:22 +03:00
vraatikka
4db366290d Removed 'datadir' value from libmysqld's start-up parameters to make it start. 2013-10-15 22:18:59 +03:00
vraatikka
52644db8ce testmain.c
Removed embedded server startup parameter '--skip-innodb' and replaced TRUE, and FALSE with true and false, respectively.
gateway.c
	Removed embedded server startup parameter '--skip-innodb' because libmysqld inside MariaDB 5.5.33 + doesn't start with that paramter.
2013-10-15 18:18:09 +03:00
Massimiliano Pinto
b5da527555 myql_common.c:gw_send_change_user_to_backend checks func.write for 0 and 1
mysql_client.c:gw_MySQLWrite_client is simply return dcb_write(dcb, queue);
The return codes are not the same of the code replaced, but they are not checked in the caller routines.
2013-10-14 18:41:49 +02:00
Massimiliano Pinto
121cff7ffa Galera cluster status is Synced, all affected files are updated 2013-10-14 15:29:26 +02:00
vraatikka
66dbb8ec23 dcb.c
dcb_write, if write failed, gwbuf wasn't freed.
mysql_backend.c 
	gw_MySQLWrite_backend, if dcb wasn'r in POLLING state then write was skpiped but gwbuf wasn't freed.
mysql_client.c
	gw_MySQLWrite_client, disabled the use of dcb_write because it returns different values than the code it replaced. Also removed erroneous call of gwbuf_consume.
mysql_common.c
	mysql_send_custom_error, removed erroneous call of gwbuf_free.
2013-10-14 15:12:30 +03:00
vraatikka
0f2eeff243 gw_buffer was not freed. 2013-10-14 13:16:33 +03:00
vraatikka
42417797a9 freeSession, trace log write referenced to backend_dcb which may be freed. 2013-10-12 12:40:49 +03:00
Massimiliano Pinto
1f0e8d5c56 Fixed: use row[1] instead of row[0] in monitorDatabase() 2013-10-11 09:02:49 +02:00
vraatikka
cd507f1461 log_manager.cc
blockbuf_get_writepos, when all existing buffers in blockbuf list are full, a new block buffer is created and added to the list. Adding to the list is done with mutex on hold. Mutex shouldn't be freed before the next iteration in while loop, which expects that bblist mutex is on hold. At the end of the function, removed an unnecessary debug assertion.

testlog.c
	Enabled more intensive write test. Replaced TRUE and FALSE with true, false, respectively.

skygw_utils.cc
	simple_mutex_unlock, added debug assertion to ensure that pthread mutex's user counter is always at least 0 (it goes negative in double free).
2013-10-10 16:46:51 +03:00
Massimiliano Pinto
e1c7887726 gw_MySQLWrite_client is now simply a call to dcb_write 2013-10-07 16:34:15 +02:00
vraatikka
655a6537b2 mysql_client_server_protocol.h :
changed gw_receive_backend_auth declaration to return int instead of boolean.
mysql_backend.c:
	gw_read_backend_event calls gw_receive_backend_auth which either fails (== -1), succeeds with nothing to read (== 0) or succeeds (== 1). For each case there is handling. If dcb_read succeeds without read bytes, return asap.
mysql_client.c:
	gw_error_client_event, gw_client_close, gw_client_hangup_event : all close client dcb but now they also close backend dcb.
mysql_common.c:
	gw_receive_backend_auth, return -1, 0, or 1 if read from backend failed, was empty, or succeed, respectively.:
2013-10-07 14:00:44 +03:00
vraatikka
80b67d1083 log_manager.cc:
State update for filewriter was missing and that caused Maxscale to fail if opening of any log file failed.
dcb.c:
	Added EAGAIN and EWOULDBLOCK handling to dcb_read. If dcb_close is called for freshly created dcb, dcb is only freed.
gateway.c:
	Added file_write_footer and write_footer of which the latter is called at exit time. It simply draws a line to screen.
gw_utils.c:
	Some macros for helping comparison between gw_read_gwbuff and dcb_read, which overlap.
poll.c:
	Some macros to help enable/disable mutexing in poll_waitevents
service.c:
	Check return value of listen and session_alloc and behave accordingly.

mysql_client.c:
	If ioctl returned successfully with b==0 it earlier caused closing the client and backend dcbs. Since that doesn't reliably indicate that client has closed socket on its side, Maxscale doesn't close its sockets either.
mysql_common.c:
	In gw_receive_backend_auth, if dcb_read returns n==0, it is not considered as an error anymore. The implemented behavior is not yet complete and correct. Result should be successful but the protocol state shouldn't change to MYSQL_IDLE before backend return is received.
	In gw_send_authentication_to_backend protocol state was always set to MYSQL_AUTH_RECV even if gw_rwite had failed. Now, return value is read and state is set in caller's context basen on the return value.
skygw_utils.cc:
	Removed ss_dassert from skyge_file_init because it prevented from returning meaningful error meassage to the client.:
2013-10-06 22:31:32 +03:00
vraatikka
e3a4be8b9d gw_write_backend_event, if dcb is not in POLLING state but writeq is NULL it is ok. Only attempt to write when dcb's socket isn't open anymore is failure. 2013-10-04 16:44:21 +03:00
vraatikka
849a366e95 log_manager.cc :
tuned error printing and log writing output format
dcb.c : 
	dcb_connect, check return value of poll_add_dcb and behave accordingly.
	dcb_write, in case of SIFPIPE, only write to trace log.
	dcb_close, dassert with incorrect dcb states.
gateway.c :
	added file_write_header to print header similar than in logs to stderr.
	main, add signal handler for SIGPIPE
poll.c : 
	poll_remove_dcb, don't fail if dcb is in NOPOLLING or in ZOMBIE states.
	poll_waitevents, write EPOLLHUPs to trace log, don't even attempt to write to closed socket.
readconnection.h : 
	shortened comment.
readwritesplit.h : 
	replaced generic names with more specific ones. 
httpd.c : 
	Check listen return value and behave accordingly.
mysql_backend.c : 
	 Tiny clean up.
mysql_client.c : 
	gw_MySQLListener, Check listen return value and behave accordingly. 
mysql_common.c : 
	Shortened a header.
telnetd.c : 
	telnetd_listen, check listen return value and behave accordingly.
readconnroute.c : 
	Tuned log writing format.
readwritesplit.c : 
	Added function search_backend_servers, which chooses suitable backend and master server among those known by Maxscale. Fixed clean-up routines. Not ready yet but works somehow.
testroute.c : 
	Cleanup.
skygw_utils.cc : 
	Log writing clean up.
2013-10-04 12:06:44 +03:00
Massimiliano Pinto
9f2f0ac006 session = dcb->session; was missing in the previous check in mysql_client.c:gw_read_client_event() 2013-10-02 15:42:55 +02:00
Massimiliano Pinto
37bd63b33b Detected closed socket in mysql_client.c:gw_read_client_event now calls the closeSession.
This will fix left opened backend connections if the client connection aborts
2013-10-02 11:15:04 +02:00
Massimiliano Pinto
c55ca0aaee Backed dcb close if now forced after routing COM_QUERY and close client dcb, in mysql_client.c gw_read_client_event
/** close backends connection */
router->closeSession(router_instance, rsession);

Tested only with readconroute router module
2013-10-02 09:27:10 +02:00
vraatikka
440a4c7278 Missing argument in log command caused maxscale to fail. 2013-09-30 12:36:08 +03:00
vraatikka
f74e7b6f79 Cannot compile. 2013-09-30 11:19:03 +03:00
vraatikka
701830f0ab Logging related (mostly) sanity checks and fixes.
- Checked argument types and counts
- Removed trailing line feeds
- Removed thread ids from error logs (they are used in trace / debug log
- Added some state information to dcbs
- Added prefix 'Error' or 'Fatal' to error logs.
- Switches all error logs to use flushing log write.
2013-09-30 11:14:36 +03:00
Massimiliano Pinto
c48dd6028f Modified dcb_read return: n = 0 means 0 bytes read without errors
if (rc < 0) is now used testing dcb_read() return, instead of if (rc <= 0)
2013-09-27 19:24:23 +02:00
vraatikka
e03d2b3ffe In gw_read_client_event, if ioctl returns non-zero and 'b' (number of readable bytes) is zero, that indicates that socket is closed. Thus, read is now skipped and dcb closed if it is in DSC_STATE_POLLING state. 2013-09-27 14:57:53 +03:00
vraatikka
1120ae9b2c Zombie processing had an risk of getting into an infinite loop. 2013-09-27 11:20:28 +03:00
Massimiliano Pinto
46c5564313 Removed states MYSQL_WAITING_RESULT and MYSQL_ROUTING 2013-09-26 18:01:48 +02:00
Mark Riddoch
ee7b799bf1 Bug 160 - fixed memory leaks with telnetd and debug CLI 2013-09-26 17:38:35 +02:00
Mark Riddoch
1e83308cd1 Bug 133 - cleanup data<pid> directory on SIGINT 2013-09-26 16:33:16 +02:00
Mark Riddoch
ab731274fd Bug 218 - add error message if MAXSCALE_HOME does not exist 2013-09-26 13:46:04 +02:00
Mark Riddoch
c26bd04ea7 Addition of messages to standard error if MaxScale refuses to start for some reason 2013-09-26 12:21:45 +02:00
Mark Riddoch
c1c7a3fb02 Additional check for service starts 2013-09-26 10:38:31 +02:00
Mark Riddoch
fe7d0477ba Improved configuration object checking 2013-09-26 10:37:55 +02:00