From 809180eef2f86d7efab042487bb730de5668dfcb Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Wed, 30 Jul 2008 04:37:06 +0000 Subject: [PATCH] HBASE-783 For single row, single family retrieval, getRow() works half as fast as getScanner().next() git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@680910 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES.txt | 2 ++ .../hadoop/hbase/regionserver/HRegion.java | 25 ++++++++++++++++--- .../hadoop/hbase/regionserver/HStore.java | 3 ++- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index b4ed15fd733..5d7f4025d02 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -324,6 +324,8 @@ Release 0.2.0 HBASE-746 Batching row mutations via thrift (Tim Sell via Stack) HBASE-772 Up default lease period from 60 to 120 seconds HBASE-779 Test changing hbase.hregion.memcache.block.multiplier to 2 + HBASE-783 For single row, single family retrieval, getRow() works half + as fast as getScanner().next() (Jean-Daniel Cryans via Stack) NEW FEATURES HBASE-47 Option to set TTL for columns in hbase diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 1417e7c99a8..74cdc031ecb 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -1181,23 +1181,40 @@ public class HRegion implements HConstants { } HStoreKey key = new HStoreKey(row, ts); Integer lid = obtainRowLock(row); + HashSet storeSet = new HashSet(); try { TreeMap result = new TreeMap(Bytes.BYTES_COMPARATOR); - for (HStore targetStore: stores.values()) { - targetStore.getFull(key, columns, result); + // Get the concerned columns or all of them + if (columns != null) { + for (byte[] bs : columns) { + HStore store = stores.get(Bytes.mapKey(HStoreKey.getFamily(bs))); + if (store != null) { + storeSet.add(store); + } + } } - // Previous step won't fetch whole families: HBASE-631. + else + storeSet.addAll(stores.values()); + // For each column name that is just a column family, open the store - // related to it and fetch everything for that row. + // related to it and fetch everything for that row. HBASE-631 + // Also remove each store from storeSet so that these stores + // won't be opened for no reason. HBASE-783 if (columns != null) { for (byte[] bs : columns) { if (HStoreKey.getFamilyDelimiterIndex(bs) == (bs.length - 1)) { HStore store = stores.get(Bytes.mapKey(HStoreKey.getFamily(bs))); store.getFull(key, null, result); + storeSet.remove(store); } } } + + for (HStore targetStore: storeSet) { + targetStore.getFull(key, columns, result); + } + return result; } finally { releaseRowLock(lid); diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HStore.java b/src/java/org/apache/hadoop/hbase/regionserver/HStore.java index 1de27b9c61e..1908d0ea994 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HStore.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HStore.java @@ -752,7 +752,8 @@ public class HStore implements HConstants { // last key of storefiles. maxId = this.storefiles.lastKey().longValue(); } - if (!force && filesToCompact.size() < compactionThreshold) { + if (!force && !hasReferences(filesToCompact) && + filesToCompact.size() < compactionThreshold) { return checkSplit(); } if (!fs.exists(compactionDir) && !fs.mkdirs(compactionDir)) {