镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package org.apache.hadoop.hbase.rsgroup;

import com.google.errorprone.annotations.RestrictedApi;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.io.IOException;
import java.util.ArrayList;
Expand Down Expand Up @@ -99,6 +100,44 @@ public class RSGroupBasedLoadBalancer implements LoadBalancer {

private volatile boolean fallbackEnabled = false;

@RestrictedApi(explanation = "Should only be called in tests", link = "",
allowedOnPath = ".*/src/test/.*")
public void setFallbackEnabledForTest(boolean enabled) {
this.fallbackEnabled = enabled;
}

// Test-only call-tracking flags, set true whenever the corresponding assignment method below is
// invoked. Reset via resetAssignmentCallFlagsForTest() before the operation under test.
private volatile boolean roundRobinAssignmentInvoked = false;
private volatile boolean retainAssignmentInvoked = false;
private volatile boolean randomAssignmentInvoked = false;

@RestrictedApi(explanation = "Should only be called in tests", link = "",
allowedOnPath = ".*/src/test/.*")
public boolean isRoundRobinAssignmentInvoked() {
return roundRobinAssignmentInvoked;
}
Comment on lines +103 to +119

@RestrictedApi(explanation = "Should only be called in tests", link = "",
allowedOnPath = ".*/src/test/.*")
public boolean isRetainAssignmentInvoked() {
return retainAssignmentInvoked;
}

@RestrictedApi(explanation = "Should only be called in tests", link = "",
allowedOnPath = ".*/src/test/.*")
public boolean isRandomAssignmentInvoked() {
return randomAssignmentInvoked;
}

@RestrictedApi(explanation = "Should only be called in tests", link = "",
allowedOnPath = ".*/src/test/.*")
public void resetAssignmentCallFlagsForTest() {
roundRobinAssignmentInvoked = false;
retainAssignmentInvoked = false;
randomAssignmentInvoked = false;
}
Comment on lines +133 to +139

/**
* Used by reflection in {@link org.apache.hadoop.hbase.master.balancer.LoadBalancerFactory}.
*/
Expand Down Expand Up @@ -180,6 +219,7 @@ public synchronized List<RegionPlan> balanceCluster(
@NonNull
public Map<ServerName, List<RegionInfo>> roundRobinAssignment(List<RegionInfo> regions,
List<ServerName> servers) throws IOException {
roundRobinAssignmentInvoked = true;
Map<ServerName, List<RegionInfo>> assignments = Maps.newHashMap();
List<Pair<List<RegionInfo>, List<ServerName>>> pairs =
generateGroupAssignments(regions, servers);
Expand All @@ -196,6 +236,7 @@ public Map<ServerName, List<RegionInfo>> roundRobinAssignment(List<RegionInfo> r
@NonNull
public Map<ServerName, List<RegionInfo>> retainAssignment(Map<RegionInfo, ServerName> regions,
List<ServerName> servers) throws HBaseIOException {
retainAssignmentInvoked = true;
try {
Map<ServerName, List<RegionInfo>> assignments = new TreeMap<>();
List<Pair<List<RegionInfo>, List<ServerName>>> pairs =
Expand All @@ -218,6 +259,7 @@ public Map<ServerName, List<RegionInfo>> retainAssignment(Map<RegionInfo, Server
@Override
public ServerName randomAssignment(RegionInfo region, List<ServerName> servers)
throws IOException {
randomAssignmentInvoked = true;
List<Pair<List<RegionInfo>, List<ServerName>>> pairs =
generateGroupAssignments(Lists.newArrayList(region), servers);
List<ServerName> filteredServers = pairs.iterator().next().getSecond();
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package org.apache.hadoop.hbase.rsgroup;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
Expand Down Expand Up @@ -207,6 +209,11 @@ protected final RSGroupInfo addGroup(String groupName, int serverCount)
}
ADMIN.moveServersToRSGroup(set, groupName);
RSGroupInfo result = ADMIN.getRSGroup(groupName);
assertEquals(set, result.getServers());
Set<Address> remainingDefaultServers = ADMIN.getRSGroup(RSGroupInfo.DEFAULT_GROUP).getServers();
for (Address server : set) {
assertFalse(remainingDefaultServers.contains(server));
}
return result;
}

Expand All @@ -226,8 +233,29 @@ protected final void removeGroup(String groupName) throws IOException {
}
}
RSGroupInfo groupInfo = ADMIN.getRSGroup(groupName);
ADMIN.moveServersToRSGroup(groupInfo.getServers(), RSGroupInfo.DEFAULT_GROUP);
Set<Address> servers = groupInfo.getServers();
ADMIN.moveServersToRSGroup(servers, RSGroupInfo.DEFAULT_GROUP);
ADMIN.removeRSGroup(groupName);
assertFalse(ADMIN.listRSGroups().stream().anyMatch(g -> g.getName().equals(groupName)));
Set<Address> onlineServers = new HashSet<>();
for (ServerName sn : MASTER.getServerManager().getOnlineServersList()) {
onlineServers.add(sn.getAddress());
}
RSGroupInfo defaultInfo = ADMIN.getRSGroup(RSGroupInfo.DEFAULT_GROUP);
for (Address server : servers) {
// moveServersToRSGroup()-to-'default' silently drops servers that are no longer online
// (see RSGroupInfoManagerImpl#moveServers), so only online servers are guaranteed to land
// in 'default'; an offline server's former group membership is simply dropped.
if (onlineServers.contains(server)) {
assertTrue(defaultInfo.getServers().contains(server));
}
}
for (TableName table : tables) {
// ADMIN.getRSGroup(String)/listRSGroups() do not resolve table membership from the
// TableDescriptor's RegionServerGroup attribute (only ADMIN.getRSGroup(TableName) does),
// so look up each table's group individually rather than via defaultInfo.getTables().
assertEquals(RSGroupInfo.DEFAULT_GROUP, ADMIN.getRSGroup(table).getName());
}
}

protected final void deleteTableIfNecessary() throws IOException {
Expand Down
Loading
Loading