78 Commits

Author SHA1 Message Date
Johan Wikman
6335d3776c MXS-2002 Replace auto_ptr with unique_ptr
Given 'Derived : public Base', a unique_ptr<Derived> converts
implictly to a unique_ptr<Base>.
2018-08-13 08:30:05 +03:00
Johan Wikman
9cfd451a1d MXS-2002 Make Worker excecution mode explicit
This is the first step in some cleanup of the Worker interface.
The execution mode must now be explicitly specified, but that is
just a temporary step. Further down the road, _posting_ will
*always* mean via the message loop while _executing_ will optionally
and by default mean direct execution if the calling thread is that
of the worker.
2018-08-13 08:30:05 +03:00
Markus Mäkelä
2e60d5fd71
MXS-1929: Store filters inside Session
The Session now holds a reference to the filters it uses. This makes the
use of filters safe even if they are destroyed mid-session.
2018-08-06 21:20:29 +03:00
Markus Mäkelä
7e64d6b3df
MXS-1929: Move use of C++ inside the Session
The Session class now handles the work involved in dealing with the
private member variables.
2018-08-06 21:20:29 +03:00
Markus Mäkelä
945510e735
MXS-1929: Add Session class
The Session class now contains all of the C++ objects that were previously
in the MXS_SESSION struct. It is also allocated with new but all
initialization is still done outside of the Session in session_alloc_body.

This commit will not compile as it is a part of a set of commits that make
parts of the session private.
2018-08-06 21:20:29 +03:00
Markus Mäkelä
47176d9bf1
MXS-1929: Take local filter lists into use
The session creation function now uses the local filter list of the
worker. This also removes the need for the has_filters function.
2018-08-06 21:20:29 +03:00
Markus Mäkelä
7d6338d65b
MXS-1929: Make filters configurable at runtime
The filters can now be altered at runtime. Currently, the filter usage
uses a service level lock. The next is to allocate a per-service key to
the worker local data and use that to orchestrate the storage of the
filter lists.
2018-08-06 21:20:29 +03:00
Markus Mäkelä
4d3dbb2040
MXS-1929: Take SFilterDef into use
The service now uses a std::vector<SFilterDef> to store the filters it
uses. Most internal parts deal with the SFilterDef but debugcmd.cc still
moves raw pointers around (needs to be changed).
2018-08-06 21:20:29 +03:00
Markus Mäkelä
ec420332ea
MXS-1929: Take ResultSet into use
Replaced the previous RESULTSET with the new implementation. As the new
ResultSet doesn't have a JSON streaming capability, the MaxInfo JSON
interface has been removed. This should not be a big problem as the REST
API offers the same information in a more secure and structured way.
2018-07-31 22:50:08 +03:00
Markus Mäkelä
cca7757090
MXS-1929: Take internal Service struct into use
The internals now mostly refer to the Service struct instead of the public
SERVICE struct.
2018-07-31 09:41:13 +03:00
Markus Mäkelä
829fdcff83
MXS-1929: Make filters fully opaque
The filter implementation is now fully hidden. Also converted it to a C++
struct allocated with new and stored the filters in a global list instead
of embedding the list in the object itself.
2018-07-31 09:41:13 +03:00
Markus Mäkelä
efd953c434
MXS-1929: Store service active state atomically
When a session is closed, it releases a reference on the service and
checks if it was the last session for a destroyed service. The state of
the service was loaded after the reference count was decremented.  This
behavior introduced a race condition where it was possible for a service
to be freed twice, first by the thread that marked the service as
destroyed and again by the last session for that service. By always
loading the service state before decrementing the reference count, we
avoid this race condition.

Currently, the memory ordering used for the reference counting is too
strict and could be relaxed. By default, all atomic operations use
sequentially consistent memory ordering. This guarantees correct behavior
but imposes a performance penalty. Incrementing the reference counts could
be done with a relaxed memory order as long as as we know the reference
we're incrementing is valid. Releasing a reference must use an
acquire-release order to guarantee the read-modify-write operation is
successful.
2018-07-31 09:41:12 +03:00
Markus Mäkelä
5a40064826
MXS-1929: Make services destroyable
Services can now be destroyed if they have no active listeners and they
are not linked to servers. When these conditions are met, the service will
be destroyed when the last session for the service is closed.

The closing of a service will close all listeners that were once assigned
to the service. This allows closing of the ports at runtime which
previously was done only on shutdown.

Exposed the command through the REST API but not through MaxAdmin as it is
deprecated.
2018-07-31 09:41:07 +03:00
Markus Mäkelä
4069072164
Do service client counts in the core
As all connections should be accepted via dcb_accept, it is the optimal
place to calculate how many open client connections per service there
are. The decrementation should be done when the session is closed instead
of when the call to dcb_close for the client DCB is done. This allows the
client count to be the absolute reference count that sessions have to a
service.

The current client count is a duplicate counter that should match the
n_current value in SERVICE_STATS. The former does differ from the latter
in that it does the incrementation when the client DCB is accepted instead
of when the session is created.
2018-07-31 09:41:06 +03:00
Johan Wikman
86b5238aaf MXS-1915 Replace worker id with worker pointer
To get rid of the need that a Worker must have an id, we store
in the MXS_POLL_DATA structure a pointer to the owning worker
instead of the id of the owning worker. This also allows some
further cleanup as the need for switching back and forth between
the id and the worker disappears.

The id will be moved from Worker to RoutingWorker as there
currently is a fair amount of code that assumes that the id of
routing workers start from 0.
2018-06-26 09:19:46 +03:00
Johan Wikman
cc0299aee6 Update change date of 2.3 2018-06-25 10:07:52 +03:00
Markus Mäkelä
a812e02ba4
Merge branch '2.2' into develop 2018-06-15 10:48:07 +03:00
Markus Mäkelä
3d1c2b421a
MXS-1921: Explain why session was closed
When a client connection is closed by MaxScale before the client initiates
a controlled closing of the connection, an error message is sent. This
error message now also explains why the connection was closed to make
problem resolution easier.
2018-06-14 13:48:07 +03:00
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