Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
apache
Shardingsphere
提交
aca45af3
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 搜索 >>
未验证
提交
aca45af3
编写于
8月 24, 2020
作者:
J
Juan Pan(Trista)
提交者:
GitHub
8月 24, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add checking for creating the same database. (#7028)
上级
8e5e83b4
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
61 addition
and
4 deletion
+61
-4
shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
...here/db/protocol/mysql/constant/MySQLServerErrorCode.java
+2
-0
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DBCreateExistsException.java
...here/proxy/backend/exception/DBCreateExistsException.java
+33
-0
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandler.java
...ingsphere/proxy/backend/text/admin/RDLBackendHandler.java
+5
-1
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/OrchestrationSchemaContextsFixture.java
...tion/jdbc/execute/OrchestrationSchemaContextsFixture.java
+1
-1
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandlerTest.java
...phere/proxy/backend/text/admin/RDLBackendHandlerTest.java
+15
-1
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-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/ddl/CreateDatabaseStatement.java
...sql/parser/sql/statement/ddl/CreateDatabaseStatement.java
+1
-1
未找到文件。
shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
浏览文件 @
aca45af3
...
...
@@ -42,6 +42,8 @@ public enum MySQLServerErrorCode implements SQLErrorCode {
ER_UNSUPPORTED_PS
(
1295
,
"HY000"
,
"This command is not supported in the prepared statement protocol yet"
),
ER_DB_CREATE_EXISTS
(
1007
,
"HY000"
,
"Message: Can't create database '%s'; database exists"
),
ER_ERROR_ON_MODIFYING_GTID_EXECUTED_TABLE
(
3176
,
"HY000"
,
"Please do not modify the %s table with an XA transaction. This is an internal system table used to store GTIDs for committed transactions. "
+
"Although modifying it can lead to an inconsistent GTID state, if neccessary you can modify it with a non-XA transaction."
);
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DBCreateExistsException.java
0 → 100644
浏览文件 @
aca45af3
/*
* 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
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
/**
* DB create exists exception.
*/
@RequiredArgsConstructor
@Getter
public
final
class
DBCreateExistsException
extends
BackendException
{
private
static
final
long
serialVersionUID
=
779787160167652641L
;
private
final
String
databaseName
;
}
shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandler.java
浏览文件 @
aca45af3
...
...
@@ -27,6 +27,7 @@ import org.apache.shardingsphere.infra.database.type.DatabaseType;
import
org.apache.shardingsphere.infra.yaml.swapper.YamlRuleConfigurationSwapperEngine
;
import
org.apache.shardingsphere.kernel.context.StandardSchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException
;
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.query.QueryData
;
...
...
@@ -72,7 +73,10 @@ public final class RDLBackendHandler implements TextProtocolBackendHandler {
}
private
BackendResponse
execute
(
final
CreateDatabaseStatementContext
context
)
{
SchemaNameCallback
.
getInstance
().
run
(
context
.
getSqlStatement
().
getSchemaName
(),
true
);
if
(
ProxySchemaContexts
.
getInstance
().
getSchemaNames
().
contains
(
context
.
getSqlStatement
().
getDatabaseName
()))
{
return
new
ErrorResponse
(
new
DBCreateExistsException
(
context
.
getSqlStatement
().
getDatabaseName
()));
}
SchemaNameCallback
.
getInstance
().
run
(
context
.
getSqlStatement
().
getDatabaseName
(),
true
);
// TODO Need to get the executed feedback from registry center for returning.
UpdateResponse
result
=
new
UpdateResponse
();
result
.
setType
(
"CREATE"
);
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/communication/jdbc/execute/OrchestrationSchemaContextsFixture.java
浏览文件 @
aca45af3
...
...
@@ -41,7 +41,7 @@ public final class OrchestrationSchemaContextsFixture implements SchemaContexts
@Override
public
Map
<
String
,
SchemaContext
>
getSchemaContexts
()
{
return
Collections
.
emptyMap
(
);
return
Collections
.
singletonMap
(
"schema"
,
mock
(
SchemaContext
.
class
)
);
}
@Override
...
...
shardingsphere-proxy/shardingsphere-proxy-backend/src/test/java/org/apache/shardingsphere/proxy/backend/text/admin/RDLBackendHandlerTest.java
浏览文件 @
aca45af3
...
...
@@ -25,6 +25,7 @@ import org.apache.shardingsphere.kernel.context.SchemaContext;
import
org.apache.shardingsphere.kernel.context.StandardSchemaContexts
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.connection.BackendConnection
;
import
org.apache.shardingsphere.proxy.backend.communication.jdbc.execute.OrchestrationSchemaContextsFixture
;
import
org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException
;
import
org.apache.shardingsphere.proxy.backend.response.BackendResponse
;
import
org.apache.shardingsphere.proxy.backend.response.error.ErrorResponse
;
import
org.apache.shardingsphere.proxy.backend.response.update.UpdateResponse
;
...
...
@@ -69,6 +70,19 @@ public final class RDLBackendHandlerTest {
assertThat
(
response
,
instanceOf
(
UpdateResponse
.
class
));
}
@Test
public
void
assertExecuteCreateDatabaseContextWithException
()
{
BackendConnection
connection
=
mock
(
BackendConnection
.
class
);
when
(
connection
.
getSchema
()).
thenReturn
(
"schema"
);
RDLBackendHandler
executeEngine
=
new
RDLBackendHandler
(
connection
,
new
CreateDatabaseStatement
(
"schema"
));
BackendResponse
response
=
executeEngine
.
execute
();
assertThat
(
response
,
instanceOf
(
ErrorResponse
.
class
));
setOrchestrationSchemaContexts
(
true
);
response
=
executeEngine
.
execute
();
assertThat
(
response
,
instanceOf
(
ErrorResponse
.
class
));
assertThat
(((
ErrorResponse
)
response
).
getCause
(),
instanceOf
(
DBCreateExistsException
.
class
));
}
private
Map
<
String
,
SchemaContext
>
getSchemaContextMap
()
{
SchemaContext
result
=
new
SchemaContext
(
"schema"
,
null
,
null
);
return
Collections
.
singletonMap
(
"schema"
,
result
);
...
...
@@ -103,7 +117,7 @@ public final class RDLBackendHandlerTest {
Field
schemaContexts
=
ProxySchemaContexts
.
getInstance
().
getClass
().
getDeclaredField
(
"schemaContexts"
);
schemaContexts
.
setAccessible
(
true
);
if
(
isOrchestration
)
{
schemaContexts
.
set
(
ProxySchemaContexts
.
getInstance
(),
mock
(
OrchestrationSchemaContextsFixture
.
class
));
schemaContexts
.
set
(
ProxySchemaContexts
.
getInstance
(),
new
OrchestrationSchemaContextsFixture
(
));
}
else
{
schemaContexts
.
set
(
ProxySchemaContexts
.
getInstance
(),
new
StandardSchemaContexts
());
}
...
...
shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
浏览文件 @
aca45af3
...
...
@@ -22,6 +22,7 @@ import lombok.NoArgsConstructor;
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.proxy.backend.exception.DBCreateExistsException
;
import
org.apache.shardingsphere.proxy.backend.exception.NoDatabaseSelectedException
;
import
org.apache.shardingsphere.proxy.backend.exception.TableModifyInTransactionException
;
import
org.apache.shardingsphere.proxy.backend.exception.UnknownDatabaseException
;
...
...
@@ -62,6 +63,9 @@ public final class MySQLErrPacketFactory {
if
(
cause
instanceof
NoDatabaseSelectedException
)
{
return
new
MySQLErrPacket
(
sequenceId
,
MySQLServerErrorCode
.
ER_NO_DB_ERROR
);
}
if
(
cause
instanceof
DBCreateExistsException
)
{
return
new
MySQLErrPacket
(
sequenceId
,
MySQLServerErrorCode
.
ER_DB_CREATE_EXISTS
,
((
DBCreateExistsException
)
cause
).
getDatabaseName
());
}
return
new
MySQLErrPacket
(
sequenceId
,
CommonErrorCode
.
UNKNOWN_EXCEPTION
,
cause
.
getMessage
());
}
}
shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/statement/ddl/CreateDatabaseStatement.java
浏览文件 @
aca45af3
...
...
@@ -27,5 +27,5 @@ import lombok.RequiredArgsConstructor;
@Getter
public
final
class
CreateDatabaseStatement
extends
DDLStatement
{
private
final
String
schema
Name
;
private
final
String
database
Name
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录