Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dev3
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojinchao95 committed Mar 16, 2024
2 parents 1fcf4d2 + 4f71ffc commit 0989e0a
Show file tree
Hide file tree
Showing 25 changed files with 37 additions and 195 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 42S02 | 10007 | Table or view \`%s\` does not exist. |
| 42000 | 10010 | Rule does not exist. |
| 44000 | 10011 | '%s.'%s' initialization failed, reason is: %s. |
| 44000 | 10012 | Can not find '%s' algorithm on table '%s'. |
| 42S02 | 10020 | Schema \`%s\` does not exist. |
| 42S02 | 10021 | Single table \`%s\` does not exist. |
| HY000 | 10022 | Can not load table with database name \`%s\` and data source name \`%s\`. |
Expand Down Expand Up @@ -276,12 +277,6 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
|-----------|-------------|-------------------------------------------------------------|
| 42S02 | 20990 | Invalid mask algorithm \`%s\` in database \`%s\`. |

### 基础算法 - 分布式序列

| SQL State | Vendor Code | 错误信息 |
|-----------|-------------|---------------------------------------------------------------------|
| 44000 | 21180 | Can not find strategy for generate keys with table \`%s\`. |

### 联邦查询

| SQL State | Vendor Code | 错误信息 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
| 42S02 | 10007 | Table or view \`%s\` does not exist. |
| 42000 | 10010 | Rule does not exist. |
| 44000 | 10011 | '%s.'%s' initialization failed, reason is: %s. |
| 44000 | 10012 | Can not find '%s' algorithm on table '%s'. |
| 42S02 | 10020 | Schema \`%s\` does not exist. |
| 42S02 | 10021 | Single table \`%s\` does not exist. |
| HY000 | 10022 | Can not load table with database name \`%s\` and data source name \`%s\`. |
Expand Down Expand Up @@ -291,12 +292,6 @@ SQL error codes provide by standard `SQL State`, `Vendor Code` and `Reason`, whi
|-----------|-------------|-------------------------------------------------------------|
| 42S02 | 20990 | Invalid mask algorithm \`%s\` in database \`%s\`. |

### Infra algorithm - key generate

| SQL State | Vendor Code | Reason |
|-----------|-------------|---------------------------------------------------------------------|
| 44000 | 21180 | Can not find strategy for generate keys with table \`%s\`. |

### SQL Federation

| SQL State | Vendor Code | Reason |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public final class StandardReadwriteSplittingDataSourceRouter {
* @return routed data source name
*/
public String route(final ReadwriteSplittingDataSourceRule rule) {
return rule.getLoadBalancer().getAvailableTargetName(rule.getName(), getFilteredReadDataSources(rule));
return rule.getLoadBalancer().getTargetName(rule.getName(), getFilteredReadDataSources(rule));
}

private List<String> getFilteredReadDataSources(final ReadwriteSplittingDataSourceRule rule) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import lombok.Getter;
import org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
import org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
import org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmNotFoundException;
import org.apache.shardingsphere.infra.algorithm.keygen.core.KeyGenerateAlgorithm;
import org.apache.shardingsphere.infra.algorithm.keygen.core.exception.GenerateKeyStrategyNotFoundException;
import org.apache.shardingsphere.infra.binder.context.statement.SQLStatementContext;
import org.apache.shardingsphere.infra.binder.context.statement.dml.SelectStatementContext;
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
Expand Down Expand Up @@ -592,7 +592,7 @@ public Collection<? extends Comparable<?>> generateKeys(final AlgorithmSQLContex

private KeyGenerateAlgorithm getKeyGenerateAlgorithm(final String logicTableName) {
Optional<ShardingTable> shardingTable = findShardingTable(logicTableName);
ShardingSpherePreconditions.checkState(shardingTable.isPresent(), () -> new GenerateKeyStrategyNotFoundException(logicTableName));
ShardingSpherePreconditions.checkState(shardingTable.isPresent(), () -> new AlgorithmNotFoundException("key generator", logicTableName));
return null == shardingTable.get().getKeyGeneratorName() ? defaultKeyGenerateAlgorithm : keyGenerators.get(shardingTable.get().getKeyGeneratorName());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import org.apache.shardingsphere.infra.algorithm.core.config.AlgorithmConfiguration;
import org.apache.shardingsphere.infra.algorithm.core.context.AlgorithmSQLContext;
import org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmInitializationException;
import org.apache.shardingsphere.infra.algorithm.keygen.core.exception.GenerateKeyStrategyNotFoundException;
import org.apache.shardingsphere.infra.algorithm.core.exception.AlgorithmNotFoundException;
import org.apache.shardingsphere.infra.algorithm.keygen.snowflake.SnowflakeKeyGenerateAlgorithm;
import org.apache.shardingsphere.infra.algorithm.keygen.uuid.UUIDKeyGenerateAlgorithm;
import org.apache.shardingsphere.infra.binder.context.segment.table.TablesContext;
Expand Down Expand Up @@ -336,7 +336,7 @@ void assertNotFindGenerateKeyColumn() {
void assertGenerateKeyFailure() {
AlgorithmSQLContext generateContext = mock(AlgorithmSQLContext.class);
when(generateContext.getTableName()).thenReturn("table_0");
assertThrows(GenerateKeyStrategyNotFoundException.class, () -> createMaximumShardingRule().generateKeys(generateContext, 1));
assertThrows(AlgorithmNotFoundException.class, () -> createMaximumShardingRule().generateKeys(generateContext, 1));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
* limitations under the License.
*/

package org.apache.shardingsphere.infra.algorithm.keygen.core.exception;
package org.apache.shardingsphere.infra.algorithm.core.exception;

import org.apache.shardingsphere.infra.exception.core.external.sql.sqlstate.XOpenSQLState;
import org.apache.shardingsphere.infra.exception.core.external.sql.type.kernel.category.MetaDataSQLException;

/**
* Generate key strategy not found exception.
* Algorithm not found exception.
*/
public final class GenerateKeyStrategyNotFoundException extends KeyGenerateSQLException {
public final class AlgorithmNotFoundException extends MetaDataSQLException {

private static final long serialVersionUID = 7456922260524630374L;
private static final long serialVersionUID = -6334833729231404326L;

public GenerateKeyStrategyNotFoundException(final String tableName) {
super(XOpenSQLState.CHECK_OPTION_VIOLATION, 80, "Can not find strategy for generate keys with table `%s`.", tableName);
public AlgorithmNotFoundException(final String algorithmType, final String tableName) {
super(XOpenSQLState.CHECK_OPTION_VIOLATION, 12, "Can not find '%s' algorithm on table '%s'.", algorithmType, tableName);
}
}
12 changes: 0 additions & 12 deletions infra/algorithm/key-generator/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,10 @@
<name>${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-algorithm-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
5 changes: 0 additions & 5 deletions infra/algorithm/key-generator/type/snowflake/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
<name>${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-algorithm-key-generator-core</artifactId>
Expand Down
5 changes: 0 additions & 5 deletions infra/algorithm/key-generator/type/uuid/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
<name>${project.artifactId}</name>

<dependencies>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-infra-algorithm-key-generator-core</artifactId>
Expand Down
7 changes: 0 additions & 7 deletions infra/algorithm/load-balancer/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,5 @@
<artifactId>shardingsphere-infra-algorithm-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ default void check(String databaseName, Collection<String> configuredTargetNames
}

/**
* Get available target name.
* Get target name.
*
* @param groupName group name which uniquely identifies available target names
* @param availableTargetNames available target names
* @return available target name
* @return available target names
*/
String getAvailableTargetName(String groupName, List<String> availableTargetNames);
String getTargetName(String groupName, List<String> availableTargetNames);
}
7 changes: 0 additions & 7 deletions infra/algorithm/load-balancer/type/random/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,5 @@
<artifactId>shardingsphere-infra-algorithm-load-balancer-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
public final class RandomLoadBalanceAlgorithm implements LoadBalanceAlgorithm {

@Override
public String getAvailableTargetName(final String groupName, final List<String> availableTargetNames) {
public String getTargetName(final String groupName, final List<String> availableTargetNames) {
return availableTargetNames.get(ThreadLocalRandom.current().nextInt(availableTargetNames.size()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ void assertGetAvailableTargetNameWithDefaultStrategy() {
String availableTargetNames2 = "test_read_ds_2";
List<String> availableTargetNames = Arrays.asList(availableTargetNames1, availableTargetNames2);
assertRandomLoadBalance(availableTargetNames, loadBalanceAlgorithm);
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getAvailableTargetName("ds", availableTargetNames)));
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getAvailableTargetName("ds", availableTargetNames)));
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getTargetName("ds", availableTargetNames)));
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getTargetName("ds", availableTargetNames)));
}

private void assertRandomLoadBalance(final List<String> availableTargetNames, final LoadBalanceAlgorithm loadBalanceAlgorithm) {
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getAvailableTargetName("ds", availableTargetNames)));
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getAvailableTargetName("ds", availableTargetNames)));
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getAvailableTargetName("ds", availableTargetNames)));
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getTargetName("ds", availableTargetNames)));
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getTargetName("ds", availableTargetNames)));
assertTrue(availableTargetNames.contains(loadBalanceAlgorithm.getTargetName("ds", availableTargetNames)));
}
}
7 changes: 0 additions & 7 deletions infra/algorithm/load-balancer/type/round-robin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,5 @@
<artifactId>shardingsphere-infra-algorithm-load-balancer-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.shardingsphere</groupId>
<artifactId>shardingsphere-test-util</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public final class RoundRobinLoadBalanceAlgorithm implements LoadBalanceAlgorith
private final AtomicInteger count = new AtomicInteger(0);

@Override
public String getAvailableTargetName(final String groupName, final List<String> availableTargetNames) {
public String getTargetName(final String groupName, final List<String> availableTargetNames) {
return availableTargetNames.get(Math.abs(count.getAndIncrement()) % availableTargetNames.size());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ void assertGetAvailableTargetNameWithDefaultStrategy() {

private void assertRoundRobinLoadBalance(final String availableTargetName1, final String availableTargetName2, final LoadBalanceAlgorithm loadBalanceAlgorithm,
final List<String> availableTargetNames) {
assertThat(loadBalanceAlgorithm.getAvailableTargetName("ds", availableTargetNames), is(availableTargetName1));
assertThat(loadBalanceAlgorithm.getAvailableTargetName("ds", availableTargetNames), is(availableTargetName2));
assertThat(loadBalanceAlgorithm.getAvailableTargetName("ds", availableTargetNames), is(availableTargetName1));
assertThat(loadBalanceAlgorithm.getAvailableTargetName("ds", availableTargetNames), is(availableTargetName2));
assertThat(loadBalanceAlgorithm.getTargetName("ds", availableTargetNames), is(availableTargetName1));
assertThat(loadBalanceAlgorithm.getTargetName("ds", availableTargetNames), is(availableTargetName2));
assertThat(loadBalanceAlgorithm.getTargetName("ds", availableTargetNames), is(availableTargetName1));
assertThat(loadBalanceAlgorithm.getTargetName("ds", availableTargetNames), is(availableTargetName2));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void check(final String databaseName, final Collection<String> configured
}

@Override
public String getAvailableTargetName(final String groupName, final List<String> availableTargetNames) {
public String getTargetName(final String groupName, final List<String> availableTargetNames) {
double[] weight = weightMap.containsKey(groupName) && weightMap.get(groupName).length == availableTargetNames.size() ? weightMap.get(groupName) : initWeight(availableTargetNames);
weightMap.put(groupName, weight);
return getAvailableTargetName(availableTargetNames, weight);
Expand Down
Loading

0 comments on commit 0989e0a

Please sign in to comment.