diff --git a/CHANGES.txt b/CHANGES.txt index bda8e77e51d..3650a118e9e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -18,6 +18,7 @@ Hbase Change Log IMPROVEMENTS HBASE-469 Streamline HStore startup and compactions HBASE-544 Purge startUpdate from internal code and test cases + HBASE-557 HTable.getRow() should receive RowResult objects Release 0.1.0 diff --git a/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java b/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java index 36eb9fff57b..9683c5c7e54 100644 --- a/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java +++ b/src/java/org/apache/hadoop/hbase/client/HConnectionManager.java @@ -24,22 +24,16 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; import java.util.concurrent.ConcurrentHashMap; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.ipc.HbaseRPC; import org.apache.hadoop.hbase.util.Writables; -import org.apache.hadoop.hbase.io.HbaseMapWritable; import org.apache.hadoop.io.Text; -import org.apache.hadoop.io.Writable; import org.apache.hadoop.ipc.RemoteException; import org.apache.hadoop.hbase.ipc.HMasterInterface; import org.apache.hadoop.hbase.util.SoftSortedMap; -import org.apache.hadoop.hbase.HStoreKey; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HBaseConfiguration; @@ -354,21 +348,6 @@ public class HConnectionManager implements HConstants { } } - /** - * Convenience method for turning a MapWritable into the underlying - * SortedMap we all know and love. - */ - private SortedMap sortedMapFromMapWritable( - HbaseMapWritable writable) { - SortedMap results = new TreeMap(); - for (Map.Entry e: writable.entrySet()) { - HStoreKey key = (HStoreKey) e.getKey(); - results.put(key.getColumn(), (Cell)e.getValue()); - } - - return results; - } - /** * Search one of the meta tables (-ROOT- or .META.) for the HRegionLocation * info that contains the table and row we're seeking. @@ -412,7 +391,7 @@ public class HConnectionManager implements HConstants { getHRegionConnection(metaLocation.getServerAddress()); // query the root region for the location of the meta region - HbaseMapWritable regionInfoRow = server.getClosestRowBefore( + RowResult regionInfoRow = server.getClosestRowBefore( metaLocation.getRegionInfo().getRegionName(), metaKey); if (regionInfoRow == null) { @@ -420,11 +399,7 @@ public class HConnectionManager implements HConstants { "' does not exist."); } - // convert the MapWritable into a Map we can use - SortedMap results = - sortedMapFromMapWritable(regionInfoRow); - - Cell value = results.get(COL_REGIONINFO); + Cell value = regionInfoRow.get(COL_REGIONINFO); if (value == null || value.getValue().length == 0) { throw new IOException("HRegionInfo was null or empty in " + @@ -447,7 +422,7 @@ public class HConnectionManager implements HConstants { } String serverAddress = - Writables.cellToString(results.get(COL_SERVER)); + Writables.cellToString(regionInfoRow.get(COL_SERVER)); if (serverAddress.equals("")) { throw new NoServerForRegionException( diff --git a/src/java/org/apache/hadoop/hbase/client/HTable.java b/src/java/org/apache/hadoop/hbase/client/HTable.java index 77b993e4602..c63fd6e4173 100644 --- a/src/java/org/apache/hadoop/hbase/client/HTable.java +++ b/src/java/org/apache/hadoop/hbase/client/HTable.java @@ -39,8 +39,6 @@ import org.apache.hadoop.hbase.filter.WhileMatchRowFilter; import org.apache.hadoop.hbase.io.BatchUpdate; import org.apache.hadoop.hbase.io.Cell; import org.apache.hadoop.hbase.io.RowResult; -import org.apache.hadoop.hbase.io.HbaseMapWritable; -import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.util.Writables; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.Writable; @@ -329,7 +327,7 @@ public class HTable implements HConstants { * @return Map of columns to values. Map is empty if row does not exist. * @throws IOException */ - public SortedMap getRow(final Text row) throws IOException { + public Map getRow(final Text row) throws IOException { return getRow(row, HConstants.LATEST_TIMESTAMP); } @@ -341,24 +339,13 @@ public class HTable implements HConstants { * @return Map of columns to values. Map is empty if row does not exist. * @throws IOException */ - public SortedMap getRow(final Text row, final long ts) + public Map getRow(final Text row, final long ts) throws IOException { - HbaseMapWritable value = null; - - value = getRegionServerWithRetries(new ServerCallable(row) { - public HbaseMapWritable call() throws IOException { + return getRegionServerWithRetries(new ServerCallable(row) { + public RowResult call() throws IOException { return server.getRow(location.getRegionInfo().getRegionName(), row, ts); } }); - - SortedMap results = new TreeMap(); - if (value != null && value.size() != 0) { - for (Map.Entry e: value.entrySet()) { - HStoreKey key = (HStoreKey) e.getKey(); - results.put(key.getColumn(), (Cell)e.getValue()); - } - } - return results; } /** @@ -369,7 +356,7 @@ public class HTable implements HConstants { * @return Map of columns to values. Map is empty if row does not exist. * @throws IOException */ - public SortedMap getRow(final Text row, final Text[] columns) + public Map getRow(final Text row, final Text[] columns) throws IOException { return getRow(row, columns, HConstants.LATEST_TIMESTAMP); } @@ -383,26 +370,15 @@ public class HTable implements HConstants { * @return Map of columns to values. Map is empty if row does not exist. * @throws IOException */ - public SortedMap getRow(final Text row, final Text[] columns, + public Map getRow(final Text row, final Text[] columns, final long ts) - throws IOException { - HbaseMapWritable value = null; - - value = getRegionServerWithRetries(new ServerCallable(row) { - public HbaseMapWritable call() throws IOException { + throws IOException { + return getRegionServerWithRetries(new ServerCallable(row) { + public RowResult call() throws IOException { return server.getRow(location.getRegionInfo().getRegionName(), row, columns, ts); } }); - - SortedMap results = new TreeMap(); - if (value != null && value.size() != 0) { - for (Map.Entry e: value.entrySet()) { - HStoreKey key = (HStoreKey) e.getKey(); - results.put(key.getColumn(), (Cell)e.getValue()); - } - } - return results; } /** diff --git a/src/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java b/src/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java index 78640dcacf2..cb973a686b3 100644 --- a/src/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java +++ b/src/java/org/apache/hadoop/hbase/ipc/HRegionInterface.java @@ -26,7 +26,6 @@ import org.apache.hadoop.hbase.io.BatchUpdate; import org.apache.hadoop.hbase.io.Cell; import org.apache.hadoop.hbase.io.RowResult; -import org.apache.hadoop.hbase.io.HbaseMapWritable; import org.apache.hadoop.io.Text; import org.apache.hadoop.ipc.VersionedProtocol; import org.apache.hadoop.hbase.HRegionInfo; @@ -100,7 +99,7 @@ public interface HRegionInterface extends VersionedProtocol { * @return map of values * @throws IOException */ - public HbaseMapWritable getRow(final Text regionName, final Text row, final long ts) + public RowResult getRow(final Text regionName, final Text row, final long ts) throws IOException; /** @@ -112,7 +111,7 @@ public interface HRegionInterface extends VersionedProtocol { * @return map of values * @throws IOException */ - public HbaseMapWritable getClosestRowBefore(final Text regionName, final Text row) + public RowResult getClosestRowBefore(final Text regionName, final Text row) throws IOException; /** @@ -123,7 +122,7 @@ public interface HRegionInterface extends VersionedProtocol { * @return map of values * @throws IOException */ - public HbaseMapWritable getRow(final Text regionName, final Text row, + public RowResult getRow(final Text regionName, final Text row, final Text[] columns, final long ts) throws IOException; @@ -135,7 +134,7 @@ public interface HRegionInterface extends VersionedProtocol { * @return map of values * @throws IOException */ - public HbaseMapWritable getRow(final Text regionName, final Text row, + public RowResult getRow(final Text regionName, final Text row, final Text[] columns) 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 5ed67e9f534..514ec95e55e 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -28,6 +28,7 @@ import java.util.Set; import java.util.Random; import java.util.SortedMap; import java.util.TreeMap; +import java.util.HashMap; import java.util.TreeSet; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; @@ -46,6 +47,8 @@ import org.apache.hadoop.hbase.filter.RowFilterInterface; import org.apache.hadoop.hbase.io.BatchOperation; import org.apache.hadoop.hbase.io.BatchUpdate; import org.apache.hadoop.hbase.io.Cell; +import org.apache.hadoop.hbase.io.RowResult; +import org.apache.hadoop.hbase.io.HbaseMapWritable; import org.apache.hadoop.hbase.util.Writables; import org.apache.hadoop.io.Text; import org.apache.hadoop.io.WritableUtils; @@ -1158,7 +1161,7 @@ public class HRegion implements HConstants { * @return map of values * @throws IOException */ - public Map getClosestRowBefore(final Text row) + public RowResult getClosestRowBefore(final Text row) 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 @@ -1190,15 +1193,18 @@ public class HRegion implements HConstants { if (key == null) { return null; } - + // now that we've found our key, get the values - TreeMap result = new TreeMap(); + Map cells = new HashMap(); for (Text colFamily: stores.keySet()) { HStore targetStore = stores.get(colFamily); - targetStore.getFull(key, null, result); + targetStore.getFull(key, null, cells); } - return result; + HbaseMapWritable cellsWritten = new HbaseMapWritable(); + cellsWritten.putAll(cells); + + return new RowResult(key.getRow(), cellsWritten); } finally { lock.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 0452e4a5ca0..209c714e44f 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1000,20 +1000,20 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable { } /** {@inheritDoc} */ - public HbaseMapWritable getRow(final Text regionName, final Text row, final long ts) + public RowResult getRow(final Text regionName, final Text row, final long ts) throws IOException { return getRow(regionName, row, null, ts); } /** {@inheritDoc} */ - public HbaseMapWritable getRow(final Text regionName, final Text row, + public RowResult getRow(final Text regionName, final Text row, final Text[] columns) throws IOException { return getRow(regionName, row, columns, HConstants.LATEST_TIMESTAMP); } /** {@inheritDoc} */ - public HbaseMapWritable getRow(final Text regionName, final Text row, + public RowResult getRow(final Text regionName, final Text row, final Text[] columns, final long ts) throws IOException { checkOpen(); @@ -1029,10 +1029,8 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable { HRegion region = getRegion(regionName); Map map = region.getFull(row, columnSet, ts); HbaseMapWritable result = new HbaseMapWritable(); - for (Map.Entry es: map.entrySet()) { - result.put(new HStoreKey(row, es.getKey()), es.getValue()); - } - return result; + result.putAll(map); + return new RowResult(row, result); } catch (IOException e) { checkFileSystem(); throw e; @@ -1040,7 +1038,7 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable { } /** {@inheritDoc} */ - public HbaseMapWritable getClosestRowBefore(final Text regionName, + public RowResult getClosestRowBefore(final Text regionName, final Text row) throws IOException { checkOpen(); @@ -1048,18 +1046,9 @@ public class HRegionServer implements HConstants, HRegionInterface, Runnable { try { // locate the region we're operating on HRegion region = getRegion(regionName); - HbaseMapWritable result = new HbaseMapWritable(); + // ask the region for all the data - Map map = region.getClosestRowBefore(row); - // convert to a MapWritable - if (map == null) { - return null; - } - for (Map.Entry es: map.entrySet()) { - result.put(new HStoreKey(row, es.getKey()), es.getValue()); - } - return result; - + return region.getClosestRowBefore(row); } catch (IOException e) { checkFileSystem(); throw e; diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HStore.java b/src/java/org/apache/hadoop/hbase/regionserver/HStore.java index 9672a1fb0f5..1be0cb30b03 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HStore.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HStore.java @@ -1092,7 +1092,7 @@ public class HStore implements HConstants { * * The returned object should map column names to Cells. */ - void getFull(HStoreKey key, final Set columns, TreeMap results) + void getFull(HStoreKey key, final Set columns, Map results) throws IOException { Map deletes = new HashMap(); @@ -1124,7 +1124,7 @@ public class HStore implements HConstants { } private void getFullFromMapFile(MapFile.Reader map, HStoreKey key, - Set columns, Map deletes, TreeMap results) + Set columns, Map deletes, Map results) throws IOException { synchronized(map) { // seek back to the beginning diff --git a/src/java/org/apache/hadoop/hbase/regionserver/Memcache.java b/src/java/org/apache/hadoop/hbase/regionserver/Memcache.java index beacc6c0d83..7c31d6f4b8c 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/Memcache.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/Memcache.java @@ -145,7 +145,7 @@ class Memcache { * @param results */ void getFull(HStoreKey key, Set columns, Map deletes, - SortedMap results) { + Map results) { this.lock.readLock().lock(); try { synchronized (memcache) { @@ -161,8 +161,7 @@ class Memcache { } private void internalGetFull(SortedMap map, HStoreKey key, - Set columns, Map deletes, - SortedMap results) { + Set columns, Map deletes, Map results) { if (map.isEmpty() || key == null) { return; diff --git a/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java b/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java index 527a8245b5d..ce006a27c03 100644 --- a/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java +++ b/src/java/org/apache/hadoop/hbase/thrift/ThriftServer.java @@ -24,7 +24,7 @@ import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; -import java.util.SortedMap; +import java.util.Map; import java.util.TreeMap; import java.util.Map.Entry; @@ -275,9 +275,9 @@ public class ThriftServer { } try { HTable table = getTable(tableName); - SortedMap values = + Map values = table.getRow(getText(row), timestamp); - // copy the map from type to + // copy the map from type to HashMap returnValues = new HashMap(); for (Entry e : values.entrySet()) { returnValues.put(e.getKey().getBytes(), e.getValue().getValue()); @@ -472,7 +472,7 @@ public class ThriftServer { retval.row = key.getRow().getBytes(); retval.columns = new HashMap(results.size()); - for (SortedMap.Entry e : results.entrySet()) { + for (Map.Entry e : results.entrySet()) { retval.columns.put(e.getKey().getBytes(), e.getValue()); } return retval;