diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java index 64b211e7101..a3f7cd074d0 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -1281,7 +1281,7 @@ public class HConnectionManager { // checking is actually the last region in the table. byte[] endKey = possibleRegion.getRegionInfo().getEndKey(); if (Bytes.equals(endKey, HConstants.EMPTY_END_ROW) || - KeyValue.getRowComparator(tableName).compareRows( + tableName.getRowComparator().compareRows( endKey, 0, endKey.length, row, 0, row.length) > 0) { return possibleRegion; } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ColumnRangeFilter.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ColumnRangeFilter.java index 6094b254044..cb15a71402a 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ColumnRangeFilter.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/filter/ColumnRangeFilter.java @@ -19,6 +19,8 @@ package org.apache.hadoop.hbase.filter; +import static org.apache.hadoop.hbase.util.Bytes.len; + import com.google.common.base.Preconditions; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; @@ -214,8 +216,8 @@ public class ColumnRangeFilter extends FilterBase { public KeyValue getNextKeyHint(KeyValue kv) { return KeyValue.createFirstOnRow(kv.getBuffer(), kv.getRowOffset(), kv .getRowLength(), kv.getBuffer(), kv.getFamilyOffset(), kv - .getFamilyLength(), this.minColumn, 0, this.minColumn == null ? 0 - : this.minColumn.length); + .getFamilyLength(), this.minColumn, 0, len(this.minColumn)); + } @Override diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index a087c55a9c6..e1d17e16916 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -19,6 +19,8 @@ */ package org.apache.hadoop.hbase; +import static org.apache.hadoop.hbase.util.Bytes.len; + import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; @@ -97,22 +99,6 @@ public class KeyValue implements Cell, HeapSize, Cloneable { */ public static final KVComparator META_COMPARATOR = new MetaComparator(); - /** - * Get the appropriate row comparator for the specified table. - * - * Hopefully we can get rid of this, I added this here because it's replacing - * something in HSK. We should move completely off of that. - * - * @param tableName The table name. - * @return The comparator. - */ - public static KeyComparator getRowComparator(TableName tableName) { - if(TableName.META_TABLE_NAME.equals(tableName)) { - return META_COMPARATOR.getRawComparator(); - } - return COMPARATOR.getRawComparator(); - } - /** Size of the key length field in bytes*/ public static final int KEY_LENGTH_SIZE = Bytes.SIZEOF_INT; @@ -317,7 +303,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable { * @param timestamp */ public KeyValue(final byte [] row, final long timestamp) { - this(row, timestamp, Type.Maximum); + this(row, null, null, timestamp, Type.Maximum, null); } /** @@ -393,31 +379,8 @@ public class KeyValue implements Cell, HeapSize, Cloneable { public KeyValue(final byte[] row, final byte[] family, final byte[] qualifier, final long timestamp, Type type, final byte[] value) { - this(row, family, qualifier, 0, qualifier==null ? 0 : qualifier.length, - timestamp, type, value, 0, value==null ? 0 : value.length); - } - - /** - * Constructs KeyValue structure filled with specified values. - * @param row row key - * @param family family name - * @param qualifier column qualifier - * @param qoffset qualifier offset - * @param qlength qualifier length - * @param timestamp version timestamp - * @param type key type - * @param value column value - * @param voffset value offset - * @param vlength value length - * @throws IllegalArgumentException - */ - public KeyValue(byte [] row, byte [] family, - byte [] qualifier, int qoffset, int qlength, long timestamp, Type type, - byte [] value, int voffset, int vlength) { - this(row, 0, row==null ? 0 : row.length, - family, 0, family==null ? 0 : family.length, - qualifier, qoffset, qlength, timestamp, type, - value, voffset, vlength); + this(row, 0, len(row), family, 0, len(family), qualifier, 0, len(qualifier), + timestamp, type, value, 0, len(value)); } /** @@ -529,85 +492,6 @@ public class KeyValue implements Cell, HeapSize, Cloneable { return bytes; } - /** - * Constructs KeyValue structure filled with specified values. Uses the provided buffer as its - * backing data buffer. - *
- * Column is split into two fields, family and qualifier. - * - * @param buffer the bytes buffer to use - * @param row row key - * @param roffset row offset - * @param rlength row length - * @param family family name - * @param foffset family offset - * @param flength family length - * @param qualifier column qualifier - * @param qoffset qualifier offset - * @param qlength qualifier length - * @param timestamp version timestamp - * @param type key type - * @param value column value - * @param voffset value offset - * @param vlength value length - * @throws IllegalArgumentException an illegal value was passed or there is insufficient space - * remaining in the buffer - */ - public KeyValue(byte [] buffer, - final byte [] row, final int roffset, final int rlength, - final byte [] family, final int foffset, final int flength, - final byte [] qualifier, final int qoffset, final int qlength, - final long timestamp, final Type type, - final byte [] value, final int voffset, final int vlength) { - - this(buffer, 0, - row, roffset, rlength, - family, foffset, flength, - qualifier, qoffset, qlength, - timestamp, type, - value, voffset, vlength); - } - - /** - * Constructs KeyValue structure filled with specified values. Uses the provided buffer as the - * data buffer. - *
- * Column is split into two fields, family and qualifier.
- *
- * @param buffer the bytes buffer to use
- * @param boffset buffer offset
- * @param row row key
- * @param roffset row offset
- * @param rlength row length
- * @param family family name
- * @param foffset family offset
- * @param flength family length
- * @param qualifier column qualifier
- * @param qoffset qualifier offset
- * @param qlength qualifier length
- * @param timestamp version timestamp
- * @param type key type
- * @param value column value
- * @param voffset value offset
- * @param vlength value length
- * @throws IllegalArgumentException an illegal value was passed or there is insufficient space
- * remaining in the buffer
- */
- public KeyValue(byte [] buffer, final int boffset,
- final byte [] row, final int roffset, final int rlength,
- final byte [] family, final int foffset, final int flength,
- final byte [] qualifier, final int qoffset, final int qlength,
- final long timestamp, final Type type,
- final byte [] value, final int voffset, final int vlength) {
-
- this.bytes = buffer;
- this.length = writeByteArray(buffer, boffset,
- row, roffset, rlength,
- family, foffset, flength, qualifier, qoffset, qlength,
- timestamp, type, value, voffset, vlength);
- this.offset = boffset;
- }
-
/**
* Checks the parameters passed to a constructor.
*
@@ -683,7 +567,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
* @throws IllegalArgumentException an illegal value was passed or there is insufficient space
* remaining in the buffer
*/
- static int writeByteArray(byte [] buffer, final int boffset,
+ private static int writeByteArray(byte [] buffer, final int boffset,
final byte [] row, final int roffset, final int rlength,
final byte [] family, final int foffset, int flength,
final byte [] qualifier, final int qoffset, int qlength,
@@ -1083,7 +967,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
/**
* @return Family offset
*/
- public int getFamilyOffset(int rlength) {
+ private int getFamilyOffset(int rlength) {
return this.offset + ROW_OFFSET + Bytes.SIZEOF_SHORT + rlength + Bytes.SIZEOF_BYTE;
}
@@ -1121,7 +1005,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
/**
* @return Qualifier offset
*/
- public int getQualifierOffset(int foffset) {
+ private int getQualifierOffset(int foffset) {
return foffset + getFamilyLength(foffset);
}
@@ -1136,7 +1020,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
/**
* @return Qualifier length
*/
- public int getQualifierLength(int rlength, int flength) {
+ private int getQualifierLength(int rlength, int flength) {
return getKeyLength() - (int) getKeyDataStructureSize(rlength, flength, 0);
}
@@ -1152,7 +1036,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
/**
* @return Column (family + qualifier) length
*/
- public int getTotalColumnLength(int rlength, int foffset) {
+ private int getTotalColumnLength(int rlength, int foffset) {
int flength = getFamilyLength(foffset);
int qlength = getQualifierLength(rlength,flength);
return flength + qlength;
@@ -1169,7 +1053,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
* @param keylength Pass if you have it to save on a int creation.
* @return Timestamp offset
*/
- public int getTimestampOffset(final int keylength) {
+ private int getTimestampOffset(final int keylength) {
return getKeyOffset() + keylength - TIMESTAMP_TYPE_SIZE;
}
@@ -1298,8 +1182,9 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
/**
* @return Type of this KeyValue.
*/
+ @Deprecated
public byte getType() {
- return getType(getKeyLength());
+ return getTypeByte();
}
/**
@@ -1307,15 +1192,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
*/
@Override
public byte getTypeByte() {
- return getType(getKeyLength());
- }
-
- /**
- * @param keylength Pass if you have it to save on a int creation.
- * @return Type of this KeyValue.
- */
- byte getType(final int keylength) {
- return this.bytes[this.offset + keylength - 1 + ROW_OFFSET];
+ return this.bytes[this.offset + getKeyLength() - 1 + ROW_OFFSET];
}
/**
@@ -1332,21 +1209,21 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
*/
public boolean isDeleteType() {
// TODO: Fix this method name vis-a-vis isDelete!
- return getType() == Type.Delete.getCode();
+ return getTypeByte() == Type.Delete.getCode();
}
/**
* @return True if this KV is a delete family type.
*/
public boolean isDeleteFamily() {
- return getType() == Type.DeleteFamily.getCode();
+ return getTypeByte() == Type.DeleteFamily.getCode();
}
/**
* @return True if this KV is a delete family-version type.
*/
public boolean isDeleteFamilyVersion() {
- return getType() == Type.DeleteFamilyVersion.getCode();
+ return getTypeByte() == Type.DeleteFamilyVersion.getCode();
}
/**
@@ -1354,7 +1231,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
* @return True if this KV is a delete family or column type.
*/
public boolean isDeleteColumnOrFamily() {
- int t = getType();
+ int t = getTypeByte();
return t == Type.DeleteColumn.getCode() || t == Type.DeleteFamily.getCode();
}
@@ -1539,8 +1416,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
* @return True if column matches
*/
public boolean matchingColumn(final byte[] family, final byte[] qualifier) {
- return matchingColumn(family, 0, family == null ? 0 : family.length,
- qualifier, 0, qualifier == null ? 0 : qualifier.length);
+ return matchingColumn(family, 0, len(family), qualifier, 0, len(qualifier));
}
/**
@@ -2252,12 +2128,11 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
throw new IllegalArgumentException("Buffer size " + (buffer.length - boffset) + " < " +
iLength);
}
- return new KeyValue(buffer, boffset,
- row, roffset, rlength,
- family, foffset, flength,
- qualifier, qoffset, qlength,
- HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum,
+
+ int len = writeByteArray(buffer, boffset, row, roffset, rlength, family, foffset, flength,
+ qualifier, qoffset, qlength, HConstants.LATEST_TIMESTAMP, KeyValue.Type.Maximum,
null, 0, 0);
+ return new KeyValue(buffer, boffset, len);
}
/**
@@ -2533,6 +2408,7 @@ public class KeyValue implements Cell, HeapSize, Cloneable {
public static class KeyComparator
implements RawComparator