60 Commits

Author SHA1 Message Date
Markus Mäkelä
b451e89e35
Use Worker::delayed_call in session_delay_routing
The use of the housekeeper is no longer needed as a better mechanism
exists.
2018-05-22 17:46:27 +03:00
Markus Mäkelä
66255361dc
MXS-553: List connections in sessions resource
The connections that relate to a particular session are now a part of the
sessions resource. Currently, only the generic information is stored for
each connection (id and server name).
2018-05-22 17:46:25 +03:00
Markus Mäkelä
643fc825fa
MXS-553: Provide full session to DCB mapping
By storing a link to the backend DCBs in the session object itself, we can
reach all related objects from the session. This removes the need to
iterate over all DCBs to find the set of related DCBs.
2018-05-22 17:46:24 +03:00
Johan Wikman
42c10cfa1c MXS-1848 Move Worker from internal to public include dir
maxscale::Worker needs to be public if monitors should be
implementable using it.
2018-05-14 10:10:18 +03:00
Johan Wikman
64d84cf1e0 Merge branch '2.2' into develop 2018-05-02 10:45:59 +03:00
Johan Wikman
8c9aa82a69 Merge branch '2.1' into 2.2 2018-05-02 10:40:24 +03:00
Markus Mäkelä
1cc99d2fda
Fix core build failure with GCC 8
GCC 8 warns when a polymorphic type is caught by value.
2018-04-17 22:17:34 +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ä
3aa62b0116
MXS-1506: Always queue the delayed routing task
The worker task should never be immediately executed to allow the task to
be executed on the next "tick" of the worker. This prevents recursive
calls to e.g. routeQuery in readwritesplit when errors are handled.
2018-04-12 10:42:40 +03:00
Markus Mäkelä
e1e01c029c
MXS-1506: Allow immediate query re-routing
Now that the readwritesplit uses the same mechanism for both
retry_failed_reads and delayed query retries, the re-routing function
should accept a delay of 0 seconds. This makes the mechanism more suitable
for other uses e.g. delaying of queries in filters.
2018-04-10 15:31:50 +03:00
Markus Mäkelä
450b31dd8c
MXS-1506: Store queries inside RWSplitSession
As the readwritesplit is the only thing that uses the statement storage,
it can be integrated into RWSplitSession. This makes the code a lot
simpler.
2018-04-10 15:31:50 +03:00
Markus Mäkelä
e5e607908d
MXS-1506: Add router to MXS_DOWNSTREAM helper function
The function makes it easier to deal with the delayed query routing as
well as removing redundancy in the code.
2018-04-10 15:29:30 +03:00
Markus Mäkelä
cc793b2151
MXS-1506: Remove unused MXS_UPSTREAM variables
The `error` variable was never used. Also added a more convenient typedef
for both the downstream and upstream functions and updated filter API
version.
2018-04-10 15:29:30 +03:00
Markus Mäkelä
c70216390f
MXS-1506: Combine housekeeper task types
The tasks themselves now control whether they are executed again. To
compare it to the old system, oneshot tasks now return `false` and
repeating tasks return `true`.

Letting the housekeeper remove the tasks makes the code simpler and
removes the possibility of the task being removed while it is being
executed. It does introduce a deadlock possibility if a housekeeper
function is called inside a housekeeper task.
2018-04-10 15:29:30 +03:00
Markus Mäkelä
96a0aae7fe
MXS-1506: Move all functionality into Housekeeper
The class now does all of the work and the API wraps the calls to the
member methods. Using an STL container makes the list management a lot
more convenient.
2018-04-10 15:29:30 +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ä
761fda2806
Add delayed query retry prototype
This is a proof-of-concept that validates the query retrying method. The
actual implementation of the query retrying mechanism needs more thought
as using the housekeeper is not very efficient.
2018-04-10 15:29:29 +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
Johan Wikman
c08fe079bf MXS-1725 Use session_set_response() in Cache
- session_set_response() made const correct
- set_response() function added to mxs::FilterSession; calls
  session_set_response().
- Cache uses set_response() for delivering the cache result
  to the client.
2018-03-26 12:17:36 +03:00
Johan Wikman
9fd64cf7ba MXS-1725 Provide mech. for short-circuiting req. processing
Filter that terminate the response processing now have a mechanism
using which a response can be provided in such a way that previous
filters will see the response.
2018-03-26 12:17:36 +03:00
Johan Wikman
81708e0ba2 MXS-1725 Replace macros with function
The macros MXS_SESSION_ROUTE_QUERY and MXS_SESSION_ROUTE_REPLY
are now defined in terms of functions that do the actual stuff.

Incidentally, the function session_route_reply() existed already
but was not used. Now slightly rewritten so that it does not simply
ignore misuse.
2018-03-26 12:17:36 +03:00
Johan Wikman
82b55ff362 MXS-1475 Add @maxscale.cache.[populate|use]
The earlier @maxscale.cache.enabled has now been replaced with
@maxscale.cache.populate and @maxscale.cache.use that provide
for more flexibility.

With the former it is possible to control in what circumstances
the cache is populated and with the latter one when it is used.
Together they can be used for having a completely client driven
caching.
2018-03-16 14:34:04 +02:00
Johan Wikman
71c8a327b2 MXS-1475 Introduce variable @maxscale.cache.enabled
With the variable @maxscale.cache.enabled the caching can be
enabled/disabled at runtime.

In a subsequent commit, the variable will actually be used.
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
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ä
a62333a29a Assign the service pointer for backend DCBs
The backend DCBs didn't have a valid service pointer whereas the client
DCBs had one. The necessity of the pointer can be questioned as a similar
pointer is located in the session.
2017-12-14 10:50:13 +02:00
Markus Mäkelä
396b81f336 Fix in-source builds
The internal header directory conflicted with in-source builds causing a
build failure. This is fixed by renaming the internal header directory to
something other than maxscale.

The renaming pointed out a few problems in a couple of source files that
appeared to include internal headers when the headers were in fact public
headers.

Fixed maxctrl in-source builds by making the copying of the sources
optional.
2017-11-22 18:40:18 +02:00
Markus Mäkelä
4dd6842447 Send KILL commands to backends
KILL commands are now sent to the backends in an asynchronous manner. As
the LocalClient class is used to connect to the servers, this will cause
an extra connection to be created on top of the original connections
created by the session.

If the user does not have the permissions to execute the KILL, the error
message is currently lost. This could be solved by adding a "result
handler" into the LocalClient class which is called with the result.
2017-10-03 14:47:16 +03:00
Johan Wikman
02b9e0a01d Merge branch '2.1.7' into develop-2.1-merge 2017-09-12 11:08:02 +03:00
Johan Wikman
70a4ad6532 MXS-1392 Take new zombie mechanism into use
Next commit will remove the remnants of the reference counting
mechanism.
2017-09-08 12:41:41 +03:00
Johan Wikman
be94066b77 MXS-1392 Manage DCB lifetime using refcounts
Now it is also possible to ensure that a DCB stays alive while
a task referring to it is posted from one worker to another.
That will be implemented in a subsequent commit.
2017-09-08 12:41:41 +03:00
Johan Wikman
9da1439b0e Rename session_link_dcb to session_link_backend_dcb
Reduce risk for confusion.
2017-09-07 15:51:48 +03:00
Johan Wikman
80815e0f54 Change session_link_dcb to void
The function attempted to detect use of freed memory, which is a
futile excersize.
2017-09-07 15:04:35 +03:00
Johan Wikman
e7926d770e MXS-1378 Provide access to current session
Provide access to current session and session id. This will
be used by the logging mechanism for logging the session id
together with messages.
2017-08-30 13:58:42 +03:00
MassimilianoPinto
cb57e10761 Develop merge
Develop merge
2017-06-29 15:34:22 +02:00
Markus Mäkelä
5fd690eb1f MXS-1220: Limit /sessions/ to client sessions
The /sessions/ resource should only contain client sessions as the
information is about the sessions, not the connections themselves.
2017-06-27 21:45:00 +03:00
Markus Mäkelä
d59e98e238 MXS-1267: Remove DCB cloning
The DCB cloning is no longer needed as the tee filter now does the session
branching by simulating a local client connection.
2017-06-02 13:07:02 +03:00
Johan Wikman
f546a17e77 Update change date of 2.2 2017-06-01 10:24:20 +03:00
Esa Korhonen
dbfd631fed Change session registry to a template class
The template class wraps a HashMap such that only a few operations
are allowed. Usage requires specializing a RegistryTraits class
template for each entry type.
2017-05-19 10:16:37 +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ä
157b7f853b MXS-1220: Fix resource self links
The top level resource self links pointed to the collection instead of the
resource itself. The individual resoures now also have a links field that
contains the self link to the resource. This should make navigation of the
API easier as all objects have valid links in them.
2017-05-09 15:32:42 +03:00
Markus Mäkelä
ca62749f25 MXS-1220: Factor out common code from JSON object creation
The JSON objects that are created from the various core MaxScale objects
share a lot of common code. Moving this into a separate files removes the
redundant code.
2017-05-09 15:32:41 +03:00
Markus Mäkelä
dcf9c8dab6 MXS-1220: Reorganize sessions resource
The sessions resource now follows the JSON API specification:

    http://jsonapi.org/

This makes the API relatively easier to use as the specification and the
client libraries to consume this data exist.
2017-05-09 15:32:41 +03:00
Esa Korhonen
ee20191645 KILL [CONNECTION | QUERY] support, part2B
Various small changes to part2, as suggested by comments and otherwise.
Mostly renaming, working logic should not change.

Exception: session id changed to 64bit in the container and associated
functions. Another commit will change it to 64bit in the session itself.
2017-05-08 09:58:02 +03:00
Esa Korhonen
17f6e94cba KILL [CONNECTION | QUERY] support, part2
MySQL sessions are added to a hasmap when created, removed when closed.
MYSQL_COM_PROCESS_KILL is now detected, the thread_id is read and the kill
command sent to all worker threads to find the correct session. If found, a
fake hangup even is created for the client dcb.

As is, this function is of little use since the client could just disconnect
itself instead. Later on, additional commands of this nature will be  added.
2017-05-08 09:51:07 +03:00
Markus Mäkelä
690d592a94 MXS-1220: Implement /sessions/ resource
The /sessions/ resource was not implemented due to changes in the core
polling mechanics. With the new worker thread messaging system, sessions
can be listed in a safe manner.
2017-05-04 09:17:48 +03:00
Markus Mäkelä
dd68069471 MXS-1220: Add back the old diagnostic entry point
This makes 2.2 maxadmin backwards compatible with 2.1.
2017-05-04 09:14:04 +03:00