From 158dedccd87eb45b6ae717e3b007190651ea494b Mon Sep 17 00:00:00 2001 From: nroskill Date: Fri, 3 Mar 2023 06:43:32 +0000 Subject: [PATCH] fix coredump at tenant hook --- deps/easy/src/io/easy_client.c | 4 +- deps/oblib/src/common/ob_queue_thread.cpp | 4 +- deps/oblib/src/lib/CMakeLists.txt | 1 + deps/oblib/src/lib/hash/ob_hashutils.h | 2 +- deps/oblib/src/lib/lock/cond.h | 4 +- deps/oblib/src/lib/lock/ob_thread_cond.cpp | 4 +- deps/oblib/src/lib/ob_define.h | 9 ++++ .../oblib/src/lib/thread}/ob_tenant_hook.cpp | 51 +++---------------- src/observer/CMakeLists.txt | 1 - .../ob_multi_version_schema_service.cpp | 2 +- 10 files changed, 28 insertions(+), 54 deletions(-) rename {src/observer/omt => deps/oblib/src/lib/thread}/ob_tenant_hook.cpp (73%) diff --git a/deps/easy/src/io/easy_client.c b/deps/easy/src/io/easy_client.c index 44a9b8353..5e65e1248 100644 --- a/deps/easy/src/io/easy_client.c +++ b/deps/easy/src/io/easy_client.c @@ -19,6 +19,8 @@ static int easy_client_uthread_wakeup_conn(easy_connection_t *c); static int easy_client_uthread_wakeup_session(easy_request_t *r); +int ob_pthread_cond_wait(pthread_cond_t *__restrict __cond, + pthread_mutex_t *__restrict __mutex); /** * 把session发送到addr上 */ @@ -148,7 +150,7 @@ void easy_client_wait(easy_client_wait_t *w, int count) pthread_mutex_lock(&w->mutex); while (w->done_count < count) { - pthread_cond_wait(&w->cond, &w->mutex); + ob_pthread_cond_wait(&w->cond, &w->mutex); } pthread_mutex_unlock(&w->mutex); diff --git a/deps/oblib/src/common/ob_queue_thread.cpp b/deps/oblib/src/common/ob_queue_thread.cpp index 0de4e3067..950fcc75a 100644 --- a/deps/oblib/src/common/ob_queue_thread.cpp +++ b/deps/oblib/src/common/ob_queue_thread.cpp @@ -62,7 +62,7 @@ int ObCond::wait() if (need_wait) { pthread_mutex_lock(&mutex_); while (OB_SUCC(ret) && false == ATOMIC_CAS(&bcond_, true, false)) { - int tmp_ret = pthread_cond_wait(&cond_, &mutex_); + int tmp_ret = ob_pthread_cond_wait(&cond_, &mutex_); if (ETIMEDOUT == tmp_ret) { ret = OB_TIMEOUT; break; @@ -95,7 +95,7 @@ int ObCond::timedwait(const int64_t time_us) ts.tv_nsec = (abs_time % 1000000) * 1000; pthread_mutex_lock(&mutex_); while (OB_SUCC(ret) && false == ATOMIC_CAS(&bcond_, true, false)) { - int tmp_ret = pthread_cond_timedwait(&cond_, &mutex_, &ts); + int tmp_ret = ob_pthread_cond_timedwait(&cond_, &mutex_, &ts); if (ETIMEDOUT == tmp_ret) { ret = OB_TIMEOUT; break; diff --git a/deps/oblib/src/lib/CMakeLists.txt b/deps/oblib/src/lib/CMakeLists.txt index 724cc7807..685d5183b 100644 --- a/deps/oblib/src/lib/CMakeLists.txt +++ b/deps/oblib/src/lib/CMakeLists.txt @@ -214,6 +214,7 @@ ob_set_subtarget(oblib_lib thread thread/protected_stack_allocator.cpp thread/thread.cpp thread/threads.cpp + thread/ob_tenant_hook.cpp ) ob_set_subtarget(oblib_lib utility diff --git a/deps/oblib/src/lib/hash/ob_hashutils.h b/deps/oblib/src/lib/hash/ob_hashutils.h index 5fae856c4..0833867c2 100644 --- a/deps/oblib/src/lib/hash/ob_hashutils.h +++ b/deps/oblib/src/lib/hash/ob_hashutils.h @@ -156,7 +156,7 @@ public: ~MutexWaiter() {} int operator()(pthread_cond_t &cond, pthread_mutex_t &lock, struct timespec &ts) { - return pthread_cond_timedwait(&cond, &lock, &ts); + return ob_pthread_cond_timedwait(&cond, &lock, &ts); } }; diff --git a/deps/oblib/src/lib/lock/cond.h b/deps/oblib/src/lib/lock/cond.h index 7071bc846..b794bc0a2 100644 --- a/deps/oblib/src/lib/lock/cond.h +++ b/deps/oblib/src/lib/lock/cond.h @@ -81,7 +81,7 @@ Cond::wait_impl(const M& mutex) const LockState state; mutex.unlock(state); - const int rc = pthread_cond_wait(&_cond, state.mutex); + const int rc = ob_pthread_cond_wait(&_cond, state.mutex); mutex.lock(state); if ( 0 != rc ) { @@ -112,7 +112,7 @@ Cond::timed_wait_impl(const M& mutex, const ObSysTime& timeout) const timespec ts; ts.tv_sec = tv.tv_sec + timeout/1000; ts.tv_nsec = tv.tv_usec * 1000 + ( timeout % 1000 ) * 1000000;*/ - const int rc = pthread_cond_timedwait(&_cond, state.mutex, &ts); + const int rc = ob_pthread_cond_timedwait(&_cond, state.mutex, &ts); mutex.lock(state); if (rc != 0) { diff --git a/deps/oblib/src/lib/lock/ob_thread_cond.cpp b/deps/oblib/src/lib/lock/ob_thread_cond.cpp index 3e35e4d96..de1069b81 100644 --- a/deps/oblib/src/lib/lock/ob_thread_cond.cpp +++ b/deps/oblib/src/lib/lock/ob_thread_cond.cpp @@ -81,7 +81,7 @@ int ObThreadCond::wait_us(const uint64_t time_us) } else { ObWaitEventGuard guard(event_no_, time_us / 1000, reinterpret_cast(this)); if (0 == time_us) { - if (OB_UNLIKELY(0 != (tmp_ret = pthread_cond_wait(&cond_, &mutex_)))) { + if (OB_UNLIKELY(0 != (tmp_ret = ob_pthread_cond_wait(&cond_, &mutex_)))) { ret = OB_ERR_SYS; COMMON_LOG(WARN, "Fail to cond wait, ", K(tmp_ret), K(ret)); } @@ -103,7 +103,7 @@ int ObThreadCond::wait_us(const uint64_t time_us) abstime.tv_sec = static_cast(std::min(static_cast(std::numeric_limits::max()), static_cast(us / 1000000))); abstime.tv_nsec = static_cast(us % static_cast(1000000)) * 1000; - if (OB_UNLIKELY(0 != (tmp_ret = pthread_cond_timedwait(&cond_, &mutex_, &abstime)))) { + if (OB_UNLIKELY(0 != (tmp_ret = ob_pthread_cond_timedwait(&cond_, &mutex_, &abstime)))) { if (ETIMEDOUT != tmp_ret) { ret = OB_ERR_SYS; COMMON_LOG(WARN, "Fail to timed cond wait, ", K(time_us), K(tmp_ret), K(ret)); diff --git a/deps/oblib/src/lib/ob_define.h b/deps/oblib/src/lib/ob_define.h index 37c845b35..20f65c7cb 100644 --- a/deps/oblib/src/lib/ob_define.h +++ b/deps/oblib/src/lib/ob_define.h @@ -2404,4 +2404,13 @@ inline bool is_x86() { #define DISABLE_WARNING_GCC_POP _Pragma("GCC diagnostic pop") #define DISABLE_WARNING_GCC_ATTRIBUTES DISABLE_WARNING_GCC("-Wattributes") +extern "C" { +extern int ob_pthread_cond_wait(pthread_cond_t *__restrict __cond, + pthread_mutex_t *__restrict __mutex); +extern int ob_pthread_cond_timedwait(pthread_cond_t *__restrict __cond, + pthread_mutex_t *__restrict __mutex, + const struct timespec *__restrict __abstime); +} + + #endif // OCEANBASE_COMMON_DEFINE_H_ diff --git a/src/observer/omt/ob_tenant_hook.cpp b/deps/oblib/src/lib/thread/ob_tenant_hook.cpp similarity index 73% rename from src/observer/omt/ob_tenant_hook.cpp rename to deps/oblib/src/lib/thread/ob_tenant_hook.cpp index 1bac8e051..af84b42df 100644 --- a/src/observer/omt/ob_tenant_hook.cpp +++ b/deps/oblib/src/lib/thread/ob_tenant_hook.cpp @@ -3,17 +3,12 @@ #ifndef PERF_MODE #define _GNU_SOURCE 1 -#include "ob_tenant.h" -#include "observer/ob_server_struct.h" -#include "observer/omt/ob_multi_tenant.h" #include "lib/worker.h" -#include "share/ob_define.h" #include #define SYS_HOOK(func_name, ...) \ ({ \ int ret = 0; \ - oceanbase::omt::ObTenant *tenant = NULL; \ if (!in_sys_hook++ && OB_NOT_NULL(oceanbase::lib::Worker::self_)) { \ oceanbase::lib::Worker::self_->set_is_blocking(true); \ ret = real_##func_name(__VA_ARGS__); \ @@ -36,16 +31,6 @@ using namespace omt; extern "C" { -ObTenant *sys_hook_get_tenant() -{ - ObTenant *tenant = NULL; - uint64_t tenant_id = 0; - if ((tenant_id = GET_TENANT_ID()) != 0 && OB_NOT_NULL(GCTX.omt_)) { - GCTX.omt_->get_tenant(tenant_id, tenant); - } - return tenant; -} - int pthread_mutex_lock(pthread_mutex_t *__mutex) { static int (*real_pthread_mutex_lock)(pthread_mutex_t * __mutex) = @@ -119,45 +104,23 @@ int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict __rwlock, } #endif -// objdump -t /lib64/libpthread.so.0 | grep pthread_cond_wait -#if defined(__x86_64__) - #define __PTHREAD_COND_WAIT_GLIBC_VERSION "GLIBC_2.3.2" -#elif defined(__aarch64__) - #define __PTHREAD_COND_WAIT_GLIBC_VERSION "GLIBC_2.17" -#else - #error arch unsupported -#endif - -int pthread_cond_wait(pthread_cond_t *__restrict __cond, - pthread_mutex_t *__restrict __mutex) +int ob_pthread_cond_wait(pthread_cond_t *__restrict __cond, + pthread_mutex_t *__restrict __mutex) { static int (*real_pthread_cond_wait)(pthread_cond_t *__restrict __cond, - pthread_mutex_t *__restrict __mutex) = - (typeof(real_pthread_cond_wait))dlvsym(RTLD_NEXT, "pthread_cond_wait", - __PTHREAD_COND_WAIT_GLIBC_VERSION); + pthread_mutex_t *__restrict __mutex) = pthread_cond_wait; int ret = 0; ret = SYS_HOOK(pthread_cond_wait, __cond, __mutex); return ret; } -// objdump -t /lib64/libpthread.so.0 | grep pthread_cond_timedwait -#if defined(__x86_64__) - #define __PTHREAD_COND_TIMEDWAIT_GLIBC_VERSION "GLIBC_2.3.2" -#elif defined(__aarch64__) - #define __PTHREAD_COND_TIMEDWAIT_GLIBC_VERSION "GLIBC_2.17" -#else - #error arch unsupported -#endif - -int pthread_cond_timedwait(pthread_cond_t *__restrict __cond, - pthread_mutex_t *__restrict __mutex, - const struct timespec *__restrict __abstime) +int ob_pthread_cond_timedwait(pthread_cond_t *__restrict __cond, + pthread_mutex_t *__restrict __mutex, + const struct timespec *__restrict __abstime) { static int (*real_pthread_cond_timedwait)( pthread_cond_t *__restrict __cond, pthread_mutex_t *__restrict __mutex, - const struct timespec *__restrict __abstime) = - (typeof(real_pthread_cond_timedwait))dlvsym( - RTLD_NEXT, "pthread_cond_timedwait", __PTHREAD_COND_TIMEDWAIT_GLIBC_VERSION); + const struct timespec *__restrict __abstime) = pthread_cond_timedwait; int ret = 0; ret = SYS_HOOK(pthread_cond_timedwait, __cond, __mutex, __abstime); return ret; diff --git a/src/observer/CMakeLists.txt b/src/observer/CMakeLists.txt index fb69293e4..68a2b3337 100644 --- a/src/observer/CMakeLists.txt +++ b/src/observer/CMakeLists.txt @@ -112,7 +112,6 @@ ob_set_subtarget(ob_server omt omt/ob_th_worker.cpp omt/ob_worker_processor.cpp omt/ob_multi_tenant_operator.cpp - omt/ob_tenant_hook.cpp omt/ob_tenant_srs_mgr.cpp omt/ob_tenant_srs.cpp ) diff --git a/src/share/schema/ob_multi_version_schema_service.cpp b/src/share/schema/ob_multi_version_schema_service.cpp index 2dc9beb5e..77e495106 100644 --- a/src/share/schema/ob_multi_version_schema_service.cpp +++ b/src/share/schema/ob_multi_version_schema_service.cpp @@ -153,7 +153,7 @@ void ObSchemaConstructTask::wait(const int64_t version) } int rc = 0; do { - rc = pthread_cond_timedwait(&schema_cond_, &schema_mutex_, &ts); + rc = ob_pthread_cond_timedwait(&schema_cond_, &schema_mutex_, &ts); } while (0); (void) rc; // make compiler happy } -- GitLab