You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/11/16 11:30:10 UTC

[GitHub] [hbase] wchevreuil commented on a change in pull request #828: HBASE-23102: Improper Usage of Map putIfAbsent

wchevreuil commented on a change in pull request #828: HBASE-23102: Improper Usage of Map putIfAbsent
URL: https://github.com/apache/hbase/pull/828#discussion_r347087338
 
 

 ##########
 File path: hbase-rsgroup/src/main/java/org/apache/hadoop/hbase/rsgroup/RSGroupAdminServer.java
 ##########
 @@ -575,32 +575,36 @@ public void removeServers(Set<Address> servers) throws IOException {
     Map<TableName, Map<ServerName, List<RegionInfo>>> result = Maps.newHashMap();
     RSGroupInfo rsGroupInfo = getRSGroupInfo(groupName);
     Map<TableName, Map<ServerName, List<RegionInfo>>> assignments = Maps.newHashMap();
-    for(Map.Entry<RegionInfo, ServerName> entry:
+    for (Map.Entry<RegionInfo, ServerName> entry:
         master.getAssignmentManager().getRegionStates().getRegionAssignments().entrySet()) {
       TableName currTable = entry.getKey().getTable();
       ServerName currServer = entry.getValue();
       RegionInfo currRegion = entry.getKey();
       if (rsGroupInfo.getTables().contains(currTable)) {
-        assignments.putIfAbsent(currTable, new HashMap<>());
-        assignments.get(currTable).putIfAbsent(currServer, new ArrayList<>());
-        assignments.get(currTable).get(currServer).add(currRegion);
+        assignments.computeIfAbsent(currTable, key -> new HashMap<>())
+            .computeIfAbsent(currServer, key -> new ArrayList<>())
+            .add(currRegion);
       }
     }
 
     Map<ServerName, List<RegionInfo>> serverMap = Maps.newHashMap();
-    for(ServerName serverName: master.getServerManager().getOnlineServers().keySet()) {
-      if(rsGroupInfo.getServers().contains(serverName.getAddress())) {
+    for (ServerName serverName: master.getServerManager().getOnlineServers().keySet()) {
 
 Review comment:
   These are more of style changes, not related to the actual jira issue. Let's address it in a separate issue, and keep this one focused on replacing _putIfAbsent_ by _computeIfAbsent_, where applicable.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services