267 Commits

Author SHA1 Message Date
Johan Wikman
b36f6faa7e MXS-1754 Reintroduce maxscale::Worker
Worker is now the base class of all workers. It has a message
queue and can be run in a thread of its own, or in the calling
thread. Worker can not be used as such, but a concrete worker
class must be derived from it. Currently there is only one
concrete class RoutingWorker.

There is some overlapping in functionality between Worker and
RoutingWorker, as there is e.g. a need for broadcasting a
message to all routing workers, but not to other workers.

Currently other workers can not be created as the array for
holding the pointers to the workers is exactly as large as
there will be RoutingWorkers. That will be changed so that
the maximum number of threads is hardwired to some ridiculous
value such as 128. That's the first step in the path towards
a situation where the number of worker threads can be changed
at runtime.
2018-04-16 14:53:08 +03:00
Johan Wikman
230876cd69 MXS-1754 Rename mxs::Worker to mxs::RoutingWorker
A new class mxs::Worker will be introduced and mxs::RoutingWorker
will be inherited from that. mxs::Worker will basically only be a
thread with a message-loop.

Once available, all current non-worker threads (but the one
implicitly created by microhttpd) can be creating by inheriting
from that; in practice that means the housekeeping thread, all
monitor threads and possibly the logging thread.

The benefit of this arrangement is that there then will be a general
mechanism for cross thread communication without having to use any
shared data structures.
2018-04-16 14:53:08 +03:00
Markus Mäkelä
ec33fcf87d
Merge branch '2.2' into develop 2018-04-13 14:53:00 +03:00
Markus Mäkelä
fab8477c05
MXS-1776: Fix utility functions
The COM_STMT_FETCH command will create a response. This was a
readwritesplit-specific interpretation of the command and it was wrong.

Also record the currently executed command event for session commands.
2018-04-12 09:44:28 +03:00
Markus Mäkelä
e327282e82
Don't log warnings for valid SQL
The warnings are about what the parser expects, not something the end user
should know.
2018-04-10 21:39:46 +03:00
Markus Mäkelä
b33f464eea
MXS-1506: Make heartbeat reads atomic
The old hkheartbeat variable was changed to the mxs_clock() function that
simply wraps an atomic load of the variable. This allows it to be
correctly read by MaxScale as well as opening up the possibility of
converting the value load to a relaxed memory order read.

Renamed the header and associated macros. Removed inclusion of the
heartbeat header from the housekeeper header and added it to the files
that were missing it.
2018-04-10 15:29:29 +03:00
Markus Mäkelä
e76b00e340
Merge branch '2.2' into develop 2018-04-10 15:28:00 +03:00
Markus Mäkelä
d28cf6b948
Merge branch '2.1' into 2.2 2018-04-10 15:27:20 +03:00
Markus Mäkelä
f94d1a9863
MXS-1767: Remove old debug assertion
The old assertion expected MaxScale to present the COMPRESS capability
which it doesn't support.
2018-04-10 15:24:57 +03:00
Markus Mäkelä
304499bd36
Merge branch '2.2' into develop 2018-04-10 14:05:39 +03:00
Markus Mäkelä
fad4508fe2
Merge branch '2.1' into 2.2 2018-04-10 13:49:42 +03:00
Markus Mäkelä
b2ec8c95de
MXS-1765: Cork query queue until server handshake is read
The internal client must not drain the query queue if the server handshake
has not yet been read.
2018-04-10 13:45:47 +03:00
Markus Mäkelä
1e3ab1fc7c
MXS-1765: Update current command for KILL processing
The current command needs to be updated before the queries are actually
routed. This allows the KILL command detection and processing to correctly
work.
2018-04-10 13:45:47 +03:00
Markus Mäkelä
099219fa0f
MXS-1767: Fix value assignment in ss_dassert
The value was updated for debug builds but not for release builds. This
caused debug builds to fail if special flags were requested.
2018-04-09 14:15:30 +03:00
Markus Mäkelä
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
Johan Wikman
6535448374 Merge branch '2.2' into develop 2018-03-27 10:17:15 +03:00
Johan Wikman
3d45d452eb MXS-1734 Add possibility to instruct when to dump statements
With the configuration entry

dump_last_statements=[never|on_close|on_error]

you can now specify when and if to dump the last statements
of of a session.
2018-03-27 09:35:35 +03:00
Johan Wikman
6d599395d4 MXS-1734 Add statement dumping mechanism
With the configuration entry

   retain_last_statements=<unsigned>

or the debug flag '--debug=retain-last-statements=<unsigned>',
MaxScale will store the specified number of last statements
for each session. By calling

    session_dump_statements(session);

MaxScale will dump the last statements as NOTICE messages.
For debugging purposes.
2018-03-27 09:35:35 +03:00
Markus Mäkelä
e45759d35d
Skip scanning of OK packets if preparing statement
The OK packet that a COM_STMT_PREPARE returns is not a normal OK packet
and need to be skipped as the packet layout is different.
2018-03-20 13:42:25 +02:00
Markus Mäkelä
10a9d70851
Get service capabilities from a better source
The DCB pointer in the MySQLProtocol struct doesn't appear to be updated
in all cases which causes it to be an unreliable source. As the session
itself is always available and it always has the service pointer properly
set, it should be used instead.

Also removed the dead protocol compression code and replaced the
parameters with the service capability bits.
2018-03-20 13:42:25 +02:00
Markus Mäkelä
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
Markus Mäkelä
04ca9658c5
Use correct executable name
The test executable name had a typo in it.
2018-03-20 13:11:52 +02:00
Johan Wikman
34dd8a52bb MXS-1475 Allow the setting on N vars with one stmt
With this change, the following will be possible.

SET @maxscale.cache.populate=false, @maxscale.cache.use=true;
2018-03-16 14:34:04 +02:00
Johan Wikman
805e3578a2 MXS-1475 Address review issues
- Clean up session header.
- Add test case
2018-03-16 14:34:04 +02:00
Johan Wikman
2434482dc6 MXS-1475 Attempt to set unknown MXS user variable causes error
By causing an error if an unknown MaxScale user variable is set,
the user will become aware of typos etc.
2018-03-16 14:34:04 +02:00
Johan Wikman
872a51a376 MXS-1475 Enable MaxScale specific user variables
With the changes in this commit it is possible to add and remove
MaxScale specific user variables. A MaxScale specific user variable
is a user variable that is interpreted by MaxScale and that
potentially changes the behaviour of MaxScale.

MaxScale specific user variables are of the format "@maxscale.x.y"
where "@maxscale" is a mandatory prefix, x a scope identifying the
component that handles the variable and y the component specific
variable. So, a variable might be called e.g. "@maxscale.cache.enabled".
The scope "core" is reserved (although not enforced yet) to MaxScale
itself.

The idea is that although MaxScale catches these, they are passed
through to the server. The benefit of this is that we do not need to
detect e.g. "SELECT @maxscale.cache.enabled", but can let the result
be returned from the server.

The interpretation of a provided value is handled by the component that
adds the variable. In a subsequent commit, it will be possible for a
component to reject a value, which will then cause an error to be
returned to the client.

There are 3 new functions:

- session_add_variable() using which a variable is added,
- session_remove_variable() using which a variable is removed, and
- session_set_variable_value().

The two former ones are to be called by components, the last one by
the protocol that catches the "set @maxscale..." statements.
2018-03-16 14:34:04 +02:00
Johan Wikman
5dfa0c1226 MXS-1475 Take SetParser and SqlModeParser into use
These changes are the first in the route toward supporting
MaxScale specific variables such as

    set @MAXSCALE.CACHE.ENABLED=TRUE
2018-03-16 14:34:04 +02:00
Johan Wikman
676594b8dd MXS-1475 Update test to use new classes
Test now implemented in terms of SetParser and SqlModeParser.
2018-03-16 14:34:04 +02:00
Johan Wikman
23d1dd42de MXS-1475 Add sql_mode parser
Given the value in a statement like "SET SQL_MODE=..." this parser
is capable of deducing whether SQL_MODE is set to DEFAULT or ORACLE
or something else.
2018-03-16 14:34:04 +02:00
Johan Wikman
f11d60420d MXS-1475 Add SetParser custom parser
SetParser is capable of returning the exact variable and value
of a "SET X=Y" statement, in the cases where X is of a specific
set of variables; currently "SQL_MODE" and "@MAXSCALE...".

The actual value of the SET statement also needs to be parsed in
the case of SQL_MODE, but it becomes unnecessary convoluted if that
information somehow should conditionally be expressable in a return
value.

So, the value will be parsed separately.
2018-03-16 14:34:04 +02:00
Markus Mäkelä
9f5d2244ea
Merge branch '2.2' into develop 2018-03-14 14:30:50 +02:00
Markus Mäkelä
d7c1d76065
Merge branch '2.1' into 2.2 2018-03-14 14:29:56 +02:00
Markus Mäkelä
2023ee4dc7
MXS-1713: Fix resultset collection code
The resultset collection was not detected early enough in the code which
caused partial results to be returned to the router.
2018-03-14 13:02:47 +02:00
Markus Mäkelä
a75ea27a96
Fix memory leak when backend authentication fails
If the backend authentication failed for a user, the buffer containing the
error packet would leak.
2018-03-13 14:32:38 +02:00
Markus Mäkelä
d6b8147119
Merge branch '2.2' into develop 2018-03-06 17:02:03 +02:00
Markus Mäkelä
d5226fa7d1
MXS-1698: Fix double SSL connection
When backend SSL connections were created, the connection creation was
done twice. This was due to the lacking detection of an already
established SSL connection.
2018-03-06 13:35:15 +02:00
Markus Mäkelä
019312c4ee
Cherry-pick: Don't write errors to dummy sessions
If a DCB is closed before a response to the handshake packet is received,
the DCB's session will point to the dummy session. In this case no error
should be written to the DCB.

This is a cherry-pick of commit f53e112bf49766f1cc55516c2d7ee571461d483f
from the 2.2 branch.
2018-03-05 13:58:09 +02:00
Johan Wikman
fcde23e6fe Merge branch '2.2' into develop 2018-02-08 18:40:29 +02:00
Markus Mäkelä
2a987716a8
Build tests by default
The tests are now built by default. This should make it easier for users
to verify that they have a working MaxScale.

Also made the building of test_parse_kill conditional like the rest of the
tests.
2018-02-08 12:48:56 +02:00
Markus Mäkelä
771716e9db
Merge branch '2.2' into develop 2018-02-05 10:22:43 +02:00
dapeng
8a0c8e63f2 MXS-199: Support Causal Read in Read Write Splitting (#164)
* MXS-199: Support Causal Read in Read Write Splitting

* move most causal read logic into rwsplit router and get server type from monitor

* misc fix: remove new line

* refactor, move config to right place, replace ltrim with gwbuf_consume

* refacter a little for previous commit

* fix code style
2018-02-05 09:09:18 +02:00
Markus Mäkelä
8c8aaeae8e Prevent double closing of client DCB
If the client is closing the connection but routing the COM_QUIT fails,
the DCB would be closed twice.
2018-02-02 12:28:07 +02:00
Markus Mäkelä
9f0a691233 Always stop the session by closing the client DCB
By always starting the session shutdown process by stopping the client
DCB, the manipulation of the session state can be removed from the backend
protocol modules and replaced with a fake hangup event.

Delivering this event via the core allows the actual dcb_close call on the
client DCB to be done only when the client DCB is being handled by a
worker.
2018-02-02 12:28:07 +02:00
Markus Mäkelä
ebf0d6fc5f Close client DCB with a hangup in the backend protocol
Directly closing the client DCB in the backend protocol modules is not
correct anymore as the state of the session doesn't change when the client
DCB is closed. By propagating the shutdown of the session with a fake
hangup to the client DCB, the closing of the DCB is done only once.

Added debug assertions that make sure all DCBs are closed only
once. Removed redundant code in the backend protocol error handling code.
2018-02-02 12:28:07 +02:00
Markus Mäkelä
f53e112bf4 Don't write errors to dummy sessions
If a DCB is closed before a response to the handshake packet is received,
the DCB's session will point to the dummy session. In this case no error
should be written to the DCB.
2018-01-31 13:38:28 +02:00
Dapeng Huang
a035c91fa6 add doc for session_track_trx_state and refactor little 2018-01-29 10:16:03 +02:00
Markus Mäkelä
7b04d17ce3 Use correct function for consuming LEncStrings
Length-encoded strings should be consumed with the correct
functions. Doing pointer arithmetic with the same pointer as a parameter
appears to fail only on CentOS 6 whereas on newer systems it performs as
expected.
2018-01-24 20:30:02 +02:00
Markus Mäkelä
dfbecc41e2 Format protocol modules
Formatted the MariaDB protocol modules with Astyle.
2018-01-24 11:20:11 +02:00
Dapeng Huang
73e5fd52fa misc fix and remove all tail spaces 2018-01-22 22:02:22 +08:00
Dapeng Huang
1729d73b19 revert deprecate eof 2018-01-22 20:28:50 +08:00