117 Commits

Author SHA1 Message Date
Markus Mäkelä
a1d5a06ba7
Use only backend DCBs with session_unlink_backend_dcb
The client DCB isn't in the set of DCBs managed by the session.
2018-08-06 21:20:29 +03:00
Markus Mäkelä
6fc3fbd697
Fix debug assertion when a DCB is printed
All DCBs don't have the server pointer set so it needs to be checked
before calling any functions that take a server as a parameter.
2018-08-03 10:34:50 +03:00
Markus Mäkelä
23d944b82e
MXS-1929: Close listener DCBs
When a service is freed, it will free all of its listeners causing their
respective DCBs to be closed. This requires that listeners can be removed
from the worker DCB list.
2018-07-31 09:41:06 +03:00
Markus Mäkelä
4069072164
Do service client counts in the core
As all connections should be accepted via dcb_accept, it is the optimal
place to calculate how many open client connections per service there
are. The decrementation should be done when the session is closed instead
of when the call to dcb_close for the client DCB is done. This allows the
client count to be the absolute reference count that sessions have to a
service.

The current client count is a duplicate counter that should match the
n_current value in SERVICE_STATS. The former does differ from the latter
in that it does the incrementation when the client DCB is accepted instead
of when the session is created.
2018-07-31 09:41:06 +03:00
Markus Mäkelä
6c59da77fb
Merge branch '2.2' into develop 2018-07-26 11:27:09 +03:00
Markus Mäkelä
21eef8a670
MXS-1985: Kill connections inside workers
The LocalClient micro-client required a reference to the session that was
valid at construction time. This is the reason why the previous
implementation used dcb_foreach to first gather the targets and then
execute queries on them. By replacing this reference with pointers to the
raw data it requires, we lift the requirement of the orignating session
being alive at construction time.

Now that the LocalClient no longer holds a reference to the session, the
killing of the connection does not have to be done on the same thread that
started the process. This prevents the deadlock that occurred when
concurrect dcb_foreach calls were made.

Replaced the unused dcb_foreach_parallel with a version of dcb_foreach
that allows iteration of DCBs local to this worker. The dcb_foreach_local
is the basis upon which all DCB access outside of administrative tasks
should be built on.

This change will introduce a regression in functionality: The client will
no longer receive an error if no connections match the KILL query
criteria. This is done to avoid having to synchronize the workers after
they have performed the killing of their own connections.
2018-07-24 09:51:46 +03:00
Markus Mäkelä
101dad74a7
MXS-1985: Add debug assertions to dcb_foreach
The dcb_foreach function is not safe to use from multiple threads at the
same time. This should be asserted by checking that the function is called
only from the main worker.

The addition of this assertion also implies that only administrative
operations should use the dcb_foreach function. To accommodate this
change, the KILL command iteration needs to be adjusted.
2018-07-24 09:51:45 +03:00
Markus Mäkelä
d91710c640
Remove unused DCB state
The state was never assigned.
2018-07-18 15:47:25 +03:00
Markus Mäkelä
44ef4912e8
Merge branch '2.2' into develop 2018-07-03 21:13:41 +03:00
Markus Mäkelä
fb1c28c702
MXS-1948: Do round-robin worker assignment
Due to the skewed accept distribution without SO_REUSEPORT, we use
round-robin assignment of workers for new client connections. This
provides better performance as work is more likely to be evenly
distributed across all threads.

Using a least-busy-worker algorithm would provide a more stable result but
this is not trivially simple to implement. For this reason, the
round-robin based approach was chosen for 2.2.
2018-07-03 12:49:59 +03:00
Johan Wikman
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
Johan Wikman
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
Johan Wikman
cc0299aee6 Update change date of 2.3 2018-06-25 10:07:52 +03:00
Markus Mäkelä
a812e02ba4
Merge branch '2.2' into develop 2018-06-15 10:48:07 +03:00
Markus Mäkelä
3d1c2b421a
MXS-1921: Explain why session was closed
When a client connection is closed by MaxScale before the client initiates
a controlled closing of the connection, an error message is sent. This
error message now also explains why the connection was closed to make
problem resolution easier.
2018-06-14 13:48:07 +03:00
Markus Mäkelä
8094c67ac2
Merge branch '2.2' into develop 2018-06-13 00:25:56 +03:00
Markus Mäkelä
24870e278c
MXS-1913: Check session before invoking dcb_foreach callback
If the session is the dummy session, the callback should not be called.
2018-06-12 23:55:30 +03:00
Johan Wikman
8f9bf100e1 MXS-1918 Remove HASHTABLE from dcb.cc 2018-06-12 17:32:35 +03:00
Markus Mäkelä
3f4d6391b5
MXS-553: Add diagnostics_json to protocol API
The protocol now allows protocol modules to return JSON formatted
information about the protocol module internals. Currently this is only
implemented by the mariadbbackend module and it returns the current
connection ID on the backend server.
2018-05-22 17:46:25 +03:00
Markus Mäkelä
66255361dc
MXS-553: List connections in sessions resource
The connections that relate to a particular session are now a part of the
sessions resource. Currently, only the generic information is stored for
each connection (id and server name).
2018-05-22 17:46:25 +03:00
Markus Mäkelä
643fc825fa
MXS-553: Provide full session to DCB mapping
By storing a link to the backend DCBs in the session object itself, we can
reach all related objects from the session. This removes the need to
iterate over all DCBs to find the set of related DCBs.
2018-05-22 17:46:24 +03:00
Johan Wikman
de0541f76b MXS-1875 Use RoutingWorker and not Worker
DCBs will only be used in conjunction with RoutingWorkers and
hence RoutingWorker and not just Worker must be used when looking
for the current worker and worker id.

The reason is that RoutingWorker cheats; the current worker id is
set to 0 at initialization time, which indicates that a worker would
be running although it isn't.

The reason is that as listeners are created before any worker has
been started, that arrangement ensures that listening DCBs are
book-kept in the worker running in the main thread.

Now, that is a kludge. It ought to be changed so that a, say,
MainRoutingWorker class is introduced that in its run function
initializes MaxScale and then continues running as any regular
RoutingWorker. In due time.
2018-05-22 16:49:16 +03:00
Johan Wikman
0d92b0bc8f Merge branch '2.2' into develop 2018-05-22 16:18:36 +03:00
Johan Wikman
3097137a2f MXS-1875 Ensure cleanup of DCB does not cause crash.
- If a client DCB should be moved to some other worker than
  the current one (cli and maxinfo), and that fails, the
  thread id must be reset to that of the calling thread as
  otherwise asserts will be triggered.
- If the creation of the first DCB fails, then the dcb list
  for that thread will be NULL and thus must be accessed
  with some caution.
2018-05-22 16:18:02 +03:00
Markus Mäkelä
0e686dd0f3
MXS-1878: Immediately process hangups
When DCBs are being hung in dcb_hangup_foreach, the hangup event can be
processed directly. This prevents excessive use of the worker message
queue pipe thus reducing the possibility of it being full.
2018-05-22 15:44:55 +03:00
Johan Wikman
bced61c6d8 MXS-1875 Log in correct branch
Also use different error message to make it plain where it is
logged.
2018-05-22 08:42:48 +03:00
Johan Wikman
f166b50b37 MXS-1875 Add fd and make note of DCB simultaneously
The fact that a client dcb was immediately added to the epoll-
instance of the relevant worker (possible, since that is thread-
safe), but was added to the book-keeping via the message mechanism
(necessary, since that is not thread-safe), meant that if the
connection was closed before the message was delivered, the handling
of the message then caused an access error.

Now the fd is also added to the epoll-instance via the messaging
mechanism, so the problem can no longer occur. The only fds this
affects are connections made to maxadmin or maxinfo as they are
always handled by the main thread due to deadlock issues.
2018-05-21 20:04:13 +03:00
Johan Wikman
42c10cfa1c MXS-1848 Move Worker from internal to public include dir
maxscale::Worker needs to be public if monitors should be
implementable using it.
2018-05-14 10:10:18 +03:00
Markus Mäkelä
490d8c0963
Merge branch '2.2' into develop 2018-04-30 12:38:19 +03:00
Markus Mäkelä
cfa599aea8
MXS-1833: Force all maxinfo traffic to the main thread
The same problem that caused maxadmin to lock up was also what caused
maxinfo to lock up. The concurrent access to the legacy administrative
functions caused deadlocks.
2018-04-27 12:38:43 +03:00
Esa Korhonen
5d010ff712 Cleanup SERVER struct
Removed one unused field. Rearranged others, clarified comments.
2018-04-27 10:48:56 +03:00
Johan Wikman
4d4ab83e99 MXS-754 Fix unit test failures caused by RoutingWorker 2018-04-19 10:51:28 +03:00
Markus Mäkelä
99a9dd1006
Merge branch '2.2' into develop 2018-04-18 09:36:17 +03:00
Markus Mäkelä
474736584b
Fix test_poll failure
With the changes to the DCB handling, the service pointer of a client DCB
must always be assigned.

Also removed the unnecessary parentheses around the comparison.
2018-04-18 08:10:42 +03:00
Johan Wikman
b36f6faa7e MXS-1754 Reintroduce maxscale::Worker
Worker is now the base class of all workers. It has a message
queue and can be run in a thread of its own, or in the calling
thread. Worker can not be used as such, but a concrete worker
class must be derived from it. Currently there is only one
concrete class RoutingWorker.

There is some overlapping in functionality between Worker and
RoutingWorker, as there is e.g. a need for broadcasting a
message to all routing workers, but not to other workers.

Currently other workers can not be created as the array for
holding the pointers to the workers is exactly as large as
there will be RoutingWorkers. That will be changed so that
the maximum number of threads is hardwired to some ridiculous
value such as 128. That's the first step in the path towards
a situation where the number of worker threads can be changed
at runtime.
2018-04-16 14:53:08 +03:00
Johan Wikman
230876cd69 MXS-1754 Rename mxs::Worker to mxs::RoutingWorker
A new class mxs::Worker will be introduced and mxs::RoutingWorker
will be inherited from that. mxs::Worker will basically only be a
thread with a message-loop.

Once available, all current non-worker threads (but the one
implicitly created by microhttpd) can be creating by inheriting
from that; in practice that means the housekeeping thread, all
monitor threads and possibly the logging thread.

The benefit of this arrangement is that there then will be a general
mechanism for cross thread communication without having to use any
shared data structures.
2018-04-16 14:53:08 +03:00
Johan Wikman
fa3143cedf Merge branch '2.2' into develop 2018-04-16 14:46:19 +03:00
Johan Wikman
7e29725050 MXS-1805 Force all maxadmin connections to main thread
If maxadmin connections are handled by different workers, then
there may be a deadlock if some maxadmin command requires
communication with all workers.

Namely, in that case a message will be sent to all other workers
but the current one, but that message will not be handled if that
other worker at that point sits in the debugcmd_lock spinlock
in debugcmd.c:execute_cmd().

We can prevent that deadlock from happening simply by ensuring
that all maxadmin connections are handled by one thread.
2018-04-16 13:25:33 +03:00
Markus Mäkelä
b33f464eea
MXS-1506: Make heartbeat reads atomic
The old hkheartbeat variable was changed to the mxs_clock() function that
simply wraps an atomic load of the variable. This allows it to be
correctly read by MaxScale as well as opening up the possibility of
converting the value load to a relaxed memory order read.

Renamed the header and associated macros. Removed inclusion of the
heartbeat header from the housekeeper header and added it to the files
that were missing it.
2018-04-10 15:29:29 +03:00
Markus Mäkelä
304499bd36
Merge branch '2.2' into develop 2018-04-10 14:05:39 +03:00
Markus Mäkelä
d22be5dd3e
Fix build failure caused by merge from 2.1
The dcb->thread.id is dcb->poll.thread.id in 2.2.
2018-04-10 13:54:30 +03:00
Markus Mäkelä
fad4508fe2
Merge branch '2.1' into 2.2 2018-04-10 13:49:42 +03:00
Johan Wikman
33457c7334 Merge branch '2.2' into develop 2018-03-26 10:07:17 +03:00
Johan Wikman
2bdac88b0b MXS-1738 Copy AF_UNIX data from listener to client dcb
We need to copy some data from a AF_UNIX based listener dcb
to the accepted client dcb, to prevent assertion violation in
dcb_get_port(). Further, to be able to log the path in the case
of an authentication error we need to copy that as well.
2018-03-26 10:06:42 +03:00
Esa Korhonen
d17c3b8ab7 Cast to uint before comparing
Fixes compilation error.
2018-03-07 13:32:42 +02:00
dapeng
82bb624981 MXS-1690: Need Backpressure mechanism (#169)
* implication of backpressure

* fix typo and refactor

* misc refactor

* misc fix

* add function session_unlink_backend_dcb and more comments

* misc fix

* refactor, move all throttling logic into dcb.cc

* misc fix

* misc fix
2018-03-07 12:34:47 +02:00
Markus Mäkelä
6f6c11e6a3
Ignore events for closed DCBs
If a closed DCB receives an event, it is ignored.
2018-02-06 16:36:04 +02:00
Markus Mäkelä
12f5cabc50 Discard fake events for closed DCBs
If a fake event is sent to a DCB that has been closed, it should be
discarded.
2018-01-31 13:38:45 +02:00
Markus Mäkelä
1febafabf3 Crash after double close on debug builds
When a double close is detected in a debug build, a debug assertion is
triggered. This will generate a core dump which should help investigate
the double close.
2018-01-31 13:38:45 +02:00
Markus Mäkelä
facecc2dcd Make sure double DCB closes are detected
Crashing after a double close makes sure it is properly detected in debug
builds.
2018-01-09 10:57:18 +02:00