1511 Commits

Author SHA1 Message Date
Johan Wikman
bc1c2e1152 Ensure exit is possible
If shutdown has been initiated (via maxadmin or by sending a
SIGINT or SIGTERM) and a SIGTERM is received, the process
is terminated.

If shutdown has been initiated (via maxadmin or by sending a
SIGINT or SIGTERM) and a SIGINT (Ctrl-C) is received, a warning
is printed that shutdown is in progess. Then, if an additional
SIGINT is received, the process is terminated.

So, in practice:
- If MaxScale is running as a daemon, the first SIGTERM initiates
  shutdown and a second one unconditionally terminates the process.
- If MaxScale is running in the console, the first Ctrl-C initiates
  shutdown, the second prints a warning and the third terminates
  the process.

This is to ensure that MaxScale can be forced to exit, in
case some thread is hung for whatever reason, and is thus preventing
the controlled shutdown.
2016-11-10 11:09:59 +02:00
MassimilianoPinto
da152353dd Merge branch 'develop' into MXS-936 2016-11-09 16:21:40 +01:00
Johan Wikman
02ec7e9b17 Wait until housekeeper has finished
When calling hkshutdown(), only a shutdown flag will be set.
In main() we will then actually wait for the housekeeper thread
to finish before exiting.
2016-11-09 15:14:52 +02:00
MassimilianoPinto
4e36e86820 MXS-936: destroyInstance added for filters
MXS-936: destroyInstance added for filters
2016-11-08 17:09:49 +01:00
MassimilianoPinto
61f0603e39 MXS-936: destroyInstance interface change
MXS-936: destroyInstance interface change
2016-11-08 14:07:48 +01:00
MassimilianoPinto
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
Markus Makela
ded551e199 Add function for full memory barrier into maxscale/atomic.h
This allows safer lock-free reads to be done on lists that never shrink in
size. The main use-case for this is to allow servers to be added to a
service without locking the service each time a new session is created.

Synchronizing the memory before adding new components into a list
guarantees that if a session reads from the list and sees the new list
item, the memory pointed by the item is valid.
2016-11-07 14:10:18 +02:00
Markus Makela
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
Markus Makela
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
Johan Wikman
bf62f8950a Remove qc_get_affected_fields
Function is no longer used and it was quite unoptimal, so now
removed.

qc_get_prepare_name, qc_get_prepare_operation and qc_get_field_info
that were missing from qc_dummy added at the same time.
2016-11-07 12:28:58 +02:00
Johan Wikman
8778e0c81e Make Users const correct 2016-11-03 09:35:49 +02:00
Johan Wikman
af65ee0ef9 qc: Ensure type is uint32_t
Some C++ compiler complains about signed being compared with unsigned.
2016-11-03 08:30:45 +02:00
Johan Wikman
c652f1330a qc: Add qc_get_field_info
This function returns more detailed information about the fields
of a statement. Supersedes qc_get_affected_fields() that will
be deprecated and removed.

Note that this function now introduced new kind of behaviour; the
returned data belongs to the GWBUF and remains valid for as long as
the GWBUF is alive. That means that unnecessary copying need not
be done.
2016-11-02 15:50:21 +02:00
Johan Wikman
ab487e687f qc: Remove QUERY_IS_TYPE macro
Explicit call to qc_query_is_type() instead.
2016-11-02 15:50:21 +02:00
Markus Makela
5085b41d20 Reset persistent MySQL connections
When a persistent connection is taken from the pool, the state is reset
with a COM_CHANGE_USER on the next write. This allows reuse of persistent
connections without having to worry about the state of the MySQL session.
2016-11-01 10:50:07 +02:00
Johan Wikman
91e36ecaed Make PREPARE operation explicit
The operation of the statement to be prepared is no longer
reported as the operation of the PREPARE statement.

Instead, when the type of the statement is
QUERY_TYPE_PREPARE_NAMED_STMT, the operation can be obtained
using qc_get_prepare_operation().

The qc_mysqlembedded implementation will be provided in a
subsequent commit.
2016-10-31 13:44:48 +02:00
Johan Wikman
8c20ad5cd0 MXS-304: Support hierarchical reload
'reload config' now also processes all configuration files
of a hierarchy.
2016-10-31 12:48:38 +02:00
Johan Wikman
1be3bb9b8d Minor cleanup of config.[h|c]
- Add const where applicable.
- Cleanup header files.

Fix collateral damage (statistics.c) as well.
2016-10-27 15:55:26 +03:00
Johan Wikman
bbade8b736 PCRE2_CODE_UNIT_WIDTH must not be defined. 2016-10-27 15:26:41 +03:00
Johan Wikman
a390331e42 Feature defines moved to <maxscale/cdefs.h>
Feature defines that affect the available functionality or the
compile time environment should be defined in a common way for
all source.
2016-10-27 14:08:58 +03:00
Johan Wikman
7499c1e1bf qc: Add minimal support for qc_get_prepare_name
If the query is a PREPARE or EXECUTE statement, then qc_get_prepare_name
will return the name of the prepared statement.
2016-10-26 14:36:37 +03:00
Johan Wikman
19e017e499 QC: Documentation cleaned up and moved to header 2016-10-26 14:22:41 +03:00
Johan Wikman
dc97de57c2 qc: Some minor cleanup
- qc_types_to_string renamed to qc_typemask_to_string
- qc_get_qtype_str removed, duplicate of qc_typemask_to_string
2016-10-26 10:21:11 +03:00
Johan Wikman
d7ce3ad75b Replace include guards with #pragma once 2016-10-26 08:23:15 +03:00
Johan Wikman
f961f87e5e Update autocommit mode and transaction state
The transaction state only reflects explicitly started transactions.
Thus, by looking at the autocommit mode and the transaction state a
component can figure out whether the current statement will be committed
or not.
2016-10-25 16:21:31 +03:00
Johan Wikman
041df39819 Move transaction state management to the right place
The transaction state must be updated after a buffer has been split
into buffer containing individual packets.

NOTE: The actual updating of the transaction state and the autocommit
      mode is currently wrong, but will be updated in a subsequent change.
2016-10-25 16:21:31 +03:00
Johan Wikman
4c286b85e6 Add new capability types 2016-10-24 15:33:24 +03:00
Johan Wikman
bd18a7d8ed Add service capabilities
The service capabilities are the union of the capabilities of the
router and all filters.
2016-10-24 15:13:16 +03:00
Johan Wikman
3915b4e7c7 Exclude MXS_DEBUG in release builds
Now, MXS_DEBUG turns into a nop in release builds.
2016-10-24 14:00:51 +03:00
Johan Wikman
1a2e0ba3ee Check log priority before logging
With this change, whether something should be logged or, that is,
whether the used log priority is enabled or not, is checked before
the logging function is called. That should save a few cycles.

Now mxs_log_message() always logs a message, without consideration
for whether the priority is enabled or not. The inline function
mxs_log_is_priority_enabled() returns true if a particular priority
is enabled and the MXS_LOG_MESSAGE() macro (that MXS_ERROR etc. are
expanded into) call that before calling the actual logging function.
2016-10-24 14:00:51 +03:00
Johan Wikman
db2cccbd8f Replace getCapabilities() with getCapabilities(void)
The latter means no args, the former means any args.
2016-10-24 11:19:43 +03:00
Johan Wikman
59a4152d8a Add getCapabilities to filters
Common capabilities are now defined in routing.h. The common
capabilities can be defined using bits 0 - 15.

Router capabilities are defined using bits 16-31 and filter
capabilities (should there ever be such) using bits 32-47.

So, to find out the capabilities of a service you only need to
OR the capabilities of the router and all filters together.

For instance, if a single filter needs statement based routing,
then that is what is done.
2016-10-24 11:19:43 +03:00
Markus Makela
8f55cfbc16 Fix cache_dir path handling in MySQLAuth
The path that was given as the option for the cache directory wasn't
properly checked for terminating forward slashes. Due to this, the cache
file was created with the wrong name.
2016-10-21 18:33:35 +03:00
Markus Makela
4e07c3313c Move dbusers.c out of the core
The dbusers.c was a MySQL protocol specific file which was used directly
by some of the modules.

Added a new return value for the loadusers authenticator entry point which
allows fatal failures to occur when users are loaded. Currently this is
only taken into notice when the service is first started. If a listener
later returns a fatal error, it is only logged but the service stays in
operation.

Moved the MySQLAuth authenticator sources and the tests that relate to
this module into a subdirectory in the authenticator
directory. Eventually, all authenticators could have a subdirectory of
their own.
2016-10-21 18:33:35 +03:00
Markus Makela
fe689504b0 Move service user injection into MySQL authenticator
The MySQL authenticator now injects the service user into the list of
allowed users if loading of database users fails. This allows the removal
of common code in the binlogrouter and maxinfo modules.
2016-10-21 18:33:35 +03:00
Johan Wikman
693d8dcbb4 Track session autocommit state
This tracks only what is explicitly set. That is, if autocommit
has been set true then, even if a transaction is started, autocommit
will not be set false.

That is, a user of the session autocommit and transaction states
need to be aware of their semantics. If a transaction is active,
then the state of autocommit is irrelevant.
2016-10-21 13:58:51 +03:00
Johan Wikman
311eae8cfe MXS-983: Add transaction state to session object 2016-10-20 23:00:33 +03:00
Johan Wikman
6bcb3ce4dc Change capabilities to uint64_t
- Since the capabilities are a bitmask, it is better if an unsigned
  integral type is used.
- Since the function is part of an ABI, it is better if an explicit
  size is used.
- 64-bits so that there also is room for independent filter
  capabilities.
2016-10-20 20:14:59 +03:00
Johan Wikman
f0cf391c18 include/maxscale/gw.h removed.
In a subsequent change, the includes of server/core/*.c will be
cleaned up, and if there is a common set of include files, needed
by most, then a server/core/maxscale/core.h that includes those
will be introduced.
2016-10-17 12:17:09 +03:00
Johan Wikman
63b5c10f31 Move daemonize() to gateway.c
The one remaining function in gw_utils.c was moved to gateway.c,
so gw_utils.c could be removed.
2016-10-17 12:17:09 +03:00
Johan Wikman
e6d7ca4ed9 GW_NOINTR_CALL removed.
Used in just one place inside MaxScale so better to simply write
it explcitly.
2016-10-17 12:17:09 +03:00
Johan Wikman
b27774e674 Rename MAX_BUFFER_SIZE
MAX_BUFFER_SIZE, which is used for limiting the amount of the data
read from a socket renamed to MXS_MAX_NW_READ_BUFFER_SIZE and moved
from gw.h to limits.h.

Consider removing altogether. Difficult to justify since non-blocking
reads are used and the amount of available data is known.
2016-10-17 12:17:09 +03:00
Johan Wikman
8aafa34d66 Hard limits moved to limits.h
Limits used with SO_[RCV|SEND]BUF moved from gw.h to limits.h and
renamed so that the prefix is MXS_.
2016-10-17 10:11:13 +03:00
Johan Wikman
4faa7f8d21 Obsolete defines removed 2016-10-17 10:11:13 +03:00
Johan Wikman
d5cf74bd24 Cleanup gw.h, part 1.
Gw.h contained a fair amount of obsolete function declarations,
duplicate declarations of functions declared in utils.h and
declarations of functions that conceptually are similar to those
in utils.h.

The obsolete and duplicate ones were removed and all but one of
the remaining moved to utils.h. Correspondingly the implementation
was moved from gw_utils.c to utils.c.

The one remaining function - gw_daemonize() - is not really worthy
of a file of its own, so that is to be moved to gateway.c after which
gw_utils.c can be removed.

Gw.h still contains defines that are duplicated in
maxscale/protocol/mysql.h. The ones in gw.h are to be removed. It
appears that the entire gw.h will disappear.
2016-10-15 11:18:14 +03:00
Johan Wikman
1333da0712 Remove skygw_utils.h
The general purpose stuff in skygw_utils.h was moved to utils.h
and the corresponding implementation from skygw_utils.cc to utils.c.
Includes updated accordingly.

Skygw_utils.h is now only used by log_manager and by mlist, which
is only used by log_manager. Consequently, skygw_utils.h was moved
to server/maxscale.

Utils.h needs a separate overhaul.
2016-10-14 19:50:54 +03:00
Markus Makela
571919264f MXS-862: Make packet sequence handling automatic
Made the packet sequence number handling automatic so that it always uses
the correct one.

All functions now have documentation in them. Cleaned up code and added
comments to GSSAPI code.
2016-10-14 18:25:38 +03:00
Johan Wikman
68e53567a0 Make mlist.h private
Mlist is only used by log_manager so for the time being it is moved
under server/core/maxscale. Eventually it may be included in log_manager
itself.
2016-10-14 15:55:33 +03:00
Johan Wikman
cd26c69ffb Remove slist
Not used by anybody, so better to remove it.
2016-10-14 15:52:27 +03:00
Johan Wikman
03dbc6df80 Remove dependency on skygw_utils.h
- STRERROR_BUFLEN moved to cdefs.h and renamed to MXS_STRERROR_BUFLEN.
  Better would be to provide a 'const char* mxs_strerror(int errno)'
  that would have a thread specific buffer for the error message.
- MIN and MAX also moved to defs.h as MXS_MIN and MXS_MAX.
- Now only mlist.h of the headers depend upon skygw_utils.h.
2016-10-14 15:42:02 +03:00