Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
1e391a6c
提交
1e391a6c
authored
12 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
MVStore: simplify the cache API a bit
上级
606aa497
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
49 行增加
和
62 行删除
+49
-62
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+1
-1
CacheLongKeyLIRS.java
h2/src/main/org/h2/mvstore/cache/CacheLongKeyLIRS.java
+22
-29
FilePathCache.java
h2/src/main/org/h2/mvstore/cache/FilePathCache.java
+1
-1
TestCacheConcurrentLIRS.java
h2/src/test/org/h2/test/store/TestCacheConcurrentLIRS.java
+1
-1
TestCacheLIRS.java
h2/src/test/org/h2/test/store/TestCacheLIRS.java
+1
-1
TestCacheLongKeyLIRS.java
h2/src/test/org/h2/test/store/TestCacheLongKeyLIRS.java
+1
-1
CacheLIRS.java
h2/src/tools/org/h2/dev/cache/CacheLIRS.java
+22
-28
没有找到文件。
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
1e391a6c
...
...
@@ -203,7 +203,7 @@ public class MVStore {
if
(
fileName
!=
null
)
{
Object
s
=
config
.
get
(
"cacheSize"
);
int
mb
=
s
==
null
?
16
:
Integer
.
parseInt
(
s
.
toString
());
cache
=
CacheLongKeyLIRS
.
newInstance
(
cache
=
new
CacheLongKeyLIRS
<
Page
>
(
mb
*
1024
*
1024
,
2048
,
16
,
mb
*
1024
*
1024
/
2048
*
2
/
100
);
}
else
{
cache
=
null
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/cache/CacheLongKeyLIRS.java
浏览文件 @
1e391a6c
...
...
@@ -61,8 +61,28 @@ public class CacheLongKeyLIRS<V> {
private
final
int
segmentMask
;
private
final
int
stackMoveDistance
;
/**
* Create a new cache with the given number of entries, and the default
* settings (an average size of 1 per entry, 16 segments, and stack move
* distance equals to the maximum number of entries divided by 100).
*
* @param maxEntries the maximum number of entries
*/
public
CacheLongKeyLIRS
(
int
maxEntries
)
{
this
(
maxEntries
,
1
,
16
,
maxEntries
/
100
);
}
/**
* Create a new cache with the given memory size.
*
* @param maxMemory the maximum memory to use (1 or larger)
* @param averageMemory the average memory (1 or larger)
* @param segmentCount the number of cache segments (must be a power of 2)
* @param stackMoveDistance how many other item are to be moved to the top
* of the stack before the current item is moved
*/
@SuppressWarnings
(
"unchecked"
)
p
rivate
CacheLongKeyLIRS
(
long
maxMemory
,
int
averageMemory
,
int
segmentCount
,
int
stackMoveDistance
)
{
p
ublic
CacheLongKeyLIRS
(
long
maxMemory
,
int
averageMemory
,
int
segmentCount
,
int
stackMoveDistance
)
{
setMaxMemory
(
maxMemory
);
setAverageMemory
(
averageMemory
);
if
(
Integer
.
bitCount
(
segmentCount
)
!=
1
)
{
...
...
@@ -269,33 +289,6 @@ public class CacheLongKeyLIRS<V> {
return
maxMemory
;
}
/**
* Create a new cache with the given number of entries, and the default
* settings (an average size of 1 per entry, 16 segments, and stack move
* distance equals to the maximum number of entries divided by 100).
*
* @param maxEntries the maximum number of entries
* @return the cache
*/
public
static
<
K
,
V
>
CacheLongKeyLIRS
<
V
>
newInstance
(
int
maxEntries
)
{
return
new
CacheLongKeyLIRS
<
V
>(
maxEntries
,
1
,
16
,
maxEntries
/
100
);
}
/**
* Create a new cache with the given memory size.
*
* @param maxMemory the maximum memory to use (1 or larger)
* @param averageMemory the average memory (1 or larger)
* @param segmentCount the number of cache segments (must be a power of 2)
* @param stackMoveDistance how many other item are to be moved to the top
* of the stack before the current item is moved
* @return the cache
*/
public
static
<
V
>
CacheLongKeyLIRS
<
V
>
newInstance
(
int
maxMemory
,
int
averageMemory
,
int
segmentCount
,
int
stackMoveDistance
)
{
return
new
CacheLongKeyLIRS
<
V
>(
maxMemory
,
averageMemory
,
segmentCount
,
stackMoveDistance
);
}
/**
* Get the entry set for all resident entries.
*
...
...
@@ -458,7 +451,7 @@ public class CacheLongKeyLIRS<V> {
*
* @param <V> the value type
*/
static
class
Segment
<
V
>
{
private
static
class
Segment
<
V
>
{
/**
* The number of (hot, cold, and non-resident) entries in the map.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/mvstore/cache/FilePathCache.java
浏览文件 @
1e391a6c
...
...
@@ -39,7 +39,7 @@ public class FilePathCache extends FilePathWrapper {
private
final
FileChannel
base
;
// 1 MB (256 * 4 * 1024)
private
final
CacheLongKeyLIRS
<
ByteBuffer
>
cache
=
CacheLongKeyLIRS
.
newInstance
(
256
);
new
CacheLongKeyLIRS
<
ByteBuffer
>
(
256
);
FileCache
(
FileChannel
base
)
{
this
.
base
=
base
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/TestCacheConcurrentLIRS.java
浏览文件 @
1e391a6c
...
...
@@ -31,7 +31,7 @@ public class TestCacheConcurrentLIRS extends TestBase {
}
private
void
testConcurrent
()
{
final
CacheLongKeyLIRS
<
Integer
>
test
=
CacheLongKeyLIRS
.
newInstance
(
100
);
final
CacheLongKeyLIRS
<
Integer
>
test
=
new
CacheLongKeyLIRS
<
Integer
>
(
100
);
int
threadCount
=
8
;
final
CountDownLatch
wait
=
new
CountDownLatch
(
1
);
final
AtomicBoolean
stopped
=
new
AtomicBoolean
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/TestCacheLIRS.java
浏览文件 @
1e391a6c
...
...
@@ -533,7 +533,7 @@ public class TestCacheLIRS extends TestBase {
}
private
static
<
K
,
V
>
CacheLIRS
<
K
,
V
>
createCache
(
int
maxSize
,
int
averageSize
)
{
return
CacheLIRS
.
newInstance
(
maxSize
,
averageSize
,
1
,
0
);
return
new
CacheLIRS
<
K
,
V
>
(
maxSize
,
averageSize
,
1
,
0
);
}
}
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/store/TestCacheLongKeyLIRS.java
浏览文件 @
1e391a6c
...
...
@@ -463,7 +463,7 @@ public class TestCacheLongKeyLIRS extends TestBase {
}
private
static
<
V
>
CacheLongKeyLIRS
<
V
>
createCache
(
int
maxSize
,
int
averageSize
)
{
return
CacheLongKeyLIRS
.
newInstance
(
maxSize
,
averageSize
,
1
,
0
);
return
new
CacheLongKeyLIRS
<
V
>
(
maxSize
,
averageSize
,
1
,
0
);
}
}
This diff is collapsed.
Click to expand it.
h2/src/tools/org/h2/dev/cache/CacheLIRS.java
浏览文件 @
1e391a6c
...
...
@@ -62,8 +62,29 @@ public class CacheLIRS<K, V> extends AbstractMap<K, V> implements Map<K, V> {
private
final
int
segmentMask
;
private
final
int
stackMoveDistance
;
/**
* Create a new cache with the given number of entries, and the default
* settings (an average size of 1 per entry, 16 segments, and stack move
* distance equals to the maximum number of entries divided by 100).
*
* @param maxEntries the maximum number of entries
*/
public
CacheLIRS
(
int
maxEntries
)
{
this
(
maxEntries
,
1
,
16
,
maxEntries
/
100
);
}
/**
* Create a new cache with the given memory size.
*
* @param maxMemory the maximum memory to use (1 or larger)
* @param averageMemory the average memory (1 or larger)
* @param segmentCount the number of cache segments (must be a power of 2)
* @param stackMoveDistance how many other item are to be moved to the top
* of the stack before the current item is moved
*/
@SuppressWarnings
(
"unchecked"
)
p
rivate
CacheLIRS
(
long
maxMemory
,
int
averageMemory
,
int
segmentCount
,
int
stackMoveDistance
)
{
p
ublic
CacheLIRS
(
long
maxMemory
,
int
averageMemory
,
int
segmentCount
,
int
stackMoveDistance
)
{
setMaxMemory
(
maxMemory
);
setAverageMemory
(
averageMemory
);
if
(
Integer
.
bitCount
(
segmentCount
)
!=
1
)
{
...
...
@@ -270,33 +291,6 @@ public class CacheLIRS<K, V> extends AbstractMap<K, V> implements Map<K, V> {
return
maxMemory
;
}
/**
* Create a new cache with the given number of entries, and the default
* settings (an average size of 1 per entry, 16 segments, and stack move
* distance equals to the maximum number of entries divided by 100).
*
* @param maxEntries the maximum number of entries
* @return the cache
*/
public
static
<
K
,
V
>
CacheLIRS
<
K
,
V
>
newInstance
(
int
maxEntries
)
{
return
new
CacheLIRS
<
K
,
V
>(
maxEntries
,
1
,
16
,
maxEntries
/
100
);
}
/**
* Create a new cache with the given memory size.
*
* @param maxMemory the maximum memory to use (1 or larger)
* @param averageMemory the average memory (1 or larger)
* @param segmentCount the number of cache segments (must be a power of 2)
* @param stackMoveDistance how many other item are to be moved to the top
* of the stack before the current item is moved
* @return the cache
*/
public
static
<
K
,
V
>
CacheLIRS
<
K
,
V
>
newInstance
(
int
maxMemory
,
int
averageMemory
,
int
segmentCount
,
int
stackMoveDistance
)
{
return
new
CacheLIRS
<
K
,
V
>(
maxMemory
,
averageMemory
,
segmentCount
,
stackMoveDistance
);
}
/**
* Get the entry set for all resident entries.
*
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论