You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by zh...@apache.org on 2024/08/10 06:07:09 UTC
(shardingsphere) branch master updated: Add AdvancedProxySQLExecutor (#32449)
This is an automated email from the ASF dual-hosted git repository.
zhangliang 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 03c797f39e5 Add AdvancedProxySQLExecutor (#32449)
03c797f39e5 is described below
commit 03c797f39e58d336d06b2a01f34f9a0501bdf98f
Author: Liang Zhang <zh...@apache.org>
AuthorDate: Sat Aug 10 14:07:03 2024 +0800
Add AdvancedProxySQLExecutor (#32449)
---
.../connector/AdvancedProxySQLExecutor.java | 39 ++++++++++++++++++++++
.../proxy/backend/connector/DatabaseConnector.java | 4 ++-
2 files changed, 42 insertions(+), 1 deletion(-)
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/AdvancedProxySQLExecutor.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/AdvancedProxySQLExecutor.java
new file mode 100644
index 00000000000..c931aa3c21b
--- /dev/null
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/AdvancedProxySQLExecutor.java
@@ -0,0 +1,39 @@
+/*
+ * 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.proxy.backend.connector;
+
+import org.apache.shardingsphere.infra.executor.sql.context.ExecutionContext;
+import org.apache.shardingsphere.infra.executor.sql.execute.result.ExecuteResult;
+import org.apache.shardingsphere.infra.spi.annotation.SingletonSPI;
+
+import java.util.List;
+
+/**
+ * Advanced proxy SQL executor.
+ */
+@SingletonSPI
+public interface AdvancedProxySQLExecutor {
+
+ /**
+ * Execute.
+ *
+ * @param executionContext execution context
+ * @return execute result
+ */
+ List<ExecuteResult> execute(ExecutionContext executionContext);
+}
diff --git a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
index ed96c09ee2f..140aa9f1cde 100644
--- a/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
+++ b/proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/connector/DatabaseConnector.java
@@ -51,6 +51,7 @@ import org.apache.shardingsphere.infra.metadata.database.schema.util.SystemSchem
import org.apache.shardingsphere.infra.rule.attribute.datanode.DataNodeRuleAttribute;
import org.apache.shardingsphere.infra.session.connection.cursor.CursorConnectionContext;
import org.apache.shardingsphere.infra.session.query.QueryContext;
+import org.apache.shardingsphere.infra.spi.ShardingSphereServiceLoader;
import org.apache.shardingsphere.mode.manager.ContextManager;
import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
import org.apache.shardingsphere.mode.metadata.refresher.MetaDataRefreshEngine;
@@ -238,7 +239,8 @@ public final class DatabaseConnector implements DatabaseBackendHandler {
return new UpdateResponseHeader(queryContext.getSqlStatementContext().getSqlStatement());
}
proxySQLExecutor.checkExecutePrerequisites(executionContext);
- List<ExecuteResult> executeResults = proxySQLExecutor.execute(executionContext);
+ Collection<AdvancedProxySQLExecutor> advancedExecutors = ShardingSphereServiceLoader.getServiceInstances(AdvancedProxySQLExecutor.class);
+ List<ExecuteResult> executeResults = advancedExecutors.isEmpty() ? proxySQLExecutor.execute(executionContext) : advancedExecutors.iterator().next().execute(executionContext);
getMetaDataRefreshEngine().refresh(queryContext.getSqlStatementContext(), executionContext.getRouteContext().getRouteUnits());
Object executeResultSample = executeResults.iterator().next();
return executeResultSample instanceof QueryResult