Java Code Examples for org.apache.hadoop.hbase.MetaTableAccessor#getDaughterRegions()
The following examples show how to use
org.apache.hadoop.hbase.MetaTableAccessor#getDaughterRegions() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CatalogJanitor.java From hbase with Apache License 2.0 | 5 votes |
/** * If daughters no longer hold reference to the parents, delete the parent. * @param parent RegionInfo of split offlined parent * @param rowContent Content of <code>parent</code> row in * <code>metaRegionName</code> * @return True if we removed <code>parent</code> from meta table and from * the filesystem. */ boolean cleanParent(final RegionInfo parent, Result rowContent) throws IOException { // Check whether it is a merged region and if it is clean of references. if (MetaTableAccessor.hasMergeRegions(rowContent.rawCells())) { // Wait until clean of merge parent regions first return false; } // Run checks on each daughter split. PairOfSameType<RegionInfo> daughters = MetaTableAccessor.getDaughterRegions(rowContent); Pair<Boolean, Boolean> a = checkDaughterInFs(parent, daughters.getFirst()); Pair<Boolean, Boolean> b = checkDaughterInFs(parent, daughters.getSecond()); if (hasNoReferences(a) && hasNoReferences(b)) { String daughterA = daughters.getFirst() != null? daughters.getFirst().getShortNameToLog(): "null"; String daughterB = daughters.getSecond() != null? daughters.getSecond().getShortNameToLog(): "null"; LOG.debug("Deleting region " + parent.getShortNameToLog() + " because daughters -- " + daughterA + ", " + daughterB + " -- no longer hold references"); ProcedureExecutor<MasterProcedureEnv> pe = this.services.getMasterProcedureExecutor(); pe.submitProcedure(new GCRegionProcedure(pe.getEnvironment(), parent)); // Remove from in-memory states this.services.getAssignmentManager().getRegionStates().deleteRegion(parent); this.services.getServerManager().removeRegion(parent); return true; } return false; }
Example 2
Source File: RegionReplicaInfo.java From hbase with Apache License 2.0 | 5 votes |
private RegionReplicaInfo(final Result result, final HRegionLocation location) { this.row = result != null ? result.getRow() : null; this.regionInfo = location != null ? location.getRegion() : null; this.regionState = (result != null && regionInfo != null) ? RegionStateStore.getRegionState(result, regionInfo) : null; this.serverName = location != null ? location.getServerName() : null; this.seqNum = (location != null) ? location.getSeqNum() : HConstants.NO_SEQNUM; this.targetServerName = (result != null && regionInfo != null) ? MetaTableAccessor.getTargetServerName(result, regionInfo.getReplicaId()) : null; this.mergeRegionInfo = (result != null) ? MetaTableAccessor.getMergeRegionsWithName(result.rawCells()) : null; if (result != null) { PairOfSameType<RegionInfo> daughterRegions = MetaTableAccessor.getDaughterRegions(result); this.splitRegionInfo = new LinkedHashMap<>(); if (daughterRegions.getFirst() != null) { splitRegionInfo.put(HConstants.SPLITA_QUALIFIER_STR, daughterRegions.getFirst()); } if (daughterRegions.getSecond() != null) { splitRegionInfo.put(HConstants.SPLITB_QUALIFIER_STR, daughterRegions.getSecond()); } } else { this.splitRegionInfo = null; } }
Example 3
Source File: TestCatalogJanitorInMemoryStates.java From hbase with Apache License 2.0 | 5 votes |
private PairOfSameType<RegionInfo> waitOnDaughters(final RegionInfo r) throws IOException { long start = System.currentTimeMillis(); PairOfSameType<RegionInfo> pair = null; try (Connection conn = ConnectionFactory.createConnection(TEST_UTIL.getConfiguration()); Table metaTable = conn.getTable(TableName.META_TABLE_NAME)) { Result result = null; RegionInfo region = null; while ((System.currentTimeMillis() - start) < 60000) { result = metaTable.get(new Get(r.getRegionName())); if (result == null) { break; } region = CatalogFamilyFormat.getRegionInfo(result); if (region.isSplitParent()) { LOG.debug(region.toString() + " IS a parent!"); pair = MetaTableAccessor.getDaughterRegions(result); break; } Threads.sleep(100); } if (pair.getFirst() == null || pair.getSecond() == null) { throw new IOException("Failed to get daughters, for parent region: " + r); } return pair; } }
Example 4
Source File: HBaseFsck.java From hbase with Apache License 2.0 | 4 votes |
/** * Scan hbase:meta, adding all regions found to the regionInfo map. * @throws IOException if an error is encountered */ boolean loadMetaEntries() throws IOException { ClientMetaTableAccessor.Visitor visitor = new ClientMetaTableAccessor.Visitor() { int countRecord = 1; // comparator to sort KeyValues with latest modtime final Comparator<Cell> comp = new Comparator<Cell>() { @Override public int compare(Cell k1, Cell k2) { return Long.compare(k1.getTimestamp(), k2.getTimestamp()); } }; @Override public boolean visit(Result result) throws IOException { try { // record the latest modification of this META record long ts = Collections.max(result.listCells(), comp).getTimestamp(); RegionLocations rl = CatalogFamilyFormat.getRegionLocations(result); if (rl == null) { emptyRegionInfoQualifiers.add(result); errors.reportError(ERROR_CODE.EMPTY_META_CELL, "Empty REGIONINFO_QUALIFIER found in hbase:meta"); return true; } ServerName sn = null; if (rl.getRegionLocation(RegionInfo.DEFAULT_REPLICA_ID) == null || rl.getRegionLocation(RegionInfo.DEFAULT_REPLICA_ID).getRegion() == null) { emptyRegionInfoQualifiers.add(result); errors.reportError(ERROR_CODE.EMPTY_META_CELL, "Empty REGIONINFO_QUALIFIER found in hbase:meta"); return true; } RegionInfo hri = rl.getRegionLocation(RegionInfo.DEFAULT_REPLICA_ID).getRegion(); if (!(isTableIncluded(hri.getTable()) || hri.isMetaRegion())) { return true; } PairOfSameType<RegionInfo> daughters = MetaTableAccessor.getDaughterRegions(result); for (HRegionLocation h : rl.getRegionLocations()) { if (h == null || h.getRegion() == null) { continue; } sn = h.getServerName(); hri = h.getRegion(); HbckRegionInfo.MetaEntry m = null; if (hri.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { m = new HbckRegionInfo.MetaEntry(hri, sn, ts, daughters.getFirst(), daughters.getSecond()); } else { m = new HbckRegionInfo.MetaEntry(hri, sn, ts, null, null); } HbckRegionInfo previous = regionInfoMap.get(hri.getEncodedName()); if (previous == null) { regionInfoMap.put(hri.getEncodedName(), new HbckRegionInfo(m)); } else if (previous.getMetaEntry() == null) { previous.setMetaEntry(m); } else { throw new IOException("Two entries in hbase:meta are same " + previous); } } List<RegionInfo> mergeParents = MetaTableAccessor.getMergeRegions(result.rawCells()); if (mergeParents != null) { for (RegionInfo mergeRegion : mergeParents) { if (mergeRegion != null) { // This region is already being merged HbckRegionInfo hbInfo = getOrCreateInfo(mergeRegion.getEncodedName()); hbInfo.setMerged(true); } } } // show proof of progress to the user, once for every 100 records. if (countRecord % 100 == 0) { errors.progress(); } countRecord++; return true; } catch (RuntimeException e) { LOG.error("Result=" + result); throw e; } } }; if (!checkMetaOnly) { // Scan hbase:meta to pick up user regions MetaTableAccessor.fullScanRegions(connection, visitor); } errors.print(""); return true; }
Example 5
Source File: TestEndToEndSplitTransaction.java From hbase with Apache License 2.0 | 4 votes |
/** * Blocks until the region split is complete in hbase:meta and region server opens the daughters */ public static void blockUntilRegionSplit(Configuration conf, long timeout, final byte[] regionName, boolean waitForDaughters) throws IOException, InterruptedException { long start = System.currentTimeMillis(); log("blocking until region is split:" + Bytes.toStringBinary(regionName)); RegionInfo daughterA = null, daughterB = null; try (Connection conn = ConnectionFactory.createConnection(conf); Table metaTable = conn.getTable(TableName.META_TABLE_NAME)) { Result result = null; RegionInfo region = null; while ((System.currentTimeMillis() - start) < timeout) { result = metaTable.get(new Get(regionName)); if (result == null) { break; } region = CatalogFamilyFormat.getRegionInfo(result); if (region.isSplitParent()) { log("found parent region: " + region.toString()); PairOfSameType<RegionInfo> pair = MetaTableAccessor.getDaughterRegions(result); daughterA = pair.getFirst(); daughterB = pair.getSecond(); break; } Threads.sleep(100); } if (daughterA == null || daughterB == null) { throw new IOException("Failed to get daughters, daughterA=" + daughterA + ", daughterB=" + daughterB + ", timeout=" + timeout + ", result=" + result + ", regionName=" + Bytes.toString(regionName) + ", region=" + region); } // if we are here, this means the region split is complete or timed out if (waitForDaughters) { long rem = timeout - (System.currentTimeMillis() - start); blockUntilRegionIsInMeta(conn, rem, daughterA); rem = timeout - (System.currentTimeMillis() - start); blockUntilRegionIsInMeta(conn, rem, daughterB); rem = timeout - (System.currentTimeMillis() - start); blockUntilRegionIsOpened(conf, rem, daughterA); rem = timeout - (System.currentTimeMillis() - start); blockUntilRegionIsOpened(conf, rem, daughterB); // Compacting the new region to make sure references can be cleaned up compactAndBlockUntilDone(TEST_UTIL.getAdmin(), TEST_UTIL.getMiniHBaseCluster().getRegionServer(0), daughterA.getRegionName()); compactAndBlockUntilDone(TEST_UTIL.getAdmin(), TEST_UTIL.getMiniHBaseCluster().getRegionServer(0), daughterB.getRegionName()); removeCompactedFiles(conn, timeout, daughterA); removeCompactedFiles(conn, timeout, daughterB); } } }