You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/05/07 11:20:31 UTC

[GitHub] [shardingsphere] sandynz commented on a diff in pull request #17403: Add MySQL unsigned int type at Scaling IT test

sandynz commented on code in PR #17403:
URL: https://github.com/apache/shardingsphere/pull/17403#discussion_r867340121


##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLIncrementTaskRunnable.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.integration.data.pipeline.cases.mysql;
+
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.shardingsphere.integration.data.pipeline.cases.command.CommonSQLCommand;
+import org.apache.shardingsphere.integration.data.pipeline.util.TableCrudUtil;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.sql.SQLException;
+import java.util.LinkedList;
+import java.util.List;
+
+@Slf4j
+@AllArgsConstructor
+public final class MySQLIncrementTaskRunnable implements Runnable {
+    
+    private static final String INSERT_ORDER = "INSERT INTO t_order (id,order_id,user_id) VALUES (?, ?, ?)";
+    
+    private static final String INSERT_ORDER_ITEM = "INSERT INTO t_order_item(item_id,order_id,user_id,status) VALUES(?,?,?,?)";
+    
+    private static final String UPDATE_ORDER_BY_ID = "UPDATE t_order SET t_varchar = 'update',t_unsigned_int = %s WHERE id = %s";
+    
+    private static final String UPDATE_ORDER_ITEM_BY_ID = "UPDATE t_order_item SET status = 'changed' WHERE item_id = %s";
+    
+    private final JdbcTemplate jdbcTemplate;
+    
+    private final CommonSQLCommand commonSQLCommand;
+    
+    @Override
+    public void run() {
+        int executeCount = 0;
+        List<Long> newPrimaryKeys = new LinkedList<>();
+        try {
+            while (!Thread.currentThread().isInterrupted() && executeCount < 20) {
+                newPrimaryKeys.add(insertOrderAndOrderItem());
+                if (newPrimaryKeys.size() % 2 == 0) {

Review Comment:
   Constant could be put at first.



##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/postgresql/PostgreSQLIncrementTaskRunnable.java:
##########
@@ -30,7 +30,15 @@
 
 @Slf4j
 @AllArgsConstructor
-public final class IncrementTaskRunnable implements Runnable {
+public final class PostgreSQLIncrementTaskRunnable implements Runnable {
+    
+    private static final String UPDATE_ORDER_BY_ID = "UPDATE t_order SET t_varchar = 'update' WHERE id = %s";
+    
+    private static final String UPDATE_ORDER_ITEM_BY_ID = "UPDATE t_order_item SET status = 'changed' WHERE item_id = %s";
+    
+    private static final String INSERT_ORDER = "INSERT INTO t_order ( id, order_id, user_id) VALUES (?, ?, ?)";
+    
+    private static final String INSERT_ORDER_ITEM = "INSERT INTO t_order_item (item_id, order_id, user_id, status) VALUES(?,?,?,?)";

Review Comment:
   1, It's better to extract DAO for better code reuse.
   
   2, It's better to update column to dynamic value, e.g. text + now().



##########
shardingsphere-test/shardingsphere-integration-test/shardingsphere-integration-test-scaling/src/test/java/org/apache/shardingsphere/integration/data/pipeline/cases/mysql/MySQLIncrementTaskRunnable.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.integration.data.pipeline.cases.mysql;
+
+import lombok.AllArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.tuple.Pair;
+import org.apache.shardingsphere.integration.data.pipeline.cases.command.CommonSQLCommand;
+import org.apache.shardingsphere.integration.data.pipeline.util.TableCrudUtil;
+import org.springframework.jdbc.core.JdbcTemplate;
+
+import java.sql.SQLException;
+import java.util.LinkedList;
+import java.util.List;
+
+@Slf4j
+@AllArgsConstructor
+public final class MySQLIncrementTaskRunnable implements Runnable {
+    
+    private static final String INSERT_ORDER = "INSERT INTO t_order (id,order_id,user_id) VALUES (?, ?, ?)";
+    
+    private static final String INSERT_ORDER_ITEM = "INSERT INTO t_order_item(item_id,order_id,user_id,status) VALUES(?,?,?,?)";
+    
+    private static final String UPDATE_ORDER_BY_ID = "UPDATE t_order SET t_varchar = 'update',t_unsigned_int = %s WHERE id = %s";
+    
+    private static final String UPDATE_ORDER_ITEM_BY_ID = "UPDATE t_order_item SET status = 'changed' WHERE item_id = %s";
+    
+    private final JdbcTemplate jdbcTemplate;
+    
+    private final CommonSQLCommand commonSQLCommand;
+    
+    @Override
+    public void run() {
+        int executeCount = 0;
+        List<Long> newPrimaryKeys = new LinkedList<>();
+        try {
+            while (!Thread.currentThread().isInterrupted() && executeCount < 20) {
+                newPrimaryKeys.add(insertOrderAndOrderItem());
+                if (newPrimaryKeys.size() % 2 == 0) {
+                    deleteOrderAndOrderItem(newPrimaryKeys.get(newPrimaryKeys.size() - 1));
+                } else {
+                    updateOrderAndOrderItem(newPrimaryKeys.get(newPrimaryKeys.size() - 1));
+                }
+                executeCount++;
+                log.info("Increment task runnable execute successfully.");
+            }
+        } catch (final SQLException ex) {
+            log.error("IncrementTaskThread error", ex);
+            throw new RuntimeException(ex);
+        }
+    }
+    
+    private long insertOrderAndOrderItem() throws SQLException {
+        Pair<Object[], Object[]> dataPair = TableCrudUtil.generateSimpleInsertData();
+        jdbcTemplate.update(INSERT_ORDER, dataPair.getLeft());
+        jdbcTemplate.update(INSERT_ORDER_ITEM, dataPair.getRight());
+        return Long.parseLong(dataPair.getLeft()[0].toString());
+    }
+    
+    private void updateOrderAndOrderItem(final long primaryKey) throws SQLException {
+        jdbcTemplate.execute(String.format(UPDATE_ORDER_BY_ID, "null", primaryKey));
+        jdbcTemplate.execute(String.format(UPDATE_ORDER_BY_ID, "100", primaryKey));

Review Comment:
   It's better use parepared statement later.



-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org