HBASE-8787 Merged region endkey is incorrect if one region has null endkey

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1495745 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
jxiang 2013-06-22 15:39:09 +00:00
parent acfe2f9fd2
commit 6a1ef5c144
2 changed files with 40 additions and 4 deletions

View File

@ -410,10 +410,9 @@ public class RegionMergeTransaction {
startKey = b.getStartKey();
}
// Choose the bigger as end key
if (a.getComparator().matchingRows(a.getEndKey(), 0, a.getEndKey().length,
HConstants.EMPTY_BYTE_ARRAY, 0, HConstants.EMPTY_BYTE_ARRAY.length)
|| a.getComparator().compareRows(a.getEndKey(), 0,
a.getEndKey().length, b.getEndKey(), 0, b.getEndKey().length) > 0) {
if (Bytes.equals(a.getEndKey(), HConstants.EMPTY_BYTE_ARRAY)
|| (!Bytes.equals(b.getEndKey(), HConstants.EMPTY_BYTE_ARRAY)
&& Bytes.compareTo(a.getEndKey(), b.getEndKey()) > 0)) {
endKey = a.getEndKey();
} else {
endKey = b.getEndKey();

View File

@ -344,6 +344,43 @@ public class TestRegionMergeTransaction {
assertTrue(TEST_UTIL.getTestFileSystem().exists(mergedRegionDir));
}
@Test
public void testMeregedRegionBoundary() {
byte[] tableName = Bytes.toBytes("testMeregedRegionBoundary");
byte[] a = Bytes.toBytes("a");
byte[] b = Bytes.toBytes("b");
byte[] z = Bytes.toBytes("z");
HRegionInfo r1 = new HRegionInfo(tableName);
HRegionInfo r2 = new HRegionInfo(tableName, a, z);
HRegionInfo m = RegionMergeTransaction.getMergedRegionInfo(r1, r2);
assertTrue(Bytes.equals(m.getStartKey(), r1.getStartKey())
&& Bytes.equals(m.getEndKey(), r1.getEndKey()));
r1 = new HRegionInfo(tableName, null, a);
r2 = new HRegionInfo(tableName, a, z);
m = RegionMergeTransaction.getMergedRegionInfo(r1, r2);
assertTrue(Bytes.equals(m.getStartKey(), r1.getStartKey())
&& Bytes.equals(m.getEndKey(), r2.getEndKey()));
r1 = new HRegionInfo(tableName, null, a);
r2 = new HRegionInfo(tableName, z, null);
m = RegionMergeTransaction.getMergedRegionInfo(r1, r2);
assertTrue(Bytes.equals(m.getStartKey(), r1.getStartKey())
&& Bytes.equals(m.getEndKey(), r2.getEndKey()));
r1 = new HRegionInfo(tableName, a, z);
r2 = new HRegionInfo(tableName, z, null);
m = RegionMergeTransaction.getMergedRegionInfo(r1, r2);
assertTrue(Bytes.equals(m.getStartKey(), r1.getStartKey())
&& Bytes.equals(m.getEndKey(), r2.getEndKey()));
r1 = new HRegionInfo(tableName, a, b);
r2 = new HRegionInfo(tableName, b, z);
m = RegionMergeTransaction.getMergedRegionInfo(r1, r2);
assertTrue(Bytes.equals(m.getStartKey(), r1.getStartKey())
&& Bytes.equals(m.getEndKey(), r2.getEndKey()));
}
/**
* Exception used in this class only.
*/