You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2021/09/10 18:16:30 UTC

[GitHub] [skywalking] sonatype-lift[bot] commented on a change in pull request #7691: tidb write by batch sql ,improve write speed.

sonatype-lift[bot] commented on a change in pull request #7691:
URL: https://github.com/apache/skywalking/pull/7691#discussion_r706380764



##########
File path: oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2BatchDAO.java
##########
@@ -81,6 +92,36 @@ public void flush(List<PrepareRequest> prepareRequests) {
         }
     }
 
+    private void executeSql(List<PrepareRequest> prepareRequests, int maxBatchSqlSize) {
+        if (log.isDebugEnabled()) {
+            log.debug("execute sql batch. data size:{}", prepareRequests.size());
+        }
+        Map<String, List<PrepareRequest>> batchRequestMap = new HashMap<>();
+        for (PrepareRequest prepareRequest : prepareRequests) {
+            SQLExecutor sqlExecutor = (SQLExecutor) prepareRequest;
+            if (batchRequestMap.get(sqlExecutor.getSql()) == null) {
+                List<PrepareRequest> prepareRequestList = new ArrayList<>();
+                batchRequestMap.put(sqlExecutor.getSql(), prepareRequestList);
+            }
+            batchRequestMap.get(sqlExecutor.getSql()).add(prepareRequest);
+        }
+        try (Connection connection = h2Client.getConnection()) {
+            try {
+                for (String key : batchRequestMap.keySet()) {
+                    BatchSQLExecutor batchSQLExecutor = new BatchSQLExecutor(key, batchRequestMap.get(key));

Review comment:
       *INEFFICIENT_KEYSET_ITERATOR:*  Accessing a value using a key that was retrieved from a `keySet` iterator. It is more efficient to use an iterator on the `entrySet` of the map, avoiding the extra `HashMap.get(key)` lookup.
   (at-me [in a reply](https://help.sonatype.com/lift) with `help` or `ignore`)

##########
File path: oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2BatchDAO.java
##########
@@ -81,6 +92,36 @@ public void flush(List<PrepareRequest> prepareRequests) {
         }
     }
 
+    private void executeSql(List<PrepareRequest> prepareRequests, int maxBatchSqlSize) {
+        if (log.isDebugEnabled()) {
+            log.debug("execute sql batch. data size:{}", prepareRequests.size());
+        }
+        Map<String, List<PrepareRequest>> batchRequestMap = new HashMap<>();
+        for (PrepareRequest prepareRequest : prepareRequests) {
+            SQLExecutor sqlExecutor = (SQLExecutor) prepareRequest;
+            if (batchRequestMap.get(sqlExecutor.getSql()) == null) {
+                List<PrepareRequest> prepareRequestList = new ArrayList<>();
+                batchRequestMap.put(sqlExecutor.getSql(), prepareRequestList);
+            }
+            batchRequestMap.get(sqlExecutor.getSql()).add(prepareRequest);

Review comment:
       *NULL_DEREFERENCE:*  object returned by `batchRequestMap.get(sqlExecutor.getSql())` could be null and is dereferenced at line 106.
   (at-me [in a reply](https://help.sonatype.com/lift) with `help` or `ignore`)




-- 
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@skywalking.apache.org

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