diff --git a/deps/oblib/src/common/ob_clock_generator.cpp b/deps/oblib/src/common/ob_clock_generator.cpp index b65a45961c..04aa86068e 100644 --- a/deps/oblib/src/common/ob_clock_generator.cpp +++ b/deps/oblib/src/common/ob_clock_generator.cpp @@ -13,8 +13,8 @@ #include "common/ob_clock_generator.h" #include "lib/oblog/ob_log.h" #include "lib/atomic/ob_atomic.h" -#include "lib/lock/Monitor.h" -#include "lib/lock/Mutex.h" +#include "lib/lock/ob_monitor.h" +#include "lib/lock/mutex.h" #include "lib/time/ob_time_utility.h" #include "lib/coro/routine.h" #include "lib/thread/ob_thread_name.h" diff --git a/deps/oblib/src/common/ob_clock_generator.h b/deps/oblib/src/common/ob_clock_generator.h index e4fb6e9ba1..6939b1e762 100644 --- a/deps/oblib/src/common/ob_clock_generator.h +++ b/deps/oblib/src/common/ob_clock_generator.h @@ -18,8 +18,8 @@ #include "lib/ob_define.h" #include "lib/oblog/ob_log.h" #include "lib/atomic/ob_atomic.h" -#include "lib/lock/Monitor.h" -#include "lib/lock/Mutex.h" +#include "lib/lock/ob_monitor.h" +#include "lib/lock/mutex.h" #include "lib/time/ob_time_utility.h" #include "lib/thread/thread_pool.h" @@ -98,16 +98,16 @@ inline int64_t ObClockGenerator::getCurrentTime() inline void ObClockGenerator::msleep(const int64_t ms) { if (ms > 0) { - tbutil::Monitor monitor_; - (void)monitor_.timedWait(tbutil::Time(ms * 1000)); + obutil::ObMonitor monitor_; + (void)monitor_.timed_wait(obutil::ObSysTime(ms * 1000)); } } inline void ObClockGenerator::usleep(const int64_t us) { if (us > 0) { - tbutil::Monitor monitor_; - (void)monitor_.timedWait(tbutil::Time(us)); + obutil::ObMonitor monitor_; + (void)monitor_.timed_wait(obutil::ObSysTime(us)); } } diff --git a/deps/oblib/src/lib/CMakeLists.txt b/deps/oblib/src/lib/CMakeLists.txt index 49f49144bc..fb95aec563 100644 --- a/deps/oblib/src/lib/CMakeLists.txt +++ b/deps/oblib/src/lib/CMakeLists.txt @@ -86,7 +86,6 @@ ob_set_subtarget(oblib_lib common ec/ob_erasure_code_table_cache.cpp encrypt/ob_encrypted_helper.cpp file/file_directory_utils.cpp - file/fileutil.cpp file/ob_file.cpp hash_func/murmur_hash.cpp hash/ob_concurrent_hash_map.cpp @@ -106,13 +105,12 @@ ob_set_subtarget(oblib_lib common json_type/ob_json_bin.cpp json_type/ob_json_base.cpp json_type/ob_json_parse.cpp - lock/Cond.cpp - lock/Mutex.cpp + lock/cond.cpp + lock/mutex.cpp lock/ob_bucket_lock.cpp lock/ob_latch.cpp lock/ob_thread_cond.cpp - lock/RecMutex.cpp - lock/tbrwlock.cpp + lock/ob_rwlock.cpp metrics/ob_meter.cpp mysqlclient/ob_isql_client.cpp mysqlclient/ob_mysql_connection.cpp @@ -130,7 +128,7 @@ ob_set_subtarget(oblib_lib common mysqlclient/ob_single_connection_proxy.cpp mysqlclient/ob_single_mysql_connection_pool.cpp net/ob_addr.cpp - net/tbnetutil.cpp + net/ob_net_util.cpp number/ob_number_v2.cpp ob_date_unit_type.cpp ob_abort.cpp @@ -250,8 +248,8 @@ ob_lib_add_pchs(lib coro/co_var.h time/Time.h time/tbtimeutil.h - net/tbnetutil.h - lock/tbrwlock.h + net/ob_net_util.h + lock/ob_rwlock.h thread/runnable.h ob_define.h ob_cxa_guard.h @@ -383,10 +381,10 @@ ob_lib_add_pchs(lib timezone/ob_timezone_info.h rowid/ob_urowid.h charset/ob_dtoa.h - lock/Lock.h - lock/Mutex.h - lock/Cond.h - lock/Monitor.h + lock/ob_lock.h + lock/mutex.h + lock/cond.h + lock/ob_monitor.h task/ob_timer.h list/ob_list.h container/ob_bit_set.h diff --git a/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp b/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp index ea5216c23b..29f220ffeb 100644 --- a/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp +++ b/deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp @@ -72,7 +72,7 @@ void* ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAt LOG_ERROR("invalid argument", K(lbt()), K(inner_attr.tenant_id_), K(ret)); } else if (OB_UNLIKELY(inner_attr.tenant_id_ >= PRESERVED_TENANT_COUNT)) { const int64_t slot = inner_attr.tenant_id_ % PRESERVED_TENANT_COUNT; - obsys::CRLockGuard guard(locks_[slot]); + obsys::ObRLockGuard guard(locks_[slot]); allocator = get_tenant_ctx_allocator(inner_attr.tenant_id_, inner_attr.ctx_id_); if (!OB_ISNULL(allocator)) { ptr = allocator->alloc(size, inner_attr); @@ -90,7 +90,7 @@ void* ObMallocAllocator::alloc(const int64_t size, const oceanbase::lib::ObMemAt } else { if (OB_UNLIKELY(inner_attr.tenant_id_ >= PRESERVED_TENANT_COUNT)) { const int64_t slot = inner_attr.tenant_id_ % PRESERVED_TENANT_COUNT; - obsys::CRLockGuard guard(locks_[slot]); + obsys::ObRLockGuard guard(locks_[slot]); allocator = get_tenant_ctx_allocator(inner_attr.tenant_id_, inner_attr.ctx_id_); if (NULL != allocator) { ptr = allocator->alloc(size, inner_attr); @@ -139,7 +139,7 @@ void* ObMallocAllocator::realloc(const void* ptr, const int64_t size, const ocea // do nothing } else if (OB_UNLIKELY(inner_attr.tenant_id_ >= PRESERVED_TENANT_COUNT)) { const int64_t slot = inner_attr.tenant_id_ % PRESERVED_TENANT_COUNT; - obsys::CRLockGuard guard(locks_[slot]); + obsys::ObRLockGuard guard(locks_[slot]); ObIAllocator* allocator = get_tenant_ctx_allocator(inner_attr.tenant_id_, inner_attr.ctx_id_); if (NULL != allocator) { nptr = allocator->realloc(ptr, size, inner_attr); @@ -258,7 +258,7 @@ int ObMallocAllocator::create_tenant_ctx_allocator(uint64_t tenant_id, uint64_t ret = create_tenant_ctx_allocator(slot, ctx_id); } if (OB_SUCC(ret)) { - obsys::CWLockGuard guard(locks_[slot]); + obsys::ObWLockGuard guard(locks_[slot]); ObTenantCtxAllocator** cur = &allocators_[slot][ctx_id]; while ((NULL != *cur) && (*cur)->get_tenant_id() < tenant_id) { cur = &((*cur)->get_next()); @@ -406,7 +406,7 @@ int64_t ObMallocAllocator::get_tenant_ctx_hold(const uint64_t tenant_id, const u int64_t hold = 0; if (OB_UNLIKELY(tenant_id >= PRESERVED_TENANT_COUNT)) { const int64_t slot = tenant_id % PRESERVED_TENANT_COUNT; - obsys::CRLockGuard guard(locks_[slot]); + obsys::ObRLockGuard guard(locks_[slot]); ObTenantCtxAllocator* allocator = get_tenant_ctx_allocator(tenant_id, ctx_id); if (!OB_ISNULL(allocator)) { hold = allocator->get_hold(); @@ -425,7 +425,7 @@ void ObMallocAllocator::get_tenant_mod_usage(uint64_t tenant_id, int mod_id, ObM ObTenantCtxAllocator* allocator = NULL; if (OB_UNLIKELY(tenant_id >= PRESERVED_TENANT_COUNT)) { const int64_t slot = tenant_id % PRESERVED_TENANT_COUNT; - obsys::CRLockGuard guard(locks_[slot]); + obsys::ObRLockGuard guard(locks_[slot]); for (int64_t i = 0; i < ObCtxIds::MAX_CTX_ID; i++) { allocator = get_tenant_ctx_allocator(tenant_id, i); if (!OB_ISNULL(allocator)) { @@ -546,7 +546,7 @@ int ObMallocAllocator::get_chunks(AChunk** chunks, int cap, int& cnt) { int ret = OB_SUCCESS; for (int64_t slot = 0; OB_SUCC(ret) && slot < PRESERVED_TENANT_COUNT; ++slot) { - obsys::CRLockGuard guard(locks_[slot]); + obsys::ObRLockGuard guard(locks_[slot]); for (int64_t ctx_id = 0; OB_SUCC(ret) && ctx_id < ObCtxIds::MAX_CTX_ID; ctx_id++) { ObTenantCtxAllocator* ta = allocators_[slot][ctx_id]; while (OB_SUCC(ret) && ta != nullptr) { diff --git a/deps/oblib/src/lib/alloc/ob_malloc_allocator.h b/deps/oblib/src/lib/alloc/ob_malloc_allocator.h index fe6a5a9e9f..9b2e518b8f 100644 --- a/deps/oblib/src/lib/alloc/ob_malloc_allocator.h +++ b/deps/oblib/src/lib/alloc/ob_malloc_allocator.h @@ -16,7 +16,7 @@ #include "lib/allocator/ob_allocator.h" #include "lib/alloc/ob_tenant_ctx_allocator.h" #include "lib/alloc/alloc_func.h" -#include "lib/lock/tbrwlock.h" +#include "lib/lock/ob_rwlock.h" namespace oceanbase { namespace lib { @@ -76,7 +76,7 @@ private: DISALLOW_COPY_AND_ASSIGN(ObMallocAllocator); private: - obsys::CRWLock locks_[PRESERVED_TENANT_COUNT]; + obsys::ObRWLock locks_[PRESERVED_TENANT_COUNT]; ObTenantCtxAllocator* allocators_[PRESERVED_TENANT_COUNT][common::ObCtxIds::MAX_CTX_ID]; int64_t reserved_; int64_t urgent_; diff --git a/deps/oblib/src/lib/file/fileutil.cpp b/deps/oblib/src/lib/file/fileutil.cpp deleted file mode 100644 index a32bbeab89..0000000000 --- a/deps/oblib/src/lib/file/fileutil.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#include "lib/file/fileutil.h" -namespace oceanbase { -namespace obsys { -bool CFileUtil::mkdirs(char* szDirPath) -{ - struct stat stats; - if (stat(szDirPath, &stats) == 0 && S_ISDIR(stats.st_mode)) - return true; - - mode_t umask_value = umask(0); - umask(umask_value); - mode_t mode = (S_IRWXUGO & (~umask_value)) | S_IWUSR | S_IXUSR; - - char* slash = szDirPath; - while (*slash == '/') - slash++; - - while (1) { - slash = strchr(slash, '/'); - if (slash == NULL) - break; - - *slash = '\0'; - int ret = mkdir(szDirPath, mode); - *slash++ = '/'; - if (0 != ret && errno != EEXIST) { - return false; - } - - while (*slash == '/') - slash++; - } - if (0 != mkdir(szDirPath, mode)) { - return false; - } - return true; -} - -// Is it a directory -bool CFileUtil::isDirectory(const char* szDirPath) -{ - struct stat stats; - if (lstat(szDirPath, &stats) == 0 && S_ISDIR(stats.st_mode)) - return true; - return false; -} - -// Is islnk -bool CFileUtil::isSymLink(const char* szDirPath) -{ - struct stat stats; - if (lstat(szDirPath, &stats) == 0 && S_ISLNK(stats.st_mode)) - return true; - return false; -} -} // namespace obsys -} // namespace oceanbase - -//////////////////END diff --git a/deps/oblib/src/lib/file/ob_string_util.cpp b/deps/oblib/src/lib/file/ob_string_util.cpp new file mode 100644 index 0000000000..84870ee4b2 --- /dev/null +++ b/deps/oblib/src/lib/file/ob_string_util.cpp @@ -0,0 +1,106 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ +#include "lib/file/ob_string_util.h" + +namespace obsys { + + bool ObStringUtil::is_int(const char *p) { + if (NULL == p || (*p) == '\0') { + return false; + } + if ((*p) == '-') p++; + while((*p)) { + if ((*p) < '0' || (*p) > '9') return false; + p++; + } + return true; + } + + int ObStringUtil::str_to_int(const char *str, int d) + { + if (is_int(str)) { + return atoi(str); + } else { + return d; + } + } + + char *ObStringUtil::str_to_lower(char *pszBuf) + { + if (NULL == pszBuf) { + return pszBuf; + } + + char *p = pszBuf; + while (*p) { + if (((*p) & 0x80) != 0) { + p++; + } else if ((*p) >= 'A' && (*p) <= 'Z') { + (*p) = static_cast((*p)+32); + } + p++; + } + return pszBuf; + } + + char *ObStringUtil::str_to_upper(char *pszBuf) + { + if (NULL == pszBuf) { + return pszBuf; + } + + char *p = pszBuf; + while (*p) { + if (((*p) & 0x80) != 0) { + p++; + } else if ((*p) >= 'a' && (*p) <= 'z') { + (*p) = static_cast((*p) - 32); + } + p++; + } + return pszBuf; + } + + void ObStringUtil::split(char *str, const char *delim, std::vector &list) + { + if (NULL == str) { + return; + } + + if (NULL == delim) { + list.push_back(str); + return; + } + + char *s; + const char *spanp; + + s = str; + while(*s) + { + spanp = delim; + while(*spanp) { + if (*s == *spanp) { + list.push_back(str); + *s = '\0'; + str = s+1; + break; + } + spanp ++; + } + s ++; + } + if (0 != *str) { + list.push_back(str); + } + } +} diff --git a/deps/oblib/src/lib/file/fileutil.h b/deps/oblib/src/lib/file/ob_string_util.h similarity index 55% rename from deps/oblib/src/lib/file/fileutil.h rename to deps/oblib/src/lib/file/ob_string_util.h index 1b5d004c7e..f474ed0400 100644 --- a/deps/oblib/src/lib/file/fileutil.h +++ b/deps/oblib/src/lib/file/ob_string_util.h @@ -9,35 +9,27 @@ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PubL v2 for more details. */ - -#ifndef TBSYS_FILE_UTIL_H -#define TBSYS_FILE_UTIL_H +#ifndef OCEANBASE_OB_STRING_UTIL_H_ +#define OCEANBASE_OB_STRING_UTIL_H_ #include -#include #include -#include -#include +#include +#include +#include +#include -namespace oceanbase { namespace obsys { -#ifndef S_IRWXUGO -#define S_IRWXUGO (S_IRWXU | S_IRWXG | S_IRWXO) -#endif - -class CFileUtil { +class ObStringUtil { public: - /** Create a multi-level directory */ - static bool mkdirs(char* szDirPath); - /** Is it a directory */ - static bool isDirectory(const char* szDirPath); - /** Is it a SymLink file */ - static bool isSymLink(const char* szDirPath); + static int str_to_int(const char *str, int d); + static bool is_int(const char *p); + static char *str_to_lower(char *str); + static char *str_to_upper(char *str); + static void split(char *str, const char *delim, std::vector &list); }; -} // namespace obsys -} // namespace oceanbase + +} #endif - -//////////////////END diff --git a/deps/oblib/src/lib/lock/Cond.h b/deps/oblib/src/lib/lock/Cond.h deleted file mode 100644 index 5e3bd41985..0000000000 --- a/deps/oblib/src/lib/lock/Cond.h +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#ifndef TBSYS_COND_H -#define TBSYS_COND_H -#include "lib/time/Time.h" -#include "lib/ob_define.h" -#include "lib/oblog/ob_log.h" -namespace tbutil { -template -class Monitor; -class Mutex; -class RecMutex; -/** - * @brief Condition variable of linux-thread - */ -class Cond { -public: - Cond(); - ~Cond(); - - /** - * @brief Signal to thread - */ - void signal(); - - /** - * @brief Broadcast to thread - */ - void broadcast(); - - /** - * @brief Thread blocking waiting - * - * @param lock - * - * @return - */ - template - inline bool wait(const Lock& lock) const - { - if (!lock.acquired()) { - _OB_LOG(ERROR, "%s", "ThreadLockedException"); - return false; - } - return waitImpl(lock._mutex); - } - - /** - * @brief Thread blocking waiting with timeout - * - * @param lock - * @param timeout - * - * @return - */ - template - inline bool timedWait(const Lock& lock, const Time& timeout) const - { - if (!lock.acquired()) { - _OB_LOG(ERROR, "%s", "ThreadLockedException"); - return false; - } - return timedWaitImpl(lock._mutex, timeout); - } - -private: - DISALLOW_COPY_AND_ASSIGN(Cond); - -private: - friend class Monitor; - friend class Monitor; - - template - bool waitImpl(const M&) const; - template - bool timedWaitImpl(const M&, const Time&) const; - - mutable pthread_cond_t _cond; -}; - -template -inline bool Cond::waitImpl(const M& mutex) const -{ - typedef typename M::LockState LockState; - - LockState state; - mutex.unlock(state); - const int rc = pthread_cond_wait(&_cond, state.mutex); - mutex.lock(state); - - if (0 != rc) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - return false; - } - return true; -} - -template -inline bool Cond::timedWaitImpl(const M& mutex, const Time& timeout) const -{ - if (timeout < Time::microSeconds(0)) { - _OB_LOG(ERROR, "%s", "InvalidTimeoutException"); - return false; - } - - typedef typename M::LockState LockState; - - LockState state; - mutex.unlock(state); - - timeval tv = Time::now(Time::Realtime) + timeout; - timespec ts; - ts.tv_sec = tv.tv_sec; - ts.tv_nsec = tv.tv_usec * 1000; - /*timeval tv = Time::now(Time::Realtime); - 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); - mutex.lock(state); - - if (rc != 0) { - if (rc != ETIMEDOUT) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - return false; - } - } - return true; -} -} // namespace tbutil -#endif diff --git a/deps/oblib/src/lib/lock/Lock.h b/deps/oblib/src/lib/lock/Lock.h deleted file mode 100644 index 635a267faf..0000000000 --- a/deps/oblib/src/lib/lock/Lock.h +++ /dev/null @@ -1,111 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#ifndef TBSYS_LOCK_H -#define TBSYS_LOCK_H -#include -namespace tbutil { -/** - * @brief LockT is a simple template, composed of constructor and destructor - * Constructor calls lock for its parameters, destructor calls unlock - * By instantiating a local variable of type Lock, the deadlock problem can be completely solved - */ -template -class LockT { -public: - explicit LockT(const T& mutex) : _mutex(mutex) - { - _mutex.lock(); - _acquired = true; - } - - ~LockT() - { - if (_acquired) { - _mutex.unlock(); - } - } - - void acquire() const - { - if (_acquired) { -#ifdef _NO_EXCEPTION - assert(!"ThreadLockedException"); -#else - throw ThreadLockedException(__FILE__, __LINE__); -#endif - } - _mutex.lock(); - _acquired = true; - } - - bool tryAcquire() const - { - if (_acquired) { -#ifdef _NO_EXCEPTION - assert(!"ThreadLockedException"); -#else - throw ThreadLockedException(__FILE__, __LINE__); -#endif - } - _acquired = _mutex.tryLock(); - return _acquired; - } - - void release() const - { - if (!_acquired) { -#ifdef _NO_EXCEPTION - assert(!"ThreadLockedException"); -#else - throw ThreadLockedException(__FILE__, __LINE__); -#endif - } - _mutex.unlock(); - _acquired = false; - } - - bool acquired() const - { - return _acquired; - } - -protected: - LockT(const T& mutex, bool) : _mutex(mutex) - { - _acquired = _mutex.tryLock(); - } - -private: - LockT(const LockT&); - LockT& operator=(const LockT&); - - const T& _mutex; - mutable bool _acquired; - - friend class Cond; -}; - -/** - * @brief TryLockT is a simple template, composed of constructor and destructor - * Constructor calls lock for its parameters, destructor calls unlock - * By instantiating a local variable of type TryLock, the deadlock problem can be completely solved - */ -template -class TryLockT : public LockT { -public: - TryLockT(const T& mutex) : LockT(mutex, true) - {} -}; -} // namespace tbutil - -#endif diff --git a/deps/oblib/src/lib/lock/Monitor.h b/deps/oblib/src/lib/lock/Monitor.h deleted file mode 100644 index a8988f9560..0000000000 --- a/deps/oblib/src/lib/lock/Monitor.h +++ /dev/null @@ -1,207 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#ifndef TBSYS_MONITOR_H -#define TBSYS_MONITOR_H -#include "lib/lock/Lock.h" -#include "lib/lock/Cond.h" - -// using namespace std; - -namespace tbutil { -/** - * @brief The monitor is a template class, which requires Mutex or RecMutex as template parameters. - * The monitor is a synchronization mechanism used to protect the critical section. - * Like a mutex, only one thread can be active in the critical section. - * - * The monitor allows you to suspend threads in the critical section, - * so that another thread can enter the critical section, - * the second thread can exit the critical section, or suspend itself in the critical section, - * no matter what the original thread will be Wake up and continue to perform the original task - */ -template -class Monitor { -public: - typedef LockT > Lock; - typedef TryLockT > TryLock; - - Monitor(); - ~Monitor(); - - /** - * @brief This function attempts to lock the monitor. If the monitor is locked by another thread, - * the calling thread will be suspended until the monitor is available. When the call returns, the monitor has been - * locked by it - */ - void lock() const; - /** - * @brief This function unlocks the monitor. If there are other threads waiting to enter the monitor - * (that is, blocked in the lock call), one of the threads will be awakened and the monitor will be locked - * - * @return - */ - void unlock() const; - /** - * @brief This function attempts to lock the monitor. If the monitor is available, - * the call will lock the monitor and return true. If the monitor has been locked by another thread, the call returns - * false - */ - bool tryLock() const; - - /** - * @brief This function suspends the calling thread and releases the lock on the monitor at the same time. - * Other threads may call notify or notifyAll to wake up the thread that was suspended in the wait call. - * When the wait call returns, the monitor is locked again, and the suspended thread will resume execution - * @return - */ - bool wait() const; - /** - * @brief This function suspends the thread that called it until the specified time has elapsed. - * If another thread calls notify or notifyAll to wake up the suspended thread before the timeout occurs,this call - * returns true, the monitor is locked again, and the suspended thread resumes execution. If a timeout occurs, the - * function returns false - * @param Time - * - * @return - */ - bool timedWait(const Time&) const; - /** - * @brief This function wakes up a thread currently suspended in the wait call. - * If there is no such thread when notify is called, the notification will be lost - * (that is, if no thread can be awakened, the call to notify will not be remembered) - */ - void notify(); - /** - * @brief This function wakes up all threads currently suspended in the wait call. - * Like notify, if there are no suspended threads at this time, the call to notifyAll will be lost - */ - void notifyAll(); - -private: - Monitor(const Monitor&); - Monitor& operator=(const Monitor&); - - void notifyImpl(int) const; - - mutable Cond _cond; - T _mutex; - mutable int _nnotify; -}; - -template -Monitor::Monitor() : _nnotify(0) -{} - -template -Monitor::~Monitor() -{} - -template -inline void Monitor::lock() const -{ - _mutex.lock(); - if (_mutex.willUnlock()) { - _nnotify = 0; - } -} - -template -inline void Monitor::unlock() const -{ - if (_mutex.willUnlock()) { - notifyImpl(_nnotify); - } - _mutex.unlock(); -} - -template -inline bool Monitor::tryLock() const -{ - bool result = _mutex.tryLock(); - if (result && _mutex.willUnlock()) { - _nnotify = 0; - } - return result; -} - -template -inline bool Monitor::wait() const -{ - notifyImpl(_nnotify); -#ifdef _NO_EXCEPTION - const bool bRet = _cond.waitImpl(_mutex); - _nnotify = 0; - return bRet; -#else - try { - _cond.waitImpl(_mutex); - } catch (...) { - _nnotify = 0; - throw; - } - - _nnotify = 0; -#endif - return true; -} - -template -inline bool Monitor::timedWait(const Time& timeout) const -{ - notifyImpl(_nnotify); -#ifdef _NO_EXCEPTION - const bool rc = _cond.timedWaitImpl(_mutex, timeout); - _nnotify = 0; - return rc; -#else - try { - _cond.timedWaitImpl(_mutex, timeout); - } catch (...) { - _nnotify = 0; - throw; - } - _nnotify = 0; -#endif - return true; -} - -template -inline void Monitor::notify() -{ - if (_nnotify != -1) { - ++_nnotify; - } -} - -template -inline void Monitor::notifyAll() -{ - _nnotify = -1; -} - -template -inline void Monitor::notifyImpl(int nnotify) const -{ - if (nnotify != 0) { - if (nnotify == -1) { - _cond.broadcast(); - return; - } else { - while (nnotify > 0) { - _cond.signal(); - --nnotify; - } - } - } -} -} // namespace tbutil -#endif diff --git a/deps/oblib/src/lib/lock/Mutex.h b/deps/oblib/src/lib/lock/Mutex.h deleted file mode 100644 index 7d13b652bb..0000000000 --- a/deps/oblib/src/lib/lock/Mutex.h +++ /dev/null @@ -1,77 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#ifndef TBSYS_MUTEX_H -#define TBSYS_MUTEX_H - -#include -#include "lib/lock/Lock.h" - -namespace tbutil { -/** -@brief Mutex, implemented as a simple data structure -Mutex non-recursive lock, you need to pay attention to the following points when using: -1.Do not call lock a second time in the same thread -2.Unless the calling thread holds a certain mutex, do not call unlock for the mutex -*/ -class Mutex { -public: - typedef LockT Lock; - typedef TryLockT TryLock; - - Mutex(); - ~Mutex(); - - /** - * @brief The lock function attempts to acquire the mutex. - * If the mutex is locked, it will suspend the calling thread until the mutex becomes available. - * Once the calling thread obtains the mutex, the call returns immediately - */ - void lock() const; - - /** - * @brief The tryLock function attempts to acquire the mutex. - * If the mutex is available, the mutex will be locked, and the call will return true. - * If other threads lock the mutex, the call returns false - * - * @return - */ - bool tryLock() const; - - /** - * @brief The unlock function unlocks the mutex - */ - void unlock() const; - - /** - * @brief Whether it has been locked - * - * @return - */ - bool willUnlock() const; - -private: - Mutex(const Mutex&); - Mutex& operator=(const Mutex&); - - struct LockState { - pthread_mutex_t* mutex; - }; - - void unlock(LockState&) const; - void lock(LockState&) const; - mutable pthread_mutex_t _mutex; - - friend class Cond; -}; -} // namespace tbutil -#endif diff --git a/deps/oblib/src/lib/lock/RecMutex.cpp b/deps/oblib/src/lib/lock/RecMutex.cpp deleted file mode 100644 index 68e2c8af6f..0000000000 --- a/deps/oblib/src/lib/lock/RecMutex.cpp +++ /dev/null @@ -1,132 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#include "lib/lock/RecMutex.h" -#include "lib/oblog/ob_log.h" -namespace tbutil { -RecMutex::RecMutex() : _count(0) -{ - pthread_mutexattr_t attr; - int rt = pthread_mutexattr_init(&attr); -#ifdef _NO_EXCEPTION - assert(0 == rt); - if (rt != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - } -#else - if (0 != rt) { - throw ThreadSyscallException(__FILE__, __LINE__, rt); - } -#endif - rt = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); -#ifdef _NO_EXCEPTION - assert(0 == rt); - if (rt != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - } -#else - if (0 != rt) { - throw ThreadSyscallException(__FILE__, __LINE__, rt); - } -#endif - rt = pthread_mutex_init(&_mutex, &attr); -#ifdef _NO_EXCEPTION - assert(0 == rt); - if (rt != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - } -#else - if (0 != rt) { - throw ThreadSyscallException(__FILE__, __LINE__, rt); - } -#endif - - rt = pthread_mutexattr_destroy(&attr); -#ifdef _NO_EXCEPTION - assert(0 == rt); - if (rt != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - } -#else - if (0 != rt) { - throw ThreadSyscallException(__FILE__, __LINE__, rt); - } -#endif -} - -RecMutex::~RecMutex() -{ - assert(_count == 0); - const int rc = pthread_mutex_destroy(&_mutex); - assert(rc == 0); - if (rc != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - } -} - -void RecMutex::lock() const -{ - const int rt = pthread_mutex_lock(&_mutex); - if (rt != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - } else { - if (++_count > 1) { - const int rc = pthread_mutex_unlock(&_mutex); - if (rc != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - } - } - } -} - -bool RecMutex::tryLock() const -{ - const int rc = pthread_mutex_trylock(&_mutex); - const bool result = (rc == 0); - if (!result) { - assert(EBUSY == rc); - } else if (++_count > 1) { - const int rt = pthread_mutex_unlock(&_mutex); - if (rt != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - } - } - return result; -} - -void RecMutex::unlock() const -{ - if (--_count == 0) { - const int rc = pthread_mutex_unlock(&_mutex); - if (rc != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); - } - } -} - -void RecMutex::unlock(LockState& state) const -{ - state.mutex = &_mutex; - state.count = _count; - _count = 0; -} - -void RecMutex::lock(LockState& state) const -{ - _count = state.count; -} - -bool RecMutex::willUnlock() const -{ - return _count == 1; -} -} // namespace tbutil diff --git a/deps/oblib/src/lib/lock/RecMutex.h b/deps/oblib/src/lib/lock/RecMutex.h deleted file mode 100644 index 255bbda072..0000000000 --- a/deps/oblib/src/lib/lock/RecMutex.h +++ /dev/null @@ -1,80 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#ifndef TBSYS_RMUTEX_H -#define TBSYS_RMUTEX_H -#include "lib/lock/Lock.h" -#include -namespace tbutil { -class Cond; -/** - * @brief RecMutex implements recursive mutex - * The use of non-recursive mutexes is the same. When using recursive mutexes, you must follow some simple rules: - * 1.Unless the calling thread holds the lock, do not call unlock for a mutex - * 2.In order for the mutex to be acquired by other threads, - * the number of times you call unlock must be the same as the number of times you call lock - * (in the internal implementation of recursive mutex, there is a counter initialized to zero. - * Every time lock is called, the counter is It will increase by one, and each time unlock is called, - * the counter will decrease by one; when the counter returns to zero, another thread can acquire the mutex) - */ -class RecMutex { -public: - typedef LockT Lock; - typedef TryLockT TryLock; - - RecMutex(); - ~RecMutex(); - - /** - * @brief The lock function attempts to acquire the mutex. - * If the mutex is locked by another thread, it will suspend the calling thread until the mutex becomes available. - * If the mutex is available or has been locked by the calling thread, the call will lock the mutex and return - * immediately - */ - void lock() const; - - /** - * @brief The function of tryLock is similar to lock, but if the mutex has been locked by another thread, - * it will not block the caller, but will return false. - * Otherwise the return value is true - * @return - */ - bool tryLock() const; - - /** - * @brief The unlock function unlocks the mutex - */ - void unlock() const; - - bool willUnlock() const; - -private: - // noncopyable - RecMutex(const RecMutex&); - RecMutex& operator=(const RecMutex&); - - struct LockState { - pthread_mutex_t* mutex; - int count; - }; - - void unlock(LockState&) const; - void lock(LockState&) const; - - friend class Cond; - - mutable pthread_mutex_t _mutex; - - mutable int _count; -}; -} // namespace tbutil -#endif diff --git a/deps/oblib/src/lib/lock/Cond.cpp b/deps/oblib/src/lib/lock/cond.cpp similarity index 94% rename from deps/oblib/src/lib/lock/Cond.cpp rename to deps/oblib/src/lib/lock/cond.cpp index d0c38a1a68..840b61b7d5 100644 --- a/deps/oblib/src/lib/lock/Cond.cpp +++ b/deps/oblib/src/lib/lock/cond.cpp @@ -11,9 +11,9 @@ */ #include -#include "lib/lock/Cond.h" +#include "lib/lock/cond.h" #include "lib/oblog/ob_log.h" -namespace tbutil { +namespace obutil { Cond::Cond() { int rt = pthread_cond_init(&_cond, NULL); @@ -45,4 +45,4 @@ void Cond::broadcast() _OB_LOG(WARN, "Failed to broadcast condition, err=%d", rt); } } -} // end namespace tbutil +} //end namespace obutil diff --git a/deps/oblib/src/lib/lock/cond.h b/deps/oblib/src/lib/lock/cond.h new file mode 100644 index 0000000000..19728fbdc2 --- /dev/null +++ b/deps/oblib/src/lib/lock/cond.h @@ -0,0 +1,120 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ +#ifndef COND_H +#define COND_H +#include "lib/time/Time.h" +#include "lib/ob_define.h" +#include "lib/oblog/ob_log.h" +namespace obutil +{ +template class ObMonitor; +class Mutex; + +class Cond +{ +public: + + Cond(); + ~Cond(); + + void signal(); + void broadcast(); + template inline bool + wait(const Lock& lock) const + { + bool ret = false; + if (!lock.acquired()) { + _OB_LOG(ERROR,"%s","ThreadLockedException"); + ret = false; + } else { + ret = wait_impl(lock._mutex); + } + return ret; + } + + template inline bool + timed_wait(const Lock& lock, const ObSysTime& timeout) const + { + bool ret = false; + if (!lock.acquired()) { + _OB_LOG(ERROR,"%s","ThreadLockedException"); + ret = false; + } else { + ret = timed_wait_impl(lock._mutex, timeout); + } + return ret; + } +private: + DISALLOW_COPY_AND_ASSIGN(Cond); +private: + + friend class ObMonitor; + + template bool wait_impl(const M&) const; + template bool timed_wait_impl(const M&, const ObSysTime&) const; + + mutable pthread_cond_t _cond; +}; + +template inline bool +Cond::wait_impl(const M& mutex) const +{ + bool ret = true; + typedef typename M::LockState LockState; + + LockState state; + mutex.unlock(state); + const int rc = pthread_cond_wait(&_cond, state.mutex); + mutex.lock(state); + + if ( 0 != rc ) { + _OB_LOG(ERROR,"%s","ThreadSyscallException"); + ret = false; + } + return ret; +} + +template inline bool +Cond::timed_wait_impl(const M& mutex, const ObSysTime& timeout) const +{ + bool ret = true; + if (timeout < ObSysTime::microSeconds(0)) { + _OB_LOG(ERROR,"%s","InvalidTimeoutException"); + ret = false; + } else { + typedef typename M::LockState LockState; + + LockState state; + mutex.unlock(state); + + timeval tv = ObSysTime::now(ObSysTime::Realtime) + timeout; + timespec ts; + ts.tv_sec = tv.tv_sec; + ts.tv_nsec = tv.tv_usec * 1000; + /*timeval tv = ObSysTime::now(ObSysTime::Realtime); + 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); + mutex.lock(state); + + if (rc != 0) { + if ( rc != ETIMEDOUT ) { + _OB_LOG(ERROR,"%s","ThreadSyscallException"); + ret = false; + } + } + } + return ret; +} +}// end namespace +#endif diff --git a/deps/oblib/src/lib/lock/Mutex.cpp b/deps/oblib/src/lib/lock/mutex.cpp similarity index 66% rename from deps/oblib/src/lib/lock/Mutex.cpp rename to deps/oblib/src/lib/lock/mutex.cpp index 7010b597f3..b2d6d13381 100644 --- a/deps/oblib/src/lib/lock/Mutex.cpp +++ b/deps/oblib/src/lib/lock/mutex.cpp @@ -9,20 +9,20 @@ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PubL v2 for more details. */ - -#include "lib/lock/Mutex.h" +#include "lib/lock/mutex.h" #include "lib/oblog/ob_log.h" -namespace tbutil { +namespace obutil +{ Mutex::Mutex() { const int rt = pthread_mutex_init(&_mutex, NULL); #ifdef _NO_EXCEPTION - assert(rt == 0); - if (rt != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); + assert( rt == 0 ); + if ( rt != 0 ) { + _OB_LOG(ERROR,"%s","ThreadSyscallException"); } #else - if (rt != 0) { + if ( rt != 0 ) { throw ThreadSyscallException(__FILE__, __LINE__, rt); } #endif @@ -32,8 +32,8 @@ Mutex::~Mutex() { const int rt = pthread_mutex_destroy(&_mutex); assert(rt == 0); - if (rt != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); + if ( rt != 0 ) { + _OB_LOG(ERROR,"%s","ThreadSyscallException"); } } @@ -41,17 +41,17 @@ void Mutex::lock() const { const int rt = pthread_mutex_lock(&_mutex); #ifdef _NO_EXCEPTION - assert(rt == 0); - if (rt != 0) { - if (rt == EDEADLK) { - _OB_LOG(ERROR, "%s", "ThreadLockedException "); + assert( rt == 0 ); + if ( rt != 0 ) { + if ( rt == EDEADLK ) { + _OB_LOG(ERROR,"%s","ThreadLockedException "); } else { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); + _OB_LOG(ERROR,"%s","ThreadSyscallException"); } } #else - if (rt != 0) { - if (rt == EDEADLK) { + if( rt != 0 ) { + if(rt == EDEADLK) { throw ThreadLockedException(__FILE__, __LINE__); } else { throw ThreadSyscallException(__FILE__, __LINE__, rt); @@ -60,21 +60,21 @@ void Mutex::lock() const #endif } -bool Mutex::tryLock() const +bool Mutex::trylock() const { const int rt = pthread_mutex_trylock(&_mutex); #ifdef _NO_EXCEPTION - if (rt != 0 && rt != EBUSY) { - if (rt == EDEADLK) { - _OB_LOG(ERROR, "%s", "ThreadLockedException "); + if ( rt != 0 && rt !=EBUSY ) { + if ( rt == EDEADLK ) { + _OB_LOG(ERROR,"%s","ThreadLockedException "); } else { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); + _OB_LOG(ERROR,"%s","ThreadSyscallException"); } return false; } #else - if (rt != 0 && rt != EBUSY) { - if (rt == EDEADLK) { + if(rt != 0 && rt != EBUSY) { + if(rt == EDEADLK) { throw ThreadLockedException(__FILE__, __LINE__); } else { throw ThreadSyscallException(__FILE__, __LINE__, rt); @@ -88,12 +88,12 @@ void Mutex::unlock() const { const int rt = pthread_mutex_unlock(&_mutex); #ifdef _NO_EXCEPTION - assert(rt == 0); - if (rt != 0) { - _OB_LOG(ERROR, "%s", "ThreadSyscallException"); + assert( rt == 0 ); + if ( rt != 0 ) { + _OB_LOG(ERROR,"%s","ThreadSyscallException"); } #else - if (rt != 0) { + if ( rt != 0 ) { throw ThreadSyscallException(__FILE__, __LINE__, rt); } #endif @@ -105,10 +105,11 @@ void Mutex::unlock(LockState& state) const } void Mutex::lock(LockState&) const -{} +{ +} -bool Mutex::willUnlock() const +bool Mutex::will_unlock() const { return true; } -} // end namespace tbutil +}//end namespace obutil diff --git a/deps/oblib/src/lib/lock/mutex.h b/deps/oblib/src/lib/lock/mutex.h new file mode 100644 index 0000000000..d178dc8dda --- /dev/null +++ b/deps/oblib/src/lib/lock/mutex.h @@ -0,0 +1,52 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ +#ifndef MUTEX_H +#define MUTEX_H + +#include +#include "lib/lock/ob_lock.h" + +namespace obutil +{ +class Mutex +{ +public: + + typedef ObLockT Lock; + typedef ObTryLockT TryLock; + + Mutex(); + ~Mutex(); + + void lock() const; + bool trylock() const; + void unlock() const; + bool will_unlock() const; + +private: + + Mutex(const Mutex&); + Mutex& operator=(const Mutex&); + + struct LockState + { + pthread_mutex_t* mutex; + }; + + void unlock(LockState&) const; + void lock(LockState&) const; + mutable pthread_mutex_t _mutex; + + friend class Cond; +}; +}//end namespace +#endif diff --git a/deps/oblib/src/lib/lock/ob_lock.h b/deps/oblib/src/lib/lock/ob_lock.h new file mode 100644 index 0000000000..eefeb72f7e --- /dev/null +++ b/deps/oblib/src/lib/lock/ob_lock.h @@ -0,0 +1,115 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ +#ifndef OB_LOCK_H +#define OB_LOCK_H +#include +namespace obutil +{ +template +class ObLockT +{ +public: + + explicit ObLockT(const T& mutex) : + mutex_(mutex) + { + mutex_.lock(); + acquired_ = true; + } + + ~ObLockT() + { + if (acquired_) + { + mutex_.unlock(); + } + } + + void acquire() const + { + if (acquired_) + { +#ifdef _NO_EXCEPTION + assert(!"ThreadLockedException"); +#else + throw ThreadLockedException(__FILE__, __LINE__); +#endif + } + mutex_.lock(); + acquired_ = true; + } + + + bool try_acquire() const + { + if (acquired_) + { +#ifdef _NO_EXCEPTION + assert(!"ThreadLockedException"); +#else + throw ThreadLockedException(__FILE__, __LINE__); +#endif + } + acquired_ = mutex_.trylock(); + return acquired_; + } + + void release() const + { + if (!acquired_) + { +#ifdef _NO_EXCEPTION + assert(!"ThreadLockedException"); +#else + throw ThreadLockedException(__FILE__, __LINE__); +#endif + } + mutex_.unlock(); + acquired_ = false; + } + + bool acquired() const + { + return acquired_; + } + +protected: + + ObLockT(const T& mutex, bool) : + mutex_(mutex) + { + acquired_ = mutex_.trylock(); + } + +private: + + ObLockT(const ObLockT&); + ObLockT& operator=(const ObLockT&); + + const T& mutex_; + mutable bool acquired_; + + friend class Cond; +}; + +template +class ObTryLockT : public ObLockT +{ +public: + + ObTryLockT(const T& mutex) : + ObLockT(mutex, true) + {} +}; +} + +#endif diff --git a/deps/oblib/src/lib/lock/ob_monitor.h b/deps/oblib/src/lib/lock/ob_monitor.h new file mode 100644 index 0000000000..6527d5cd62 --- /dev/null +++ b/deps/oblib/src/lib/lock/ob_monitor.h @@ -0,0 +1,160 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ +#ifndef OB_MONITOR_H +#define OB_MONITOR_H +#include "lib/lock/ob_lock.h" +#include "lib/lock/cond.h" + + +namespace obutil +{ +template +class ObMonitor +{ +public: + + typedef ObLockT > Lock; + typedef ObTryLockT > TryLock; + + ObMonitor(); + ~ObMonitor(); + + void lock() const; + void unlock() const; + bool trylock() const; + bool wait() const; + bool timed_wait(const ObSysTime&) const; + void notify(); + void notify_all(); + +private: + + ObMonitor(const ObMonitor&); + ObMonitor& operator=(const ObMonitor&); + + void notify_impl(int) const; + + mutable Cond cond_; + T mutex_; + mutable int nnotify_; +}; + +template +ObMonitor::ObMonitor() : + nnotify_(0) +{ +} + +template +ObMonitor::~ObMonitor() +{ +} + +template inline void +ObMonitor::lock() const +{ + mutex_.lock(); + if(mutex_.will_unlock()) { + nnotify_ = 0; + } +} + +template inline void +ObMonitor::unlock() const +{ + if(mutex_.will_unlock()) { + notify_impl(nnotify_); + } + mutex_.unlock(); +} + +template inline bool +ObMonitor::trylock() const +{ + bool result = mutex_.trylock(); + if(result && mutex_.will_unlock()) { + nnotify_ = 0; + } + return result; +} + +template inline bool +ObMonitor::wait() const +{ + notify_impl(nnotify_); +#ifdef _NO_EXCEPTION + const bool bRet = cond_.wait_impl(mutex_); + nnotify_ = 0; + return bRet; +#else + try { + cond_.wait_impl(mutex_); + } catch(...) { + nnotify_ = 0; + throw; + } + + nnotify_ = 0; + return true; +#endif +} + +template inline bool +ObMonitor::timed_wait(const ObSysTime& timeout) const +{ + notify_impl(nnotify_); +#ifdef _NO_EXCEPTION + const bool rc = cond_.timed_wait_impl(mutex_, timeout); + nnotify_ = 0; + return rc; +#else + try { + cond_.timed_wait_impl(mutex_, timeout); + } catch(...) { + nnotify_ = 0; + throw; + } + nnotify_ = 0; + return true; +#endif +} + +template inline void +ObMonitor::notify() +{ + if(nnotify_ != -1) { + ++nnotify_; + } +} + +template inline void +ObMonitor::notify_all() +{ + nnotify_ = -1; +} + + +template inline void +ObMonitor::notify_impl(int nnotify) const +{ + if (nnotify == 0) { + } else if (nnotify == -1) { + cond_.broadcast(); + } else { + while(nnotify > 0) { + cond_.signal(); + --nnotify; + } + } +} +}//end namespace +#endif diff --git a/deps/oblib/src/lib/lock/tbrwlock.cpp b/deps/oblib/src/lib/lock/ob_rwlock.cpp similarity index 56% rename from deps/oblib/src/lib/lock/tbrwlock.cpp rename to deps/oblib/src/lib/lock/ob_rwlock.cpp index 54c2001e3d..a40c58b205 100644 --- a/deps/oblib/src/lib/lock/tbrwlock.cpp +++ b/deps/oblib/src/lib/lock/ob_rwlock.cpp @@ -9,43 +9,41 @@ * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. * See the Mulan PubL v2 for more details. */ - -#include "lib/lock/tbrwlock.h" +#include "lib/lock/ob_rwlock.h" using namespace oceanbase::obsys; -int CRLock::lock() const +int ObRLock::lock() const { - return pthread_rwlock_rdlock(_rlock); + return pthread_rwlock_rdlock(rlock_); } -int CRLock::tryLock() const +int ObRLock::trylock() const { - return pthread_rwlock_tryrdlock(_rlock); + return pthread_rwlock_tryrdlock(rlock_); } -int CRLock::unlock() const +int ObRLock::unlock() const { - return pthread_rwlock_unlock(_rlock); + return pthread_rwlock_unlock(rlock_); } -int CWLock::lock() const +int ObWLock::lock() const { - return pthread_rwlock_wrlock(_wlock); + return pthread_rwlock_wrlock(wlock_); } -int CWLock::tryLock() const +int ObWLock::trylock() const { - return pthread_rwlock_trywrlock(_wlock); + return pthread_rwlock_trywrlock(wlock_); } -int CWLock::unlock() const +int ObWLock::unlock() const { - return pthread_rwlock_unlock(_wlock); + return pthread_rwlock_unlock(wlock_); } -////////////////////////////////////////////////////////////////////////////////////// -CRWLock::CRWLock(ELockMode lockMode) : _rlock(&_rwlock), _wlock(&_rwlock) +ObRWLock::ObRWLock(LockMode lockMode) { pthread_rwlockattr_t attr; pthread_rwlockattr_init(&attr); @@ -54,10 +52,14 @@ CRWLock::CRWLock(ELockMode lockMode) : _rlock(&_rwlock), _wlock(&_rwlock) } else if (lockMode == WRITE_PRIORITY) { pthread_rwlockattr_setkind_np(&attr, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP); } - pthread_rwlock_init(&_rwlock, &attr); + pthread_rwlock_init(&rwlock_, &attr); + rlock_ = new ObRLock(&rwlock_); + wlock_ = new ObWLock(&rwlock_); } -CRWLock::~CRWLock() +ObRWLock::~ObRWLock() { - pthread_rwlock_destroy(&_rwlock); + pthread_rwlock_destroy(&rwlock_); + delete rlock_; + delete wlock_; } diff --git a/deps/oblib/src/lib/lock/ob_rwlock.h b/deps/oblib/src/lib/lock/ob_rwlock.h new file mode 100644 index 0000000000..f11e4b257c --- /dev/null +++ b/deps/oblib/src/lib/lock/ob_rwlock.h @@ -0,0 +1,104 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ +#ifndef OB_RW_LOCK_H +#define OB_RW_LOCK_H + +#include +namespace oceanbase { +namespace obsys { +template +class ObLockGuardBase +{ +public: + ObLockGuardBase(const T& lock, bool block = true) : lock_(lock) + { + acquired_ = !(block ? lock_.lock() : lock_.trylock()); + } + ~ObLockGuardBase() + { + if (acquired_) { + lock_.unlock(); + } + } + bool acquired() const { return acquired_; } + +private: + const T& lock_; + mutable bool acquired_; +}; + +enum LockMode +{ + NO_PRIORITY, + WRITE_PRIORITY, + READ_PRIORITY +}; + +class ObRLock +{ +public: + explicit ObRLock(pthread_rwlock_t* lock) : rlock_(lock) {} + ~ObRLock() {} + int lock() const; + int trylock() const; + int unlock() const; +private: + mutable pthread_rwlock_t* rlock_; +}; + +class ObWLock +{ +public: + explicit ObWLock(pthread_rwlock_t* lock) : wlock_(lock) {} + ~ObWLock() {} + int lock() const; + int trylock() const; + int unlock() const; +private: + mutable pthread_rwlock_t* wlock_; +}; + +class ObRWLock +{ +public: + ObRWLock(LockMode lockMode = NO_PRIORITY); + ~ObRWLock(); + ObRLock* rlock() const { return rlock_; } + ObWLock* wlock() const { return wlock_; } +private: + ObRLock* rlock_; + ObWLock* wlock_; + pthread_rwlock_t rwlock_; +}; + +class ObRLockGuard +{ +public: + ObRLockGuard(const ObRWLock& rwlock, bool block = true) : guard_((*rwlock.rlock()), block) {} + ~ObRLockGuard(){} + bool acquired() { return guard_.acquired(); } +private: + ObLockGuardBase guard_; +}; + +class ObWLockGuard +{ +public: + ObWLockGuard(const ObRWLock& rwlock, bool block = true) : guard_((*rwlock.wlock()), block) {} + ~ObWLockGuard(){} + bool acquired() { return guard_.acquired(); } +private: + ObLockGuardBase guard_; +}; +} +} +#endif diff --git a/deps/oblib/src/lib/lock/ob_tc_rwlock.h b/deps/oblib/src/lib/lock/ob_tc_rwlock.h index d315035a2a..edbc15ed95 100644 --- a/deps/oblib/src/lib/lock/ob_tc_rwlock.h +++ b/deps/oblib/src/lib/lock/ob_tc_rwlock.h @@ -174,7 +174,7 @@ public: ATOMIC_STORE(&write_id_, itid); get_tcref().sync(&read_ref_); int64_t ttl = 0; - while (0 != ATOMIC_LOAD(&read_ref_) && (ttl = abs_timeout_us - obsys::CTimeUtil::getTime()) >= 0) { + while (0 != ATOMIC_LOAD(&read_ref_) && (ttl = abs_timeout_us - obsys::ObSysTimeUtil::getTime()) >= 0) { lcond_.wait(std::min(ttl, (int64_t)10 * 1000)); } if (ttl < 0) { diff --git a/deps/oblib/src/lib/lock/tbrwlock.h b/deps/oblib/src/lib/lock/tbrwlock.h deleted file mode 100644 index 2774059e40..0000000000 --- a/deps/oblib/src/lib/lock/tbrwlock.h +++ /dev/null @@ -1,141 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#ifndef TBSYS_RW_LOCK_H -#define TBSYS_RW_LOCK_H - -#include - -namespace oceanbase { -namespace obsys { -enum ELockMode { NO_PRIORITY, WRITE_PRIORITY, READ_PRIORITY }; - -/** - * @brief Encapsulation of read lock in linux-thread read-write lock - */ -class CRLock { -public: - explicit CRLock(pthread_rwlock_t* lock) : _rlock(lock) - {} - ~CRLock() - {} - - int lock() const; - int tryLock() const; - int unlock() const; - -private: - mutable pthread_rwlock_t* _rlock; -}; - -/** - * @brief Encapsulation of write lock in linux-thread read-write lock - */ -class CWLock { -public: - explicit CWLock(pthread_rwlock_t* lock) : _wlock(lock) - {} - ~CWLock() - {} - - int lock() const; - int tryLock() const; - int unlock() const; - -private: - mutable pthread_rwlock_t* _wlock; -}; - -class CRWLock { -public: - CRWLock(ELockMode lockMode = NO_PRIORITY); - ~CRWLock(); - - const CRLock *rlock() const - { - return &_rlock; - } - const CWLock *wlock() const - { - return &_wlock; - } - -private: - CRLock _rlock; - CWLock _wlock; - pthread_rwlock_t _rwlock; -}; - -template -class CLockGuard { -public: - CLockGuard(const T& lock, bool block = true) : _lock(lock) - { - _acquired = !(block ? _lock.lock() : _lock.tryLock()); - } - - ~CLockGuard() - { - if (_acquired) - _lock.unlock(); - } - - bool acquired() const - { - return _acquired; - } - -private: - const T& _lock; - mutable bool _acquired; -}; -/** - * @brief Helper class for read lock in linux thread lock - */ -class CRLockGuard { -public: - CRLockGuard(const CRWLock& rwlock, bool block = true) : _guard((*rwlock.rlock()), block) - {} - ~CRLockGuard() - {} - - bool acquired() - { - return _guard.acquired(); - } - -private: - CLockGuard _guard; -}; - -/** - * @brief Helper class for write lock in linux thread lock - */ -class CWLockGuard { -public: - CWLockGuard(const CRWLock& rwlock, bool block = true) : _guard((*rwlock.wlock()), block) - {} - ~CWLockGuard() - {} - - bool acquired() - { - return _guard.acquired(); - } - -private: - CLockGuard _guard; -}; -} // namespace obsys -} // namespace oceanbase - -#endif diff --git a/deps/oblib/src/lib/lock/threadcond.h b/deps/oblib/src/lib/lock/threadcond.h index 34d0c9d69d..849fa0da5f 100644 --- a/deps/oblib/src/lib/lock/threadcond.h +++ b/deps/oblib/src/lib/lock/threadcond.h @@ -10,77 +10,42 @@ * See the Mulan PubL v2 for more details. */ -#ifndef TBSYS_COND_H_ -#define TBSYS_COND_H_ +#ifndef THREAD_COND_H_ +#define THREAD_COND_H_ #include "lib/lock/ob_thread_cond.h" namespace oceanbase { namespace obsys { -class CThreadCond { +class ThreadCond { public: - CThreadCond() - { + ThreadCond() { cond_.init(); } - - ~CThreadCond() - { - cond_.destroy(); + ~ThreadCond() { + cond_.destroy(); } - - int lock() - { + int lock() { return cond_.lock(); } - - int unlock() - { + int unlock() { return cond_.unlock(); } - - bool wait(int milliseconds = 0) - { - return OB_SUCCESS == cond_.wait(milliseconds); + bool wait(int milliseconds = 0) { + return oblib::OB_SUCCESS == cond_.wait(milliseconds); } - - void signal() - { - cond_.signal(); + void signal() { + cond_.signal(); } - - void broadcast() - { - cond_.broadcast(); + void broadcast() { + cond_.broadcast(); } private: oceanbase::common::ObThreadCond cond_; }; -class CCondGuard { -public: - explicit CCondGuard(CThreadCond* cond) - { - cond_ = NULL; - if (NULL != cond) { - cond_ = cond; - cond_->lock(); - } - } - - ~CCondGuard() - { - if (NULL != cond_) { - cond_->unlock(); - } - } - -private: - CThreadCond* cond_; -}; - } // namespace obsys } // namespace oceanbase -#endif /*COND_H_*/ +#endif /*THREAD_COND_H_*/ diff --git a/deps/oblib/src/lib/lock/threadmutex.h b/deps/oblib/src/lib/lock/threadmutex.h index d462699d5c..a1c8a20024 100644 --- a/deps/oblib/src/lib/lock/threadmutex.h +++ b/deps/oblib/src/lib/lock/threadmutex.h @@ -10,100 +10,67 @@ * See the Mulan PubL v2 for more details. */ -#ifndef TBSYS_MUTEX_H_ -#define TBSYS_MUTEX_H_ +#ifndef THREAD_MUTEX_H_ +#define THREAD_MUTEX_H_ #include #include namespace oceanbase { namespace obsys { -/* - * author cjxrobot - * - * Linux thread-lock - */ - -/** - * @brief Simple encapsulation of linux thread-lock and mutex-lock - */ -class CThreadMutex { +class ThreadMutex { public: - /* - * Constructor - */ - CThreadMutex() - { - // assert(pthread_mutex_init(&_mutex, NULL) == 0); - const int iRet = pthread_mutex_init(&_mutex, NULL); - (void)iRet; - assert(iRet == 0); + ThreadMutex() { + //assert(pthread_mutex_init(&mutex_, NULL) == 0); + const int iRet = pthread_mutex_init(&mutex_, NULL); + (void) iRet; + assert( iRet == 0 ); } - /* - * Destructor - */ - ~CThreadMutex() - { - pthread_mutex_destroy(&_mutex); + ~ThreadMutex() { + pthread_mutex_destroy(&mutex_); } - /** - * Lock - */ - - void lock() - { - pthread_mutex_lock(&_mutex); + void lock () { + pthread_mutex_lock(&mutex_); } - /** - * trylock - */ - - int trylock() - { - return pthread_mutex_trylock(&_mutex); + int trylock () { + return pthread_mutex_trylock(&mutex_); } - /** - * Unlock - */ - void unlock() - { - pthread_mutex_unlock(&_mutex); + void unlock() { + pthread_mutex_unlock(&mutex_); } protected: - pthread_mutex_t _mutex; + + pthread_mutex_t mutex_; }; -/** - * @brief Thread guard - */ -class CThreadGuard { +class ThreadGuard +{ public: - CThreadGuard(CThreadMutex* mutex) + ThreadGuard(ThreadMutex *mutex) { - _mutex = NULL; + mutex_ = NULL; if (mutex) { - _mutex = mutex; - _mutex->lock(); + mutex_ = mutex; + mutex_->lock(); } } - ~CThreadGuard() + ~ThreadGuard() { - if (_mutex) { - _mutex->unlock(); + if (mutex_) { + mutex_->unlock(); } } - private: - CThreadMutex* _mutex; + ThreadMutex *mutex_; }; } // namespace obsys } // namespace oceanbase -#endif /*MUTEX_H_*/ +#endif /*THREAD_MUTEX_H_*/ diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.cpp b/deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.cpp index 35076e843d..fbb711ed80 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.cpp +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.cpp @@ -56,7 +56,7 @@ ObMySQLConnectionPool::ObMySQLConnectionPool() ObMySQLConnectionPool::~ObMySQLConnectionPool() { ObServerConnectionPool* pool = NULL; - obsys::CWLockGuard lock(get_lock_); + obsys::ObWLockGuard lock(get_lock_); for (ClusterList::iterator cluster_iter = cluster_list_.begin(); cluster_iter != cluster_list_.end(); cluster_iter++) { ClusterServerList*& cluster_server_list = *cluster_iter; @@ -163,7 +163,7 @@ void ObMySQLConnectionPool::signal_refresh() void ObMySQLConnectionPool::close_all_connection() { int ret = OB_SUCCESS; - obsys::CWLockGuard lock(get_lock_); + obsys::ObWLockGuard lock(get_lock_); ObServerConnectionPool* pool = NULL; for (ClusterList::iterator cluster_iter = cluster_list_.begin(); cluster_iter != cluster_list_.end(); cluster_iter++) { @@ -397,7 +397,7 @@ int ObMySQLConnectionPool::acquire(const int64_t cluster_id, ObMySQLConnection*& if (OB_ISNULL(connection)) { LOG_WARN("failed to acquire connection", K(cluster_id), K(this), K(server_count), K(busy_conn_count_), K(ret)); - obsys::CRLockGuard lock(get_lock_); + obsys::ObRLockGuard lock(get_lock_); for (ClusterList::iterator cluster_iter = cluster_list_.begin(); cluster_iter != cluster_list_.end(); cluster_iter++) { ClusterServerList*& cluster_server_list = *cluster_iter; @@ -421,7 +421,7 @@ int64_t ObMySQLConnectionPool::get_server_count(const int64_t cluster_id) const { int64_t count = 0; int ret = OB_SUCCESS; - obsys::CRLockGuard lock(get_lock_); + obsys::ObRLockGuard lock(get_lock_); ClusterServerList* cluster_server_list = NULL; if (OB_FAIL(get_cluster_server_list_(cluster_id, cluster_server_list))) { LOG_WARN("fail to get cluster_server_list", K(ret), K(cluster_id)); @@ -436,7 +436,7 @@ int64_t ObMySQLConnectionPool::get_server_count(const int64_t cluster_id) const int ObMySQLConnectionPool::do_acquire(const int64_t cluster_id, ObMySQLConnection*& connection) { int ret = OB_SUCCESS; - obsys::CRLockGuard lock(get_lock_); + obsys::ObRLockGuard lock(get_lock_); ObServerConnectionPool* pool = NULL; if (OB_FAIL(get_pool(cluster_id, pool))) { LOG_WARN("failed to get pool", K(ret)); @@ -520,7 +520,7 @@ int ObMySQLConnectionPool::execute_init_sql(ObMySQLConnection* connection) int ObMySQLConnectionPool::release(ObMySQLConnection* connection, const bool succ) { int ret = OB_SUCCESS; - obsys::CRLockGuard lock(get_lock_); + obsys::ObRLockGuard lock(get_lock_); ObServerConnectionPool* pool = NULL; if (OB_ISNULL(connection)) { ret = OB_INVALID_ARGUMENT; @@ -570,7 +570,7 @@ void ObMySQLConnectionPool::runTimerTask() // Ignore the error code and does not affect the subsequent process LOG_WARN("failed to prepare refresh", K(ret), K(tmp_ret)); } - obsys::CWLockGuard lock(get_lock_); + obsys::ObWLockGuard lock(get_lock_); if (OB_FAIL(server_provider_->refresh_server_list())) { if (!is_updated_) { // has never successfully updated, it is in startup time, should not print ERROR LOG_INFO("fail to refresh mysql server list in startup time, it's normal", K(ret)); @@ -724,7 +724,7 @@ int ObDbLinkConnectionPool::create_dblink_pool(uint64_t dblink_id, const ObAddr& { int ret = OB_SUCCESS; ObServerConnectionPool* dblink_pool = NULL; - obsys::CRLockGuard lock(get_lock_); + obsys::ObRLockGuard lock(get_lock_); if (OB_FAIL(get_dblink_pool(dblink_id, dblink_pool))) { LOG_WARN("fail to get dblink connection pool", K(dblink_id)); } else if (OB_NOT_NULL(dblink_pool)) { diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.h b/deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.h index 7fe3e4e5fe..3b3021a596 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.h +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.h @@ -193,7 +193,7 @@ protected: char db_name_[OB_MAX_DATABASE_NAME_BUF_LENGTH]; char init_sql_[OB_MAX_SQL_LENGTH]; ObConnPoolConfigParam config_; - mutable obsys::CRWLock get_lock_; + mutable obsys::ObRWLock get_lock_; common::ObArenaAllocator allocator_; ClusterList cluster_list_; common::ObCachedAllocator server_pool_; diff --git a/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp b/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp index c6b5af2732..578fd99bb0 100644 --- a/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp +++ b/deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp @@ -82,7 +82,7 @@ int ObMySQLStatement::execute_update(int64_t& affected_rows) ret = OB_ERR_UNEXPECTED; LOG_ERROR("invalid mysql stmt", K_(conn), K_(stmt), K_(sql_str), K(ret)); } else { - int64_t begin = obsys::CTimeUtil::getMonotonicTime(); + int64_t begin = obsys::ObSysTimeUtil::getMonotonicTime(); if (0 != (tmp_ret = mysql_real_query(stmt_, sql_str_, STRLEN(sql_str_)))) { ret = -mysql_errno(stmt_); LOG_WARN("fail to query server", @@ -101,7 +101,7 @@ int ObMySQLStatement::execute_update(int64_t& affected_rows) } else { affected_rows = mysql_affected_rows(stmt_); } - int64_t end = obsys::CTimeUtil::getMonotonicTime(); + int64_t end = obsys::ObSysTimeUtil::getMonotonicTime(); LOG_TRACE("execute stat", "excute time(us)", (end - begin), "SQL:", sql_str_); } return ret; @@ -115,7 +115,7 @@ ObMySQLResult* ObMySQLStatement::execute_query() ret = OB_ERR_UNEXPECTED; LOG_ERROR("invalid mysql stmt", K_(conn), K_(stmt), K_(sql_str), K(ret)); } else { - int64_t begin = obsys::CTimeUtil::getMonotonicTime(); + int64_t begin = obsys::ObSysTimeUtil::getMonotonicTime(); if (0 != mysql_real_query(stmt_, sql_str_, STRLEN(sql_str_))) { ret = -mysql_errno(stmt_); const int ER_LOCK_WAIT_TIMEOUT = -1205; @@ -136,7 +136,7 @@ ObMySQLResult* ObMySQLStatement::execute_query() result = &result_; } conn_->set_last_error(ret); - int64_t end = obsys::CTimeUtil::getMonotonicTime(); + int64_t end = obsys::ObSysTimeUtil::getMonotonicTime(); LOG_TRACE("execute stat", "time(us)", (end - begin), "SQL", sql_str_, K(ret)); } return result; diff --git a/deps/oblib/src/lib/net/ob_net_util.cpp b/deps/oblib/src/lib/net/ob_net_util.cpp new file mode 100644 index 0000000000..6d980b2278 --- /dev/null +++ b/deps/oblib/src/lib/net/ob_net_util.cpp @@ -0,0 +1,118 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ +#define USING_LOG_PREFIX LIB +#include "lib/oblog/ob_log.h" +#include "lib/utility/ob_print_utils.h" +#include "lib/net/ob_net_util.h" +#include +#include +#include +#include + +using namespace oceanbase::common; + +namespace oceanbase { +namespace obsys { + +int ObNetUtil::get_local_addr_ipv6(const char *dev_name, char *ipv6, int len) +{ + int ret = -1; + struct ifaddrs *ifa = nullptr, *ifa_tmp = nullptr; + + if (len < INET6_ADDRSTRLEN || getifaddrs(&ifa) == -1) { + } else { + ifa_tmp = ifa; + while (ifa_tmp) { + if (ifa_tmp->ifa_addr && ifa_tmp->ifa_addr->sa_family == AF_INET6 && + !strcmp(ifa_tmp->ifa_name, dev_name)) { + struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ifa_tmp->ifa_addr; + if (IN6_IS_ADDR_LOOPBACK(&in6->sin6_addr) + || IN6_IS_ADDR_LINKLOCAL(&in6->sin6_addr) + || IN6_IS_ADDR_SITELOCAL(&in6->sin6_addr) + || IN6_IS_ADDR_V4MAPPED(&in6->sin6_addr)) { + // filter ipv6 local, site-local etc. + } else if (!inet_ntop(AF_INET6, &in6->sin6_addr, ipv6, len)) { // use ipv6 global + ret = 0; + break; + } + } + ifa_tmp = ifa_tmp->ifa_next; + } // while + } + return ret; +} + +uint32_t ObNetUtil::get_local_addr_ipv4(const char *dev_name) +{ + uint32_t ret_addr = 0; + int ret = OB_SUCCESS; + int fd = -1; + int interface = 0; + struct ifreq buf[16]; + struct ifconf ifc; + + if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { + LOG_ERROR("syscall socket failed", K(errno), KP(dev_name)); + } else { + ifc.ifc_len = sizeof(buf); + ifc.ifc_buf = (caddr_t)buf; + + if (0 != ioctl(fd, SIOCGIFCONF, (char *)&ifc)) { + LOG_WARN("syscall ioctl(SIOCGIFCONF) failed", K(errno), K(fd), KP(dev_name)); + } else { + interface = static_cast(ifc.ifc_len / sizeof(struct ifreq)); + while (interface-- > 0 && OB_SUCC(ret)) { + if (0 != ioctl(fd, SIOCGIFFLAGS, (char *)&buf[interface])) { + continue; + } + if (!(buf[interface].ifr_flags & IFF_UP)) { + continue; + } + if (NULL != dev_name && strcmp(dev_name, buf[interface].ifr_name)) { + continue; + } + if (!(ioctl(fd, SIOCGIFADDR, (char *)&buf[interface]))) { + ret = -1; + ret_addr = ((struct sockaddr_in *) (&buf[interface].ifr_addr))->sin_addr.s_addr; + } + } + } + close(fd); + } + + return ret_addr; +} + +std::string ObNetUtil::addr_to_string(uint64_t ipport) +{ + char str[32]; + uint32_t ip = (uint32_t)(ipport & 0xffffffff); + int port = (int)((ipport >> 32 ) & 0xffff); + unsigned char *bytes = (unsigned char *) &ip; + if (port > 0) { + snprintf(str, sizeof(str), "%d.%d.%d.%d:%d", bytes[0], bytes[1], bytes[2], bytes[3], port); + } else { + snprintf(str, sizeof(str), "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]); + } + return str; +} + +uint64_t ObNetUtil::ip_to_addr(uint32_t ip, int port) +{ + uint64_t ipport = port; + ipport <<= 32; + ipport |= ip; + return ipport; +} + +} +} diff --git a/deps/oblib/src/lib/net/ob_net_util.h b/deps/oblib/src/lib/net/ob_net_util.h new file mode 100644 index 0000000000..cc0bbfc496 --- /dev/null +++ b/deps/oblib/src/lib/net/ob_net_util.h @@ -0,0 +1,44 @@ +/** + * Copyright (c) 2021 OceanBase + * OceanBase CE is licensed under Mulan PubL v2. + * You can use this software according to the terms and conditions of the Mulan PubL v2. + * You may obtain a copy of Mulan PubL v2 at: + * http://license.coscl.org.cn/MulanPubL-2.0 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, + * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, + * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PubL v2 for more details. + */ +#ifndef OCEANBASE_NET_UTIL_H_ +#define OCEANBASE_NET_UTIL_H_ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace oceanbase { +namespace obsys { + +class ObNetUtil { +public: + static int get_local_addr_ipv6(const char *dev_name, char *ipv6, int len); + static uint32_t get_local_addr_ipv4(const char *dev_name); + static std::string addr_to_string(uint64_t ipport); + static uint64_t ip_to_addr(uint32_t ip, int port); +}; + +} +} +#endif diff --git a/deps/oblib/src/lib/net/tbnetutil.cpp b/deps/oblib/src/lib/net/tbnetutil.cpp deleted file mode 100644 index c2f0a667ea..0000000000 --- a/deps/oblib/src/lib/net/tbnetutil.cpp +++ /dev/null @@ -1,179 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#include -#include -#include -#include "lib/net/tbnetutil.h" - -namespace oceanbase { -namespace obsys { - -int CNetUtil::getLocalAddr6(const char* dev_name, char* ipv6, int len) -{ - int ret = -1; - struct ifaddrs *ifa = nullptr, *ifa_tmp = nullptr; - - if (len < INET6_ADDRSTRLEN || getifaddrs(&ifa) == -1) { - } else { - ifa_tmp = ifa; - while (ifa_tmp) { - if (ifa_tmp->ifa_addr && ifa_tmp->ifa_addr->sa_family == AF_INET6 && !strcmp(ifa_tmp->ifa_name, dev_name)) { - struct sockaddr_in6* in6 = (struct sockaddr_in6*)ifa_tmp->ifa_addr; - if (IN6_IS_ADDR_LOOPBACK(&in6->sin6_addr) || IN6_IS_ADDR_LINKLOCAL(&in6->sin6_addr) || - IN6_IS_ADDR_SITELOCAL(&in6->sin6_addr) || IN6_IS_ADDR_V4MAPPED(&in6->sin6_addr)) { - // filter ipv6 local, site-local etc. - } else if (!inet_ntop(AF_INET6, &in6->sin6_addr, ipv6, len)) { // use ipv6 global - ret = 0; - break; - } - } - ifa_tmp = ifa_tmp->ifa_next; - } // while - } - return ret; -} - -uint32_t CNetUtil::getLocalAddr(const char* dev_name) -{ - uint32_t ret = 0; - int fd, intf; - struct ifreq buf[16]; - struct ifconf ifc; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) { - ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = (caddr_t)buf; - if (ioctl(fd, SIOCGIFCONF, (char*)&ifc) == 0) { - intf = static_cast(ifc.ifc_len / sizeof(struct ifreq)); - while (intf-- > 0) { - if (ioctl(fd, SIOCGIFFLAGS, (char*)&buf[intf]) != 0) - continue; - if (!(buf[intf].ifr_flags & IFF_UP)) - continue; - if (dev_name != NULL && strcmp(dev_name, buf[intf].ifr_name)) - continue; - if (!(ioctl(fd, SIOCGIFADDR, (char*)&buf[intf]))) { - ret = ((struct sockaddr_in*)(&buf[intf].ifr_addr))->sin_addr.s_addr; - break; - } - } - } - close(fd); - } - return ret; -} - -bool CNetUtil::isLocalAddr(uint32_t ip, bool loopSkip) -{ - int fd, intrface; - struct ifreq buf[16]; - struct ifconf ifc; - - if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { - return false; - } - - ifc.ifc_len = sizeof(buf); - ifc.ifc_buf = (caddr_t)buf; - if (ioctl(fd, SIOCGIFCONF, (char*)&ifc) != 0) { - close(fd); - return false; - } - - intrface = static_cast(ifc.ifc_len / sizeof(struct ifreq)); - while (intrface-- > 0) { - if (ioctl(fd, SIOCGIFFLAGS, (char*)&buf[intrface]) != 0) { - continue; - } - if (loopSkip && buf[intrface].ifr_flags & IFF_LOOPBACK) - continue; - if (!(buf[intrface].ifr_flags & IFF_UP)) - continue; - if (ioctl(fd, SIOCGIFADDR, (char*)&buf[intrface]) != 0) { - continue; - } - if (((struct sockaddr_in*)(&buf[intrface].ifr_addr))->sin_addr.s_addr == ip) { - close(fd); - return true; - } - } - close(fd); - return false; -} - -/** - * 10.0.100.89 => 1499725834 - */ -uint32_t CNetUtil::getAddr(const char* ip) -{ - if (ip == NULL) - return 0; - int x = inet_addr(ip); - if (x == (int)INADDR_NONE) { - struct hostent* hp; - if ((hp = gethostbyname(ip)) == NULL) { - return 0; - } - x = ((struct in_addr*)hp->h_addr)->s_addr; - } - return x; -} - -std::string CNetUtil::addrToString(uint64_t ipport) -{ - char str[32]; - uint32_t ip = (uint32_t)(ipport & 0xffffffff); - int port = (int)((ipport >> 32) & 0xffff); - unsigned char* bytes = (unsigned char*)&ip; - if (port > 0) { - sprintf(str, "%d.%d.%d.%d:%d", bytes[0], bytes[1], bytes[2], bytes[3], port); - } else { - sprintf(str, "%d.%d.%d.%d", bytes[0], bytes[1], bytes[2], bytes[3]); - } - return str; -} - -uint64_t CNetUtil::strToAddr(const char* ip, int port) -{ - uint32_t nip = 0; - const char* p = strchr(ip, ':'); - if (p != NULL && p > ip) { - int64_t len = p - ip; - if (len > 64) - len = 64; - char tmp[128]; - strncpy(tmp, ip, len); - tmp[len] = '\0'; - nip = getAddr(tmp); - port = atoi(p + 1); - } else { - nip = getAddr(ip); - } - if (nip == 0) { - return 0; - } - uint64_t ipport = port; - ipport <<= 32; - ipport |= nip; - return ipport; -} - -uint64_t CNetUtil::ipToAddr(uint32_t ip, int port) -{ - uint64_t ipport = port; - ipport <<= 32; - ipport |= ip; - return ipport; -} -} // namespace obsys -} // namespace oceanbase diff --git a/deps/oblib/src/lib/net/tbnetutil.h b/deps/oblib/src/lib/net/tbnetutil.h deleted file mode 100644 index a4c3c2aae1..0000000000 --- a/deps/oblib/src/lib/net/tbnetutil.h +++ /dev/null @@ -1,63 +0,0 @@ -/** - * Copyright (c) 2021 OceanBase - * OceanBase CE is licensed under Mulan PubL v2. - * You can use this software according to the terms and conditions of the Mulan PubL v2. - * You may obtain a copy of Mulan PubL v2 at: - * http://license.coscl.org.cn/MulanPubL-2.0 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, - * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, - * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PubL v2 for more details. - */ - -#ifndef TBSYS_NETUTIL_H_ -#define TBSYS_NETUTIL_H_ - -#include -#include -#include -#include -#include -#include // ifaddrs -#include -#include -#include -#include -#include -#include -#include -#include -#include - -// using namespace std; - -namespace oceanbase { -namespace obsys { -struct ipaddr_less { - bool operator()(const uint64_t a, const uint64_t b) const - { - uint64_t a1 = ((a & 0xFF) << 24) | ((a & 0xFF00) << 8) | ((a & 0xFF0000) >> 8) | ((a & 0xFF000000) >> 24); - a1 <<= 32; - a1 |= ((a >> 32) & 0xffff); - uint64_t b1 = ((b & 0xFF) << 24) | ((b & 0xFF00) << 8) | ((b & 0xFF0000) >> 8) | ((b & 0xFF000000) >> 24); - b1 <<= 32; - b1 |= ((b >> 32) & 0xffff); - return (a1 < b1); - } -}; - -class CNetUtil { -public: - static int getLocalAddr6(const char* dev_name, char* ipv6, int len); - static uint32_t getLocalAddr(const char* dev_name); - static bool isLocalAddr(uint32_t ip, bool loopSkip = true); - static uint32_t getAddr(const char* ip); - static std::string addrToString(uint64_t ipport); - static uint64_t strToAddr(const char* ip, int port); - static uint64_t ipToAddr(uint32_t ip, int port); -}; - -} // namespace obsys -} // namespace oceanbase - -#endif diff --git a/deps/oblib/src/lib/oblog/ob_async_log_struct.cpp b/deps/oblib/src/lib/oblog/ob_async_log_struct.cpp index 2e5562ad56..31cf9e4349 100644 --- a/deps/oblib/src/lib/oblog/ob_async_log_struct.cpp +++ b/deps/oblib/src/lib/oblog/ob_async_log_struct.cpp @@ -13,6 +13,7 @@ #include "ob_async_log_struct.h" #include "lib/objectpool/ob_concurrency_objpool.h" +using namespace obutil; namespace oceanbase { namespace common { ObPLogItem::ObPLogItem() diff --git a/deps/oblib/src/lib/task/ob_timer.cpp b/deps/oblib/src/lib/task/ob_timer.cpp index dbc3302d0d..b57a77e23a 100644 --- a/deps/oblib/src/lib/task/ob_timer.cpp +++ b/deps/oblib/src/lib/task/ob_timer.cpp @@ -19,7 +19,7 @@ namespace oceanbase { namespace common { -using namespace tbutil; +using namespace obutil; using namespace lib; const int32_t ObTimer::MAX_TASK_NUM; @@ -48,13 +48,13 @@ ObTimer::~ObTimer() int ObTimer::create() { int ret = OB_SUCCESS; - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); if (is_stopped_) { if (OB_FAIL(ThreadPool::start())) { OB_LOG(ERROR, "failed to start timer thread", K(ret)); } else { is_stopped_ = false; - monitor_.notifyAll(); + monitor_.notify_all(); OB_LOG(INFO, "ObTimer create success", KP(this), K_(thread_id), K(lbt())); } } @@ -64,12 +64,12 @@ int ObTimer::create() int ObTimer::start() { int ret = OB_SUCCESS; - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); if (!is_inited_) { ret = OB_NOT_INIT; } else if (is_stopped_) { is_stopped_ = false; - monitor_.notifyAll(); + monitor_.notify_all(); OB_LOG(INFO, "ObTimer start success", KP(this), K_(thread_id), K(lbt())); } return ret; @@ -77,32 +77,32 @@ int ObTimer::start() void ObTimer::stop() { - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); if (!is_stopped_) { is_stopped_ = true; - monitor_.notifyAll(); + monitor_.notify_all(); OB_LOG(INFO, "ObTimer stop success", KP(this), K_(thread_id)); } } void ObTimer::wait() { - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); while (has_running_task_) { - static const int64_t WAIT_INTERVAL_US = 2000000; // 2s - (void)monitor_.timedWait(Time(WAIT_INTERVAL_US)); + static const int64_t WAIT_INTERVAL_US = 2000000; // 2s + (void)monitor_.timed_wait(ObSysTime(WAIT_INTERVAL_US)); } } void ObTimer::destroy() { if (!is_destroyed_ && is_inited_) { - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); is_stopped_ = true; is_destroyed_ = true; is_inited_ = false; has_running_repeat_task_ = false; - monitor_.notifyAll(); + monitor_.notify_all(); tasks_num_ = 0; OB_LOG(INFO, "ObTimer destroy", KP(this), K_(thread_id)); } @@ -113,7 +113,7 @@ void ObTimer::destroy() bool ObTimer::task_exist(const ObTimerTask& task) { bool ret = false; - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); for (int pos = 0; pos < tasks_num_; ++pos) { if (tokens_[pos].task == &task) { ret = true; @@ -152,7 +152,7 @@ int ObTimer::schedule_task( ObTimerTask& task, const int64_t delay, const bool repeate, const bool is_scheduled_immediately) { int ret = OB_SUCCESS; - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); if (!is_inited_) { ret = OB_NOT_INIT; } else if (delay < 0) { @@ -162,7 +162,7 @@ int ObTimer::schedule_task( ret = OB_ERR_UNEXPECTED; OB_LOG(WARN, "too much timer task", K(ret), K_(tasks_num), "max_task_num", MAX_TASK_NUM); } else { - int64_t time = Time::now(Time::Monotonic).toMicroSeconds(); + int64_t time = ObSysTime::now(ObSysTime::Monotonic).toMicroSeconds(); if (!is_scheduled_immediately) { time += delay; } @@ -216,7 +216,7 @@ int ObTimer::insert_token(const Token& token) int ObTimer::cancel(const ObTimerTask& task) { int ret = OB_SUCCESS; - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); if (!is_inited_) { ret = OB_NOT_INIT; } else { @@ -239,7 +239,7 @@ int ObTimer::cancel(const ObTimerTask& task) void ObTimer::cancel_all() { - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); tasks_num_ = 0; OB_LOG(INFO, "cancel all", KP(this), K_(thread_id), K(wakeup_time_), K(tasks_num_)); } @@ -257,8 +257,8 @@ void ObTimer::run1() } while (true) { { - Monitor::Lock guard(monitor_); - static const int64_t STATISTICS_INTERVAL_US = 600L * 1000 * 1000; // 10m + ObMonitor::Lock guard(monitor_); + static const int64_t STATISTICS_INTERVAL_US = 600L * 1000 * 1000; // 10m if (REACH_TIME_INTERVAL(STATISTICS_INTERVAL_US)) { OB_LOG(INFO, "dump timer info", KP(this), K_(tasks_num), K_(wakeup_time)); for (int64_t i = 0; i < tasks_num_; i++) { @@ -272,14 +272,14 @@ void ObTimer::run1() // add repeated task to tasks_ again if (token.delay != 0 && token.task->need_retry()) { has_running_repeat_task_ = false; - token.scheduled_time = Time::now(Time::Monotonic).toMicroSeconds() + token.delay; + token.scheduled_time = ObSysTime::now(ObSysTime::Monotonic).toMicroSeconds() + token.delay; if (OB_SUCCESS != (tmp_ret = insert_token(Token(token.scheduled_time, token.delay, token.task)))) { OB_LOG(WARN, "insert token error", K(tmp_ret), K(token)); } } has_running_task_ = false; if (is_stopped_) { - monitor_.notifyAll(); + monitor_.notify_all(); } while (!is_destroyed_ && is_stopped_) { monitor_.wait(); @@ -298,7 +298,7 @@ void ObTimer::run1() break; } while (tasks_num_ > 0 && !is_destroyed_ && !is_stopped_) { - const int64_t now = Time::now(Time::Monotonic).toMicroSeconds(); + const int64_t now = ObSysTime::now(ObSysTime::Monotonic).toMicroSeconds(); if (tokens_[0].scheduled_time <= now) { has_running_task_ = true; token = tokens_[0]; @@ -327,7 +327,7 @@ void ObTimer::run1() OB_LOG(ERROR, "Hardware clock error", K(rt1), K(rt2), K_(wakeup_time), K(now)); } } - monitor_.timedWait(Time(wakeup_time_ - now)); + monitor_.timed_wait(ObSysTime(wakeup_time_ - now)); } } } diff --git a/deps/oblib/src/lib/task/ob_timer.h b/deps/oblib/src/lib/task/ob_timer.h index b113e59a28..15205a8144 100644 --- a/deps/oblib/src/lib/task/ob_timer.h +++ b/deps/oblib/src/lib/task/ob_timer.h @@ -16,8 +16,8 @@ #include #include #include "lib/time/Time.h" -#include "lib/lock/Mutex.h" -#include "lib/lock/Monitor.h" +#include "lib/lock/mutex.h" +#include "lib/lock/ob_monitor.h" #include "lib/ob_define.h" #include "lib/utility/ob_print_utils.h" #include "lib/thread/thread_pool.h" @@ -131,7 +131,7 @@ private: bool is_inited_; bool is_stopped_; bool is_destroyed_; - tbutil::Monitor monitor_; + obutil::ObMonitor monitor_; Token tokens_[MAX_TASK_NUM]; bool has_running_task_; bool has_running_repeat_task_; diff --git a/deps/oblib/src/lib/time/Time.cpp b/deps/oblib/src/lib/time/Time.cpp index 0e4dbccde7..80876be2da 100644 --- a/deps/oblib/src/lib/time/Time.cpp +++ b/deps/oblib/src/lib/time/Time.cpp @@ -15,11 +15,11 @@ #include #include "lib/oblog/ob_log.h" -namespace tbutil { -Time::Time() : _usec(0) +namespace obutil { +ObSysTime::ObSysTime() : _usec(0) {} -Time Time::now(Clock clock) +ObSysTime ObSysTime::now(Clock clock) { if (clock == Realtime) { struct timeval tv; @@ -31,7 +31,7 @@ Time Time::now(Clock clock) throw SyscallException(__FILE__, __LINE__, errno); #endif } - return Time(tv.tv_sec * INT64_C(1000000) + tv.tv_usec); + return ObSysTime(tv.tv_sec * INT64_C(1000000) + tv.tv_usec); } else // Monotonic { struct timespec ts; @@ -43,26 +43,26 @@ Time Time::now(Clock clock) throw SyscallException(__FILE__, __LINE__, errno); #endif } - return Time(ts.tv_sec * INT64_C(1000000) + ts.tv_nsec / INT64_C(1000)); + return ObSysTime(ts.tv_sec * INT64_C(1000000) + ts.tv_nsec / INT64_C(1000)); } } -Time Time::seconds(int64_t t) +ObSysTime ObSysTime::seconds(int64_t t) { - return Time(t * INT64_C(1000000)); + return ObSysTime(t * INT64_C(1000000)); } -Time Time::milliSeconds(int64_t t) +ObSysTime ObSysTime::milliSeconds(int64_t t) { - return Time(t * INT64_C(1000)); + return ObSysTime(t * INT64_C(1000)); } -Time Time::microSeconds(int64_t t) +ObSysTime ObSysTime::microSeconds(int64_t t) { - return Time(t); + return ObSysTime(t); } -Time::operator timeval() const +ObSysTime::operator timeval() const { timeval tv; tv.tv_sec = static_cast(_usec / 1000000); @@ -70,37 +70,37 @@ Time::operator timeval() const return tv; } -int64_t Time::toSeconds() const +int64_t ObSysTime::toSeconds() const { return _usec / 1000000; } -int64_t Time::toMilliSeconds() const +int64_t ObSysTime::toMilliSeconds() const { return _usec / 1000; } -int64_t Time::toMicroSeconds() const +int64_t ObSysTime::toMicroSeconds() const { return _usec; } -double Time::toSecondsDouble() const +double ObSysTime::toSecondsDouble() const { return static_cast(_usec) / 1000000.0; } -double Time::toMilliSecondsDouble() const +double ObSysTime::toMilliSecondsDouble() const { return static_cast(_usec) / 1000.0; } -double Time::toMicroSecondsDouble() const +double ObSysTime::toMicroSecondsDouble() const { return static_cast(_usec); } -std::string Time::toDateTime() const +std::string ObSysTime::toDateTime() const { time_t time = static_cast(_usec / 1000000); @@ -121,7 +121,7 @@ std::string Time::toDateTime() const return os.str(); } -std::string Time::toDuration() const +std::string ObSysTime::toDuration() const { int64_t usecs = _usec % 1000000; int64_t secs = _usec / 1000000 % 60; @@ -143,7 +143,7 @@ std::string Time::toDuration() const return os.str(); } -Time::Time(int64_t usec) : _usec(usec) +ObSysTime::ObSysTime(int64_t usec) : _usec(usec) {} -} // end namespace tbutil +} // end namespace obutil diff --git a/deps/oblib/src/lib/time/Time.h b/deps/oblib/src/lib/time/Time.h index 20dfa286e4..ba233ea201 100644 --- a/deps/oblib/src/lib/time/Time.h +++ b/deps/oblib/src/lib/time/Time.h @@ -11,235 +11,238 @@ #include #include #include -namespace tbutil { +namespace obutil +{ /** - * @brief Time class provide interface for time operation - */ -class Time { +* @brief Time class provide interface for time operation +*/ +class ObSysTime +{ public: - Time(); - enum Clock { Realtime, Monotonic }; - /** - * @brief get current time - * - * @param clock Realtime: system rtc time; Monotonic: system time from boost - * - * @return - */ - static Time now(Clock clock = Realtime); - /** - * @brief construct a Time object - * - * @param usec: time of construct(seconds) - * - * @return - */ - static Time seconds(int64_t usec); - /** - * @brief construct a Time object - * - * @param milli : time of construct(milliseconds) - * - * @return - */ - static Time milliSeconds(int64_t milli); - /** - * @brief construct a Time object - * - * @param micro : time of construct(microseconds) - * - * @return - */ - static Time microSeconds(int64_t micro); + ObSysTime(); - /** - * @brief convert Time to timeval - * - * @return - */ - operator timeval() const; + enum Clock { Realtime, Monotonic }; + /** + * @brief get current time + * + * @param clock Realtime: system rtc time; Monotonic: system time from boost + * + * @return + */ + static ObSysTime now(Clock clock= Realtime); + /** + * @brief construct a Time object + * + * @param usec: time of construct(seconds) + * + * @return + */ + static ObSysTime seconds(int64_t usec); + /** + * @brief construct a Time object + * + * @param milli : time of construct(milliseconds) + * + * @return + */ + static ObSysTime milliSeconds(int64_t milli); + /** + * @brief construct a Time object + * + * @param micro : time of construct(microseconds) + * + * @return + */ + static ObSysTime microSeconds(int64_t micro); - /** - * @brief convert time to second - * - * @return - */ - int64_t toSeconds() const; - /** - * @brief convert time to millisecond - * - * @return - */ - int64_t toMilliSeconds() const; - /** - * @brief convert time to microseconds - * - * @return - */ - int64_t toMicroSeconds() const; + /** + * @brief convert Time to timeval + * + * @return + */ + operator timeval() const; - double toSecondsDouble() const; - double toMilliSecondsDouble() const; - double toMicroSecondsDouble() const; + /** + * @brief convert time to second + * + * @return + */ + int64_t toSeconds() const; + /** + * @brief convert time to millisecond + * + * @return + */ + int64_t toMilliSeconds() const; + /** + * @brief convert time to microseconds + * + * @return + */ + int64_t toMicroSeconds() const; - /** - * @brief convert time to string, such as: 2009-10-26 10:47:47.932 - * - * @return - */ - std::string toDateTime() const; - /** - * @brief convert time to string, such as: 14543d 02:47:47.932 - * - * @return - */ - std::string toDuration() const; + double toSecondsDouble() const; + double toMilliSecondsDouble() const; + double toMicroSecondsDouble() const; - Time operator-() const - { - return Time(-_usec); - } + /** + * @brief convert time to string, such as: 2009-10-26 10:47:47.932 + * + * @return + */ + std::string toDateTime() const; + /** + * @brief convert time to string, such as: 14543d 02:47:47.932 + * + * @return + */ + std::string toDuration() const; - Time operator-(const Time& rhs) const - { - return Time(_usec - rhs._usec); - } + ObSysTime operator-() const + { + return ObSysTime(-_usec); + } - Time operator+(const Time& rhs) const - { - return Time(_usec + rhs._usec); - } + ObSysTime operator-(const ObSysTime& rhs) const + { + return ObSysTime(_usec - rhs._usec); + } - Time& operator+=(const Time& rhs) - { - _usec += rhs._usec; - return *this; - } + ObSysTime operator+(const ObSysTime& rhs) const + { + return ObSysTime(_usec + rhs._usec); + } - Time& operator-=(const Time& rhs) - { - _usec -= rhs._usec; - return *this; - } + ObSysTime& operator+=(const ObSysTime& rhs) + { + _usec += rhs._usec; + return *this; + } - bool operator<(const Time& rhs) const - { - return _usec < rhs._usec; - } + ObSysTime& operator-=(const ObSysTime& rhs) + { + _usec -= rhs._usec; + return *this; + } - bool operator<=(const Time& rhs) const - { - return _usec <= rhs._usec; - } + bool operator<(const ObSysTime& rhs) const + { + return _usec < rhs._usec; + } - bool operator>(const Time& rhs) const - { - return _usec > rhs._usec; - } + bool operator<=(const ObSysTime& rhs) const + { + return _usec <= rhs._usec; + } - bool operator>=(const Time& rhs) const - { - return _usec >= rhs._usec; - } + bool operator>(const ObSysTime& rhs) const + { + return _usec > rhs._usec; + } - bool operator==(const Time& rhs) const - { - return _usec == rhs._usec; - } + bool operator>=(const ObSysTime& rhs) const + { + return _usec >= rhs._usec; + } - bool operator!=(const Time& rhs) const - { - return _usec != rhs._usec; - } + bool operator==(const ObSysTime& rhs) const + { + return _usec == rhs._usec; + } - double operator/(const Time& rhs) const - { - return (double)_usec / (double)rhs._usec; - } + bool operator!=(const ObSysTime& rhs) const + { + return _usec != rhs._usec; + } - Time& operator*=(int rhs) - { - _usec *= rhs; - return *this; - } + double operator/(const ObSysTime& rhs) const + { + return (double)_usec / (double)rhs._usec; + } - Time operator*(int rhs) const - { - Time t; - t._usec = _usec * rhs; - return t; - } + ObSysTime& operator*=(int rhs) + { + _usec *= rhs; + return *this; + } - Time& operator/=(int rhs) - { - _usec /= rhs; - return *this; - } + ObSysTime operator*(int rhs) const + { + ObSysTime t; + t._usec = _usec * rhs; + return t; + } - Time operator/(int rhs) const - { - Time t; - t._usec = _usec / rhs; - return t; - } + ObSysTime& operator/=(int rhs) + { + _usec /= rhs; + return *this; + } - Time& operator*=(int64_t rhs) - { - _usec *= rhs; - return *this; - } + ObSysTime operator/(int rhs) const + { + ObSysTime t; + t._usec = _usec / rhs; + return t; + } - Time operator*(int64_t rhs) const - { - Time t; - t._usec = _usec * rhs; - return t; - } + ObSysTime& operator*=(int64_t rhs) + { + _usec *= rhs; + return *this; + } - Time& operator/=(int64_t rhs) - { - _usec /= rhs; - return *this; - } + ObSysTime operator*(int64_t rhs) const + { + ObSysTime t; + t._usec = _usec * rhs; + return t; + } - Time operator/(int64_t rhs) const - { - Time t; - t._usec = _usec / rhs; - return t; - } + ObSysTime& operator/=(int64_t rhs) + { + _usec /= rhs; + return *this; + } - Time& operator*=(double rhs) - { - _usec = static_cast(static_cast(_usec) * rhs); - return *this; - } + ObSysTime operator/(int64_t rhs) const + { + ObSysTime t; + t._usec = _usec / rhs; + return t; + } - Time operator*(double rhs) const - { - Time t; - t._usec = static_cast(static_cast(_usec) * rhs); - return t; - } + ObSysTime& operator*=(double rhs) + { + _usec = static_cast(static_cast(_usec) * rhs); + return *this; + } - Time& operator/=(double rhs) - { - _usec = static_cast(static_cast(_usec) / rhs); - return *this; - } + ObSysTime operator*(double rhs) const + { + ObSysTime t; + t._usec = static_cast(static_cast(_usec) * rhs); + return t; + } - Time operator/(double rhs) const - { - Time t; - t._usec = static_cast(static_cast(_usec) / rhs); - return t; - } + ObSysTime& operator/=(double rhs) + { + _usec = static_cast(static_cast(_usec) / rhs); + return *this; + } - Time(int64_t); + ObSysTime operator/(double rhs) const + { + ObSysTime t; + t._usec = static_cast(static_cast(_usec) / rhs); + return t; + } + + ObSysTime(int64_t); private: int64_t _usec; }; -} // namespace tbutil +} // namespace obutil #endif diff --git a/deps/oblib/src/lib/time/tbtimeutil.cpp b/deps/oblib/src/lib/time/tbtimeutil.cpp index 6c7b49d209..f680616add 100644 --- a/deps/oblib/src/lib/time/tbtimeutil.cpp +++ b/deps/oblib/src/lib/time/tbtimeutil.cpp @@ -23,14 +23,14 @@ namespace obsys { /* * get current time */ -int64_t CTimeUtil::getTime() +int64_t ObSysTimeUtil::getTime() { - struct timeval t; - (void)gettimeofday(&t, NULL); - return (static_cast(t.tv_sec) * static_cast(1000000) + static_cast(t.tv_usec)); + struct timeval t; + (void)gettimeofday(&t, NULL); + return (static_cast(t.tv_sec) * static_cast(1000000) + static_cast(t.tv_usec)); } -int64_t CTimeUtil::getMonotonicTime() +int64_t ObSysTimeUtil::getMonotonicTime() { timespec t; clock_gettime(CLOCK_MONOTONIC, &t); @@ -40,7 +40,7 @@ int64_t CTimeUtil::getMonotonicTime() /** * format int into 20080101101010 */ -char* CTimeUtil::timeToStr(time_t t, char* dest) +char* ObSysTimeUtil::timeToStr(time_t t, char* dest) { struct tm r; memset(&r, 0, sizeof(r)); @@ -57,7 +57,7 @@ char* CTimeUtil::timeToStr(time_t t, char* dest) * format string to time(local) */ /* -int CTimeUtil::strToTime(char *str) +int ObSysTimeUtil::strToTime(char *str) { if (str == NULL || strlen(str) != 14) { return 0; diff --git a/deps/oblib/src/lib/time/tbtimeutil.h b/deps/oblib/src/lib/time/tbtimeutil.h index c67280b366..a984ab8464 100644 --- a/deps/oblib/src/lib/time/tbtimeutil.h +++ b/deps/oblib/src/lib/time/tbtimeutil.h @@ -25,7 +25,7 @@ namespace obsys { /** * @brief Simple encapsulation of linux time operation */ -class CTimeUtil { +class ObSysTimeUtil { public: /** * ms timestamp diff --git a/deps/oblib/unittest/lib/container/test_ext_ring_buffer.cpp b/deps/oblib/unittest/lib/container/test_ext_ring_buffer.cpp index a3f88ab627..a9365b44f0 100644 --- a/deps/oblib/unittest/lib/container/test_ext_ring_buffer.cpp +++ b/deps/oblib/unittest/lib/container/test_ext_ring_buffer.cpp @@ -310,13 +310,13 @@ TEST(HazPtr, Basic0) const int64_t lmt = 10000000; int64_t cnt = 0; - int64_t start = obsys::CTimeUtil::getTime(); + int64_t start = obsys::ObSysTimeUtil::getTime(); while (++cnt < lmt) { TypeA* ptr = hazptr.acquire(target, 0); EXPECT_EQ(target, ptr); hazptr.revert(0); } - int64_t end = obsys::CTimeUtil::getTime(); + int64_t end = obsys::ObSysTimeUtil::getTime(); LIB_LOG(ERROR, ">>>", K(cnt), K(end - start), K((double)cnt / ((double)(end - start) / 1000000))); err = hazptr.destroy(); diff --git a/deps/oblib/unittest/lib/hash/test_concurrent_hash_map.cpp b/deps/oblib/unittest/lib/hash/test_concurrent_hash_map.cpp index 6cc8902f55..c08f4a6c04 100644 --- a/deps/oblib/unittest/lib/hash/test_concurrent_hash_map.cpp +++ b/deps/oblib/unittest/lib/hash/test_concurrent_hash_map.cpp @@ -67,7 +67,7 @@ public: HashMap* hashmap; private: - obsys::CThreadMutex mutex; + obsys::ThreadMutex mutex; }; TEST(TestObConcurrentHashMap, concurrent) diff --git a/deps/oblib/unittest/lib/hash/test_concurrent_hash_map_with_hazard_value.cpp b/deps/oblib/unittest/lib/hash/test_concurrent_hash_map_with_hazard_value.cpp index ed8e9c73f8..432c83c569 100644 --- a/deps/oblib/unittest/lib/hash/test_concurrent_hash_map_with_hazard_value.cpp +++ b/deps/oblib/unittest/lib/hash/test_concurrent_hash_map_with_hazard_value.cpp @@ -175,7 +175,7 @@ public: HashMap* hashmap; private: - obsys::CThreadMutex mutex; + obsys::ThreadMutex mutex; int finished_count; }; diff --git a/src/election/ob_election_async_log.cpp b/src/election/ob_election_async_log.cpp index 5356cb5f36..b70add530a 100644 --- a/src/election/ob_election_async_log.cpp +++ b/src/election/ob_election_async_log.cpp @@ -17,7 +17,7 @@ #include "lib/wait_event/ob_wait_event.h" #include "lib/stat/ob_diagnose_info.h" -using namespace tbutil; +using namespace obutil; namespace oceanbase { using namespace common; diff --git a/src/election/ob_election_async_log.h b/src/election/ob_election_async_log.h index 69e9698c41..130e9c098a 100644 --- a/src/election/ob_election_async_log.h +++ b/src/election/ob_election_async_log.h @@ -17,8 +17,8 @@ #include #include #include -#include "lib/lock/Mutex.h" -#include "lib/lock/Monitor.h" +#include "lib/lock/mutex.h" +#include "lib/lock/ob_monitor.h" #include "lib/oblog/ob_log.h" #include "lib/oblog/ob_log_print_kv.h" #include "share/ob_errno.h" @@ -65,7 +65,7 @@ private: int start_; int end_; Type elems_[size]; - tbutil::Monitor monitor_; + obutil::ObMonitor monitor_; }; template @@ -80,7 +80,7 @@ int ObRingBuffer::push(const Type& elem, Type& old_elem, bool& overw { int ret = common::OB_SUCCESS; - tbutil::Monitor::Lock guard(monitor_); + obutil::ObMonitor::Lock guard(monitor_); if (destroyed_) { ret = common::OB_NOT_INIT; } else if (is_full() && !overwrite) { @@ -111,7 +111,7 @@ int ObRingBuffer::pop(Type& elem) { int ret = common::OB_SUCCESS; - tbutil::Monitor::Lock guard(monitor_); + obutil::ObMonitor::Lock guard(monitor_); while (!destroyed_ && is_empty()) { monitor_.wait(); } @@ -128,9 +128,9 @@ int ObRingBuffer::pop(Type& elem) template void ObRingBuffer::destroy() { - tbutil::Monitor::Lock guard(monitor_); + obutil::ObMonitor::Lock guard(monitor_); if (!destroyed_) { - monitor_.notifyAll(); + monitor_.notify_all(); destroyed_ = true; } } diff --git a/src/election/ob_election_base.cpp b/src/election/ob_election_base.cpp index d6b4ec520e..47bd3dfef0 100644 --- a/src/election/ob_election_base.cpp +++ b/src/election/ob_election_base.cpp @@ -11,9 +11,9 @@ */ #include -#include "lib/lock/Monitor.h" +#include "lib/lock/ob_monitor.h" #include "lib/net/ob_addr.h" -#include "lib/net/tbnetutil.h" +#include "lib/net/ob_net_util.h" #include "ob_election_base.h" #include "ob_election_async_log.h" #include "share/config/ob_server_config.h" @@ -21,7 +21,7 @@ namespace oceanbase { using namespace common; -using namespace tbutil; +using namespace obutil; namespace election { // TODO need check versions @@ -43,12 +43,12 @@ int get_self_addr(ObAddr& self, const char* dev, const int32_t port) ret = OB_INVALID_ARGUMENT; } else { if (GCONF.use_ipv6) { - if (OB_FAIL(obsys::CNetUtil::getLocalAddr6(dev, ipv6, sizeof(ipv6)))) { + if (OB_FAIL(obsys::ObNetUtil::get_local_addr_ipv6(dev, ipv6, sizeof(ipv6)))) { ELECT_ASYNC_LOG(WARN, "get local ipv6 error", K(dev)); ret = OB_INVALID_ARGUMENT; } } else { - if (0 == (ipv4 = obsys::CNetUtil::getLocalAddr(dev))) { + if (0 == (ipv4 = obsys::ObNetUtil::get_local_addr_ipv4(dev))) { ELECT_ASYNC_LOG(WARN, "get local ipv4 error", K(dev)); ret = OB_INVALID_ARGUMENT; } else if (!server.set_ipv4_addr(ipv4, port)) { @@ -153,8 +153,8 @@ const char* ObElectionStageName(ObElectionStage stage) void msleep(int64_t ms) { - tbutil::Monitor monitor_; - (void)monitor_.timedWait(Time(ms * 1000)); + obutil::ObMonitor monitor_; + (void)monitor_.timed_wait(ObSysTime(ms * 1000)); } } // namespace election diff --git a/src/observer/mysql/ob_eliminate_task.cpp b/src/observer/mysql/ob_eliminate_task.cpp index c2f5643ec4..ee1315cc5f 100644 --- a/src/observer/mysql/ob_eliminate_task.cpp +++ b/src/observer/mysql/ob_eliminate_task.cpp @@ -149,7 +149,7 @@ void ObEliminateTask::runTimerTask() } } if (OB_SUCC(ret)) { - int64_t start_time = obsys::CTimeUtil::getTime(); + int64_t start_time = obsys::ObSysTimeUtil::getTime(); int64_t evict_batch_count = 0; // Eliminate by memory if (evict_high_level < allocator->allocated()) { @@ -188,7 +188,7 @@ void ObEliminateTask::runTimerTask() if (true == is_change) { allocator->set_total_limit(config_mem_limit_); } - int64_t end_time = obsys::CTimeUtil::getTime(); + int64_t end_time = obsys::ObSysTimeUtil::getTime(); LOG_INFO("sql audit evict task end", K(evict_high_level), K(evict_batch_count), diff --git a/src/observer/ob_server.cpp b/src/observer/ob_server.cpp index 030f9dc402..a198b8e76e 100644 --- a/src/observer/ob_server.cpp +++ b/src/observer/ob_server.cpp @@ -30,7 +30,7 @@ #include "lib/io/ob_io_benchmark.h" #include "lib/resource/ob_resource_mgr.h" #include "lib/hash_func/murmur_hash.h" -#include "lib/net/tbnetutil.h" +#include "lib/net/ob_net_util.h" #include "lib/alloc/memory_dump.h" #include "share/interrupt/ob_global_interrupt_call.h" #include "rpc/obrpc/ob_rpc_proxy.h" @@ -895,10 +895,10 @@ int ObServer::init_config() int32_t local_port = static_cast(config_.rpc_port); if (config_.use_ipv6) { char ipv6[MAX_IP_ADDR_LENGTH] = {'\0'}; - obsys::CNetUtil::getLocalAddr6(config_.devname, ipv6, sizeof(ipv6)); + obsys::ObNetUtil::get_local_addr_ipv6(config_.devname, ipv6, sizeof(ipv6)); self_addr_.set_ip_addr(ipv6, local_port); } else { - int32_t ipv4 = ntohl(obsys::CNetUtil::getLocalAddr(config_.devname)); + int32_t ipv4 = ntohl(obsys::ObNetUtil::get_local_addr_ipv4(config_.devname)); self_addr_.set_ipv4_addr(ipv4, local_port); } diff --git a/src/observer/omt/ob_tenant_config.cpp b/src/observer/omt/ob_tenant_config.cpp index 603ba10640..0b44b1c9d7 100644 --- a/src/observer/omt/ob_tenant_config.cpp +++ b/src/observer/omt/ob_tenant_config.cpp @@ -14,7 +14,7 @@ #include "ob_tenant_config.h" #include "common/ob_common_utility.h" -#include "lib/net/tbnetutil.h" +#include "lib/net/ob_net_util.h" #include "lib/oblog/ob_log.h" #include "share/config/ob_server_config.h" #include "share/schema/ob_schema_getter_guard.h" @@ -122,7 +122,7 @@ int ObTenantConfig::read_config() ObAddr server; char local_ip[OB_MAX_SERVER_ADDR_SIZE] = ""; ObLatchWGuard wr_guard(lock_, ObLatchIds::CONFIG_LOCK); - if (!server.set_ipv4_addr(ntohl(obsys::CNetUtil::getLocalAddr(GCONF.devname)), 0)) { + if (!server.set_ipv4_addr(ntohl(obsys::ObNetUtil::get_local_addr_ipv4(GCONF.devname)), 0)) { ret = OB_INVALID_ARGUMENT; } else if (OB_UNLIKELY(true != server.ip_to_string(local_ip, sizeof(local_ip)))) { ret = OB_CONVERT_ERROR; @@ -239,7 +239,7 @@ int ObTenantConfig::got_version(int64_t version, const bool remove_repeat) } else if (version < current_version_) { LOG_WARN("Local tenant config is newer than rs, weird", K_(current_version), K(version)); } else if (version > current_version_) { - if (!mutex_.tryLock()) { + if (!mutex_.trylock()) { LOG_DEBUG("Processed by other thread!"); } else { if (version > newest_version_) { @@ -247,7 +247,7 @@ int ObTenantConfig::got_version(int64_t version, const bool remove_repeat) newest_version_ = version; update_task_.update_local_ = true; update_task_.version_ = version; - update_task_.scheduled_time_ = obsys::CTimeUtil::getMonotonicTime(); + update_task_.scheduled_time_ = obsys::ObSysTimeUtil::getMonotonicTime(); schedule_task = true; } else if (version < newest_version_) { LOG_WARN("Receive weird tenant config version", K_(current_version), K_(newest_version), K(version)); diff --git a/src/observer/omt/ob_tenant_config.h b/src/observer/omt/ob_tenant_config.h index cd9546b79e..5e5bc850d3 100644 --- a/src/observer/omt/ob_tenant_config.h +++ b/src/observer/omt/ob_tenant_config.h @@ -67,7 +67,7 @@ public: volatile int64_t version_; volatile int64_t scheduled_time_; bool update_local_; - tbutil::Mutex task_lock_; + obutil::Mutex task_lock_; bool is_running_; }; friend class TenantConfigUpdateTask; @@ -127,7 +127,7 @@ private: int64_t current_version_; // currently processed task version int64_t newest_version_; volatile int64_t running_task_count_; - tbutil::Mutex mutex_; + obutil::Mutex mutex_; TenantConfigUpdateTask update_task_; common::ObSystemConfig system_config_; ObTenantConfigMgr* config_mgr_; diff --git a/src/observer/omt/ob_tenant_config_mgr.cpp b/src/observer/omt/ob_tenant_config_mgr.cpp index 0e8276be74..1e407171d9 100644 --- a/src/observer/omt/ob_tenant_config_mgr.cpp +++ b/src/observer/omt/ob_tenant_config_mgr.cpp @@ -228,8 +228,7 @@ int ObTenantConfigMgr::del_tenant_config(uint64_t tenant_id) } else if (OB_FAIL(config_map_.get_refactored(ObTenantID(tenant_id), config))) { LOG_WARN("get tenant config failed", K(tenant_id), K(ret)); } else if (OB_SUCC(GCTX.omt_->get_tenant(tenant_id, tenant))) { - // https://work.aone.alibaba-inc.com/issue/31717023 - // 判断租户是否在这台机器上,避免启动时没有刷到租户时删掉了租户配置项 + // check tenant is exist in this server, to avoid tenant has been deleted before config has been refresh LOG_WARN("tenant still exist, try to delete tenant config later...", K(tenant_id)); } else { static const int DEL_TRY_TIMES = 30; @@ -507,7 +506,7 @@ int ObTenantConfigMgr::cancel(const ObTenantConfig::TenantConfigUpdateTask& task LOG_WARN("cancel tenant config update task failed", K(ret)); } else { for (int i = 0; i < try_times; ++i) { - if (task.task_lock_.tryLock()) { + if (task.task_lock_.trylock()) { if (!task.is_running_) { task.task_lock_.unlock(); break; diff --git a/src/observer/omt/ob_tenant_timezone.cpp b/src/observer/omt/ob_tenant_timezone.cpp index a64dbba357..c3606ce671 100644 --- a/src/observer/omt/ob_tenant_timezone.cpp +++ b/src/observer/omt/ob_tenant_timezone.cpp @@ -13,7 +13,7 @@ #define USING_LOG_PREFIX SERVER_OMT #include "common/ob_common_utility.h" -#include "lib/net/tbnetutil.h" +#include "lib/net/ob_net_util.h" #include "lib/oblog/ob_log.h" #include "share/schema/ob_schema_getter_guard.h" #include "observer/ob_server_struct.h" @@ -82,7 +82,7 @@ int ObTenantTimezone::init(ObTenantTimezoneMgr* tz_mgr) void ObTenantTimezone::TenantTZUpdateTask::runTimerTask() { int ret = OB_SUCCESS; - if (task_lock_.tryLock()) { + if (task_lock_.trylock()) { if (!tenant_tz_mgr_->get_start_refresh()) { const int64_t delay = 1 * 1000 * 1000; const bool repeat = false; diff --git a/src/observer/omt/ob_tenant_timezone.h b/src/observer/omt/ob_tenant_timezone.h index 035a0b83dc..ce459c2fc0 100644 --- a/src/observer/omt/ob_tenant_timezone.h +++ b/src/observer/omt/ob_tenant_timezone.h @@ -46,7 +46,7 @@ public: void runTimerTask(void) override; ObTenantTimezoneMgr* tenant_tz_mgr_; ObTenantTimezone* tenant_tz_; - tbutil::Mutex task_lock_; + obutil::Mutex task_lock_; const uint64_t SLEEP_USECONDS = 5000000; }; friend class TenantTZUpdateTask; diff --git a/src/observer/omt/ob_tenant_timezone_mgr.cpp b/src/observer/omt/ob_tenant_timezone_mgr.cpp index 3a4876a51e..826fa20fb4 100644 --- a/src/observer/omt/ob_tenant_timezone_mgr.cpp +++ b/src/observer/omt/ob_tenant_timezone_mgr.cpp @@ -354,7 +354,7 @@ int ObTenantTimezoneMgr::delete_tenant_timezone() bool locked = false; // waiting for running task with lock finished for (int64_t j = 0; j < try_times; ++j) { - if (task.task_lock_.tryLock()) { + if (task.task_lock_.trylock()) { locked = true; break; } diff --git a/src/share/allocator/ob_tenant_mutil_allocator_mgr.cpp b/src/share/allocator/ob_tenant_mutil_allocator_mgr.cpp index bd82e55815..6c2ae008ed 100644 --- a/src/share/allocator/ob_tenant_mutil_allocator_mgr.cpp +++ b/src/share/allocator/ob_tenant_mutil_allocator_mgr.cpp @@ -82,7 +82,7 @@ int ObTenantMutilAllocatorMgr::get_tenant_mutil_allocator( bool is_need_create = false; do { // rdlock - obsys::CRLockGuard guard(locks_[slot]); + obsys::ObRLockGuard guard(locks_[slot]); TMA** cur = &tma_array_[slot]; while ((NULL != cur) && (NULL != *cur) && (*cur)->get_tenant_id() < tenant_id) { cur = &((*cur)->get_next()); @@ -177,7 +177,7 @@ int ObTenantMutilAllocatorMgr::create_tenant_mutil_allocator_(const uint64_t ten } do { // Need lock when modify slog list - obsys::CWLockGuard guard(locks_[slot]); + obsys::ObWLockGuard guard(locks_[slot]); if (OB_SUCC(ret)) { bool is_need_create = false; TMA** cur = &tma_array_[slot]; diff --git a/src/share/allocator/ob_tenant_mutil_allocator_mgr.h b/src/share/allocator/ob_tenant_mutil_allocator_mgr.h index cdc60dcdc0..a790a6cdb9 100644 --- a/src/share/allocator/ob_tenant_mutil_allocator_mgr.h +++ b/src/share/allocator/ob_tenant_mutil_allocator_mgr.h @@ -68,7 +68,7 @@ private: private: bool is_inited_; - obsys::CRWLock locks_[PRESERVED_TENANT_COUNT]; + obsys::ObRWLock locks_[PRESERVED_TENANT_COUNT]; ObTenantMutilAllocator* tma_array_[PRESERVED_TENANT_COUNT]; ObBlockAllocMgr clog_body_blk_alloc_; ObVSliceAlloc clog_entry_alloc_; diff --git a/src/share/config/ob_config_manager.cpp b/src/share/config/ob_config_manager.cpp index 3e81358483..52f9b7d66b 100644 --- a/src/share/config/ob_config_manager.cpp +++ b/src/share/config/ob_config_manager.cpp @@ -415,7 +415,7 @@ int ObConfigManager::got_version(int64_t version, const bool remove_repeat /* = if (schedule) { update_task_.version_ = version; - update_task_.scheduled_time_ = obsys::CTimeUtil::getMonotonicTime(); + update_task_.scheduled_time_ = obsys::ObSysTimeUtil::getMonotonicTime(); if (OB_FAIL(TG_SCHEDULE(lib::TGDefIDs::CONFIG_MGR, update_task_, 0, false))) { LOG_ERROR("Update local config failed", K(ret)); } else { diff --git a/src/share/config/ob_config_manager.h b/src/share/config/ob_config_manager.h index 8b5bbd4d41..ecdfbfca97 100644 --- a/src/share/config/ob_config_manager.h +++ b/src/share/config/ob_config_manager.h @@ -89,7 +89,7 @@ private: int64_t current_version_; char dump_path_[OB_MAX_FILE_NAME_LENGTH]; ObReloadConfig& reload_config_func_; - tbutil::Mutex mutex_; + obutil::Mutex mutex_; DISALLOW_COPY_AND_ASSIGN(ObConfigManager); }; diff --git a/src/share/config/ob_server_config.cpp b/src/share/config/ob_server_config.cpp index a605ac0d6e..24422f672e 100644 --- a/src/share/config/ob_server_config.cpp +++ b/src/share/config/ob_server_config.cpp @@ -18,6 +18,7 @@ #include "common/ob_common_utility.h" #include "lib/mysqlclient/ob_isql_client.h" #include "lib/utility/utility.h" +#include "lib/net/ob_net_util.h" #include "common/ob_record_header.h" #include "common/ob_zone.h" #include "share/ob_dml_sql_splicer.h" diff --git a/src/storage/memtable/ob_lock_wait_mgr.cpp b/src/storage/memtable/ob_lock_wait_mgr.cpp index e2ff49c6ef..70aa7e2a3e 100644 --- a/src/storage/memtable/ob_lock_wait_mgr.cpp +++ b/src/storage/memtable/ob_lock_wait_mgr.cpp @@ -195,7 +195,7 @@ void ObLockWaitMgr::wakeup(uint64_t hash) if (NULL != node) { EVENT_INC(MEMSTORE_WRITE_LOCK_WAKENUP_COUNT); - EVENT_ADD(MEMSTORE_WAIT_WRITE_LOCK_TIME, obsys::CTimeUtil::getTime() - node->lock_ts_); + EVENT_ADD(MEMSTORE_WAIT_WRITE_LOCK_TIME, obsys::ObSysTimeUtil::getTime() - node->lock_ts_); node->on_retry_lock(hash); (void)repost(node); @@ -231,7 +231,7 @@ ObLockWaitMgr::Node* ObLockWaitMgr::fetch_waiter(uint64_t hash) // we do not need to wake up if the request is not running while (NULL != node && node->hash() <= hash) { if (node->hash() == hash) { - if (node->get_run_ts() > obsys::CTimeUtil::getTime()) { + if (node->get_run_ts() > obsys::ObSysTimeUtil::getTime()) { // wake up the first task whose execution time is not yet break; } else { @@ -287,7 +287,7 @@ ObLink* ObLockWaitMgr::check_timeout() // it needs to be placed before the judgment of session_id to prevent the // abnormal case which session_id equals 0 from causing the problem of missing wakeup } else if (iter->is_standalone_task() || - (iter->get_run_ts() > 0 && obsys::CTimeUtil::getTime() > iter->get_run_ts())) { + (iter->get_run_ts() > 0 && obsys::ObSysTimeUtil::getTime() > iter->get_run_ts())) { node2del = iter; need_check_session = true; // it is desgined to fix the case once the lock_for_write does not try @@ -376,7 +376,7 @@ void ObLockWaitMgr::retire_node(ObLink*& tail, Node* node) int err = 0; Node* tmp_node = NULL; EVENT_INC(MEMSTORE_WRITE_LOCK_WAKENUP_COUNT); - EVENT_ADD(MEMSTORE_WAIT_WRITE_LOCK_TIME, obsys::CTimeUtil::getTime() - node->lock_ts_); + EVENT_ADD(MEMSTORE_WAIT_WRITE_LOCK_TIME, obsys::ObSysTimeUtil::getTime() - node->lock_ts_); while (-EAGAIN == (err = hash_.del(node, tmp_node))) ; if (0 == err) { @@ -394,7 +394,7 @@ void ObLockWaitMgr::delay_header_node_run_ts(const Key& key) if (NULL != node && !node->is_dummy()) { // delay the execution of the header node by 10ms to ensure that the remote // request can be executed successfully - node->update_run_ts(obsys::CTimeUtil::getTime() + 50 * 1000); + node->update_run_ts(obsys::ObSysTimeUtil::getTime() + 50 * 1000); TRANS_LOG(INFO, "LOCK_MGR: delay header node"); } } diff --git a/src/storage/ob_partition_scheduler.cpp b/src/storage/ob_partition_scheduler.cpp index 9081f71a97..de42db14a2 100644 --- a/src/storage/ob_partition_scheduler.cpp +++ b/src/storage/ob_partition_scheduler.cpp @@ -389,7 +389,7 @@ int ObMergeStatistic::notify_merge_start(const int64_t frozen_version) ret = OB_INVALID_ARGUMENT; LOG_WARN("Invalid argument, ", K(frozen_version), K(ret)); } else { - obsys::CWLockGuard guard(lock_); + obsys::ObWLockGuard guard(lock_); if (OB_FAIL(search_entry(frozen_version, pentry))) { if (OB_ENTRY_NOT_EXIST == ret) { pentry = &(stats_[frozen_version % MAX_KEPT_HISTORY]); @@ -419,7 +419,7 @@ int ObMergeStatistic::notify_merge_finish(const int64_t frozen_version) ret = OB_INVALID_ARGUMENT; LOG_WARN("Invalid argument, ", K(frozen_version), K(ret)); } else { - obsys::CWLockGuard guard(lock_); + obsys::ObWLockGuard guard(lock_); if (OB_FAIL(search_entry(frozen_version, pentry))) { LOG_WARN("Fail to search entry, ", K(ret)); } else if (OB_ISNULL(pentry)) { @@ -450,7 +450,7 @@ int ObMergeStatistic::get_entry(const int64_t frozen_version, ObMergeStatEntry& ret = OB_INVALID_ARGUMENT; LOG_WARN("Invalid argument, ", K(frozen_version), K(ret)); } else { - obsys::CRLockGuard guard(lock_); + obsys::ObRLockGuard guard(lock_); if (OB_FAIL(search_entry(frozen_version, pentry))) { if (OB_ENTRY_NOT_EXIST == ret) { entry.reset(); @@ -771,7 +771,7 @@ int ObPartitionScheduler::schedule_merge(const int64_t frozen_version) ret = OB_INVALID_ARGUMENT; LOG_WARN("Invalid argument, ", K(frozen_version), K(ret)); } else { - obsys::CWLockGuard frozen_version_guard(frozen_version_lock_); + obsys::ObWLockGuard frozen_version_guard(frozen_version_lock_); lib::ObMutexGuard merge_guard(timer_lock_); if (frozen_version_ < frozen_version) { TG_CANCEL(lib::TGDefIDs::MinorScan, minor_task_for_major_); @@ -813,7 +813,7 @@ int ObPartitionScheduler::schedule_merge(const ObPartitionKey& partition_key, bo LOG_WARN("Invalid argument, ", K(partition_key), K(ret)); } else { { - obsys::CRLockGuard frozen_version_guard(frozen_version_lock_); + obsys::ObRLockGuard frozen_version_guard(frozen_version_lock_); frozen_version = frozen_version_; } @@ -1010,7 +1010,7 @@ int ObPartitionScheduler::schedule_load_bloomfilter( int64_t ObPartitionScheduler::get_frozen_version() const { - obsys::CRLockGuard frozen_version_guard(frozen_version_lock_); + obsys::ObRLockGuard frozen_version_guard(frozen_version_lock_); return frozen_version_; } @@ -1726,7 +1726,7 @@ int ObPartitionScheduler::check_all_partitions(bool& check_finished, common::ObV ret = OB_EAGAIN; } else { { - obsys::CRLockGuard frozen_version_guard(frozen_version_lock_); + obsys::ObRLockGuard frozen_version_guard(frozen_version_lock_); frozen_version = frozen_version_; } // skip the partition which check failed @@ -1928,7 +1928,7 @@ int ObPartitionScheduler::schedule_all_partitions(bool& merge_finished, common:: } else { // get frozen_version { - obsys::CRLockGuard frozen_version_guard(frozen_version_lock_); + obsys::ObRLockGuard frozen_version_guard(frozen_version_lock_); frozen_version = frozen_version_; } @@ -2313,7 +2313,7 @@ int ObPartitionScheduler::notify_minor_merge_start(const uint64_t tenant_id, con int ret = OB_SUCCESS; ObMinorMergeHistory* history = nullptr; { - obsys::CRLockGuard lock_guard(frozen_version_lock_); + obsys::ObRLockGuard lock_guard(frozen_version_lock_); if (OB_FAIL(minor_merge_his_map_.get_refactored(tenant_id, history))) { if (OB_HASH_NOT_EXIST != ret) { LOG_WARN("failed to get minor merge history", K(ret), K(tenant_id), K(snapshot_version)); @@ -2322,7 +2322,7 @@ int ObPartitionScheduler::notify_minor_merge_start(const uint64_t tenant_id, con } } if (OB_UNLIKELY(OB_HASH_NOT_EXIST == ret)) { - obsys::CWLockGuard lock_guard(frozen_version_lock_); + obsys::ObWLockGuard lock_guard(frozen_version_lock_); if (OB_FAIL(minor_merge_his_map_.get_refactored(tenant_id, history))) { if (OB_HASH_NOT_EXIST == ret) { void* buf = nullptr; @@ -2357,7 +2357,7 @@ int ObPartitionScheduler::notify_minor_merge_finish(const uint64_t tenant_id, co int ret = OB_SUCCESS; ObMinorMergeHistory* history = nullptr; { - obsys::CRLockGuard lock_guard(frozen_version_lock_); + obsys::ObRLockGuard lock_guard(frozen_version_lock_); if (OB_FAIL(minor_merge_his_map_.get_refactored(tenant_id, history))) { if (OB_HASH_NOT_EXIST != ret) { LOG_WARN("failed to get minor merge history", K(ret), K(tenant_id), K(snapshot_version)); diff --git a/src/storage/ob_partition_scheduler.h b/src/storage/ob_partition_scheduler.h index f183751dc5..c3e4a955a1 100644 --- a/src/storage/ob_partition_scheduler.h +++ b/src/storage/ob_partition_scheduler.h @@ -102,7 +102,7 @@ public: private: int search_entry(const int64_t frozen_version, ObMergeStatEntry*& pentry); static const int64_t MAX_KEPT_HISTORY = 16; - obsys::CRWLock lock_; + obsys::ObRWLock lock_; ObMergeStatEntry stats_[MAX_KEPT_HISTORY]; private: @@ -371,7 +371,7 @@ private: int64_t failure_fast_retry_interval_us_; int64_t minor_merge_schedule_interval_; ObMergeStatistic merge_statistic_; - mutable obsys::CRWLock frozen_version_lock_; + mutable obsys::ObRWLock frozen_version_lock_; mutable lib::ObMutex timer_lock_; bool first_most_merged_; bool inited_; diff --git a/src/storage/transaction/ob_time_wheel.cpp b/src/storage/transaction/ob_time_wheel.cpp index 0e31ed4f36..afe7b8fd8d 100644 --- a/src/storage/transaction/ob_time_wheel.cpp +++ b/src/storage/transaction/ob_time_wheel.cpp @@ -19,7 +19,7 @@ namespace oceanbase { namespace common { -using namespace tbutil; +using namespace obutil; void ObTimeWheelTask::reset() { diff --git a/src/storage/transaction/ob_trans_result.cpp b/src/storage/transaction/ob_trans_result.cpp index e35aed71e6..bbe04c8bbd 100644 --- a/src/storage/transaction/ob_trans_result.cpp +++ b/src/storage/transaction/ob_trans_result.cpp @@ -18,7 +18,7 @@ namespace oceanbase { namespace transaction { using namespace common; -using namespace tbutil; +using namespace obutil; void ObTransCond::reset() { @@ -51,10 +51,10 @@ int ObTransCond::wait(const int64_t wait_time_us, int& result) int64_t start_time_us = ObClockGenerator::getClock(); THIS_WORKER.sched_wait(); { - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); while (!finished_ && OB_SUCC(ret)) { left_time_us = wait_time_us - (ObClockGenerator::getClock() - start_time_us); - if (left_time_us <= 0 || !monitor_.timedWait(Time(left_time_us))) { // timeout + if (left_time_us <= 0 || !monitor_.timed_wait(ObSysTime(left_time_us))) { // timeout ret = OB_TIMEOUT; } } @@ -71,21 +71,21 @@ int ObTransCond::wait(const int64_t wait_time_us, int& result) // set transaction result by transaction context void ObTransCond::notify(const int result) { - Monitor::Lock guard(monitor_); + ObMonitor::Lock guard(monitor_); if (finished_) { TRANS_LOG(DEBUG, "transaction has already get result", "old_result", result_, "new_result", result); } finished_ = true; result_ = result; - monitor_.notifyAll(); + monitor_.notify_all(); } void ObTransCond::usleep(const int64_t us) { if (us > 0) { - Monitor monitor; + ObMonitor monitor; THIS_WORKER.sched_wait(); - (void)monitor.timedWait(Time(us)); + (void)monitor.timed_wait(ObSysTime(us)); THIS_WORKER.sched_run(); } } diff --git a/src/storage/transaction/ob_trans_result.h b/src/storage/transaction/ob_trans_result.h index de690437f2..ed7a18e5d8 100644 --- a/src/storage/transaction/ob_trans_result.h +++ b/src/storage/transaction/ob_trans_result.h @@ -14,8 +14,8 @@ #define OCEANBASE_TRANSACTION_OB_TRANS_COND_ #include -#include "lib/lock/Monitor.h" -#include "lib/lock/Mutex.h" +#include "lib/lock/ob_monitor.h" +#include "lib/lock/mutex.h" #include "share/ob_define.h" namespace oceanbase { @@ -48,7 +48,7 @@ private: private: bool finished_; - mutable tbutil::Monitor monitor_; + mutable obutil::ObMonitor monitor_; int result_; }; diff --git a/unittest/election/test_election_base.cpp b/unittest/election/test_election_base.cpp index 317dc01b56..8d374bc3d8 100644 --- a/unittest/election/test_election_base.cpp +++ b/unittest/election/test_election_base.cpp @@ -15,7 +15,7 @@ #include "common/ob_clock_generator.h" #include "election/ob_election_async_log.h" #include "lib/net/ob_addr.h" -#include "lib/net/tbnetutil.h" +#include "lib/net/ob_net_util.h" #include "election/ob_election_base.h" namespace oceanbase { @@ -55,7 +55,7 @@ TEST_F(TestObElectionBase, get_self_addr) if (ifa->ifa_addr->sa_family == AF_INET) { const char *dev = ifa->ifa_name; EXPECT_EQ(OB_SUCCESS, get_self_addr(addr, dev, port)); - uint32_t ip = obsys::CNetUtil::getLocalAddr(dev); + uint32_t ip = obsys::ObNetUtil::get_local_addr_ipv4(dev); EXPECT_EQ(ip, addr.get_ipv4()); EXPECT_EQ(port, addr.get_port()); } diff --git a/unittest/share/schema/test_priv_mgr.cpp b/unittest/share/schema/test_priv_mgr.cpp index 63de065383..231d3b19b6 100644 --- a/unittest/share/schema/test_priv_mgr.cpp +++ b/unittest/share/schema/test_priv_mgr.cpp @@ -37,7 +37,7 @@ protected: void TestPrivMgr::SetUp() { - // obsys::CConfig c1; + // obsys::ObSysConfig c1; // priv_mgr_.init(); } diff --git a/unittest/share/test_latch.cpp b/unittest/share/test_latch.cpp index 69c56b4722..dc792da9e2 100644 --- a/unittest/share/test_latch.cpp +++ b/unittest/share/test_latch.cpp @@ -30,7 +30,7 @@ public: int64_t round0_; int64_t value0_; ObLatch lock0_; - obsys::CRWLock lock_; + obsys::ObRWLock lock_; pthread_mutex_t mutex_; }; @@ -70,7 +70,7 @@ void TestLatchStress::run(obsys::CThread* thread, void* arg) // ASSERT_EQ(0, ret); // pthread_mutex_unlock(&mutex_); - // obsys::CWLockGuard guard(lock_); + // obsys::ObWLockGuard guard(lock_); // ASSERT_EQ(OB_SUCCESS, ret); } } else { @@ -91,7 +91,7 @@ void TestLatchStress::run(obsys::CThread* thread, void* arg) // ASSERT_EQ(0, ret); // pthread_mutex_unlock(&mutex_); - // obsys::CRLockGuard guard(lock_); + // obsys::ObRLockGuard guard(lock_); // ASSERT_EQ(OB_SUCCESS, ret); } } diff --git a/unittest/sql/executor/ob_mock_utils.h b/unittest/sql/executor/ob_mock_utils.h index 115c521c6f..a319192834 100644 --- a/unittest/sql/executor/ob_mock_utils.h +++ b/unittest/sql/executor/ob_mock_utils.h @@ -103,7 +103,7 @@ public: private: static ObMockPacketQueueThread* instance_; - static tbutil::Mutex locker_; + static obutil::Mutex locker_; }; } // namespace sql diff --git a/unittest/sql/parser/test_parser_perf.cpp b/unittest/sql/parser/test_parser_perf.cpp index f27f1bc079..4e4fa2216b 100644 --- a/unittest/sql/parser/test_parser_perf.cpp +++ b/unittest/sql/parser/test_parser_perf.cpp @@ -61,9 +61,9 @@ void TestParserPerf::do_parse(const char* query_str) parse_result.is_fp_ = IS_FP; ObString query = ObString::make_string(query_str); int ret = OB_SUCCESS; - t0 = obsys::CTimeUtil::getTime(); + t0 = obsys::ObSysTimeUtil::getTime(); ret = parser.parse(query, parse_result, pmode); - t1 = obsys::CTimeUtil::getTime(); + t1 = obsys::ObSysTimeUtil::getTime(); if (OB_SUCC(ret)) { succ_cnt_++; } diff --git a/unittest/storage/mockcontainer/mock_ob_server.cpp b/unittest/storage/mockcontainer/mock_ob_server.cpp index e4cbaae1e5..3fcd8d12fc 100644 --- a/unittest/storage/mockcontainer/mock_ob_server.cpp +++ b/unittest/storage/mockcontainer/mock_ob_server.cpp @@ -18,7 +18,7 @@ #include "lib/string/ob_sql_string.h" #include "lib/io/ob_io_manager.h" -#include "lib/net/tbnetutil.h" +#include "lib/net/ob_net_util.h" #include "rpc/obrpc/ob_rpc_proxy.h" #include "share/schema/ob_multi_version_schema_service.h" #include "share/partition_table/ob_partition_info.h" @@ -90,7 +90,7 @@ int MockObServer::init( ret = OB_ELECTION_ASYNC_LOG_WARN_INIT; } - int32_t local_ip = ntohl(obsys::CNetUtil::getLocalAddr(config_.devname)); + int32_t local_ip = ntohl(obsys::ObNetUtil::get_local_addr_ipv4(config_.devname)); int32_t local_port = static_cast(config_.rpc_port); config_.print();