Commit Graph

1889 Commits

Author SHA1 Message Date
09fb336403 Abstract EVP cipher context creation
The EVP_CIPHER_CTX is now created inside a wrapper function to add support
for OpenSSL 1.1. Also fixed improper use of the EVP_CIPHER_CTX internals
in binlogrouter.
2017-06-29 15:55:44 +03:00
8fb9b79dbb Make RWSplit::config() const
The function can be const.
2017-06-29 15:53:50 +03:00
3b3799889e MXS-852: Fix PS storage when locker to the master
When the router session is locked to the master, the storage of prepared
statements is not necessary as no other server can be used. The ID sent by
the client can be used without modification as it will always be the same
on the master.
2017-06-29 15:53:50 +03:00
1f8072f3d6 Fix temporary table detection in readwritesplit
The column information does not contain the used tables and the correct
function to use is qc_get_table_names.

Added a utility function for iterating over the set of tables. This
removes the need to have the same table iteration code in multiple places
and makes the code easier to comprehend.
2017-06-29 15:53:50 +03:00
5384162fb1 Fix slave server candidate ordering
The return value of the comparison was misinterpreted so that the
selection process preferred the new candidate over the current one if both
were equal. This was not an intended change and only a better candidate
should be chosen over the current candidate.
2017-06-29 15:53:50 +03:00
f7500cce9e Clean up route target resolution function
Cleaned up the function that resolves to which type of a server the query
should go.
2017-06-29 15:53:50 +03:00
dd05b44d38 Always extract the current command from the buffer
As readwritesplit queues queries, it needs to extract the command from the
buffer when the queued queries are routed. It cannot rely on the client
protocol command when the rerouting is taking place.
2017-06-29 15:53:50 +03:00
b0023e1689 Clean up readwritesplit API functions
Cleaned up some of the comments and documentation for the
functions. Renamed some variables and moved parts of the error handling
logging into a subfunction.
2017-06-29 15:53:50 +03:00
f2b199b3b0 MXS-852: Refactor gathering of routing information
The routing information is now gathered into a struct before the routing
process is started. This allows the requirements of the query to be
gathered before the actual target is selected.
2017-06-29 15:53:50 +03:00
a9a1291703 Split readwritesplit sources into separate parts
The common readwritesplit header was split into three distinct parts; the
instance, session and prepared statement headers. The definitions of any
members were moved to .cc files away from the headers.

The RWSplitSession, with its RWBackend class, is declared in the
rwsplitsession.hh header with all relevant definitions in
rwsplitsession.cc.

The PSManager class and all prepared statement related functions are now
located in the rwsplit_ps.hh header.

The old readwritesplit.hh header now contains the instance level
structures and all common classes used by the router. The
rwsplit_internal.hh header could be absorbed into the three newly created
headers with new headers for distinct parts of the router.
2017-06-29 15:53:50 +03:00
013b081b9e Rename readwritesplit router session class
Renamed the struct to RWSplitSession and removed the obsole next pointer.
2017-06-29 15:53:50 +03:00
917fe21f72 Refactor readwritesplit instance class
Changed the ROUTER_INSTANCE struct to a class and added functions for
common operations.

Renamed configuration and statistics structures and added constructors.

Moved objects around in readwritesplit.hh to be ready for a split into
multiple headers.
2017-06-29 15:53:50 +03:00
8ed16fd9d2 Reduce readwritesplit debug verbosity
Moved the LOG_RS output down to debug level. The output is not useful for
the end users.
2017-06-29 15:53:50 +03:00
16201592a2 MXS-852: Fix execution of COM_STMT_FETCH
The COM_STMT_FETCH queries are always executed when the result has not
been fully read. This means that the statement queuing code needs to allow
COM_STMT_FETCH commands to pass if a statement is being executed but the
command queue is empty.
2017-06-29 15:53:50 +03:00
296c1001a2 MXS-852: Track COM_STMT_EXECUTE by statement ID
The COM_STMT_EXECUTE targets are now tracked per statement ID. This should
theoretically allow parallel execution of COM_STMT_EXECUTE commands that
use cursors but the current implementation of the reply state processing
does not yet allow it.
2017-06-29 15:53:50 +03:00
d0b8ccd6b8 MXS-852: Track target of last COM_STMT_EXECUTE
Tracking of the node where the last COM_STMT_EXECUTE was sent allows
routing of all following COM_STMT_FETCH to the same node. This is required
for cursors to work.

MariaDB/MySQL does not support multiple active cursors so the
COM_STMT_FETCH will always refer to the latest COM_STMT_EXECUTE and using
a different ID goes against the protocol. If/when the support for multiple
active cursors is added, the tracking should be done for each
COM_STMT_EXECUTE statement. This should be relatively easily to achieve
but currently it is unnecessary.
2017-06-29 15:53:50 +03:00
52b7fb9340 MXS-852: Handle one-way session commands
Session commands that will not return a response can be completed
immediately. This requires some special code in the readwritesplit Backend
class implementation as well as a small addition to the Backend class
itself.

Since not all commands expect a response from the server, the queued query
routing function needs some adjustment. The routing of queued queries
should be attempted until a command which expects a response is found or
the queue is empty.

By properly handling these types of session commands, the router can
enable the execution of COM_STMT_CLOSE and COM_STMT_RESET on all
servers. This will prevent resource leakages in the server and allow
proper handling of COM_STMT type command.
2017-06-29 15:53:50 +03:00
5fc30740b7 MXS-852: Store the internal ID in the buffer
If the internal ID is stored in the buffer when it is moving inside the
readwritesplit router, the RWBackend can manage the execution of all
commands with a statement ID by replacing the stored ID with the correct
value.
2017-06-29 15:53:49 +03:00
3c4e1e3b4b MXS-852: Use stored query type for COM_STMT_EXECUTE
When a COM_STMT_EXECUTE or a COM_STMT_SEND_LONG_DATA command is executed,
the query type of the prepared statement is used. This allows read-only
prepared statements to be load balanced across slaves.
2017-06-29 15:53:49 +03:00
77f78c4b20 MXS-852: Map client PS handle to internal ID
Mapping the handles returned to the client to a session command ID allows
the mapping of client handle to the backend specific handle. Currently,
the mapping is used for diagnostic output only.
2017-06-29 15:53:49 +03:00
0aa0fa82b7 MXS-852: Add PS manager class
The class manages both text and binary protocol prepared statement ID to
type mapping. The text protocol statements are mapped by their plaintext
name and the binary protocol statements are mapped by the session command
ID of the prepared statement.

By mapping the binary protocol prepared statement type to the session
command identifier, we can store the types for both styles of prepared
statements in a very similar manner. When the prepared statement handle is
received from the backend and is sent to the client, the client handle to
session command ID mapping can be done. This allows the mapping of both
client and backend PS handles to internal session command IDs.
2017-06-29 15:53:49 +03:00
3eac28248d MXS-852: Store prepared statement handles in RWBackend
The readwritesplit Backend implementation maps the returned PS handles to
session command identifiers. This allows the handles to be retrieven later
on when the prepared statements are executed.
2017-06-29 15:53:49 +03:00
4993fd683c Merge branch 'develop' into MXS-1266 2017-06-29 11:31:56 +02:00
6cd6ded3d8 Merge branch '2.1-oracle-compat' into develop-new-merge-oracle 2017-06-29 09:39:55 +02:00
40b1739249 MXS-1299: Fix CREATE TABLE t1 LIKE t2 processing
The creation of tables from other tables was not working even though the
information was available inside the avrorouter.
2017-06-28 11:25:57 +03:00
84925b3f10 Merge branch '2.0' into 2.1 2017-06-28 10:59:06 +03:00
9b0631f30b MXS-1289: Fix crash on TABLE_MAP with ID > 1024
The active table map was acquired with a modulo operation on the size of
the array instead of the number of elements.
2017-06-28 08:49:57 +03: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
18993bc8ca Refactor Backend class states
The states are now internal to the Backend class. This simplifies the use
of the class by moving the burder of state tracking to the class
itself.

Refactored the way the schemarouter uses the Backend class.

Also fixed a memory leak in the schemarouter when `ignore_databases_regex`
was used..
2017-06-22 10:40:16 +03:00
bbfd9ce136 Move Backend and SessionCommand classes to the core
Using the same implementation of the Backend and SessionCommand classes in
both schemarouter and readwritesplit will prevent duplication of code.

This commit only splits the generic parts of the class to a Backend class
which the schemarouter then extends. The session commands for both routers
are similar so they require no special handling.
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