You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/10/25 11:04:37 UTC

[GitHub] [shardingsphere] tuichenchuxin opened a new pull request, #21748: Add validate for duplicated single table.

tuichenchuxin opened a new pull request, #21748:
URL: https://github.com/apache/shardingsphere/pull/21748

   Prevent adding same single table in one logic datasource.
   Like this.
   ```
   mysql> SHOW DEFAULT SINGLE TABLE STORAGE UNIT;
   +-------------------+
   | storage_unit_name |
   +-------------------+
   | RANDOM            |
   +-------------------+
   1 row in set (0.00 sec)
   
   mysql> create table t2 (id int);
   Query OK, 0 rows affected (0.14 sec)
   
   mysql> create table t2 (id int);
   Query OK, 0 rows affected (0.15 sec)
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #21748: Add validate for duplicated single table.

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on code in PR #21748:
URL: https://github.com/apache/shardingsphere/pull/21748#discussion_r1005119086


##########
kernel/single-table/core/src/main/java/org/apache/shardingsphere/singletable/route/engine/SingleTableStandardRouteEngine.java:
##########
@@ -80,13 +81,20 @@ private Map<String, RouteUnit> getDataSourceRouteUnits(final RouteContext newRou
     private void route0(final RouteContext routeContext, final SingleTableRule rule) {
         if (sqlStatement instanceof CreateTableStatement) {
             String dataSourceName = rule.assignNewDataSourceName();
-            String tableName = singleTableNames.iterator().next().getTableName();
-            routeContext.getRouteUnits().add(new RouteUnit(new RouteMapper(dataSourceName, dataSourceName), Collections.singleton(new RouteMapper(tableName, tableName))));
+            QualifiedTable table = singleTableNames.iterator().next();
+            if (isDuplicatedTable(table, rule)) {
+                throw new DuplicatedSingleTableException(table.getTableName());

Review Comment:
   Can we use TableExistsException here?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] tuichenchuxin commented on a diff in pull request #21748: Add validate for duplicated single table.

Posted by GitBox <gi...@apache.org>.
tuichenchuxin commented on code in PR #21748:
URL: https://github.com/apache/shardingsphere/pull/21748#discussion_r1005128669


##########
kernel/single-table/core/src/main/java/org/apache/shardingsphere/singletable/route/engine/SingleTableStandardRouteEngine.java:
##########
@@ -80,13 +81,20 @@ private Map<String, RouteUnit> getDataSourceRouteUnits(final RouteContext newRou
     private void route0(final RouteContext routeContext, final SingleTableRule rule) {
         if (sqlStatement instanceof CreateTableStatement) {
             String dataSourceName = rule.assignNewDataSourceName();
-            String tableName = singleTableNames.iterator().next().getTableName();
-            routeContext.getRouteUnits().add(new RouteUnit(new RouteMapper(dataSourceName, dataSourceName), Collections.singleton(new RouteMapper(tableName, tableName))));
+            QualifiedTable table = singleTableNames.iterator().next();
+            if (isDuplicatedTable(table, rule)) {
+                throw new DuplicatedSingleTableException(table.getTableName());

Review Comment:
   Done. Thanks.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [shardingsphere] strongduanmu merged pull request #21748: Add validate for duplicated single table.

Posted by GitBox <gi...@apache.org>.
strongduanmu merged PR #21748:
URL: https://github.com/apache/shardingsphere/pull/21748


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org