提交 68cd5587 编写于 作者: L ly0 提交者: LINGuanRen

patch tair code removing from 22x to 31CE

上级 518fd355
......@@ -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"
......
......@@ -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<tbutil::Mutex> monitor_;
(void)monitor_.timedWait(tbutil::Time(ms * 1000));
obutil::ObMonitor<obutil::Mutex> monitor_;
(void)monitor_.timed_wait(obutil::ObSysTime(ms * 1000));
}
}
inline void ObClockGenerator::usleep(const int64_t us)
{
if (us > 0) {
tbutil::Monitor<tbutil::Mutex> monitor_;
(void)monitor_.timedWait(tbutil::Time(us));
obutil::ObMonitor<obutil::Mutex> monitor_;
(void)monitor_.timed_wait(obutil::ObSysTime(us));
}
}
......
......@@ -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
......
......@@ -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) {
......
......@@ -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_;
......
/**
* 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
/**
* 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<char>((*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<char>((*p) - 32);
}
p++;
}
return pszBuf;
}
void ObStringUtil::split(char *str, const char *delim, std::vector<char*> &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);
}
}
}
......@@ -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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <string>
#include <time.h>
#include <vector>
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<char *> &list);
};
} // namespace obsys
} // namespace oceanbase
#endif
}
//////////////////END
#endif
/**
* 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 T>
class Monitor {
public:
typedef LockT<Monitor<T> > Lock;
typedef TryLockT<Monitor<T> > 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 <class T>
Monitor<T>::Monitor() : _nnotify(0)
{}
template <class T>
Monitor<T>::~Monitor()
{}
template <class T>
inline void Monitor<T>::lock() const
{
_mutex.lock();
if (_mutex.willUnlock()) {
_nnotify = 0;
}
}
template <class T>
inline void Monitor<T>::unlock() const
{
if (_mutex.willUnlock()) {
notifyImpl(_nnotify);
}
_mutex.unlock();
}
template <class T>
inline bool Monitor<T>::tryLock() const
{
bool result = _mutex.tryLock();
if (result && _mutex.willUnlock()) {
_nnotify = 0;
}
return result;
}
template <class T>
inline bool Monitor<T>::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 <class T>
inline bool Monitor<T>::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 <class T>
inline void Monitor<T>::notify()
{
if (_nnotify != -1) {
++_nnotify;
}
}
template <class T>
inline void Monitor<T>::notifyAll()
{
_nnotify = -1;
}
template <class T>
inline void Monitor<T>::notifyImpl(int nnotify) const
{
if (nnotify != 0) {
if (nnotify == -1) {
_cond.broadcast();
return;
} else {
while (nnotify > 0) {
_cond.signal();
--nnotify;
}
}
}
}
} // namespace tbutil
#endif
/**
* 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
/**
* 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 <pthread.h>
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<RecMutex> Lock;
typedef TryLockT<RecMutex> 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
......@@ -11,9 +11,9 @@
*/
#include <sys/time.h>
#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
......@@ -9,88 +9,66 @@
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef TBSYS_COND_H
#define TBSYS_COND_H
#ifndef COND_H
#define COND_H
#include "lib/time/Time.h"
#include "lib/ob_define.h"
#include "lib/oblog/ob_log.h"
namespace tbutil {
template <class T>
class Monitor;
namespace obutil
{
template<class T> class ObMonitor;
class Mutex;
class RecMutex;
/**
* @brief Condition variable of linux-thread
*/
class Cond {
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 <typename Lock>
inline bool wait(const Lock& lock) const
template <typename Lock> inline bool
wait(const Lock& lock) const
{
bool ret = false;
if (!lock.acquired()) {
_OB_LOG(ERROR, "%s", "ThreadLockedException");
return false;
_OB_LOG(ERROR,"%s","ThreadLockedException");
ret = false;
} else {
ret = wait_impl(lock._mutex);
}
return waitImpl(lock._mutex);
return ret;
}
/**
* @brief Thread blocking waiting with timeout
*
* @param lock
* @param timeout
*
* @return
*/
template <typename Lock>
inline bool timedWait(const Lock& lock, const Time& timeout) const
template <typename Lock> inline bool
timed_wait(const Lock& lock, const ObSysTime& timeout) const
{
bool ret = false;
if (!lock.acquired()) {
_OB_LOG(ERROR, "%s", "ThreadLockedException");
return false;
_OB_LOG(ERROR,"%s","ThreadLockedException");
ret = false;
} else {
ret = timed_wait_impl(lock._mutex, timeout);
}
return timedWaitImpl(lock._mutex, timeout);
return ret;
}
private:
DISALLOW_COPY_AND_ASSIGN(Cond);
private:
friend class Monitor<Mutex>;
friend class Monitor<RecMutex>;
template <typename M>
bool waitImpl(const M&) const;
template <typename M>
bool timedWaitImpl(const M&, const Time&) const;
friend class ObMonitor<Mutex>;
template <typename M> bool wait_impl(const M&) const;
template <typename M> bool timed_wait_impl(const M&, const ObSysTime&) const;
mutable pthread_cond_t _cond;
};
template <typename M>
inline bool Cond::waitImpl(const M& mutex) const
template <typename M> inline bool
Cond::wait_impl(const M& mutex) const
{
bool ret = true;
typedef typename M::LockState LockState;
LockState state;
......@@ -98,44 +76,45 @@ inline bool Cond::waitImpl(const M& mutex) const
const int rc = pthread_cond_wait(&_cond, state.mutex);
mutex.lock(state);
if (0 != rc) {
_OB_LOG(ERROR, "%s", "ThreadSyscallException");
return false;
if ( 0 != rc ) {
_OB_LOG(ERROR,"%s","ThreadSyscallException");
ret = false;
}
return true;
return ret;
}
template <typename M>
inline bool Cond::timedWaitImpl(const M& mutex, const Time& timeout) const
template <typename M> inline bool
Cond::timed_wait_impl(const M& mutex, const ObSysTime& 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;
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 true;
return ret;
}
} // namespace tbutil
}// end namespace
#endif
......@@ -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
......@@ -9,61 +9,36 @@
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef TBSYS_MUTEX_H
#define TBSYS_MUTEX_H
#ifndef MUTEX_H
#define MUTEX_H
#include <pthread.h>
#include "lib/lock/Lock.h"
#include "lib/lock/ob_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 {
namespace obutil
{
class Mutex
{
public:
typedef LockT<Mutex> Lock;
typedef TryLockT<Mutex> TryLock;
typedef ObLockT<Mutex> Lock;
typedef ObTryLockT<Mutex> 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
*/
bool trylock() const;
void unlock() const;
/**
* @brief Whether it has been locked
*
* @return
*/
bool willUnlock() const;
bool will_unlock() const;
private:
Mutex(const Mutex&);
Mutex& operator=(const Mutex&);
struct LockState {
struct LockState
{
pthread_mutex_t* mutex;
};
......@@ -73,5 +48,5 @@ private:
friend class Cond;
};
} // namespace tbutil
}//end namespace
#endif
......@@ -9,103 +9,107 @@
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef TBSYS_LOCK_H
#define TBSYS_LOCK_H
#ifndef OB_LOCK_H
#define OB_LOCK_H
#include <assert.h>
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
*/
namespace obutil
{
template <typename T>
class LockT {
class ObLockT
{
public:
explicit LockT(const T& mutex) : _mutex(mutex)
explicit ObLockT(const T& mutex) :
mutex_(mutex)
{
_mutex.lock();
_acquired = true;
mutex_.lock();
acquired_ = true;
}
~LockT()
~ObLockT()
{
if (_acquired) {
_mutex.unlock();
if (acquired_)
{
mutex_.unlock();
}
}
void acquire() const
{
if (_acquired) {
if (acquired_)
{
#ifdef _NO_EXCEPTION
assert(!"ThreadLockedException");
assert(!"ThreadLockedException");
#else
throw ThreadLockedException(__FILE__, __LINE__);
throw ThreadLockedException(__FILE__, __LINE__);
#endif
}
_mutex.lock();
_acquired = true;
mutex_.lock();
acquired_ = true;
}
bool tryAcquire() const
bool try_acquire() const
{
if (_acquired) {
if (acquired_)
{
#ifdef _NO_EXCEPTION
assert(!"ThreadLockedException");
#else
throw ThreadLockedException(__FILE__, __LINE__);
#endif
}
_acquired = _mutex.tryLock();
return _acquired;
acquired_ = mutex_.trylock();
return acquired_;
}
void release() const
{
if (!_acquired) {
if (!acquired_)
{
#ifdef _NO_EXCEPTION
assert(!"ThreadLockedException");
#else
throw ThreadLockedException(__FILE__, __LINE__);
#endif
}
_mutex.unlock();
_acquired = false;
mutex_.unlock();
acquired_ = false;
}
bool acquired() const
{
return _acquired;
return acquired_;
}
protected:
LockT(const T& mutex, bool) : _mutex(mutex)
ObLockT(const T& mutex, bool) :
mutex_(mutex)
{
_acquired = _mutex.tryLock();
acquired_ = mutex_.trylock();
}
private:
LockT(const LockT&);
LockT& operator=(const LockT&);
const T& _mutex;
mutable bool _acquired;
ObLockT(const ObLockT&);
ObLockT& operator=(const ObLockT&);
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 <typename T>
class TryLockT : public LockT<T> {
class ObTryLockT : public ObLockT<T>
{
public:
TryLockT(const T& mutex) : LockT<T>(mutex, true)
ObTryLockT(const T& mutex) :
ObLockT<T>(mutex, true)
{}
};
} // namespace tbutil
}
#endif
/**
* 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 T>
class ObMonitor
{
public:
typedef ObLockT<ObMonitor<T> > Lock;
typedef ObTryLockT<ObMonitor<T> > 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 <class T>
ObMonitor<T>::ObMonitor() :
nnotify_(0)
{
}
template <class T>
ObMonitor<T>::~ObMonitor()
{
}
template <class T> inline void
ObMonitor<T>::lock() const
{
mutex_.lock();
if(mutex_.will_unlock()) {
nnotify_ = 0;
}
}
template <class T> inline void
ObMonitor<T>::unlock() const
{
if(mutex_.will_unlock()) {
notify_impl(nnotify_);
}
mutex_.unlock();
}
template <class T> inline bool
ObMonitor<T>::trylock() const
{
bool result = mutex_.trylock();
if(result && mutex_.will_unlock()) {
nnotify_ = 0;
}
return result;
}
template <class T> inline bool
ObMonitor<T>::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 <class T> inline bool
ObMonitor<T>::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 <class T> inline void
ObMonitor<T>::notify()
{
if(nnotify_ != -1) {
++nnotify_;
}
}
template <class T> inline void
ObMonitor<T>::notify_all()
{
nnotify_ = -1;
}
template <class T> inline void
ObMonitor<T>::notify_impl(int nnotify) const
{
if (nnotify == 0) {
} else if (nnotify == -1) {
cond_.broadcast();
} else {
while(nnotify > 0) {
cond_.signal();
--nnotify;
}
}
}
}//end namespace
#endif
......@@ -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_;
}
......@@ -9,133 +9,96 @@
* 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
#ifndef OB_RW_LOCK_H
#define OB_RW_LOCK_H
#include <pthread.h>
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 {
template <class T>
class ObLockGuardBase
{
public:
explicit CRLock(pthread_rwlock_t* lock) : _rlock(lock)
{}
~CRLock()
{}
int lock() const;
int tryLock() const;
int unlock() const;
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:
mutable pthread_rwlock_t* _rlock;
const T& lock_;
mutable bool acquired_;
};
/**
* @brief Encapsulation of write lock in linux-thread read-write lock
*/
class CWLock {
public:
explicit CWLock(pthread_rwlock_t* lock) : _wlock(lock)
{}
~CWLock()
{}
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 trylock() const;
int unlock() const;
private:
mutable pthread_rwlock_t* _wlock;
mutable pthread_rwlock_t* rlock_;
};
class CRWLock {
class ObWLock
{
public:
CRWLock(ELockMode lockMode = NO_PRIORITY);
~CRWLock();
const CRLock *rlock() const
{
return &_rlock;
}
const CWLock *wlock() const
{
return &_wlock;
}
explicit ObWLock(pthread_rwlock_t* lock) : wlock_(lock) {}
~ObWLock() {}
int lock() const;
int trylock() const;
int unlock() const;
private:
CRLock _rlock;
CWLock _wlock;
pthread_rwlock_t _rwlock;
mutable pthread_rwlock_t* wlock_;
};
template <class T>
class CLockGuard {
class ObRWLock
{
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;
}
ObRWLock(LockMode lockMode = NO_PRIORITY);
~ObRWLock();
ObRLock* rlock() const { return rlock_; }
ObWLock* wlock() const { return wlock_; }
private:
const T& _lock;
mutable bool _acquired;
ObRLock* rlock_;
ObWLock* wlock_;
pthread_rwlock_t rwlock_;
};
/**
* @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();
}
class ObRLockGuard
{
public:
ObRLockGuard(const ObRWLock& rwlock, bool block = true) : guard_((*rwlock.rlock()), block) {}
~ObRLockGuard(){}
bool acquired() { return guard_.acquired(); }
private:
CLockGuard<CRLock> _guard;
ObLockGuardBase<ObRLock> guard_;
};
/**
* @brief Helper class for write lock in linux thread lock
*/
class CWLockGuard {
class ObWLockGuard
{
public:
CWLockGuard(const CRWLock& rwlock, bool block = true) : _guard((*rwlock.wlock()), block)
{}
~CWLockGuard()
{}
bool acquired()
{
return _guard.acquired();
}
ObWLockGuard(const ObRWLock& rwlock, bool block = true) : guard_((*rwlock.wlock()), block) {}
~ObWLockGuard(){}
bool acquired() { return guard_.acquired(); }
private:
CLockGuard<CWLock> _guard;
ObLockGuardBase<ObWLock> guard_;
};
} // namespace obsys
} // namespace oceanbase
}
}
#endif
......@@ -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) {
......
......@@ -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_*/
......@@ -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 <assert.h>
#include <pthread.h>
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_*/
......@@ -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)) {
......
......@@ -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<ObServerConnectionPool> server_pool_;
......
......@@ -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;
......
/**
* 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 <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
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<int>(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;
}
}
}
......@@ -9,16 +9,15 @@
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PubL v2 for more details.
*/
#ifndef TBSYS_NETUTIL_H_
#define TBSYS_NETUTIL_H_
#ifndef OCEANBASE_NET_UTIL_H_
#define OCEANBASE_NET_UTIL_H_
#include <stdint.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <ifaddrs.h> // ifaddrs
#include <ifaddrs.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <netdb.h>
......@@ -29,35 +28,17 @@
#include <linux/unistd.h>
#include <string>
// 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 {
class ObNetUtil {
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);
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);
};
} // namespace obsys
} // namespace oceanbase
}
}
#endif
/**
* 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 <string.h>
#include <stdlib.h>
#include <stdio.h>
#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<int>(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<int>(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
......@@ -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()
......
......@@ -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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
static const int64_t STATISTICS_INTERVAL_US = 600L * 1000 * 1000; // 10m
ObMonitor<Mutex>::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));
}
}
}
......
......@@ -16,8 +16,8 @@
#include <pthread.h>
#include <typeinfo>
#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<tbutil::Mutex> monitor_;
obutil::ObMonitor<obutil::Mutex> monitor_;
Token tokens_[MAX_TASK_NUM];
bool has_running_task_;
bool has_running_repeat_task_;
......
......@@ -15,11 +15,11 @@
#include <sstream>
#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<long>(_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<double>(_usec) / 1000000.0;
}
double Time::toMilliSecondsDouble() const
double ObSysTime::toMilliSecondsDouble() const
{
return static_cast<double>(_usec) / 1000.0;
}
double Time::toMicroSecondsDouble() const
double ObSysTime::toMicroSecondsDouble() const
{
return static_cast<double>(_usec);
}
std::string Time::toDateTime() const
std::string ObSysTime::toDateTime() const
{
time_t time = static_cast<long>(_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
......@@ -11,235 +11,238 @@
#include <sys/time.h>
#include <stdint.h>
#include <string>
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);
/**
* @brief convert Time to timeval
*
* @return
*/
operator timeval() 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;
double toSecondsDouble() const;
double toMilliSecondsDouble() const;
double toMicroSecondsDouble() 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;
Time operator-() const
{
return Time(-_usec);
}
Time operator-(const Time& rhs) const
{
return Time(_usec - rhs._usec);
}
Time operator+(const Time& rhs) const
{
return Time(_usec + rhs._usec);
}
Time& operator+=(const Time& rhs)
{
_usec += rhs._usec;
return *this;
}
Time& operator-=(const Time& rhs)
{
_usec -= rhs._usec;
return *this;
}
bool operator<(const Time& rhs) const
{
return _usec < rhs._usec;
}
bool operator<=(const Time& rhs) const
{
return _usec <= rhs._usec;
}
bool operator>(const Time& rhs) const
{
return _usec > rhs._usec;
}
bool operator>=(const Time& rhs) const
{
return _usec >= rhs._usec;
}
bool operator==(const Time& rhs) const
{
return _usec == rhs._usec;
}
bool operator!=(const Time& rhs) const
{
return _usec != rhs._usec;
}
double operator/(const Time& rhs) const
{
return (double)_usec / (double)rhs._usec;
}
Time& operator*=(int rhs)
{
_usec *= rhs;
return *this;
}
Time operator*(int rhs) const
{
Time t;
t._usec = _usec * rhs;
return t;
}
Time& operator/=(int rhs)
{
_usec /= rhs;
return *this;
}
Time operator/(int rhs) const
{
Time t;
t._usec = _usec / rhs;
return t;
}
Time& operator*=(int64_t rhs)
{
_usec *= rhs;
return *this;
}
Time operator*(int64_t rhs) const
{
Time t;
t._usec = _usec * rhs;
return t;
}
Time& operator/=(int64_t rhs)
{
_usec /= rhs;
return *this;
}
Time operator/(int64_t rhs) const
{
Time t;
t._usec = _usec / rhs;
return t;
}
Time& operator*=(double rhs)
{
_usec = static_cast<int64_t>(static_cast<double>(_usec) * rhs);
return *this;
}
Time operator*(double rhs) const
{
Time t;
t._usec = static_cast<int64_t>(static_cast<double>(_usec) * rhs);
return t;
}
Time& operator/=(double rhs)
{
_usec = static_cast<int64_t>(static_cast<double>(_usec) / rhs);
return *this;
}
Time operator/(double rhs) const
{
Time t;
t._usec = static_cast<int64_t>(static_cast<double>(_usec) / rhs);
return t;
}
Time(int64_t);
ObSysTime();
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 timeval
*
* @return
*/
operator timeval() 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;
double toSecondsDouble() const;
double toMilliSecondsDouble() const;
double toMicroSecondsDouble() 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;
ObSysTime operator-() const
{
return ObSysTime(-_usec);
}
ObSysTime operator-(const ObSysTime& rhs) const
{
return ObSysTime(_usec - rhs._usec);
}
ObSysTime operator+(const ObSysTime& rhs) const
{
return ObSysTime(_usec + rhs._usec);
}
ObSysTime& operator+=(const ObSysTime& rhs)
{
_usec += rhs._usec;
return *this;
}
ObSysTime& operator-=(const ObSysTime& rhs)
{
_usec -= rhs._usec;
return *this;
}
bool operator<(const ObSysTime& rhs) const
{
return _usec < rhs._usec;
}
bool operator<=(const ObSysTime& rhs) const
{
return _usec <= rhs._usec;
}
bool operator>(const ObSysTime& rhs) const
{
return _usec > rhs._usec;
}
bool operator>=(const ObSysTime& rhs) const
{
return _usec >= rhs._usec;
}
bool operator==(const ObSysTime& rhs) const
{
return _usec == rhs._usec;
}
bool operator!=(const ObSysTime& rhs) const
{
return _usec != rhs._usec;
}
double operator/(const ObSysTime& rhs) const
{
return (double)_usec / (double)rhs._usec;
}
ObSysTime& operator*=(int rhs)
{
_usec *= rhs;
return *this;
}
ObSysTime operator*(int rhs) const
{
ObSysTime t;
t._usec = _usec * rhs;
return t;
}
ObSysTime& operator/=(int rhs)
{
_usec /= rhs;
return *this;
}
ObSysTime operator/(int rhs) const
{
ObSysTime t;
t._usec = _usec / rhs;
return t;
}
ObSysTime& operator*=(int64_t rhs)
{
_usec *= rhs;
return *this;
}
ObSysTime operator*(int64_t rhs) const
{
ObSysTime t;
t._usec = _usec * rhs;
return t;
}
ObSysTime& operator/=(int64_t rhs)
{
_usec /= rhs;
return *this;
}
ObSysTime operator/(int64_t rhs) const
{
ObSysTime t;
t._usec = _usec / rhs;
return t;
}
ObSysTime& operator*=(double rhs)
{
_usec = static_cast<int64_t>(static_cast<double>(_usec) * rhs);
return *this;
}
ObSysTime operator*(double rhs) const
{
ObSysTime t;
t._usec = static_cast<int64_t>(static_cast<double>(_usec) * rhs);
return t;
}
ObSysTime& operator/=(double rhs)
{
_usec = static_cast<int64_t>(static_cast<double>(_usec) / rhs);
return *this;
}
ObSysTime operator/(double rhs) const
{
ObSysTime t;
t._usec = static_cast<int64_t>(static_cast<double>(_usec) / rhs);
return t;
}
ObSysTime(int64_t);
private:
int64_t _usec;
};
} // namespace tbutil
} // namespace obutil
#endif
......@@ -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<int64_t>(t.tv_sec) * static_cast<int64_t>(1000000) + static_cast<int64_t>(t.tv_usec));
struct timeval t;
(void)gettimeofday(&t, NULL);
return (static_cast<int64_t>(t.tv_sec) * static_cast<int64_t>(1000000) + static_cast<int64_t>(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;
......
......@@ -25,7 +25,7 @@ namespace obsys {
/**
* @brief Simple encapsulation of linux time operation
*/
class CTimeUtil {
class ObSysTimeUtil {
public:
/**
* ms timestamp
......
......@@ -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();
......
......@@ -67,7 +67,7 @@ public:
HashMap* hashmap;
private:
obsys::CThreadMutex mutex;
obsys::ThreadMutex mutex;
};
TEST(TestObConcurrentHashMap, concurrent)
......
......@@ -175,7 +175,7 @@ public:
HashMap* hashmap;
private:
obsys::CThreadMutex mutex;
obsys::ThreadMutex mutex;
int finished_count;
};
......
......@@ -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;
......
......@@ -17,8 +17,8 @@
#include <stdlib.h>
#include <sys/types.h>
#include <algorithm>
#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<tbutil::Mutex> monitor_;
obutil::ObMonitor<obutil::Mutex> monitor_;
};
template <typename Type, int size>
......@@ -80,7 +80,7 @@ int ObRingBuffer<Type, size>::push(const Type& elem, Type& old_elem, bool& overw
{
int ret = common::OB_SUCCESS;
tbutil::Monitor<tbutil::Mutex>::Lock guard(monitor_);
obutil::ObMonitor<obutil::Mutex>::Lock guard(monitor_);
if (destroyed_) {
ret = common::OB_NOT_INIT;
} else if (is_full() && !overwrite) {
......@@ -111,7 +111,7 @@ int ObRingBuffer<Type, size>::pop(Type& elem)
{
int ret = common::OB_SUCCESS;
tbutil::Monitor<tbutil::Mutex>::Lock guard(monitor_);
obutil::ObMonitor<obutil::Mutex>::Lock guard(monitor_);
while (!destroyed_ && is_empty()) {
monitor_.wait();
}
......@@ -128,9 +128,9 @@ int ObRingBuffer<Type, size>::pop(Type& elem)
template <typename Type, int size>
void ObRingBuffer<Type, size>::destroy()
{
tbutil::Monitor<tbutil::Mutex>::Lock guard(monitor_);
obutil::ObMonitor<obutil::Mutex>::Lock guard(monitor_);
if (!destroyed_) {
monitor_.notifyAll();
monitor_.notify_all();
destroyed_ = true;
}
}
......
......@@ -11,9 +11,9 @@
*/
#include <execinfo.h>
#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<tbutil::Mutex> monitor_;
(void)monitor_.timedWait(Time(ms * 1000));
obutil::ObMonitor<obutil::Mutex> monitor_;
(void)monitor_.timed_wait(ObSysTime(ms * 1000));
}
} // namespace election
......
......@@ -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),
......
......@@ -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<int32_t>(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);
}
......
......@@ -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));
......
......@@ -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_;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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];
......
......@@ -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_;
......
......@@ -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 {
......
......@@ -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);
};
......
......@@ -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"
......
......@@ -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");
}
}
......
......@@ -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));
......
......@@ -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_;
......
......@@ -19,7 +19,7 @@ namespace oceanbase {
namespace common {
using namespace tbutil;
using namespace obutil;
void ObTimeWheelTask::reset()
{
......
......@@ -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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex>::Lock guard(monitor_);
ObMonitor<Mutex>::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<Mutex> monitor;
ObMonitor<Mutex> monitor;
THIS_WORKER.sched_wait();
(void)monitor.timedWait(Time(us));
(void)monitor.timed_wait(ObSysTime(us));
THIS_WORKER.sched_run();
}
}
......
......@@ -14,8 +14,8 @@
#define OCEANBASE_TRANSACTION_OB_TRANS_COND_
#include <stdint.h>
#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<tbutil::Mutex> monitor_;
mutable obutil::ObMonitor<obutil::Mutex> monitor_;
int result_;
};
......
......@@ -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());
}
......
......@@ -37,7 +37,7 @@ protected:
void TestPrivMgr::SetUp()
{
// obsys::CConfig c1;
// obsys::ObSysConfig c1;
// priv_mgr_.init();
}
......
......@@ -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);
}
}
......
......@@ -103,7 +103,7 @@ public:
private:
static ObMockPacketQueueThread* instance_;
static tbutil::Mutex locker_;
static obutil::Mutex locker_;
};
} // namespace sql
......
......@@ -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_++;
}
......
......@@ -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<int32_t>(config_.rpc_port);
config_.print();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册