HADOOP-2600 Performance: HStore.getRowKeyAtOrBefore should use

MapFile.Reader#getClosest (before)


git-svn-id: https://svn.apache.org/repos/asf/lucene/hadoop/trunk/src/contrib/hbase@612614 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2008-01-16 23:04:28 +00:00
parent f8269a1e47
commit 5f5472e631
3 changed files with 30 additions and 12 deletions

View File

@ -42,6 +42,9 @@ Trunk (unreleased changes)
consumes >20% CPU consumes >20% CPU
HADOOP-2443 Keep lazy cache of regions in client rather than an HADOOP-2443 Keep lazy cache of regions in client rather than an
'authoritative' list (Bryan Duxbury via Stack) 'authoritative' list (Bryan Duxbury via Stack)
HADOOP-2600 Performance: HStore.getRowKeyAtOrBefore should use
MapFile.Reader#getClosest (before)
(Bryan Duxbury via Stack)
BUG FIXES BUG FIXES
HADOOP-2059 In tests, exceptions in min dfs shutdown should not fail test HADOOP-2059 In tests, exceptions in min dfs shutdown should not fail test

View File

@ -1871,30 +1871,46 @@ public class HStore implements HConstants {
private Text rowAtOrBeforeFromMapFile(MapFile.Reader map, Text row, private Text rowAtOrBeforeFromMapFile(MapFile.Reader map, Text row,
long timestamp) long timestamp)
throws IOException { throws IOException {
HStoreKey searchKey = new HStoreKey(row, timestamp);
Text previousRow = null; Text previousRow = null;
ImmutableBytesWritable readval = new ImmutableBytesWritable(); ImmutableBytesWritable readval = new ImmutableBytesWritable();
HStoreKey readkey = new HStoreKey(); HStoreKey readkey = new HStoreKey();
synchronized(map) { synchronized(map) {
// start at the beginning of the map // don't bother with the rest of this if the file is empty
// TODO: this sucks. do a clever binary search instead.
map.reset(); map.reset();
if (!map.next(readkey, readval)) {
while(map.next(readkey, readval)){ return null;
}
HStoreKey finalKey = new HStoreKey();
map.finalKey(finalKey);
if (finalKey.getRow().compareTo(row) < 0) {
return finalKey.getRow();
}
// seek to the exact row, or the one that would be immediately before it
readkey = (HStoreKey)map.getClosest(searchKey, readval, true);
if (readkey == null) {
// didn't find anything that would match, so returns
return null;
}
do {
if (readkey.getRow().compareTo(row) == 0) { if (readkey.getRow().compareTo(row) == 0) {
// exact match on row // exact match on row
if (readkey.getTimestamp() <= timestamp) { if (readkey.getTimestamp() <= timestamp) {
// timestamp fits, return this key // timestamp fits, return this key
return readkey.getRow(); return readkey.getRow();
} }
// getting here means that we matched the row, but the timestamp // getting here means that we matched the row, but the timestamp
// is too recent - hopefully one of the next cells will match // is too recent - hopefully one of the next cells will match
// better, so keep rolling // better, so keep rolling
} continue;
// if the row key we just read is beyond the key we're searching for, } else if (readkey.getRow().toString().compareTo(row.toString()) > 0 ) {
// then we're done; return the last key we saw before this one // if the row key we just read is beyond the key we're searching for,
else if (readkey.getRow().toString().compareTo(row.toString()) > 0 ) { // then we're done; return the last key we saw before this one
return previousRow; return previousRow;
} else { } else {
// so, the row key doesn't match, and we haven't gone past the row // so, the row key doesn't match, and we haven't gone past the row
@ -1905,8 +1921,8 @@ public class HStore implements HConstants {
} }
// otherwise, ignore this key, because it doesn't fulfill our // otherwise, ignore this key, because it doesn't fulfill our
// requirements. // requirements.
} }
} } while(map.next(readkey, readval));
} }
// getting here means we exhausted all of the cells in the mapfile. // getting here means we exhausted all of the cells in the mapfile.
// whatever satisfying row we reached previously is the row we should // whatever satisfying row we reached previously is the row we should

View File

@ -201,7 +201,6 @@ public class TestGet2 extends HBaseTestCase {
assertEquals(new String(results.get(COLUMNS[0])), "t20 bytes"); assertEquals(new String(results.get(COLUMNS[0])), "t20 bytes");
// try "050", should get stuff from "040" // try "050", should get stuff from "040"
t50 = new Text("050");
results = region.getClosestRowBefore(t50, HConstants.LATEST_TIMESTAMP); results = region.getClosestRowBefore(t50, HConstants.LATEST_TIMESTAMP);
assertEquals(new String(results.get(COLUMNS[0])), "t40 bytes"); assertEquals(new String(results.get(COLUMNS[0])), "t40 bytes");
} finally { } finally {