HBASE-7731 Append/Increment methods in HRegion don't check whether the table is readonly or not (Devaraj)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1441593 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b11479cf9e
commit
997c8f8d6b
|
@ -4665,6 +4665,7 @@ public class HRegion implements HeapSize { // , Writable{
|
||||||
long size = 0;
|
long size = 0;
|
||||||
long txid = 0;
|
long txid = 0;
|
||||||
|
|
||||||
|
checkReadOnly();
|
||||||
// Lock row
|
// Lock row
|
||||||
startRegionOperation();
|
startRegionOperation();
|
||||||
this.writeRequestsCount.increment();
|
this.writeRequestsCount.increment();
|
||||||
|
@ -4829,6 +4830,7 @@ public class HRegion implements HeapSize { // , Writable{
|
||||||
long size = 0;
|
long size = 0;
|
||||||
long txid = 0;
|
long txid = 0;
|
||||||
|
|
||||||
|
checkReadOnly();
|
||||||
// Lock row
|
// Lock row
|
||||||
startRegionOperation();
|
startRegionOperation();
|
||||||
this.writeRequestsCount.increment();
|
this.writeRequestsCount.increment();
|
||||||
|
|
|
@ -519,6 +519,41 @@ public class TestHRegion extends HBaseTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAppendWithReadOnlyTable() throws Exception {
|
||||||
|
byte[] TABLE = Bytes.toBytes("readOnlyTable");
|
||||||
|
this.region = initHRegion(TABLE, getName(), conf, true, Bytes.toBytes("somefamily"));
|
||||||
|
boolean exceptionCaught = false;
|
||||||
|
Append append = new Append(Bytes.toBytes("somerow"));
|
||||||
|
append.add(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"),
|
||||||
|
Bytes.toBytes("somevalue"));
|
||||||
|
try {
|
||||||
|
region.append(append, false);
|
||||||
|
} catch (IOException e) {
|
||||||
|
exceptionCaught = true;
|
||||||
|
} finally {
|
||||||
|
HRegion.closeHRegion(this.region);
|
||||||
|
this.region = null;
|
||||||
|
}
|
||||||
|
assertTrue(exceptionCaught == true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testIncrWithReadOnlyTable() throws Exception {
|
||||||
|
byte[] TABLE = Bytes.toBytes("readOnlyTable");
|
||||||
|
this.region = initHRegion(TABLE, getName(), conf, true, Bytes.toBytes("somefamily"));
|
||||||
|
boolean exceptionCaught = false;
|
||||||
|
Increment inc = new Increment(Bytes.toBytes("somerow"));
|
||||||
|
inc.addColumn(Bytes.toBytes("somefamily"), Bytes.toBytes("somequalifier"), 1L);
|
||||||
|
try {
|
||||||
|
region.increment(inc, false);
|
||||||
|
} catch (IOException e) {
|
||||||
|
exceptionCaught = true;
|
||||||
|
} finally {
|
||||||
|
HRegion.closeHRegion(this.region);
|
||||||
|
this.region = null;
|
||||||
|
}
|
||||||
|
assertTrue(exceptionCaught == true);
|
||||||
|
}
|
||||||
|
|
||||||
private void deleteColumns(HRegion r, String value, String keyPrefix)
|
private void deleteColumns(HRegion r, String value, String keyPrefix)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
InternalScanner scanner = buildScanner(keyPrefix, value, r);
|
InternalScanner scanner = buildScanner(keyPrefix, value, r);
|
||||||
|
@ -3119,7 +3154,7 @@ public class TestHRegion extends HBaseTestCase {
|
||||||
byte[] tableName = Bytes.toBytes(method);
|
byte[] tableName = Bytes.toBytes(method);
|
||||||
byte[] family = Bytes.toBytes("family");
|
byte[] family = Bytes.toBytes("family");
|
||||||
this.region = initHRegion(tableName, Bytes.toBytes("x"), Bytes.toBytes("z"), method,
|
this.region = initHRegion(tableName, Bytes.toBytes("x"), Bytes.toBytes("z"), method,
|
||||||
conf, family);
|
conf, false, family);
|
||||||
try {
|
try {
|
||||||
byte[] rowNotServed = Bytes.toBytes("a");
|
byte[] rowNotServed = Bytes.toBytes("a");
|
||||||
Get g = new Get(rowNotServed);
|
Get g = new Get(rowNotServed);
|
||||||
|
@ -3841,7 +3876,22 @@ public class TestHRegion extends HBaseTestCase {
|
||||||
public static HRegion initHRegion (byte [] tableName, String callingMethod,
|
public static HRegion initHRegion (byte [] tableName, String callingMethod,
|
||||||
Configuration conf, byte [] ... families)
|
Configuration conf, byte [] ... families)
|
||||||
throws IOException{
|
throws IOException{
|
||||||
return initHRegion(tableName, null, null, callingMethod, conf, families);
|
return initHRegion(tableName, null, null, callingMethod, conf, false, families);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param tableName
|
||||||
|
* @param callingMethod
|
||||||
|
* @param conf
|
||||||
|
* @param isReadOnly
|
||||||
|
* @param families
|
||||||
|
* @throws IOException
|
||||||
|
* @return A region on which you must call {@link HRegion#closeHRegion(HRegion)} when done.
|
||||||
|
*/
|
||||||
|
public static HRegion initHRegion (byte [] tableName, String callingMethod,
|
||||||
|
Configuration conf, boolean isReadOnly, byte [] ... families)
|
||||||
|
throws IOException{
|
||||||
|
return initHRegion(tableName, null, null, callingMethod, conf, isReadOnly, families);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -3850,14 +3900,16 @@ public class TestHRegion extends HBaseTestCase {
|
||||||
* @param stopKey
|
* @param stopKey
|
||||||
* @param callingMethod
|
* @param callingMethod
|
||||||
* @param conf
|
* @param conf
|
||||||
|
* @param isReadOnly
|
||||||
* @param families
|
* @param families
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* @return A region on which you must call {@link HRegion#closeHRegion(HRegion)} when done.
|
* @return A region on which you must call {@link HRegion#closeHRegion(HRegion)} when done.
|
||||||
*/
|
*/
|
||||||
private static HRegion initHRegion(byte[] tableName, byte[] startKey, byte[] stopKey,
|
private static HRegion initHRegion(byte[] tableName, byte[] startKey, byte[] stopKey,
|
||||||
String callingMethod, Configuration conf, byte[]... families)
|
String callingMethod, Configuration conf, boolean isReadOnly, byte[]... families)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
HTableDescriptor htd = new HTableDescriptor(tableName);
|
HTableDescriptor htd = new HTableDescriptor(tableName);
|
||||||
|
htd.setReadOnly(isReadOnly);
|
||||||
for(byte [] family : families) {
|
for(byte [] family : families) {
|
||||||
htd.addFamily(new HColumnDescriptor(family));
|
htd.addFamily(new HColumnDescriptor(family));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue