Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
e7382be6
提交
e7382be6
authored
6月 22, 2018
作者:
Evgenij Ryazanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove DbSettings.largeTransactions
上级
820d98dd
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
39 行增加
和
170 行删除
+39
-170
DbSettings.java
h2/src/main/org/h2/engine/DbSettings.java
+0
-6
UndoLog.java
h2/src/main/org/h2/engine/UndoLog.java
+39
-81
TestUndoLogMemory.java
h2/src/test/org/h2/test/todo/TestUndoLogMemory.java
+0
-83
没有找到文件。
h2/src/main/org/h2/engine/DbSettings.java
浏览文件 @
e7382be6
...
...
@@ -130,12 +130,6 @@ public class DbSettings extends SettingsBase {
*/
public
final
boolean
functionsInSchema
=
get
(
"FUNCTIONS_IN_SCHEMA"
,
true
);
/**
* Database setting <code>LARGE_TRANSACTIONS</code> (default: true).<br />
* Support very large transactions
*/
public
final
boolean
largeTransactions
=
get
(
"LARGE_TRANSACTIONS"
,
true
);
/**
* Database setting <code>LOB_TIMEOUT</code> (default: 300000,
* which means 5 minutes).<br />
...
...
h2/src/main/org/h2/engine/UndoLog.java
浏览文件 @
e7382be6
...
...
@@ -8,7 +8,6 @@ package org.h2.engine;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
org.h2.message.DbException
;
import
org.h2.store.Data
;
import
org.h2.store.FileStore
;
import
org.h2.table.Table
;
...
...
@@ -27,7 +26,6 @@ public class UndoLog {
private
int
memoryUndo
;
private
int
storedEntries
;
private
HashMap
<
Integer
,
Table
>
tables
;
private
final
boolean
largeTransactions
;
/**
* Create a new undo log for the given session.
...
...
@@ -36,7 +34,6 @@ public class UndoLog {
*/
UndoLog
(
Session
session
)
{
this
.
database
=
session
.
getDatabase
();
largeTransactions
=
database
.
getSettings
().
largeTransactions
;
}
/**
...
...
@@ -45,13 +42,7 @@ public class UndoLog {
* @return the number of rows
*/
int
size
()
{
if
(
largeTransactions
)
{
return
storedEntries
+
records
.
size
();
}
if
(
SysProperties
.
CHECK
&&
memoryUndo
>
records
.
size
())
{
DbException
.
throwInternalError
();
}
return
records
.
size
();
return
storedEntries
+
records
.
size
();
}
/**
...
...
@@ -77,26 +68,24 @@ public class UndoLog {
*/
public
UndoLogRecord
getLast
()
{
int
i
=
records
.
size
()
-
1
;
if
(
largeTransactions
)
{
if
(
i
<
0
&&
storedEntries
>
0
)
{
int
last
=
storedEntriesPos
.
size
()
-
1
;
long
pos
=
storedEntriesPos
.
remove
(
last
);
long
end
=
file
.
length
();
int
bufferLength
=
(
int
)
(
end
-
pos
);
Data
buff
=
Data
.
create
(
database
,
bufferLength
);
file
.
seek
(
pos
);
file
.
readFully
(
buff
.
getBytes
(),
0
,
bufferLength
);
while
(
buff
.
length
()
<
bufferLength
)
{
UndoLogRecord
e
=
UndoLogRecord
.
loadFromBuffer
(
buff
,
this
);
records
.
add
(
e
);
memoryUndo
++;
}
storedEntries
-=
records
.
size
();
file
.
setLength
(
pos
);
file
.
seek
(
pos
);
if
(
i
<
0
&&
storedEntries
>
0
)
{
int
last
=
storedEntriesPos
.
size
()
-
1
;
long
pos
=
storedEntriesPos
.
remove
(
last
);
long
end
=
file
.
length
();
int
bufferLength
=
(
int
)
(
end
-
pos
);
Data
buff
=
Data
.
create
(
database
,
bufferLength
);
file
.
seek
(
pos
);
file
.
readFully
(
buff
.
getBytes
(),
0
,
bufferLength
);
while
(
buff
.
length
()
<
bufferLength
)
{
UndoLogRecord
e
=
UndoLogRecord
.
loadFromBuffer
(
buff
,
this
);
records
.
add
(
e
);
memoryUndo
++;
}
i
=
records
.
size
()
-
1
;
storedEntries
-=
records
.
size
();
file
.
setLength
(
pos
);
file
.
seek
(
pos
);
}
i
=
records
.
size
()
-
1
;
UndoLogRecord
entry
=
records
.
get
(
i
);
if
(
entry
.
isStored
())
{
int
start
=
Math
.
max
(
0
,
i
-
database
.
getMaxMemoryUndo
()
/
2
);
...
...
@@ -152,62 +141,31 @@ public class UndoLog {
*/
void
add
(
UndoLogRecord
entry
)
{
records
.
add
(
entry
);
if
(
largeTransactions
)
{
memoryUndo
++;
if
(
memoryUndo
>
database
.
getMaxMemoryUndo
()
&&
database
.
isPersistent
()
&&
!
database
.
isMVStore
())
{
if
(
file
==
null
)
{
String
fileName
=
database
.
createTempFile
();
file
=
database
.
openFile
(
fileName
,
"rw"
,
false
);
file
.
setCheckedWriting
(
false
);
file
.
setLength
(
FileStore
.
HEADER_LENGTH
);
}
Data
buff
=
Data
.
create
(
database
,
Constants
.
DEFAULT_PAGE_SIZE
);
for
(
int
i
=
0
;
i
<
records
.
size
();
i
++)
{
UndoLogRecord
r
=
records
.
get
(
i
);
buff
.
checkCapacity
(
Constants
.
DEFAULT_PAGE_SIZE
);
r
.
append
(
buff
,
this
);
if
(
i
==
records
.
size
()
-
1
||
buff
.
length
()
>
Constants
.
UNDO_BLOCK_SIZE
)
{
storedEntriesPos
.
add
(
file
.
getFilePointer
());
file
.
write
(
buff
.
getBytes
(),
0
,
buff
.
length
());
buff
.
reset
();
}
}
storedEntries
+=
records
.
size
();
memoryUndo
=
0
;
records
.
clear
();
file
.
autoDelete
();
memoryUndo
++;
if
(
memoryUndo
>
database
.
getMaxMemoryUndo
()
&&
database
.
isPersistent
()
&&
!
database
.
isMVStore
())
{
if
(
file
==
null
)
{
String
fileName
=
database
.
createTempFile
();
file
=
database
.
openFile
(
fileName
,
"rw"
,
false
);
file
.
setCheckedWriting
(
false
);
file
.
setLength
(
FileStore
.
HEADER_LENGTH
);
}
}
else
{
if
(!
entry
.
isStored
())
{
memoryUndo
++;
}
if
(
memoryUndo
>
database
.
getMaxMemoryUndo
()
&&
database
.
isPersistent
()
&&
!
database
.
isMVStore
())
{
if
(
file
==
null
)
{
String
fileName
=
database
.
createTempFile
();
file
=
database
.
openFile
(
fileName
,
"rw"
,
false
);
file
.
setCheckedWriting
(
false
);
file
.
seek
(
FileStore
.
HEADER_LENGTH
);
rowBuff
=
Data
.
create
(
database
,
Constants
.
DEFAULT_PAGE_SIZE
);
Data
buff
=
rowBuff
;
for
(
UndoLogRecord
r
:
records
)
{
saveIfPossible
(
r
,
buff
);
}
}
else
{
saveIfPossible
(
entry
,
rowBuff
);
Data
buff
=
Data
.
create
(
database
,
Constants
.
DEFAULT_PAGE_SIZE
);
for
(
int
i
=
0
;
i
<
records
.
size
();
i
++)
{
UndoLogRecord
r
=
records
.
get
(
i
);
buff
.
checkCapacity
(
Constants
.
DEFAULT_PAGE_SIZE
);
r
.
append
(
buff
,
this
);
if
(
i
==
records
.
size
()
-
1
||
buff
.
length
()
>
Constants
.
UNDO_BLOCK_SIZE
)
{
storedEntriesPos
.
add
(
file
.
getFilePointer
());
file
.
write
(
buff
.
getBytes
(),
0
,
buff
.
length
());
buff
.
reset
();
}
file
.
autoDelete
();
}
}
}
private
void
saveIfPossible
(
UndoLogRecord
r
,
Data
buff
)
{
if
(!
r
.
isStored
()
&&
r
.
canStore
())
{
r
.
save
(
buff
,
file
,
this
);
memoryUndo
--;
storedEntries
+=
records
.
size
();
memoryUndo
=
0
;
records
.
clear
();
file
.
autoDelete
();
}
}
...
...
h2/src/test/org/h2/test/todo/TestUndoLogMemory.java
deleted
100644 → 0
浏览文件 @
820d98dd
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package
org
.
h2
.
test
.
todo
;
import
java.sql.Connection
;
import
java.sql.DriverManager
;
import
java.sql.PreparedStatement
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
org.h2.tools.DeleteDbFiles
;
/**
* A test to reproduce out of memory using a large operation.
*/
public
class
TestUndoLogMemory
{
/**
* Run just this test.
*
* @param args ignored
*/
public
static
void
main
(
String
...
args
)
throws
Exception
{
TestUndoLogMemory
.
test
(
10
,
"null"
);
TestUndoLogMemory
.
test
(
100
,
"space(100000)"
);
// new TestUndoLogMemory().test(100000, "null");
// new TestUndoLogMemory().test(1000, "space(100000)");
}
private
static
void
test
(
int
count
,
String
defaultValue
)
throws
SQLException
{
// -Xmx1m -XX:+HeapDumpOnOutOfMemoryError
DeleteDbFiles
.
execute
(
"data"
,
"test"
,
true
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:data/test;large_transactions=true"
);
Statement
stat
=
conn
.
createStatement
();
stat
.
execute
(
"set cache_size 32"
);
stat
.
execute
(
"SET max_operation_memory 100"
);
stat
.
execute
(
"SET max_memory_undo 100"
);
conn
.
setAutoCommit
(
false
);
// also a problem: tables without unique index
System
.
out
.
println
(
"create--- "
+
count
+
" "
+
defaultValue
);
stat
.
execute
(
"create table test(id int, name varchar default "
+
defaultValue
+
" )"
);
System
.
out
.
println
(
"insert---"
);
stat
.
execute
(
"insert into test(id) select x from system_range(1, "
+
count
+
")"
);
System
.
out
.
println
(
"rollback---"
);
conn
.
rollback
();
System
.
out
.
println
(
"drop---"
);
stat
.
execute
(
"drop table test"
);
System
.
out
.
println
(
"create---"
);
stat
.
execute
(
"create table test"
+
"(id int primary key, name varchar default "
+
defaultValue
+
" )"
);
// INSERT problem
System
.
out
.
println
(
"insert---"
);
stat
.
execute
(
"insert into test(id) select x from system_range(1, "
+
count
+
")"
);
System
.
out
.
println
(
"delete---"
);
stat
.
execute
(
"delete from test"
);
// DELETE problem
System
.
out
.
println
(
"insert---"
);
PreparedStatement
prep
=
conn
.
prepareStatement
(
"insert into test(id) values(?)"
);
for
(
int
i
=
0
;
i
<
count
;
i
++)
{
prep
.
setInt
(
1
,
i
);
prep
.
execute
();
}
System
.
out
.
println
(
"delete---"
);
stat
.
execute
(
"delete from test"
);
System
.
out
.
println
(
"close---"
);
conn
.
close
();
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论