HBASE-1215 migration; metautils scan of meta region was broken; wouldn't see first row

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@796850 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-07-22 19:33:04 +00:00
parent 2fc56ed998
commit 9037b2149a
5 changed files with 44 additions and 52 deletions

View File

@ -380,6 +380,13 @@ public class HColumnDescriptor implements ISerializable, WritableComparable<HCol
new ImmutableBytesWritable(value)); new ImmutableBytesWritable(value));
} }
/**
* @param key Key whose key and value we're to remove from HCD parameters.
*/
public void remove(final byte [] key) {
values.remove(new ImmutableBytesWritable(key));
}
/** /**
* @param key The key. * @param key The key.
* @param value The value. * @param value The value.

View File

@ -192,23 +192,33 @@ public class MetaUtils {
if (this.rootRegion == null) { if (this.rootRegion == null) {
openRootRegion(); openRootRegion();
} }
scanMetaRegion(this.rootRegion, listener);
}
/**
* Scan the passed in metaregion <code>m</code> invoking the passed
* <code>listener</code> per row found.
* @param m
* @param listener
* @throws IOException
*/
public void scanMetaRegion(final HRegion r, final ScannerListener listener)
throws IOException {
Scan scan = new Scan(); Scan scan = new Scan();
scan.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); scan.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
InternalScanner rootScanner = this.rootRegion.getScanner(scan); InternalScanner s = r.getScanner(scan);
try { try {
List<KeyValue> results = new ArrayList<KeyValue>(); List<KeyValue> results = new ArrayList<KeyValue>();
boolean hasNext = true; boolean hasNext = true;
do { do {
hasNext = rootScanner.next(results); hasNext = s.next(results);
HRegionInfo info = null; HRegionInfo info = null;
for (KeyValue kv: results) { for (KeyValue kv: results) {
info = Writables.getHRegionInfoOrNull(kv.getValue()); info = Writables.getHRegionInfoOrNull(kv.getValue());
if (info == null) { if (info == null) {
LOG.warn("region info is null for row " + LOG.warn("Region info is null for row " +
Bytes.toString(kv.getRow()) + " in table " + Bytes.toString(kv.getRow()) + " in table " +
HConstants.ROOT_TABLE_NAME); r.getTableDesc().getNameAsString());
} }
continue; continue;
} }
@ -218,7 +228,7 @@ public class MetaUtils {
results.clear(); results.clear();
} while (hasNext); } while (hasNext);
} finally { } finally {
rootScanner.close(); r.close();
} }
} }
@ -244,46 +254,6 @@ public class MetaUtils {
scanMetaRegion(metaRegion, listener); scanMetaRegion(metaRegion, listener);
} }
/**
* Scan the passed in metaregion <code>m</code> invoking the passed
* <code>listener</code> per row found.
* @param m
* @param listener
* @throws IOException
*/
public void scanMetaRegion(final HRegion m, final ScannerListener listener)
throws IOException {
Scan scan = new Scan();
scan.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
InternalScanner metaScanner = m.getScanner(scan);
try {
List<KeyValue> results = new ArrayList<KeyValue>();
while (metaScanner.next(results)) {
HRegionInfo info = null;
for (KeyValue kv: results) {
if(kv.matchingColumn(HConstants.CATALOG_FAMILY,
HConstants.REGIONINFO_QUALIFIER)) {
info = Writables.getHRegionInfoOrNull(kv.getValue());
if (info == null) {
LOG.warn("region info is null for row " +
Bytes.toString(kv.getRow()) +
" in table " + HConstants.META_TABLE_NAME);
}
break;
}
}
if (!listener.processRow(info)) {
break;
}
results.clear();
}
} finally {
metaScanner.close();
}
}
private synchronized HRegion openRootRegion() throws IOException { private synchronized HRegion openRootRegion() throws IOException {
if (this.rootRegion != null) { if (this.rootRegion != null) {
return this.rootRegion; return this.rootRegion;

View File

@ -247,8 +247,9 @@ public class Migrate extends Configured implements Tool {
final MetaUtils utils = new MetaUtils(this.conf); final MetaUtils utils = new MetaUtils(this.conf);
final List<HRegionInfo> metas = new ArrayList<HRegionInfo>(); final List<HRegionInfo> metas = new ArrayList<HRegionInfo>();
try { try {
// Rewrite root.
rewriteHRegionInfo(utils.getRootRegion().getRegionInfo()); rewriteHRegionInfo(utils.getRootRegion().getRegionInfo());
// Scan the root region // Scan the root region to rewrite metas.
utils.scanRootRegion(new MetaUtils.ScannerListener() { utils.scanRootRegion(new MetaUtils.ScannerListener() {
public boolean processRow(HRegionInfo info) public boolean processRow(HRegionInfo info)
throws IOException { throws IOException {
@ -261,7 +262,7 @@ public class Migrate extends Configured implements Tool {
return true; return true;
} }
}); });
// Scan meta. // Scan meta to rewrite table stuff.
for (HRegionInfo hri: metas) { for (HRegionInfo hri: metas) {
final HRegion h = utils.getMetaRegion(hri); final HRegion h = utils.getMetaRegion(hri);
utils.scanMetaRegion(h, new MetaUtils.ScannerListener() { utils.scanMetaRegion(h, new MetaUtils.ScannerListener() {
@ -432,8 +433,11 @@ public class Migrate extends Configured implements Tool {
// Set compression to none. Previous was 'none'. Needs to be upper-case. // Set compression to none. Previous was 'none'. Needs to be upper-case.
// Any other compression we are turning off. Have user enable it. // Any other compression we are turning off. Have user enable it.
hcd.setCompressionType(Algorithm.NONE); hcd.setCompressionType(Algorithm.NONE);
// Remove the old MEMCACHE_FLUSHSIZE if present
hcd.remove(Bytes.toBytes("MEMCACHE_FLUSHSIZE"));
result = true;
} }
return true; return result;
} }

View File

@ -25,6 +25,17 @@ import java.util.Arrays;
import junit.framework.TestCase; import junit.framework.TestCase;
public class TestBytes extends TestCase { public class TestBytes extends TestCase {
public void testNullHashCode() {
byte [] b = null;
Exception ee = null;
try {
Bytes.hashCode(b);
} catch (Exception e) {
ee = e;
}
assertNotNull(ee);
}
public void testSplit() throws Exception { public void testSplit() throws Exception {
byte [] lowest = Bytes.toBytes("AAA"); byte [] lowest = Bytes.toBytes("AAA");
byte [] middle = Bytes.toBytes("CCC"); byte [] middle = Bytes.toBytes("CCC");