Skip to content

Commit

Permalink
HBASE-22941 merge operation returns parent regions in random order (a…
Browse files Browse the repository at this point in the history
…pache#556)

* HBASE-22941 merge operation returns parent regions in random order

store and return the merge parent regions in ascending order

remove left over check for exactly two merged regions

add unit test

* use SortedMap type to emphasise that the Map is sorted.

* use regionCount consistently and checkstyle fixes

* Delete tests that expect multiregion merges to fail.

Signed-off-by: stack <[email protected]>
(cherry picked from commit 047aad1)

Change-Id: I081888b3205db4c34dc5df466edcdf34aae3cd76
  • Loading branch information
stoty authored and Jenkins committed Aug 29, 2019
1 parent 86ba446 commit 4b5c6d7
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -805,10 +805,6 @@ public MergeTableRegionsResponse mergeTableRegions(

RegionStates regionStates = master.getAssignmentManager().getRegionStates();

if (request.getRegionCount() != 2) {
throw new ServiceException(new DoNotRetryIOException(
"Only support merging 2 regions but " + request.getRegionCount() + " region passed"));
}
RegionInfo[] regionsToMerge = new RegionInfo[request.getRegionCount()];
for (int i = 0; i < request.getRegionCount(); i++) {
final byte[] encodedNameOfRegion = request.getRegion(i).getValue().toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;

import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellBuilderFactory;
Expand Down Expand Up @@ -246,7 +246,7 @@ public void mergeRegions(RegionInfo child, RegionInfo [] parents, ServerName ser
throws IOException {
TableDescriptor htd = getTableDescriptor(child.getTable());
boolean globalScope = htd.hasGlobalReplicationScope();
Map<RegionInfo, Long> parentSeqNums = new HashMap<>(parents.length);
SortedMap<RegionInfo, Long> parentSeqNums = new TreeMap<>();
for (RegionInfo ri: parents) {
parentSeqNums.put(ri, globalScope? getOpenSeqNumForParentRegion(ri): -1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.util.List;
import java.util.concurrent.TimeUnit;
import org.apache.hadoop.hbase.Waiter.ExplainingPredicate;
import org.apache.hadoop.hbase.client.AsyncConnection;
Expand Down Expand Up @@ -104,4 +106,51 @@ public String explainFailure() throws Exception {
.getRegionLocation(Bytes.toBytes(1), true).get().getServerName());
}
}

@Test
public void testMergeRegionOrder() throws Exception {

int regionCount= 20;

TableName tableName = TableName.valueOf("MergeRegionOrder");
byte[] family = Bytes.toBytes("CF");
TableDescriptor td = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build();

byte[][] splitKeys = new byte[regionCount-1][];

for (int c = 0; c < regionCount-1; c++) {
splitKeys[c] = Bytes.toBytes(c+1 * 1000);
}

UTIL.getAdmin().createTable(td, splitKeys);
UTIL.waitTableAvailable(tableName);

List<RegionInfo> regions = UTIL.getAdmin().getRegions(tableName);

byte[][] regionNames = new byte[regionCount][];
for (int c = 0; c < regionCount; c++) {
regionNames[c] = regions.get(c).getRegionName();
}

UTIL.getAdmin().mergeRegionsAsync(regionNames, false).get(60, TimeUnit.SECONDS);

List<RegionInfo> mergedRegions =
MetaTableAccessor.getTableRegions(UTIL.getConnection(), tableName);

assertEquals(1, mergedRegions.size());

RegionInfo mergedRegion = mergedRegions.get(0);

List<RegionInfo> mergeParentRegions = MetaTableAccessor.getMergeRegions(UTIL.getConnection(),
mergedRegion.getEncodedNameAsBytes());

assertEquals(mergeParentRegions.size(), regionCount);

for (int c = 0; c < regionCount-1; c++) {
assertTrue(Bytes.compareTo(
mergeParentRegions.get(c).getStartKey(),
mergeParentRegions.get(c+1).getStartKey()) < 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor;
Expand Down Expand Up @@ -1467,15 +1466,6 @@ public void testMergeRegionsInvalidRegionCount()
} catch (IllegalArgumentException e) {
// expected
}
// 3
try {
admin.mergeRegionsAsync(
tableRegions.stream().map(RegionInfo::getEncodedNameAsBytes).toArray(byte[][]::new),
false).get();
fail();
} catch (DoNotRetryIOException e) {
// expected
}
} finally {
admin.disableTable(tableName);
admin.deleteTable(tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
import org.apache.hadoop.hbase.AsyncMetaTableAccessor;
import org.apache.hadoop.hbase.DoNotRetryIOException;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionLocation;
Expand Down Expand Up @@ -205,16 +204,6 @@ public void testMergeRegionsInvalidRegionCount() throws Exception {
// expected
assertThat(e.getCause(), instanceOf(IllegalArgumentException.class));
}
// 3
try {
admin.mergeRegions(
regions.stream().map(RegionInfo::getEncodedNameAsBytes).collect(Collectors.toList()), false)
.get();
fail();
} catch (ExecutionException e) {
// expected
assertThat(e.getCause(), instanceOf(DoNotRetryIOException.class));
}
}

@Test
Expand Down

0 comments on commit 4b5c6d7

Please sign in to comment.