Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
5a84a557
提交
5a84a557
authored
13 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
New experimental system property "h2.modifyOnWrite".
上级
d744354c
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
92 行增加
和
24 行删除
+92
-24
Command.java
h2/src/main/org/h2/command/Command.java
+13
-4
Constants.java
h2/src/main/org/h2/engine/Constants.java
+5
-0
Session.java
h2/src/main/org/h2/engine/Session.java
+2
-2
SessionInterface.java
h2/src/main/org/h2/engine/SessionInterface.java
+7
-0
SessionRemote.java
h2/src/main/org/h2/engine/SessionRemote.java
+27
-1
JdbcConnection.java
h2/src/main/org/h2/jdbc/JdbcConnection.java
+11
-9
TcpServerThread.java
h2/src/main/org/h2/server/TcpServerThread.java
+26
-7
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+1
-1
没有找到文件。
h2/src/main/org/h2/command/Command.java
浏览文件 @
5a84a557
...
@@ -174,7 +174,9 @@ public abstract class Command implements CommandInterface {
...
@@ -174,7 +174,9 @@ public abstract class Command implements CommandInterface {
session
.
waitIfExclusiveModeEnabled
();
session
.
waitIfExclusiveModeEnabled
();
boolean
writing
=
!
isReadOnly
();
boolean
writing
=
!
isReadOnly
();
if
(
writing
)
{
if
(
writing
)
{
database
.
beforeWriting
();
while
(!
database
.
beforeWriting
())
{
// wait
}
}
}
synchronized
(
sync
)
{
synchronized
(
sync
)
{
session
.
setCurrentCommand
(
this
);
session
.
setCurrentCommand
(
this
);
...
@@ -208,9 +210,14 @@ public abstract class Command implements CommandInterface {
...
@@ -208,9 +210,14 @@ public abstract class Command implements CommandInterface {
Object
sync
=
database
.
isMultiThreaded
()
?
(
Object
)
session
:
(
Object
)
database
;
Object
sync
=
database
.
isMultiThreaded
()
?
(
Object
)
session
:
(
Object
)
database
;
session
.
waitIfExclusiveModeEnabled
();
session
.
waitIfExclusiveModeEnabled
();
boolean
callStop
=
true
;
boolean
callStop
=
true
;
database
.
beforeWriting
();
boolean
writing
=
!
isReadOnly
();
if
(
writing
)
{
while
(!
database
.
beforeWriting
())
{
// wait
}
}
synchronized
(
sync
)
{
synchronized
(
sync
)
{
int
rollback
=
session
.
get
LogId
();
int
rollback
=
session
.
get
UndoLogPos
();
session
.
setCurrentCommand
(
this
);
session
.
setCurrentCommand
(
this
);
try
{
try
{
while
(
true
)
{
while
(
true
)
{
...
@@ -248,7 +255,9 @@ public abstract class Command implements CommandInterface {
...
@@ -248,7 +255,9 @@ public abstract class Command implements CommandInterface {
stop
();
stop
();
}
}
}
finally
{
}
finally
{
database
.
afterWriting
();
if
(
writing
)
{
database
.
afterWriting
();
}
}
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
5a84a557
...
@@ -61,6 +61,11 @@ public class Constants {
...
@@ -61,6 +61,11 @@ public class Constants {
*/
*/
public
static
final
int
TCP_PROTOCOL_VERSION_9
=
9
;
public
static
final
int
TCP_PROTOCOL_VERSION_9
=
9
;
/**
* The TCP protocol version number 10.
*/
public
static
final
int
TCP_PROTOCOL_VERSION_10
=
10
;
/**
/**
* The major version of this database.
* The major version of this database.
*/
*/
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Session.java
浏览文件 @
5a84a557
...
@@ -542,7 +542,7 @@ public class Session extends SessionWithState {
...
@@ -542,7 +542,7 @@ public class Session extends SessionWithState {
}
}
}
}
public
int
get
LogId
()
{
public
int
get
UndoLogPos
()
{
return
undoLog
.
size
();
return
undoLog
.
size
();
}
}
...
@@ -755,7 +755,7 @@ public class Session extends SessionWithState {
...
@@ -755,7 +755,7 @@ public class Session extends SessionWithState {
if
(
savepoints
==
null
)
{
if
(
savepoints
==
null
)
{
savepoints
=
database
.
newStringMap
();
savepoints
=
database
.
newStringMap
();
}
}
savepoints
.
put
(
name
,
get
LogId
());
savepoints
.
put
(
name
,
get
UndoLogPos
());
}
}
/**
/**
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/SessionInterface.java
浏览文件 @
5a84a557
...
@@ -67,6 +67,13 @@ public interface SessionInterface extends Closeable {
...
@@ -67,6 +67,13 @@ public interface SessionInterface extends Closeable {
*/
*/
DataHandler
getDataHandler
();
DataHandler
getDataHandler
();
/**
* Get the undo log position.
*
* @return the position (0 means no pending transaction)
*/
int
getUndoLogPos
();
/**
/**
* Cancel the current or next command (called when closing a connection).
* Cancel the current or next command (called when closing a connection).
*/
*/
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/SessionRemote.java
浏览文件 @
5a84a557
...
@@ -55,6 +55,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
...
@@ -55,6 +55,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
public
static
final
int
SESSION_CANCEL_STATEMENT
=
13
;
public
static
final
int
SESSION_CANCEL_STATEMENT
=
13
;
public
static
final
int
SESSION_CHECK_KEY
=
14
;
public
static
final
int
SESSION_CHECK_KEY
=
14
;
public
static
final
int
SESSION_SET_AUTOCOMMIT
=
15
;
public
static
final
int
SESSION_SET_AUTOCOMMIT
=
15
;
public
static
final
int
SESSION_UNDO_LOG_POS
=
16
;
public
static
final
int
STATUS_ERROR
=
0
;
public
static
final
int
STATUS_ERROR
=
0
;
public
static
final
int
STATUS_OK
=
1
;
public
static
final
int
STATUS_OK
=
1
;
...
@@ -94,7 +95,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
...
@@ -94,7 +95,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
trans
.
setSSL
(
ci
.
isSSL
());
trans
.
setSSL
(
ci
.
isSSL
());
trans
.
init
();
trans
.
init
();
trans
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_6
);
trans
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_6
);
trans
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_
9
);
trans
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_
10
);
trans
.
writeString
(
db
);
trans
.
writeString
(
db
);
trans
.
writeString
(
ci
.
getOriginalURL
());
trans
.
writeString
(
ci
.
getOriginalURL
());
trans
.
writeString
(
ci
.
getUserName
());
trans
.
writeString
(
ci
.
getUserName
());
...
@@ -120,6 +121,24 @@ public class SessionRemote extends SessionWithState implements DataHandler {
...
@@ -120,6 +121,24 @@ public class SessionRemote extends SessionWithState implements DataHandler {
return
trans
;
return
trans
;
}
}
public
int
getUndoLogPos
()
{
if
(
clientVersion
<
Constants
.
TCP_PROTOCOL_VERSION_10
)
{
return
1
;
}
for
(
int
i
=
0
,
count
=
0
;
i
<
transferList
.
size
();
i
++)
{
Transfer
transfer
=
transferList
.
get
(
i
);
try
{
traceOperation
(
"SESSION_UNDO_LOG_POS"
,
0
);
transfer
.
writeInt
(
SessionRemote
.
SESSION_UNDO_LOG_POS
);
done
(
transfer
);
return
transfer
.
readInt
();
}
catch
(
IOException
e
)
{
removeServer
(
e
,
i
--,
++
count
);
}
}
return
1
;
}
public
void
cancel
()
{
public
void
cancel
()
{
// this method is called when closing the connection
// this method is called when closing the connection
// the statement that is currently running is not canceled in this case
// the statement that is currently running is not canceled in this case
...
@@ -482,6 +501,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
...
@@ -482,6 +501,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
}
}
public
void
close
()
{
public
void
close
()
{
RuntimeException
closeError
=
null
;
if
(
transferList
!=
null
)
{
if
(
transferList
!=
null
)
{
synchronized
(
this
)
{
synchronized
(
this
)
{
for
(
Transfer
transfer
:
transferList
)
{
for
(
Transfer
transfer
:
transferList
)
{
...
@@ -490,6 +510,9 @@ public class SessionRemote extends SessionWithState implements DataHandler {
...
@@ -490,6 +510,9 @@ public class SessionRemote extends SessionWithState implements DataHandler {
transfer
.
writeInt
(
SessionRemote
.
SESSION_CLOSE
);
transfer
.
writeInt
(
SessionRemote
.
SESSION_CLOSE
);
done
(
transfer
);
done
(
transfer
);
transfer
.
close
();
transfer
.
close
();
}
catch
(
RuntimeException
e
)
{
trace
.
error
(
e
,
"close"
);
closeError
=
e
;
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
trace
.
error
(
e
,
"close"
);
trace
.
error
(
e
,
"close"
);
}
}
...
@@ -502,6 +525,9 @@ public class SessionRemote extends SessionWithState implements DataHandler {
...
@@ -502,6 +525,9 @@ public class SessionRemote extends SessionWithState implements DataHandler {
embedded
.
close
();
embedded
.
close
();
embedded
=
null
;
embedded
=
null
;
}
}
if
(
closeError
!=
null
)
{
throw
closeError
;
}
}
}
public
Trace
getTrace
()
{
public
Trace
getTrace
()
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/jdbc/JdbcConnection.java
浏览文件 @
5a84a557
...
@@ -345,15 +345,17 @@ public class JdbcConnection extends TraceObject implements Connection {
...
@@ -345,15 +345,17 @@ public class JdbcConnection extends TraceObject implements Connection {
try
{
try
{
if
(!
session
.
isClosed
())
{
if
(!
session
.
isClosed
())
{
try
{
try
{
// roll back unless that would require to re-connect
if
(
session
.
getUndoLogPos
()
!=
0
)
{
// (the transaction can't be rolled back after re-connecting)
// roll back unless that would require to re-connect
if
(!
session
.
isReconnectNeeded
(
true
))
{
// (the transaction can't be rolled back after re-connecting)
try
{
if
(!
session
.
isReconnectNeeded
(
true
))
{
rollbackInternal
();
try
{
}
catch
(
DbException
e
)
{
rollbackInternal
();
// ignore if the connection is broken right now
}
catch
(
DbException
e
)
{
if
(
e
.
getErrorCode
()
!=
ErrorCode
.
CONNECTION_BROKEN_1
)
{
// ignore if the connection is broken right now
throw
e
;
if
(
e
.
getErrorCode
()
!=
ErrorCode
.
CONNECTION_BROKEN_1
)
{
throw
e
;
}
}
}
}
}
session
.
afterWriting
();
session
.
afterWriting
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/TcpServerThread.java
浏览文件 @
5a84a557
...
@@ -71,12 +71,12 @@ public class TcpServerThread implements Runnable {
...
@@ -71,12 +71,12 @@ public class TcpServerThread implements Runnable {
int
minClientVersion
=
transfer
.
readInt
();
int
minClientVersion
=
transfer
.
readInt
();
if
(
minClientVersion
<
Constants
.
TCP_PROTOCOL_VERSION_6
)
{
if
(
minClientVersion
<
Constants
.
TCP_PROTOCOL_VERSION_6
)
{
throw
DbException
.
get
(
ErrorCode
.
DRIVER_VERSION_ERROR_2
,
""
+
clientVersion
,
""
+
Constants
.
TCP_PROTOCOL_VERSION_6
);
throw
DbException
.
get
(
ErrorCode
.
DRIVER_VERSION_ERROR_2
,
""
+
clientVersion
,
""
+
Constants
.
TCP_PROTOCOL_VERSION_6
);
}
else
if
(
minClientVersion
>
Constants
.
TCP_PROTOCOL_VERSION_
9
)
{
}
else
if
(
minClientVersion
>
Constants
.
TCP_PROTOCOL_VERSION_
10
)
{
throw
DbException
.
get
(
ErrorCode
.
DRIVER_VERSION_ERROR_2
,
""
+
clientVersion
,
""
+
Constants
.
TCP_PROTOCOL_VERSION_
9
);
throw
DbException
.
get
(
ErrorCode
.
DRIVER_VERSION_ERROR_2
,
""
+
clientVersion
,
""
+
Constants
.
TCP_PROTOCOL_VERSION_
10
);
}
}
int
maxClientVersion
=
transfer
.
readInt
();
int
maxClientVersion
=
transfer
.
readInt
();
if
(
maxClientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION_
9
)
{
if
(
maxClientVersion
>=
Constants
.
TCP_PROTOCOL_VERSION_
10
)
{
clientVersion
=
Constants
.
TCP_PROTOCOL_VERSION_
9
;
clientVersion
=
Constants
.
TCP_PROTOCOL_VERSION_
10
;
}
else
{
}
else
{
clientVersion
=
minClientVersion
;
clientVersion
=
minClientVersion
;
}
}
...
@@ -149,20 +149,32 @@ public class TcpServerThread implements Runnable {
...
@@ -149,20 +149,32 @@ public class TcpServerThread implements Runnable {
private
void
closeSession
()
{
private
void
closeSession
()
{
if
(
session
!=
null
)
{
if
(
session
!=
null
)
{
RuntimeException
closeError
=
null
;
try
{
try
{
Command
rollback
=
session
.
prepareLocal
(
"ROLLBACK"
);
Command
rollback
=
session
.
prepareLocal
(
"ROLLBACK"
);
rollback
.
executeUpdate
();
rollback
.
executeUpdate
();
}
catch
(
RuntimeException
e
)
{
closeError
=
e
;
server
.
traceError
(
e
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
server
.
traceError
(
e
);
server
.
traceError
(
e
);
}
}
try
{
try
{
session
.
close
();
session
.
close
();
server
.
removeConnection
(
threadId
);
server
.
removeConnection
(
threadId
);
}
catch
(
RuntimeException
e
)
{
if
(
closeError
==
null
)
{
closeError
=
e
;
server
.
traceError
(
e
);
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
server
.
traceError
(
e
);
server
.
traceError
(
e
);
}
finally
{
}
finally
{
session
=
null
;
session
=
null
;
}
}
if
(
closeError
!=
null
)
{
throw
closeError
;
}
}
}
}
}
...
@@ -173,12 +185,13 @@ public class TcpServerThread implements Runnable {
...
@@ -173,12 +185,13 @@ public class TcpServerThread implements Runnable {
try
{
try
{
stop
=
true
;
stop
=
true
;
closeSession
();
closeSession
();
transfer
.
close
();
trace
(
"Close"
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
server
.
traceError
(
e
);
server
.
traceError
(
e
);
}
finally
{
transfer
.
close
();
trace
(
"Close"
);
server
.
remove
(
this
);
}
}
server
.
remove
(
this
);
}
}
private
void
sendError
(
Throwable
t
)
{
private
void
sendError
(
Throwable
t
)
{
...
@@ -241,6 +254,7 @@ public class TcpServerThread implements Runnable {
...
@@ -241,6 +254,7 @@ public class TcpServerThread implements Runnable {
break
;
break
;
}
}
case
SessionRemote
.
SESSION_CLOSE
:
{
case
SessionRemote
.
SESSION_CLOSE
:
{
stop
=
true
;
closeSession
();
closeSession
();
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
).
flush
();
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
).
flush
();
close
();
close
();
...
@@ -364,6 +378,11 @@ public class TcpServerThread implements Runnable {
...
@@ -364,6 +378,11 @@ public class TcpServerThread implements Runnable {
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
).
flush
();
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
).
flush
();
break
;
break
;
}
}
case
SessionRemote
.
SESSION_UNDO_LOG_POS
:
{
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
).
writeInt
(
session
.
getUndoLogPos
()).
flush
();
break
;
}
default
:
default
:
trace
(
"Unknown operation: "
+
operation
);
trace
(
"Unknown operation: "
+
operation
);
closeSession
();
closeSession
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
5a84a557
...
@@ -224,7 +224,7 @@ public class FileLock implements Runnable {
...
@@ -224,7 +224,7 @@ public class FileLock implements Runnable {
transfer
.
setSocket
(
socket
);
transfer
.
setSocket
(
socket
);
transfer
.
init
();
transfer
.
init
();
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_6
);
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_6
);
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_
9
);
transfer
.
writeInt
(
Constants
.
TCP_PROTOCOL_VERSION_
10
);
transfer
.
writeString
(
null
);
transfer
.
writeString
(
null
);
transfer
.
writeString
(
null
);
transfer
.
writeString
(
null
);
transfer
.
writeString
(
id
);
transfer
.
writeString
(
id
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论