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:
parent
cb4320232d
commit
1f176022fe
|
@ -775,11 +775,14 @@ implements WritableComparable<HRegionInfo> {
|
||||||
|
|
||||||
// Compare end keys.
|
// Compare end keys.
|
||||||
result = Bytes.compareTo(this.endKey, o.endKey);
|
result = Bytes.compareTo(this.endKey, o.endKey);
|
||||||
|
|
||||||
if (result != 0) {
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
if (this.offLine == o.offLine)
|
if (this.offLine == o.offLine)
|
||||||
return 0;
|
return 0;
|
||||||
if (this.offLine == true) return -1;
|
if (this.offLine == true) return -1;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -157,7 +157,11 @@ class CatalogJanitor extends Chore {
|
||||||
if (result != 0) return result;
|
if (result != 0) return result;
|
||||||
// Compare end keys.
|
// Compare end keys.
|
||||||
result = Bytes.compareTo(left.getEndKey(), right.getEndKey());
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -336,23 +336,50 @@ public class TestCatalogJanitor {
|
||||||
/**
|
/**
|
||||||
* Make sure parent gets cleaned up even if daughter is cleaned up before it.
|
* Make sure parent gets cleaned up even if daughter is cleaned up before it.
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testParentCleanedEvenIfDaughterGoneFirst()
|
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 {
|
throws IOException, InterruptedException {
|
||||||
HBaseTestingUtility htu = new HBaseTestingUtility();
|
HBaseTestingUtility htu = new HBaseTestingUtility();
|
||||||
setRootDirAndCleanIt(htu, "testParentCleanedEvenIfDaughterGoneFirst");
|
setRootDirAndCleanIt(htu, rootDir);
|
||||||
Server server = new MockServer(htu);
|
Server server = new MockServer(htu);
|
||||||
MasterServices services = new MockMasterServices(server);
|
MasterServices services = new MockMasterServices(server);
|
||||||
CatalogJanitor janitor = new CatalogJanitor(server, services);
|
CatalogJanitor janitor = new CatalogJanitor(server, services);
|
||||||
final HTableDescriptor htd = createHTableDescriptor();
|
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
|
// Parent
|
||||||
HRegionInfo parent = new HRegionInfo(htd.getName(), Bytes.toBytes("aaa"),
|
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
|
// Sleep a second else the encoded name on these regions comes out
|
||||||
// same for all with same start key and made in same second.
|
// same for all with same start key and made in same second.
|
||||||
Thread.sleep(1001);
|
Thread.sleep(1001);
|
||||||
|
@ -369,13 +396,13 @@ public class TestCatalogJanitor {
|
||||||
|
|
||||||
// Daughter b
|
// Daughter b
|
||||||
HRegionInfo splitb = new HRegionInfo(htd.getName(), Bytes.toBytes("ccc"),
|
HRegionInfo splitb = new HRegionInfo(htd.getName(), Bytes.toBytes("ccc"),
|
||||||
Bytes.toBytes("eee"));
|
lastEndKey);
|
||||||
Thread.sleep(1001);
|
Thread.sleep(1001);
|
||||||
// Make Daughters of daughterb; splitba and splitbb.
|
// Make Daughters of daughterb; splitba and splitbb.
|
||||||
HRegionInfo splitba = new HRegionInfo(htd.getName(), Bytes.toBytes("ccc"),
|
HRegionInfo splitba = new HRegionInfo(htd.getName(), Bytes.toBytes("ccc"),
|
||||||
Bytes.toBytes("ddd"));
|
Bytes.toBytes("ddd"));
|
||||||
HRegionInfo splitbb = new HRegionInfo(htd.getName(), 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.
|
// First test that our Comparator works right up in CatalogJanitor.
|
||||||
// Just fo kicks.
|
// Just fo kicks.
|
||||||
|
|
|
@ -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
|
@Test
|
||||||
public void testMetaTables() {
|
public void testMetaTables() {
|
||||||
assertTrue(HRegionInfo.ROOT_REGIONINFO.isMetaTable());
|
assertTrue(HRegionInfo.ROOT_REGIONINFO.isMetaTable());
|
||||||
|
|
Loading…
Reference in New Issue