Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
indiff7643
Terarkdb
提交
30701dc1
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,发现更多精彩内容 >>
提交
30701dc1
编写于
9月 14, 2018
作者:
R
rockeet
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
memtable.cc: Refactory & minor bugfix
上级
dae84261
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
30 addition
and
27 deletion
+30
-27
db/memtable.cc
db/memtable.cc
+30
-27
未找到文件。
db/memtable.cc
浏览文件 @
30701dc1
...
...
@@ -36,6 +36,7 @@
#include "util/memory_usage.h"
#include "util/murmurhash.h"
#include "util/mutexlock.h"
#include "util/util.h"
namespace
rocksdb
{
...
...
@@ -117,10 +118,10 @@ MemTableRep* MemTableRepFactory::CreateMemTableRep(
const
MemTableRep
::
KeyComparator
&
key_cmp
,
Allocator
*
allocator
,
const
ImmutableCFOptions
&
ioptions
,
const
MutableCFOptions
&
mutable_cf_options
,
uint32_t
/* column_family_id */
)
{
uint32_t
column_family_id
)
{
return
CreateMemTableRep
(
key_cmp
,
allocator
,
mutable_cf_options
.
prefix_extractor
.
get
(),
ioptions
.
info_log
);
ioptions
.
info_log
,
column_family_id
);
}
MemTable
::~
MemTable
()
{
...
...
@@ -679,7 +680,7 @@ static bool SaveValue(void* arg, const MemTableRep::KeyValuePair* pair) {
*
(
s
->
found_final_value
)
=
true
;
return
false
;
}
// intentional fallthrough
FALLTHROUGH_INTENDED
;
case
kTypeValue
:
{
if
(
s
->
inplace_update_support
)
{
s
->
mem
->
GetLock
(
s
->
key
->
user_key
())
->
ReadLock
();
...
...
@@ -819,7 +820,8 @@ bool MemTable::Get(const LookupKey& key, std::string* value, Status* s,
return
found_final_value
;
}
void
MemTable
::
Update
(
SequenceNumber
seq
,
const
Slice
&
key
,
void
MemTable
::
Update
(
SequenceNumber
seq
,
const
Slice
&
key
,
const
Slice
&
value
)
{
LookupKey
lkey
(
key
,
seq
);
Slice
mem_key
=
lkey
.
memtable_key
();
...
...
@@ -831,8 +833,8 @@ void MemTable::Update(SequenceNumber seq, const Slice& key,
if
(
iter
->
Valid
())
{
// sequence number since the Seek() call above should have skipped
// all entries with overly large sequence numbers.
Slice
internal_key
,
prev
_value
;
std
::
tie
(
internal_key
,
prev
_value
)
=
iter
->
GetKeyValue
();
Slice
internal_key
,
old
_value
;
std
::
tie
(
internal_key
,
old
_value
)
=
iter
->
GetKeyValue
();
if
(
comparator_
.
comparator
.
user_comparator
()
->
Equal
(
ExtractUserKey
(
internal_key
),
lkey
.
user_key
()))
{
// Correct user key
...
...
@@ -842,13 +844,13 @@ void MemTable::Update(SequenceNumber seq, const Slice& key,
SequenceNumber
unused
;
UnPackSequenceAndType
(
tag
,
&
unused
,
&
type
);
if
(
type
==
kTypeValue
)
{
uint32_t
prev_size
=
static_cast
<
uint32_t
>
(
prev
_value
.
size
());
uint32_t
old_size
=
static_cast
<
uint32_t
>
(
old
_value
.
size
());
uint32_t
new_size
=
static_cast
<
uint32_t
>
(
value
.
size
());
// Update value, if new value size <=
previous
value size
if
(
new_size
<=
prev
_size
)
{
// Update value, if new value size <=
old
value size
if
(
new_size
<=
old
_size
)
{
char
*
p
=
const_cast
<
char
*>
(
prev_value
.
data
())
-
VarintLength
(
prev
_size
);
const_cast
<
char
*>
(
old_value
.
data
())
-
VarintLength
(
old
_size
);
p
=
EncodeVarint32
(
p
,
new_size
);
WriteLock
wl
(
GetLock
(
lkey
.
user_key
()));
memcpy
(
p
,
value
.
data
(),
value
.
size
());
...
...
@@ -863,7 +865,8 @@ void MemTable::Update(SequenceNumber seq, const Slice& key,
Add
(
seq
,
kTypeValue
,
key
,
value
);
}
bool
MemTable
::
UpdateCallback
(
SequenceNumber
seq
,
const
Slice
&
key
,
bool
MemTable
::
UpdateCallback
(
SequenceNumber
seq
,
const
Slice
&
key
,
const
Slice
&
delta
)
{
LookupKey
lkey
(
key
,
seq
);
Slice
memkey
=
lkey
.
memtable_key
();
...
...
@@ -876,8 +879,8 @@ bool MemTable::UpdateCallback(SequenceNumber seq, const Slice& key,
// Check that it belongs to same user key. We do not check the
// sequence number since the Seek() call above should have skipped
// all entries with overly large sequence numbers.
Slice
internal_key
,
prev
_value
;
std
::
tie
(
internal_key
,
prev
_value
)
=
iter
->
GetKeyValue
();
Slice
internal_key
,
old
_value
;
std
::
tie
(
internal_key
,
old
_value
)
=
iter
->
GetKeyValue
();
if
(
comparator_
.
comparator
.
user_comparator
()
->
Equal
(
ExtractUserKey
(
internal_key
),
lkey
.
user_key
()))
{
// Correct user key
...
...
@@ -888,33 +891,33 @@ bool MemTable::UpdateCallback(SequenceNumber seq, const Slice& key,
UnPackSequenceAndType
(
tag
,
&
unused
,
&
type
);
switch
(
type
)
{
case
kTypeValue
:
{
uint32_t
prev_size
=
static_cast
<
uint32_t
>
(
prev
_value
.
size
());
uint32_t
old_size
=
static_cast
<
uint32_t
>
(
old
_value
.
size
());
char
*
prev_buffer
=
const_cast
<
char
*>
(
prev
_value
.
data
());
uint32_t
new_
prev_size
=
prev
_size
;
char
*
old_buffer
=
const_cast
<
char
*>
(
old
_value
.
data
());
uint32_t
new_
inplace_size
=
old
_size
;
std
::
string
str
_value
;
std
::
string
merged
_value
;
WriteLock
wl
(
GetLock
(
lkey
.
user_key
()));
auto
status
=
moptions_
.
inplace_callback
(
prev_buffer
,
&
new_prev
_size
,
delta
,
&
str
_value
);
auto
status
=
moptions_
.
inplace_callback
(
old_buffer
,
&
new_inplace
_size
,
delta
,
&
merged
_value
);
if
(
status
==
UpdateStatus
::
UPDATED_INPLACE
)
{
// Value already updated by callback.
assert
(
new_
prev_size
<=
prev
_size
);
if
(
new_
prev_size
<
prev
_size
)
{
// overwrite the new
prev_
size
assert
(
new_
inplace_size
<=
old
_size
);
if
(
new_
inplace_size
<
old
_size
)
{
// overwrite the new
inplace
size
char
*
p
=
const_cast
<
char
*>
(
prev_value
.
data
())
-
VarintLength
(
prev
_size
);
p
=
EncodeVarint32
(
p
,
new_
prev
_size
);
if
(
p
<
prev
_buffer
)
{
const_cast
<
char
*>
(
old_value
.
data
())
-
VarintLength
(
old
_size
);
p
=
EncodeVarint32
(
p
,
new_
inplace
_size
);
if
(
p
<
old
_buffer
)
{
// shift the value buffer as well.
memmove
(
p
,
prev_buffer
,
new_prev
_size
);
memmove
(
p
,
old_buffer
,
new_inplace
_size
);
}
}
RecordTick
(
moptions_
.
statistics
,
NUMBER_KEYS_UPDATED
);
UpdateFlushState
();
return
true
;
}
else
if
(
status
==
UpdateStatus
::
UPDATED
)
{
Add
(
seq
,
kTypeValue
,
key
,
Slice
(
str
_value
));
Add
(
seq
,
kTypeValue
,
key
,
Slice
(
merged
_value
));
RecordTick
(
moptions_
.
statistics
,
NUMBER_KEYS_WRITTEN
);
UpdateFlushState
();
return
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录