diff --git a/CHANGES.txt b/CHANGES.txt index 5bcadfbf3a7..5e78cfbef05 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -181,6 +181,7 @@ Release 0.91.0 - Unreleased HBASE-4138 If zookeeper.znode.parent is not specifed explicitly in Client code then HTable object loops continuously waiting for the root region by using /hbase as the base node.(ramkrishna.s.vasudevan) + HBASE-4032 HBASE-451 improperly breaks public API HRegionInfo#getTableDesc IMPROVEMENTS HBASE-3290 Max Compaction Size (Nicolas Spiegelberg via Stack) diff --git a/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java b/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java index 49746a1d24a..24b4d008b73 100644 --- a/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java +++ b/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -26,9 +26,13 @@ import java.util.Arrays; 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 @@ public class HRegionInfo extends VersionedWritable implements WritableComparable 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 */ diff --git a/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java b/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java index 225547603ff..fcd5518a100 100644 --- a/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java +++ b/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegionInfo.java @@ -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 @@ -52,6 +59,25 @@ public class TestHRegionInfo { nameStr); } + @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");