Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ce5690e6
Unverified
提交
ce5690e6
authored
1月 20, 2018
作者:
Andrei Tokar
提交者:
GitHub
1月 20, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #797 from katzyn/TransactionMap2
Add ceilingKey() and floorKey() to TransactionMap (version 2)
上级
7d646fcf
592aca2e
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
89 行增加
和
24 行删除
+89
-24
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+3
-3
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+38
-21
TestTransactionStore.java
h2/src/test/org/h2/test/store/TestTransactionStore.java
+48
-0
没有找到文件。
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
ce5690e6
...
@@ -228,9 +228,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
...
@@ -228,9 +228,9 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
}
}
private
void
requireUnique
(
SearchRow
row
,
TransactionMap
<
Value
,
Value
>
map
,
ValueArray
unique
)
{
private
void
requireUnique
(
SearchRow
row
,
TransactionMap
<
Value
,
Value
>
map
,
ValueArray
unique
)
{
Iterator
<
Value
>
it
=
map
.
keyIterator
(
unique
);
Value
key
=
map
.
ceilingKey
(
unique
);
if
(
it
.
hasNext
()
)
{
if
(
key
!=
null
)
{
ValueArray
k
=
(
ValueArray
)
it
.
next
()
;
ValueArray
k
=
(
ValueArray
)
key
;
if
(
compareRows
(
row
,
convertToSearchRow
(
k
))
==
0
)
{
if
(
compareRows
(
row
,
convertToSearchRow
(
k
))
==
0
)
{
// committed
// committed
throw
getDuplicateKeyException
(
k
.
toString
());
throw
getDuplicateKeyException
(
k
.
toString
());
...
...
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
ce5690e6
...
@@ -1320,15 +1320,10 @@ public class TransactionStore {
...
@@ -1320,15 +1320,10 @@ public class TransactionStore {
*/
*/
public
K
lastKey
()
{
public
K
lastKey
()
{
K
k
=
map
.
lastKey
();
K
k
=
map
.
lastKey
();
while
(
true
)
{
while
(
k
!=
null
&&
get
(
k
)
==
null
)
{
if
(
k
==
null
)
{
return
null
;
}
if
(
get
(
k
)
!=
null
)
{
return
k
;
}
k
=
map
.
lowerKey
(
k
);
k
=
map
.
lowerKey
(
k
);
}
}
return
k
;
}
}
/**
/**
...
@@ -1339,13 +1334,22 @@ public class TransactionStore {
...
@@ -1339,13 +1334,22 @@ public class TransactionStore {
* @return the result
* @return the result
*/
*/
public
K
higherKey
(
K
key
)
{
public
K
higherKey
(
K
key
)
{
while
(
true
)
{
do
{
K
k
=
map
.
higherKey
(
key
);
key
=
map
.
higherKey
(
key
);
if
(
k
==
null
||
get
(
k
)
!=
null
)
{
}
while
(
key
!=
null
&&
get
(
key
)
==
null
);
return
k
;
return
key
;
}
}
key
=
k
;
}
/**
* Get the smallest key that is larger than or equal to this key,
* or null if no such key exists.
*
* @param key the key (may not be null)
* @return the result
*/
public
K
ceilingKey
(
K
key
)
{
Iterator
<
K
>
it
=
keyIterator
(
key
);
return
it
.
hasNext
()
?
it
.
next
()
:
null
;
}
}
/**
/**
...
@@ -1365,6 +1369,22 @@ public class TransactionStore {
...
@@ -1365,6 +1369,22 @@ public class TransactionStore {
return
map
.
getKey
(
index
+
offset
);
return
map
.
getKey
(
index
+
offset
);
}
}
/**
* Get the largest key that is smaller than or equal to this key,
* or null if no such key exists.
*
* @param key the key (may not be null)
* @return the result
*/
public
K
floorKey
(
K
key
)
{
key
=
map
.
floorKey
(
key
);
while
(
key
!=
null
&&
get
(
key
)
==
null
)
{
// Use lowerKey() for the next attempts, otherwise we'll get an infinite loop
key
=
map
.
lowerKey
(
key
);
}
return
key
;
}
/**
/**
* Get the largest key that is smaller than the given key, or null if no
* Get the largest key that is smaller than the given key, or null if no
* such key exists.
* such key exists.
...
@@ -1373,13 +1393,10 @@ public class TransactionStore {
...
@@ -1373,13 +1393,10 @@ public class TransactionStore {
* @return the result
* @return the result
*/
*/
public
K
lowerKey
(
K
key
)
{
public
K
lowerKey
(
K
key
)
{
while
(
true
)
{
do
{
K
k
=
map
.
lowerKey
(
key
);
key
=
map
.
lowerKey
(
key
);
if
(
k
==
null
||
get
(
k
)
!=
null
)
{
}
while
(
key
!=
null
&&
get
(
key
)
==
null
);
return
k
;
return
key
;
}
key
=
k
;
}
}
}
/**
/**
...
...
h2/src/test/org/h2/test/store/TestTransactionStore.java
浏览文件 @
ce5690e6
...
@@ -22,6 +22,7 @@ import org.h2.mvstore.db.TransactionStore;
...
@@ -22,6 +22,7 @@ import org.h2.mvstore.db.TransactionStore;
import
org.h2.mvstore.db.TransactionStore.Change
;
import
org.h2.mvstore.db.TransactionStore.Change
;
import
org.h2.mvstore.db.TransactionStore.Transaction
;
import
org.h2.mvstore.db.TransactionStore.Transaction
;
import
org.h2.mvstore.db.TransactionStore.TransactionMap
;
import
org.h2.mvstore.db.TransactionStore.TransactionMap
;
import
org.h2.mvstore.type.ObjectDataType
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.store.fs.FileUtils
;
import
org.h2.test.TestBase
;
import
org.h2.test.TestBase
;
import
org.h2.util.New
;
import
org.h2.util.New
;
...
@@ -44,6 +45,7 @@ public class TestTransactionStore extends TestBase {
...
@@ -44,6 +45,7 @@ public class TestTransactionStore extends TestBase {
@Override
@Override
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
FileUtils
.
createDirectories
(
getBaseDir
());
FileUtils
.
createDirectories
(
getBaseDir
());
testHCLFKey
();
testConcurrentAddRemove
();
testConcurrentAddRemove
();
testConcurrentAdd
();
testConcurrentAdd
();
testCountWithOpenTransactions
();
testCountWithOpenTransactions
();
...
@@ -62,6 +64,52 @@ public class TestTransactionStore extends TestBase {
...
@@ -62,6 +64,52 @@ public class TestTransactionStore extends TestBase {
testStoreMultiThreadedReads
();
testStoreMultiThreadedReads
();
}
}
private
void
testHCLFKey
()
{
MVStore
s
=
MVStore
.
open
(
null
);
final
TransactionStore
ts
=
new
TransactionStore
(
s
);
ts
.
init
();
Transaction
t
=
ts
.
begin
();
ObjectDataType
keyType
=
new
ObjectDataType
();
TransactionMap
<
Long
,
Long
>
map
=
t
.
openMap
(
"test"
,
keyType
,
keyType
);
// firstKey()
assertNull
(
map
.
firstKey
());
// lastKey()
assertNull
(
map
.
lastKey
());
map
.
put
(
10L
,
100L
);
map
.
put
(
20L
,
200L
);
map
.
put
(
30L
,
300L
);
map
.
put
(
40L
,
400L
);
t
.
commit
();
t
=
ts
.
begin
();
map
=
t
.
openMap
(
"test"
,
keyType
,
keyType
);
map
.
put
(
15L
,
150L
);
// The same transaction
assertEquals
((
Object
)
15L
,
map
.
higherKey
(
10L
));
t
=
ts
.
begin
();
map
=
t
.
openMap
(
"test"
,
keyType
,
keyType
);
// Another transaction
// higherKey()
assertEquals
((
Object
)
20L
,
map
.
higherKey
(
10L
));
assertEquals
((
Object
)
20L
,
map
.
higherKey
(
15L
));
assertNull
(
map
.
higherKey
(
40L
));
// ceilingKey()
assertEquals
((
Object
)
10L
,
map
.
ceilingKey
(
10L
));
assertEquals
((
Object
)
20L
,
map
.
ceilingKey
(
15L
));
assertEquals
((
Object
)
40L
,
map
.
ceilingKey
(
40L
));
assertNull
(
map
.
higherKey
(
45L
));
// lowerKey()
assertNull
(
map
.
lowerKey
(
10L
));
assertEquals
((
Object
)
10L
,
map
.
lowerKey
(
15L
));
assertEquals
((
Object
)
10L
,
map
.
lowerKey
(
20L
));
assertEquals
((
Object
)
20L
,
map
.
lowerKey
(
25L
));
// floorKey()
assertNull
(
map
.
floorKey
(
5L
));
assertEquals
((
Object
)
10L
,
map
.
floorKey
(
10L
));
assertEquals
((
Object
)
10L
,
map
.
floorKey
(
15L
));
assertEquals
((
Object
)
30L
,
map
.
floorKey
(
35L
));
s
.
close
();
}
private
static
void
testConcurrentAddRemove
()
throws
InterruptedException
{
private
static
void
testConcurrentAddRemove
()
throws
InterruptedException
{
MVStore
s
=
MVStore
.
open
(
null
);
MVStore
s
=
MVStore
.
open
(
null
);
int
threadCount
=
3
;
int
threadCount
=
3
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论