Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
indiff7643
Terarkdb
提交
c9be9058
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,发现更多精彩内容 >>
提交
c9be9058
编写于
7月 22, 2020
作者:
Z
ZhaoMing
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix LIRS strict_capacity_limit bug
上级
35d933aa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
44 addition
and
43 deletion
+44
-43
cache/lirs_cache.cc
cache/lirs_cache.cc
+41
-42
cache/lirs_cache.h
cache/lirs_cache.h
+3
-1
未找到文件。
cache/lirs_cache.cc
浏览文件 @
c9be9058
...
...
@@ -220,17 +220,10 @@ void LIRSCacheShard::ApplyToAllCacheEntries(void (*callback)(void*, size_t),
void
LIRSCacheShard
::
LIRS_Remove
(
LIRSHandle
*
e
)
{
if
(
e
->
next_queue
!=
nullptr
)
{
e
->
next_queue
->
prev_queue
=
e
->
prev_queue
;
e
->
prev_queue
->
next_queue
=
e
->
next_queue
;
e
->
next_queue
=
e
->
prev_queue
=
nullptr
;
RemoveFromQueue
(
e
);
}
if
(
e
->
next_stack
!=
nullptr
)
{
e
->
next_stack
->
prev_stack
=
e
->
prev_stack
;
e
->
prev_stack
->
next_stack
=
e
->
next_stack
;
e
->
next_stack
=
e
->
prev_stack
=
nullptr
;
}
usage_
-=
e
->
charge
;
if
(
e
->
LIR
())
{
RemoveFromStack
(
e
);
stack_usage_
-=
e
->
charge
;
}
}
...
...
@@ -244,7 +237,6 @@ void LIRSCacheShard::LIRS_Insert(LIRSHandle* e) {
PushToQueue
(
e
);
e
->
SetHIR
();
}
usage_
+=
e
->
charge
;
}
void
LIRSCacheShard
::
EvictFromLIRS
(
size_t
charge
,
...
...
@@ -263,8 +255,9 @@ void LIRSCacheShard::EvictFromLIRS(size_t charge,
while
(
stack_usage_
+
charge
>
stack_capacity_
&&
cache_
.
prev_stack
!=
&
cache_
)
{
LIRSHandle
*
old
=
cache_
.
prev_stack
;
PushToQueue
(
old
);
stack_usage_
-=
old
->
charge
;
RemoveFromStack
(
old
);
PushToQueue
(
old
);
}
}
...
...
@@ -278,37 +271,39 @@ Cache::Handle* LIRSCacheShard::Lookup(const Slice& key, uint32_t hash) {
MutexLock
l
(
&
mutex_
);
LIRSHandle
*
h
=
table_
.
Lookup
(
key
,
hash
);
if
(
h
!=
nullptr
)
{
if
(
h
->
refs
==
1
)
{
LIRS_Remove
(
h
);
}
h
->
refs
++
;
if
(
h
->
LIR
())
{
AdjustToStackTop
(
h
);
}
else
if
(
h
->
HIR
())
{
if
(
h
->
next_stack
!=
nullptr
)
{
h
->
SetLIR
();
AdjustToStackTop
(
h
);
RemoveFromQueue
(
h
);
AdjustStackBottom
();
if
(
!
h
->
Remote
())
{
if
(
h
->
refs
==
1
)
{
LIRS_Remove
(
h
);
}
else
{
PushToStack
(
h
);
PushToQueue
(
h
);
AdjustToQueueTail
(
h
);
}
}
else
{
ShiftQueueHead
();
if
(
h
->
next_stack
!=
nullptr
)
{
h
->
SetLIR
();
AdjustToStackTop
(
h
);
AdjustStackBottom
();
}
else
{
h
->
SetHIR
();
PushToStack
(
h
);
PushToQueue
(
h
);
if
(
h
->
LIR
())
{
AdjustToStackTop
(
h
);
}
else
if
(
h
->
HIR
())
{
if
(
h
->
next_stack
!=
nullptr
)
{
h
->
SetLIR
();
AdjustToStackTop
(
h
);
RemoveFromQueue
(
h
);
AdjustStackBottom
();
}
else
{
PushToStack
(
h
);
AdjustToQueueTail
(
h
);
}
}
else
{
ShiftQueueHead
();
if
(
h
->
next_stack
!=
nullptr
)
{
h
->
SetLIR
();
AdjustToStackTop
(
h
);
AdjustStackBottom
();
}
else
{
h
->
SetHIR
();
PushToStack
(
h
);
PushToQueue
(
h
);
}
}
StackPruning
();
}
}
h
->
refs
++
;
}
StackPruning
();
return
reinterpret_cast
<
Cache
::
Handle
*>
(
h
);
}
...
...
@@ -377,9 +372,12 @@ Status LIRSCacheShard::Insert(const Slice& key, uint32_t hash, void* value,
{
MutexLock
l
(
&
mutex_
);
EvictFromLIRS
(
charge
,
&
last_reference_list
);
if
(
usage_
+
charge
>
capacity_
)
{
delete
[]
reinterpret_cast
<
char
*>
(
e
);
*
handle
=
nullptr
;
if
(
usage_
+
charge
>
capacity_
&&
strict_capacity_limit_
)
{
e
->
refs
=
0
;
last_reference_list
.
push_back
(
e
);
if
(
handle
!=
nullptr
)
{
*
handle
=
nullptr
;
}
s
=
Status
::
Incomplete
(
"Insert failed due to LIRS cache being full."
);
}
else
{
LIRSHandle
*
old
=
table_
.
Insert
(
e
);
...
...
@@ -394,6 +392,7 @@ Status LIRSCacheShard::Insert(const Slice& key, uint32_t hash, void* value,
if
(
handle
==
nullptr
)
{
LIRS_Insert
(
e
);
}
else
{
e
->
SetRemote
();
*
handle
=
reinterpret_cast
<
Cache
::
Handle
*>
(
e
);
}
s
=
Status
::
OK
();
...
...
@@ -542,4 +541,4 @@ std::shared_ptr<Cache> NewLIRSCache(
std
::
move
(
memory_allocator
));
}
}
// namespace rocksdb
}
// namespace rocksdb
\ No newline at end of file
cache/lirs_cache.h
浏览文件 @
c9be9058
...
...
@@ -21,18 +21,20 @@ struct LIRSHandle {
uint32_t
refs
;
uint32_t
hash
;
// Hash of key(); used for fast sharding and comparisons
enum
State
{
k
LIR
=
0
,
kHIR
,
kNHIR
,
kInvalid
}
state
;
enum
State
{
k
Remote
=
0
,
kLIR
,
kHIR
,
kNHIR
,
kInvalid
}
state
;
char
key_data
[
1
];
// Beginning of key
Slice
key
()
const
{
return
Slice
(
key_data
,
key_length
);
}
bool
Remote
()
{
return
state
==
kRemote
;
}
bool
LIR
()
{
return
state
==
kLIR
;
}
bool
HIR
()
{
return
state
==
kHIR
;
}
bool
InCache
()
{
return
state
==
kLIR
||
state
==
kHIR
||
state
==
kNHIR
;
}
bool
NHIR
()
{
return
state
==
kNHIR
;
}
bool
Valid
()
{
return
state
!=
kInvalid
;
}
void
SetRemote
()
{
state
=
kRemote
;
}
void
SetLIR
()
{
state
=
kLIR
;
}
void
SetHIR
()
{
state
=
kHIR
;
}
void
SetNHIR
()
{
state
=
kNHIR
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录