HBASE-2658 REST (stargate) TableRegionModel Regions need to be updated to work w/ new region naming convention from HBASE-2531

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1026131 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2010-10-21 20:35:57 +00:00
parent 5200b27780
commit 3a7d12ce2c
8 changed files with 58 additions and 26 deletions

View File

@ -599,6 +599,8 @@ Release 0.21.0 - Unreleased
HBASE-2985 HRegionServer.multi() no longer calls HRegion.put(List) when
possible
HBASE-3031 CopyTable MR job named "Copy Table" in Driver
HBASE-2658 REST (stargate) TableRegionModel Regions need to be updated to
work w/ new region naming convention from HBASE-2531
IMPROVEMENTS

View File

@ -261,7 +261,16 @@ public class HRegionInfo extends VersionedWritable implements WritableComparable
this.encodedName = other.getEncodedName();
}
private static byte [] createRegionName(final byte [] tableName,
/**
* Make a region name of passed parameters.
* @param tableName
* @param startKey Can be null
* @param id Region id (Usually timestamp from when region was created).
* @param newFormat should we create the region name in the new format
* (such that it contains its encoded name?).
* @return Region name made of passed tableName, startKey and id
*/
public static byte [] createRegionName(final byte [] tableName,
final byte [] startKey, final long regionid, boolean newFormat) {
return createRegionName(tableName, startKey, Long.toString(regionid), newFormat);
}
@ -270,7 +279,7 @@ public class HRegionInfo extends VersionedWritable implements WritableComparable
* Make a region name of passed parameters.
* @param tableName
* @param startKey Can be null
* @param id Region id.
* @param id Region id (Usually timestamp from when region was created).
* @param newFormat should we create the region name in the new format
* (such that it contains its encoded name?).
* @return Region name made of passed tableName, startKey and id
@ -279,11 +288,12 @@ public class HRegionInfo extends VersionedWritable implements WritableComparable
final byte [] startKey, final String id, boolean newFormat) {
return createRegionName(tableName, startKey, Bytes.toBytes(id), newFormat);
}
/**
* Make a region name of passed parameters.
* @param tableName
* @param startKey Can be null
* @param id Region id
* @param id Region id (Usually timestamp from when region was created).
* @param newFormat should we create the region name in the new format
* (such that it contains its encoded name?).
* @return Region name made of passed tableName, startKey and id

View File

@ -254,6 +254,15 @@ public class HTableDescriptor implements WritableComparable<HTableDescriptor> {
return isMetaRegion() && !isRootRegion();
}
/**
* @param n Table name.
* @return True if a catalog table, -ROOT- or .META.
*/
public static boolean isMetaTable(final byte [] n) {
return Bytes.equals(n, HConstants.ROOT_TABLE_NAME) ||
Bytes.equals(n, HConstants.META_TABLE_NAME);
}
/**
* Check passed buffer is legal user-space table name.
* @param b Table name.

View File

@ -41,9 +41,9 @@ import org.apache.hadoop.hbase.PleaseHoldException;
import org.apache.hadoop.hbase.Server;
import org.apache.hadoop.hbase.Stoppable;
import org.apache.hadoop.hbase.YouAreDeadException;
import org.apache.hadoop.hbase.ZooKeeperConnectionException;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.RetriesExhaustedException;
import org.apache.hadoop.hbase.ipc.HRegionInterface;
import org.apache.hadoop.hbase.master.handler.ServerShutdownHandler;
import org.apache.hadoop.hbase.master.metrics.MasterMetrics;

View File

@ -25,6 +25,8 @@ import java.io.Serializable;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.util.Bytes;
/**
@ -91,13 +93,11 @@ public class TableRegionModel implements Serializable {
*/
@XmlAttribute
public String getName() {
StringBuilder sb = new StringBuilder();
sb.append(table);
sb.append(',');
sb.append(Bytes.toString(startKey));
sb.append(',');
sb.append(id);
return sb.toString();
byte [] tableNameAsBytes = Bytes.toBytes(this.table);
byte [] nameAsBytes = HRegionInfo.createRegionName(tableNameAsBytes,
this.startKey, this.id,
!HTableDescriptor.isMetaTable(tableNameAsBytes));
return Bytes.toString(nameAsBytes);
}
/**
@ -137,9 +137,11 @@ public class TableRegionModel implements Serializable {
*/
public void setName(String name) {
String split[] = name.split(",");
table = split[0];
startKey = Bytes.toBytes(split[1]);
id = Long.valueOf(split[2]);
this.table = split[0];
this.startKey = Bytes.toBytes(split[1]);
String tail = split[2];
split = tail.split("\\.");
id = Long.valueOf(split[0]);
}
/**

View File

@ -475,13 +475,4 @@ public class MetaUtils {
}});
return result;
}
/**
* @param n Table name.
* @return True if a catalog table, -ROOT- or .META.
*/
public static boolean isMetaTableName(final byte [] n) {
return Bytes.equals(n, HConstants.ROOT_TABLE_NAME) ||
Bytes.equals(n, HConstants.META_TABLE_NAME);
}
}

View File

@ -170,7 +170,7 @@ public class TestTableResource extends HBaseRESTClusterTestBase {
HRegionInfo hri = e.getKey();
String hriRegionName = hri.getRegionNameAsString();
String regionName = region.getName();
if (hriRegionName.startsWith(regionName)) {
if (hriRegionName.equals(regionName)) {
found = true;
byte[] startKey = hri.getStartKey();
byte[] endKey = hri.getEndKey();

View File

@ -26,6 +26,8 @@ import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.util.Bytes;
import junit.framework.TestCase;
@ -75,14 +77,30 @@ public class TestTableRegionModel extends TestCase {
assertEquals(model.getId(), ID);
assertEquals(model.getLocation(), LOCATION);
assertEquals(model.getName(),
TABLE + "," + Bytes.toString(START_KEY) + "," + Long.toString(ID));
TABLE + "," + Bytes.toString(START_KEY) + "," + Long.toString(ID) +
".ad9860f031282c46ed431d7af8f94aca.");
}
public void testBuildModel() throws Exception {
checkModel(buildTestModel());
}
public void testGetName() {
TableRegionModel model = buildTestModel();
String modelName = model.getName();
HRegionInfo hri = new HRegionInfo(new HTableDescriptor(TABLE),
START_KEY, END_KEY, false, ID);
assertEquals(modelName, hri.getRegionNameAsString());
}
public void testSetName() {
TableRegionModel model = buildTestModel();
String name = model.getName();
model.setName(name);
assertEquals(name, model.getName());
}
public void testFromXML() throws Exception {
checkModel(fromXML(AS_XML));
}
}
}