HBASE-1804 Puts are permitted (and stored) when including an appended colon

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@810668 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-09-02 18:56:59 +00:00
parent ea3b8028c9
commit 61c20195ca
6 changed files with 28 additions and 29 deletions

View File

@ -365,6 +365,7 @@ Release 0.20.0 - Unreleased
HBASE-1809 NPE thrown in BoundedRangeFileInputStream
HBASE-1810 ConcurrentModificationException in region assignment
(Mathias Herberts via Stack)
HBASE-1804 Puts are permitted (and stored) when including an appended colon
IMPROVEMENTS
HBASE-1089 Add count of regions on filesystem to master UI; add percentage

View File

@ -101,7 +101,7 @@ ISerializable {
// Key is hash of the family name.
public final Map<byte [], HColumnDescriptor> families =
new TreeMap<byte [], HColumnDescriptor>(KeyValue.FAMILY_COMPARATOR);
new TreeMap<byte [], HColumnDescriptor>(Bytes.BYTES_RAWCOMPARATOR);
/**
* Private constructor used internally creating table descriptors for

View File

@ -69,7 +69,8 @@ public class KeyValue implements Writable, HeapSize {
*/
public static final char COLUMN_FAMILY_DELIMITER = ':';
public static final byte[] COLUMN_FAMILY_DELIM_ARRAY = new byte[]{COLUMN_FAMILY_DELIMITER};
public static final byte[] COLUMN_FAMILY_DELIM_ARRAY =
new byte[]{COLUMN_FAMILY_DELIMITER};
/**
* Comparator for plain key/values; i.e. non-catalog table key/values.
@ -106,30 +107,6 @@ public class KeyValue implements Writable, HeapSize {
*/
public static KeyComparator ROOT_KEY_COMPARATOR = new RootKeyComparator();
/**
* Comparator that compares the family portion of columns only.
* Use this making NavigableMaps of Stores or when you need to compare
* column family portion only of two column names.
*/
public static final RawComparator<byte []> FAMILY_COMPARATOR =
new RawComparator<byte []> () {
public int compare(byte [] a, int ao, int al, byte [] b, int bo, int bl) {
int indexa = KeyValue.getDelimiter(a, ao, al, COLUMN_FAMILY_DELIMITER);
if (indexa < 0) {
indexa = al;
}
int indexb = KeyValue.getDelimiter(b, bo, bl, COLUMN_FAMILY_DELIMITER);
if (indexb < 0) {
indexb = bl;
}
return Bytes.compareTo(a, ao, indexa, b, bo, indexb);
}
public int compare(byte[] a, byte[] b) {
return compare(a, 0, a.length, b, 0, b.length);
}
};
/**
* Get the appropriate row comparator for the specified table.
*

View File

@ -351,7 +351,9 @@ public class HTable implements HTableInterface {
*/
public RowResult getClosestRowBefore(final byte[] row, final byte[] family)
throws IOException {
Result r = getRowOrBefore(row, family);
// Do parse in case we are passed a family with a ':' on it.
final byte [] f = KeyValue.parseColumn(family)[0];
Result r = getRowOrBefore(row, f);
return r == null || r.isEmpty()? null: r.getRowResult();
}

View File

@ -122,7 +122,7 @@ public class HRegion implements HConstants, HeapSize { // , Writable{
private final Map<Integer, byte []> locksToRows =
new ConcurrentHashMap<Integer, byte []>();
protected final Map<byte [], Store> stores =
new ConcurrentSkipListMap<byte [], Store>(KeyValue.FAMILY_COMPARATOR);
new ConcurrentSkipListMap<byte [], Store>(Bytes.BYTES_RAWCOMPARATOR);
//These variable are just used for getting data out of the region, to test on
//client side

View File

@ -72,13 +72,32 @@ public class TestHRegion extends HBaseTestCase {
super.setUp();
}
//////////////////////////////////////////////////////////////////////////////
// New tests that doesn't spin up a mini cluster but rather just test the
// individual code pieces in the HRegion. Putting files locally in
// /tmp/testtable
//////////////////////////////////////////////////////////////////////////////
public void testFamilyWithAndWithoutColon() throws Exception {
byte [] b = Bytes.toBytes(getName());
byte [] cf = Bytes.toBytes("cf");
initHRegion(b, getName(), cf);
Put p = new Put(b);
byte [] cfwithcolon = Bytes.toBytes("cf:");
p.add(cfwithcolon, cfwithcolon, cfwithcolon);
boolean exception = false;
try {
this.region.put(p);
} catch (NoSuchColumnFamilyException e) {
exception = true;
}
assertTrue(exception);
// Can I add it using old style call?
p = new Put(b);
p.add(cfwithcolon, System.currentTimeMillis(), cfwithcolon);
this.region.put(p);
}
//////////////////////////////////////////////////////////////////////////////
// checkAndPut tests
//////////////////////////////////////////////////////////////////////////////