hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1437254 - in /hbase/branches/0.94/src: main/java/org/apache/hadoop/hbase/client/HConnectionManager.java test/java/org/apache/hadoop/hbase/client/TestHCM.java
Date Wed, 23 Jan 2013 02:34:07 GMT
Author: tedyu
Date: Wed Jan 23 02:34:06 2013
New Revision: 1437254

URL: http://svn.apache.org/viewvc?rev=1437254&view=rev
Log:
HBASE-7638 [0.94] region cache entry should only be removed on error if the error is from
the server currently in cache (Sergey)


Modified:
    hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
    hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java

Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java?rev=1437254&r1=1437253&r2=1437254&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
(original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java
Wed Jan 23 02:34:06 2013
@@ -987,7 +987,7 @@ public class HConnectionManager {
                 return location;
               }
             } else {
-              deleteCachedLocation(tableName, row);
+              deleteCachedLocation(tableName, row, null);
             }
 
             // Query the root or meta region for the location of the meta region
@@ -1134,25 +1134,35 @@ public class HConnectionManager {
      * @param tableName tableName
      * @param row
      */
-    void deleteCachedLocation(final byte [] tableName, final byte [] row) {
+    void deleteCachedLocation(final byte[] tableName, final byte[] row, HRegionLocation source)
{
+      boolean isStaleDelete = false;
+      HRegionLocation oldLocation = null;
       synchronized (this.cachedRegionLocations) {
         Map<byte[], HRegionLocation> tableLocations =
             getTableLocations(tableName);
         // start to examine the cache. we can only do cache actions
         // if there's something in the cache for this table.
         if (!tableLocations.isEmpty()) {
-          HRegionLocation rl = getCachedLocation(tableName, row);
-          if (rl != null) {
-            tableLocations.remove(rl.getRegionInfo().getStartKey());
-            if (LOG.isDebugEnabled()) {
-              LOG.debug("Removed " +
-                rl.getRegionInfo().getRegionNameAsString() +
-                " for tableName=" + Bytes.toString(tableName) +
-                " from cache " + "because of " + Bytes.toStringBinary(row));
+          oldLocation = getCachedLocation(tableName, row);
+          if (oldLocation != null) {
+            isStaleDelete = (source != null) && !oldLocation.equals(source);
+            if (!isStaleDelete) {
+              tableLocations.remove(oldLocation.getRegionInfo().getStartKey());
             }
           }
         }
       }
+      if (LOG.isDebugEnabled()) {
+        if (isStaleDelete) {
+          LOG.debug("Received an error from " + source.getHostnamePort() + " for ["
+            + oldLocation.getRegionInfo().getRegionNameAsString()  + "]; not removing "
+            + oldLocation.getHostnamePort() + " from cache.");
+        } else if (oldLocation != null) {
+          LOG.debug("Removed [" + oldLocation.getRegionInfo().getRegionNameAsString()
+            + "] for tableName=" + Bytes.toString(tableName) + " from cache because of ["
+            + Bytes.toStringBinary(row) + "]");
+        }
+      }
     }
 
     @Override
@@ -1593,7 +1603,7 @@ public class HConnectionManager {
             actionCount++;
             Row row = list.get(i);
             workingList.add(row);
-            deleteCachedLocation(tableName, row.getRow());
+            deleteCachedLocation(tableName, row.getRow(), lastServers[i]);
           } else {
             if (results[i] != null && results[i] instanceof Throwable) {
               actionCount++;

Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java?rev=1437254&r1=1437253&r2=1437254&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/client/TestHCM.java Wed Jan
23 02:34:06 2013
@@ -61,6 +61,7 @@ public class TestHCM {
   private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
   private static final byte[] TABLE_NAME = Bytes.toBytes("test");
   private static final byte[] TABLE_NAME1 = Bytes.toBytes("test1");
+  private static final byte[] TABLE_NAME2 = Bytes.toBytes("test2");
   private static final byte[] FAM_NAM = Bytes.toBytes("f");
   private static final byte[] ROW = Bytes.toBytes("bbb");
 
@@ -162,7 +163,7 @@ public class TestHCM {
     HConnectionManager.HConnectionImplementation conn =
         (HConnectionManager.HConnectionImplementation)table.getConnection();
     assertNotNull(conn.getCachedLocation(TABLE_NAME, ROW));
-    conn.deleteCachedLocation(TABLE_NAME, ROW);
+    conn.deleteCachedLocation(TABLE_NAME, ROW, null);
     HRegionLocation rl = conn.getCachedLocation(TABLE_NAME, ROW);
     assertNull("What is this location?? " + rl, rl);
     table.close();
@@ -326,6 +327,31 @@ public class TestHCM {
     assertTrue(c2 != c3);
   }
 
+  @Test(timeout = 60000)
+  public void testDeleteFromCacheOnlyWorksFromTheSameSource() throws Exception{
+    HTable table = TEST_UTIL.createTable(TABLE_NAME2, FAM_NAM);
+    TEST_UTIL.createMultiRegions(table, FAM_NAM);
+    Put put = new Put(ROW);
+    put.add(FAM_NAM, ROW, ROW);
+    table.put(put);
+    HConnectionManager.HConnectionImplementation conn =
+        (HConnectionManager.HConnectionImplementation)table.getConnection();
+
+    HRegionLocation location = conn.getCachedLocation(TABLE_NAME2, ROW);
+    assertNotNull(location);
+    HRegionLocation anySource = new HRegionLocation(location.getRegionInfo(),
+        location.getHostname(), location.getPort() - 1);
+    conn.deleteCachedLocation(TABLE_NAME2, ROW, anySource);
+    location = conn.getCachedLocation(TABLE_NAME2, ROW);
+    assertNotNull(location); // different server, no delete.
+
+    conn.deleteCachedLocation(TABLE_NAME2, ROW, location);
+    location = conn.getCachedLocation(TABLE_NAME2, ROW);
+    assertNull(location); // same server, delete.
+
+    TEST_UTIL.deleteTable(TABLE_NAME2);
+  }
+
   @org.junit.Rule
   public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
     new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();



Mime
View raw message