Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5cbc873e
提交
5cbc873e
authored
11月 01, 2007
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
--no commit message
--no commit message
上级
4cde8b24
全部展开
显示空白字符变更
内嵌
并排
正在显示
9 个修改的文件
包含
1462 行增加
和
1391 行删除
+1462
-1391
advanced.html
h2/src/docsrc/html/advanced.html
+22
-0
_docs_de.utf8.txt
h2/src/docsrc/text/_docs_de.utf8.txt
+354
-342
_docs_en.utf8.txt
h2/src/docsrc/text/_docs_en.utf8.txt
+354
-342
_docs_ja.utf8.txt
h2/src/docsrc/text/_docs_ja.utf8.txt
+355
-343
_docs_en.properties
h2/src/docsrc/textbase/_docs_en.properties
+347
-343
TableData.java
h2/src/main/org/h2/table/TableData.java
+9
-9
TestAll.java
h2/src/test/org/h2/test/TestAll.java
+0
-9
TestMVCC.java
h2/src/test/org/h2/test/mvcc/TestMVCC.java
+20
-2
testSimple.in.txt
h2/src/test/org/h2/test/testSimple.in.txt
+1
-1
没有找到文件。
h2/src/docsrc/html/advanced.html
浏览文件 @
5cbc873e
...
...
@@ -20,6 +20,8 @@ Advanced Topics
Linked Tables
</a><br
/>
<a
href=
"#transaction_isolation"
>
Transaction Isolation
</a><br
/>
<a
href=
"#mvcc"
>
Multi-Version Concurrency Control (MVCC)
</a><br
/>
<a
href=
"#clustering"
>
Clustering / High Availability
</a><br
/>
<a
href=
"#two_phase_commit"
>
...
...
@@ -176,6 +178,26 @@ connection will get a lock timeout exception. The lock timeout can be set indivi
for each connection.
</p>
<br
/><a
name=
"mvcc"
></a>
<h2>
Multi-Version Concurrency Control (MVCC)
</h2>
<p>
The MVCC feature allows higher concurrency than using (table level or row level) locks.
When using MVCC in this database, delete, insert and update operations will only issue a
shared lock on the table. Table are still locked exclusively when adding or removing columns,
when dropping the table, and when using SELECT ... FOR UPDATE. Connections
only 'see' committed data, and own changes. That means, if connection A updates
a row but doesn't commit this change yet, connection B will see the old value.
Only when the change is committed, the new value is visible by other connections
(read committed). If multiple connections concurrently try to update the same row, this
database fails fast: a concurrent update exception is thrown.
</p>
<p>
To use the MVCC feature, append MVCC=TRUE to the database URL:
<pre>
jdbc:h2:~/test;MVCC=TRUE
</pre>
</p>
<br
/><a
name=
"clustering"
></a>
<h2>
Clustering / High Availability
</h2>
<p>
...
...
h2/src/docsrc/text/_docs_de.utf8.txt
浏览文件 @
5cbc873e
差异被折叠。
点击展开。
h2/src/docsrc/text/_docs_en.utf8.txt
浏览文件 @
5cbc873e
差异被折叠。
点击展开。
h2/src/docsrc/text/_docs_ja.utf8.txt
浏览文件 @
5cbc873e
差异被折叠。
点击展开。
h2/src/docsrc/textbase/_docs_en.properties
浏览文件 @
5cbc873e
差异被折叠。
点击展开。
h2/src/main/org/h2/table/TableData.java
浏览文件 @
5cbc873e
...
...
@@ -311,20 +311,20 @@ public class TableData extends Table implements RecordReader {
return
;
}
long
max
=
System
.
currentTimeMillis
()
+
session
.
getLockTimeout
();
synchronized
(
database
)
{
while
(
true
)
{
if
(
lockExclusive
==
session
)
{
return
;
}
if
(!
force
&&
database
.
isMultiVersion
())
{
// MVCC: update, delete, and insert use a shared lock
// but
select doesn't lock
//
select doesn't lock
if
(
exclusive
)
{
exclusive
=
false
;
}
else
{
return
;
}
}
synchronized
(
database
)
{
while
(
true
)
{
if
(
lockExclusive
==
session
)
{
return
;
}
if
(
exclusive
)
{
if
(
lockExclusive
==
null
)
{
if
(
lockShared
.
isEmpty
())
{
...
...
h2/src/test/org/h2/test/TestAll.java
浏览文件 @
5cbc873e
...
...
@@ -142,15 +142,6 @@ java org.h2.test.TestAll timer
/*
TODO history:
Math operations using unknown data types (for example -? and ?+?) are now interpreted as decimal.
INSTR, LOCATE: backward searching is not supported by using a negative start position
TODO doc:
MVCC still locks the table exclusively when adding or removing columns and when dropping the table.
Also, a shared lock is still added when inserting or removing rows.
replicating file system
background thread writing file system (all writes)
...
...
h2/src/test/org/h2/test/mvcc/TestMVCC.java
浏览文件 @
5cbc873e
...
...
@@ -40,13 +40,14 @@ public class TestMVCC extends TestBase {
DeleteDbFiles
.
execute
(
null
,
"test"
,
true
);
Class
.
forName
(
"org.h2.Driver"
);
c1
=
DriverManager
.
getConnection
(
"jdbc:h2:test;MVCC=TRUE"
,
"sa"
,
"sa"
);
c1
=
DriverManager
.
getConnection
(
"jdbc:h2:test;MVCC=TRUE
;LOCK_TIMEOUT=10
"
,
"sa"
,
"sa"
);
s1
=
c1
.
createStatement
();
c2
=
DriverManager
.
getConnection
(
"jdbc:h2:test;MVCC=TRUE"
,
"sa"
,
"sa"
);
c2
=
DriverManager
.
getConnection
(
"jdbc:h2:test;MVCC=TRUE
;LOCK_TIMEOUT=10
"
,
"sa"
,
"sa"
);
s2
=
c2
.
createStatement
();
c1
.
setAutoCommit
(
false
);
c2
.
setAutoCommit
(
false
);
// it should not be possible to drop a table when an uncommitted transaction changed something
s1
.
execute
(
"create table test(id int primary key)"
);
s1
.
execute
(
"insert into test values(1)"
);
try
{
...
...
@@ -60,6 +61,23 @@ public class TestMVCC extends TestBase {
s2
.
execute
(
"drop table test"
);
c2
.
rollback
();
// select for update should do an exclusive lock, even with mvcc
s1
.
execute
(
"create table test(id int primary key, name varchar(255))"
);
s1
.
execute
(
"insert into test values(1, 'y')"
);
c1
.
commit
();
s2
.
execute
(
"select * from test for update"
);
try
{
s1
.
execute
(
"insert into test values(2, 'x')"
);
error
(
"Unexpected success"
);
}
catch
(
SQLException
e
)
{
// lock timeout expected
checkNotGeneralException
(
e
);
}
c2
.
rollback
();
s1
.
execute
(
"drop table test"
);
c1
.
commit
();
c2
.
commit
();
s1
.
execute
(
"create table test(id int primary key, name varchar(255))"
);
s2
.
execute
(
"insert into test values(4, 'Hello')"
);
c2
.
rollback
();
...
...
h2/src/test/org/h2/test/testSimple.in.txt
浏览文件 @
5cbc873e
select instr('a
sg
isj','s', -1) from dual;
select instr('a
bc
isj','s', -1) from dual;
> 5;
CREATE TABLE TEST(ID INT);
INSERT INTO TEST VALUES(1), (2), (3);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论