HBASE-2516 Ugly IOE when region is being closed; rather, should NSRE

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@947675 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2010-05-24 15:43:46 +00:00
parent c7ed31b969
commit d7276f47fd
3 changed files with 33 additions and 1 deletions

View File

@ -351,6 +351,8 @@ Release 0.21.0 - Unreleased
HBASE-2590 Failed parse of branch element in saveVersion.sh
HBASE-2591 HBASE-2587 hardcoded the port that dfscluster runs on
HBASE-2519 StoreFileScanner.seek swallows IOEs (Todd Lipcon via Stack)
HBASE-2516 Ugly IOE when region is being closed; rather, should NSRE
(Daniel Ploeg via Stack)
IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable

View File

@ -1192,7 +1192,7 @@ public class HRegion implements HConstants, HeapSize { // , Writable{
newScannerLock.readLock().lock();
try {
if (this.closed.get()) {
throw new IOException("Region " + this + " closed");
throw new NotServingRegionException("Region " + this + " closed");
}
// Verify families are all valid
if(scan.hasFamilies()) {

View File

@ -1135,6 +1135,36 @@ public class TestHRegion extends HBaseTestCase {
((RegionScanner)is).storeHeap.getHeap().size());
}
/**
* This method tests https://issues.apache.org/jira/browse/HBASE-2516.
*/
public void testGetScanner_WithRegionClosed() {
byte[] tableName = Bytes.toBytes("testtable");
byte[] fam1 = Bytes.toBytes("fam1");
byte[] fam2 = Bytes.toBytes("fam2");
byte[][] families = {fam1, fam2};
//Setting up region
String method = this.getName();
try {
initHRegion(tableName, method, families);
} catch (IOException e) {
e.printStackTrace();
fail("Got IOException during initHRegion, " + e.getMessage());
}
region.closed.set(true);
try {
region.getScanner(null);
fail("Expected to get an exception during getScanner on a region that is closed");
} catch (org.apache.hadoop.hbase.NotServingRegionException e) {
//this is the correct exception that is expected
} catch (IOException e) {
fail("Got wrong type of exception - should be a NotServingRegionException, but was an IOException: "
+ e.getMessage());
}
}
public void testRegionScanner_Next() throws IOException {
byte [] tableName = Bytes.toBytes("testtable");
byte [] row1 = Bytes.toBytes("row1");