395 Commits

Author SHA1 Message Date
Markus Makela
76f06572ed Fix to multi-statement processing
Renamed is_mysql_comment_start to is_mysql_statement_end because it checks
whether a statement truly ends instead of just checking comment block starts.

The calculations for buffer length in readwritesplit now use the payload size
instead of the buffer size.
2016-03-03 10:44:11 +02:00
Markus Makela
8b6595aa68 Improvements and fixes to strchr_esc_mysql
The C style comments were not ignored and the -- style comments
did not check for the trailing whitespace and made return values char*.

The creation of a stored procedure would prevent sessions from using
any of the slave servers because readwritesplit would interpret
the creation statement as a multi-statement query.

Parts of modutil and readwritesplit now compare pointers to pointers instead of
converting pointers to integers.
2016-03-02 21:34:22 +02:00
Markus Makela
2589630b8e Unknown SQL commands are treated as writes
This will prevent any possible damage to a slave by new or unexpected commands.
2016-03-02 21:27:34 +02:00
Markus Makela
9bfef5c7c1 Improved multi-statement detection in readwritesplit
Now comment blocks and identifiers quoted with backticks are taken into
consideration when multi-statements are processed.
2016-03-02 21:27:34 +02:00
Markus Makela
bf1a789376 Added configurable multistatement behavior
Whether all queries should be routed to the master after a multistatement
query is executed can now be controlled with the `strict_multi_stmt` option.

When the option is disabled queries executed after a multistatement query will
be routed normally.
2016-03-01 10:45:08 +02:00
Markus Makela
ac007fa8f5 MXS-497: Multi-statement queries are always routed to the master
This will prevent the routing of queries that modify data to the slaves.

In the future a more intricate solution can done where all the statements
are parsed and the destination is resolved based on the actual contents.
2016-03-01 09:32:55 +02:00
Markus Makela
bf24f18805 Merge branch 'develop' into MXS-544 2016-02-29 10:40:33 +02:00
counterpoint
395cbdc103 Simplify handling of "client data" by having a pointer to it only in DCB and not in session structure. Change name of session->client to session->client_dcb for greater clarity. Temporary free of client data in DCB, to be moved to authenticator when it becomes a module. Fix incorrect name of listener_alloc. 2016-02-23 11:13:21 +00:00
Markus Makela
26cbcb7365 MXS-511: Made log messages about master status coherent
The checking of the master status and the possible error logging were done
in two different steps. This led to confusing error messages when the state
of the server changed between the check and the logging of the error message.
2016-02-12 21:18:57 +02:00
Markus Makela
cfefc046e9 Merge branch 'release-1.3.0' into develop 2016-02-11 10:23:00 +02:00
Markus Makela
379cb6c781 MXS-564: Slave server states were not properly cleared after session commands
When a command that changes the session state is executed on all servers and
a slave server goes down, an error message was sent to the client even though
one wasn't expected. These appeared as odd connection errors on the client side.
2016-02-05 13:54:24 +02:00
Markus Makela
9432967da5 Don't assert the master server state when routing query to slave
When a query is being routed to the slave, it is not necessary to assert that
the master server's state is still master. It is possible that the master server
changes states while the query is being routed but that doesn't affect the query
being currently routed.
2016-02-04 09:57:27 +02:00
Markus Makela
e731f6a29e Fixed double freeing of buffers
The buffers in readwritesplit are handled at the routeQuery level and freeing
them at lower levels cause a double free of the used buffers.
2016-02-04 09:57:27 +02:00
Markus Makela
d9eeb72198 Added missing check for closed master backend reference into readwritesplit
The master DCB was checked for NULL-ness but the proper way is to check if
the backend reference is closed. This will fix a debug assertion in addition
to possibly preventing crashes.
2016-02-04 09:57:27 +02:00
Markus Makela
379004a2a4 Removed corrupted error messages from readwritesplit
When a slave server fails to execute a session command, the log message printed
the command that was being executed as if the ERR packet was a COM_QUERY packet.
This caused corrupt strings to be printed into the error logs.
2016-01-28 13:04:23 +02:00
Markus Makela
e6d18f0b66 Fixed debug assertion causing a crash in readwritesplit
A debug assertion in the readwritesplit would always fail when the master DCB
was NULL. This was caused by the fact that the debug assertion assumes that the
pointer that is passed to it is a valid pointer.
2016-01-28 10:46:55 +02:00
Markus Makela
087ab202c2 MXS-559: Fixed unsafe use of the master DCB in readwritesplit
The master DCB was used without checking if it was still open. It was possible
that the master DCB was closed and processed before the client had fully
processed all queries which caused it to fail at a debug assertion.

The fix to this is to use the client's DCB to get access to the shared session
authentication data as it is protected by additional locks.
2016-01-26 14:48:01 +02:00
Markus Makela
d41fe5b9c7 Added extra checks to readwritesplit
Added a check that the master server reference is actually in use before
doing anything with it. Also removed a false assertion.
2016-01-15 16:25:05 +02:00
Johan Wikman
23a7562d3a Replace skygw_ type prefix with qc_.
- skygw_query_type_t renamed to qc_query_type_t.
- skygw_query_op_t renamed to qc_query_op_t.
2016-01-11 12:06:21 +02:00
Johan Wikman
2f42246880 Rename query classifier functions consistently.
All public query classifier functions now have the prefix qc_.
2016-01-11 12:04:52 +02:00
Markus Makela
cba190f84c Checks for temporary tables are only done if they have been created
Previously all queries were inspected for CREATE, DROP and SELECT statements
which targeted temporary tables even if they haven't been created.
2016-01-08 11:16:43 +02:00
Markus Makela
b84e739cfa All queries related to prepared statement are sent to the master
The preparation and closing of prepared statements was sent to all servers
even though the execution was always sent to the master. With this change,
all queries which interact with prepared statements are only sent to the master.

The sending of statement preparations to all servers is a problem when a
statement which depends on a database or a table is created and the DDL
statement which created that table has not yet been replicated to the
slaves.

In addition to fixing the aforementioned problem, this change should also
reduce unnecessary network traffic to slaves and improve the overall
performance of the prepared statements.
2016-01-08 11:16:30 +02:00
Markus Makela
d6afe70c6f Fix to MXS-323: Routers properly handle client DCB errors
All routers now detect if a client DCB is passed to handleError and
take the appropriate action.
2015-12-02 18:01:14 +02:00
Markus Makela
02da87f737 Fix to MXS-439: Weightby value of 0 no longer causes a crash
A weightby parameter with a value of 0 no longer causes SIGFPE and the
invalid weight value is set to the correct value of 1.
2015-11-30 19:06:04 +02:00
Markus Makela
8ae187622c Fixed weightby overflow being silently ignored in readwritesplit
If individual servers had a weightby parameter value greater than INT_MAX * 1000
the integer used for calculation would overflow and the server would end up
having a negative weight. This would cause all connections to pile up on this
server.

The same overflow was possible for the sum of all the weightby parameter values
even if no single parameter exceeded the limit.
2015-11-25 22:43:46 +02:00
Markus Makela
038877b8db Fixed minor format errors and resource leaks
Some format strings used integer values for unsigned integers.
Memory and file descriptors leaked in some error conditions.
2015-11-25 12:43:49 +02:00
Johan Wikman
a8535f42af Remove all traces of logfile_t
The earlier log file based approach for enabling and disabling
messages has now been completely replaced with the syslog priority
based approach.

Similarly as with log files before it is now possible to enable
and disable a log priority for a particular session, even though
it apparently has not been used much.

The local test-programs of the logging has got minimal attention
only to make them compile. They should get an overhaul as they did
not work before either.
2015-11-23 19:10:53 +02:00
Markus Makela
422d6f5ab2 Updated readwritesplit default values
The combination of only one slave being used and the slave_selection_criteria
being LEAST_CURRENT_OPERATIONS can possibly cause a connection pileup on one
slave server. This would skew the query distribution heavily towards the first
available slave even if multiple slave were being used.

Having the maximum number of slave servers to be equal to the total amount of
available slaves allows for a more even and responsive distribution of the
query traffic.
2015-11-20 05:57:51 +02:00
Johan Wikman
ee7793312b Broken error message fixed in readwritesplit.c
When converting the skygw_ logging calls to MXS_ equivalents,
some part of the error message got lost.
2015-11-18 20:51:11 +02:00
Johan Wikman
d59c6a3570 readwritesplit: skygw_log_writes replaced. 2015-11-18 12:28:40 +02:00
Johan Wikman
1de202ca20 LOGIF removed from readwritesplit 2015-11-17 12:51:08 +02:00
Johan Wikman
a355e1beef Printf format checking added to logging function.
Printf format checking added to logging function and all
issues that were revealed by that fixed.
2015-11-16 12:40:49 +02:00
Markus Makela
30d1fc66b7 getCapabilities no longer takes arguments and returns an int. 2015-11-11 18:14:03 +02:00
counterpoint
dee20fe077 Merge remote-tracking branch 'origin/develop' into MXS-329-develop-20151111
# Conflicts:
#	server/core/CMakeLists.txt
#	server/core/buffer.c
#	server/core/service.c
#	server/modules/filter/tee.c
#	server/modules/monitor/mysql_mon.c
#	server/modules/routing/binlog/blr.c
#	server/modules/routing/binlog/blr_slave.c
#	server/modules/routing/debugcmd.c
#	server/modules/routing/readwritesplit/readwritesplit.c
#	utils/skygw_utils.cc

- resolved.
2015-11-11 11:08:02 +00:00
Johan Wikman
834a88aeda Log variables moved to log_manager.h
The log manager variables lm_enabled_log_files_bitmask, log_ses_count
and tls_log_info that earlier were declared separately in every
c-file are now declared in the log_manager.h header.
2015-11-04 14:26:53 +02:00
Markus Makela
0accf869de Fix to MXS-365: https://mariadb.atlassian.net/browse/MXS-365 Added tracking of LOAD DATA LOCAL INFILE
While a LOAD DATA LOCAL INFILE query is being executed, all queries will be sent to the master
and they will not be processed as normal packets.
2015-11-04 12:47:55 +02:00
Markus Makela
d6230e68ef Moved warnings about session command history limits to message log. 2015-11-04 09:12:37 +02:00
Markus Makela
5112d4118f Fix to MXS-409: https://mariadb.atlassian.net/browse/MXS-409
Prepared statements are sent to the master instead of all servers.

The planned functionality to store the types of the prepared statements was not implemented
and all executions of prepared statements are sent to the master. Because of this the preparations
should be all sent to the master server instead of sending them to all servers.
2015-10-19 09:01:58 +03:00
counterpoint
e38ea9d07d Correct missing return value. 2015-10-02 16:19:59 +01:00
Markus Makela
4f316419c5 Merge branch 'develop' into MXS-329 2015-09-30 12:47:28 +03:00
Markus Makela
96f76a1f2e Changed the way max_sescmd_history works and combined disable_sescmd_history and disable_slave_recovery.
Before these changes when max_sescmd_history was used the session
was closed when the limit was exceeded. With this change, when the
limit is exceeded the recovery of slaves and the session command history
are both disabled. This will allow the sessions to continue while still
keeping the old functionality of limited salve replacement.

The disable_sescmd_history and disable_slave_recovery parameters were combined
so that disabling the session command history will also disable slave recovery.
This way no harm can be done with disable_sescmd_history.
2015-09-29 12:03:22 +03:00
Johan Wikman
db0e2e881f Double free prevented.
routeQuery calls route_single_stmt, which requires the GWBUF to be
contiguous. Earlier it was made contiguous (if needed) in
route_single_stmt. However, since the process of making a GWBUF
contiguous causes the original buffer to be freed, this would lead
to a double free later in routeQuery that frees the passed buffer.

This is prevented now by making the buffer contiguous before calling
route_single_stmt.
2015-09-29 10:57:45 +03:00
counterpoint
2231d0870c Place checks in callback routines because DCB will not always contain a reference to a router session, and the associated data will be invalid in this case. 2015-09-25 12:17:18 +01:00
Markus Makela
2dfb9e3c11 Merge branch 'develop' into MXS-329 2015-09-24 17:59:36 +03:00
Johan Wikman
561891aac5 Fix for double free, possible fix for bug601.
In the end of execute_sescmd_in_backend the buffer was consumed
in case the protocol function failed. Or actually if it returned
something else but 1.

In the case of mysql_backend, the buffer is always freed when
authorizing and either consumed or placed on the dcb writequeue
when the data is written.

That is, it is never ok to consume the buffer in this function.
The end-result is likely to be an abort.
2015-09-21 13:45:15 +03:00
counterpoint
88716c35fb Various changes to block loopholes in different cases and tidy up. 2015-09-21 09:23:22 +01:00
Martin Brampton
31c6666278 Ensure DCB for closing session does not become persistent; remove bref_was_not_in_use. 2015-09-17 14:38:56 +01:00
Martin Brampton
dc3b0b067b Revert the dcb_close changes in handleError. 2015-09-17 13:35:18 +01:00
Martin Brampton
1ad8e27c91 Try a different arrangement of DCB closures in handleError of read-write split. 2015-09-17 13:27:25 +01:00
Martin Brampton
357c4bcae5 Add to or take from persistent pool only if server is running; add conditions to DCB close in read-write handleError to check backend reference was in use. 2015-09-17 12:53:59 +01:00