liuml07 commented on a change in pull request #1523: HBASE-24195 :
Admin.getRegionServers() should return live servers exc…
URL: https://github.com/apache/hbase/pull/1523#discussion_r409296301
##########
File path: hbase-client/src/main/java/org/apache/hadoop/hbase/client/Admin.java
##########
@@ -1064,7 +1067,31 @@ default ServerName getMaster() throws IOException {
* @throws IOException if a remote or network exception occurs
*/
default Collection<ServerName> getRegionServers() throws IOException {
- return getClusterMetrics(EnumSet.of(Option.SERVERS_NAME)).getServersName();
+ return getRegionServers(false);
+ }
+
+ /**
+ * Retrieve all current live region servers including decommissioned
+ * if excludeDecommissionedRS is false, else non-decommissioned ones only
+ *
+ * @param excludeDecommissionedRS should we exclude decommissioned RS nodes
+ * @return all current live region servers including/excluding
decommissioned hosts
+ * @throws IOException if a remote or network exception occurs
+ */
+ default Collection<ServerName> getRegionServers(boolean
excludeDecommissionedRS)
+ throws IOException {
+ List<ServerName> allServers =
+ getClusterMetrics(EnumSet.of(Option.SERVERS_NAME)).getServersName();
+ if (!excludeDecommissionedRS) {
+ return allServers;
+ }
+ List<ServerName> decommissionedRegionServers =
listDecommissionedRegionServers();
+ if (CollectionUtils.isNotEmpty(decommissionedRegionServers)) {
Review comment:
```
if (CollectionUtils.isNotEmpty(decommissionedRegionServers)) {
allServers = new ArrayList<>(allServers);
allServers.removeIf(decommissionedRegionServers::contains);
return Collections.unmodifiableList(allServers);
}
return allServers;
```
to
```
return allServers.stream()
.filter(s -> !decommissionedRegionServers.contains(s))
.collect(ImmutableList.toImmutableList());
```
I think this will save one time full copy (previous code copy twice, and
this copies just once). Need to confirm.
----------------------------------------------------------------
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:
[email protected]
With regards,
Apache Git Services