HBASE-16665 Check whether KeyValueUtil.createXXX could be replaced by CellUtil without copy

This commit is contained in:
chenheng 2016-09-25 14:06:55 +08:00
parent f7bb6fbf21
commit 21969f5159
8 changed files with 46 additions and 11 deletions

View File

@ -275,12 +275,24 @@ public class Result implements CellScannable, CellScanner {
return result;
}
private byte[] notNullBytes(final byte[] bytes) {
if (bytes == null) {
return HConstants.EMPTY_BYTE_ARRAY;
} else {
return bytes;
}
}
protected int binarySearch(final Cell [] kvs,
final byte [] family,
final byte [] qualifier) {
byte[] familyNotNull = notNullBytes(family);
byte[] qualifierNotNull = notNullBytes(qualifier);
Cell searchTerm =
KeyValueUtil.createFirstOnRow(CellUtil.cloneRow(kvs[0]),
family, qualifier);
CellUtil.createFirstOnRow(kvs[0].getRowArray(),
kvs[0].getRowOffset(), kvs[0].getRowLength(),
familyNotNull, 0, (byte)familyNotNull.length,
qualifierNotNull, 0, qualifierNotNull.length);
// pos === ( -(insertion point) - 1)
int pos = Arrays.binarySearch(kvs, searchTerm, CellComparator.COMPARATOR);

View File

@ -1735,6 +1735,24 @@ public final class CellUtil {
return new FirstOnRowCell(row, roffset, rlength);
}
public static Cell createFirstOnRow(final byte[] row, final byte[] family, final byte[] col) {
return createFirstOnRow(row, 0, (short)row.length,
family, 0, (byte)family.length,
col, 0, col.length);
}
public static Cell createFirstOnRow(final byte[] row, int roffset, short rlength,
final byte[] family, int foffset, byte flength,
final byte[] col, int coffset, int clength) {
return new FirstOnRowColCell(row, roffset, rlength,
family, foffset, flength,
col, coffset, clength);
}
public static Cell createFirstOnRow(final byte[] row) {
return createFirstOnRow(row, 0, (short)row.length);
}
/**
* Create a Cell that is smaller than all other possible Cells for the given Cell's row.
* The family length is considered to be 0
@ -1824,6 +1842,10 @@ public final class CellUtil {
return new LastOnRowCell(cell.getRowArray(), cell.getRowOffset(), cell.getRowLength());
}
public static Cell createLastOnRow(final byte[] row) {
return new LastOnRowCell(row, 0, (short)row.length);
}
/**
* Create a Cell that is larger than all other possible Cells for the given Cell's rk:cf:q. Used
* in creating "fake keys" for the multi-column Bloom filter optimization to skip the row/column

View File

@ -317,7 +317,7 @@ public class HFilePrettyPrinter extends Configured implements Tool {
if (this.isSeekToRow) {
// seek to the first kv on this row
shouldScanKeysValues =
(scanner.seekTo(KeyValueUtil.createFirstOnRow(this.row)) != -1);
(scanner.seekTo(CellUtil.createFirstOnRow(this.row)) != -1);
} else {
shouldScanKeysValues = scanner.seekTo();
}

View File

@ -27,6 +27,7 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.ArrayBackedTag;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.KeyValue;
@ -155,7 +156,7 @@ public class MemStoreWrapper {
context.getCounter(SweepCounter.FILE_AFTER_MERGE_OR_CLEAN).increment(1);
// write reference/fileName back to the store files of HBase.
scanner = snapshot.getScanner();
scanner.seek(KeyValueUtil.createFirstOnRow(HConstants.EMPTY_START_ROW));
scanner.seek(CellUtil.createFirstOnRow(HConstants.EMPTY_START_ROW));
cell = null;
Tag tableNameTag = new ArrayBackedTag(TagType.MOB_TABLE_NAME_TAG_TYPE,
Bytes.toBytes(this.table.getName().toString()));

View File

@ -36,6 +36,7 @@ import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathFilter;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.CellUtil;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.InvalidFamilyOperationException;
@ -348,7 +349,7 @@ public class SweepReducer extends Reducer<Text, KeyValue, Writable, Writable> {
file.open();
try {
scanner = file.getScanner();
scanner.seek(KeyValueUtil.createFirstOnRow(HConstants.EMPTY_BYTE_ARRAY));
scanner.seek(CellUtil.createFirstOnRow(HConstants.EMPTY_BYTE_ARRAY));
Cell cell;
while (null != (cell = scanner.next())) {
if (kvs.contains(cell)) {

View File

@ -270,7 +270,7 @@ public abstract class AbstractMemStore implements MemStore {
// Get the Cells for the row/family/qualifier regardless of timestamp.
// For this case we want to clean up any other puts
Cell firstCell = KeyValueUtil.createFirstOnRow(
Cell firstCell = CellUtil.createFirstOnRow(
cell.getRowArray(), cell.getRowOffset(), cell.getRowLength(),
cell.getFamilyArray(), cell.getFamilyOffset(), cell.getFamilyLength(),
cell.getQualifierArray(), cell.getQualifierOffset(), cell.getQualifierLength());

View File

@ -30,6 +30,7 @@ import java.util.UUID;
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.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
@ -598,7 +599,7 @@ public class HRegionFileSystem {
try {
if (top) {
//check if larger than last key.
KeyValue splitKey = KeyValueUtil.createFirstOnRow(splitRow);
Cell splitKey = CellUtil.createFirstOnRow(splitRow);
Cell lastKey = f.getLastKey();
// If lastKey is null means storefile is empty.
if (lastKey == null) {
@ -609,7 +610,7 @@ public class HRegionFileSystem {
}
} else {
//check if smaller than first key
KeyValue splitKey = KeyValueUtil.createLastOnRow(splitRow);
Cell splitKey = CellUtil.createLastOnRow(splitRow);
Cell firstKey = f.getFirstKey();
// If firstKey is null means storefile is empty.
if (firstKey == null) {

View File

@ -236,9 +236,7 @@ public class StoreFileReader {
if (columns != null && columns.size() == 1) {
byte[] column = columns.first();
// create the required fake key
Cell kvKey = KeyValueUtil.createFirstOnRow(row, 0, row.length,
HConstants.EMPTY_BYTE_ARRAY, 0, 0, column, 0,
column.length);
Cell kvKey = CellUtil.createFirstOnRow(row, HConstants.EMPTY_BYTE_ARRAY, column);
return passesGeneralRowColBloomFilter(kvKey);
}