sandynz commented on code in PR #24146:
URL: https://github.com/apache/shardingsphere/pull/24146#discussion_r1105214956
##########
jdbc/core/src/main/java/org/apache/shardingsphere/driver/data/pipeline/datasource/creator/ShardingSpherePipelineDataSourceCreator.java:
##########
@@ -41,6 +42,8 @@ public DataSource createPipelineDataSource(final Object
dataSourceConfig) throws
enableRangeQueryForInline(shardingRuleConfig);
rootConfig.setDatabaseName(null);
rootConfig.setSchemaName(null);
+ // TODO set a large enough value, make sure when a jdbc streaming
query parameter is take effect
+
rootConfig.getProps().put(ConfigurationPropertyKey.MAX_CONNECTIONS_SIZE_PER_QUERY.getKey(),
100000);
Review Comment:
Need some test when data source max connection is less than
MAX_CONNECTIONS_SIZE_PER_QUERY
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/util/JDBCStreamQueryUtil.java:
##########
@@ -0,0 +1,59 @@
+/*
+ * 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.data.pipeline.core.util;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * JDBC stream query util.
+ */
+public final class JDBCStreamQueryUtil {
+
+ /**
+ * Generate MySQL stream query prepared statement.
+ *
+ * @param connection connection
+ * @param sql sql
+ * @return stream query prepared statement
+ * @throws SQLException SQL exception
+ */
+ public static PreparedStatement
generateMySQLStreamQueryPreparedStatement(final Connection connection, final
String sql) throws SQLException {
+ PreparedStatement result = connection.prepareStatement(sql,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
+ result.setFetchSize(Integer.MIN_VALUE);
+ return result;
+ }
+
+ /**
+ * Generate PostgreSQL stream query prepared statement.
+ *
+ * @param connection connection
+ * @param sql sql
+ * @param fetchSize fetch size
+ * @return stream query prepared statement
+ * @throws SQLException SQL exception
+ */
+ public static PreparedStatement
generatePostgreSQLStreamQueryPreparedStatement(final Connection connection,
final String sql, final int fetchSize) throws SQLException {
+ PreparedStatement result = connection.prepareStatement(sql,
ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
ResultSet.CLOSE_CURSORS_AT_COMMIT);
+ connection.setAutoCommit(false);
+ result.setFetchSize(fetchSize);
Review Comment:
If `fetchSize` is not required for streaming query, then it's better not set
fetchSize here
##########
kernel/data-pipeline/core/src/main/java/org/apache/shardingsphere/data/pipeline/core/check/consistency/algorithm/DataMatchDataConsistencyCalculateAlgorithm.java:
##########
@@ -154,9 +158,18 @@ private CalculationContext createCalculationContext(final
DataConsistencyCalcula
private void fulfillCalculationContext(final CalculationContext
calculationContext, final DataConsistencyCalculateParameter param) throws
SQLException {
String sql = getQuerySQL(param);
- PreparedStatement preparedStatement =
setCurrentStatement(calculationContext.getConnection().prepareStatement(sql));
+ DatabaseType databaseType =
TypedSPILoader.getService(DatabaseType.class, param.getDatabaseType());
+ PreparedStatement preparedStatement;
+ if (databaseType instanceof MySQLDatabaseType) {
+ preparedStatement =
setCurrentStatement(JDBCStreamQueryUtil.generateMySQLStreamQueryPreparedStatement(calculationContext.getConnection(),
sql));
+ } else if (databaseType instanceof PostgreSQLDatabaseType ||
databaseType instanceof OpenGaussDatabaseType) {
+ preparedStatement =
setCurrentStatement(JDBCStreamQueryUtil.generatePostgreSQLStreamQueryPreparedStatement(calculationContext.getConnection(),
sql, chunkSize));
+ } else {
+ log.warn("not support {} streaming query now, pay attention to
memory usage", databaseType.getType());
+ preparedStatement =
setCurrentStatement(calculationContext.getConnection().prepareStatement(sql));
+ preparedStatement.setFetchSize(chunkSize);
+ }
Review Comment:
Could we extract this code block into `JDBCStreamQueryUtil`? Since there's
the same code block in `InventoryDumper`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]