diff --git a/CHANGES.txt b/CHANGES.txt index 297e4fb4d6b..490dfa5ba75 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -145,6 +145,7 @@ Trunk (unreleased changes) hadoop instead HADOOP-2668 Documentation and improved logging so fact that hbase now requires migration comes as less of a surprise + HADOOP-2686 Removed tables stick around in .META. IMPROVEMENTS HADOOP-2401 Add convenience put method that takes writable diff --git a/src/java/org/apache/hadoop/hbase/HConstants.java b/src/java/org/apache/hadoop/hbase/HConstants.java index 0baa2b7e5a5..d543d6fd44a 100644 --- a/src/java/org/apache/hadoop/hbase/HConstants.java +++ b/src/java/org/apache/hadoop/hbase/HConstants.java @@ -149,6 +149,12 @@ public interface HConstants { /** the upper half of a split region */ static final Text COL_SPLITB = new Text(COLUMN_FAMILY_STR + "splitB"); + + /** All the columns in the catalog -ROOT- and .META. tables. + */ + static final Text[] ALL_META_COLUMNS = {COL_REGIONINFO, COL_SERVER, + COL_STARTCODE, COL_SPLITA, COL_SPLITB}; + // Other constants /** diff --git a/src/java/org/apache/hadoop/hbase/HMaster.java b/src/java/org/apache/hadoop/hbase/HMaster.java index a28168ca072..c13735f6ae4 100644 --- a/src/java/org/apache/hadoop/hbase/HMaster.java +++ b/src/java/org/apache/hadoop/hbase/HMaster.java @@ -332,19 +332,13 @@ public class HMaster extends Thread implements HConstants, HMasterInterface, if (!hasReferencesA && !hasReferencesB) { LOG.info("Deleting region " + parent.getRegionName() + - " because daughter splits no longer hold references"); + " because daughter splits no longer hold references"); if (!HRegion.deleteRegion(fs, rootdir, parent)) { LOG.warn("Deletion of " + parent.getRegionName() + " failed"); } - BatchUpdate b = new BatchUpdate(rand.nextLong()); - long lockid = b.startUpdate(parent.getRegionName()); - b.delete(lockid, COL_REGIONINFO); - b.delete(lockid, COL_SERVER); - b.delete(lockid, COL_STARTCODE); - b.delete(lockid, COL_SPLITA); - b.delete(lockid, COL_SPLITB); - srvr.batchUpdate(metaRegionName, System.currentTimeMillis(), b); + HRegion.removeRegionFromMETA(srvr, metaRegionName, + parent.getRegionName()); result = true; } else if (LOG.isDebugEnabled()) { // If debug, note we checked and current state of daughters. @@ -2069,7 +2063,7 @@ public class HMaster extends Thread implements HConstants, HMasterInterface, break; } LOG.info(info.getRegionName() + " was on shutdown server <" + - serverName + "> (or server is null). Marking unassigned if " + + serverName + "> (or server is null). Marking unassigned in " + "meta and clearing pendingRegions"); if (info.isMetaTable()) { @@ -2126,19 +2120,13 @@ public class HMaster extends Thread implements HConstants, HMasterInterface, } } - // Remove server from root/meta entries + // Update server in root/meta entries for (ToDoEntry e: toDoList) { - BatchUpdate b = new BatchUpdate(rand.nextLong()); - long lockid = b.startUpdate(e.row); if (e.deleteRegion) { - b.delete(lockid, COL_REGIONINFO); - } else if (e.regionOffline) { - e.info.setOffline(true); - b.put(lockid, COL_REGIONINFO, Writables.getBytes(e.info)); + HRegion.removeRegionFromMETA(server, regionName, e.row); + } else { + HRegion.offlineRegionInMETA(server, regionName, e.info); } - b.delete(lockid, COL_SERVER); - b.delete(lockid, COL_STARTCODE); - server.batchUpdate(regionName, System.currentTimeMillis(), b); } // Get regions reassigned @@ -2384,22 +2372,14 @@ public class HMaster extends Thread implements HConstants, HMasterInterface, return true; } - HRegionInterface server = getMetaServer(); try { - BatchUpdate b = new BatchUpdate(rand.nextLong()); - long lockid = b.startUpdate(regionInfo.getRegionName()); - if (deleteRegion) { - b.delete(lockid, COL_REGIONINFO); - - } else if (!reassignRegion ) { - regionInfo.setOffline(true); - b.put(lockid, COL_REGIONINFO, Writables.getBytes(regionInfo)); + HRegion.removeRegionFromMETA(getMetaServer(), metaRegionName, + regionInfo.getRegionName()); + } else { + HRegion.offlineRegionInMETA(getMetaServer(), metaRegionName, + regionInfo); } - b.delete(lockid, COL_SERVER); - b.delete(lockid, COL_STARTCODE); - server.batchUpdate(metaRegionName, System.currentTimeMillis(), b); - break; } catch (IOException e) { @@ -3012,9 +2992,11 @@ public class HMaster extends Thread implements HConstants, HMasterInterface, @Override protected void updateRegionInfo(BatchUpdate b, - @SuppressWarnings("unused") HRegionInfo i) { - - b.delete(lockid, COL_REGIONINFO); + @SuppressWarnings("unused") HRegionInfo info) { + for (int i = 0; i < ALL_META_COLUMNS.length; i++) { + // Be sure to clean all columns + b.delete(lockid, ALL_META_COLUMNS[i]); + } } } diff --git a/src/java/org/apache/hadoop/hbase/HRegion.java b/src/java/org/apache/hadoop/hbase/HRegion.java index 5b4230da5d4..b6d4e8bebfa 100644 --- a/src/java/org/apache/hadoop/hbase/HRegion.java +++ b/src/java/org/apache/hadoop/hbase/HRegion.java @@ -1816,6 +1816,7 @@ public class HRegion implements HConstants { * @param r HRegion to add to meta * * @throws IOException + * @see {@link #removeRegionFromMETA(HRegion, HRegion)} */ static void addRegionToMETA(HRegion meta, HRegion r) throws IOException { meta.checkResources(); @@ -1833,7 +1834,52 @@ public class HRegion implements HConstants { meta.releaseRowLock(row); } } - + + /** + * Delete a region's meta information from the passed + * meta region. + * + * @param srvr META server to be updated + * @param metaRegionName Meta region name + * @param regionNmae HRegion to remove from meta + * + * @throws IOException + * @see {@link #addRegionToMETA(HRegion, HRegion)} + */ + static void removeRegionFromMETA(final HRegionInterface srvr, + final Text metaRegionName, final Text regionName) + throws IOException { + BatchUpdate b = new BatchUpdate(rand.nextLong()); + long lockid = b.startUpdate(regionName); + for (int i = 0; i < ALL_META_COLUMNS.length; i++) { + b.delete(lockid, ALL_META_COLUMNS[i]); + } + srvr.batchUpdate(metaRegionName, System.currentTimeMillis(), b); + } + + /** + * Utility method used by HMaster marking regions offlined. + * @param srvr META server to be updated + * @param metaRegionName Meta region name + * @param info HRegion to update in meta + * + * @throws IOException + * @see {@link #addRegionToMETA(HRegion, HRegion)} + */ + static void offlineRegionInMETA(final HRegionInterface srvr, + final Text metaRegionName, final HRegionInfo info) + throws IOException { + BatchUpdate b = new BatchUpdate(rand.nextLong()); + long lockid = b.startUpdate(info.getRegionName()); + info.setOffline(true); + b.put(lockid, COL_REGIONINFO, Writables.getBytes(info)); + b.delete(lockid, COL_SERVER); + b.delete(lockid, COL_STARTCODE); + // If carrying splits, they'll be in place when we show up on new + // server. + srvr.batchUpdate(metaRegionName, System.currentTimeMillis(), b); + } + /** * Deletes all the files for a HRegion * diff --git a/src/java/org/apache/hadoop/hbase/HRegionInfo.java b/src/java/org/apache/hadoop/hbase/HRegionInfo.java index 67ea695c928..40ca71f561c 100644 --- a/src/java/org/apache/hadoop/hbase/HRegionInfo.java +++ b/src/java/org/apache/hadoop/hbase/HRegionInfo.java @@ -252,7 +252,7 @@ public class HRegionInfo implements WritableComparable { public String toString() { return "regionname: " + this.regionName.toString() + ", startKey: <" + this.startKey.toString() + ">, endKey: <" + this.endKey.toString() + - ">, encodedName(" + getEncodedName() + ")" + + ">, encodedName: " + getEncodedName() + "," + (isOffline()? " offline: true,": "") + (isSplit()? " split: true,": "") + " tableDesc: {" + this.tableDesc.toString() + "}"; } diff --git a/src/java/org/apache/hadoop/hbase/HTableDescriptor.java b/src/java/org/apache/hadoop/hbase/HTableDescriptor.java index d2811f14e6f..5f9f2e58f8f 100644 --- a/src/java/org/apache/hadoop/hbase/HTableDescriptor.java +++ b/src/java/org/apache/hadoop/hbase/HTableDescriptor.java @@ -132,6 +132,9 @@ public class HTableDescriptor implements WritableComparable { * @param family HColumnDescriptor of familyto add. */ public void addFamily(HColumnDescriptor family) { + if (family.getName() == null || family.getName().getLength() <= 0) { + throw new NullPointerException("Family name cannot be null or empty"); + } families.put(family.getName(), family); } diff --git a/src/test/org/apache/hadoop/hbase/TestToString.java b/src/test/org/apache/hadoop/hbase/TestToString.java index 22c8e33da70..fb31db33872 100644 --- a/src/test/org/apache/hadoop/hbase/TestToString.java +++ b/src/test/org/apache/hadoop/hbase/TestToString.java @@ -55,7 +55,7 @@ public class TestToString extends TestCase { HRegionInfo hri = HRegionInfo.rootRegionInfo; System.out.println(hri.toString()); assertEquals("HRegionInfo", - "regionname: -ROOT-,,0, startKey: <>, endKey: <>, encodedName(70236052) tableDesc: " + + "regionname: -ROOT-,,0, startKey: <>, endKey: <>, encodedName: 70236052, tableDesc: " + "{name: -ROOT-, families: {info:={name: info, max versions: 1, " + "compression: NONE, in memory: false, max length: 2147483647, bloom " + "filter: none}}}", hri.toString());