@Test public void testCleanParent() throws IOException { HBaseTestingUtility htu = new HBaseTestingUtility(); Server server = new MockServer(htu); MasterServices services = new MockMasterServices(server); CatalogJanitor janitor = new CatalogJanitor(server, services); HTableDescriptor htd = new HTableDescriptor("table"); htd.addFamily(new HColumnDescriptor("family")); HRegionInfo parent = new HRegionInfo(htd, Bytes.toBytes("aaa"), Bytes.toBytes("eee")); HRegionInfo splita = new HRegionInfo(htd, Bytes.toBytes("aaa"), Bytes.toBytes("ccc")); HRegionInfo splitb = new HRegionInfo(htd, Bytes.toBytes("ccc"), Bytes.toBytes("eee")); List<KeyValue> kvs = new ArrayList<KeyValue>(); kvs.add(new KeyValue(parent.getRegionName(), HConstants.CATALOG_FAMILY, HConstants.SPLITA_QUALIFIER, Writables.getBytes(splita))); kvs.add(new KeyValue(parent.getRegionName(), HConstants.CATALOG_FAMILY, HConstants.SPLITB_QUALIFIER, Writables.getBytes(splitb))); Result r = new Result(kvs); Path rootdir = services.getMasterFileSystem().getRootDir(); Path tabledir = HTableDescriptor.getTableDir(rootdir, htd.getName()); Path storedir = Store.getStoreHomedir(tabledir, splita.getEncodedName(), htd.getColumnFamilies()[0].getName()); Reference ref = new Reference(Bytes.toBytes("ccc"), Reference.Range.top); long now = System.currentTimeMillis(); Path p = new Path(storedir, Long.toString(now) + "." + parent.getEncodedName()); FileSystem fs = services.getMasterFileSystem().getFileSystem(); ref.write(fs, p); assertFalse(janitor.cleanParent(parent, r)); assertTrue(fs.delete(p, true)); assertTrue(janitor.cleanParent(parent, r)); }
boolean cleanParent(final HRegionInfo parent, Result rowContent) throws IOException { boolean result = false; boolean hasReferencesA = checkDaughter(parent, rowContent, HConstants.SPLITA_QUALIFIER); boolean hasReferencesB = checkDaughter(parent, rowContent, HConstants.SPLITB_QUALIFIER); if (!hasReferencesA && !hasReferencesB) { LOG.debug("Deleting region " + parent.getRegionNameAsString() + " because daughter splits no longer hold references"); if (this.services.getAssignmentManager() != null) { this.services.getAssignmentManager().regionOffline(parent); } FileSystem fs = this.services.getMasterFileSystem().getFileSystem(); Path rootdir = this.services.getMasterFileSystem().getRootDir(); HRegion.deleteRegion(fs, rootdir, parent); MetaEditor.deleteRegion(this.server.getCatalogTracker(), parent); result = true; } return result; }
CatalogJanitor extends Chore { boolean cleanParent(final HRegionInfo parent, Result rowContent) throws IOException { boolean result = false; boolean hasReferencesA = checkDaughter(parent, rowContent, HConstants.SPLITA_QUALIFIER); boolean hasReferencesB = checkDaughter(parent, rowContent, HConstants.SPLITB_QUALIFIER); if (!hasReferencesA && !hasReferencesB) { LOG.debug("Deleting region " + parent.getRegionNameAsString() + " because daughter splits no longer hold references"); if (this.services.getAssignmentManager() != null) { this.services.getAssignmentManager().regionOffline(parent); } FileSystem fs = this.services.getMasterFileSystem().getFileSystem(); Path rootdir = this.services.getMasterFileSystem().getRootDir(); HRegion.deleteRegion(fs, rootdir, parent); MetaEditor.deleteRegion(this.server.getCatalogTracker(), parent); result = true; } return result; } }
CatalogJanitor extends Chore { boolean cleanParent(final HRegionInfo parent, Result rowContent) throws IOException { boolean result = false; boolean hasReferencesA = checkDaughter(parent, rowContent, HConstants.SPLITA_QUALIFIER); boolean hasReferencesB = checkDaughter(parent, rowContent, HConstants.SPLITB_QUALIFIER); if (!hasReferencesA && !hasReferencesB) { LOG.debug("Deleting region " + parent.getRegionNameAsString() + " because daughter splits no longer hold references"); if (this.services.getAssignmentManager() != null) { this.services.getAssignmentManager().regionOffline(parent); } FileSystem fs = this.services.getMasterFileSystem().getFileSystem(); Path rootdir = this.services.getMasterFileSystem().getRootDir(); HRegion.deleteRegion(fs, rootdir, parent); MetaEditor.deleteRegion(this.server.getCatalogTracker(), parent); result = true; } return result; } CatalogJanitor(final Server server, final MasterServices services); }
CatalogJanitor extends Chore { boolean cleanParent(final HRegionInfo parent, Result rowContent) throws IOException { boolean result = false; boolean hasReferencesA = checkDaughter(parent, rowContent, HConstants.SPLITA_QUALIFIER); boolean hasReferencesB = checkDaughter(parent, rowContent, HConstants.SPLITB_QUALIFIER); if (!hasReferencesA && !hasReferencesB) { LOG.debug("Deleting region " + parent.getRegionNameAsString() + " because daughter splits no longer hold references"); if (this.services.getAssignmentManager() != null) { this.services.getAssignmentManager().regionOffline(parent); } FileSystem fs = this.services.getMasterFileSystem().getFileSystem(); Path rootdir = this.services.getMasterFileSystem().getRootDir(); HRegion.deleteRegion(fs, rootdir, parent); MetaEditor.deleteRegion(this.server.getCatalogTracker(), parent); result = true; } return result; } CatalogJanitor(final Server server, final MasterServices services); void setEnabled(final boolean enabled); }
CatalogJanitor extends Chore { boolean cleanParent(final HRegionInfo parent, Result rowContent) throws IOException { boolean result = false; boolean hasReferencesA = checkDaughter(parent, rowContent, HConstants.SPLITA_QUALIFIER); boolean hasReferencesB = checkDaughter(parent, rowContent, HConstants.SPLITB_QUALIFIER); if (!hasReferencesA && !hasReferencesB) { LOG.debug("Deleting region " + parent.getRegionNameAsString() + " because daughter splits no longer hold references"); if (this.services.getAssignmentManager() != null) { this.services.getAssignmentManager().regionOffline(parent); } FileSystem fs = this.services.getMasterFileSystem().getFileSystem(); Path rootdir = this.services.getMasterFileSystem().getRootDir(); HRegion.deleteRegion(fs, rootdir, parent); MetaEditor.deleteRegion(this.server.getCatalogTracker(), parent); result = true; } return result; } CatalogJanitor(final Server server, final MasterServices services); void setEnabled(final boolean enabled);  }