From 6e6c79d93eac45d39f8b534e8cdd1817d2a7d9ab Mon Sep 17 00:00:00 2001 From: Jean-Daniel Cryans Date: Sat, 6 Dec 2008 17:43:03 +0000 Subject: [PATCH] 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 --- CHANGES.txt | 3 ++ .../hbase/client/HConnectionManager.java | 5 +- .../hadoop/hbase/ipc/HRegionInterface.java | 6 ++- .../hadoop/hbase/regionserver/HRegion.java | 54 +++++++++++-------- .../hbase/regionserver/HRegionServer.java | 6 +-- 5 files changed, 44 insertions(+), 30 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 9538dc97239..0cf60d3da11 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java index 1f46a2c6d2c..f65bf1f72c9 100644 --- a/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -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)); diff --git a/src/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java b/src/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java index 0a41e1db05a..8d345b483c5 100644 --- a/src/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java +++ b/src/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java @@ -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; /** diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 83720f2e624..ea7e0024fe2 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -326,7 +326,8 @@ public class HRegion implements HConstants { private final Map> targetColumns = new ConcurrentHashMap>(); // Default access because read by tests. - protected final Map stores = new ConcurrentHashMap(); + protected final Map stores = + new ConcurrentHashMap(); 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 row exactly, + * or the one that immediately preceeds it, at or immediately before + * ts. + * + * @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 cells = new HbaseMapWritable(); - 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(); diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index fe34744ccd3..bc377ea1584 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -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();