HBASE-1336 Splitting up the compare of family+column into 2 different compares
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@772021 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
92e5efdcb6
commit
734890772f
|
@ -110,6 +110,7 @@ Release 0.20.0 - Unreleased
|
||||||
HBASE-1264 Wrong return values of comparators for ColumnValueFilter
|
HBASE-1264 Wrong return values of comparators for ColumnValueFilter
|
||||||
(Thomas Schneider via Andrew Purtell)
|
(Thomas Schneider via Andrew Purtell)
|
||||||
HBASE-1374 NPE out of ZooKeeperWrapper.loadZooKeeperConfig
|
HBASE-1374 NPE out of ZooKeeperWrapper.loadZooKeeperConfig
|
||||||
|
HBASE-1336 Splitting up the compare of family+column into 2 different compare
|
||||||
|
|
||||||
IMPROVEMENTS
|
IMPROVEMENTS
|
||||||
HBASE-1089 Add count of regions on filesystem to master UI; add percentage
|
HBASE-1089 Add count of regions on filesystem to master UI; add percentage
|
||||||
|
|
|
@ -772,13 +772,17 @@ public class KeyValue {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param column Column minus its delimiter
|
* @param column Column minus its delimiter
|
||||||
|
* @param familylength Length of family in passed <code>column</code>
|
||||||
* @return True if column matches.
|
* @return True if column matches.
|
||||||
* @see #matchingColumn(byte[])
|
* @see #matchingColumn(byte[])
|
||||||
*/
|
*/
|
||||||
public boolean matchingColumnNoDelimiter(final byte [] column) {
|
public boolean matchingColumnNoDelimiter(final byte [] column,
|
||||||
|
final int familylength) {
|
||||||
int o = getColumnOffset();
|
int o = getColumnOffset();
|
||||||
int l = getColumnLength(o);
|
int l = getColumnLength(o);
|
||||||
return compareColumns(getBuffer(), o, l, column, 0, column.length) == 0;
|
int f = getFamilyLength(o);
|
||||||
|
return compareColumns(getBuffer(), o, l, f,
|
||||||
|
column, 0, column.length, familylength) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -801,15 +805,27 @@ public class KeyValue {
|
||||||
* @param left
|
* @param left
|
||||||
* @param loffset
|
* @param loffset
|
||||||
* @param llength
|
* @param llength
|
||||||
|
* @param lfamilylength Offset of family delimiter in left column.
|
||||||
* @param right
|
* @param right
|
||||||
* @param roffset
|
* @param roffset
|
||||||
* @param rlength
|
* @param rlength
|
||||||
|
* @param rfamilylength Offset of family delimiter in right column.
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
static int compareColumns(final byte [] left, final int loffset,
|
static int compareColumns(final byte [] left, final int loffset,
|
||||||
final int llength, final byte [] right, final int roffset,
|
final int llength, final int lfamilylength,
|
||||||
final int rlength) {
|
final byte [] right, final int roffset, final int rlength,
|
||||||
return Bytes.compareTo(left, loffset, llength, right, roffset, 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1037,11 +1053,12 @@ public class KeyValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
public int compareColumns(final KeyValue left, final byte [] right,
|
public int compareColumns(final KeyValue left, final byte [] right,
|
||||||
final int roffset, final int rlength) {
|
final int roffset, final int rlength, final int rfamilyoffset) {
|
||||||
int offset = left.getColumnOffset();
|
int offset = left.getColumnOffset();
|
||||||
int length = left.getColumnLength(offset);
|
int length = left.getColumnLength(offset);
|
||||||
return getRawComparator().compareColumns(left.getBuffer(), offset, length,
|
return getRawComparator().compareColumns(left.getBuffer(), offset, length,
|
||||||
right, roffset, rlength);
|
left.getFamilyLength(offset),
|
||||||
|
right, roffset, rlength, rfamilyoffset);
|
||||||
}
|
}
|
||||||
|
|
||||||
int compareColumns(final KeyValue left, final short lrowlength,
|
int compareColumns(final KeyValue left, final short lrowlength,
|
||||||
|
@ -1051,9 +1068,11 @@ public class KeyValue {
|
||||||
int roffset = right.getColumnOffset(rrowlength);
|
int roffset = right.getColumnOffset(rrowlength);
|
||||||
int llength = left.getColumnLength(loffset, lkeylength);
|
int llength = left.getColumnLength(loffset, lkeylength);
|
||||||
int rlength = right.getColumnLength(roffset, rkeylength);
|
int rlength = right.getColumnLength(roffset, rkeylength);
|
||||||
|
int lfamilylength = left.getFamilyLength(loffset);
|
||||||
|
int rfamilylength = right.getFamilyLength(roffset);
|
||||||
return getRawComparator().compareColumns(left.getBuffer(), loffset,
|
return getRawComparator().compareColumns(left.getBuffer(), loffset,
|
||||||
llength,
|
llength, lfamilylength,
|
||||||
right.getBuffer(), roffset, rlength);
|
right.getBuffer(), roffset, rlength, rfamilylength);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1381,9 +1400,11 @@ public class KeyValue {
|
||||||
return Bytes.compareTo(left, loffset, llength, right, roffset, rlength);
|
return Bytes.compareTo(left, loffset, llength, right, roffset, rlength);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int compareColumns(byte [] left, int loffset, int llength,
|
protected int compareColumns(
|
||||||
byte [] right, int roffset, int rlength) {
|
byte [] left, int loffset, int llength, final int lfamilylength,
|
||||||
return KeyValue.compareColumns(left, loffset, llength, right, roffset, rlength);
|
byte [] right, int roffset, int rlength, final int rfamilylength) {
|
||||||
|
return KeyValue.compareColumns(left, loffset, llength, lfamilylength,
|
||||||
|
right, roffset, rlength, rfamilylength);
|
||||||
}
|
}
|
||||||
|
|
||||||
int compareTimestamps(final long ltimestamp, final long rtimestamp) {
|
int compareTimestamps(final long ltimestamp, final long rtimestamp) {
|
||||||
|
|
|
@ -126,6 +126,7 @@ public abstract class HAbstractScanner implements InternalScanner {
|
||||||
private Pattern columnMatcher;
|
private Pattern columnMatcher;
|
||||||
// Column without delimiter so easy compare to KeyValue column
|
// Column without delimiter so easy compare to KeyValue column
|
||||||
private byte [] col;
|
private byte [] col;
|
||||||
|
private int familylength = 0;
|
||||||
|
|
||||||
ColumnMatcher(final byte [] col) throws IOException {
|
ColumnMatcher(final byte [] col) throws IOException {
|
||||||
byte [][] parse = parseColumn(col);
|
byte [][] parse = parseColumn(col);
|
||||||
|
@ -150,6 +151,7 @@ public abstract class HAbstractScanner implements InternalScanner {
|
||||||
} else {
|
} else {
|
||||||
this.matchType = MATCH_TYPE.SIMPLE;
|
this.matchType = MATCH_TYPE.SIMPLE;
|
||||||
this.col = columnWithoutDelimiter;
|
this.col = columnWithoutDelimiter;
|
||||||
|
this.familylength = parse[0].length;
|
||||||
this.wildCardmatch = false;
|
this.wildCardmatch = false;
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
@ -165,7 +167,7 @@ public abstract class HAbstractScanner implements InternalScanner {
|
||||||
*/
|
*/
|
||||||
boolean matches(final KeyValue kv) throws IOException {
|
boolean matches(final KeyValue kv) throws IOException {
|
||||||
if (this.matchType == MATCH_TYPE.SIMPLE) {
|
if (this.matchType == MATCH_TYPE.SIMPLE) {
|
||||||
return kv.matchingColumnNoDelimiter(this.col);
|
return kv.matchingColumnNoDelimiter(this.col, this.familylength);
|
||||||
} else if(this.matchType == MATCH_TYPE.FAMILY_ONLY) {
|
} else if(this.matchType == MATCH_TYPE.FAMILY_ONLY) {
|
||||||
return kv.matchingFamily(this.family);
|
return kv.matchingFamily(this.family);
|
||||||
} else if (this.matchType == MATCH_TYPE.REGEX) {
|
} else if (this.matchType == MATCH_TYPE.REGEX) {
|
||||||
|
|
|
@ -309,7 +309,9 @@ public class Store implements HConstants {
|
||||||
// Check this edit is for me. Also, guard against writing the speical
|
// Check this edit is for me. Also, guard against writing the speical
|
||||||
// METACOLUMN info such as HBASE::CACHEFLUSH entries
|
// METACOLUMN info such as HBASE::CACHEFLUSH entries
|
||||||
KeyValue kv = val.getKeyValue();
|
KeyValue kv = val.getKeyValue();
|
||||||
if (val.isTransactionEntry() || kv.matchingColumnNoDelimiter(HLog.METACOLUMN) ||
|
if (val.isTransactionEntry() ||
|
||||||
|
kv.matchingColumnNoDelimiter(HLog.METACOLUMN,
|
||||||
|
HLog.METACOLUMN.length - 1) ||
|
||||||
!Bytes.equals(key.getRegionName(), regioninfo.getRegionName()) ||
|
!Bytes.equals(key.getRegionName(), regioninfo.getRegionName()) ||
|
||||||
!kv.matchingFamily(family.getName())) {
|
!kv.matchingFamily(family.getName())) {
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -251,7 +251,8 @@ public class MetaUtils {
|
||||||
HRegionInfo info = null;
|
HRegionInfo info = null;
|
||||||
for (KeyValue kv: results) {
|
for (KeyValue kv: results) {
|
||||||
if (KeyValue.META_COMPARATOR.compareColumns(kv,
|
if (KeyValue.META_COMPARATOR.compareColumns(kv,
|
||||||
HConstants.COL_REGIONINFO, 0, HConstants.COL_REGIONINFO.length) == 0) {
|
HConstants.COL_REGIONINFO, 0, HConstants.COL_REGIONINFO.length,
|
||||||
|
HConstants.COLUMN_FAMILY_STR.length()) == 0) {
|
||||||
info = Writables.getHRegionInfoOrNull(kv.getValue());
|
info = Writables.getHRegionInfoOrNull(kv.getValue());
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
LOG.warn("region info is null for row " +
|
LOG.warn("region info is null for row " +
|
||||||
|
|
|
@ -35,6 +35,19 @@ import org.apache.hadoop.hbase.util.Bytes;
|
||||||
public class TestKeyValue extends TestCase {
|
public class TestKeyValue extends TestCase {
|
||||||
private final Log LOG = LogFactory.getLog(this.getClass().getName());
|
private final Log LOG = LogFactory.getLog(this.getClass().getName());
|
||||||
|
|
||||||
|
public void testColumnCompare() throws Exception {
|
||||||
|
final byte [] a = Bytes.toBytes("aaa");
|
||||||
|
byte [] column1 = Bytes.toBytes("abc:def");
|
||||||
|
byte [] column2 = Bytes.toBytes("abcd:ef");
|
||||||
|
KeyValue aaa = new KeyValue(a, column1, a);
|
||||||
|
assertFalse(KeyValue.COMPARATOR.
|
||||||
|
compareColumns(aaa, column2, 0, column2.length, 4) == 0);
|
||||||
|
column1 = Bytes.toBytes("abcd:");
|
||||||
|
aaa = new KeyValue(a, column1, a);
|
||||||
|
assertFalse(KeyValue.COMPARATOR.
|
||||||
|
compareColumns(aaa, column1, 0, column1.length, 4) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
public void testBasics() throws Exception {
|
public void testBasics() throws Exception {
|
||||||
LOG.info("LOWKEY: " + KeyValue.LOWESTKEY.toString());
|
LOG.info("LOWKEY: " + KeyValue.LOWESTKEY.toString());
|
||||||
check(Bytes.toBytes(getName()),
|
check(Bytes.toBytes(getName()),
|
||||||
|
|
Loading…
Reference in New Issue