Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
ab9408d9
提交
ab9408d9
authored
6月 18, 2018
作者:
Andrei Tokar
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix KillRestartMulti in progress
上级
6c004246
隐藏空白字符变更
内嵌
并排
正在显示
12 个修改的文件
包含
164 行增加
和
16 行删除
+164
-16
Database.java
h2/src/main/org/h2/engine/Database.java
+13
-5
MetaRecord.java
h2/src/main/org/h2/engine/MetaRecord.java
+7
-0
BaseIndex.java
h2/src/main/org/h2/index/BaseIndex.java
+6
-0
Index.java
h2/src/main/org/h2/index/Index.java
+9
-0
PageDelegateIndex.java
h2/src/main/org/h2/index/PageDelegateIndex.java
+5
-0
MVDelegateIndex.java
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
+10
-0
MVPrimaryIndex.java
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
+48
-1
MVSecondaryIndex.java
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
+7
-0
MVTable.java
h2/src/main/org/h2/mvstore/db/MVTable.java
+21
-0
TxDecisionMaker.java
h2/src/main/org/h2/mvstore/tx/TxDecisionMaker.java
+23
-10
Table.java
h2/src/main/org/h2/table/Table.java
+14
-0
TestKillRestartMulti.java
h2/src/test/org/h2/test/synth/TestKillRestartMulti.java
+1
-0
没有找到文件。
h2/src/main/org/h2/engine/Database.java
浏览文件 @
ab9408d9
...
...
@@ -784,12 +784,12 @@ public class Database implements DataHandler {
data
.
session
=
systemSession
;
meta
=
mainSchema
.
createTable
(
data
);
IndexColumn
[]
pkCols
=
IndexColumn
.
wrap
(
new
Column
[]
{
columnId
});
starting
=
true
;
metaIdIndex
=
meta
.
addIndex
(
systemSession
,
"SYS_ID"
,
0
,
pkCols
,
IndexType
.
createPrimaryKey
(
false
,
false
),
true
,
null
);
systemSession
.
commit
(
true
);
objectIds
.
set
(
0
);
starting
=
true
;
Cursor
cursor
=
metaIdIndex
.
find
(
systemSession
,
null
,
null
);
ArrayList
<
MetaRecord
>
records
=
new
ArrayList
<>((
int
)
metaIdIndex
.
getRowCountApproximation
());
while
(
cursor
.
next
())
{
...
...
@@ -1727,10 +1727,18 @@ public class Database implements DataHandler {
lockMeta
(
session
);
synchronized
(
this
)
{
int
id
=
obj
.
getId
();
removeMeta
(
session
,
id
);
addMeta
(
session
,
obj
);
// for temporary objects
if
(
id
>
0
)
{
if
(
id
>
0
)
{
if
(!
starting
&&
!
obj
.
isTemporary
())
{
Row
newRow
=
meta
.
getTemplateRow
();
MetaRecord
.
populateRowFromDBObject
(
obj
,
newRow
);
Row
oldRow
=
metaIdIndex
.
getRow
(
session
,
id
);
if
(
oldRow
!=
null
)
{
meta
.
updateRow
(
session
,
oldRow
,
newRow
);
}
// removeMeta(session, id);
// addMeta(session, obj);
}
// for temporary objects
objectIds
.
set
(
id
);
}
}
...
...
h2/src/main/org/h2/engine/MetaRecord.java
浏览文件 @
ab9408d9
...
...
@@ -24,6 +24,13 @@ public class MetaRecord implements Comparable<MetaRecord> {
private
final
int
objectType
;
private
final
String
sql
;
public
static
void
populateRowFromDBObject
(
DbObject
obj
,
SearchRow
r
)
{
r
.
setValue
(
0
,
ValueInt
.
get
(
obj
.
getId
()));
r
.
setValue
(
1
,
ValueInt
.
get
(
0
));
r
.
setValue
(
2
,
ValueInt
.
get
(
obj
.
getType
()));
r
.
setValue
(
3
,
ValueString
.
get
(
obj
.
getCreateSQL
()));
}
public
MetaRecord
(
SearchRow
r
)
{
id
=
r
.
getValue
(
0
).
getInt
();
objectType
=
r
.
getValue
(
2
).
getInt
();
...
...
h2/src/main/org/h2/index/BaseIndex.java
浏览文件 @
ab9408d9
...
...
@@ -481,4 +481,10 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
// Lookup batching is not supported.
return
null
;
}
@Override
public
void
update
(
Session
session
,
Row
oldRow
,
Row
newRow
)
{
remove
(
session
,
oldRow
);
add
(
session
,
newRow
);
}
}
h2/src/main/org/h2/index/Index.java
浏览文件 @
ab9408d9
...
...
@@ -51,6 +51,15 @@ public interface Index extends SchemaObject {
*/
void
remove
(
Session
session
,
Row
row
);
/**
* Update index after row change.
*
* @param session the session
* @param oldRow row before the update
* @param newRow row after the update
*/
void
update
(
Session
session
,
Row
oldRow
,
Row
newRow
);
/**
* Returns {@code true} if {@code find()} implementation performs scan over all
* index, {@code false} if {@code find()} performs the fast lookup.
...
...
h2/src/main/org/h2/index/PageDelegateIndex.java
浏览文件 @
ab9408d9
...
...
@@ -119,6 +119,11 @@ public class PageDelegateIndex extends PageIndex {
// nothing to do
}
@Override
public
void
update
(
Session
session
,
Row
oldRow
,
Row
newRow
)
{
// nothing to do
}
@Override
public
void
remove
(
Session
session
)
{
mainIndex
.
setMainIndexColumn
(-
1
);
...
...
h2/src/main/org/h2/mvstore/db/MVDelegateIndex.java
浏览文件 @
ab9408d9
...
...
@@ -54,6 +54,11 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
// nothing to do
}
@Override
public
Row
getRow
(
Session
session
,
long
key
)
{
return
mainIndex
.
getRow
(
session
,
key
);
}
@Override
public
boolean
canGetFirstOrLast
()
{
return
true
;
...
...
@@ -109,6 +114,11 @@ public class MVDelegateIndex extends BaseIndex implements MVIndex {
// nothing to do
}
@Override
public
void
update
(
Session
session
,
Row
oldRow
,
Row
newRow
)
{
// nothing to do
}
@Override
public
void
remove
(
Session
session
)
{
mainIndex
.
setMainIndexColumn
(
SearchRow
.
ROWID_INDEX
);
...
...
h2/src/main/org/h2/mvstore/db/MVPrimaryIndex.java
浏览文件 @
ab9408d9
...
...
@@ -162,6 +162,53 @@ public class MVPrimaryIndex extends BaseIndex {
}
}
@Override
public
void
update
(
Session
session
,
Row
oldRow
,
Row
newRow
)
{
if
(
mainIndexColumn
!=
SearchRow
.
ROWID_INDEX
)
{
long
c
=
newRow
.
getValue
(
mainIndexColumn
).
getLong
();
newRow
.
setKey
(
c
);
}
long
key
=
oldRow
.
getKey
();
assert
mainIndexColumn
!=
SearchRow
.
ROWID_INDEX
||
key
!=
0
;
assert
key
==
newRow
.
getKey
()
:
key
+
" != "
+
newRow
.
getKey
();
if
(
mvTable
.
getContainsLargeObject
())
{
for
(
int
i
=
0
,
len
=
oldRow
.
getColumnCount
();
i
<
len
;
i
++)
{
Value
oldValue
=
oldRow
.
getValue
(
i
);
Value
newValue
=
newRow
.
getValue
(
i
);
if
(
oldValue
!=
newValue
)
{
if
(
oldValue
.
isLinkedToTable
())
{
session
.
removeAtCommit
(
oldValue
);
}
Value
v2
=
newValue
.
copy
(
database
,
getId
());
if
(
v2
.
isLinkedToTable
())
{
session
.
removeAtCommitStop
(
v2
);
}
if
(
newValue
!=
v2
)
{
newRow
.
setValue
(
i
,
v2
);
}
}
}
}
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
try
{
Value
existing
=
map
.
put
(
ValueLong
.
get
(
key
),
ValueArray
.
get
(
newRow
.
getValueList
()));
if
(
existing
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_WHEN_DELETING_1
,
getSQL
()
+
": "
+
key
);
}
}
catch
(
IllegalStateException
e
)
{
throw
mvTable
.
convertException
(
e
);
}
// because it's possible to directly update the key using the _rowid_
// syntax
if
(
newRow
.
getKey
()
>
lastKey
.
get
())
{
lastKey
.
set
(
newRow
.
getKey
());
}
}
public
void
lockRows
(
Session
session
,
Iterable
<
Row
>
rowsForUpdate
)
{
TransactionMap
<
Value
,
Value
>
map
=
getMap
(
session
);
for
(
Row
row
:
rowsForUpdate
)
{
...
...
@@ -216,7 +263,7 @@ public class MVPrimaryIndex extends BaseIndex {
Value
v
=
map
.
get
(
ValueLong
.
get
(
key
));
if
(
v
==
null
)
{
throw
DbException
.
get
(
ErrorCode
.
ROW_NOT_FOUND_IN_PRIMARY_INDEX
,
getSQL
()
+
": "
+
key
);
getSQL
()
,
String
.
valueOf
(
key
)
);
}
ValueArray
array
=
(
ValueArray
)
v
;
Row
row
=
session
.
createRow
(
array
.
getList
(),
0
);
...
...
h2/src/main/org/h2/mvstore/db/MVSecondaryIndex.java
浏览文件 @
ab9408d9
...
...
@@ -252,6 +252,13 @@ public final class MVSecondaryIndex extends BaseIndex implements MVIndex {
}
}
@Override
public
void
update
(
Session
session
,
Row
oldRow
,
Row
newRow
)
{
if
(
compareRows
(
oldRow
,
newRow
)
!=
0
)
{
super
.
update
(
session
,
oldRow
,
newRow
);
}
}
@Override
public
Cursor
find
(
Session
session
,
SearchRow
first
,
SearchRow
last
)
{
return
find
(
session
,
first
,
false
,
last
);
...
...
h2/src/main/org/h2/mvstore/db/MVTable.java
浏览文件 @
ab9408d9
...
...
@@ -739,6 +739,27 @@ public class MVTable extends TableBase {
analyzeIfRequired
(
session
);
}
@Override
public
void
updateRow
(
Session
session
,
Row
oldRow
,
Row
newRow
)
{
newRow
.
setKey
(
oldRow
.
getKey
());
lastModificationId
=
database
.
getNextModificationDataId
();
Transaction
t
=
session
.
getTransaction
();
long
savepoint
=
t
.
setSavepoint
();
try
{
for
(
Index
index
:
indexes
)
{
index
.
update
(
session
,
oldRow
,
newRow
);
}
}
catch
(
Throwable
e
)
{
try
{
t
.
rollbackToSavepoint
(
savepoint
);
}
catch
(
Throwable
nested
)
{
e
.
addSuppressed
(
nested
);
}
throw
DbException
.
convert
(
e
);
}
analyzeIfRequired
(
session
);
}
@Override
public
void
lockRows
(
Session
session
,
Iterable
<
Row
>
rowsForUpdate
)
{
primaryIndex
.
lockRows
(
session
,
rowsForUpdate
);
...
...
h2/src/main/org/h2/mvstore/tx/TxDecisionMaker.java
浏览文件 @
ab9408d9
...
...
@@ -18,6 +18,7 @@ public abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue
final
Object
value
;
private
final
Transaction
transaction
;
long
undoKey
;
private
long
lastOperationId
;
private
Transaction
blockingTransaction
;
private
MVMap
.
Decision
decision
;
...
...
@@ -48,24 +49,36 @@ public abstract class TxDecisionMaker extends MVMap.DecisionMaker<VersionedValue
// because a tree root has definitely been changed.
logIt
(
existingValue
.
value
==
null
?
null
:
VersionedValue
.
getInstance
(
existingValue
.
value
));
decision
=
MVMap
.
Decision
.
PUT
;
}
else
if
(
fetchTransaction
(
blockingId
)
==
null
)
{
// condition above means transaction has been committed/rolled back and closed by now
decision
=
MVMap
.
Decision
.
REPEAT
;
}
else
{
// this entry comes from a different transaction, and this
// transaction is not committed yet
}
else
if
(
fetchTransaction
(
blockingId
)
!=
null
)
{
// this entry comes from a different transaction, and this transaction is not committed yet
// should wait on blockingTransaction that was determined earlier
decision
=
MVMap
.
Decision
.
ABORT
;
}
else
if
(
id
==
lastOperationId
)
{
// There is no transaction with that id, so we've retried it just before,
// but map root has not changed (which must be the case if we just missed a closed transaction),
// therefore we came back here again.
// Now we assume it's a leftover after unclean shutdown (map update was written but not undo log),
// and will effectively roll it back (just overwrite).
Object
committedValue
=
existingValue
.
getCommittedValue
();
logIt
(
committedValue
==
null
?
null
:
VersionedValue
.
getInstance
(
committedValue
));
decision
=
MVMap
.
Decision
.
PUT
;
}
else
{
// condition above means transaction has been committed/rolled back and closed by now
decision
=
MVMap
.
Decision
.
REPEAT
;
lastOperationId
=
id
;
}
return
decision
;
}
@Override
public
final
void
reset
()
{
if
(
decision
!=
null
&&
decision
!=
MVMap
.
Decision
.
ABORT
&&
decision
!=
MVMap
.
Decision
.
REPEAT
)
{
// positive decision has been made already and undo record created,
// but map was updated afterwards and undo record deletion required
transaction
.
logUndo
();
if
(
decision
!=
MVMap
.
Decision
.
REPEAT
)
{
lastOperationId
=
0
;
if
(
decision
==
MVMap
.
Decision
.
PUT
)
{
// positive decision has been made already and undo record created,
// but map was updated afterwards and undo record deletion required
transaction
.
logUndo
();
}
}
blockingTransaction
=
null
;
decision
=
null
;
...
...
h2/src/main/org/h2/table/Table.java
浏览文件 @
ab9408d9
...
...
@@ -210,6 +210,20 @@ public abstract class Table extends SchemaObjectBase {
*/
public
abstract
void
addRow
(
Session
session
,
Row
row
);
/**
* Update a row to the table and all indexes.
*
* @param session the session
* @param oldRow the row to update
* @param newRow the row with updated values (_rowid_ suppose to be the same)
* @throws DbException if a constraint was violated
*/
public
void
updateRow
(
Session
session
,
Row
oldRow
,
Row
newRow
)
{
newRow
.
setKey
(
oldRow
.
getKey
());
removeRow
(
session
,
oldRow
);
addRow
(
session
,
newRow
);
}
/**
* Commit an operation (when using multi-version concurrency).
*
...
...
h2/src/test/org/h2/test/synth/TestKillRestartMulti.java
浏览文件 @
ab9408d9
...
...
@@ -83,6 +83,7 @@ public class TestKillRestartMulti extends TestBase {
// show up in our log.
ProcessBuilder
pb
=
new
ProcessBuilder
().
redirectError
(
Redirect
.
INHERIT
)
.
command
(
"java"
,
selfDestruct
,
"-cp"
,
getClassPath
(),
"-ea"
,
getClass
().
getName
(),
"-url"
,
url
,
"-user"
,
user
,
"-password"
,
password
);
deleteDb
(
"killRestartMulti"
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论