Skip to content

Commit

Permalink
Remove DuplicateDataSourceException (#30737)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Apr 1, 2024
1 parent d1a4564 commit 327fe6d
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 08000 | 10110 | Storage units can not connect, error messages are: %s. |
| 0A000 | 10111 | Can not alter connection info in storage units: '%s'. |
| 44000 | 10120 | Invalid storage unit status, error message is: %s. |
| 42S01 | 10130 | Duplicate data sources '%s' in database '%s' and global data sources. |
| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s |
| 42S02 | 10201 | There is no rule in database '%s'. |
| 42S02 | 10202 | %s rules '%s' do not exist in database '%s'. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| 08000 | 10110 | Storage units can not connect, error messages are: %s. |
| 0A000 | 10111 | Can not alter connection info in storage units: '%s'. |
| 44000 | 10120 | Invalid storage unit status, error message is: %s. |
| 42S01 | 10130 | Duplicate data sources '%s' in database '%s' and global data sources. |
| 44000 | 10200 | Invalid '%s' rule '%s', error message is: %s |
| 42S02 | 10201 | There is no rule in database '%s'. |
| 42S02 | 10202 | %s rules '%s' do not exist in database '%s'. |
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public final class DuplicateStorageUnitException extends ResourceDefinitionExcep

private static final long serialVersionUID = 2103793827572264148L;

public DuplicateStorageUnitException(final Collection<String> storageUnitNames) {
super(XOpenSQLState.DUPLICATE, 4, "Duplicate storage unit names '%s'.", String.join(", ", storageUnitNames));
public DuplicateStorageUnitException(final String databaseName, final Collection<String> storageUnitNames) {
super(XOpenSQLState.DUPLICATE, 4, "Duplicate storage unit names '%s' on database '%s'.", String.join(", ", storageUnitNames), databaseName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void checkBefore(final AlterStorageUnitStatement sqlStatement) {

private void checkDuplicatedStorageUnitNames(final Collection<String> storageUnitNames) {
Collection<String> duplicatedStorageUnitNames = storageUnitNames.stream().filter(each -> storageUnitNames.stream().filter(each::equals).count() > 1).collect(Collectors.toList());
ShardingSpherePreconditions.checkState(duplicatedStorageUnitNames.isEmpty(), () -> new DuplicateStorageUnitException(duplicatedStorageUnitNames));
ShardingSpherePreconditions.checkState(duplicatedStorageUnitNames.isEmpty(), () -> new DuplicateStorageUnitException(database.getName(), duplicatedStorageUnitNames));
}

private void checkStorageUnitNameExisted(final Collection<String> storageUnitNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void checkDuplicatedDataSourceNames(final ContextManager contextManager,
}
dataSourceNames.add(each.getName());
}
ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitException(duplicatedDataSourceNames));
ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitException(database.getName(), duplicatedDataSourceNames));
}

private void checkDuplicatedLogicalDataSourceNames(final Collection<String> requiredDataSourceNames) {
Expand All @@ -98,7 +98,7 @@ private void checkDuplicatedLogicalDataSourceNames(final Collection<String> requ
return;
}
Collection<String> duplicatedDataSourceNames = requiredDataSourceNames.stream().filter(logicalDataSourceNames::contains).collect(Collectors.toSet());
ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitException(duplicatedDataSourceNames));
ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitException(database.getName(), duplicatedDataSourceNames));
}

private Collection<String> getCurrentStorageUnitNames(final ContextManager contextManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
import org.apache.shardingsphere.infra.exception.metadata.resource.storageunit.DuplicateStorageUnitException;
import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDataSourceConfiguration;
import org.apache.shardingsphere.proxy.backend.config.yaml.YamlProxyDatabaseConfiguration;
import org.apache.shardingsphere.infra.exception.metadata.resource.datasource.DuplicateDataSourceException;

import java.util.Collection;
import java.util.Map;
Expand All @@ -47,6 +47,6 @@ public static void checkDataSources(final Map<String, YamlProxyDataSourceConfigu
private static void checkDataSources(final Map<String, YamlProxyDataSourceConfiguration> globalDataSources,
final Map<String, YamlProxyDataSourceConfiguration> databaseDataSources, final String databaseName) {
Collection<String> duplicatedDataSourceNames = globalDataSources.keySet().stream().filter(databaseDataSources.keySet()::contains).collect(Collectors.toSet());
ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateDataSourceException(databaseName, duplicatedDataSourceNames));
ShardingSpherePreconditions.checkState(duplicatedDataSourceNames.isEmpty(), () -> new DuplicateStorageUnitException(databaseName, duplicatedDataSourceNames));
}
}

0 comments on commit 327fe6d

Please sign in to comment.