private Result getRegionFromMeta(Connection connection, List<RegionInfo> regionsOfTable) throws IOException { byte[] metaKeyForRegion = MetaTableAccessor.getMetaKeyForRegion(regionsOfTable.get(0)); Get get = new Get(metaKeyForRegion); get.addFamily(HConstants.CATALOG_FAMILY); Table metaTable = MetaTableAccessor.getMetaHTable(connection); Result r = metaTable.get(get); return r; }
/** * Returns the HRegionLocation from meta for the given region * @param metaTable * @param regionName region we're looking for * @return HRegionLocation for the given region */ public static CompletableFuture<Optional<HRegionLocation>> getRegionLocation( AsyncTable<?> metaTable, byte[] regionName) { CompletableFuture<Optional<HRegionLocation>> future = new CompletableFuture<>(); try { RegionInfo parsedRegionInfo = MetaTableAccessor.parseRegionInfoFromRegionName(regionName); metaTable.get( new Get(MetaTableAccessor.getMetaKeyForRegion(parsedRegionInfo)) .addFamily(HConstants.CATALOG_FAMILY)).whenComplete( (r, err) -> { if (err != null) { future.completeExceptionally(err); return; } future.complete(getRegionLocations(r).map( locations -> locations.getRegionLocation(parsedRegionInfo.getReplicaId()))); }); } catch (IOException parseEx) { LOG.warn("Failed to parse the passed region name: " + Bytes.toStringBinary(regionName)); future.completeExceptionally(parseEx); } return future; }
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionInfo region information * @return HRegionLocation for the given region */ public static HRegionLocation getRegionLocation(Connection connection, RegionInfo regionInfo) throws IOException { byte[] row = getMetaKeyForRegion(regionInfo); Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); return getRegionLocation(r, regionInfo, regionInfo.getReplicaId()); }
/** * Updates the location of the specified region to be the specified server. * <p> * Connects to the specified server which should be hosting the specified catalog region name to * perform the edit. * @param connection connection we're using * @param regionInfo region to update location of * @param sn Server name * @param openSeqNum the latest sequence number obtained when the region was open * @param masterSystemTime wall clock time from master if passed in the open region RPC * @throws IOException In particular could throw {@link java.net.ConnectException} if the server * is down on other end. */ private static void updateLocation(Connection connection, RegionInfo regionInfo, ServerName sn, long openSeqNum, long masterSystemTime) throws IOException { // region replicas are kept in the primary region's row Put put = new Put(getMetaKeyForRegion(regionInfo), masterSystemTime); addRegionInfo(put, regionInfo); addLocation(put, sn, openSeqNum, regionInfo.getReplicaId()); putToMetaTable(connection, put); LOG.info("Updated row {} with server=", regionInfo.getRegionNameAsString(), sn); }
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionName region we're looking for * @return HRegionLocation for the given region */ public static HRegionLocation getRegionLocation(Connection connection, byte[] regionName) throws IOException { byte[] row = regionName; RegionInfo parsedInfo = null; try { parsedInfo = parseRegionInfoFromRegionName(regionName); row = getMetaKeyForRegion(parsedInfo); } catch (Exception parseEx) { // Ignore. This is used with tableName passed as regionName. } Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); RegionLocations locations = getRegionLocations(r); return locations == null ? null : locations.getRegionLocation(parsedInfo == null ? 0 : parsedInfo.getReplicaId()); }
long time = EnvironmentEdgeManager.currentTime(); final int replicaId = regionInfo.getReplicaId(); final Put put = new Put(MetaTableAccessor.getMetaKeyForRegion(regionInfo), time); MetaTableAccessor.addRegionInfo(put, regionInfo); final StringBuilder info =
/** * Returns the HRegionLocation from meta for the given region * @param metaTable * @param regionName region we're looking for * @return HRegionLocation for the given region */ public static CompletableFuture<Optional<HRegionLocation>> getRegionLocation( AsyncTable<?> metaTable, byte[] regionName) { CompletableFuture<Optional<HRegionLocation>> future = new CompletableFuture<>(); try { RegionInfo parsedRegionInfo = MetaTableAccessor.parseRegionInfoFromRegionName(regionName); metaTable.get( new Get(MetaTableAccessor.getMetaKeyForRegion(parsedRegionInfo)) .addFamily(HConstants.CATALOG_FAMILY)).whenComplete( (r, err) -> { if (err != null) { future.completeExceptionally(err); return; } future.complete(getRegionLocations(r).map( locations -> locations.getRegionLocation(parsedRegionInfo.getReplicaId()))); }); } catch (IOException parseEx) { LOG.warn("Failed to parse the passed region name: " + Bytes.toStringBinary(regionName)); future.completeExceptionally(parseEx); } return future; }
/** * Updates the location of the specified region to be the specified server. * <p> * Connects to the specified server which should be hosting the specified catalog region name to * perform the edit. * @param connection connection we're using * @param regionInfo region to update location of * @param sn Server name * @param openSeqNum the latest sequence number obtained when the region was open * @param masterSystemTime wall clock time from master if passed in the open region RPC * @throws IOException In particular could throw {@link java.net.ConnectException} if the server * is down on other end. */ private static void updateLocation(Connection connection, RegionInfo regionInfo, ServerName sn, long openSeqNum, long masterSystemTime) throws IOException { // region replicas are kept in the primary region's row Put put = new Put(getMetaKeyForRegion(regionInfo), masterSystemTime); addRegionInfo(put, regionInfo); addLocation(put, sn, openSeqNum, regionInfo.getReplicaId()); putToMetaTable(connection, put); LOG.info("Updated row {} with server=", regionInfo.getRegionNameAsString(), sn); }
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionInfo region information * @return HRegionLocation for the given region */ public static HRegionLocation getRegionLocation(Connection connection, RegionInfo regionInfo) throws IOException { byte[] row = getMetaKeyForRegion(regionInfo); Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); return getRegionLocation(r, regionInfo, regionInfo.getReplicaId()); }
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionName region we're looking for * @return HRegionLocation for the given region */ public static HRegionLocation getRegionLocation(Connection connection, byte[] regionName) throws IOException { byte[] row = regionName; RegionInfo parsedInfo = null; try { parsedInfo = parseRegionInfoFromRegionName(regionName); row = getMetaKeyForRegion(parsedInfo); } catch (Exception parseEx) { // Ignore. This is used with tableName passed as regionName. } Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); RegionLocations locations = getRegionLocations(r); return locations == null ? null : locations.getRegionLocation(parsedInfo == null ? 0 : parsedInfo.getReplicaId()); }
/** * Returns the HRegionLocation from meta for the given region * @param metaTable * @param regionName region we're looking for * @return HRegionLocation for the given region */ public static CompletableFuture<Optional<HRegionLocation>> getRegionLocation( AsyncTable<?> metaTable, byte[] regionName) { CompletableFuture<Optional<HRegionLocation>> future = new CompletableFuture<>(); try { RegionInfo parsedRegionInfo = MetaTableAccessor.parseRegionInfoFromRegionName(regionName); metaTable.get( new Get(MetaTableAccessor.getMetaKeyForRegion(parsedRegionInfo)) .addFamily(HConstants.CATALOG_FAMILY)).whenComplete( (r, err) -> { if (err != null) { future.completeExceptionally(err); return; } future.complete(getRegionLocations(r).map( locations -> locations.getRegionLocation(parsedRegionInfo.getReplicaId()))); }); } catch (IOException parseEx) { LOG.warn("Failed to parse the passed region name: " + Bytes.toStringBinary(regionName)); future.completeExceptionally(parseEx); } return future; }
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionInfo region information * @return HRegionLocation for the given region */ public static HRegionLocation getRegionLocation(Connection connection, RegionInfo regionInfo) throws IOException { byte[] row = getMetaKeyForRegion(regionInfo); Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); return getRegionLocation(r, regionInfo, regionInfo.getReplicaId()); }
/** * Updates the location of the specified region to be the specified server. * <p> * Connects to the specified server which should be hosting the specified catalog region name to * perform the edit. * @param connection connection we're using * @param regionInfo region to update location of * @param sn Server name * @param openSeqNum the latest sequence number obtained when the region was open * @param masterSystemTime wall clock time from master if passed in the open region RPC * @throws IOException In particular could throw {@link java.net.ConnectException} if the server * is down on other end. */ private static void updateLocation(Connection connection, RegionInfo regionInfo, ServerName sn, long openSeqNum, long masterSystemTime) throws IOException { // region replicas are kept in the primary region's row Put put = new Put(getMetaKeyForRegion(regionInfo), masterSystemTime); addRegionInfo(put, regionInfo); addLocation(put, sn, openSeqNum, regionInfo.getReplicaId()); putToMetaTable(connection, put); LOG.info("Updated row {} with server=", regionInfo.getRegionNameAsString(), sn); }
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionInfo region information * @return HRegionLocation for the given region * @throws IOException */ public static HRegionLocation getRegionLocation(Connection connection, HRegionInfo regionInfo) throws IOException { byte[] row = getMetaKeyForRegion(regionInfo); Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); return getRegionLocation(r, regionInfo, regionInfo.getReplicaId()); }
/** * Updates the location of the specified region to be the specified server. * <p> * Connects to the specified server which should be hosting the specified * catalog region name to perform the edit. * * @param connection connection we're using * @param regionInfo region to update location of * @param sn Server name * @param openSeqNum the latest sequence number obtained when the region was open * @param masterSystemTime wall clock time from master if passed in the open region RPC or -1 * @throws IOException In particular could throw {@link java.net.ConnectException} * if the server is down on other end. */ private static void updateLocation(final Connection connection, HRegionInfo regionInfo, ServerName sn, long openSeqNum, long masterSystemTime) throws IOException { // use the maximum of what master passed us vs local time. long time = Math.max(EnvironmentEdgeManager.currentTime(), masterSystemTime); // region replicas are kept in the primary region's row Put put = new Put(getMetaKeyForRegion(regionInfo), time); addLocation(put, sn, openSeqNum, time, regionInfo.getReplicaId()); putToMetaTable(connection, put); LOG.info("Updated row " + regionInfo.getRegionNameAsString() + " with server=" + sn); }
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionName region we're looking for * @return HRegionLocation for the given region */ public static HRegionLocation getRegionLocation(Connection connection, byte[] regionName) throws IOException { byte[] row = regionName; RegionInfo parsedInfo = null; try { parsedInfo = parseRegionInfoFromRegionName(regionName); row = getMetaKeyForRegion(parsedInfo); } catch (Exception parseEx) { // Ignore. This is used with tableName passed as regionName. } Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); RegionLocations locations = getRegionLocations(r); return locations == null ? null : locations.getRegionLocation(parsedInfo == null ? 0 : parsedInfo.getReplicaId()); }
/** * Returns the HRegionLocation from meta for the given region * @param connection connection we're using * @param regionName region we're looking for * @return HRegionLocation for the given region * @throws IOException */ public static HRegionLocation getRegionLocation(Connection connection, byte[] regionName) throws IOException { byte[] row = regionName; HRegionInfo parsedInfo = null; try { parsedInfo = parseRegionInfoFromRegionName(regionName); row = getMetaKeyForRegion(parsedInfo); } catch (Exception parseEx) { // Ignore. This is used with tableName passed as regionName. } Get get = new Get(row); get.addFamily(HConstants.CATALOG_FAMILY); Result r = get(getMetaHTable(connection), get); RegionLocations locations = getRegionLocations(r); return locations == null ? null : locations.getRegionLocation(parsedInfo == null ? 0 : parsedInfo.getReplicaId()); }
Put put = new Put(MetaTableAccessor.getMetaKeyForRegion(hri)); StringBuilder info = new StringBuilder("Updating hbase:meta row "); info.append(hri.getRegionNameAsString()).append(" with state=").append(state);