You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uniffle.apache.org by zu...@apache.org on 2022/09/27 05:03:00 UTC

[incubator-uniffle] branch master updated: [MINOR] Fix inefficient map iteration (#245)

This is an automated email from the ASF dual-hosted git repository.

zuston pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-uniffle.git


The following commit(s) were added to refs/heads/master by this push:
     new 0645ebed [MINOR] Fix inefficient map iteration (#245)
0645ebed is described below

commit 0645ebedbc137c8ce420a49cb0802e5864f4d9b2
Author: Kaijie Chen <ck...@apache.org>
AuthorDate: Tue Sep 27 13:02:55 2022 +0800

    [MINOR] Fix inefficient map iteration (#245)
    
    ### What changes were proposed in this pull request?
    
    Iterate Map by `Map.entrySet()` instead of `Map.keySet()` + `Map.get(key)`.
    
    ### Why are the changes needed?
    
    It's more efficient.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    CI.
---
 .../coordinator/LowestIOSampleCostSelectStorageStrategy.java        | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/coordinator/src/main/java/org/apache/uniffle/coordinator/LowestIOSampleCostSelectStorageStrategy.java b/coordinator/src/main/java/org/apache/uniffle/coordinator/LowestIOSampleCostSelectStorageStrategy.java
index f55e04ce..291ce43d 100644
--- a/coordinator/src/main/java/org/apache/uniffle/coordinator/LowestIOSampleCostSelectStorageStrategy.java
+++ b/coordinator/src/main/java/org/apache/uniffle/coordinator/LowestIOSampleCostSelectStorageStrategy.java
@@ -86,7 +86,9 @@ public class LowestIOSampleCostSelectStorageStrategy implements SelectStorageStr
 
   public void checkReadAndWrite() {
     if (remoteStoragePathRankValue.size() > 1) {
-      for (String path : remoteStoragePathRankValue.keySet()) {
+      for (Map.Entry<String, RankValue> entry : remoteStoragePathRankValue.entrySet()) {
+        final String path = entry.getKey();
+        final RankValue rankValue = entry.getValue();
         Path remotePath = new Path(path);
         Path testPath = new Path(path + "/rssTest");
         long startWriteTime = System.currentTimeMillis();
@@ -107,7 +109,6 @@ public class LowestIOSampleCostSelectStorageStrategy implements SelectStorageStr
                 if (hasReadBytes < fileSize) {
                   for (int i = 0; i < readBytes; i++) {
                     if (data[hasReadBytes + i] != readData[i]) {
-                      RankValue rankValue = remoteStoragePathRankValue.get(path);
                       remoteStoragePathRankValue.put(path, new RankValue(Long.MAX_VALUE, rankValue.getAppNum().get()));
                     }
                   }
@@ -118,7 +119,6 @@ public class LowestIOSampleCostSelectStorageStrategy implements SelectStorageStr
           }
         } catch (Exception e) {
           LOG.error("Storage read and write error, we will not use this remote path {}.", path, e);
-          RankValue rankValue = remoteStoragePathRankValue.get(path);
           remoteStoragePathRankValue.put(path, new RankValue(Long.MAX_VALUE, rankValue.getAppNum().get()));
         } finally {
           sortPathByRankValue(path, testPath, startWriteTime);