HBASE-3170 RegionServer confused about empty row keys

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1436587 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2013-01-21 20:11:42 +00:00
parent f17016bd5b
commit 4580a66bbb
3 changed files with 45 additions and 3 deletions

View File

@ -92,6 +92,7 @@ public class Scan extends OperationWithAttributes {
private int storeLimit = -1; private int storeLimit = -1;
private int storeOffset = 0; private int storeOffset = 0;
private boolean getScan;
// If application wants to collect scan metrics, it needs to // If application wants to collect scan metrics, it needs to
// call scan.setAttribute(SCAN_ATTRIBUTES_ENABLE, Bytes.toBytes(Boolean.TRUE)) // call scan.setAttribute(SCAN_ATTRIBUTES_ENABLE, Bytes.toBytes(Boolean.TRUE))
@ -141,6 +142,8 @@ public class Scan extends OperationWithAttributes {
public Scan(byte [] startRow, byte [] stopRow) { public Scan(byte [] startRow, byte [] stopRow) {
this.startRow = startRow; this.startRow = startRow;
this.stopRow = stopRow; this.stopRow = stopRow;
//if the startRow and stopRow both are empty, it is not a Get
this.getScan = isStartRowAndEqualsStopRow();
} }
/** /**
@ -159,6 +162,7 @@ public class Scan extends OperationWithAttributes {
caching = scan.getCaching(); caching = scan.getCaching();
maxResultSize = scan.getMaxResultSize(); maxResultSize = scan.getMaxResultSize();
cacheBlocks = scan.getCacheBlocks(); cacheBlocks = scan.getCacheBlocks();
getScan = scan.isGetScan();
filter = scan.getFilter(); // clone? filter = scan.getFilter(); // clone?
loadColumnFamiliesOnDemand = scan.getLoadColumnFamiliesOnDemandValue(); loadColumnFamiliesOnDemand = scan.getLoadColumnFamiliesOnDemandValue();
TimeRange ctr = scan.getTimeRange(); TimeRange ctr = scan.getTimeRange();
@ -194,13 +198,17 @@ public class Scan extends OperationWithAttributes {
this.storeOffset = get.getRowOffsetPerColumnFamily(); this.storeOffset = get.getRowOffsetPerColumnFamily();
this.tr = get.getTimeRange(); this.tr = get.getTimeRange();
this.familyMap = get.getFamilyMap(); this.familyMap = get.getFamilyMap();
this.getScan = true;
} }
public boolean isGetScan() { public boolean isGetScan() {
return this.getScan || isStartRowAndEqualsStopRow();
}
private boolean isStartRowAndEqualsStopRow() {
return this.startRow != null && this.startRow.length > 0 && return this.startRow != null && this.startRow.length > 0 &&
Bytes.equals(this.startRow, this.stopRow); Bytes.equals(this.startRow, this.stopRow);
} }
/** /**
* Get all columns from the specified family. * Get all columns from the specified family.
* <p> * <p>

View File

@ -3406,7 +3406,7 @@ public class HRegion implements HeapSize { // , Writable{
} }
this.batch = scan.getBatch(); this.batch = scan.getBatch();
if (Bytes.equals(scan.getStopRow(), HConstants.EMPTY_END_ROW)) { if (Bytes.equals(scan.getStopRow(), HConstants.EMPTY_END_ROW) && !scan.isGetScan()) {
this.stopRow = null; this.stopRow = null;
} else { } else {
this.stopRow = scan.getStopRow(); this.stopRow = scan.getStopRow();

View File

@ -22,6 +22,7 @@ package org.apache.hadoop.hbase.client;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@ -51,6 +52,9 @@ public class TestFromClientSide3 {
private static byte[] FAMILY = Bytes.toBytes("testFamily"); private static byte[] FAMILY = Bytes.toBytes("testFamily");
private static Random random = new Random(); private static Random random = new Random();
private static int SLAVES = 3; private static int SLAVES = 3;
private final static byte[] COL_QUAL = Bytes.toBytes("f1");
private final static byte[] VAL_BYTES = Bytes.toBytes("v1");
private final static byte[] ROW_BYTES = Bytes.toBytes("r1");
/** /**
* @throws java.lang.Exception * @throws java.lang.Exception
@ -256,4 +260,34 @@ public class TestFromClientSide3 {
"hbase.hstore.compaction.min")); "hbase.hstore.compaction.min"));
} }
@Test
public void testGetEmptyRow() throws Exception {
//Create a table and put in 1 row
HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
HTableDescriptor desc = new HTableDescriptor(Bytes.toBytes("test"));
desc.addFamily(new HColumnDescriptor(FAMILY));
admin.createTable(desc);
HTable table = new HTable(TEST_UTIL.getConfiguration(), "test");
Put put = new Put(ROW_BYTES);
put.add(FAMILY, COL_QUAL, VAL_BYTES);
table.put(put);
table.flushCommits();
//Try getting the row with an empty row key and make sure the other base cases work as well
Result res = table.get(new Get(new byte[0]));
assertTrue(res.isEmpty() == true);
res = table.get(new Get(Bytes.toBytes("r1-not-exist")));
assertTrue(res.isEmpty() == true);
res = table.get(new Get(ROW_BYTES));
assertTrue(Arrays.equals(res.getValue(FAMILY, COL_QUAL), VAL_BYTES));
//Now actually put in a row with an empty row key
put = new Put(new byte[0]);
put.add(FAMILY, COL_QUAL, VAL_BYTES);
table.put(put);
table.flushCommits();
res = table.get(new Get(new byte[0]));
assertTrue(Arrays.equals(res.getValue(FAMILY, COL_QUAL), VAL_BYTES));
}
} }