Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
a77075e0
Unverified
提交
a77075e0
authored
7月 29, 2018
作者:
Andrei Tokar
提交者:
GitHub
7月 29, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1336 from h2database/minor-refactoring
Minor refactorings
上级
13dc84af
55f0fa28
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
32 行增加
和
81 行删除
+32
-81
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+1
-4
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+1
-1
MVSpatialIndex.java
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
+10
-19
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+1
-8
MVTableEngine.java
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
+0
-1
TransactionMap.java
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
+19
-48
没有找到文件。
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
a77075e0
...
@@ -56,11 +56,8 @@ public class MVPrimaryIndex extends BaseIndex {
...
@@ -56,11 +56,8 @@ public class MVPrimaryIndex extends BaseIndex {
mapName
=
"table."
+
getId
();
mapName
=
"table."
+
getId
();
Transaction
t
=
mvTable
.
getTransactionBegin
();
Transaction
t
=
mvTable
.
getTransactionBegin
();
dataMap
=
t
.
openMap
(
mapName
,
keyType
,
valueType
);
dataMap
=
t
.
openMap
(
mapName
,
keyType
,
valueType
);
dataMap
.
map
.
setVolatile
(!
indexType
.
isPersistent
());
dataMap
.
map
.
setVolatile
(!
table
.
isPersistData
()
||
!
indexType
.
isPersistent
());
t
.
commit
();
t
.
commit
();
if
(!
table
.
isPersistData
()
||
!
indexType
.
isPersistent
())
{
dataMap
.
map
.
setVolatile
(
true
);
}
Value
k
=
dataMap
.
map
.
lastKey
();
// include uncommitted keys as well
Value
k
=
dataMap
.
map
.
lastKey
();
// include uncommitted keys as well
lastKey
.
set
(
k
==
null
?
0
:
k
.
getLong
());
lastKey
.
set
(
k
==
null
?
0
:
k
.
getLong
());
}
}
...
...
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
a77075e0
...
@@ -66,7 +66,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
...
@@ -66,7 +66,7 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
ValueDataType
valueType
=
new
ValueDataType
();
ValueDataType
valueType
=
new
ValueDataType
();
Transaction
t
=
mvTable
.
getTransactionBegin
();
Transaction
t
=
mvTable
.
getTransactionBegin
();
dataMap
=
t
.
openMap
(
mapName
,
keyType
,
valueType
);
dataMap
=
t
.
openMap
(
mapName
,
keyType
,
valueType
);
dataMap
.
map
.
setVolatile
(!
indexType
.
isPersistent
());
dataMap
.
map
.
setVolatile
(!
table
.
isPersistData
()
||
!
indexType
.
isPersistent
());
t
.
commit
();
t
.
commit
();
if
(!
keyType
.
equals
(
dataMap
.
getKeyType
()))
{
if
(!
keyType
.
equals
(
dataMap
.
getKeyType
()))
{
throw
DbException
.
throwInternalError
(
throw
DbException
.
throwInternalError
(
...
...
h2/src/main/org/h2/mvstore/db/MVSpatialIndex.java
浏览文件 @
a77075e0
...
@@ -101,7 +101,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
...
@@ -101,7 +101,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
spatialMap
=
db
.
getMvStore
().
getStore
().
openMap
(
mapName
,
mapBuilder
);
spatialMap
=
db
.
getMvStore
().
getStore
().
openMap
(
mapName
,
mapBuilder
);
Transaction
t
=
mvTable
.
getTransactionBegin
();
Transaction
t
=
mvTable
.
getTransactionBegin
();
dataMap
=
t
.
openMap
(
spatialMap
);
dataMap
=
t
.
openMap
(
spatialMap
);
dataMap
.
map
.
setVolatile
(!
indexType
.
isPersistent
());
dataMap
.
map
.
setVolatile
(!
table
.
isPersistData
()
||
!
indexType
.
isPersistent
());
t
.
commit
();
t
.
commit
();
}
}
...
@@ -201,7 +201,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
...
@@ -201,7 +201,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
Iterator
<
SpatialKey
>
cursor
=
spatialMap
.
keyIterator
(
null
);
Iterator
<
SpatialKey
>
cursor
=
spatialMap
.
keyIterator
(
null
);
TransactionMap
<
SpatialKey
,
Value
>
map
=
getMap
(
session
);
TransactionMap
<
SpatialKey
,
Value
>
map
=
getMap
(
session
);
Iterator
<
SpatialKey
>
it
=
map
.
wrapIterator
(
cursor
,
false
);
Iterator
<
SpatialKey
>
it
=
map
.
wrapIterator
(
cursor
,
false
);
return
new
MVStoreCursor
(
session
,
it
);
return
new
MVStoreCursor
(
session
,
it
,
mvTable
);
}
}
@Override
@Override
...
@@ -215,7 +215,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
...
@@ -215,7 +215,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
spatialMap
.
findIntersectingKeys
(
getKey
(
intersection
));
spatialMap
.
findIntersectingKeys
(
getKey
(
intersection
));
TransactionMap
<
SpatialKey
,
Value
>
map
=
getMap
(
session
);
TransactionMap
<
SpatialKey
,
Value
>
map
=
getMap
(
session
);
Iterator
<
SpatialKey
>
it
=
map
.
wrapIterator
(
cursor
,
false
);
Iterator
<
SpatialKey
>
it
=
map
.
wrapIterator
(
cursor
,
false
);
return
new
MVStoreCursor
(
session
,
it
);
return
new
MVStoreCursor
(
session
,
it
,
mvTable
);
}
}
private
SpatialKey
getKey
(
SearchRow
row
)
{
private
SpatialKey
getKey
(
SearchRow
row
)
{
...
@@ -230,18 +230,6 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
...
@@ -230,18 +230,6 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
(
float
)
env
.
getMinY
(),
(
float
)
env
.
getMaxY
());
(
float
)
env
.
getMinY
(),
(
float
)
env
.
getMaxY
());
}
}
/**
* Get the row with the given index key.
*
* @param key the index key
* @return the row
*/
SearchRow
getRow
(
SpatialKey
key
)
{
SearchRow
searchRow
=
mvTable
.
getTemplateRow
();
searchRow
.
setKey
(
key
.
getId
());
return
searchRow
;
}
@Override
@Override
public
MVTable
getTable
()
{
public
MVTable
getTable
()
{
return
mvTable
;
return
mvTable
;
...
@@ -324,7 +312,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
...
@@ -324,7 +312,7 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
* @param session the session
* @param session the session
* @return the map
* @return the map
*/
*/
TransactionMap
<
SpatialKey
,
Value
>
getMap
(
Session
session
)
{
private
TransactionMap
<
SpatialKey
,
Value
>
getMap
(
Session
session
)
{
if
(
session
==
null
)
{
if
(
session
==
null
)
{
return
dataMap
;
return
dataMap
;
}
}
...
@@ -335,17 +323,19 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
...
@@ -335,17 +323,19 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
/**
/**
* A cursor.
* A cursor.
*/
*/
class
MVStoreCursor
implements
Cursor
{
private
static
class
MVStoreCursor
implements
Cursor
{
private
final
Session
session
;
private
final
Session
session
;
private
final
Iterator
<
SpatialKey
>
it
;
private
final
Iterator
<
SpatialKey
>
it
;
private
final
MVTable
mvTable
;
private
SpatialKey
current
;
private
SpatialKey
current
;
private
SearchRow
searchRow
;
private
SearchRow
searchRow
;
private
Row
row
;
private
Row
row
;
public
MVStoreCursor
(
Session
session
,
Iterator
<
SpatialKey
>
it
)
{
public
MVStoreCursor
(
Session
session
,
Iterator
<
SpatialKey
>
it
,
MVTable
mvTable
)
{
this
.
session
=
session
;
this
.
session
=
session
;
this
.
it
=
it
;
this
.
it
=
it
;
this
.
mvTable
=
mvTable
;
}
}
@Override
@Override
...
@@ -363,7 +353,8 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
...
@@ -363,7 +353,8 @@ public class MVSpatialIndex extends BaseIndex implements SpatialIndex, MVIndex {
public
SearchRow
getSearchRow
()
{
public
SearchRow
getSearchRow
()
{
if
(
searchRow
==
null
)
{
if
(
searchRow
==
null
)
{
if
(
current
!=
null
)
{
if
(
current
!=
null
)
{
searchRow
=
getRow
(
current
);
searchRow
=
mvTable
.
getTemplateRow
();
searchRow
.
setKey
(
current
.
getId
());
}
}
}
}
return
searchRow
;
return
searchRow
;
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
a77075e0
...
@@ -142,15 +142,8 @@ public class MVTable extends TableBase {
...
@@ -142,15 +142,8 @@ public class MVTable extends TableBase {
}
}
containsLargeObject
=
b
;
containsLargeObject
=
b
;
traceLock
=
database
.
getTrace
(
Trace
.
LOCK
);
traceLock
=
database
.
getTrace
(
Trace
.
LOCK
);
}
/**
primaryIndex
=
new
MVPrimaryIndex
(
database
,
this
,
getId
(),
* Initialize the table.
*
* @param session the session
*/
void
init
(
Session
session
)
{
primaryIndex
=
new
MVPrimaryIndex
(
session
.
getDatabase
(),
this
,
getId
(),
IndexColumn
.
wrap
(
getColumns
()),
IndexType
.
createScan
(
true
));
IndexColumn
.
wrap
(
getColumns
()),
IndexType
.
createScan
(
true
));
indexes
.
add
(
primaryIndex
);
indexes
.
add
(
primaryIndex
);
}
}
...
...
h2/src/main/org/h2/mvstore/db/MVTableEngine.java
浏览文件 @
a77075e0
...
@@ -221,7 +221,6 @@ public class MVTableEngine implements TableEngine {
...
@@ -221,7 +221,6 @@ public class MVTableEngine implements TableEngine {
*/
*/
public
MVTable
createTable
(
CreateTableData
data
)
{
public
MVTable
createTable
(
CreateTableData
data
)
{
MVTable
table
=
new
MVTable
(
data
,
this
);
MVTable
table
=
new
MVTable
(
data
,
this
);
table
.
init
(
data
.
session
);
tableMap
.
put
(
table
.
getMapName
(),
table
);
tableMap
.
put
(
table
.
getMapName
(),
table
);
return
table
;
return
table
;
}
}
...
...
h2/src/main/org/h2/mvstore/tx/TransactionMap.java
浏览文件 @
a77075e0
...
@@ -390,32 +390,6 @@ public class TransactionMap<K, V> {
...
@@ -390,32 +390,6 @@ public class TransactionMap<K, V> {
return
tx
==
transaction
.
transactionId
;
return
tx
==
transaction
.
transactionId
;
}
}
/**
* Get the versioned value from the raw versioned value (possibly uncommitted),
* as visible by the current transaction.
*
* @param data the value stored in the main map
* @param committingTransactions set of transactions being committed
* at the time when snapshot was taken
* @return the value
*/
VersionedValue
getValue
(
VersionedValue
data
,
BitSet
committingTransactions
)
{
long
id
;
int
tx
;
// If value doesn't exist or it was deleted by a committed transaction,
// or if value is a committed one, just return it.
if
(
data
!=
null
&&
(
id
=
data
.
getOperationId
())
!=
0
&&
((
tx
=
TransactionStore
.
getTransactionId
(
id
))
!=
transaction
.
transactionId
&&
!
committingTransactions
.
get
(
tx
)))
{
// current value comes from another uncommitted transaction
// take committed value instead
Object
committedValue
=
data
.
getCommittedValue
();
data
=
committedValue
==
null
?
null
:
VersionedValue
.
getInstance
(
committedValue
);
}
return
data
;
}
/**
/**
* Check whether this map is closed.
* Check whether this map is closed.
*
*
...
@@ -482,23 +456,6 @@ public class TransactionMap<K, V> {
...
@@ -482,23 +456,6 @@ public class TransactionMap<K, V> {
return
it
.
hasNext
()
?
it
.
next
()
:
null
;
return
it
.
hasNext
()
?
it
.
next
()
:
null
;
}
}
/**
* Get one of the previous or next keys. There might be no value
* available for the returned key.
*
* @param key the key (may not be null)
* @param offset how many keys to skip (-1 for previous, 1 for next)
* @return the key
*/
public
K
relativeKey
(
K
key
,
long
offset
)
{
K
k
=
offset
>
0
?
map
.
ceilingKey
(
key
)
:
map
.
floorKey
(
key
);
if
(
k
==
null
)
{
return
k
;
}
long
index
=
map
.
getKeyIndex
(
k
);
return
map
.
getKey
(
index
+
offset
);
}
/**
/**
* Get the largest key that is smaller than or equal to this key,
* Get the largest key that is smaller than or equal to this key,
* or null if no such key exists.
* or null if no such key exists.
...
@@ -649,15 +606,16 @@ public class TransactionMap<K, V> {
...
@@ -649,15 +606,16 @@ public class TransactionMap<K, V> {
}
}
private
abstract
static
class
TMIterator
<
K
,
X
>
implements
Iterator
<
X
>
{
private
abstract
static
class
TMIterator
<
K
,
X
>
implements
Iterator
<
X
>
{
private
final
TransactionMap
<
K
,?>
transactionMap
;
private
final
int
transactionId
;
private
final
BitSet
committingTransactions
;
private
final
BitSet
committingTransactions
;
private
final
Cursor
<
K
,
VersionedValue
>
cursor
;
private
final
Cursor
<
K
,
VersionedValue
>
cursor
;
private
final
boolean
includeAllUncommitted
;
private
final
boolean
includeAllUncommitted
;
private
X
current
;
private
X
current
;
protected
TMIterator
(
TransactionMap
<
K
,?>
transactionMap
,
K
from
,
K
to
,
boolean
includeAllUncommitted
)
{
protected
TMIterator
(
TransactionMap
<
K
,?>
transactionMap
,
K
from
,
K
to
,
boolean
includeAllUncommitted
)
{
this
.
transactionMap
=
transactionMap
;
Transaction
transaction
=
transactionMap
.
transaction
;
TransactionStore
store
=
transactionMap
.
transaction
.
store
;
this
.
transactionId
=
transaction
.
transactionId
;
TransactionStore
store
=
transaction
.
store
;
MVMap
<
K
,
VersionedValue
>
map
=
transactionMap
.
map
;
MVMap
<
K
,
VersionedValue
>
map
=
transactionMap
.
map
;
// The purpose of the following loop is to get a coherent picture
// The purpose of the following loop is to get a coherent picture
// of a state of two independent volatile / atomic variables,
// of a state of two independent volatile / atomic variables,
...
@@ -687,10 +645,23 @@ public class TransactionMap<K, V> {
...
@@ -687,10 +645,23 @@ public class TransactionMap<K, V> {
K
key
=
cursor
.
next
();
K
key
=
cursor
.
next
();
VersionedValue
data
=
cursor
.
getValue
();
VersionedValue
data
=
cursor
.
getValue
();
if
(!
includeAllUncommitted
)
{
if
(!
includeAllUncommitted
)
{
data
=
transactionMap
.
getValue
(
data
,
committingTransactions
);
// If value doesn't exist or it was deleted by a committed transaction,
// or if value is a committed one, just return it.
if
(
data
!=
null
)
{
long
id
=
data
.
getOperationId
();
if
(
id
!=
0
)
{
int
tx
=
TransactionStore
.
getTransactionId
(
id
);
if
(
tx
!=
transactionId
&&
!
committingTransactions
.
get
(
tx
))
{
// current value comes from another uncommitted transaction
// take committed value instead
Object
committedValue
=
data
.
getCommittedValue
();
data
=
committedValue
==
null
?
null
:
VersionedValue
.
getInstance
(
committedValue
);
}
}
}
}
}
if
(
data
!=
null
&&
(
data
.
value
!=
null
||
if
(
data
!=
null
&&
(
data
.
value
!=
null
||
includeAllUncommitted
&&
transaction
Map
.
transaction
.
transaction
Id
!=
includeAllUncommitted
&&
transactionId
!=
TransactionStore
.
getTransactionId
(
data
.
getOperationId
())))
{
TransactionStore
.
getTransactionId
(
data
.
getOperationId
())))
{
current
=
registerCurrent
(
key
,
data
);
current
=
registerCurrent
(
key
,
data
);
return
;
return
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论