hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmhs...@apache.org
Subject svn commit: r1548020 - in /hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase: TableName.java util/Bytes.java
Date Thu, 05 Dec 2013 06:16:31 GMT
Author: jmhsieh
Date: Thu Dec  5 06:16:30 2013
New Revision: 1548020

URL: http://svn.apache.org/r1548020
Log:
HBASE-10079 Race in TableName cache

Modified:
    hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
    hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java

Modified: hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java?rev=1548020&r1=1548019&r2=1548020&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java (original)
+++ hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java Thu Dec
 5 06:16:30 2013
@@ -248,7 +248,7 @@ public final class TableName implements 
    */
   private TableName(ByteBuffer namespace, ByteBuffer qualifier) throws IllegalArgumentException
{
     this.qualifier = new byte[qualifier.remaining()];
-    qualifier.get(this.qualifier);
+    qualifier.duplicate().get(this.qualifier);
     this.qualifierAsString = Bytes.toString(this.qualifier);
 
     if (qualifierAsString.equals(OLD_ROOT_STR)) {
@@ -275,7 +275,7 @@ public final class TableName implements 
         this.systemTable = true;
       } else {
         this.namespace = new byte[namespace.remaining()];
-        namespace.get(this.namespace);
+        namespace.duplicate().get(this.namespace);
         this.namespaceAsString = Bytes.toString(this.namespace);
         this.systemTable = false;
       }
@@ -325,15 +325,15 @@ public final class TableName implements 
     TableName newTable = new TableName(bns, qns);
     if (tableCache.add(newTable)) {  // Adds the specified element if it is not already present
       return newTable;
-    } else {
-      // Someone else added it. Let's find it.
-      for (TableName tn : tableCache) {
-        if (Bytes.equals(tn.getQualifier(), qns) && Bytes.equals(tn.getNamespace(),
bns)) {
-          return tn;
-        }
-      }
     }
 
+    // Someone else added it. Let's find it.
+    for (TableName tn : tableCache) {
+      if (Bytes.equals(tn.getQualifier(), qns) && Bytes.equals(tn.getNamespace(),
bns)) {
+        return tn;
+      }
+    }
+    // this should never happen.
     throw new IllegalStateException(newTable + " was supposed to be in the cache");
   }
 

Modified: hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java?rev=1548020&r1=1548019&r2=1548020&view=diff
==============================================================================
--- hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java (original)
+++ hbase/trunk/hbase-common/src/main/java/org/apache/hadoop/hbase/util/Bytes.java Thu Dec
 5 06:16:30 2013
@@ -1279,19 +1279,18 @@ public class Bytes {
    * @param b right operand
    * @return True if equal
    */
-  public static boolean equals(byte[] a, ByteBuffer b) {
-    if (a == null) return b == null;
-    if (b == null) return false;
-    if (a.length != b.remaining()) return false;
+  public static boolean equals(byte[] a, ByteBuffer buf) {
+    if (a == null) return buf == null;
+    if (buf == null) return false;
+    if (a.length != buf.remaining()) return false;
 
-    b.mark();
+    // Thou shalt not modify the original byte buffer in what should be read only operations.
+    ByteBuffer b = buf.duplicate();
     for (byte anA : a) {
       if (anA != b.get()) {
-        b.reset();
         return false;
       }
     }
-    b.reset();
     return true;
   }
 



Mime
View raw message