41 Commits

Author SHA1 Message Date
Markus Mäkelä
6d089e3283
Clear session commands in Backend::close
If a reconnection would take place, the old commands would get executed.
2019-05-31 14:01:15 +03:00
Markus Mäkelä
7db87784ac
Deliver hangups only to valid DCBs
If a DCB was closed and a hangup event was sent to it via
dcb_hangup_foreach shortly after it was closed, the DCB would still
receive it even if it was closed. To prevent this, events must only be
delivered to DCBs if they haven't been closed.
2019-03-08 12:10:30 +02:00
Markus Mäkelä
24c9b62a2f
Add verbose logging for session command failures
If the routing of a session command fails due to problems with the backend
connections, a more verbose error message is logged. The added status
information in the Backend class makes tracking the original cause of the
problem a lot easier due to knowing where, when and why the connection was
closed.
2019-01-31 14:23:26 +02:00
Niclas Antti
5175d2b2d7 MXS-2078 Add support for holding router specific server data.
New class to hold the statistics, part of which is currently in
RWSplitSession. Simple API in Backend to create session
specific data.
2018-11-08 10:44:32 +02:00
Markus Mäkelä
2e069fa892
MXS-1632: Take mxb::atomic::add into use
The function now mostly replaces the use of atomic_add_ functions declared
in atomic.h.
2018-09-18 15:21:54 +03:00
Niclas Antti
c447e5cf15 Uncrustify maxscale
See script directory for method. The script to run in the top level
MaxScale directory is called maxscale-uncrustify.sh, which uses
another script, list-src, from the same directory (so you need to set
your PATH). The uncrustify version was 0.66.
2018-09-09 22:26:19 +03:00
Johan Wikman
ab9a9f92cb MXS-2020 Remove maxscale/debug.h
- Removed from all files.
- maxbase/assert.h included where necessary.
2018-08-22 11:35:35 +03:00
Johan Wikman
3f53eddbde MXS-2020 Replace ss[_info]_dassert with mxb_assert[_message] 2018-08-22 11:34:59 +03:00
Johan Wikman
b1e405442f MXS-2020 Replace ss_debug with MXB_AT_DEBUG 2018-08-22 11:34:06 +03:00
Johan Wikman
ae43e4f0f2 MXS-2013 Remove all CHK_-macros 2018-08-15 09:28:04 +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
Johan Wikman
dc4a555c70 Merge branch '2.2' into develop 2018-06-28 10:34:41 +03:00
Markus Mäkelä
f49c31625d
Use derived version of write for session commands
Prepared statements via readwritesplit need to have their IDs mapped from
the internal representation to the backend specific one. The RWBackend
class does this in its write method but the fix in commit
e561c3995c7396cf3749ccdf6a3357d7dd32c856 caused this to be bypassed and
the base version was always used.
2018-06-27 08:49:54 +03:00
Markus Mäkelä
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
Johan Wikman
cc0299aee6 Update change date of 2.3 2018-06-25 10:07:52 +03:00
Markus Mäkelä
b96228f95c
Merge branch '2.2' into develop 2018-06-22 10:44:39 +03:00
Markus Mäkelä
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
Markus Mäkelä
2005164222
Fix slave reconnection logic
Allowing calls to select_connect_backend_servers even when all slaves are
connected solves the debug assertion in select_connect_backend_servers
that happens when the execution of a queued query causes a new connection
to be created.
2018-06-15 16:16:53 +03:00
Markus Mäkelä
3ed6411741
Fix debug assert on reconnection with session commands
When a query was routed to a server that must first be connected to, the
expected response count was not updated for the executed session commands.
2018-06-15 16:16:53 +03:00
Esa Korhonen
5d010ff712 Cleanup SERVER struct
Removed one unused field. Rearranged others, clarified comments.
2018-04-27 10:48:56 +03:00
Markus Mäkelä
34008082e5
Rename to has_session_commands
This way it is similar to other member functions.
2018-04-10 15:30:28 +03:00
Markus Mäkelä
caa5fe89bb
MXS-1503: Make sure backend is in use before using it
The get_backend_from_dcb function needs to check that the backend is in
use before comparing the pointer. This prevents stale pointers from being
used and is logically more sound than relying on raw DCB matches.
2018-04-03 13:32:10 +03:00
Markus Mäkelä
319122e621
MXS-1502: Add have_session_commands helper function
The function conveys the meaning of the call better than using
session_command_count to check whether there are session commands to be
executed.
2018-04-03 13:32:10 +03:00
Markus Mäkelä
e57ac4b0a3
MXS-1502: Prune session commands
The session command history is now compacted to contain only the first and
last execution of a session command. This should still allow most of the
more eccentric use-cases of user variables while keeping the session
command history smaller.

Added some convenience functions into the SessionCommand class to make the
pruning process easier.
2018-04-03 13:30:53 +03:00
Markus Mäkelä
be2186c8f1
MXS-1503: Remove redundant code
Moved session command execution into the Backend class itself as the
session commands are defined as a related part of it. This allows all
connections to execute session commands if some are available.

Removed explicit SERVER_REF usage in the readwritesplit connection
creation code and replaced it with SRWBackend. This allows the removal of
the get_root_master_backend function which duplicated the functionality in
get_root_master.
2018-04-03 13:30:51 +03:00
Markus Mäkelä
f743e99795
Set internal DCB to NULL on close
The Backend::dcb() method gives the raw pointer to the internal DCB. This
pointer is used by at least readwritesplit to map raw DCB pointers to
backends. To prevent stale pointers from being returned, m_dcb needs to be
set to NULL after it has been closed.
2018-04-03 10:59:55 +03:00
Markus Mäkelä
ebf0d6fc5f Close client DCB with a hangup in the backend protocol
Directly closing the client DCB in the backend protocol modules is not
correct anymore as the state of the session doesn't change when the client
DCB is closed. By propagating the shutdown of the session with a fake
hangup to the client DCB, the closing of the DCB is done only once.

Added debug assertions that make sure all DCBs are closed only
once. Removed redundant code in the backend protocol error handling code.
2018-02-02 12:28:07 +02:00
Markus Mäkelä
6c5fa071d5 Inline backend related functions
Inlined the getter/setter type functions that are often used. Profiling
shows that inlining the RWBackend get/set functions for the reply state
manipulation reduces the relative cost of the function to acceptable
levels. Inlining the Backend state function did not have as large an
effect but it appears contribute a slight performance boost.
2017-10-12 12:29:43 +03:00
Markus Mäkelä
45e0e8bb59 Introduce internal protocol command enum
The enums exposed by the connector are not intended to be used by the
users of the library. The fact that the protocol, and other, modules used
it was in violation of how the library is intended to be used.

Adding an internal mapping into MaxScale also removes some of the
dependencies that the core has on the connector.
2017-09-14 15:30:43 +03:00
MassimilianoPinto
cb57e10761 Develop merge
Develop merge
2017-06-29 15:34:22 +02:00
Markus Mäkelä
c7520a2156 Add name and uri helpers to Backend
Providing helper functions for the commonly used parts of the server makes
code easier to read. It also removes any possibility for formatting
problems by moving the URI and name string handling inside the Backend
class.
2017-06-22 10:40:18 +03:00
Markus Mäkelä
d7543988ee Add server state helper functions
Added helper functions that check various server states. This makes the
readwritesplit code easier to read as the function names convey the
intention better than the macro invokations.
2017-06-22 10:40:18 +03:00
Markus Mäkelä
e5f6d00fda Fix debug assertion in backend.cc
The Backend should be closed in the destructor if it was in use but was
not closed.
2017-06-22 10:40:17 +03:00
Markus Mäkelä
7a98e6d050 Remove redundant states
The closed state is not required as a separate boolean is used to track
it.
2017-06-22 10:40:17 +03:00
Markus Mäkelä
0c8e68fd05 Rename and overload adding of session commands
As the session commands are always appended to the end of the list, the
name should reflect that action. For this reason, the function was renamed
to append_session_command.

Readwritesplit supports replacement of slave servers by storing all
executed session commands in a list. To make the copying of this list a
bit cleaner, an overload for a list of session commands was added. This
will allow relatively smooth addition of server replacement to all router
modules that use the Backend class.
2017-06-22 10:40:17 +03:00
Markus Mäkelä
1f31cfdfd7 Add more session command related functions to Backend
The class now allows simpler construction of session commands by
overloading the add_session_command with a version that accepts a const
reference to a shared pointer. This removes the need to copy the
references to the source buffer by calling gwbuf_clone.

Exposed the first session command as a const reference to allow
interaction with it. Currently, it is planned to be used to get the
session command position of each backend.
2017-06-22 10:40:17 +03:00
Markus Mäkelä
c3c905f745 Add is_active helper to Backend
The Backend now provides a helper function for checking if the SERFER_REF
is still active.

Also renamed the close_type enum values.
2017-06-22 10:40:16 +03:00
Markus Mäkelä
5a5effdf7a Take Backend into use in rwsplit_select_backends.cc
This is the first step to taking the Backend class into use. It is now
used in rwsplit_select_backends.cc and readwritesplit.hh. The module is
not yet functional and doesn't even compile.

Added some helper functions to the Backend class to get easier access to
the server referenced by the SERVER_REF and to check the state of the
backend.
2017-06-22 10:40:16 +03:00
Markus Mäkelä
1fcb62895e Add fatal failure checking method to Backend
The method allows the caller to check whether the backend has suffered a
fatal failure.
2017-06-22 10:40:16 +03:00
Markus Mäkelä
18993bc8ca Refactor Backend class states
The states are now internal to the Backend class. This simplifies the use
of the class by moving the burder of state tracking to the class
itself.

Refactored the way the schemarouter uses the Backend class.

Also fixed a memory leak in the schemarouter when `ignore_databases_regex`
was used..
2017-06-22 10:40:16 +03:00
Markus Mäkelä
bbfd9ce136 Move Backend and SessionCommand classes to the core
Using the same implementation of the Backend and SessionCommand classes in
both schemarouter and readwritesplit will prevent duplication of code.

This commit only splits the generic parts of the class to a Backend class
which the schemarouter then extends. The session commands for both routers
are similar so they require no special handling.
2017-06-22 10:40:16 +03:00