7340 Commits

Author SHA1 Message Date
Markus Mäkelä
f91d415be1 Add simple test for atomic operations
The test runs some simple tests with the atomic operations in MaxScale.
2017-04-24 15:58:28 +03:00
Markus Mäkelä
122337569c Add atomic store and load operations
Added abstractions for storing and loading 32-bit and 64-bit values
atomically. The functions currently use the GCC __atomic builtin atomics.
2017-04-24 15:58:28 +03:00
Johan Wikman
8174690f77 Introduce concept of Worker tasks
A Worker::Task is an object that can be sent to a worker for
execution. The task is sent to the worker using the messaging
mechanism where the `execute` function of the task will be
called in the thread context of the worker.

There are two kinds of tasks; regular tasks and disposable tasks.
The former are just sent to the worker for execution while the
latter are sent and subsequently disposed of, once the task has
been executed.

A disposable task can be sent to either one worker or to all
workers. In the latter case, the task will be deleted once it
has been executed by all workers.

A semaphore can be associated with a regular task. Once the task
has been executed by the worker, the semaphore will automatically
be posted. That way, it is trivial to send a task for execution
to a worker and wait until the task has been executed. For instance:

    Semaphore sem;
    MyTask task;

    pWorker->execute(&task, &sem);
    sem.wait();

    const MyResult& result = task.result();

The low level mechanism for posting and broadcasting messages will
be removed.
2017-04-24 14:52:54 +03:00
Johan Wikman
172cdbc5a3 Update comment regarding use of level-triggered events 2017-04-24 10:51:45 +03:00
Johan Wikman
b0922576be Add Semaphore class
A simple Semaphore class that makes it simpler and less
erroprone to use a semaphore.
2017-04-23 18:54:18 +03:00
Johan Wikman
c5fd2bdb81 Add listening sockets to shared epoll instance
All sorts of additional cleaning up can now be performed.
2017-04-22 17:02:52 +03:00
Johan Wikman
56b411aea9 Add shared epoll instance to workers
All workers share an epoll instance that is added level-triggered
to the epoll instance of each Worker. This is intended to be used
together with listening sockets.

When a listening socket is added to the shared epoll instance the
effect is that EPOLLIN will be active for it whenever there is a
connection pending on a listening socket added to that epoll
instance.

When that occurs all workers in their epoll_wait()-calls will return.
When the workers subsequently call epoll_wait() on the shared epoll
instance, that will return with an event provided some other thread(s)
has not yet called accept() on the listening socket.

As each worker extracts just one event at a time and calls accept just
once before calling epoll_wait(), it means that the client connections
will be distributed evenly across all workers, provided the load on
the workers is roughly the same. If it isn't then a worker with less
load will get more connections to handle (which will even out the load).
2017-04-21 21:24:20 +03:00
Johan Wikman
a27bec5e88 Add return value to Worker::init()
Cleaner to return status than exit upon failure.
2017-04-21 19:57:45 +03:00
MassimilianoPinto
adb2cc1517 MXS-1209: blr_slave_query cleanup
New routine: blr_handle_admin_stmt() is in use
2017-04-20 15:48:26 +02:00
MassimilianoPinto
371598fc8f MXS-1209: blr_slave_query cleanup
Added blr_handle_admin_stmt()
2017-04-20 15:19:49 +02:00
Markus Mäkelä
b0bec7b9b8 Always read Avro headers from file
The headers were read from memory as if they were in compressed
format. This mistake was caused by the fact that the function names were
changed.
2017-04-20 14:22:55 +03:00
Markus Mäkelä
9a221c46f3 Process PS responses in readwritesplit
When a prepared statement preparation is being routed to the master, the
response is now collected into one buffer before being sent back. This
allows proper processing of pipelined prepared statements.
2017-04-20 14:22:55 +03:00
Markus Mäkelä
36d06960bf Combine query preparation into one function
The same operations of protocol state and inspections of the buffer were
done in multiple places. Combining these into one function removes the
duplicated code.
2017-04-20 14:22:55 +03:00
Markus Mäkelä
73dd9bd025 Allow collection of prepared statement responses
The backend MySQL protocol can now collect prepared statement preparation
responses as well as result sets. This removes the need to parse and
collect the preparation responses at the router level.
2017-04-20 14:22:55 +03:00
Markus Mäkelä
a88e98035f Clean up MySQL protocol debug logging
Removed pthread_self calls from the backend modules. This makes the debug
logging easier to parse when the messages aren't prefixed with the verbose
thread ID.
2017-04-20 14:22:55 +03:00
Markus Mäkelä
cf2272f479 Clean up DCB debug logging
All debug messages from dcb.cc were prefixed with the pthread ID of the
current thread. If the thread ID is needed, it should be logged by the log
manager.
2017-04-20 14:21:35 +03:00
Markus Mäkelä
8fe31f360d Remove multi-packet additions to response parsing
The additions to the packet parsing code weren't necessary once the
statement output change was reverted.
2017-04-20 14:18:40 +03:00
Markus Mäkelä
5037646846 Remove redundant flag value definitions
The response status flag values are already declared in the mysql_com.h
header.
2017-04-20 14:18:40 +03:00
Markus Mäkelä
673631084a MXS-1203: Fix response tracking of LOAD DATA LOCAL INFILE
When responses are being tracked, the execution of a LOAD DATA LOCAL
INFILE requires special handling. The readwritesplit now has a simple
state machine for the handling of the LOAD DATA LOCAL INFILE command. This
should also make the code a bit more readable.
2017-04-20 14:18:40 +03:00
Markus Mäkelä
ea38d511e3 MXS-1203: Process multiple results correctly with readwritesplit
The readwritesplit didn't correctly process the response packets that
contained more than one part of a multi-result response. By processing the
packets in a loop, this problem is avoided.

Removed some of the more "unique" ways of sending error messages in favor
of simply writing the error to the client DCB. This removes the need for
extra logic in the clientReply response handling.
2017-04-20 14:18:40 +03:00
Markus Mäkelä
d7258fffd0 MXS-1203: Improve resultset processing functions
The functions used to track the resultset EOF packets now expose the
position of the end of the result set. This allows the modules that use
them to check if more results exist in the same buffer.

Added the status bits for OK and EOF packets to the mysql.h protocol
header. This can be used to check for various state changes that happen in
the session. Currently the status bits are only used to detect if more
results are expected.
2017-04-20 14:18:40 +03:00
Markus Mäkelä
a1c7ee438d MXS-1203: Fix current command tracking with statement routing
When statement based routing was used, it was possible that the current
statement being executed wasn't properly updated. Readwritesplit requires
it to track whether a command will create a response.
2017-04-20 14:18:40 +03:00
Markus Mäkelä
6f468c573e MXS-1203: Fix readwritesplit routing decision logging
The info level logging could print binary data as if it were a
null-terminated string. Also cleaned up the function to make it a bit more
manageable.
2017-04-20 14:18:39 +03:00
Markus Mäkelä
66cf571412 MXS-1203: Better handling of batch queries
When batched queries are done through readwritesplit, it will now handle
them one by one. This allows batched queries to be used with
readwritesplit but it does impose a performance penalty when compared to
direct execution on the backend.
2017-04-20 14:18:39 +03:00
Johan Wikman
a8b42d24b7 Handle fake events when they are delivered
Since fake events are delivered via the event loop they can and
indeed should be processed immediately.
2017-04-20 13:51:16 +03:00
Johan Wikman
db3153ee4e Move statistics to Worker
Now the statistics is in a single structure and the property of the
Worker instance in question. Methods are provided for obtaining the
statistics of all workers in one go.
2017-04-20 13:51:16 +03:00
Johan Wikman
722d6da46f The thread state is now a property of the worker
A worker's state is not statistics, but transient information.
2017-04-20 13:51:16 +03:00
Johan Wikman
effa2f5674 poll_waitevents moved to Worker
A direct move without any non-essential modifications. Poll_waitevents will
be turned into a regular methods using instance variables.
2017-04-20 13:51:16 +03:00
Johan Wikman
4ed615a6c1 Cleanup of poll.cc
Unnecessary/unused functions, variable and headers removed.
2017-04-20 13:51:16 +03:00
Johan Wikman
2bbb67b4f5 Remove old load calculation
The existing load calculation does not fit the 2.0 thread approach
that well. So it is removed entirely now, to be replaced with some
new approach later.
2017-04-20 13:51:16 +03:00
Johan Wikman
f742a98119 Remove queue event reporting
Was not updated, output meaningless.
2017-04-20 13:51:16 +03:00
Johan Wikman
b265ca457d Remove various obsolete stuff 2017-04-20 13:51:16 +03:00
Johan Wikman
3ac619bfec Fold thread state into poll stats 2017-04-20 13:51:16 +03:00
Johan Wikman
30d7f52852 Remove meaningsless stats
Showing dcb addresses, the number of fds and the events is
meaningless as the information is completely transient and
is likely to have changed the moment is was displayed.
2017-04-20 13:51:16 +03:00
Johan Wikman
1464230714 Fix stats calculation error 2017-04-20 13:51:16 +03:00
Johan Wikman
05d9d31499 Remove meaningless statistics
Counting how many times no threads are in epoll_wait does not
make sense anymore, now that threads do not share any work.
2017-04-20 13:51:16 +03:00
Johan Wikman
f952a11eb8 Move queue statistics to Worker
Just like the thread stats and poll stats earlier, the queue stats
are now moved to worker.

A litte refactoring still, and the polling will only work on local
data.
2017-04-20 13:51:16 +03:00
Johan Wikman
76825eb2c5 Poll statistics moved to worker
Each worker now has a separate structure for collecting the
polling statistics that is passed to epoll_waitevents(). When
the stats are asked for, we loop over all separate stats and
combine them. So, instead of having every statistics of each
thread one cacheline apart, each thread has all its statistics
in one lump that, for obvious reasons, are going to be apart.

The primary purpose of this excersize is to remove the hardwired
nature of the statistics collection. For instance, the admin
thread will be doing I/O but that I/O should not be included
in the statistics of the workers.
2017-04-20 13:51:16 +03:00
Johan Wikman
c11ca1c328 Move thread data to workers
This is a step in the direction that any worker/thread related data
is the property of the worker/thread.
2017-04-20 13:51:16 +03:00
Johan Wikman
052975bccd Add MessageQueue to Worker
The Worker no longer creates a pipe and implements the cross
worker/thread message mechanism itself. Instead it has a
MessageQueue instance variable for that purpose.
2017-04-20 13:51:16 +03:00
Johan Wikman
b8c78a23df Add MessageQueue class
MessageQueue encapsulates a message queue built on top of a
pipe. The message queue needs a handler for receiving messages
and must be added to a worker for pumping messages through the
pipe.

Each Worker will have an instance of MessageQueue.
2017-04-20 13:51:16 +03:00
Johan Wikman
d20c89be37 Use epoll instance of Worker
Now the epoll instance of the Worker is used when polling. The
work is still done in poll.cc and the worker provides the descriptor
and thread id.

The comments of poll_waitevents() have been removed; they were not
accurate anymore so better to let the code speak for itself.
2017-04-20 13:51:16 +03:00
Johan Wikman
949b41b0aa Remove serialization mutex from poll.cc
I don't think it has been ever used and the comment even suggested
that it "may" be useful.
2017-04-20 13:51:16 +03:00
Johan Wikman
21ac606ee1 poll_[add|remove]_fd_[from|to]_worker made boolean 2017-04-20 13:51:16 +03:00
Johan Wikman
9829d6e365 Add epoll instance to Worker
And add the Worker header...
The epoll instance is not used yet, but the common creation of epoll
instances in poll.cc will be removed and the epoll instances of each
worker used instead.
2017-04-20 13:51:16 +03:00
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