diff --git a/server/core/internal/service.h b/server/core/internal/service.h index 1310b5db6..7c1634ff9 100644 --- a/server/core/internal/service.h +++ b/server/core/internal/service.h @@ -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 */ diff --git a/server/core/service.cc b/server/core/service.cc index 3385b3c2c..3669e7665 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -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; +} diff --git a/server/core/worker.cc b/server/core/worker.cc index aeae5fea5..0bbe59ff3 100644 --- a/server/core/worker.cc +++ b/server/core/worker.cc @@ -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)