Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Metz
oceanbase
提交
68cd5587
O
oceanbase
项目概览
Metz
/
oceanbase
与 Fork 源项目一致
Fork自
oceanbase / oceanbase
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
oceanbase
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
68cd5587
编写于
4月 06, 2022
作者:
L
ly0
提交者:
LINGuanRen
4月 06, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
patch tair code removing from 22x to 31CE
上级
518fd355
变更
66
隐藏空白更改
内联
并排
Showing
66 changed file
with
1340 addition
and
1261 deletion
+1340
-1261
deps/oblib/src/common/ob_clock_generator.cpp
deps/oblib/src/common/ob_clock_generator.cpp
+2
-2
deps/oblib/src/common/ob_clock_generator.h
deps/oblib/src/common/ob_clock_generator.h
+6
-6
deps/oblib/src/lib/CMakeLists.txt
deps/oblib/src/lib/CMakeLists.txt
+10
-12
deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp
deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp
+7
-7
deps/oblib/src/lib/alloc/ob_malloc_allocator.h
deps/oblib/src/lib/alloc/ob_malloc_allocator.h
+2
-2
deps/oblib/src/lib/file/fileutil.cpp
deps/oblib/src/lib/file/fileutil.cpp
+0
-71
deps/oblib/src/lib/file/ob_string_util.cpp
deps/oblib/src/lib/file/ob_string_util.cpp
+106
-0
deps/oblib/src/lib/file/ob_string_util.h
deps/oblib/src/lib/file/ob_string_util.h
+14
-22
deps/oblib/src/lib/lock/Monitor.h
deps/oblib/src/lib/lock/Monitor.h
+0
-207
deps/oblib/src/lib/lock/RecMutex.cpp
deps/oblib/src/lib/lock/RecMutex.cpp
+0
-132
deps/oblib/src/lib/lock/RecMutex.h
deps/oblib/src/lib/lock/RecMutex.h
+0
-80
deps/oblib/src/lib/lock/cond.cpp
deps/oblib/src/lib/lock/cond.cpp
+3
-3
deps/oblib/src/lib/lock/cond.h
deps/oblib/src/lib/lock/cond.h
+120
-0
deps/oblib/src/lib/lock/mutex.cpp
deps/oblib/src/lib/lock/mutex.cpp
+31
-30
deps/oblib/src/lib/lock/mutex.h
deps/oblib/src/lib/lock/mutex.h
+52
-0
deps/oblib/src/lib/lock/ob_lock.h
deps/oblib/src/lib/lock/ob_lock.h
+115
-0
deps/oblib/src/lib/lock/ob_monitor.h
deps/oblib/src/lib/lock/ob_monitor.h
+160
-0
deps/oblib/src/lib/lock/ob_rwlock.cpp
deps/oblib/src/lib/lock/ob_rwlock.cpp
+21
-19
deps/oblib/src/lib/lock/ob_rwlock.h
deps/oblib/src/lib/lock/ob_rwlock.h
+104
-0
deps/oblib/src/lib/lock/ob_tc_rwlock.h
deps/oblib/src/lib/lock/ob_tc_rwlock.h
+1
-1
deps/oblib/src/lib/lock/threadcond.h
deps/oblib/src/lib/lock/threadcond.h
+15
-50
deps/oblib/src/lib/lock/threadmutex.h
deps/oblib/src/lib/lock/threadmutex.h
+29
-62
deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.cpp
deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.cpp
+8
-8
deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.h
deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.h
+1
-1
deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp
deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp
+4
-4
deps/oblib/src/lib/net/ob_net_util.cpp
deps/oblib/src/lib/net/ob_net_util.cpp
+118
-0
deps/oblib/src/lib/net/ob_net_util.h
deps/oblib/src/lib/net/ob_net_util.h
+44
-0
deps/oblib/src/lib/net/tbnetutil.cpp
deps/oblib/src/lib/net/tbnetutil.cpp
+0
-179
deps/oblib/src/lib/oblog/ob_async_log_struct.cpp
deps/oblib/src/lib/oblog/ob_async_log_struct.cpp
+1
-0
deps/oblib/src/lib/task/ob_timer.cpp
deps/oblib/src/lib/task/ob_timer.cpp
+23
-23
deps/oblib/src/lib/task/ob_timer.h
deps/oblib/src/lib/task/ob_timer.h
+3
-3
deps/oblib/src/lib/time/Time.cpp
deps/oblib/src/lib/time/Time.cpp
+22
-22
deps/oblib/src/lib/time/Time.h
deps/oblib/src/lib/time/Time.h
+228
-225
deps/oblib/src/lib/time/tbtimeutil.cpp
deps/oblib/src/lib/time/tbtimeutil.cpp
+7
-7
deps/oblib/src/lib/time/tbtimeutil.h
deps/oblib/src/lib/time/tbtimeutil.h
+1
-1
deps/oblib/unittest/lib/container/test_ext_ring_buffer.cpp
deps/oblib/unittest/lib/container/test_ext_ring_buffer.cpp
+2
-2
deps/oblib/unittest/lib/hash/test_concurrent_hash_map.cpp
deps/oblib/unittest/lib/hash/test_concurrent_hash_map.cpp
+1
-1
deps/oblib/unittest/lib/hash/test_concurrent_hash_map_with_hazard_value.cpp
...t/lib/hash/test_concurrent_hash_map_with_hazard_value.cpp
+1
-1
src/election/ob_election_async_log.cpp
src/election/ob_election_async_log.cpp
+1
-1
src/election/ob_election_async_log.h
src/election/ob_election_async_log.h
+7
-7
src/election/ob_election_base.cpp
src/election/ob_election_base.cpp
+7
-7
src/observer/mysql/ob_eliminate_task.cpp
src/observer/mysql/ob_eliminate_task.cpp
+2
-2
src/observer/ob_server.cpp
src/observer/ob_server.cpp
+3
-3
src/observer/omt/ob_tenant_config.cpp
src/observer/omt/ob_tenant_config.cpp
+4
-4
src/observer/omt/ob_tenant_config.h
src/observer/omt/ob_tenant_config.h
+2
-2
src/observer/omt/ob_tenant_config_mgr.cpp
src/observer/omt/ob_tenant_config_mgr.cpp
+2
-3
src/observer/omt/ob_tenant_timezone.cpp
src/observer/omt/ob_tenant_timezone.cpp
+2
-2
src/observer/omt/ob_tenant_timezone.h
src/observer/omt/ob_tenant_timezone.h
+1
-1
src/observer/omt/ob_tenant_timezone_mgr.cpp
src/observer/omt/ob_tenant_timezone_mgr.cpp
+1
-1
src/share/allocator/ob_tenant_mutil_allocator_mgr.cpp
src/share/allocator/ob_tenant_mutil_allocator_mgr.cpp
+2
-2
src/share/allocator/ob_tenant_mutil_allocator_mgr.h
src/share/allocator/ob_tenant_mutil_allocator_mgr.h
+1
-1
src/share/config/ob_config_manager.cpp
src/share/config/ob_config_manager.cpp
+1
-1
src/share/config/ob_config_manager.h
src/share/config/ob_config_manager.h
+1
-1
src/share/config/ob_server_config.cpp
src/share/config/ob_server_config.cpp
+1
-0
src/storage/memtable/ob_lock_wait_mgr.cpp
src/storage/memtable/ob_lock_wait_mgr.cpp
+5
-5
src/storage/ob_partition_scheduler.cpp
src/storage/ob_partition_scheduler.cpp
+11
-11
src/storage/ob_partition_scheduler.h
src/storage/ob_partition_scheduler.h
+2
-2
src/storage/transaction/ob_time_wheel.cpp
src/storage/transaction/ob_time_wheel.cpp
+1
-1
src/storage/transaction/ob_trans_result.cpp
src/storage/transaction/ob_trans_result.cpp
+7
-7
src/storage/transaction/ob_trans_result.h
src/storage/transaction/ob_trans_result.h
+3
-3
unittest/election/test_election_base.cpp
unittest/election/test_election_base.cpp
+2
-2
unittest/share/schema/test_priv_mgr.cpp
unittest/share/schema/test_priv_mgr.cpp
+1
-1
unittest/share/test_latch.cpp
unittest/share/test_latch.cpp
+3
-3
unittest/sql/executor/ob_mock_utils.h
unittest/sql/executor/ob_mock_utils.h
+1
-1
unittest/sql/parser/test_parser_perf.cpp
unittest/sql/parser/test_parser_perf.cpp
+2
-2
unittest/storage/mockcontainer/mock_ob_server.cpp
unittest/storage/mockcontainer/mock_ob_server.cpp
+2
-2
未找到文件。
deps/oblib/src/common/ob_clock_generator.cpp
浏览文件 @
68cd5587
...
...
@@ -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/
M
onitor.h"
#include "lib/lock/
M
utex.h"
#include "lib/lock/
ob_m
onitor.h"
#include "lib/lock/
m
utex.h"
#include "lib/time/ob_time_utility.h"
#include "lib/coro/routine.h"
#include "lib/thread/ob_thread_name.h"
...
...
deps/oblib/src/common/ob_clock_generator.h
浏览文件 @
68cd5587
...
...
@@ -18,8 +18,8 @@
#include "lib/ob_define.h"
#include "lib/oblog/ob_log.h"
#include "lib/atomic/ob_atomic.h"
#include "lib/lock/
M
onitor.h"
#include "lib/lock/
M
utex.h"
#include "lib/lock/
ob_m
onitor.h"
#include "lib/lock/
m
utex.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
<
t
butil
::
Mutex
>
monitor_
;
(
void
)
monitor_
.
timed
Wait
(
tbutil
::
Time
(
ms
*
1000
));
obutil
::
ObMonitor
<
o
butil
::
Mutex
>
monitor_
;
(
void
)
monitor_
.
timed
_wait
(
obutil
::
ObSys
Time
(
ms
*
1000
));
}
}
inline
void
ObClockGenerator
::
usleep
(
const
int64_t
us
)
{
if
(
us
>
0
)
{
tbutil
::
Monitor
<
t
butil
::
Mutex
>
monitor_
;
(
void
)
monitor_
.
timed
Wait
(
tbutil
::
Time
(
us
));
obutil
::
ObMonitor
<
o
butil
::
Mutex
>
monitor_
;
(
void
)
monitor_
.
timed
_wait
(
obutil
::
ObSys
Time
(
us
));
}
}
...
...
deps/oblib/src/lib/CMakeLists.txt
浏览文件 @
68cd5587
...
...
@@ -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/
C
ond.cpp
lock/
M
utex.cpp
lock/
c
ond.cpp
lock/
m
utex.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/
tbnet
util.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/
tbnet
util.h
lock/
tb
rwlock.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/
L
ock.h
lock/
M
utex.h
lock/
C
ond.h
lock/
M
onitor.h
lock/
ob_l
ock.h
lock/
m
utex.h
lock/
c
ond.h
lock/
ob_m
onitor.h
task/ob_timer.h
list/ob_list.h
container/ob_bit_set.h
...
...
deps/oblib/src/lib/alloc/ob_malloc_allocator.cpp
浏览文件 @
68cd5587
...
...
@@ -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
::
C
RLockGuard
guard
(
locks_
[
slot
]);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
guard
(
locks_
[
slot
]);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
guard
(
locks_
[
slot
]);
obsys
::
Ob
RLockGuard
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
::
C
WLockGuard
guard
(
locks_
[
slot
]);
obsys
::
Ob
WLockGuard
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
::
C
RLockGuard
guard
(
locks_
[
slot
]);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
guard
(
locks_
[
slot
]);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
guard
(
locks_
[
slot
]);
obsys
::
Ob
RLockGuard
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
)
{
...
...
deps/oblib/src/lib/alloc/ob_malloc_allocator.h
浏览文件 @
68cd5587
...
...
@@ -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/
tb
rwlock.h"
#include "lib/lock/
ob_
rwlock.h"
namespace
oceanbase
{
namespace
lib
{
...
...
@@ -76,7 +76,7 @@ private:
DISALLOW_COPY_AND_ASSIGN
(
ObMallocAllocator
);
private:
obsys
::
C
RWLock
locks_
[
PRESERVED_TENANT_COUNT
];
obsys
::
Ob
RWLock
locks_
[
PRESERVED_TENANT_COUNT
];
ObTenantCtxAllocator
*
allocators_
[
PRESERVED_TENANT_COUNT
][
common
::
ObCtxIds
::
MAX_CTX_ID
];
int64_t
reserved_
;
int64_t
urgent_
;
...
...
deps/oblib/src/lib/file/fileutil.cpp
已删除
100644 → 0
浏览文件 @
518fd355
/**
* 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
deps/oblib/src/lib/file/ob_string_util.cpp
0 → 100644
浏览文件 @
68cd5587
/**
* 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
);
}
}
}
deps/oblib/src/lib/file/
file
util.h
→
deps/oblib/src/lib/file/
ob_string_
util.h
浏览文件 @
68cd5587
...
...
@@ -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
deps/oblib/src/lib/lock/Monitor.h
已删除
100644 → 0
浏览文件 @
518fd355
/**
* 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
deps/oblib/src/lib/lock/RecMutex.cpp
已删除
100644 → 0
浏览文件 @
518fd355
/**
* 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
deps/oblib/src/lib/lock/RecMutex.h
已删除
100644 → 0
浏览文件 @
518fd355
/**
* 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
deps/oblib/src/lib/lock/
C
ond.cpp
→
deps/oblib/src/lib/lock/
c
ond.cpp
浏览文件 @
68cd5587
...
...
@@ -11,9 +11,9 @@
*/
#include <sys/time.h>
#include "lib/lock/
C
ond.h"
#include "lib/lock/
c
ond.h"
#include "lib/oblog/ob_log.h"
namespace
t
butil
{
namespace
o
butil
{
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 t
butil
}
//end namespace o
butil
deps/oblib/src/lib/lock/
C
ond.h
→
deps/oblib/src/lib/lock/
c
ond.h
浏览文件 @
68cd5587
...
...
@@ -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
Ob
Monitor
;
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
ObSys
Time
&
)
const
;
mutable
pthread_cond_t
_cond
;
};
template
<
typename
M
>
inline
bool
Cond
::
waitI
mpl
(
const
M
&
mutex
)
const
template
<
typename
M
>
inline
bool
Cond
::
wait_i
mpl
(
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"
);
ret
urn
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
ObSys
Time
&
timeout
)
const
{
if
(
timeout
<
Time
::
microSeconds
(
0
))
{
_OB_LOG
(
ERROR
,
"%s"
,
"InvalidTimeoutException"
);
return
false
;
}
typedef
typename
M
::
LockState
LockState
;
LockState
state
;
mutex
.
unlock
(
state
);
timeval
tv
=
Time
::
now
(
Time
::
Realtime
)
+
timeout
;
timespec
ts
;
ts
.
tv_sec
=
tv
.
tv_sec
;
ts
.
tv_nsec
=
tv
.
tv_usec
*
1000
;
/*timeval tv = Time::now(Time::Realtime);
timespec ts;
ts.tv_sec = tv.tv_sec + timeout/1000;
ts.tv_nsec = tv.tv_usec * 1000 + ( timeout % 1000 ) * 1000000;*/
const
int
rc
=
pthread_cond_timedwait
(
&
_cond
,
state
.
mutex
,
&
ts
);
mutex
.
lock
(
state
);
if
(
rc
!=
0
)
{
if
(
rc
!=
ETIMEDOUT
)
{
_OB_LOG
(
ERROR
,
"%s"
,
"ThreadSyscallException"
);
return
false
;
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
deps/oblib/src/lib/lock/
M
utex.cpp
→
deps/oblib/src/lib/lock/
m
utex.cpp
浏览文件 @
68cd5587
...
...
@@ -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
::
try
L
ock
()
const
bool
Mutex
::
try
l
ock
()
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
::
will
U
nlock
()
const
bool
Mutex
::
will
_u
nlock
()
const
{
return
true
;
}
}
// end namespace t
butil
}
//end namespace o
butil
deps/oblib/src/lib/lock/
M
utex.h
→
deps/oblib/src/lib/lock/
m
utex.h
浏览文件 @
68cd5587
...
...
@@ -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/
L
ock.h"
#include "lib/lock/
ob_l
ock.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
deps/oblib/src/lib/lock/
L
ock.h
→
deps/oblib/src/lib/lock/
ob_l
ock.h
浏览文件 @
68cd5587
...
...
@@ -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
()
~
Ob
LockT
()
{
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
.
tryL
ock
();
return
_acquired
;
acquired_
=
mutex_
.
tryl
ock
();
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
.
tryL
ock
();
acquired_
=
mutex_
.
tryl
ock
();
}
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
deps/oblib/src/lib/lock/ob_monitor.h
0 → 100644
浏览文件 @
68cd5587
/**
* 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
deps/oblib/src/lib/lock/
tb
rwlock.cpp
→
deps/oblib/src/lib/lock/
ob_
rwlock.cpp
浏览文件 @
68cd5587
...
...
@@ -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
C
RLock
::
lock
()
const
int
Ob
RLock
::
lock
()
const
{
return
pthread_rwlock_rdlock
(
_rlock
);
return
pthread_rwlock_rdlock
(
rlock_
);
}
int
CRLock
::
tryL
ock
()
const
int
ObRLock
::
tryl
ock
()
const
{
return
pthread_rwlock_tryrdlock
(
_rlock
);
return
pthread_rwlock_tryrdlock
(
rlock_
);
}
int
C
RLock
::
unlock
()
const
int
Ob
RLock
::
unlock
()
const
{
return
pthread_rwlock_unlock
(
_rlock
);
return
pthread_rwlock_unlock
(
rlock_
);
}
int
C
WLock
::
lock
()
const
int
Ob
WLock
::
lock
()
const
{
return
pthread_rwlock_wrlock
(
_wlock
);
return
pthread_rwlock_wrlock
(
wlock_
);
}
int
CWLock
::
tryL
ock
()
const
int
ObWLock
::
tryl
ock
()
const
{
return
pthread_rwlock_trywrlock
(
_wlock
);
return
pthread_rwlock_trywrlock
(
wlock_
);
}
int
C
WLock
::
unlock
()
const
int
Ob
WLock
::
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
::~
C
RWLock
()
ObRWLock
::~
Ob
RWLock
()
{
pthread_rwlock_destroy
(
&
_rwlock
);
pthread_rwlock_destroy
(
&
rwlock_
);
delete
rlock_
;
delete
wlock_
;
}
deps/oblib/src/lib/lock/
tb
rwlock.h
→
deps/oblib/src/lib/lock/
ob_
rwlock.h
浏览文件 @
68cd5587
...
...
@@ -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
try
L
ock
()
const
;
int
try
l
ock
()
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
deps/oblib/src/lib/lock/ob_tc_rwlock.h
浏览文件 @
68cd5587
...
...
@@ -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
::
C
TimeUtil
::
getTime
())
>=
0
)
{
while
(
0
!=
ATOMIC_LOAD
(
&
read_ref_
)
&&
(
ttl
=
abs_timeout_us
-
obsys
::
ObSys
TimeUtil
::
getTime
())
>=
0
)
{
lcond_
.
wait
(
std
::
min
(
ttl
,
(
int64_t
)
10
*
1000
));
}
if
(
ttl
<
0
)
{
...
...
deps/oblib/src/lib/lock/threadcond.h
浏览文件 @
68cd5587
...
...
@@ -10,77 +10,42 @@
* See the Mulan PubL v2 for more details.
*/
#ifndef T
BSYS
_COND_H_
#define T
BSYS
_COND_H_
#ifndef T
HREAD
_COND_H_
#define T
HREAD
_COND_H_
#include "lib/lock/ob_thread_cond.h"
namespace
oceanbase
{
namespace
obsys
{
class
C
ThreadCond
{
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_*/
deps/oblib/src/lib/lock/threadmutex.h
浏览文件 @
68cd5587
...
...
@@ -10,100 +10,67 @@
* See the Mulan PubL v2 for more details.
*/
#ifndef T
BSYS
_MUTEX_H_
#define T
BSYS
_MUTEX_H_
#ifndef T
HREAD
_MUTEX_H_
#define T
HREAD
_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
();
}
}
~
C
ThreadGuard
()
~
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_*/
deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.cpp
浏览文件 @
68cd5587
...
...
@@ -56,7 +56,7 @@ ObMySQLConnectionPool::ObMySQLConnectionPool()
ObMySQLConnectionPool
::~
ObMySQLConnectionPool
()
{
ObServerConnectionPool
*
pool
=
NULL
;
obsys
::
C
WLockGuard
lock
(
get_lock_
);
obsys
::
Ob
WLockGuard
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
::
C
WLockGuard
lock
(
get_lock_
);
obsys
::
Ob
WLockGuard
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
::
C
RLockGuard
lock
(
get_lock_
);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
lock
(
get_lock_
);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
lock
(
get_lock_
);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
lock
(
get_lock_
);
obsys
::
Ob
RLockGuard
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
::
C
WLockGuard
lock
(
get_lock_
);
obsys
::
Ob
WLockGuard
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
::
C
RLockGuard
lock
(
get_lock_
);
obsys
::
Ob
RLockGuard
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
))
{
...
...
deps/oblib/src/lib/mysqlclient/ob_mysql_connection_pool.h
浏览文件 @
68cd5587
...
...
@@ -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
::
C
RWLock
get_lock_
;
mutable
obsys
::
Ob
RWLock
get_lock_
;
common
::
ObArenaAllocator
allocator_
;
ClusterList
cluster_list_
;
common
::
ObCachedAllocator
<
ObServerConnectionPool
>
server_pool_
;
...
...
deps/oblib/src/lib/mysqlclient/ob_mysql_statement.cpp
浏览文件 @
68cd5587
...
...
@@ -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
::
C
TimeUtil
::
getMonotonicTime
();
int64_t
begin
=
obsys
::
ObSys
TimeUtil
::
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
::
C
TimeUtil
::
getMonotonicTime
();
int64_t
end
=
obsys
::
ObSys
TimeUtil
::
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
::
C
TimeUtil
::
getMonotonicTime
();
int64_t
begin
=
obsys
::
ObSys
TimeUtil
::
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
::
C
TimeUtil
::
getMonotonicTime
();
int64_t
end
=
obsys
::
ObSys
TimeUtil
::
getMonotonicTime
();
LOG_TRACE
(
"execute stat"
,
"time(us)"
,
(
end
-
begin
),
"SQL"
,
sql_str_
,
K
(
ret
));
}
return
result
;
...
...
deps/oblib/src/lib/net/ob_net_util.cpp
0 → 100644
浏览文件 @
68cd5587
/**
* 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
;
}
}
}
deps/oblib/src/lib/net/
tbnet
util.h
→
deps/oblib/src/lib/net/
ob_net_
util.h
浏览文件 @
68cd5587
...
...
@@ -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
C
NetUtil
{
class
Ob
NetUtil
{
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
deps/oblib/src/lib/net/tbnetutil.cpp
已删除
100644 → 0
浏览文件 @
518fd355
/**
* 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
deps/oblib/src/lib/oblog/ob_async_log_struct.cpp
浏览文件 @
68cd5587
...
...
@@ -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
()
...
...
deps/oblib/src/lib/task/ob_timer.cpp
浏览文件 @
68cd5587
...
...
@@ -19,7 +19,7 @@
namespace
oceanbase
{
namespace
common
{
using
namespace
t
butil
;
using
namespace
o
butil
;
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_
);
Ob
Monitor
<
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_
.
notify
A
ll
();
monitor_
.
notify
_a
ll
();
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_
);
Ob
Monitor
<
Mutex
>::
Lock
guard
(
monitor_
);
if
(
!
is_inited_
)
{
ret
=
OB_NOT_INIT
;
}
else
if
(
is_stopped_
)
{
is_stopped_
=
false
;
monitor_
.
notify
A
ll
();
monitor_
.
notify
_a
ll
();
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_
);
Ob
Monitor
<
Mutex
>::
Lock
guard
(
monitor_
);
if
(
!
is_stopped_
)
{
is_stopped_
=
true
;
monitor_
.
notify
A
ll
();
monitor_
.
notify
_a
ll
();
OB_LOG
(
INFO
,
"ObTimer stop success"
,
KP
(
this
),
K_
(
thread_id
));
}
}
void
ObTimer
::
wait
()
{
Monitor
<
Mutex
>::
Lock
guard
(
monitor_
);
Ob
Monitor
<
Mutex
>::
Lock
guard
(
monitor_
);
while
(
has_running_task_
)
{
static
const
int64_t
WAIT_INTERVAL_US
=
2000000
;
// 2s
(
void
)
monitor_
.
timed
Wait
(
Time
(
WAIT_INTERVAL_US
));
static
const
int64_t
WAIT_INTERVAL_US
=
2000000
;
// 2s
(
void
)
monitor_
.
timed
_wait
(
ObSys
Time
(
WAIT_INTERVAL_US
));
}
}
void
ObTimer
::
destroy
()
{
if
(
!
is_destroyed_
&&
is_inited_
)
{
Monitor
<
Mutex
>::
Lock
guard
(
monitor_
);
Ob
Monitor
<
Mutex
>::
Lock
guard
(
monitor_
);
is_stopped_
=
true
;
is_destroyed_
=
true
;
is_inited_
=
false
;
has_running_repeat_task_
=
false
;
monitor_
.
notify
A
ll
();
monitor_
.
notify
_a
ll
();
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_
);
Ob
Monitor
<
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_
);
Ob
Monitor
<
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
(
ObSys
Time
::
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_
);
Ob
Monitor
<
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_
);
Ob
Monitor
<
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
Ob
Monitor
<
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
(
ObSys
Time
::
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_
.
notify
A
ll
();
monitor_
.
notify
_a
ll
();
}
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
(
ObSys
Time
::
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_
.
timed
Wait
(
Time
(
wakeup_time_
-
now
));
monitor_
.
timed
_wait
(
ObSys
Time
(
wakeup_time_
-
now
));
}
}
}
...
...
deps/oblib/src/lib/task/ob_timer.h
浏览文件 @
68cd5587
...
...
@@ -16,8 +16,8 @@
#include <pthread.h>
#include <typeinfo>
#include "lib/time/Time.h"
#include "lib/lock/
M
utex.h"
#include "lib/lock/
M
onitor.h"
#include "lib/lock/
m
utex.h"
#include "lib/lock/
ob_m
onitor.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
<
t
butil
::
Mutex
>
monitor_
;
obutil
::
ObMonitor
<
o
butil
::
Mutex
>
monitor_
;
Token
tokens_
[
MAX_TASK_NUM
];
bool
has_running_task_
;
bool
has_running_repeat_task_
;
...
...
deps/oblib/src/lib/time/Time.cpp
浏览文件 @
68cd5587
...
...
@@ -15,11 +15,11 @@
#include <sstream>
#include "lib/oblog/ob_log.h"
namespace
t
butil
{
Time
::
Time
()
:
_usec
(
0
)
namespace
o
butil
{
ObSysTime
::
ObSys
Time
()
:
_usec
(
0
)
{}
Time
Time
::
now
(
Clock
clock
)
ObSysTime
ObSys
Time
::
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
ObSys
Time
(
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
ObSys
Time
(
ts
.
tv_sec
*
INT64_C
(
1000000
)
+
ts
.
tv_nsec
/
INT64_C
(
1000
));
}
}
Time
Time
::
seconds
(
int64_t
t
)
ObSysTime
ObSys
Time
::
seconds
(
int64_t
t
)
{
return
Time
(
t
*
INT64_C
(
1000000
));
return
ObSys
Time
(
t
*
INT64_C
(
1000000
));
}
Time
Time
::
milliSeconds
(
int64_t
t
)
ObSysTime
ObSys
Time
::
milliSeconds
(
int64_t
t
)
{
return
Time
(
t
*
INT64_C
(
1000
));
return
ObSys
Time
(
t
*
INT64_C
(
1000
));
}
Time
Time
::
microSeconds
(
int64_t
t
)
ObSysTime
ObSys
Time
::
microSeconds
(
int64_t
t
)
{
return
Time
(
t
);
return
ObSys
Time
(
t
);
}
Time
::
operator
timeval
()
const
ObSys
Time
::
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
ObSys
Time
::
toSeconds
()
const
{
return
_usec
/
1000000
;
}
int64_t
Time
::
toMilliSeconds
()
const
int64_t
ObSys
Time
::
toMilliSeconds
()
const
{
return
_usec
/
1000
;
}
int64_t
Time
::
toMicroSeconds
()
const
int64_t
ObSys
Time
::
toMicroSeconds
()
const
{
return
_usec
;
}
double
Time
::
toSecondsDouble
()
const
double
ObSys
Time
::
toSecondsDouble
()
const
{
return
static_cast
<
double
>
(
_usec
)
/
1000000.0
;
}
double
Time
::
toMilliSecondsDouble
()
const
double
ObSys
Time
::
toMilliSecondsDouble
()
const
{
return
static_cast
<
double
>
(
_usec
)
/
1000.0
;
}
double
Time
::
toMicroSecondsDouble
()
const
double
ObSys
Time
::
toMicroSecondsDouble
()
const
{
return
static_cast
<
double
>
(
_usec
);
}
std
::
string
Time
::
toDateTime
()
const
std
::
string
ObSys
Time
::
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
ObSys
Time
::
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
::
ObSys
Time
(
int64_t
usec
)
:
_usec
(
usec
)
{}
}
// end namespace
t
butil
}
// end namespace
o
butil
deps/oblib/src/lib/time/Time.h
浏览文件 @
68cd5587
...
...
@@ -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
t
butil
}
// namespace
o
butil
#endif
deps/oblib/src/lib/time/tbtimeutil.cpp
浏览文件 @
68cd5587
...
...
@@ -23,14 +23,14 @@ namespace obsys {
/*
* get current time
*/
int64_t
C
TimeUtil
::
getTime
()
int64_t
ObSys
TimeUtil
::
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
C
TimeUtil
::
getMonotonicTime
()
int64_t
ObSys
TimeUtil
::
getMonotonicTime
()
{
timespec
t
;
clock_gettime
(
CLOCK_MONOTONIC
,
&
t
);
...
...
@@ -40,7 +40,7 @@ int64_t CTimeUtil::getMonotonicTime()
/**
* format int into 20080101101010
*/
char
*
C
TimeUtil
::
timeToStr
(
time_t
t
,
char
*
dest
)
char
*
ObSys
TimeUtil
::
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
C
TimeUtil::strToTime(char *str)
int
ObSys
TimeUtil::strToTime(char *str)
{
if (str == NULL || strlen(str) != 14) {
return 0;
...
...
deps/oblib/src/lib/time/tbtimeutil.h
浏览文件 @
68cd5587
...
...
@@ -25,7 +25,7 @@ namespace obsys {
/**
* @brief Simple encapsulation of linux time operation
*/
class
C
TimeUtil
{
class
ObSys
TimeUtil
{
public:
/**
* ms timestamp
...
...
deps/oblib/unittest/lib/container/test_ext_ring_buffer.cpp
浏览文件 @
68cd5587
...
...
@@ -310,13 +310,13 @@ TEST(HazPtr, Basic0)
const
int64_t
lmt
=
10000000
;
int64_t
cnt
=
0
;
int64_t
start
=
obsys
::
C
TimeUtil
::
getTime
();
int64_t
start
=
obsys
::
ObSys
TimeUtil
::
getTime
();
while
(
++
cnt
<
lmt
)
{
TypeA
*
ptr
=
hazptr
.
acquire
(
target
,
0
);
EXPECT_EQ
(
target
,
ptr
);
hazptr
.
revert
(
0
);
}
int64_t
end
=
obsys
::
C
TimeUtil
::
getTime
();
int64_t
end
=
obsys
::
ObSys
TimeUtil
::
getTime
();
LIB_LOG
(
ERROR
,
">>>"
,
K
(
cnt
),
K
(
end
-
start
),
K
((
double
)
cnt
/
((
double
)(
end
-
start
)
/
1000000
)));
err
=
hazptr
.
destroy
();
...
...
deps/oblib/unittest/lib/hash/test_concurrent_hash_map.cpp
浏览文件 @
68cd5587
...
...
@@ -67,7 +67,7 @@ public:
HashMap
*
hashmap
;
private:
obsys
::
C
ThreadMutex
mutex
;
obsys
::
ThreadMutex
mutex
;
};
TEST
(
TestObConcurrentHashMap
,
concurrent
)
...
...
deps/oblib/unittest/lib/hash/test_concurrent_hash_map_with_hazard_value.cpp
浏览文件 @
68cd5587
...
...
@@ -175,7 +175,7 @@ public:
HashMap
*
hashmap
;
private:
obsys
::
C
ThreadMutex
mutex
;
obsys
::
ThreadMutex
mutex
;
int
finished_count
;
};
...
...
src/election/ob_election_async_log.cpp
浏览文件 @
68cd5587
...
...
@@ -17,7 +17,7 @@
#include "lib/wait_event/ob_wait_event.h"
#include "lib/stat/ob_diagnose_info.h"
using
namespace
t
butil
;
using
namespace
o
butil
;
namespace
oceanbase
{
using
namespace
common
;
...
...
src/election/ob_election_async_log.h
浏览文件 @
68cd5587
...
...
@@ -17,8 +17,8 @@
#include <stdlib.h>
#include <sys/types.h>
#include <algorithm>
#include "lib/lock/
M
utex.h"
#include "lib/lock/
M
onitor.h"
#include "lib/lock/
m
utex.h"
#include "lib/lock/
ob_m
onitor.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
<
t
butil
::
Mutex
>
monitor_
;
obutil
::
ObMonitor
<
o
butil
::
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
<
t
butil
::
Mutex
>::
Lock
guard
(
monitor_
);
obutil
::
ObMonitor
<
o
butil
::
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
<
t
butil
::
Mutex
>::
Lock
guard
(
monitor_
);
obutil
::
ObMonitor
<
o
butil
::
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
<
t
butil
::
Mutex
>::
Lock
guard
(
monitor_
);
obutil
::
ObMonitor
<
o
butil
::
Mutex
>::
Lock
guard
(
monitor_
);
if
(
!
destroyed_
)
{
monitor_
.
notify
A
ll
();
monitor_
.
notify
_a
ll
();
destroyed_
=
true
;
}
}
...
...
src/election/ob_election_base.cpp
浏览文件 @
68cd5587
...
...
@@ -11,9 +11,9 @@
*/
#include <execinfo.h>
#include "lib/lock/
M
onitor.h"
#include "lib/lock/
ob_m
onitor.h"
#include "lib/net/ob_addr.h"
#include "lib/net/
tbnet
util.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
t
butil
;
using
namespace
o
butil
;
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
::
getLocalAddr
6
(
dev
,
ipv6
,
sizeof
(
ipv6
))))
{
if
(
OB_FAIL
(
obsys
::
ObNetUtil
::
get_local_addr_ipv
6
(
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
<
t
butil
::
Mutex
>
monitor_
;
(
void
)
monitor_
.
timed
Wait
(
Time
(
ms
*
1000
));
obutil
::
ObMonitor
<
o
butil
::
Mutex
>
monitor_
;
(
void
)
monitor_
.
timed
_wait
(
ObSys
Time
(
ms
*
1000
));
}
}
// namespace election
...
...
src/observer/mysql/ob_eliminate_task.cpp
浏览文件 @
68cd5587
...
...
@@ -149,7 +149,7 @@ void ObEliminateTask::runTimerTask()
}
}
if
(
OB_SUCC
(
ret
))
{
int64_t
start_time
=
obsys
::
C
TimeUtil
::
getTime
();
int64_t
start_time
=
obsys
::
ObSys
TimeUtil
::
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
::
C
TimeUtil
::
getTime
();
int64_t
end_time
=
obsys
::
ObSys
TimeUtil
::
getTime
();
LOG_INFO
(
"sql audit evict task end"
,
K
(
evict_high_level
),
K
(
evict_batch_count
),
...
...
src/observer/ob_server.cpp
浏览文件 @
68cd5587
...
...
@@ -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/
tbnet
util.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
::
getLocalAddr
6
(
config_
.
devname
,
ipv6
,
sizeof
(
ipv6
));
obsys
::
ObNetUtil
::
get_local_addr_ipv
6
(
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
);
}
...
...
src/observer/omt/ob_tenant_config.cpp
浏览文件 @
68cd5587
...
...
@@ -14,7 +14,7 @@
#include "ob_tenant_config.h"
#include "common/ob_common_utility.h"
#include "lib/net/
tbnet
util.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_
.
try
L
ock
())
{
if
(
!
mutex_
.
try
l
ock
())
{
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
::
C
TimeUtil
::
getMonotonicTime
();
update_task_
.
scheduled_time_
=
obsys
::
ObSys
TimeUtil
::
getMonotonicTime
();
schedule_task
=
true
;
}
else
if
(
version
<
newest_version_
)
{
LOG_WARN
(
"Receive weird tenant config version"
,
K_
(
current_version
),
K_
(
newest_version
),
K
(
version
));
...
...
src/observer/omt/ob_tenant_config.h
浏览文件 @
68cd5587
...
...
@@ -67,7 +67,7 @@ public:
volatile
int64_t
version_
;
volatile
int64_t
scheduled_time_
;
bool
update_local_
;
t
butil
::
Mutex
task_lock_
;
o
butil
::
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_
;
t
butil
::
Mutex
mutex_
;
o
butil
::
Mutex
mutex_
;
TenantConfigUpdateTask
update_task_
;
common
::
ObSystemConfig
system_config_
;
ObTenantConfigMgr
*
config_mgr_
;
...
...
src/observer/omt/ob_tenant_config_mgr.cpp
浏览文件 @
68cd5587
...
...
@@ -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_
.
try
L
ock
())
{
if
(
task
.
task_lock_
.
try
l
ock
())
{
if
(
!
task
.
is_running_
)
{
task
.
task_lock_
.
unlock
();
break
;
...
...
src/observer/omt/ob_tenant_timezone.cpp
浏览文件 @
68cd5587
...
...
@@ -13,7 +13,7 @@
#define USING_LOG_PREFIX SERVER_OMT
#include "common/ob_common_utility.h"
#include "lib/net/
tbnet
util.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_
.
try
L
ock
())
{
if
(
task_lock_
.
try
l
ock
())
{
if
(
!
tenant_tz_mgr_
->
get_start_refresh
())
{
const
int64_t
delay
=
1
*
1000
*
1000
;
const
bool
repeat
=
false
;
...
...
src/observer/omt/ob_tenant_timezone.h
浏览文件 @
68cd5587
...
...
@@ -46,7 +46,7 @@ public:
void
runTimerTask
(
void
)
override
;
ObTenantTimezoneMgr
*
tenant_tz_mgr_
;
ObTenantTimezone
*
tenant_tz_
;
t
butil
::
Mutex
task_lock_
;
o
butil
::
Mutex
task_lock_
;
const
uint64_t
SLEEP_USECONDS
=
5000000
;
};
friend
class
TenantTZUpdateTask
;
...
...
src/observer/omt/ob_tenant_timezone_mgr.cpp
浏览文件 @
68cd5587
...
...
@@ -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_
.
try
L
ock
())
{
if
(
task
.
task_lock_
.
try
l
ock
())
{
locked
=
true
;
break
;
}
...
...
src/share/allocator/ob_tenant_mutil_allocator_mgr.cpp
浏览文件 @
68cd5587
...
...
@@ -82,7 +82,7 @@ int ObTenantMutilAllocatorMgr::get_tenant_mutil_allocator(
bool
is_need_create
=
false
;
do
{
// rdlock
obsys
::
C
RLockGuard
guard
(
locks_
[
slot
]);
obsys
::
Ob
RLockGuard
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
::
C
WLockGuard
guard
(
locks_
[
slot
]);
obsys
::
Ob
WLockGuard
guard
(
locks_
[
slot
]);
if
(
OB_SUCC
(
ret
))
{
bool
is_need_create
=
false
;
TMA
**
cur
=
&
tma_array_
[
slot
];
...
...
src/share/allocator/ob_tenant_mutil_allocator_mgr.h
浏览文件 @
68cd5587
...
...
@@ -68,7 +68,7 @@ private:
private:
bool
is_inited_
;
obsys
::
C
RWLock
locks_
[
PRESERVED_TENANT_COUNT
];
obsys
::
Ob
RWLock
locks_
[
PRESERVED_TENANT_COUNT
];
ObTenantMutilAllocator
*
tma_array_
[
PRESERVED_TENANT_COUNT
];
ObBlockAllocMgr
clog_body_blk_alloc_
;
ObVSliceAlloc
clog_entry_alloc_
;
...
...
src/share/config/ob_config_manager.cpp
浏览文件 @
68cd5587
...
...
@@ -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
::
C
TimeUtil
::
getMonotonicTime
();
update_task_
.
scheduled_time_
=
obsys
::
ObSys
TimeUtil
::
getMonotonicTime
();
if
(
OB_FAIL
(
TG_SCHEDULE
(
lib
::
TGDefIDs
::
CONFIG_MGR
,
update_task_
,
0
,
false
)))
{
LOG_ERROR
(
"Update local config failed"
,
K
(
ret
));
}
else
{
...
...
src/share/config/ob_config_manager.h
浏览文件 @
68cd5587
...
...
@@ -89,7 +89,7 @@ private:
int64_t
current_version_
;
char
dump_path_
[
OB_MAX_FILE_NAME_LENGTH
];
ObReloadConfig
&
reload_config_func_
;
t
butil
::
Mutex
mutex_
;
o
butil
::
Mutex
mutex_
;
DISALLOW_COPY_AND_ASSIGN
(
ObConfigManager
);
};
...
...
src/share/config/ob_server_config.cpp
浏览文件 @
68cd5587
...
...
@@ -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"
...
...
src/storage/memtable/ob_lock_wait_mgr.cpp
浏览文件 @
68cd5587
...
...
@@ -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
::
C
TimeUtil
::
getTime
()
-
node
->
lock_ts_
);
EVENT_ADD
(
MEMSTORE_WAIT_WRITE_LOCK_TIME
,
obsys
::
ObSys
TimeUtil
::
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
::
C
TimeUtil
::
getTime
())
{
if
(
node
->
get_run_ts
()
>
obsys
::
ObSys
TimeUtil
::
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
::
C
TimeUtil
::
getTime
()
>
iter
->
get_run_ts
()))
{
(
iter
->
get_run_ts
()
>
0
&&
obsys
::
ObSys
TimeUtil
::
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
::
C
TimeUtil
::
getTime
()
-
node
->
lock_ts_
);
EVENT_ADD
(
MEMSTORE_WAIT_WRITE_LOCK_TIME
,
obsys
::
ObSys
TimeUtil
::
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
::
C
TimeUtil
::
getTime
()
+
50
*
1000
);
node
->
update_run_ts
(
obsys
::
ObSys
TimeUtil
::
getTime
()
+
50
*
1000
);
TRANS_LOG
(
INFO
,
"LOCK_MGR: delay header node"
);
}
}
...
...
src/storage/ob_partition_scheduler.cpp
浏览文件 @
68cd5587
...
...
@@ -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
::
C
WLockGuard
guard
(
lock_
);
obsys
::
Ob
WLockGuard
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
::
C
WLockGuard
guard
(
lock_
);
obsys
::
Ob
WLockGuard
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
::
C
RLockGuard
guard
(
lock_
);
obsys
::
Ob
RLockGuard
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
::
C
WLockGuard
frozen_version_guard
(
frozen_version_lock_
);
obsys
::
Ob
WLockGuard
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
::
C
RLockGuard
frozen_version_guard
(
frozen_version_lock_
);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
frozen_version_guard
(
frozen_version_lock_
);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
frozen_version_guard
(
frozen_version_lock_
);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
frozen_version_guard
(
frozen_version_lock_
);
obsys
::
Ob
RLockGuard
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
::
C
RLockGuard
lock_guard
(
frozen_version_lock_
);
obsys
::
Ob
RLockGuard
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
::
C
WLockGuard
lock_guard
(
frozen_version_lock_
);
obsys
::
Ob
WLockGuard
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
::
C
RLockGuard
lock_guard
(
frozen_version_lock_
);
obsys
::
Ob
RLockGuard
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
));
...
...
src/storage/ob_partition_scheduler.h
浏览文件 @
68cd5587
...
...
@@ -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
::
C
RWLock
lock_
;
obsys
::
Ob
RWLock
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
::
C
RWLock
frozen_version_lock_
;
mutable
obsys
::
Ob
RWLock
frozen_version_lock_
;
mutable
lib
::
ObMutex
timer_lock_
;
bool
first_most_merged_
;
bool
inited_
;
...
...
src/storage/transaction/ob_time_wheel.cpp
浏览文件 @
68cd5587
...
...
@@ -19,7 +19,7 @@ namespace oceanbase {
namespace
common
{
using
namespace
t
butil
;
using
namespace
o
butil
;
void
ObTimeWheelTask
::
reset
()
{
...
...
src/storage/transaction/ob_trans_result.cpp
浏览文件 @
68cd5587
...
...
@@ -18,7 +18,7 @@ namespace oceanbase {
namespace
transaction
{
using
namespace
common
;
using
namespace
t
butil
;
using
namespace
o
butil
;
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_
);
Ob
Monitor
<
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_
.
timed
Wait
(
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_
);
Ob
Monitor
<
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_
.
notify
A
ll
();
monitor_
.
notify
_a
ll
();
}
void
ObTransCond
::
usleep
(
const
int64_t
us
)
{
if
(
us
>
0
)
{
Monitor
<
Mutex
>
monitor
;
Ob
Monitor
<
Mutex
>
monitor
;
THIS_WORKER
.
sched_wait
();
(
void
)
monitor
.
timed
Wait
(
Time
(
us
));
(
void
)
monitor
.
timed
_wait
(
ObSys
Time
(
us
));
THIS_WORKER
.
sched_run
();
}
}
...
...
src/storage/transaction/ob_trans_result.h
浏览文件 @
68cd5587
...
...
@@ -14,8 +14,8 @@
#define OCEANBASE_TRANSACTION_OB_TRANS_COND_
#include <stdint.h>
#include "lib/lock/
M
onitor.h"
#include "lib/lock/
M
utex.h"
#include "lib/lock/
ob_m
onitor.h"
#include "lib/lock/
m
utex.h"
#include "share/ob_define.h"
namespace
oceanbase
{
...
...
@@ -48,7 +48,7 @@ private:
private:
bool
finished_
;
mutable
tbutil
::
Monitor
<
t
butil
::
Mutex
>
monitor_
;
mutable
obutil
::
ObMonitor
<
o
butil
::
Mutex
>
monitor_
;
int
result_
;
};
...
...
unittest/election/test_election_base.cpp
浏览文件 @
68cd5587
...
...
@@ -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/
tbnet
util.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
());
}
...
...
unittest/share/schema/test_priv_mgr.cpp
浏览文件 @
68cd5587
...
...
@@ -37,7 +37,7 @@ protected:
void
TestPrivMgr
::
SetUp
()
{
// obsys::
C
Config c1;
// obsys::
ObSys
Config c1;
// priv_mgr_.init();
}
...
...
unittest/share/test_latch.cpp
浏览文件 @
68cd5587
...
...
@@ -30,7 +30,7 @@ public:
int64_t
round0_
;
int64_t
value0_
;
ObLatch
lock0_
;
obsys
::
C
RWLock
lock_
;
obsys
::
Ob
RWLock
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::
C
WLockGuard guard(lock_);
// obsys::
Ob
WLockGuard 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::
C
RLockGuard guard(lock_);
// obsys::
Ob
RLockGuard guard(lock_);
// ASSERT_EQ(OB_SUCCESS, ret);
}
}
...
...
unittest/sql/executor/ob_mock_utils.h
浏览文件 @
68cd5587
...
...
@@ -103,7 +103,7 @@ public:
private:
static
ObMockPacketQueueThread
*
instance_
;
static
t
butil
::
Mutex
locker_
;
static
o
butil
::
Mutex
locker_
;
};
}
// namespace sql
...
...
unittest/sql/parser/test_parser_perf.cpp
浏览文件 @
68cd5587
...
...
@@ -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
::
C
TimeUtil
::
getTime
();
t0
=
obsys
::
ObSys
TimeUtil
::
getTime
();
ret
=
parser
.
parse
(
query
,
parse_result
,
pmode
);
t1
=
obsys
::
C
TimeUtil
::
getTime
();
t1
=
obsys
::
ObSys
TimeUtil
::
getTime
();
if
(
OB_SUCC
(
ret
))
{
succ_cnt_
++
;
}
...
...
unittest/storage/mockcontainer/mock_ob_server.cpp
浏览文件 @
68cd5587
...
...
@@ -18,7 +18,7 @@
#include "lib/string/ob_sql_string.h"
#include "lib/io/ob_io_manager.h"
#include "lib/net/
tbnet
util.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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录