Commit Graph

921 Commits

Author SHA1 Message Date
7840c86b7f Remove unnecessary result processing in readwritesplit
The result processing code did unnecessary work to confirm that the result
buffers are contiguous. The code also assumed that multiple packets can be
routed at the same time when in fact only one contiguous result packet is
returned at a time.

By assuming that the buffers are contiguous and contain only one packet,
most of the copying and buffer manipulation can be avoided.
2017-10-12 12:29:43 +03:00
0d6c06f33d MXS-1446: Add heartbeat conversion macros
The macros make the conversion from heartbeats to seconds more convenient
and consistent.
2017-09-27 19:44:25 +03:00
551bfb6f26 Merge branch '2.1' into 2.2 2017-09-25 12:35:11 +03:00
944a5bd9c1 Only extract successful PS responses
If a prepared statement fails to execute on a backend server, no prepared
statement ID is returned. As the connection to the slave backend will be
closed when the result of a session command differs from the master's
response, there's no need to even attempt extracting the response.

This change avoids the triggering of a false positive in
mxs_mysql_extract_ps_response when an attempt to extract a
COM_STMT_PREPARE response is made on a response that isn't a
COM_STMT_PREPARE response.
2017-09-25 10:46:55 +03:00
2d590308b6 Set current command when executing queued queries
When readwritesplit is routing any queued queries, the currently executed
command of the protocol modules needs to be adjusted by
readwritesplit. This is not a true fix but more of a workaround to fix the
problems of queued query execution.

The correct solution would be to move the queued query handling into the
client protocol module so that all components see the same state.
2017-09-25 10:46:55 +03:00
30f92ebb4b Only pre-process the current statement
If a statement is about to be queued, there's no need to fully parse it
when it will be done again once the current command being executed
finishes.
2017-09-25 10:46:55 +03:00
fbc1a7d44b Fix handling of multi-packet queries in readwritesplit
If a prepared statement sends large amounts of data, the target server
where the data is sent will be tracked. The tracked target was not reset
after a multi-packet query was completed and the target itself was used to
check whether the session was processing a multi-packet query.

Changed the check to use the boolean variable instead of the target and
added a reset of the tracked target after a multi-packet query was
completed.
2017-09-25 10:46:44 +03:00
9046db06c5 MXS-1295: Add strict_sp_calls parameter
The new parameter allows the session to be "locked" to the master server
after a stored procedure is called. This will keep the session state
consistent if the stored procedure call modifies the state of the session.
2017-09-20 11:18:16 +03:00
68bcd00a22 Merge branch '2.1' into develop 2017-09-20 10:47:53 +03:00
9267f8ad70 MXS-1418: Keep connections open if server is removed
The removal of a server from a service is intended to affect only new
sessions.

Added a test that checks that the connections are kept open even if the
server is removed from the service.
2017-09-16 07:28:17 +03:00
45e0e8bb59 Introduce internal protocol command enum
The enums exposed by the connector are not intended to be used by the
users of the library. The fact that the protocol, and other, modules used
it was in violation of how the library is intended to be used.

Adding an internal mapping into MaxScale also removes some of the
dependencies that the core has on the connector.
2017-09-14 15:30:43 +03:00
3676dcebb1 MXS-1398: Clean up mysql.h header
Cleaned up the MaxScale version of the mysql.h header by removing all
unused includes. This revealed a large amount of dependencies on these
removed includes in other files which needed to be fixed.

Also sorted all includes in changed files by type and alphabetical
order. Removed explicit revision history from modified files.
2017-09-14 15:30:43 +03:00
e6f78bfcb3 Pass modutil function state as a struct
This allows the type to change without changing it at the call sites.
2017-08-29 22:46:35 +03:00
13f7015e7b Fix EOF packet calculation for large rows
The EOF packet calculation function in modutil.cc didn't handle the case
where the payload exceeded maximum packet size and could mistake binary
data for a ERR packet.

The state of a multi-packet payload is now exposed by the
modutil_count_signal_packets function. This allows proper handling of
large multi-packet payloads.

Added minor improvements to mxs1110_16mb to handle testing of this change.
2017-08-25 17:00:42 +03:00
ae2b9fd30d Fix hang with queries larger than 2^24 bytes
Readwritesplit didn't track multi-packet queries which resulted in them
being confused for pipelined queries.
2017-08-24 09:46:02 +03:00
ca4dbf5d0d Refactor readwritesplit connection creation
The connections for a router session can now be done without a constructed
router session. This simplifies the creation of new router session by
removing the need to handle memory allocations.

Readwritesplit router sessions are now created in the static `create`
function which handles the actual creation of the connections and
allocation of the session itself.
2017-08-18 10:27:49 +03:00
46b7db1d45 Refactor readwritesplit session creation
Moved the initialization of the router session's member variables into the
constructor. Changed two functions that calculated server counts into the
router instance as they don't relate to a particular session.
2017-08-18 10:27:49 +03:00
d3a77b64c0 Fix response counter discrepancy on retried read
When a read was successfully retried, the original expected response was
not decremented from the reponse counter. This caused one extra response
to be expected for successfully retried reads which caused a hang after a
retried read.
2017-08-17 15:02:16 +03:00
db8ad7efa8 Fix MXS-1323 regression
The check for session command count on failed session command was inverted
so that only session command failures would be routed to the client.
2017-08-16 13:27:39 +03:00
5a5ab1fb26 Fix routing of stored queries in error handler
When a session command was executed and the last slave that was executing
dies, readwritesplit would route any pending queries before closing the
slave connection. This could cause a hang if the routing logic decided to
pick the failed server as the target of the stored query.

This fixes the MXS-1323 related regression in the develop branch.
2017-08-16 13:26:46 +03:00
782b8db2aa Fix readwritesplit handling of unexpected responses
The backend server can send a response even if the client hasn't sent a
request. One case where this occurs is when the server is shutting
down. The internal logic of readwritesplit can't handle unexpected states
gracefully so the safest thing to do is to just ignore them and send the
responses to the client.
2017-08-02 11:51:26 +03:00
3eb99139f5 Merge branch '2.1' into develop 2017-07-31 15:57:05 +03:00
ed44c45be1 MXS-1323: Fix crash on attempted retry of read
When a backend is waiting for a response but no statement is stored for
the session, the buffer where the stored statement is copied is not
modified. This means that it needs to be initialized to a NULL value.

Added a test that checks that the behavior works as expected even with
persistent connections. A second test reproduces the crash by executing
parallel SET commands while slaves are blocked.

There is still a behavioral problem in readwritesplit. If a session
command is being executed and it fails on a slave, an error is sent to the
client. In this case it would not be necessary to close the session if the
master is still alive.
2017-07-25 11:25:43 +03:00
cb57e10761 Develop merge
Develop merge
2017-06-29 15:34:22 +02:00
8825f89670 Perform cleanup of rwsplit_route_stmt.cc
Adjusted comments and variable declarations.
2017-06-22 10:40:19 +03:00
33a0f8be88 MXS-852: Add support for text protocol prepared statements
When a statement is being prepared, the type and name of the statement is
stored in the router session. If the name of a statement to be executed is
found in the map, the query type that stored in the map is used.
2017-06-22 10:40:18 +03:00
1ac37d6a50 Change rwsplit comparison function types
The comparison functions now take a const reference to a Backend type
class.
2017-06-22 10:40:18 +03:00
c7520a2156 Add name and uri helpers to Backend
Providing helper functions for the commonly used parts of the server makes
code easier to read. It also removes any possibility for formatting
problems by moving the URI and name string handling inside the Backend
class.
2017-06-22 10:40:18 +03:00
d7543988ee Add server state helper functions
Added helper functions that check various server states. This makes the
readwritesplit code easier to read as the function names convey the
intention better than the macro invokations.
2017-06-22 10:40:18 +03:00
37b6cf250d Rename readwritesplit variables
Renamed variables to better represent the types of variables they
represent. Reordered some of the functions so that the functions don't
need to be declared before they are used.
2017-06-22 10:40:18 +03:00
aa61c8a30b Clean up backend comparison function
Renamed and reorganized the function that compares the backend servers.
2017-06-22 10:40:18 +03:00
ae1cdea802 Clean up functions that use SRWBackend
Return values instead of objects. This removes the need to handle cases
where a reference to a "debug value" is returned.

Return SRWBackend values instead of passing output references. This
doubles as a false boolan return value when an empty reference is
returned.
2017-06-22 10:40:18 +03:00
0c8e68fd05 Rename and overload adding of session commands
As the session commands are always appended to the end of the list, the
name should reflect that action. For this reason, the function was renamed
to append_session_command.

Readwritesplit supports replacement of slave servers by storing all
executed session commands in a list. To make the copying of this list a
bit cleaner, an overload for a list of session commands was added. This
will allow relatively smooth addition of server replacement to all router
modules that use the Backend class.
2017-06-22 10:40:17 +03:00
869325e00a Make execute_session_command virtual
Making the function allows higher level checking to be done by the derived
class.

The readwritesplit does some of the reply bookkeeping for session commands
in the function. This makes their execution less prone for errors as the
states are always updated correctly whenever a session command is
executed.
2017-06-22 10:40:17 +03:00
0c45eb5d17 Take SessionCommand into use in readwritesplit
Readwritesplit now uses the SessionCommand class as a "master list" of
executed session commands. This allows the session commands to be easily
copied over to slaves that are taken into use after session commands have
already been executed.

Currently, the code doesn't execute the session command history when a
mid-session reconnection occurs. A method to cleanly copy the session
commands needs to be exposed by the Backend class.
2017-06-22 10:40:17 +03:00
b48bb4fc5e Refactor auxiliary routing functions
Refactored some of the functions used to calculate servers. Removed
redundant checks and moved the ack_write() call to the right place.
2017-06-22 10:40:17 +03:00
15ef274178 Refactor routing code to use the Backend class
The Backend class is now used to handle the interaction with the backend
servers in the code that decides where each query is routed.
2017-06-22 10:40:17 +03:00
ab56cd0074 Use Backend in readwritesplit.cc
Removed old router property code as it is no longer needed when
SessionCommand class used by the Backend class is taken into use.

Removed unnecessary code that is implemented as a part of the Backend
class.

Changed functions to return references to Backends instead of handling raw
DCBs. This introduces a few cases where the code returns a reference when
no reference is actually available. These cases are solved by having an
empty static shared_ptr that is returned in these cases. This is done to
silence any compiler warnings that returning references to local variables
would bring as these should never happen if the code is functioning
properly.
2017-06-22 10:40:16 +03:00
5a5effdf7a Take Backend into use in rwsplit_select_backends.cc
This is the first step to taking the Backend class into use. It is now
used in rwsplit_select_backends.cc and readwritesplit.hh. The module is
not yet functional and doesn't even compile.

Added some helper functions to the Backend class to get easier access to
the server referenced by the SERVER_REF and to check the state of the
backend.
2017-06-22 10:40:16 +03:00
05fef4b23e Duplicate connections to the Backend class
Creating duplicate connections using the Backend class allows the
connections and their handling to be tested at the same time that the old
system is in place. This should make it somewhat easier to grasp what
changes and where when the new implementation is taken into use.
2017-06-22 10:40:16 +03:00
dc8c20bf6a Store session commands also as SessionCommand
The session commands are now duplicated as SessionCommand objects This
allows for an easier migration from the old session command implementation
to the new one.
2017-06-22 10:40:16 +03:00
1ffe04571c Integrate the temporary tables into the router session
Removed the temporary table router property and moved the set of tables
into the router session.
2017-06-22 10:40:16 +03:00
dfc1d0a413 Always include debug members in objects
Having the structures be of the same size with and without debug mode is
beneficial when debugging release binaries.
2017-06-22 10:40:16 +03:00
bd7a26d830 Abstract the session default database
The default database can now be manipulated with a set of functions
exposed by the maxscale/protocol/mysql.h header. This removes the need to
handle the structures themselves in the modules and is a step towards
moving the dcb->data contents inside the session.
2017-06-22 10:40:16 +03:00
93660c19ed Reorganize readwritesplit.cc
Reorganized the main source file of readwritesplit. The internal functions
are first followed by the API entry points. The actual module definition
is the last declared object in the file.
2017-06-22 10:40:16 +03:00
cb7f257ea0 Refactor rewadwritesplit temporary table handling
The temporary table detection and handling now uses C++ containers to
store the set of temporary tables. The detection also uses the new query
classifier field info API to detect which tables and databases are
targeted.
2017-06-22 10:40:16 +03:00
4c1dc9e624 Clean up readwritesplit.hh
Cleaned up the readwritesplit main header. The structs were named to their
typedef names so that no code changes are required. The structs should be
renamed if/when they are converted to proper C++ classes.
2017-06-22 10:40:15 +03:00
f5a0526f2c Use new instead of malloc
Using new instead of malloc is required for proper initialization of C++
classes.
2017-06-22 10:40:15 +03:00
c77dcea807 Compile readwritesplit as C++
Compiling readwritesplit as C++ allows the use of C++ containers.
2017-06-22 10:40:15 +03:00
32cd28daf2 Rename MAX_SERVER_NAME_LEN to MAX_SERVER_ADDRESS_LEN 2017-06-19 14:05:26 +03:00