Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -812,10 +812,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 @@ -263,7 +263,7 @@ public void mergeRegions(RegionInfo child, RegionInfo [] parents, ServerName ser
throws IOException {
TableDescriptor htd = getDescriptor(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,50 @@ 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[20][];
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(), 20);

for (int c = 0; c < 19; c++) {
assertTrue(Bytes.compareTo(mergeParentRegions.get(c).getStartKey(), mergeParentRegions.get(c+1).getStartKey())<0);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace:end of line

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace:end of line

}
}