Commit Graph

2312 Commits

Author SHA1 Message Date
36b10d3f05 MXS-1502: Log session command warning only once
The warning that tells the user that the session command history has been
exceeded is now only logged once. This is to prevent the message from
being repeatedly logged when the default value is not large enough.

Also fixed the session_limits test to use distinct session commands. This
way the session command history compaction is not in effect and the test
again tests the correct thing.
2018-04-03 13:32:10 +03:00
07821970ff MXS-1503: Remove false debug assertion
It is possible, and perfectly OK, for the new master to be in use at the
same time the old master is. This is the case if one of the slaves is
promoted as the master.
2018-04-03 13:32:10 +03:00
caa5fe89bb MXS-1503: Make sure backend is in use before using it
The get_backend_from_dcb function needs to check that the backend is in
use before comparing the pointer. This prevents stale pointers from being
used and is logically more sound than relying on raw DCB matches.
2018-04-03 13:32:10 +03:00
be0ab82283 MXS-1503: Fix master failure logging logic
The code that logs the master failure error was not working correctly
after the changes done for MXS-359 and MXS-1503. Updated the logic and
converted impossible cases into debug assertions.
2018-04-03 13:32:10 +03:00
319122e621 MXS-1502: Add have_session_commands helper function
The function conveys the meaning of the call better than using
session_command_count to check whether there are session commands to be
executed.
2018-04-03 13:32:10 +03:00
7d4f37d25b MXS-1503: Fix read-only mode regression
The master_failure_mode=error_on_write mode was broken due to a faulty
assumption that all successfully routed queries would produce a
target. This is not the case when a write in error_on_write mode is
received.
2018-04-03 13:32:09 +03:00
a15d36b2f0 MXS-1503: Take EqualPointees<T> into use
Take the template into use in readwritesplit.
2018-04-03 13:31:53 +03:00
14e399dd68 Move RWSplitSession into rwsplitsession.cc
Moved the class method definitions into the correct file.
2018-04-03 13:30:55 +03:00
d5643bc14d Create RWBackends from servers
Added a helper function that creates a list of servers to use. This should
remove some of the duplicate code in the routers.
2018-04-03 13:30:55 +03:00
6ef9e1fd9a Move RWBackend into a separate file
Moved the RWBackend class implementation into its own file. Made some of
the command type functions a part of the <maxscale/protocol/mysql.h>
header to make it reusable.
2018-04-03 13:30:55 +03:00
8206e1f46d Move RWBackend::reply_is_complete into rwsplitsession.cc
The function is now defined in the correct file. Removed the debug output
as it can be logged inside RWBackend::set_reply_state.
2018-04-03 13:30:54 +03:00
8222bdbc20 Move reply_is_complete into RWBackend
Moved the reply state checking inside the RWBackend class to make it
possibly reusable in other parts of MaxScale. Also removed a redundant
function.
2018-04-03 13:30:54 +03:00
3857912c61 MXS-1503: Abort connection when inside transaction
Before the transaction migration is implemented, the connection must be
closed if a transaction is open and the connection to the master is
lost. Doing this retains the same transactionality as a direct connection
to the server would.
2018-04-03 13:30:54 +03:00
7f0745e552 MXS-1503: Queue command if executing a session command
When a non-connected target is chosed as the target server and the session
command history is not empty, the query needs to be placed into the query
queue and routed only after the session commands have been executed.
2018-04-03 13:30:53 +03:00
e57ac4b0a3 MXS-1502: Prune session commands
The session command history is now compacted to contain only the first and
last execution of a session command. This should still allow most of the
more eccentric use-cases of user variables while keeping the session
command history smaller.

Added some convenience functions into the SessionCommand class to make the
pruning process easier.
2018-04-03 13:30:53 +03:00
ce853d3f7f MXS-1503: Enable limited session command history
Enabling the session command history but limiting it to a history of 50
commands allows reconnections for sessions that don't change the state too
often.

As pooled connections will exceed this limit quite fast, they are not able
to reconnect to servers once connections are lost. To solve this problem,
the session command history needs a compaction process that removes
redundant history.
2018-04-03 13:30:53 +03:00
7e4665b03b MXS-1503: Respect max_slave_connections
The slave selection now again respects max_slave_connections. This means
that the amount of slave connections each session has will never grow
beyond the configured value.
2018-04-03 13:30:52 +03:00
4cf9bec10b MXS-1503: Restore slave reconnection
The slave connections can now be recovered after a failure as long as the
session command history is enabled. In comparison to the old
functionality, the server now replaces the connection when a query is
received instead of reconnecting when the slave fails.

As a negative side effect of this change, the max_slave_connections is no
longer enforced after the connection is created. To fix this broken
functionality, the connected slaves need to be preferred over unconnected
ones. This will be added in a follow-up commit.
2018-04-03 13:30:52 +03:00
3d63d18bdd MXS-1503: Split get_target_backend into smaller pieces
Split the code into separate functions. This should make it easier to
comprehend.
2018-04-03 13:30:52 +03:00
9c7578272c MXS-1503: Refactor slave selection
Refactored and cleaned up the slave selection in preparation of
reconnection code unification.
2018-04-03 13:30:52 +03:00
876187b340 MXS-1503: Enable master reconnection
The `master_reconnection` parameter now controls both the reconnection of
the master server as well as the migration of the master server to another
server. Although these two cases appear to be different, the end result
from readwritesplit's point of view is the same and are thus controlled
with the same parameter.

The RWBackend class now resets its internal state when it is closed. This
allows readwritesplit to handle the case when a result was expected from
the master but the master died before the result was returned. The same
code should also handle slave connection failures mid-result, allowing
Backend reuse.

Added a test case that verifies the new functionality when combined with
`master_failure_mode=error_on_write`.
2018-04-03 13:30:51 +03:00
481db8acbc MXS-359: Rename parameter to master_reconnection
Changing the parameter name to `master_reconnection` allows similar
reconnection functionality to be combined under one parameter.
2018-04-03 13:30:51 +03:00
3f803ab3e8 MXS-1503: Don't use empty smart pointers
The check for the existence of a valid pointer is now done in the correct
place.
2018-04-03 13:30:51 +03:00
be2186c8f1 MXS-1503: Remove redundant code
Moved session command execution into the Backend class itself as the
session commands are defined as a related part of it. This allows all
connections to execute session commands if some are available.

Removed explicit SERVER_REF usage in the readwritesplit connection
creation code and replaced it with SRWBackend. This allows the removal of
the get_root_master_backend function which duplicated the functionality in
get_root_master.
2018-04-03 13:30:51 +03:00
a1b5fcd4ff MXS-1503: Clean up connection creation function
The select_connect_backend_servers function is the main connection
creation function. Cleaned it up and split it into smaller, reusable
parts.
2018-04-03 13:30:51 +03:00
a0a37bf793 MXS-1503: Disable reconnection in clientReply
Disabled the reconnection in clientReply prior to moving the connection
creation code into routeQuery. This allows new connections to be made when
they are needed.
2018-04-03 13:30:50 +03:00
1ddcb15547 MXS-1625 Move RWS specific data out from function
In order to be able to move routing decision into the
query classifier, no RWS specific data can be present.
2018-03-29 13:02:38 +03:00
93cd4e7de3 MXS-1625 Remove rwsplit_tmp_table_multi.cc
Contains no functionality anymore.
2018-03-28 12:43:07 +03:00
0e968c2b28 MXS-1625 All RouteInfo functionality moved to routeinfo.cc
Provides a clearer separation between what deals with query
classification and what deals with query routing.

Functions have only been moved. No other cleanup has been
done.
2018-03-27 16:08:18 +03:00
9c6e15b426 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:58:09 +02:00
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
3e0b3db65e MXS-359: Fix master_failure_mode=fail_instantly
The connection was not closed when master_failure_mode=fail_instantly was
used. This caused rwsplit_readonly to fail.
2018-03-20 13:42:25 +02:00
20c5ca1619 Make session state change tracking conditional
By making it conditional, we prevent the problems that arise when the
replication protocol is used in combination with the session state change
tracking. In addition to this, it prevents unnecessary work for routers
and filters that don't need it.
2018-03-20 13:42:24 +02:00
3999bed3e2 MXS-359: Reset temporary table tracking on master change
When the master changes mid-session, the temporary tables are inevitably
lost. This could be avoided by routing temporary table creation to all
servers.
2018-03-14 14:34:49 +02:00
57b18cc0ce MXS-359: Reconnect with disable_sescmd_history if possible
If a session has not yet executed any session commands, it should be
possible to replace failed slave servers.
2018-03-14 14:34:48 +02:00
16f201beed MXS-359: Close failed backend if in read-only transaction
If the connection to the backend where a read-only transaction is being
performed fails, the Backend object should be closed for it. This fixes a
debug assertion in readwritesplit.cc:check_and_log_backend_state which
asserts that the failed connection must not be in use after the error
handling is done.

Also reordered the failing assertion and the accompanying error message so
that the error is logged first.
2018-03-14 14:34:48 +02:00
8d7bff932b Add missing readwritesplit initialization
The wait_gtid_state variable was not initialized. In addition to that, the
routing would continue with a NULL buffer in some cases.
2018-03-14 14:32:03 +02:00
885d0af50f Merge branch '2.2' into develop 2018-03-09 21:00:16 +02:00
e036582a98 Fix typo in readwritesplit log message
The `stmt` label was wrongly set to `pastmt`.
2018-03-08 14:03:46 +02:00
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
c2341a0003 MXS-359: Allow master changes mid-session
With the `allow_master_change` parameter enabled, sessions can start using
a different master node if one is available. This will not prevent
sessions from closing if a write query is received while no master
replacement is available.
2018-03-08 11:19:17 +02:00
d6b8147119 Merge branch '2.2' into develop 2018-03-06 17:02:03 +02:00
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
8232c5d449 Merge branch '2.2' into develop 2018-03-06 10:38:54 +02:00
8bfb4f231a Merge branch '2.1' into 2.2 2018-03-06 10:38:01 +02:00
93f3529bb4 MXS-1697: Treat missing libraries as an error
If the avrorouter is being build and the required libraries are not found,
the configuration process should fail. Adding the command to bypass this
into the error message should make it easier to disable this part if it is
not needed.
2018-03-05 13:58:09 +02:00
ea83420620 Merge branch '2.2' into develop 2018-03-01 18:08:45 +02:00
39d3c42c94 Merge branch '2.1' into 2.2 2018-03-01 17:52:42 +02:00
13c222488e RWS: Log packet length when logging transaction status 2018-02-25 20:56:02 +02:00
9b36ba5e0a MXS-1677: Don't assume all queries are in text form
After a temporary table is created, readwritesplit will check whether a
query drops or targets that temporary table. The check for query type was
missing from the table dropping part of the code. The temporary table read
part was checking that the query is a text form query.

Added a debug assertion to the query parsing function in qc_sqlite to
catch this type of interface misuse.
2018-02-24 17:02:51 +02:00