2161 Commits

Author SHA1 Message Date
Markus Mäkelä
4fb4ed416b
MXS-1977: Fix protocol and readwritesplit memory leaks
The protocol could leak memory in rare cases where several commands were
queued at the same time. Readwritesplit also didn't free the memory it
acquired via qc_get_table_names.
2018-07-16 06:07:14 +03:00
Markus Mäkelä
ceb1c0f2a4
MXS-1950: Add missing error messages
When a valid target was not found, no error message was logged by the
router. This would cause the "Routing the query failed. Session will be
closed." message to be logged with no explanation as to why the routing
failed.

In addition to the above-mentioned case, no message would be logged if the
target for a COM_STMT_FETCH was not in use.
2018-07-03 02:08:25 +03:00
Markus Mäkelä
f97f422379
Don't use closed backends
Only use backends that are still in use. The COM_STMT_EXECUTE and
COM_STMT_FETCH relationship caused unused backends to be used.
2018-06-27 08:49:21 +03:00
Markus Mäkelä
6183fab79b
MXS-1938: Log query for inconsistent replies
If a session command produces a different result on the slave than it did
on the master, a warning is logged. This warning now also logs the query
that was being executed to make investigation of the problem easier.
2018-06-25 08:44:13 +03:00
Markus Mäkelä
e561c3995c
Use correct write in Backend::execute_session_command
Backend::execute_session_command would use the overridden write method
instead of the Backend::write method that it intended to use. This caused
session commands that did not expect a response to be in a state that
expected a result.

Also fixed RWBackend::write pass the response_type value to
Backend::write.
2018-06-22 10:37:11 +03:00
Markus Mäkelä
9e4b86ff0a
MXS-1935: Accent NULL from qc_get_preparable_stmt in readwritesplit
If the prepared statement cannot be extracted from the query, treat it as
a query with an unknown type.
2018-06-21 10:04:34 +03:00
Markus Mäkelä
980caa5be5
MXS-1926: Ignore server shutdown errors
If the server sends a server shutdown error, it is safe for readwritesplit
to ignore it. When the TCP connection is closed, the router error handling
will discard the connection, optionally replacing it.
2018-06-20 00:34:16 +03:00
Markus Mäkelä
315738f279
Merge branch '2.1' into 2.2 2018-06-13 23:15:11 +03:00
Markus Mäkelä
53177c30de
Fix runtime listener creation
The number of arguments to createListener was incremented but the maximum
count was not. Also fixed the parameter types for createListener and
alterServer.
2018-06-13 23:13:16 +03:00
Markus Mäkelä
143882ddce
Merge branch '2.1' into 2.2 2018-06-13 21:04:49 +03:00
Markus Mäkelä
1ea7c65861
Fix runtime alteration of servers
The server runtime alteration was broken by commit
c850336199c3c19508a3d280fb7000291d66b80c when it increased the maximum
argument count of the `alter server` command to 14.
2018-06-13 14:29:28 +03:00
dapeng huang
cd136b11a7 MXS-1891: dealloc named prepare should route to all (#174)
* dealloc named prepare route to all

* add newline

* erase from ps manager too

* little refactor
2018-06-12 10:45:11 +03:00
Markus Mäkelä
1a24f0a956
Merge branch '2.1' into 2.2 2018-06-11 10:36:57 +03:00
Markus Mäkelä
1e1734f42e
MXS-1910: Only require ssl_ca_cert for servers
Servers in MaxScale can encrypt the connections without client keys and
certificates. As keys and certificates are no longer required, the CA
certificate must always be initialized.
2018-06-09 00:15:48 +03:00
Markus Mäkelä
a7dd2127d6
Merge branch '2.1' into 2.2 2018-06-08 11:21:35 +03:00
Markus Mäkelä
c850336199
MXS-1907: Allow ssl_verify_peer_certificate when creating listener
When a listener is created at runtime or SSL is being enabled for an
already created listener, the ssl_verify_peer_certificate parameter can
now be defined.
2018-06-08 10:11:43 +03:00
Markus Mäkelä
6ba423cf94
Dump statements on unexpected internal state
If a server responds when no response was expected, dump stored
statements. This should help deduce root causes of problems relating to
unexpected responses.
2018-06-08 07:45:18 +03:00
Marko
0dd7448586 MXS-1709 Fix memory leaks in unit tests 2018-06-06 22:59:52 +03:00
Markus Mäkelä
9d0b1be08b
Improve unexpected response error message
The message now logs the current command and the query if it is available.
2018-06-04 15:17:48 +03:00
Markus Mäkelä
d22f6d7b1c
MXS-1743: Fix load balancing with router_options=master,slave
The code that selects the candidate backend always returned the root
master if the server bitmask contained the master bit. This should only be
done if the master bit is the only bit in the bitmask and when there are
other bits, the normal candidate selection code should be used.

Also added a query to the expanded test case to make sure the connection
actually works.
2018-06-04 15:17:48 +03:00
Markus Mäkelä
cddcc6d7d5
MXS-1896: Distinct LOAD DATA LOCAL INFILE from LOAD DATA INFILE
The two operations return different types of results and need to be
treated differently in order for them to be handled correctly in 2.2.

This fixes the unexpected internal state errors that happened in all 2.2
versions due to a wrong assumption made by readwritesplit. This fix is not
necessary for newer versions as the LOAD DATA LOCAL INFILE processing is
done with a simpler, and more robust, method.
2018-06-04 15:17:48 +03:00
Markus Mäkelä
c88aa11e11
Copy FDE events in avrorouter
Commit 67386980e327ad063b24cb55971cf44f4930e241 caused the actual events
to be ignored. This meant that the larger event size was assumed for all
events. In most cases this works but it is not the correct way to do it.
2018-06-04 15:17:48 +03:00
Johan Wikman
089be56103 MXS-1889 Only turn on master bit for slaves
The bitmask ensures that the master bit would be ignored in
cases where it is not relevant, but nicer if it is set only
when it is relevant.
2018-06-01 13:43:02 +03:00
Johan Wikman
d77a9a3040 MXS-1889 Handle master used as slave
Up until 2.1.12, if it in the configuration file said
'router_options=slave', the master was used if there were no
slaves at session creation time.

That broke in 2.1.13 as a side-effect of MXS-1516 that checks
at routing time whether the server initially selected as master
still is the master.

Now the required server status is stored separately for each
session, so that if the master was chosen, even though we have
'router_options=slave', we can turn on the SERVER_MASTER bit.

That allows us to handle the case correctly in connection_is_valid().
2018-06-01 11:00:13 +03:00
Markus Mäkelä
3cb389a3b5
MXS-1866: Add support for COM_STMT_BULK_EXECUTE
Readwritesplit now detects the COM_STMT_BULK_EXECUTE command and handles
it correctly.
2018-05-18 12:30:24 +03:00
Markus Mäkelä
8067f312a1
MXS-1873: Collect results for all session commands
To work around the limitation in the session command handling and
multi-part results, all session commands are now treated as gathered
results. This allows session commands which return result sets to be used
with MaxScale.

This change should not cause problems with practical workloads as they
usually do not return massive resultsets for session commands.

The optimal way to handle the multi-part responses would be to integrate
it into the result completion tracking process. This would allow the
prepared statement IDs to be extracted while the command is being
processed.
2018-05-18 12:29:34 +03:00
Markus Mäkelä
46d1187172
Backport GCC 8 fixes to 2.1
Backported the minimal set of changes required to build 2.1 with GCC
8. The format-truncation and format-overflow warnings are disabled instead
of fixed in 2.1 to remove duplication of effort that was already done in
2.2 (the commit doesn't cherry-pick cleanly).
2018-05-16 11:09:47 +03:00
Markus Mäkelä
121d255780
Add protocol packet statistics to servers
The individual servers were missing a statistic that would give an
estimated query count. As there is no simple way to count queries for all
modules, counting the number of routed protocol packets is a suitable
substitute.
2018-05-03 09:50:45 +03:00
Markus Mäkelä
c97d2c94eb
MXS-1825: Fix PS output parameter tracking for MySQL variants
The resultset processing for MySQL requires some extra work as it lacks
the proper SERVER_MORE_RESULTS_EXIST flag in the last EOF packet. Instead,
the first EOF packet has the SERVER_PS_OUT_PARAMS flag which needs to be
interpreted as a SERVER_MORE_RESULTS_EXIST flag for the second EOF packet.

Also corrected the EOF packet handling to do the flag checks in the code
that deals with the EOF packets.

As the modutil_state parameter is now used for more than large packet
tracking, the correct solution is to store this state object in the
readwritesplit session instead of interpreting it to a boolean value.
2018-04-26 16:02:09 +03:00
Markus Mäkelä
260fcf85ec
Remove false debug assertion
A prepared statement ID of 0 is allowed.
2018-04-26 16:02:09 +03:00
Markus Mäkelä
0df326d581
MXS-1824: Track only the opening of cursors
Whether a cursor is open or not does not matter as long as the attempt to
open a cursor is detected.
2018-04-26 16:02:09 +03:00
Johan Wikman
5cf56c7c0f Merge branch '2.1' into 2.2 2018-04-24 12:39:22 +03:00
Johan Wikman
bafe8f5eeb MXS-1618 Use right type for the return value of getopt_long
getopt_long returns an 'int'. If 'char' is used on a big-endian
platform you'll end up with an infinite loop.
2018-04-24 12:31:08 +03:00
Markus Mäkelä
d67320e06a
Fix more GCC 8 build failures
Fixed string truncation warnings by reducing max parameter lengths by one
where applicable. The binlogrouter filename lengths are slightly different
so using memcpy to work around the warnings is an adequate "solution"
until the root of the problem is solved.

Removed unnecessary CMake policy settings from qc_sqlite. Adding a
self-dependency on the source file of an external project has no effect
and only caused warnings to be logged.
2018-04-23 14:02:54 +03:00
Markus Mäkelä
ad15f4d4be
Fix binlogrouter build failures with GCC 8
GCC 8 appears to have improved the snprintf truncation detection which
revealed problems in the binlogrouter.
2018-04-17 21:55:47 +03:00
Markus Mäkelä
3a1c2119fb
MXS-1804: Fix hanging of large session commands
Large session commands weren't properly handled which caused the router to
think that the trailing end of a multi-packet query was actually a new
query.

This cannot be confidently solved in 2.2 which is why the router session
is now closed the moment a large session command is noticed.
2018-04-17 15:04:12 +03:00
Markus Mäkelä
232f807ef3
MXS-1808: Only store SQL statements for retrying
Only commands that can contain an SQL statements should be stored for
retrying (COM_QUERY and COM_EXECUTE). Other commands are either session
commands or do not work with query retrying.
2018-04-17 11:25:56 +03:00
dapeng huang
3d09c836c5 init inst->sessions for maxinfo (#173)
* init inst->sessions for maxinfo

* misc fix
2018-04-13 12:58:02 +03:00
Markus Mäkelä
802b16f709
MXS-1786: Fix hang on COM_STATISTICS
The commands needs to be handled separately from the rest of the result
types.

Added a test case that reproduces the problem and verifies that the change
in code fixes it.
2018-04-12 20:00:00 +03:00
Markus Mäkelä
1a293c0093
MXS-1785: Don't assume empty packet is for LDLI
When a LOAD DATA LOCAL INFILE finishes, the client sends an empty
packet. The second case when the client sends an empty packet when the
previous packet was exactly 0xffffff bytes long. These two packets were
confused which caused the internal state to temporarily flip from inactive
to ending and back to inactive.

The aforementioned flip-flopping didn't have any practical differences but
it was caught by a debug assertion.
2018-04-12 19:36:34 +03:00
Markus Mäkelä
da03c73373
MXS-1776: Fix COM_STMT_EXECUTE flag extraction
The code extracted the statement id, not the flags.
2018-04-12 10:25:10 +03:00
Markus Mäkelä
fab8477c05
MXS-1776: Fix utility functions
The COM_STMT_FETCH command will create a response. This was a
readwritesplit-specific interpretation of the command and it was wrong.

Also record the currently executed command event for session commands.
2018-04-12 09:44:28 +03:00
Markus Mäkelä
ad5458f0e7
MXS-1776: Initialize RWBackend::m_command
The variable was not initialized which caused COM_CHANGE_USER to produce
unexpected behavior.
2018-04-12 09:43:38 +03:00
Markus Mäkelä
311adf817f
MXS-1776: Handle recursive COM_STMT_EXECUTE commands
Readwritesplit would not handle multiple overlapping COM_STMT_EXECUTE
commands properly if they opened cursors. This was due to the fact that
the result would not be marked as complete and COM_STMT_FETCH commands
were executed as if they did not return results.

The correct implementation is to consider a COM_STMT_EXECUTE that opens a
cursor complete only when the first EOF packet is read (that is, when the
resultset header is read). This allows subsequent COM_STMT_FETCH commands
to be handled separately.

The separate COM_STMT_FETCH handling must count the number of packets that
are being fetched. This allows correct tracking of the state of a
COM_STMT_FETCH by checking that the number of packets is correct or the
second EOF/ERR packet is read.
2018-04-11 15:26:37 +03:00
Markus Mäkelä
1eefb46e68
MXS-1773: Update internal state when LOAD DATA LOCAL INFILE fails
When a LOAD DATA LOCAL INFILE is actively rejected by the server, the
server sends an error to the client. This error was not detected and the
router was stuck in the special mode that handles LOAD DATA LOCAL INFILE.
2018-04-11 09:25:23 +03:00
Markus Mäkelä
a2fcecd98f
MXS-1743: Fix usage of both master and slave types
The use of `router_options=master,slave` was not working as expected. This
was mostly caused by the master bit checks using a bitwise AND instead of
comparing equality. In addition to this, the master would not be
considered a valid candidate if both slaves and masters were available.
2018-04-04 19:43:46 +03:00
Markus Mäkelä
092286297e
MXS-1719: Fix hang on multi-statement UPDATE
When a multi-statement query consisting completely of UPDATE statements is
received, the packets can be received in two separate buffers. To cope
with this situation, the state change into REPLY_STATE_RSET_COLDEF must
only be done if the buffer contains more than a single packet.
2018-03-21 14:14:16 +02:00
Markus Mäkelä
e036582a98
Fix typo in readwritesplit log message
The `stmt` label was wrongly set to `pastmt`.
2018-03-08 14:03:46 +02:00
Markus Mäkelä
f54bbdf73b
Fix -Werror=format-truncation= warnings in blr_slave.c
The errors were caused by the fact that the server name
MAX_SERVER_NAME_LEN is 1024 bytes long whereas the buffer was 251 bytes.
2018-03-08 11:28:05 +02:00
Markus Mäkelä
016a6a6bd2
Add more info output to readwritesplit replies
When readwritesplit receives a reply from a backend, an info level log
message is now logged. This allows easier debugging of situations where
replies aren't properly returned by the router.
2018-03-06 13:35:15 +02:00