HBASE-9502. HStore.seekToScanner should handle magic value (Liang Xie)
git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1546925 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bad837066f
commit
178d0b918e
|
@ -1647,7 +1647,7 @@ public class HStore implements Store {
|
||||||
if (this.comparator.compareRows(firstKV, firstOnRow) == 0) kv = firstKV;
|
if (this.comparator.compareRows(firstKV, firstOnRow) == 0) kv = firstKV;
|
||||||
int result = scanner.seekTo(kv.getBuffer(), kv.getKeyOffset(),
|
int result = scanner.seekTo(kv.getBuffer(), kv.getKeyOffset(),
|
||||||
kv.getKeyLength());
|
kv.getKeyLength());
|
||||||
return result >= 0;
|
return result != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -4239,28 +4239,44 @@ public class TestFromClientSide {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetClosestRowBefore() throws IOException {
|
public void testGetClosestRowBefore() throws IOException, InterruptedException {
|
||||||
final byte [] tableAname = Bytes.toBytes("testGetClosestRowBefore");
|
final byte[] tableAname = Bytes.toBytes("testGetClosestRowBefore");
|
||||||
final byte [] row = Bytes.toBytes("row");
|
final byte[] firstRow = Bytes.toBytes("row111");
|
||||||
|
final byte[] secondRow = Bytes.toBytes("row222");
|
||||||
|
final byte[] thirdRow = Bytes.toBytes("row333");
|
||||||
|
final byte[] forthRow = Bytes.toBytes("row444");
|
||||||
|
final byte[] beforeFirstRow = Bytes.toBytes("row");
|
||||||
|
final byte[] beforeSecondRow = Bytes.toBytes("row22");
|
||||||
|
final byte[] beforeThirdRow = Bytes.toBytes("row33");
|
||||||
|
final byte[] beforeForthRow = Bytes.toBytes("row44");
|
||||||
|
|
||||||
|
HTable table =
|
||||||
|
TEST_UTIL.createTable(tableAname,
|
||||||
|
new byte[][] { HConstants.CATALOG_FAMILY, Bytes.toBytes("info2") }, 1, 64);
|
||||||
|
// set block size to 64 to making 2 kvs into one block, bypassing the walkForwardInSingleRow
|
||||||
|
// in Store.rowAtOrBeforeFromStoreFile
|
||||||
|
table.setAutoFlush(true);
|
||||||
|
String regionName = table.getRegionLocations().firstKey().getEncodedName();
|
||||||
|
HRegion region =
|
||||||
|
TEST_UTIL.getRSForFirstRegionInTable(tableAname).getFromOnlineRegions(regionName);
|
||||||
|
Put put1 = new Put(firstRow);
|
||||||
|
Put put2 = new Put(secondRow);
|
||||||
|
Put put3 = new Put(thirdRow);
|
||||||
|
Put put4 = new Put(forthRow);
|
||||||
|
byte[] one = new byte[] { 1 };
|
||||||
|
byte[] two = new byte[] { 2 };
|
||||||
|
byte[] three = new byte[] { 3 };
|
||||||
|
byte[] four = new byte[] { 4 };
|
||||||
|
|
||||||
byte[] firstRow = Bytes.toBytes("ro");
|
put1.add(HConstants.CATALOG_FAMILY, null, one);
|
||||||
byte[] beforeFirstRow = Bytes.toBytes("rn");
|
put2.add(HConstants.CATALOG_FAMILY, null, two);
|
||||||
byte[] beforeSecondRow = Bytes.toBytes("rov");
|
put3.add(HConstants.CATALOG_FAMILY, null, three);
|
||||||
|
put4.add(HConstants.CATALOG_FAMILY, null, four);
|
||||||
HTable table = TEST_UTIL.createTable(tableAname,
|
table.put(put1);
|
||||||
new byte [][] {HConstants.CATALOG_FAMILY, Bytes.toBytes("info2")});
|
|
||||||
Put put = new Put(firstRow);
|
|
||||||
Put put2 = new Put(row);
|
|
||||||
byte[] zero = new byte[]{0};
|
|
||||||
byte[] one = new byte[]{1};
|
|
||||||
|
|
||||||
put.add(HConstants.CATALOG_FAMILY, null, zero);
|
|
||||||
put2.add(HConstants.CATALOG_FAMILY, null, one);
|
|
||||||
|
|
||||||
table.put(put);
|
|
||||||
table.put(put2);
|
table.put(put2);
|
||||||
|
table.put(put3);
|
||||||
|
table.put(put4);
|
||||||
|
region.flushcache();
|
||||||
Result result = null;
|
Result result = null;
|
||||||
|
|
||||||
// Test before first that null is returned
|
// Test before first that null is returned
|
||||||
|
@ -4270,22 +4286,50 @@ public class TestFromClientSide {
|
||||||
// Test at first that first is returned
|
// Test at first that first is returned
|
||||||
result = table.getRowOrBefore(firstRow, HConstants.CATALOG_FAMILY);
|
result = table.getRowOrBefore(firstRow, HConstants.CATALOG_FAMILY);
|
||||||
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
||||||
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), zero));
|
assertTrue(Bytes.equals(result.getRow(), firstRow));
|
||||||
|
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), one));
|
||||||
|
|
||||||
// Test in between first and second that first is returned
|
// Test in between first and second that first is returned
|
||||||
result = table.getRowOrBefore(beforeSecondRow, HConstants.CATALOG_FAMILY);
|
result = table.getRowOrBefore(beforeSecondRow, HConstants.CATALOG_FAMILY);
|
||||||
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
||||||
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), zero));
|
assertTrue(Bytes.equals(result.getRow(), firstRow));
|
||||||
|
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), one));
|
||||||
|
|
||||||
// Test at second make sure second is returned
|
// Test at second make sure second is returned
|
||||||
result = table.getRowOrBefore(row, HConstants.CATALOG_FAMILY);
|
result = table.getRowOrBefore(secondRow, HConstants.CATALOG_FAMILY);
|
||||||
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
||||||
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), one));
|
assertTrue(Bytes.equals(result.getRow(), secondRow));
|
||||||
|
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), two));
|
||||||
|
|
||||||
// Test after second, make sure second is returned
|
// Test in second and third, make sure second is returned
|
||||||
result = table.getRowOrBefore(Bytes.add(row,one), HConstants.CATALOG_FAMILY);
|
result = table.getRowOrBefore(beforeThirdRow, HConstants.CATALOG_FAMILY);
|
||||||
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
||||||
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), one));
|
assertTrue(Bytes.equals(result.getRow(), secondRow));
|
||||||
|
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), two));
|
||||||
|
|
||||||
|
// Test at third make sure third is returned
|
||||||
|
result = table.getRowOrBefore(thirdRow, HConstants.CATALOG_FAMILY);
|
||||||
|
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
||||||
|
assertTrue(Bytes.equals(result.getRow(), thirdRow));
|
||||||
|
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), three));
|
||||||
|
|
||||||
|
// Test in third and forth, make sure third is returned
|
||||||
|
result = table.getRowOrBefore(beforeForthRow, HConstants.CATALOG_FAMILY);
|
||||||
|
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
||||||
|
assertTrue(Bytes.equals(result.getRow(), thirdRow));
|
||||||
|
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), three));
|
||||||
|
|
||||||
|
// Test at forth make sure forth is returned
|
||||||
|
result = table.getRowOrBefore(forthRow, HConstants.CATALOG_FAMILY);
|
||||||
|
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
||||||
|
assertTrue(Bytes.equals(result.getRow(), forthRow));
|
||||||
|
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), four));
|
||||||
|
|
||||||
|
// Test after forth make sure forth is returned
|
||||||
|
result = table.getRowOrBefore(Bytes.add(forthRow, one), HConstants.CATALOG_FAMILY);
|
||||||
|
assertTrue(result.containsColumn(HConstants.CATALOG_FAMILY, null));
|
||||||
|
assertTrue(Bytes.equals(result.getRow(), forthRow));
|
||||||
|
assertTrue(Bytes.equals(result.getValue(HConstants.CATALOG_FAMILY, null), four));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue