HBASE-26015 Should implement getRegionServers(boolean) method in Asyn… (#3406)
Signed-off-by: Duo Zhang <zhangduo@apache.org>
This commit is contained in:
parent
bffe8957c5
commit
e6eb65733a
|
@ -55,6 +55,7 @@ import org.apache.hadoop.hbase.security.access.UserPermission;
|
||||||
import org.apache.hadoop.hbase.util.Pair;
|
import org.apache.hadoop.hbase.util.Pair;
|
||||||
import org.apache.yetus.audience.InterfaceAudience;
|
import org.apache.yetus.audience.InterfaceAudience;
|
||||||
|
|
||||||
|
import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableList;
|
||||||
import org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel;
|
import org.apache.hbase.thirdparty.com.google.protobuf.RpcChannel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1084,6 +1085,32 @@ public interface AsyncAdmin {
|
||||||
.thenApply(ClusterMetrics::getServersName);
|
.thenApply(ClusterMetrics::getServersName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default CompletableFuture<Collection<ServerName>> getRegionServers(
|
||||||
|
boolean excludeDecommissionedRS) {
|
||||||
|
CompletableFuture<Collection<ServerName>> future = new CompletableFuture<>();
|
||||||
|
addListener(
|
||||||
|
getClusterMetrics(EnumSet.of(Option.SERVERS_NAME)).thenApply(ClusterMetrics::getServersName),
|
||||||
|
(allServers, err) -> {
|
||||||
|
if (err != null) {
|
||||||
|
future.completeExceptionally(err);
|
||||||
|
} else {
|
||||||
|
if (!excludeDecommissionedRS) {
|
||||||
|
future.complete(allServers);
|
||||||
|
} else {
|
||||||
|
addListener(listDecommissionedRegionServers(), (decomServers, decomErr) -> {
|
||||||
|
if (decomErr != null) {
|
||||||
|
future.completeExceptionally(decomErr);
|
||||||
|
} else {
|
||||||
|
future.complete(allServers.stream().filter(s -> !decomServers.contains(s))
|
||||||
|
.collect(ImmutableList.toImmutableList()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return future;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return a list of master coprocessors wrapped by {@link CompletableFuture}
|
* @return a list of master coprocessors wrapped by {@link CompletableFuture}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -262,6 +263,26 @@ public class TestAsyncClusterAdminApi extends TestAsyncAdminBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetRegionServers() throws Exception{
|
||||||
|
List<ServerName> serverNames = new ArrayList<>(admin.getRegionServers(true).get());
|
||||||
|
assertEquals(2, serverNames.size());
|
||||||
|
|
||||||
|
List<ServerName> serversToDecom = new ArrayList<>();
|
||||||
|
ServerName serverToDecommission = serverNames.get(0);
|
||||||
|
|
||||||
|
serversToDecom.add(serverToDecommission);
|
||||||
|
admin.decommissionRegionServers(serversToDecom, false).join();
|
||||||
|
|
||||||
|
assertEquals(1, admin.getRegionServers(true).get().size());
|
||||||
|
assertEquals(2, admin.getRegionServers(false).get().size());
|
||||||
|
|
||||||
|
admin.recommissionRegionServer(serverToDecommission, Collections.emptyList()).join();
|
||||||
|
|
||||||
|
assertEquals(2, admin.getRegionServers(true).get().size());
|
||||||
|
assertEquals(2, admin.getRegionServers(false).get().size());
|
||||||
|
}
|
||||||
|
|
||||||
private void compareRegionLoads(Collection<RegionMetrics> regionLoadCluster,
|
private void compareRegionLoads(Collection<RegionMetrics> regionLoadCluster,
|
||||||
Collection<RegionMetrics> regionLoads) {
|
Collection<RegionMetrics> regionLoads) {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue