From edb4716c7e89eead8463214c58be4e6bc93534eb Mon Sep 17 00:00:00 2001 From: Andy Yang Date: Tue, 19 Sep 2017 09:26:18 -0700 Subject: [PATCH] HBASE-13844 Move static helper methods from KeyValue into CellUtils --- .../java/org/apache/hadoop/hbase/HRegionInfo.java | 3 +- .../hadoop/hbase/client/RegionInfoBuilder.java | 3 +- .../java/org/apache/hadoop/hbase/CellUtil.java | 35 + .../java/org/apache/hadoop/hbase/KeyValue.java | 810 +-------------------- .../java/org/apache/hadoop/hbase/TableName.java | 16 - .../hadoop/hbase/mapreduce/TableInputFormat.java | 4 +- .../org/apache/hadoop/hbase/rest/RowResource.java | 19 +- .../hadoop/hbase/rest/RowResultGenerator.java | 4 +- .../hadoop/hbase/rest/ScannerResultGenerator.java | 4 +- .../hadoop/hbase/rest/client/RemoteHTable.java | 2 +- .../hadoop/hbase/rest/TestScannerResource.java | 4 +- .../hadoop/hbase/rest/TestScannersWithFilters.java | 2 +- .../hadoop/hbase/rest/TestScannersWithLabels.java | 4 +- .../hadoop/hbase/rest/TestTableResource.java | 4 +- .../hadoop/hbase/io/hfile/FixedFileTrailer.java | 6 +- .../org/apache/hadoop/hbase/HBaseTestCase.java | 2 +- .../hadoop/hbase/thrift/IncrementCoalescer.java | 4 +- .../hadoop/hbase/thrift/ThriftServerRunner.java | 35 +- .../hadoop/hbase/thrift/ThriftUtilities.java | 6 +- 19 files changed, 94 insertions(+), 873 deletions(-) diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java index cc8873396e..753e31693e 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -31,7 +31,6 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.client.RegionInfoBuilder; import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.client.RegionInfo; -import org.apache.hadoop.hbase.KeyValue.KVComparator; import org.apache.hadoop.hbase.exceptions.DeserializationException; import org.apache.hadoop.hbase.master.RegionState; import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; @@ -690,7 +689,7 @@ public class HRegionInfo implements RegionInfo, Comparable { * @deprecated Use Region#getCellComparator(). deprecated for hbase 2.0, remove for hbase 3.0 */ @Deprecated - public KVComparator getComparator() { + public CellComparator getComparator() { return isMetaRegion()? KeyValue.META_COMPARATOR: KeyValue.COMPARATOR; } diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionInfoBuilder.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionInfoBuilder.java index a76767d57d..562daa8a58 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionInfoBuilder.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/RegionInfoBuilder.java @@ -27,6 +27,7 @@ import org.apache.hadoop.hbase.util.Bytes; import org.apache.yetus.audience.InterfaceAudience; import java.util.Arrays; +import org.apache.hadoop.hbase.CellComparator; @InterfaceAudience.Private public class RegionInfoBuilder { @@ -616,7 +617,7 @@ public class RegionInfoBuilder { * @deprecated Use Region#getCellComparator(). deprecated for hbase 2.0, remove for hbase 3.0 */ @Deprecated - public KeyValue.KVComparator getComparator() { + public CellComparator getComparator() { return isMetaRegion()? KeyValue.META_COMPARATOR: KeyValue.COMPARATOR; } diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java index a3029f8669..c0c6f7794b 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/CellUtil.java @@ -20,6 +20,8 @@ package org.apache.hadoop.hbase; import static org.apache.hadoop.hbase.HConstants.EMPTY_BYTE_ARRAY; import static org.apache.hadoop.hbase.Tag.TAG_LENGTH_SIZE; +import static org.apache.hadoop.hbase.KeyValue.COLUMN_FAMILY_DELIMITER; +import static org.apache.hadoop.hbase.KeyValue.getDelimiter; import java.io.DataOutputStream; import java.io.IOException; @@ -126,6 +128,39 @@ public final class CellUtil { return output; } + /** + * Splits a column in {@code family:qualifier} form into separate byte arrays. An empty qualifier + * (ie, {@code fam:}) is parsed as { fam, EMPTY_BYTE_ARRAY } while no delimiter (ie, + * {@code fam}) is parsed as an array of one element, { fam }. + *

+ * Don't forget, HBase DOES support empty qualifiers. (see HBASE-9549) + *

+ *

+ * Not recommend to be used as this is old-style API. + *

+ * @param c The column. + * @return The parsed column. + */ + public static byte [][] parseColumn(byte [] c) { + final int index = getDelimiter(c, 0, c.length, COLUMN_FAMILY_DELIMITER); + if (index == -1) { + // If no delimiter, return array of size 1 + return new byte [][] { c }; + } else if(index == c.length - 1) { + // family with empty qualifier, return array size 2 + byte [] family = new byte[c.length-1]; + System.arraycopy(c, 0, family, 0, family.length); + return new byte [][] { family, HConstants.EMPTY_BYTE_ARRAY}; + } + // Family and column, return array size 2 + final byte [][] result = new byte [2][]; + result[0] = new byte [index]; + System.arraycopy(c, 0, result[0], 0, index); + final int len = c.length - (index + 1); + result[1] = new byte[len]; + System.arraycopy(c, index + 1 /* Skip delimiter */, result[1], 0, len); + return result; + } /******************** copyTo **********************************/ 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 ae95738342..74962132eb 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 @@ -23,9 +23,7 @@ import static org.apache.hadoop.hbase.util.Bytes.len; import java.io.DataInput; import java.io.DataOutput; -import java.io.EOFException; import java.io.IOException; -import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; import java.util.ArrayList; @@ -41,11 +39,9 @@ import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.util.ByteBufferUtils; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.ClassSize; -import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.RawComparator; import org.apache.hadoop.hbase.shaded.com.google.common.annotations.VisibleForTesting; - /** * An HBase Key/Value. This is the fundamental HBase Type. *

@@ -98,27 +94,11 @@ public class KeyValue implements ExtendedCell { public static final byte[] COLUMN_FAMILY_DELIM_ARRAY = new byte[]{COLUMN_FAMILY_DELIMITER}; - /** - * Comparator for plain key/values; i.e. non-catalog table key/values. Works on Key portion - * of KeyValue only. - * @deprecated Use {@link CellComparator#COMPARATOR} instead - */ - @Deprecated - public static final KVComparator COMPARATOR = new KVComparator(); - /** - * A {@link KVComparator} for hbase:meta catalog table - * {@link KeyValue}s. - * @deprecated Use {@link CellComparator#META_COMPARATOR} instead - */ - @Deprecated - public static final KVComparator META_COMPARATOR = new MetaComparator(); + public static final CellComparator COMPARATOR = CellComparator.COMPARATOR; - /** - * Needed for Bloom Filters. - * * @deprecated Use {@link Bytes#BYTES_RAWCOMPARATOR} instead - */ - @Deprecated - public static final KVComparator RAW_COMPARATOR = new RawBytesComparator(); + public static final CellComparator META_COMPARATOR = CellComparator.META_COMPARATOR; + + public static final RawComparator RAW_COMPARATOR = Bytes.BYTES_RAWCOMPARATOR; /** Size of the key length field in bytes*/ public static final int KEY_LENGTH_SIZE = Bytes.SIZEOF_INT; @@ -1509,14 +1489,6 @@ public class KeyValue implements ExtendedCell { } /** - * @return Type of this KeyValue. - */ - @Deprecated - public byte getType() { - return getTypeByte(); - } - - /** * @return KeyValue.TYPE byte representation */ @Override @@ -1525,16 +1497,6 @@ public class KeyValue implements ExtendedCell { } /** - * @return True if a delete type, a {@link KeyValue.Type#Delete} or - * a {KeyValue.Type#DeleteFamily} or a {@link KeyValue.Type#DeleteColumn} - * KeyValue type. - */ - @Deprecated // use CellUtil#isDelete - public boolean isDelete() { - return KeyValue.isDelete(getType()); - } - - /** * This returns the offset where the tag actually starts. */ @Override @@ -1602,40 +1564,6 @@ public class KeyValue implements ExtendedCell { } /** - * Splits a column in {@code family:qualifier} form into separate byte arrays. An empty qualifier - * (ie, {@code fam:}) is parsed as { fam, EMPTY_BYTE_ARRAY } while no delimiter (ie, - * {@code fam}) is parsed as an array of one element, { fam }. - *

- * Don't forget, HBase DOES support empty qualifiers. (see HBASE-9549) - *

- *

- * Not recommend to be used as this is old-style API. - *

- * @param c The column. - * @return The parsed column. - */ - public static byte [][] parseColumn(byte [] c) { - final int index = getDelimiter(c, 0, c.length, COLUMN_FAMILY_DELIMITER); - if (index == -1) { - // If no delimiter, return array of size 1 - return new byte [][] { c }; - } else if(index == c.length - 1) { - // family with empty qualifier, return array size 2 - byte [] family = new byte[c.length-1]; - System.arraycopy(c, 0, family, 0, family.length); - return new byte [][] { family, HConstants.EMPTY_BYTE_ARRAY}; - } - // Family and column, return array size 2 - final byte [][] result = new byte [2][]; - result[0] = new byte [index]; - System.arraycopy(c, 0, result[0], 0, index); - final int len = c.length - (index + 1); - result[1] = new byte[len]; - System.arraycopy(c, index + 1 /* Skip delimiter */, result[1], 0, len); - return result; - } - - /** * Makes a column in family:qualifier form from separate byte arrays. *

* Not recommended for usage as this is old-style API. @@ -1690,639 +1618,6 @@ public class KeyValue implements ExtendedCell { } /** - * A {@link KVComparator} for hbase:meta catalog table - * {@link KeyValue}s. - * @deprecated : {@link CellComparator#META_COMPARATOR} to be used - */ - @Deprecated - public static class MetaComparator extends KVComparator { - /** - * Compare key portion of a {@link KeyValue} for keys in hbase:meta - * table. - */ - @Override - public int compare(final Cell left, final Cell right) { - return CellComparator.META_COMPARATOR.compareKeyIgnoresMvcc(left, right); - } - - @Override - public int compareOnlyKeyPortion(Cell left, Cell right) { - return compare(left, right); - } - - @Override - public int compareRows(byte [] left, int loffset, int llength, - byte [] right, int roffset, int rlength) { - int leftDelimiter = getDelimiter(left, loffset, llength, - HConstants.DELIMITER); - int rightDelimiter = getDelimiter(right, roffset, rlength, - HConstants.DELIMITER); - // Compare up to the delimiter - int lpart = (leftDelimiter < 0 ? llength :leftDelimiter - loffset); - int rpart = (rightDelimiter < 0 ? rlength :rightDelimiter - roffset); - int result = Bytes.compareTo(left, loffset, lpart, right, roffset, rpart); - if (result != 0) { - return result; - } else { - if (leftDelimiter < 0 && rightDelimiter >= 0) { - return -1; - } else if (rightDelimiter < 0 && leftDelimiter >= 0) { - return 1; - } else if (leftDelimiter < 0 && rightDelimiter < 0) { - return 0; - } - } - // Compare middle bit of the row. - // Move past delimiter - leftDelimiter++; - rightDelimiter++; - int leftFarDelimiter = getDelimiterInReverse(left, leftDelimiter, - llength - (leftDelimiter - loffset), HConstants.DELIMITER); - int rightFarDelimiter = getDelimiterInReverse(right, - rightDelimiter, rlength - (rightDelimiter - roffset), - HConstants.DELIMITER); - // Now compare middlesection of row. - lpart = (leftFarDelimiter < 0 ? llength + loffset: leftFarDelimiter) - leftDelimiter; - rpart = (rightFarDelimiter < 0 ? rlength + roffset: rightFarDelimiter)- rightDelimiter; - result = super.compareRows(left, leftDelimiter, lpart, right, rightDelimiter, rpart); - if (result != 0) { - return result; - } else { - if (leftDelimiter < 0 && rightDelimiter >= 0) { - return -1; - } else if (rightDelimiter < 0 && leftDelimiter >= 0) { - return 1; - } else if (leftDelimiter < 0 && rightDelimiter < 0) { - return 0; - } - } - // Compare last part of row, the rowid. - leftFarDelimiter++; - rightFarDelimiter++; - result = Bytes.compareTo(left, leftFarDelimiter, llength - (leftFarDelimiter - loffset), - right, rightFarDelimiter, rlength - (rightFarDelimiter - roffset)); - return result; - } - - /** - * Don't do any fancy Block Index splitting tricks. - */ - @Override - public byte[] getShortMidpointKey(final byte[] leftKey, final byte[] rightKey) { - return Arrays.copyOf(rightKey, rightKey.length); - } - - /** - * The HFileV2 file format's trailer contains this class name. We reinterpret this and - * instantiate the appropriate comparator. - * TODO: With V3 consider removing this. - * @return legacy class name for FileFileTrailer#comparatorClassName - */ - @Override - public String getLegacyKeyComparatorName() { - return "org.apache.hadoop.hbase.KeyValue$MetaKeyComparator"; - } - - @Override - protected Object clone() throws CloneNotSupportedException { - return new MetaComparator(); - } - - /** - * Override the row key comparison to parse and compare the meta row key parts. - */ - @Override - protected int compareRowKey(final Cell l, final Cell r) { - byte[] left = l.getRowArray(); - int loffset = l.getRowOffset(); - int llength = l.getRowLength(); - byte[] right = r.getRowArray(); - int roffset = r.getRowOffset(); - int rlength = r.getRowLength(); - return compareRows(left, loffset, llength, right, roffset, rlength); - } - } - - /** - * Compare KeyValues. When we compare KeyValues, we only compare the Key - * portion. This means two KeyValues with same Key but different Values are - * considered the same as far as this Comparator is concerned. - * @deprecated : Use {@link CellComparator}. - */ - @Deprecated - public static class KVComparator implements RawComparator, SamePrefixComparator { - - /** - * The HFileV2 file format's trailer contains this class name. We reinterpret this and - * instantiate the appropriate comparator. - * TODO: With V3 consider removing this. - * @return legacy class name for FileFileTrailer#comparatorClassName - */ - public String getLegacyKeyComparatorName() { - return "org.apache.hadoop.hbase.KeyValue$KeyComparator"; - } - - @Override // RawComparator - public int compare(byte[] l, int loff, int llen, byte[] r, int roff, int rlen) { - return compareFlatKey(l,loff,llen, r,roff,rlen); - } - - - /** - * Compares the only the user specified portion of a Key. This is overridden by MetaComparator. - * @param left - * @param right - * @return 0 if equal, <0 if left smaller, >0 if right smaller - */ - protected int compareRowKey(final Cell left, final Cell right) { - return CellComparator.COMPARATOR.compareRows(left, right); - } - - /** - * Compares left to right assuming that left,loffset,llength and right,roffset,rlength are - * full KVs laid out in a flat byte[]s. - * @param left - * @param loffset - * @param llength - * @param right - * @param roffset - * @param rlength - * @return 0 if equal, <0 if left smaller, >0 if right smaller - */ - public int compareFlatKey(byte[] left, int loffset, int llength, - byte[] right, int roffset, int rlength) { - // Compare row - short lrowlength = Bytes.toShort(left, loffset); - short rrowlength = Bytes.toShort(right, roffset); - int compare = compareRows(left, loffset + Bytes.SIZEOF_SHORT, - lrowlength, right, roffset + Bytes.SIZEOF_SHORT, rrowlength); - if (compare != 0) { - return compare; - } - - // Compare the rest of the two KVs without making any assumptions about - // the common prefix. This function will not compare rows anyway, so we - // don't need to tell it that the common prefix includes the row. - return compareWithoutRow(0, left, loffset, llength, right, roffset, - rlength, rrowlength); - } - - public int compareFlatKey(byte[] left, byte[] right) { - return compareFlatKey(left, 0, left.length, right, 0, right.length); - } - - // compare a key against row/fam/qual/ts/type - public int compareKey(Cell cell, - byte[] row, int roff, int rlen, - byte[] fam, int foff, int flen, - byte[] col, int coff, int clen, - long ts, byte type) { - - int compare = compareRows( - cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(), - row, roff, rlen); - if (compare != 0) { - return compare; - } - // If the column is not specified, the "minimum" key type appears the - // latest in the sorted order, regardless of the timestamp. This is used - // for specifying the last key/value in a given row, because there is no - // "lexicographically last column" (it would be infinitely long). The - // "maximum" key type does not need this behavior. - if (cell.getFamilyLength() + cell.getQualifierLength() == 0 - && cell.getTypeByte() == Type.Minimum.getCode()) { - // left is "bigger", i.e. it appears later in the sorted order - return 1; - } - if (flen+clen == 0 && type == Type.Minimum.getCode()) { - return -1; - } - - compare = compareFamilies( - cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(), - fam, foff, flen); - if (compare != 0) { - return compare; - } - compare = compareColumns( - cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength(), - col, coff, clen); - if (compare != 0) { - return compare; - } - // Next compare timestamps. - compare = compareTimestamps(cell.getTimestamp(), ts); - if (compare != 0) { - return compare; - } - - // Compare types. Let the delete types sort ahead of puts; i.e. types - // of higher numbers sort before those of lesser numbers. Maximum (255) - // appears ahead of everything, and minimum (0) appears after - // everything. - return (0xff & type) - (0xff & cell.getTypeByte()); - } - - public int compareOnlyKeyPortion(Cell left, Cell right) { - return CellComparator.COMPARATOR.compareKeyIgnoresMvcc(left, right); - } - - /** - * Compares the Key of a cell -- with fields being more significant in this order: - * rowkey, colfam/qual, timestamp, type, mvcc - */ - @Override - public int compare(final Cell left, final Cell right) { - int compare = CellComparator.COMPARATOR.compare(left, right); - return compare; - } - - public int compareTimestamps(final Cell left, final Cell right) { - return CellComparator.compareTimestamps(left, right); - } - - /** - * @param left - * @param right - * @return Result comparing rows. - */ - public int compareRows(final Cell left, final Cell right) { - return compareRows(left.getRowArray(),left.getRowOffset(), left.getRowLength(), - right.getRowArray(), right.getRowOffset(), right.getRowLength()); - } - - /** - * Get the b[],o,l for left and right rowkey portions and compare. - * @param left - * @param loffset - * @param llength - * @param right - * @param roffset - * @param rlength - * @return 0 if equal, <0 if left smaller, >0 if right smaller - */ - public int compareRows(byte [] left, int loffset, int llength, - byte [] right, int roffset, int rlength) { - return Bytes.compareTo(left, loffset, llength, right, roffset, rlength); - } - - int compareColumns(final Cell left, final short lrowlength, final Cell right, - final short rrowlength) { - return CellComparator.compareColumns(left, right); - } - - protected int compareColumns( - byte [] left, int loffset, int llength, final int lfamilylength, - byte [] right, int roffset, int rlength, final int rfamilylength) { - // Compare family portion first. - int diff = Bytes.compareTo(left, loffset, lfamilylength, - right, roffset, rfamilylength); - if (diff != 0) { - return diff; - } - // Compare qualifier portion - return Bytes.compareTo(left, loffset + lfamilylength, - llength - lfamilylength, - right, roffset + rfamilylength, rlength - rfamilylength); - } - - static int compareTimestamps(final long ltimestamp, final long rtimestamp) { - // The below older timestamps sorting ahead of newer timestamps looks - // wrong but it is intentional. This way, newer timestamps are first - // found when we iterate over a memstore and newer versions are the - // first we trip over when reading from a store file. - if (ltimestamp < rtimestamp) { - return 1; - } else if (ltimestamp > rtimestamp) { - return -1; - } - return 0; - } - - /** - * Overridden - * @param commonPrefix - * @param left - * @param loffset - * @param llength - * @param right - * @param roffset - * @param rlength - * @return 0 if equal, <0 if left smaller, >0 if right smaller - */ - @Override // SamePrefixComparator - public int compareIgnoringPrefix(int commonPrefix, byte[] left, - int loffset, int llength, byte[] right, int roffset, int rlength) { - // Compare row - short lrowlength = Bytes.toShort(left, loffset); - short rrowlength; - - int comparisonResult = 0; - if (commonPrefix < ROW_LENGTH_SIZE) { - // almost nothing in common - rrowlength = Bytes.toShort(right, roffset); - comparisonResult = compareRows(left, loffset + ROW_LENGTH_SIZE, - lrowlength, right, roffset + ROW_LENGTH_SIZE, rrowlength); - } else { // the row length is the same - rrowlength = lrowlength; - if (commonPrefix < ROW_LENGTH_SIZE + rrowlength) { - // The rows are not the same. Exclude the common prefix and compare - // the rest of the two rows. - int common = commonPrefix - ROW_LENGTH_SIZE; - comparisonResult = compareRows( - left, loffset + common + ROW_LENGTH_SIZE, lrowlength - common, - right, roffset + common + ROW_LENGTH_SIZE, rrowlength - common); - } - } - if (comparisonResult != 0) { - return comparisonResult; - } - - assert lrowlength == rrowlength; - return compareWithoutRow(commonPrefix, left, loffset, llength, right, - roffset, rlength, lrowlength); - } - - /** - * Compare columnFamily, qualifier, timestamp, and key type (everything - * except the row). This method is used both in the normal comparator and - * the "same-prefix" comparator. Note that we are assuming that row portions - * of both KVs have already been parsed and found identical, and we don't - * validate that assumption here. - * @param commonPrefix - * the length of the common prefix of the two key-values being - * compared, including row length and row - */ - private int compareWithoutRow(int commonPrefix, byte[] left, int loffset, - int llength, byte[] right, int roffset, int rlength, short rowlength) { - /*** - * KeyValue Format and commonLength: - * |_keyLen_|_valLen_|_rowLen_|_rowKey_|_famiLen_|_fami_|_Quali_|.... - * ------------------|-------commonLength--------|-------------- - */ - int commonLength = ROW_LENGTH_SIZE + FAMILY_LENGTH_SIZE + rowlength; - - // commonLength + TIMESTAMP_TYPE_SIZE - int commonLengthWithTSAndType = TIMESTAMP_TYPE_SIZE + commonLength; - // ColumnFamily + Qualifier length. - int lcolumnlength = llength - commonLengthWithTSAndType; - int rcolumnlength = rlength - commonLengthWithTSAndType; - - byte ltype = left[loffset + (llength - 1)]; - byte rtype = right[roffset + (rlength - 1)]; - - // If the column is not specified, the "minimum" key type appears the - // latest in the sorted order, regardless of the timestamp. This is used - // for specifying the last key/value in a given row, because there is no - // "lexicographically last column" (it would be infinitely long). The - // "maximum" key type does not need this behavior. - if (lcolumnlength == 0 && ltype == Type.Minimum.getCode()) { - // left is "bigger", i.e. it appears later in the sorted order - return 1; - } - if (rcolumnlength == 0 && rtype == Type.Minimum.getCode()) { - return -1; - } - - int lfamilyoffset = commonLength + loffset; - int rfamilyoffset = commonLength + roffset; - - // Column family length. - int lfamilylength = left[lfamilyoffset - 1]; - int rfamilylength = right[rfamilyoffset - 1]; - // If left family size is not equal to right family size, we need not - // compare the qualifiers. - boolean sameFamilySize = (lfamilylength == rfamilylength); - int common = 0; - if (commonPrefix > 0) { - common = Math.max(0, commonPrefix - commonLength); - if (!sameFamilySize) { - // Common should not be larger than Math.min(lfamilylength, - // rfamilylength). - common = Math.min(common, Math.min(lfamilylength, rfamilylength)); - } else { - common = Math.min(common, Math.min(lcolumnlength, rcolumnlength)); - } - } - if (!sameFamilySize) { - // comparing column family is enough. - return Bytes.compareTo(left, lfamilyoffset + common, lfamilylength - - common, right, rfamilyoffset + common, rfamilylength - common); - } - // Compare family & qualifier together. - final int comparison = Bytes.compareTo(left, lfamilyoffset + common, - lcolumnlength - common, right, rfamilyoffset + common, - rcolumnlength - common); - if (comparison != 0) { - return comparison; - } - - //// - // Next compare timestamps. - long ltimestamp = Bytes.toLong(left, - loffset + (llength - TIMESTAMP_TYPE_SIZE)); - long rtimestamp = Bytes.toLong(right, - roffset + (rlength - TIMESTAMP_TYPE_SIZE)); - int compare = compareTimestamps(ltimestamp, rtimestamp); - if (compare != 0) { - return compare; - } - - // Compare types. Let the delete types sort ahead of puts; i.e. types - // of higher numbers sort before those of lesser numbers. Maximum (255) - // appears ahead of everything, and minimum (0) appears after - // everything. - return (0xff & rtype) - (0xff & ltype); - } - - protected int compareFamilies(final byte[] left, final int loffset, final int lfamilylength, - final byte[] right, final int roffset, final int rfamilylength) { - int diff = Bytes.compareTo(left, loffset, lfamilylength, right, roffset, rfamilylength); - return diff; - } - - protected int compareColumns(final byte[] left, final int loffset, final int lquallength, - final byte[] right, final int roffset, final int rquallength) { - int diff = Bytes.compareTo(left, loffset, lquallength, right, roffset, rquallength); - return diff; - } - /** - * Compares the row and column of two keyvalues for equality - * @param left - * @param right - * @return True if same row and column. - */ - public boolean matchingRowColumn(final Cell left, - final Cell right) { - short lrowlength = left.getRowLength(); - short rrowlength = right.getRowLength(); - - // TsOffset = end of column data. just comparing Row+CF length of each - if ((left.getRowLength() + left.getFamilyLength() + left.getQualifierLength()) != (right - .getRowLength() + right.getFamilyLength() + right.getQualifierLength())) { - return false; - } - - if (!matchingRows(left, lrowlength, right, rrowlength)) { - return false; - } - - int lfoffset = left.getFamilyOffset(); - int rfoffset = right.getFamilyOffset(); - int lclength = left.getQualifierLength(); - int rclength = right.getQualifierLength(); - int lfamilylength = left.getFamilyLength(); - int rfamilylength = right.getFamilyLength(); - int diff = compareFamilies(left.getFamilyArray(), lfoffset, lfamilylength, - right.getFamilyArray(), rfoffset, rfamilylength); - if (diff != 0) { - return false; - } else { - diff = compareColumns(left.getQualifierArray(), left.getQualifierOffset(), lclength, - right.getQualifierArray(), right.getQualifierOffset(), rclength); - return diff == 0; - } - } - - /** - * Compares the row of two keyvalues for equality - * @param left - * @param right - * @return True if rows match. - */ - public boolean matchingRows(final Cell left, final Cell right) { - short lrowlength = left.getRowLength(); - short rrowlength = right.getRowLength(); - return matchingRows(left, lrowlength, right, rrowlength); - } - - /** - * @param left - * @param lrowlength - * @param right - * @param rrowlength - * @return True if rows match. - */ - private boolean matchingRows(final Cell left, final short lrowlength, - final Cell right, final short rrowlength) { - return lrowlength == rrowlength && - matchingRows(left.getRowArray(), left.getRowOffset(), lrowlength, - right.getRowArray(), right.getRowOffset(), rrowlength); - } - - /** - * Compare rows. Just calls Bytes.equals, but it's good to have this encapsulated. - * @param left Left row array. - * @param loffset Left row offset. - * @param llength Left row length. - * @param right Right row array. - * @param roffset Right row offset. - * @param rlength Right row length. - * @return Whether rows are the same row. - */ - public boolean matchingRows(final byte [] left, final int loffset, final int llength, - final byte [] right, final int roffset, final int rlength) { - return Bytes.equals(left, loffset, llength, right, roffset, rlength); - } - - public byte[] calcIndexKey(byte[] lastKeyOfPreviousBlock, byte[] firstKeyInBlock) { - byte[] fakeKey = getShortMidpointKey(lastKeyOfPreviousBlock, firstKeyInBlock); - if (compareFlatKey(fakeKey, firstKeyInBlock) > 0) { - LOG.error("Unexpected getShortMidpointKey result, fakeKey:" - + Bytes.toStringBinary(fakeKey) + ", firstKeyInBlock:" - + Bytes.toStringBinary(firstKeyInBlock)); - return firstKeyInBlock; - } - if (lastKeyOfPreviousBlock != null && compareFlatKey(lastKeyOfPreviousBlock, fakeKey) >= 0) { - LOG.error("Unexpected getShortMidpointKey result, lastKeyOfPreviousBlock:" + - Bytes.toStringBinary(lastKeyOfPreviousBlock) + ", fakeKey:" + - Bytes.toStringBinary(fakeKey)); - return firstKeyInBlock; - } - return fakeKey; - } - - /** - * This is a HFile block index key optimization. - * @param leftKey - * @param rightKey - * @return 0 if equal, <0 if left smaller, >0 if right smaller - * @deprecated Since 0.99.2; - */ - @Deprecated - public byte[] getShortMidpointKey(final byte[] leftKey, final byte[] rightKey) { - if (rightKey == null) { - throw new IllegalArgumentException("rightKey can not be null"); - } - if (leftKey == null) { - return Arrays.copyOf(rightKey, rightKey.length); - } - if (compareFlatKey(leftKey, rightKey) >= 0) { - throw new IllegalArgumentException("Unexpected input, leftKey:" + Bytes.toString(leftKey) - + ", rightKey:" + Bytes.toString(rightKey)); - } - - short leftRowLength = Bytes.toShort(leftKey, 0); - short rightRowLength = Bytes.toShort(rightKey, 0); - int leftCommonLength = ROW_LENGTH_SIZE + FAMILY_LENGTH_SIZE + leftRowLength; - int rightCommonLength = ROW_LENGTH_SIZE + FAMILY_LENGTH_SIZE + rightRowLength; - int leftCommonLengthWithTSAndType = TIMESTAMP_TYPE_SIZE + leftCommonLength; - int rightCommonLengthWithTSAndType = TIMESTAMP_TYPE_SIZE + rightCommonLength; - int leftColumnLength = leftKey.length - leftCommonLengthWithTSAndType; - int rightColumnLength = rightKey.length - rightCommonLengthWithTSAndType; - // rows are equal - if (leftRowLength == rightRowLength && compareRows(leftKey, ROW_LENGTH_SIZE, leftRowLength, - rightKey, ROW_LENGTH_SIZE, rightRowLength) == 0) { - // Compare family & qualifier together. - int comparison = Bytes.compareTo(leftKey, leftCommonLength, leftColumnLength, rightKey, - rightCommonLength, rightColumnLength); - // same with "row + family + qualifier", return rightKey directly - if (comparison == 0) { - return Arrays.copyOf(rightKey, rightKey.length); - } - // "family + qualifier" are different, generate a faked key per rightKey - byte[] newKey = Arrays.copyOf(rightKey, rightKey.length); - Bytes.putLong(newKey, rightKey.length - TIMESTAMP_TYPE_SIZE, HConstants.LATEST_TIMESTAMP); - Bytes.putByte(newKey, rightKey.length - TYPE_SIZE, Type.Maximum.getCode()); - return newKey; - } - // rows are different - short minLength = leftRowLength < rightRowLength ? leftRowLength : rightRowLength; - short diffIdx = 0; - while (diffIdx < minLength - && leftKey[ROW_LENGTH_SIZE + diffIdx] == rightKey[ROW_LENGTH_SIZE + diffIdx]) { - diffIdx++; - } - byte[] newRowKey = null; - if (diffIdx >= minLength) { - // leftKey's row is prefix of rightKey's. - newRowKey = new byte[diffIdx + 1]; - System.arraycopy(rightKey, ROW_LENGTH_SIZE, newRowKey, 0, diffIdx + 1); - } else { - int diffByte = leftKey[ROW_LENGTH_SIZE + diffIdx]; - if ((0xff & diffByte) < 0xff && (diffByte + 1) < - (rightKey[ROW_LENGTH_SIZE + diffIdx] & 0xff)) { - newRowKey = new byte[diffIdx + 1]; - System.arraycopy(leftKey, ROW_LENGTH_SIZE, newRowKey, 0, diffIdx); - newRowKey[diffIdx] = (byte) (diffByte + 1); - } else { - newRowKey = new byte[diffIdx + 1]; - System.arraycopy(rightKey, ROW_LENGTH_SIZE, newRowKey, 0, diffIdx + 1); - } - } - return new KeyValue(newRowKey, null, null, HConstants.LATEST_TIMESTAMP, - Type.Maximum).getKey(); - } - - @Override - protected Object clone() throws CloneNotSupportedException { - super.clone(); - return new KVComparator(); - } - - } - - /** * @param b * @return A KeyValue made of a byte array that holds the key-only part. * Needed to convert hfile index members to KeyValues. @@ -2410,34 +1705,6 @@ public class KeyValue implements ExtendedCell { } /** - * Create a KeyValue reading from the raw InputStream. - * Named iscreate so doesn't clash with {@link #create(DataInput)} - * @param in - * @return Created KeyValue or throws an exception - * @throws IOException - * {@link Deprecated} As of 1.2. Use {@link KeyValueUtil#iscreate(InputStream, boolean)} instead. - */ - @Deprecated - public static KeyValue iscreate(final InputStream in) throws IOException { - byte [] intBytes = new byte[Bytes.SIZEOF_INT]; - int bytesRead = 0; - while (bytesRead < intBytes.length) { - int n = in.read(intBytes, bytesRead, intBytes.length - bytesRead); - if (n < 0) { - if (bytesRead == 0) { - throw new EOFException(); - } - throw new IOException("Failed read of int, read " + bytesRead + " bytes"); - } - bytesRead += n; - } - // TODO: perhaps some sanity check is needed here. - byte [] bytes = new byte[Bytes.toInt(intBytes)]; - IOUtils.readFully(in, bytes, 0, bytes.length); - return new KeyValue(bytes, 0, bytes.length); - } - - /** * Write out a KeyValue in the manner in which we used to when KeyValue was a Writable. * @param kv * @param out @@ -2500,9 +1767,9 @@ public class KeyValue implements ExtendedCell { * Comparator that compares row component only of a KeyValue. */ public static class RowOnlyComparator implements Comparator { - final KVComparator comparator; + final CellComparator comparator; - public RowOnlyComparator(final KVComparator c) { + public RowOnlyComparator(final CellComparator c) { this.comparator = c; } @@ -2529,71 +1796,6 @@ public class KeyValue implements ExtendedCell { } /** - * @deprecated Not to be used for any comparsions - */ - @Deprecated - public static class RawBytesComparator extends KVComparator { - /** - * The HFileV2 file format's trailer contains this class name. We reinterpret this and - * instantiate the appropriate comparator. - * TODO: With V3 consider removing this. - * @return legacy class name for FileFileTrailer#comparatorClassName - */ - @Override - public String getLegacyKeyComparatorName() { - return "org.apache.hadoop.hbase.util.Bytes$ByteArrayComparator"; - } - - /** - * @deprecated Since 0.99.2. - */ - @Override - @Deprecated - public int compareFlatKey(byte[] left, int loffset, int llength, byte[] right, - int roffset, int rlength) { - return Bytes.BYTES_RAWCOMPARATOR.compare(left, loffset, llength, right, roffset, rlength); - } - - @Override - public int compare(Cell left, Cell right) { - return compareOnlyKeyPortion(left, right); - } - - @Override - @VisibleForTesting - public int compareOnlyKeyPortion(Cell left, Cell right) { - int c = Bytes.BYTES_RAWCOMPARATOR.compare(left.getRowArray(), left.getRowOffset(), - left.getRowLength(), right.getRowArray(), right.getRowOffset(), right.getRowLength()); - if (c != 0) { - return c; - } - c = Bytes.BYTES_RAWCOMPARATOR.compare(left.getFamilyArray(), left.getFamilyOffset(), - left.getFamilyLength(), right.getFamilyArray(), right.getFamilyOffset(), - right.getFamilyLength()); - if (c != 0) { - return c; - } - c = Bytes.BYTES_RAWCOMPARATOR.compare(left.getQualifierArray(), left.getQualifierOffset(), - left.getQualifierLength(), right.getQualifierArray(), right.getQualifierOffset(), - right.getQualifierLength()); - if (c != 0) { - return c; - } - c = compareTimestamps(left.getTimestamp(), right.getTimestamp()); - if (c != 0) { - return c; - } - return (0xff & left.getTypeByte()) - (0xff & right.getTypeByte()); - } - - @Override - public byte[] calcIndexKey(byte[] lastKeyOfPreviousBlock, byte[] firstKeyInBlock) { - return firstKeyInBlock; - } - - } - - /** * HeapSize implementation * * We do not count the bytes in the rowCache because it should be empty for a KeyValue in the diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java index 79d264faee..74a4c8a360 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/TableName.java @@ -26,7 +26,6 @@ import java.util.concurrent.CopyOnWriteArraySet; import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.util.Bytes; -import org.apache.hadoop.hbase.KeyValue.KVComparator; /** * Immutable POJO class for representing a table name. @@ -536,19 +535,4 @@ public final class TableName implements Comparable { return this.nameAsString.compareTo(tableName.getNameAsString()); } - /** - * Get the appropriate row comparator for this table. - * - * @return The comparator. - * @deprecated The comparator is an internal property of the table. Should - * not have been exposed here - */ - @InterfaceAudience.Private - @Deprecated - public KVComparator getRowComparator() { - if(TableName.META_TABLE_NAME.equals(this)) { - return KeyValue.META_COMPARATOR; - } - return KeyValue.COMPARATOR; - } } diff --git a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormat.java b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormat.java index b25bff596b..9eefac9def 100644 --- a/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormat.java +++ b/hbase-mapreduce/src/main/java/org/apache/hadoop/hbase/mapreduce/TableInputFormat.java @@ -27,7 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; -import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.TableName; import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.client.Connection; @@ -213,7 +213,7 @@ implements Configurable { * @throws IllegalArgumentException When familyAndQualifier is invalid. */ private static void addColumn(Scan scan, byte[] familyAndQualifier) { - byte [][] fq = KeyValue.parseColumn(familyAndQualifier); + byte [][] fq = CellUtil.parseColumn(familyAndQualifier); if (fq.length == 1) { scan.addFamily(fq[0]); } else if (fq.length == 2) { diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java index 199a60c046..2ecf17f3ae 100644 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java +++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RowResource.java @@ -43,7 +43,6 @@ import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HConstants; -import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Append; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Increment; @@ -233,7 +232,7 @@ public class RowResource extends ResourceBase { .type(MIMETYPE_TEXT).entity("Bad request: Column found to be null." + CRLF) .build(); } - byte [][] parts = KeyValue.parseColumn(col); + byte [][] parts = CellUtil.parseColumn(col); if (parts.length != 2) { return Response.status(Response.Status.BAD_REQUEST) .type(MIMETYPE_TEXT).entity("Bad request" + CRLF) @@ -301,7 +300,7 @@ public class RowResource extends ResourceBase { .build(); } Put put = new Put(row); - byte parts[][] = KeyValue.parseColumn(column); + byte parts[][] = CellUtil.parseColumn(column); if (parts.length != 2) { return Response.status(Response.Status.BAD_REQUEST) .type(MIMETYPE_TEXT).entity("Bad request" + CRLF) @@ -390,7 +389,7 @@ public class RowResource extends ResourceBase { delete = new Delete(rowspec.getRow()); for (byte[] column: rowspec.getColumns()) { - byte[][] split = KeyValue.parseColumn(column); + byte[][] split = CellUtil.parseColumn(column); if (rowspec.hasTimestamp()) { if (split.length == 1) { delete.addFamily(split[0], rowspec.getTimestamp()); @@ -473,7 +472,7 @@ public class RowResource extends ResourceBase { boolean retValue; CellModel valueToCheckCell = cellModels.get(cellModelCount - 1); byte[] valueToCheckColumn = valueToCheckCell.getColumn(); - byte[][] valueToPutParts = KeyValue.parseColumn(valueToCheckColumn); + byte[][] valueToPutParts = CellUtil.parseColumn(valueToCheckColumn); if (valueToPutParts.length == 2 && valueToPutParts[1].length > 0) { CellModel valueToPutCell = null; @@ -490,7 +489,7 @@ public class RowResource extends ResourceBase { .build(); } - byte [][] parts = KeyValue.parseColumn(col); + byte [][] parts = CellUtil.parseColumn(col); if (parts.length != 2) { return Response.status(Response.Status.BAD_REQUEST) @@ -606,7 +605,7 @@ public class RowResource extends ResourceBase { .build(); } - parts = KeyValue.parseColumn(col); + parts = CellUtil.parseColumn(col); if (parts.length == 1) { // Only Column Family is specified @@ -623,7 +622,7 @@ public class RowResource extends ResourceBase { } } - parts = KeyValue.parseColumn(valueToDeleteColumn); + parts = CellUtil.parseColumn(valueToDeleteColumn); if (parts.length == 2) { if (parts[1].length != 0) { // To support backcompat of deleting a cell @@ -722,7 +721,7 @@ public class RowResource extends ResourceBase { .type(MIMETYPE_TEXT).entity("Bad request: Column found to be null." + CRLF) .build(); } - byte [][] parts = KeyValue.parseColumn(col); + byte [][] parts = CellUtil.parseColumn(col); if (parts.length != 2) { servlet.getMetrics().incrementFailedAppendRequests(1); return Response.status(Response.Status.BAD_REQUEST) @@ -816,7 +815,7 @@ public class RowResource extends ResourceBase { .type(MIMETYPE_TEXT).entity("Bad request: Column found to be null." + CRLF) .build(); } - byte [][] parts = KeyValue.parseColumn(col); + byte [][] parts = CellUtil.parseColumn(col); if (parts.length != 2) { servlet.getMetrics().incrementFailedIncrementRequests(1); return Response.status(Response.Status.BAD_REQUEST) diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RowResultGenerator.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RowResultGenerator.java index 4cf8492a82..1edd73a063 100644 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RowResultGenerator.java +++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/RowResultGenerator.java @@ -25,10 +25,10 @@ import java.util.NoSuchElementException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.hbase.CellUtil; import org.apache.yetus.audience.InterfaceAudience; import org.apache.hadoop.hbase.Cell; import org.apache.hadoop.hbase.DoNotRetryIOException; -import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Get; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.Table; @@ -50,7 +50,7 @@ public class RowResultGenerator extends ResultGenerator { Get get = new Get(rowspec.getRow()); if (rowspec.hasColumns()) { for (byte[] col: rowspec.getColumns()) { - byte[][] split = KeyValue.parseColumn(col); + byte[][] split = CellUtil.parseColumn(col); if (split.length == 1) { get.addFamily(split[0]); } else if (split.length == 2) { diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerResultGenerator.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerResultGenerator.java index 50208cf61d..ece4f1249b 100644 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerResultGenerator.java +++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/ScannerResultGenerator.java @@ -25,7 +25,7 @@ import java.util.Iterator; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.hbase.Cell; -import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.TableNotEnabledException; import org.apache.hadoop.hbase.TableNotFoundException; import org.apache.hadoop.hbase.UnknownScannerException; @@ -80,7 +80,7 @@ public class ScannerResultGenerator extends ResultGenerator { if (rowspec.hasColumns()) { byte[][] columns = rowspec.getColumns(); for (byte[] column: columns) { - byte[][] split = KeyValue.parseColumn(column); + byte[][] split = CellUtil.parseColumn(column); if (split.length == 1) { scan.addFamily(split[0]); } else if (split.length == 2) { diff --git a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java index 8899044783..b15537a88c 100644 --- a/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java +++ b/hbase-rest/src/main/java/org/apache/hadoop/hbase/rest/client/RemoteHTable.java @@ -177,7 +177,7 @@ public class RemoteHTable implements Table { for (RowModel row: model.getRows()) { List kvs = new ArrayList<>(row.getCells().size()); for (CellModel cell: row.getCells()) { - byte[][] split = KeyValue.parseColumn(cell.getColumn()); + byte[][] split = CellUtil.parseColumn(cell.getColumn()); byte[] column = split[0]; byte[] qualifier = null; if (split.length == 1) { diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java index 2b47c4f9ae..2b2e5e3700 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannerResource.java @@ -44,7 +44,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Connection; @@ -93,7 +93,7 @@ public class TestScannerResource { throws IOException { Random rng = new Random(); byte[] k = new byte[3]; - byte [][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(column)); + byte [][] famAndQf = CellUtil.parseColumn(Bytes.toBytes(column)); List puts = new ArrayList<>(); for (byte b1 = 'a'; b1 < 'z'; b1++) { for (byte b2 = 'a'; b2 < 'z'; b2++) { diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java index 5e57e983d6..c8bbc24149 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithFilters.java @@ -295,7 +295,7 @@ public class TestScannersWithFilters { for (CellModel cell: cells) { assertTrue("Row mismatch", Bytes.equals(rowModel.getKey(), CellUtil.cloneRow(kvs[idx]))); - byte[][] split = KeyValue.parseColumn(cell.getColumn()); + byte[][] split = CellUtil.parseColumn(cell.getColumn()); assertTrue("Family mismatch", Bytes.equals(split[0], CellUtil.cloneFamily(kvs[idx]))); assertTrue("Qualifier mismatch", diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithLabels.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithLabels.java index 2d5a0c629e..6ac8e87cb9 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithLabels.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestScannersWithLabels.java @@ -21,7 +21,7 @@ import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.Connection; @@ -92,7 +92,7 @@ public class TestScannersWithLabels { private static int insertData(TableName tableName, String column, double prob) throws IOException { byte[] k = new byte[3]; - byte[][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(column)); + byte[][] famAndQf = CellUtil.parseColumn(Bytes.toBytes(column)); List puts = new ArrayList<>(9); for (int i = 0; i < 9; i++) { diff --git a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java index 826468070f..26891774b7 100644 --- a/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java +++ b/hbase-rest/src/test/java/org/apache/hadoop/hbase/rest/TestTableResource.java @@ -39,7 +39,7 @@ import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HTableDescriptor; -import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; import org.apache.hadoop.hbase.client.Admin; @@ -99,7 +99,7 @@ public class TestTableResource { htd.addFamily(new HColumnDescriptor(COLUMN_FAMILY)); admin.createTable(htd); byte[] k = new byte[3]; - byte [][] famAndQf = KeyValue.parseColumn(Bytes.toBytes(COLUMN)); + byte [][] famAndQf = CellUtil.parseColumn(Bytes.toBytes(COLUMN)); List puts = new ArrayList<>(); for (byte b1 = 'a'; b1 < 'z'; b1++) { for (byte b2 = 'a'; b2 < 'z'; b2++) { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java index 6628e742bd..71193327e4 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/FixedFileTrailer.java @@ -559,14 +559,14 @@ public class FixedFileTrailer { private static Class getComparatorClass(String comparatorClassName) throws IOException { Class comparatorKlass; - if (comparatorClassName.equals(KeyValue.COMPARATOR.getLegacyKeyComparatorName()) + if (comparatorClassName.equals("org.apache.hadoop.hbase.KeyValue$KeyComparator") || comparatorClassName.equals(KeyValue.COMPARATOR.getClass().getName())) { comparatorKlass = CellComparator.class; - } else if (comparatorClassName.equals(KeyValue.META_COMPARATOR.getLegacyKeyComparatorName()) + } else if (comparatorClassName.equals("org.apache.hadoop.hbase.KeyValue$MetaKeyComparator") || comparatorClassName.equals(KeyValue.META_COMPARATOR.getClass().getName())) { comparatorKlass = MetaCellComparator.class; } else if (comparatorClassName.equals(KeyValue.RAW_COMPARATOR.getClass().getName()) - || comparatorClassName.equals(KeyValue.RAW_COMPARATOR.getLegacyKeyComparatorName())) { + || comparatorClassName.equals("org.apache.hadoop.hbase.util.Bytes$ByteArrayComparator")) { // When the comparator to be used is Bytes.BYTES_RAWCOMPARATOR, we just return null from here // Bytes.BYTES_RAWCOMPARATOR is not a CellComparator comparatorKlass = null; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestCase.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestCase.java index 153f36b0e4..32cffc0887 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestCase.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseTestCase.java @@ -326,7 +326,7 @@ public abstract class HBaseTestCase extends TestCase { } } byte[][] split = - KeyValue.parseColumn(Bytes.toBytes(sb.toString())); + CellUtil.parseColumn(Bytes.toBytes(sb.toString())); if(split.length == 1) { byte[] qualifier = new byte[0]; put.addColumn(split[0], qualifier, t); diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/IncrementCoalescer.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/IncrementCoalescer.java index edd251db59..3f0530a338 100644 --- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/IncrementCoalescer.java +++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/IncrementCoalescer.java @@ -34,7 +34,7 @@ import java.util.concurrent.atomic.LongAdder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.client.Table; import org.apache.hadoop.hbase.thrift.ThriftServerRunner.HBaseHandler; import org.apache.hadoop.hbase.thrift.generated.TIncrement; @@ -196,7 +196,7 @@ public class IncrementCoalescer implements IncrementCoalescerMBean { } private boolean internalQueueTincrement(TIncrement inc) throws TException { - byte[][] famAndQf = KeyValue.parseColumn(inc.getColumn()); + byte[][] famAndQf = CellUtil.parseColumn(inc.getColumn()); if (famAndQf.length != 2) return false; return internalQueueIncrement(inc.getTable(), inc.getRow(), famAndQf[0], famAndQf[1], diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java index 48a365d361..83ecf74885 100644 --- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java +++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftServerRunner.java @@ -59,6 +59,7 @@ import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HRegionLocation; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; +import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableName; @@ -921,7 +922,7 @@ public class ThriftServerRunner implements Runnable { ByteBuffer tableName, ByteBuffer row, ByteBuffer column, Map attributes) throws IOError { - byte [][] famAndQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famAndQf = CellUtil.parseColumn(getBytes(column)); if (famAndQf.length == 1) { return get(tableName, row, famAndQf[0], null, attributes); } @@ -966,7 +967,7 @@ public class ThriftServerRunner implements Runnable { @Override public List getVer(ByteBuffer tableName, ByteBuffer row, ByteBuffer column, int numVersions, Map attributes) throws IOError { - byte [][] famAndQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famAndQf = CellUtil.parseColumn(getBytes(column)); if(famAndQf.length == 1) { return getVer(tableName, row, famAndQf[0], null, numVersions, attributes); } @@ -1012,7 +1013,7 @@ public class ThriftServerRunner implements Runnable { @Override public List getVerTs(ByteBuffer tableName, ByteBuffer row, ByteBuffer column, long timestamp, int numVersions, Map attributes) throws IOError { - byte [][] famAndQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famAndQf = CellUtil.parseColumn(getBytes(column)); if (famAndQf.length == 1) { return getVerTs(tableName, row, famAndQf[0], null, timestamp, numVersions, attributes); } @@ -1099,7 +1100,7 @@ public class ThriftServerRunner implements Runnable { Get get = new Get(getBytes(row)); addAttributes(get, attributes); for(ByteBuffer column : columns) { - byte [][] famAndQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famAndQf = CellUtil.parseColumn(getBytes(column)); if (famAndQf.length == 1) { get.addFamily(famAndQf[0]); } else { @@ -1165,7 +1166,7 @@ public class ThriftServerRunner implements Runnable { if (columns != null) { for(ByteBuffer column : columns) { - byte [][] famAndQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famAndQf = CellUtil.parseColumn(getBytes(column)); if (famAndQf.length == 1) { get.addFamily(famAndQf[0]); } else { @@ -1205,7 +1206,7 @@ public class ThriftServerRunner implements Runnable { table = getTable(tableName); Delete delete = new Delete(getBytes(row)); addAttributes(delete, attributes); - byte [][] famAndQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famAndQf = CellUtil.parseColumn(getBytes(column)); if (famAndQf.length == 1) { delete.addFamily(famAndQf[0], timestamp); } else { @@ -1318,7 +1319,7 @@ public class ThriftServerRunner implements Runnable { // I apologize for all this mess :) for (Mutation m : mutations) { - byte[][] famAndQf = KeyValue.parseColumn(getBytes(m.column)); + byte[][] famAndQf = CellUtil.parseColumn(getBytes(m.column)); if (m.isDelete) { if (famAndQf.length == 1) { delete.addFamily(famAndQf[0], timestamp); @@ -1377,7 +1378,7 @@ public class ThriftServerRunner implements Runnable { Put put = new Put(row, timestamp); addAttributes(put, attributes); for (Mutation m : mutations) { - byte[][] famAndQf = KeyValue.parseColumn(getBytes(m.column)); + byte[][] famAndQf = CellUtil.parseColumn(getBytes(m.column)); if (m.isDelete) { // no qualifier, family only. if (famAndQf.length == 1) { @@ -1431,7 +1432,7 @@ public class ThriftServerRunner implements Runnable { public long atomicIncrement( ByteBuffer tableName, ByteBuffer row, ByteBuffer column, long amount) throws IOError, IllegalArgument, TException { - byte [][] famAndQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famAndQf = CellUtil.parseColumn(getBytes(column)); if(famAndQf.length == 1) { return atomicIncrement(tableName, row, famAndQf[0], HConstants.EMPTY_BYTE_ARRAY, amount); } @@ -1523,7 +1524,7 @@ public class ThriftServerRunner implements Runnable { } if (tScan.isSetColumns() && tScan.getColumns().size() != 0) { for(ByteBuffer column : tScan.getColumns()) { - byte [][] famQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famQf = CellUtil.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { @@ -1563,7 +1564,7 @@ public class ThriftServerRunner implements Runnable { addAttributes(scan, attributes); if(columns != null && columns.size() != 0) { for(ByteBuffer column : columns) { - byte [][] famQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famQf = CellUtil.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { @@ -1593,7 +1594,7 @@ public class ThriftServerRunner implements Runnable { addAttributes(scan, attributes); if(columns != null && columns.size() != 0) { for(ByteBuffer column : columns) { - byte [][] famQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famQf = CellUtil.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { @@ -1627,7 +1628,7 @@ public class ThriftServerRunner implements Runnable { scan.setFilter(f); if (columns != null && columns.size() != 0) { for(ByteBuffer column : columns) { - byte [][] famQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famQf = CellUtil.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { @@ -1657,7 +1658,7 @@ public class ThriftServerRunner implements Runnable { scan.setTimeRange(0, timestamp); if (columns != null && columns.size() != 0) { for (ByteBuffer column : columns) { - byte [][] famQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famQf = CellUtil.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { @@ -1688,7 +1689,7 @@ public class ThriftServerRunner implements Runnable { scan.setTimeRange(0, timestamp); if (columns != null && columns.size() != 0) { for (ByteBuffer column : columns) { - byte [][] famQf = KeyValue.parseColumn(getBytes(column)); + byte [][] famQf = CellUtil.parseColumn(getBytes(column)); if(famQf.length == 1) { scan.addFamily(famQf[0]); } else { @@ -1866,7 +1867,7 @@ public class ThriftServerRunner implements Runnable { put = new Put(getBytes(row), HConstants.LATEST_TIMESTAMP); addAttributes(put, attributes); - byte[][] famAndQf = KeyValue.parseColumn(getBytes(mput.column)); + byte[][] famAndQf = CellUtil.parseColumn(getBytes(mput.column)); put.addImmutable(famAndQf[0], famAndQf[1], mput.value != null ? getBytes(mput.value) : HConstants.EMPTY_BYTE_ARRAY); @@ -1880,7 +1881,7 @@ public class ThriftServerRunner implements Runnable { Table table = null; try { table = getTable(tableName); - byte[][] famAndQf = KeyValue.parseColumn(getBytes(column)); + byte[][] famAndQf = CellUtil.parseColumn(getBytes(column)); return table.checkAndPut(getBytes(row), famAndQf[0], famAndQf[1], value != null ? getBytes(value) : HConstants.EMPTY_BYTE_ARRAY, put); } catch (IOException e) { diff --git a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftUtilities.java b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftUtilities.java index 9510040fd9..12e22ff63b 100644 --- a/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftUtilities.java +++ b/hbase-thrift/src/main/java/org/apache/hadoop/hbase/thrift/ThriftUtilities.java @@ -67,7 +67,7 @@ public class ThriftUtilities { if (in.name == null || !in.name.hasRemaining()) { throw new IllegalArgument("column name is empty"); } - byte [] parsedName = KeyValue.parseColumn(Bytes.getBytes(in.name))[0]; + byte [] parsedName = CellUtil.parseColumn(Bytes.getBytes(in.name))[0]; HColumnDescriptor col = new HColumnDescriptor(parsedName) .setMaxVersions(in.maxVersions) .setCompressionType(comp) @@ -203,7 +203,7 @@ public class ThriftUtilities { */ public static Increment incrementFromThrift(TIncrement tincrement) { Increment inc = new Increment(tincrement.getRow()); - byte[][] famAndQf = KeyValue.parseColumn(tincrement.getColumn()); + byte[][] famAndQf = CellUtil.parseColumn(tincrement.getColumn()); if (famAndQf.length != 2) return null; inc.addColumn(famAndQf[0], famAndQf[1], tincrement.getAmmount()); return inc; @@ -227,7 +227,7 @@ public class ThriftUtilities { int length = columns.size(); for (int i = 0; i < length; i++) { - byte[][] famAndQf = KeyValue.parseColumn(getBytes(columns.get(i))); + byte[][] famAndQf = CellUtil.parseColumn(getBytes(columns.get(i))); append.addColumn(famAndQf[0], famAndQf[1], getBytes(values.get(i))); } return append; -- 2.11.0