Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
70660686
提交
70660686
authored
16 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
After an automatic re-connect, part of the session state stays.
上级
b514ec22
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
74 行增加
和
6 行删除
+74
-6
CommandRemote.java
h2/src/main/org/h2/command/CommandRemote.java
+2
-0
Session.java
h2/src/main/org/h2/engine/Session.java
+11
-0
SessionRemote.java
h2/src/main/org/h2/engine/SessionRemote.java
+36
-0
TcpServerThread.java
h2/src/main/org/h2/server/TcpServerThread.java
+18
-4
TestAutoReconnect.java
h2/src/test/org/h2/test/server/TestAutoReconnect.java
+6
-1
TestAutoServer.java
h2/src/test/org/h2/test/server/TestAutoServer.java
+1
-1
没有找到文件。
h2/src/main/org/h2/command/CommandRemote.java
浏览文件 @
70660686
...
...
@@ -173,6 +173,7 @@ public class CommandRemote implements CommandInterface {
}
}
session
.
autoCommitIfCluster
();
session
.
readSessionState
();
return
result
;
}
}
...
...
@@ -198,6 +199,7 @@ public class CommandRemote implements CommandInterface {
}
session
.
setAutoCommit
(
autoCommit
);
session
.
autoCommitIfCluster
();
session
.
readSessionState
();
return
updateCount
;
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Session.java
浏览文件 @
70660686
...
...
@@ -88,6 +88,7 @@ public class Session implements SessionInterface {
private
int
lastUncommittedDelete
;
private
boolean
commitOrRollbackDisabled
;
private
Table
waitForLock
;
private
int
modificationId
;
public
Session
()
{
// nothing to do
...
...
@@ -124,6 +125,7 @@ public class Session implements SessionInterface {
*/
public
void
setVariable
(
String
name
,
Value
value
)
throws
SQLException
{
initVariables
();
modificationId
++;
Value
old
;
if
(
value
==
ValueNull
.
INSTANCE
)
{
old
=
(
Value
)
variables
.
remove
(
name
);
...
...
@@ -200,6 +202,7 @@ public class Session implements SessionInterface {
if
(
localTempTables
.
get
(
table
.
getName
())
!=
null
)
{
throw
Message
.
getSQLException
(
ErrorCode
.
TABLE_OR_VIEW_ALREADY_EXISTS_1
,
table
.
getSQL
());
}
modificationId
++;
localTempTables
.
put
(
table
.
getName
(),
table
);
}
...
...
@@ -209,6 +212,7 @@ public class Session implements SessionInterface {
* @param table the table
*/
public
void
removeLocalTempTable
(
Table
table
)
throws
SQLException
{
modificationId
++;
localTempTables
.
remove
(
table
.
getName
());
table
.
removeChildrenAndResources
(
this
);
}
...
...
@@ -534,6 +538,7 @@ public class Session implements SessionInterface {
for
(
int
i
=
0
;
i
<
list
.
size
();
i
++)
{
Table
table
=
(
Table
)
list
.
get
(
i
);
if
(
closeSession
||
table
.
getOnCommitDrop
())
{
modificationId
++;
table
.
setModified
();
localTempTables
.
remove
(
table
.
getName
());
table
.
removeChildrenAndResources
(
this
);
...
...
@@ -755,6 +760,7 @@ public class Session implements SessionInterface {
}
public
void
setCurrentSchema
(
Schema
schema
)
{
modificationId
++;
this
.
currentSchemaName
=
schema
.
getName
();
}
...
...
@@ -852,6 +858,7 @@ public class Session implements SessionInterface {
}
public
void
setSchemaSearchPath
(
String
[]
schemas
)
{
modificationId
++;
this
.
schemaSearchPath
=
schemas
;
}
...
...
@@ -970,5 +977,9 @@ public class Session implements SessionInterface {
public
Table
getWaitForLock
()
{
return
waitForLock
;
}
public
int
getModificationId
()
{
return
modificationId
;
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/SessionRemote.java
浏览文件 @
70660686
...
...
@@ -59,6 +59,7 @@ public class SessionRemote implements SessionInterface, DataHandler {
public
static
final
int
STATUS_ERROR
=
0
;
public
static
final
int
STATUS_OK
=
1
;
public
static
final
int
STATUS_CLOSED
=
2
;
public
static
final
int
STATUS_OK_STATE_CHANGED
=
3
;
private
TraceSystem
traceSystem
;
private
Trace
trace
;
...
...
@@ -77,6 +78,9 @@ public class SessionRemote implements SessionInterface, DataHandler {
private
boolean
autoReconnect
;
private
int
lastReconnect
;
private
SessionInterface
embedded
;
private
boolean
sessionStateChanged
;
private
ObjectArray
sessionState
;
private
boolean
sessionStateUpdating
;
public
SessionRemote
()
{
// nothing to do
...
...
@@ -424,6 +428,19 @@ public class SessionRemote implements SessionInterface, DataHandler {
// unfortunately
connectEmbeddedOrServer
();
}
if
(
sessionState
!=
null
&&
sessionState
.
size
()
>
0
)
{
sessionStateUpdating
=
true
;
try
{
for
(
int
i
=
0
;
i
<
sessionState
.
size
();
i
++)
{
String
sql
=
(
String
)
sessionState
.
get
(
i
);
CommandInterface
ci
=
prepareCommand
(
sql
,
Integer
.
MAX_VALUE
);
ci
.
executeUpdate
();
}
}
finally
{
sessionStateUpdating
=
false
;
sessionStateChanged
=
false
;
}
}
return
true
;
}
...
...
@@ -496,6 +513,8 @@ public class SessionRemote implements SessionInterface, DataHandler {
throw
new
JdbcSQLException
(
message
,
sql
,
sqlstate
,
errorCode
,
null
,
stackTrace
);
}
else
if
(
status
==
STATUS_CLOSED
)
{
transferList
=
null
;
}
else
if
(
status
==
STATUS_OK_STATE_CHANGED
)
{
sessionStateChanged
=
true
;
}
}
...
...
@@ -622,4 +641,21 @@ public class SessionRemote implements SessionInterface, DataHandler {
return
lastReconnect
;
}
/**
* Read the session state if necessary.
*/
public
void
readSessionState
()
throws
SQLException
{
if
(!
sessionStateChanged
||
sessionStateUpdating
)
{
return
;
}
sessionStateChanged
=
false
;
sessionState
=
new
ObjectArray
();
CommandInterface
ci
=
prepareCommand
(
"SELECT * FROM INFORMATION_SCHEMA.SESSION_STATE"
,
Integer
.
MAX_VALUE
);
ResultInterface
result
=
ci
.
executeQuery
(
0
,
false
);
while
(
result
.
next
())
{
Value
[]
row
=
result
.
currentRow
();
sessionState
.
add
(
row
[
1
].
getString
());
}
}
}
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/server/TcpServerThread.java
浏览文件 @
70660686
...
...
@@ -208,13 +208,14 @@ public class TcpServerThread implements Runnable {
case
SessionRemote
.
SESSION_PREPARE
:
{
int
id
=
transfer
.
readInt
();
String
sql
=
transfer
.
readString
();
int
old
=
session
.
getModificationId
();
Command
command
=
session
.
prepareLocal
(
sql
);
boolean
readonly
=
command
.
isReadOnly
();
cache
.
addObject
(
id
,
command
);
boolean
isQuery
=
command
.
isQuery
();
ObjectArray
params
=
command
.
getParameters
();
int
paramCount
=
params
.
size
();
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
).
writeBoolean
(
isQuery
).
writeBoolean
(
readonly
)
transfer
.
writeInt
(
getState
(
old
)
).
writeBoolean
(
isQuery
).
writeBoolean
(
readonly
)
.
writeInt
(
paramCount
);
if
(
operation
==
SessionRemote
.
SESSION_PREPARE_READ_PARAMS
)
{
for
(
int
i
=
0
;
i
<
paramCount
;
i
++)
{
...
...
@@ -235,8 +236,9 @@ public class TcpServerThread implements Runnable {
if
(
commit
==
null
)
{
commit
=
session
.
prepareLocal
(
"COMMIT"
);
}
int
old
=
session
.
getModificationId
();
commit
.
executeUpdate
();
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
).
flush
();
transfer
.
writeInt
(
getState
(
old
)
).
flush
();
break
;
}
case
SessionRemote
.
COMMAND_GET_META_DATA
:
{
...
...
@@ -260,10 +262,12 @@ public class TcpServerThread implements Runnable {
int
fetchSize
=
transfer
.
readInt
();
Command
command
=
(
Command
)
cache
.
getObject
(
id
,
false
);
setParameters
(
command
);
int
old
=
session
.
getModificationId
();
LocalResult
result
=
command
.
executeQueryLocal
(
maxRows
);
cache
.
addObject
(
objectId
,
result
);
int
columnCount
=
result
.
getVisibleColumnCount
();
transfer
.
writeInt
(
SessionRemote
.
STATUS_OK
).
writeInt
(
columnCount
);
int
state
=
getState
(
old
);
transfer
.
writeInt
(
state
).
writeInt
(
columnCount
);
int
rowCount
=
result
.
getRowCount
();
transfer
.
writeInt
(
rowCount
);
for
(
int
i
=
0
;
i
<
columnCount
;
i
++)
{
...
...
@@ -280,10 +284,13 @@ public class TcpServerThread implements Runnable {
int
id
=
transfer
.
readInt
();
Command
command
=
(
Command
)
cache
.
getObject
(
id
,
false
);
setParameters
(
command
);
int
old
=
session
.
getModificationId
();
int
updateCount
=
command
.
executeUpdate
();
int
status
=
SessionRemote
.
STATUS_OK
;
int
status
;
if
(
session
.
isClosed
())
{
status
=
SessionRemote
.
STATUS_CLOSED
;
}
else
{
status
=
getState
(
old
);
}
transfer
.
writeInt
(
status
).
writeInt
(
updateCount
).
writeBoolean
(
session
.
getAutoCommit
());
transfer
.
flush
();
...
...
@@ -343,6 +350,13 @@ public class TcpServerThread implements Runnable {
close
();
}
}
private
int
getState
(
int
oldModificationId
)
{
if
(
session
.
getModificationId
()
==
oldModificationId
)
{
return
SessionRemote
.
STATUS_OK
;
}
return
SessionRemote
.
STATUS_OK_STATE_CHANGED
;
}
private
void
sendRow
(
LocalResult
result
)
throws
IOException
,
SQLException
{
if
(
result
.
next
())
{
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/server/TestAutoReconnect.java
浏览文件 @
70660686
...
...
@@ -32,7 +32,7 @@ public class TestAutoReconnect extends TestBase {
* @param a ignored
*/
public
static
void
main
(
String
[]
a
)
throws
Exception
{
new
TestAutoReconnect
().
init
().
test
();
TestBase
.
createCaller
().
init
().
test
();
}
private
void
restart
()
throws
SQLException
{
...
...
@@ -98,6 +98,11 @@ public class TestAutoReconnect extends TestBase {
restart
();
assertFalse
(
rs
.
next
());
restart
();
stat
.
execute
(
"SET @TEST 10"
);
restart
();
rs
=
stat
.
executeQuery
(
"CALL @TEST"
);
rs
.
next
();
assertEquals
(
10
,
rs
.
getInt
(
1
));
stat
.
setFetchSize
(
10
);
restart
();
rs
=
stat
.
executeQuery
(
"select * from system_range(1, 20)"
);
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/server/TestAutoServer.java
浏览文件 @
70660686
...
...
@@ -30,7 +30,7 @@ public class TestAutoServer extends TestBase {
* @param a ignored
*/
public
static
void
main
(
String
[]
a
)
throws
Exception
{
new
TestAutoServ
er
().
init
().
test
();
TestBase
.
createCall
er
().
init
().
test
();
}
public
void
test
()
throws
Exception
{
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论