phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rajeshb...@apache.org
Subject phoenix git commit: PHOENIX-1060 Replace ReferencingColumn with ColumnReference(Rajeshbabu)
Date Sun, 08 Mar 2015 06:58:36 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.0 c5cf51eb8 -> b99d4e500


PHOENIX-1060 Replace ReferencingColumn with ColumnReference(Rajeshbabu)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/b99d4e50
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b99d4e50
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b99d4e50

Branch: refs/heads/4.0
Commit: b99d4e500a9f6650703a3f1a05528752c2dc266f
Parents: c5cf51e
Author: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Authored: Sun Mar 8 12:28:18 2015 +0530
Committer: Rajeshbabu Chintaguntla <rajeshbabu@apache.org>
Committed: Sun Mar 8 12:28:18 2015 +0530

----------------------------------------------------------------------
 .../index/covered/example/CoveredColumn.java    |   6 +-
 .../index/covered/update/ColumnReference.java   | 128 ++++++++++---------
 .../hbase/index/scanner/ScannerBuilder.java     |   2 +-
 .../hbase/index/util/IndexManagementUtil.java   |  40 ------
 .../index/util/ReadOnlyImmutableBytesPtr.java   |  59 +++++++++
 .../apache/phoenix/index/IndexMaintainer.java   |  11 +-
 .../java/org/apache/phoenix/util/IndexUtil.java |   8 +-
 7 files changed, 144 insertions(+), 110 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/b99d4e50/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumn.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumn.java
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumn.java
index 5c6989f..78a1042 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumn.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/example/CoveredColumn.java
@@ -54,7 +54,7 @@ public class CoveredColumn extends ColumnReference {
   }
 
   public String serialize() {
-    return CoveredColumn.serialize(familyString, qualifier);
+    return CoveredColumn.serialize(familyString, getQualifier());
   }
 
   public static String serialize(String first, byte[] second) {
@@ -96,12 +96,12 @@ public class CoveredColumn extends ColumnReference {
     CoveredColumn other = (CoveredColumn) obj;
     if (hashCode != other.hashCode) return false;
     if (!familyString.equals(other.familyString)) return false;
-    return Bytes.equals(qualifier, other.qualifier);
+    return Bytes.equals(getQualifier(), other.getQualifier());
   }
 
   @Override
   public String toString() {
-    String qualString = qualifier == null ? "null" : Bytes.toString(qualifier);
+    String qualString = getQualifier() == null ? "null" : Bytes.toString(getQualifier());
     return "CoveredColumn:[" + familyString + ":" + qualString + "]";
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b99d4e50/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/ColumnReference.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/ColumnReference.java
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/ColumnReference.java
index 4052d68..4ea7295 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/ColumnReference.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/covered/update/ColumnReference.java
@@ -21,6 +21,7 @@ import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
+import org.apache.phoenix.hbase.index.util.ReadOnlyImmutableBytesPtr;
 
 /**
  * 
@@ -29,60 +30,68 @@ public class ColumnReference implements Comparable<ColumnReference>
{
     
   public static final byte[] ALL_QUALIFIERS = new byte[0];
   
-  private static int calcHashCode(byte[] family, byte[] qualifier) {
+  private static int calcHashCode(ImmutableBytesWritable familyPtr, ImmutableBytesWritable
qualifierPtr) {
     final int prime = 31;
     int result = 1;
-    result = prime * result + Bytes.hashCode(family);
-    result = prime * result + Bytes.hashCode(qualifier);
+    result = prime * result + familyPtr.hashCode();;
+    result = prime * result + qualifierPtr.hashCode();
     return result;
   }
 
-  private final int hashCode;
-  protected final byte[] family;
-  protected final byte[] qualifier;
-    private volatile ImmutableBytesWritable familyPtr;
-    private volatile ImmutableBytesWritable qualifierPtr;
+    private final int hashCode;
+    protected volatile byte[] family;
+    protected volatile byte[] qualifier;
+    private final ImmutableBytesPtr familyPtr;
+    private final ImmutableBytesPtr qualifierPtr;
 
-  public ColumnReference(byte[] family, byte[] qualifier) {
-    this.family = family;
-    this.qualifier = qualifier;
-    this.hashCode = calcHashCode(family, qualifier);
-  }
+    public ColumnReference(byte[] family, byte[] qualifier) {
+        this.familyPtr = new ReadOnlyImmutableBytesPtr(family);
+        this.qualifierPtr = new ReadOnlyImmutableBytesPtr(qualifier);
+        this.hashCode = calcHashCode(this.familyPtr, this.qualifierPtr);
+    }
 
-  public byte[] getFamily() {
-    return this.family;
-  }
+    public ColumnReference(byte[] family, int familyOffset, int familyLength, byte[] qualifier,
+            int qualifierOffset, int qualifierLength) {
+        this.familyPtr = new ReadOnlyImmutableBytesPtr(family, familyOffset, familyLength);
+        this.qualifierPtr =
+                new ReadOnlyImmutableBytesPtr(qualifier, qualifierOffset, qualifierLength);
+        this.hashCode = calcHashCode(this.familyPtr, this.qualifierPtr);
+    }
 
-  public byte[] getQualifier() {
-    return this.qualifier;
-  }
-  
-    public ImmutableBytesWritable getFamilyWritable() {
-        if (this.familyPtr == null) {
-            synchronized (this.family) {
-                if (this.familyPtr == null) {
-                    this.familyPtr = new ImmutableBytesPtr(this.family);
+    public byte[] getFamily() {
+        if (this.family == null) {
+            synchronized (this.familyPtr) {
+                if (this.family == null) {
+                    this.family = this.familyPtr.copyBytesIfNecessary();
                 }
             }
         }
-        return this.familyPtr;
+        return this.family;
     }
 
-    public ImmutableBytesWritable getQualifierWritable() {
-        if (this.qualifierPtr == null) {
-            synchronized (this.qualifier) {
-                if (this.qualifierPtr == null) {
-                    this.qualifierPtr = new ImmutableBytesPtr(this.qualifier);
+    public byte[] getQualifier() {
+        if (this.qualifier == null) {
+            synchronized (this.qualifierPtr) {
+                if (this.qualifier == null) {
+                    this.qualifier = this.qualifierPtr.copyBytesIfNecessary();
                 }
             }
         }
+        return this.qualifier;
+    }
+
+    public ImmutableBytesPtr getFamilyWritable() {
+        return this.familyPtr;
+    }
+
+    public ImmutableBytesPtr getQualifierWritable() {
         return this.qualifierPtr;
     }
 
   @SuppressWarnings("deprecation")
   public boolean matches(KeyValue kv) {
-    if (matchesFamily(kv.getBuffer(), kv.getFamilyOffset(), kv.getFamilyLength())) {
-      return matchesQualifier(kv.getBuffer(), kv.getQualifierOffset(), kv.getQualifierLength());
+    if (matchesFamily(kv.getRowArray(), kv.getFamilyOffset(), kv.getFamilyLength())) {
+      return matchesQualifier(kv.getRowArray(), kv.getQualifierOffset(), kv.getQualifierLength());
     }
     return false;
   }
@@ -95,9 +104,10 @@ public class ColumnReference implements Comparable<ColumnReference>
{
     return matchesQualifier(qual, 0, qual.length);
   }
 
-  public boolean matchesQualifier(byte[] bytes, int offset, int length) {
-    return allColumns() ? true : match(bytes, offset, length, qualifier);
-  }
+    public boolean matchesQualifier(byte[] bytes, int offset, int length) {
+        return allColumns() ? true : match(bytes, offset, length, qualifierPtr.get(),
+            qualifierPtr.getOffset(), qualifierPtr.getLength());
+    }
 
   /**
    * @param family to check against
@@ -108,37 +118,39 @@ public class ColumnReference implements Comparable<ColumnReference>
{
   }
 
   public boolean matchesFamily(byte[] bytes, int offset, int length) {
-    return match(bytes, offset, length, family);
+    return match(bytes, offset, length, familyPtr.get(), familyPtr.getOffset(), familyPtr.getLength());
   }
 
   /**
    * @return <tt>true</tt> if this should include all column qualifiers, <tt>false</tt>
otherwise
    */
   public boolean allColumns() {
-    return this.qualifier == ALL_QUALIFIERS;
-  }
-
-  /**
-   * Check to see if the passed bytes match the stored bytes
-   * @param first
-   * @param storedKey the stored byte[], should never be <tt>null</tt>
-   * @return <tt>true</tt> if they are byte-equal
-   */
-  private boolean match(byte[] first, int offset, int length, byte[] storedKey) {
-    return first == null ? false : Bytes.equals(first, offset, length, storedKey, 0,
-      storedKey.length);
-  }
+    return getQualifier() == ALL_QUALIFIERS;
+  }
+
+    /**
+     * Check to see if the passed bytes match the stored bytes
+     * @param first
+     * @param storedKey the stored byte[], should never be <tt>null</tt>
+     * @return <tt>true</tt> if they are byte-equal
+     */
+    private boolean match(byte[] first, int offset1, int length1, byte[] storedKey, int offset2,
+            int length2) {
+        return first == null ? false : Bytes.equals(first, offset1, length1, storedKey, offset2,
+            length2);
+    }
 
-  public KeyValue getFirstKeyValueForRow(byte[] row) {
-    return KeyValue.createFirstOnRow(row, family, qualifier == ALL_QUALIFIERS ? null : qualifier);
-  }
+    public KeyValue getFirstKeyValueForRow(byte[] row) {
+        return KeyValue.createFirstOnRow(row, getFamily(), getQualifier() == ALL_QUALIFIERS
? null
+                : getQualifier());
+    }
 
   @Override
   public int compareTo(ColumnReference o) {
-    int c = Bytes.compareTo(family, o.family);
+    int c = familyPtr.compareTo(o.familyPtr);
     if (c == 0) {
       // matching families, compare qualifiers
-      c = Bytes.compareTo(qualifier, o.qualifier);
+      c = qualifierPtr.compareTo(o.qualifierPtr);
     }
     return c;
   }
@@ -147,8 +159,8 @@ public class ColumnReference implements Comparable<ColumnReference>
{
   public boolean equals(Object o) {
     if (o instanceof ColumnReference) {
       ColumnReference other = (ColumnReference) o;
-      if (hashCode == other.hashCode && Bytes.equals(family, other.family)) {
-        return Bytes.equals(qualifier, other.qualifier);
+      if (hashCode == other.hashCode && familyPtr.equals(other.familyPtr)) {
+        return qualifierPtr.equals(other.qualifierPtr);
       }
     }
     return false;
@@ -161,6 +173,6 @@ public class ColumnReference implements Comparable<ColumnReference>
{
 
   @Override
   public String toString() {
-    return "ColumnReference - " + Bytes.toString(family) + ":" + Bytes.toString(qualifier);
+    return "ColumnReference - " + Bytes.toString(getFamily()) + ":" + Bytes.toString(getQualifier());
   }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b99d4e50/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/ScannerBuilder.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/ScannerBuilder.java
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/ScannerBuilder.java
index edc26d5..575779a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/ScannerBuilder.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/scanner/ScannerBuilder.java
@@ -101,7 +101,7 @@ public class ScannerBuilder {
       getAllFamilies(Collection<? extends ColumnReference> columns) {
     Set<ImmutableBytesPtr> families = new HashSet<ImmutableBytesPtr>();
     for (ColumnReference ref : columns) {
-      families.add(new ImmutableBytesPtr(ref.getFamily()));
+      families.add(ref.getFamilyWritable());
     }
     return families;
   }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b99d4e50/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
index 05a9f90..f9f0029 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/IndexManagementUtil.java
@@ -97,46 +97,6 @@ public class IndexManagementUtil {
 
     }
 
-    public static class ReferencingColumn {
-        ImmutableBytesPtr family;
-        ImmutableBytesPtr qual;
-
-        public static ReferencingColumn wrap(ColumnReference ref) {
-            ImmutableBytesPtr family = new ImmutableBytesPtr(ref.getFamily());
-            ImmutableBytesPtr qual = new ImmutableBytesPtr(ref.getQualifier());
-            return new ReferencingColumn(family, qual);
-        }
-
-        public ReferencingColumn(ImmutableBytesPtr family, ImmutableBytesPtr qual) {
-            this.family = family;
-            this.qual = qual;
-        }
-
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ((family == null) ? 0 : family.hashCode());
-            result = prime * result + ((qual == null) ? 0 : qual.hashCode());
-            return result;
-        }
-
-        @Override
-        public boolean equals(Object obj) {
-            if (this == obj) return true;
-            if (obj == null) return false;
-            if (getClass() != obj.getClass()) return false;
-            ReferencingColumn other = (ReferencingColumn)obj;
-            if (family == null) {
-                if (other.family != null) return false;
-            } else if (!family.equals(other.family)) return false;
-            if (qual == null) {
-                if (other.qual != null) return false;
-            } else if (!qual.equals(other.qual)) return false;
-            return true;
-        }
-    }
-
     public static ValueGetter createGetterFromScanner(Scanner scanner, byte[] currentRow)
{
         return new LazyValueGetter(scanner, currentRow);
     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b99d4e50/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/ReadOnlyImmutableBytesPtr.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/ReadOnlyImmutableBytesPtr.java
b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/ReadOnlyImmutableBytesPtr.java
new file mode 100644
index 0000000..6a7334f
--- /dev/null
+++ b/phoenix-core/src/main/java/org/apache/phoenix/hbase/index/util/ReadOnlyImmutableBytesPtr.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.phoenix.hbase.index.util;
+
+import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
+
+public class ReadOnlyImmutableBytesPtr extends ImmutableBytesPtr {
+    
+    private static final String ERROR_MESSAGE = "Read-only bytes pointer may not be changed";
+
+    public ReadOnlyImmutableBytesPtr() {
+    }
+
+    public ReadOnlyImmutableBytesPtr(byte[] bytes) {
+        super(bytes);
+    }
+
+    public ReadOnlyImmutableBytesPtr(ImmutableBytesWritable ibw) {
+        super(ibw.get(), ibw.getOffset(), ibw.getLength());
+    }
+
+    public ReadOnlyImmutableBytesPtr(ImmutableBytesPtr ibp) {
+        super(ibp.get(), ibp.getOffset(), ibp.getLength());
+    }
+
+    public ReadOnlyImmutableBytesPtr(byte[] bytes, int offset, int length) {
+        super(bytes, offset, length);
+    }
+
+    @Override
+    public void set(byte[] b) {
+        throw new UnsupportedOperationException(ERROR_MESSAGE);
+    }
+
+    @Override
+    public void set(ImmutableBytesWritable ptr) {
+        throw new UnsupportedOperationException(ERROR_MESSAGE);
+    }
+
+    @Override
+    public void set(byte[] b, int offset, int length) {
+        throw new UnsupportedOperationException(ERROR_MESSAGE);
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b99d4e50/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
index fd006c9..4f785eb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/index/IndexMaintainer.java
@@ -54,7 +54,6 @@ import org.apache.phoenix.expression.visitor.KeyValueExpressionVisitor;
 import org.apache.phoenix.hbase.index.ValueGetter;
 import org.apache.phoenix.hbase.index.covered.update.ColumnReference;
 import org.apache.phoenix.hbase.index.util.ImmutableBytesPtr;
-import org.apache.phoenix.hbase.index.util.IndexManagementUtil.ReferencingColumn;
 import org.apache.phoenix.hbase.index.util.KeyValueBuilder;
 import org.apache.phoenix.jdbc.PhoenixConnection;
 import org.apache.phoenix.jdbc.PhoenixStatement;
@@ -1048,9 +1047,9 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference>
{
         }
         size += WritableUtils.getVIntSize(coveredColumns.size());
         for (ColumnReference ref : coveredColumns) {
-            size += WritableUtils.getVIntSize(ref.getFamily().length);
+            size += WritableUtils.getVIntSize(ref.getFamilyWritable().getSize());
             size += ref.getFamily().length;
-            size += WritableUtils.getVIntSize(ref.getQualifier().length);
+            size += WritableUtils.getVIntSize(ref.getQualifierWritable().getSize());
             size += ref.getQualifier().length;
         }
         size += indexTableName.length + WritableUtils.getVIntSize(indexTableName.length);
@@ -1301,20 +1300,20 @@ public class IndexMaintainer implements Writable, Iterable<ColumnReference>
{
     }
 
     public ValueGetter createGetterFromKeyValues(final byte[] rowKey, Collection<? extends
Cell> pendingUpdates) {
-        final Map<ReferencingColumn, ImmutableBytesPtr> valueMap = Maps.newHashMapWithExpectedSize(pendingUpdates
+        final Map<ColumnReference, ImmutableBytesPtr> valueMap = Maps.newHashMapWithExpectedSize(pendingUpdates
                 .size());
         for (Cell kv : pendingUpdates) {
             // create new pointers to each part of the kv
             ImmutableBytesPtr family = new ImmutableBytesPtr(kv.getRowArray(),kv.getFamilyOffset(),kv.getFamilyLength());
             ImmutableBytesPtr qual = new ImmutableBytesPtr(kv.getRowArray(), kv.getQualifierOffset(),
kv.getQualifierLength());
             ImmutableBytesPtr value = new ImmutableBytesPtr(kv.getValueArray(), kv.getValueOffset(),
kv.getValueLength());
-            valueMap.put(new ReferencingColumn(family, qual), value);
+            valueMap.put(new ColumnReference(kv.getRowArray(), kv.getFamilyOffset(), kv.getFamilyLength(),
kv.getRowArray(), kv.getQualifierOffset(), kv.getQualifierLength()), value);
         }
         return new ValueGetter() {
             @Override
             public ImmutableBytesPtr getLatestValue(ColumnReference ref) {
                 if(ref.equals(dataEmptyKeyValueRef)) return null;
-                return valueMap.get(ReferencingColumn.wrap(ref));
+                return valueMap.get(ref);
             }
             @Override
             public byte[] getRowKey() {

http://git-wip-us.apache.org/repos/asf/phoenix/blob/b99d4e50/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
index b72d3db..c147f91 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/util/IndexUtil.java
@@ -199,8 +199,12 @@ public class IndexUtil {
 
     private static boolean isEmptyKeyValue(PTable table, ColumnReference ref) {
         byte[] emptyKeyValueCF = SchemaUtil.getEmptyColumnFamily(table);
-        return (Bytes.compareTo(emptyKeyValueCF, ref.getFamily()) == 0 &&
-                Bytes.compareTo(QueryConstants.EMPTY_COLUMN_BYTES, ref.getQualifier()) ==
0);
+        return (Bytes.compareTo(emptyKeyValueCF, 0, emptyKeyValueCF.length, ref.getFamilyWritable()
+                .get(), ref.getFamilyWritable().getOffset(), ref.getFamilyWritable().getLength())
== 0 && Bytes
+                .compareTo(QueryConstants.EMPTY_COLUMN_BYTES, 0,
+                    QueryConstants.EMPTY_COLUMN_BYTES.length, ref.getQualifierWritable().get(),
ref
+                            .getQualifierWritable().getOffset(), ref.getQualifierWritable()
+                            .getLength()) == 0);
     }
 
     public static List<Mutation> generateIndexData(final PTable table, PTable index,


Mime
View raw message