This is an automated email from the ASF dual-hosted git repository.
zhaojinchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git
The following commit(s) were added to refs/heads/master by this push:
new 9eb7f066fde Add InvalidReadDatabaseWeightException (#21117)
9eb7f066fde is described below
commit 9eb7f066fde062d6bf06ddc2de0319c4b7fc4bab
Author: Liang Zhang <[email protected]>
AuthorDate: Wed Sep 21 18:55:36 2022 +0800
Add InvalidReadDatabaseWeightException (#21117)
---
.../user-manual/error-code/sql-error-code.cn.md | 6 ++++
.../user-manual/error-code/sql-error-code.en.md | 6 ++++
...ReplicaWeightReadQueryLoadBalanceAlgorithm.java | 3 +-
...sactionWeightReadQueryLoadBalanceAlgorithm.java | 3 +-
.../WeightReadQueryLoadBalanceAlgorithm.java | 3 +-
.../exception/ReadwriteSplittingSQLException.java | 35 ++++++++++++++++++++++
.../InvalidReadDatabaseWeightException.java | 33 ++++++++++++++++++++
7 files changed, 86 insertions(+), 3 deletions(-)
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
index a6c300f9e25..edd11a95b36 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.cn.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.cn.md
@@ -151,6 +151,12 @@ SQL 错误码以标准的 SQL State,Vendor Code 和详细错误信息提供,
| 44000 | 20082 | Inline sharding algorithms expression \`%s\` and
sharding column \`%s\` do not match |
| 44000 | 20090 | Can not find strategy for generate keys with table
\`%s\` |
+### 读写分离
+
+| SQL State | Vendor Code | 错误信息 |
+| --------- | ----------- | ------ |
+| HY004 | 20280 | Invalid read database weight \`%s\` |
+
### 数据库高可用
| SQL State | Vendor Code | 错误信息 |
diff --git a/docs/document/content/user-manual/error-code/sql-error-code.en.md
b/docs/document/content/user-manual/error-code/sql-error-code.en.md
index 0f90f91a98c..e66f92311bd 100644
--- a/docs/document/content/user-manual/error-code/sql-error-code.en.md
+++ b/docs/document/content/user-manual/error-code/sql-error-code.en.md
@@ -151,6 +151,12 @@ SQL error codes provide by standard `SQL State`, `Vendor
Code` and `Reason`, whi
| 44000 | 20082 | Inline sharding algorithms expression \`%s\` and
sharding column \`%s\` do not match |
| 44000 | 20090 | Can not find strategy for generate keys with table
\`%s\` |
+### Readwrite Splitting
+
+| SQL State | Vendor Code | Reason |
+| --------- | ----------- | ------ |
+| HY004 | 20280 | Invalid read database weight \`%s\` |
+
### Database HA
| SQL State | Vendor Code | Reason |
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/FixedReplicaWeightReadQueryLoadBalanceAlgorithm.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/FixedReplicaWeightReadQueryLoadBalanceAlgorithm.java
index ac4eff04437..3a5c96598e4 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/FixedReplicaWeightReadQueryLoadBalanceAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/FixedReplicaWeightReadQueryLoadBalanceAlgorithm.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance;
import com.google.common.base.Preconditions;
import lombok.Getter;
import
org.apache.shardingsphere.infra.context.transaction.TransactionConnectionContext;
+import
org.apache.shardingsphere.readwritesplitting.exception.algorithm.InvalidReadDatabaseWeightException;
import
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import java.util.Arrays;
@@ -110,7 +111,7 @@ public final class
FixedReplicaWeightReadQueryLoadBalanceAlgorithm implements Re
try {
result = Double.parseDouble(weightObject.toString());
} catch (final NumberFormatException ex) {
- throw new NumberFormatException("Read database weight
configuration error, configuration parameters:" + weightObject);
+ throw new InvalidReadDatabaseWeightException(weightObject);
}
if (Double.isInfinite(result)) {
result = 10000.0D;
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/TransactionWeightReadQueryLoadBalanceAlgorithm.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/TransactionWeightReadQueryLoadBalanceAlgorithm.java
index d888ede2a0c..8c6821303f5 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/TransactionWeightReadQueryLoadBalanceAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/TransactionWeightReadQueryLoadBalanceAlgorithm.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance;
import com.google.common.base.Preconditions;
import lombok.Getter;
import
org.apache.shardingsphere.infra.context.transaction.TransactionConnectionContext;
+import
org.apache.shardingsphere.readwritesplitting.exception.algorithm.InvalidReadDatabaseWeightException;
import
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import java.util.Arrays;
@@ -104,7 +105,7 @@ public final class
TransactionWeightReadQueryLoadBalanceAlgorithm implements Rea
try {
result = Double.parseDouble(weightObject.toString());
} catch (final NumberFormatException ex) {
- throw new NumberFormatException("Read database weight
configuration error, configuration parameters:" + weightObject);
+ throw new InvalidReadDatabaseWeightException(weightObject);
}
if (Double.isInfinite(result)) {
result = 10000.0D;
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithm.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithm.java
index 089b0d044bd..55b21bb1679 100644
---
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithm.java
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/algorithm/loadbalance/WeightReadQueryLoadBalanceAlgorithm.java
@@ -20,6 +20,7 @@ package
org.apache.shardingsphere.readwritesplitting.algorithm.loadbalance;
import com.google.common.base.Preconditions;
import lombok.Getter;
import
org.apache.shardingsphere.infra.context.transaction.TransactionConnectionContext;
+import
org.apache.shardingsphere.readwritesplitting.exception.algorithm.InvalidReadDatabaseWeightException;
import
org.apache.shardingsphere.readwritesplitting.spi.ReadQueryLoadBalanceAlgorithm;
import java.util.Arrays;
@@ -108,7 +109,7 @@ public final class WeightReadQueryLoadBalanceAlgorithm
implements ReadQueryLoadB
try {
result = Double.parseDouble(weightObject.toString());
} catch (final NumberFormatException ex) {
- throw new NumberFormatException("Read database weight
configuration error, configuration parameters:" + weightObject);
+ throw new InvalidReadDatabaseWeightException(weightObject);
}
if (Double.isInfinite(result)) {
result = 10000.0D;
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/ReadwriteSplittingSQLException.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/ReadwriteSplittingSQLException.java
new file mode 100644
index 00000000000..f0152f8df3f
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/ReadwriteSplittingSQLException.java
@@ -0,0 +1,35 @@
+/*
+ * 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.readwritesplitting.exception;
+
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.SQLState;
+import
org.apache.shardingsphere.infra.util.exception.external.sql.type.feature.FeatureSQLException;
+
+/**
+ * Readwrite splitting SQL exception.
+ */
+public abstract class ReadwriteSplittingSQLException extends
FeatureSQLException {
+
+ private static final long serialVersionUID = -4072517988732429040L;
+
+ private static final int FEATURE_CODE = 2;
+
+ public ReadwriteSplittingSQLException(final SQLState sqlState, final int
errorCode, final String reason, final Object... messageArguments) {
+ super(sqlState, FEATURE_CODE, errorCode, reason, messageArguments);
+ }
+}
diff --git
a/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/InvalidReadDatabaseWeightException.java
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/InvalidReadDatabaseWeightException.java
new file mode 100644
index 00000000000..7bb8844f877
--- /dev/null
+++
b/shardingsphere-features/shardingsphere-readwrite-splitting/shardingsphere-readwrite-splitting-core/src/main/java/org/apache/shardingsphere/readwritesplitting/exception/algorithm/InvalidReadDatabaseWeightException.java
@@ -0,0 +1,33 @@
+/*
+ * 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.readwritesplitting.exception.algorithm;
+
+import
org.apache.shardingsphere.infra.util.exception.external.sql.sqlstate.XOpenSQLState;
+import
org.apache.shardingsphere.readwritesplitting.exception.ReadwriteSplittingSQLException;
+
+/**
+ * Invalid read database weight exception.
+ */
+public final class InvalidReadDatabaseWeightException extends
ReadwriteSplittingSQLException {
+
+ private static final long serialVersionUID = -846600820893274188L;
+
+ public InvalidReadDatabaseWeightException(final Object weight) {
+ super(XOpenSQLState.INVALID_DATA_TYPE, 80, "Invalid read database
weight `%s`", weight);
+ }
+}