You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by me...@apache.org on 2022/06/15 09:17:16 UTC
[shardingsphere] branch master updated: Optimize stop writing error message for PostgreSQL (#18376)
This is an automated email from the ASF dual-hosted git repository.
menghaoran 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 5948a30eb3b Optimize stop writing error message for PostgreSQL (#18376)
5948a30eb3b is described below
commit 5948a30eb3b346c650137bd8cb866166d77163e3
Author: gin <ja...@163.com>
AuthorDate: Wed Jun 15 17:17:09 2022 +0800
Optimize stop writing error message for PostgreSQL (#18376)
---
.../db/protocol/postgresql/constant/PostgreSQLErrorCode.java | 1 +
.../proxy/backend/exception/DatabaseLockedException.java | 6 ++++++
.../proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java | 5 +++++
3 files changed, 12 insertions(+)
diff --git a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLErrorCode.java b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLErrorCode.java
index d050f509e15..4cb9f187cc7 100644
--- a/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLErrorCode.java
+++ b/shardingsphere-db-protocol/shardingsphere-db-protocol-postgresql/src/main/java/org/apache/shardingsphere/db/protocol/postgresql/constant/PostgreSQLErrorCode.java
@@ -44,6 +44,7 @@ public enum PostgreSQLErrorCode {
SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION("08001", "sqlclient_unable_to_establish_sqlconnection"),
SQLSERVER_REJECTED_ESTABLISHMENT_OF_SQLCONNECTION("08004", "sqlserver_rejected_establishment_of_sqlconnection"),
TRANSACTION_RESOLUTION_UNKNOWN("08007", "transaction_resolution_unknown"),
+ MODIFYING_SQL_DATA_NOT_PERMITTED("38002", "modifying_sql_data_not_permitted"),
PROTOCOL_VIOLATION("08P01", "protocol_violation"),
FEATURE_NOT_SUPPORTED("0A000", "feature_not_supported"),
DUPLICATE_DATABASE("42P04", "Database '%s' already exists"),
diff --git a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseLockedException.java b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseLockedException.java
index c61996eca31..f9e7c21f5d5 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseLockedException.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/DatabaseLockedException.java
@@ -30,4 +30,10 @@ public final class DatabaseLockedException extends BackendException {
private static final long serialVersionUID = -5409739222950362541L;
private final String databaseName;
+
+ private final String errorMessage;
+
+ public DatabaseLockedException(final String databaseName) {
+ this(databaseName, String.format("The database %s is read-only", databaseName));
+ }
}
diff --git a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
index 5d2a4527fac..7b8f9a76e35 100644
--- a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
+++ b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-postgresql/src/main/java/org/apache/shardingsphere/proxy/frontend/postgresql/err/PostgreSQLErrPacketFactory.java
@@ -24,6 +24,7 @@ import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLError
import org.apache.shardingsphere.db.protocol.postgresql.constant.PostgreSQLMessageSeverityLevel;
import org.apache.shardingsphere.db.protocol.postgresql.packet.generic.PostgreSQLErrorResponsePacket;
import org.apache.shardingsphere.proxy.backend.exception.DBCreateExistsException;
+import org.apache.shardingsphere.proxy.backend.exception.DatabaseLockedException;
import org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.InvalidAuthorizationSpecificationException;
import org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLAuthenticationException;
import org.apache.shardingsphere.proxy.frontend.postgresql.authentication.exception.PostgreSQLProtocolViolationException;
@@ -71,6 +72,10 @@ public final class PostgreSQLErrPacketFactory {
return PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.ERROR, PostgreSQLErrorCode.DUPLICATE_DATABASE,
String.format(PostgreSQLErrorCode.DUPLICATE_DATABASE.getConditionName(), ((DBCreateExistsException) cause).getDatabaseName())).build();
}
+ if (cause instanceof DatabaseLockedException) {
+ DatabaseLockedException exception = (DatabaseLockedException) cause;
+ return PostgreSQLErrorResponsePacket.newBuilder(PostgreSQLMessageSeverityLevel.ERROR, PostgreSQLErrorCode.MODIFYING_SQL_DATA_NOT_PERMITTED, exception.getErrorMessage()).build();
+ }
// TODO PostgreSQL need consider FrontendConnectionLimitException
return createErrorResponsePacketForUnknownException(cause);
}