Commit Graph

2608 Commits

Author SHA1 Message Date
86cdb14286 Don't process queued commands when replaying transaction
If a transaction is replayed, queued commands must not be processed. The
exception to this rule is when pending session commands are executed
before the first statement in the replayed transaction is executed.
2018-07-11 14:08:47 +03:00
0614ff4c9d Fix handling of transactions with large results
If transaction replaying was enabled and a result was returned in more
than one call to clientReply, a NULL value would be added to the statement
which in turn would trigger a debug assertion.

Similarly any following statements in the transaction would be executed
regardless of whether the result was complete.

Renamed the statement execution function to better describe what it does.

Extended the basic functional test case to cover this.
2018-07-11 14:08:47 +03:00
77a1417479 Replace TR1 headers with standard headers
Now that the C++11 standard is the default one, we can remove the TR1
headers and classes.
2018-07-11 14:08:46 +03:00
a5e384fd29 Add reconfiguration to router API
Added a new router API entry point that allows configuration changes after
the instance has been created. This makes alterations to most service
parameters at runtime possible.

An option to reconfiguration would have been the creation of a new
service and the eventual destruction of the old one. This would be a more
complicated and costly method but from an architectural point of view it
is interesting.

The actual implementation of the configuration change is left to the
router. Currently, only readwritesplit performs reconfiguration as
implementing it with versioned configurations is very easy.

Versioned configurations can be considered an adequate first step but it
is not an optimal solution as it causes a bottleneck in the reference
counting of the shared configuration. Thread-specific configuration
definitions would make for a more efficient solution but the
implementation is more complex.
2018-07-11 14:08:45 +03:00
bd4be3a97b Use shared configurations in readwritesplit
By using a shared pointer instead of a plain object, we can replace the
router configuration without it affecting existing sessions. This is a
change that is required to enable runtime reconfiguration of
readwritesplit.
2018-07-11 14:08:45 +03:00
13763ace32 MXS-1820 Make routing of queries in schemarouter case insensitive 2018-07-09 16:18:18 +03:00
0fe5eb2743 MXS-1820 Show original case in schemarouter SHOW DATABASES queries
Original case is now used in schemarouter this means that database and
table names are now case sensitive as well.
2018-07-09 16:17:38 +03:00
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
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
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
44ef4912e8 Merge branch '2.2' into develop 2018-07-03 21:13:41 +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
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
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
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
dc4a555c70 Merge branch '2.2' into develop 2018-06-28 10:34:41 +03:00
f97f422379 Don't use closed backends
Only use backends that are still in use. The COM_STMT_EXECUTE and
COM_STMT_FETCH relationship caused unused backends to be used.
2018-06-27 08:49:21 +03:00
8ea7d8898a MXS-1915 Remove id from mxs::Worker
The id has now been moved from mxs::Worker to mxs::RoutingWorker
and the implications are felt in many places.

The primary need for the id was to be able to access worker specfic
data, maintained outside of a routing worker, when given a worker
(the id is used to index into an array). Slightly related to that
was the need to be able to iterate over all workers. That obviously
implies some kind of collection.

That causes all sorts of issues if there is a need for being able
to create and destroy a worker at runtime. With the id removed from
mxs::Worker all those issues are gone, and its perfectly ok to create
and destory mxs::Workers as needed.

Further, while there is a need to broadcast a particular message to
all _routing_ workers, it hardly makes sense to broadcast a particular
message too _all_ workers. Consequently, only routing workers are kept
in a collection and all static member functions dealing with all
workers (e.g. broadcast) have now been moved to mxs::RoutingWorker.

Now, instead of passing the id around we instead deal directly
with the worker pointer. Later the data in all those external arrays
will be moved into mxs::[Worker|RoutingWorker] so that worker related
data is maintained in exactly one place.
2018-06-26 09:19:46 +03:00
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
cc0299aee6 Update change date of 2.3 2018-06-25 10:07:52 +03:00
b8e0c31872 Merge branch '2.2' into develop 2018-06-25 09:37:18 +03:00
6183fab79b MXS-1938: Log query for inconsistent replies
If a session command produces a different result on the slave than it did
on the master, a warning is logged. This warning now also logs the query
that was being executed to make investigation of the problem easier.
2018-06-25 08:44:13 +03:00
f308dd281a MXS-1849 Combine table and database mapping
Previously schemarouter only mapped databases to the servers
they were resided on. Now all the tables are also mapped to allow the
router to route queries to the right server based on the tables used in
that query.
2018-06-24 22:26:36 +03:00
b38cac4939 MXS-1849 Add functions for mapping tables to servers 2018-06-24 22:26:36 +03:00
b96228f95c Merge branch '2.2' into develop 2018-06-22 10:44:39 +03:00
e561c3995c Use correct write in Backend::execute_session_command
Backend::execute_session_command would use the overridden write method
instead of the Backend::write method that it intended to use. This caused
session commands that did not expect a response to be in a state that
expected a result.

Also fixed RWBackend::write pass the response_type value to
Backend::write.
2018-06-22 10:37:11 +03:00
9e4b86ff0a MXS-1935: Accent NULL from qc_get_preparable_stmt in readwritesplit
If the prepared statement cannot be extracted from the query, treat it as
a query with an unknown type.
2018-06-21 10:04:34 +03:00
6278f27ab6 Merge branch '2.2' into develop 2018-06-20 10:26:29 +03:00
980caa5be5 MXS-1926: Ignore server shutdown errors
If the server sends a server shutdown error, it is safe for readwritesplit
to ignore it. When the TCP connection is closed, the router error handling
will discard the connection, optionally replacing it.
2018-06-20 00:34:16 +03:00
1f166482b2 Fix slave reconnection regression
The state of the backend needs to be checked before any pending session
commands are executed on it.

Added debug assertions to catch invalid use of the status functions of
closed backends.
2018-06-18 14:25:05 +03:00
bd6155b950 MXS-1914: Resolve symbols at link time
Enabled link time symbol resolution to administrative modules.
2018-06-18 12:58:51 +03:00
95935991ab MXS-1881: Move Rpl related code out of Avro files
Organized the Rpl and Avro code in a way that they aren't mixed.
2018-06-16 23:29:40 +03:00
a3a4bb3da6 MXS-1881: Add TableCreateEvent JSON serialization
Serializing the object allows replicated events to be processed even if
the CREATE TABLE statement is not in the binary logs.
2018-06-16 23:29:40 +03:00
3417842e75 MXS-1881: Add table creation method to RowEventHandler
The new method is called for each new CREATE TABLE statement that is
processed as well as all ALTER TABLE statemets that modify the table
structure.

Right now the entry point not in use but it opens up the possibility of
persisting the CREATE TABLE statements at creation time. Currently the
tables are only persisted when the first actual event for the table is
received.
2018-06-16 23:29:39 +03:00
c27529c9a4 MXS-1881: Expand GTID helper class
Added string conversion methods to the gtid_pos_t class that can be used
to store and load a GTID value.

Also added the missing rpl.cc file that previously only had the Rpl class
constructor in it.
2018-06-16 23:29:39 +03:00
ac6370afcf Clean up common binlogrouter headers
Cleaned up blr_constants.h and moved the REP_HEADER construction helper
into binlog_common.h.
2018-06-16 23:29:39 +03:00
e74591cfe5 MXS-1881: Delegate event processing to the Rpl class
The actual processing of the replicated events is now delegated to the Rpl
class. This class only deals with the raw binary format log events which
allows it to be used for both binlogs stored on disk as well as binlogs
that have just been replicated.
2018-06-16 23:29:39 +03:00
4def9382f2 MXS-1881: Remove unneeded code
The code that checks for stop events is not needed as it is only used for
log messages. These aren't really useful to the end user so they can be
removed.

Moved the modification of the event size in case binlog checksums are
enabled outside of the handle_one_event function. This will make it
possible to move most of the processing done inside it into a reusable
class of its own.

Also fixed the memory leak for the event data.
2018-06-16 23:29:39 +03:00
c39fa4009e MXS-1881: Pass the RowEventConverer as a parameter
The RowEventConverter is now passed as a parameter to the Avro
instance. Wrapped the value in an std::auto_ptr to make the cleanup
automatic (when it is implemented).

Fixed a typo in the event handler member variable and removed the unused
stats member.
2018-06-16 23:29:39 +03:00