private static void bootstrap(final Path rd, final Configuration c) throws IOException { LOG.info("BOOTSTRAP: creating ROOT and first META regions"); try { // Bootstrapping, make sure blockcache is off. Else, one will be // created here in bootstap and it'll need to be cleaned up. Better to // not make it in first place. Turn off block caching for bootstrap. // Enable after. HRegionInfo rootHRI = new HRegionInfo(HRegionInfo.ROOT_REGIONINFO); setInfoFamilyCachingForRoot(false); HRegionInfo metaHRI = new HRegionInfo(HRegionInfo.FIRST_META_REGIONINFO); setInfoFamilyCachingForMeta(false); HRegion root = HRegion.createHRegion(rootHRI, rd, c, HTableDescriptor.ROOT_TABLEDESC); HRegion meta = HRegion.createHRegion(metaHRI, rd, c, HTableDescriptor.META_TABLEDESC); setInfoFamilyCachingForRoot(true); setInfoFamilyCachingForMeta(true); // Add first region from the META table to the ROOT region. HRegion.addRegionToMETA(root, meta); root.close(); root.getLog().closeAndDelete(); meta.close(); meta.getLog().closeAndDelete(); } catch (IOException e) { e = RemoteExceptionHandler.checkIOException(e); LOG.error("bootstrap", e); throw e; } }
/** * Test that if we fail a flush, abort gets set on close. * * @see <a href="https://issues.apache.org/jira/browse/HBASE-4270">HBASE-4270</a> * @throws IOException * @throws NodeExistsException * @throws KeeperException */ @Test public void testFailedFlushAborts() throws IOException, NodeExistsException, KeeperException { final Server server = new MockServer(HTU, false); final RegionServerServices rss = HTU.createMockRegionServerService(); HTableDescriptor htd = TEST_HTD; final HRegionInfo hri = new HRegionInfo(htd.getTableName(), HConstants.EMPTY_END_ROW, HConstants.EMPTY_END_ROW); HRegion region = HTU.createLocalHRegion(hri, htd); try { assertNotNull(region); // Spy on the region so can throw exception when close is called. HRegion spy = Mockito.spy(region); final boolean abort = false; Mockito.when(spy.close(abort)).thenThrow(new RuntimeException("Mocked failed close!")); // The CloseRegionHandler will try to get an HRegion that corresponds // to the passed hri -- so insert the region into the online region Set. rss.addToOnlineRegions(spy); // Assert the Server is NOT stopped before we call close region. assertFalse(server.isStopped()); CloseRegionHandler handler = new CloseRegionHandler(server, rss, hri, false, false, -1); boolean throwable = false; try { handler.process(); } catch (Throwable t) { throwable = true; } finally { assertTrue(throwable); // Abort calls stop so stopped flag should be set. assertTrue(server.isStopped()); } } finally { HRegion.closeHRegion(region); } }
private void closeRegion(final HRegion region) throws IOException { if (region != null) { region.close(); HLog wal = region.getLog(); if (wal != null) wal.close(); } }
protected boolean merge(final HRegionInfo[] info) throws IOException { if (info.length < 2) { LOG.info("only one region - nothing to merge"); return false; } HRegion currentRegion = null; long currentSize = 0; HRegion nextRegion = null; long nextSize = 0; for (int i = 0; i < info.length - 1; i++) { if (currentRegion == null) { currentRegion = HRegion.newHRegion(tabledir, hlog, fs, conf, info[i], this.htd, null); currentRegion.initialize(); currentSize = currentRegion.getLargestHStoreSize(); } nextRegion = HRegion.newHRegion(tabledir, hlog, fs, conf, info[i + 1], this.htd, null); nextRegion.initialize(); nextSize = nextRegion.getLargestHStoreSize(); if ((currentSize + nextSize) <= (maxFilesize / 2)) { // We merge two adjacent regions if their total size is less than // one half of the desired maximum size LOG.info( "Merging regions " + currentRegion.getRegionNameAsString() + " and " + nextRegion.getRegionNameAsString()); HRegion mergedRegion = HRegion.mergeAdjacent(currentRegion, nextRegion); updateMeta(currentRegion.getRegionName(), nextRegion.getRegionName(), mergedRegion); break; } LOG.info( "not merging regions " + Bytes.toStringBinary(currentRegion.getRegionName()) + " and " + Bytes.toStringBinary(nextRegion.getRegionName())); currentRegion.close(); currentRegion = nextRegion; currentSize = nextSize; } if (currentRegion != null) { currentRegion.close(); } return true; }
private void closeRegion(final HRegion region) throws IOException { if (region != null) { region.close(); WAL wal = region.getWAL(); if (wal != null) { wal.shutdown(); } } }
/** Creates, flushes, and closes a new region. */ public static HRegion createHDFSRegionDir( Configuration conf, HRegionInfo hri, HTableDescriptor htd) throws IOException { // Create HRegion Path root = FSUtils.getRootDir(conf); HRegion region = HRegion.createHRegion(hri, root, conf, htd, null); // Close the new region to flush to disk. Close log file too. region.close(); return region; }
OfflineMerger(Configuration conf, FileSystem fs) throws IOException { super(conf, fs, HConstants.META_TABLE_NAME); Path rootTableDir = HTableDescriptor.getTableDir( fs.makeQualified(new Path(conf.get(HConstants.HBASE_DIR))), HConstants.ROOT_TABLE_NAME); // Scan root region to find all the meta regions root = HRegion.newHRegion( rootTableDir, hlog, fs, conf, HRegionInfo.ROOT_REGIONINFO, HTableDescriptor.ROOT_TABLEDESC, null); root.initialize(); Scan scan = new Scan(); scan.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); InternalScanner rootScanner = root.getScanner(scan); try { List<KeyValue> results = new ArrayList<KeyValue>(); boolean hasMore; do { hasMore = rootScanner.next(results); for (KeyValue kv : results) { HRegionInfo info = Writables.getHRegionInfoOrNull(kv.getValue()); if (info != null) { metaRegions.add(info); } } } while (hasMore); } finally { rootScanner.close(); try { root.close(); } catch (IOException e) { LOG.error(e); } } }
@After public void tearDown() throws Exception { HLog hlog = region.getLog(); region.close(); hlog.closeAndDelete(); }
void cleanupFailedOpen(final HRegion region) throws IOException { if (region != null) region.close(); }