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:
parent
b5ae8db868
commit
c32f6e31bd
|
@ -44,6 +44,8 @@ Hbase Change Log
|
||||||
HBASE-670 Historian deadlocks if regionserver is at global memory boundary
|
HBASE-670 Historian deadlocks if regionserver is at global memory boundary
|
||||||
and is hosting .META.
|
and is hosting .META.
|
||||||
HBASE-665 Server side scanner doesn't honor stop row
|
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
|
IMPROVEMENTS
|
||||||
HBASE-559 MR example job to count table rows
|
HBASE-559 MR example job to count table rows
|
||||||
|
|
|
@ -22,6 +22,8 @@ package org.apache.hadoop.hbase;
|
||||||
import java.io.DataInput;
|
import java.io.DataInput;
|
||||||
import java.io.DataOutput;
|
import java.io.DataOutput;
|
||||||
import java.io.IOException;
|
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.Bytes;
|
||||||
import org.apache.hadoop.hbase.util.JenkinsHash;
|
import org.apache.hadoop.hbase.util.JenkinsHash;
|
||||||
|
@ -53,12 +55,22 @@ public class HRegionInfo implements WritableComparable {
|
||||||
new HRegionInfo(1L, HTableDescriptor.META_TABLEDESC);
|
new HRegionInfo(1L, HTableDescriptor.META_TABLEDESC);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extracts table name prefix from a region name.
|
* Extracts table name prefix from a metaregion row name.
|
||||||
* Presumes region names are ASCII characters only.
|
* @param regionName A metaregion row name.
|
||||||
* @param regionName A region name.
|
|
||||||
* @return The table prefix of a region name.
|
* @return The table prefix of a region name.
|
||||||
*/
|
*/
|
||||||
public static byte [] getTableNameFromRegionName(final byte [] regionName) {
|
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;
|
int offset = -1;
|
||||||
for (int i = 0; i < regionName.length; i++) {
|
for (int i = 0; i < regionName.length; i++) {
|
||||||
if (regionName[i] == DELIMITER) {
|
if (regionName[i] == DELIMITER) {
|
||||||
|
@ -72,7 +84,30 @@ public class HRegionInfo implements WritableComparable {
|
||||||
}
|
}
|
||||||
byte [] tableName = new byte[offset];
|
byte [] tableName = new byte[offset];
|
||||||
System.arraycopy(regionName, 0, tableName, 0, 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;
|
private byte [] endKey = HConstants.EMPTY_BYTE_ARRAY;
|
||||||
|
|
|
@ -269,7 +269,7 @@ public class HConnectionManager implements HConstants {
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public boolean processRow(
|
public boolean processRow(
|
||||||
@SuppressWarnings("unused") RowResult rowResult,
|
@SuppressWarnings("unused") RowResult rowResult,
|
||||||
@SuppressWarnings("unused") HRegionLocation metaLocation,
|
@SuppressWarnings("unused") HRegionLocation regionLocation,
|
||||||
HRegionInfo info) {
|
HRegionInfo info) {
|
||||||
|
|
||||||
// Only examine the rows where the startKey is zero length
|
// Only examine the rows where the startKey is zero length
|
||||||
|
|
|
@ -359,7 +359,7 @@ public class HTable {
|
||||||
MetaScannerVisitor visitor = new MetaScannerVisitor() {
|
MetaScannerVisitor visitor = new MetaScannerVisitor() {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public boolean processRow(@SuppressWarnings("unused") RowResult rowResult,
|
public boolean processRow(@SuppressWarnings("unused") RowResult rowResult,
|
||||||
@SuppressWarnings("unused") HRegionLocation metaLocation,
|
@SuppressWarnings("unused") HRegionLocation regionLocation,
|
||||||
HRegionInfo info)
|
HRegionInfo info)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) {
|
if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) {
|
||||||
|
@ -388,14 +388,14 @@ public class HTable {
|
||||||
|
|
||||||
MetaScannerVisitor visitor = new MetaScannerVisitor() {
|
MetaScannerVisitor visitor = new MetaScannerVisitor() {
|
||||||
public boolean processRow(@SuppressWarnings("unused") RowResult rowResult,
|
public boolean processRow(@SuppressWarnings("unused") RowResult rowResult,
|
||||||
HRegionLocation metaLocation, HRegionInfo hri) {
|
HRegionLocation regionLocation, HRegionInfo hri) {
|
||||||
|
|
||||||
HRegionInfo info = new UnmodifyableHRegionInfo(hri);
|
HRegionInfo info = new UnmodifyableHRegionInfo(hri);
|
||||||
if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) {
|
if (!(Bytes.equals(info.getTableDesc().getName(), getTableName()))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!(info.isOffline() || info.isSplit())) {
|
if (!(info.isOffline() || info.isSplit())) {
|
||||||
regionMap.put(info, metaLocation.getServerAddress());
|
regionMap.put(info, regionLocation.getServerAddress());
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.apache.hadoop.hbase.client;
|
package org.apache.hadoop.hbase.client;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.HBaseConfiguration;
|
import org.apache.hadoop.hbase.HBaseConfiguration;
|
||||||
import org.apache.hadoop.hbase.HConstants;
|
import org.apache.hadoop.hbase.HConstants;
|
||||||
|
@ -44,12 +45,11 @@ class MetaScanner implements HConstants {
|
||||||
MetaScannerVisitor visitor, byte[] tableName)
|
MetaScannerVisitor visitor, byte[] tableName)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
HConnection connection = HConnectionManager.getConnection(configuration);
|
HConnection connection = HConnectionManager.getConnection(configuration);
|
||||||
HRegionLocation metaLocation = null;
|
|
||||||
boolean toContinue = true;
|
boolean toContinue = true;
|
||||||
byte [] startRow = Bytes.equals(tableName, EMPTY_START_ROW)? tableName:
|
byte [] startRow = Bytes.equals(tableName, EMPTY_START_ROW)? tableName:
|
||||||
HRegionInfo.createRegionName(tableName, null, NINES);
|
HRegionInfo.createRegionName(tableName, null, NINES);
|
||||||
|
|
||||||
// Scan over the each meta region
|
// Scan over each meta region
|
||||||
do {
|
do {
|
||||||
ScannerCallable callable = new ScannerCallable(connection,
|
ScannerCallable callable = new ScannerCallable(connection,
|
||||||
META_TABLE_NAME, COL_REGIONINFO_ARRAY, tableName, LATEST_TIMESTAMP,
|
META_TABLE_NAME, COL_REGIONINFO_ARRAY, tableName, LATEST_TIMESTAMP,
|
||||||
|
@ -57,15 +57,17 @@ class MetaScanner implements HConstants {
|
||||||
try {
|
try {
|
||||||
// Open scanner
|
// Open scanner
|
||||||
connection.getRegionServerWithRetries(callable);
|
connection.getRegionServerWithRetries(callable);
|
||||||
metaLocation = connection.locateRegion(META_TABLE_NAME, startRow);
|
|
||||||
while (toContinue) {
|
while (toContinue) {
|
||||||
RowResult rowResult = connection.getRegionServerWithRetries(callable);
|
RowResult rowResult = connection.getRegionServerWithRetries(callable);
|
||||||
if (rowResult == null || rowResult.size() == 0) {
|
if (rowResult == null || rowResult.size() == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
HRegionInfo info = Writables.
|
HRegionInfo info = Writables.getHRegionInfo(rowResult
|
||||||
getHRegionInfo(rowResult.get(COL_REGIONINFO));
|
.get(COL_REGIONINFO));
|
||||||
toContinue = visitor.processRow(rowResult, metaLocation, info);
|
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
|
// Advance the startRow to the end key of the current region
|
||||||
startRow = callable.getHRegionInfo().getEndKey();
|
startRow = callable.getHRegionInfo().getEndKey();
|
||||||
|
@ -88,12 +90,12 @@ class MetaScanner implements HConstants {
|
||||||
* unnecessary for some reason.
|
* unnecessary for some reason.
|
||||||
*
|
*
|
||||||
* @param rowResult
|
* @param rowResult
|
||||||
* @param metaLocation
|
* @param regionLocation
|
||||||
* @param info
|
* @param info
|
||||||
* @return A boolean to know if it should continue to loop in the region
|
* @return A boolean to know if it should continue to loop in the region
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
public boolean processRow(RowResult rowResult,
|
public boolean processRow(RowResult rowResult,
|
||||||
HRegionLocation metaLocation, HRegionInfo info) throws IOException;
|
HRegionLocation regionLocation, HRegionInfo info) throws IOException;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,25 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.hbase.regionserver;
|
package org.apache.hadoop.hbase.regionserver;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.hadoop.hbase.HBaseTestCase;
|
import org.apache.hadoop.hbase.HBaseTestCase;
|
||||||
import org.apache.hadoop.hbase.HRegionInfo;
|
import org.apache.hadoop.hbase.HRegionInfo;
|
||||||
import org.apache.hadoop.hbase.util.Bytes;
|
import org.apache.hadoop.hbase.util.Bytes;
|
||||||
|
|
||||||
public class TestHRegionInfo extends HBaseTestCase {
|
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 {
|
public void testCreateHRegionInfoName() throws Exception {
|
||||||
String tableName = "tablename";
|
String tableName = "tablename";
|
||||||
final byte [] tn = Bytes.toBytes(tableName);
|
final byte [] tn = Bytes.toBytes(tableName);
|
||||||
|
|
Loading…
Reference in New Issue