3420 Commits

Author SHA1 Message Date
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ä
5c4fe263ba
Remove unused code
Removed functions that print to stdout.
2018-07-31 09:41:12 +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ä
b9500e6329
MXS-1929: Allocate SERVICE with new
Allocating the service with new allows integration of C++ objects.
2018-07-31 09:41:12 +03:00
Markus Mäkelä
93521e4327
MXS-1929: Destroy filters separately from services
The previous implementation did not destroy filters that were not used by
services. With the full initialization of filters in filter_alloc, we can
simply traverse the list of created filters and destroy them knowing that
they are all valid.
2018-07-31 09:41:11 +03:00
Markus Mäkelä
cea36dc7be
MXS-1929: Initialize filter in filter_alloc
Changed the filter_alloc function to fully initialize the filter. This
means that if filter_alloc returns a non-NULL pointer, the filter was
successfully loaded and an instance was successfully created.
2018-07-31 09:41:11 +03:00
Markus Mäkelä
e39242d6e5
MXS-1929: Add filter deletion entry points
Added the code required to delete a filter via the REST API. The actual
deleting of the filters is still to be implemented.
2018-07-31 09:41:11 +03:00
Markus Mäkelä
22cc155e55
MXS-1929: Process relationships when creating services
The relationships of a service are handled by the service alteration
code. Currently, only server relationships are handled by the code in
question and filter relationships are ignored.
2018-07-31 09:41:10 +03:00
Markus Mäkelä
fb3101f7c4
MXS-1929: Improve JSON type error messages
If an invalid value or type is given to the REST API, having the expected
type as well as the given type make problem resolution easier.

Also added a value check into MaxCtrl for listener ports.
2018-07-31 09:41:10 +03:00
Markus Mäkelä
0c63471715
MXS-1929: Use correct object type when loading defaults
The service creation attempted to load defaults for a filter module when
the module in question was a router.
2018-07-31 09:41:09 +03:00
Markus Mäkelä
a50fce0c65
MXS-1929: Allow startup with no services
MaxScale can now be started with an empty configuration file and services
can be created at runtime. Filters cannot yet be created at runtime so
complete runtime creation of configurations is not yet possible.
2018-07-31 09:41:09 +03:00
Markus Mäkelä
823efffb00
Read config as late as possible
By reading the configuration as late as possible, we allow the objects to
be created in an environment which is nearly identical to the environment
that is present at runtime.

This change makes it possible to execute worker tasks in the instance
creation functions of various modules. The avrorouter in particular
depended on being able to queue worker tasks on startup.
2018-07-31 09:41:08 +03:00
Markus Mäkelä
a553ddba6e
MXS-1929: Split housekeeper initialization
The initialization and starting of the housekeeper is now done
separately. This allows housekeeper tasks to be created when the services
are being created while still preventing the execution of the task before
the startup is complete.
2018-07-31 09:41:08 +03:00
Markus Mäkelä
560157081c
MXS-1929: Persist the router parameter
The router parameter was not persisted for services.
2018-07-31 09:41:08 +03:00
Markus Mäkelä
f10eab4406
MXS-1929: Fix binlogrouter unit test failure
The test failed because router instances are now created when the service
is allocated. In addition to this, a debug assertion was hit when a
service was freed if the router instance creation failed.
2018-07-31 09:41:07 +03:00
Markus Mäkelä
037cedf70e
MXS-1929: Allow service creation at runtime
Services can now be created at runtime. The command to create services is
exposed in the REST API.
2018-07-31 09:41:07 +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ä
18c1ec2678
MXS-1929: Make listeners inactive when destroyed
By using service_remove_listener the listener is marked as inactive when
it is destroyed.
2018-07-31 09:41:06 +03:00
Markus Mäkelä
23d944b82e
MXS-1929: Close listener DCBs
When a service is freed, it will free all of its listeners causing their
respective DCBs to be closed. This requires that listeners can be removed
from the worker DCB list.
2018-07-31 09:41:06 +03:00
Markus Mäkelä
b93eaf6fb2
MXS-1929: Validate multiple JSON relationships
The runtime configuration JSON validation now allows multiple
relationships to be verified at one time. This makes it easier to validate
all objects using the same framework.
2018-07-31 09:41:06 +03:00
Markus Mäkelä
aeb94cbc9e
MXS-1929: Remove listener from service and workers
When a listener is removed from a service, it should also be removed from
any workers it has been added to. This guarantees that if the opening of
the listener was successful, no requests will be accepted on it after the
removal of the listener.
2018-07-31 09:41:06 +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
Markus Mäkelä
36822da172
MXS-1929: Create router instance in service_alloc
By creating the router instance as a part of the service allocation
process, we are guaranteed that either the creation of the service is
completely successful or it fails. This should make runtime creation of
services easier.
2018-07-31 09:41:05 +03:00
Markus Mäkelä
d8b539c85a
MXS-1929: Add REST API filter test
Most parts of the test still fail due to the fact that they haven't been
implemented.
2018-07-31 09:41:05 +03:00
Markus Mäkelä
2c1f79c5d1
MXS-1929: Add runtime creation of filters
Filters can now be created at runtime. This is not yet a usable feature
since the filters can't be added to services at runtime.
2018-07-31 09:41:05 +03:00
Markus Mäkelä
6c59da77fb
Merge branch '2.2' into develop 2018-07-26 11:27:09 +03:00
Marko
571d52f557
Typo fix in logthrottling_test 2018-07-26 10:59:53 +03:00
Marko
4dc1638f78
Silence the -Wunused-result warning
-Wunused-result warning in test_logthrottling.cc was causing error when
trying to build MaxScale from source. This warning can be silenced with by
putting the function triggering the warning in if-clause.
2018-07-26 10:59:53 +03:00
Esa Korhonen
fbce38878b Turn server status macros to functions 2018-07-25 11:19:47 +03:00
Esa Korhonen
b421e56d1c Move execute_worker_task to MonitorInstance
The function is rather general and may of use to other monitor modules.
2018-07-24 15:07:18 +03:00
Markus Mäkelä
4b7cd7a281
Dump queue contents on unexpectedly NULL buffer
When the query queue does not contain a complete packet
(i.e. modutil_get_next_MySQL_packet return NULL), an informative dump of
how many bytes and what is stored is logged.
2018-07-24 09:51:48 +03:00
Markus Mäkelä
ea5c5f3a07
Never return NULL from gwbuf_make_contiguous
By aborting the process if memory runs out when a buffer needs to be made
contiguous, we rule out other, more subtle, errors. Failing as soon as a
possible when memory allocation fails gives better error messages.
2018-07-24 09:51:47 +03:00
Markus Mäkelä
bbe4f42935
Add more packet splitting debug assertions
Having more debug assertions in functions that split packets guarantees
that they work as expected.
2018-07-24 09:51:47 +03:00
Markus Mäkelä
21eef8a670
MXS-1985: Kill connections inside workers
The LocalClient micro-client required a reference to the session that was
valid at construction time. This is the reason why the previous
implementation used dcb_foreach to first gather the targets and then
execute queries on them. By replacing this reference with pointers to the
raw data it requires, we lift the requirement of the orignating session
being alive at construction time.

Now that the LocalClient no longer holds a reference to the session, the
killing of the connection does not have to be done on the same thread that
started the process. This prevents the deadlock that occurred when
concurrect dcb_foreach calls were made.

Replaced the unused dcb_foreach_parallel with a version of dcb_foreach
that allows iteration of DCBs local to this worker. The dcb_foreach_local
is the basis upon which all DCB access outside of administrative tasks
should be built on.

This change will introduce a regression in functionality: The client will
no longer receive an error if no connections match the KILL query
criteria. This is done to avoid having to synchronize the workers after
they have performed the killing of their own connections.
2018-07-24 09:51:46 +03:00
Markus Mäkelä
101dad74a7
MXS-1985: Add debug assertions to dcb_foreach
The dcb_foreach function is not safe to use from multiple threads at the
same time. This should be asserted by checking that the function is called
only from the main worker.

The addition of this assertion also implies that only administrative
operations should use the dcb_foreach function. To accommodate this
change, the KILL command iteration needs to be adjusted.
2018-07-24 09:51:45 +03:00
Markus Mäkelä
6b8d9dc5d9
Print an error on invalid request JSON
When a request to the REST API is made with invalid JSON, it's hard to see
why the request fails due to the fact that no error is sent.
2018-07-24 09:51:35 +03:00
Esa Korhonen
862ae099b0 Construct diagnostics results in the monitor thread
MariaDBMonitor diagnostics printing is unsafe as some of the read
fields are arrays. To be on the safe side, the fields are now read
in the monitor worker thread.

Since diagnostics must work even for stopped monitors, a worker task
is used. In practice, it usually runs when the monitor is sleeping.
2018-07-20 10:18:58 +03:00
Markus Mäkelä
d91710c640
Remove unused DCB state
The state was never assigned.
2018-07-18 15:47:25 +03:00
Markus Mäkelä
d9fde54b95
Use mxs::SpinLock in config_runtime.cc
The C++ version with the lock guard is easier to manage when there are
multiple return points from a function. It also makes sure that the lock
is freed after it's used.
2018-07-17 11:52:37 +03:00
Markus Mäkelä
c31e78754d
Fix object name tokenization
Spaces must be considered a part of the object name in tokenization. This
ensures that the name normalization process generates correct names and
that tokens are split at correct places.
2018-07-17 11:52:23 +03:00
Markus Mäkelä
28609a2c77
Remove session command processing from mariadbbackend
With the removal of the old session command implementation, the code that
used it can be removed or replaced with newer constructs. As a result, the
backend protocol no longer does any session command processing.

The three buffer types, GWBUF_TYPE_SESCMD_RESPONSE,
GWBUF_TYPE_RESPONSE_END and GWBUF_TYPE_SESCMD as well as their related
macros are no longer used and can be removed.
2018-07-17 11:52:22 +03:00
Markus Mäkelä
728a3f6957
Clean up filter usage in services
Using a stack-allocated vector allows the filter definition array to only
be allocated once all filters have been successfully processed.
2018-07-17 11:52:22 +03:00
Markus Mäkelä
16aece6f83
Clean up new service configuration
Removed redundant checks and dead code, replaced manual server searches
with correct ones.
2018-07-17 11:52:22 +03:00
Markus Mäkelä
4e8ac8dd4f
Fix explicit server allocation
The test cases allocated servers in a way that doesn't comfortably suit
the way the servers are now allocated. Adding a helper C++ class to load
module defaults makes it easier to do explicit server initialization in
tests.

The binlogrouter was also fixed in this commit as it uses servers much
like a test would use.
2018-07-17 11:52:21 +03:00
Markus Mäkelä
df94ef990c
Use module-type parameters for servers
The server base objects now use the module-type parameters for generic
configuration.
2018-07-17 11:52:20 +03:00
Markus Mäkelä
d28b1c9d1d
Validate SSL parameters via the module-type parameters
The configuration system that modules use allows the SSL parameter
validation to be simplified. It should also provide more consistent error
messages for similar types of errors.

The SSL_LISTENER initialization is now done in one step. There was no good
reason to do it in two separate steps for listeners but in one step for
servers.

The `ssl` parameter now also accepts boolean values. As the parameter
behaves like a boolean and looks like a boolean, it ought to be a
boolean. It still accepts the custom `required` and `disabled` values
simply for backwards compatibility.

Also added the missing freeing functions for the SSL_LISTENER type. This
prevents failed SSL_LISTENER creations from leaking memory.
2018-07-17 11:52:20 +03:00
Markus Mäkelä
177f7357e0
Use module-style parameters with filters
Filters now use the module-style parameters to automate the type checking
and default value assignment.
2018-07-17 11:52:19 +03:00
Markus Mäkelä
ddaf300783
Fix and improve configuration validation
The parameter type and value validation is now fully done for the base
module parameters as well. This fixes a problem that was introduced when
the listeners were moved to the module parameter system where the
`service` parameter values weren't fixed for the new naming style.

Added an explicit check for the module type that catches errors in the
type parameter. The lack of this parameter prevents the proper detection
of other parameters.

Also cleaned up and/or removed redundant sections of code. By treating
reserved parameters the same way as module declared ones, the same code
can be re-used for all types.
2018-07-17 11:52:18 +03:00
Markus Mäkelä
421282421c
Use module-style parameters with listeners
Listeners now use the module-style parameters to automate the type
checking and default value assignment.
2018-07-17 11:52:18 +03:00
Markus Mäkelä
5fdf82a508
Only warn about whitespace in section names
The warnings were logged even when the fix_section_name function was used
to fix non-section names.
2018-07-17 11:52:15 +03:00