208 Commits

Author SHA1 Message Date
Markus Mäkelä
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
Markus Mäkelä
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
Markus Mäkelä
c7a45466fb Use Backend::write for all writes in schemarouter
The schemarouter should always use Backend::write for communication with
the backend servers. This keeps the backends in the correct state.

This fix solves some of the random test failures in the `sharding` test.
2017-07-18 11:36:54 +03:00
Markus Mäkelä
ef73f3e217 Merge branch '2.1' into develop 2017-07-06 11:25:36 +03:00
Markus Mäkelä
9618e63b5f MXS-1310: Add deterministic conflict resolution
The schemarouter can now resolve database mapping conflicts in a
deterministic manner. This will fix the problem of central databases which
are replicated shards being assigned in a non-deterministic manner.
2017-07-05 19:19:49 +03:00
Markus Mäkelä
0c33572a96 MXS-1310: Detect implicit database usage
When the current database is implicitly used in a query that also uses an
explicit database, it must be routed to the shard which has the current
database.

As cross-shard joins are not supported, the safest, and possibly the most
expected course of action to take, is to route it to the so-called default
shard. The default shard is the shard that contains the database that is
currently set as the active database with a COM_INIT_DB, a text protocol
USE <database> query or it was set at connection time.
2017-07-04 23:21:04 +03:00
Markus Mäkelä
c6b579619a MXS-1310: Route implicit table queries to the current shard
When a query that implicitly uses the current database is detected, it
will be routed to the shard which has the current database.
2017-07-04 23:04:27 +03:00
Markus Mäkelä
374c204a04 Only print text protocol statements in schemarouter
The schemarouter info level logging treated all queries as something that
contain SQL statements. This, for somewhat obvious reasons, cannot be
expected.
2017-07-04 22:26:24 +03:00
Markus Mäkelä
71bc67b694 Use unordered_map in schemarouter
The shard map doesn't have to be in order and an unordered map will do
just fine.
2017-07-04 13:01:04 +03:00
Markus Mäkelä
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
Markus Mäkelä
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
Markus Mäkelä
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
Markus Mäkelä
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
Johan Wikman
f546a17e77 Update change date of 2.2 2017-06-01 10:24:20 +03:00
Esa Korhonen
aebe839990 Change session id to 64bit
The server internal session id may be larger than 4 bytes (MariaDB uses 8)
but only 4 are sent in the handshake. The full value can be queried
from the server, but this query is not supported by MaxScale yet. In any
case, both the protocol and MXS_SESSION now have 64 bit counters. Only the
low 32 bits are sent in the handshake, similar to server.
2017-05-10 13:26:25 +03:00
Markus Mäkelä
8e2c7fd952 Merge branch '2.0' into 2.1 2017-05-10 09:12:42 +03:00
Markus Mäkelä
fc887c7f5f MXS-1220: Add old router diagnostic interface
Added back the old diagnostic entry point to the router interface.
2017-05-04 09:17:42 +03:00
Markus Mäkelä
076599ee5e MXS-1220: Make the parameters of the diagnostic entry points const
The diagnostic entry points should not modify the state of the object
being diagnosed.
2017-05-04 09:14:03 +03:00
Markus Mäkelä
eb3ff1cc7b MXS-1220: Implement JSON diagnostics for most routers
All routers except the binlogrouter now fully implement the JSON
diagnostic entry point. The binlogrouter needs to be handled in a separate
commit as it produces a large amount of diagnostic output.
2017-05-04 09:12:15 +03:00
Esa Korhonen
bfd94c2b31 KILL [CONNECTION | QUERY] support, part1
Preparation for adding KILL syntax support.
Session id changed to uint32 everywhere. Added atomic op.
Session id can be acquired before session_alloc().
Added session_alloc_with_id(), which is given a session id number.
Worker object has a session_id->SESSION* mapping, not used yet.
2017-05-02 10:29:55 +03:00
Markus Mäkelä
ce6b52ab39 Rename schemarouter internal functions
Renamed the functions to better describe what they do.
2017-04-06 09:22:21 +03:00
Markus Mäkelä
c37c5abfeb Use collectable resultset type for database mapping
When the databases are mapped, it is desirable to get the complete
response in one contiguous buffer. This removes the need to manually
process the partial packets in the router code.
2017-04-06 09:22:21 +03:00
Markus Mäkelä
2310381465 Make variables of Backend private
The variables are no longer directly manipulated by the session level
code.
2017-04-06 09:22:21 +03:00
Markus Mäkelä
0d7f987598 Move state checks inside the Backend class
The class now has methods to query its internal state.
2017-04-06 09:22:20 +03:00
Markus Mäkelä
cbc1e864d9 Use RFC 3986 compliant addresses in log messages
When log messages are written with both address and port information, IPv6
addresses can cause confusion if the normal address:port formatting is
used. The RFC 3986 suggests that all IPv6 addresses are expressed as a
bracket enclosed address optionally followed by the port that is separate
from the address by a colon.

In practice, the "all interfaces" address and port number 3306 can be
written in IPv4 numbers-and-dots notation as 0.0.0.0:3306 and in IPv6
notation as [::]:3306. Using the latter format in log messages keeps the
output consistent with all types of addresses.

The details of the standard can be found at the following addresses:

     https://www.ietf.org/rfc/rfc3986.txt

     https://www.rfc-editor.org/std/std66.txt
2017-03-31 14:12:58 +03:00
Markus Mäkelä
5c1c89c835 Remove unused buffer types
A part of the buffer types weren't used or provided no real functionality.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
c59ed30da1 Simplify error handling
The error handlers are now simpler as the Backend class handles the
closing of the connections.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
a3396a06b8 Fix shared_ptr usage
The std::shared_ptr type was used instead of std::tr1::shared_ptr. A NULL
pointer was also implicitly cast into a Backend pointer which caused
compilation problems on some platforms with the tr1 version of shared_ptr.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
6e218adc1d Make connections and command queues internal to Backends
The SERVER_REF and DCB members of the Backend class are now
private. Access to the stored SERVER_REF is provided with the backend()
function. No accompanying setter function is provided as the backend
server should not change during the lifetime of the session.

The creation of the internal DCB is hidden behind the connect()
function. It simplifies the process of connecting to a server by removing
the need to manually do the bookkeeping of the server reference connection
counts. Access to the DCB is provided by the dcb() function.

The closing of the backend is done with the close() function which
contains the code that was previously in closeSession. If the backend
isn't closed when the destructor is called, it will be done
automatically. This should prevent connection leakage.

The pending command queues and the methods used to write them are now also
internal to the backends. They are simple wrappers around dcb->func.write
and the interfaces provided by the Buffer class. The mapping command queue
is still public. It needs to be combined with the generic command queue.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
66fa4fbc7d Use shared pointers to Backend classes
The schemarouter now uses shared pointers. This removes the need to copy
the class.

Following changes move the member variables inside the Backend class.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
f9e5275605 Fix bugs introduced by refactoring
Fixed minor bugs that were introduced by the refactoring.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
94ac2d89d0 MXS-1160: Add support for LOAD DATA LOCAL INFILE
Schemarouter now supports the LOAD DATA LOCAL INFILE command.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
f6470c580a Fix minor problems
Use correct value in initialization, return correct return value on
success, do a equals comparison on route target.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
34b0b07cd1 Ignore duplicate shards in a subfunction
The ignoring of duplicate shards is now done inside a subfunction.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
5ba9de6f42 Move Backend functions inside the class
The functions that handle Backend classes are now methods of the class
itself.

Prefix all member variables with `m_` to distinct them from other
variables.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
d1aa2a4b8a Use a list of backends instead of an array
Changed the backend_ref_t struct into a Backend class. Replaced static
arrays with lists. Altered functions to make the code compile.

Further refactoring is needed, a part of the functions should be moved
into this new class.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
c4638666cf Remove typedefs from schemarouter enums
The enum typedefs weren't really useful in most cases.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
f5a259ba57 Do configuration outside of constructors
Configuration errors can be resolved before the instance is created. This
avoids the unnecessary throws that were generated when an error occured.

As the configuration is stored in the router, the router sessions can use
a pointer to it instead of copying it locally. This should avoid some
unnecessary copying if more complex configuration parameters are added.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
b9fae58891 Favor pointers over references
The use of a pointer instead of a reference conveys the message that the
lifetime of the object being pointed can, and most likely will, exceed the
lifetime of the function.

Also shuffled the member variables and internal functions around and
removed unneeded function declarations.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
02796e7304 Move #pragma to first line in each header
The `#pragma once` is now on the first line of each header.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
14cfd482de Fix variable naming and usage
Don't use `this->` when it's not needed. Use snake_case for member
variables. Initialize the members using a initialization list.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
a10aa85736 Clean up routeQuery and clientReply
Moved parts of the functionality into subfunctions. Reordered code to
remove redundant logic.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
39903e40b7 Rename member variables
Renamed and cleaned up schemarouter member variables. Removed unused
variables.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
ac641e0f22 Use router template in schemarouter
The schemarouter now uses the router template.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
b2ff0c5a0f Clean up schemarouter headers
Cleaned up the headers, removed unused structures. Changed some members to
strings instead of char arrays. Switch to router templates should now be
easier.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
d151512d20 Take new sharding implementation into use
The sharding implementation now uses a class to abstract the details of
the shard. This allows for different design where each session makes a
copy of the global shard map which is then used for the duration of the
session. In addition to making the desing a bit clearer to understand, it
also removes lock competition between threads.

Due to the change to C++, the main entry points need to be wrapped in the
exception-safety macros. The next step in the refactoring will be to use
the router template. This will remove the need to manually define them.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
9587b2ecfc Remove unused schemarouter code
The temporary table detection in schemarouter was not used.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
bda0fd2db0 Replace session command implementation
The schemarouter now uses the new session commands. It uses a standard
library container to manage the execution and storage of session commands.

The session command history is disabled until a more complete refactoring
can be done.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
d8abefff5f Add session command class
The class abstracts the session commands and the lists of session commands
using standard library containers.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
9e4e70a337 Move shard map handling into a separate file
Moved the handling of shard maps into another file.
2017-03-31 14:12:00 +03:00