HBASE-4927 CatalogJanior:SplitParentFirstComparator doesn't sort as expected, for the last region when the endkey is empty

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1211204 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2011-12-06 22:15:11 +00:00
parent cb4320232d
commit 1f176022fe
4 changed files with 52 additions and 8 deletions

View File

@ -775,11 +775,14 @@ implements WritableComparable<HRegionInfo> {
// Compare end keys.
result = Bytes.compareTo(this.endKey, o.endKey);
if (result != 0) {
if (this.getEndKey().length == 0) return 1; // this is last region
if (o.getEndKey().length == 0) return -1; // o is the last region
return result;
}
if (this.offLine == o.offLine)
return 0;
return 0;
if (this.offLine == true) return -1;
return 1;

View File

@ -157,7 +157,11 @@ class CatalogJanitor extends Chore {
if (result != 0) return result;
// Compare end keys.
result = Bytes.compareTo(left.getEndKey(), right.getEndKey());
if (result != 0) return -result; // Flip the result so parent comes first.
if (result != 0) {
if (left.getEndKey().length == 0) return -1; // left is last region
if (right.getEndKey().length == 0) return 1; // right is the last region
return -result; // Flip the result so parent comes first.
}
return result;
}
}

View File

@ -336,23 +336,50 @@ public class TestCatalogJanitor {
/**
* Make sure parent gets cleaned up even if daughter is cleaned up before it.
* @throws IOException
* @throws InterruptedException
* @throws InterruptedException
*/
@Test
public void testParentCleanedEvenIfDaughterGoneFirst()
throws IOException, InterruptedException {
parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(
"testParentCleanedEvenIfDaughterGoneFirst", Bytes.toBytes("eee"));
}
/**
* Make sure last parent with empty end key gets cleaned up even if daughter is cleaned up before it.
* @throws IOException
* @throws InterruptedException
*/
@Test
public void testLastParentCleanedEvenIfDaughterGoneFirst()
throws IOException, InterruptedException {
parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(
"testLastParentCleanedEvenIfDaughterGoneFirst", new byte[0]);
}
/**
* Make sure parent with specified end key gets cleaned up even if daughter is cleaned up before it.
*
* @param rootDir the test case name, used as the HBase testing utility root
* @param lastEndKey the end key of the split parent
* @throws IOException
* @throws InterruptedException
*/
private void parentWithSpecifiedEndKeyCleanedEvenIfDaughterGoneFirst(
final String rootDir, final byte[] lastEndKey)
throws IOException, InterruptedException {
HBaseTestingUtility htu = new HBaseTestingUtility();
setRootDirAndCleanIt(htu, "testParentCleanedEvenIfDaughterGoneFirst");
setRootDirAndCleanIt(htu, rootDir);
Server server = new MockServer(htu);
MasterServices services = new MockMasterServices(server);
CatalogJanitor janitor = new CatalogJanitor(server, services);
final HTableDescriptor htd = createHTableDescriptor();
// Create regions: aaa->eee, aaa->ccc, aaa->bbb, bbb->ccc, etc.
// Create regions: aaa->{lastEndKey}, aaa->ccc, aaa->bbb, bbb->ccc, etc.
// Parent
HRegionInfo parent = new HRegionInfo(htd.getName(), Bytes.toBytes("aaa"),
Bytes.toBytes("eee"));
lastEndKey);
// Sleep a second else the encoded name on these regions comes out
// same for all with same start key and made in same second.
Thread.sleep(1001);
@ -369,13 +396,13 @@ public class TestCatalogJanitor {
// Daughter b
HRegionInfo splitb = new HRegionInfo(htd.getName(), Bytes.toBytes("ccc"),
Bytes.toBytes("eee"));
lastEndKey);
Thread.sleep(1001);
// Make Daughters of daughterb; splitba and splitbb.
HRegionInfo splitba = new HRegionInfo(htd.getName(), Bytes.toBytes("ccc"),
Bytes.toBytes("ddd"));
HRegionInfo splitbb = new HRegionInfo(htd.getName(), Bytes.toBytes("ddd"),
Bytes.toBytes("eee"));
lastEndKey);
// First test that our Comparator works right up in CatalogJanitor.
// Just fo kicks.

View File

@ -114,6 +114,16 @@ public class TestHRegionInfo {
}
}
@Test
public void testLastRegionCompare() {
HTableDescriptor tableDesc = new HTableDescriptor("testtable");
HRegionInfo hrip = new HRegionInfo(
tableDesc.getName(), Bytes.toBytes("a"), new byte[0]);
HRegionInfo hric = new HRegionInfo(
tableDesc.getName(), Bytes.toBytes("a"), Bytes.toBytes("b"));
assertTrue(hrip.compareTo(hric) > 0);
}
@Test
public void testMetaTables() {
assertTrue(HRegionInfo.ROOT_REGIONINFO.isMetaTable());