Java Code Examples for org.apache.hadoop.hbase.HRegionLocation#getRegion()
The following examples show how to use
org.apache.hadoop.hbase.HRegionLocation#getRegion() .
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: TestRegionSplitter.java From hbase with Apache License 2.0 | 6 votes |
private void verifyBounds(List<byte[]> expectedBounds, TableName tableName) throws Exception { // Get region boundaries from the cluster and verify their endpoints final int numRegions = expectedBounds.size()-1; try (Table table = UTIL.getConnection().getTable(tableName); RegionLocator locator = UTIL.getConnection().getRegionLocator(tableName)) { final List<HRegionLocation> regionInfoMap = locator.getAllRegionLocations(); assertEquals(numRegions, regionInfoMap.size()); for (HRegionLocation entry : regionInfoMap) { final RegionInfo regionInfo = entry.getRegion(); byte[] regionStart = regionInfo.getStartKey(); byte[] regionEnd = regionInfo.getEndKey(); // This region's start key should be one of the region boundaries int startBoundaryIndex = indexOfBytes(expectedBounds, regionStart); assertNotSame(-1, startBoundaryIndex); // This region's end key should be the region boundary that comes // after the starting boundary. byte[] expectedRegionEnd = expectedBounds.get(startBoundaryIndex + 1); assertEquals(0, Bytes.compareTo(regionEnd, expectedRegionEnd)); } } }
Example 2
Source File: ThriftUtilities.java From hbase with Apache License 2.0 | 6 votes |
public static THRegionLocation regionLocationFromHBase(HRegionLocation hrl) { RegionInfo hri = hrl.getRegion(); ServerName serverName = hrl.getServerName(); THRegionInfo thRegionInfo = new THRegionInfo(); THRegionLocation thRegionLocation = new THRegionLocation(); TServerName tServerName = new TServerName(); tServerName.setHostName(serverName.getHostname()); tServerName.setPort(serverName.getPort()); tServerName.setStartCode(serverName.getStartcode()); thRegionInfo.setTableName(hri.getTable().getName()); thRegionInfo.setEndKey(hri.getEndKey()); thRegionInfo.setStartKey(hri.getStartKey()); thRegionInfo.setOffline(hri.isOffline()); thRegionInfo.setSplit(hri.isSplit()); thRegionInfo.setReplicaId(hri.getReplicaId()); thRegionLocation.setRegionInfo(thRegionInfo); thRegionLocation.setServerName(tServerName); return thRegionLocation; }
Example 3
Source File: RawAsyncTableImpl.java From hbase with Apache License 2.0 | 5 votes |
private <S, R> void onLocateComplete(Function<RpcChannel, S> stubMaker, ServiceCaller<S, R> callable, CoprocessorCallback<R> callback, List<HRegionLocation> locs, byte[] endKey, boolean endKeyInclusive, AtomicBoolean locateFinished, AtomicInteger unfinishedRequest, HRegionLocation loc, Throwable error) { if (error != null) { callback.onError(error); return; } unfinishedRequest.incrementAndGet(); RegionInfo region = loc.getRegion(); if (locateFinished(region, endKey, endKeyInclusive)) { locateFinished.set(true); } else { addListener( conn.getLocator().getRegionLocation(tableName, region.getEndKey(), RegionLocateType.CURRENT, operationTimeoutNs), (l, e) -> onLocateComplete(stubMaker, callable, callback, locs, endKey, endKeyInclusive, locateFinished, unfinishedRequest, l, e)); } addListener(coprocessorService(stubMaker, callable, region, region.getStartKey()), (r, e) -> { if (e != null) { callback.onRegionError(region, e); } else { callback.onRegionComplete(region, r); } if (unfinishedRequest.decrementAndGet() == 0 && locateFinished.get()) { callback.onComplete(); } }); }
Example 4
Source File: TestAsyncNonMetaRegionLocator.java From hbase with Apache License 2.0 | 5 votes |
private void assertLocEquals(byte[] startKey, byte[] endKey, ServerName serverName, HRegionLocation loc) { RegionInfo info = loc.getRegion(); assertEquals(TABLE_NAME, info.getTable()); assertArrayEquals(startKey, info.getStartKey()); assertArrayEquals(endKey, info.getEndKey()); assertEquals(serverName, loc.getServerName()); }
Example 5
Source File: AbstractTestRegionLocator.java From hbase with Apache License 2.0 | 5 votes |
private void assertRegionLocation(HRegionLocation loc, int index, int replicaId) { RegionInfo region = loc.getRegion(); byte[] startKey = getStartKey(index); assertArrayEquals(startKey, region.getStartKey()); assertArrayEquals(getEndKey(index), region.getEndKey()); assertEquals(replicaId, region.getReplicaId()); ServerName expected = findRegionLocation(TABLE_NAME, region.getStartKey(), replicaId); assertEquals(expected, loc.getServerName()); }
Example 6
Source File: TestAsyncRegionAdminApi2.java From hbase with Apache License 2.0 | 5 votes |
@Test public void testGetRegionLocation() throws Exception { RawAsyncHBaseAdmin rawAdmin = (RawAsyncHBaseAdmin) ASYNC_CONN.getAdmin(); TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY); AsyncTableRegionLocator locator = ASYNC_CONN.getRegionLocator(tableName); HRegionLocation regionLocation = locator.getRegionLocation(Bytes.toBytes("mmm")).get(); RegionInfo region = regionLocation.getRegion(); byte[] regionName = regionLocation.getRegion().getRegionName(); HRegionLocation location = rawAdmin.getRegionLocation(regionName).get(); assertTrue(Bytes.equals(regionName, location.getRegion().getRegionName())); location = rawAdmin.getRegionLocation(region.getEncodedNameAsBytes()).get(); assertTrue(Bytes.equals(regionName, location.getRegion().getRegionName())); }
Example 7
Source File: TestTableResource.java From hbase with Apache License 2.0 | 5 votes |
void checkTableInfo(TableInfoModel model) { assertEquals(model.getName(), TABLE.getNameAsString()); Iterator<TableRegionModel> regions = model.getRegions().iterator(); assertTrue(regions.hasNext()); while (regions.hasNext()) { TableRegionModel region = regions.next(); boolean found = false; LOG.debug("looking for region " + region.getName()); for (HRegionLocation e: regionMap) { RegionInfo hri = e.getRegion(); // getRegionNameAsString uses Bytes.toStringBinary which escapes some non-printable // characters String hriRegionName = Bytes.toString(hri.getRegionName()); String regionName = region.getName(); LOG.debug("comparing to region " + hriRegionName); if (hriRegionName.equals(regionName)) { found = true; byte[] startKey = hri.getStartKey(); byte[] endKey = hri.getEndKey(); ServerName serverName = e.getServerName(); InetSocketAddress sa = new InetSocketAddress(serverName.getHostname(), serverName.getPort()); String location = sa.getHostName() + ":" + Integer.valueOf(sa.getPort()); assertEquals(hri.getRegionId(), region.getId()); assertTrue(Bytes.equals(startKey, region.getStartKey())); assertTrue(Bytes.equals(endKey, region.getEndKey())); assertEquals(location, region.getLocation()); break; } } assertTrue("Couldn't find region " + region.getName(), found); } }
Example 8
Source File: AsyncRegionLocatorHelper.java From hbase with Apache License 2.0 | 5 votes |
static void updateCachedLocationOnError(HRegionLocation loc, Throwable exception, Function<HRegionLocation, HRegionLocation> cachedLocationSupplier, Consumer<HRegionLocation> addToCache, Consumer<HRegionLocation> removeFromCache, MetricsConnection metrics) { HRegionLocation oldLoc = cachedLocationSupplier.apply(loc); if (LOG.isDebugEnabled()) { LOG.debug("Try updating {} , the old value is {}, error={}", loc, oldLoc, exception != null ? exception.toString() : "none"); } if (!canUpdateOnError(loc, oldLoc)) { return; } Throwable cause = findException(exception); if (LOG.isDebugEnabled()) { LOG.debug("The actual exception when updating {} is {}", loc, cause != null ? cause.toString() : "none"); } if (cause == null || !isMetaClearingException(cause)) { LOG.debug("Will not update {} because the exception is null or not the one we care about", loc); return; } if (cause instanceof RegionMovedException) { RegionMovedException rme = (RegionMovedException) cause; HRegionLocation newLoc = new HRegionLocation(loc.getRegion(), rme.getServerName(), rme.getLocationSeqNum()); LOG.debug("Try updating {} with the new location {} constructed by {}", loc, newLoc, rme.toString()); addToCache.accept(newLoc); } else { LOG.debug("Try removing {} from cache", loc); if (metrics != null) { metrics.incrCacheDroppingExceptions(exception); } removeFromCache.accept(loc); } }
Example 9
Source File: AsyncNonMetaRegionLocator.java From hbase with Apache License 2.0 | 5 votes |
private boolean onScanNext(TableName tableName, LocateRequest req, Result result) { RegionLocations locs = CatalogFamilyFormat.getRegionLocations(result); if (LOG.isDebugEnabled()) { LOG.debug("The fetched location of '{}', row='{}', locateType={} is {}", tableName, Bytes.toStringBinary(req.row), req.locateType, locs); } // remove HRegionLocation with null location, i.e, getServerName returns null. if (locs != null) { locs = locs.removeElementsWithNullLocation(); } // the default region location should always be presented when fetching from meta, otherwise // let's fail the request. if (locs == null || locs.getDefaultRegionLocation() == null) { complete(tableName, req, null, new HBaseIOException(String.format("No location found for '%s', row='%s', locateType=%s", tableName, Bytes.toStringBinary(req.row), req.locateType))); return true; } HRegionLocation loc = locs.getDefaultRegionLocation(); RegionInfo info = loc.getRegion(); if (info == null) { complete(tableName, req, null, new HBaseIOException(String.format("HRegionInfo is null for '%s', row='%s', locateType=%s", tableName, Bytes.toStringBinary(req.row), req.locateType))); return true; } if (info.isSplitParent()) { return false; } complete(tableName, req, locs, null); return true; }
Example 10
Source File: MajorCompactor.java From hbase with Apache License 2.0 | 5 votes |
private Map<ServerName, List<RegionInfo>> getServerRegionsMap() throws IOException { Map<ServerName, List<RegionInfo>> snRegionMap = Maps.newHashMap(); List<HRegionLocation> regionLocations = connection.getRegionLocator(tableName).getAllRegionLocations(); for (HRegionLocation regionLocation : regionLocations) { ServerName sn = regionLocation.getServerName(); RegionInfo hri = regionLocation.getRegion(); if (!snRegionMap.containsKey(sn)) { snRegionMap.put(sn, Lists.newArrayList()); } snRegionMap.get(sn).add(hri); } return snRegionMap; }
Example 11
Source File: HBCKServerCrashProcedure.java From hbase with Apache License 2.0 | 5 votes |
@Override public boolean visit(Result result) throws IOException { RegionLocations rls = CatalogFamilyFormat.getRegionLocations(result); if (rls == null) { return true; } for (HRegionLocation hrl: rls.getRegionLocations()) { if (hrl == null) { continue; } if (hrl.getRegion() == null) { continue; } if (hrl.getServerName() == null) { continue; } if (!hrl.getServerName().equals(this.unknownServerName)) { continue; } RegionState.State state = RegionStateStore.getRegionState(result, hrl.getRegion()); RegionState rs = new RegionState(hrl.getRegion(), state, hrl.getServerName()); if (rs.isClosing()) { // Move region to CLOSED in hbase:meta. LOG.info("Moving {} from CLOSING to CLOSED in hbase:meta", hrl.getRegion().getRegionNameAsString()); try { MetaTableAccessor.updateRegionState(this.connection, hrl.getRegion(), RegionState.State.CLOSED); } catch (IOException ioe) { LOG.warn("Failed moving {} from CLOSING to CLOSED", hrl.getRegion().getRegionNameAsString(), ioe); } } else if (rs.isOpening() || rs.isOpened()) { this.reassigns.add(hrl.getRegion()); } else { LOG.info("Passing {}", rs); } } return true; }
Example 12
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 13
Source File: RegionStateStore.java From hbase with Apache License 2.0 | 5 votes |
private void visitMetaEntry(final RegionStateVisitor visitor, final Result result) throws IOException { final RegionLocations rl = CatalogFamilyFormat.getRegionLocations(result); if (rl == null) return; final HRegionLocation[] locations = rl.getRegionLocations(); if (locations == null) return; for (int i = 0; i < locations.length; ++i) { final HRegionLocation hrl = locations[i]; if (hrl == null) continue; final RegionInfo regionInfo = hrl.getRegion(); if (regionInfo == null) continue; final int replicaId = regionInfo.getReplicaId(); final State state = getRegionState(result, regionInfo); final ServerName lastHost = hrl.getServerName(); ServerName regionLocation = MetaTableAccessor.getTargetServerName(result, replicaId); final long openSeqNum = hrl.getSeqNum(); // TODO: move under trace, now is visible for debugging LOG.info( "Load hbase:meta entry region={}, regionState={}, lastHost={}, " + "regionLocation={}, openSeqNum={}", regionInfo.getEncodedName(), state, lastHost, regionLocation, openSeqNum); visitor.visitRegionState(result, regionInfo, state, regionLocation, lastHost, openSeqNum); } }
Example 14
Source File: TestRegionServerMetrics.java From hbase with Apache License 2.0 | 5 votes |
private void assertRegionMetrics(String metric, long expectedValue) throws Exception { try (RegionLocator locator = connection.getRegionLocator(tableName)) { for ( HRegionLocation location: locator.getAllRegionLocations()) { RegionInfo hri = location.getRegion(); MetricsRegionAggregateSource agg = rs.getRegion(hri.getRegionName()).getMetrics().getSource().getAggregateSource(); String prefix = "namespace_" + NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR + "_table_" + tableName.getNameAsString() + "_region_" + hri.getEncodedName()+ "_metric_"; metricsHelper.assertCounter(prefix + metric, expectedValue, agg); } } }
Example 15
Source File: HBaseFsck.java From hbase with Apache License 2.0 | 4 votes |
/** * Attempts to undeploy a region from a region server based in information in * META. Any operations that modify the file system should make sure that * its corresponding region is not deployed to prevent data races. * * A separate call is required to update the master in-memory region state * kept in the AssignementManager. Because disable uses this state instead of * that found in META, we can't seem to cleanly disable/delete tables that * have been hbck fixed. When used on a version of HBase that does not have * the offline ipc call exposed on the master (<0.90.5, <0.92.0) a master * restart or failover may be required. */ void closeRegion(HbckRegionInfo hi) throws IOException, InterruptedException { if (hi.getMetaEntry() == null && hi.getHdfsEntry() == null) { undeployRegions(hi); return; } // get assignment info and hregioninfo from meta. Get get = new Get(hi.getRegionName()); get.addColumn(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); get.addColumn(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER); get.addColumn(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER); // also get the locations of the replicas to close if the primary region is being closed if (hi.getReplicaId() == RegionInfo.DEFAULT_REPLICA_ID) { int numReplicas = admin.getDescriptor(hi.getTableName()).getRegionReplication(); for (int i = 0; i < numReplicas; i++) { get.addColumn(HConstants.CATALOG_FAMILY, CatalogFamilyFormat.getServerColumn(i)); get.addColumn(HConstants.CATALOG_FAMILY, CatalogFamilyFormat.getStartCodeColumn(i)); } } Result r = meta.get(get); RegionLocations rl = CatalogFamilyFormat.getRegionLocations(r); if (rl == null) { LOG.warn("Unable to close region " + hi.getRegionNameAsString() + " since meta does not have handle to reach it"); return; } for (HRegionLocation h : rl.getRegionLocations()) { ServerName serverName = h.getServerName(); if (serverName == null) { errors.reportError("Unable to close region " + hi.getRegionNameAsString() + " because meta does not " + "have handle to reach it."); continue; } RegionInfo hri = h.getRegion(); if (hri == null) { LOG.warn("Unable to close region " + hi.getRegionNameAsString() + " because hbase:meta had invalid or missing " + HConstants.CATALOG_FAMILY_STR + ":" + Bytes.toString(HConstants.REGIONINFO_QUALIFIER) + " qualifier value."); continue; } // close the region -- close files and remove assignment HBaseFsckRepair.closeRegionSilentlyAndWait(connection, serverName, hri); } }
Example 16
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 17
Source File: TestAccessController.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testGlobalAuthorizationForNewRegisteredRS() throws Exception { LOG.debug("Test for global authorization for a new registered RegionServer."); MiniHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster(); final Admin admin = TEST_UTIL.getAdmin(); TableDescriptorBuilder.ModifyableTableDescriptor tableDescriptor = new TableDescriptorBuilder.ModifyableTableDescriptor(TEST_TABLE2); tableDescriptor.setColumnFamily( new ColumnFamilyDescriptorBuilder.ModifyableColumnFamilyDescriptor(TEST_FAMILY)); createTable(TEST_UTIL, tableDescriptor); // Starting a new RegionServer. JVMClusterUtil.RegionServerThread newRsThread = hbaseCluster .startRegionServer(); final HRegionServer newRs = newRsThread.getRegionServer(); // Move region to the new RegionServer. List<HRegionLocation> regions; try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE2)) { regions = locator.getAllRegionLocations(); } HRegionLocation location = regions.get(0); final RegionInfo hri = location.getRegion(); final ServerName server = location.getServerName(); try (Table table = systemUserConnection.getTable(TEST_TABLE2)) { AccessTestAction moveAction = new AccessTestAction() { @Override public Object run() throws Exception { admin.move(hri.getEncodedNameAsBytes(), newRs.getServerName()); return null; } }; SUPERUSER.runAs(moveAction); final int RETRIES_LIMIT = 10; int retries = 0; while (newRs.getRegions(TEST_TABLE2).size() < 1 && retries < RETRIES_LIMIT) { LOG.debug("Waiting for region to be opened. Already retried " + retries + " times."); try { Thread.sleep(1000); } catch (InterruptedException e) { } retries++; if (retries == RETRIES_LIMIT - 1) { fail("Retry exhaust for waiting region to be opened."); } } // Verify write permission for user "admin2" who has the global // permissions. AccessTestAction putAction = new AccessTestAction() { @Override public Object run() throws Exception { Put put = new Put(Bytes.toBytes("test")); put.addColumn(TEST_FAMILY, Bytes.toBytes("qual"), Bytes.toBytes("value")); table.put(put); return null; } }; USER_ADMIN.runAs(putAction); } }
Example 18
Source File: TestAsyncRegionAdminApi2.java From hbase with Apache License 2.0 | 4 votes |
@Test public void testMergeRegions() throws Exception { byte[][] splitRows = new byte[][]{Bytes.toBytes("3"), Bytes.toBytes("6")}; createTableWithDefaultConf(tableName, splitRows); AsyncTable<AdvancedScanResultConsumer> metaTable = ASYNC_CONN.getTable(META_TABLE_NAME); List<HRegionLocation> regionLocations = ClientMetaTableAccessor .getTableHRegionLocations(metaTable, tableName).get(); RegionInfo regionA; RegionInfo regionB; RegionInfo regionC; RegionInfo mergedChildRegion = null; // merge with full name assertEquals(3, regionLocations.size()); regionA = regionLocations.get(0).getRegion(); regionB = regionLocations.get(1).getRegion(); regionC = regionLocations.get(2).getRegion(); admin.mergeRegions(regionA.getRegionName(), regionB.getRegionName(), false).get(); regionLocations = ClientMetaTableAccessor .getTableHRegionLocations(metaTable, tableName).get(); assertEquals(2, regionLocations.size()); for (HRegionLocation rl : regionLocations) { if (regionC.compareTo(rl.getRegion()) != 0) { mergedChildRegion = rl.getRegion(); break; } } assertNotNull(mergedChildRegion); // Need to wait GC for merged child region is done. HMaster services = TEST_UTIL.getHBaseCluster().getMaster(); CatalogJanitor cj = services.getCatalogJanitor(); cj.cleanMergeQualifier(mergedChildRegion); // Wait until all procedures settled down while (!services.getMasterProcedureExecutor().getActiveProcIds().isEmpty()) { Thread.sleep(200); } // merge with encoded name admin.mergeRegions(regionC.getRegionName(), mergedChildRegion.getRegionName(), false).get(); regionLocations = ClientMetaTableAccessor .getTableHRegionLocations(metaTable, tableName).get(); assertEquals(1, regionLocations.size()); }
Example 19
Source File: CatalogJanitor.java From hbase with Apache License 2.0 | 4 votes |
/** * Run through referenced servers and save off unknown and the dead. */ private void checkServer(RegionLocations locations) { if (this.services == null) { // Can't do this test if no services. return; } if (locations == null) { return; } if (locations.getRegionLocations() == null) { return; } // Check referenced servers are known/online. Here we are looking // at both the default replica -- the main replica -- and then replica // locations too. for (HRegionLocation location: locations.getRegionLocations()) { if (location == null) { continue; } ServerName sn = location.getServerName(); if (sn == null) { continue; } if (location.getRegion() == null) { LOG.warn("Empty RegionInfo in {}", location); // This should never happen but if it does, will mess up below. continue; } RegionInfo ri = location.getRegion(); // Skip split parent region if (ri.isSplitParent()) { continue; } // skip the offline regions which belong to disabled table. if (isTableDisabled(ri)) { continue; } RegionState rs = this.services.getAssignmentManager().getRegionStates().getRegionState(ri); if (rs == null || rs.isClosedOrAbnormallyClosed()) { // If closed against an 'Unknown Server', that is should be fine. continue; } ServerManager.ServerLiveState state = this.services.getServerManager(). isServerKnownAndOnline(sn); switch (state) { case UNKNOWN: this.report.unknownServers.add(new Pair<>(ri, sn)); break; default: break; } } }
Example 20
Source File: BaseResultIterators.java From phoenix with Apache License 2.0 | 4 votes |
/** * Get parallel scans of the specified scan boundaries. This can be used for getting parallel * scans when there is split/merges while scanning a chunk. In this case we need not go by all * the regions or guideposts. * @param scan * @return * @throws SQLException */ private List<List<Scan>> getParallelScans(Scan scan) throws SQLException { List<HRegionLocation> regionLocations = getRegionBoundaries(scanGrouper); List<byte[]> regionBoundaries = toBoundaries(regionLocations); int regionIndex = 0; int stopIndex = regionBoundaries.size(); if (scan.getStartRow().length > 0) { regionIndex = getIndexContainingInclusive(regionBoundaries, scan.getStartRow()); } if (scan.getStopRow().length > 0) { stopIndex = Math.min(stopIndex, regionIndex + getIndexContainingExclusive(regionBoundaries.subList(regionIndex, stopIndex), scan.getStopRow())); } List<List<Scan>> parallelScans = Lists.newArrayListWithExpectedSize(stopIndex - regionIndex + 1); List<Scan> scans = Lists.newArrayListWithExpectedSize(2); while (regionIndex <= stopIndex) { HRegionLocation regionLocation = regionLocations.get(regionIndex); RegionInfo regionInfo = regionLocation.getRegion(); Scan newScan = ScanUtil.newScan(scan); byte[] endKey; if (regionIndex == stopIndex) { endKey = scan.getStopRow(); } else { endKey = regionBoundaries.get(regionIndex); } if(ScanUtil.isLocalIndex(scan)) { ScanUtil.setLocalIndexAttributes(newScan, 0, regionInfo.getStartKey(), regionInfo.getEndKey(), newScan.getAttribute(SCAN_START_ROW_SUFFIX), newScan.getAttribute(SCAN_STOP_ROW_SUFFIX)); } else { if(Bytes.compareTo(scan.getStartRow(), regionInfo.getStartKey())<=0) { newScan.setAttribute(SCAN_ACTUAL_START_ROW, regionInfo.getStartKey()); newScan.setStartRow(regionInfo.getStartKey()); } if(scan.getStopRow().length == 0 || (regionInfo.getEndKey().length != 0 && Bytes.compareTo(scan.getStopRow(), regionInfo.getEndKey())>0)) { newScan.setStopRow(regionInfo.getEndKey()); } } scans = addNewScan(parallelScans, scans, newScan, endKey, true, regionLocation); regionIndex++; } if (!scans.isEmpty()) { // Add any remaining scans parallelScans.add(scans); } return parallelScans; }