Commit Graph

41 Commits

Author SHA1 Message Date
658329b648 Merge branch '2.2' into develop 2018-05-03 10:00:44 +03:00
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
5d010ff712 Cleanup SERVER struct
Removed one unused field. Rearranged others, clarified comments.
2018-04-27 10:48:56 +03:00
34008082e5 Rename to has_session_commands
This way it is similar to other member functions.
2018-04-10 15:30:28 +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
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
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
ef73f3e217 Merge branch '2.1' into develop 2017-07-06 11:25:36 +03:00
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
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
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
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
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
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
f546a17e77 Update change date of 2.2 2017-06-01 10:24:20 +03:00
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
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
ce6b52ab39 Rename schemarouter internal functions
Renamed the functions to better describe what they do.
2017-04-06 09:22:21 +03:00
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
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
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
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
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
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
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
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
f9e5275605 Fix bugs introduced by refactoring
Fixed minor bugs that were introduced by the refactoring.
2017-03-31 14:12:02 +03:00
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
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
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
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
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
c4638666cf Remove typedefs from schemarouter enums
The enum typedefs weren't really useful in most cases.
2017-03-31 14:12:01 +03:00
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
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
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
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
39903e40b7 Rename member variables
Renamed and cleaned up schemarouter member variables. Removed unused
variables.
2017-03-31 14:12:00 +03:00
ac641e0f22 Use router template in schemarouter
The schemarouter now uses the router template.
2017-03-31 14:12:00 +03:00