HBASE-1857 WrongRegionException when setting region online after .META. split

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@817779 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-09-22 19:18:43 +00:00
parent 0d2289f54d
commit 23e790f50b
3 changed files with 72 additions and 1 deletions

View File

@ -40,6 +40,8 @@ Release 0.21.0 - Unreleased
to contact a failed regionserver to contact a failed regionserver
HBASE-1856 HBASE-1765 broke MapReduce when using Result.list() HBASE-1856 HBASE-1765 broke MapReduce when using Result.list()
(Lars George via Stack) (Lars George via Stack)
HBASE-1857 WrongRegionException when setting region online after .META.
split (Cosmin Lehane via Stack)
IMPROVEMENTS IMPROVEMENTS
HBASE-1760 Cleanup TODOs in HTable HBASE-1760 Cleanup TODOs in HTable

View File

@ -624,7 +624,7 @@ class RegionManager implements HConstants {
return onlineMetaRegions.get(newRegion.getRegionName()); return onlineMetaRegions.get(newRegion.getRegionName());
} }
return onlineMetaRegions.get(onlineMetaRegions.headMap( return onlineMetaRegions.get(onlineMetaRegions.headMap(
newRegion.getTableDesc().getName()).lastKey()); newRegion.getRegionName()).lastKey());
} }
} }
} }

View File

@ -0,0 +1,69 @@
package org.apache.hadoop.hbase.master;
import java.io.IOException;
import java.util.Map;
import org.apache.hadoop.hbase.HBaseClusterTestCase;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HBaseTestCase;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HServerAddress;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.HBaseAdmin;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.regionserver.HRegion;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Writables;
import org.apache.hadoop.util.StringUtils;
public class TestRegionManager extends HBaseClusterTestCase {
public void testGetFirstMetaRegionForRegionAfterMetaSplit()
throws Exception {
HTable meta = new HTable(HConstants.META_TABLE_NAME);
HMaster master = this.cluster.getMaster();
HServerAddress address = master.getMasterAddress();
HTableDescriptor tableDesc = new HTableDescriptor(Bytes.toBytes("_MY_TABLE_"));
HTableDescriptor metaTableDesc = meta.getTableDescriptor();
// master.regionManager.onlineMetaRegions already contains first .META. region at key Bytes.toBytes("")
byte[] startKey0 = Bytes.toBytes("f");
byte[] endKey0 = Bytes.toBytes("h");
HRegionInfo regionInfo0 = new HRegionInfo(tableDesc, startKey0, endKey0);
// 1st .META. region will be something like .META.,,1253625700761
HRegionInfo metaRegionInfo0 = new HRegionInfo(metaTableDesc, Bytes.toBytes(""), regionInfo0.getRegionName());
MetaRegion meta0 = new MetaRegion(address, metaRegionInfo0);
byte[] startKey1 = Bytes.toBytes("j");
byte[] endKey1 = Bytes.toBytes("m");
HRegionInfo regionInfo1 = new HRegionInfo(tableDesc, startKey1, endKey1);
// 2nd .META. region will be something like .META.,_MY_TABLE_,f,1253625700761,1253625700761
HRegionInfo metaRegionInfo1 = new HRegionInfo(metaTableDesc, regionInfo0.getRegionName(), regionInfo1.getRegionName());
MetaRegion meta1 = new MetaRegion(address, metaRegionInfo1);
// 3rd .META. region will be something like .META.,_MY_TABLE_,j,1253625700761,1253625700761
HRegionInfo metaRegionInfo2 = new HRegionInfo(metaTableDesc, regionInfo1.getRegionName(), Bytes.toBytes(""));
MetaRegion meta2 = new MetaRegion(address, metaRegionInfo2);
byte[] startKeyX = Bytes.toBytes("h");
byte[] endKeyX = Bytes.toBytes("j");
HRegionInfo regionInfoX = new HRegionInfo(tableDesc, startKeyX, endKeyX);
master.regionManager.offlineMetaRegion(startKey0);
master.regionManager.putMetaRegionOnline(meta0);
master.regionManager.putMetaRegionOnline(meta1);
master.regionManager.putMetaRegionOnline(meta2);
// for (byte[] b : master.regionManager.getOnlineMetaRegions().keySet()) {
// System.out.println("FROM TEST KEY " + b +" " +new String(b));
// }
assertEquals(metaRegionInfo1.getStartKey(), master.regionManager.getFirstMetaRegionForRegion(regionInfoX).getStartKey());
assertEquals(metaRegionInfo1.getRegionName(), master.regionManager.getFirstMetaRegionForRegion(regionInfoX).getRegionName());
}
}