HBASE-6162 Move KeyValue to hbase-common module
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1350378 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
1c8d541b6d
commit
d602aa4385
|
@ -667,6 +667,8 @@ public final class HConstants {
|
||||||
* The actual value is irrelevant because this is always compared by reference.
|
* The actual value is irrelevant because this is always compared by reference.
|
||||||
*/
|
*/
|
||||||
public static final byte [] NO_NEXT_INDEXED_KEY = Bytes.toBytes("NO_NEXT_INDEXED_KEY");
|
public static final byte [] NO_NEXT_INDEXED_KEY = Bytes.toBytes("NO_NEXT_INDEXED_KEY");
|
||||||
|
/** delimiter used between portions of a region name */
|
||||||
|
public static final int DELIMITER = ',';
|
||||||
|
|
||||||
private HConstants() {
|
private HConstants() {
|
||||||
// Can't be instantiated with this ctor.
|
// Can't be instantiated with this ctor.
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2009 The Apache Software Foundation
|
* Copyright The Apache Software Foundation
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
@ -33,7 +33,6 @@ import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.classification.InterfaceStability;
|
import org.apache.hadoop.classification.InterfaceStability;
|
||||||
import org.apache.hadoop.hbase.io.HeapSize;
|
import org.apache.hadoop.hbase.io.HeapSize;
|
||||||
import org.apache.hadoop.hbase.io.hfile.HFile;
|
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
import org.apache.hadoop.hbase.util.ClassSize;
|
import org.apache.hadoop.hbase.util.ClassSize;
|
||||||
import org.apache.hadoop.io.RawComparator;
|
import org.apache.hadoop.io.RawComparator;
|
||||||
|
@ -127,10 +126,10 @@ public class KeyValue implements Writable, HeapSize {
|
||||||
* @return The comparator.
|
* @return The comparator.
|
||||||
*/
|
*/
|
||||||
public static KeyComparator getRowComparator(byte [] tableName) {
|
public static KeyComparator getRowComparator(byte [] tableName) {
|
||||||
if(Bytes.equals(HTableDescriptor.ROOT_TABLEDESC.getName(),tableName)) {
|
if(Bytes.equals(HConstants.ROOT_TABLE_NAME,tableName)) {
|
||||||
return ROOT_COMPARATOR.getRawComparator();
|
return ROOT_COMPARATOR.getRawComparator();
|
||||||
}
|
}
|
||||||
if(Bytes.equals(HTableDescriptor.META_TABLEDESC.getName(), tableName)) {
|
if(Bytes.equals(HConstants.META_TABLE_NAME, tableName)) {
|
||||||
return META_COMPARATOR.getRawComparator();
|
return META_COMPARATOR.getRawComparator();
|
||||||
}
|
}
|
||||||
return COMPARATOR.getRawComparator();
|
return COMPARATOR.getRawComparator();
|
||||||
|
@ -2232,11 +2231,11 @@ public class KeyValue implements Writable, HeapSize {
|
||||||
int lmetaOffsetPlusDelimiter = loffset + metalength;
|
int lmetaOffsetPlusDelimiter = loffset + metalength;
|
||||||
int leftFarDelimiter = getDelimiterInReverse(left,
|
int leftFarDelimiter = getDelimiterInReverse(left,
|
||||||
lmetaOffsetPlusDelimiter,
|
lmetaOffsetPlusDelimiter,
|
||||||
llength - metalength, HRegionInfo.DELIMITER);
|
llength - metalength, HConstants.DELIMITER);
|
||||||
int rmetaOffsetPlusDelimiter = roffset + metalength;
|
int rmetaOffsetPlusDelimiter = roffset + metalength;
|
||||||
int rightFarDelimiter = getDelimiterInReverse(right,
|
int rightFarDelimiter = getDelimiterInReverse(right,
|
||||||
rmetaOffsetPlusDelimiter, rlength - metalength,
|
rmetaOffsetPlusDelimiter, rlength - metalength,
|
||||||
HRegionInfo.DELIMITER);
|
HConstants.DELIMITER);
|
||||||
if (leftFarDelimiter < 0 && rightFarDelimiter >= 0) {
|
if (leftFarDelimiter < 0 && rightFarDelimiter >= 0) {
|
||||||
// Nothing between .META. and regionid. Its first key.
|
// Nothing between .META. and regionid. Its first key.
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -2287,9 +2286,9 @@ public class KeyValue implements Writable, HeapSize {
|
||||||
// LOG.info("META " + Bytes.toString(left, loffset, llength) +
|
// LOG.info("META " + Bytes.toString(left, loffset, llength) +
|
||||||
// "---" + Bytes.toString(right, roffset, rlength));
|
// "---" + Bytes.toString(right, roffset, rlength));
|
||||||
int leftDelimiter = getDelimiter(left, loffset, llength,
|
int leftDelimiter = getDelimiter(left, loffset, llength,
|
||||||
HRegionInfo.DELIMITER);
|
HConstants.DELIMITER);
|
||||||
int rightDelimiter = getDelimiter(right, roffset, rlength,
|
int rightDelimiter = getDelimiter(right, roffset, rlength,
|
||||||
HRegionInfo.DELIMITER);
|
HConstants.DELIMITER);
|
||||||
if (leftDelimiter < 0 && rightDelimiter >= 0) {
|
if (leftDelimiter < 0 && rightDelimiter >= 0) {
|
||||||
// Nothing between .META. and regionid. Its first key.
|
// Nothing between .META. and regionid. Its first key.
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -2309,10 +2308,10 @@ public class KeyValue implements Writable, HeapSize {
|
||||||
leftDelimiter++;
|
leftDelimiter++;
|
||||||
rightDelimiter++;
|
rightDelimiter++;
|
||||||
int leftFarDelimiter = getRequiredDelimiterInReverse(left, leftDelimiter,
|
int leftFarDelimiter = getRequiredDelimiterInReverse(left, leftDelimiter,
|
||||||
llength - (leftDelimiter - loffset), HRegionInfo.DELIMITER);
|
llength - (leftDelimiter - loffset), HConstants.DELIMITER);
|
||||||
int rightFarDelimiter = getRequiredDelimiterInReverse(right,
|
int rightFarDelimiter = getRequiredDelimiterInReverse(right,
|
||||||
rightDelimiter, rlength - (rightDelimiter - roffset),
|
rightDelimiter, rlength - (rightDelimiter - roffset),
|
||||||
HRegionInfo.DELIMITER);
|
HConstants.DELIMITER);
|
||||||
// Now compare middlesection of row.
|
// Now compare middlesection of row.
|
||||||
result = super.compareRows(left, leftDelimiter,
|
result = super.compareRows(left, leftDelimiter,
|
||||||
leftFarDelimiter - leftDelimiter, right, rightDelimiter,
|
leftFarDelimiter - leftDelimiter, right, rightDelimiter,
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2009 The Apache Software Foundation
|
* Copyright The Apache Software Foundation
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
|
@ -1,5 +1,5 @@
|
||||||
/**
|
/**
|
||||||
* Copyright 2010 The Apache Software Foundation
|
* Copyright The Apache Software Foundation
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
|
@ -147,9 +147,6 @@ implements WritableComparable<HRegionInfo> {
|
||||||
return encodedRegionName;
|
return encodedRegionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** delimiter used between portions of a region name */
|
|
||||||
public static final int DELIMITER = ',';
|
|
||||||
|
|
||||||
/** HRegionInfo for root region */
|
/** HRegionInfo for root region */
|
||||||
public static final HRegionInfo ROOT_REGIONINFO =
|
public static final HRegionInfo ROOT_REGIONINFO =
|
||||||
new HRegionInfo(0L, Bytes.toBytes("-ROOT-"));
|
new HRegionInfo(0L, Bytes.toBytes("-ROOT-"));
|
||||||
|
@ -363,12 +360,12 @@ implements WritableComparable<HRegionInfo> {
|
||||||
|
|
||||||
int offset = tableName.length;
|
int offset = tableName.length;
|
||||||
System.arraycopy(tableName, 0, b, 0, offset);
|
System.arraycopy(tableName, 0, b, 0, offset);
|
||||||
b[offset++] = DELIMITER;
|
b[offset++] = HConstants.DELIMITER;
|
||||||
if (startKey != null && startKey.length > 0) {
|
if (startKey != null && startKey.length > 0) {
|
||||||
System.arraycopy(startKey, 0, b, offset, startKey.length);
|
System.arraycopy(startKey, 0, b, offset, startKey.length);
|
||||||
offset += startKey.length;
|
offset += startKey.length;
|
||||||
}
|
}
|
||||||
b[offset++] = DELIMITER;
|
b[offset++] = HConstants.DELIMITER;
|
||||||
System.arraycopy(id, 0, b, offset, id.length);
|
System.arraycopy(id, 0, b, offset, id.length);
|
||||||
offset += id.length;
|
offset += id.length;
|
||||||
|
|
||||||
|
@ -406,7 +403,7 @@ implements WritableComparable<HRegionInfo> {
|
||||||
public static byte [] getTableName(byte [] regionName) {
|
public static byte [] getTableName(byte [] regionName) {
|
||||||
int offset = -1;
|
int offset = -1;
|
||||||
for (int i = 0; i < regionName.length; i++) {
|
for (int i = 0; i < regionName.length; i++) {
|
||||||
if (regionName[i] == DELIMITER) {
|
if (regionName[i] == HConstants.DELIMITER) {
|
||||||
offset = i;
|
offset = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -426,7 +423,7 @@ implements WritableComparable<HRegionInfo> {
|
||||||
throws IOException {
|
throws IOException {
|
||||||
int offset = -1;
|
int offset = -1;
|
||||||
for (int i = 0; i < regionName.length; i++) {
|
for (int i = 0; i < regionName.length; i++) {
|
||||||
if (regionName[i] == DELIMITER) {
|
if (regionName[i] == HConstants.DELIMITER) {
|
||||||
offset = i;
|
offset = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -436,7 +433,7 @@ implements WritableComparable<HRegionInfo> {
|
||||||
System.arraycopy(regionName, 0, tableName, 0, offset);
|
System.arraycopy(regionName, 0, tableName, 0, offset);
|
||||||
offset = -1;
|
offset = -1;
|
||||||
for (int i = regionName.length - 1; i > 0; i--) {
|
for (int i = regionName.length - 1; i > 0; i--) {
|
||||||
if(regionName[i] == DELIMITER) {
|
if(regionName[i] == HConstants.DELIMITER) {
|
||||||
offset = i;
|
offset = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -454,8 +454,8 @@ public class MetaReader {
|
||||||
static byte [] getTableStartRowForMeta(final byte [] tableName) {
|
static byte [] getTableStartRowForMeta(final byte [] tableName) {
|
||||||
byte [] startRow = new byte[tableName.length + 2];
|
byte [] startRow = new byte[tableName.length + 2];
|
||||||
System.arraycopy(tableName, 0, startRow, 0, tableName.length);
|
System.arraycopy(tableName, 0, startRow, 0, tableName.length);
|
||||||
startRow[startRow.length - 2] = HRegionInfo.DELIMITER;
|
startRow[startRow.length - 2] = HConstants.DELIMITER;
|
||||||
startRow[startRow.length - 1] = HRegionInfo.DELIMITER;
|
startRow[startRow.length - 1] = HConstants.DELIMITER;
|
||||||
return startRow;
|
return startRow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import java.util.TreeMap;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
import org.apache.hadoop.classification.InterfaceAudience;
|
import org.apache.hadoop.classification.InterfaceAudience;
|
||||||
import org.apache.hadoop.hbase.HRegionInfo;
|
import org.apache.hadoop.hbase.HConstants;
|
||||||
import org.apache.hadoop.hbase.KeyValue;
|
import org.apache.hadoop.hbase.KeyValue;
|
||||||
import org.apache.hadoop.hbase.KeyValue.KVComparator;
|
import org.apache.hadoop.hbase.KeyValue.KVComparator;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
@ -70,7 +70,7 @@ class GetClosestRowBeforeTracker {
|
||||||
int l = -1;
|
int l = -1;
|
||||||
if (metaregion) {
|
if (metaregion) {
|
||||||
l = KeyValue.getDelimiter(kv.getBuffer(), rowoffset, kv.getRowLength(),
|
l = KeyValue.getDelimiter(kv.getBuffer(), rowoffset, kv.getRowLength(),
|
||||||
HRegionInfo.DELIMITER) - this.rowoffset;
|
HConstants.DELIMITER) - this.rowoffset;
|
||||||
}
|
}
|
||||||
this.tablenamePlusDelimiterLength = metaregion? l + 1: -1;
|
this.tablenamePlusDelimiterLength = metaregion? l + 1: -1;
|
||||||
this.oldestts = System.currentTimeMillis() - ttl;
|
this.oldestts = System.currentTimeMillis() - ttl;
|
||||||
|
|
|
@ -166,9 +166,9 @@ public class TestGetClosestAtOrBefore extends HBaseTestCase {
|
||||||
|
|
||||||
private byte [] extractRowFromMetaRow(final byte [] b) {
|
private byte [] extractRowFromMetaRow(final byte [] b) {
|
||||||
int firstDelimiter = KeyValue.getDelimiter(b, 0, b.length,
|
int firstDelimiter = KeyValue.getDelimiter(b, 0, b.length,
|
||||||
HRegionInfo.DELIMITER);
|
HConstants.DELIMITER);
|
||||||
int lastDelimiter = KeyValue.getDelimiterInReverse(b, 0, b.length,
|
int lastDelimiter = KeyValue.getDelimiterInReverse(b, 0, b.length,
|
||||||
HRegionInfo.DELIMITER);
|
HConstants.DELIMITER);
|
||||||
int length = lastDelimiter - firstDelimiter - 1;
|
int length = lastDelimiter - firstDelimiter - 1;
|
||||||
byte [] row = new byte[length];
|
byte [] row = new byte[length];
|
||||||
System.arraycopy(b, firstDelimiter + 1, row, 0, length);
|
System.arraycopy(b, firstDelimiter + 1, row, 0, length);
|
||||||
|
|
Loading…
Reference in New Issue