Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
indiff7643
Terarkdb
提交
4b7286ad
T
Terarkdb
项目概览
indiff7643
/
Terarkdb
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Terarkdb
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b7286ad
编写于
9月 23, 2020
作者:
P
Peter Dillinger
提交者:
奏之章
2月 08, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[cherry pick] update timer test
上级
5a0ac9d1
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
65 addition
and
32 deletion
+65
-32
CMakeLists.txt
CMakeLists.txt
+2
-1
TARGETS
TARGETS
+7
-0
db/db_impl.cc
db/db_impl.cc
+1
-1
db/db_impl_gc_ttl_test.cc
db/db_impl_gc_ttl_test.cc
+11
-10
db/periodic_work_scheduler_test.cc
db/periodic_work_scheduler_test.cc
+1
-0
src.mk
src.mk
+1
-0
util/mock_time_env.cc
util/mock_time_env.cc
+38
-0
util/mock_time_env.h
util/mock_time_env.h
+4
-20
未找到文件。
CMakeLists.txt
浏览文件 @
4b7286ad
...
...
@@ -919,7 +919,8 @@ endif()
IF
(
WITH_TESTS OR WITH_TOOLS
)
add_library
(
testharness OBJECT util/testharness.cc
)
add_library
(
testharness OBJECT util/testharness.cc util/mock_time_env.cc
)
target_link_libraries
(
testharness gtest
)
ENDIF
()
if
(
WITH_TESTS
)
...
...
TARGETS
浏览文件 @
4b7286ad
...
...
@@ -609,6 +609,13 @@ cpp_library(
srcs = [
"db/db_test_util.cc",
"table/mock_table.cc",
<<<<<<< HEAD
=======
"test_util/mock_time_env.cc",
"test_util/testharness.cc",
"test_util/testutil.cc",
"tools/block_cache_analyzer/block_cache_trace_analyzer.cc",
>>>>>>> ac1734d06... Fix/minimize mock_time_env.h dependencies (#7426)
"tools/trace_analyzer_tool.cc",
"util/fault_injection_test_env.cc",
"util/testharness.cc",
...
...
db/db_impl.cc
浏览文件 @
4b7286ad
...
...
@@ -926,7 +926,7 @@ void DBImpl::ScheduleGCTTL() {
TEST_SYNC_POINT
(
"DBImpl:ScheduleGCTTL"
);
uint64_t
mark_count
=
0
;
uint64_t
marked_count
=
0
;
uint64_t
nowSeconds
=
env_
->
NowMicros
()
/
1000
000
;
uint64_t
nowSeconds
=
env_
->
NowMicros
()
/
1000
U
/
1000U
;
auto
should_marked_for_compacted
=
[](
uint64_t
ratio_expire_time
,
uint64_t
scan_gap_expire_time
,
uint64_t
now
)
{
...
...
db/db_impl_gc_ttl_test.cc
浏览文件 @
4b7286ad
...
...
@@ -12,18 +12,22 @@ namespace rocksdb {
class
DBImplGCTTL_Test
:
public
DBTestBase
{
public:
DBImplGCTTL_Test
()
:
DBTestBase
(
"/db_GC_ttl_test"
){
}
void
init
()
{
void
init
(){
rocksdb
::
SyncPoint
::
GetInstance
()
->
SetCallBack
(
"DBImpl:ScheduleGCTTL"
,
[
&
](
void
*
/*arg*/
)
{
mark
=
0
;
flag
=
true
;});
[
&
](
void
*
/*arg*/
)
{
mark
=
0
;
flag
=
true
;
});
rocksdb
::
SyncPoint
::
GetInstance
()
->
SetCallBack
(
"DBImpl:ScheduleGCTTL-mark"
,
[
&
](
void
*
/*arg*/
)
{
mark
++
;});
SyncPoint
::
GetInstance
()
->
EnableProcessing
();
dbname
=
test
::
PerThreadDBPath
(
"ttl_gc_test"
);
ASSERT_OK
(
DestroyDB
(
dbname
,
options
)
);
DestroyDB
(
dbname
,
options
);
options
.
create_if_missing
=
true
;
options
.
ttl_garbage_collection_percentage
=
50.0
;
...
...
@@ -32,10 +36,10 @@ class DBImplGCTTL_Test : public DBTestBase {
options
.
level0_file_num_compaction_trigger
=
8
;
options
.
stats_dump_period_sec
=
10
;
options
.
table_factory
.
reset
(
new
BlockBasedTableFactory
(
BlockBasedTableOptions
()));
}
protected:
std
::
unique_ptr
<
rocksdb
::
MockTimeEnv
>
mock_env
;
Options
options
;
std
::
string
dbname
;
bool
flag
=
false
;
...
...
@@ -44,14 +48,13 @@ class DBImplGCTTL_Test : public DBTestBase {
TEST_F
(
DBImplGCTTL_Test
,
L0FileExpiredTest
)
{
init
();
std
::
unique_ptr
<
rocksdb
::
MockTimeEnv
>
mock_env
;
int
L0FilesNums
=
4
;
uint64_t
ttl
=
200
;
mock_env
.
reset
(
new
rocksdb
::
MockTimeEnv
(
env_
));
mock_env
->
set_current_time
(
0
);
// in seconds
mock_env
->
set_current_time
(
ttl
);
// in seconds
options
.
env
=
mock_env
.
get
();
Reopen
(
options
);
int
L0FilesNums
=
4
;
uint64_t
ttl
=
200
;
char
ts_string
[
8
];
EncodeFixed64
(
ts_string
,
ttl
);
int
KeyEntrys
=
800
;
...
...
@@ -72,8 +75,6 @@ TEST_F(DBImplGCTTL_Test, L0FileExpiredTest) {
ASSERT_TRUE
(
flag
);
ASSERT_EQ
(
L0FilesNums
,
mark
);
dbfull
()
->
TEST_WaitForCompact
();
dbfull
()
->
Close
();
}
}
// namespace rocksdb
...
...
db/periodic_work_scheduler_test.cc
浏览文件 @
4b7286ad
...
...
@@ -6,6 +6,7 @@
#include "db/periodic_work_scheduler.h"
#include "db/db_test_util.h"
#include "util/cast_util.h"
namespace
rocksdb
{
...
...
src.mk
浏览文件 @
4b7286ad
...
...
@@ -314,6 +314,7 @@ TEST_LIB_SOURCES = \
=======
TEST_LIB_SOURCES
=
\
db/db_test_util.cc
\
test_util/mock_time_env.cc
\
test_util/testharness.cc
\
test_util/testutil.cc
\
>>>>>>>
671d15cbd... Persistent Stats: persist stats
history
to disk
(
#5046
)
...
...
util/mock_time_env.cc
0 → 100644
浏览文件 @
4b7286ad
// Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
// This source code is licensed under both the GPLv2 (found in the
// COPYING file in the root directory) and Apache 2.0 License
// (found in the LICENSE.Apache file in the root directory).
#include "util/mock_time_env.h"
#include "util/sync_point.h"
namespace
rocksdb
{
// TODO: this is a workaround for the different behavior on different platform
// for timedwait timeout. Ideally timedwait API should be moved to env.
// details: PR #7101.
void
MockTimeEnv
::
InstallTimedWaitFixCallback
()
{
#ifndef NDEBUG
SyncPoint
::
GetInstance
()
->
DisableProcessing
();
SyncPoint
::
GetInstance
()
->
ClearAllCallBacks
();
#ifdef OS_MACOSX
// This is an alternate way (vs. SpecialEnv) of dealing with the fact
// that on some platforms, pthread_cond_timedwait does not appear to
// release the lock for other threads to operate if the deadline time
// is already passed. (TimedWait calls are currently a bad abstraction
// because the deadline parameter is usually computed from Env time,
// but is interpreted in real clock time.)
SyncPoint
::
GetInstance
()
->
SetCallBack
(
"InstrumentedCondVar::TimedWaitInternal"
,
[
&
](
void
*
arg
)
{
uint64_t
time_us
=
*
reinterpret_cast
<
uint64_t
*>
(
arg
);
if
(
time_us
<
this
->
RealNowMicros
())
{
*
reinterpret_cast
<
uint64_t
*>
(
arg
)
=
this
->
RealNowMicros
()
+
1000
;
}
});
#endif // OS_MACOSX
SyncPoint
::
GetInstance
()
->
EnableProcessing
();
#endif // !NDEBUG
}
}
// namespace ROCKSDB_NAMESPACE
util/mock_time_env.h
浏览文件 @
4b7286ad
...
...
@@ -5,6 +5,8 @@
#pragma once
#include <atomic>
#include "rocksdb/env.h"
#include "rocksdb/terark_namespace.h"
...
...
@@ -60,29 +62,11 @@ class MockTimeEnv : public EnvWrapper {
// TODO: this is a workaround for the different behavior on different platform
// for timedwait timeout. Ideally timedwait API should be moved to env.
// details: PR #7101.
void
InstallTimedWaitFixCallback
()
{
SyncPoint
::
GetInstance
()
->
DisableProcessing
();
SyncPoint
::
GetInstance
()
->
ClearAllCallBacks
();
#if defined(OS_MACOSX) && !defined(NDEBUG)
// This is an alternate way (vs. SpecialEnv) of dealing with the fact
// that on some platforms, pthread_cond_timedwait does not appear to
// release the lock for other threads to operate if the deadline time
// is already passed. (TimedWait calls are currently a bad abstraction
// because the deadline parameter is usually computed from Env time,
// but is interpreted in real clock time.)
SyncPoint
::
GetInstance
()
->
SetCallBack
(
"InstrumentedCondVar::TimedWaitInternal"
,
[
&
](
void
*
arg
)
{
uint64_t
time_us
=
*
reinterpret_cast
<
uint64_t
*>
(
arg
);
if
(
time_us
<
this
->
RealNowMicros
())
{
*
reinterpret_cast
<
uint64_t
*>
(
arg
)
=
this
->
RealNowMicros
()
+
1000
;
}
});
#endif // OS_MACOSX && !NDEBUG
SyncPoint
::
GetInstance
()
->
EnableProcessing
();
}
void
InstallTimedWaitFixCallback
();
private:
std
::
atomic
<
uint64_t
>
current_time_us_
{
0
};
static
constexpr
uint64_t
kMicrosInSecond
=
1000U
*
1000U
;
};
}
// namespace TERARKDB_NAMESPACE
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录