hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r678578 - in /hadoop/hbase/trunk: CHANGES.txt src/java/org/apache/hadoop/hbase/regionserver/HRegion.java
Date Mon, 21 Jul 2008 21:34:57 GMT
Author: stack
Date: Mon Jul 21 14:34:57 2008
New Revision: 678578

URL: http://svn.apache.org/viewvc?rev=678578&view=rev
Log:
HBASE-758 Throwing IOE read-only when should be throwing NSRE

Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=678578&r1=678577&r2=678578&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Mon Jul 21 14:34:57 2008
@@ -196,6 +196,7 @@
    HBASE-43    Add a read-only attribute to columns (Andrew Purtell via Stack)
    HBASE-424   Should be able to enable/disable .META. table
    HBASE-679   Regionserver addresses are still not right in the new tables page
+   HBASE-758   Throwing IOE read-only when should be throwing NSRE
    
   IMPROVEMENTS
    HBASE-559   MR example job to count table rows

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java?rev=678578&r1=678577&r2=678578&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java Mon Jul
21 14:34:57 2008
@@ -341,6 +341,20 @@
     volatile boolean compacting = false;
     // Gets set in close. If set, cannot compact or flush again.
     volatile boolean writesEnabled = true;
+    // Set if region is read-only
+    private volatile boolean readOnly = false;
+    
+    /**
+     * Set flags that make this region read-only.
+     */
+    synchronized void setReadOnly(final boolean onOff) {
+      this.writesEnabled = !onOff;
+      this.readOnly = onOff;
+    }
+    
+    boolean isReadOnly() {
+      return this.readOnly;
+    }
   }
 
   private volatile WriteState writestate = new WriteState();
@@ -494,8 +508,10 @@
     this.blockingMemcacheSize = this.memcacheFlushSize *
       conf.getInt("hbase.hregion.memcache.block.multiplier", 1);
 
-    if (this.regionInfo.getTableDesc().isReadOnly())
-      this.writestate.writesEnabled = false;
+    // See if region is meant to run read-only.
+    if (this.regionInfo.getTableDesc().isReadOnly()) {
+      this.writestate.setReadOnly(true);
+    }
 
     // HRegion is ready to go!
     this.writestate.compacting = false;
@@ -1317,10 +1333,7 @@
    */
   public void batchUpdate(BatchUpdate b)
   throws IOException {
-
-    if (!this.writestate.writesEnabled) {
-      throw new IOException("region is read only");
-    }
+    checkReadOnly();
 
     // Do a rough check that we have resources to accept a write.  The check is
     // 'rough' in that between the resource check and the call to obtain a 
@@ -1429,9 +1442,7 @@
   public void deleteAll(final byte [] row, final byte [] column, final long ts)
   throws IOException {
     checkColumn(column);
-    if (!this.writestate.writesEnabled) {
-      throw new IOException("region is read only");
-    }
+    checkReadOnly();
     Integer lid = obtainRowLock(row);
     try {
       deleteMultiple(row, column, ts, ALL_VERSIONS);
@@ -1448,9 +1459,7 @@
    */
   public void deleteAll(final byte [] row, final long ts)
   throws IOException {
-    if (!this.writestate.writesEnabled) {
-      throw new IOException("region is read only");
-    }
+    checkReadOnly();
     Integer lid = obtainRowLock(row);    
     try {
       for (HStore store : stores.values()){
@@ -1478,9 +1487,7 @@
    */
   public void deleteFamily(byte [] row, byte [] family, long timestamp)
   throws IOException{
-    if (!this.writestate.writesEnabled) {
-      throw new IOException("region is read only");
-    }
+    checkReadOnly();
     Integer lid = obtainRowLock(row);    
     try {
       // find the HStore for the column family
@@ -1513,9 +1520,7 @@
   private void deleteMultiple(final byte [] row, final byte [] column,
       final long ts, final int versions)
   throws IOException {
-    if (!this.writestate.writesEnabled) {
-      throw new IOException("region is read only");
-    }
+    checkReadOnly();
     HStoreKey origin = new HStoreKey(row, column, ts);
     Set<HStoreKey> keys = getKeys(origin, versions);
     if (keys.size() > 0) {
@@ -1528,6 +1533,15 @@
   }
   
   /**
+   * @throws IOException Throws exception if region is in read-only mode.
+   */
+  protected void checkReadOnly() throws IOException {
+    if (this.writestate.isReadOnly()) {
+      throw new IOException("region is read only");
+    }
+  }
+  
+  /**
    * Private implementation.
    * 
    * localput() is used for both puts and deletes. We just place the values
@@ -1543,9 +1557,7 @@
       final byte [] val)
   throws IOException {
     checkColumn(key.getColumn());
-    if (!this.writestate.writesEnabled) {
-      throw new IOException("region is read only");
-    }
+    checkReadOnly();
     TreeMap<HStoreKey, byte []> targets = this.targetColumns.get(lockid);
     if (targets == null) {
       targets = new TreeMap<HStoreKey, byte []>();
@@ -1567,9 +1579,7 @@
     if (updatesByColumn == null || updatesByColumn.size() <= 0) {
       return;
     }
-    if (!this.writestate.writesEnabled) {
-      throw new IOException("region is read only");
-    }
+    checkReadOnly();
     boolean flush = false;
     this.updatesLock.readLock().lock();
     try {



Mime
View raw message