81 Commits

Author SHA1 Message Date
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
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
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
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ä
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
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
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
Johan Wikman
da77b0419c Call the DCB "this" consistently for dcb
Since there is a concept called "listener" it is confusing that the
dcb "this" argument in some dcb functions is called 'listener' instead
of 'dcb' as it is called everywhere else.
2017-12-29 08:34:46 +02:00
Johan Wikman
140620a366 MXS-1582 Close listener sockets on exit
If the listener socket refers to a Unix domain socket, the socket file
will be deleted as well.
2017-12-29 08:34:46 +02:00
Markus Mäkelä
396b81f336 Fix in-source builds
The internal header directory conflicted with in-source builds causing a
build failure. This is fixed by renaming the internal header directory to
something other than maxscale.

The renaming pointed out a few problems in a couple of source files that
appeared to include internal headers when the headers were in fact public
headers.

Fixed maxctrl in-source builds by making the copying of the sources
optional.
2017-11-22 18:40:18 +02:00
Markus Mäkelä
b80f394cd0 Use explicit types
Use uint64_t instead of unsigned. This guarantees that the size of the
type is the same across all platforms.
2017-11-14 16:53:09 +02:00
Johan Wikman
b1b78a5be7 Remove references to QUEUE_CONFIG
Only used in conjunction with queued connections, which are not
enabled anyway. Once that comes on the table again, better to use
some standard data structures.
2017-11-08 10:44:14 +02:00
Markus Mäkelä
071d364b0a Fix formatting errors
Fixed the formatting errors introduced by Astyle. Changed the comment
syntax to use a more Astyle-friendly one.
2017-09-28 20:27:07 +03:00
Markus Mäkelä
895d950da0 Format all source files with Astyle
Formatted all source files Astyle.
2017-09-28 07:04:21 +03:00
Markus Mäkelä
b18c0ed0b8 Assign worker ID in dcb_alloc
Apart from listeners, all DCBs will be assigned to the current
thread. This simplifies the addition of DCBs to worker threads.

Also performed a small cleanup of poll_add_dcb to make it more readable.
2017-09-12 15:14:51 +03:00
Johan Wikman
02b9e0a01d Merge branch '2.1.7' into develop-2.1-merge 2017-09-12 11:08:02 +03:00
Johan Wikman
65066ae126 Call drain callback only if drained
In case of write errors the write queue will not be drained. In
that case callbacks should not be called.
2017-09-11 16:56:47 +03:00
Johan Wikman
402b27ad01 MXS-1392 Remove remnats of DCB reference counting 2017-09-08 12:41:41 +03:00
Johan Wikman
70a4ad6532 MXS-1392 Take new zombie mechanism into use
Next commit will remove the remnants of the reference counting
mechanism.
2017-09-08 12:41:41 +03:00
Johan Wikman
be94066b77 MXS-1392 Manage DCB lifetime using refcounts
Now it is also possible to ensure that a DCB stays alive while
a task referring to it is posted from one worker to another.
That will be implemented in a subsequent commit.
2017-09-08 12:41:41 +03:00
Johan Wikman
bf42d845cf MXS-1392 Remove dcb_free
Not used and with reference counting it must not be available either.
2017-09-08 12:41:41 +03:00
Johan Wikman
7e17e2cd56 MXS-1392 Add reference count to MXS_POLL_DATA
The polling mechanism can now optionally be used for managing
the lifetime of an object placed into the poll set.

If a MXS_POLL_DATA has a non-null 'free', then the reference count
of the data will be increased before calling the handler and
decreased after. In that case, if the reference count reaches 0,
the free function will be called.

Note that the reference counts of *all* MXS_POLL_DATAs returned
by 'epoll_wait' will be increased before the events are delivered
to the handlers individually for each MXS_POLL_DATA, and then once
all events have been delivered, the reference count of each
MXS_POLL_DATA will be decreased.

This ensure that if there are interdependencies between different
MXS_POLL_DATAs returned by one call to 'epoll_wait', the case that
an MXS_POLL_DATA is deleted before its events have been delivered
can be avoided by using the reference count for lifetime management.

In subsequent commits, the reference count will be taken into use
in the lifetime management of DCBs.
2017-09-08 12:41:41 +03:00
Johan Wikman
cae0e658fb Handle failures in dcb_connect properly
When something fails inside dcb_connect we rewind the situation
properly, without calling any of the close functions intended for
shutting down a properly created DCB. That way they can be simplified
and once the reference counting is taken into use it is sufficient to
call dcb_dec_ref(dcb) instead of dcb_free_all_memory().
2017-09-07 16:03:17 +03:00
Johan Wikman
9da1439b0e Rename session_link_dcb to session_link_backend_dcb
Reduce risk for confusion.
2017-09-07 15:51:48 +03:00
Johan Wikman
80815e0f54 Change session_link_dcb to void
The function attempted to detect use of freed memory, which is a
futile excersize.
2017-09-07 15:04:35 +03:00
Johan Wikman
44db97215f Deliver fake events for the current dcb immediately
If a fake event is added to the current dcb, we arrange things so
that it is delivered immediately when the handling of the event(s)
during which the fake event was added, has been performed.

Otherwise the event is delivered via the event loop.
2017-09-07 13:48:07 +03:00
Johan Wikman
699b3909f7 Set current_dcb to NULL if the current DCB is deleted 2017-09-06 13:45:39 +03:00
Markus Mäkelä
c542010e67 Fix internal test failures
The adminusers test did not properly initialize all subsystems in
MaxScale. The polling and DCB tests weren't updated with the changes to
the DCB closing.
2017-09-06 13:20:28 +03:00
Johan Wikman
3770b4da95 Name read/fake queue consistently
Now dcb_readqueue and dvb_fakequeue are named readq and fakeq
respectively, to be consistent with the naming of the write
and delay queue.
2017-09-06 11:30:24 +03:00
Johan Wikman
24044a7376 Add dcb functions
dcb_readq_append()
dcb_readq_prepend()
dcb_readq_set()
dcb_readq_has()
dcb_readq_release()
dcb_readq_get()
dcb_readq_length()

No code but for DCB code itself should directly manipulate the
internals of a DCB. Thesse functions will be taken into use in
protocol modules.
2017-09-06 11:12:32 +03:00
Johan Wikman
186ee31abf Fix setting of this_thread.current_dcb
Also in the case of fake events, the current dcb must be set.
2017-09-05 16:04:59 +03:00
Johan Wikman
d3f4723c81 Do not report events for closed dcb
Before each event handler is called, it is checked whether the
dcb has been closed. If it has been, then the event handler is
not called.

The check has to be made before each event handler, because any
event handler can close the dcb.
2017-09-05 13:20:22 +03:00
Johan Wikman
2f0292fd68 Relax dcb_close assert
If the current worker id is -1, we do not insist that the dcb
is closed by the owning thread. That will happen only for dcbs
that are created before the workers have been started and hence
it is also ok to close them after the workers have exited.
2017-09-04 16:00:27 +03:00
Johan Wikman
b43ab674e3 Add dcb_close_in_owning_thread(DCB*);
Allows a DCB to be closed by a thread other than the owning
thread.
2017-09-04 13:41:16 +03:00
Johan Wikman
ccbff0f6d4 Allow debugging of dcb event handling
Using DCB_LOG_EVENT_HANDLING is defined, a notice will be
logged for each event when it is handled.
2017-09-04 11:29:18 +03:00
Johan Wikman
1a468049b8 Overwrite dcb thread id at final close 2017-09-04 11:09:48 +03:00
Johan Wikman
18cb61f7de Delay closing in dcb_close
If a dcb being closed is the dcb for which events are currently being
processed, the dcb is not closed immediately but only after all events
have been delivered.
2017-09-01 11:03:23 +03:00
Johan Wikman
d7b04fc451 Add static storage to anonymous unit/thread structures
Without static, CentOS6 complains about non-local variable
using anonymous type.
2017-08-31 12:45:16 +03:00
Johan Wikman
67efd1daea MXS-1378 Provide access to the current DCB
This will be used by a subsequent `session_get_current()` and
`session_get_current_id()` for obtaining the current SESSION and
session id, respectively. The latter of those will be used by the
logging mechanism for logging the session id in conjunction with
messages.
2017-08-30 13:58:42 +03:00
Johan Wikman
2a346fd061 MXS-1376 Really close a DCB only at the end of event loop
When dcb_close() is called, the DCB is only marked for closing
and the actual closing takes place only after all event handlers
have been called. That way, the state of the DCB will not change
during event processing but only after.

From a handler perspective this should now be just like it was
when the zombie queue was present.

TODO: There are far too many state variables or variables akin to
      state variables - dcb_role, state, persistentstart, n_close -
      in DCB. A cleanup is warranted.
2017-08-29 15:44:50 +03:00
Johan Wikman
9c25e6d995 MXS-1376 All zombie related code removed
As dcbs are now closed when dcb_close() is called and there is
no zombie queue, the zombie state can also be removed.
2017-08-25 14:48:16 +03:00
Johan Wikman
c11d8fa328 MXS-1376 Close a connection in dcb_close
As each client/server connection will be handled by a specific
thread, all closing activity can take place directly when the
connection is closed and not later when the zombie queue is
processed.

In a subsequent commit the zombie queue will be removed.
2017-08-25 14:48:16 +03:00
Johan Wikman
72831c86ac DCBEVENTQ removed
No longer used for anything
2017-08-24 09:57:42 +03:00