Pre-load users for all threads

Pre-loading users for all threads at startup significantly reduces the
chance for failures caused by the lazy initialization of the user database
done by the authenticators.

If users are not loaded at startup and the connection limit for all
servers is reached, authentication in MaxScale will fail not due to too
many connections but due to the lack of authentication data. This causes
repeated reloading of users, which floods the log with messages, and
unnecessary stress on the cluster itself.
This commit is contained in:
Markus Mäkelä 2017-12-22 09:29:44 +02:00
parent ad57de6784
commit fb1875c61c
3 changed files with 29 additions and 3 deletions

View File

@ -69,6 +69,15 @@ void service_destroy_instances(void);
*/
int service_launch_all(void);
/**
* Perform thread-specific initialization
*
* Currently this function only pre-loads users for all threads.
*
* @return True on success, false on error (currently always returns true).
*/
bool service_thread_init();
/**
* Creating and adding new components to services
*/

View File

@ -2773,3 +2773,17 @@ uint64_t service_get_version(const SERVICE *service, service_version_which_t whi
return version;
}
bool service_thread_init()
{
spinlock_acquire(&service_spin);
for (SERVICE* service = allServices; service; service = service->next)
{
service_refresh_users(service);
}
spinlock_release(&service_spin);
return true;
}

View File

@ -34,6 +34,7 @@
#include "internal/dcb.h"
#include "internal/modules.h"
#include "internal/poll.h"
#include "internal/service.h"
#include "internal/statistics.h"
#include "internal/workertask.hh"
@ -857,11 +858,11 @@ void Worker::delete_zombies()
void Worker::run()
{
if (modules_thread_init())
this_thread.current_worker_id = m_id;
if (modules_thread_init() && service_thread_init())
{
this_thread.current_worker_id = m_id;
poll_waitevents();
this_thread.current_worker_id = WORKER_ABSENT_ID;
MXS_NOTICE("Worker %d has shut down.", m_id);
modules_thread_finish();
@ -870,6 +871,8 @@ void Worker::run()
{
MXS_ERROR("Could not perform thread initialization for all modules. Thread exits.");
}
this_thread.current_worker_id = WORKER_ABSENT_ID;
}
bool Worker::start(size_t stack_size)