/** * Put the passed <code>p</code> to the <code>hbase:meta</code> table. * @param connection connection we're using * @param p Put to add to hbase:meta */ private static void putToMetaTable(Connection connection, Put p) throws IOException { try (Table table = getMetaHTable(connection)) { put(table, p); } }
/** * Gets the result in hbase:meta for the specified region. * @param connection connection we're using * @param regionName region we're looking for * @return result of the specified region */ public static Result getRegionResult(Connection connection, byte[] regionName) throws IOException { Get get = new Get(regionName); get.addFamily(HConstants.CATALOG_FAMILY); return get(getMetaHTable(connection), get); }
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; }
/** * Delete the passed <code>deletes</code> from the <code>hbase:meta</code> table. * @param connection connection we're using * @param deletes Deletes to add to hbase:meta This list should support #remove. */ private static void deleteFromMetaTable(final Connection connection, final List<Delete> deletes) throws IOException { try (Table t = getMetaHTable(connection)) { debugLogMutations(deletes); t.delete(deletes); } }
/** * Put the passed <code>ps</code> to the <code>hbase:meta</code> table. * @param connection connection we're using * @param ps Put to add to hbase:meta */ public static void putsToMetaTable(final Connection connection, final List<Put> ps) throws IOException { if (ps.isEmpty()) { return; } try (Table t = getMetaHTable(connection)) { debugLogMutations(ps); // the implementation for putting a single Put is much simpler so here we do a check first. if (ps.size() == 1) { t.put(ps.get(0)); } else { t.put(ps); } } }
/** * Execute the passed <code>mutations</code> against <code>hbase:meta</code> table. * @param connection connection we're using * @param mutations Puts and Deletes to execute on hbase:meta * @throws IOException */ public static void mutateMetaTable(final Connection connection, final List<Mutation> mutations) throws IOException { Table t = getMetaHTable(connection); try { debugLogMutations(mutations); t.batch(mutations, null); } catch (InterruptedException e) { InterruptedIOException ie = new InterruptedIOException(e.getMessage()); ie.initCause(e); throw ie; } finally { t.close(); } }
public static long[] getReplicationBarrier(Connection conn, byte[] regionName) throws IOException { try (Table table = getMetaHTable(conn)) { Result result = table.get(new Get(regionName) .addColumn(HConstants.REPLICATION_BARRIER_FAMILY, HConstants.SEQNUM_QUALIFIER) .readAllVersions()); return getReplicationBarriers(result); } }
/** * 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()); }
/** * Adds daughter region infos to hbase:meta row for the specified region. Note that this does not * add its daughter's as different rows, but adds information about the daughters in the same row * as the parent. Use * {@link #splitRegion(Connection, RegionInfo, long, RegionInfo, RegionInfo, ServerName, int)} * if you want to do that. * @param connection connection we're using * @param regionInfo RegionInfo of parent region * @param splitA first split daughter of the parent regionInfo * @param splitB second split daughter of the parent regionInfo * @throws IOException if problem connecting or updating meta */ public static void addSplitsToParent(Connection connection, RegionInfo regionInfo, RegionInfo splitA, RegionInfo splitB) throws IOException { Table meta = getMetaHTable(connection); try { Put put = makePutFromRegionInfo(regionInfo, EnvironmentEdgeManager.currentTime()); addDaughtersToPut(put, splitA, splitB); meta.put(put); debugLogMutation(put); LOG.debug("Added region {}", regionInfo.getRegionNameAsString()); } finally { meta.close(); } }
/** * Fetch table state for given table from META table * @param conn connection to use * @param tableName table to fetch state for * @return state * @throws IOException */ @Nullable public static TableState getTableState(Connection conn, TableName tableName) throws IOException { if (tableName.equals(TableName.META_TABLE_NAME)) { return new TableState(tableName, TableState.State.ENABLED); } Table metaHTable = getMetaHTable(conn); Get get = new Get(tableName.getName()).addColumn(getTableFamily(), getTableStateColumn()); Result result = metaHTable.get(get); return getTableState(result); }
public static ReplicationBarrierResult getReplicationBarrierResult(Connection conn, TableName tableName, byte[] row, byte[] encodedRegionName) throws IOException { byte[] metaStartKey = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false); byte[] metaStopKey = RegionInfo.createRegionName(tableName, HConstants.EMPTY_START_ROW, "", false); Scan scan = new Scan().withStartRow(metaStartKey).withStopRow(metaStopKey) .addColumn(getCatalogFamily(), getRegionStateColumn()) .addFamily(HConstants.REPLICATION_BARRIER_FAMILY).readAllVersions().setReversed(true) .setCaching(10); try (Table table = getMetaHTable(conn); ResultScanner scanner = table.getScanner(scan)) { for (Result result;;) { result = scanner.next(); if (result == null) { return new ReplicationBarrierResult(new long[0], null, Collections.emptyList()); } byte[] regionName = result.getRow(); // TODO: we may look up a region which has already been split or merged so we need to check // whether the encoded name matches. Need to find a way to quit earlier when there is no // record for the given region, for now it will scan to the end of the table. if (!Bytes.equals(encodedRegionName, Bytes.toBytes(RegionInfo.encodeRegionName(regionName)))) { continue; } return getReplicationBarrierResult(result); } } }
try (Table metaTable = getMetaHTable(connection)) { try (ResultScanner scanner = metaTable.getScanner(scan)) { Result data;
/** * @return Get closest metatable region row to passed <code>row</code> */ @NonNull private static RegionInfo getClosestRegionInfo(Connection connection, @NonNull final TableName tableName, @NonNull final byte[] row) throws IOException { byte[] searchRow = RegionInfo.createRegionName(tableName, row, HConstants.NINES, false); Scan scan = getMetaScan(connection, 1); scan.setReversed(true); scan.withStartRow(searchRow); try (ResultScanner resultScanner = getMetaHTable(connection).getScanner(scan)) { Result result = resultScanner.next(); if (result == null) { throw new TableNotFoundException("Cannot find row in META " + " for table: " + tableName + ", row=" + Bytes.toStringBinary(row)); } RegionInfo regionInfo = getRegionInfo(result); if (regionInfo == null) { throw new IOException("RegionInfo was null or empty in Meta for " + tableName + ", row=" + Bytes.toStringBinary(row)); } return regionInfo; } }
@Test public void testMetaLocationForRegionReplicasIsAddedAtTableCreation() throws IOException { long regionId = System.currentTimeMillis(); RegionInfo primary = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())) .setStartKey(HConstants.EMPTY_START_ROW) .setEndKey(HConstants.EMPTY_END_ROW) .setSplit(false) .setRegionId(regionId) .setReplicaId(0) .build(); Table meta = MetaTableAccessor.getMetaHTable(connection); try { List<RegionInfo> regionInfos = Lists.newArrayList(primary); MetaTableAccessor.addRegionsToMeta(connection, regionInfos, 3); assertEmptyMetaLocation(meta, primary.getRegionName(), 1); assertEmptyMetaLocation(meta, primary.getRegionName(), 2); } finally { meta.close(); } }
.build(); try (Table meta = MetaTableAccessor.getMetaHTable(connection)) { List<RegionInfo> regionInfos = Lists.newArrayList(parentA, parentB); MetaTableAccessor.addRegionsToMeta(connection, regionInfos, 3);
.build(); try (Table meta = MetaTableAccessor.getMetaHTable(connection)) { List<RegionInfo> regionInfos = Lists.newArrayList(parent); MetaTableAccessor.addRegionsToMeta(connection, regionInfos, 3);
Result result; try (ResultScanner scanner = MetaTableAccessor.getMetaHTable(UTIL.getConnection()).getScanner(barrierScan)) { while ((result = scanner.next()) != null) { assertTrue(MetaTableAccessor.getReplicationBarriers(result).length > 0);
.setRegionId(regionId).setReplicaId(0).build(); Table meta = MetaTableAccessor.getMetaHTable(connection); try { List<RegionInfo> regionInfos = Lists.newArrayList(primary);
try (Table meta = MetaTableAccessor.getMetaHTable(connection)) { List<RegionInfo> regionInfos = Lists.newArrayList(regionInfo); MetaTableAccessor.addRegionsToMeta(connection, regionInfos, 1);