This is an automated email from the ASF dual-hosted git repository.
xiaoyu 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 a35c5e7 Refactor LockWaitTimeoutException (#8683)
a35c5e7 is described below
commit a35c5e786a615510adfa40ca7fa5b90ef2d0edd4
Author: Haoran Meng <[email protected]>
AuthorDate: Fri Dec 18 11:49:07 2020 +0800
Refactor LockWaitTimeoutException (#8683)
---
.../db/protocol/mysql/constant/MySQLServerErrorCode.java | 2 +-
.../infra/config/properties/ConfigurationPropertyKey.java | 2 +-
.../backend/communication/DatabaseCommunicationEngine.java | 14 +++++++-------
.../proxy/backend/exception/LockWaitTimeoutException.java | 7 +++++++
.../src/main/resources/conf/server.yaml | 2 +-
.../proxy/frontend/state/impl/LockProxyState.java | 5 +++--
.../proxy/frontend/mysql/MySQLErrPacketFactory.java | 2 +-
7 files changed, 21 insertions(+), 13 deletions(-)
diff --git
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
index e54f707..84923aa 100644
---
a/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
+++
b/shardingsphere-db-protocol/shardingsphere-db-protocol-mysql/src/main/java/org/apache/shardingsphere/db/protocol/mysql/constant/MySQLServerErrorCode.java
@@ -58,7 +58,7 @@ public enum MySQLServerErrorCode implements SQLErrorCode {
"Please do not modify the %s table with an XA transaction. This is
an internal system table used to store GTIDs for committed transactions. "
+ "Although modifying it can lead to an inconsistent GTID
state, if neccessary you can modify it with a non-XA transaction."),
- ER_LOCKING_SERVICE_TIMEOUT(3133, "HY000", "Message: Service lock wait
timeout exceeded");
+ ER_LOCKING_SERVICE_TIMEOUT(3133, "HY000", "Message: Service lock wait
timeout of %s ms exceeded");
private final int errorCode;
diff --git
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/properties/ConfigurationPropertyKey.java
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/properties/ConfigurationPropertyKey.java
index 68f7026..036350d 100644
---
a/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/properties/ConfigurationPropertyKey.java
+++
b/shardingsphere-infra/shardingsphere-infra-common/src/main/java/org/apache/shardingsphere/infra/config/properties/ConfigurationPropertyKey.java
@@ -126,7 +126,7 @@ public enum ConfigurationPropertyKey implements
TypedPropertyKey {
/**
* The length of time in milliseconds an SQL waits for a global lock
before giving up.
*/
- LOCK_WAIT_TIMEOUT_MILLISECONDS("lock-wait-timeout-milliseconds",
String.valueOf(5000L), long.class);
+ LOCK_WAIT_TIMEOUT_MILLISECONDS("lock-wait-timeout-milliseconds",
String.valueOf(50000L), long.class);
private final String key;
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
index 56e3cbf..b40f58c 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/communication/DatabaseCommunicationEngine.java
@@ -108,7 +108,7 @@ public final class DatabaseCommunicationEngine {
if (executionContext.getExecutionUnits().isEmpty()) {
return new
UpdateResponseHeader(executionContext.getSqlStatementContext().getSqlStatement());
}
- lockForDDL(executionContext);
+ lockForDDL(executionContext,
ProxyContext.getInstance().getMetaDataContexts().getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS));
proxySQLExecutor.checkExecutePrerequisites(executionContext);
Collection<ExecuteResult> executeResults =
proxySQLExecutor.execute(executionContext);
ExecuteResult executeResultSample = executeResults.iterator().next();
@@ -117,12 +117,12 @@ public final class DatabaseCommunicationEngine {
: processExecuteUpdate(executionContext,
executeResults.stream().map(each -> (UpdateResult)
each).collect(Collectors.toList()));
}
- private void lockForDDL(final ExecutionContext executionContext) {
+ private void lockForDDL(final ExecutionContext executionContext, final
Long lockTimeoutMilliseconds) {
if (needLock(executionContext)) {
- if
(!LockContext.getLockStrategy().tryLock(ProxyContext.getInstance().getMetaDataContexts().getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS)))
{
- throw new LockWaitTimeoutException();
+ if
(!LockContext.getLockStrategy().tryLock(lockTimeoutMilliseconds)) {
+ throw new LockWaitTimeoutException(lockTimeoutMilliseconds);
}
- checkLock();
+ checkLock(lockTimeoutMilliseconds);
}
}
@@ -130,9 +130,9 @@ public final class DatabaseCommunicationEngine {
return
SchemaRefresherFactory.newInstance(executionContext.getSqlStatementContext().getSqlStatement()).isPresent();
}
- private void checkLock() {
+ private void checkLock(final Long lockTimeoutMilliseconds) {
if (!LockContext.getLockStrategy().checkLock()) {
- throw new LockWaitTimeoutException();
+ throw new LockWaitTimeoutException(lockTimeoutMilliseconds);
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/LockWaitTimeoutException.java
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/LockWaitTimeoutException.java
index f968c05..eafc786 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/LockWaitTimeoutException.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-backend/src/main/java/org/apache/shardingsphere/proxy/backend/exception/LockWaitTimeoutException.java
@@ -17,10 +17,17 @@
package org.apache.shardingsphere.proxy.backend.exception;
+import lombok.Getter;
+import lombok.RequiredArgsConstructor;
+
/**
* Lock wait timeout exception.
*/
+@RequiredArgsConstructor
+@Getter
public final class LockWaitTimeoutException extends BackendException {
private static final long serialVersionUID = 2599713085782288003L;
+
+ private final Long timeoutMilliseconds;
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
index f858525..10ca789 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
+++
b/shardingsphere-proxy/shardingsphere-proxy-bootstrap/src/main/resources/conf/server.yaml
@@ -56,4 +56,4 @@
# query-with-cipher-column: true
# sql-show: false
# check-table-metadata-enabled: false
-# lock-wait-timeout-milliseconds: 5000 # The maximum time to wait for a lock
+# lock-wait-timeout-milliseconds: 50000 # The maximum time to wait for a lock
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
index 07c5af4..99dfba3 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-core/src/main/java/org/apache/shardingsphere/proxy/frontend/state/impl/LockProxyState.java
@@ -54,8 +54,9 @@ public final class LockProxyState implements ProxyState {
}
private void block(final ChannelHandlerContext context, final
DatabaseProtocolFrontendEngine databaseProtocolFrontendEngine) {
- if
(!LockContext.await(ProxyContext.getInstance().getMetaDataContexts().getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS)))
{
- doError(context, databaseProtocolFrontendEngine, new
LockWaitTimeoutException());
+ Long lockTimeoutMilliseconds =
ProxyContext.getInstance().getMetaDataContexts().getProps().<Long>getValue(ConfigurationPropertyKey.LOCK_WAIT_TIMEOUT_MILLISECONDS);
+ if (!LockContext.await(lockTimeoutMilliseconds)) {
+ doError(context, databaseProtocolFrontendEngine, new
LockWaitTimeoutException(lockTimeoutMilliseconds));
return;
}
}
diff --git
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
index d8f1228..363a3ec 100644
---
a/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
+++
b/shardingsphere-proxy/shardingsphere-proxy-frontend/shardingsphere-proxy-frontend-mysql/src/main/java/org/apache/shardingsphere/proxy/frontend/mysql/MySQLErrPacketFactory.java
@@ -108,7 +108,7 @@ public final class MySQLErrPacketFactory {
return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_SP_DOES_NOT_EXIST);
}
if (cause instanceof LockWaitTimeoutException) {
- return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_LOCKING_SERVICE_TIMEOUT);
+ return new MySQLErrPacket(1,
MySQLServerErrorCode.ER_LOCKING_SERVICE_TIMEOUT, ((LockWaitTimeoutException)
cause).getTimeoutMilliseconds());
}
return new MySQLErrPacket(1, CommonErrorCode.UNKNOWN_EXCEPTION,
cause.getMessage());
}