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 24d88b3..ca65a41 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 @@ -436,14 +436,28 @@ public class KeyValueUtil { /*************** misc **********************************/ /** * @param cell - * @return cell if it is an instance of {@link KeyValue} else we will return a - * new {@link KeyValue} instance made from cell + * @return cell if it is an object of class {@link KeyValue} else we will return a + * new {@link KeyValue} instance made from cell Note: Even if the cell is an + * object of any of the subclass of {@link KeyValue}, we will create a new + * {@link KeyValue} object wrapping same buffer. This API is used only with MR based tools + * which expect the type to be exactly KeyValue. That is the reason for doing this way. * @deprecated without any replacement. */ @Deprecated public static KeyValue ensureKeyValue(final Cell cell) { if (cell == null) return null; - return cell instanceof KeyValue? (KeyValue)cell: copyToNewKeyValue(cell); + if (cell instanceof KeyValue) { + if (cell.getClass().getName().equals(KeyValue.class.getName())) { + return (KeyValue) cell; + } + // Cell is an Object of any of the sub classes of KeyValue. Make a new KeyValue wrapping the + // same byte[] + KeyValue kv = (KeyValue) cell; + KeyValue newKv = new KeyValue(kv.bytes, kv.offset, kv.length); + newKv.setSequenceId(kv.getSequenceId()); + return newKv; + } + return copyToNewKeyValue(cell); } @Deprecated diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlockIndex.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlockIndex.java index 75f1f82..1bdba3b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlockIndex.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileBlockIndex.java @@ -40,7 +40,6 @@ import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue.KeyOnlyKeyValue; -import org.apache.hadoop.hbase.KeyValueUtil; import org.apache.hadoop.hbase.ByteBufferedKeyOnlyKeyValue; import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.io.HeapSize; @@ -350,9 +349,8 @@ public class HFileBlockIndex { if (index == -1) { // This has to be changed // For now change this to key value - KeyValue kv = KeyValueUtil.ensureKeyValue(key); throw new IOException("The key " - + Bytes.toStringBinary(kv.getKey(), kv.getKeyOffset(), kv.getKeyLength()) + + CellUtil.getCellKeyAsString(key) + " is before the" + " first key of the non-root index block " + block); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/mapreduce/MemStoreWrapper.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/mapreduce/MemStoreWrapper.java index fdda1de..08e6753 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/mapreduce/MemStoreWrapper.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/mapreduce/MemStoreWrapper.java @@ -172,12 +172,12 @@ public class MemStoreWrapper { } /** - * Adds a KeyValue into the memstore. - * @param kv The KeyValue to be added. + * Adds a Cell into the memstore. + * @param cell The Cell to be added. * @throws IOException */ - public void addToMemstore(KeyValue kv) throws IOException { - memstore.add(kv); + public void addToMemstore(Cell cell) throws IOException { + memstore.add(cell); // flush the memstore if it's full. flushMemStoreIfNecessary(); } diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/mapreduce/SweepReducer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/mapreduce/SweepReducer.java index 03a05cc..d39267b 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/mapreduce/SweepReducer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/mob/mapreduce/SweepReducer.java @@ -331,13 +331,13 @@ public class SweepReducer extends Reducer { } // write the hfile name writer.append(mobFileName.getFileName(), MobConstants.EMPTY_STRING); - Set kvs = new HashSet(); + Set kvs = new HashSet(); for (KeyValue kv : values) { if (kv.getValueLength() > Bytes.SIZEOF_INT) { mobFileStat.addValidSize(Bytes.toInt(kv.getValueArray(), kv.getValueOffset(), Bytes.SIZEOF_INT)); } - kvs.add(kv.createKeyOnly(false)); + kvs.add(kv); } // If the mob file is a invalid one or a small one, merge it into new/bigger ones. if (mobFileStat.needClean() || (mergeSmall && mobFileStat.needMerge())) { @@ -351,11 +351,9 @@ public class SweepReducer extends Reducer { scanner.seek(KeyValueUtil.createFirstOnRow(HConstants.EMPTY_BYTE_ARRAY)); Cell cell; while (null != (cell = scanner.next())) { - KeyValue kv = KeyValueUtil.ensureKeyValue(cell); - KeyValue keyOnly = kv.createKeyOnly(false); - if (kvs.contains(keyOnly)) { + if (kvs.contains(cell)) { // write the KeyValue existing in HBase to the memstore. - memstore.addToMemstore(kv); + memstore.addToMemstore(cell); memstoreUpdated = true; } }