fix: explicit set Worker::self_ to thread local
This commit is contained in:
1
deps/oblib/src/lib/thread/threads.cpp
vendored
1
deps/oblib/src/lib/thread/threads.cpp
vendored
@ -209,6 +209,7 @@ void Threads::run(int64_t idx)
|
|||||||
ObTLTaGuard ta_guard(GET_TENANT_ID() ?:OB_SERVER_TENANT_ID);
|
ObTLTaGuard ta_guard(GET_TENANT_ID() ?:OB_SERVER_TENANT_ID);
|
||||||
thread_idx_ = static_cast<uint64_t>(idx);
|
thread_idx_ = static_cast<uint64_t>(idx);
|
||||||
Worker worker;
|
Worker worker;
|
||||||
|
Worker::set_worker_to_thread_local(&worker);
|
||||||
run1();
|
run1();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
9
deps/oblib/src/lib/worker.cpp
vendored
9
deps/oblib/src/lib/worker.cpp
vendored
@ -58,15 +58,6 @@ Worker::Worker()
|
|||||||
disable_wait_(false)
|
disable_wait_(false)
|
||||||
{
|
{
|
||||||
worker_node_.get_data() = this;
|
worker_node_.get_data() = this;
|
||||||
if (OB_ISNULL(self_)) {
|
|
||||||
self_ = this;
|
|
||||||
} else {
|
|
||||||
// Ideally, there won't be worker creating when a routine, or
|
|
||||||
// thread, has a worker, i.e. self_ isn't null. Whereas ObThWorker
|
|
||||||
// which derived from Worker doesn't create instance on the same
|
|
||||||
// routine as it is. So we can't assert self_ is null when new
|
|
||||||
// Worker is initializing right now.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Worker::~Worker()
|
Worker::~Worker()
|
||||||
|
|||||||
7
deps/oblib/src/lib/worker.h
vendored
7
deps/oblib/src/lib/worker.h
vendored
@ -116,6 +116,7 @@ public:
|
|||||||
static void set_compatibility_mode(CompatMode mode);
|
static void set_compatibility_mode(CompatMode mode);
|
||||||
static CompatMode get_compatibility_mode();
|
static CompatMode get_compatibility_mode();
|
||||||
static Worker& self();
|
static Worker& self();
|
||||||
|
static void set_worker_to_thread_local(Worker *worker);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static __thread Worker *self_;
|
static __thread Worker *self_;
|
||||||
@ -154,6 +155,12 @@ private:
|
|||||||
|
|
||||||
extern void *alloc_worker();
|
extern void *alloc_worker();
|
||||||
extern void common_yield();
|
extern void common_yield();
|
||||||
|
|
||||||
|
inline void Worker::set_worker_to_thread_local(Worker *worker)
|
||||||
|
{
|
||||||
|
self_ = worker;
|
||||||
|
}
|
||||||
|
|
||||||
inline Worker &Worker::self()
|
inline Worker &Worker::self()
|
||||||
{
|
{
|
||||||
// wbuf won't been NULL.
|
// wbuf won't been NULL.
|
||||||
|
|||||||
@ -33,6 +33,7 @@ int ObTableServiceLibrary::init()
|
|||||||
::oceanbase::common::USE_CO_LATCH = false;
|
::oceanbase::common::USE_CO_LATCH = false;
|
||||||
// Create worker for current thread.
|
// Create worker for current thread.
|
||||||
::oceanbase::lib::Worker worker;
|
::oceanbase::lib::Worker worker;
|
||||||
|
::oceanbase::lib::Worker::set_worker_to_thread_local(&worker);
|
||||||
// setup easy
|
// setup easy
|
||||||
easy_log_set_format(easy_log_format_adaptor);
|
easy_log_set_format(easy_log_format_adaptor);
|
||||||
easy_log_level = EASY_LOG_INFO;
|
easy_log_level = EASY_LOG_INFO;
|
||||||
|
|||||||
@ -526,7 +526,7 @@ int main(int argc, char *argv[])
|
|||||||
// thread has already had a worker, which can prevent binding
|
// thread has already had a worker, which can prevent binding
|
||||||
// new worker with it.
|
// new worker with it.
|
||||||
lib::Worker worker;
|
lib::Worker worker;
|
||||||
|
lib::Worker::set_worker_to_thread_local(&worker);
|
||||||
ObServer &observer = ObServer::get_instance();
|
ObServer &observer = ObServer::get_instance();
|
||||||
LOG_INFO("observer starts", "observer_version", PACKAGE_STRING);
|
LOG_INFO("observer starts", "observer_version", PACKAGE_STRING);
|
||||||
// to speed up bootstrap phase, need set election INIT TS
|
// to speed up bootstrap phase, need set election INIT TS
|
||||||
|
|||||||
@ -237,6 +237,7 @@ void ObPxPool::run(int64_t idx)
|
|||||||
set_thread_idx(idx);
|
set_thread_idx(idx);
|
||||||
// Create worker for current thread.
|
// Create worker for current thread.
|
||||||
ObPxWorker worker;
|
ObPxWorker worker;
|
||||||
|
Worker::set_worker_to_thread_local(&worker);
|
||||||
run1();
|
run1();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -315,8 +315,7 @@ void ObThWorker::set_th_worker_thread_name(uint64_t tenant_id)
|
|||||||
void ObThWorker::worker(int64_t &tenant_id, int64_t &req_recv_timestamp, int32_t &worker_level)
|
void ObThWorker::worker(int64_t &tenant_id, int64_t &req_recv_timestamp, int32_t &worker_level)
|
||||||
{
|
{
|
||||||
int ret = OB_SUCCESS;
|
int ret = OB_SUCCESS;
|
||||||
lib::Worker::self_ = this;
|
Worker::set_worker_to_thread_local(static_cast<lib::Worker*>(this));
|
||||||
lib::Worker::self_ = this;
|
|
||||||
int64_t wait_start_time = 0;
|
int64_t wait_start_time = 0;
|
||||||
int64_t wait_end_time = 0;
|
int64_t wait_end_time = 0;
|
||||||
int64_t req_start_time = 0;
|
int64_t req_start_time = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user