Commit Graph

6852 Commits

Author SHA1 Message Date
293279366f MXS-1849 Fix handling of show tables queries in schemarouter
There was a bug in handling of the "show tables from" queries that
caused multiple results to the client. These queries are now handled
correctly.
2018-07-09 11:34:59 +03:00
bfd3d2975d Merge branch '2.2' into develop 2018-07-06 14:56:19 +03:00
f2b8487577 MXS-1624 Add configuration parameter
With the global configuration parameter 'query_classifier_cache'
the query classification cache can be turned on. At the moment it
does not matter what value it has; its presence simply enables the
caching.

Eventually you will be able to specify how much memory the cache
is allowed to consume.
2018-07-06 12:12:31 +03:00
e7913cc022 MXS-1624 Update qc_setup() prototype
Now takes a structure that, if present, enables the query
classification caching and specifies the properties of the
cache.

For the time being no actual properties are yet available.
2018-07-06 12:12:31 +03:00
b7c5abf73b MXS-1624 Discard QC result if the sql mode has changed
The sql mode affects the result of the query classification.
Consequently, we cannot use the cached result if it was generated
when the sql mode was something else than what it currently is.
2018-07-06 12:12:31 +03:00
1be9528227 MXS-1624 Provide initial implemenation of QC caching
The mapping from a canonical statement to the query classification
result is maintained by the class QCInfoCache of which there exist
an instance per thread. That way no locking is needed but the
information will be cached multiple times (but that is a smaller
price to pay). Currently the information is stored in a regular
std::unordered_map, which means that the consumed amount of
memory will just keep on growing unless the number of canonical
statements used by clients happens to have an upper bound.

The LRU cache (that provides means for putting a bound on the
amount of memory used and number of items) used in the cache filter
will be generalized and be taken into use here as well.

The key is now the canonical statement itself, which means that
a fair amount of memory will be used. To preserve memory it might
make sense to use a hashed value instead, although that at least
in principle opens up the possibility for unintended collisions.

This feature will also be made configurable.
2018-07-06 12:12:31 +03:00
d01db42679 MXS-1624 Clean up query_classifier.cc
Minor cleanup:
- Unit variables places in anonymous namespace.
- Unit variables accessed via this_unit struct.

This is the first commit of many where the mapping from canonical
statement to query classification result is introduced.

The mapping is placed above the actual query classifier, so that all
query classifiers will benefit from it.

The mapping will be maintained by thread so that there will not be
any synchronization issues. Further, initially a simple map without
upper boundary will be used; if this is found to provide measurable
benefits, the map will then be replaced with an LRU mechanism so
that it becomes possible to specify just how much memory the mapping
may use.
2018-07-06 12:12:31 +03:00
c89bdb9626 MXS-1823 Replace meaningless eventq info with meaningful
The evq_length file held the returned number of descriptors from
the last epoll_wait() call. As such it is highly temporal and not
particularly meaningful.

That has now been removed and the instead the average number of
returned descriptors is maintained. That information changes slowly
and thus carries some meaning.
2018-07-06 11:22:42 +03:00
d339b89990 MXS-1774 Make rejection of functions optional
It is now possible to prevent the masking filter from rejecting
statements using functions in conjunction with fields to be
masked. So now it is possible to not use the blanket rejection
of the masking filter and replace it with more detailed firewall
rules.
2018-07-06 11:20:31 +03:00
43cc6ca3cd MXS-1774 Reject query with masked columns + functions
The masking filter works only on the result-set. However, if
functions are used, the column names will not be available in
the result-set, and hence masking will not take place.

Now, the statement is checked and if functions are used in
conjunction with columns that should be masked, the statement
is rejected. Thus, functions can no longer be used for bypassing
the masking. That was possible earlier as well, but required
manually setting up the firewall filter.
2018-07-06 11:20:31 +03:00
702f8aaed4 Merge branch '2.2' into develop 2018-07-05 13:53:14 +03:00
f44d305a46 MXS-1949: Fix user injection warning
If a service has no active servers and users are injected, a warning would
be logged. This is a misleading warning if the service has no servers and
should only be logged if the failure to load any users is an unexpected
situation.
2018-07-05 12:49:46 +03:00
33fa9b26fe Make version counter in mlist_t volatile
The log manager is the only one that uses the mlist_t versioned list. The
counter that keeps track of the version number was not modified using
atomic operations meaning that the compiler is free to optimize away parts
of the lock-free versioning mechanism that uses it.

To prevent this optimization, the variable is declared volatile. A rewrite
is direly needed but it cannot be done in 2.2.
2018-07-05 12:47:28 +03:00
7954de0da6 Always log commit ID
There's no good reason to not include the commit ID in release build
startup messages.
2018-07-05 12:01:38 +03:00
d3c1ec4742 MXS-1664 Add --runtimedir config parameter 2018-07-04 22:38:28 +03:00
40376bd12a MXS-1849 Fix connecting to empty databases in schemarouter
Empty databases were not mapped to ServerMap because they had no tables
to map. Modified the query to also include empty databases making it
possible to also connect to empty databases through schemarouter.
2018-07-04 22:25:09 +03:00
2e88ce4132 Merge branch '2.2' into develop 2018-07-04 22:01:01 +03:00
3f9a204116 Log unknown users and wrong passwords separately
If authentication fails due to a wrong password, a different error message
is logged. This should help resolve problems with user management.
2018-07-04 13:51:09 +03:00
79acbae4e5 Fix cache test build failure
The change in defaults caused the test to fail.
2018-07-04 13:51:09 +03:00
44ef4912e8 Merge branch '2.2' into develop 2018-07-03 21:13:41 +03:00
fb1c28c702 MXS-1948: Do round-robin worker assignment
Due to the skewed accept distribution without SO_REUSEPORT, we use
round-robin assignment of workers for new client connections. This
provides better performance as work is more likely to be evenly
distributed across all threads.

Using a least-busy-worker algorithm would provide a more stable result but
this is not trivially simple to implement. For this reason, the
round-robin based approach was chosen for 2.2.
2018-07-03 12:49:59 +03:00
e455e7f15d MXS-1953: Always initialize the GWBUF spinlock
The spinlock in the buffer is used but it was not always initialized. Also
added missing initialization of the SERVER pointer.
2018-07-03 11:32:36 +03:00
34f61bc4f2 Close connections before starting loop
The connections should be closed after the check queries.
2018-07-03 10:32:06 +03:00
7ded2c436f Fix monitor shutdown and restart
Monitor restart was not working.
2018-07-03 10:32:06 +03:00
03491a45f0 Remove old code
The functionality is elsewhere.
2018-07-03 10:32:06 +03:00
013dfa79aa Quote whitespace-only default values
Parameters that accept whitespace-only values need to have their default
values quoted if they contain only whitespace characters. In 2.2 the
qlafilter is the only module that did not do this.
2018-07-03 03:09:19 +03:00
ceb1c0f2a4 MXS-1950: Add missing error messages
When a valid target was not found, no error message was logged by the
router. This would cause the "Routing the query failed. Session will be
closed." message to be logged with no explanation as to why the routing
failed.

In addition to the above-mentioned case, no message would be logged if the
target for a COM_STMT_FETCH was not in use.
2018-07-03 02:08:25 +03:00
ed068f4d93 Expand authentication failure log message
If the authentication failure was due to a missing database, this extra
information can be logged. This will help cases where users are using
databases that do not exist.
2018-07-03 02:08:24 +03:00
fd31c9cced MXS-1905 Set slaves with low disk space to maintenance
Also, servers in maintenance are updated just as other servers.
2018-07-02 14:24:57 +03:00
8d7cb27884 Remove faulty debug assertion
The debug assertion was missing the check for the queued commands.
2018-07-02 13:29:21 +03:00
9d5b8c8de2 Share data between identical session commands
If two or more session commands contain identical buffers, the buffer of
the first session command is shared between the others. This reduces the
amount of memory used to store repeated executions of session commands.

The purging of session command history in readwritesplit was replaced with
session command de-duplication. This was done to prevent problems that
could arise when the order of session commands plays a significant role.
2018-07-02 13:29:21 +03:00
295d59881e Remove spinlocks from GWBUF
The spinlock does not protect from or prevent misuse as buffers must not
be used concurrently by multiple threads.
2018-07-02 13:29:21 +03:00
709c394064 Remove debug messages from readwritesplit
The debug log messages weren't very useful and the information that they
contained can be deduced from other messages.
2018-07-02 13:29:21 +03:00
8b736854e8 Assert that backend is used or can be connected to
The assertion that was added to RWSplitSession::handle_slave_is_target
failed when delayed_retry was enabled or when slave reconnection
occurred. In 2.3, targets returned by the target selection functions do
not need to be in use but they must be valid connection targets.
2018-07-02 13:29:20 +03:00
9c6cc713c8 Remove unnecessary session command logging
All executed session commands were logged in the RWSplitSession
destructor. This is not really necessary and shouldn't have been placed
there in the first place.
2018-07-02 13:29:20 +03:00
8cf22dbb56 MXS-1549: Prevent optimistic transaction with no slaves
If the router session does not have an already open slave connection,
optimistic transactions are not attempted.
2018-07-02 13:29:19 +03:00
12398bfc26 MXS-1549: Implement optimistic transaction execution
When the `optimistic_trx` mode is enabled, all transactions are started on
a slave server. If the client executes a query inside the transaction that
is not of a read-only nature, the transaction is rolled back and replayed
on the master.
2018-07-02 13:29:19 +03:00
af45006567 MXS-1549: Add optimistic_trx parameter
The optimistic_trx parameter will control whether transactions are assumed
to be read-only and will be optimistically executed on slave
servers. Currently, the parameter does nothing.
2018-07-02 13:29:18 +03:00
d6a964304b MXS-1549: Always store previous target
Unconditionally update the previous target on each routed query. This
allows routing to the previous server in case it is needed. One example of
this is a new type of hint that allows routing to the same server where
the previous query was sent.

Also added a minor clarifying comment to the resetting of the
current_query.
2018-07-02 13:29:18 +03:00
a417567a18 Format readwritesplit with Astyle
Formatted readwritesplit with Astyle. Changed the initialization of
Backend::m_modutil_state to use curly braces to cope with Astyle's lack of
support for curly braces inside parentheses.
2018-07-02 13:29:18 +03:00
e610b285b9 MXS-1549: Count RO and RW transactions in readwritesplit
Readwritesplit now keeps track of how many read-only and read-write
transactions have been executed. This allows a coarse estimation of how
widely read-only transactions are done even without explicit read-only
transactions being used (i.e. START TRANSACTION READ ONLY).
2018-07-02 13:29:17 +03:00
b59f607471 MXS-1549: Track transaction type in the query classifier
The characteristics of a transaction can now be tracked by the query
classifier. This allows read-only and read-write transaction statistics to
be calculated.
2018-07-02 13:29:17 +03:00
b0902402b6 MXS-1940 Turn cache filter non-experimental
Also change the following defaults:

- "selects": Was "verify_cacheable", is now "assume_cacheable"
- "cached_data": Was "shared", is now "thread_specific"
2018-07-02 08:44:39 +03:00
fa83901d03 Silence routing failure warnings when retrying queries
If a routing failure happens while a query can still be retried, it should
not be logged.
2018-06-30 19:26:24 +03:00
93fdada534 Fix crash on trx replay with session command
Readwritesplit would crash with the following transaction:

    BEGIN;
    SET @a = 1; -- This is where it would crash
    COMMIT;

When a session command was a part of the transaction, empty queries
(i.e. NULL GWBUFs) would be added to the transaction. If the transaction
were to be replayed, MaxScale would crash when these NULL queries were
executed.

Once the empty responses were fixed, the replaying of the transaction
would fail with a checksum mismatch. This was caused by the wrong order of
processing in RWSplitSession::clientReply. The response processing for
session commands was done after the response processing for replayed
transactions. This would trigger a checksum comparison too early for the
transaction in question.
2018-06-30 19:26:23 +03:00
a59c0c61ce Remove depth field from SERVER
It was not really used anymore.
2018-06-29 10:54:34 +03:00
960d08a36a Code cleanup
Removed unused code.
2018-06-29 10:54:34 +03:00
0afcd4b468 Fix test-program failures
Due to recent changes, mxs::MessageQueue::init() must be called
explicitly, if a monitor is created.
2018-06-29 10:43:49 +03:00
9525d3507b Run manual commands without stopping the monitor
The command is saved in a function object which is read by the monitor
thread. This way, manual and automatic cluster modification commands are
ran in the same step of a monitor cycle.

This update required several modifications in related code.
2018-06-28 16:56:41 +03:00
6bf10904d7 MXS-1845 Only rebuild topology when required
The monitor now detects when a server has changed such that a replication
graph rebuild is needed and only then rebuilds the graph and detects
cycles and master.

Also, some old code is no longer called in the monitor cycle. It will be
removed in later commits. Refactored some of the related functions.
2018-06-28 16:56:41 +03:00