Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
indiff7643
Terarkdb
提交
3d2e709b
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,发现更多精彩内容 >>
未验证
提交
3d2e709b
编写于
8月 25, 2021
作者:
J
Jim Lin
提交者:
GitHub
8月 25, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: skip value get (#114)
* feat: skip value get Co-authored-by:
N
wangyi
<
wangyi.ywq@bytedance.com
>
上级
49ab7e3b
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
78 addition
and
23 deletion
+78
-23
db/db_impl.cc
db/db_impl.cc
+2
-3
db/db_test.cc
db/db_test.cc
+32
-0
db/memtable.cc
db/memtable.cc
+11
-9
db/merge_test.cc
db/merge_test.cc
+3
-0
db/version_set.cc
db/version_set.cc
+7
-5
include/rocksdb/db.h
include/rocksdb/db.h
+19
-6
utilities/ttl/db_ttl_impl.cc
utilities/ttl/db_ttl_impl.cc
+4
-0
未找到文件。
db/db_impl.cc
浏览文件 @
3d2e709b
...
...
@@ -1637,7 +1637,7 @@ Status DBImpl::Get(const ReadOptions& read_options,
ColumnFamilyHandle
*
column_family
,
const
Slice
&
key
,
LazyBuffer
*
value
)
{
auto
s
=
GetImpl
(
read_options
,
column_family
,
key
,
value
);
assert
(
!
s
.
ok
()
||
value
->
valid
());
assert
(
!
s
.
ok
()
||
value
==
nullptr
||
value
->
valid
());
return
s
;
}
...
...
@@ -1648,7 +1648,6 @@ Status DBImpl::GetImpl(const ReadOptions& read_options,
LatencyHistGuard
guard
(
&
read_latency_reporter_
);
read_qps_reporter_
.
AddCount
(
1
);
assert
(
lazy_val
!=
nullptr
);
StopWatch
sw
(
env_
,
stats_
,
DB_GET
);
PERF_TIMER_GUARD
(
get_snapshot_time
);
...
...
@@ -1742,7 +1741,7 @@ Status DBImpl::GetImpl(const ReadOptions& read_options,
RecordTick
(
stats_
,
MEMTABLE_MISS
);
}
if
(
s
.
ok
())
{
if
(
s
.
ok
()
&&
lazy_val
!=
nullptr
)
{
lazy_val
->
pin
(
LazyBufferPinLevel
::
DB
);
s
=
lazy_val
->
fetch
();
}
...
...
db/db_test.cc
浏览文件 @
3d2e709b
...
...
@@ -5684,6 +5684,38 @@ TEST_F(DBTest, ThreadLocalPtrDeadlock) {
fprintf
(
stderr
,
"Done. Flushed %d times, destroyed %d threads
\n
"
,
flushes_done
.
load
(),
threads_destroyed
.
load
());
}
TEST_F
(
DBTest
,
SkipValueGet
)
{
Options
options
=
CurrentOptions
();
DestroyAndReopen
(
options
);
ASSERT_OK
(
Put
(
Key
(
0
),
""
));
// memtable get
auto
s
=
db_
->
Get
(
ReadOptions
{},
db_
->
DefaultColumnFamily
(),
Key
(
0
));
ASSERT_OK
(
s
);
s
=
db_
->
Get
(
ReadOptions
{},
db_
->
DefaultColumnFamily
(),
Key
(
0
),
static_cast
<
LazyBuffer
*>
(
nullptr
));
ASSERT_OK
(
s
);
s
=
db_
->
Get
(
ReadOptions
{},
Key
(
0
),
static_cast
<
std
::
string
*>
(
nullptr
));
ASSERT_OK
(
s
);
s
=
db_
->
Get
(
ReadOptions
{},
Key
(
1
),
static_cast
<
std
::
string
*>
(
nullptr
));
ASSERT_TRUE
(
s
.
IsNotFound
());
ASSERT_OK
(
Flush
());
dbfull
()
->
TEST_WaitForFlushMemTable
();
// sst get
s
=
db_
->
Get
(
ReadOptions
{},
db_
->
DefaultColumnFamily
(),
Key
(
0
));
ASSERT_OK
(
s
);
s
=
db_
->
Get
(
ReadOptions
{},
db_
->
DefaultColumnFamily
(),
Key
(
0
),
static_cast
<
LazyBuffer
*>
(
nullptr
));
ASSERT_OK
(
s
);
s
=
db_
->
Get
(
ReadOptions
{},
Key
(
0
),
static_cast
<
std
::
string
*>
(
nullptr
));
ASSERT_OK
(
s
);
s
=
db_
->
Get
(
ReadOptions
{},
Key
(
1
),
static_cast
<
std
::
string
*>
(
nullptr
));
ASSERT_TRUE
(
s
.
IsNotFound
());
}
}
// namespace TERARKDB_NAMESPACE
int
main
(
int
argc
,
char
**
argv
)
{
...
...
db/memtable.cc
浏览文件 @
3d2e709b
...
...
@@ -773,7 +773,7 @@ static bool SaveValue(void* arg, const Slice& internal_key, const char* value) {
}
*
s
->
status
=
Status
::
OK
();
if
(
*
s
->
merge_in_progress
)
{
if
(
s
->
value
!=
nullptr
)
{
if
(
LIKELY
(
s
->
value
!=
nullptr
)
)
{
LazyBuffer
lazy_val
(
GetLengthPrefixedSlice
(
value
),
false
);
*
s
->
status
=
MergeHelper
::
TimedFullMerge
(
merge_operator
,
s
->
key
->
user_key
(),
&
lazy_val
,
...
...
@@ -783,7 +783,7 @@ static bool SaveValue(void* arg, const Slice& internal_key, const char* value) {
s
->
value
->
pin
(
LazyBufferPinLevel
::
Internal
);
}
}
}
else
if
(
s
->
value
!=
nullptr
)
{
}
else
if
(
LIKELY
(
s
->
value
!=
nullptr
)
)
{
s
->
value
->
reset
(
GetLengthPrefixedSlice
(
value
),
s
->
inplace_update_support
);
}
...
...
@@ -797,7 +797,7 @@ static bool SaveValue(void* arg, const Slice& internal_key, const char* value) {
case
kTypeSingleDeletion
:
case
kTypeRangeDeletion
:
{
if
(
*
s
->
merge_in_progress
)
{
if
(
s
->
value
!=
nullptr
)
{
if
(
LIKELY
(
s
->
value
!=
nullptr
)
)
{
*
s
->
status
=
MergeHelper
::
TimedFullMerge
(
merge_operator
,
s
->
key
->
user_key
(),
nullptr
,
merge_context
->
GetOperands
(),
s
->
value
,
s
->
logger
,
...
...
@@ -831,13 +831,15 @@ static bool SaveValue(void* arg, const Slice& internal_key, const char* value) {
LazyBuffer
(
GetLengthPrefixedSlice
(
value
),
Cleanable
()));
if
(
merge_operator
->
ShouldMerge
(
merge_context
->
GetOperandsDirectionBackward
()))
{
if
(
LIKELY
(
s
->
value
!=
nullptr
))
{
*
s
->
status
=
MergeHelper
::
TimedFullMerge
(
merge_operator
,
s
->
key
->
user_key
(),
nullptr
,
merge_context
->
GetOperands
(),
s
->
value
,
s
->
logger
,
s
->
statistics
,
s
->
env_
,
true
);
merge_context
->
GetOperands
(),
s
->
value
,
s
->
logger
,
s
->
statistics
,
s
->
env_
,
true
);
if
(
s
->
status
->
ok
())
{
s
->
value
->
pin
(
LazyBufferPinLevel
::
Internal
);
}
}
*
s
->
found_final_value
=
true
;
return
false
;
}
...
...
db/merge_test.cc
浏览文件 @
3d2e709b
...
...
@@ -169,6 +169,9 @@ class Counters {
bool
get
(
const
std
::
string
&
key
,
uint64_t
*
value
)
{
std
::
string
str
;
auto
s
=
db_
->
Get
(
get_option_
,
key
,
&
str
);
auto
x
=
num_merge_operator_calls
;
assert
(
db_
->
Get
(
get_option_
,
key
).
code
()
==
s
.
code
());
num_merge_operator_calls
=
x
;
if
(
s
.
IsNotFound
())
{
// return default value if not found;
...
...
db/version_set.cc
浏览文件 @
3d2e709b
...
...
@@ -1410,12 +1410,14 @@ void Version::Get(const ReadOptions& read_options, const Slice& user_key,
}
// merge_operands are in saver and we hit the beginning of the key history
// do a final merge of nullptr and operands;
if
(
value
!=
nullptr
)
{
*
status
=
MergeHelper
::
TimedFullMerge
(
merge_operator_
,
user_key
,
nullptr
,
merge_context
->
GetOperands
(),
value
,
info_log_
,
db_statistics_
,
env_
,
true
);
merge_operator_
,
user_key
,
nullptr
,
merge_context
->
GetOperands
()
,
value
,
info_log_
,
db_statistics_
,
env_
,
true
);
if
(
status
->
ok
())
{
value
->
pin
(
LazyBufferPinLevel
::
Internal
);
}
}
}
else
{
if
(
key_exists
!=
nullptr
)
{
*
key_exists
=
false
;
...
...
include/rocksdb/db.h
浏览文件 @
3d2e709b
...
...
@@ -353,6 +353,7 @@ class DB {
// If the database contains an entry for "key" store the
// corresponding value in *value and return OK.
// If "value" equals to nullptr, the corresponding value will not be loaded.
//
// If there is no entry for "key" leave *value unchanged and return
// a status for which Status::IsNotFound() returns true.
...
...
@@ -361,21 +362,33 @@ class DB {
virtual
inline
Status
Get
(
const
ReadOptions
&
options
,
ColumnFamilyHandle
*
column_family
,
const
Slice
&
key
,
std
::
string
*
value
)
{
assert
(
value
!=
nullptr
);
if
(
value
!=
nullptr
)
{
LazyBuffer
lazy_val
(
value
);
auto
s
=
Get
(
options
,
column_family
,
key
,
&
lazy_val
);
if
(
s
.
ok
())
{
s
=
std
::
move
(
lazy_val
).
dump
(
value
);
}
return
s
;
}
else
{
return
Get
(
options
,
column_family
,
key
,
static_cast
<
LazyBuffer
*>
(
nullptr
));
}
}
virtual
Status
Get
(
const
ReadOptions
&
options
,
ColumnFamilyHandle
*
column_family
,
const
Slice
&
key
,
LazyBuffer
*
value
)
=
0
;
virtual
Status
Get
(
const
ReadOptions
&
options
,
ColumnFamilyHandle
*
column_family
,
const
Slice
&
key
)
{
return
Get
(
options
,
column_family
,
key
,
static_cast
<
LazyBuffer
*>
(
nullptr
));
}
virtual
Status
Get
(
const
ReadOptions
&
options
,
const
Slice
&
key
,
std
::
string
*
value
)
{
return
Get
(
options
,
DefaultColumnFamily
(),
key
,
value
);
}
virtual
Status
Get
(
const
ReadOptions
&
options
,
const
Slice
&
key
)
{
return
Get
(
options
,
DefaultColumnFamily
(),
key
,
static_cast
<
LazyBuffer
*>
(
nullptr
));
}
#ifdef BOOSTLIB
static
void
CallOnMainStack
(
const
std
::
function
<
void
()
>&
);
static
void
SubmitAsyncTask
(
std
::
function
<
void
()
>
);
...
...
utilities/ttl/db_ttl_impl.cc
浏览文件 @
3d2e709b
...
...
@@ -209,6 +209,10 @@ Status DBWithTTLImpl::Put(const WriteOptions& options,
Status
DBWithTTLImpl
::
Get
(
const
ReadOptions
&
options
,
ColumnFamilyHandle
*
column_family
,
const
Slice
&
key
,
LazyBuffer
*
value
)
{
LazyBuffer
buffer
;
if
(
value
==
nullptr
)
{
value
=
&
buffer
;
}
Status
st
=
db_
->
Get
(
options
,
column_family
,
key
,
value
);
if
(
!
st
.
ok
())
{
return
st
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录