HBASE-1046 Narrow getClosestRowBefore by passing column family (backport)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/branches/0.18@724019 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cfb9cb2946
commit
6e6c79d93e
|
@ -7,6 +7,9 @@ Release 0.18.2 - Unreleased
|
|||
HBASE-927 We don't recover if HRS hosting -ROOT-/.META. goes down -
|
||||
(back port from trunk)
|
||||
|
||||
IMPROVEMENTS
|
||||
HBASE-1046 Narrow getClosestRowBefore by passing column family (backport)
|
||||
|
||||
|
||||
Release 0.18.1 - Released October 27, 2008
|
||||
|
||||
|
|
|
@ -486,9 +486,10 @@ public class HConnectionManager implements HConstants {
|
|||
HRegionInterface server =
|
||||
getHRegionConnection(metaLocation.getServerAddress());
|
||||
|
||||
// query the root region for the location of the meta region
|
||||
// Query the root region for the location of the meta region
|
||||
RowResult regionInfoRow = server.getClosestRowBefore(
|
||||
metaLocation.getRegionInfo().getRegionName(), metaKey);
|
||||
metaLocation.getRegionInfo().getRegionName(), metaKey,
|
||||
HConstants.COLUMN_FAMILY);
|
||||
|
||||
if (regionInfoRow == null) {
|
||||
throw new TableNotFoundException(Bytes.toString(tableName));
|
||||
|
|
|
@ -37,8 +37,9 @@ public interface HRegionInterface extends VersionedProtocol {
|
|||
/**
|
||||
* Protocol version.
|
||||
* Upped to 4 when we removed overloaded methods from the protocol.
|
||||
* Upped to 5 when we changed getClosestRowBefore signature.
|
||||
*/
|
||||
public static final long versionID = 4L;
|
||||
public static final long versionID = 5L;
|
||||
|
||||
/**
|
||||
* Get metainfo about an HRegion
|
||||
|
@ -72,11 +73,12 @@ public interface HRegionInterface extends VersionedProtocol {
|
|||
*
|
||||
* @param regionName region name
|
||||
* @param row row key
|
||||
* @param columnFamily Column family to look for row in.
|
||||
* @return map of values
|
||||
* @throws IOException
|
||||
*/
|
||||
public RowResult getClosestRowBefore(final byte [] regionName,
|
||||
final byte [] row)
|
||||
final byte [] row, final byte [] columnFamily)
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
|
|
|
@ -326,7 +326,8 @@ public class HRegion implements HConstants {
|
|||
private final Map<Integer, TreeMap<HStoreKey, byte []>> targetColumns =
|
||||
new ConcurrentHashMap<Integer, TreeMap<HStoreKey, byte []>>();
|
||||
// Default access because read by tests.
|
||||
protected final Map<Integer, HStore> stores = new ConcurrentHashMap<Integer, HStore>();
|
||||
protected final Map<Integer, HStore> stores =
|
||||
new ConcurrentHashMap<Integer, HStore>();
|
||||
final AtomicLong memcacheSize = new AtomicLong(0);
|
||||
|
||||
final Path basedir;
|
||||
|
@ -1236,40 +1237,47 @@ public class HRegion implements HConstants {
|
|||
* @return map of values
|
||||
* @throws IOException
|
||||
*/
|
||||
public RowResult getClosestRowBefore(final byte [] row)
|
||||
throws IOException{
|
||||
RowResult getClosestRowBefore(final byte [] row) throws IOException{
|
||||
return getClosestRowBefore(row, HConstants.COLUMN_FAMILY);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the data for the row that matches <i>row</i> exactly,
|
||||
* or the one that immediately preceeds it, at or immediately before
|
||||
* <i>ts</i>.
|
||||
*
|
||||
* @param row row key
|
||||
* @param columnFamily
|
||||
* @return map of values
|
||||
* @throws IOException
|
||||
*/
|
||||
public RowResult getClosestRowBefore(final byte [] row,
|
||||
final byte [] columnFamily) throws IOException{
|
||||
// look across all the HStores for this region and determine what the
|
||||
// closest key is across all column families, since the data may be sparse
|
||||
HStoreKey key = null;
|
||||
checkRow(row);
|
||||
splitsAndClosesLock.readLock().lock();
|
||||
try {
|
||||
// examine each column family for the preceeding or matching key
|
||||
for (HStore store : stores.values()) {
|
||||
// get the closest key
|
||||
byte [] closestKey = store.getRowKeyAtOrBefore(row);
|
||||
// if it happens to be an exact match, we can stop looping
|
||||
if (HStoreKey.equalsTwoRowKeys(regionInfo,row, closestKey)) {
|
||||
key = new HStoreKey(closestKey, this.regionInfo);
|
||||
break;
|
||||
}
|
||||
// otherwise, we need to check if it's the max and move to the next
|
||||
if (closestKey != null
|
||||
&& (key == null || HStoreKey.compareTwoRowKeys(
|
||||
HStore store = getStore(columnFamily);
|
||||
// get the closest key
|
||||
byte [] closestKey = store.getRowKeyAtOrBefore(row);
|
||||
// If it happens to be an exact match, we can stop looping.
|
||||
// Otherwise, we need to check if it's the max and move to the next
|
||||
if (HStoreKey.equalsTwoRowKeys(regionInfo, row, closestKey)) {
|
||||
key = new HStoreKey(closestKey, this.regionInfo);
|
||||
} else if (closestKey != null &&
|
||||
(key == null || HStoreKey.compareTwoRowKeys(
|
||||
regionInfo,closestKey, key.getRow()) > 0) ) {
|
||||
key = new HStoreKey(closestKey, this.regionInfo);
|
||||
}
|
||||
}
|
||||
if (key == null) {
|
||||
key = new HStoreKey(closestKey, this.regionInfo);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
// now that we've found our key, get the values
|
||||
// Now that we've found our key, get the values
|
||||
HbaseMapWritable<byte [], Cell> cells =
|
||||
new HbaseMapWritable<byte [], Cell>();
|
||||
for (HStore s: stores.values()) {
|
||||
s.getFull(key, null, cells);
|
||||
}
|
||||
store.getFull(key, null, cells);
|
||||
return new RowResult(key.getRow(), cells);
|
||||
} finally {
|
||||
splitsAndClosesLock.readLock().unlock();
|
||||
|
|
|
@ -808,7 +808,7 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable {
|
|||
if(e == null || stopRequested.get()) {
|
||||
continue;
|
||||
}
|
||||
LOG.info(e.msg);
|
||||
LOG.info("Worker: " + e.msg);
|
||||
switch(e.msg.getType()) {
|
||||
|
||||
case MSG_REGIONSERVER_QUIESCE:
|
||||
|
@ -1048,7 +1048,7 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable {
|
|||
}
|
||||
|
||||
public RowResult getClosestRowBefore(final byte [] regionName,
|
||||
final byte [] row)
|
||||
final byte [] row, final byte [] columnFamily)
|
||||
throws IOException {
|
||||
checkOpen();
|
||||
requestCount.incrementAndGet();
|
||||
|
@ -1056,7 +1056,7 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable {
|
|||
// locate the region we're operating on
|
||||
HRegion region = getRegion(regionName);
|
||||
// ask the region for all the data
|
||||
RowResult rr = region.getClosestRowBefore(row);
|
||||
RowResult rr = region.getClosestRowBefore(row, columnFamily);
|
||||
return rr;
|
||||
} catch (IOException e) {
|
||||
checkFileSystem();
|
||||
|
|
Loading…
Reference in New Issue