Commit Graph

564 Commits

Author SHA1 Message Date
34a8694b34 Use module parameters for readwritesplit
The parameters that readwritesplit uses now use the new system. This
removes the need for the qualified parameter processing found in config.c.

All values for router_options are now also accepted as parameters. The
router_options is deprecated and support for it will be removed in a
future version.
2017-01-05 19:51:22 +02:00
a2a38f952a Add [process|thread] [init|finish] functions to modules
The MXS_MODULDE object now contains optinal pointers for functions
to be called att process and thread startup and shutdown. Since the
functions were added to the end, strictly speaking, all structures
would not have needed to have been modified, but better to be
explicit. In a subsequent change, these will be called.

C++ does not support flexible arrays, so for the time being C++
modules are restricted to 10 parameters. Better approach is to
factor out the parameters to a separate array and then just store
a pointer to that array in MXS_MODULE.
2017-01-05 14:44:02 +02:00
1c8a4b13b9 Name variables the same way as the parameters
The variables now use the actual option and parameter names. This should
help make the code more readable and easier to understand in relation to
the used options.
2017-01-05 14:18:56 +02:00
c96bd64aa8 Rename MODULE_INFO to MXS_MODULE
The MODULE_INFO is now the main object which is used by modules to convey
information to the MaxScale core. The MXS_MODULE name is more apt as it
now contains the actual module definition.

The old MODULES structure was moved into load_utils.c as an internal
implementation and was renamed so that it is not confused with the new
MODULE structure.
2017-01-03 18:01:14 +02:00
b00e0328d5 Create a macro for module declarations
The modules are now declared with a common macro. This allows future
additions to the module loading process while also making the loaded
symbol name a constant.
2017-01-03 18:01:13 +02:00
ae0577c695 Move module object inside MODULE_INFO
This allows modules to only expose one entry point with a consistent
signature. In the future, this could be used to implement declarations of
module parameters.
2017-01-03 18:01:13 +02:00
6c53999c97 Combine ModuleInit and GetModuleObject
The two functions can be combined into one as both are called only
once. This removes the need for the explicit ModuleInit function.
2017-01-03 18:01:13 +02:00
7df29aa1ec Move version entry point into MODULE_INFO
The MODULE_INFO can easily hold the version information of the
module. This removes the need for a explicit version entry point.
2017-01-03 18:01:13 +02:00
520d28b27d Merge branch '2.0' into develop 2016-12-22 13:40:16 +02:00
6e6a3e4626 Replace gwbuf_clone_all with gwbuf_clone
gwbuf_clone cloned only the first buffer of a chain of buffers,
which never can be the desired outcome, while gwbuf_clone_all
cloned all buffers.

Now, gwbuf_clone behaves the way gwbuf_clone_all used to behave
and gwbuf_clone_all has been removed.
2016-12-19 11:00:47 +02:00
11d1875399 Handle batched reads from cloned sessions
Readwritesplit should route all queries from cloned sessions to the
master. This allows batch statements to be safely routed.

Native readwritesplit sessions only support batched writes as batched
reads aren't very common. Once readwritesplit supports batched reads, the
special handling for cloned DCBs can be removed.
2016-12-16 10:27:56 +02:00
4d431b787a Remove rwsplit transaction tracking
The transaction tracking is done by the client protocol so readwritesplit
doesn't need to do it.
2016-12-16 10:27:56 +02:00
7a04259fc0 MXS-756: Retry reads on slave failure
If a slave fails while a non-critical read is being executed, the read is
retried on a different server. This is controlled by the new
`retry_failed_reads` option.

Only selects done that are done outside of a transaction and with
autocommit enabled are retried.
2016-12-13 09:12:58 +02:00
15a8675fca Mark error handler as called for closed sessions
When a DCB error occurs, the handleError entry point of the routers is
called. The caller of this entry point expects that the error handler
marks the DCB as handled. The aforementioned behavior is wrong as the
error handler should not keep track of whether the handler was already
called.
2016-12-11 21:41:38 +02:00
d4d40c0b9b MXS-1047: Backport to 2.0
Backported commits 0e50ecb525003b87e8199708008e4a18606c5e54 and
570e12942ba3d2363ec7098dcf1d35c6b68667a1 to 2.0.
2016-12-09 11:13:27 +02:00
570e12942b MXS-1047: Fix batch insert execution
Doing batch inserts though readwritesplit would stall due to the fact that
pending session commands were stored instead of executed immediately.

Session command responses that weren't complete also discarded the partial
event instead of storing it for later use.
2016-12-08 15:09:36 +02:00
66feeb8fbc Fix rwsplit debug assertion
A maximum of zero slaves is an accepted value.
2016-12-08 12:09:06 +02:00
0fab454e66 Close the DCB and the related backend at the same time
Closing the DCB and the backend reference that uses it at the same time
makes the error handling code clearer and removes some of the assumptions
that the code made. It will cause the DCB to be closed in multiple places
but the logic of why a DCB is being closed is more visible from the code.

This change should remove all cases where a DCB is closed without a
tightly coupled backend reference.
2016-12-07 10:48:54 +02:00
970d70700d Close master references when they lose the master state
If the `error_on_write` mode is used when a master loses the master state,
the backend would not get closed. This would allow masters that appear
back to be used which is not intended.
2016-12-07 08:51:51 +02:00
4ae85dc754 Merge branch '2.0' into develop 2016-12-05 21:19:59 +02:00
943aa48fb5 Make sure DCBs are OK before closing them
Added a check for the validity of the backend DCBs before they are
closed. This should guarantee that only valid DCBs are closed by
readwritesplit.

However, this is not the correct solution for the problem. The DCB should
not be in an invalid state in the first place and this fix just removes
the bad side effects of the double closing.

With the added logging in the readwritesplit error handler, more detailed
information should become available.
2016-12-04 06:35:35 +02:00
6f7b572822 Only close DCBs we know are valid
If a DCB is passed to the error handler for which we cannot find the
corresponding backend reference, it should not be closed.

Added extra logging for situations where the backend reference can't be
found or it is in the wrong state.
2016-12-02 14:26:43 +02:00
0bc68742a6 Do error handling in one big locked action
This is not the optimal way to do error handling but it should solve all
problems that could rise from the multi-threaded model of MaxScale.

By taking a lock at the start of handleError, we'll be able to modify the
dcb error handling flag in a thread-safe manner. This should prevent
double error handling for all DCBs.
2016-11-29 12:07:12 +02:00
f8f400bdfd Only close the errored DCB if it is not in use
It was theoretically possible that a DCB was closed while it was still in
use.
2016-11-29 12:07:12 +02:00
8dae8136aa Add more logging to solve MXS-956
If a DCB is about to be closed but is has already been closed, a message
is logged. This will allow us to figure out exactly where the DCB is
closed.
2016-11-29 12:07:12 +02:00
265aacaf15 GWBUF_DATA(...) explicitly returns uint8_t* 2016-11-24 13:31:29 +02:00
f4e3ca2c87 Merge branch '2.0.2' into develop 2016-11-23 11:24:34 +02:00
1432677406 Fix regression in prepared statement routing
The prepared statements were router according to the real type instead of
being router to the master. This was caused by the change in the route
target function.
2016-11-21 23:05:46 +02:00
9e4ee0323d Merge branch '2.0' into develop 2016-11-21 12:23:30 +02:00
5aefd35df9 MXS-969: Detect user variable modifications
With the use_sql_variables_in=master option, readwritesplit should route
all user variable modifications and reads with user variables to the
master.

Previously, the modification of user variables was grouped into generic
system variables which caused all modifications to system variables to go
to the master only. The router requires a finer grained distiction between
normal system variable modifications and user variable modifications.

With the improvements to the query classifier, readwritesplit now properly
routes all user variable operations to the master and other system
variable modifications to all servers.
2016-11-16 15:26:06 +02:00
44a55d231f Merge commit 'a7c21eee88c3c2530c06fea8a20c718004eed244' into develop-2.0-merge 2016-11-16 12:57:23 +02:00
a7c21eee88 Always treat master failures as fatal errors
When a connection to the master fails, readwritesplit should always treat
it the same way. Previously, if a connection to the master was lost but it
hadn't lost the master status, the failure would be treated like a slave
server failure.
2016-11-15 22:18:26 +02:00
3c15b58891 Merge branch '2.0' into develop-2.0-merge 2016-11-15 00:09:24 +02:00
da129025eb Use common backend closing function
The backend references now use a common closing function so that all
variables are reset to proper states. The stored queries weren't always
freed and they would leak memory if left open.
2016-11-14 16:14:20 +02:00
ba4ab9d35f Remove sorting of backends with qsort
The backends are no longer sorted with qsort. This removes the possibility
of stale backend references.
2016-11-14 15:01:41 +02:00
2334c663e0 Merge branch 'develop' into MXS-936 2016-11-10 15:42:09 +01:00
65886dc386 Check whether server references are active
Before a query is routed to a backend, the status of the server reference
is checked. This allows the servers that are removed from a service to be
ejected from the list of active servers for active sessions.
2016-11-10 15:15:10 +02:00
ea0dcea5d6 Clean up instance and session lifecycle functions
The createInstace, newSession, closeSession and freeSession functions were
cleaned up and reorganized to be a bit clearer for the reader. Removed
unnecessary comments and replaced them with ones that explain what's
happening in the code.

Removed unused linked lists from both sessions and instances and replaced
them with better alternatives. This should improve performance since new
session don't have to acquire the instance level lock to put themselves
into the session list.
2016-11-10 15:15:10 +02:00
88dca05dc7 Remove unused code from readwritesplit
There was a lot of extra debug logging behind unused defines. These were
never enabled and some of the code never worked.
2016-11-10 15:15:10 +02:00
dc8c068936 Modify readwritesplit to understand changes in server references
The readwritesplit now understands that the amount of servers can change
and some of the items in the list of server references aren't in use. This
allows dynamic changes to the number of servers used by readwritesplit.
2016-11-10 15:15:10 +02:00
b12a87ef04 Fix false error message in readwritesplit
The error message for failure to find master wasn't included in the new
master error logging.
2016-11-09 23:21:53 +02:00
8d893b4e56 Reassing master reference after sorting backends
The master reference used by the readwritesplit sessions needs to be
reassigned if slave reconnection occurs. This happens because the
reference refers to a certain place in the backend reference array
instead of the actual backend reference and those places are mixed
when the array is sorted.
2016-11-09 23:21:47 +02:00
de18f25cb8 MXS-936: add shutdown hooks
First part: add shutdown hooks for routers.

Binlog is the first one with a  destroyInstance() routine
2016-11-08 11:12:37 +01:00
a163e31b9a Remove BACKEND structure from readwritesplit
The BACKEND structure is no longer created for the instance. This allows
sessions to dynamically create new servers.
2016-11-07 14:10:18 +02:00
a097204c70 MXS-922: Move server weight calculation into the core
The core now does the server weight calculation instead of each router
module doing the same thing.
2016-11-07 14:10:18 +02:00
83f3245f75 Improve master routing failure error logging
The error logging is now more detailed and tells why the connection is
being closed. This should help the user figure out what is happening when
write fails and the connection is closed.
2016-11-06 10:25:56 +02:00
263688d3af Use proper server status macros in readwritesplit
Some of the master server status checks didn't check whether the server
was actually running. The macros in server.h should always be used instead
of manually inspecting the server status.
2016-11-06 07:03:07 +02:00
3d4a7179c7 Prevent active readwritesplit sessions from connecting to a master
If a readwritesplit session is active, it should never connect to a new
master. This will lead to unexpected results as the session states aren't
consistent.
2016-11-05 11:31:06 +02:00
c30d0dfc9d Add more error logging to DCB handling
If an illegal DCB close is done with a backend DCB, it will log the server
where it was connected. This allows us to know whether the DCB was
connected to a master or a slave.

Added more debug assertions to readwritesplit code. The DCBs should never
enter the DCB_STATE_DISCONNECTED.

Removed useless debug log messages. The messages usually just flood the
logs with no use to the developers.
2016-11-05 11:28:18 +02:00
8f6c1bdd5b Add more error messages for unexpected situations
Some error messages were logged at INFO level and some had conditions that
prevent the logging. Removed these restrictions that an error situation is
always logged.
2016-11-03 10:16:46 +02:00