diff --git a/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java b/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java index 49746a1..f09e222 100644 --- a/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java +++ b/src/main/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -21,14 +21,19 @@ package org.apache.hadoop.hbase; import java.io.DataInput; import java.io.DataOutput; +import java.io.FileNotFoundException; import java.io.IOException; 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 +540,48 @@ 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 + */ @Deprecated public HTableDescriptor getTableDesc(){ - return null; + 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/TestHRegionInfo.java b/src/test/java/org/apache/hadoop/hbase/TestHRegionInfo.java new file mode 100644 index 0000000..d162735 --- /dev/null +++ b/src/test/java/org/apache/hadoop/hbase/TestHRegionInfo.java @@ -0,0 +1,46 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hadoop.hbase.util.FSUtils; +import org.junit.Test; + +public class TestHRegionInfo { + HBaseTestingUtility HTU = new HBaseTestingUtility(); + + @Test public void testGetSetOfHTD() { + 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)); + } +} \ No newline at end of file