2695 Commits

Author SHA1 Message Date
Johan Wikman
df5553c35a All worker data moved to Worker class
With the exception of the poll structure.
2017-04-20 13:51:16 +03:00
Johan Wikman
72eadff181 Further remove use of the worker C-API 2017-04-20 13:51:16 +03:00
Johan Wikman
f1e99a475a Remove unneded worker C-API 2017-04-20 13:51:16 +03:00
Johan Wikman
0e4e889c15 Turn worker into a C++ class
This is the first step in turning the worker mechanism and everything
around it into a set of C++ classes. In this change, the original C
API is still present, but in subsequent changes that will be removed.
2017-04-20 13:51:16 +03:00
Johan Wikman
ece77c4478 Compile worker.c as C++ 2017-04-20 13:51:16 +03:00
Johan Wikman
64ab48f698 Sorting out rebase 2017-04-20 13:51:16 +03:00
Johan Wikman
b89cf62d38 Sorting out merge from 2.1 2017-04-20 13:51:16 +03:00
Johan Wikman
274f299b54 Rebase sorting out 2017-04-20 13:51:16 +03:00
Johan Wikman
86b7eb622e DCBs now added/removed without locks
This is not globally safe yet, but all other access is directly or
indirectly related to maxadmin, which is irrelevant as far as
performance testing is concerned.
2017-04-20 13:51:16 +03:00
Johan Wikman
6c3c96cb7e Inject hangup event in owning thread
When a hangup event needs to be inserted into all DCBs referring
to a particular server, it is done in the worker thread that owns
the DCB.
2017-04-20 13:51:16 +03:00
Johan Wikman
7844680c7d Add possibilty to execute function in thread
Now possible to send a function and arguments to a specific worker
thread for execution.

In particular, this will be used for transferring the injection of
fake hangup events into DCBs, related to a particular server, from
the monitor thread to the worker threads, thus removing the need
for locks.
2017-04-20 13:51:16 +03:00
Johan Wikman
5138032fe5 Add shutdown support
The shutdown is now performed so that a shutdown message is
sent to all workers. When the workers receive that message, they
turn on a shutdown flag, which subsequently is checked in the poll
loop.
2017-04-20 13:51:16 +03:00
Johan Wikman
ab37333ce5 MXS_WORKER passed to poll_waitevents 2017-04-20 13:51:16 +03:00
Johan Wikman
016ed89b3e Move worker thread management to worker
The worker threads are now started by the workers themselves.
2017-04-20 13:51:16 +03:00
Johan Wikman
72977128f7 Introduce private worker header 2017-04-20 13:51:16 +03:00
Johan Wikman
bb6e0767cc Add first version of MXS_WORKER
MXS_WORKER is an abstraction of a worker aka worker thread.
It has a pipe whose read descriptor is added to the worker/thread
specific poll set and a write descriptor used for sending messages
to the worker.

The worker exposes a function mxs_worker_post_message using which
messages can be sent to the worker. These messages can be sent from
any thread but will be delivered on the thread dedicated for the
worker.

To illustrate how it works, maxadmin has been provided with a new
command "ping workers" that sends a message to every worker, which
then logs a message to the log.

Additional refactoring are needed, since there currently are overlaps
and undesirable interactions between the poll mechanism, the thread
mechanism and the worker mechanism.

This is visible currently, for instance, by it not being possible to
shut down MaxScale. The reason is that the workers should be shut down
first, then the poll mechanism and finally the threads. The shutdown
need to be arranged so that a shutdown message is sent to the workers
who then cause the polling loop to exit, which will cause the threads
to exit.

That can be arranged cleanly by making poll_waitevents() a "method"
of the worker, which implies that the poll set becomes a "member
variable" of the worker.

To be continued.
2017-04-20 13:51:16 +03:00
Johan Wikman
22b39daf06 Make EPOLLET the default
The whole worker thread mechanism assumes EPOLLET and non-blocking
descriptors, so that should be the default.

TODO: In debug mode, check that the provided file descriptor indeed
      is non-blocking.
2017-04-20 13:51:16 +03:00
Johan Wikman
56c132f273 Move poll_[add|remove]_dcb to dcb.c 2017-04-20 13:51:16 +03:00
Johan Wikman
85faca74f7 Move DCB specific event handling to dcb.c 2017-04-20 13:51:16 +03:00
Johan Wikman
b11b848e66 Move all statistics gathering to poll_waitevents().
The handler callback should now return a bitmask with bits set
according to what it did when it was called. That way the actual
statistics gathering can be done in poll_waitevents() and the
handler need not be aware of any thread structs.

Actually, the only thing that needs any assistance is accept handling,
because in poll_waitevents() we do not know whether a READ event
relates to a listening or a normal socket, that is, should the
event be counted as an accept or as a read.
2017-04-20 13:51:16 +03:00
Johan Wikman
dec2bcdab2 Change DCB to MXS_POLL_DATA in statistics
Only the address of the data is used, so the code need not be
DCB specific.
2017-04-20 13:51:16 +03:00
Johan Wikman
8500a980ac Update events bitmap in poll_waitevents
This information is also generally applicable for all
poll event handlers, not just DCB. The state of the thread
is already set in poll_waitevents().
2017-04-20 13:51:16 +03:00
Johan Wikman
1e47c4aa50 Move stats-collecting to poll_waitevents()
If the stats-collecting is performed in poll_waitevents() then it
will be collected for all kinds of sockets (when other that DCB
ones can be added).
2017-04-20 13:51:16 +03:00
Johan Wikman
63141bb191 WIP: Allow the adding of any fds to the poll set
This is just a first step in a trial that will allow the addition
of any file descriptor to the general poll mechanism and hence
allow any i/o to be handled by the worker threads.

There is a structure

  typedef struct mxs_poll_data
  {
      void (*handler)(struct mxs_poll_data *data, int wid, uint32_t events);
      struct
      {
          int id;
      } thread;
  } MXS_POLL_DATA;

that any other structure (e.g. a DCB) encapsulating a file descriptor must
have as its first member (a C++ struct could basically derive from it).

That structure contains two members; 'handler' and 'thread.id'. Handler is a
pointer to a function taking a pointer to a struct mxs_poll_data, a worker thread
if and an epoll event mask as argument.

So, DCB is modified to have MXS_POLL_DATA as its first member and 'handler'
is initialized with a function that *knows* the passed MXS_POLL_DATA can
be downcast to a DCB.

process_pollq no longer exists, but is now called process_pollq_dcb. The
general stuff related to statistics etc. will be moved to poll_waitevents
itself after which the whole function is moved to dcb.c. At that point,
the handler pointer will be set in dcb_alloc().

Effectively poll.[h|c] will provide a generic mechanism for listening on
whatever descriptors and the dcb stuff will be part of dcb.[h|c].
2017-04-20 13:51:16 +03:00
Markus Mäkelä
5704ae5ffd Allow paths to be created if they don't exist
A module can now declare a path parameter for a directory that does not
yet exist. If the directory does not exist, MaxScale will create the
directory with the requested permissions.
2017-04-20 13:26:16 +03:00
Johan Wikman
c3cfc86a7b Merge branch '2.1' into develop 2017-04-19 18:19:13 +03:00
Johan Wikman
27e97a546d Remove superfluous logging
Just because of a debug build you do not want the transaction
parser to log.
2017-04-19 18:15:56 +03:00
Johan Wikman
3b4fdbcf32 Fix compilation error 2017-04-18 14:53:12 +03:00
Esa Korhonen
a418387d0a MXS-1218 Poll statistics changed to 64bit to avoid looparound
Statistics calculation, printing and MaxInfo are modified.
n_fds remains 32bit.
2017-04-18 13:14:47 +03:00
Markus Mäkelä
a54d6fe816 Add connector plugindir to help output
The output now displays the connector directory.
2017-04-13 17:57:52 +03:00
Esa Korhonen
9e8ddc842c Fix leaks in testconfig 2017-04-06 12:51:09 +03:00
Esa Korhonen
15951423d8 Fix memory errors in test_poll and test_queuemanager
test_poll was calling poll_init() two times since it's already included in
init_test_env().

test_queuemanager was missing a bunch of frees. This doesn't fix it completely,
but removes most of the leaks and valgrind errors.
2017-04-05 17:37:21 +03:00
Esa Korhonen
b1f66d21c8 Fix valgrind-errors in test_filter and test_modutil
Reduces valgrind clutter quite a bit.
2017-04-05 15:04:36 +03:00
Markus Mäkelä
ad1c05b015 Merge branch '2.1' into develop 2017-04-05 11:35:13 +03:00
Esa Korhonen
2d987b25b2 Fix test_dcb
Set threadcount to one, don't check validity after freeing.
2017-04-05 10:49:43 +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
Johan Wikman
8d2d6d8721 Join threads to prevent leaks 2017-04-03 14:20:54 +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
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ä
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
Johan Wikman
8a86efc30e Fix gwbuf_clone
With this change, the test_clone() test in testbuffer.c no longer
causes a leak according to valgrind.
2017-03-30 22:16:51 +03:00
Johan Wikman
8284716e6a Add test for gwbuf_clone to testbuffer.c
- Under valgrind, this test reveals the leak of gebuf_clone.
2017-03-30 22:14:58 +03:00
Johan Wikman
29fa4a6088 Fix testbuffer.c
Free memory allocated by tests, so that it is meaningful to run under
valgrind in order to check for GWBUF leaks.
2017-03-30 22:02:34 +03:00
Johan Wikman
b4c119915b Fix gwbuf_rtrim
- If everything in the first buffer of a buffer chain is consumed,
  then the whole chain and not just the first buffer was freed.

NOTE: gwbuf_rtrim needs to be fixed so that it removes data from the
      tail of a chain and *not* from the end of the first buffer in
      a chain. That cannot ever be what is wanted.
2017-03-30 21:49:57 +03:00
Johan Wikman
a1d1413b24 Add atomic_add for 64-bit integers.
Now only GCC intrinsics are used.
2017-03-30 12:36:23 +03:00
Markus Mäkelä
b458b63756 Use IPv6 for created listeners
When listeners are created, use the default values of [::]:3306.
2017-03-29 17:14:39 +03:00
Markus Mäkelä
1901a3bc0a Bind to IPv6 addresses by default
The `::` address covers both IPv4 and IPv6 addresses allowing both IP
versions to be used by default.
2017-03-28 21:25:30 +03:00
Johan Wikman
58c1c1a3ca Remove BLOCKING_POLL
The code was not correct anymore and correcting it does not seem
worthwhile.
2017-03-27 11:12:37 +03:00
MassimilianoPinto
8e24f847e6 Fix compile errors in Centos 6
Fix compile errors in Centos 6
2017-03-27 09:49:21 +02:00