7248 Commits

Author SHA1 Message Date
Markus Mäkelä
ad1c05b015 Merge branch '2.1' into develop 2017-04-05 11:35:13 +03:00
Esa Korhonen
e0a98f6539 Fix calls of pcre2_substitute
If the output buffer given to pcre2_substitute is too small, an error
value is written to the last parameter (output length). That value
should not be used for calculations. This patch gives a copy as
parameter instead.

Coincidentally, this commit fixes the crashes of query classifier tests.

Also, increase buffer growth rate in utils.c.
2017-04-04 16:19:21 +03:00
Esa Korhonen
dca086571b TestMaxScalePCRE2: Fix memory leaks
Not really leaks, but this reduces needless clutter in the valgrind
output.
2017-04-04 16:18:47 +03:00
Markus Mäkelä
872f69b681 Also check IPv6 mapped IPv4 addresses as IPv4
If a client connects from an IPv4 address, but the listener listens on an
IPv6 address, the client IP will be a IPv6 mapped IPv4 address
e.g. ::ffff:127.0.0.1. A grant for an IPv4 address should still match an
IPv6 mapped IPv4 address.
2017-04-04 15:28:39 +03:00
Markus Mäkelä
9f14f3659f Only check user permissions on startup
When users were loaded, the permissions for the service user were
checked. The conditional that makes sure the check is executed only at
startup was checking the listener's users instead of the SQLite handle
which caused all reloads of users to check the permissions.
2017-04-04 15:28:39 +03:00
Markus Mäkelä
860b14526c Fix mxs_mysql_is_result_set
The function assumed that the packet payload was always at least two
bytes.
2017-04-04 15:28:39 +03:00
Markus Mäkelä
1ff83150f0 Revert "Route statements in larger batches"
This reverts commit f3c83770903151a0a3b53593c3e05fa0af94cd5f. The
functionality was used implicitly by modules that declare the
RCAP_TYPE_CONTIGUOUS_OUTPUT capability.
2017-04-04 09:56:51 +03:00
MassimilianoPinto
0c3f9ffa2e Maxrows: documentation update and use of MXS_MODULE_PARAM_SIZE for max_resultset_size parameter
max_resultset_size parameter now uses MXS_MODULE_PARAM_SIZE and
config_get_size

Documentation change follows the change.
2017-04-04 08:43:55 +02:00
Esa Korhonen
1fb8cde5d8 NamedServerFilter: Add HINT_ROUTE_TO_ALL support
This was already supported by HintRouter. The tag for the MaxScale
config file is "->all". Also add note to Documentation and reformat
it a bit.
2017-04-04 09:40:04 +03:00
Markus Mäkelä
6ef90bf9b6 Add a warning about limit_queries and action=allow
The `limit_queries` rule should not be used in the `allow` mode.
2017-04-03 16:22:21 +03:00
Markus Mäkelä
d32a2e410b Use matched instead of blocked
As queries that match a rule aren't always blocked, it's more appropriate
to use `matched` instead of `blocked`.
2017-04-03 16:22:21 +03:00
Markus Mäkelä
108978fcd2 Format dbfwfilter documentation
Split lines that are longer than 80 characters.
2017-04-03 16:22:21 +03:00
Johan Wikman
8d2d6d8721 Join threads to prevent leaks 2017-04-03 14:20:54 +03:00
Johan Wikman
815780aa4a In cache testrules.c ensure there seems to be at least one thread 2017-04-03 14:20:54 +03:00
Markus Mäkelä
0f2f9d48b7 Improve maxadmin help messages
The help messages are now more descriptive and have usage information in
them. This should help users use the commands without relying on the
online documentation.
2017-04-03 12:09:59 +03:00
Markus Mäkelä
e650597eb5 MXS-1200: Document and increase line length limitations
The line length limitation is now increased to 16384 bytes. It is now
clearly documented in the limitations document.

The configuration parser now uses memory from the heap instead of the
stack. This should remove any problems caused by the larger line length.
2017-04-03 12:07:45 +03:00
Markus Mäkelä
f3c8377090 Route statements in larger batches
The RCAP_TYPE_STMT_OUTPUT is not used in its previous form. It can be
altered to route only complete packets back to the client. This allows
routers to do safer parsing on the results.
2017-04-03 12:07:45 +03:00
Esa Korhonen
259b0673a0 Add "backend_connect_attempts" to monitor documentation 2017-04-03 10:52:06 +03:00
Esa Korhonen
a362bd0024 Add parameter backend_connect_attempts to monitor
This number (defaults to 1) sets how many times mon_connect_to_db
will try to connect to a backend before returning an error. Every
connection attempt may take backend_connect_timeout seconds to
complete.

Also refactored code a bit. Renamed mon_connect_to_db to
mon_ping_or_connect_to_db, since it does not connect if the connection
is already alive.
2017-04-03 09:56:22 +03:00
Esa Korhonen
657d79470c Update NamedServerFilter documentation
The document is now up to date with the rewrite. Also added an assert
to enforce a minimum number of allowed match-target pairs.
2017-04-03 09:49:12 +03:00
MassimilianoPinto
d4da5caf3b MXS-1211: MaxRows documentation update
MXS-1211: MaxRows documentation update
2017-04-03 08:39:12 +02:00
MassimilianoPinto
e6d2c96f5b MXS-1211: maxrows should be configurable to return error when limit has been exceeded
New parameter added to maxsrows filter:
max_resultset_return=empty|error|ok
Default, 'empty' is to return an empty set, as the current
implementation.
'err' will return an ERR reply with the input SQL statement
'ok' will return an OK packet
2017-03-31 14:26:44 +02:00
Johan Wikman
84ea6e6c8d Update ChangeLog 2017-03-31 15:09:16 +03:00
Johan Wikman
4abdfa2ff7 Update version number in branch 2.1
The next release will be 2.1.3, so better to have it in place now.
2017-03-31 15:09:16 +03:00
Markus Mäkelä
70c834026c Update launchable script documentation
Updated examples with new address formatting.
2017-03-31 14:12:58 +03:00
Markus Mäkelä
cbc1e864d9 Use RFC 3986 compliant addresses in log messages
When log messages are written with both address and port information, IPv6
addresses can cause confusion if the normal address:port formatting is
used. The RFC 3986 suggests that all IPv6 addresses are expressed as a
bracket enclosed address optionally followed by the port that is separate
from the address by a colon.

In practice, the "all interfaces" address and port number 3306 can be
written in IPv4 numbers-and-dots notation as 0.0.0.0:3306 and in IPv6
notation as [::]:3306. Using the latter format in log messages keeps the
output consistent with all types of addresses.

The details of the standard can be found at the following addresses:

     https://www.ietf.org/rfc/rfc3986.txt

     https://www.rfc-editor.org/std/std66.txt
2017-03-31 14:12:58 +03:00
Markus Mäkelä
c2857b976a Add collectable resultset buffer type
The new type allows routers to send queries and get complete result sets
as a response. This allows the routers to easily send commands that create
result sets and which are parsed by the router.

Currently only the schemarouter benefits from this new capability as it
generates the database mappings by parsing the output of a SHOW DATABASES
query.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
5c1c89c835 Remove unused buffer types
A part of the buffer types weren't used or provided no real functionality.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
c59ed30da1 Simplify error handling
The error handlers are now simpler as the Backend class handles the
closing of the connections.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
a3396a06b8 Fix shared_ptr usage
The std::shared_ptr type was used instead of std::tr1::shared_ptr. A NULL
pointer was also implicitly cast into a Backend pointer which caused
compilation problems on some platforms with the tr1 version of shared_ptr.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
6e218adc1d Make connections and command queues internal to Backends
The SERVER_REF and DCB members of the Backend class are now
private. Access to the stored SERVER_REF is provided with the backend()
function. No accompanying setter function is provided as the backend
server should not change during the lifetime of the session.

The creation of the internal DCB is hidden behind the connect()
function. It simplifies the process of connecting to a server by removing
the need to manually do the bookkeeping of the server reference connection
counts. Access to the DCB is provided by the dcb() function.

The closing of the backend is done with the close() function which
contains the code that was previously in closeSession. If the backend
isn't closed when the destructor is called, it will be done
automatically. This should prevent connection leakage.

The pending command queues and the methods used to write them are now also
internal to the backends. They are simple wrappers around dcb->func.write
and the interfaces provided by the Buffer class. The mapping command queue
is still public. It needs to be combined with the generic command queue.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
66fa4fbc7d Use shared pointers to Backend classes
The schemarouter now uses shared pointers. This removes the need to copy
the class.

Following changes move the member variables inside the Backend class.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
f9e5275605 Fix bugs introduced by refactoring
Fixed minor bugs that were introduced by the refactoring.
2017-03-31 14:12:02 +03:00
Markus Mäkelä
94ac2d89d0 MXS-1160: Add support for LOAD DATA LOCAL INFILE
Schemarouter now supports the LOAD DATA LOCAL INFILE command.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
f6470c580a Fix minor problems
Use correct value in initialization, return correct return value on
success, do a equals comparison on route target.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
34b0b07cd1 Ignore duplicate shards in a subfunction
The ignoring of duplicate shards is now done inside a subfunction.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
5ba9de6f42 Move Backend functions inside the class
The functions that handle Backend classes are now methods of the class
itself.

Prefix all member variables with `m_` to distinct them from other
variables.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
d1aa2a4b8a Use a list of backends instead of an array
Changed the backend_ref_t struct into a Backend class. Replaced static
arrays with lists. Altered functions to make the code compile.

Further refactoring is needed, a part of the functions should be moved
into this new class.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
c4638666cf Remove typedefs from schemarouter enums
The enum typedefs weren't really useful in most cases.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
f5a259ba57 Do configuration outside of constructors
Configuration errors can be resolved before the instance is created. This
avoids the unnecessary throws that were generated when an error occured.

As the configuration is stored in the router, the router sessions can use
a pointer to it instead of copying it locally. This should avoid some
unnecessary copying if more complex configuration parameters are added.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
b9fae58891 Favor pointers over references
The use of a pointer instead of a reference conveys the message that the
lifetime of the object being pointed can, and most likely will, exceed the
lifetime of the function.

Also shuffled the member variables and internal functions around and
removed unneeded function declarations.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
02796e7304 Move #pragma to first line in each header
The `#pragma once` is now on the first line of each header.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
14cfd482de Fix variable naming and usage
Don't use `this->` when it's not needed. Use snake_case for member
variables. Initialize the members using a initialization list.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
a10aa85736 Clean up routeQuery and clientReply
Moved parts of the functionality into subfunctions. Reordered code to
remove redundant logic.
2017-03-31 14:12:01 +03:00
Markus Mäkelä
39903e40b7 Rename member variables
Renamed and cleaned up schemarouter member variables. Removed unused
variables.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
ac641e0f22 Use router template in schemarouter
The schemarouter now uses the router template.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
b2ff0c5a0f Clean up schemarouter headers
Cleaned up the headers, removed unused structures. Changed some members to
strings instead of char arrays. Switch to router templates should now be
easier.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
d151512d20 Take new sharding implementation into use
The sharding implementation now uses a class to abstract the details of
the shard. This allows for different design where each session makes a
copy of the global shard map which is then used for the duration of the
session. In addition to making the desing a bit clearer to understand, it
also removes lock competition between threads.

Due to the change to C++, the main entry points need to be wrapped in the
exception-safety macros. The next step in the refactoring will be to use
the router template. This will remove the need to manually define them.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
9587b2ecfc Remove unused schemarouter code
The temporary table detection in schemarouter was not used.
2017-03-31 14:12:00 +03:00
Markus Mäkelä
bda0fd2db0 Replace session command implementation
The schemarouter now uses the new session commands. It uses a standard
library container to manage the execution and storage of session commands.

The session command history is disabled until a more complete refactoring
can be done.
2017-03-31 14:12:00 +03:00