Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
e9ac5125
Shardingsphere
项目概览
apache
/
Shardingsphere
通知
56
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Shardingsphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
e9ac5125
编写于
9月 16, 2020
作者:
T
terrymanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add CircuitBreakException
上级
de6a0bc1
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
65 addition
and
37 deletion
+65
-37
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
...org/apache/shardingsphere/sharding/rule/ShardingRule.java
+28
-28
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/CircuitBreakException.java
...sphere/proxy/backend/exception/CircuitBreakException.java
+26
-0
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
...ingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
+4
-0
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
...and/query/binary/execute/MySQLComStmtExecuteExecutor.java
+2
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
...command/query/text/query/MySQLComQueryPacketExecutor.java
+2
-3
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
...phere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
+3
-3
未找到文件。
shardingsphere-features/shardingsphere-sharding/shardingsphere-sharding-common/src/main/java/org/apache/shardingsphere/sharding/rule/ShardingRule.java
浏览文件 @
e9ac5125
...
...
@@ -77,36 +77,36 @@ public final class ShardingRule implements DataNodeRoutedRule {
private
final
KeyGenerateAlgorithm
defaultKeyGenerateAlgorithm
;
public
ShardingRule
(
final
ShardingRuleConfiguration
config
uration
,
final
Collection
<
String
>
dataSourceNames
)
{
Preconditions
.
checkArgument
(
null
!=
config
uration
,
"ShardingRuleConfig cannot be null."
);
public
ShardingRule
(
final
ShardingRuleConfiguration
config
,
final
Collection
<
String
>
dataSourceNames
)
{
Preconditions
.
checkArgument
(
null
!=
config
,
"ShardingRuleConfig cannot be null."
);
Preconditions
.
checkArgument
(
null
!=
dataSourceNames
&&
!
dataSourceNames
.
isEmpty
(),
"Data sources cannot be empty."
);
this
.
dataSourceNames
=
getDataSourceNames
(
config
uration
.
getTables
(),
dataSourceNames
);
config
uration
.
getShardingAlgorithms
().
forEach
((
key
,
value
)
->
shardingAlgorithms
.
put
(
key
,
ShardingSphereAlgorithmFactory
.
createAlgorithm
(
value
,
ShardingAlgorithm
.
class
)));
config
uration
.
getKeyGenerators
().
forEach
((
key
,
value
)
->
keyGenerators
.
put
(
key
,
ShardingSphereAlgorithmFactory
.
createAlgorithm
(
value
,
KeyGenerateAlgorithm
.
class
)));
tableRules
=
new
LinkedList
<>(
createTableRules
(
config
uration
.
getTables
(),
configuration
.
getDefaultKeyGenerateStrategy
()));
tableRules
.
addAll
(
createAutoTableRules
(
config
uration
.
getAutoTables
(),
configuration
.
getDefaultKeyGenerateStrategy
()));
broadcastTables
=
config
uration
.
getBroadcastTables
();
bindingTableRules
=
createBindingTableRules
(
config
uration
.
getBindingTableGroups
());
defaultDatabaseShardingStrategy
=
createDefaultShardingStrategy
(
config
uration
.
getDefaultDatabaseShardingStrategy
());
defaultTableShardingStrategy
=
createDefaultShardingStrategy
(
config
uration
.
getDefaultTableShardingStrategy
());
defaultKeyGenerateAlgorithm
=
null
==
config
uration
.
getDefaultKeyGenerateStrategy
()
?
TypedSPIRegistry
.
getRegisteredService
(
KeyGenerateAlgorithm
.
class
)
:
keyGenerators
.
get
(
config
uration
.
getDefaultKeyGenerateStrategy
().
getKeyGeneratorName
());
}
public
ShardingRule
(
final
AlgorithmProvidedShardingRuleConfiguration
config
uration
,
final
Collection
<
String
>
dataSourceNames
)
{
Preconditions
.
checkArgument
(
null
!=
config
uration
,
"ShardingRuleConfig cannot be null."
);
this
.
dataSourceNames
=
getDataSourceNames
(
config
.
getTables
(),
dataSourceNames
);
config
.
getShardingAlgorithms
().
forEach
((
key
,
value
)
->
shardingAlgorithms
.
put
(
key
,
ShardingSphereAlgorithmFactory
.
createAlgorithm
(
value
,
ShardingAlgorithm
.
class
)));
config
.
getKeyGenerators
().
forEach
((
key
,
value
)
->
keyGenerators
.
put
(
key
,
ShardingSphereAlgorithmFactory
.
createAlgorithm
(
value
,
KeyGenerateAlgorithm
.
class
)));
tableRules
=
new
LinkedList
<>(
createTableRules
(
config
.
getTables
(),
config
.
getDefaultKeyGenerateStrategy
()));
tableRules
.
addAll
(
createAutoTableRules
(
config
.
getAutoTables
(),
config
.
getDefaultKeyGenerateStrategy
()));
broadcastTables
=
config
.
getBroadcastTables
();
bindingTableRules
=
createBindingTableRules
(
config
.
getBindingTableGroups
());
defaultDatabaseShardingStrategy
=
createDefaultShardingStrategy
(
config
.
getDefaultDatabaseShardingStrategy
());
defaultTableShardingStrategy
=
createDefaultShardingStrategy
(
config
.
getDefaultTableShardingStrategy
());
defaultKeyGenerateAlgorithm
=
null
==
config
.
getDefaultKeyGenerateStrategy
()
?
TypedSPIRegistry
.
getRegisteredService
(
KeyGenerateAlgorithm
.
class
)
:
keyGenerators
.
get
(
config
.
getDefaultKeyGenerateStrategy
().
getKeyGeneratorName
());
}
public
ShardingRule
(
final
AlgorithmProvidedShardingRuleConfiguration
config
,
final
Collection
<
String
>
dataSourceNames
)
{
Preconditions
.
checkArgument
(
null
!=
config
,
"ShardingRuleConfig cannot be null."
);
Preconditions
.
checkArgument
(
null
!=
dataSourceNames
&&
!
dataSourceNames
.
isEmpty
(),
"Data sources cannot be empty."
);
this
.
dataSourceNames
=
getDataSourceNames
(
config
uration
.
getTables
(),
dataSourceNames
);
shardingAlgorithms
.
putAll
(
config
uration
.
getShardingAlgorithms
());
keyGenerators
.
putAll
(
config
uration
.
getKeyGenerators
());
tableRules
=
new
LinkedList
<>(
createTableRules
(
config
uration
.
getTables
(),
configuration
.
getDefaultKeyGenerateStrategy
()));
tableRules
.
addAll
(
createAutoTableRules
(
config
uration
.
getAutoTables
(),
configuration
.
getDefaultKeyGenerateStrategy
()));
broadcastTables
=
config
uration
.
getBroadcastTables
();
bindingTableRules
=
createBindingTableRules
(
config
uration
.
getBindingTableGroups
());
defaultDatabaseShardingStrategy
=
createDefaultShardingStrategy
(
config
uration
.
getDefaultDatabaseShardingStrategy
());
defaultTableShardingStrategy
=
createDefaultShardingStrategy
(
config
uration
.
getDefaultTableShardingStrategy
());
defaultKeyGenerateAlgorithm
=
null
==
config
uration
.
getDefaultKeyGenerateStrategy
()
?
TypedSPIRegistry
.
getRegisteredService
(
KeyGenerateAlgorithm
.
class
)
:
keyGenerators
.
get
(
config
uration
.
getDefaultKeyGenerateStrategy
().
getKeyGeneratorName
());
this
.
dataSourceNames
=
getDataSourceNames
(
config
.
getTables
(),
dataSourceNames
);
shardingAlgorithms
.
putAll
(
config
.
getShardingAlgorithms
());
keyGenerators
.
putAll
(
config
.
getKeyGenerators
());
tableRules
=
new
LinkedList
<>(
createTableRules
(
config
.
getTables
(),
config
.
getDefaultKeyGenerateStrategy
()));
tableRules
.
addAll
(
createAutoTableRules
(
config
.
getAutoTables
(),
config
.
getDefaultKeyGenerateStrategy
()));
broadcastTables
=
config
.
getBroadcastTables
();
bindingTableRules
=
createBindingTableRules
(
config
.
getBindingTableGroups
());
defaultDatabaseShardingStrategy
=
createDefaultShardingStrategy
(
config
.
getDefaultDatabaseShardingStrategy
());
defaultTableShardingStrategy
=
createDefaultShardingStrategy
(
config
.
getDefaultTableShardingStrategy
());
defaultKeyGenerateAlgorithm
=
null
==
config
.
getDefaultKeyGenerateStrategy
()
?
TypedSPIRegistry
.
getRegisteredService
(
KeyGenerateAlgorithm
.
class
)
:
keyGenerators
.
get
(
config
.
getDefaultKeyGenerateStrategy
().
getKeyGeneratorName
());
}
private
Collection
<
String
>
getDataSourceNames
(
final
Collection
<
ShardingTableRuleConfiguration
>
tableRuleConfigs
,
final
Collection
<
String
>
dataSourceNames
)
{
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/CircuitBreakException.java
0 → 100644
浏览文件 @
e9ac5125
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.apache.shardingsphere.proxy.backend.exception
;
/**
* Circuit break exception.
*/
public
final
class
CircuitBreakException
extends
BackendException
{
private
static
final
long
serialVersionUID
=
6339672680026286798L
;
}
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
浏览文件 @
e9ac5125
...
...
@@ -23,6 +23,7 @@ import org.apache.shardingsphere.db.protocol.error.CommonErrorCode;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLServerErrorCode
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket
;
import
org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException
;
import
org.apache.shardingsphere.proxy.backend.exception.CircuitBreakException
;
import
org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException
;
import
org.apache.shardingsphere.proxy.backend.exception.DBDropExistsException
;
import
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException
;
...
...
@@ -76,6 +77,9 @@ public final class MySQLErrPacketFactory {
if
(
cause
instanceof
TableExistsException
)
{
return
new
MySQLErrPacket
(
sequenceId
,
MySQLServerErrorCode
.
ER_TABLE_EXISTS_ERROR
,
((
TableExistsException
)
cause
).
getTableName
());
}
if
(
cause
instanceof
CircuitBreakException
)
{
return
new
MySQLErrPacket
(
sequenceId
,
CommonErrorCode
.
CIRCUIT_BREAK_MODE
);
}
if
(
cause
instanceof
ShardingSphereConfigurationException
||
cause
instanceof
SQLParsingException
)
{
return
new
MySQLErrPacket
(
sequenceId
,
MySQLServerErrorCode
.
ER_NOT_SUPPORTED_YET
,
cause
.
getMessage
());
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/binary/execute/MySQLComStmtExecuteExecutor.java
浏览文件 @
e9ac5125
...
...
@@ -18,7 +18,6 @@
package
org.apache.shardingsphere.proxy.frontend.mysql.command.query.binary.execute
;
import
lombok.Getter
;
import
org.apache.shardingsphere.db.protocol.error.CommonErrorCode
;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLColumnType
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.MySQLPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.command.query.MySQLColumnDefinition41Packet
;
...
...
@@ -26,7 +25,6 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.MySQLFie
import
org.apache.shardingsphere.db.protocol.mysql.packet.command.query.binary.execute.MySQLBinaryResultSetRowPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.command.query.binary.execute.MySQLComStmtExecutePacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLEofPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket
;
import
org.apache.shardingsphere.db.protocol.packet.DatabasePacket
;
import
org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.QueryHeader
;
...
...
@@ -34,6 +32,7 @@ import org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicati
import
org.apache.shardingsphere.proxy.backend.communication.DatabaseCommunicationEngineFactory
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.context.ProxyContext
;
import
org.apache.shardingsphere.proxy.backend.exception.CircuitBreakException
;
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
...
...
@@ -70,7 +69,7 @@ public final class MySQLComStmtExecuteExecutor implements QueryCommandExecutor {
@Override
public
Collection
<
DatabasePacket
<?>>
execute
()
throws
SQLException
{
if
(
ProxyContext
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
MySQLErrPacket
(
1
,
CommonErrorCode
.
CIRCUIT_BREAK_MODE
)
);
throw
new
CircuitBreakException
(
);
}
BackendResponse
backendResponse
=
databaseCommunicationEngine
.
execute
();
if
(
backendResponse
instanceof
QueryResponse
)
{
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/command/query/text/query/MySQLComQueryPacketExecutor.java
浏览文件 @
e9ac5125
...
...
@@ -18,7 +18,6 @@
package
org.apache.shardingsphere.proxy.frontend.mysql.command.query.text.query
;
import
lombok.Getter
;
import
org.apache.shardingsphere.db.protocol.error.CommonErrorCode
;
import
org.apache.shardingsphere.db.protocol.mysql.constant.MySQLColumnType
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.MySQLPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.command.query.MySQLColumnDefinition41Packet
;
...
...
@@ -27,13 +26,13 @@ import org.apache.shardingsphere.db.protocol.mysql.packet.command.query.MySQLFie
import
org.apache.shardingsphere.db.protocol.mysql.packet.command.query.text.MySQLTextResultSetRowPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.command.query.text.query.MySQLComQueryPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLEofPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLErrPacket
;
import
org.apache.shardingsphere.db.protocol.mysql.packet.generic.MySQLOKPacket
;
import
org.apache.shardingsphere.db.protocol.packet.DatabasePacket
;
import
org.apache.shardingsphere.infra.database.type.DatabaseTypes
;
import
org.apache.shardingsphere.infra.executor.sql.raw.execute.result.query.QueryHeader
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.context.ProxyContext
;
import
org.apache.shardingsphere.proxy.backend.exception.CircuitBreakException
;
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
...
...
@@ -67,7 +66,7 @@ public final class MySQLComQueryPacketExecutor implements QueryCommandExecutor {
@Override
public
Collection
<
DatabasePacket
<?>>
execute
()
throws
SQLException
{
if
(
ProxyContext
.
getInstance
().
getSchemaContexts
().
isCircuitBreak
())
{
return
Collections
.
singletonList
(
new
MySQLErrPacket
(
1
,
CommonErrorCode
.
CIRCUIT_BREAK_MODE
)
);
throw
new
CircuitBreakException
(
);
}
BackendResponse
backendResponse
=
textProtocolBackendHandler
.
execute
();
if
(
backendResponse
instanceof
QueryResponse
)
{
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/test/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactoryTest.java
浏览文件 @
e9ac5125
...
...
@@ -36,7 +36,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public
void
assertNewInstanceWithSQLException
()
{
MySQLErrPacket
actual
=
MySQLErrPacketFactory
.
newInstance
(
1
,
new
SQLException
(
"No reason"
,
"XXX"
,
9999
,
new
RuntimeException
()));
MySQLErrPacket
actual
=
MySQLErrPacketFactory
.
newInstance
(
1
,
new
SQLException
(
"No reason"
,
"XXX"
,
9999
,
new
RuntimeException
(
""
)));
assertThat
(
actual
.
getSequenceId
(),
is
(
1
));
assertThat
(
actual
.
getErrorCode
(),
is
(
9999
));
assertThat
(
actual
.
getSqlState
(),
is
(
"XXX"
));
...
...
@@ -44,7 +44,7 @@ public final class MySQLErrPacketFactoryTest {
}
@Test
public
void
assertNewInstanceWithSQLExceptionOfNullS
ql
State
()
{
public
void
assertNewInstanceWithSQLExceptionOfNullS
QL
State
()
{
MySQLErrPacket
actual
=
MySQLErrPacketFactory
.
newInstance
(
1
,
new
SQLException
(
new
RuntimeException
(
"No reason"
)));
assertThat
(
actual
.
getSequenceId
(),
is
(
1
));
assertThat
(
actual
.
getErrorCode
(),
is
(
1815
));
...
...
@@ -54,7 +54,7 @@ public final class MySQLErrPacketFactoryTest {
@Test
public
void
assertNewInstanceWithSQLExceptionOfNullParam
()
{
MySQLErrPacket
actual
=
MySQLErrPacketFactory
.
newInstance
(
1
,
new
SQLException
());
MySQLErrPacket
actual
=
MySQLErrPacketFactory
.
newInstance
(
1
,
new
SQLException
(
""
));
assertThat
(
actual
.
getSequenceId
(),
is
(
1
));
assertThat
(
actual
.
getErrorCode
(),
is
(
1815
));
assertThat
(
actual
.
getSqlState
(),
is
(
"HY000"
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录