Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
f0436942
提交
f0436942
authored
15 年前
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Cluster: non-admin users could not connect when one of the cluster node was stopped. Issue 206.
上级
632bf2a0
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
49 行增加
和
14 行删除
+49
-14
Set.java
h2/src/main/org/h2/command/dml/Set.java
+7
-1
Constants.java
h2/src/main/org/h2/engine/Constants.java
+6
-0
Engine.java
h2/src/main/org/h2/engine/Engine.java
+6
-4
SessionRemote.java
h2/src/main/org/h2/engine/SessionRemote.java
+5
-3
CreateCluster.java
h2/src/main/org/h2/tools/CreateCluster.java
+12
-6
TestCluster.java
h2/src/test/org/h2/test/db/TestCluster.java
+13
-0
没有找到文件。
h2/src/main/org/h2/command/dml/Set.java
浏览文件 @
f0436942
...
@@ -10,6 +10,7 @@ import java.text.Collator;
...
@@ -10,6 +10,7 @@ import java.text.Collator;
import
org.h2.command.Prepared
;
import
org.h2.command.Prepared
;
import
org.h2.compress.Compressor
;
import
org.h2.compress.Compressor
;
import
org.h2.constant.ErrorCode
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.engine.Database
;
import
org.h2.engine.Database
;
import
org.h2.engine.Mode
;
import
org.h2.engine.Mode
;
import
org.h2.engine.Session
;
import
org.h2.engine.Session
;
...
@@ -82,8 +83,13 @@ public class Set extends Prepared {
...
@@ -82,8 +83,13 @@ public class Set extends Prepared {
addOrUpdateSetting
(
name
,
null
,
getIntValue
());
addOrUpdateSetting
(
name
,
null
,
getIntValue
());
break
;
break
;
case
SetTypes
.
CLUSTER
:
{
case
SetTypes
.
CLUSTER
:
{
if
(
Constants
.
CLUSTERING_ENABLED
.
equals
(
stringValue
))
{
// this value is used when connecting
// ignore, as the cluster setting is checked later
break
;
}
String
value
=
StringUtils
.
quoteStringSQL
(
stringValue
);
String
value
=
StringUtils
.
quoteStringSQL
(
stringValue
);
if
(!
value
.
equals
(
database
.
getCluster
())
&&
!
value
.
equals
(
"''"
))
{
if
(!
value
.
equals
(
database
.
getCluster
())
&&
!
value
.
equals
(
Constants
.
CLUSTERING_DISABLED
))
{
// anybody can disable the cluster
// anybody can disable the cluster
// (if he can't access a cluster node)
// (if he can't access a cluster node)
session
.
getUser
().
checkAdmin
();
session
.
getUser
().
checkAdmin
();
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Constants.java
浏览文件 @
f0436942
...
@@ -81,6 +81,12 @@ public class Constants {
...
@@ -81,6 +81,12 @@ public class Constants {
*/
*/
public
static
final
String
CLUSTERING_DISABLED
=
"''"
;
public
static
final
String
CLUSTERING_DISABLED
=
"''"
;
/**
* The value of the cluster setting if clustering is enabled (the actual
* value is checked later).
*/
public
static
final
String
CLUSTERING_ENABLED
=
"TRUE"
;
/**
/**
* The database URL used when calling a function if only the column list
* The database URL used when calling a function if only the column list
* should be returned.
* should be returned.
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/Engine.java
浏览文件 @
f0436942
...
@@ -195,6 +195,7 @@ public class Engine {
...
@@ -195,6 +195,7 @@ public class Engine {
}
}
String
clusterDb
=
database
.
getCluster
();
String
clusterDb
=
database
.
getCluster
();
if
(!
Constants
.
CLUSTERING_DISABLED
.
equals
(
clusterDb
))
{
if
(!
Constants
.
CLUSTERING_DISABLED
.
equals
(
clusterDb
))
{
if
(!
Constants
.
CLUSTERING_ENABLED
.
equals
(
clusterSession
))
{
if
(!
StringUtils
.
equals
(
clusterSession
,
clusterDb
))
{
if
(!
StringUtils
.
equals
(
clusterSession
,
clusterDb
))
{
if
(
clusterDb
.
equals
(
Constants
.
CLUSTERING_DISABLED
))
{
if
(
clusterDb
.
equals
(
Constants
.
CLUSTERING_DISABLED
))
{
throw
DbException
.
get
(
ErrorCode
.
CLUSTER_ERROR_DATABASE_RUNS_ALONE
);
throw
DbException
.
get
(
ErrorCode
.
CLUSTER_ERROR_DATABASE_RUNS_ALONE
);
...
@@ -203,6 +204,7 @@ public class Engine {
...
@@ -203,6 +204,7 @@ public class Engine {
}
}
}
}
}
}
}
/**
/**
* Called after a database has been closed, to remove the object from the
* Called after a database has been closed, to remove the object from the
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/engine/SessionRemote.java
浏览文件 @
f0436942
...
@@ -153,7 +153,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
...
@@ -153,7 +153,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
}
}
}
}
private
void
switchOffAutoCommitIfCluster
(
)
{
private
void
checkClusterDisableAutoCommit
(
String
serverList
)
{
if
(
autoCommit
&&
transferList
.
size
()
>
1
)
{
if
(
autoCommit
&&
transferList
.
size
()
>
1
)
{
if
(
switchOffAutoCommit
==
null
)
{
if
(
switchOffAutoCommit
==
null
)
{
switchOffAutoCommit
=
prepareCommand
(
"SET AUTOCOMMIT FALSE"
,
Integer
.
MAX_VALUE
);
switchOffAutoCommit
=
prepareCommand
(
"SET AUTOCOMMIT FALSE"
,
Integer
.
MAX_VALUE
);
...
@@ -162,6 +162,8 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
...
@@ -162,6 +162,8 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
switchOffAutoCommit
.
executeUpdate
();
switchOffAutoCommit
.
executeUpdate
();
// so we need to switch it on
// so we need to switch it on
autoCommit
=
true
;
autoCommit
=
true
;
CommandInterface
c
=
prepareCommand
(
"SET CLUSTER "
+
serverList
,
Integer
.
MAX_VALUE
);
c
.
executeUpdate
();
cluster
=
true
;
cluster
=
true
;
}
}
}
}
...
@@ -290,7 +292,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
...
@@ -290,7 +292,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
String
serverList
=
null
;
String
serverList
=
null
;
if
(
server
.
indexOf
(
','
)
>=
0
)
{
if
(
server
.
indexOf
(
','
)
>=
0
)
{
serverList
=
StringUtils
.
quoteStringSQL
(
server
);
serverList
=
StringUtils
.
quoteStringSQL
(
server
);
ci
.
setProperty
(
"CLUSTER"
,
serverList
);
ci
.
setProperty
(
"CLUSTER"
,
Constants
.
CLUSTERING_ENABLED
);
}
}
autoReconnect
=
Boolean
.
valueOf
(
ci
.
getProperty
(
"AUTO_RECONNECT"
,
"false"
)).
booleanValue
();
autoReconnect
=
Boolean
.
valueOf
(
ci
.
getProperty
(
"AUTO_RECONNECT"
,
"false"
)).
booleanValue
();
// AUTO_SERVER implies AUTO_RECONNECT
// AUTO_SERVER implies AUTO_RECONNECT
...
@@ -332,7 +334,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
...
@@ -332,7 +334,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
if
(
switchOffCluster
)
{
if
(
switchOffCluster
)
{
switchOffCluster
();
switchOffCluster
();
}
}
switchOffAutoCommitIfCluster
(
);
checkClusterDisableAutoCommit
(
serverList
);
}
catch
(
DbException
e
)
{
}
catch
(
DbException
e
)
{
traceSystem
.
close
();
traceSystem
.
close
();
throw
e
;
throw
e
;
...
...
This diff is collapsed.
Click to expand it.
h2/src/main/org/h2/tools/CreateCluster.java
浏览文件 @
f0436942
...
@@ -11,6 +11,8 @@ import java.sql.Connection;
...
@@ -11,6 +11,8 @@ import java.sql.Connection;
import
java.sql.DriverManager
;
import
java.sql.DriverManager
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
import
java.sql.Statement
;
import
java.sql.Statement
;
import
org.h2.constant.ErrorCode
;
import
org.h2.engine.Constants
;
import
org.h2.util.IOUtils
;
import
org.h2.util.IOUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.JdbcUtils
;
import
org.h2.util.Tool
;
import
org.h2.util.Tool
;
...
@@ -100,16 +102,20 @@ public class CreateCluster extends Tool {
...
@@ -100,16 +102,20 @@ public class CreateCluster extends Tool {
try
{
try
{
org
.
h2
.
Driver
.
load
();
org
.
h2
.
Driver
.
load
();
// verify that the database doesn't exist
// verify that the database doesn't exist,
boolean
exists
;
// or if it exists (an old cluster instance), it is deleted
boolean
exists
=
true
;
try
{
try
{
connTarget
=
DriverManager
.
getConnection
(
urlTarget
+
";IFEXISTS=TRUE"
,
user
,
password
);
connTarget
=
DriverManager
.
getConnection
(
urlTarget
+
";IFEXISTS=TRUE;CLUSTER="
+
Constants
.
CLUSTERING_ENABLED
,
user
,
password
);
connTarget
.
createStatement
().
execute
(
"DROP ALL OBJECTS DELETE FILES"
);
exists
=
false
;
connTarget
.
close
();
connTarget
.
close
();
exists
=
true
;
}
catch
(
SQLException
e
)
{
}
catch
(
SQLException
e
)
{
// database does not exists - ok
if
(
e
.
getErrorCode
()
==
ErrorCode
.
DATABASE_NOT_FOUND_1
)
{
// database does not exists yet - ok
exists
=
false
;
exists
=
false
;
}
}
}
if
(
exists
)
{
if
(
exists
)
{
throw
new
SQLException
(
"Target database must not yet exist. Please delete it first"
);
throw
new
SQLException
(
"Target database must not yet exist. Please delete it first"
);
}
}
...
...
This diff is collapsed.
Click to expand it.
h2/src/test/org/h2/test/db/TestCluster.java
浏览文件 @
f0436942
...
@@ -112,6 +112,16 @@ public class TestCluster extends TestBase {
...
@@ -112,6 +112,16 @@ public class TestCluster extends TestBase {
check
(
connApp
,
len
,
"'"
+
serverList
+
"'"
);
check
(
connApp
,
len
,
"'"
+
serverList
+
"'"
);
n1
.
stop
();
n1
.
stop
();
// test non-admin cluster connection if only one server runs
Connection
connApp2
=
DriverManager
.
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
check
(
connApp2
,
len
,
"''"
);
connApp2
.
close
();
// test non-admin cluster connection if only one server runs
connApp2
=
DriverManager
.
getConnection
(
urlCluster
+
";AUTO_RECONNECT=TRUE"
,
user2
,
password2
);
check
(
connApp2
,
len
,
"''"
);
connApp2
.
close
();
n2
.
stop
();
n2
.
stop
();
deleteFiles
();
deleteFiles
();
}
}
...
@@ -179,6 +189,9 @@ public class TestCluster extends TestBase {
...
@@ -179,6 +189,9 @@ public class TestCluster extends TestBase {
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
check
(
conn
,
len
,
"''"
);
check
(
conn
,
len
,
"''"
);
conn
.
close
();
conn
.
close
();
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://"
+
serverList
+
"/test"
,
user
,
password
);
check
(
conn
,
len
,
"''"
);
conn
.
close
();
// disable the cluster
// disable the cluster
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:tcp://localhost:"
+
port1
+
"/test;CLUSTER=''"
,
user
,
password
);
...
...
This diff is collapsed.
Click to expand it.
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论