Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
bba66ba7
提交
bba66ba7
authored
5月 02, 2014
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Javadocs
上级
fd988701
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
7 个修改的文件
包含
824 行增加
和
762 行删除
+824
-762
_docs_en.utf8.txt
h2/src/docsrc/text/_docs_en.utf8.txt
+254
-245
_docs_ja.utf8.txt
h2/src/docsrc/text/_docs_ja.utf8.txt
+254
-245
_docs_en.properties
h2/src/docsrc/textbase/_docs_en.properties
+248
-245
TransactionStore.java
h2/src/main/org/h2/mvstore/db/TransactionStore.java
+1
-1
TestShardedMap.java
h2/src/test/org/h2/test/store/TestShardedMap.java
+4
-4
TestConcurrentUpdate.java
h2/src/test/org/h2/test/synth/TestConcurrentUpdate.java
+9
-4
ShardedMap.java
h2/src/tools/org/h2/dev/cluster/ShardedMap.java
+54
-18
没有找到文件。
h2/src/docsrc/text/_docs_en.utf8.txt
浏览文件 @
bba66ba7
差异被折叠。
点击展开。
h2/src/docsrc/text/_docs_ja.utf8.txt
浏览文件 @
bba66ba7
差异被折叠。
点击展开。
h2/src/docsrc/textbase/_docs_en.properties
浏览文件 @
bba66ba7
差异被折叠。
点击展开。
h2/src/main/org/h2/mvstore/db/TransactionStore.java
浏览文件 @
bba66ba7
...
@@ -1228,7 +1228,7 @@ public class TransactionStore {
...
@@ -1228,7 +1228,7 @@ public class TransactionStore {
// the transaction was not committed correctly
// the transaction was not committed correctly
throw
DataUtils
.
newIllegalStateException
(
throw
DataUtils
.
newIllegalStateException
(
DataUtils
.
ERROR_TRANSACTION_CORRUPT
,
DataUtils
.
ERROR_TRANSACTION_CORRUPT
,
"The transaction log might be corrupt for key {0}"
,
"The transaction log might be corrupt for key {0}"
,
key
);
key
);
}
}
}
else
{
}
else
{
...
...
h2/src/test/org/h2/test/store/TestShardedMap.java
浏览文件 @
bba66ba7
...
@@ -44,7 +44,7 @@ public class TestShardedMap extends TestBase {
...
@@ -44,7 +44,7 @@ public class TestShardedMap extends TestBase {
assertEquals
(
10
,
map
.
size
());
assertEquals
(
10
,
map
.
size
());
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
assertEquals
(
i
*
10
,
map
.
get
(
i
).
intValue
());
assertEquals
(
i
*
10
,
map
.
get
(
i
).
intValue
());
}
}
assertEquals
(
"[0, 1, 2, 3, 4]"
,
assertEquals
(
"[0, 1, 2, 3, 4]"
,
a
.
keySet
().
toString
());
a
.
keySet
().
toString
());
assertEquals
(
"[5, 6, 7, 8, 9]"
,
assertEquals
(
"[5, 6, 7, 8, 9]"
,
...
@@ -53,7 +53,7 @@ public class TestShardedMap extends TestBase {
...
@@ -53,7 +53,7 @@ public class TestShardedMap extends TestBase {
map
.
keySet
().
toString
());
map
.
keySet
().
toString
());
assertEquals
(
10
,
map
.
sizeAsLong
());
assertEquals
(
10
,
map
.
sizeAsLong
());
}
}
private
void
testReplication
()
{
private
void
testReplication
()
{
ShardedMap
<
Integer
,
Integer
>
map
=
new
ShardedMap
<
Integer
,
Integer
>();
ShardedMap
<
Integer
,
Integer
>
map
=
new
ShardedMap
<
Integer
,
Integer
>();
TreeMap
<
Integer
,
Integer
>
a
=
new
TreeMap
<
Integer
,
Integer
>();
TreeMap
<
Integer
,
Integer
>
a
=
new
TreeMap
<
Integer
,
Integer
>();
...
@@ -66,7 +66,7 @@ public class TestShardedMap extends TestBase {
...
@@ -66,7 +66,7 @@ public class TestShardedMap extends TestBase {
assertEquals
(
10
,
map
.
size
());
assertEquals
(
10
,
map
.
size
());
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
for
(
int
i
=
0
;
i
<
10
;
i
++)
{
assertEquals
(
i
*
10
,
map
.
get
(
i
).
intValue
());
assertEquals
(
i
*
10
,
map
.
get
(
i
).
intValue
());
}
}
assertEquals
(
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
,
assertEquals
(
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
,
a
.
keySet
().
toString
());
a
.
keySet
().
toString
());
assertEquals
(
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
,
assertEquals
(
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
,
...
@@ -89,7 +89,7 @@ public class TestShardedMap extends TestBase {
...
@@ -89,7 +89,7 @@ public class TestShardedMap extends TestBase {
assertEquals
(-
1
,
map
.
size
());
assertEquals
(-
1
,
map
.
size
());
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
for
(
int
i
=
0
;
i
<
20
;
i
++)
{
assertEquals
(
i
*
10
,
map
.
get
(
i
).
intValue
());
assertEquals
(
i
*
10
,
map
.
get
(
i
).
intValue
());
}
}
assertEquals
(
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
,
assertEquals
(
"[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"
,
a
.
keySet
().
toString
());
a
.
keySet
().
toString
());
assertEquals
(
"[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]"
,
assertEquals
(
"[5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]"
,
...
...
h2/src/test/org/h2/test/synth/TestConcurrentUpdate.java
浏览文件 @
bba66ba7
...
@@ -21,10 +21,10 @@ import org.h2.util.Task;
...
@@ -21,10 +21,10 @@ import org.h2.util.Task;
* A concurrent test.
* A concurrent test.
*/
*/
public
class
TestConcurrentUpdate
extends
TestBase
{
public
class
TestConcurrentUpdate
extends
TestBase
{
private
static
final
int
THREADS
=
3
;
private
static
final
int
THREADS
=
3
;
private
static
final
int
ROW_COUNT
=
10
;
private
static
final
int
ROW_COUNT
=
10
;
/**
/**
* Run just this test.
* Run just this test.
*
*
...
@@ -42,7 +42,7 @@ public class TestConcurrentUpdate extends TestBase {
...
@@ -42,7 +42,7 @@ public class TestConcurrentUpdate extends TestBase {
Connection
conn
=
getConnection
(
url
);
Connection
conn
=
getConnection
(
url
);
Statement
stat
=
conn
.
createStatement
();
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
stat
.
execute
(
"create table test(id int primary key, name varchar)"
);
Task
[]
tasks
=
new
Task
[
THREADS
];
Task
[]
tasks
=
new
Task
[
THREADS
];
for
(
int
i
=
0
;
i
<
THREADS
;
i
++)
{
for
(
int
i
=
0
;
i
<
THREADS
;
i
++)
{
final
int
threadId
=
i
;
final
int
threadId
=
i
;
...
@@ -112,7 +112,12 @@ public class TestConcurrentUpdate extends TestBase {
...
@@ -112,7 +112,12 @@ public class TestConcurrentUpdate extends TestBase {
}
}
conn
.
close
();
conn
.
close
();
}
}
/**
* Handle or ignore the exception.
*
* @param e the exception
*/
void
handleException
(
SQLException
e
)
throws
SQLException
{
void
handleException
(
SQLException
e
)
throws
SQLException
{
switch
(
e
.
getErrorCode
())
{
switch
(
e
.
getErrorCode
())
{
case
ErrorCode
.
CONCURRENT_UPDATE_1
:
case
ErrorCode
.
CONCURRENT_UPDATE_1
:
...
...
h2/src/tools/org/h2/dev/cluster/ShardedMap.java
浏览文件 @
bba66ba7
...
@@ -21,7 +21,7 @@ import org.h2.mvstore.type.ObjectDataType;
...
@@ -21,7 +21,7 @@ import org.h2.mvstore.type.ObjectDataType;
/**
/**
* A sharded map. It is typically split into multiple sub-maps that don't have
* A sharded map. It is typically split into multiple sub-maps that don't have
* overlapping keys.
* overlapping keys.
*
*
* @param <K> the key type
* @param <K> the key type
* @param <V> the value type
* @param <V> the value type
*/
*/
...
@@ -38,7 +38,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -38,7 +38,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
* are applied to all maps within the range.
* are applied to all maps within the range.
*/
*/
private
Shard
<
K
,
V
>[]
shards
;
private
Shard
<
K
,
V
>[]
shards
;
public
ShardedMap
()
{
public
ShardedMap
()
{
this
(
new
ObjectDataType
());
this
(
new
ObjectDataType
());
}
}
...
@@ -48,14 +48,20 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -48,14 +48,20 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
this
.
keyType
=
keyType
;
this
.
keyType
=
keyType
;
shards
=
new
Shard
[
0
];
shards
=
new
Shard
[
0
];
}
}
public
static
long
getSize
(
Map
<?,
?>
map
)
{
/**
* Get the size of the map.
*
* @param map the map
* @return the size
*/
static
long
getSize
(
Map
<?,
?>
map
)
{
if
(
map
instanceof
LargeMap
)
{
if
(
map
instanceof
LargeMap
)
{
return
((
LargeMap
)
map
).
sizeAsLong
();
return
((
LargeMap
)
map
).
sizeAsLong
();
}
}
return
map
.
size
();
return
map
.
size
();
}
}
/**
/**
* Add the given shard.
* Add the given shard.
*
*
...
@@ -76,7 +82,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -76,7 +82,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
newShards
[
len
-
1
]
=
newShard
;
newShards
[
len
-
1
]
=
newShard
;
shards
=
newShards
;
shards
=
newShards
;
}
}
private
boolean
isInRange
(
K
key
,
Shard
<
K
,
V
>
shard
)
{
private
boolean
isInRange
(
K
key
,
Shard
<
K
,
V
>
shard
)
{
if
(
shard
.
minIncluding
!=
null
)
{
if
(
shard
.
minIncluding
!=
null
)
{
if
(
keyType
.
compare
(
key
,
shard
.
minIncluding
)
<
0
)
{
if
(
keyType
.
compare
(
key
,
shard
.
minIncluding
)
<
0
)
{
...
@@ -90,13 +96,18 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -90,13 +96,18 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
}
}
return
true
;
return
true
;
}
}
@Override
@Override
public
int
size
()
{
public
int
size
()
{
long
size
=
sizeAsLong
();
long
size
=
sizeAsLong
();
return
size
>
Integer
.
MAX_VALUE
?
Integer
.
MAX_VALUE
:
(
int
)
size
;
return
size
>
Integer
.
MAX_VALUE
?
Integer
.
MAX_VALUE
:
(
int
)
size
;
}
}
/**
* The size of the map.
*
* @return the size
*/
public
long
sizeAsLong
()
{
public
long
sizeAsLong
()
{
Shard
<
K
,
V
>[]
copy
=
shards
;
Shard
<
K
,
V
>[]
copy
=
shards
;
for
(
Shard
<
K
,
V
>
s
:
copy
)
{
for
(
Shard
<
K
,
V
>
s
:
copy
)
{
...
@@ -113,7 +124,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -113,7 +124,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
}
}
return
-
1
;
return
-
1
;
}
}
private
boolean
isSimpleSplit
(
Shard
<
K
,
V
>[]
shards
)
{
private
boolean
isSimpleSplit
(
Shard
<
K
,
V
>[]
shards
)
{
K
last
=
null
;
K
last
=
null
;
for
(
int
i
=
0
;
i
<
shards
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
shards
.
length
;
i
++)
{
...
@@ -127,7 +138,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -127,7 +138,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
}
}
if
(
s
.
maxExcluding
==
null
)
{
if
(
s
.
maxExcluding
==
null
)
{
return
i
==
shards
.
length
-
1
;
return
i
==
shards
.
length
-
1
;
}
}
last
=
s
.
maxExcluding
;
last
=
s
.
maxExcluding
;
}
}
return
last
==
null
;
return
last
==
null
;
...
@@ -212,7 +223,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -212,7 +223,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
}
}
}
}
/**
/**
* A combination of multiple sets.
* A combination of multiple sets.
*
*
...
@@ -220,10 +231,10 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -220,10 +231,10 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
* @param <V> the value type
* @param <V> the value type
*/
*/
private
static
class
CombinedSet
<
K
,
V
>
extends
AbstractSet
<
Entry
<
K
,
V
>>
{
private
static
class
CombinedSet
<
K
,
V
>
extends
AbstractSet
<
Entry
<
K
,
V
>>
{
final
int
size
;
final
int
size
;
final
Shard
<
K
,
V
>[]
shards
;
final
Shard
<
K
,
V
>[]
shards
;
CombinedSet
(
int
size
,
Shard
<
K
,
V
>[]
shards
)
{
CombinedSet
(
int
size
,
Shard
<
K
,
V
>[]
shards
)
{
this
.
size
=
size
;
this
.
size
=
size
;
this
.
shards
=
shards
;
this
.
shards
=
shards
;
...
@@ -232,12 +243,12 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -232,12 +243,12 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
@Override
@Override
public
Iterator
<
Entry
<
K
,
V
>>
iterator
()
{
public
Iterator
<
Entry
<
K
,
V
>>
iterator
()
{
return
new
Iterator
<
Entry
<
K
,
V
>>()
{
return
new
Iterator
<
Entry
<
K
,
V
>>()
{
boolean
init
;
boolean
init
;
Entry
<
K
,
V
>
current
;
Entry
<
K
,
V
>
current
;
Iterator
<
Entry
<
K
,
V
>>
currentIterator
;
Iterator
<
Entry
<
K
,
V
>>
currentIterator
;
int
shardIndex
;
int
shardIndex
;
private
void
fetchNext
()
{
private
void
fetchNext
()
{
while
(
currentIterator
==
null
||
!
currentIterator
.
hasNext
())
{
while
(
currentIterator
==
null
||
!
currentIterator
.
hasNext
())
{
if
(
shardIndex
>=
shards
.
length
)
{
if
(
shardIndex
>=
shards
.
length
)
{
...
@@ -272,7 +283,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -272,7 +283,7 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
public
void
remove
()
{
public
void
remove
()
{
throw
new
UnsupportedOperationException
();
throw
new
UnsupportedOperationException
();
}
}
};
};
}
}
...
@@ -280,13 +291,19 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -280,13 +291,19 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
public
int
size
()
{
public
int
size
()
{
return
size
;
return
size
;
}
}
}
}
/**
/**
* A large map.
* A large map.
*/
*/
public
interface
LargeMap
{
public
interface
LargeMap
{
/**
* The size of the map.
*
* @return the size
*/
long
sizeAsLong
();
long
sizeAsLong
();
}
}
...
@@ -295,7 +312,26 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
...
@@ -295,7 +312,26 @@ public class ShardedMap<K, V> extends AbstractMap<K, V>
* given index.
* given index.
*/
*/
public
interface
CountedMap
<
K
,
V
>
{
public
interface
CountedMap
<
K
,
V
>
{
/**
* Get the key at the given index.
*
* @param index the index
* @return the key
*/
K
getKey
(
long
index
);
K
getKey
(
long
index
);
/**
* Get the index of the given key in the map.
* <p>
* If the key was found, the returned value is the index in the key
* array. If not found, the returned value is negative, where -1 means
* the provided key is smaller than any keys. See also
* Arrays.binarySearch.
*
* @param key the key
* @return the index
*/
long
getKeyIndex
(
K
key
);
long
getKeyIndex
(
K
key
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论