From c4e4056cab3a8e82f7a7cdf613e1739bceed2127 Mon Sep 17 00:00:00 2001 From: Andy Yang Date: Thu, 14 Sep 2017 20:20:46 -0700 Subject: [PATCH] HBASE-13844 Move static helper methods from KeyValue into CellUtils --- .../java/org/apache/hadoop/hbase/HRegionInfo.java | 12 +- .../hadoop/hbase/filter/TestComparators.java | 12 +- .../hadoop/hbase/filter/TestKeyOnlyFilter.java | 2 +- .../hbase/shaded/protobuf/TestProtobufUtil.java | 6 +- .../java/org/apache/hadoop/hbase/CellUtil.java | 35 + .../java/org/apache/hadoop/hbase/KeyValue.java | 828 +-------------------- .../java/org/apache/hadoop/hbase/KeyValueUtil.java | 4 +- .../java/org/apache/hadoop/hbase/TableName.java | 16 - .../hadoop/hbase/io/encoding/RowIndexCodecV1.java | 2 +- .../hadoop/hbase/TestByteBufferKeyValue.java | 18 +- .../apache/hadoop/hbase/TestCellComparator.java | 6 +- .../java/org/apache/hadoop/hbase/TestCellUtil.java | 12 +- .../java/org/apache/hadoop/hbase/TestKeyValue.java | 4 +- .../hadoop/hbase/io/TestTagCompressionContext.java | 6 +- .../hadoop/hbase/util/RedundantKVGenerator.java | 6 +- .../util/TestByteRangeWithKVSerialization.java | 4 +- .../hadoop/hbase/mapreduce/TableInputFormat.java | 4 +- .../hbase/codec/prefixtree/PrefixTreeCodec.java | 2 +- .../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 | 6 +- .../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 +- .../org/apache/hadoop/hbase/TestSerialization.java | 2 +- .../hbase/filter/TestSingleColumnValueFilter.java | 34 +- .../hbase/io/encoding/TestDataBlockEncoders.java | 2 +- .../hbase/io/encoding/TestPrefixTreeEncoding.java | 2 +- .../hadoop/hbase/protobuf/TestProtobufUtil.java | 6 +- .../hbase/regionserver/DataBlockEncodingTool.java | 18 +- .../hadoop/hbase/regionserver/TestHStoreFile.java | 4 +- .../wal/TestWALCellCodecWithCompression.java | 6 +- .../hadoop/hbase/wal/TestWALReaderOnSecureWAL.java | 4 +- .../hadoop/hbase/thrift/IncrementCoalescer.java | 4 +- .../hadoop/hbase/thrift/ThriftServerRunner.java | 35 +- .../hadoop/hbase/thrift/ThriftUtilities.java | 6 +- 40 files changed, 179 insertions(+), 978 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 d470ffa2f4..564c810924 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 @@ -30,7 +30,7 @@ import org.apache.commons.logging.LogFactory; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.client.RegionReplicaUtil; -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.com.google.protobuf.UnsafeByteOperations; @@ -869,16 +869,6 @@ public class HRegionInfo implements Comparable { } /** - * @return Comparator to use comparing {@link KeyValue}s. - * @deprecated Use Region#getCellComparator(). deprecated for hbase 2.0, remove for hbase 3.0 - */ - @Deprecated - public KVComparator getComparator() { - return isMetaRegion()? - KeyValue.META_COMPARATOR: KeyValue.COMPARATOR; - } - - /** * Convert a HRegionInfo to the protobuf RegionInfo * * @return the converted RegionInfo diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestComparators.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestComparators.java index 0c69eced2d..37f2b5d693 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestComparators.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestComparators.java @@ -50,18 +50,18 @@ public class TestComparators { byte[] v2 = Bytes.toBytes(l2); // Row compare KeyValue kv = new KeyValue(r1, f, q1, v1); - ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); + ByteBuffer buffer = ByteBuffer.wrap(kv.getRowArray()); Cell bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); ByteArrayComparable comparable = new BinaryComparator(r1); assertEquals(0, CellComparator.compareRow(bbCell, comparable)); assertEquals(0, CellComparator.compareRow(kv, comparable)); kv = new KeyValue(r0, f, q1, v1); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertTrue(CellComparator.compareRow(bbCell, comparable) > 0); assertTrue(CellComparator.compareRow(kv, comparable) > 0); kv = new KeyValue(r2, f, q1, v1); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertTrue(CellComparator.compareRow(bbCell, comparable) < 0); assertTrue(CellComparator.compareRow(kv, comparable) < 0); @@ -70,12 +70,12 @@ public class TestComparators { assertEquals(0, CellComparator.compareQualifier(bbCell, comparable)); assertEquals(0, CellComparator.compareQualifier(kv, comparable)); kv = new KeyValue(r2, f, q2, v1); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(0, CellComparator.compareQualifier(bbCell, comparable)); assertEquals(0, CellComparator.compareQualifier(kv, comparable)); kv = new KeyValue(r2, f, q3, v1); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertTrue(CellComparator.compareQualifier(bbCell, comparable) < 0); assertTrue(CellComparator.compareQualifier(kv, comparable) < 0); @@ -84,7 +84,7 @@ public class TestComparators { assertEquals(0, CellComparator.compareValue(bbCell, comparable)); assertEquals(0, CellComparator.compareValue(kv, comparable)); kv = new KeyValue(r1, f, q1, v2); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertTrue(CellComparator.compareValue(bbCell, comparable) < 0); assertTrue(CellComparator.compareValue(kv, comparable) < 0); diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestKeyOnlyFilter.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestKeyOnlyFilter.java index f957b592f7..4864a42daf 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestKeyOnlyFilter.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/filter/TestKeyOnlyFilter.java @@ -63,7 +63,7 @@ public class TestKeyOnlyFilter { KeyValue kv = new KeyValue(r, f, q, 0, q.length, 1234L, Type.Put, v, 0, v.length, tags); - ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); + ByteBuffer buffer = ByteBuffer.wrap(kv.getRowArray()); ByteBufferKeyValue bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); diff --git a/hbase-client/src/test/java/org/apache/hadoop/hbase/shaded/protobuf/TestProtobufUtil.java b/hbase-client/src/test/java/org/apache/hadoop/hbase/shaded/protobuf/TestProtobufUtil.java index 0c12648fe2..107e9a677a 100644 --- a/hbase-client/src/test/java/org/apache/hadoop/hbase/shaded/protobuf/TestProtobufUtil.java +++ b/hbase-client/src/test/java/org/apache/hadoop/hbase/shaded/protobuf/TestProtobufUtil.java @@ -252,9 +252,9 @@ public class TestProtobufUtil { KeyValue kv3 = new KeyValue(Bytes.toBytes("ccc"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), new byte[30]); byte[] arr = new byte[kv1.getLength() + kv2.getLength() + kv3.getLength()]; - System.arraycopy(kv1.getBuffer(), kv1.getOffset(), arr, 0, kv1.getLength()); - System.arraycopy(kv2.getBuffer(), kv2.getOffset(), arr, kv1.getLength(), kv2.getLength()); - System.arraycopy(kv3.getBuffer(), kv3.getOffset(), arr, kv1.getLength() + kv2.getLength(), + System.arraycopy(kv1.getRowArray(), kv1.getOffset(), arr, 0, kv1.getLength()); + System.arraycopy(kv2.getRowArray(), kv2.getOffset(), arr, kv1.getLength(), kv2.getLength()); + System.arraycopy(kv3.getRowArray(), kv3.getOffset(), arr, kv1.getLength() + kv2.getLength(), kv3.getLength()); ByteBuffer dbb = ByteBuffer.allocateDirect(arr.length); dbb.put(arr); 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 d1a72b79a0..2b81f2db8a 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 98cf9cb1da..c3885ab89c 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,8 @@ import org.apache.hadoop.hbase.classification.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 +93,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; @@ -1237,15 +1216,6 @@ public class KeyValue implements ExtendedCell { //--------------------------------------------------------------------------- /** - * @return The byte array backing this KeyValue. - * @deprecated Since 0.98.0. Use Cell Interface instead. Do not presume single backing buffer. - */ - @Deprecated - public byte [] getBuffer() { - return this.bytes; - } - - /** * @return Offset into {@link #getBuffer()} at which this KeyValue starts. */ public int getOffset() { @@ -1286,7 +1256,7 @@ public class KeyValue implements ExtendedCell { } public String getKeyString() { - return Bytes.toStringBinary(getBuffer(), getKeyOffset(), getKeyLength()); + return Bytes.toStringBinary(getRowArray(), getKeyOffset(), getKeyLength()); } /** @@ -1441,7 +1411,7 @@ public class KeyValue implements ExtendedCell { * @return True if this KeyValue has a LATEST_TIMESTAMP timestamp. */ public boolean isLatestTimestamp() { - return Bytes.equals(getBuffer(), getTimestampOffset(), Bytes.SIZEOF_LONG, + return Bytes.equals(getRowArray(), getTimestampOffset(), Bytes.SIZEOF_LONG, HConstants.LATEST_TIMESTAMP_BYTES, 0, Bytes.SIZEOF_LONG); } @@ -1485,7 +1455,7 @@ public class KeyValue implements ExtendedCell { public byte [] getKey() { int keylength = getKeyLength(); byte [] key = new byte[keylength]; - System.arraycopy(getBuffer(), getKeyOffset(), key, 0, keylength); + System.arraycopy(getRowArray(), getKeyOffset(), key, 0, keylength); return key; } @@ -1508,14 +1478,6 @@ public class KeyValue implements ExtendedCell { } /** - * @return Type of this KeyValue. - */ - @Deprecated - public byte getType() { - return getTypeByte(); - } - - /** * @return KeyValue.TYPE byte representation */ @Override @@ -1524,16 +1486,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 @@ -1601,40 +1553,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. @@ -1689,639 +1607,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. @@ -2409,34 +1694,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 @@ -2449,7 +1706,7 @@ public class KeyValue implements ExtendedCell { // work for all implementations. int length = kv.getLength(); out.writeInt(length); - out.write(kv.getBuffer(), kv.getOffset(), length); + out.write(kv.getRowArray(), kv.getOffset(), length); return length + Bytes.SIZEOF_INT; } @@ -2499,9 +1756,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; } @@ -2528,71 +1785,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/KeyValueUtil.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java index 35f5225cba..b00e5dea82 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValueUtil.java @@ -199,7 +199,7 @@ public class KeyValueUtil { final boolean includeMvccVersion) { // keep pushing the limit out. assume enough capacity bb.limit(bb.position() + kv.getLength()); - bb.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); + bb.put(kv.getRowArray(), kv.getOffset(), kv.getLength()); if (includeMvccVersion) { int numMvccVersionBytes = WritableUtils.getVIntSize(kv.getSequenceId()); ByteBufferUtils.extendLimit(bb, numMvccVersionBytes); @@ -514,7 +514,7 @@ public class KeyValueUtil { // work for all implementations. int length = kv.getLength(); out.writeInt(length); - out.write(kv.getBuffer(), kv.getOffset(), length); + out.write(kv.getRowArray(), kv.getOffset(), length); return length + Bytes.SIZEOF_INT; } 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 347709833b..4c06dd591a 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.hadoop.hbase.classification.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-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexCodecV1.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexCodecV1.java index 0f8ea017d0..172ef8af1d 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexCodecV1.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/encoding/RowIndexCodecV1.java @@ -120,7 +120,7 @@ public class RowIndexCodecV1 extends AbstractDataBlockEncoder { DataOutputStream out = new DataOutputStream(baos); for (Cell cell : kvs) { KeyValue currentCell = KeyValueUtil.copyToNewKeyValue(cell); - out.write(currentCell.getBuffer(), currentCell.getOffset(), + out.write(currentCell.getRowArray(), currentCell.getOffset(), currentCell.getLength()); if (includesMvcc) { WritableUtils.writeVLong(out, cell.getSequenceId()); diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestByteBufferKeyValue.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestByteBufferKeyValue.java index ff6c4f746a..bec9699aea 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestByteBufferKeyValue.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestByteBufferKeyValue.java @@ -54,8 +54,8 @@ public class TestByteBufferKeyValue { @Test public void testByteBufferBackedKeyValue() throws Exception { KeyValue kvCell = new KeyValue(row1, fam1, qual1, 0l, Type.Put, row1); - ByteBuffer buf = ByteBuffer.allocateDirect(kvCell.getBuffer().length); - ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getBuffer(), 0, kvCell.getBuffer().length); + ByteBuffer buf = ByteBuffer.allocateDirect(kvCell.getRowArray().length); + ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getRowArray(), 0, kvCell.getRowArray().length); ByteBufferCell offheapKV = new ByteBufferKeyValue(buf, 0, buf.capacity(), 0l); assertEquals( ROW1, @@ -97,8 +97,8 @@ public class TestByteBufferKeyValue { assertEquals(Type.Put.getCode(), offheapKV.getTypeByte()); kvCell = new KeyValue(row1, fam2, qual2, 0l, Type.Put, row1); - buf = ByteBuffer.allocateDirect(kvCell.getBuffer().length); - ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getBuffer(), 0, kvCell.getBuffer().length); + buf = ByteBuffer.allocateDirect(kvCell.getRowArray().length); + ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getRowArray(), 0, kvCell.getRowArray().length); offheapKV = new ByteBufferKeyValue(buf, 0, buf.capacity(), 0l); assertEquals( FAM2, @@ -110,8 +110,8 @@ public class TestByteBufferKeyValue { offheapKV.getQualifierPosition(), offheapKV.getQualifierLength())); byte[] nullQualifier = new byte[0]; kvCell = new KeyValue(row1, fam1, nullQualifier, 0L, Type.Put, row1); - buf = ByteBuffer.allocateDirect(kvCell.getBuffer().length); - ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getBuffer(), 0, kvCell.getBuffer().length); + buf = ByteBuffer.allocateDirect(kvCell.getRowArray().length); + ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getRowArray(), 0, kvCell.getRowArray().length); offheapKV = new ByteBufferKeyValue(buf, 0, buf.capacity(), 0l); assertEquals( ROW1, @@ -136,8 +136,8 @@ public class TestByteBufferKeyValue { @Test public void testByteBufferBackedKeyValueWithTags() throws Exception { KeyValue kvCell = new KeyValue(row1, fam1, qual1, 0l, Type.Put, row1, tags); - ByteBuffer buf = ByteBuffer.allocateDirect(kvCell.getBuffer().length); - ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getBuffer(), 0, kvCell.getBuffer().length); + ByteBuffer buf = ByteBuffer.allocateDirect(kvCell.getRowArray().length); + ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getRowArray(), 0, kvCell.getRowArray().length); ByteBufferCell offheapKV = new ByteBufferKeyValue(buf, 0, buf.capacity(), 0l); assertEquals( ROW1, @@ -176,7 +176,7 @@ public class TestByteBufferKeyValue { public void testGetKeyMethods() throws Exception { KeyValue kvCell = new KeyValue(row1, fam1, qual1, 0l, Type.Put, row1, tags); ByteBuffer buf = ByteBuffer.allocateDirect(kvCell.getKeyLength()); - ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getBuffer(), kvCell.getKeyOffset(), + ByteBufferUtils.copyFromArrayToBuffer(buf, kvCell.getRowArray(), kvCell.getKeyOffset(), kvCell.getKeyLength()); ByteBufferCell offheapKeyOnlyKV = new ByteBufferKeyOnlyKeyValue(buf, 0, buf.capacity()); assertEquals( diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java index 791b9ee45b..4646e5b36f 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellComparator.java @@ -100,15 +100,15 @@ public class TestCellComparator { byte[] q2 = Bytes.toBytes("qual2"); byte[] v = Bytes.toBytes("val1"); KeyValue kv = new KeyValue(r1, f1, q1, v); - ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); + ByteBuffer buffer = ByteBuffer.wrap(kv.getRowArray()); Cell bbCell1 = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); kv = new KeyValue(r2, f1, q1, v); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); Cell bbCell2 = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(0, CellComparator.compareColumns(bbCell1, bbCell2)); assertEquals(0, CellComparator.compareColumns(bbCell1, kv)); kv = new KeyValue(r2, f1, q2, v); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); Cell bbCell3 = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(0, CellComparator.compareFamilies(bbCell2, bbCell3)); assertTrue(CellComparator.compareQualifiers(bbCell2, bbCell3) < 0); diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellUtil.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellUtil.java index bbc7a3101f..8a6a67ed21 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellUtil.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestCellUtil.java @@ -414,7 +414,7 @@ public class TestCellUtil { byte[] v = Bytes.toBytes("val1"); byte[] tags = Bytes.toBytes("tag1"); KeyValue kv = new KeyValue(r, f, q, 0, q.length, 1234L, Type.Put, v, 0, v.length, tags); - ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); + ByteBuffer buffer = ByteBuffer.wrap(kv.getRowArray()); Cell bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); byte[] rDest = CellUtil.cloneRow(bbCell); assertTrue(Bytes.equals(r, rDest)); @@ -438,10 +438,10 @@ public class TestCellUtil { byte[] v = Bytes.toBytes("val1"); byte[] tags = Bytes.toBytes("tag1"); KeyValue kv = new KeyValue(r, f, q1, 0, q1.length, 1234L, Type.Put, v, 0, v.length, tags); - ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); + ByteBuffer buffer = ByteBuffer.wrap(kv.getRowArray()); Cell bbCell1 = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); kv = new KeyValue(r, f, q2, 0, q2.length, 1234L, Type.Put, v, 0, v.length, tags); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); Cell bbCell2 = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertTrue(CellUtil.matchingRows(bbCell1, bbCell2)); assertTrue(CellUtil.matchingRows(kv, bbCell2)); @@ -471,20 +471,20 @@ public class TestCellUtil { long vl = 10981L; byte[] v = Bytes.toBytes(vl); KeyValue kv = new KeyValue(r, f, q, v); - ByteBuffer buffer = ByteBuffer.wrap(kv.getBuffer()); + ByteBuffer buffer = ByteBuffer.wrap(kv.getRowArray()); Cell bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(ri, CellUtil.getRowAsInt(bbCell)); assertEquals(vl, CellUtil.getValueAsLong(bbCell)); double vd = 3005.5; v = Bytes.toBytes(vd); kv = new KeyValue(r, f, q, v); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(vd, CellUtil.getValueAsDouble(bbCell), 0.0); BigDecimal bd = new BigDecimal(9999); v = Bytes.toBytes(bd); kv = new KeyValue(r, f, q, v); - buffer = ByteBuffer.wrap(kv.getBuffer()); + buffer = ByteBuffer.wrap(kv.getRowArray()); bbCell = new ByteBufferKeyValue(buffer, 0, buffer.remaining()); assertEquals(bd, CellUtil.getValueAsBigDecimal(bbCell)); } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java index 562c00848c..8e9ad59e4a 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/TestKeyValue.java @@ -408,12 +408,12 @@ public class TestKeyValue extends TestCase { int endingPadding = 20; int keyLen = kv.getKeyLength(); byte[] tmpArr = new byte[initialPadding + endingPadding + keyLen]; - System.arraycopy(kv.getBuffer(), kv.getKeyOffset(), tmpArr, + System.arraycopy(kv.getRowArray(), kv.getKeyOffset(), tmpArr, initialPadding, keyLen); KeyValue kvFromKey = KeyValueUtil.createKeyValueFromKey(tmpArr, initialPadding, keyLen); assertEquals(keyLen, kvFromKey.getKeyLength()); - assertEquals(KeyValue.ROW_OFFSET + keyLen, kvFromKey.getBuffer().length); + assertEquals(KeyValue.ROW_OFFSET + keyLen, kvFromKey.getRowArray().length); System.err.println("kv=" + kv); System.err.println("kvFromKey=" + kvFromKey); assertEquals(kvFromKey.toString(), diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java index dddd9e7eef..e6e47f1b2d 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/io/TestTagCompressionContext.java @@ -164,9 +164,9 @@ public class TestTagCompressionContext { tags.add(new ArrayBackedTag((byte) i, "tagValue" + i)); } KeyValue kv = new KeyValue(ROW, CF, Q, 1234L, V, tags); - ByteBuffer dbb = ByteBuffer.allocateDirect(kv.getBuffer().length); - ByteBufferUtils.copyFromArrayToBuffer(dbb, kv.getBuffer(), 0, kv.getBuffer().length); - ByteBufferKeyValue offheapKV = new ByteBufferKeyValue(dbb, 0, kv.getBuffer().length, 0); + ByteBuffer dbb = ByteBuffer.allocateDirect(kv.getRowArray().length); + ByteBufferUtils.copyFromArrayToBuffer(dbb, kv.getRowArray(), 0, kv.getRowArray().length); + ByteBufferKeyValue offheapKV = new ByteBufferKeyValue(dbb, 0, kv.getRowArray().length, 0); return offheapKV; } } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java index 4f167a4981..ab098e62f9 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/RedundantKVGenerator.java @@ -367,7 +367,7 @@ public class RedundantKVGenerator { KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, value, new Tag[] { new ArrayBackedTag((byte) 1, "value1") }); ByteBuffer offheapKVBB = ByteBuffer.allocateDirect(keyValue.getLength()); - ByteBufferUtils.copyFromArrayToBuffer(offheapKVBB, keyValue.getBuffer(), + ByteBufferUtils.copyFromArrayToBuffer(offheapKVBB, keyValue.getRowArray(), keyValue.getOffset(), keyValue.getLength()); ByteBufferKeyValue offheapKV = new ExtendedOffheapKeyValue(offheapKVBB, 0, keyValue.getLength(), 0); @@ -375,7 +375,7 @@ public class RedundantKVGenerator { } else { KeyValue keyValue = new KeyValue(row, family, qualifier, timestamp, value); ByteBuffer offheapKVBB = ByteBuffer.allocateDirect(keyValue.getLength()); - ByteBufferUtils.copyFromArrayToBuffer(offheapKVBB, keyValue.getBuffer(), + ByteBufferUtils.copyFromArrayToBuffer(offheapKVBB, keyValue.getRowArray(), keyValue.getOffset(), keyValue.getLength()); ByteBufferKeyValue offheapKV = new ExtendedOffheapKeyValue(offheapKVBB, 0, keyValue.getLength(), 0); @@ -461,7 +461,7 @@ public class RedundantKVGenerator { ByteBuffer result = ByteBuffer.allocate(totalSize); for (KeyValue kv : keyValues) { - result.put(kv.getBuffer(), kv.getOffset(), kv.getLength()); + result.put(kv.getRowArray(), kv.getOffset(), kv.getLength()); if (includesMemstoreTS) { ByteBufferUtils.writeVLong(result, kv.getSequenceId()); } diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java index 8ae2a29b7d..f1e62aeb1e 100644 --- a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java +++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestByteRangeWithKVSerialization.java @@ -35,8 +35,8 @@ public class TestByteRangeWithKVSerialization { static void writeCell(PositionedByteRange pbr, KeyValue kv) throws Exception { pbr.putInt(kv.getKeyLength()); pbr.putInt(kv.getValueLength()); - pbr.put(kv.getBuffer(), kv.getKeyOffset(), kv.getKeyLength()); - pbr.put(kv.getBuffer(), kv.getValueOffset(), kv.getValueLength()); + pbr.put(kv.getRowArray(), kv.getKeyOffset(), kv.getKeyLength()); + pbr.put(kv.getRowArray(), kv.getValueOffset(), kv.getValueLength()); int tagsLen = kv.getTagsLength(); pbr.put((byte) (tagsLen >> 8 & 0xff)); pbr.put((byte) (tagsLen & 0xff)); 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 63868daf07..05ae40e2c5 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.hadoop.hbase.classification.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-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeCodec.java b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeCodec.java index 1efee969de..d4bae4e0c9 100644 --- a/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeCodec.java +++ b/hbase-prefix-tree/src/main/java/org/apache/hadoop/hbase/codec/prefixtree/PrefixTreeCodec.java @@ -99,7 +99,7 @@ public class PrefixTreeCodec implements DataBlockEncoder { // needs to be modified for DirectByteBuffers. no existing methods to // write VLongs to byte[] int offset = result.arrayOffset() + result.position(); - System.arraycopy(currentCell.getBuffer(), currentCell.getOffset(), result.array(), offset, + System.arraycopy(currentCell.getRowArray(), currentCell.getOffset(), result.array(), offset, currentCell.getLength()); int keyValueLength = KeyValueUtil.length(currentCell); ByteBufferUtils.skip(result, keyValueLength); 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 d6a3e14efe..3e8e1c80fe 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.hadoop.hbase.classification.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 74afcd9417..e207415bfe 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.hadoop.hbase.classification.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 2ddb6c37eb..9b929aaa75 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 65803819f1..5043fcd4bd 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..ece0f58c57 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 @@ -36,13 +36,13 @@ import javax.xml.bind.Unmarshaller; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.hbase.CellUtil; +import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.CompareOperator; import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HConstants; 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.Delete; @@ -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 1854236036..946301eb11 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$MetaKeyComparator") || 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-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java index e3c1df34a5..54e3a58056 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestSerialization.java @@ -75,7 +75,7 @@ public class TestSerialization { ByteArrayInputStream bais = new ByteArrayInputStream(mb); DataInputStream dis = new DataInputStream(bais); KeyValue deserializedKv = KeyValueUtil.create(dis); - assertTrue(Bytes.equals(kv.getBuffer(), deserializedKv.getBuffer())); + assertTrue(Bytes.equals(kv.getValueArray(), deserializedKv.getValueArray())); assertEquals(kv.getOffset(), deserializedKv.getOffset()); assertEquals(kv.getLength(), deserializedKv.getLength()); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java index a2167cecfa..276a38d2eb 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java @@ -108,7 +108,7 @@ public class TestSingleColumnValueFilter { Bytes.toBytes(1L)); assertTrue("less than", filter.filterKeyValue(kv) == Filter.ReturnCode.NEXT_ROW); filter.reset(); - byte[] buffer = kv.getBuffer(); + byte[] buffer = kv.getValueArray(); Cell c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("less than", filter.filterKeyValue(c) == Filter.ReturnCode.NEXT_ROW); filter.reset(); @@ -117,7 +117,7 @@ public class TestSingleColumnValueFilter { Bytes.toBytes(100L)); assertTrue("Equals 100", filter.filterKeyValue(kv) == Filter.ReturnCode.NEXT_ROW); filter.reset(); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("Equals 100", filter.filterKeyValue(c) == Filter.ReturnCode.NEXT_ROW); filter.reset(); @@ -126,7 +126,7 @@ public class TestSingleColumnValueFilter { Bytes.toBytes(120L)); assertTrue("include 120", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); filter.reset(); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("include 120", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); } @@ -135,29 +135,29 @@ public class TestSingleColumnValueFilter { throws Exception { KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_2); assertTrue("basicFilter1", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - byte[] buffer = kv.getBuffer(); + byte[] buffer = kv.getValueArray(); Cell c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("basicFilter1", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_3); assertTrue("basicFilter2", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("basicFilter2", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_4); assertTrue("basicFilter3", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("basicFilter3", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); assertFalse("basicFilterNotNull", filter.filterRow()); filter.reset(); kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_1); assertTrue("basicFilter4", filter.filterKeyValue(kv) == Filter.ReturnCode.NEXT_ROW); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("basicFilter4", filter.filterKeyValue(c) == Filter.ReturnCode.NEXT_ROW); kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_2); assertTrue("basicFilter4", filter.filterKeyValue(kv) == Filter.ReturnCode.NEXT_ROW); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("basicFilter4", filter.filterKeyValue(c) == Filter.ReturnCode.NEXT_ROW); assertFalse("basicFilterAllRemaining", filter.filterAllRemaining()); @@ -166,12 +166,12 @@ public class TestSingleColumnValueFilter { filter.setLatestVersionOnly(false); kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_1); assertTrue("basicFilter5", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("basicFilter5", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_2); assertTrue("basicFilter5", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("basicFilter5", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); assertFalse("basicFilterNotNull", filter.filterRow()); @@ -181,14 +181,14 @@ public class TestSingleColumnValueFilter { ((SingleColumnValueFilter) filter).setFilterIfMissing(true); KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, FULLSTRING_1); assertTrue("null1", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - byte[] buffer = kv.getBuffer(); + byte[] buffer = kv.getValueArray(); Cell c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("null1", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); assertFalse("null1FilterRow", filter.filterRow()); filter.reset(); kv = new KeyValue(ROW, COLUMN_FAMILY, Bytes.toBytes("qual2"), FULLSTRING_2); assertTrue("null2", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("null2", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); assertTrue("null2FilterRow", filter.filterRow()); @@ -200,13 +200,13 @@ public class TestSingleColumnValueFilter { FULLSTRING_1); assertTrue("substrTrue", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - byte[] buffer = kv.getBuffer(); + byte[] buffer = kv.getValueArray(); Cell c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("substrTrue", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, FULLSTRING_2); assertTrue("substrFalse", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("substrFalse", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); assertFalse("substrFilterAllRemaining", filter.filterAllRemaining()); @@ -219,13 +219,13 @@ public class TestSingleColumnValueFilter { FULLSTRING_1); assertTrue("regexTrue", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - byte[] buffer = kv.getBuffer(); + byte[] buffer = kv.getValueArray(); Cell c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("regexTrue", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, FULLSTRING_2); assertTrue("regexFalse", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - buffer = kv.getBuffer(); + buffer = kv.getValueArray(); c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("regexFalse", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); assertFalse("regexFilterAllRemaining", filter.filterAllRemaining()); @@ -238,7 +238,7 @@ public class TestSingleColumnValueFilter { FULLSTRING_1); assertTrue("regexTrue", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE); - byte[] buffer = kv.getBuffer(); + byte[] buffer = kv.getValueArray(); Cell c = new ByteBufferKeyValue(ByteBuffer.wrap(buffer), 0, buffer.length); assertTrue("regexTrue", filter.filterKeyValue(c) == Filter.ReturnCode.INCLUDE); assertFalse("regexFilterAllRemaining", filter.filterAllRemaining()); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java index 45d1a36a41..52a5739a30 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestDataBlockEncoders.java @@ -297,7 +297,7 @@ public class TestDataBlockEncoders { .findCommonPrefixInFlatKey(expectedKeyValue, cell, false, true); fail(String.format("next() produces wrong results " + "encoder: %s i: %d commonPrefix: %d" + "\n expected %s\n actual %s", encoder - .toString(), i, commonPrefix, Bytes.toStringBinary(expectedKeyValue.getBuffer(), + .toString(), i, commonPrefix, Bytes.toStringBinary(expectedKeyValue.getValueArray(), expectedKeyValue.getKeyOffset(), expectedKeyValue.getKeyLength()), CellUtil.toString( cell, false))); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestPrefixTreeEncoding.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestPrefixTreeEncoding.java index decd39d565..6504b56618 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestPrefixTreeEncoding.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/io/encoding/TestPrefixTreeEncoding.java @@ -233,7 +233,7 @@ public class TestPrefixTreeEncoding { encodeSeeker.setCurrentBuffer(new SingleByteBuff(encodedData)); KeyValue firstOnRow = KeyValueUtil.createFirstOnRow(getRowKey(batchId, i)); encodeSeeker.seekToKeyInBlock( - new KeyValue.KeyOnlyKeyValue(firstOnRow.getBuffer(), firstOnRow.getKeyOffset(), + new KeyValue.KeyOnlyKeyValue(firstOnRow.getValueArray(), firstOnRow.getKeyOffset(), firstOnRow.getKeyLength()), false); boolean hasMoreOfEncodeScanner = encodeSeeker.next(); CollectionBackedScanner collectionScanner = new CollectionBackedScanner( diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java index 364055cadf..d92706c001 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/protobuf/TestProtobufUtil.java @@ -325,9 +325,9 @@ public class TestProtobufUtil { KeyValue kv3 = new KeyValue(Bytes.toBytes("ccc"), Bytes.toBytes("f1"), Bytes.toBytes("q1"), new byte[30]); byte[] arr = new byte[kv1.getLength() + kv2.getLength() + kv3.getLength()]; - System.arraycopy(kv1.getBuffer(), kv1.getOffset(), arr, 0, kv1.getLength()); - System.arraycopy(kv2.getBuffer(), kv2.getOffset(), arr, kv1.getLength(), kv2.getLength()); - System.arraycopy(kv3.getBuffer(), kv3.getOffset(), arr, kv1.getLength() + kv2.getLength(), + System.arraycopy(kv1.getValueArray(), kv1.getOffset(), arr, 0, kv1.getLength()); + System.arraycopy(kv2.getValueArray(), kv2.getOffset(), arr, kv1.getLength(), kv2.getLength()); + System.arraycopy(kv3.getValueArray(), kv3.getOffset(), arr, kv1.getLength() + kv2.getLength(), kv3.getLength()); ByteBuffer dbb = ByteBuffer.allocateDirect(arr.length); dbb.put(arr); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/DataBlockEncodingTool.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/DataBlockEncodingTool.java index 2635e2d316..e6f62403d1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/DataBlockEncodingTool.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/DataBlockEncodingTool.java @@ -192,7 +192,7 @@ public class DataBlockEncodingTool { } } - uncompressedOutputStream.write(currentKV.getBuffer(), + uncompressedOutputStream.write(currentKV.getValueArray(), currentKV.getOffset(), currentKV.getLength()); previousKey = currentKey; @@ -249,8 +249,8 @@ public class DataBlockEncodingTool { Cell c = it.next(); KeyValue codecKv = KeyValueUtil.ensureKeyValue(c); if (codecKv == null || 0 != Bytes.compareTo( - codecKv.getBuffer(), codecKv.getOffset(), codecKv.getLength(), - currentKv.getBuffer(), currentKv.getOffset(), + codecKv.getValueArray(), codecKv.getOffset(), codecKv.getLength(), + currentKv.getValueArray(), currentKv.getOffset(), currentKv.getLength())) { if (codecKv == null) { LOG.error("There is a bug in codec " + it + @@ -260,8 +260,8 @@ public class DataBlockEncodingTool { int limitLength = 2 * Bytes.SIZEOF_INT + Math.min(codecKv.getLength(), currentKv.getLength()); while (prefix < limitLength && - codecKv.getBuffer()[prefix + codecKv.getOffset()] == - currentKv.getBuffer()[prefix + currentKv.getOffset()]) { + codecKv.getValueArray()[prefix + codecKv.getOffset()] == + currentKv.getValueArray()[prefix + currentKv.getOffset()]) { prefix++; } @@ -277,15 +277,15 @@ public class DataBlockEncodingTool { " familyName " + currentKv.getFamilyLength() + " qualifier " + currentKv.getQualifierLength() + "\n prefix " + prefix + - "\n codecKv '" + Bytes.toStringBinary(codecKv.getBuffer(), + "\n codecKv '" + Bytes.toStringBinary(codecKv.getValueArray(), codecKv.getOffset(), prefix) + "' diff '" + - Bytes.toStringBinary(codecKv.getBuffer(), + Bytes.toStringBinary(codecKv.getValueArray(), codecKv.getOffset() + prefix, codecKv.getLength() - prefix) + "'" + "\n currentKv '" + Bytes.toStringBinary( - currentKv.getBuffer(), + currentKv.getValueArray(), currentKv.getOffset(), prefix) + "' diff '" + - Bytes.toStringBinary(currentKv.getBuffer(), + Bytes.toStringBinary(currentKv.getValueArray(), currentKv.getOffset() + prefix, currentKv.getLength() - prefix) + "'" ); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStoreFile.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStoreFile.java index e74e939366..ea8e09225f 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStoreFile.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHStoreFile.java @@ -974,8 +974,8 @@ public class TestHStoreFile extends HBaseTestCase { KeyValue keyv1 = KeyValueUtil.ensureKeyValue(kv1); KeyValue keyv2 = KeyValueUtil.ensureKeyValue(kv2); assertTrue(Bytes.compareTo( - keyv1.getBuffer(), keyv1.getKeyOffset(), keyv1.getKeyLength(), - keyv2.getBuffer(), keyv2.getKeyOffset(), keyv2.getKeyLength()) == 0); + keyv1.getValueArray(), keyv1.getKeyOffset(), keyv1.getKeyLength(), + keyv2.getValueArray(), keyv2.getKeyOffset(), keyv2.getKeyLength()) == 0); assertTrue(Bytes.compareTo( kv1.getValueArray(), kv1.getValueOffset(), kv1.getValueLength(), kv2.getValueArray(), kv2.getValueOffset(), kv2.getValueLength()) == 0); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALCellCodecWithCompression.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALCellCodecWithCompression.java index 8a246be4e6..e79c07fb89 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALCellCodecWithCompression.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/wal/TestWALCellCodecWithCompression.java @@ -119,8 +119,8 @@ public class TestWALCellCodecWithCompression { tags.add(new ArrayBackedTag((byte) i, Bytes.toBytes("tagValue" + i))); } KeyValue kv = new KeyValue(row, cf, q, HConstants.LATEST_TIMESTAMP, value, tags); - ByteBuffer dbb = ByteBuffer.allocateDirect(kv.getBuffer().length); - dbb.put(kv.getBuffer()); - return new ByteBufferKeyValue(dbb, 0, kv.getBuffer().length); + ByteBuffer dbb = ByteBuffer.allocateDirect(kv.getValueArray().length); + dbb.put(kv.getValueArray()); + return new ByteBufferKeyValue(dbb, 0, kv.getValueArray().length); } } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/TestWALReaderOnSecureWAL.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/TestWALReaderOnSecureWAL.java index ecde00d2f1..c39600c00b 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/TestWALReaderOnSecureWAL.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/wal/TestWALReaderOnSecureWAL.java @@ -122,8 +122,8 @@ public class TestWALReaderOnSecureWAL { WALEdit kvs = new WALEdit(); KeyValue kv = new KeyValue(row, family, Bytes.toBytes(i), value); if (offheap) { - ByteBuffer bb = ByteBuffer.allocateDirect(kv.getBuffer().length); - bb.put(kv.getBuffer()); + ByteBuffer bb = ByteBuffer.allocateDirect(kv.getValueArray().length); + bb.put(kv.getValueArray()); ByteBufferKeyValue offheapKV = new ByteBufferKeyValue(bb, 0, kv.getLength()); kvs.add(offheapKV); } else { 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 221786af39..2aaad2c9e2 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.AtomicLong; 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 0b6e2304a1..9eddb5f125 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 0301bbcebe..72b077f090 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