Index: src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java =================================================================== --- src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java (revision 1152375) +++ src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java (working copy) @@ -19,13 +19,20 @@ */ package org.apache.hadoop.hbase.regionserver; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.apache.hadoop.hbase.HBaseTestingUtility; +import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.HRegionInfo; import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.FSUtils; import org.apache.hadoop.hbase.util.MD5Hash; - import org.junit.Test; -import static org.junit.Assert.*; public class TestHRegionInfo { @Test @@ -53,6 +60,25 @@ } @Test + public void testGetSetOfHTD() { + HBaseTestingUtility HTU = new HBaseTestingUtility(); + final String tablename = "testGetSetOfHTD"; + HTableDescriptor htd = new HTableDescriptor(tablename); + FSUtils.createTableDescriptor(htd, HTU.getConfiguration()); + HRegionInfo hri = new HRegionInfo(Bytes.toBytes("testGetSetOfHTD"), + HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW); + HTableDescriptor htd2 = hri.getTableDesc(); + assertTrue(htd.equals(htd2)); + final String key = "SOME_KEY"; + assertNull(htd.getValue(key)); + final String value = "VALUE"; + htd.setValue(key, value); + hri.setTableDesc(htd); + HTableDescriptor htd3 = hri.getTableDesc(); + assertTrue(htd.equals(htd3)); + } + + @Test public void testContainsRange() { HTableDescriptor tableDesc = new HTableDescriptor("testtable"); HRegionInfo hri = new HRegionInfo( Index: src/main/java/org/apache/hadoop/hbase/HRegionInfo.java =================================================================== --- src/main/java/org/apache/hadoop/hbase/HRegionInfo.java (revision 1152383) +++ src/main/java/org/apache/hadoop/hbase/HRegionInfo.java (working copy) @@ -26,9 +26,13 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.fs.FileSystem; +import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.KeyValue.KVComparator; import org.apache.hadoop.hbase.migration.HRegionInfo090x; import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.FSTableDescriptors; import org.apache.hadoop.hbase.util.JenkinsHash; import org.apache.hadoop.hbase.util.MD5Hash; import org.apache.hadoop.io.VersionedWritable; @@ -535,18 +539,50 @@ Bytes.equals(endKey, HConstants.EMPTY_BYTE_ARRAY)); } - /** @return the tableDesc */ + /** + * @return the tableDesc + * @deprecated Do not use; expensive call + * use HRegionInfo.getTableNameAsString() in place of + * HRegionInfo.getTableDesc().getNameAsString() + */ @Deprecated - public HTableDescriptor getTableDesc(){ - return null; + public HTableDescriptor getTableDesc() { + Configuration c = HBaseConfiguration.create(); + FileSystem fs; + try { + fs = FileSystem.get(c); + } catch (IOException e) { + throw new RuntimeException(e); + } + FSTableDescriptors fstd = + new FSTableDescriptors(fs, new Path(c.get(HConstants.HBASE_DIR))); + try { + return fstd.get(this.tableName); + } catch (IOException e) { + throw new RuntimeException(e); + } } /** * @param newDesc new table descriptor to use + * @deprecated Do not use; expensive call */ @Deprecated public void setTableDesc(HTableDescriptor newDesc) { - // do nothing. + Configuration c = HBaseConfiguration.create(); + FileSystem fs; + try { + fs = FileSystem.get(c); + } catch (IOException e) { + throw new RuntimeException(e); + } + FSTableDescriptors fstd = + new FSTableDescriptors(fs, new Path(c.get(HConstants.HBASE_DIR))); + try { + fstd.add(newDesc); + } catch (IOException e) { + throw new RuntimeException(e); + } } /** @return true if this is the root region */