HBASE-662 UI in table.jsp gives META locations, not the table's regions location

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@665994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2008-06-10 07:46:14 +00:00
parent b5ae8db868
commit c32f6e31bd
6 changed files with 69 additions and 16 deletions

View File

@ -44,6 +44,8 @@ Hbase Change Log
HBASE-670 Historian deadlocks if regionserver is at global memory boundary
and is hosting .META.
HBASE-665 Server side scanner doesn't honor stop row
HBASE-662 UI in table.jsp gives META locations, not the table's regions
location (Jean-Daniel Cryans via Stack)
IMPROVEMENTS
HBASE-559 MR example job to count table rows

View File

@ -22,6 +22,8 @@ package org.apache.hadoop.hbase;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.JenkinsHash;
@ -53,12 +55,22 @@ public class HRegionInfo implements WritableComparable {
new HRegionInfo(1L, HTableDescriptor.META_TABLEDESC);
/**
* Extracts table name prefix from a region name.
* Presumes region names are ASCII characters only.
* @param regionName A region name.
* Extracts table name prefix from a metaregion row name.
* @param regionName A metaregion row name.
* @return The table prefix of a region name.
*/
public static byte [] getTableNameFromRegionName(final byte [] regionName) {
return parseMetaRegionRow(regionName).get(0);
}
/**
* Parses passed metaregion row into its constituent parts.
* Presumes region names are ASCII characters only.
* @param regionName A metaregion row name.
* @return A list where first element is the tablename, second the row
* portion, and the third the id.
*/
public static List<byte []> parseMetaRegionRow(final byte [] regionName) {
int offset = -1;
for (int i = 0; i < regionName.length; i++) {
if (regionName[i] == DELIMITER) {
@ -72,7 +84,30 @@ public class HRegionInfo implements WritableComparable {
}
byte [] tableName = new byte[offset];
System.arraycopy(regionName, 0, tableName, 0, offset);
return tableName;
// Now move in from the tail till we hit DELIMITER to find the id
offset = -1;
for (int i = regionName.length - 1; i > tableName.length; i--) {
if (regionName[i] == DELIMITER) {
offset = i;
break;
}
}
if (offset == -1) {
throw new IllegalArgumentException(Bytes.toString(regionName) +
" does not have parseable tail");
}
byte [] row = new byte[offset - (tableName.length + 1)];
System.arraycopy(regionName, tableName.length + 1, row, 0,
offset - (tableName.length + 1));
byte [] id = new byte[regionName.length - (offset + 1)];
System.arraycopy(regionName, offset + 1, id, 0,
regionName.length - (offset + 1));
// Now make up an array to hold the three parse pieces.
List<byte []> result = new ArrayList<byte []>(3);
result.add(tableName);
result.add(row);
result.add(id);
return result;
}
private byte [] endKey = HConstants.EMPTY_BYTE_ARRAY;

View File

@ -269,7 +269,7 @@ public class HConnectionManager implements HConstants {
/** {@inheritDoc} */
public boolean processRow(
@SuppressWarnings("unused") RowResult rowResult,
@SuppressWarnings("unused") HRegionLocation metaLocation,
@SuppressWarnings("unused") HRegionLocation regionLocation,
HRegionInfo info) {
// Only examine the rows where the startKey is zero length

View File

@ -359,7 +359,7 @@ public class HTable {
MetaScannerVisitor visitor = new MetaScannerVisitor() {
@SuppressWarnings("unused")
public boolean processRow(@SuppressWarnings("unused") RowResult rowResult,
@SuppressWarnings("unused") HRegionLocation metaLocation,
@SuppressWarnings("unused") HRegionLocation regionLocation,
HRegionInfo info)
throws IOException {
if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) {
@ -388,14 +388,14 @@ public class HTable {
MetaScannerVisitor visitor = new MetaScannerVisitor() {
public boolean processRow(@SuppressWarnings("unused") RowResult rowResult,
HRegionLocation metaLocation, HRegionInfo hri) {
HRegionLocation regionLocation, HRegionInfo hri) {
HRegionInfo info = new UnmodifyableHRegionInfo(hri);
if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) {
return false;
}
if (!(info.isOffline() || info.isSplit())) {
regionMap.put(info, metaLocation.getServerAddress());
regionMap.put(info, regionLocation.getServerAddress());
}
return true;
}

View File

@ -1,6 +1,7 @@
package org.apache.hadoop.hbase.client;
import java.io.IOException;
import java.util.List;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
@ -44,12 +45,11 @@ class MetaScanner implements HConstants {
MetaScannerVisitor visitor, byte[] tableName)
throws IOException {
HConnection connection = HConnectionManager.getConnection(configuration);
HRegionLocation metaLocation = null;
boolean toContinue = true;
byte [] startRow = Bytes.equals(tableName, EMPTY_START_ROW)? tableName:
HRegionInfo.createRegionName(tableName, null, NINES);
// Scan over the each meta region
// Scan over each meta region
do {
ScannerCallable callable = new ScannerCallable(connection,
META_TABLE_NAME, COL_REGIONINFO_ARRAY, tableName, LATEST_TIMESTAMP,
@ -57,15 +57,17 @@ class MetaScanner implements HConstants {
try {
// Open scanner
connection.getRegionServerWithRetries(callable);
metaLocation = connection.locateRegion(META_TABLE_NAME, startRow);
while (toContinue) {
RowResult rowResult = connection.getRegionServerWithRetries(callable);
if (rowResult == null || rowResult.size() == 0) {
break;
}
HRegionInfo info = Writables.
getHRegionInfo(rowResult.get(COL_REGIONINFO));
toContinue = visitor.processRow(rowResult, metaLocation, info);
HRegionInfo info = Writables.getHRegionInfo(rowResult
.get(COL_REGIONINFO));
List<byte []> parse = HRegionInfo.parseMetaRegionRow(info.getRegionName());
HRegionLocation regionLocation =
connection.locateRegion(parse.get(0), parse.get(1));
toContinue = visitor.processRow(rowResult, regionLocation, info);
}
// Advance the startRow to the end key of the current region
startRow = callable.getHRegionInfo().getEndKey();
@ -88,12 +90,12 @@ class MetaScanner implements HConstants {
* unnecessary for some reason.
*
* @param rowResult
* @param metaLocation
* @param regionLocation
* @param info
* @return A boolean to know if it should continue to loop in the region
* @throws IOException
*/
public boolean processRow(RowResult rowResult,
HRegionLocation metaLocation, HRegionInfo info) throws IOException;
HRegionLocation regionLocation, HRegionInfo info) throws IOException;
}
}

View File

@ -19,11 +19,25 @@
*/
package org.apache.hadoop.hbase.regionserver;
import java.util.List;
import org.apache.hadoop.hbase.HBaseTestCase;
import org.apache.hadoop.hbase.HRegionInfo;
import org.apache.hadoop.hbase.util.Bytes;
public class TestHRegionInfo extends HBaseTestCase {
public void testParse() throws Exception {
String tableName = getName();
String row = getName();
long id = 12345;
List<byte []> parse =
HRegionInfo.parseMetaRegionRow(Bytes.toBytes(tableName + "," + row +
"," + Long.toString(id)));
assertEquals(Bytes.toString(parse.get(0)), tableName);
assertEquals(Bytes.toString(parse.get(1)), row);
assertEquals(Long.parseLong(Bytes.toString(parse.get(2))), id);
}
public void testCreateHRegionInfoName() throws Exception {
String tableName = "tablename";
final byte [] tn = Bytes.toBytes(tableName);