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.
This commit is contained in:
Johan Wikman
2017-02-15 20:59:08 +02:00
parent 22b39daf06
commit bb6e0767cc
6 changed files with 345 additions and 0 deletions

View File

@ -73,6 +73,7 @@
#include <maxscale/maxscale.h>
#include <maxscale/version.h>
#include <maxscale/log_manager.h>
#include <maxscale/worker.h>
#include "../../../core/maxscale/config_runtime.h"
#include "../../../core/maxscale/maxscale.h"
@ -926,6 +927,38 @@ static void cmd_AddServer(DCB *dcb, SERVER *server, char *v1, char *v2, char *v3
}
}
/**
* The subcommands of the ping command.
*/
void ping_workers(DCB* dcb)
{
int n_workers = config_threadcount();
for (int i = 0; i < n_workers; ++i)
{
MXS_WORKER *worker = mxs_worker_get(i);
if (mxs_worker_post_message(worker, MXS_WORKER_MSG_PING, 0, NULL))
{
dcb_printf(dcb, "Posted message to worker %d.\n", i);
}
else
{
dcb_printf(dcb, "Could not post message to worker %d: %s\n", i, mxs_strerror(errno));
}
}
}
struct subcommand pingoptions[] =
{
{
"workers", 0, 0, ping_workers,
"Ping Workers",
"Ping Workers",
{ARG_TYPE_NONE}
}
};
/**
* The subcommands of the add command
*/
@ -1654,6 +1687,7 @@ static struct
{ "show", showoptions },
{ "sync", syncoptions },
{ "call", calloptions },
{ "ping", pingoptions },
{ NULL, NULL }
};