hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1441648 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/regionserver/HRegion.java test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
Date Fri, 01 Feb 2013 22:15:15 GMT
Author: tedyu
Date: Fri Feb  1 22:15:15 2013
New Revision: 1441648

URL: http://svn.apache.org/viewvc?rev=1441648&view=rev
Log:
HBASE-7731 Append/Increment methods in HRegion don't check whether the table is readonly or
not (Devaraj)


Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=1441648&r1=1441647&r2=1441648&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java Fri
Feb  1 22:15:15 2013
@@ -4809,6 +4809,7 @@ public class HRegion implements HeapSize
     long size = 0;
     long txid = 0;
 
+    checkReadOnly();
     // Lock row
     startRegionOperation();
     this.writeRequestsCount.increment();
@@ -4978,6 +4979,7 @@ public class HRegion implements HeapSize
     long size = 0;
     long txid = 0;
 
+    checkReadOnly();
     // Lock row
     startRegionOperation();
     this.writeRequestsCount.increment();

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java?rev=1441648&r1=1441647&r2=1441648&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
(original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
Fri Feb  1 22:15:15 2013
@@ -502,6 +502,41 @@ public class TestHRegion extends HBaseTe
     }
   }
 
+  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)
   throws IOException {
     InternalScanner scanner = buildScanner(keyPrefix, value, r);
@@ -3525,7 +3560,7 @@ public class TestHRegion extends HBaseTe
     byte[] tableName = Bytes.toBytes(method);
     byte[] family = Bytes.toBytes("family");
     this.region = initHRegion(tableName, Bytes.toBytes("x"), Bytes.toBytes("z"), method,
-        conf, family);
+        conf, false, family);
     try {
       byte[] rowNotServed = Bytes.toBytes("a");
       Get g = new Get(rowNotServed);
@@ -4204,7 +4239,22 @@ public class TestHRegion extends HBaseTe
   public static HRegion initHRegion (byte [] tableName, String callingMethod,
       Configuration conf, byte [] ... families)
     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);
   }
 
   /**
@@ -4213,14 +4263,16 @@ public class TestHRegion extends HBaseTe
    * @param stopKey
    * @param callingMethod
    * @param conf
+   * @param isReadOnly
    * @param families
    * @throws IOException
    * @return A region on which you must call {@link HRegion#closeHRegion(HRegion)} when done.
    */
   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 {
     HTableDescriptor htd = new HTableDescriptor(tableName);
+    htd.setReadOnly(isReadOnly);
     for(byte [] family : families) {
       htd.addFamily(new HColumnDescriptor(family));
     }



Mime
View raw message