Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
2f95302e
Unverified
提交
2f95302e
authored
3月 10, 2018
作者:
Evgenij Ryazanov
提交者:
GitHub
3月 10, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #952 from katzyn/misc
Optimize arguments for MVMap.init()
上级
c72a244c
f295ac3e
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
37 行增加
和
53 行删除
+37
-53
CreateTable.java
h2/src/main/org/h2/command/ddl/CreateTable.java
+1
-2
DataUtils.java
h2/src/main/org/h2/mvstore/DataUtils.java
+25
-21
MVMap.java
h2/src/main/org/h2/mvstore/MVMap.java
+6
-9
MVStore.java
h2/src/main/org/h2/mvstore/MVStore.java
+5
-14
SequenceMap.java
h2/src/test/org/h2/test/store/SequenceMap.java
+0
-7
没有找到文件。
h2/src/main/org/h2/command/ddl/CreateTable.java
浏览文件 @
2f95302e
...
@@ -125,8 +125,7 @@ public class CreateTable extends CommandWithColumns {
...
@@ -125,8 +125,7 @@ public class CreateTable extends CommandWithColumns {
try
{
try
{
session
.
setUndoLogEnabled
(
false
);
session
.
setUndoLogEnabled
(
false
);
session
.
startStatementWithinTransaction
();
session
.
startStatementWithinTransaction
();
Insert
insert
=
null
;
Insert
insert
=
new
Insert
(
session
);
insert
=
new
Insert
(
session
);
insert
.
setSortedInsertMode
(
sortedInsertMode
);
insert
.
setSortedInsertMode
(
sortedInsertMode
);
insert
.
setQuery
(
asQuery
);
insert
.
setQuery
(
asQuery
);
insert
.
setTable
(
table
);
insert
.
setTable
(
table
);
...
...
h2/src/main/org/h2/mvstore/DataUtils.java
浏览文件 @
2f95302e
...
@@ -632,9 +632,7 @@ public final class DataUtils {
...
@@ -632,9 +632,7 @@ public final class DataUtils {
c
=
s
.
charAt
(
i
++);
c
=
s
.
charAt
(
i
++);
if
(
c
==
'\\'
)
{
if
(
c
==
'\\'
)
{
if
(
i
==
size
)
{
if
(
i
==
size
)
{
throw
DataUtils
.
newIllegalStateException
(
throw
newIllegalStateException
(
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
DataUtils
.
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
}
}
c
=
s
.
charAt
(
i
++);
c
=
s
.
charAt
(
i
++);
}
else
if
(
c
==
'\"'
)
{
}
else
if
(
c
==
'\"'
)
{
...
@@ -663,8 +661,7 @@ public final class DataUtils {
...
@@ -663,8 +661,7 @@ public final class DataUtils {
int
startKey
=
i
;
int
startKey
=
i
;
i
=
s
.
indexOf
(
':'
,
i
);
i
=
s
.
indexOf
(
':'
,
i
);
if
(
i
<
0
)
{
if
(
i
<
0
)
{
throw
DataUtils
.
newIllegalStateException
(
throw
newIllegalStateException
(
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
DataUtils
.
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
}
}
String
key
=
s
.
substring
(
startKey
,
i
++);
String
key
=
s
.
substring
(
startKey
,
i
++);
i
=
parseMapValue
(
buff
,
s
,
i
,
size
);
i
=
parseMapValue
(
buff
,
s
,
i
,
size
);
...
@@ -696,20 +693,19 @@ public final class DataUtils {
...
@@ -696,20 +693,19 @@ public final class DataUtils {
int
startKey
=
i
;
int
startKey
=
i
;
i
=
s
.
indexOf
(
':'
,
i
);
i
=
s
.
indexOf
(
':'
,
i
);
if
(
i
<
0
)
{
if
(
i
<
0
)
{
throw
DataUtils
.
newIllegalStateException
(
throw
newIllegalStateException
(
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
DataUtils
.
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
}
}
if
(
i
-
startKey
==
8
&&
s
.
regionMatches
(
startKey
,
"fletcher"
,
0
,
8
))
{
if
(
i
-
startKey
==
8
&&
s
.
regionMatches
(
startKey
,
"fletcher"
,
0
,
8
))
{
DataUtils
.
parseMapValue
(
buff
,
s
,
i
+
1
,
size
);
parseMapValue
(
buff
,
s
,
i
+
1
,
size
);
int
check
=
(
int
)
Long
.
parseLong
(
buff
.
toString
(),
16
);
int
check
=
(
int
)
Long
.
parseLong
(
buff
.
toString
(),
16
);
if
(
check
==
DataUtils
.
getFletcher32
(
bytes
,
start
,
startKey
-
1
))
{
if
(
check
==
getFletcher32
(
bytes
,
start
,
startKey
-
1
))
{
return
map
;
return
map
;
}
}
// Corrupted map
// Corrupted map
return
null
;
return
null
;
}
}
String
key
=
s
.
substring
(
startKey
,
i
++);
String
key
=
s
.
substring
(
startKey
,
i
++);
i
=
DataUtils
.
parseMapValue
(
buff
,
s
,
i
,
size
);
i
=
parseMapValue
(
buff
,
s
,
i
,
size
);
map
.
put
(
key
,
buff
.
toString
());
map
.
put
(
key
,
buff
.
toString
());
buff
.
setLength
(
0
);
buff
.
setLength
(
0
);
}
}
...
@@ -725,16 +721,28 @@ public final class DataUtils {
...
@@ -725,16 +721,28 @@ public final class DataUtils {
* @throws IllegalStateException if parsing failed
* @throws IllegalStateException if parsing failed
*/
*/
public
static
String
getMapName
(
String
s
)
{
public
static
String
getMapName
(
String
s
)
{
return
getFromMap
(
s
,
"name"
);
}
/**
* Parse a specified pair from key-value pair list.
*
* @param s the list
* @param key the name of the key
* @return value of the specified item, or {@code null}
* @throws IllegalStateException if parsing failed
*/
public
static
String
getFromMap
(
String
s
,
String
key
)
{
int
keyLength
=
key
.
length
();
for
(
int
i
=
0
,
size
=
s
.
length
();
i
<
size
;)
{
for
(
int
i
=
0
,
size
=
s
.
length
();
i
<
size
;)
{
int
startKey
=
i
;
int
startKey
=
i
;
i
=
s
.
indexOf
(
':'
,
i
);
i
=
s
.
indexOf
(
':'
,
i
);
if
(
i
<
0
)
{
if
(
i
<
0
)
{
throw
DataUtils
.
newIllegalStateException
(
throw
newIllegalStateException
(
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
DataUtils
.
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
}
}
if
(
i
++
-
startKey
==
4
&&
s
.
regionMatches
(
startKey
,
"name"
,
0
,
4
))
{
if
(
i
++
-
startKey
==
keyLength
&&
s
.
regionMatches
(
startKey
,
key
,
0
,
keyLength
))
{
StringBuilder
buff
=
new
StringBuilder
();
StringBuilder
buff
=
new
StringBuilder
();
i
=
parseMapValue
(
buff
,
s
,
i
,
size
);
parseMapValue
(
buff
,
s
,
i
,
size
);
return
buff
.
toString
();
return
buff
.
toString
();
}
else
{
}
else
{
while
(
i
<
size
)
{
while
(
i
<
size
)
{
...
@@ -745,12 +753,9 @@ public final class DataUtils {
...
@@ -745,12 +753,9 @@ public final class DataUtils {
while
(
i
<
size
)
{
while
(
i
<
size
)
{
c
=
s
.
charAt
(
i
++);
c
=
s
.
charAt
(
i
++);
if
(
c
==
'\\'
)
{
if
(
c
==
'\\'
)
{
if
(
i
==
size
)
{
if
(
i
++
==
size
)
{
throw
DataUtils
.
newIllegalStateException
(
throw
newIllegalStateException
(
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
DataUtils
.
ERROR_FILE_CORRUPT
,
"Not a map: {0}"
,
s
);
}
}
c
=
s
.
charAt
(
i
++);
}
else
if
(
c
==
'\"'
)
{
}
else
if
(
c
==
'\"'
)
{
break
;
break
;
}
}
...
@@ -1082,8 +1087,7 @@ public final class DataUtils {
...
@@ -1082,8 +1087,7 @@ public final class DataUtils {
@Override
@Override
public
V
setValue
(
V
value
)
{
public
V
setValue
(
V
value
)
{
throw
DataUtils
.
newUnsupportedOperationException
(
throw
newUnsupportedOperationException
(
"Updating the value is not supported"
);
"Updating the value is not supported"
);
}
}
}
}
...
...
h2/src/main/org/h2/mvstore/MVMap.java
浏览文件 @
2f95302e
...
@@ -8,7 +8,6 @@ package org.h2.mvstore;
...
@@ -8,7 +8,6 @@ package org.h2.mvstore;
import
java.util.AbstractList
;
import
java.util.AbstractList
;
import
java.util.AbstractMap
;
import
java.util.AbstractMap
;
import
java.util.AbstractSet
;
import
java.util.AbstractSet
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -96,12 +95,13 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -96,12 +95,13 @@ public class MVMap<K, V> extends AbstractMap<K, V>
* Open this map with the given store and configuration.
* Open this map with the given store and configuration.
*
*
* @param store the store
* @param store the store
* @param config the configuration
* @param id map id
* @param createVersion version in which this map was created
*/
*/
protected
void
init
(
MVStore
store
,
HashMap
<
String
,
Object
>
config
)
{
protected
void
init
(
MVStore
store
,
int
id
,
long
createVersion
)
{
this
.
store
=
store
;
this
.
store
=
store
;
this
.
id
=
DataUtils
.
readHexInt
(
config
,
"id"
,
0
)
;
this
.
id
=
id
;
this
.
createVersion
=
DataUtils
.
readHexLong
(
config
,
"createVersion"
,
0
)
;
this
.
createVersion
=
createVersion
;
this
.
writeVersion
=
store
.
getCurrentVersion
();
this
.
writeVersion
=
store
.
getCurrentVersion
();
this
.
root
=
Page
.
createEmpty
(
this
,
-
1
);
this
.
root
=
Page
.
createEmpty
(
this
,
-
1
);
}
}
...
@@ -1112,10 +1112,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
...
@@ -1112,10 +1112,7 @@ public class MVMap<K, V> extends AbstractMap<K, V>
MVMap
<
K
,
V
>
openReadOnly
()
{
MVMap
<
K
,
V
>
openReadOnly
()
{
MVMap
<
K
,
V
>
m
=
new
MVMap
<>(
keyType
,
valueType
);
MVMap
<
K
,
V
>
m
=
new
MVMap
<>(
keyType
,
valueType
);
m
.
readOnly
=
true
;
m
.
readOnly
=
true
;
HashMap
<
String
,
Object
>
config
=
new
HashMap
<>();
m
.
init
(
store
,
id
,
createVersion
);
config
.
put
(
"id"
,
id
);
config
.
put
(
"createVersion"
,
createVersion
);
m
.
init
(
store
,
config
);
m
.
root
=
root
;
m
.
root
=
root
;
return
m
;
return
m
;
}
}
...
...
h2/src/main/org/h2/mvstore/MVStore.java
浏览文件 @
2f95302e
...
@@ -336,10 +336,7 @@ public final class MVStore {
...
@@ -336,10 +336,7 @@ public final class MVStore {
(
UncaughtExceptionHandler
)
config
.
get
(
"backgroundExceptionHandler"
);
(
UncaughtExceptionHandler
)
config
.
get
(
"backgroundExceptionHandler"
);
meta
=
new
MVMap
<>(
StringDataType
.
INSTANCE
,
meta
=
new
MVMap
<>(
StringDataType
.
INSTANCE
,
StringDataType
.
INSTANCE
);
StringDataType
.
INSTANCE
);
HashMap
<
String
,
Object
>
c
=
new
HashMap
<>();
meta
.
init
(
this
,
0
,
currentVersion
);
c
.
put
(
"id"
,
0
);
c
.
put
(
"createVersion"
,
currentVersion
);
meta
.
init
(
this
,
c
);
if
(
this
.
fileStore
!=
null
)
{
if
(
this
.
fileStore
!=
null
)
{
retentionTime
=
this
.
fileStore
.
getDefaultRetentionTime
();
retentionTime
=
this
.
fileStore
.
getDefaultRetentionTime
();
int
kb
=
DataUtils
.
getConfigParam
(
config
,
"autoCommitBufferSize"
,
1024
);
int
kb
=
DataUtils
.
getConfigParam
(
config
,
"autoCommitBufferSize"
,
1024
);
...
@@ -445,35 +442,29 @@ public final class MVStore {
...
@@ -445,35 +442,29 @@ public final class MVStore {
* @param builder the map builder
* @param builder the map builder
* @return the map
* @return the map
*/
*/
@SuppressWarnings
({
"unchecked"
,
"rawtypes"
})
public
synchronized
<
M
extends
MVMap
<
K
,
V
>,
K
,
V
>
M
openMap
(
public
synchronized
<
M
extends
MVMap
<
K
,
V
>,
K
,
V
>
M
openMap
(
String
name
,
MVMap
.
MapBuilder
<
M
,
K
,
V
>
builder
)
{
String
name
,
MVMap
.
MapBuilder
<
M
,
K
,
V
>
builder
)
{
checkOpen
();
checkOpen
();
String
x
=
meta
.
get
(
"name."
+
name
);
String
x
=
meta
.
get
(
"name."
+
name
);
int
id
;
int
id
;
long
root
;
long
root
;
HashMap
<
String
,
Object
>
c
;
M
map
;
M
map
;
if
(
x
!=
null
)
{
if
(
x
!=
null
)
{
id
=
DataUtils
.
parseHexInt
(
x
);
id
=
DataUtils
.
parseHexInt
(
x
);
@SuppressWarnings
(
"unchecked"
)
M
old
=
(
M
)
maps
.
get
(
id
);
M
old
=
(
M
)
maps
.
get
(
id
);
if
(
old
!=
null
)
{
if
(
old
!=
null
)
{
return
old
;
return
old
;
}
}
map
=
builder
.
create
();
map
=
builder
.
create
();
String
config
=
meta
.
get
(
MVMap
.
getMapKey
(
id
));
String
config
=
meta
.
get
(
MVMap
.
getMapKey
(
id
));
// Cast from HashMap<String, String> to HashMap<String, Object> is safe
String
v
=
DataUtils
.
getFromMap
(
config
,
"createVersion"
);
c
=
(
HashMap
)
DataUtils
.
parseMap
(
config
);
map
.
init
(
this
,
id
,
v
!=
null
?
DataUtils
.
parseHexLong
(
v
):
0
);
c
.
put
(
"id"
,
id
);
map
.
init
(
this
,
c
);
root
=
getRootPos
(
meta
,
id
);
root
=
getRootPos
(
meta
,
id
);
}
else
{
}
else
{
c
=
new
HashMap
<>();
id
=
++
lastMapId
;
id
=
++
lastMapId
;
c
.
put
(
"id"
,
id
);
c
.
put
(
"createVersion"
,
currentVersion
);
map
=
builder
.
create
();
map
=
builder
.
create
();
map
.
init
(
this
,
c
);
map
.
init
(
this
,
id
,
currentVersion
);
markMetaChanged
();
markMetaChanged
();
x
=
Integer
.
toHexString
(
id
);
x
=
Integer
.
toHexString
(
id
);
meta
.
put
(
MVMap
.
getMapKey
(
id
),
map
.
asString
(
name
));
meta
.
put
(
MVMap
.
getMapKey
(
id
),
map
.
asString
(
name
));
...
...
h2/src/test/org/h2/test/store/SequenceMap.java
浏览文件 @
2f95302e
...
@@ -6,11 +6,9 @@
...
@@ -6,11 +6,9 @@
package
org
.
h2
.
test
.
store
;
package
org
.
h2
.
test
.
store
;
import
java.util.AbstractSet
;
import
java.util.AbstractSet
;
import
java.util.HashMap
;
import
java.util.Iterator
;
import
java.util.Iterator
;
import
java.util.Set
;
import
java.util.Set
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVMap
;
import
org.h2.mvstore.MVStore
;
/**
/**
* A custom map returning the keys and values values 1 .. 10.
* A custom map returning the keys and values values 1 .. 10.
...
@@ -31,11 +29,6 @@ public class SequenceMap extends MVMap<Long, Long> {
...
@@ -31,11 +29,6 @@ public class SequenceMap extends MVMap<Long, Long> {
super
(
null
,
null
);
super
(
null
,
null
);
}
}
@Override
public
void
init
(
MVStore
store
,
HashMap
<
String
,
Object
>
config
)
{
super
.
init
(
store
,
config
);
}
@Override
@Override
public
Set
<
Long
>
keySet
()
{
public
Set
<
Long
>
keySet
()
{
return
new
AbstractSet
<
Long
>()
{
return
new
AbstractSet
<
Long
>()
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论