Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HBASE-23173 ArrayIndexOutOfBoundsException in BaseLoadBalancer$Cluste… #723

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -863,19 +863,6 @@ void regionMoved(int region, int oldServer, int newServer) {
}
}

int[] removeRegion(int[] regions, int regionIndex) {
//TODO: this maybe costly. Consider using linked lists
int[] newRegions = new int[regions.length - 1];
int i = 0;
for (i = 0; i < regions.length; i++) {
if (regions[i] == regionIndex) {
break;
}
newRegions[i] = regions[i];
}
System.arraycopy(regions, i+1, newRegions, i, newRegions.length - i);
return newRegions;
}

int[] addRegion(int[] regions, int regionIndex) {
int[] newRegions = new int[regions.length + 1];
Expand Down Expand Up @@ -1646,6 +1633,28 @@ protected Map<ServerName, List<RegionInfo>> getRegionAssignmentsByServer(
}
}

/**
* Returns a new array with the region at <code>regionIndex</code>
* removed (unless regionIndex > regions.length and then we just
* return <code>regions</code>).
*/
static int[] removeRegion(int[] regions, int regionIndex) {
if (regionIndex >= regions.length) {
return regions;
}
//TODO: this maybe costly. Consider using linked lists
int[] newRegions = new int[regions.length - 1];
int i = 0;
for (; i < regions.length; i++) {
if (regions[i] == regionIndex) {
break;
}
newRegions[i] = regions[i];
}
System.arraycopy(regions, i+1, newRegions, i, newRegions.length - i);
return newRegions;
}

@Override
public void onConfigurationChange(Configuration conf) {
}
Expand Down
Expand Up @@ -566,4 +566,26 @@ public void testClusterRegionLocations() {
assertEquals(1, cluster.regionLocations[r43].length);
assertEquals(-1, cluster.regionLocations[r43][0]);
}

@Test
public void testRemoveRegion() {
int [] regions = new int [] {0, 1, 2};
int [] result = BaseLoadBalancer.removeRegion(regions, 0);
assertTrue(result.length == 2);
assertTrue(result[0] == 1);
assertTrue(result[1] == 2);
result = BaseLoadBalancer.removeRegion(regions, 1);
assertTrue(result.length == 2);
assertTrue(result[0] == 0);
assertTrue(result[1] == 2);
result = BaseLoadBalancer.removeRegion(regions, 2);
assertTrue(result.length == 2);
assertTrue(result[0] == 0);
assertTrue(result[1] == 1);
result = BaseLoadBalancer.removeRegion(regions, regions.length);
assertTrue(result.length == 3);
assertTrue(result[0] == 0);
assertTrue(result[1] == 1);
assertTrue(result[2] == 2);
}
}