HBASE-13977 - Convert getKey and related APIs to Cell (Ram)

This commit is contained in:
ramkrishna 2015-07-03 22:59:58 +05:30
parent 1b75fd2bd6
commit 74e82c64e5
31 changed files with 159 additions and 164 deletions

View File

@ -894,9 +894,13 @@ public final class CellUtil {
String value = null;
if (verbose) {
// TODO: pretty print tags as well
tag = Bytes.toStringBinary(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength());
value = Bytes.toStringBinary(cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength());
if (cell.getTagsLength() > 0) {
tag = Bytes.toStringBinary(cell.getTagsArray(), cell.getTagsOffset(), cell.getTagsLength());
}
if (!(cell instanceof KeyValue.KeyOnlyKeyValue)) {
value = Bytes.toStringBinary(cell.getValueArray(), cell.getValueOffset(),
cell.getValueLength());
}
}
builder

View File

@ -641,11 +641,10 @@ abstract class BufferedDataBlockEncoder implements DataBlockEncoder {
}
@Override
public ByteBuffer getKeyDeepCopy() {
ByteBuffer keyBuffer = ByteBuffer.allocate(current.keyLength);
keyBuffer.put(current.keyBuffer, 0, current.keyLength);
keyBuffer.rewind();
return keyBuffer;
public Cell getKey() {
byte[] key = new byte[current.keyLength];
System.arraycopy(current.keyBuffer, 0, key, 0, current.keyLength);
return new KeyValue.KeyOnlyKeyValue(key);
}
@Override

View File

@ -140,11 +140,11 @@ public interface DataBlockEncoder {
void setCurrentBuffer(ByteBuffer buffer);
/**
* Does a deep copy of the key at the current position. A deep copy is
* necessary because buffers are reused in the decoder.
* From the current position creates a cell using the key part
* of the current buffer
* @return key at current position
*/
ByteBuffer getKeyDeepCopy();
Cell getKey();
/**
* Does a shallow copy of the value at the current position. A shallow

View File

@ -74,8 +74,8 @@ public class PrefixTreeSeeker implements EncodedSeeker {
@Override
public ByteBuffer getKeyDeepCopy() {
return KeyValueUtil.copyKeyToNewByteBuffer(ptSearcher.current());
public Cell getKey() {
return ptSearcher.current();
}

View File

@ -125,7 +125,7 @@ public class HalfStoreFileReader extends StoreFile.Reader {
final HFileScanner delegate = s;
public boolean atEnd = false;
public ByteBuffer getKey() {
public Cell getKey() {
if (atEnd) return null;
return delegate.getKey();
}
@ -148,10 +148,10 @@ public class HalfStoreFileReader extends StoreFile.Reader {
return delegate.getValueString();
}
public Cell getKeyValue() {
public Cell getCell() {
if (atEnd) return null;
return delegate.getKeyValue();
return delegate.getCell();
}
public boolean next() throws IOException {
@ -163,9 +163,7 @@ public class HalfStoreFileReader extends StoreFile.Reader {
}
// constrain the bottom.
if (!top) {
ByteBuffer bb = getKey();
if (getComparator().compare(splitCell, bb.array(), bb.arrayOffset(),
bb.limit()) <= 0) {
if (getComparator().compare(splitCell, getKey()) <= 0) {
atEnd = true;
return false;
}
@ -195,10 +193,7 @@ public class HalfStoreFileReader extends StoreFile.Reader {
return b;
}
// Check key.
ByteBuffer k = this.delegate.getKey();
return (this.delegate.getReader().getComparator().
compare(splitCell, k.array(), k.arrayOffset(), k.limit()
)) > 0;
return (this.delegate.getReader().getComparator().compare(splitCell, getKey())) > 0;
}
public org.apache.hadoop.hbase.io.hfile.HFile.Reader getReader() {
@ -307,7 +302,7 @@ public class HalfStoreFileReader extends StoreFile.Reader {
}
@Override
public byte[] getLastKey() {
public Cell getLastKey() {
if (top) {
return super.getLastKey();
}
@ -315,7 +310,7 @@ public class HalfStoreFileReader extends StoreFile.Reader {
HFileScanner scanner = getScanner(true, true);
try {
if (scanner.seekBefore(this.splitCell)) {
return Bytes.toBytes(scanner.getKey());
return scanner.getKey();
}
} catch (IOException e) {
LOG.warn("Failed seekBefore " + Bytes.toStringBinary(this.splitkey), e);
@ -335,7 +330,7 @@ public class HalfStoreFileReader extends StoreFile.Reader {
HFileScanner scanner = getScanner(true, true, false);
try {
if (scanner.seekTo()) {
this.firstKey = new KeyValue.KeyOnlyKeyValue(Bytes.toBytes(scanner.getKey()));
this.firstKey = scanner.getKey();
}
firstKeySeeked = true;
} catch (IOException e) {

View File

@ -393,7 +393,7 @@ public class HFile {
Map<byte[], byte[]> loadFileInfo() throws IOException;
byte[] getLastKey();
Cell getLastKey();
Cell midkey() throws IOException;

View File

@ -314,7 +314,7 @@ public class HFilePrettyPrinter extends Configured implements Tool {
HFileScanner scanner, byte[] row) throws IOException {
Cell pCell = null;
do {
Cell cell = scanner.getKeyValue();
Cell cell = scanner.getCell();
if (row != null && row.length != 0) {
int result = CellComparator.COMPARATOR.compareRows(cell, row, 0, row.length);
if (result > 0) {
@ -482,7 +482,7 @@ public class HFilePrettyPrinter extends Configured implements Tool {
keyLen.update(curRowKeyLength);
if (curRowBytes > maxRowBytes && prevCell != null) {
biggestRow = prevCell.getRow();
biggestRow = CellUtil.cloneRow(prevCell);
maxRowBytes = curRowBytes;
}

View File

@ -39,7 +39,6 @@ import org.apache.hadoop.hbase.SizeCachedKeyValue;
import org.apache.hadoop.hbase.SizeCachedNoTagsKeyValue;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.fs.HFileSystem;
import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper;
import org.apache.hadoop.hbase.io.compress.Compression;
@ -90,7 +89,7 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
private HFileDataBlockEncoder dataBlockEncoder = NoOpDataBlockEncoder.INSTANCE;
/** Last key in the file. Filled in when we read in the file info */
private byte [] lastKey = null;
private Cell lastKeyCell = null;
/** Average key length read from file info */
private int avgKeyLen = -1;
@ -216,7 +215,9 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
byte[] creationTimeBytes = fileInfo.get(FileInfo.CREATE_TIME_TS);
this.hfileContext.setFileCreateTime(creationTimeBytes == null? 0:
Bytes.toLong(creationTimeBytes));
lastKey = fileInfo.get(FileInfo.LASTKEY);
if (fileInfo.get(FileInfo.LASTKEY) != null) {
lastKeyCell = new KeyValue.KeyOnlyKeyValue(fileInfo.get(FileInfo.LASTKEY));
}
avgKeyLen = Bytes.toInt(fileInfo.get(FileInfo.AVG_KEY_LEN));
avgValueLen = Bytes.toInt(fileInfo.get(FileInfo.AVG_VALUE_LEN));
byte [] keyValueFormatVersion = fileInfo.get(HFileWriterImpl.KEY_VALUE_VERSION);
@ -314,7 +315,7 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
}
private String toStringLastKey() {
return KeyValue.keyToString(getLastKey());
return CellUtil.toString(getLastKey(), false);
}
@Override
@ -371,8 +372,8 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
*/
@Override
public byte[] getLastRowKey() {
byte[] lastKey = getLastKey();
return lastKey == null? null: KeyValueUtil.createKeyValueFromKey(lastKey).getRow();
Cell lastKey = getLastKey();
return lastKey == null? null: CellUtil.cloneRow(lastKey);
}
/** @return number of KV entries in this HFile */
@ -819,7 +820,7 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
}
@Override
public Cell getKeyValue() {
public Cell getCell() {
if (!isSeeked())
return null;
@ -838,12 +839,11 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
}
@Override
public ByteBuffer getKey() {
public Cell getKey() {
assertSeeked();
return ByteBuffer.wrap(
blockBuffer.array(),
return new KeyValue.KeyOnlyKeyValue(blockBuffer.array(),
blockBuffer.arrayOffset() + blockBuffer.position()
+ KEY_VALUE_LEN_SIZE, currKeyLen).slice();
+ KEY_VALUE_LEN_SIZE, currKeyLen);
}
@Override
@ -1365,13 +1365,13 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
}
/**
* @return Last key in the file. May be null if file has no entries. Note that
* this is not the last row key, but rather the byte form of the last
* KeyValue.
* @return Last key as cell in the file. May be null if file has no entries. Note that
* this is not the last row key, but it is the Cell representation of the last
* key
*/
@Override
public byte[] getLastKey() {
return dataBlockIndexReader.isEmpty() ? null : lastKey;
public Cell getLastKey() {
return dataBlockIndexReader.isEmpty() ? null : lastKeyCell;
}
/**
@ -1516,9 +1516,9 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
}
@Override
public ByteBuffer getKey() {
public Cell getKey() {
assertValidSeek();
return seeker.getKeyDeepCopy();
return seeker.getKey();
}
@Override
@ -1528,7 +1528,7 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
}
@Override
public Cell getKeyValue() {
public Cell getCell() {
if (block == null) {
return null;
}
@ -1537,9 +1537,7 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
@Override
public String getKeyString() {
ByteBuffer keyBuffer = getKey();
return Bytes.toStringBinary(keyBuffer.array(),
keyBuffer.arrayOffset(), keyBuffer.limit());
return CellUtil.toString(getKey(), true);
}
@Override

View File

@ -105,12 +105,11 @@ public interface HFileScanner extends Shipper {
*/
boolean next() throws IOException;
/**
* Gets a buffer view to the current key. You must call
* Gets the current key in the form of a cell. You must call
* {@link #seekTo(Cell)} before this method.
* @return byte buffer for the key. The limit is set to the key size, and the
* position is 0, the start of the buffer view.
* @return gets the current key as a Cell.
*/
ByteBuffer getKey();
Cell getKey();
/**
* Gets a buffer view to the current value. You must call
* {@link #seekTo(Cell)} before this method.
@ -120,9 +119,9 @@ public interface HFileScanner extends Shipper {
*/
ByteBuffer getValue();
/**
* @return Instance of {@link org.apache.hadoop.hbase.KeyValue}.
* @return Instance of {@link org.apache.hadoop.hbase.Cell}.
*/
Cell getKeyValue();
Cell getCell();
/**
* Convenience method to get a copy of the key as a string - interpreting the
* bytes as UTF8. You must call {@link #seekTo(Cell)} before this method.

View File

@ -827,8 +827,7 @@ public class LoadIncrementalHFiles extends Configured implements Tool {
HFileScanner scanner = halfReader.getScanner(false, false, false);
scanner.seekTo();
do {
KeyValue kv = KeyValueUtil.ensureKeyValue(scanner.getKeyValue());
halfWriter.append(kv);
halfWriter.append(scanner.getCell());
} while (scanner.next());
for (Map.Entry<byte[],byte[]> entry : fileInfo.entrySet()) {

View File

@ -587,12 +587,12 @@ public class HRegionFileSystem {
if (top) {
//check if larger than last key.
KeyValue splitKey = KeyValueUtil.createFirstOnRow(splitRow);
byte[] lastKey = f.createReader().getLastKey();
Cell lastKey = f.createReader().getLastKey();
// If lastKey is null means storefile is empty.
if (lastKey == null) {
return null;
}
if (f.getReader().getComparator().compare(splitKey, lastKey, 0, lastKey.length) > 0) {
if (f.getReader().getComparator().compare(splitKey, lastKey) > 0) {
return null;
}
} else {

View File

@ -55,7 +55,6 @@ import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.TagType;
@ -712,9 +711,9 @@ public class HStore implements Store {
byte[] firstKey = reader.getFirstRowKey();
Preconditions.checkState(firstKey != null, "First key can not be null");
byte[] lk = reader.getLastKey();
Cell lk = reader.getLastKey();
Preconditions.checkState(lk != null, "Last key can not be null");
byte[] lastKey = KeyValueUtil.createKeyValueFromKey(lk).getRow();
byte[] lastKey = CellUtil.cloneRow(lk);
LOG.debug("HFile bounds: first=" + Bytes.toStringBinary(firstKey) +
" last=" + Bytes.toStringBinary(lastKey));
@ -741,7 +740,7 @@ public class HStore implements Store {
HFileScanner scanner = reader.getScanner(false, false, false);
scanner.seekTo();
do {
Cell cell = scanner.getKeyValue();
Cell cell = scanner.getCell();
if (prevCell != null) {
if (comparator.compareRows(prevCell, cell) > 0) {
throw new InvalidHFileException("Previous row is greater than"
@ -1840,16 +1839,15 @@ public class HStore implements Store {
// TODO: Cache these keys rather than make each time?
Cell firstKV = r.getFirstKey();
if (firstKV == null) return false;
byte [] lk = r.getLastKey();
KeyValue lastKV = KeyValueUtil.createKeyValueFromKey(lk, 0, lk.length);
KeyValue firstOnRow = state.getTargetKey();
Cell lastKV = r.getLastKey();
Cell firstOnRow = state.getTargetKey();
if (this.comparator.compareRows(lastKV, firstOnRow) < 0) {
// If last key in file is not of the target table, no candidates in this
// file. Return.
if (!state.isTargetTable(lastKV)) return false;
// If the row we're looking for is past the end of file, set search key to
// last key. TODO: Cache last and first key rather than make each time.
firstOnRow = new KeyValue(lastKV.getRow(), HConstants.LATEST_TIMESTAMP);
firstOnRow = CellUtil.createFirstOnRow(lastKV);
}
// Get a scanner that caches blocks and that uses pread.
HFileScanner scanner = r.getScanner(true, true, false);
@ -1860,11 +1858,11 @@ public class HStore implements Store {
if (walkForwardInSingleRow(scanner, firstOnRow, state)) return true;
// If here, need to start backing up.
while (scanner.seekBefore(firstOnRow)) {
Cell kv = scanner.getKeyValue();
Cell kv = scanner.getCell();
if (!state.isTargetTable(kv)) break;
if (!state.isBetterCandidate(kv)) break;
// Make new first on row.
firstOnRow = new KeyValue(kv.getRow(), HConstants.LATEST_TIMESTAMP);
firstOnRow = CellUtil.createFirstOnRow(kv);
// Seek scanner. If can't seek it, break.
if (!seekToScanner(scanner, firstOnRow, firstKV)) return false;
// If we find something, break;
@ -1882,7 +1880,7 @@ public class HStore implements Store {
* @throws IOException
*/
private boolean seekToScanner(final HFileScanner scanner,
final KeyValue firstOnRow,
final Cell firstOnRow,
final Cell firstKV)
throws IOException {
Cell kv = firstOnRow;
@ -1903,12 +1901,12 @@ public class HStore implements Store {
* @throws IOException
*/
private boolean walkForwardInSingleRow(final HFileScanner scanner,
final KeyValue firstOnRow,
final Cell firstOnRow,
final GetClosestRowBeforeTracker state)
throws IOException {
boolean foundCandidate = false;
do {
Cell kv = scanner.getKeyValue();
Cell kv = scanner.getCell();
// If we are not in the row, skip.
if (this.comparator.compareRows(kv, firstOnRow) < 0) continue;
// Did we go beyond the target row? If so break.

View File

@ -681,8 +681,7 @@ public class StoreFile {
Cell midkey = this.reader.midkey();
if (midkey != null) {
Cell firstKey = this.reader.getFirstKey();
byte [] lk = this.reader.getLastKey();
KeyValue lastKey = KeyValueUtil.createKeyValueFromKey(lk, 0, lk.length);
Cell lastKey = this.reader.getLastKey();
// if the midkey is the same as the first or last keys, we cannot (ever) split this region.
if (comparator.compareRows(midkey, firstKey) == 0
|| comparator.compareRows(midkey, lastKey) == 0) {
@ -1369,10 +1368,8 @@ public class StoreFile {
KeyValue largestScanKeyValue = scan.isReversed() ? KeyValueUtil
.createLastOnRow(scan.getStartRow()) : KeyValueUtil.createLastOnRow(scan
.getStopRow());
// TODO this is in hot path? Optimize and avoid 2 extra object creations.
Cell firstKeyKV = this.getFirstKey();
KeyValue.KeyOnlyKeyValue lastKeyKV =
new KeyValue.KeyOnlyKeyValue(this.getLastKey(), 0, this.getLastKey().length);
Cell lastKeyKV = this.getLastKey();
boolean nonOverLapping = ((getComparator().compare(firstKeyKV, largestScanKeyValue)) > 0
&& !Bytes
.equals(scan.isReversed() ? scan.getStartRow() : scan.getStopRow(),
@ -1483,7 +1480,7 @@ public class StoreFile {
this.deleteFamilyBloomFilter = null;
}
public byte[] getLastKey() {
public Cell getLastKey() {
return reader.getLastKey();
}

View File

@ -135,7 +135,7 @@ public class StoreFileScanner implements KeyValueScanner {
// only seek if we aren't at the end. cur == null implies 'end'.
if (cur != null) {
hfs.next();
setCurrentCell(hfs.getKeyValue());
setCurrentCell(hfs.getCell());
if (hasMVCCInfo || this.reader.isBulkLoaded()) {
skipKVsNewerThanReadpoint();
}
@ -158,7 +158,7 @@ public class StoreFileScanner implements KeyValueScanner {
return false;
}
setCurrentCell(hfs.getKeyValue());
setCurrentCell(hfs.getCell());
if (!hasMVCCInfo && this.reader.isBulkLoaded()) {
return skipKVsNewerThanReadpoint();
@ -184,7 +184,7 @@ public class StoreFileScanner implements KeyValueScanner {
this.cur = null;
return false;
}
setCurrentCell(hfs.getKeyValue());
setCurrentCell(hfs.getCell());
if (!hasMVCCInfo && this.reader.isBulkLoaded()) {
return skipKVsNewerThanReadpoint();
@ -217,7 +217,7 @@ public class StoreFileScanner implements KeyValueScanner {
&& cur != null
&& (cur.getSequenceId() > readPt)) {
hfs.next();
setCurrentCell(hfs.getKeyValue());
setCurrentCell(hfs.getCell());
if (this.stopSkippingKVsIfNextRow
&& getComparator().compareRows(cur, startKV) > 0) {
return false;
@ -426,8 +426,8 @@ public class StoreFileScanner implements KeyValueScanner {
this.cur = null;
return false;
}
KeyValue firstKeyOfPreviousRow = KeyValueUtil.createFirstOnRow(hfs.getKeyValue()
.getRowArray(), hfs.getKeyValue().getRowOffset(), hfs.getKeyValue().getRowLength());
Cell curCell = hfs.getCell();
Cell firstKeyOfPreviousRow = CellUtil.createFirstOnRow(curCell);
if (seekCount != null) seekCount.incrementAndGet();
if (!seekAtOrAfter(hfs, firstKeyOfPreviousRow)) {
@ -435,7 +435,7 @@ public class StoreFileScanner implements KeyValueScanner {
return false;
}
setCurrentCell(hfs.getKeyValue());
setCurrentCell(hfs.getCell());
this.stopSkippingKVsIfNextRow = true;
boolean resultOfSkipKVs;
try {

View File

@ -343,7 +343,7 @@ public abstract class StripeMultiFileWriter implements Compactor.CellSink {
doCreateWriter = true;
}
if (doCreateWriter) {
byte[] boundary = existingWriters.isEmpty() ? left : cell.getRow(); // make a copy
byte[] boundary = existingWriters.isEmpty() ? left : CellUtil.cloneRow(cell); // make a copy
if (LOG.isDebugEnabled()) {
LOG.debug("Creating new writer starting at [" + Bytes.toString(boundary) + "]");
}
@ -366,7 +366,7 @@ public abstract class StripeMultiFileWriter implements Compactor.CellSink {
if (lastRowInCurrentWriter == null
&& existingWriters.size() < targetCount
&& cellsSeen >= targetCells) {
lastRowInCurrentWriter = cell.getRow(); // make a copy
lastRowInCurrentWriter = CellUtil.cloneRow(cell); // make a copy
if (LOG.isDebugEnabled()) {
LOG.debug("Preparing to start a new writer after [" + Bytes.toString(
lastRowInCurrentWriter) + "] row; observed " + cellsSeen + " kvs and wrote out "

View File

@ -31,6 +31,7 @@ import org.apache.hadoop.hbase.classification.InterfaceAudience;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellScanner;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HRegionLocation;
@ -234,7 +235,7 @@ public class WALEditsReplaySink {
List<Cell> cells = edit.getCells();
for (Cell cell : cells) {
// filtering WAL meta entries
setLocation(conn.locateRegion(tableName, cell.getRow()));
setLocation(conn.locateRegion(tableName, CellUtil.cloneRow(cell)));
skip = true;
break;
}

View File

@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.util;
import java.nio.ByteBuffer;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.classification.InterfaceAudience;
/**

View File

@ -138,7 +138,7 @@ public class CompressionTest {
HFileScanner scanner = reader.getScanner(false, true);
scanner.seekTo(); // position to the start of file
// Scanner does not do Cells yet. Do below for now till fixed.
cc = scanner.getKeyValue();
cc = scanner.getCell();
if (CellComparator.COMPARATOR.compareRows(c, cc) != 0) {
throw new Exception("Read back incorrect result: " + c.toString() + " vs " + cc.toString());
}

View File

@ -77,6 +77,7 @@ import org.apache.hadoop.fs.permission.FsAction;
import org.apache.hadoop.fs.permission.FsPermission;
import org.apache.hadoop.hbase.Abortable;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.ClusterStatus;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseInterfaceAudience;
@ -86,7 +87,6 @@ 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.KeyValueUtil;
import org.apache.hadoop.hbase.MasterNotRunningException;
import org.apache.hadoop.hbase.MetaTableAccessor;
import org.apache.hadoop.hbase.RegionLocations;
@ -781,8 +781,8 @@ public class HBaseFsck extends Configured implements Closeable {
}
if ((reader.getLastKey() != null)
&& ((storeLastKey == null) || (comparator.compare(storeLastKey,
reader.getLastKey())) < 0)) {
storeLastKey = reader.getLastKey();
((KeyValue.KeyOnlyKeyValue)reader.getLastKey()).getKey())) < 0)) {
storeLastKey = ((KeyValue.KeyOnlyKeyValue)reader.getLastKey()).getKey();
}
reader.close();
}
@ -881,8 +881,8 @@ public class HBaseFsck extends Configured implements Closeable {
hf.loadFileInfo();
Cell startKv = hf.getFirstKey();
start = startKv.getRow();
KeyValue endKv = KeyValueUtil.createKeyValueFromKey(hf.getLastKey());
end = endKv.getRow();
Cell endKv = hf.getLastKey();
end = CellUtil.cloneRow(endKv);
} catch (IOException ioe) {
LOG.warn("Problem reading orphan file " + hfile + ", skipping");
continue;

View File

@ -411,7 +411,7 @@ public class HFilePerformanceEvaluation {
void doRow(int i) throws Exception {
if (this.scanner.next()) {
// TODO: Fix. Make Scanner do Cells.
Cell c = this.scanner.getKeyValue();
Cell c = this.scanner.getCell();
PerformanceEvaluationCommons.assertKey(format(i + 1), c);
PerformanceEvaluationCommons.assertValueSize(c.getValueLength(), ROW_LENGTH);
}
@ -442,7 +442,7 @@ public class HFilePerformanceEvaluation {
return;
}
// TODO: Fix scanner so it does Cells
Cell c = scanner.getKeyValue();
Cell c = scanner.getCell();
PerformanceEvaluationCommons.assertKey(b, c);
PerformanceEvaluationCommons.assertValueSize(c.getValueLength(), ROW_LENGTH);
}
@ -471,7 +471,7 @@ public class HFilePerformanceEvaluation {
return;
}
// TODO: HFileScanner doesn't do Cells yet. Temporary fix.
c = scanner.getKeyValue();
c = scanner.getCell();
// System.out.println("Found row: " +
// new String(c.getRowArray(), c.getRowOffset(), c.getRowLength()));
PerformanceEvaluationCommons.assertKey(b, c);
@ -480,7 +480,7 @@ public class HFilePerformanceEvaluation {
LOG.info("NOTHING FOLLOWS");
return;
}
c = scanner.getKeyValue();
c = scanner.getCell();
PerformanceEvaluationCommons.assertValueSize(c.getValueLength(), ROW_LENGTH);
}
}
@ -510,7 +510,7 @@ public class HFilePerformanceEvaluation {
return;
}
// TODO: Fix. Make scanner do Cells.
scanner.getKeyValue();
scanner.getCell();
}
}

View File

@ -126,7 +126,7 @@ public class TestHalfStoreFileReader {
scanner.seekTo();
Cell curr;
do {
curr = scanner.getKeyValue();
curr = scanner.getCell();
KeyValue reseekKv =
getLastOnCol(curr);
int ret = scanner.reseekTo(reseekKv);
@ -223,7 +223,7 @@ public class TestHalfStoreFileReader {
halfreader.loadFileInfo();
final HFileScanner scanner = halfreader.getScanner(false, false);
scanner.seekBefore(seekBefore);
return scanner.getKeyValue();
return scanner.getCell();
}
private KeyValue getLastOnCol(Cell curr) {

View File

@ -39,6 +39,7 @@ import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValue.Type;
import org.apache.hadoop.hbase.KeyValueUtil;
import org.apache.hadoop.hbase.Tag;
import org.apache.hadoop.hbase.codec.prefixtree.PrefixTreeSeeker;
import org.apache.hadoop.hbase.io.compress.Compression;
import org.apache.hadoop.hbase.io.hfile.HFileBlock.Writer.BufferGrabbingByteArrayOutputStream;
import org.apache.hadoop.hbase.io.hfile.HFileContext;
@ -337,7 +338,13 @@ public class TestDataBlockEncoders {
seeker.rewind();
ByteBuffer actualKeyValue = seeker.getKeyValueBuffer();
ByteBuffer actualKey = seeker.getKeyDeepCopy();
ByteBuffer actualKey = null;
if (seeker instanceof PrefixTreeSeeker) {
byte[] serializedKey = CellUtil.getCellKeySerializedAsKeyValueKey(seeker.getKey());
actualKey = ByteBuffer.wrap(KeyValueUtil.createKeyValueFromKey(serializedKey).getKey());
} else {
actualKey = ByteBuffer.wrap(((KeyValue) seeker.getKey()).getKey());
}
ByteBuffer actualValue = seeker.getValueShallowCopy();
if (expectedKeyValue != null) {

View File

@ -353,7 +353,7 @@ public class TestCacheOnWrite {
// iterate all the keyvalue from hfile
while (scanner.next()) {
scanner.getKeyValue();
scanner.getCell();
}
reader.close();
}

View File

@ -200,7 +200,7 @@ public class TestHFile extends HBaseTestCase {
String value = "value";
int i = start;
for (; i < (start + n); i++) {
ByteBuffer key = scanner.getKey();
ByteBuffer key = ByteBuffer.wrap(((KeyValue)scanner.getKey()).getKey());
ByteBuffer val = scanner.getValue();
String keyStr = String.format(localFormatter, Integer.valueOf(i));
String valStr = value + keyStr;
@ -279,7 +279,7 @@ public class TestHFile extends HBaseTestCase {
assertTrue("location lookup failed",
scanner.seekTo(KeyValueUtil.createKeyValueFromKey(getSomeKey(50))) == 0);
// read the key and see if it matches
ByteBuffer readKey = scanner.getKey();
ByteBuffer readKey = ByteBuffer.wrap(((KeyValue)scanner.getKey()).getKey());
assertTrue("seeked key does not match", Arrays.equals(getSomeKey(50),
Bytes.toBytes(readKey)));

View File

@ -576,21 +576,21 @@ public class TestHFileBlockIndex {
reader.getTrailer().getNumDataIndexLevels());
assertTrue(Bytes.equals(keys[0], ((KeyValue)reader.getFirstKey()).getKey()));
assertTrue(Bytes.equals(keys[NUM_KV - 1], reader.getLastKey()));
assertTrue(Bytes.equals(keys[NUM_KV - 1], ((KeyValue)reader.getLastKey()).getKey()));
LOG.info("Last key: " + Bytes.toStringBinary(keys[NUM_KV - 1]));
for (boolean pread : new boolean[] { false, true }) {
HFileScanner scanner = reader.getScanner(true, pread);
for (int i = 0; i < NUM_KV; ++i) {
checkSeekTo(keys, scanner, i);
checkKeyValue("i=" + i, keys[i], values[i], scanner.getKey(),
scanner.getValue());
checkKeyValue("i=" + i, keys[i], values[i],
ByteBuffer.wrap(((KeyValue) scanner.getKey()).getKey()), scanner.getValue());
}
assertTrue(scanner.seekTo());
for (int i = NUM_KV - 1; i >= 0; --i) {
checkSeekTo(keys, scanner, i);
checkKeyValue("i=" + i, keys[i], values[i], scanner.getKey(),
scanner.getValue());
checkKeyValue("i=" + i, keys[i], values[i],
ByteBuffer.wrap(((KeyValue) scanner.getKey()).getKey()), scanner.getValue());
}
}

View File

@ -225,7 +225,7 @@ public class TestHFileEncryption {
assertTrue("Initial seekTo failed", scanner.seekTo());
int i = 0;
do {
Cell kv = scanner.getKeyValue();
Cell kv = scanner.getCell();
assertTrue("Read back an unexpected or invalid KV",
testKvs.contains(KeyValueUtil.ensureKeyValue(kv)));
i++;

View File

@ -186,9 +186,8 @@ public class TestHFileSeek extends TestCase {
Reader reader = HFile.createReaderFromStream(path, fsdis,
fs.getFileStatus(path).getLen(), new CacheConfig(conf), conf);
reader.loadFileInfo();
KeySampler kSampler =
new KeySampler(rng, ((KeyValue)reader.getFirstKey()).getKey(), reader.getLastKey(),
keyLenGen);
KeySampler kSampler = new KeySampler(rng, ((KeyValue) reader.getFirstKey()).getKey(),
((KeyValue) reader.getLastKey()).getKey(), keyLenGen);
HFileScanner scanner = reader.getScanner(false, USE_PREAD);
BytesWritable key = new BytesWritable();
timer.reset();
@ -198,7 +197,7 @@ public class TestHFileSeek extends TestCase {
byte [] k = new byte [key.getLength()];
System.arraycopy(key.getBytes(), 0, k, 0, key.getLength());
if (scanner.seekTo(KeyValueUtil.createKeyValueFromKey(k)) >= 0) {
ByteBuffer bbkey = scanner.getKey();
ByteBuffer bbkey = ByteBuffer.wrap(((KeyValue) scanner.getKey()).getKey());
ByteBuffer bbval = scanner.getValue();
totalBytes += bbkey.limit();
totalBytes += bbval.limit();

View File

@ -153,23 +153,23 @@ public class TestSeekTo {
assertFalse(scanner.seekBefore(toKV("c", tagUsage)));
assertTrue(scanner.seekBefore(toKV("d", tagUsage)));
assertEquals("c", toRowStr(scanner.getKeyValue()));
assertEquals("c", toRowStr(scanner.getCell()));
assertTrue(scanner.seekBefore(toKV("e", tagUsage)));
assertEquals("c", toRowStr(scanner.getKeyValue()));
assertEquals("c", toRowStr(scanner.getCell()));
assertTrue(scanner.seekBefore(toKV("f", tagUsage)));
assertEquals("e", toRowStr(scanner.getKeyValue()));
assertEquals("e", toRowStr(scanner.getCell()));
assertTrue(scanner.seekBefore(toKV("g", tagUsage)));
assertEquals("e", toRowStr(scanner.getKeyValue()));
assertEquals("e", toRowStr(scanner.getCell()));
assertTrue(scanner.seekBefore(toKV("h", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
assertTrue(scanner.seekBefore(toKV("i", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
assertTrue(scanner.seekBefore(toKV("j", tagUsage)));
assertEquals("i", toRowStr(scanner.getKeyValue()));
Cell cell = scanner.getKeyValue();
assertEquals("i", toRowStr(scanner.getCell()));
Cell cell = scanner.getCell();
if (tagUsage != TagUsage.NO_TAG && cell.getTagsLength() > 0) {
Iterator<Tag> tagsIterator = CellUtil.tagsIterator(cell.getTagsArray(), cell.getTagsOffset(),
cell.getTagsLength());
@ -179,9 +179,9 @@ public class TestSeekTo {
}
}
assertTrue(scanner.seekBefore(toKV("k", tagUsage)));
assertEquals("i", toRowStr(scanner.getKeyValue()));
assertEquals("i", toRowStr(scanner.getCell()));
assertTrue(scanner.seekBefore(toKV("l", tagUsage)));
assertEquals("k", toRowStr(scanner.getKeyValue()));
assertEquals("k", toRowStr(scanner.getCell()));
reader.close();
deleteTestDir(fs);
@ -214,76 +214,76 @@ public class TestSeekTo {
// seekBefore d, so the scanner points to c
assertTrue(scanner.seekBefore(toKV("d", tagUsage)));
assertEquals("c", toRowStr(scanner.getKeyValue()));
assertEquals("c", toRowStr(scanner.getCell()));
// reseekTo e and g
assertEquals(0, scanner.reseekTo(toKV("c", tagUsage)));
assertEquals("c", toRowStr(scanner.getKeyValue()));
assertEquals("c", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore e, so the scanner points to c
assertTrue(scanner.seekBefore(toKV("e", tagUsage)));
assertEquals("c", toRowStr(scanner.getKeyValue()));
assertEquals("c", toRowStr(scanner.getCell()));
// reseekTo e and g
assertEquals(0, scanner.reseekTo(toKV("e", tagUsage)));
assertEquals("e", toRowStr(scanner.getKeyValue()));
assertEquals("e", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore f, so the scanner points to e
assertTrue(scanner.seekBefore(toKV("f", tagUsage)));
assertEquals("e", toRowStr(scanner.getKeyValue()));
assertEquals("e", toRowStr(scanner.getCell()));
// reseekTo e and g
assertEquals(0, scanner.reseekTo(toKV("e", tagUsage)));
assertEquals("e", toRowStr(scanner.getKeyValue()));
assertEquals("e", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore g, so the scanner points to e
assertTrue(scanner.seekBefore(toKV("g", tagUsage)));
assertEquals("e", toRowStr(scanner.getKeyValue()));
assertEquals("e", toRowStr(scanner.getCell()));
// reseekTo e and g again
assertEquals(0, scanner.reseekTo(toKV("e", tagUsage)));
assertEquals("e", toRowStr(scanner.getKeyValue()));
assertEquals("e", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore h, so the scanner points to g
assertTrue(scanner.seekBefore(toKV("h", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
// reseekTo g
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore i, so the scanner points to g
assertTrue(scanner.seekBefore(toKV("i", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
// reseekTo g
assertEquals(0, scanner.reseekTo(toKV("g", tagUsage)));
assertEquals("g", toRowStr(scanner.getKeyValue()));
assertEquals("g", toRowStr(scanner.getCell()));
// seekBefore j, so the scanner points to i
assertTrue(scanner.seekBefore(toKV("j", tagUsage)));
assertEquals("i", toRowStr(scanner.getKeyValue()));
assertEquals("i", toRowStr(scanner.getCell()));
// reseekTo i
assertEquals(0, scanner.reseekTo(toKV("i", tagUsage)));
assertEquals("i", toRowStr(scanner.getKeyValue()));
assertEquals("i", toRowStr(scanner.getCell()));
// seekBefore k, so the scanner points to i
assertTrue(scanner.seekBefore(toKV("k", tagUsage)));
assertEquals("i", toRowStr(scanner.getKeyValue()));
assertEquals("i", toRowStr(scanner.getCell()));
// reseekTo i and k
assertEquals(0, scanner.reseekTo(toKV("i", tagUsage)));
assertEquals("i", toRowStr(scanner.getKeyValue()));
assertEquals("i", toRowStr(scanner.getCell()));
assertEquals(0, scanner.reseekTo(toKV("k", tagUsage)));
assertEquals("k", toRowStr(scanner.getKeyValue()));
assertEquals("k", toRowStr(scanner.getCell()));
// seekBefore l, so the scanner points to k
assertTrue(scanner.seekBefore(toKV("l", tagUsage)));
assertEquals("k", toRowStr(scanner.getKeyValue()));
assertEquals("k", toRowStr(scanner.getCell()));
// reseekTo k
assertEquals(0, scanner.reseekTo(toKV("k", tagUsage)));
assertEquals("k", toRowStr(scanner.getKeyValue()));
assertEquals("k", toRowStr(scanner.getCell()));
deleteTestDir(fs);
}
@ -306,19 +306,19 @@ public class TestSeekTo {
assertEquals(-1, scanner.seekTo(toKV("a", tagUsage)));
assertEquals(1, scanner.seekTo(toKV("d", tagUsage)));
assertEquals("c", toRowStr(scanner.getKeyValue()));
assertEquals("c", toRowStr(scanner.getCell()));
// Across a block boundary now.
// 'h' does not exist so we will get a '1' back for not found.
assertEquals(0, scanner.seekTo(toKV("i", tagUsage)));
assertEquals("i", toRowStr(scanner.getKeyValue()));
assertEquals("i", toRowStr(scanner.getCell()));
assertEquals(1, scanner.seekTo(toKV("l", tagUsage)));
if (encoding == DataBlockEncoding.PREFIX_TREE) {
// TODO : Fix this
assertEquals(null, scanner.getKeyValue());
assertEquals(null, scanner.getCell());
} else {
assertEquals("k", toRowStr(scanner.getKeyValue()));
assertEquals("k", toRowStr(scanner.getCell()));
}
reader.close();

View File

@ -355,7 +355,7 @@ public class TestMajorCompaction {
HFileScanner scanner = f.getReader().getScanner(false, false);
scanner.seekTo();
do {
byte [] row = scanner.getKeyValue().getRow();
byte [] row = scanner.getCell().getRow();
if (Bytes.equals(row, STARTROW)) {
count1++;
} else if(Bytes.equals(row, secondRowBytes)) {

View File

@ -469,7 +469,7 @@ public class TestRegionReplicas {
do {
keys++;
Cell cell = scanner.getKeyValue();
Cell cell = scanner.getCell();
sum += Integer.parseInt(Bytes.toString(cell.getRowArray(),
cell.getRowOffset(), cell.getRowLength()));
} while (scanner.next());

View File

@ -172,7 +172,7 @@ public class TestStoreFile extends HBaseTestCase {
// timestamp.
Cell kv = reader.midkey();
byte [] midRow = kv.getRow();
kv = KeyValueUtil.createKeyValueFromKey(reader.getLastKey());
kv = reader.getLastKey();
byte [] finalRow = kv.getRow();
// Make a reference
HRegionInfo splitHri = new HRegionInfo(hri.getTable(), null, midRow);
@ -183,7 +183,7 @@ public class TestStoreFile extends HBaseTestCase {
// keys from top half of the file.
HFileScanner s = refHsf.createReader().getScanner(false, false);
for(boolean first = true; (!s.isSeeked() && s.seekTo()) || s.next();) {
ByteBuffer bb = s.getKey();
ByteBuffer bb = ByteBuffer.wrap(((KeyValue) s.getKey()).getKey());
kv = KeyValueUtil.createKeyValueFromKey(bb);
if (first) {
assertTrue(Bytes.equals(kv.getRow(), midRow));
@ -343,7 +343,7 @@ public class TestStoreFile extends HBaseTestCase {
HFileScanner topScanner = top.getScanner(false, false);
while ((!topScanner.isSeeked() && topScanner.seekTo()) ||
(topScanner.isSeeked() && topScanner.next())) {
key = topScanner.getKey();
key = ByteBuffer.wrap(((KeyValue) topScanner.getKey()).getKey());
if ((topScanner.getReader().getComparator().compare(midKV, key.array(),
key.arrayOffset(), key.limit())) > 0) {
@ -361,8 +361,8 @@ public class TestStoreFile extends HBaseTestCase {
HFileScanner bottomScanner = bottom.getScanner(false, false);
while ((!bottomScanner.isSeeked() && bottomScanner.seekTo()) ||
bottomScanner.next()) {
previous = bottomScanner.getKey();
key = bottomScanner.getKey();
previous = ByteBuffer.wrap(((KeyValue) bottomScanner.getKey()).getKey());
key = ByteBuffer.wrap(((KeyValue) bottomScanner.getKey()).getKey());
if (first) {
first = false;
LOG.info("First in bottom: " +
@ -394,7 +394,7 @@ public class TestStoreFile extends HBaseTestCase {
KeyValue.KeyOnlyKeyValue keyOnlyKV = new KeyValue.KeyOnlyKeyValue();
while ((!topScanner.isSeeked() && topScanner.seekTo()) ||
topScanner.next()) {
key = topScanner.getKey();
key = ByteBuffer.wrap(((KeyValue) topScanner.getKey()).getKey());
keyOnlyKV.setKey(key.array(), 0 + key.arrayOffset(), key.limit());
assertTrue(topScanner.getReader().getComparator()
.compare(keyOnlyKV, badmidkey, 0, badmidkey.length) >= 0);
@ -429,7 +429,7 @@ public class TestStoreFile extends HBaseTestCase {
bottomScanner = bottom.getScanner(false, false);
while ((!bottomScanner.isSeeked() && bottomScanner.seekTo()) ||
bottomScanner.next()) {
key = bottomScanner.getKey();
key = ByteBuffer.wrap(((KeyValue) bottomScanner.getKey()).getKey());
if (first) {
first = false;
keyKV = KeyValueUtil.createKeyValueFromKey(key);